@build-astron-co/nimbus 0.2.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 (313) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +628 -0
  3. package/bin/nimbus +38 -0
  4. package/package.json +80 -0
  5. package/src/__tests__/app.test.ts +76 -0
  6. package/src/__tests__/audit.test.ts +877 -0
  7. package/src/__tests__/circuit-breaker.test.ts +116 -0
  8. package/src/__tests__/cli-run.test.ts +115 -0
  9. package/src/__tests__/context-manager.test.ts +502 -0
  10. package/src/__tests__/context.test.ts +242 -0
  11. package/src/__tests__/enterprise.test.ts +401 -0
  12. package/src/__tests__/generator.test.ts +433 -0
  13. package/src/__tests__/hooks.test.ts +582 -0
  14. package/src/__tests__/init.test.ts +436 -0
  15. package/src/__tests__/intent-parser.test.ts +229 -0
  16. package/src/__tests__/llm-router.test.ts +209 -0
  17. package/src/__tests__/lsp.test.ts +293 -0
  18. package/src/__tests__/modes.test.ts +336 -0
  19. package/src/__tests__/permissions.test.ts +338 -0
  20. package/src/__tests__/serve.test.ts +275 -0
  21. package/src/__tests__/sessions.test.ts +227 -0
  22. package/src/__tests__/sharing.test.ts +288 -0
  23. package/src/__tests__/snapshots.test.ts +581 -0
  24. package/src/__tests__/state-db.test.ts +334 -0
  25. package/src/__tests__/stream-with-tools.test.ts +732 -0
  26. package/src/__tests__/subagents.test.ts +176 -0
  27. package/src/__tests__/system-prompt.test.ts +169 -0
  28. package/src/__tests__/tool-converter.test.ts +256 -0
  29. package/src/__tests__/tool-schemas.test.ts +397 -0
  30. package/src/__tests__/tools.test.ts +143 -0
  31. package/src/__tests__/version.test.ts +49 -0
  32. package/src/agent/compaction-agent.ts +227 -0
  33. package/src/agent/context-manager.ts +435 -0
  34. package/src/agent/context.ts +427 -0
  35. package/src/agent/deploy-preview.ts +426 -0
  36. package/src/agent/index.ts +68 -0
  37. package/src/agent/loop.ts +717 -0
  38. package/src/agent/modes.ts +429 -0
  39. package/src/agent/permissions.ts +466 -0
  40. package/src/agent/subagents/base.ts +116 -0
  41. package/src/agent/subagents/cost.ts +51 -0
  42. package/src/agent/subagents/explore.ts +42 -0
  43. package/src/agent/subagents/general.ts +54 -0
  44. package/src/agent/subagents/index.ts +102 -0
  45. package/src/agent/subagents/infra.ts +59 -0
  46. package/src/agent/subagents/security.ts +69 -0
  47. package/src/agent/system-prompt.ts +436 -0
  48. package/src/app.ts +122 -0
  49. package/src/audit/activity-log.ts +290 -0
  50. package/src/audit/compliance-checker.ts +540 -0
  51. package/src/audit/cost-tracker.ts +318 -0
  52. package/src/audit/index.ts +23 -0
  53. package/src/audit/security-scanner.ts +596 -0
  54. package/src/auth/guard.ts +75 -0
  55. package/src/auth/index.ts +56 -0
  56. package/src/auth/oauth.ts +455 -0
  57. package/src/auth/providers.ts +470 -0
  58. package/src/auth/sso.ts +113 -0
  59. package/src/auth/store.ts +505 -0
  60. package/src/auth/types.ts +187 -0
  61. package/src/build.ts +141 -0
  62. package/src/cli/index.ts +16 -0
  63. package/src/cli/init.ts +854 -0
  64. package/src/cli/openapi-spec.ts +356 -0
  65. package/src/cli/run.ts +237 -0
  66. package/src/cli/serve-auth.ts +80 -0
  67. package/src/cli/serve.ts +462 -0
  68. package/src/cli/web.ts +67 -0
  69. package/src/cli.ts +1417 -0
  70. package/src/clients/core-engine-client.ts +227 -0
  71. package/src/clients/enterprise-client.ts +334 -0
  72. package/src/clients/generator-client.ts +351 -0
  73. package/src/clients/git-client.ts +627 -0
  74. package/src/clients/github-client.ts +410 -0
  75. package/src/clients/helm-client.ts +504 -0
  76. package/src/clients/index.ts +80 -0
  77. package/src/clients/k8s-client.ts +497 -0
  78. package/src/clients/llm-client.ts +161 -0
  79. package/src/clients/rest-client.ts +130 -0
  80. package/src/clients/service-discovery.ts +33 -0
  81. package/src/clients/terraform-client.ts +482 -0
  82. package/src/clients/tools-client.ts +1843 -0
  83. package/src/clients/ws-client.ts +115 -0
  84. package/src/commands/analyze/index.ts +352 -0
  85. package/src/commands/apply/helm.ts +473 -0
  86. package/src/commands/apply/index.ts +213 -0
  87. package/src/commands/apply/k8s.ts +454 -0
  88. package/src/commands/apply/terraform.ts +582 -0
  89. package/src/commands/ask.ts +167 -0
  90. package/src/commands/audit/index.ts +238 -0
  91. package/src/commands/auth-cloud.ts +294 -0
  92. package/src/commands/auth-list.ts +134 -0
  93. package/src/commands/auth-profile.ts +121 -0
  94. package/src/commands/auth-status.ts +141 -0
  95. package/src/commands/aws/ec2.ts +501 -0
  96. package/src/commands/aws/iam.ts +397 -0
  97. package/src/commands/aws/index.ts +133 -0
  98. package/src/commands/aws/lambda.ts +396 -0
  99. package/src/commands/aws/rds.ts +439 -0
  100. package/src/commands/aws/s3.ts +439 -0
  101. package/src/commands/aws/vpc.ts +393 -0
  102. package/src/commands/aws-discover.ts +649 -0
  103. package/src/commands/aws-terraform.ts +805 -0
  104. package/src/commands/azure/aks.ts +376 -0
  105. package/src/commands/azure/functions.ts +253 -0
  106. package/src/commands/azure/index.ts +116 -0
  107. package/src/commands/azure/storage.ts +478 -0
  108. package/src/commands/azure/vm.ts +355 -0
  109. package/src/commands/billing/index.ts +256 -0
  110. package/src/commands/chat.ts +314 -0
  111. package/src/commands/config.ts +346 -0
  112. package/src/commands/cost/cloud-cost-estimator.ts +266 -0
  113. package/src/commands/cost/estimator.ts +79 -0
  114. package/src/commands/cost/index.ts +594 -0
  115. package/src/commands/cost/parsers/terraform.ts +273 -0
  116. package/src/commands/cost/parsers/types.ts +25 -0
  117. package/src/commands/cost/pricing/aws.ts +544 -0
  118. package/src/commands/cost/pricing/azure.ts +499 -0
  119. package/src/commands/cost/pricing/gcp.ts +396 -0
  120. package/src/commands/cost/pricing/index.ts +40 -0
  121. package/src/commands/demo.ts +250 -0
  122. package/src/commands/doctor.ts +794 -0
  123. package/src/commands/drift/index.ts +439 -0
  124. package/src/commands/explain.ts +277 -0
  125. package/src/commands/feedback.ts +389 -0
  126. package/src/commands/fix.ts +324 -0
  127. package/src/commands/fs/index.ts +402 -0
  128. package/src/commands/gcp/compute.ts +325 -0
  129. package/src/commands/gcp/functions.ts +271 -0
  130. package/src/commands/gcp/gke.ts +438 -0
  131. package/src/commands/gcp/iam.ts +344 -0
  132. package/src/commands/gcp/index.ts +129 -0
  133. package/src/commands/gcp/storage.ts +284 -0
  134. package/src/commands/generate-helm.ts +1249 -0
  135. package/src/commands/generate-k8s.ts +1560 -0
  136. package/src/commands/generate-terraform.ts +1460 -0
  137. package/src/commands/gh/index.ts +863 -0
  138. package/src/commands/git/index.ts +1343 -0
  139. package/src/commands/helm/index.ts +1126 -0
  140. package/src/commands/help.ts +539 -0
  141. package/src/commands/history.ts +142 -0
  142. package/src/commands/import.ts +868 -0
  143. package/src/commands/index.ts +367 -0
  144. package/src/commands/init.ts +1046 -0
  145. package/src/commands/k8s/index.ts +1137 -0
  146. package/src/commands/login.ts +631 -0
  147. package/src/commands/logout.ts +83 -0
  148. package/src/commands/onboarding.ts +228 -0
  149. package/src/commands/plan/display.ts +279 -0
  150. package/src/commands/plan/index.ts +599 -0
  151. package/src/commands/preview.ts +452 -0
  152. package/src/commands/questionnaire.ts +1270 -0
  153. package/src/commands/resume.ts +55 -0
  154. package/src/commands/team/index.ts +346 -0
  155. package/src/commands/template.ts +232 -0
  156. package/src/commands/tf/index.ts +1034 -0
  157. package/src/commands/upgrade.ts +550 -0
  158. package/src/commands/usage/index.ts +134 -0
  159. package/src/commands/version.ts +170 -0
  160. package/src/compat/index.ts +2 -0
  161. package/src/compat/runtime.ts +12 -0
  162. package/src/compat/sqlite.ts +107 -0
  163. package/src/config/index.ts +17 -0
  164. package/src/config/manager.ts +530 -0
  165. package/src/config/safety-policy.ts +358 -0
  166. package/src/config/schema.ts +125 -0
  167. package/src/config/types.ts +527 -0
  168. package/src/context/context-db.ts +199 -0
  169. package/src/demo/index.ts +349 -0
  170. package/src/demo/scenarios/full-journey.ts +229 -0
  171. package/src/demo/scenarios/getting-started.ts +127 -0
  172. package/src/demo/scenarios/helm-release.ts +341 -0
  173. package/src/demo/scenarios/k8s-deployment.ts +194 -0
  174. package/src/demo/scenarios/terraform-vpc.ts +170 -0
  175. package/src/demo/types.ts +92 -0
  176. package/src/engine/cost-estimator.ts +438 -0
  177. package/src/engine/diagram-generator.ts +256 -0
  178. package/src/engine/drift-detector.ts +902 -0
  179. package/src/engine/executor.ts +1035 -0
  180. package/src/engine/index.ts +76 -0
  181. package/src/engine/orchestrator.ts +636 -0
  182. package/src/engine/planner.ts +720 -0
  183. package/src/engine/safety.ts +743 -0
  184. package/src/engine/verifier.ts +770 -0
  185. package/src/enterprise/audit.ts +348 -0
  186. package/src/enterprise/auth.ts +270 -0
  187. package/src/enterprise/billing.ts +822 -0
  188. package/src/enterprise/index.ts +17 -0
  189. package/src/enterprise/teams.ts +443 -0
  190. package/src/generator/best-practices.ts +1608 -0
  191. package/src/generator/helm.ts +630 -0
  192. package/src/generator/index.ts +37 -0
  193. package/src/generator/intent-parser.ts +514 -0
  194. package/src/generator/kubernetes.ts +976 -0
  195. package/src/generator/terraform.ts +1867 -0
  196. package/src/history/index.ts +8 -0
  197. package/src/history/manager.ts +322 -0
  198. package/src/history/types.ts +34 -0
  199. package/src/hooks/config.ts +432 -0
  200. package/src/hooks/engine.ts +391 -0
  201. package/src/hooks/index.ts +4 -0
  202. package/src/llm/auth-bridge.ts +198 -0
  203. package/src/llm/circuit-breaker.ts +140 -0
  204. package/src/llm/config-loader.ts +201 -0
  205. package/src/llm/cost-calculator.ts +171 -0
  206. package/src/llm/index.ts +8 -0
  207. package/src/llm/model-aliases.ts +115 -0
  208. package/src/llm/provider-registry.ts +63 -0
  209. package/src/llm/providers/anthropic.ts +433 -0
  210. package/src/llm/providers/bedrock.ts +477 -0
  211. package/src/llm/providers/google.ts +405 -0
  212. package/src/llm/providers/ollama.ts +767 -0
  213. package/src/llm/providers/openai-compatible.ts +340 -0
  214. package/src/llm/providers/openai.ts +328 -0
  215. package/src/llm/providers/openrouter.ts +338 -0
  216. package/src/llm/router.ts +1035 -0
  217. package/src/llm/types.ts +232 -0
  218. package/src/lsp/client.ts +298 -0
  219. package/src/lsp/languages.ts +116 -0
  220. package/src/lsp/manager.ts +278 -0
  221. package/src/mcp/client.ts +402 -0
  222. package/src/mcp/index.ts +5 -0
  223. package/src/mcp/manager.ts +133 -0
  224. package/src/nimbus.ts +214 -0
  225. package/src/plugins/index.ts +27 -0
  226. package/src/plugins/loader.ts +334 -0
  227. package/src/plugins/manager.ts +376 -0
  228. package/src/plugins/types.ts +284 -0
  229. package/src/scanners/cicd-scanner.ts +258 -0
  230. package/src/scanners/cloud-scanner.ts +466 -0
  231. package/src/scanners/framework-scanner.ts +469 -0
  232. package/src/scanners/iac-scanner.ts +388 -0
  233. package/src/scanners/index.ts +539 -0
  234. package/src/scanners/language-scanner.ts +276 -0
  235. package/src/scanners/package-manager-scanner.ts +277 -0
  236. package/src/scanners/types.ts +172 -0
  237. package/src/sessions/manager.ts +365 -0
  238. package/src/sessions/types.ts +44 -0
  239. package/src/sharing/sync.ts +296 -0
  240. package/src/sharing/viewer.ts +97 -0
  241. package/src/snapshots/index.ts +2 -0
  242. package/src/snapshots/manager.ts +530 -0
  243. package/src/state/artifacts.ts +147 -0
  244. package/src/state/audit.ts +137 -0
  245. package/src/state/billing.ts +240 -0
  246. package/src/state/checkpoints.ts +117 -0
  247. package/src/state/config.ts +67 -0
  248. package/src/state/conversations.ts +14 -0
  249. package/src/state/credentials.ts +154 -0
  250. package/src/state/db.ts +58 -0
  251. package/src/state/index.ts +26 -0
  252. package/src/state/messages.ts +115 -0
  253. package/src/state/projects.ts +123 -0
  254. package/src/state/schema.ts +236 -0
  255. package/src/state/sessions.ts +147 -0
  256. package/src/state/teams.ts +200 -0
  257. package/src/telemetry.ts +108 -0
  258. package/src/tools/aws-ops.ts +952 -0
  259. package/src/tools/azure-ops.ts +579 -0
  260. package/src/tools/file-ops.ts +593 -0
  261. package/src/tools/gcp-ops.ts +625 -0
  262. package/src/tools/git-ops.ts +773 -0
  263. package/src/tools/github-ops.ts +799 -0
  264. package/src/tools/helm-ops.ts +943 -0
  265. package/src/tools/index.ts +17 -0
  266. package/src/tools/k8s-ops.ts +819 -0
  267. package/src/tools/schemas/converter.ts +184 -0
  268. package/src/tools/schemas/devops.ts +612 -0
  269. package/src/tools/schemas/index.ts +73 -0
  270. package/src/tools/schemas/standard.ts +1144 -0
  271. package/src/tools/schemas/types.ts +705 -0
  272. package/src/tools/terraform-ops.ts +862 -0
  273. package/src/types/ambient.d.ts +193 -0
  274. package/src/types/config.ts +83 -0
  275. package/src/types/drift.ts +116 -0
  276. package/src/types/enterprise.ts +335 -0
  277. package/src/types/index.ts +20 -0
  278. package/src/types/plan.ts +44 -0
  279. package/src/types/request.ts +65 -0
  280. package/src/types/response.ts +54 -0
  281. package/src/types/service.ts +51 -0
  282. package/src/ui/App.tsx +997 -0
  283. package/src/ui/DeployPreview.tsx +169 -0
  284. package/src/ui/Header.tsx +68 -0
  285. package/src/ui/InputBox.tsx +350 -0
  286. package/src/ui/MessageList.tsx +585 -0
  287. package/src/ui/PermissionPrompt.tsx +151 -0
  288. package/src/ui/StatusBar.tsx +158 -0
  289. package/src/ui/ToolCallDisplay.tsx +409 -0
  290. package/src/ui/chat-ui.ts +853 -0
  291. package/src/ui/index.ts +33 -0
  292. package/src/ui/ink/index.ts +711 -0
  293. package/src/ui/streaming.ts +176 -0
  294. package/src/ui/types.ts +57 -0
  295. package/src/utils/analytics.ts +72 -0
  296. package/src/utils/cost-warning.ts +27 -0
  297. package/src/utils/env.ts +46 -0
  298. package/src/utils/errors.ts +69 -0
  299. package/src/utils/event-bus.ts +38 -0
  300. package/src/utils/index.ts +24 -0
  301. package/src/utils/logger.ts +171 -0
  302. package/src/utils/rate-limiter.ts +121 -0
  303. package/src/utils/service-auth.ts +49 -0
  304. package/src/utils/validation.ts +53 -0
  305. package/src/version.ts +4 -0
  306. package/src/watcher/index.ts +163 -0
  307. package/src/wizard/approval.ts +383 -0
  308. package/src/wizard/index.ts +25 -0
  309. package/src/wizard/prompts.ts +338 -0
  310. package/src/wizard/types.ts +171 -0
  311. package/src/wizard/ui.ts +556 -0
  312. package/src/wizard/wizard.ts +304 -0
  313. package/tsconfig.json +24 -0
package/src/cli.ts ADDED
@@ -0,0 +1,1417 @@
1
+ /**
2
+ * CLI Command Router
3
+ *
4
+ * Dispatches CLI commands to their implementations in src/commands/.
5
+ */
6
+
7
+ import { analytics } from './utils';
8
+ import {
9
+ generateTerraformCommand,
10
+ type GenerateTerraformOptions,
11
+ awsDiscoverCommand,
12
+ type AwsDiscoverOptions,
13
+ awsTerraformCommand,
14
+ type AwsTerraformOptions,
15
+ loginCommand,
16
+ type LoginOptions,
17
+ logoutCommand,
18
+ type LogoutOptions,
19
+ authStatusCommand,
20
+ type AuthStatusOptions,
21
+ authListCommand,
22
+ type AuthListOptions,
23
+ chatCommand,
24
+ type ChatOptions,
25
+ configCommand,
26
+ type ConfigSetOptions,
27
+ type ConfigGetOptions,
28
+ type ConfigListOptions,
29
+ type ConfigInitOptions,
30
+ initCommand,
31
+ type InitOptions,
32
+ // Infrastructure tool commands
33
+ tfCommand,
34
+ k8sCommand,
35
+ helmCommand,
36
+ gitCommand,
37
+ // FS commands
38
+ fsCommand,
39
+ // History command
40
+ historyCommand,
41
+ historyShowCommand,
42
+ type HistoryOptions,
43
+ // GitHub CLI commands
44
+ ghCommand,
45
+ // Enterprise commands
46
+ teamCommand,
47
+ billingCommand,
48
+ usageCommand,
49
+ parseUsageOptions,
50
+ auditCommand,
51
+ analyzeCommand,
52
+ parseAnalyzeOptions,
53
+ // Cloud provider commands
54
+ awsCommand,
55
+ azureCommand,
56
+ gcpCommand,
57
+ // Cost and drift commands
58
+ costCommand,
59
+ driftCommand,
60
+ // Demo, feedback, preview, import, questionnaire commands
61
+ demoCommand,
62
+ parseDemoOptions,
63
+ feedbackCommand,
64
+ parseFeedbackOptions,
65
+ previewCommand,
66
+ type PreviewOptions,
67
+ importCommand,
68
+ parseImportOptions,
69
+ questionnaireCommand,
70
+ type QuestionnaireOptions,
71
+ // Cloud auth command
72
+ authCloudCommand,
73
+ type AuthCloudOptions,
74
+ // Generate commands
75
+ generateK8sCommand,
76
+ type GenerateK8sOptions,
77
+ generateHelmCommand,
78
+ type GenerateHelmOptions,
79
+ // Utility commands
80
+ versionCommand,
81
+ type VersionOptions,
82
+ helpCommand,
83
+ type HelpOptions,
84
+ doctorCommand,
85
+ type DoctorOptions,
86
+ // Apply commands
87
+ applyCommand,
88
+ // AI-powered commands
89
+ askCommand,
90
+ type AskOptions,
91
+ explainCommand,
92
+ type ExplainOptions,
93
+ fixCommand,
94
+ type FixOptions,
95
+ // Plan command
96
+ planCommand,
97
+ parsePlanOptions,
98
+ // Resume command
99
+ resumeCommand,
100
+ // Template commands
101
+ templateCommand,
102
+ // Auth profile commands
103
+ authProfileCommand,
104
+ } from './commands';
105
+ import { upgradeCommand, type UpgradeOptions } from './commands/upgrade';
106
+ import { requiresAuth, type LLMProviderName } from './auth';
107
+
108
+ /** Top-level command aliases for convenience shortcuts. */
109
+ const COMMAND_ALIASES: Record<string, string[]> = {
110
+ pr: ['gh', 'pr'],
111
+ issue: ['gh', 'issue'],
112
+ read: ['fs', 'read'],
113
+ tree: ['fs', 'tree'],
114
+ search: ['fs', 'search'],
115
+ write: ['fs', 'write'],
116
+ // Short command aliases
117
+ terraform: ['tf'],
118
+ k: ['k8s'],
119
+ g: ['generate'],
120
+ h: ['helm'],
121
+ };
122
+
123
+ /**
124
+ * Run a CLI command directly.
125
+ *
126
+ * This is the main entry point for `nimbus <command> <subcommand>`.
127
+ * It resolves aliases, checks authentication, and dispatches to
128
+ * the appropriate command handler.
129
+ */
130
+ export async function runCommand(args: string[]): Promise<void> {
131
+ // Resolve top-level command aliases
132
+ if (COMMAND_ALIASES[args[0]]) {
133
+ args = [...COMMAND_ALIASES[args[0]], ...args.slice(1)];
134
+ }
135
+
136
+ const command = args[0];
137
+ const subcommand = args[1];
138
+
139
+ // Fire-and-forget analytics tracking for every CLI command invocation.
140
+ // This is a no-op when POSTHOG_API_KEY is not set.
141
+ const commandName =
142
+ subcommand && !subcommand.startsWith('-') ? `${command} ${subcommand}` : command;
143
+ analytics.trackEvent('command_executed', { command: commandName }).catch(() => {});
144
+
145
+ // ==========================================
146
+ // Auth commands (always available, no guard)
147
+ // ==========================================
148
+
149
+ // nimbus login
150
+ if (command === 'login') {
151
+ const options: LoginOptions = {};
152
+
153
+ for (let i = 1; i < args.length; i++) {
154
+ const arg = args[i];
155
+
156
+ if (arg === '--skip-github') {
157
+ options.skipGitHub = true;
158
+ } else if (arg === '--provider' && args[i + 1]) {
159
+ options.provider = args[++i] as LLMProviderName;
160
+ } else if (arg === '--api-key' && args[i + 1]) {
161
+ options.apiKey = args[++i];
162
+ } else if (arg === '--model' && args[i + 1]) {
163
+ options.model = args[++i];
164
+ } else if (arg === '--non-interactive') {
165
+ options.nonInteractive = true;
166
+ } else if (arg === '--sso') {
167
+ options.sso = true;
168
+ }
169
+ }
170
+
171
+ await loginCommand(options);
172
+ return;
173
+ }
174
+
175
+ // nimbus logout
176
+ if (command === 'logout') {
177
+ const options: LogoutOptions = {};
178
+
179
+ for (let i = 1; i < args.length; i++) {
180
+ const arg = args[i];
181
+
182
+ if (arg === '--force' || arg === '-f') {
183
+ options.force = true;
184
+ }
185
+ }
186
+
187
+ await logoutCommand(options);
188
+ return;
189
+ }
190
+
191
+ // nimbus auth status
192
+ if (command === 'auth' && subcommand === 'status') {
193
+ const options: AuthStatusOptions = {};
194
+
195
+ for (let i = 2; i < args.length; i++) {
196
+ const arg = args[i];
197
+
198
+ if (arg === '--json') {
199
+ options.json = true;
200
+ }
201
+ }
202
+
203
+ await authStatusCommand(options);
204
+ return;
205
+ }
206
+
207
+ // nimbus auth list
208
+ if (command === 'auth' && subcommand === 'list') {
209
+ const options: AuthListOptions = {};
210
+
211
+ for (let i = 2; i < args.length; i++) {
212
+ const arg = args[i];
213
+
214
+ if (arg === '--json') {
215
+ options.json = true;
216
+ }
217
+ }
218
+
219
+ await authListCommand(options);
220
+ return;
221
+ }
222
+
223
+ // nimbus auth cloud|aws|gcp|azure
224
+ if (
225
+ command === 'auth' &&
226
+ (subcommand === 'cloud' ||
227
+ subcommand === 'aws' ||
228
+ subcommand === 'gcp' ||
229
+ subcommand === 'azure')
230
+ ) {
231
+ const provider = subcommand === 'cloud' ? args[2] || 'aws' : subcommand;
232
+ const options: AuthCloudOptions = {};
233
+
234
+ const startIdx = subcommand === 'cloud' ? 3 : 2;
235
+ for (let i = startIdx; i < args.length; i++) {
236
+ const arg = args[i];
237
+
238
+ if (arg === '--profile' && args[i + 1]) {
239
+ options.profile = args[++i];
240
+ } else if (arg === '--project' && args[i + 1]) {
241
+ options.project = args[++i];
242
+ } else if (arg === '--subscription' && args[i + 1]) {
243
+ options.subscription = args[++i];
244
+ } else if (arg === '--region' && args[i + 1]) {
245
+ options.region = args[++i];
246
+ }
247
+ }
248
+
249
+ await authCloudCommand(provider, options);
250
+ return;
251
+ }
252
+
253
+ // nimbus onboarding (first-run setup wizard)
254
+ if (command === 'onboarding') {
255
+ const { onboardingCommand } = await import('./commands/onboarding');
256
+ await onboardingCommand({});
257
+ return;
258
+ }
259
+
260
+ // nimbus version
261
+ if (command === 'version' || command === '-v' || command === '--version') {
262
+ const options: VersionOptions = {};
263
+
264
+ for (let i = 1; i < args.length; i++) {
265
+ const arg = args[i];
266
+
267
+ if (arg === '--verbose' || arg === '-v') {
268
+ options.verbose = true;
269
+ } else if (arg === '--json') {
270
+ options.json = true;
271
+ }
272
+ }
273
+
274
+ await versionCommand(options);
275
+ return;
276
+ }
277
+
278
+ // nimbus help
279
+ if (command === 'help' || command === '-h' || command === '--help') {
280
+ const options: HelpOptions = {};
281
+
282
+ // Check for command-specific help
283
+ if (subcommand && !subcommand.startsWith('-')) {
284
+ options.command = subcommand;
285
+ }
286
+
287
+ await helpCommand(options);
288
+ return;
289
+ }
290
+
291
+ // nimbus doctor
292
+ if (command === 'doctor') {
293
+ const options: DoctorOptions = {};
294
+
295
+ for (let i = 1; i < args.length; i++) {
296
+ const arg = args[i];
297
+
298
+ if (arg === '--fix') {
299
+ options.fix = true;
300
+ } else if (arg === '--verbose' || arg === '-v') {
301
+ options.verbose = true;
302
+ } else if (arg === '--json') {
303
+ options.json = true;
304
+ }
305
+ }
306
+
307
+ await doctorCommand(options);
308
+ return;
309
+ }
310
+
311
+ // nimbus upgrade
312
+ if (command === 'upgrade' || command === 'update') {
313
+ const options: UpgradeOptions = {};
314
+
315
+ for (let i = 1; i < args.length; i++) {
316
+ const arg = args[i];
317
+
318
+ if (arg === '--force' || arg === '-f') {
319
+ options.force = true;
320
+ } else if (arg === '--check' || arg === '-c') {
321
+ options.check = true;
322
+ }
323
+ }
324
+
325
+ await upgradeCommand(options);
326
+ return;
327
+ }
328
+
329
+ // nimbus init
330
+ if (command === 'init') {
331
+ const options: InitOptions = {};
332
+
333
+ for (let i = 1; i < args.length; i++) {
334
+ const arg = args[i];
335
+
336
+ if (arg === '--force' || arg === '-f') {
337
+ options.force = true;
338
+ } else if ((arg === '--name' || arg === '-n') && args[i + 1]) {
339
+ options.name = args[++i];
340
+ } else if (arg === '--provider' && args[i + 1]) {
341
+ options.provider = args[++i];
342
+ } else if ((arg === '--output' || arg === '-o') && args[i + 1]) {
343
+ options.output = args[++i];
344
+ } else if (arg === '--non-interactive') {
345
+ options.nonInteractive = true;
346
+ }
347
+ }
348
+
349
+ await initCommand(options);
350
+ return;
351
+ }
352
+
353
+ // nimbus serve — headless API server (no auth guard)
354
+ if (command === 'serve') {
355
+ const { serveCommand } = await import('./cli/serve');
356
+ const serveOptions: { port?: number; host?: string; auth?: string } = {};
357
+
358
+ for (let i = 1; i < args.length; i++) {
359
+ const arg = args[i];
360
+
361
+ if ((arg === '--port' || arg === '-p') && args[i + 1]) {
362
+ serveOptions.port = parseInt(args[++i], 10);
363
+ } else if (arg === '--host' && args[i + 1]) {
364
+ serveOptions.host = args[++i];
365
+ } else if (arg === '--auth' && args[i + 1]) {
366
+ serveOptions.auth = args[++i];
367
+ }
368
+ }
369
+
370
+ await serveCommand(serveOptions);
371
+ return;
372
+ }
373
+
374
+ // nimbus web
375
+ if (command === 'web') {
376
+ const { webCommand } = await import('./cli/web');
377
+ await webCommand({
378
+ port: args.includes('--port') ? parseInt(args[args.indexOf('--port') + 1], 10) : undefined,
379
+ host: args.includes('--host') ? args[args.indexOf('--host') + 1] : undefined,
380
+ auth: args.includes('--auth') ? args[args.indexOf('--auth') + 1] : undefined,
381
+ uiUrl: args.includes('--ui-url') ? args[args.indexOf('--ui-url') + 1] : undefined,
382
+ });
383
+ return;
384
+ }
385
+
386
+ // ==========================================
387
+ // Auth guard - check authentication for other commands
388
+ // ==========================================
389
+ // Check if running in non-interactive mode
390
+ const isNonInteractive = args.includes('--non-interactive');
391
+
392
+ if (requiresAuth()) {
393
+ if (isNonInteractive) {
394
+ console.error('');
395
+ console.error('Error: Authentication required but running in non-interactive mode.');
396
+ console.error(
397
+ 'Please run `nimbus login` first, or set provider API keys via environment variables.'
398
+ );
399
+ console.error('');
400
+ process.exit(1);
401
+ }
402
+
403
+ console.log('');
404
+ console.log('Welcome to Nimbus! You need to set up authentication first.');
405
+ console.log('');
406
+
407
+ const success = await loginCommand({});
408
+ if (!success) {
409
+ process.exit(1);
410
+ }
411
+ console.log('');
412
+ }
413
+
414
+ // ==========================================
415
+ // Infrastructure commands (require auth)
416
+ // ==========================================
417
+
418
+ // nimbus run "prompt" [options]
419
+ if (command === 'run') {
420
+ const { parseRunArgs, executeRun } = await import('./cli/run');
421
+ const { getAppContext } = await import('./app');
422
+
423
+ const ctx = getAppContext();
424
+ if (!ctx) {
425
+ console.error('Error: App not initialised.');
426
+ process.exit(1);
427
+ }
428
+
429
+ const runOptions = parseRunArgs(args.slice(1));
430
+ await executeRun(ctx.router, runOptions);
431
+ return;
432
+ }
433
+
434
+ // nimbus generate terraform
435
+ if (command === 'generate' && subcommand === 'terraform') {
436
+ const options: GenerateTerraformOptions = {};
437
+
438
+ for (let i = 2; i < args.length; i++) {
439
+ const arg = args[i];
440
+
441
+ if (arg === '--profile' && args[i + 1]) {
442
+ options.profile = args[++i];
443
+ } else if (arg === '--regions' && args[i + 1]) {
444
+ options.regions = args[++i].split(',');
445
+ } else if (arg === '--services' && args[i + 1]) {
446
+ options.services = args[++i].split(',');
447
+ } else if (arg === '--output' && args[i + 1]) {
448
+ options.output = args[++i];
449
+ } else if (arg === '--non-interactive') {
450
+ options.nonInteractive = true;
451
+ } else if (arg === '--accept-all-improvements') {
452
+ options.acceptAllImprovements = true;
453
+ } else if (arg === '--reject-all-improvements') {
454
+ options.rejectAllImprovements = true;
455
+ } else if (arg === '--mock') {
456
+ options.mock = true;
457
+ }
458
+ }
459
+
460
+ await generateTerraformCommand(options);
461
+ return;
462
+ }
463
+
464
+ // nimbus generate k8s (or nimbus generate-k8s)
465
+ if ((command === 'generate' && subcommand === 'k8s') || command === 'generate-k8s') {
466
+ const options: GenerateK8sOptions = {};
467
+ const startIdx = command === 'generate-k8s' ? 1 : 2;
468
+
469
+ for (let i = startIdx; i < args.length; i++) {
470
+ const arg = args[i];
471
+
472
+ if ((arg === '--workload-type' || arg === '--type') && args[i + 1]) {
473
+ options.workloadType = args[++i] as GenerateK8sOptions['workloadType'];
474
+ } else if ((arg === '--namespace' || arg === '-n') && args[i + 1]) {
475
+ options.namespace = args[++i];
476
+ } else if (arg === '--name' && args[i + 1]) {
477
+ options.name = args[++i];
478
+ } else if (arg === '--image' && args[i + 1]) {
479
+ options.image = args[++i];
480
+ } else if (arg === '--replicas' && args[i + 1]) {
481
+ options.replicas = parseInt(args[++i], 10);
482
+ } else if (arg === '--port' && args[i + 1]) {
483
+ options.port = parseInt(args[++i], 10);
484
+ } else if (arg === '--service-type' && args[i + 1]) {
485
+ options.serviceType = args[++i] as GenerateK8sOptions['serviceType'];
486
+ } else if ((arg === '--output' || arg === '-o') && args[i + 1]) {
487
+ options.output = args[++i];
488
+ } else if (arg === '--non-interactive') {
489
+ options.nonInteractive = true;
490
+ } else if (arg === '--include-ingress') {
491
+ options.includeIngress = true;
492
+ } else if (arg === '--include-hpa') {
493
+ options.includeHpa = true;
494
+ } else if (arg === '--include-pdb') {
495
+ options.includePdb = true;
496
+ } else if (arg === '--include-configmap') {
497
+ options.includeConfigMap = true;
498
+ } else if (arg === '--include-secret') {
499
+ options.includeSecret = true;
500
+ } else if (arg === '--cpu-request' && args[i + 1]) {
501
+ options.cpuRequest = args[++i];
502
+ } else if (arg === '--cpu-limit' && args[i + 1]) {
503
+ options.cpuLimit = args[++i];
504
+ } else if (arg === '--memory-request' && args[i + 1]) {
505
+ options.memoryRequest = args[++i];
506
+ } else if (arg === '--memory-limit' && args[i + 1]) {
507
+ options.memoryLimit = args[++i];
508
+ }
509
+ }
510
+
511
+ await generateK8sCommand(options);
512
+ return;
513
+ }
514
+
515
+ // nimbus generate helm (or nimbus generate-helm)
516
+ if ((command === 'generate' && subcommand === 'helm') || command === 'generate-helm') {
517
+ const options: GenerateHelmOptions = {};
518
+ const startIdx = command === 'generate-helm' ? 1 : 2;
519
+
520
+ for (let i = startIdx; i < args.length; i++) {
521
+ const arg = args[i];
522
+
523
+ if (arg === '--chart' && args[i + 1]) {
524
+ options.chart = args[++i];
525
+ } else if ((arg === '--release' || arg === '--release-name') && args[i + 1]) {
526
+ options.releaseName = args[++i];
527
+ } else if ((arg === '--namespace' || arg === '-n') && args[i + 1]) {
528
+ options.namespace = args[++i];
529
+ } else if ((arg === '--output' || arg === '-o') && args[i + 1]) {
530
+ options.output = args[++i];
531
+ } else if (arg === '--non-interactive') {
532
+ options.nonInteractive = true;
533
+ } else if (arg === '--include-secrets') {
534
+ options.includeSecrets = true;
535
+ } else if (arg === '--no-secrets') {
536
+ options.includeSecrets = false;
537
+ } else if (arg === '--environment' && args[i + 1]) {
538
+ options.environment = args[++i] as GenerateHelmOptions['environment'];
539
+ } else if (arg === '--version' && args[i + 1]) {
540
+ options.version = args[++i];
541
+ } else if (arg === '--repo' && args[i + 1]) {
542
+ options.repo = args[++i];
543
+ } else if (arg === '--values-file' && args[i + 1]) {
544
+ options.valuesFile = args[++i];
545
+ }
546
+ }
547
+
548
+ await generateHelmCommand(options);
549
+ return;
550
+ }
551
+
552
+ // nimbus aws discover
553
+ if (command === 'aws' && subcommand === 'discover') {
554
+ const options: AwsDiscoverOptions = {};
555
+
556
+ for (let i = 2; i < args.length; i++) {
557
+ const arg = args[i];
558
+
559
+ if (arg === '--profile' && args[i + 1]) {
560
+ options.profile = args[++i];
561
+ } else if (arg === '--regions' && args[i + 1]) {
562
+ options.regions = args[++i].split(',');
563
+ } else if (arg === '--services' && args[i + 1]) {
564
+ options.services = args[++i].split(',');
565
+ } else if (arg === '--exclude-services' && args[i + 1]) {
566
+ options.excludeServices = args[++i].split(',');
567
+ } else if (arg === '--output-format' && args[i + 1]) {
568
+ options.outputFormat = args[++i] as 'json' | 'table' | 'summary';
569
+ } else if (arg === '--output-file' && args[i + 1]) {
570
+ options.outputFile = args[++i];
571
+ } else if (arg === '--non-interactive') {
572
+ options.nonInteractive = true;
573
+ }
574
+ }
575
+
576
+ await awsDiscoverCommand(options);
577
+ return;
578
+ }
579
+
580
+ // nimbus aws terraform
581
+ if (command === 'aws' && subcommand === 'terraform') {
582
+ const options: AwsTerraformOptions = {};
583
+
584
+ for (let i = 2; i < args.length; i++) {
585
+ const arg = args[i];
586
+
587
+ if (arg === '--profile' && args[i + 1]) {
588
+ options.profile = args[++i];
589
+ } else if (arg === '--regions' && args[i + 1]) {
590
+ options.regions = args[++i].split(',');
591
+ } else if (arg === '--services' && args[i + 1]) {
592
+ options.services = args[++i].split(',');
593
+ } else if (arg === '--session-id' && args[i + 1]) {
594
+ options.sessionId = args[++i];
595
+ } else if (arg === '--resources-file' && args[i + 1]) {
596
+ options.resourcesFile = args[++i];
597
+ } else if (arg === '--output' && args[i + 1]) {
598
+ options.output = args[++i];
599
+ } else if (arg === '--terraform-version' && args[i + 1]) {
600
+ options.terraformVersion = args[++i];
601
+ } else if (arg === '--organize-by-service') {
602
+ options.organizeByService = true;
603
+ } else if (arg === '--no-organize-by-service') {
604
+ options.organizeByService = false;
605
+ } else if (arg === '--import-blocks') {
606
+ options.importBlocks = true;
607
+ } else if (arg === '--no-import-blocks') {
608
+ options.importBlocks = false;
609
+ } else if (arg === '--import-script') {
610
+ options.importScript = true;
611
+ } else if (arg === '--no-import-script') {
612
+ options.importScript = false;
613
+ } else if (arg === '--starter-kit') {
614
+ options.includeStarterKit = true;
615
+ } else if (arg === '--no-starter-kit') {
616
+ options.includeStarterKit = false;
617
+ } else if (arg === '--non-interactive') {
618
+ options.nonInteractive = true;
619
+ } else if (arg === '--skip-discovery') {
620
+ options.skipDiscovery = true;
621
+ }
622
+ }
623
+
624
+ await awsTerraformCommand(options);
625
+ return;
626
+ }
627
+
628
+ // nimbus aws <service> <action> (catch-all for other AWS subcommands)
629
+ if (command === 'aws' && subcommand && subcommand !== 'discover' && subcommand !== 'terraform') {
630
+ await awsCommand(subcommand, args.slice(2));
631
+ return;
632
+ }
633
+
634
+ // nimbus azure <service> <action>
635
+ if (command === 'azure') {
636
+ if (!subcommand) {
637
+ console.error('Usage: nimbus azure <service> <action>');
638
+ console.log('');
639
+ console.log('Available services:');
640
+ console.log(' vm - Virtual machine operations');
641
+ console.log(' storage - Storage account operations');
642
+ console.log(' aks - Azure Kubernetes Service operations');
643
+ console.log(' functions - Azure Functions operations');
644
+ process.exit(1);
645
+ }
646
+
647
+ await azureCommand(subcommand, args.slice(2));
648
+ return;
649
+ }
650
+
651
+ // nimbus gcp <service> <action>
652
+ if (command === 'gcp') {
653
+ if (!subcommand) {
654
+ console.error('Usage: nimbus gcp <service> <action>');
655
+ console.log('');
656
+ console.log('Available services:');
657
+ console.log(' compute - Compute Engine operations');
658
+ console.log(' storage - Cloud Storage operations');
659
+ console.log(' gke - Google Kubernetes Engine operations');
660
+ console.log(' functions - Cloud Functions operations');
661
+ console.log(' iam - IAM operations');
662
+ process.exit(1);
663
+ }
664
+
665
+ await gcpCommand(subcommand, args.slice(2));
666
+ return;
667
+ }
668
+
669
+ // nimbus cost <subcommand>
670
+ if (command === 'cost') {
671
+ await costCommand(args.slice(1));
672
+ return;
673
+ }
674
+
675
+ // nimbus drift <subcommand>
676
+ if (command === 'drift') {
677
+ await driftCommand(args.slice(1));
678
+ return;
679
+ }
680
+
681
+ // nimbus demo [options]
682
+ if (command === 'demo') {
683
+ const options = parseDemoOptions(args.slice(1));
684
+ await demoCommand(options);
685
+ return;
686
+ }
687
+
688
+ // nimbus feedback [options]
689
+ if (command === 'feedback') {
690
+ const options = parseFeedbackOptions(args.slice(1));
691
+ await feedbackCommand(options);
692
+ return;
693
+ }
694
+
695
+ // nimbus preview <type> [options]
696
+ if (command === 'preview') {
697
+ const options: PreviewOptions = {
698
+ type: (subcommand as PreviewOptions['type']) || 'terraform',
699
+ };
700
+
701
+ for (let i = 2; i < args.length; i++) {
702
+ const arg = args[i];
703
+
704
+ if ((arg === '--directory' || arg === '-d') && args[i + 1]) {
705
+ options.directory = args[++i];
706
+ } else if (arg === '--format' && args[i + 1]) {
707
+ options.format = args[++i] as PreviewOptions['format'];
708
+ } else if (arg === '--verbose' || arg === '-v') {
709
+ options.verbose = true;
710
+ } else if (arg === '--skip-safety') {
711
+ options.skipSafety = true;
712
+ } else if (arg === '--target' && args[i + 1]) {
713
+ options.target = args[++i];
714
+ } else if ((arg === '--namespace' || arg === '-n') && args[i + 1]) {
715
+ options.namespace = args[++i];
716
+ } else if (arg === '--release' && args[i + 1]) {
717
+ options.release = args[++i];
718
+ } else if (arg === '--values-file' && args[i + 1]) {
719
+ options.valuesFile = args[++i];
720
+ }
721
+ }
722
+
723
+ await previewCommand(options);
724
+ return;
725
+ }
726
+
727
+ // nimbus import [options]
728
+ if (command === 'import') {
729
+ const options = parseImportOptions(args.slice(1));
730
+ await importCommand(options);
731
+ return;
732
+ }
733
+
734
+ // nimbus questionnaire <type> [options]
735
+ if (command === 'questionnaire') {
736
+ const options: QuestionnaireOptions = {
737
+ type: (subcommand as QuestionnaireOptions['type']) || 'terraform',
738
+ };
739
+
740
+ for (let i = 2; i < args.length; i++) {
741
+ const arg = args[i];
742
+
743
+ if (arg === '--non-interactive') {
744
+ options.nonInteractive = true;
745
+ } else if (arg === '--answers-file' && args[i + 1]) {
746
+ options.answersFile = args[++i];
747
+ } else if ((arg === '--output' || arg === '-o') && args[i + 1]) {
748
+ options.outputDir = args[++i];
749
+ } else if (arg === '--dry-run') {
750
+ options.dryRun = true;
751
+ }
752
+ }
753
+
754
+ await questionnaireCommand(options);
755
+ return;
756
+ }
757
+
758
+ // nimbus chat
759
+ if (command === 'chat') {
760
+ const options: ChatOptions = {};
761
+
762
+ for (let i = 1; i < args.length; i++) {
763
+ const arg = args[i];
764
+
765
+ if ((arg === '--model' || arg === '-M') && args[i + 1]) {
766
+ options.model = args[++i];
767
+ } else if ((arg === '--message' || arg === '-m') && args[i + 1]) {
768
+ options.message = args[++i];
769
+ options.nonInteractive = true;
770
+ } else if (arg === '--system-prompt' && args[i + 1]) {
771
+ options.systemPrompt = args[++i];
772
+ } else if (arg === '--show-tokens') {
773
+ options.showTokenCount = true;
774
+ } else if (arg === '--non-interactive') {
775
+ options.nonInteractive = true;
776
+ } else if (arg === '--ui' && args[i + 1]) {
777
+ options.ui = args[++i] as ChatOptions['ui'];
778
+ } else if (arg.startsWith('--ui=')) {
779
+ options.ui = arg.slice('--ui='.length) as ChatOptions['ui'];
780
+ } else if (arg === '--continue' || arg === '--resume') {
781
+ options.continue = true;
782
+ }
783
+ }
784
+
785
+ await chatCommand(options);
786
+ return;
787
+ }
788
+
789
+ // nimbus config <subcommand>
790
+ if (command === 'config') {
791
+ const isNonInteractive = args.includes('--non-interactive');
792
+
793
+ // nimbus config set <key> <value>
794
+ if (subcommand === 'set') {
795
+ const options: ConfigSetOptions = { nonInteractive: isNonInteractive };
796
+
797
+ for (let i = 2; i < args.length; i++) {
798
+ const arg = args[i];
799
+ if (!arg.startsWith('-')) {
800
+ if (!options.key) {
801
+ options.key = arg;
802
+ } else if (!options.value) {
803
+ options.value = arg;
804
+ }
805
+ }
806
+ }
807
+
808
+ await configCommand.set(options);
809
+ return;
810
+ }
811
+
812
+ // nimbus config get <key>
813
+ if (subcommand === 'get') {
814
+ const options: ConfigGetOptions = { nonInteractive: isNonInteractive };
815
+
816
+ for (let i = 2; i < args.length; i++) {
817
+ const arg = args[i];
818
+ if (!arg.startsWith('-') && !options.key) {
819
+ options.key = arg;
820
+ }
821
+ }
822
+
823
+ await configCommand.get(options);
824
+ return;
825
+ }
826
+
827
+ // nimbus config list
828
+ if (subcommand === 'list') {
829
+ const options: ConfigListOptions = { nonInteractive: isNonInteractive };
830
+
831
+ for (let i = 2; i < args.length; i++) {
832
+ const arg = args[i];
833
+ if (arg === '--json') {
834
+ options.json = true;
835
+ } else if (arg === '--changed') {
836
+ options.changed = true;
837
+ }
838
+ }
839
+
840
+ await configCommand.list(options);
841
+ return;
842
+ }
843
+
844
+ // nimbus config init
845
+ if (subcommand === 'init') {
846
+ const options: ConfigInitOptions = { nonInteractive: isNonInteractive };
847
+
848
+ for (let i = 2; i < args.length; i++) {
849
+ const arg = args[i];
850
+ if (arg === '--force' || arg === '-f') {
851
+ options.force = true;
852
+ }
853
+ }
854
+
855
+ await configCommand.init(options);
856
+ return;
857
+ }
858
+
859
+ // nimbus config reset
860
+ if (subcommand === 'reset') {
861
+ await configCommand.reset({ nonInteractive: isNonInteractive });
862
+ return;
863
+ }
864
+
865
+ // nimbus config telemetry <enable|disable|status>
866
+ if (subcommand === 'telemetry') {
867
+ const telemetryAction = args[2];
868
+ const fs = await import('node:fs');
869
+ const nodePath = await import('node:path');
870
+ const { homedir } = await import('os');
871
+ const { randomUUID } = await import('crypto');
872
+ const configPath = nodePath.join(homedir(), '.nimbus', 'config.json');
873
+ const configDir = nodePath.join(homedir(), '.nimbus');
874
+
875
+ // Ensure directory exists
876
+ if (!fs.existsSync(configDir)) {
877
+ fs.mkdirSync(configDir, { recursive: true });
878
+ }
879
+
880
+ // Read existing config
881
+ let config: any = {};
882
+ try {
883
+ if (fs.existsSync(configPath)) {
884
+ config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
885
+ }
886
+ } catch {
887
+ /* ignore */
888
+ }
889
+
890
+ if (telemetryAction === 'enable') {
891
+ config.telemetry = {
892
+ ...config.telemetry,
893
+ enabled: true,
894
+ anonymousId: config.telemetry?.anonymousId || randomUUID(),
895
+ };
896
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
897
+ console.log(
898
+ 'Telemetry enabled. Anonymous usage data will be collected to help improve Nimbus.'
899
+ );
900
+ console.log(`Anonymous ID: ${config.telemetry.anonymousId}`);
901
+ return;
902
+ }
903
+
904
+ if (telemetryAction === 'disable') {
905
+ config.telemetry = { ...config.telemetry, enabled: false };
906
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
907
+ console.log('Telemetry disabled. No usage data will be collected.');
908
+ return;
909
+ }
910
+
911
+ if (telemetryAction === 'status' || !telemetryAction) {
912
+ const enabled = config.telemetry?.enabled === true;
913
+ console.log(`Telemetry: ${enabled ? 'enabled' : 'disabled'}`);
914
+ if (config.telemetry?.anonymousId) {
915
+ console.log(`Anonymous ID: ${config.telemetry.anonymousId}`);
916
+ }
917
+ return;
918
+ }
919
+
920
+ console.error(`Unknown telemetry action: ${telemetryAction}`);
921
+ console.log('Usage: nimbus config telemetry <enable|disable|status>');
922
+ process.exit(1);
923
+ }
924
+
925
+ // No subcommand - show list
926
+ if (!subcommand) {
927
+ await configCommand.list({ nonInteractive: isNonInteractive });
928
+ return;
929
+ }
930
+
931
+ console.error(`Unknown config subcommand: ${subcommand}`);
932
+ console.log('');
933
+ console.log('Available config commands:');
934
+ console.log(' nimbus config list - List all configuration');
935
+ console.log(' nimbus config get <key> - Get a configuration value');
936
+ console.log(' nimbus config set <key> <value> - Set a configuration value');
937
+ console.log(' nimbus config init - Initialize configuration interactively');
938
+ console.log(' nimbus config reset - Reset configuration to defaults');
939
+ console.log(' nimbus config telemetry - Manage telemetry settings');
940
+ process.exit(1);
941
+ }
942
+
943
+ // ==========================================
944
+ // Infrastructure tool commands (require auth)
945
+ // ==========================================
946
+
947
+ // nimbus tf <subcommand>
948
+ if (command === 'tf') {
949
+ if (!subcommand) {
950
+ console.error('Usage: nimbus tf <subcommand>');
951
+ console.log('');
952
+ console.log('Available subcommands:');
953
+ console.log(' init - Initialize Terraform working directory');
954
+ console.log(' plan - Generate execution plan');
955
+ console.log(' apply - Apply changes');
956
+ console.log(' validate - Validate configuration');
957
+ console.log(' destroy - Destroy infrastructure');
958
+ console.log(' show - Show state');
959
+ console.log(' fmt - Format configuration files');
960
+ console.log(' workspace - Manage workspaces (list, select, new, delete)');
961
+ console.log(' import - Import existing infrastructure');
962
+ console.log(' output - Show output values');
963
+ process.exit(1);
964
+ }
965
+
966
+ await tfCommand(subcommand, args.slice(2));
967
+ return;
968
+ }
969
+
970
+ // nimbus k8s <subcommand>
971
+ if (command === 'k8s') {
972
+ if (!subcommand) {
973
+ console.error('Usage: nimbus k8s <subcommand>');
974
+ console.log('');
975
+ console.log('Available subcommands:');
976
+ console.log(' get <resource> [name] - Get Kubernetes resources');
977
+ console.log(' apply <manifest> - Apply manifests');
978
+ console.log(' delete <resource> <name> - Delete resources');
979
+ console.log(' logs <pod> - Get pod logs');
980
+ console.log(' describe <resource> <name> - Describe resource');
981
+ console.log(' scale <resource> <name> <replicas> - Scale deployment');
982
+ console.log(' exec <pod> -- <cmd...> - Execute command in pod');
983
+ console.log(' rollout <action> <resource> - Manage rollouts');
984
+ process.exit(1);
985
+ }
986
+
987
+ await k8sCommand(subcommand, args.slice(2));
988
+ return;
989
+ }
990
+
991
+ // nimbus helm <subcommand>
992
+ if (command === 'helm') {
993
+ if (!subcommand) {
994
+ console.error('Usage: nimbus helm <subcommand>');
995
+ console.log('');
996
+ console.log('Available subcommands:');
997
+ console.log(' list - List releases');
998
+ console.log(' install <name> <chart> - Install a chart');
999
+ console.log(' upgrade <name> <chart> - Upgrade a release');
1000
+ console.log(' uninstall <name> - Uninstall a release');
1001
+ console.log(' rollback <name> <rev> - Rollback to revision');
1002
+ console.log(' history <name> - Show release history');
1003
+ console.log(' search <keyword> - Search for charts');
1004
+ console.log(' show <chart> - Show chart information');
1005
+ console.log(' repo add <name> <url> - Add repository');
1006
+ console.log(' repo update - Update repositories');
1007
+ process.exit(1);
1008
+ }
1009
+
1010
+ await helmCommand(subcommand, args.slice(2));
1011
+ return;
1012
+ }
1013
+
1014
+ // nimbus apply <type> [target] [options]
1015
+ if (command === 'apply') {
1016
+ await applyCommand(subcommand, args.slice(2));
1017
+ return;
1018
+ }
1019
+
1020
+ // nimbus ask "<question>" [options]
1021
+ if (command === 'ask') {
1022
+ const options: AskOptions = {};
1023
+ let question = '';
1024
+
1025
+ for (let i = 1; i < args.length; i++) {
1026
+ const arg = args[i];
1027
+
1028
+ if ((arg === '--context' || arg === '-c') && args[i + 1]) {
1029
+ options.context = args[++i];
1030
+ } else if (arg === '--context-file' && args[i + 1]) {
1031
+ options.contextFile = args[++i];
1032
+ } else if (arg === '--model' && args[i + 1]) {
1033
+ options.model = args[++i];
1034
+ } else if (arg === '--json') {
1035
+ options.json = true;
1036
+ } else if (!arg.startsWith('-')) {
1037
+ question = arg;
1038
+ }
1039
+ }
1040
+
1041
+ await askCommand(question, options);
1042
+ return;
1043
+ }
1044
+
1045
+ // nimbus explain <target> [options]
1046
+ if (command === 'explain') {
1047
+ const options: ExplainOptions = {};
1048
+ let target = '';
1049
+
1050
+ for (let i = 1; i < args.length; i++) {
1051
+ const arg = args[i];
1052
+
1053
+ if (arg === '--type' && args[i + 1]) {
1054
+ options.type = args[++i] as ExplainOptions['type'];
1055
+ } else if (arg === '--file' && args[i + 1]) {
1056
+ options.file = args[++i];
1057
+ } else if (arg === '--verbose' || arg === '-v') {
1058
+ options.verbose = true;
1059
+ } else if (arg === '--json') {
1060
+ options.json = true;
1061
+ } else if (!arg.startsWith('-')) {
1062
+ target = arg;
1063
+ }
1064
+ }
1065
+
1066
+ await explainCommand(target, options);
1067
+ return;
1068
+ }
1069
+
1070
+ // nimbus fix <error-or-file> [options]
1071
+ if (command === 'fix') {
1072
+ const options: FixOptions = {};
1073
+ let errorOrFile = '';
1074
+
1075
+ for (let i = 1; i < args.length; i++) {
1076
+ const arg = args[i];
1077
+
1078
+ if (arg === '--file' && args[i + 1]) {
1079
+ options.file = args[++i];
1080
+ } else if (arg === '--auto-apply' || arg === '-y') {
1081
+ options.autoApply = true;
1082
+ } else if (arg === '--dry-run') {
1083
+ options.dryRun = true;
1084
+ } else if (arg === '--json') {
1085
+ options.json = true;
1086
+ } else if (!arg.startsWith('-')) {
1087
+ errorOrFile = arg;
1088
+ }
1089
+ }
1090
+
1091
+ await fixCommand(errorOrFile, options);
1092
+ return;
1093
+ }
1094
+
1095
+ // nimbus plan [options]
1096
+ if (command === 'plan') {
1097
+ const options = parsePlanOptions(args.slice(1));
1098
+ await planCommand(options);
1099
+ return;
1100
+ }
1101
+
1102
+ // nimbus resume <task-id>
1103
+ if (command === 'resume') {
1104
+ const taskId = subcommand;
1105
+ await resumeCommand(taskId || {});
1106
+ return;
1107
+ }
1108
+
1109
+ // nimbus git <subcommand>
1110
+ if (command === 'git') {
1111
+ if (!subcommand) {
1112
+ console.error('Usage: nimbus git <subcommand>');
1113
+ console.log('');
1114
+ console.log('Available subcommands:');
1115
+ console.log(' status - Show git status');
1116
+ console.log(' add <files...> - Stage files');
1117
+ console.log(' commit -m "message" - Create commit');
1118
+ console.log(' push - Push to remote');
1119
+ console.log(' pull - Pull from remote');
1120
+ console.log(' fetch - Fetch from remote');
1121
+ console.log(' log - Show commit log');
1122
+ console.log(' branch - List branches');
1123
+ console.log(' checkout <branch> - Checkout branch');
1124
+ console.log(' diff - Show diff');
1125
+ console.log(' merge <branch> - Merge a branch');
1126
+ console.log(
1127
+ ' stash <action> - Stash operations (push, pop, list, drop, apply, clear)'
1128
+ );
1129
+ process.exit(1);
1130
+ }
1131
+
1132
+ await gitCommand(subcommand, args.slice(2));
1133
+ return;
1134
+ }
1135
+
1136
+ // nimbus fs <subcommand>
1137
+ if (command === 'fs' || command === 'files') {
1138
+ if (!subcommand) {
1139
+ console.error('Usage: nimbus fs <subcommand>');
1140
+ console.log('');
1141
+ console.log('Available subcommands:');
1142
+ console.log(' list [path] - List directory contents');
1143
+ console.log(' tree [path] - List directory contents recursively');
1144
+ console.log(' search <pattern> [path] - Search for files');
1145
+ console.log(' read <file> - Read file contents');
1146
+ console.log(' write <path> <content> - Write content to a file');
1147
+ console.log(' diff <file1> <file2> - Show diff between two files');
1148
+ process.exit(1);
1149
+ }
1150
+
1151
+ await fsCommand(subcommand, args.slice(2));
1152
+ return;
1153
+ }
1154
+
1155
+ // nimbus history
1156
+ if (command === 'history') {
1157
+ // nimbus history show <id>
1158
+ if (subcommand === 'show' && args[2]) {
1159
+ await historyShowCommand(args[2]);
1160
+ return;
1161
+ }
1162
+
1163
+ // nimbus history [options]
1164
+ const options: HistoryOptions = {};
1165
+
1166
+ for (let i = 1; i < args.length; i++) {
1167
+ const arg = args[i];
1168
+
1169
+ if ((arg === '--limit' || arg === '-n') && args[i + 1]) {
1170
+ options.limit = parseInt(args[++i], 10);
1171
+ } else if ((arg === '--filter' || arg === '-f') && args[i + 1]) {
1172
+ options.filter = args[++i];
1173
+ } else if (arg === '--since' && args[i + 1]) {
1174
+ options.since = args[++i];
1175
+ } else if (arg === '--until' && args[i + 1]) {
1176
+ options.until = args[++i];
1177
+ } else if (arg === '--status' && args[i + 1]) {
1178
+ options.status = args[++i] as 'success' | 'failure' | 'pending';
1179
+ } else if (arg === '--json') {
1180
+ options.json = true;
1181
+ } else if (arg === '--clear') {
1182
+ options.clear = true;
1183
+ }
1184
+ }
1185
+
1186
+ await historyCommand(options);
1187
+ return;
1188
+ }
1189
+
1190
+ // nimbus gh <subcommand>
1191
+ if (command === 'gh') {
1192
+ if (!subcommand) {
1193
+ console.error('Usage: nimbus gh <subcommand>');
1194
+ console.log('');
1195
+ console.log('Available subcommands:');
1196
+ console.log(' pr list - List pull requests');
1197
+ console.log(' pr view <number> - View a pull request');
1198
+ console.log(' pr create - Create a pull request');
1199
+ console.log(' pr merge <number> - Merge a pull request');
1200
+ console.log(' issue list - List issues');
1201
+ console.log(' issue view <number> - View an issue');
1202
+ console.log(' issue create - Create an issue');
1203
+ console.log(' issue close <number> - Close an issue');
1204
+ console.log(' issue comment <n> - Add a comment');
1205
+ console.log(' repo info - Show repository info');
1206
+ console.log(' repo branches - List branches');
1207
+ process.exit(1);
1208
+ }
1209
+
1210
+ await ghCommand(subcommand, args.slice(2));
1211
+ return;
1212
+ }
1213
+
1214
+ // ==========================================
1215
+ // Enterprise commands
1216
+ // ==========================================
1217
+
1218
+ // nimbus team <subcommand>
1219
+ if (command === 'team') {
1220
+ await teamCommand(subcommand || '', args.slice(2));
1221
+ return;
1222
+ }
1223
+
1224
+ // nimbus billing <subcommand>
1225
+ if (command === 'billing') {
1226
+ await billingCommand(subcommand || '', args.slice(2));
1227
+ return;
1228
+ }
1229
+
1230
+ // nimbus usage
1231
+ if (command === 'usage') {
1232
+ await usageCommand(parseUsageOptions(args.slice(1)));
1233
+ return;
1234
+ }
1235
+
1236
+ // nimbus audit <subcommand>
1237
+ if (command === 'audit') {
1238
+ await auditCommand(subcommand || '', args.slice(2));
1239
+ return;
1240
+ }
1241
+
1242
+ // nimbus analyze
1243
+ if (command === 'analyze') {
1244
+ await analyzeCommand(parseAnalyzeOptions(args.slice(1)));
1245
+ return;
1246
+ }
1247
+
1248
+ // nimbus template <subcommand>
1249
+ if (command === 'template') {
1250
+ if (!subcommand) {
1251
+ console.error('Usage: nimbus template <subcommand>');
1252
+ console.log('');
1253
+ console.log('Available subcommands:');
1254
+ console.log(' list - List all templates');
1255
+ console.log(' get <id> - Get template details');
1256
+ console.log(' save --name <n> [--file] - Save a new template');
1257
+ console.log(' delete <id> - Delete a template');
1258
+ process.exit(1);
1259
+ }
1260
+
1261
+ await templateCommand(subcommand, args.slice(2));
1262
+ return;
1263
+ }
1264
+
1265
+ // nimbus auth-profile <subcommand>
1266
+ if (command === 'auth-profile') {
1267
+ if (!subcommand) {
1268
+ console.error('Usage: nimbus auth-profile <subcommand>');
1269
+ console.log('');
1270
+ console.log('Available subcommands:');
1271
+ console.log(' list - List configured providers');
1272
+ console.log(' show - Show current default provider');
1273
+ console.log(' switch <provider> - Switch default provider');
1274
+ process.exit(1);
1275
+ }
1276
+
1277
+ await authProfileCommand(subcommand, args.slice(2));
1278
+ return;
1279
+ }
1280
+
1281
+ // Unknown command
1282
+ console.error(`Unknown command: ${command} ${subcommand || ''}`);
1283
+ console.log('');
1284
+ console.log('Available commands:');
1285
+ console.log('');
1286
+ console.log(' Chat & AI:');
1287
+ console.log(' nimbus chat - Start interactive chat with AI');
1288
+ console.log(' nimbus chat -m "..." - Send a single message');
1289
+ console.log(' nimbus run "prompt" - Non-interactive agent run with tools');
1290
+ console.log(' nimbus ask "question" - Quick question/answer');
1291
+ console.log(' nimbus explain <file> - Explain code or infrastructure');
1292
+ console.log(' nimbus fix <error> - AI-assisted error fixing');
1293
+ console.log('');
1294
+ console.log(' Workspace:');
1295
+ console.log(' nimbus init - Initialize workspace in current directory');
1296
+ console.log('');
1297
+ console.log(' Configuration:');
1298
+ console.log(' nimbus config - List all configuration');
1299
+ console.log(' nimbus config set <k> <v> - Set a configuration value');
1300
+ console.log(' nimbus config get <key> - Get a configuration value');
1301
+ console.log(' nimbus config init - Initialize global configuration');
1302
+ console.log(' nimbus config telemetry - Manage telemetry (enable|disable|status)');
1303
+ console.log('');
1304
+ console.log(' Authentication:');
1305
+ console.log(' nimbus login - Set up authentication and LLM providers');
1306
+ console.log(' nimbus logout - Clear all credentials');
1307
+ console.log(' nimbus auth status - Show current authentication status');
1308
+ console.log(' nimbus auth list - List all available providers');
1309
+ console.log('');
1310
+ console.log(' Infrastructure Generation:');
1311
+ console.log(
1312
+ ' nimbus generate terraform - Generate Terraform from AWS infrastructure (wizard)'
1313
+ );
1314
+ console.log(' nimbus generate k8s - Generate Kubernetes manifests (wizard)');
1315
+ console.log(' nimbus generate helm - Generate Helm values files (wizard)');
1316
+ console.log(' nimbus aws discover - Discover AWS infrastructure resources');
1317
+ console.log(' nimbus aws terraform - Generate Terraform from AWS resources');
1318
+ console.log('');
1319
+ console.log(' Cloud Providers:');
1320
+ console.log(
1321
+ ' nimbus aws <service> <action> - AWS operations (ec2, s3, rds, lambda, iam, vpc)'
1322
+ );
1323
+ console.log(
1324
+ ' nimbus azure <service> <action> - Azure operations (vm, storage, aks, functions)'
1325
+ );
1326
+ console.log(
1327
+ ' nimbus gcp <service> <action> - GCP operations (compute, storage, gke, functions, iam)'
1328
+ );
1329
+ console.log(' nimbus auth aws|gcp|azure - Validate cloud credentials');
1330
+ console.log('');
1331
+ console.log(' Infrastructure Management:');
1332
+ console.log(' nimbus cost estimate - Estimate infrastructure costs');
1333
+ console.log(' nimbus cost history - View cost history');
1334
+ console.log(' nimbus drift detect - Detect infrastructure drift');
1335
+ console.log(' nimbus drift fix - Remediate drift');
1336
+ console.log(' nimbus preview <type> - Preview infrastructure changes');
1337
+ console.log(' nimbus import - Import existing cloud resources');
1338
+ console.log('');
1339
+ console.log(' Infrastructure Tools:');
1340
+ console.log(' nimbus plan - Preview infrastructure changes');
1341
+ console.log(' nimbus apply <type> - Apply infrastructure (terraform, k8s, helm)');
1342
+ console.log(' nimbus resume <task-id> - Resume a task from its last checkpoint');
1343
+ console.log(
1344
+ ' nimbus tf <cmd> - Terraform operations (init, plan, apply, validate, destroy, show, fmt, workspace, import, output)'
1345
+ );
1346
+ console.log(
1347
+ ' nimbus k8s <cmd> - Kubernetes operations (get, apply, delete, logs, describe, scale, exec, rollout)'
1348
+ );
1349
+ console.log(
1350
+ ' nimbus helm <cmd> - Helm operations (list, install, upgrade, uninstall, rollback, show)'
1351
+ );
1352
+ console.log(
1353
+ ' nimbus git <cmd> - Git operations (status, add, commit, push, pull, fetch, log, merge, stash)'
1354
+ );
1355
+ console.log(
1356
+ ' nimbus fs <cmd> - File system operations (list, search, read, write, diff)'
1357
+ );
1358
+ console.log('');
1359
+ console.log(' Wizards & Tools:');
1360
+ console.log(' nimbus questionnaire <type> - Interactive infrastructure questionnaire');
1361
+ console.log(' nimbus demo - Run demo scenarios');
1362
+ console.log(' nimbus feedback - Submit feedback');
1363
+ console.log('');
1364
+ console.log(' GitHub:');
1365
+ console.log(' nimbus gh pr <cmd> - PR operations (list, view, create, merge)');
1366
+ console.log(
1367
+ ' nimbus gh issue <cmd> - Issue operations (list, view, create, close, comment)'
1368
+ );
1369
+ console.log(' nimbus gh repo <cmd> - Repo operations (info, branches)');
1370
+ console.log('');
1371
+ console.log(' Aliases:');
1372
+ console.log(' nimbus terraform <cmd> - Alias for nimbus tf <cmd>');
1373
+ console.log(' nimbus k <cmd> - Alias for nimbus k8s <cmd>');
1374
+ console.log(' nimbus g <type> - Alias for nimbus generate <type>');
1375
+ console.log(' nimbus h <cmd> - Alias for nimbus helm <cmd>');
1376
+ console.log(' nimbus pr <cmd> - Alias for nimbus gh pr <cmd>');
1377
+ console.log(' nimbus issue <cmd> - Alias for nimbus gh issue <cmd>');
1378
+ console.log(' nimbus read <file> - Alias for nimbus fs read <file>');
1379
+ console.log(' nimbus tree [path] - Alias for nimbus fs tree [path]');
1380
+ console.log(' nimbus search <pattern> - Alias for nimbus fs search <pattern>');
1381
+ console.log(' nimbus write <path> <c> - Alias for nimbus fs write <path> <content>');
1382
+ console.log('');
1383
+ console.log(' History:');
1384
+ console.log(' nimbus history - View command history');
1385
+ console.log(' nimbus history show <id> - Show details for a history entry');
1386
+ console.log(' nimbus history --clear - Clear all history');
1387
+ console.log('');
1388
+ console.log(' Team & Enterprise:');
1389
+ console.log(' nimbus team create <name> - Create a team');
1390
+ console.log(' nimbus team invite <email> - Invite a member');
1391
+ console.log(' nimbus team members - List team members');
1392
+ console.log(' nimbus team switch - Switch active team');
1393
+ console.log(' nimbus billing status - View billing status');
1394
+ console.log(' nimbus billing upgrade - Upgrade plan');
1395
+ console.log(' nimbus usage - View usage dashboard');
1396
+ console.log(' nimbus audit - View audit logs');
1397
+ console.log('');
1398
+ console.log(' Analysis:');
1399
+ console.log(' nimbus analyze - Analyze codebase for improvements');
1400
+ console.log('');
1401
+ console.log(' Server:');
1402
+ console.log(' nimbus serve - Start headless API server (default port 4200)');
1403
+ console.log(' nimbus serve --port 8080 - Start on custom port');
1404
+ console.log(' nimbus serve --host 0.0.0.0 - Bind to all interfaces');
1405
+ console.log(' nimbus serve --auth u:p - Enable HTTP Basic Auth');
1406
+ console.log(' nimbus web [--port N] [--ui-url URL] - Start API server and open Web UI');
1407
+ console.log('');
1408
+ console.log(' Utilities:');
1409
+ console.log(' nimbus version - Show version information');
1410
+ console.log(' nimbus help - Show this help message');
1411
+ console.log(' nimbus help <command> - Show help for a specific command');
1412
+ console.log(' nimbus doctor - Run diagnostic checks');
1413
+ console.log(' nimbus upgrade - Check for and install updates');
1414
+ console.log('');
1415
+ console.log('Use --help with any command for more options');
1416
+ process.exit(1);
1417
+ }