@build-astron-co/nimbus 0.4.1 → 0.4.3

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 (435) hide show
  1. package/CHANGELOG.md +268 -89
  2. package/README.md +26 -567
  3. package/dist/src/agent/compaction-agent.js +24 -12
  4. package/dist/src/agent/context-manager.js +2 -1
  5. package/dist/src/agent/expand-files.js +2 -1
  6. package/dist/src/agent/loop.js +71 -33
  7. package/dist/src/agent/permissions.js +4 -2
  8. package/dist/src/agent/system-prompt.js +34 -17
  9. package/dist/src/app.js +1 -1
  10. package/dist/src/auth/keychain.js +8 -4
  11. package/dist/src/auth/store.js +70 -107
  12. package/dist/src/cli/init.js +35 -19
  13. package/dist/src/cli/run.js +18 -10
  14. package/dist/src/cli/serve.js +4 -2
  15. package/dist/src/cli.js +52 -11
  16. package/dist/src/commands/alias.js +5 -3
  17. package/dist/src/commands/audit/index.js +2 -1
  18. package/dist/src/commands/aws-terraform.js +36 -18
  19. package/dist/src/commands/completions.js +1 -1
  20. package/dist/src/commands/config.js +3 -2
  21. package/dist/src/commands/connect-github.js +92 -0
  22. package/dist/src/commands/cost/index.js +3 -2
  23. package/dist/src/commands/deploy.js +15 -10
  24. package/dist/src/commands/doctor.js +9 -6
  25. package/dist/src/commands/drift/index.js +2 -1
  26. package/dist/src/commands/export.js +5 -3
  27. package/dist/src/commands/generate-terraform.js +110 -2
  28. package/dist/src/commands/import.js +3 -3
  29. package/dist/src/commands/incident.js +10 -5
  30. package/dist/src/commands/login.js +8 -93
  31. package/dist/src/commands/logs.js +16 -8
  32. package/dist/src/commands/onboarding.js +6 -4
  33. package/dist/src/commands/pipeline.js +6 -3
  34. package/dist/src/commands/plugin.js +3 -2
  35. package/dist/src/commands/profile.js +27 -14
  36. package/dist/src/commands/questionnaire.js +1 -1
  37. package/dist/src/commands/rollback.js +3 -2
  38. package/dist/src/commands/rollout.js +5 -3
  39. package/dist/src/commands/runbook.js +17 -10
  40. package/dist/src/commands/schedule.js +10 -5
  41. package/dist/src/commands/status.js +2 -1
  42. package/dist/src/commands/team-context.js +12 -7
  43. package/dist/src/commands/template.js +1 -1
  44. package/dist/src/commands/tf/index.js +6 -3
  45. package/dist/src/commands/upgrade.js +5 -3
  46. package/dist/src/commands/version.js +6 -3
  47. package/dist/src/commands/watch.js +6 -3
  48. package/dist/src/compat/sqlite.js +5 -3
  49. package/dist/src/config/mode-store.js +2 -1
  50. package/dist/src/config/profiles.js +4 -2
  51. package/dist/src/config/types.js +2 -1
  52. package/dist/src/engine/executor.js +8 -4
  53. package/dist/src/engine/planner.js +9 -5
  54. package/dist/src/llm/providers/anthropic.js +6 -3
  55. package/dist/src/llm/providers/ollama.js +1 -1
  56. package/dist/src/llm/router.js +22 -7
  57. package/dist/src/nimbus.js +1 -0
  58. package/dist/src/sessions/manager.js +6 -3
  59. package/dist/src/sharing/viewer.js +2 -1
  60. package/dist/src/tools/file-ops.js +1 -2
  61. package/dist/src/tools/schemas/devops.js +197 -108
  62. package/dist/src/tools/schemas/standard.js +1 -1
  63. package/dist/src/ui/App.js +25 -13
  64. package/dist/src/ui/FileDiffModal.js +22 -11
  65. package/dist/src/ui/HelpModal.js +2 -1
  66. package/dist/src/ui/InputBox.js +6 -3
  67. package/dist/src/ui/MessageList.js +40 -20
  68. package/dist/src/ui/TerminalPane.js +2 -1
  69. package/dist/src/ui/ToolCallDisplay.js +12 -6
  70. package/dist/src/ui/TreePane.js +2 -1
  71. package/dist/src/ui/ink/index.js +37 -21
  72. package/dist/src/version.js +1 -1
  73. package/dist/src/watcher/index.js +8 -4
  74. package/package.json +3 -5
  75. package/src/__tests__/alias.test.ts +0 -133
  76. package/src/__tests__/app.test.ts +0 -76
  77. package/src/__tests__/audit.test.ts +0 -877
  78. package/src/__tests__/circuit-breaker.test.ts +0 -116
  79. package/src/__tests__/cli-run.test.ts +0 -351
  80. package/src/__tests__/compat-sqlite.test.ts +0 -68
  81. package/src/__tests__/context-manager.test.ts +0 -632
  82. package/src/__tests__/context.test.ts +0 -242
  83. package/src/__tests__/devops-terminal-gaps.test.ts +0 -718
  84. package/src/__tests__/doctor.test.ts +0 -48
  85. package/src/__tests__/enterprise.test.ts +0 -401
  86. package/src/__tests__/export.test.ts +0 -236
  87. package/src/__tests__/gap-11-18-20.test.ts +0 -958
  88. package/src/__tests__/generator.test.ts +0 -433
  89. package/src/__tests__/helm-streaming.test.ts +0 -127
  90. package/src/__tests__/hooks.test.ts +0 -582
  91. package/src/__tests__/incident.test.ts +0 -179
  92. package/src/__tests__/init.test.ts +0 -487
  93. package/src/__tests__/intent-parser.test.ts +0 -229
  94. package/src/__tests__/llm-router.test.ts +0 -209
  95. package/src/__tests__/logs.test.ts +0 -107
  96. package/src/__tests__/loop-errors.test.ts +0 -244
  97. package/src/__tests__/lsp.test.ts +0 -293
  98. package/src/__tests__/modes.test.ts +0 -336
  99. package/src/__tests__/perf-optimizations.test.ts +0 -847
  100. package/src/__tests__/permissions.test.ts +0 -338
  101. package/src/__tests__/pipeline.test.ts +0 -50
  102. package/src/__tests__/polish-phase3.test.ts +0 -340
  103. package/src/__tests__/profile.test.ts +0 -237
  104. package/src/__tests__/rollback.test.ts +0 -83
  105. package/src/__tests__/runbook.test.ts +0 -219
  106. package/src/__tests__/schedule.test.ts +0 -206
  107. package/src/__tests__/serve.test.ts +0 -275
  108. package/src/__tests__/sessions.test.ts +0 -322
  109. package/src/__tests__/sharing.test.ts +0 -340
  110. package/src/__tests__/snapshots.test.ts +0 -581
  111. package/src/__tests__/standalone-migration.test.ts +0 -199
  112. package/src/__tests__/state-db.test.ts +0 -334
  113. package/src/__tests__/status.test.ts +0 -158
  114. package/src/__tests__/stream-with-tools.test.ts +0 -778
  115. package/src/__tests__/subagents.test.ts +0 -176
  116. package/src/__tests__/system-prompt.test.ts +0 -248
  117. package/src/__tests__/terminal-gap-v2.test.ts +0 -395
  118. package/src/__tests__/terminal-parity.test.ts +0 -393
  119. package/src/__tests__/tf-apply.test.ts +0 -187
  120. package/src/__tests__/tool-converter.test.ts +0 -256
  121. package/src/__tests__/tool-schemas.test.ts +0 -602
  122. package/src/__tests__/tools.test.ts +0 -144
  123. package/src/__tests__/version-json.test.ts +0 -184
  124. package/src/__tests__/version.test.ts +0 -49
  125. package/src/__tests__/watch.test.ts +0 -129
  126. package/src/agent/compaction-agent.ts +0 -266
  127. package/src/agent/context-manager.ts +0 -499
  128. package/src/agent/context.ts +0 -427
  129. package/src/agent/deploy-preview.ts +0 -487
  130. package/src/agent/expand-files.ts +0 -108
  131. package/src/agent/index.ts +0 -68
  132. package/src/agent/loop.ts +0 -1998
  133. package/src/agent/modes.ts +0 -429
  134. package/src/agent/permissions.ts +0 -513
  135. package/src/agent/subagents/base.ts +0 -116
  136. package/src/agent/subagents/cost.ts +0 -51
  137. package/src/agent/subagents/explore.ts +0 -42
  138. package/src/agent/subagents/general.ts +0 -54
  139. package/src/agent/subagents/index.ts +0 -102
  140. package/src/agent/subagents/infra.ts +0 -59
  141. package/src/agent/subagents/security.ts +0 -69
  142. package/src/agent/system-prompt.ts +0 -990
  143. package/src/app.ts +0 -180
  144. package/src/audit/activity-log.ts +0 -290
  145. package/src/audit/compliance-checker.ts +0 -540
  146. package/src/audit/cost-tracker.ts +0 -318
  147. package/src/audit/index.ts +0 -23
  148. package/src/audit/security-scanner.ts +0 -641
  149. package/src/auth/guard.ts +0 -75
  150. package/src/auth/index.ts +0 -56
  151. package/src/auth/keychain.ts +0 -82
  152. package/src/auth/oauth.ts +0 -465
  153. package/src/auth/providers.ts +0 -470
  154. package/src/auth/sso.ts +0 -113
  155. package/src/auth/store.ts +0 -505
  156. package/src/auth/types.ts +0 -187
  157. package/src/build.ts +0 -141
  158. package/src/cli/index.ts +0 -16
  159. package/src/cli/init.ts +0 -1227
  160. package/src/cli/openapi-spec.ts +0 -356
  161. package/src/cli/run.ts +0 -628
  162. package/src/cli/serve-auth.ts +0 -80
  163. package/src/cli/serve.ts +0 -539
  164. package/src/cli/web.ts +0 -71
  165. package/src/cli.ts +0 -1728
  166. package/src/clients/core-engine-client.ts +0 -227
  167. package/src/clients/enterprise-client.ts +0 -334
  168. package/src/clients/generator-client.ts +0 -351
  169. package/src/clients/git-client.ts +0 -627
  170. package/src/clients/github-client.ts +0 -410
  171. package/src/clients/helm-client.ts +0 -504
  172. package/src/clients/index.ts +0 -80
  173. package/src/clients/k8s-client.ts +0 -497
  174. package/src/clients/llm-client.ts +0 -161
  175. package/src/clients/rest-client.ts +0 -130
  176. package/src/clients/service-discovery.ts +0 -38
  177. package/src/clients/terraform-client.ts +0 -482
  178. package/src/clients/tools-client.ts +0 -1843
  179. package/src/clients/ws-client.ts +0 -115
  180. package/src/commands/alias.ts +0 -100
  181. package/src/commands/analyze/index.ts +0 -352
  182. package/src/commands/apply/helm.ts +0 -473
  183. package/src/commands/apply/index.ts +0 -213
  184. package/src/commands/apply/k8s.ts +0 -454
  185. package/src/commands/apply/terraform.ts +0 -582
  186. package/src/commands/ask.ts +0 -167
  187. package/src/commands/audit/index.ts +0 -357
  188. package/src/commands/auth-cloud.ts +0 -407
  189. package/src/commands/auth-list.ts +0 -134
  190. package/src/commands/auth-profile.ts +0 -121
  191. package/src/commands/auth-refresh.ts +0 -187
  192. package/src/commands/auth-status.ts +0 -141
  193. package/src/commands/aws/ec2.ts +0 -501
  194. package/src/commands/aws/iam.ts +0 -397
  195. package/src/commands/aws/index.ts +0 -133
  196. package/src/commands/aws/lambda.ts +0 -396
  197. package/src/commands/aws/rds.ts +0 -439
  198. package/src/commands/aws/s3.ts +0 -439
  199. package/src/commands/aws/vpc.ts +0 -393
  200. package/src/commands/aws-discover.ts +0 -542
  201. package/src/commands/aws-terraform.ts +0 -755
  202. package/src/commands/azure/aks.ts +0 -376
  203. package/src/commands/azure/functions.ts +0 -253
  204. package/src/commands/azure/index.ts +0 -116
  205. package/src/commands/azure/storage.ts +0 -478
  206. package/src/commands/azure/vm.ts +0 -355
  207. package/src/commands/billing/index.ts +0 -256
  208. package/src/commands/chat.ts +0 -320
  209. package/src/commands/completions.ts +0 -268
  210. package/src/commands/config.ts +0 -372
  211. package/src/commands/cost/cloud-cost-estimator.ts +0 -266
  212. package/src/commands/cost/estimator.ts +0 -79
  213. package/src/commands/cost/index.ts +0 -810
  214. package/src/commands/cost/parsers/terraform.ts +0 -273
  215. package/src/commands/cost/parsers/types.ts +0 -25
  216. package/src/commands/cost/pricing/aws.ts +0 -544
  217. package/src/commands/cost/pricing/azure.ts +0 -499
  218. package/src/commands/cost/pricing/gcp.ts +0 -396
  219. package/src/commands/cost/pricing/index.ts +0 -40
  220. package/src/commands/demo.ts +0 -250
  221. package/src/commands/deploy.ts +0 -260
  222. package/src/commands/doctor.ts +0 -1386
  223. package/src/commands/drift/index.ts +0 -787
  224. package/src/commands/explain.ts +0 -277
  225. package/src/commands/export.ts +0 -146
  226. package/src/commands/feedback.ts +0 -389
  227. package/src/commands/fix.ts +0 -324
  228. package/src/commands/fs/index.ts +0 -402
  229. package/src/commands/gcp/compute.ts +0 -325
  230. package/src/commands/gcp/functions.ts +0 -271
  231. package/src/commands/gcp/gke.ts +0 -438
  232. package/src/commands/gcp/iam.ts +0 -344
  233. package/src/commands/gcp/index.ts +0 -129
  234. package/src/commands/gcp/storage.ts +0 -284
  235. package/src/commands/generate-helm.ts +0 -1249
  236. package/src/commands/generate-k8s.ts +0 -1508
  237. package/src/commands/generate-terraform.ts +0 -1202
  238. package/src/commands/gh/index.ts +0 -863
  239. package/src/commands/git/index.ts +0 -1343
  240. package/src/commands/helm/index.ts +0 -1126
  241. package/src/commands/help.ts +0 -715
  242. package/src/commands/history.ts +0 -149
  243. package/src/commands/import.ts +0 -868
  244. package/src/commands/incident.ts +0 -166
  245. package/src/commands/index.ts +0 -367
  246. package/src/commands/init.ts +0 -1051
  247. package/src/commands/k8s/index.ts +0 -1137
  248. package/src/commands/login.ts +0 -716
  249. package/src/commands/logout.ts +0 -83
  250. package/src/commands/logs.ts +0 -167
  251. package/src/commands/onboarding.ts +0 -405
  252. package/src/commands/pipeline.ts +0 -186
  253. package/src/commands/plan/display.ts +0 -279
  254. package/src/commands/plan/index.ts +0 -599
  255. package/src/commands/plugin.ts +0 -398
  256. package/src/commands/preview.ts +0 -452
  257. package/src/commands/profile.ts +0 -342
  258. package/src/commands/questionnaire.ts +0 -1172
  259. package/src/commands/resume.ts +0 -47
  260. package/src/commands/rollback.ts +0 -315
  261. package/src/commands/rollout.ts +0 -88
  262. package/src/commands/runbook.ts +0 -346
  263. package/src/commands/schedule.ts +0 -236
  264. package/src/commands/status.ts +0 -252
  265. package/src/commands/team/index.ts +0 -346
  266. package/src/commands/team-context.ts +0 -220
  267. package/src/commands/template.ts +0 -233
  268. package/src/commands/tf/index.ts +0 -1093
  269. package/src/commands/upgrade.ts +0 -607
  270. package/src/commands/usage/index.ts +0 -134
  271. package/src/commands/version.ts +0 -174
  272. package/src/commands/watch.ts +0 -153
  273. package/src/compat/index.ts +0 -2
  274. package/src/compat/runtime.ts +0 -12
  275. package/src/compat/sqlite.ts +0 -177
  276. package/src/config/index.ts +0 -17
  277. package/src/config/manager.ts +0 -530
  278. package/src/config/mode-store.ts +0 -62
  279. package/src/config/profiles.ts +0 -84
  280. package/src/config/safety-policy.ts +0 -358
  281. package/src/config/schema.ts +0 -125
  282. package/src/config/types.ts +0 -609
  283. package/src/config/workspace-state.ts +0 -53
  284. package/src/context/context-db.ts +0 -199
  285. package/src/demo/index.ts +0 -349
  286. package/src/demo/scenarios/full-journey.ts +0 -229
  287. package/src/demo/scenarios/getting-started.ts +0 -127
  288. package/src/demo/scenarios/helm-release.ts +0 -341
  289. package/src/demo/scenarios/k8s-deployment.ts +0 -194
  290. package/src/demo/scenarios/terraform-vpc.ts +0 -170
  291. package/src/demo/types.ts +0 -92
  292. package/src/engine/cost-estimator.ts +0 -480
  293. package/src/engine/diagram-generator.ts +0 -256
  294. package/src/engine/drift-detector.ts +0 -902
  295. package/src/engine/executor.ts +0 -1066
  296. package/src/engine/index.ts +0 -76
  297. package/src/engine/orchestrator.ts +0 -636
  298. package/src/engine/planner.ts +0 -787
  299. package/src/engine/safety.ts +0 -743
  300. package/src/engine/verifier.ts +0 -770
  301. package/src/enterprise/audit.ts +0 -348
  302. package/src/enterprise/auth.ts +0 -270
  303. package/src/enterprise/billing.ts +0 -822
  304. package/src/enterprise/index.ts +0 -17
  305. package/src/enterprise/teams.ts +0 -443
  306. package/src/generator/best-practices.ts +0 -1608
  307. package/src/generator/helm.ts +0 -630
  308. package/src/generator/index.ts +0 -37
  309. package/src/generator/intent-parser.ts +0 -514
  310. package/src/generator/kubernetes.ts +0 -976
  311. package/src/generator/terraform.ts +0 -1875
  312. package/src/history/index.ts +0 -8
  313. package/src/history/manager.ts +0 -250
  314. package/src/history/types.ts +0 -34
  315. package/src/hooks/config.ts +0 -432
  316. package/src/hooks/engine.ts +0 -392
  317. package/src/hooks/index.ts +0 -4
  318. package/src/llm/auth-bridge.ts +0 -198
  319. package/src/llm/circuit-breaker.ts +0 -140
  320. package/src/llm/config-loader.ts +0 -201
  321. package/src/llm/cost-calculator.ts +0 -171
  322. package/src/llm/index.ts +0 -8
  323. package/src/llm/model-aliases.ts +0 -115
  324. package/src/llm/provider-registry.ts +0 -63
  325. package/src/llm/providers/anthropic.ts +0 -462
  326. package/src/llm/providers/bedrock.ts +0 -477
  327. package/src/llm/providers/google.ts +0 -405
  328. package/src/llm/providers/ollama.ts +0 -767
  329. package/src/llm/providers/openai-compatible.ts +0 -340
  330. package/src/llm/providers/openai.ts +0 -328
  331. package/src/llm/providers/openrouter.ts +0 -338
  332. package/src/llm/router.ts +0 -1104
  333. package/src/llm/types.ts +0 -232
  334. package/src/lsp/client.ts +0 -298
  335. package/src/lsp/languages.ts +0 -119
  336. package/src/lsp/manager.ts +0 -294
  337. package/src/mcp/client.ts +0 -402
  338. package/src/mcp/index.ts +0 -5
  339. package/src/mcp/manager.ts +0 -133
  340. package/src/nimbus.ts +0 -233
  341. package/src/plugins/index.ts +0 -27
  342. package/src/plugins/loader.ts +0 -334
  343. package/src/plugins/manager.ts +0 -376
  344. package/src/plugins/types.ts +0 -284
  345. package/src/scanners/cicd-scanner.ts +0 -258
  346. package/src/scanners/cloud-scanner.ts +0 -466
  347. package/src/scanners/framework-scanner.ts +0 -469
  348. package/src/scanners/iac-scanner.ts +0 -388
  349. package/src/scanners/index.ts +0 -539
  350. package/src/scanners/language-scanner.ts +0 -276
  351. package/src/scanners/package-manager-scanner.ts +0 -277
  352. package/src/scanners/types.ts +0 -172
  353. package/src/sessions/manager.ts +0 -472
  354. package/src/sessions/types.ts +0 -44
  355. package/src/sharing/sync.ts +0 -300
  356. package/src/sharing/viewer.ts +0 -163
  357. package/src/snapshots/index.ts +0 -2
  358. package/src/snapshots/manager.ts +0 -530
  359. package/src/state/artifacts.ts +0 -147
  360. package/src/state/audit.ts +0 -137
  361. package/src/state/billing.ts +0 -240
  362. package/src/state/checkpoints.ts +0 -117
  363. package/src/state/config.ts +0 -67
  364. package/src/state/conversations.ts +0 -14
  365. package/src/state/credentials.ts +0 -154
  366. package/src/state/db.ts +0 -58
  367. package/src/state/index.ts +0 -26
  368. package/src/state/messages.ts +0 -115
  369. package/src/state/projects.ts +0 -123
  370. package/src/state/schema.ts +0 -236
  371. package/src/state/sessions.ts +0 -147
  372. package/src/state/teams.ts +0 -200
  373. package/src/telemetry.ts +0 -108
  374. package/src/tools/aws-ops.ts +0 -952
  375. package/src/tools/azure-ops.ts +0 -579
  376. package/src/tools/file-ops.ts +0 -615
  377. package/src/tools/gcp-ops.ts +0 -625
  378. package/src/tools/git-ops.ts +0 -773
  379. package/src/tools/github-ops.ts +0 -799
  380. package/src/tools/helm-ops.ts +0 -943
  381. package/src/tools/index.ts +0 -17
  382. package/src/tools/k8s-ops.ts +0 -819
  383. package/src/tools/schemas/converter.ts +0 -184
  384. package/src/tools/schemas/devops.ts +0 -3502
  385. package/src/tools/schemas/index.ts +0 -73
  386. package/src/tools/schemas/standard.ts +0 -1148
  387. package/src/tools/schemas/types.ts +0 -735
  388. package/src/tools/spawn-exec.ts +0 -148
  389. package/src/tools/terraform-ops.ts +0 -862
  390. package/src/types/ambient.d.ts +0 -193
  391. package/src/types/config.ts +0 -83
  392. package/src/types/drift.ts +0 -116
  393. package/src/types/enterprise.ts +0 -335
  394. package/src/types/index.ts +0 -20
  395. package/src/types/plan.ts +0 -44
  396. package/src/types/request.ts +0 -65
  397. package/src/types/response.ts +0 -54
  398. package/src/types/service.ts +0 -51
  399. package/src/ui/App.tsx +0 -2114
  400. package/src/ui/DeployPreview.tsx +0 -174
  401. package/src/ui/FileDiffModal.tsx +0 -162
  402. package/src/ui/Header.tsx +0 -131
  403. package/src/ui/HelpModal.tsx +0 -57
  404. package/src/ui/InputBox.tsx +0 -503
  405. package/src/ui/MessageList.tsx +0 -1032
  406. package/src/ui/PermissionPrompt.tsx +0 -163
  407. package/src/ui/StatusBar.tsx +0 -277
  408. package/src/ui/TerminalPane.tsx +0 -84
  409. package/src/ui/ToolCallDisplay.tsx +0 -643
  410. package/src/ui/TreePane.tsx +0 -132
  411. package/src/ui/chat-ui.ts +0 -850
  412. package/src/ui/index.ts +0 -33
  413. package/src/ui/ink/index.ts +0 -1444
  414. package/src/ui/streaming.ts +0 -176
  415. package/src/ui/theme.ts +0 -104
  416. package/src/ui/types.ts +0 -75
  417. package/src/utils/analytics.ts +0 -72
  418. package/src/utils/cost-warning.ts +0 -27
  419. package/src/utils/env.ts +0 -46
  420. package/src/utils/errors.ts +0 -69
  421. package/src/utils/event-bus.ts +0 -38
  422. package/src/utils/index.ts +0 -24
  423. package/src/utils/logger.ts +0 -171
  424. package/src/utils/rate-limiter.ts +0 -121
  425. package/src/utils/service-auth.ts +0 -49
  426. package/src/utils/validation.ts +0 -53
  427. package/src/version.ts +0 -4
  428. package/src/watcher/index.ts +0 -214
  429. package/src/wizard/approval.ts +0 -383
  430. package/src/wizard/index.ts +0 -25
  431. package/src/wizard/prompts.ts +0 -338
  432. package/src/wizard/types.ts +0 -172
  433. package/src/wizard/ui.ts +0 -556
  434. package/src/wizard/wizard.ts +0 -304
  435. package/tsconfig.json +0 -24
@@ -1,1202 +0,0 @@
1
- /**
2
- * Generate Terraform Command
3
- *
4
- * Interactive wizard for AWS infrastructure discovery and Terraform generation
5
- *
6
- * Usage: nimbus generate terraform [options]
7
- */
8
-
9
- import { logger } from '../utils';
10
- import {
11
- createWizard,
12
- ui,
13
- select,
14
- multiSelect,
15
- confirm,
16
- input,
17
- pathInput,
18
- type TerraformWizardContext,
19
- type WizardStep,
20
- type StepResult,
21
- } from '../wizard';
22
- import { generateTerraformProject, type GeneratedFile } from '../generator/terraform';
23
-
24
- // ---- Cloud CLI helpers (replace microservice REST calls) ----
25
-
26
- function getAwsProfiles(): string[] {
27
- try {
28
- const { execFileSync } = require('child_process');
29
- const out = execFileSync('aws', ['configure', 'list-profiles'], {
30
- encoding: 'utf-8', timeout: 5000, stdio: ['pipe', 'pipe', 'pipe'],
31
- }) as string;
32
- return out.trim().split('\n').map((s: string) => s.trim()).filter(Boolean);
33
- } catch {
34
- return ['default'];
35
- }
36
- }
37
-
38
- function validateAwsProfile(profile: string): { accountId?: string; valid: boolean; error?: string } {
39
- try {
40
- const { execFileSync } = require('child_process');
41
- const out = execFileSync('aws', ['sts', 'get-caller-identity', '--profile', profile, '--output', 'json'], {
42
- encoding: 'utf-8', timeout: 10000, stdio: ['pipe', 'pipe', 'pipe'],
43
- }) as string;
44
- const data = JSON.parse(out);
45
- return { valid: true, accountId: data.Account };
46
- } catch (e: any) {
47
- return { valid: false, error: e.message?.slice(0, 100) };
48
- }
49
- }
50
-
51
- function getGcpProject(): string {
52
- try {
53
- const { execFileSync } = require('child_process');
54
- return (execFileSync('gcloud', ['config', 'get-value', 'project'], {
55
- encoding: 'utf-8', timeout: 5000, stdio: ['pipe', 'pipe', 'pipe'],
56
- }) as string).trim();
57
- } catch {
58
- return '';
59
- }
60
- }
61
-
62
- function validateAzureSubscription(subscriptionId: string): { name?: string; valid: boolean; error?: string } {
63
- try {
64
- const { execFileSync } = require('child_process');
65
- const out = execFileSync('az', ['account', 'show', '--subscription', subscriptionId, '--output', 'json'], {
66
- encoding: 'utf-8', timeout: 10000, stdio: ['pipe', 'pipe', 'pipe'],
67
- }) as string;
68
- const data = JSON.parse(out);
69
- return { valid: true, name: data.name };
70
- } catch (e: any) {
71
- return { valid: false, error: e.message?.slice(0, 100) };
72
- }
73
- }
74
-
75
- /**
76
- * Command options from CLI arguments
77
- */
78
- export interface GenerateTerraformOptions {
79
- profile?: string;
80
- regions?: string[];
81
- services?: string[];
82
- output?: string;
83
- nonInteractive?: boolean;
84
- acceptAllImprovements?: boolean;
85
- rejectAllImprovements?: boolean;
86
- acceptCategories?: string[];
87
- mock?: boolean;
88
- provider?: 'aws' | 'gcp' | 'azure';
89
- gcpProject?: string;
90
- azureSubscription?: string;
91
- jsonOutput?: boolean;
92
- questionnaire?: boolean;
93
- conversational?: boolean;
94
- skipValidation?: boolean;
95
- validationMode?: 'required' | 'optional';
96
- }
97
-
98
- /**
99
- * Run the generate terraform command
100
- */
101
- export async function generateTerraformCommand(
102
- options: GenerateTerraformOptions = {}
103
- ): Promise<void> {
104
- logger.info('Starting Terraform generation wizard');
105
-
106
- // Non-interactive mode
107
- if (options.nonInteractive) {
108
- await runNonInteractive(options);
109
- return;
110
- }
111
-
112
- // Questionnaire mode
113
- if (options.questionnaire) {
114
- const { questionnaireCommand } = await import('./questionnaire');
115
- await questionnaireCommand({
116
- type: 'terraform',
117
- outputDir: options.output,
118
- });
119
- return;
120
- }
121
-
122
- // Conversational mode (Mode B)
123
- if (options.conversational) {
124
- await runConversational(options);
125
- return;
126
- }
127
-
128
- // Interactive wizard mode
129
- const steps = createWizardSteps();
130
-
131
- const wizard = createWizard<TerraformWizardContext>({
132
- title: 'nimbus generate terraform',
133
- description: 'Generate Terraform from your cloud infrastructure',
134
- initialContext: {
135
- provider: 'aws',
136
- awsProfile: options.profile,
137
- awsRegions: options.regions,
138
- servicesToScan: options.services,
139
- outputPath: options.output,
140
- },
141
- steps,
142
- onEvent: event => {
143
- if (event.type === 'step:start' && process.stdout.isTTY) {
144
- const idx = steps.findIndex(s => s.id === event.stepId);
145
- if (idx >= 0) {
146
- // Visual step progress bar
147
- const progress = steps.map((s, i) => {
148
- if (i < idx) {
149
- return ui.color(`\u2713 ${s.title}`, 'green');
150
- }
151
- if (i === idx) {
152
- return ui.color(`\u25CF ${s.title}`, 'cyan');
153
- }
154
- return ui.dim(`\u25CB ${s.title}`);
155
- });
156
- ui.newLine();
157
- ui.print(ui.dim(' Progress: ') + progress.join(ui.dim(' \u2500 ')));
158
- }
159
- }
160
- logger.debug('Wizard event', { type: event.type });
161
- },
162
- });
163
-
164
- const result = await wizard.run();
165
-
166
- if (result.success) {
167
- ui.newLine();
168
- ui.box({
169
- title: 'Complete!',
170
- content: [
171
- 'Your infrastructure has been codified as Terraform.',
172
- '',
173
- 'Next steps:',
174
- ` 1. Review the generated files in ${result.context.outputPath}`,
175
- ' 2. Run "terraform plan" to see what will be imported',
176
- ' 3. Run "terraform apply" to bring resources under Terraform control',
177
- '',
178
- 'Scan saved to history. View with: nimbus infra history',
179
- ],
180
- style: 'rounded',
181
- borderColor: 'green',
182
- padding: 1,
183
- });
184
- } else {
185
- ui.error(`Wizard failed: ${result.error?.message || 'Unknown error'}`);
186
- process.exit(1);
187
- }
188
- }
189
-
190
- /**
191
- * Create wizard steps
192
- */
193
- function createWizardSteps(): WizardStep<TerraformWizardContext>[] {
194
- return [
195
- // Step 1: Provider Selection
196
- {
197
- id: 'provider',
198
- title: 'Cloud Provider Selection',
199
- description: 'Select the cloud provider to scan for infrastructure',
200
- execute: providerSelectionStep,
201
- },
202
-
203
- // Step 2: AWS Configuration
204
- {
205
- id: 'aws-config',
206
- title: 'AWS Configuration',
207
- description: 'Configure AWS profile and regions to scan',
208
- condition: ctx => ctx.provider === 'aws',
209
- execute: awsConfigStep,
210
- },
211
-
212
- // Step 3: Service Selection
213
- {
214
- id: 'services',
215
- title: 'Service Selection',
216
- description: 'Select which AWS services to scan',
217
- condition: ctx => ctx.provider === 'aws',
218
- execute: serviceSelectionStep,
219
- },
220
-
221
- // GCP Configuration
222
- {
223
- id: 'gcp-config',
224
- title: 'GCP Configuration',
225
- description: 'Configure GCP project and regions to scan',
226
- condition: ctx => ctx.provider === 'gcp',
227
- execute: gcpConfigStep,
228
- },
229
-
230
- // GCP Service Selection
231
- {
232
- id: 'gcp-services',
233
- title: 'GCP Service Selection',
234
- description: 'Select which GCP services to scan',
235
- condition: ctx => ctx.provider === 'gcp',
236
- execute: gcpServiceSelectionStep,
237
- },
238
-
239
- // Azure Configuration
240
- {
241
- id: 'azure-config',
242
- title: 'Azure Configuration',
243
- description: 'Configure Azure subscription and resource group',
244
- condition: ctx => ctx.provider === 'azure',
245
- execute: azureConfigStep,
246
- },
247
-
248
- // Azure Service Selection
249
- {
250
- id: 'azure-services',
251
- title: 'Azure Service Selection',
252
- description: 'Select which Azure services to scan',
253
- condition: ctx => ctx.provider === 'azure',
254
- execute: azureServiceSelectionStep,
255
- },
256
-
257
- // Step 4: Discovery
258
- {
259
- id: 'discovery',
260
- title: 'Infrastructure Discovery',
261
- description: 'Scanning your AWS infrastructure...',
262
- execute: discoveryStep,
263
- },
264
-
265
- // Step 5: Generation Options
266
- {
267
- id: 'generation-options',
268
- title: 'Generation Options',
269
- description: 'Configure Terraform generation options',
270
- execute: generationOptionsStep,
271
- },
272
-
273
- // Step 6: Output Location
274
- {
275
- id: 'output',
276
- title: 'Output Location',
277
- description: 'Where should the Terraform files be saved?',
278
- execute: outputLocationStep,
279
- },
280
-
281
- // Future steps (Phase 2+):
282
- // - Terraform Generation
283
- // - Best Practices Analysis
284
- // - Interactive Review
285
- // - Starter Kit Generation
286
- // - Terraform Operations
287
- ];
288
- }
289
-
290
- /**
291
- * Step 1: Provider Selection
292
- */
293
- async function providerSelectionStep(ctx: TerraformWizardContext): Promise<StepResult> {
294
- const provider = await select<'aws' | 'gcp' | 'azure'>({
295
- message: 'Select cloud provider:',
296
- options: [
297
- {
298
- value: 'aws',
299
- label: 'AWS (Amazon Web Services)',
300
- description: 'Scan EC2, S3, RDS, Lambda, VPC, IAM, and more',
301
- },
302
- {
303
- value: 'gcp',
304
- label: 'GCP (Google Cloud Platform)',
305
- description: 'Scan Compute, GCS, GKE, Cloud Functions, VPC, IAM',
306
- },
307
- {
308
- value: 'azure',
309
- label: 'Azure (Microsoft Azure)',
310
- description: 'Scan VMs, Storage, AKS, Functions, VNet, IAM',
311
- },
312
- ],
313
- defaultValue: ctx.provider || 'aws',
314
- });
315
-
316
- if (!provider) {
317
- return { success: false, error: 'No provider selected' };
318
- }
319
-
320
- return {
321
- success: true,
322
- data: { provider },
323
- };
324
- }
325
-
326
- /**
327
- * Step 2: AWS Configuration
328
- */
329
- async function awsConfigStep(ctx: TerraformWizardContext): Promise<StepResult> {
330
- // Fetch available profiles via CLI
331
- ui.startSpinner({ message: 'Fetching AWS profiles...' });
332
- const profileNames = getAwsProfiles();
333
- ui.stopSpinnerSuccess(`Found ${profileNames.length} AWS profile(s)`);
334
-
335
- // Profile selection
336
- let selectedProfile = ctx.awsProfile;
337
-
338
- if (!selectedProfile) {
339
- const profileOptions = profileNames.map(p => ({ value: p, label: p }));
340
-
341
- selectedProfile = await select({
342
- message: 'Select AWS profile:',
343
- options: profileOptions,
344
- defaultValue: 'default',
345
- });
346
-
347
- if (!selectedProfile) {
348
- return { success: false, error: 'No profile selected' };
349
- }
350
- }
351
-
352
- // Validate credentials via CLI
353
- ui.startSpinner({ message: `Validating credentials for profile "${selectedProfile}"...` });
354
- const validation = validateAwsProfile(selectedProfile);
355
-
356
- if (!validation.valid) {
357
- ui.stopSpinnerFail(`Invalid credentials: ${validation.error || 'Unknown error'}`);
358
- return { success: false, error: 'Invalid AWS credentials' };
359
- }
360
-
361
- ui.stopSpinnerSuccess(`Authenticated to account ${validation.accountId || 'unknown'}`);
362
- ctx.awsAccountId = validation.accountId;
363
-
364
- // Region selection
365
- ui.newLine();
366
-
367
- const regionChoice = await select<'all' | 'specific'>({
368
- message: 'Select regions to scan:',
369
- options: [
370
- {
371
- value: 'all',
372
- label: 'All enabled regions',
373
- description: 'Scan all regions enabled for your account',
374
- },
375
- {
376
- value: 'specific',
377
- label: 'Specific regions',
378
- description: 'Select specific regions to scan',
379
- },
380
- ],
381
- defaultValue: 'all',
382
- });
383
-
384
- let selectedRegions: string[] = [];
385
-
386
- if (regionChoice === 'specific') {
387
- // Hardcoded common AWS regions (no service needed)
388
- const regionOptions = [
389
- { value: 'us-east-1', label: 'us-east-1 - N. Virginia' },
390
- { value: 'us-east-2', label: 'us-east-2 - Ohio' },
391
- { value: 'us-west-1', label: 'us-west-1 - N. California' },
392
- { value: 'us-west-2', label: 'us-west-2 - Oregon' },
393
- { value: 'eu-west-1', label: 'eu-west-1 - Ireland' },
394
- { value: 'eu-central-1', label: 'eu-central-1 - Frankfurt' },
395
- { value: 'ap-southeast-1', label: 'ap-southeast-1 - Singapore' },
396
- { value: 'ap-northeast-1', label: 'ap-northeast-1 - Tokyo' },
397
- ];
398
-
399
- selectedRegions = (await multiSelect({
400
- message: 'Select regions to scan:',
401
- options: regionOptions,
402
- required: true,
403
- })) as string[];
404
- }
405
-
406
- return {
407
- success: true,
408
- data: {
409
- awsProfile: selectedProfile,
410
- awsRegions: regionChoice === 'all' ? undefined : selectedRegions,
411
- },
412
- };
413
- }
414
-
415
- /**
416
- * Step 3: Service Selection
417
- */
418
- async function serviceSelectionStep(_ctx: TerraformWizardContext): Promise<StepResult> {
419
- const serviceChoice = await select<'all' | 'specific'>({
420
- message: 'Select services to scan:',
421
- options: [
422
- {
423
- value: 'all',
424
- label: 'All supported services',
425
- description: 'EC2, S3, RDS, Lambda, VPC, IAM, ECS, EKS, DynamoDB, CloudFront',
426
- },
427
- {
428
- value: 'specific',
429
- label: 'Specific services',
430
- description: 'Select specific services to scan',
431
- },
432
- ],
433
- defaultValue: 'all',
434
- });
435
-
436
- if (serviceChoice === 'all') {
437
- return { success: true, data: { servicesToScan: undefined } };
438
- }
439
-
440
- const serviceOptions = [
441
- { value: 'EC2', label: 'EC2', description: 'Instances, volumes, security groups, AMIs' },
442
- { value: 'S3', label: 'S3', description: 'Buckets and bucket policies' },
443
- { value: 'RDS', label: 'RDS', description: 'Database instances and clusters' },
444
- { value: 'Lambda', label: 'Lambda', description: 'Functions and layers' },
445
- { value: 'VPC', label: 'VPC', description: 'VPCs, subnets, route tables, NAT gateways' },
446
- { value: 'IAM', label: 'IAM', description: 'Roles, policies, users, groups' },
447
- { value: 'ECS', label: 'ECS', description: 'Clusters, services, task definitions' },
448
- { value: 'EKS', label: 'EKS', description: 'Clusters and node groups' },
449
- { value: 'DynamoDB', label: 'DynamoDB', description: 'Tables' },
450
- { value: 'CloudFront', label: 'CloudFront', description: 'Distributions' },
451
- ];
452
-
453
- const selectedServices = await multiSelect({
454
- message: 'Select services to scan:',
455
- options: serviceOptions,
456
- required: true,
457
- });
458
-
459
- return {
460
- success: true,
461
- data: { servicesToScan: selectedServices as string[] },
462
- };
463
- }
464
-
465
- /**
466
- * GCP Configuration Step
467
- */
468
- async function gcpConfigStep(ctx: TerraformWizardContext): Promise<StepResult> {
469
- // Project ID
470
- const projectId = await input({
471
- message: 'Enter your GCP project ID:',
472
- defaultValue: ctx.gcpProject || '',
473
- });
474
-
475
- if (!projectId) {
476
- return { success: false, error: 'GCP project ID is required' };
477
- }
478
-
479
- // Validate project access via gcloud CLI
480
- ui.startSpinner({ message: `Validating access to project "${projectId}"...` });
481
- try {
482
- const { execFileSync } = await import('child_process');
483
- execFileSync('gcloud', ['projects', 'describe', projectId, '--format=json'], {
484
- encoding: 'utf-8', timeout: 10000, stdio: ['pipe', 'pipe', 'pipe'],
485
- });
486
- ui.stopSpinnerSuccess(`Connected to project ${projectId}`);
487
- } catch (error: any) {
488
- ui.stopSpinnerFail(`Could not validate project: ${error.message?.slice(0, 80) || 'unknown'}`);
489
- // Non-fatal — user may still proceed if gcloud is not configured
490
- ui.info('Proceeding without validation. Ensure gcloud credentials are configured.');
491
- }
492
-
493
- // Region selection
494
- ui.newLine();
495
-
496
- const regionChoice = await select<'all' | 'specific'>({
497
- message: 'Select regions to scan:',
498
- options: [
499
- {
500
- value: 'all',
501
- label: 'All available regions',
502
- description: 'Scan all GCP regions',
503
- },
504
- {
505
- value: 'specific',
506
- label: 'Specific regions',
507
- description: 'Select specific regions to scan',
508
- },
509
- ],
510
- defaultValue: 'all',
511
- });
512
-
513
- let selectedRegions: string[] = [];
514
-
515
- if (regionChoice === 'specific') {
516
- const gcpRegionOptions = [
517
- { value: 'us-central1', label: 'us-central1 - Iowa' },
518
- { value: 'us-east1', label: 'us-east1 - South Carolina' },
519
- { value: 'us-east4', label: 'us-east4 - Northern Virginia' },
520
- { value: 'us-west1', label: 'us-west1 - Oregon' },
521
- { value: 'europe-west1', label: 'europe-west1 - Belgium' },
522
- { value: 'europe-west2', label: 'europe-west2 - London' },
523
- { value: 'asia-east1', label: 'asia-east1 - Taiwan' },
524
- { value: 'asia-southeast1', label: 'asia-southeast1 - Singapore' },
525
- ];
526
-
527
- selectedRegions = (await multiSelect({
528
- message: 'Select GCP regions to scan:',
529
- options: gcpRegionOptions,
530
- required: true,
531
- })) as string[];
532
- }
533
-
534
- return {
535
- success: true,
536
- data: {
537
- gcpProject: projectId,
538
- gcpRegions: regionChoice === 'all' ? undefined : selectedRegions,
539
- },
540
- };
541
- }
542
-
543
- /**
544
- * GCP Service Selection Step
545
- */
546
- async function gcpServiceSelectionStep(_ctx: TerraformWizardContext): Promise<StepResult> {
547
- const serviceChoice = await select<'all' | 'specific'>({
548
- message: 'Select GCP services to scan:',
549
- options: [
550
- {
551
- value: 'all',
552
- label: 'All supported services',
553
- description: 'Compute, GCS, GKE, Cloud Functions, VPC, IAM, Cloud SQL, Pub/Sub',
554
- },
555
- {
556
- value: 'specific',
557
- label: 'Specific services',
558
- description: 'Select specific services to scan',
559
- },
560
- ],
561
- defaultValue: 'all',
562
- });
563
-
564
- if (serviceChoice === 'all') {
565
- return { success: true, data: { servicesToScan: undefined } };
566
- }
567
-
568
- const serviceOptions = [
569
- { value: 'Compute', label: 'Compute Engine', description: 'VMs, disks, images' },
570
- { value: 'GCS', label: 'Cloud Storage', description: 'Buckets and objects' },
571
- { value: 'GKE', label: 'Google Kubernetes Engine', description: 'Clusters and node pools' },
572
- { value: 'CloudFunctions', label: 'Cloud Functions', description: 'Serverless functions' },
573
- { value: 'VPC', label: 'VPC Network', description: 'Networks, subnets, firewalls' },
574
- { value: 'IAM', label: 'IAM', description: 'Roles, service accounts, policies' },
575
- { value: 'CloudSQL', label: 'Cloud SQL', description: 'Database instances' },
576
- { value: 'PubSub', label: 'Pub/Sub', description: 'Topics and subscriptions' },
577
- ];
578
-
579
- const selectedServices = await multiSelect({
580
- message: 'Select GCP services to scan:',
581
- options: serviceOptions,
582
- required: true,
583
- });
584
-
585
- return {
586
- success: true,
587
- data: { servicesToScan: selectedServices as string[] },
588
- };
589
- }
590
-
591
- /**
592
- * Azure Configuration Step
593
- */
594
- async function azureConfigStep(ctx: TerraformWizardContext): Promise<StepResult> {
595
- // Subscription ID
596
- const subscriptionId = await input({
597
- message: 'Enter your Azure subscription ID:',
598
- defaultValue: ctx.azureSubscription || '',
599
- });
600
-
601
- if (!subscriptionId) {
602
- return { success: false, error: 'Azure subscription ID is required' };
603
- }
604
-
605
- // Validate subscription access via Azure CLI
606
- ui.startSpinner({ message: `Validating access to subscription "${subscriptionId}"...` });
607
- const azVal = validateAzureSubscription(subscriptionId);
608
- if (!azVal.valid) {
609
- ui.stopSpinnerFail(`Could not validate subscription: ${azVal.error || 'unknown'}`);
610
- ui.info('Proceeding without validation. Ensure az CLI credentials are configured.');
611
- } else {
612
- ui.stopSpinnerSuccess(`Connected to subscription${azVal.name ? ` (${azVal.name})` : ''}`);
613
- }
614
-
615
- // Resource group (optional)
616
- ui.newLine();
617
- const resourceGroup = await input({
618
- message: 'Resource group (leave empty to scan all):',
619
- defaultValue: ctx.azureResourceGroup || '',
620
- });
621
-
622
- // Region selection
623
- ui.newLine();
624
-
625
- const regionChoice = await select<'all' | 'specific'>({
626
- message: 'Select regions to scan:',
627
- options: [
628
- {
629
- value: 'all',
630
- label: 'All available regions',
631
- description: 'Scan all Azure regions',
632
- },
633
- {
634
- value: 'specific',
635
- label: 'Specific regions',
636
- description: 'Select specific regions to scan',
637
- },
638
- ],
639
- defaultValue: 'all',
640
- });
641
-
642
- let _selectedRegions: string[] = [];
643
-
644
- if (regionChoice === 'specific') {
645
- const azureRegionOptions = [
646
- { value: 'eastus', label: 'East US' },
647
- { value: 'eastus2', label: 'East US 2' },
648
- { value: 'westus2', label: 'West US 2' },
649
- { value: 'centralus', label: 'Central US' },
650
- { value: 'westeurope', label: 'West Europe' },
651
- { value: 'northeurope', label: 'North Europe' },
652
- { value: 'southeastasia', label: 'Southeast Asia' },
653
- { value: 'eastasia', label: 'East Asia' },
654
- ];
655
-
656
- _selectedRegions = (await multiSelect({
657
- message: 'Select Azure regions to scan:',
658
- options: azureRegionOptions,
659
- required: true,
660
- })) as string[];
661
- }
662
-
663
- return {
664
- success: true,
665
- data: {
666
- azureSubscription: subscriptionId,
667
- azureResourceGroup: resourceGroup || undefined,
668
- },
669
- };
670
- }
671
-
672
- /**
673
- * Azure Service Selection Step
674
- */
675
- async function azureServiceSelectionStep(_ctx: TerraformWizardContext): Promise<StepResult> {
676
- const serviceChoice = await select<'all' | 'specific'>({
677
- message: 'Select Azure services to scan:',
678
- options: [
679
- {
680
- value: 'all',
681
- label: 'All supported services',
682
- description: 'VMs, Storage, AKS, Functions, VNet, IAM, SQL, Service Bus',
683
- },
684
- {
685
- value: 'specific',
686
- label: 'Specific services',
687
- description: 'Select specific services to scan',
688
- },
689
- ],
690
- defaultValue: 'all',
691
- });
692
-
693
- if (serviceChoice === 'all') {
694
- return { success: true, data: { servicesToScan: undefined } };
695
- }
696
-
697
- const serviceOptions = [
698
- { value: 'VirtualMachines', label: 'Virtual Machines', description: 'VMs, disks, images' },
699
- {
700
- value: 'Storage',
701
- label: 'Storage Accounts',
702
- description: 'Blob, file, queue, table storage',
703
- },
704
- { value: 'AKS', label: 'Azure Kubernetes Service', description: 'Clusters and node pools' },
705
- { value: 'Functions', label: 'Azure Functions', description: 'Serverless functions' },
706
- { value: 'VNet', label: 'Virtual Network', description: 'VNets, subnets, NSGs' },
707
- { value: 'IAM', label: 'IAM', description: 'Role assignments, managed identities' },
708
- { value: 'SQLDatabase', label: 'Azure SQL', description: 'SQL databases and servers' },
709
- { value: 'ServiceBus', label: 'Service Bus', description: 'Queues and topics' },
710
- ];
711
-
712
- const selectedServices = await multiSelect({
713
- message: 'Select Azure services to scan:',
714
- options: serviceOptions,
715
- required: true,
716
- });
717
-
718
- return {
719
- success: true,
720
- data: { servicesToScan: selectedServices as string[] },
721
- };
722
- }
723
-
724
- /**
725
- * Run synchronous CLI-based infrastructure discovery.
726
- * Replaces the old REST polling approach.
727
- */
728
- async function discoverInfra(ctx: TerraformWizardContext): Promise<{ resourceCount: number; components: string[] }> {
729
- const { execFileSync } = await import('child_process');
730
- const components: string[] = [];
731
- let resourceCount = 0;
732
-
733
- if (ctx.provider === 'aws') {
734
- const profile = ctx.awsProfile || 'default';
735
- const env = { ...process.env, AWS_PROFILE: profile };
736
-
737
- // EC2 instances
738
- try {
739
- const out = execFileSync('aws', ['ec2', 'describe-instances', '--query', 'Reservations[*].Instances[*].InstanceId', '--output', 'json'], { encoding: 'utf-8', timeout: 15000, stdio: ['pipe', 'pipe', 'pipe'], env });
740
- const ids = JSON.parse(out).flat();
741
- if (ids.length > 0) { components.push('ec2'); resourceCount += ids.length; }
742
- } catch { /* not available */ }
743
-
744
- // S3 buckets
745
- try {
746
- const out = execFileSync('aws', ['s3', 'ls'], { encoding: 'utf-8', timeout: 10000, stdio: ['pipe', 'pipe', 'pipe'], env });
747
- const buckets = out.trim().split('\n').filter(Boolean).length;
748
- if (buckets > 0) { components.push('s3'); resourceCount += buckets; }
749
- } catch { /* not available */ }
750
-
751
- // RDS
752
- try {
753
- const out = execFileSync('aws', ['rds', 'describe-db-instances', '--query', 'DBInstances[*].DBInstanceIdentifier', '--output', 'json'], { encoding: 'utf-8', timeout: 15000, stdio: ['pipe', 'pipe', 'pipe'], env });
754
- const dbs = JSON.parse(out);
755
- if (dbs.length > 0) { components.push('rds'); resourceCount += dbs.length; }
756
- } catch { /* not available */ }
757
-
758
- // EKS clusters
759
- try {
760
- const out = execFileSync('aws', ['eks', 'list-clusters', '--output', 'json'], { encoding: 'utf-8', timeout: 15000, stdio: ['pipe', 'pipe', 'pipe'], env });
761
- const clusters = JSON.parse(out).clusters;
762
- if (clusters?.length > 0) { components.push('eks'); resourceCount += clusters.length; }
763
- } catch { /* not available */ }
764
-
765
- // VPC (always include as foundational)
766
- components.push('vpc');
767
- } else if (ctx.provider === 'gcp') {
768
- try {
769
- execFileSync('gcloud', ['compute', 'instances', 'list', '--format=json'], { encoding: 'utf-8', timeout: 15000, stdio: ['pipe', 'pipe', 'pipe'] });
770
- components.push('compute');
771
- } catch { /* not available */ }
772
- components.push('vpc');
773
- } else if (ctx.provider === 'azure') {
774
- try {
775
- const out = execFileSync('az', ['resource', 'list', '--output', 'json'], { encoding: 'utf-8', timeout: 20000, stdio: ['pipe', 'pipe', 'pipe'] });
776
- const resources = JSON.parse(out);
777
- resourceCount += resources.length;
778
- components.push('vnet');
779
- } catch { /* not available */ }
780
- }
781
-
782
- return { resourceCount, components: [...new Set(components)] };
783
- }
784
-
785
- /**
786
- * Step: Discovery — uses direct CLI calls instead of REST polling
787
- */
788
- async function discoveryStep(ctx: TerraformWizardContext): Promise<StepResult> {
789
- ui.startSpinner({ message: 'Discovering infrastructure via CLI...' });
790
- try {
791
- const { resourceCount, components } = await discoverInfra(ctx);
792
- ui.stopSpinnerSuccess(`Discovery complete — found ${resourceCount} resource(s), components: ${components.join(', ') || 'vpc'}`);
793
- ctx.discoveredComponents = components;
794
- return { success: true, data: { discoveredComponents: components } };
795
- } catch (e: any) {
796
- ui.stopSpinnerFail('Discovery failed');
797
- ui.warning(`Could not auto-discover: ${e.message}. You can still generate a template.`);
798
- return { success: true, data: { discoveredComponents: ['vpc'] } };
799
- }
800
- }
801
-
802
- /**
803
- * Step 5: Generation Options
804
- */
805
- async function generationOptionsStep(_ctx: TerraformWizardContext): Promise<StepResult> {
806
- // Import method
807
- const importMethod = await select<'both' | 'blocks' | 'script'>({
808
- message: 'How should imports be generated?',
809
- options: [
810
- {
811
- value: 'both',
812
- label: 'Both import blocks and shell script (Recommended)',
813
- description: 'Maximum compatibility with all Terraform versions',
814
- },
815
- {
816
- value: 'blocks',
817
- label: 'Import blocks only (Terraform 1.5+)',
818
- description: 'Modern declarative imports',
819
- },
820
- {
821
- value: 'script',
822
- label: 'Shell script only',
823
- description: 'Traditional terraform import commands',
824
- },
825
- ],
826
- defaultValue: 'both',
827
- });
828
-
829
- // Starter kit options
830
- ui.newLine();
831
- const includeStarterKit = await confirm({
832
- message: 'Generate starter kit (README, .gitignore, Makefile, CI/CD)?',
833
- defaultValue: true,
834
- });
835
-
836
- return {
837
- success: true,
838
- data: {
839
- importMethod,
840
- includeReadme: includeStarterKit,
841
- includeGitignore: includeStarterKit,
842
- includeMakefile: includeStarterKit,
843
- includeGithubActions: includeStarterKit,
844
- },
845
- };
846
- }
847
-
848
- /**
849
- * Step 6: Output Location
850
- */
851
- async function outputLocationStep(ctx: TerraformWizardContext): Promise<StepResult> {
852
- const outputPath = await pathInput(
853
- 'Where should the Terraform files be saved?',
854
- ctx.outputPath || './terraform-infrastructure'
855
- );
856
-
857
- if (!outputPath) {
858
- return { success: false, error: 'Output path is required' };
859
- }
860
-
861
- // Ask about saving preferences
862
- ui.newLine();
863
- const savePreferences = await confirm({
864
- message: 'Save your preferences as organization policy for future runs?',
865
- defaultValue: false,
866
- });
867
-
868
- return {
869
- success: true,
870
- data: {
871
- outputPath,
872
- savePreferences,
873
- },
874
- };
875
- }
876
-
877
- /**
878
- * Run in conversational mode (Mode B)
879
- * Uses the generator service's conversational endpoints to describe infrastructure
880
- * in natural language and generate Terraform from the conversation.
881
- */
882
- async function runConversational(options: GenerateTerraformOptions): Promise<void> {
883
- const crypto = await import('crypto');
884
- const fs = await import('fs/promises');
885
- const pathMod = await import('path');
886
-
887
- const sessionId = crypto.randomUUID();
888
-
889
- ui.header('nimbus generate terraform', 'Conversational mode');
890
- ui.print('Describe your infrastructure in natural language.');
891
- ui.print('Type "generate" or "done" when ready to generate Terraform.');
892
- ui.print('Type "exit" to quit.');
893
- ui.newLine();
894
-
895
- for (;;) {
896
- const message = await input({
897
- message: 'You:',
898
- defaultValue: '',
899
- });
900
-
901
- if (!message || message.trim() === '') {
902
- continue;
903
- }
904
-
905
- const trimmed = message.trim().toLowerCase();
906
-
907
- if (trimmed === 'exit') {
908
- ui.info('Exiting conversational mode.');
909
- return;
910
- }
911
-
912
- // User explicitly wants to generate
913
- if (trimmed === 'generate' || trimmed === 'done') {
914
- const generated = await generateFromConversation(sessionId, options, fs, pathMod);
915
- if (generated) {
916
- ui.newLine();
917
- ui.print('You can refine the generated Terraform by continuing the conversation.');
918
- ui.print('Type "generate" to regenerate, or "exit" to finish.');
919
- ui.newLine();
920
- continue; // stays in the while(true) loop with same sessionId
921
- }
922
- return;
923
- }
924
-
925
- // Build request from conversational description — use chatCommand for natural language interaction
926
- ui.newLine();
927
- ui.info(`You said: "${message}"`);
928
- ui.info('Type "generate" or "done" to generate Terraform from this description, or describe your infrastructure further.');
929
- ui.newLine();
930
- }
931
- }
932
-
933
- /**
934
- * Generate Terraform files from a conversational session using the local generator
935
- */
936
- async function generateFromConversation(
937
- _sessionId: string,
938
- options: GenerateTerraformOptions,
939
- fs: typeof import('fs/promises'),
940
- pathMod: typeof import('path')
941
- ): Promise<boolean> {
942
- ui.newLine();
943
- ui.startSpinner({ message: 'Generating Terraform from description...' });
944
-
945
- try {
946
- const provider = options.provider || 'aws';
947
- const outputDir = options.output || './infrastructure';
948
-
949
- const generatedProject = await generateTerraformProject({
950
- projectName: 'infrastructure',
951
- provider: provider as 'aws' | 'gcp' | 'azure',
952
- region: options.regions?.[0] || (provider === 'aws' ? 'us-east-1' : provider === 'gcp' ? 'us-central1' : 'eastus'),
953
- components: options.services || ['vpc'],
954
- });
955
-
956
- ui.stopSpinnerSuccess('Terraform code generated');
957
-
958
- const files: GeneratedFile[] = generatedProject.files;
959
- await fs.mkdir(outputDir, { recursive: true });
960
-
961
- for (const file of files) {
962
- const filePath = pathMod.join(outputDir, file.path);
963
- await fs.mkdir(pathMod.dirname(filePath), { recursive: true });
964
- await fs.writeFile(filePath, file.content);
965
- }
966
-
967
- ui.newLine();
968
- ui.success(`Generated ${files.length} Terraform file(s) in ${outputDir}`);
969
- ui.newLine();
970
- ui.print('Generated files:');
971
- for (const file of files) {
972
- ui.print(` ${ui.color('●', 'green')} ${file.path}`);
973
- }
974
- ui.newLine();
975
- ui.print('Next steps:');
976
- ui.print(` 1. Review the generated files in ${outputDir}`);
977
- ui.print(' 2. Run "terraform plan" to preview changes');
978
- ui.print(' 3. Run "terraform apply" to create infrastructure');
979
- return true;
980
- } catch (error: any) {
981
- ui.stopSpinnerFail('Generation failed');
982
- ui.error(`Failed to generate Terraform: ${error.message}`);
983
- return false;
984
- }
985
- }
986
-
987
- /**
988
- * Run in non-interactive mode
989
- */
990
- async function runNonInteractive(options: GenerateTerraformOptions): Promise<void> {
991
- ui.header('nimbus generate terraform', 'Non-interactive mode');
992
-
993
- const provider = options.provider || 'aws';
994
-
995
- // Validate required flags per provider
996
- if (provider === 'aws' && !options.profile) {
997
- ui.error('AWS profile is required in non-interactive mode (--profile)');
998
- process.exit(1);
999
- }
1000
- if (provider === 'gcp' && !options.gcpProject) {
1001
- ui.error('GCP project is required in non-interactive mode (--gcp-project)');
1002
- process.exit(1);
1003
- }
1004
- if (provider === 'azure' && !options.azureSubscription) {
1005
- ui.error('Azure subscription is required in non-interactive mode (--azure-subscription)');
1006
- process.exit(1);
1007
- }
1008
-
1009
- ui.info(`Provider: ${provider}`);
1010
- if (provider === 'aws') {
1011
- ui.info(`Profile: ${options.profile}`);
1012
- } else if (provider === 'gcp') {
1013
- ui.info(`Project: ${options.gcpProject}`);
1014
- } else if (provider === 'azure') {
1015
- ui.info(`Subscription: ${options.azureSubscription}`);
1016
- }
1017
- ui.info(`Regions: ${options.regions?.join(', ') || 'all'}`);
1018
- ui.info(`Services: ${options.services?.join(', ') || 'all'}`);
1019
- ui.info(`Output: ${options.output || './terraform-infrastructure'}`);
1020
- ui.newLine();
1021
-
1022
- // Build discovery context
1023
- const ctx: TerraformWizardContext = {
1024
- provider,
1025
- awsProfile: options.profile,
1026
- awsRegions: options.regions,
1027
- gcpProject: options.gcpProject,
1028
- azureSubscription: options.azureSubscription,
1029
- servicesToScan: options.services,
1030
- outputPath: options.output || './terraform-infrastructure',
1031
- };
1032
-
1033
- // Run direct CLI discovery
1034
- ui.info('Starting infrastructure discovery...');
1035
- ui.newLine();
1036
-
1037
- const { components: discoveredComponents } = await discoverInfra(ctx).catch(() => ({ components: ['vpc'] }));
1038
- ui.success(`Discovered components: ${discoveredComponents.join(', ')}`);
1039
- ui.newLine();
1040
-
1041
- // Generate Terraform from discovered inventory using src/generator/terraform.ts
1042
- ui.startSpinner({ message: 'Generating Terraform code...' });
1043
-
1044
- try {
1045
- const outputDir = options.output || './terraform-infrastructure';
1046
- const components = options.services || discoveredComponents;
1047
-
1048
- const generatedProject = await generateTerraformProject({
1049
- projectName: 'infrastructure',
1050
- provider: provider as 'aws' | 'gcp' | 'azure',
1051
- region: options.regions?.[0] || (provider === 'aws' ? 'us-east-1' : provider === 'gcp' ? 'us-central1' : 'eastus'),
1052
- components,
1053
- });
1054
-
1055
- ui.stopSpinnerSuccess('Terraform code generated');
1056
-
1057
- // Write generated files
1058
- const fs = await import('fs/promises');
1059
- const path = await import('path');
1060
-
1061
- await fs.mkdir(outputDir, { recursive: true });
1062
-
1063
- const files: GeneratedFile[] = generatedProject.files;
1064
- for (const file of files) {
1065
- const filePath = path.join(outputDir, file.path);
1066
- await fs.mkdir(path.dirname(filePath), { recursive: true });
1067
- await fs.writeFile(filePath, file.content);
1068
- }
1069
-
1070
- if (options.jsonOutput) {
1071
- const summary = {
1072
- success: true,
1073
- provider,
1074
- outputDir,
1075
- filesGenerated: files.map(f => f.path),
1076
- componentsGenerated: components,
1077
- };
1078
- console.log(JSON.stringify(summary, null, 2));
1079
- } else {
1080
- ui.newLine();
1081
- ui.success(`Generated ${files.length} Terraform file(s) in ${outputDir}`);
1082
- ui.newLine();
1083
- ui.print('Generated files:');
1084
- for (const file of files) {
1085
- ui.print(` ${ui.color('●', 'green')} ${file.path}`);
1086
- }
1087
- ui.newLine();
1088
- ui.print('Next steps:');
1089
- ui.print(` 1. Review the generated files in ${outputDir}`);
1090
- ui.print(' 2. Run "terraform plan" to see what will be imported');
1091
- ui.print(' 3. Run "terraform apply" to bring resources under Terraform control');
1092
- }
1093
- } catch (error: any) {
1094
- ui.stopSpinnerFail('Generation failed');
1095
- ui.error(`Failed to generate Terraform: ${error.message}`);
1096
- process.exit(1);
1097
- }
1098
- }
1099
-
1100
- /**
1101
- * Run post-generation validation using terraform fmt/validate if available.
1102
- * Non-blocking: warnings shown but errors don't abort.
1103
- */
1104
- async function runPostGenerationValidation(
1105
- files: Array<{ path: string; content: string }>,
1106
- jsonOutput?: boolean
1107
- ): Promise<Record<string, unknown> | undefined> {
1108
- if (!jsonOutput) {
1109
- ui.newLine();
1110
- ui.info('Tip: Run "terraform init && terraform validate" in the output directory to validate the generated files.');
1111
- }
1112
- return undefined;
1113
- }
1114
-
1115
- /**
1116
- * Display a human-readable validation report.
1117
- * Shows results for terraform fmt, terraform validate, tflint, and checkov.
1118
- * Tools that are not installed show as "not installed" gracefully.
1119
- */
1120
- function displayValidationReport(report: any): void {
1121
- const items: Array<{ severity: string; message: string; file?: string; rule?: string }> =
1122
- report.items || [];
1123
- const summary = report.summary || { errors: 0, warnings: 0, info: 0 };
1124
-
1125
- // Overall status
1126
- const isValid = report.valid !== false && summary.errors === 0;
1127
- if (isValid) {
1128
- ui.print(` ${ui.color('\u2713', 'green')} Validation passed`);
1129
- } else {
1130
- ui.print(` ${ui.color('\u2717', 'red')} Validation found issues`);
1131
- }
1132
-
1133
- // Summary line
1134
- const parts: string[] = [];
1135
- if (summary.errors > 0) {
1136
- parts.push(ui.color(`${summary.errors} error(s)`, 'red'));
1137
- }
1138
- if (summary.warnings > 0) {
1139
- parts.push(ui.color(`${summary.warnings} warning(s)`, 'yellow'));
1140
- }
1141
- if (summary.info > 0) {
1142
- parts.push(ui.dim(`${summary.info} info`));
1143
- }
1144
- if (parts.length > 0) {
1145
- ui.print(` Summary: ${parts.join(', ')}`);
1146
- }
1147
-
1148
- // Tool-level results (grouped by rule prefix)
1149
- const toolStatus: Record<string, 'pass' | 'fail' | 'not-installed'> = {
1150
- 'terraform-fmt': 'pass',
1151
- 'terraform-validate': 'pass',
1152
- tflint: 'pass',
1153
- checkov: 'pass',
1154
- };
1155
-
1156
- for (const item of items) {
1157
- if (item.severity === 'error' || item.severity === 'warning') {
1158
- const rule = item.rule || '';
1159
- if (rule.startsWith('fmt') || rule.includes('format')) {
1160
- toolStatus['terraform-fmt'] = 'fail';
1161
- } else if (rule.startsWith('hcl') || rule.includes('syntax')) {
1162
- toolStatus['terraform-validate'] = 'fail';
1163
- } else if (rule.startsWith('require-') || rule.includes('anti-pattern')) {
1164
- toolStatus['tflint'] = 'fail';
1165
- } else if (rule.startsWith('checkov') || rule.includes('security')) {
1166
- toolStatus['checkov'] = 'fail';
1167
- }
1168
- }
1169
- }
1170
-
1171
- ui.newLine();
1172
- ui.print(' Tool Results:');
1173
- for (const [tool, status] of Object.entries(toolStatus)) {
1174
- const icon =
1175
- status === 'pass'
1176
- ? ui.color('\u2713', 'green')
1177
- : status === 'fail'
1178
- ? ui.color('\u2717', 'red')
1179
- : ui.dim('-');
1180
- const label = status === 'not-installed' ? ui.dim('not installed') : status;
1181
- ui.print(` ${icon} ${tool}: ${label}`);
1182
- }
1183
-
1184
- // Show first 5 error/warning details
1185
- const significant = items.filter(i => i.severity === 'error' || i.severity === 'warning');
1186
- if (significant.length > 0) {
1187
- ui.newLine();
1188
- ui.print(' Details:');
1189
- const toShow = significant.slice(0, 5);
1190
- for (const item of toShow) {
1191
- const sevIcon = item.severity === 'error' ? ui.color('E', 'red') : ui.color('W', 'yellow');
1192
- const fileInfo = item.file ? ` (${item.file})` : '';
1193
- ui.print(` [${sevIcon}] ${item.message}${fileInfo}`);
1194
- }
1195
- if (significant.length > 5) {
1196
- ui.print(ui.dim(` ... and ${significant.length - 5} more`));
1197
- }
1198
- }
1199
- }
1200
-
1201
- // Export as default command
1202
- export default generateTerraformCommand;