@build-astron-co/nimbus 0.4.2 → 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 (430) hide show
  1. package/dist/src/agent/compaction-agent.js +24 -12
  2. package/dist/src/agent/context-manager.js +2 -1
  3. package/dist/src/agent/expand-files.js +2 -1
  4. package/dist/src/agent/loop.js +71 -33
  5. package/dist/src/agent/permissions.js +4 -2
  6. package/dist/src/agent/system-prompt.js +34 -17
  7. package/dist/src/app.js +1 -1
  8. package/dist/src/auth/keychain.js +8 -4
  9. package/dist/src/auth/store.js +70 -107
  10. package/dist/src/cli/init.js +35 -19
  11. package/dist/src/cli/run.js +18 -10
  12. package/dist/src/cli/serve.js +4 -2
  13. package/dist/src/cli.js +52 -11
  14. package/dist/src/commands/alias.js +5 -3
  15. package/dist/src/commands/audit/index.js +2 -1
  16. package/dist/src/commands/aws-terraform.js +36 -18
  17. package/dist/src/commands/completions.js +1 -1
  18. package/dist/src/commands/config.js +3 -2
  19. package/dist/src/commands/connect-github.js +92 -0
  20. package/dist/src/commands/cost/index.js +3 -2
  21. package/dist/src/commands/deploy.js +15 -10
  22. package/dist/src/commands/doctor.js +6 -3
  23. package/dist/src/commands/drift/index.js +2 -1
  24. package/dist/src/commands/export.js +5 -3
  25. package/dist/src/commands/generate-terraform.js +110 -2
  26. package/dist/src/commands/import.js +3 -3
  27. package/dist/src/commands/incident.js +10 -5
  28. package/dist/src/commands/login.js +8 -93
  29. package/dist/src/commands/logs.js +16 -8
  30. package/dist/src/commands/onboarding.js +6 -4
  31. package/dist/src/commands/pipeline.js +6 -3
  32. package/dist/src/commands/plugin.js +3 -2
  33. package/dist/src/commands/profile.js +27 -14
  34. package/dist/src/commands/questionnaire.js +1 -1
  35. package/dist/src/commands/rollback.js +3 -2
  36. package/dist/src/commands/rollout.js +5 -3
  37. package/dist/src/commands/runbook.js +17 -10
  38. package/dist/src/commands/schedule.js +10 -5
  39. package/dist/src/commands/status.js +2 -1
  40. package/dist/src/commands/team-context.js +12 -7
  41. package/dist/src/commands/template.js +1 -1
  42. package/dist/src/commands/tf/index.js +6 -3
  43. package/dist/src/commands/version.js +6 -3
  44. package/dist/src/commands/watch.js +6 -3
  45. package/dist/src/compat/sqlite.js +5 -3
  46. package/dist/src/config/mode-store.js +2 -1
  47. package/dist/src/config/profiles.js +4 -2
  48. package/dist/src/config/types.js +2 -1
  49. package/dist/src/engine/executor.js +8 -4
  50. package/dist/src/engine/planner.js +9 -5
  51. package/dist/src/llm/providers/anthropic.js +6 -3
  52. package/dist/src/llm/providers/ollama.js +1 -1
  53. package/dist/src/llm/router.js +22 -7
  54. package/dist/src/sessions/manager.js +6 -3
  55. package/dist/src/sharing/viewer.js +2 -1
  56. package/dist/src/tools/file-ops.js +1 -2
  57. package/dist/src/tools/schemas/devops.js +197 -108
  58. package/dist/src/tools/schemas/standard.js +1 -1
  59. package/dist/src/ui/App.js +25 -13
  60. package/dist/src/ui/FileDiffModal.js +22 -11
  61. package/dist/src/ui/HelpModal.js +2 -1
  62. package/dist/src/ui/InputBox.js +6 -3
  63. package/dist/src/ui/MessageList.js +40 -20
  64. package/dist/src/ui/TerminalPane.js +2 -1
  65. package/dist/src/ui/ToolCallDisplay.js +12 -6
  66. package/dist/src/ui/TreePane.js +2 -1
  67. package/dist/src/ui/ink/index.js +37 -21
  68. package/dist/src/watcher/index.js +8 -4
  69. package/package.json +3 -5
  70. package/src/__tests__/alias.test.ts +0 -133
  71. package/src/__tests__/app.test.ts +0 -76
  72. package/src/__tests__/audit.test.ts +0 -877
  73. package/src/__tests__/circuit-breaker.test.ts +0 -116
  74. package/src/__tests__/cli-run.test.ts +0 -351
  75. package/src/__tests__/compat-sqlite.test.ts +0 -68
  76. package/src/__tests__/context-manager.test.ts +0 -632
  77. package/src/__tests__/context.test.ts +0 -242
  78. package/src/__tests__/devops-terminal-gaps.test.ts +0 -718
  79. package/src/__tests__/doctor.test.ts +0 -48
  80. package/src/__tests__/enterprise.test.ts +0 -401
  81. package/src/__tests__/export.test.ts +0 -236
  82. package/src/__tests__/gap-11-18-20.test.ts +0 -958
  83. package/src/__tests__/generator.test.ts +0 -433
  84. package/src/__tests__/helm-streaming.test.ts +0 -127
  85. package/src/__tests__/hooks.test.ts +0 -582
  86. package/src/__tests__/incident.test.ts +0 -179
  87. package/src/__tests__/init.test.ts +0 -487
  88. package/src/__tests__/intent-parser.test.ts +0 -229
  89. package/src/__tests__/llm-router.test.ts +0 -209
  90. package/src/__tests__/logs.test.ts +0 -107
  91. package/src/__tests__/loop-errors.test.ts +0 -244
  92. package/src/__tests__/lsp.test.ts +0 -293
  93. package/src/__tests__/modes.test.ts +0 -336
  94. package/src/__tests__/perf-optimizations.test.ts +0 -847
  95. package/src/__tests__/permissions.test.ts +0 -338
  96. package/src/__tests__/pipeline.test.ts +0 -50
  97. package/src/__tests__/polish-phase3.test.ts +0 -340
  98. package/src/__tests__/profile.test.ts +0 -237
  99. package/src/__tests__/rollback.test.ts +0 -83
  100. package/src/__tests__/runbook.test.ts +0 -219
  101. package/src/__tests__/schedule.test.ts +0 -206
  102. package/src/__tests__/serve.test.ts +0 -275
  103. package/src/__tests__/sessions.test.ts +0 -322
  104. package/src/__tests__/sharing.test.ts +0 -340
  105. package/src/__tests__/snapshots.test.ts +0 -581
  106. package/src/__tests__/standalone-migration.test.ts +0 -199
  107. package/src/__tests__/state-db.test.ts +0 -334
  108. package/src/__tests__/status.test.ts +0 -158
  109. package/src/__tests__/stream-with-tools.test.ts +0 -778
  110. package/src/__tests__/subagents.test.ts +0 -176
  111. package/src/__tests__/system-prompt.test.ts +0 -248
  112. package/src/__tests__/terminal-gap-v2.test.ts +0 -395
  113. package/src/__tests__/terminal-parity.test.ts +0 -393
  114. package/src/__tests__/tf-apply.test.ts +0 -187
  115. package/src/__tests__/tool-converter.test.ts +0 -256
  116. package/src/__tests__/tool-schemas.test.ts +0 -602
  117. package/src/__tests__/tools.test.ts +0 -144
  118. package/src/__tests__/version-json.test.ts +0 -184
  119. package/src/__tests__/version.test.ts +0 -49
  120. package/src/__tests__/watch.test.ts +0 -129
  121. package/src/agent/compaction-agent.ts +0 -266
  122. package/src/agent/context-manager.ts +0 -499
  123. package/src/agent/context.ts +0 -427
  124. package/src/agent/deploy-preview.ts +0 -487
  125. package/src/agent/expand-files.ts +0 -108
  126. package/src/agent/index.ts +0 -68
  127. package/src/agent/loop.ts +0 -1998
  128. package/src/agent/modes.ts +0 -429
  129. package/src/agent/permissions.ts +0 -513
  130. package/src/agent/subagents/base.ts +0 -116
  131. package/src/agent/subagents/cost.ts +0 -51
  132. package/src/agent/subagents/explore.ts +0 -42
  133. package/src/agent/subagents/general.ts +0 -54
  134. package/src/agent/subagents/index.ts +0 -102
  135. package/src/agent/subagents/infra.ts +0 -59
  136. package/src/agent/subagents/security.ts +0 -69
  137. package/src/agent/system-prompt.ts +0 -990
  138. package/src/app.ts +0 -180
  139. package/src/audit/activity-log.ts +0 -290
  140. package/src/audit/compliance-checker.ts +0 -540
  141. package/src/audit/cost-tracker.ts +0 -318
  142. package/src/audit/index.ts +0 -23
  143. package/src/audit/security-scanner.ts +0 -641
  144. package/src/auth/guard.ts +0 -75
  145. package/src/auth/index.ts +0 -56
  146. package/src/auth/keychain.ts +0 -82
  147. package/src/auth/oauth.ts +0 -465
  148. package/src/auth/providers.ts +0 -470
  149. package/src/auth/sso.ts +0 -113
  150. package/src/auth/store.ts +0 -505
  151. package/src/auth/types.ts +0 -187
  152. package/src/build.ts +0 -141
  153. package/src/cli/index.ts +0 -16
  154. package/src/cli/init.ts +0 -1227
  155. package/src/cli/openapi-spec.ts +0 -356
  156. package/src/cli/run.ts +0 -628
  157. package/src/cli/serve-auth.ts +0 -80
  158. package/src/cli/serve.ts +0 -539
  159. package/src/cli/web.ts +0 -71
  160. package/src/cli.ts +0 -1728
  161. package/src/clients/core-engine-client.ts +0 -227
  162. package/src/clients/enterprise-client.ts +0 -334
  163. package/src/clients/generator-client.ts +0 -351
  164. package/src/clients/git-client.ts +0 -627
  165. package/src/clients/github-client.ts +0 -410
  166. package/src/clients/helm-client.ts +0 -504
  167. package/src/clients/index.ts +0 -80
  168. package/src/clients/k8s-client.ts +0 -497
  169. package/src/clients/llm-client.ts +0 -161
  170. package/src/clients/rest-client.ts +0 -130
  171. package/src/clients/service-discovery.ts +0 -38
  172. package/src/clients/terraform-client.ts +0 -482
  173. package/src/clients/tools-client.ts +0 -1843
  174. package/src/clients/ws-client.ts +0 -115
  175. package/src/commands/alias.ts +0 -100
  176. package/src/commands/analyze/index.ts +0 -352
  177. package/src/commands/apply/helm.ts +0 -473
  178. package/src/commands/apply/index.ts +0 -213
  179. package/src/commands/apply/k8s.ts +0 -454
  180. package/src/commands/apply/terraform.ts +0 -582
  181. package/src/commands/ask.ts +0 -167
  182. package/src/commands/audit/index.ts +0 -357
  183. package/src/commands/auth-cloud.ts +0 -407
  184. package/src/commands/auth-list.ts +0 -134
  185. package/src/commands/auth-profile.ts +0 -121
  186. package/src/commands/auth-refresh.ts +0 -187
  187. package/src/commands/auth-status.ts +0 -141
  188. package/src/commands/aws/ec2.ts +0 -501
  189. package/src/commands/aws/iam.ts +0 -397
  190. package/src/commands/aws/index.ts +0 -133
  191. package/src/commands/aws/lambda.ts +0 -396
  192. package/src/commands/aws/rds.ts +0 -439
  193. package/src/commands/aws/s3.ts +0 -439
  194. package/src/commands/aws/vpc.ts +0 -393
  195. package/src/commands/aws-discover.ts +0 -542
  196. package/src/commands/aws-terraform.ts +0 -755
  197. package/src/commands/azure/aks.ts +0 -376
  198. package/src/commands/azure/functions.ts +0 -253
  199. package/src/commands/azure/index.ts +0 -116
  200. package/src/commands/azure/storage.ts +0 -478
  201. package/src/commands/azure/vm.ts +0 -355
  202. package/src/commands/billing/index.ts +0 -256
  203. package/src/commands/chat.ts +0 -320
  204. package/src/commands/completions.ts +0 -268
  205. package/src/commands/config.ts +0 -372
  206. package/src/commands/cost/cloud-cost-estimator.ts +0 -266
  207. package/src/commands/cost/estimator.ts +0 -79
  208. package/src/commands/cost/index.ts +0 -810
  209. package/src/commands/cost/parsers/terraform.ts +0 -273
  210. package/src/commands/cost/parsers/types.ts +0 -25
  211. package/src/commands/cost/pricing/aws.ts +0 -544
  212. package/src/commands/cost/pricing/azure.ts +0 -499
  213. package/src/commands/cost/pricing/gcp.ts +0 -396
  214. package/src/commands/cost/pricing/index.ts +0 -40
  215. package/src/commands/demo.ts +0 -250
  216. package/src/commands/deploy.ts +0 -260
  217. package/src/commands/doctor.ts +0 -1386
  218. package/src/commands/drift/index.ts +0 -787
  219. package/src/commands/explain.ts +0 -277
  220. package/src/commands/export.ts +0 -146
  221. package/src/commands/feedback.ts +0 -389
  222. package/src/commands/fix.ts +0 -324
  223. package/src/commands/fs/index.ts +0 -402
  224. package/src/commands/gcp/compute.ts +0 -325
  225. package/src/commands/gcp/functions.ts +0 -271
  226. package/src/commands/gcp/gke.ts +0 -438
  227. package/src/commands/gcp/iam.ts +0 -344
  228. package/src/commands/gcp/index.ts +0 -129
  229. package/src/commands/gcp/storage.ts +0 -284
  230. package/src/commands/generate-helm.ts +0 -1249
  231. package/src/commands/generate-k8s.ts +0 -1508
  232. package/src/commands/generate-terraform.ts +0 -1202
  233. package/src/commands/gh/index.ts +0 -863
  234. package/src/commands/git/index.ts +0 -1343
  235. package/src/commands/helm/index.ts +0 -1126
  236. package/src/commands/help.ts +0 -715
  237. package/src/commands/history.ts +0 -149
  238. package/src/commands/import.ts +0 -868
  239. package/src/commands/incident.ts +0 -166
  240. package/src/commands/index.ts +0 -367
  241. package/src/commands/init.ts +0 -1051
  242. package/src/commands/k8s/index.ts +0 -1137
  243. package/src/commands/login.ts +0 -716
  244. package/src/commands/logout.ts +0 -83
  245. package/src/commands/logs.ts +0 -167
  246. package/src/commands/onboarding.ts +0 -405
  247. package/src/commands/pipeline.ts +0 -186
  248. package/src/commands/plan/display.ts +0 -279
  249. package/src/commands/plan/index.ts +0 -599
  250. package/src/commands/plugin.ts +0 -398
  251. package/src/commands/preview.ts +0 -452
  252. package/src/commands/profile.ts +0 -342
  253. package/src/commands/questionnaire.ts +0 -1172
  254. package/src/commands/resume.ts +0 -47
  255. package/src/commands/rollback.ts +0 -315
  256. package/src/commands/rollout.ts +0 -88
  257. package/src/commands/runbook.ts +0 -346
  258. package/src/commands/schedule.ts +0 -236
  259. package/src/commands/status.ts +0 -252
  260. package/src/commands/team/index.ts +0 -346
  261. package/src/commands/team-context.ts +0 -220
  262. package/src/commands/template.ts +0 -233
  263. package/src/commands/tf/index.ts +0 -1093
  264. package/src/commands/upgrade.ts +0 -609
  265. package/src/commands/usage/index.ts +0 -134
  266. package/src/commands/version.ts +0 -174
  267. package/src/commands/watch.ts +0 -153
  268. package/src/compat/index.ts +0 -2
  269. package/src/compat/runtime.ts +0 -12
  270. package/src/compat/sqlite.ts +0 -177
  271. package/src/config/index.ts +0 -17
  272. package/src/config/manager.ts +0 -530
  273. package/src/config/mode-store.ts +0 -62
  274. package/src/config/profiles.ts +0 -84
  275. package/src/config/safety-policy.ts +0 -358
  276. package/src/config/schema.ts +0 -125
  277. package/src/config/types.ts +0 -609
  278. package/src/config/workspace-state.ts +0 -53
  279. package/src/context/context-db.ts +0 -199
  280. package/src/demo/index.ts +0 -349
  281. package/src/demo/scenarios/full-journey.ts +0 -229
  282. package/src/demo/scenarios/getting-started.ts +0 -127
  283. package/src/demo/scenarios/helm-release.ts +0 -341
  284. package/src/demo/scenarios/k8s-deployment.ts +0 -194
  285. package/src/demo/scenarios/terraform-vpc.ts +0 -170
  286. package/src/demo/types.ts +0 -92
  287. package/src/engine/cost-estimator.ts +0 -480
  288. package/src/engine/diagram-generator.ts +0 -256
  289. package/src/engine/drift-detector.ts +0 -902
  290. package/src/engine/executor.ts +0 -1066
  291. package/src/engine/index.ts +0 -76
  292. package/src/engine/orchestrator.ts +0 -636
  293. package/src/engine/planner.ts +0 -787
  294. package/src/engine/safety.ts +0 -743
  295. package/src/engine/verifier.ts +0 -770
  296. package/src/enterprise/audit.ts +0 -348
  297. package/src/enterprise/auth.ts +0 -270
  298. package/src/enterprise/billing.ts +0 -822
  299. package/src/enterprise/index.ts +0 -17
  300. package/src/enterprise/teams.ts +0 -443
  301. package/src/generator/best-practices.ts +0 -1608
  302. package/src/generator/helm.ts +0 -630
  303. package/src/generator/index.ts +0 -37
  304. package/src/generator/intent-parser.ts +0 -514
  305. package/src/generator/kubernetes.ts +0 -976
  306. package/src/generator/terraform.ts +0 -1875
  307. package/src/history/index.ts +0 -8
  308. package/src/history/manager.ts +0 -250
  309. package/src/history/types.ts +0 -34
  310. package/src/hooks/config.ts +0 -432
  311. package/src/hooks/engine.ts +0 -392
  312. package/src/hooks/index.ts +0 -4
  313. package/src/llm/auth-bridge.ts +0 -198
  314. package/src/llm/circuit-breaker.ts +0 -140
  315. package/src/llm/config-loader.ts +0 -201
  316. package/src/llm/cost-calculator.ts +0 -171
  317. package/src/llm/index.ts +0 -8
  318. package/src/llm/model-aliases.ts +0 -115
  319. package/src/llm/provider-registry.ts +0 -63
  320. package/src/llm/providers/anthropic.ts +0 -462
  321. package/src/llm/providers/bedrock.ts +0 -477
  322. package/src/llm/providers/google.ts +0 -405
  323. package/src/llm/providers/ollama.ts +0 -767
  324. package/src/llm/providers/openai-compatible.ts +0 -340
  325. package/src/llm/providers/openai.ts +0 -328
  326. package/src/llm/providers/openrouter.ts +0 -338
  327. package/src/llm/router.ts +0 -1104
  328. package/src/llm/types.ts +0 -232
  329. package/src/lsp/client.ts +0 -298
  330. package/src/lsp/languages.ts +0 -119
  331. package/src/lsp/manager.ts +0 -294
  332. package/src/mcp/client.ts +0 -402
  333. package/src/mcp/index.ts +0 -5
  334. package/src/mcp/manager.ts +0 -133
  335. package/src/nimbus.ts +0 -234
  336. package/src/plugins/index.ts +0 -27
  337. package/src/plugins/loader.ts +0 -334
  338. package/src/plugins/manager.ts +0 -376
  339. package/src/plugins/types.ts +0 -284
  340. package/src/scanners/cicd-scanner.ts +0 -258
  341. package/src/scanners/cloud-scanner.ts +0 -466
  342. package/src/scanners/framework-scanner.ts +0 -469
  343. package/src/scanners/iac-scanner.ts +0 -388
  344. package/src/scanners/index.ts +0 -539
  345. package/src/scanners/language-scanner.ts +0 -276
  346. package/src/scanners/package-manager-scanner.ts +0 -277
  347. package/src/scanners/types.ts +0 -172
  348. package/src/sessions/manager.ts +0 -472
  349. package/src/sessions/types.ts +0 -44
  350. package/src/sharing/sync.ts +0 -300
  351. package/src/sharing/viewer.ts +0 -163
  352. package/src/snapshots/index.ts +0 -2
  353. package/src/snapshots/manager.ts +0 -530
  354. package/src/state/artifacts.ts +0 -147
  355. package/src/state/audit.ts +0 -137
  356. package/src/state/billing.ts +0 -240
  357. package/src/state/checkpoints.ts +0 -117
  358. package/src/state/config.ts +0 -67
  359. package/src/state/conversations.ts +0 -14
  360. package/src/state/credentials.ts +0 -154
  361. package/src/state/db.ts +0 -58
  362. package/src/state/index.ts +0 -26
  363. package/src/state/messages.ts +0 -115
  364. package/src/state/projects.ts +0 -123
  365. package/src/state/schema.ts +0 -236
  366. package/src/state/sessions.ts +0 -147
  367. package/src/state/teams.ts +0 -200
  368. package/src/telemetry.ts +0 -108
  369. package/src/tools/aws-ops.ts +0 -952
  370. package/src/tools/azure-ops.ts +0 -579
  371. package/src/tools/file-ops.ts +0 -615
  372. package/src/tools/gcp-ops.ts +0 -625
  373. package/src/tools/git-ops.ts +0 -773
  374. package/src/tools/github-ops.ts +0 -799
  375. package/src/tools/helm-ops.ts +0 -943
  376. package/src/tools/index.ts +0 -17
  377. package/src/tools/k8s-ops.ts +0 -819
  378. package/src/tools/schemas/converter.ts +0 -184
  379. package/src/tools/schemas/devops.ts +0 -3502
  380. package/src/tools/schemas/index.ts +0 -73
  381. package/src/tools/schemas/standard.ts +0 -1148
  382. package/src/tools/schemas/types.ts +0 -735
  383. package/src/tools/spawn-exec.ts +0 -148
  384. package/src/tools/terraform-ops.ts +0 -862
  385. package/src/types/ambient.d.ts +0 -193
  386. package/src/types/config.ts +0 -83
  387. package/src/types/drift.ts +0 -116
  388. package/src/types/enterprise.ts +0 -335
  389. package/src/types/index.ts +0 -20
  390. package/src/types/plan.ts +0 -44
  391. package/src/types/request.ts +0 -65
  392. package/src/types/response.ts +0 -54
  393. package/src/types/service.ts +0 -51
  394. package/src/ui/App.tsx +0 -2114
  395. package/src/ui/DeployPreview.tsx +0 -174
  396. package/src/ui/FileDiffModal.tsx +0 -162
  397. package/src/ui/Header.tsx +0 -131
  398. package/src/ui/HelpModal.tsx +0 -57
  399. package/src/ui/InputBox.tsx +0 -503
  400. package/src/ui/MessageList.tsx +0 -1032
  401. package/src/ui/PermissionPrompt.tsx +0 -163
  402. package/src/ui/StatusBar.tsx +0 -277
  403. package/src/ui/TerminalPane.tsx +0 -84
  404. package/src/ui/ToolCallDisplay.tsx +0 -643
  405. package/src/ui/TreePane.tsx +0 -132
  406. package/src/ui/chat-ui.ts +0 -850
  407. package/src/ui/index.ts +0 -33
  408. package/src/ui/ink/index.ts +0 -1444
  409. package/src/ui/streaming.ts +0 -176
  410. package/src/ui/theme.ts +0 -104
  411. package/src/ui/types.ts +0 -75
  412. package/src/utils/analytics.ts +0 -72
  413. package/src/utils/cost-warning.ts +0 -27
  414. package/src/utils/env.ts +0 -46
  415. package/src/utils/errors.ts +0 -69
  416. package/src/utils/event-bus.ts +0 -38
  417. package/src/utils/index.ts +0 -24
  418. package/src/utils/logger.ts +0 -171
  419. package/src/utils/rate-limiter.ts +0 -121
  420. package/src/utils/service-auth.ts +0 -49
  421. package/src/utils/validation.ts +0 -53
  422. package/src/version.ts +0 -4
  423. package/src/watcher/index.ts +0 -214
  424. package/src/wizard/approval.ts +0 -383
  425. package/src/wizard/index.ts +0 -25
  426. package/src/wizard/prompts.ts +0 -338
  427. package/src/wizard/types.ts +0 -172
  428. package/src/wizard/ui.ts +0 -556
  429. package/src/wizard/wizard.ts +0 -304
  430. package/tsconfig.json +0 -24
@@ -1,1508 +0,0 @@
1
- /**
2
- * Generate Kubernetes Manifests Command
3
- *
4
- * Interactive wizard for generating K8s resources
5
- *
6
- * Usage: nimbus generate k8s [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 WizardStep,
19
- type StepResult,
20
- } from '../wizard';
21
-
22
- /**
23
- * Workload types for Kubernetes
24
- */
25
- export type K8sWorkloadType = 'deployment' | 'statefulset' | 'daemonset' | 'job' | 'cronjob';
26
-
27
- /**
28
- * Service types for Kubernetes
29
- */
30
- export type K8sServiceType = 'ClusterIP' | 'NodePort' | 'LoadBalancer' | 'None';
31
-
32
- /**
33
- * Command options from CLI arguments
34
- */
35
- export interface GenerateK8sOptions {
36
- workloadType?: K8sWorkloadType;
37
- namespace?: string;
38
- name?: string;
39
- image?: string;
40
- replicas?: number;
41
- port?: number;
42
- serviceType?: K8sServiceType;
43
- output?: string;
44
- nonInteractive?: boolean;
45
- includeIngress?: boolean;
46
- includeHpa?: boolean;
47
- includePdb?: boolean;
48
- includeConfigMap?: boolean;
49
- includeSecret?: boolean;
50
- cpuRequest?: string;
51
- cpuLimit?: string;
52
- memoryRequest?: string;
53
- memoryLimit?: string;
54
- }
55
-
56
- /**
57
- * Wizard context for K8s generation
58
- */
59
- export interface K8sWizardContext {
60
- // Workload configuration
61
- workloadType?: K8sWorkloadType;
62
- name?: string;
63
- namespace?: string;
64
- image?: string;
65
- imageTag?: string;
66
-
67
- // Replica configuration
68
- replicas?: number;
69
- minReplicas?: number;
70
- maxReplicas?: number;
71
- targetCPUUtilization?: number;
72
-
73
- // Port & Service configuration
74
- containerPort?: number;
75
- serviceType?: K8sServiceType;
76
- servicePort?: number;
77
-
78
- // Resource limits
79
- cpuRequest?: string;
80
- cpuLimit?: string;
81
- memoryRequest?: string;
82
- memoryLimit?: string;
83
-
84
- // Additional resources
85
- includeService?: boolean;
86
- includeIngress?: boolean;
87
- includeHpa?: boolean;
88
- includePdb?: boolean;
89
- includeConfigMap?: boolean;
90
- includeSecret?: boolean;
91
-
92
- // Ingress configuration
93
- ingressHost?: string;
94
- ingressPath?: string;
95
- ingressTls?: boolean;
96
-
97
- // PDB configuration
98
- minAvailable?: number | string;
99
-
100
- // Job/CronJob specific
101
- schedule?: string;
102
- backoffLimit?: number;
103
- completions?: number;
104
- parallelism?: number;
105
-
106
- // Health checks
107
- includeProbes?: boolean;
108
- livenessPath?: string;
109
- readinessPath?: string;
110
-
111
- // Output
112
- outputPath?: string;
113
- outputFormat?: 'multiple' | 'single' | 'kustomize';
114
- generatedFiles?: string[];
115
- }
116
-
117
- /**
118
- * Run the generate k8s command
119
- */
120
- export async function generateK8sCommand(options: GenerateK8sOptions = {}): Promise<void> {
121
- logger.info('Starting Kubernetes manifest generation wizard');
122
-
123
- // Non-interactive mode
124
- if (options.nonInteractive) {
125
- await runNonInteractive(options);
126
- return;
127
- }
128
-
129
- // Interactive wizard mode
130
- const wizard = createWizard<K8sWizardContext>({
131
- title: 'nimbus generate k8s',
132
- description: 'Generate Kubernetes manifests for your application',
133
- initialContext: {
134
- workloadType: options.workloadType,
135
- namespace: options.namespace,
136
- name: options.name,
137
- image: options.image,
138
- replicas: options.replicas,
139
- containerPort: options.port,
140
- serviceType: options.serviceType,
141
- outputPath: options.output,
142
- includeIngress: options.includeIngress,
143
- includeHpa: options.includeHpa,
144
- includePdb: options.includePdb,
145
- includeConfigMap: options.includeConfigMap,
146
- includeSecret: options.includeSecret,
147
- cpuRequest: options.cpuRequest,
148
- cpuLimit: options.cpuLimit,
149
- memoryRequest: options.memoryRequest,
150
- memoryLimit: options.memoryLimit,
151
- },
152
- steps: createWizardSteps(),
153
- onEvent: event => {
154
- logger.debug('Wizard event', { type: event.type });
155
- },
156
- });
157
-
158
- const result = await wizard.run();
159
-
160
- if (result.success) {
161
- ui.newLine();
162
- ui.box({
163
- title: 'Complete!',
164
- content: [
165
- 'Your Kubernetes manifests have been generated.',
166
- '',
167
- 'Generated files:',
168
- ...(result.context.generatedFiles?.map(f => ` - ${f}`) || [' - (manifests generated)']),
169
- '',
170
- 'Next steps:',
171
- ` 1. Review the generated files in ${result.context.outputPath}`,
172
- ' 2. Customize values as needed for your environment',
173
- ' 3. Run "kubectl apply -f <path>" or "nimbus apply k8s <path>"',
174
- ],
175
- style: 'rounded',
176
- borderColor: 'green',
177
- padding: 1,
178
- });
179
- } else {
180
- ui.error(`Wizard failed: ${result.error?.message || 'Unknown error'}`);
181
- process.exit(1);
182
- }
183
- }
184
-
185
- /**
186
- * Create wizard steps
187
- */
188
- function createWizardSteps(): WizardStep<K8sWizardContext>[] {
189
- return [
190
- // Step 1: Workload Type Selection
191
- {
192
- id: 'workload-type',
193
- title: 'Workload Type',
194
- description: 'Select the type of Kubernetes workload to generate',
195
- execute: workloadTypeStep,
196
- },
197
-
198
- // Step 2: Basic Configuration
199
- {
200
- id: 'basic-config',
201
- title: 'Basic Configuration',
202
- description: 'Configure name, namespace, and image',
203
- execute: basicConfigStep,
204
- },
205
-
206
- // Step 3: Replica Configuration (not for DaemonSet or Job)
207
- {
208
- id: 'replicas',
209
- title: 'Replica Configuration',
210
- description: 'Configure replicas and scaling options',
211
- condition: ctx => !['daemonset', 'job'].includes(ctx.workloadType || ''),
212
- execute: replicaConfigStep,
213
- },
214
-
215
- // Step 4: Job/CronJob Configuration
216
- {
217
- id: 'job-config',
218
- title: 'Job Configuration',
219
- description: 'Configure job-specific settings',
220
- condition: ctx => ['job', 'cronjob'].includes(ctx.workloadType || ''),
221
- execute: jobConfigStep,
222
- },
223
-
224
- // Step 5: Port & Service Configuration
225
- {
226
- id: 'service-config',
227
- title: 'Port & Service Configuration',
228
- description: 'Configure container ports and service exposure',
229
- execute: serviceConfigStep,
230
- },
231
-
232
- // Step 6: Resource Limits
233
- {
234
- id: 'resources',
235
- title: 'Resource Limits',
236
- description: 'Configure CPU and memory requests/limits',
237
- execute: resourceLimitsStep,
238
- },
239
-
240
- // Step 7: Additional Resources
241
- {
242
- id: 'additional-resources',
243
- title: 'Additional Resources',
244
- description: 'Select additional Kubernetes resources to generate',
245
- execute: additionalResourcesStep,
246
- },
247
-
248
- // Step 8: Health Checks
249
- {
250
- id: 'health-checks',
251
- title: 'Health Checks',
252
- description: 'Configure liveness and readiness probes',
253
- condition: ctx => !['job', 'cronjob'].includes(ctx.workloadType || ''),
254
- execute: healthChecksStep,
255
- },
256
-
257
- // Step 9: Output Configuration
258
- {
259
- id: 'output',
260
- title: 'Output Configuration',
261
- description: 'Configure where and how to save the manifests',
262
- execute: outputConfigStep,
263
- },
264
-
265
- // Step 10: Generate
266
- {
267
- id: 'generate',
268
- title: 'Generate Manifests',
269
- description: 'Generating your Kubernetes manifests...',
270
- execute: generateStep,
271
- },
272
- ];
273
- }
274
-
275
- /**
276
- * Step 1: Workload Type Selection
277
- */
278
- async function workloadTypeStep(ctx: K8sWizardContext): Promise<StepResult> {
279
- const workloadType = await select<K8sWorkloadType>({
280
- message: 'Select workload type:',
281
- options: [
282
- {
283
- value: 'deployment',
284
- label: 'Deployment',
285
- description: 'Stateless application with rolling updates (most common)',
286
- },
287
- {
288
- value: 'statefulset',
289
- label: 'StatefulSet',
290
- description: 'Stateful application with stable network identity and storage',
291
- },
292
- {
293
- value: 'daemonset',
294
- label: 'DaemonSet',
295
- description: 'Run a pod on every node (e.g., monitoring agents)',
296
- },
297
- {
298
- value: 'job',
299
- label: 'Job',
300
- description: 'Run a task to completion',
301
- },
302
- {
303
- value: 'cronjob',
304
- label: 'CronJob',
305
- description: 'Run a job on a schedule',
306
- },
307
- ],
308
- defaultValue: ctx.workloadType || 'deployment',
309
- });
310
-
311
- if (!workloadType) {
312
- return { success: false, error: 'No workload type selected' };
313
- }
314
-
315
- return {
316
- success: true,
317
- data: { workloadType },
318
- };
319
- }
320
-
321
- /**
322
- * Step 2: Basic Configuration
323
- */
324
- async function basicConfigStep(ctx: K8sWizardContext): Promise<StepResult> {
325
- // Application name
326
- const name = await input({
327
- message: 'Application name:',
328
- defaultValue: ctx.name || 'my-app',
329
- validate: value => {
330
- if (!value) {
331
- return 'Name is required';
332
- }
333
- if (!/^[a-z0-9]([-a-z0-9]*[a-z0-9])?$/.test(value)) {
334
- return 'Name must be lowercase alphanumeric with dashes only';
335
- }
336
- return true;
337
- },
338
- });
339
-
340
- if (!name) {
341
- return { success: false, error: 'Name is required' };
342
- }
343
-
344
- // Namespace
345
- ui.newLine();
346
- const namespace = await input({
347
- message: 'Namespace:',
348
- defaultValue: ctx.namespace || 'default',
349
- validate: value => {
350
- if (!value) {
351
- return 'Namespace is required';
352
- }
353
- if (!/^[a-z0-9]([-a-z0-9]*[a-z0-9])?$/.test(value)) {
354
- return 'Namespace must be lowercase alphanumeric with dashes only';
355
- }
356
- return true;
357
- },
358
- });
359
-
360
- if (!namespace) {
361
- return { success: false, error: 'Namespace is required' };
362
- }
363
-
364
- // Container image
365
- ui.newLine();
366
- const image = await input({
367
- message: 'Container image (e.g., nginx:latest, myregistry/myapp):',
368
- defaultValue: ctx.image || '',
369
- validate: value => {
370
- if (!value) {
371
- return 'Image is required';
372
- }
373
- return true;
374
- },
375
- });
376
-
377
- if (!image) {
378
- return { success: false, error: 'Image is required' };
379
- }
380
-
381
- // Parse image and tag
382
- const imageParts = image.split(':');
383
- const imageBase = imageParts[0];
384
- const imageTag = imageParts[1] || 'latest';
385
-
386
- return {
387
- success: true,
388
- data: {
389
- name,
390
- namespace,
391
- image: imageBase,
392
- imageTag,
393
- },
394
- };
395
- }
396
-
397
- /**
398
- * Step 3: Replica Configuration
399
- */
400
- async function replicaConfigStep(ctx: K8sWizardContext): Promise<StepResult> {
401
- const replicas = await input({
402
- message: 'Number of replicas:',
403
- defaultValue: String(ctx.replicas || 2),
404
- validate: value => {
405
- const num = parseInt(value, 10);
406
- if (isNaN(num) || num < 1) {
407
- return 'Must be a positive number';
408
- }
409
- return true;
410
- },
411
- });
412
-
413
- if (!replicas) {
414
- return { success: false, error: 'Replicas required' };
415
- }
416
-
417
- // Ask about HPA
418
- ui.newLine();
419
- const includeHpa =
420
- ctx.includeHpa ??
421
- (await confirm({
422
- message: 'Include Horizontal Pod Autoscaler (HPA)?',
423
- defaultValue: false,
424
- }));
425
-
426
- let minReplicas: number | undefined;
427
- let maxReplicas: number | undefined;
428
- let targetCPUUtilization: number | undefined;
429
-
430
- if (includeHpa) {
431
- ui.newLine();
432
- const min = await input({
433
- message: 'Minimum replicas:',
434
- defaultValue: String(ctx.minReplicas || Math.max(1, parseInt(replicas, 10) - 1)),
435
- validate: value => {
436
- const num = parseInt(value, 10);
437
- if (isNaN(num) || num < 1) {
438
- return 'Must be a positive number';
439
- }
440
- return true;
441
- },
442
- });
443
- minReplicas = parseInt(min || '1', 10);
444
-
445
- const max = await input({
446
- message: 'Maximum replicas:',
447
- defaultValue: String(ctx.maxReplicas || parseInt(replicas, 10) * 2),
448
- validate: value => {
449
- const num = parseInt(value, 10);
450
- if (isNaN(num) || num < minReplicas!) {
451
- return `Must be >= ${minReplicas}`;
452
- }
453
- return true;
454
- },
455
- });
456
- maxReplicas = parseInt(max || '4', 10);
457
-
458
- const cpu = await input({
459
- message: 'Target CPU utilization (%):',
460
- defaultValue: String(ctx.targetCPUUtilization || 70),
461
- validate: value => {
462
- const num = parseInt(value, 10);
463
- if (isNaN(num) || num < 1 || num > 100) {
464
- return 'Must be between 1 and 100';
465
- }
466
- return true;
467
- },
468
- });
469
- targetCPUUtilization = parseInt(cpu || '70', 10);
470
- }
471
-
472
- return {
473
- success: true,
474
- data: {
475
- replicas: parseInt(replicas, 10),
476
- includeHpa,
477
- minReplicas,
478
- maxReplicas,
479
- targetCPUUtilization,
480
- },
481
- };
482
- }
483
-
484
- /**
485
- * Step 4: Job/CronJob Configuration
486
- */
487
- async function jobConfigStep(ctx: K8sWizardContext): Promise<StepResult> {
488
- let schedule: string | undefined;
489
-
490
- if (ctx.workloadType === 'cronjob') {
491
- const scheduleInput = await input({
492
- message: 'Cron schedule (e.g., "*/5 * * * *" for every 5 minutes):',
493
- defaultValue: ctx.schedule || '0 * * * *',
494
- validate: value => {
495
- if (!value) {
496
- return 'Schedule is required for CronJob';
497
- }
498
- // Basic cron validation (5 fields)
499
- const parts = value.trim().split(/\s+/);
500
- if (parts.length !== 5) {
501
- return 'Schedule must have 5 fields (min hour day month weekday)';
502
- }
503
- return true;
504
- },
505
- });
506
- schedule = scheduleInput;
507
- }
508
-
509
- // Backoff limit
510
- ui.newLine();
511
- const backoffInput = await input({
512
- message: 'Backoff limit (retries on failure):',
513
- defaultValue: String(ctx.backoffLimit || 6),
514
- validate: value => {
515
- const num = parseInt(value, 10);
516
- if (isNaN(num) || num < 0) {
517
- return 'Must be a non-negative number';
518
- }
519
- return true;
520
- },
521
- });
522
- const backoffLimit = parseInt(backoffInput || '6', 10);
523
-
524
- // Completions
525
- ui.newLine();
526
- const completionsInput = await input({
527
- message: 'Number of completions (total successful pods):',
528
- defaultValue: String(ctx.completions || 1),
529
- validate: value => {
530
- const num = parseInt(value, 10);
531
- if (isNaN(num) || num < 1) {
532
- return 'Must be a positive number';
533
- }
534
- return true;
535
- },
536
- });
537
- const completions = parseInt(completionsInput || '1', 10);
538
-
539
- // Parallelism
540
- ui.newLine();
541
- const parallelismInput = await input({
542
- message: 'Parallelism (concurrent pods):',
543
- defaultValue: String(ctx.parallelism || 1),
544
- validate: value => {
545
- const num = parseInt(value, 10);
546
- if (isNaN(num) || num < 1) {
547
- return 'Must be a positive number';
548
- }
549
- return true;
550
- },
551
- });
552
- const parallelism = parseInt(parallelismInput || '1', 10);
553
-
554
- return {
555
- success: true,
556
- data: {
557
- schedule,
558
- backoffLimit,
559
- completions,
560
- parallelism,
561
- },
562
- };
563
- }
564
-
565
- /**
566
- * Step 5: Port & Service Configuration
567
- */
568
- async function serviceConfigStep(ctx: K8sWizardContext): Promise<StepResult> {
569
- // Container port
570
- const portInput = await input({
571
- message: 'Container port:',
572
- defaultValue: String(ctx.containerPort || 8080),
573
- validate: value => {
574
- const num = parseInt(value, 10);
575
- if (isNaN(num) || num < 1 || num > 65535) {
576
- return 'Must be between 1 and 65535';
577
- }
578
- return true;
579
- },
580
- });
581
-
582
- if (!portInput) {
583
- return { success: false, error: 'Port is required' };
584
- }
585
-
586
- const containerPort = parseInt(portInput, 10);
587
-
588
- // Service exposure (not for Jobs)
589
- let includeService = false;
590
- let serviceType: K8sServiceType = 'ClusterIP';
591
- let servicePort = containerPort;
592
-
593
- if (!['job', 'cronjob'].includes(ctx.workloadType || '')) {
594
- ui.newLine();
595
- includeService = await confirm({
596
- message: 'Create a Service to expose this workload?',
597
- defaultValue: true,
598
- });
599
-
600
- if (includeService) {
601
- ui.newLine();
602
- serviceType =
603
- (await select<K8sServiceType>({
604
- message: 'Service type:',
605
- options: [
606
- {
607
- value: 'ClusterIP',
608
- label: 'ClusterIP',
609
- description: 'Internal cluster access only (default)',
610
- },
611
- {
612
- value: 'NodePort',
613
- label: 'NodePort',
614
- description: "Expose on each node's IP at a static port",
615
- },
616
- {
617
- value: 'LoadBalancer',
618
- label: 'LoadBalancer',
619
- description: 'External load balancer (cloud provider)',
620
- },
621
- ],
622
- defaultValue: ctx.serviceType || 'ClusterIP',
623
- })) || 'ClusterIP';
624
-
625
- const servicePortInput = await input({
626
- message: 'Service port:',
627
- defaultValue: String(ctx.servicePort || containerPort),
628
- validate: value => {
629
- const num = parseInt(value, 10);
630
- if (isNaN(num) || num < 1 || num > 65535) {
631
- return 'Must be between 1 and 65535';
632
- }
633
- return true;
634
- },
635
- });
636
- servicePort = parseInt(servicePortInput || String(containerPort), 10);
637
- }
638
- }
639
-
640
- return {
641
- success: true,
642
- data: {
643
- containerPort,
644
- includeService,
645
- serviceType,
646
- servicePort,
647
- },
648
- };
649
- }
650
-
651
- /**
652
- * Step 6: Resource Limits
653
- */
654
- async function resourceLimitsStep(ctx: K8sWizardContext): Promise<StepResult> {
655
- const setLimits = await confirm({
656
- message: 'Configure resource requests and limits? (recommended for production)',
657
- defaultValue: true,
658
- });
659
-
660
- if (!setLimits) {
661
- return { success: true, data: {} };
662
- }
663
-
664
- ui.newLine();
665
- ui.info('Resource requests (guaranteed resources):');
666
-
667
- const cpuRequest = await input({
668
- message: 'CPU request (e.g., 100m, 0.5):',
669
- defaultValue: ctx.cpuRequest || '100m',
670
- });
671
-
672
- const memoryRequest = await input({
673
- message: 'Memory request (e.g., 128Mi, 1Gi):',
674
- defaultValue: ctx.memoryRequest || '128Mi',
675
- });
676
-
677
- ui.newLine();
678
- ui.info('Resource limits (maximum allowed):');
679
-
680
- const cpuLimit = await input({
681
- message: 'CPU limit (e.g., 500m, 1):',
682
- defaultValue: ctx.cpuLimit || '500m',
683
- });
684
-
685
- const memoryLimit = await input({
686
- message: 'Memory limit (e.g., 256Mi, 2Gi):',
687
- defaultValue: ctx.memoryLimit || '256Mi',
688
- });
689
-
690
- return {
691
- success: true,
692
- data: {
693
- cpuRequest,
694
- cpuLimit,
695
- memoryRequest,
696
- memoryLimit,
697
- },
698
- };
699
- }
700
-
701
- /**
702
- * Step 7: Additional Resources
703
- */
704
- async function additionalResourcesStep(ctx: K8sWizardContext): Promise<StepResult> {
705
- const resourceOptions = [
706
- { value: 'configmap', label: 'ConfigMap', description: 'Environment configuration' },
707
- { value: 'secret', label: 'Secret', description: 'Sensitive data (passwords, tokens)' },
708
- ];
709
-
710
- // Only show Ingress for services
711
- if (ctx.includeService) {
712
- resourceOptions.push({
713
- value: 'ingress',
714
- label: 'Ingress',
715
- description: 'HTTP/HTTPS routing (requires ingress controller)',
716
- });
717
- }
718
-
719
- // Only show PDB for Deployments/StatefulSets
720
- if (['deployment', 'statefulset'].includes(ctx.workloadType || '')) {
721
- resourceOptions.push({
722
- value: 'pdb',
723
- label: 'PodDisruptionBudget',
724
- description: 'Ensure availability during disruptions',
725
- });
726
- }
727
-
728
- const selectedResources = (await multiSelect({
729
- message: 'Select additional resources to generate:',
730
- options: resourceOptions,
731
- required: false,
732
- })) as string[];
733
-
734
- const includeConfigMap = selectedResources.includes('configmap') || ctx.includeConfigMap;
735
- const includeSecret = selectedResources.includes('secret') || ctx.includeSecret;
736
- const includeIngress = selectedResources.includes('ingress') || ctx.includeIngress;
737
- const includePdb = selectedResources.includes('pdb') || ctx.includePdb;
738
-
739
- // Ingress configuration
740
- let ingressHost: string | undefined;
741
- let ingressPath: string | undefined;
742
- let ingressTls = false;
743
-
744
- if (includeIngress) {
745
- ui.newLine();
746
- ui.info('Ingress Configuration:');
747
-
748
- ingressHost = await input({
749
- message: 'Hostname (e.g., app.example.com):',
750
- defaultValue: ctx.ingressHost || `${ctx.name}.example.com`,
751
- });
752
-
753
- ingressPath = await input({
754
- message: 'Path:',
755
- defaultValue: ctx.ingressPath || '/',
756
- });
757
-
758
- ingressTls = await confirm({
759
- message: 'Enable TLS?',
760
- defaultValue: ctx.ingressTls ?? true,
761
- });
762
- }
763
-
764
- // PDB configuration
765
- let minAvailable: number | string | undefined;
766
-
767
- if (includePdb) {
768
- ui.newLine();
769
- const minAvailableInput = await input({
770
- message: 'Minimum available pods (number or percentage like "50%"):',
771
- defaultValue: String(ctx.minAvailable || 1),
772
- });
773
- minAvailable = minAvailableInput?.includes('%')
774
- ? minAvailableInput
775
- : parseInt(minAvailableInput || '1', 10);
776
- }
777
-
778
- return {
779
- success: true,
780
- data: {
781
- includeConfigMap,
782
- includeSecret,
783
- includeIngress,
784
- includePdb,
785
- ingressHost,
786
- ingressPath,
787
- ingressTls,
788
- minAvailable,
789
- },
790
- };
791
- }
792
-
793
- /**
794
- * Step 8: Health Checks
795
- */
796
- async function healthChecksStep(ctx: K8sWizardContext): Promise<StepResult> {
797
- const includeProbes = await confirm({
798
- message: 'Configure health check probes? (recommended for production)',
799
- defaultValue: true,
800
- });
801
-
802
- if (!includeProbes) {
803
- return { success: true, data: { includeProbes: false } };
804
- }
805
-
806
- ui.newLine();
807
- const livenessPath = await input({
808
- message: 'Liveness probe path (e.g., /healthz):',
809
- defaultValue: ctx.livenessPath || '/healthz',
810
- });
811
-
812
- const readinessPath = await input({
813
- message: 'Readiness probe path (e.g., /ready):',
814
- defaultValue: ctx.readinessPath || '/ready',
815
- });
816
-
817
- return {
818
- success: true,
819
- data: {
820
- includeProbes,
821
- livenessPath,
822
- readinessPath,
823
- },
824
- };
825
- }
826
-
827
- /**
828
- * Step 9: Output Configuration
829
- */
830
- async function outputConfigStep(ctx: K8sWizardContext): Promise<StepResult> {
831
- const outputFormat = await select<'multiple' | 'single' | 'kustomize'>({
832
- message: 'Output format:',
833
- options: [
834
- {
835
- value: 'multiple',
836
- label: 'Multiple files',
837
- description: 'One file per resource (deployment.yaml, service.yaml, etc.)',
838
- },
839
- {
840
- value: 'single',
841
- label: 'Single file',
842
- description: 'All resources in one file with document separators',
843
- },
844
- {
845
- value: 'kustomize',
846
- label: 'Kustomize structure',
847
- description: 'Base with kustomization.yaml for overlays',
848
- },
849
- ],
850
- defaultValue: ctx.outputFormat || 'multiple',
851
- });
852
-
853
- ui.newLine();
854
- const outputPath = await pathInput('Output directory:', ctx.outputPath || `./${ctx.name}-k8s`);
855
-
856
- if (!outputPath) {
857
- return { success: false, error: 'Output path is required' };
858
- }
859
-
860
- return {
861
- success: true,
862
- data: {
863
- outputFormat,
864
- outputPath,
865
- },
866
- };
867
- }
868
-
869
- /**
870
- * Step 10: Generate Manifests
871
- */
872
- async function generateStep(ctx: K8sWizardContext): Promise<StepResult> {
873
- ui.startSpinner({ message: 'Generating Kubernetes manifests...' });
874
-
875
- try {
876
- // Generate manifests locally using built-in generator
877
- const files = generateManifestsLocally(ctx);
878
- await writeFilesToDisk(files, ctx.outputPath!);
879
-
880
- ui.stopSpinnerSuccess(`Generated ${files.length} manifest(s)`);
881
-
882
- return {
883
- success: true,
884
- data: {
885
- generatedFiles: files.map(f => f.path),
886
- },
887
- };
888
- } catch (error: any) {
889
- return {
890
- success: false,
891
- error: error.message,
892
- };
893
- }
894
- }
895
-
896
- /**
897
- * Build the generation request from context
898
- */
899
- function buildGenerationRequest(ctx: K8sWizardContext): Record<string, unknown> {
900
- return {
901
- workloadType: ctx.workloadType,
902
- name: ctx.name,
903
- namespace: ctx.namespace,
904
- image: ctx.image,
905
- imageTag: ctx.imageTag,
906
- replicas: ctx.replicas,
907
- containerPort: ctx.containerPort,
908
- serviceType: ctx.serviceType,
909
- servicePort: ctx.servicePort,
910
- cpuRequest: ctx.cpuRequest,
911
- cpuLimit: ctx.cpuLimit,
912
- memoryRequest: ctx.memoryRequest,
913
- memoryLimit: ctx.memoryLimit,
914
- includeService: ctx.includeService,
915
- includeIngress: ctx.includeIngress,
916
- includeHpa: ctx.includeHpa,
917
- includePdb: ctx.includePdb,
918
- includeConfigMap: ctx.includeConfigMap,
919
- includeSecret: ctx.includeSecret,
920
- includeProbes: ctx.includeProbes,
921
- livenessPath: ctx.livenessPath,
922
- readinessPath: ctx.readinessPath,
923
- ingressHost: ctx.ingressHost,
924
- ingressPath: ctx.ingressPath,
925
- ingressTls: ctx.ingressTls,
926
- minAvailable: ctx.minAvailable,
927
- minReplicas: ctx.minReplicas,
928
- maxReplicas: ctx.maxReplicas,
929
- targetCPUUtilization: ctx.targetCPUUtilization,
930
- schedule: ctx.schedule,
931
- backoffLimit: ctx.backoffLimit,
932
- completions: ctx.completions,
933
- parallelism: ctx.parallelism,
934
- outputFormat: ctx.outputFormat,
935
- outputPath: ctx.outputPath,
936
- };
937
- }
938
-
939
- /**
940
- * Generate manifests locally when service is unavailable
941
- */
942
- function generateManifestsLocally(
943
- ctx: K8sWizardContext
944
- ): Array<{ name: string; content: string; path: string }> {
945
- const files: Array<{ name: string; content: string; path: string }> = [];
946
- const labels: Record<string, string> = {
947
- 'app.kubernetes.io/name': ctx.name || 'unnamed',
948
- 'app.kubernetes.io/instance': ctx.name || 'unnamed',
949
- 'app.kubernetes.io/managed-by': 'nimbus',
950
- };
951
-
952
- // Generate main workload
953
- const workloadManifest = generateWorkloadManifest(ctx, labels);
954
- files.push({
955
- name: `${ctx.workloadType}.yaml`,
956
- content: workloadManifest,
957
- path: `${ctx.outputPath}/${ctx.workloadType}.yaml`,
958
- });
959
-
960
- // Generate Service
961
- if (ctx.includeService) {
962
- files.push({
963
- name: 'service.yaml',
964
- content: generateServiceManifest(ctx, labels),
965
- path: `${ctx.outputPath}/service.yaml`,
966
- });
967
- }
968
-
969
- // Generate Ingress
970
- if (ctx.includeIngress) {
971
- files.push({
972
- name: 'ingress.yaml',
973
- content: generateIngressManifest(ctx, labels),
974
- path: `${ctx.outputPath}/ingress.yaml`,
975
- });
976
- }
977
-
978
- // Generate HPA
979
- if (ctx.includeHpa) {
980
- files.push({
981
- name: 'hpa.yaml',
982
- content: generateHpaManifest(ctx, labels),
983
- path: `${ctx.outputPath}/hpa.yaml`,
984
- });
985
- }
986
-
987
- // Generate PDB
988
- if (ctx.includePdb) {
989
- files.push({
990
- name: 'pdb.yaml',
991
- content: generatePdbManifest(ctx, labels),
992
- path: `${ctx.outputPath}/pdb.yaml`,
993
- });
994
- }
995
-
996
- // Generate ConfigMap
997
- if (ctx.includeConfigMap) {
998
- files.push({
999
- name: 'configmap.yaml',
1000
- content: generateConfigMapManifest(ctx, labels),
1001
- path: `${ctx.outputPath}/configmap.yaml`,
1002
- });
1003
- }
1004
-
1005
- // Generate Secret
1006
- if (ctx.includeSecret) {
1007
- files.push({
1008
- name: 'secret.yaml',
1009
- content: generateSecretManifest(ctx, labels),
1010
- path: `${ctx.outputPath}/secret.yaml`,
1011
- });
1012
- }
1013
-
1014
- return files;
1015
- }
1016
-
1017
- /**
1018
- * Generate main workload manifest
1019
- */
1020
- function generateWorkloadManifest(ctx: K8sWizardContext, labels: Record<string, string>): string {
1021
- const { workloadType, name, namespace, image, imageTag, replicas, containerPort } = ctx;
1022
-
1023
- // Build container spec
1024
- const containerSpec: Record<string, unknown> = {
1025
- name,
1026
- image: `${image}:${imageTag || 'latest'}`,
1027
- ports: containerPort ? [{ containerPort }] : undefined,
1028
- resources:
1029
- ctx.cpuRequest || ctx.memoryRequest
1030
- ? {
1031
- requests: {
1032
- ...(ctx.cpuRequest && { cpu: ctx.cpuRequest }),
1033
- ...(ctx.memoryRequest && { memory: ctx.memoryRequest }),
1034
- },
1035
- limits: {
1036
- ...(ctx.cpuLimit && { cpu: ctx.cpuLimit }),
1037
- ...(ctx.memoryLimit && { memory: ctx.memoryLimit }),
1038
- },
1039
- }
1040
- : undefined,
1041
- };
1042
-
1043
- // Add probes if configured
1044
- if (ctx.includeProbes) {
1045
- containerSpec.livenessProbe = {
1046
- httpGet: {
1047
- path: ctx.livenessPath || '/healthz',
1048
- port: containerPort,
1049
- },
1050
- initialDelaySeconds: 10,
1051
- periodSeconds: 10,
1052
- };
1053
- containerSpec.readinessProbe = {
1054
- httpGet: {
1055
- path: ctx.readinessPath || '/ready',
1056
- port: containerPort,
1057
- },
1058
- initialDelaySeconds: 5,
1059
- periodSeconds: 5,
1060
- };
1061
- }
1062
-
1063
- // Add envFrom if ConfigMap or Secret
1064
- const envFrom = [];
1065
- if (ctx.includeConfigMap) {
1066
- envFrom.push({ configMapRef: { name: `${name}-config` } });
1067
- }
1068
- if (ctx.includeSecret) {
1069
- envFrom.push({ secretRef: { name: `${name}-secret` } });
1070
- }
1071
- if (envFrom.length > 0) {
1072
- containerSpec.envFrom = envFrom;
1073
- }
1074
-
1075
- // Clean up undefined values
1076
- Object.keys(containerSpec).forEach(key => {
1077
- if (containerSpec[key] === undefined) {
1078
- delete containerSpec[key];
1079
- }
1080
- });
1081
-
1082
- const podSpec = {
1083
- containers: [containerSpec],
1084
- };
1085
-
1086
- let manifest: Record<string, unknown>;
1087
-
1088
- switch (workloadType) {
1089
- case 'deployment':
1090
- manifest = {
1091
- apiVersion: 'apps/v1',
1092
- kind: 'Deployment',
1093
- metadata: { name, namespace, labels },
1094
- spec: {
1095
- replicas,
1096
- selector: { matchLabels: { 'app.kubernetes.io/name': name } },
1097
- template: {
1098
- metadata: { labels },
1099
- spec: podSpec,
1100
- },
1101
- },
1102
- };
1103
- break;
1104
-
1105
- case 'statefulset':
1106
- manifest = {
1107
- apiVersion: 'apps/v1',
1108
- kind: 'StatefulSet',
1109
- metadata: { name, namespace, labels },
1110
- spec: {
1111
- replicas,
1112
- serviceName: name,
1113
- selector: { matchLabels: { 'app.kubernetes.io/name': name } },
1114
- template: {
1115
- metadata: { labels },
1116
- spec: podSpec,
1117
- },
1118
- },
1119
- };
1120
- break;
1121
-
1122
- case 'daemonset':
1123
- manifest = {
1124
- apiVersion: 'apps/v1',
1125
- kind: 'DaemonSet',
1126
- metadata: { name, namespace, labels },
1127
- spec: {
1128
- selector: { matchLabels: { 'app.kubernetes.io/name': name } },
1129
- template: {
1130
- metadata: { labels },
1131
- spec: podSpec,
1132
- },
1133
- },
1134
- };
1135
- break;
1136
-
1137
- case 'job':
1138
- manifest = {
1139
- apiVersion: 'batch/v1',
1140
- kind: 'Job',
1141
- metadata: { name, namespace, labels },
1142
- spec: {
1143
- backoffLimit: ctx.backoffLimit,
1144
- completions: ctx.completions,
1145
- parallelism: ctx.parallelism,
1146
- template: {
1147
- metadata: { labels },
1148
- spec: {
1149
- ...podSpec,
1150
- restartPolicy: 'Never',
1151
- },
1152
- },
1153
- },
1154
- };
1155
- break;
1156
-
1157
- case 'cronjob':
1158
- manifest = {
1159
- apiVersion: 'batch/v1',
1160
- kind: 'CronJob',
1161
- metadata: { name, namespace, labels },
1162
- spec: {
1163
- schedule: ctx.schedule,
1164
- jobTemplate: {
1165
- spec: {
1166
- backoffLimit: ctx.backoffLimit,
1167
- template: {
1168
- metadata: { labels },
1169
- spec: {
1170
- ...podSpec,
1171
- restartPolicy: 'Never',
1172
- },
1173
- },
1174
- },
1175
- },
1176
- },
1177
- };
1178
- break;
1179
-
1180
- default:
1181
- manifest = {};
1182
- }
1183
-
1184
- return toYaml(manifest);
1185
- }
1186
-
1187
- /**
1188
- * Generate Service manifest
1189
- */
1190
- function generateServiceManifest(ctx: K8sWizardContext, labels: Record<string, string>): string {
1191
- const manifest = {
1192
- apiVersion: 'v1',
1193
- kind: 'Service',
1194
- metadata: {
1195
- name: ctx.name,
1196
- namespace: ctx.namespace,
1197
- labels,
1198
- },
1199
- spec: {
1200
- type: ctx.serviceType,
1201
- selector: { 'app.kubernetes.io/name': ctx.name },
1202
- ports: [
1203
- {
1204
- port: ctx.servicePort,
1205
- targetPort: ctx.containerPort,
1206
- protocol: 'TCP',
1207
- },
1208
- ],
1209
- },
1210
- };
1211
-
1212
- return toYaml(manifest);
1213
- }
1214
-
1215
- /**
1216
- * Generate Ingress manifest
1217
- */
1218
- function generateIngressManifest(ctx: K8sWizardContext, labels: Record<string, string>): string {
1219
- const manifest: Record<string, unknown> = {
1220
- apiVersion: 'networking.k8s.io/v1',
1221
- kind: 'Ingress',
1222
- metadata: {
1223
- name: ctx.name,
1224
- namespace: ctx.namespace,
1225
- labels,
1226
- annotations: {
1227
- 'kubernetes.io/ingress.class': 'nginx',
1228
- },
1229
- },
1230
- spec: {
1231
- rules: [
1232
- {
1233
- host: ctx.ingressHost,
1234
- http: {
1235
- paths: [
1236
- {
1237
- path: ctx.ingressPath || '/',
1238
- pathType: 'Prefix',
1239
- backend: {
1240
- service: {
1241
- name: ctx.name,
1242
- port: { number: ctx.servicePort },
1243
- },
1244
- },
1245
- },
1246
- ],
1247
- },
1248
- },
1249
- ],
1250
- },
1251
- };
1252
-
1253
- if (ctx.ingressTls) {
1254
- (manifest.spec as Record<string, unknown>).tls = [
1255
- {
1256
- hosts: [ctx.ingressHost],
1257
- secretName: `${ctx.name}-tls`,
1258
- },
1259
- ];
1260
- }
1261
-
1262
- return toYaml(manifest);
1263
- }
1264
-
1265
- /**
1266
- * Generate HPA manifest
1267
- */
1268
- function generateHpaManifest(ctx: K8sWizardContext, labels: Record<string, string>): string {
1269
- const manifest = {
1270
- apiVersion: 'autoscaling/v2',
1271
- kind: 'HorizontalPodAutoscaler',
1272
- metadata: {
1273
- name: ctx.name,
1274
- namespace: ctx.namespace,
1275
- labels,
1276
- },
1277
- spec: {
1278
- scaleTargetRef: {
1279
- apiVersion: 'apps/v1',
1280
- kind: ctx.workloadType === 'statefulset' ? 'StatefulSet' : 'Deployment',
1281
- name: ctx.name,
1282
- },
1283
- minReplicas: ctx.minReplicas,
1284
- maxReplicas: ctx.maxReplicas,
1285
- metrics: [
1286
- {
1287
- type: 'Resource',
1288
- resource: {
1289
- name: 'cpu',
1290
- target: {
1291
- type: 'Utilization',
1292
- averageUtilization: ctx.targetCPUUtilization,
1293
- },
1294
- },
1295
- },
1296
- ],
1297
- },
1298
- };
1299
-
1300
- return toYaml(manifest);
1301
- }
1302
-
1303
- /**
1304
- * Generate PDB manifest
1305
- */
1306
- function generatePdbManifest(ctx: K8sWizardContext, labels: Record<string, string>): string {
1307
- const manifest = {
1308
- apiVersion: 'policy/v1',
1309
- kind: 'PodDisruptionBudget',
1310
- metadata: {
1311
- name: ctx.name,
1312
- namespace: ctx.namespace,
1313
- labels,
1314
- },
1315
- spec: {
1316
- minAvailable: ctx.minAvailable,
1317
- selector: { matchLabels: { 'app.kubernetes.io/name': ctx.name } },
1318
- },
1319
- };
1320
-
1321
- return toYaml(manifest);
1322
- }
1323
-
1324
- /**
1325
- * Generate ConfigMap manifest
1326
- */
1327
- function generateConfigMapManifest(ctx: K8sWizardContext, labels: Record<string, string>): string {
1328
- const manifest = {
1329
- apiVersion: 'v1',
1330
- kind: 'ConfigMap',
1331
- metadata: {
1332
- name: `${ctx.name}-config`,
1333
- namespace: ctx.namespace,
1334
- labels,
1335
- },
1336
- data: {
1337
- // Placeholder values - user should customize
1338
- APP_ENV: 'production',
1339
- LOG_LEVEL: 'info',
1340
- },
1341
- };
1342
-
1343
- return toYaml(manifest);
1344
- }
1345
-
1346
- /**
1347
- * Generate Secret manifest
1348
- */
1349
- function generateSecretManifest(ctx: K8sWizardContext, labels: Record<string, string>): string {
1350
- const manifest = {
1351
- apiVersion: 'v1',
1352
- kind: 'Secret',
1353
- metadata: {
1354
- name: `${ctx.name}-secret`,
1355
- namespace: ctx.namespace,
1356
- labels,
1357
- },
1358
- type: 'Opaque',
1359
- stringData: {
1360
- // Placeholder values - user should customize
1361
- 'example-key': 'example-value',
1362
- },
1363
- };
1364
-
1365
- return toYaml(manifest);
1366
- }
1367
-
1368
- /**
1369
- * Convert object to YAML string
1370
- */
1371
- function toYaml(obj: Record<string, unknown>, indent = 0): string {
1372
- const lines: string[] = [];
1373
- const spaces = ' '.repeat(indent);
1374
-
1375
- for (const [key, value] of Object.entries(obj)) {
1376
- if (value === undefined || value === null) {
1377
- continue;
1378
- }
1379
-
1380
- if (Array.isArray(value)) {
1381
- if (value.length === 0) {
1382
- continue;
1383
- }
1384
- lines.push(`${spaces}${key}:`);
1385
- for (const item of value) {
1386
- if (typeof item === 'object' && item !== null) {
1387
- const itemYaml = toYaml(item as Record<string, unknown>, indent + 1);
1388
- const itemLines = itemYaml.split('\n').filter(l => l.trim());
1389
- lines.push(`${spaces}- ${itemLines[0].trim()}`);
1390
- for (let i = 1; i < itemLines.length; i++) {
1391
- lines.push(`${spaces} ${itemLines[i].trim()}`);
1392
- }
1393
- } else {
1394
- lines.push(`${spaces}- ${item}`);
1395
- }
1396
- }
1397
- } else if (typeof value === 'object') {
1398
- lines.push(`${spaces}${key}:`);
1399
- lines.push(toYaml(value as Record<string, unknown>, indent + 1));
1400
- } else if (
1401
- typeof value === 'string' &&
1402
- (value.includes(':') || value.includes('#') || value.includes('\n'))
1403
- ) {
1404
- lines.push(`${spaces}${key}: "${value}"`);
1405
- } else {
1406
- lines.push(`${spaces}${key}: ${value}`);
1407
- }
1408
- }
1409
-
1410
- return lines.join('\n');
1411
- }
1412
-
1413
- /**
1414
- * Write files to disk
1415
- */
1416
- async function writeFilesToDisk(
1417
- files: Array<{ name: string; content: string; path: string }>,
1418
- outputPath: string
1419
- ): Promise<void> {
1420
- const fs = await import('fs/promises');
1421
- const path = await import('path');
1422
-
1423
- // Create output directory
1424
- await fs.mkdir(outputPath, { recursive: true });
1425
-
1426
- // Write each file
1427
- for (const file of files) {
1428
- const filePath = path.join(outputPath, file.name);
1429
- await fs.writeFile(filePath, file.content, 'utf-8');
1430
- }
1431
- }
1432
-
1433
- /**
1434
- * Run in non-interactive mode
1435
- */
1436
- async function runNonInteractive(options: GenerateK8sOptions): Promise<void> {
1437
- ui.header('nimbus generate k8s', 'Non-interactive mode');
1438
-
1439
- // Validate required options
1440
- if (!options.name) {
1441
- ui.error('Name is required in non-interactive mode (--name)');
1442
- process.exit(1);
1443
- }
1444
-
1445
- if (!options.image) {
1446
- ui.error('Image is required in non-interactive mode (--image)');
1447
- process.exit(1);
1448
- }
1449
-
1450
- ui.info(`Workload type: ${options.workloadType || 'deployment'}`);
1451
- ui.info(`Name: ${options.name}`);
1452
- ui.info(`Namespace: ${options.namespace || 'default'}`);
1453
- ui.info(`Image: ${options.image}`);
1454
- ui.info(`Output: ${options.output || `./${options.name}-k8s`}`);
1455
-
1456
- // Build context from options
1457
- const ctx: K8sWizardContext = {
1458
- workloadType: options.workloadType || 'deployment',
1459
- name: options.name,
1460
- namespace: options.namespace || 'default',
1461
- image: options.image.split(':')[0],
1462
- imageTag: options.image.split(':')[1] || 'latest',
1463
- replicas: options.replicas ?? 2,
1464
- containerPort: options.port ?? 8080,
1465
- serviceType: options.serviceType || 'ClusterIP',
1466
- includeService: true,
1467
- includeIngress: options.includeIngress ?? false,
1468
- includeHpa: options.includeHpa ?? false,
1469
- includePdb: options.includePdb ?? false,
1470
- includeConfigMap: options.includeConfigMap ?? false,
1471
- includeSecret: options.includeSecret ?? false,
1472
- cpuRequest: options.cpuRequest,
1473
- cpuLimit: options.cpuLimit,
1474
- memoryRequest: options.memoryRequest,
1475
- memoryLimit: options.memoryLimit,
1476
- outputPath: options.output || `./${options.name}-k8s`,
1477
- outputFormat: 'multiple',
1478
- };
1479
-
1480
- ui.newLine();
1481
- ui.startSpinner({ message: 'Generating manifests...' });
1482
-
1483
- try {
1484
- const files = generateManifestsLocally(ctx);
1485
- await writeFilesToDisk(files, ctx.outputPath!);
1486
-
1487
- ui.stopSpinnerSuccess(`Generated ${files.length} manifest(s)`);
1488
-
1489
- ui.newLine();
1490
- ui.box({
1491
- title: 'Complete!',
1492
- content: [
1493
- `Generated ${files.length} manifest(s) in ${ctx.outputPath}:`,
1494
- ...files.map(f => ` - ${f.name}`),
1495
- ],
1496
- style: 'rounded',
1497
- borderColor: 'green',
1498
- padding: 1,
1499
- });
1500
- } catch (error: any) {
1501
- ui.stopSpinnerFail('Generation failed');
1502
- ui.error(error.message);
1503
- process.exit(1);
1504
- }
1505
- }
1506
-
1507
- // Export as default command
1508
- export default generateK8sCommand;