@build-astron-co/nimbus 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (313) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +628 -0
  3. package/bin/nimbus +38 -0
  4. package/package.json +80 -0
  5. package/src/__tests__/app.test.ts +76 -0
  6. package/src/__tests__/audit.test.ts +877 -0
  7. package/src/__tests__/circuit-breaker.test.ts +116 -0
  8. package/src/__tests__/cli-run.test.ts +115 -0
  9. package/src/__tests__/context-manager.test.ts +502 -0
  10. package/src/__tests__/context.test.ts +242 -0
  11. package/src/__tests__/enterprise.test.ts +401 -0
  12. package/src/__tests__/generator.test.ts +433 -0
  13. package/src/__tests__/hooks.test.ts +582 -0
  14. package/src/__tests__/init.test.ts +436 -0
  15. package/src/__tests__/intent-parser.test.ts +229 -0
  16. package/src/__tests__/llm-router.test.ts +209 -0
  17. package/src/__tests__/lsp.test.ts +293 -0
  18. package/src/__tests__/modes.test.ts +336 -0
  19. package/src/__tests__/permissions.test.ts +338 -0
  20. package/src/__tests__/serve.test.ts +275 -0
  21. package/src/__tests__/sessions.test.ts +227 -0
  22. package/src/__tests__/sharing.test.ts +288 -0
  23. package/src/__tests__/snapshots.test.ts +581 -0
  24. package/src/__tests__/state-db.test.ts +334 -0
  25. package/src/__tests__/stream-with-tools.test.ts +732 -0
  26. package/src/__tests__/subagents.test.ts +176 -0
  27. package/src/__tests__/system-prompt.test.ts +169 -0
  28. package/src/__tests__/tool-converter.test.ts +256 -0
  29. package/src/__tests__/tool-schemas.test.ts +397 -0
  30. package/src/__tests__/tools.test.ts +143 -0
  31. package/src/__tests__/version.test.ts +49 -0
  32. package/src/agent/compaction-agent.ts +227 -0
  33. package/src/agent/context-manager.ts +435 -0
  34. package/src/agent/context.ts +427 -0
  35. package/src/agent/deploy-preview.ts +426 -0
  36. package/src/agent/index.ts +68 -0
  37. package/src/agent/loop.ts +717 -0
  38. package/src/agent/modes.ts +429 -0
  39. package/src/agent/permissions.ts +466 -0
  40. package/src/agent/subagents/base.ts +116 -0
  41. package/src/agent/subagents/cost.ts +51 -0
  42. package/src/agent/subagents/explore.ts +42 -0
  43. package/src/agent/subagents/general.ts +54 -0
  44. package/src/agent/subagents/index.ts +102 -0
  45. package/src/agent/subagents/infra.ts +59 -0
  46. package/src/agent/subagents/security.ts +69 -0
  47. package/src/agent/system-prompt.ts +436 -0
  48. package/src/app.ts +122 -0
  49. package/src/audit/activity-log.ts +290 -0
  50. package/src/audit/compliance-checker.ts +540 -0
  51. package/src/audit/cost-tracker.ts +318 -0
  52. package/src/audit/index.ts +23 -0
  53. package/src/audit/security-scanner.ts +596 -0
  54. package/src/auth/guard.ts +75 -0
  55. package/src/auth/index.ts +56 -0
  56. package/src/auth/oauth.ts +455 -0
  57. package/src/auth/providers.ts +470 -0
  58. package/src/auth/sso.ts +113 -0
  59. package/src/auth/store.ts +505 -0
  60. package/src/auth/types.ts +187 -0
  61. package/src/build.ts +141 -0
  62. package/src/cli/index.ts +16 -0
  63. package/src/cli/init.ts +854 -0
  64. package/src/cli/openapi-spec.ts +356 -0
  65. package/src/cli/run.ts +237 -0
  66. package/src/cli/serve-auth.ts +80 -0
  67. package/src/cli/serve.ts +462 -0
  68. package/src/cli/web.ts +67 -0
  69. package/src/cli.ts +1417 -0
  70. package/src/clients/core-engine-client.ts +227 -0
  71. package/src/clients/enterprise-client.ts +334 -0
  72. package/src/clients/generator-client.ts +351 -0
  73. package/src/clients/git-client.ts +627 -0
  74. package/src/clients/github-client.ts +410 -0
  75. package/src/clients/helm-client.ts +504 -0
  76. package/src/clients/index.ts +80 -0
  77. package/src/clients/k8s-client.ts +497 -0
  78. package/src/clients/llm-client.ts +161 -0
  79. package/src/clients/rest-client.ts +130 -0
  80. package/src/clients/service-discovery.ts +33 -0
  81. package/src/clients/terraform-client.ts +482 -0
  82. package/src/clients/tools-client.ts +1843 -0
  83. package/src/clients/ws-client.ts +115 -0
  84. package/src/commands/analyze/index.ts +352 -0
  85. package/src/commands/apply/helm.ts +473 -0
  86. package/src/commands/apply/index.ts +213 -0
  87. package/src/commands/apply/k8s.ts +454 -0
  88. package/src/commands/apply/terraform.ts +582 -0
  89. package/src/commands/ask.ts +167 -0
  90. package/src/commands/audit/index.ts +238 -0
  91. package/src/commands/auth-cloud.ts +294 -0
  92. package/src/commands/auth-list.ts +134 -0
  93. package/src/commands/auth-profile.ts +121 -0
  94. package/src/commands/auth-status.ts +141 -0
  95. package/src/commands/aws/ec2.ts +501 -0
  96. package/src/commands/aws/iam.ts +397 -0
  97. package/src/commands/aws/index.ts +133 -0
  98. package/src/commands/aws/lambda.ts +396 -0
  99. package/src/commands/aws/rds.ts +439 -0
  100. package/src/commands/aws/s3.ts +439 -0
  101. package/src/commands/aws/vpc.ts +393 -0
  102. package/src/commands/aws-discover.ts +649 -0
  103. package/src/commands/aws-terraform.ts +805 -0
  104. package/src/commands/azure/aks.ts +376 -0
  105. package/src/commands/azure/functions.ts +253 -0
  106. package/src/commands/azure/index.ts +116 -0
  107. package/src/commands/azure/storage.ts +478 -0
  108. package/src/commands/azure/vm.ts +355 -0
  109. package/src/commands/billing/index.ts +256 -0
  110. package/src/commands/chat.ts +314 -0
  111. package/src/commands/config.ts +346 -0
  112. package/src/commands/cost/cloud-cost-estimator.ts +266 -0
  113. package/src/commands/cost/estimator.ts +79 -0
  114. package/src/commands/cost/index.ts +594 -0
  115. package/src/commands/cost/parsers/terraform.ts +273 -0
  116. package/src/commands/cost/parsers/types.ts +25 -0
  117. package/src/commands/cost/pricing/aws.ts +544 -0
  118. package/src/commands/cost/pricing/azure.ts +499 -0
  119. package/src/commands/cost/pricing/gcp.ts +396 -0
  120. package/src/commands/cost/pricing/index.ts +40 -0
  121. package/src/commands/demo.ts +250 -0
  122. package/src/commands/doctor.ts +794 -0
  123. package/src/commands/drift/index.ts +439 -0
  124. package/src/commands/explain.ts +277 -0
  125. package/src/commands/feedback.ts +389 -0
  126. package/src/commands/fix.ts +324 -0
  127. package/src/commands/fs/index.ts +402 -0
  128. package/src/commands/gcp/compute.ts +325 -0
  129. package/src/commands/gcp/functions.ts +271 -0
  130. package/src/commands/gcp/gke.ts +438 -0
  131. package/src/commands/gcp/iam.ts +344 -0
  132. package/src/commands/gcp/index.ts +129 -0
  133. package/src/commands/gcp/storage.ts +284 -0
  134. package/src/commands/generate-helm.ts +1249 -0
  135. package/src/commands/generate-k8s.ts +1560 -0
  136. package/src/commands/generate-terraform.ts +1460 -0
  137. package/src/commands/gh/index.ts +863 -0
  138. package/src/commands/git/index.ts +1343 -0
  139. package/src/commands/helm/index.ts +1126 -0
  140. package/src/commands/help.ts +539 -0
  141. package/src/commands/history.ts +142 -0
  142. package/src/commands/import.ts +868 -0
  143. package/src/commands/index.ts +367 -0
  144. package/src/commands/init.ts +1046 -0
  145. package/src/commands/k8s/index.ts +1137 -0
  146. package/src/commands/login.ts +631 -0
  147. package/src/commands/logout.ts +83 -0
  148. package/src/commands/onboarding.ts +228 -0
  149. package/src/commands/plan/display.ts +279 -0
  150. package/src/commands/plan/index.ts +599 -0
  151. package/src/commands/preview.ts +452 -0
  152. package/src/commands/questionnaire.ts +1270 -0
  153. package/src/commands/resume.ts +55 -0
  154. package/src/commands/team/index.ts +346 -0
  155. package/src/commands/template.ts +232 -0
  156. package/src/commands/tf/index.ts +1034 -0
  157. package/src/commands/upgrade.ts +550 -0
  158. package/src/commands/usage/index.ts +134 -0
  159. package/src/commands/version.ts +170 -0
  160. package/src/compat/index.ts +2 -0
  161. package/src/compat/runtime.ts +12 -0
  162. package/src/compat/sqlite.ts +107 -0
  163. package/src/config/index.ts +17 -0
  164. package/src/config/manager.ts +530 -0
  165. package/src/config/safety-policy.ts +358 -0
  166. package/src/config/schema.ts +125 -0
  167. package/src/config/types.ts +527 -0
  168. package/src/context/context-db.ts +199 -0
  169. package/src/demo/index.ts +349 -0
  170. package/src/demo/scenarios/full-journey.ts +229 -0
  171. package/src/demo/scenarios/getting-started.ts +127 -0
  172. package/src/demo/scenarios/helm-release.ts +341 -0
  173. package/src/demo/scenarios/k8s-deployment.ts +194 -0
  174. package/src/demo/scenarios/terraform-vpc.ts +170 -0
  175. package/src/demo/types.ts +92 -0
  176. package/src/engine/cost-estimator.ts +438 -0
  177. package/src/engine/diagram-generator.ts +256 -0
  178. package/src/engine/drift-detector.ts +902 -0
  179. package/src/engine/executor.ts +1035 -0
  180. package/src/engine/index.ts +76 -0
  181. package/src/engine/orchestrator.ts +636 -0
  182. package/src/engine/planner.ts +720 -0
  183. package/src/engine/safety.ts +743 -0
  184. package/src/engine/verifier.ts +770 -0
  185. package/src/enterprise/audit.ts +348 -0
  186. package/src/enterprise/auth.ts +270 -0
  187. package/src/enterprise/billing.ts +822 -0
  188. package/src/enterprise/index.ts +17 -0
  189. package/src/enterprise/teams.ts +443 -0
  190. package/src/generator/best-practices.ts +1608 -0
  191. package/src/generator/helm.ts +630 -0
  192. package/src/generator/index.ts +37 -0
  193. package/src/generator/intent-parser.ts +514 -0
  194. package/src/generator/kubernetes.ts +976 -0
  195. package/src/generator/terraform.ts +1867 -0
  196. package/src/history/index.ts +8 -0
  197. package/src/history/manager.ts +322 -0
  198. package/src/history/types.ts +34 -0
  199. package/src/hooks/config.ts +432 -0
  200. package/src/hooks/engine.ts +391 -0
  201. package/src/hooks/index.ts +4 -0
  202. package/src/llm/auth-bridge.ts +198 -0
  203. package/src/llm/circuit-breaker.ts +140 -0
  204. package/src/llm/config-loader.ts +201 -0
  205. package/src/llm/cost-calculator.ts +171 -0
  206. package/src/llm/index.ts +8 -0
  207. package/src/llm/model-aliases.ts +115 -0
  208. package/src/llm/provider-registry.ts +63 -0
  209. package/src/llm/providers/anthropic.ts +433 -0
  210. package/src/llm/providers/bedrock.ts +477 -0
  211. package/src/llm/providers/google.ts +405 -0
  212. package/src/llm/providers/ollama.ts +767 -0
  213. package/src/llm/providers/openai-compatible.ts +340 -0
  214. package/src/llm/providers/openai.ts +328 -0
  215. package/src/llm/providers/openrouter.ts +338 -0
  216. package/src/llm/router.ts +1035 -0
  217. package/src/llm/types.ts +232 -0
  218. package/src/lsp/client.ts +298 -0
  219. package/src/lsp/languages.ts +116 -0
  220. package/src/lsp/manager.ts +278 -0
  221. package/src/mcp/client.ts +402 -0
  222. package/src/mcp/index.ts +5 -0
  223. package/src/mcp/manager.ts +133 -0
  224. package/src/nimbus.ts +214 -0
  225. package/src/plugins/index.ts +27 -0
  226. package/src/plugins/loader.ts +334 -0
  227. package/src/plugins/manager.ts +376 -0
  228. package/src/plugins/types.ts +284 -0
  229. package/src/scanners/cicd-scanner.ts +258 -0
  230. package/src/scanners/cloud-scanner.ts +466 -0
  231. package/src/scanners/framework-scanner.ts +469 -0
  232. package/src/scanners/iac-scanner.ts +388 -0
  233. package/src/scanners/index.ts +539 -0
  234. package/src/scanners/language-scanner.ts +276 -0
  235. package/src/scanners/package-manager-scanner.ts +277 -0
  236. package/src/scanners/types.ts +172 -0
  237. package/src/sessions/manager.ts +365 -0
  238. package/src/sessions/types.ts +44 -0
  239. package/src/sharing/sync.ts +296 -0
  240. package/src/sharing/viewer.ts +97 -0
  241. package/src/snapshots/index.ts +2 -0
  242. package/src/snapshots/manager.ts +530 -0
  243. package/src/state/artifacts.ts +147 -0
  244. package/src/state/audit.ts +137 -0
  245. package/src/state/billing.ts +240 -0
  246. package/src/state/checkpoints.ts +117 -0
  247. package/src/state/config.ts +67 -0
  248. package/src/state/conversations.ts +14 -0
  249. package/src/state/credentials.ts +154 -0
  250. package/src/state/db.ts +58 -0
  251. package/src/state/index.ts +26 -0
  252. package/src/state/messages.ts +115 -0
  253. package/src/state/projects.ts +123 -0
  254. package/src/state/schema.ts +236 -0
  255. package/src/state/sessions.ts +147 -0
  256. package/src/state/teams.ts +200 -0
  257. package/src/telemetry.ts +108 -0
  258. package/src/tools/aws-ops.ts +952 -0
  259. package/src/tools/azure-ops.ts +579 -0
  260. package/src/tools/file-ops.ts +593 -0
  261. package/src/tools/gcp-ops.ts +625 -0
  262. package/src/tools/git-ops.ts +773 -0
  263. package/src/tools/github-ops.ts +799 -0
  264. package/src/tools/helm-ops.ts +943 -0
  265. package/src/tools/index.ts +17 -0
  266. package/src/tools/k8s-ops.ts +819 -0
  267. package/src/tools/schemas/converter.ts +184 -0
  268. package/src/tools/schemas/devops.ts +612 -0
  269. package/src/tools/schemas/index.ts +73 -0
  270. package/src/tools/schemas/standard.ts +1144 -0
  271. package/src/tools/schemas/types.ts +705 -0
  272. package/src/tools/terraform-ops.ts +862 -0
  273. package/src/types/ambient.d.ts +193 -0
  274. package/src/types/config.ts +83 -0
  275. package/src/types/drift.ts +116 -0
  276. package/src/types/enterprise.ts +335 -0
  277. package/src/types/index.ts +20 -0
  278. package/src/types/plan.ts +44 -0
  279. package/src/types/request.ts +65 -0
  280. package/src/types/response.ts +54 -0
  281. package/src/types/service.ts +51 -0
  282. package/src/ui/App.tsx +997 -0
  283. package/src/ui/DeployPreview.tsx +169 -0
  284. package/src/ui/Header.tsx +68 -0
  285. package/src/ui/InputBox.tsx +350 -0
  286. package/src/ui/MessageList.tsx +585 -0
  287. package/src/ui/PermissionPrompt.tsx +151 -0
  288. package/src/ui/StatusBar.tsx +158 -0
  289. package/src/ui/ToolCallDisplay.tsx +409 -0
  290. package/src/ui/chat-ui.ts +853 -0
  291. package/src/ui/index.ts +33 -0
  292. package/src/ui/ink/index.ts +711 -0
  293. package/src/ui/streaming.ts +176 -0
  294. package/src/ui/types.ts +57 -0
  295. package/src/utils/analytics.ts +72 -0
  296. package/src/utils/cost-warning.ts +27 -0
  297. package/src/utils/env.ts +46 -0
  298. package/src/utils/errors.ts +69 -0
  299. package/src/utils/event-bus.ts +38 -0
  300. package/src/utils/index.ts +24 -0
  301. package/src/utils/logger.ts +171 -0
  302. package/src/utils/rate-limiter.ts +121 -0
  303. package/src/utils/service-auth.ts +49 -0
  304. package/src/utils/validation.ts +53 -0
  305. package/src/version.ts +4 -0
  306. package/src/watcher/index.ts +163 -0
  307. package/src/wizard/approval.ts +383 -0
  308. package/src/wizard/index.ts +25 -0
  309. package/src/wizard/prompts.ts +338 -0
  310. package/src/wizard/types.ts +171 -0
  311. package/src/wizard/ui.ts +556 -0
  312. package/src/wizard/wizard.ts +304 -0
  313. package/tsconfig.json +24 -0
@@ -0,0 +1,1270 @@
1
+ /**
2
+ * Questionnaire Command
3
+ *
4
+ * Interactive questionnaire flow for generating infrastructure code
5
+ *
6
+ * Usage:
7
+ * nimbus questionnaire terraform
8
+ * nimbus questionnaire kubernetes
9
+ * nimbus questionnaire helm
10
+ * nimbus generate terraform --interactive
11
+ */
12
+
13
+ import { logger } from '../utils';
14
+ import { ui } from '../wizard/ui';
15
+ import { select, input, confirm, multiSelect } from '../wizard/prompts';
16
+ import { generatorClient } from '../clients/generator-client';
17
+
18
+ export interface QuestionnaireOptions {
19
+ /** Questionnaire type */
20
+ type: 'terraform' | 'kubernetes' | 'helm';
21
+ /** Non-interactive mode (use answers file) */
22
+ nonInteractive?: boolean;
23
+ /** Path to answers file (JSON) */
24
+ answersFile?: string;
25
+ /** Output directory for generated code */
26
+ outputDir?: string;
27
+ /** Skip generation, just collect answers */
28
+ dryRun?: boolean;
29
+ }
30
+
31
+ interface Question {
32
+ id: string;
33
+ type: 'select' | 'multiselect' | 'text' | 'number' | 'confirm';
34
+ label: string;
35
+ description?: string;
36
+ options?: Array<{ value: string; label: string; description?: string }>;
37
+ default?: unknown;
38
+ validation?: Array<{ type: string; value?: unknown; message: string }>;
39
+ }
40
+
41
+ interface QuestionnaireStep {
42
+ id: string;
43
+ title: string;
44
+ description?: string;
45
+ questions: Question[];
46
+ }
47
+
48
+ interface _QuestionnaireResponse {
49
+ session: {
50
+ id: string;
51
+ type: string;
52
+ completed: boolean;
53
+ };
54
+ currentStep?: QuestionnaireStep;
55
+ nextStep?: QuestionnaireStep;
56
+ progress: {
57
+ current: number;
58
+ total: number;
59
+ percentage: number;
60
+ };
61
+ }
62
+
63
+ /**
64
+ * Run questionnaire command
65
+ */
66
+ export async function questionnaireCommand(options: QuestionnaireOptions): Promise<void> {
67
+ logger.info('Starting questionnaire', { type: options.type });
68
+
69
+ ui.newLine();
70
+ ui.header(`${capitalize(options.type)} Configuration Wizard`);
71
+
72
+ // Try to use generator service if available
73
+ const serviceAvailable = await generatorClient.isAvailable();
74
+
75
+ if (serviceAvailable) {
76
+ try {
77
+ await runWithGeneratorService(options);
78
+ return;
79
+ } catch (error: any) {
80
+ logger.warn('Generator service failed, falling back to local', { error: error.message });
81
+ ui.warning(`Generator service error: ${error.message}. Falling back to local questionnaire.`);
82
+ }
83
+ }
84
+
85
+ await runLocal(options);
86
+ }
87
+
88
+ /**
89
+ * Run questionnaire via generator service
90
+ */
91
+ async function runWithGeneratorService(options: QuestionnaireOptions): Promise<void> {
92
+ ui.info('Connected to Generator Service');
93
+ ui.newLine();
94
+
95
+ // Start questionnaire session
96
+ let session = await generatorClient.startQuestionnaire(
97
+ options.type as 'terraform' | 'kubernetes'
98
+ );
99
+ const sessionId = session.sessionId;
100
+
101
+ const answers: Record<string, unknown> = {};
102
+
103
+ // Loop through questions until complete
104
+ while (!session.completed && session.currentQuestion) {
105
+ const question = session.currentQuestion;
106
+
107
+ // Build a Question object compatible with askQuestion()
108
+ const questionObj: Question = {
109
+ id: question.id,
110
+ type: (question.type || 'text') as Question['type'],
111
+ label: question.text,
112
+ options: question.options?.map(opt => ({
113
+ value: opt,
114
+ label: opt,
115
+ })),
116
+ };
117
+
118
+ const answer = await askQuestion(questionObj, answers);
119
+ answers[question.id] = answer;
120
+
121
+ // Submit answer to generator service
122
+ session = await generatorClient.submitQuestionnaireAnswer(sessionId, question.id, answer);
123
+
124
+ // Display progress
125
+ if (session.progress !== undefined) {
126
+ const percentage = typeof session.progress === 'number' ? session.progress : 0;
127
+ ui.print(ui.dim(` Progress: ${percentage}%`));
128
+ }
129
+ }
130
+
131
+ ui.newLine();
132
+ ui.success('Questionnaire completed!');
133
+
134
+ if (!options.dryRun) {
135
+ ui.newLine();
136
+ ui.startSpinner({ message: 'Generating code via Generator Service...' });
137
+
138
+ const result = await generatorClient.generateFromQuestionnaire(sessionId);
139
+
140
+ ui.stopSpinnerSuccess('Code generated successfully');
141
+
142
+ // Write generated files to output directory
143
+ const outputDir = options.outputDir || `./${options.type}`;
144
+ const fs = await import('fs/promises');
145
+ const path = await import('path');
146
+
147
+ await fs.mkdir(outputDir, { recursive: true });
148
+
149
+ const fileNames: string[] = [];
150
+ for (const [fileName, content] of Object.entries(result.files)) {
151
+ const filePath = path.join(outputDir, fileName);
152
+ // Ensure parent directory exists for nested paths
153
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
154
+ await fs.writeFile(filePath, content);
155
+ fileNames.push(fileName);
156
+ }
157
+
158
+ ui.newLine();
159
+ ui.print(ui.bold('Generated files:'));
160
+ for (const file of fileNames) {
161
+ ui.print(` ${ui.color('●', 'green')} ${file}`);
162
+ }
163
+ ui.newLine();
164
+ ui.print(`Output directory: ${outputDir}`);
165
+ } else {
166
+ ui.newLine();
167
+ ui.print(ui.bold('Collected answers:'));
168
+ ui.print(JSON.stringify(answers, null, 2));
169
+ }
170
+ }
171
+
172
+ /**
173
+ * Run questionnaire locally
174
+ */
175
+ async function runLocal(options: QuestionnaireOptions): Promise<void> {
176
+ ui.info('Starting local questionnaire...');
177
+ ui.newLine();
178
+
179
+ const answers: Record<string, unknown> = {};
180
+
181
+ // Get questionnaire steps based on type
182
+ const steps = getLocalQuestionnaireSteps(options.type);
183
+
184
+ for (let i = 0; i < steps.length; i++) {
185
+ const step = steps[i];
186
+
187
+ // Check step condition
188
+ if (step.condition && !step.condition(answers)) {
189
+ continue;
190
+ }
191
+
192
+ // Display step header
193
+ ui.print(ui.bold(`Step ${i + 1}/${steps.length}: ${step.title}`));
194
+ if (step.description) {
195
+ ui.print(ui.dim(step.description));
196
+ }
197
+ ui.newLine();
198
+
199
+ // Process questions
200
+ for (const question of step.questions) {
201
+ // Check question dependency
202
+ if (question.dependsOn) {
203
+ const depValue = answers[question.dependsOn.questionId];
204
+ if (depValue !== question.dependsOn.value) {
205
+ continue;
206
+ }
207
+ }
208
+
209
+ const answer = await askQuestion(question, answers);
210
+ answers[question.id] = answer;
211
+ }
212
+
213
+ // Show progress
214
+ displayProgress({
215
+ current: i + 1,
216
+ total: steps.length,
217
+ percentage: Math.round(((i + 1) / steps.length) * 100),
218
+ });
219
+ }
220
+
221
+ ui.newLine();
222
+ ui.success('Questionnaire completed!');
223
+
224
+ if (!options.dryRun) {
225
+ // Generate code from answers
226
+ await generateFromAnswers(answers, options.type, options);
227
+ } else {
228
+ ui.newLine();
229
+ ui.print(ui.bold('Collected answers:'));
230
+ ui.print(JSON.stringify(answers, null, 2));
231
+ }
232
+ }
233
+
234
+ /**
235
+ * Ask a single question and return the answer
236
+ */
237
+ async function askQuestion(
238
+ question: Question,
239
+ currentAnswers: Record<string, unknown>
240
+ ): Promise<unknown> {
241
+ // Substitute variables in label and description
242
+ const label = substituteVariables(question.label, currentAnswers);
243
+ const _description = question.description
244
+ ? substituteVariables(question.description, currentAnswers)
245
+ : undefined;
246
+
247
+ switch (question.type) {
248
+ case 'select':
249
+ return select({
250
+ message: label,
251
+ options: question.options || [],
252
+ });
253
+
254
+ case 'multiselect':
255
+ return multiSelect({
256
+ message: label,
257
+ options: question.options || [],
258
+ });
259
+
260
+ case 'text':
261
+ return input({
262
+ message: label,
263
+ defaultValue: question.default as string,
264
+ });
265
+
266
+ case 'number': {
267
+ const numStr = await input({
268
+ message: label,
269
+ defaultValue: String(question.default ?? ''),
270
+ });
271
+ return parseInt(numStr, 10);
272
+ }
273
+
274
+ case 'confirm':
275
+ return confirm({
276
+ message: label,
277
+ defaultValue: question.default as boolean,
278
+ });
279
+
280
+ default:
281
+ return input({
282
+ message: label,
283
+ defaultValue: question.default as string,
284
+ });
285
+ }
286
+ }
287
+
288
+ /**
289
+ * Substitute variables in text ({{variable}} format)
290
+ */
291
+ function substituteVariables(text: string, answers: Record<string, unknown>): string {
292
+ return text.replace(/\{\{(\w+)\}\}/g, (_, key) => {
293
+ const value = answers[key];
294
+ return value !== undefined ? String(value) : `{{${key}}}`;
295
+ });
296
+ }
297
+
298
+ /**
299
+ * Display progress bar
300
+ */
301
+ function displayProgress(progress: { current: number; total: number; percentage: number }): void {
302
+ const barWidth = 30;
303
+ const filled = Math.round((progress.current / progress.total) * barWidth);
304
+ const empty = barWidth - filled;
305
+ const bar = ui.color('█'.repeat(filled), 'green') + ui.dim('░'.repeat(empty));
306
+
307
+ ui.newLine();
308
+ ui.print(` Progress: ${bar} ${progress.percentage}%`);
309
+ }
310
+
311
+ /**
312
+ * Generate code from answers
313
+ */
314
+ async function generateFromAnswers(
315
+ answers: Record<string, unknown>,
316
+ type: string,
317
+ options: QuestionnaireOptions
318
+ ): Promise<void> {
319
+ ui.newLine();
320
+ ui.startSpinner({ message: 'Generating code...' });
321
+
322
+ try {
323
+ const outputDir = options.outputDir || `./${type}`;
324
+ const fs = await import('fs/promises');
325
+ const path = await import('path');
326
+
327
+ // Ensure output directory exists
328
+ await fs.mkdir(outputDir, { recursive: true });
329
+
330
+ // Generate code based on type
331
+ let files: string[] = [];
332
+
333
+ if (type === 'terraform') {
334
+ files = await generateTerraformCode(answers, outputDir, fs, path);
335
+ } else if (type === 'kubernetes') {
336
+ files = await generateKubernetesCode(answers, outputDir, fs, path);
337
+ } else if (type === 'helm') {
338
+ files = await generateHelmCode(answers, outputDir, fs, path);
339
+ }
340
+
341
+ ui.stopSpinnerSuccess('Code generated successfully');
342
+
343
+ // Display generated files
344
+ ui.newLine();
345
+ ui.print(ui.bold('Generated files:'));
346
+ for (const file of files) {
347
+ ui.print(` ${ui.color('●', 'green')} ${file}`);
348
+ }
349
+ ui.newLine();
350
+ ui.print(`Output directory: ${outputDir}`);
351
+
352
+ // Run post-generation validation for Terraform
353
+ if (type === 'terraform') {
354
+ await runPostGenerationValidation(outputDir);
355
+ }
356
+ } catch (error) {
357
+ ui.stopSpinnerFail('Code generation failed');
358
+ ui.error((error as Error).message);
359
+ }
360
+ }
361
+
362
+ /**
363
+ * Generate Terraform code from answers
364
+ */
365
+ async function generateTerraformCode(
366
+ answers: Record<string, unknown>,
367
+ outputDir: string,
368
+ fs: typeof import('fs/promises'),
369
+ path: typeof import('path')
370
+ ): Promise<string[]> {
371
+ const files: string[] = [];
372
+
373
+ // Generate main.tf
374
+ const mainContent = generateTerraformMain(answers);
375
+ const mainPath = path.join(outputDir, 'main.tf');
376
+ await fs.writeFile(mainPath, mainContent);
377
+ files.push('main.tf');
378
+
379
+ // Generate variables.tf
380
+ const varsContent = generateTerraformVariables(answers);
381
+ const varsPath = path.join(outputDir, 'variables.tf');
382
+ await fs.writeFile(varsPath, varsContent);
383
+ files.push('variables.tf');
384
+
385
+ // Generate outputs.tf
386
+ const outputsContent = generateTerraformOutputs(answers);
387
+ const outputsPath = path.join(outputDir, 'outputs.tf');
388
+ await fs.writeFile(outputsPath, outputsContent);
389
+ files.push('outputs.tf');
390
+
391
+ // Generate environment directories if environments were selected
392
+ const environments = answers.environments as string[] | undefined;
393
+ if (environments && environments.length > 0) {
394
+ const envFiles = await generateEnvironmentDirs(answers, outputDir, fs, path);
395
+ files.push(...envFiles);
396
+ }
397
+
398
+ return files;
399
+ }
400
+
401
+ /**
402
+ * Generate Terraform main.tf content
403
+ */
404
+ function generateTerraformMain(answers: Record<string, unknown>): string {
405
+ const provider = (answers.provider as string) || 'aws';
406
+ const _region = (answers.region as string) || 'us-east-1';
407
+
408
+ let content = `# Generated by Nimbus CLI
409
+
410
+ terraform {
411
+ required_version = ">= 1.0.0"
412
+
413
+ required_providers {
414
+ ${provider} = {
415
+ source = "hashicorp/${provider}"
416
+ version = "~> 5.0"
417
+ }
418
+ }
419
+ }
420
+
421
+ provider "${provider}" {
422
+ region = var.region
423
+ }
424
+ `;
425
+
426
+ // Add VPC if selected
427
+ const components = (answers.components as string[]) || [];
428
+ if (components.includes('vpc')) {
429
+ const vpcCidr = (answers.vpc_cidr as string) || '10.0.0.0/16';
430
+ content += `
431
+ # VPC
432
+ module "vpc" {
433
+ source = "terraform-aws-modules/vpc/aws"
434
+ version = "~> 5.0"
435
+
436
+ name = var.project_name
437
+ cidr = "${vpcCidr}"
438
+
439
+ azs = var.availability_zones
440
+ private_subnets = var.private_subnets
441
+ public_subnets = var.public_subnets
442
+
443
+ enable_nat_gateway = true
444
+ single_nat_gateway = true
445
+
446
+ tags = var.tags
447
+ }
448
+ `;
449
+ }
450
+
451
+ return content;
452
+ }
453
+
454
+ /**
455
+ * Generate Terraform variables.tf content
456
+ */
457
+ function generateTerraformVariables(answers: Record<string, unknown>): string {
458
+ const projectName = (answers.project_name as string) || 'my-project';
459
+
460
+ return `# Generated by Nimbus CLI
461
+
462
+ variable "region" {
463
+ description = "AWS region"
464
+ type = string
465
+ default = "us-east-1"
466
+ }
467
+
468
+ variable "project_name" {
469
+ description = "Project name"
470
+ type = string
471
+ default = "${projectName}"
472
+ }
473
+
474
+ variable "environment" {
475
+ description = "Environment (dev, staging, prod)"
476
+ type = string
477
+ default = "dev"
478
+ }
479
+
480
+ variable "availability_zones" {
481
+ description = "List of availability zones"
482
+ type = list(string)
483
+ default = ["us-east-1a", "us-east-1b", "us-east-1c"]
484
+ }
485
+
486
+ variable "private_subnets" {
487
+ description = "Private subnet CIDRs"
488
+ type = list(string)
489
+ default = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
490
+ }
491
+
492
+ variable "public_subnets" {
493
+ description = "Public subnet CIDRs"
494
+ type = list(string)
495
+ default = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
496
+ }
497
+
498
+ variable "tags" {
499
+ description = "Tags to apply to resources"
500
+ type = map(string)
501
+ default = {}
502
+ }
503
+ `;
504
+ }
505
+
506
+ /**
507
+ * Generate Terraform outputs.tf content
508
+ */
509
+ function generateTerraformOutputs(answers: Record<string, unknown>): string {
510
+ const components = (answers.components as string[]) || [];
511
+
512
+ let content = `# Generated by Nimbus CLI
513
+ `;
514
+
515
+ if (components.includes('vpc')) {
516
+ content += `
517
+ output "vpc_id" {
518
+ description = "VPC ID"
519
+ value = module.vpc.vpc_id
520
+ }
521
+
522
+ output "private_subnets" {
523
+ description = "Private subnet IDs"
524
+ value = module.vpc.private_subnets
525
+ }
526
+
527
+ output "public_subnets" {
528
+ description = "Public subnet IDs"
529
+ value = module.vpc.public_subnets
530
+ }
531
+ `;
532
+ }
533
+
534
+ return content;
535
+ }
536
+
537
+ /**
538
+ * Generate Kubernetes code from answers
539
+ */
540
+ async function generateKubernetesCode(
541
+ answers: Record<string, unknown>,
542
+ outputDir: string,
543
+ fs: typeof import('fs/promises'),
544
+ path: typeof import('path')
545
+ ): Promise<string[]> {
546
+ const files: string[] = [];
547
+ const appName = (answers.app_name as string) || 'my-app';
548
+
549
+ // Generate deployment.yaml
550
+ const deploymentContent = `# Generated by Nimbus CLI
551
+ apiVersion: apps/v1
552
+ kind: Deployment
553
+ metadata:
554
+ name: ${appName}
555
+ labels:
556
+ app: ${appName}
557
+ spec:
558
+ replicas: ${answers.replicas || 2}
559
+ selector:
560
+ matchLabels:
561
+ app: ${appName}
562
+ template:
563
+ metadata:
564
+ labels:
565
+ app: ${appName}
566
+ spec:
567
+ containers:
568
+ - name: ${appName}
569
+ image: ${answers.image || 'nginx:latest'}
570
+ ports:
571
+ - containerPort: ${answers.port || 80}
572
+ resources:
573
+ requests:
574
+ cpu: ${answers.cpu_request || '100m'}
575
+ memory: ${answers.memory_request || '128Mi'}
576
+ limits:
577
+ cpu: ${answers.cpu_limit || '500m'}
578
+ memory: ${answers.memory_limit || '512Mi'}
579
+ `;
580
+
581
+ const deploymentPath = path.join(outputDir, 'deployment.yaml');
582
+ await fs.writeFile(deploymentPath, deploymentContent);
583
+ files.push('deployment.yaml');
584
+
585
+ // Generate service.yaml if enabled
586
+ if (answers.create_service !== false) {
587
+ const serviceContent = `# Generated by Nimbus CLI
588
+ apiVersion: v1
589
+ kind: Service
590
+ metadata:
591
+ name: ${appName}
592
+ spec:
593
+ selector:
594
+ app: ${appName}
595
+ ports:
596
+ - protocol: TCP
597
+ port: ${answers.service_port || 80}
598
+ targetPort: ${answers.port || 80}
599
+ type: ${answers.service_type || 'ClusterIP'}
600
+ `;
601
+
602
+ const servicePath = path.join(outputDir, 'service.yaml');
603
+ await fs.writeFile(servicePath, serviceContent);
604
+ files.push('service.yaml');
605
+ }
606
+
607
+ return files;
608
+ }
609
+
610
+ /**
611
+ * Generate Helm chart code from answers
612
+ */
613
+ async function generateHelmCode(
614
+ answers: Record<string, unknown>,
615
+ outputDir: string,
616
+ fs: typeof import('fs/promises'),
617
+ path: typeof import('path')
618
+ ): Promise<string[]> {
619
+ const files: string[] = [];
620
+ const chartName = (answers.chart_name as string) || 'my-chart';
621
+
622
+ // Create templates directory
623
+ const templatesDir = path.join(outputDir, 'templates');
624
+ await fs.mkdir(templatesDir, { recursive: true });
625
+
626
+ // Generate Chart.yaml
627
+ const chartContent = `# Generated by Nimbus CLI
628
+ apiVersion: v2
629
+ name: ${chartName}
630
+ description: ${answers.description || 'A Helm chart for Kubernetes'}
631
+ type: application
632
+ version: ${answers.version || '0.1.0'}
633
+ appVersion: "${answers.app_version || '1.0.0'}"
634
+ `;
635
+
636
+ const chartPath = path.join(outputDir, 'Chart.yaml');
637
+ await fs.writeFile(chartPath, chartContent);
638
+ files.push('Chart.yaml');
639
+
640
+ // Generate values.yaml
641
+ const valuesContent = `# Generated by Nimbus CLI
642
+ # Default values for ${chartName}
643
+
644
+ replicaCount: ${answers.replicas || 1}
645
+
646
+ image:
647
+ repository: ${answers.image_repository || 'nginx'}
648
+ tag: ${answers.image_tag || 'latest'}
649
+ pullPolicy: IfNotPresent
650
+
651
+ service:
652
+ type: ${answers.service_type || 'ClusterIP'}
653
+ port: ${answers.service_port || 80}
654
+
655
+ resources:
656
+ requests:
657
+ cpu: ${answers.cpu_request || '100m'}
658
+ memory: ${answers.memory_request || '128Mi'}
659
+ limits:
660
+ cpu: ${answers.cpu_limit || '500m'}
661
+ memory: ${answers.memory_limit || '512Mi'}
662
+ `;
663
+
664
+ const valuesPath = path.join(outputDir, 'values.yaml');
665
+ await fs.writeFile(valuesPath, valuesContent);
666
+ files.push('values.yaml');
667
+
668
+ return files;
669
+ }
670
+
671
+ /**
672
+ * Generate per-environment directories with module references
673
+ */
674
+ async function generateEnvironmentDirs(
675
+ answers: Record<string, unknown>,
676
+ outputDir: string,
677
+ fs: typeof import('fs/promises'),
678
+ path: typeof import('path')
679
+ ): Promise<string[]> {
680
+ const environments = answers.environments as string[];
681
+ const projectName = (answers.project_name as string) || 'my-project';
682
+ const _provider = (answers.cloud as string) || (answers.provider as string) || 'aws';
683
+ const region = (answers.region as string) || 'us-east-1';
684
+ const useRemoteState = answers.use_remote_state as boolean;
685
+ const files: string[] = [];
686
+
687
+ const envsDir = path.join(outputDir, 'environments');
688
+ await fs.mkdir(envsDir, { recursive: true });
689
+
690
+ for (const env of environments) {
691
+ const envDir = path.join(envsDir, env);
692
+ await fs.mkdir(envDir, { recursive: true });
693
+
694
+ // main.tf — module source pointing to root
695
+ const mainContent = `# ${env.charAt(0).toUpperCase() + env.slice(1)} Environment
696
+ # Generated by Nimbus CLI
697
+
698
+ module "infrastructure" {
699
+ source = "../../"
700
+
701
+ project_name = "${projectName}"
702
+ environment = "${env}"
703
+ region = var.region
704
+
705
+ tags = merge(var.tags, {
706
+ Environment = "${env}"
707
+ })
708
+ }
709
+ `;
710
+ await fs.writeFile(path.join(envDir, 'main.tf'), mainContent);
711
+ files.push(`environments/${env}/main.tf`);
712
+
713
+ // terraform.tfvars
714
+ const _instanceSize =
715
+ env === 'prod' ? 't3.large' : env === 'staging' ? 't3.medium' : 't3.small';
716
+ const tfvarsContent = `# ${env.charAt(0).toUpperCase() + env.slice(1)} environment variables
717
+ # Generated by Nimbus CLI
718
+
719
+ region = "${region}"
720
+
721
+ tags = {
722
+ Environment = "${env}"
723
+ Project = "${projectName}"
724
+ ManagedBy = "terraform"
725
+ }
726
+ `;
727
+ await fs.writeFile(path.join(envDir, 'terraform.tfvars'), tfvarsContent);
728
+ files.push(`environments/${env}/terraform.tfvars`);
729
+
730
+ // backend.tf — remote state if selected
731
+ if (useRemoteState) {
732
+ const backendContent = `# Remote state configuration for ${env}
733
+ # Generated by Nimbus CLI
734
+
735
+ terraform {
736
+ backend "s3" {
737
+ bucket = "${projectName}-tfstate"
738
+ key = "${env}/terraform.tfstate"
739
+ region = "${region}"
740
+ encrypt = true
741
+ dynamodb_table = "${projectName}-tflock"
742
+ }
743
+ }
744
+ `;
745
+ await fs.writeFile(path.join(envDir, 'backend.tf'), backendContent);
746
+ files.push(`environments/${env}/backend.tf`);
747
+ }
748
+ }
749
+
750
+ return files;
751
+ }
752
+
753
+ /**
754
+ * Run post-generation validation on Terraform files
755
+ */
756
+ async function runPostGenerationValidation(outputDir: string): Promise<void> {
757
+ const { execFile } = await import('child_process');
758
+ const { promisify } = await import('util');
759
+ const execFileAsync = promisify(execFile);
760
+
761
+ ui.newLine();
762
+ ui.section('Post-Generation Validation');
763
+
764
+ // Check if terraform CLI is available
765
+ let _hasTerraform = false;
766
+ try {
767
+ await execFileAsync('terraform', ['version'], { timeout: 5000 });
768
+ _hasTerraform = true;
769
+ } catch {
770
+ ui.info('Terraform CLI not found - skipping validation');
771
+ ui.print(ui.dim(' Install terraform for automatic validation'));
772
+ return;
773
+ }
774
+
775
+ // Run terraform fmt -check
776
+ try {
777
+ ui.startSpinner({ message: 'Running terraform fmt...' });
778
+ await execFileAsync('terraform', ['fmt', '-check', '-diff'], {
779
+ cwd: outputDir,
780
+ timeout: 15000,
781
+ });
782
+ ui.stopSpinnerSuccess('Code formatting valid');
783
+ } catch (error: any) {
784
+ ui.stopSpinnerFail('Formatting issues found');
785
+ // Try to auto-fix
786
+ try {
787
+ await execFileAsync('terraform', ['fmt'], { cwd: outputDir, timeout: 15000 });
788
+ ui.success('Auto-formatted Terraform files');
789
+ } catch {
790
+ ui.warning('Could not auto-format files');
791
+ }
792
+ }
793
+
794
+ // Run terraform init -backend=false for validation
795
+ try {
796
+ ui.startSpinner({ message: 'Running terraform validate...' });
797
+ await execFileAsync('terraform', ['init', '-backend=false', '-no-color'], {
798
+ cwd: outputDir,
799
+ timeout: 30000,
800
+ });
801
+ const { stdout } = await execFileAsync('terraform', ['validate', '-no-color'], {
802
+ cwd: outputDir,
803
+ timeout: 15000,
804
+ });
805
+ ui.stopSpinnerSuccess('Terraform validation passed');
806
+ if (stdout.includes('Success')) {
807
+ ui.print(ui.dim(` ${stdout.trim()}`));
808
+ }
809
+ } catch (error: any) {
810
+ ui.stopSpinnerFail('Terraform validation failed');
811
+ const output = error.stdout || error.stderr || error.message;
812
+ ui.print(ui.dim(` ${output}`));
813
+ }
814
+
815
+ // Check if tflint is available
816
+ try {
817
+ await execFileAsync('tflint', ['--version'], { timeout: 5000 });
818
+ ui.startSpinner({ message: 'Running tflint...' });
819
+ const { stdout } = await execFileAsync('tflint', ['--no-color'], {
820
+ cwd: outputDir,
821
+ timeout: 15000,
822
+ });
823
+ ui.stopSpinnerSuccess('tflint check passed');
824
+ if (stdout) {
825
+ ui.print(ui.dim(` ${stdout.trim()}`));
826
+ }
827
+ } catch (error: any) {
828
+ if (error.code === 'ENOENT') {
829
+ ui.info('tflint not found - skipping lint check');
830
+ ui.print(ui.dim(' Install tflint for additional validation'));
831
+ } else {
832
+ ui.warning('tflint found issues');
833
+ const output = error.stdout || error.stderr || error.message;
834
+ ui.print(ui.dim(` ${output}`));
835
+ }
836
+ }
837
+
838
+ // Check if checkov is available for security scanning
839
+ try {
840
+ await execFileAsync('checkov', ['--version'], { timeout: 5000 });
841
+ ui.startSpinner({ message: 'Running checkov security scan...' });
842
+ const { stdout } = await execFileAsync(
843
+ 'checkov',
844
+ ['-d', outputDir, '--framework', 'terraform', '--compact', '--quiet'],
845
+ { timeout: 60000 }
846
+ );
847
+ ui.stopSpinnerSuccess('checkov security scan passed');
848
+ // Parse passed/failed from output
849
+ const passedMatch = stdout.match(/Passed checks: (\d+)/);
850
+ const failedMatch = stdout.match(/Failed checks: (\d+)/);
851
+ if (passedMatch || failedMatch) {
852
+ const passed = passedMatch ? passedMatch[1] : '0';
853
+ const failed = failedMatch ? failedMatch[1] : '0';
854
+ ui.print(ui.dim(` Passed: ${passed}, Failed: ${failed}`));
855
+ } else if (stdout.trim()) {
856
+ ui.print(ui.dim(` ${stdout.trim()}`));
857
+ }
858
+ } catch (error: any) {
859
+ if (error.code === 'ENOENT') {
860
+ ui.info('Security scanning available with checkov. Install: pip install checkov');
861
+ } else {
862
+ ui.warning('checkov found security issues');
863
+ const output = error.stdout || error.stderr || error.message;
864
+ // Parse passed/failed from output even on non-zero exit
865
+ const passedMatch = output.match(/Passed checks: (\d+)/);
866
+ const failedMatch = output.match(/Failed checks: (\d+)/);
867
+ if (passedMatch || failedMatch) {
868
+ const passed = passedMatch ? passedMatch[1] : '0';
869
+ const failed = failedMatch ? failedMatch[1] : '0';
870
+ ui.print(ui.dim(` Passed: ${passed}, Failed: ${failed}`));
871
+ } else {
872
+ ui.print(ui.dim(` ${output}`));
873
+ }
874
+ }
875
+ }
876
+ }
877
+
878
+ /**
879
+ * Get local questionnaire steps based on type
880
+ */
881
+ function getLocalQuestionnaireSteps(type: 'terraform' | 'kubernetes' | 'helm'): Array<{
882
+ id: string;
883
+ title: string;
884
+ description?: string;
885
+ questions: Array<Question & { dependsOn?: { questionId: string; value: unknown } }>;
886
+ condition?: (answers: Record<string, unknown>) => boolean;
887
+ }> {
888
+ switch (type) {
889
+ case 'terraform':
890
+ return getTerraformSteps();
891
+ case 'kubernetes':
892
+ return getKubernetesSteps();
893
+ case 'helm':
894
+ return getHelmSteps();
895
+ default:
896
+ return [];
897
+ }
898
+ }
899
+
900
+ /**
901
+ * Terraform questionnaire steps (local fallback)
902
+ */
903
+ function getTerraformSteps() {
904
+ return [
905
+ {
906
+ id: 'provider',
907
+ title: 'Cloud Provider',
908
+ description: 'Select your cloud provider and region',
909
+ questions: [
910
+ {
911
+ id: 'cloud',
912
+ type: 'select' as const,
913
+ label: 'Which cloud provider?',
914
+ options: [
915
+ { value: 'aws', label: 'AWS', description: 'Amazon Web Services' },
916
+ { value: 'gcp', label: 'GCP', description: 'Google Cloud Platform' },
917
+ { value: 'azure', label: 'Azure', description: 'Microsoft Azure' },
918
+ ],
919
+ default: 'aws',
920
+ },
921
+ {
922
+ id: 'region',
923
+ type: 'select' as const,
924
+ label: 'Which region?',
925
+ options: [
926
+ { value: 'us-east-1', label: 'US East (N. Virginia)' },
927
+ { value: 'us-west-2', label: 'US West (Oregon)' },
928
+ { value: 'eu-west-1', label: 'EU (Ireland)' },
929
+ { value: 'ap-southeast-1', label: 'Asia Pacific (Singapore)' },
930
+ ],
931
+ default: 'us-east-1',
932
+ dependsOn: { questionId: 'cloud', value: 'aws' },
933
+ },
934
+ {
935
+ id: 'project_name',
936
+ type: 'text' as const,
937
+ label: 'Project name',
938
+ default: 'my-project',
939
+ },
940
+ {
941
+ id: 'environment',
942
+ type: 'select' as const,
943
+ label: 'Environment',
944
+ options: [
945
+ { value: 'dev', label: 'Development' },
946
+ { value: 'staging', label: 'Staging' },
947
+ { value: 'prod', label: 'Production' },
948
+ ],
949
+ default: 'dev',
950
+ },
951
+ ],
952
+ },
953
+ {
954
+ id: 'components',
955
+ title: 'Infrastructure Components',
956
+ description: 'Select the components you need',
957
+ questions: [
958
+ {
959
+ id: 'components',
960
+ type: 'multiselect' as const,
961
+ label: 'What components do you need?',
962
+ options: [
963
+ { value: 'vpc', label: 'VPC / Network' },
964
+ { value: 'eks', label: 'Kubernetes (EKS)' },
965
+ { value: 'rds', label: 'Database (RDS)' },
966
+ { value: 's3', label: 'Object Storage (S3)' },
967
+ { value: 'ecs', label: 'Container Service (ECS)' },
968
+ ],
969
+ default: ['vpc'],
970
+ },
971
+ ],
972
+ },
973
+ {
974
+ id: 'environments',
975
+ title: 'Environment Separation',
976
+ description: 'Configure environment-specific deployments',
977
+ questions: [
978
+ {
979
+ id: 'environments',
980
+ type: 'multiselect' as const,
981
+ label: 'Which environments do you need?',
982
+ options: [
983
+ { value: 'dev', label: 'Development' },
984
+ { value: 'staging', label: 'Staging' },
985
+ { value: 'prod', label: 'Production' },
986
+ ],
987
+ default: ['dev'],
988
+ },
989
+ {
990
+ id: 'use_remote_state',
991
+ type: 'confirm' as const,
992
+ label: 'Use remote state backend (S3)?',
993
+ default: true,
994
+ },
995
+ ],
996
+ },
997
+ {
998
+ id: 'vpc_config',
999
+ title: 'VPC Configuration',
1000
+ condition: (answers: Record<string, unknown>) => {
1001
+ const components = answers.components as string[];
1002
+ return components && components.includes('vpc');
1003
+ },
1004
+ questions: [
1005
+ {
1006
+ id: 'vpc_cidr',
1007
+ type: 'text' as const,
1008
+ label: 'VPC CIDR block',
1009
+ default: '10.0.0.0/16',
1010
+ },
1011
+ {
1012
+ id: 'availability_zones',
1013
+ type: 'number' as const,
1014
+ label: 'Number of availability zones',
1015
+ default: 3,
1016
+ },
1017
+ {
1018
+ id: 'nat_gateway',
1019
+ type: 'select' as const,
1020
+ label: 'NAT Gateway configuration',
1021
+ options: [
1022
+ { value: 'single', label: 'Single NAT (~$32/month)' },
1023
+ { value: 'ha', label: 'HA NAT (one per AZ)' },
1024
+ { value: 'none', label: 'No NAT Gateway' },
1025
+ ],
1026
+ default: 'single',
1027
+ },
1028
+ ],
1029
+ },
1030
+ ];
1031
+ }
1032
+
1033
+ /**
1034
+ * Kubernetes questionnaire steps (local fallback)
1035
+ */
1036
+ function getKubernetesSteps() {
1037
+ return [
1038
+ {
1039
+ id: 'workload',
1040
+ title: 'Workload Type',
1041
+ description: 'Configure your Kubernetes workload',
1042
+ questions: [
1043
+ {
1044
+ id: 'workload_type',
1045
+ type: 'select' as const,
1046
+ label: 'What type of workload?',
1047
+ options: [
1048
+ {
1049
+ value: 'deployment',
1050
+ label: 'Deployment',
1051
+ description: 'Standard stateless workload',
1052
+ },
1053
+ {
1054
+ value: 'statefulset',
1055
+ label: 'StatefulSet',
1056
+ description: 'Stateful workload with persistent storage',
1057
+ },
1058
+ { value: 'daemonset', label: 'DaemonSet', description: 'Run on every node' },
1059
+ { value: 'cronjob', label: 'CronJob', description: 'Scheduled job' },
1060
+ ],
1061
+ default: 'deployment',
1062
+ },
1063
+ {
1064
+ id: 'name',
1065
+ type: 'text' as const,
1066
+ label: 'Workload name',
1067
+ default: 'my-app',
1068
+ },
1069
+ {
1070
+ id: 'namespace',
1071
+ type: 'text' as const,
1072
+ label: 'Namespace',
1073
+ default: 'default',
1074
+ },
1075
+ ],
1076
+ },
1077
+ {
1078
+ id: 'container',
1079
+ title: 'Container Configuration',
1080
+ questions: [
1081
+ {
1082
+ id: 'image',
1083
+ type: 'text' as const,
1084
+ label: 'Container image',
1085
+ default: 'nginx:latest',
1086
+ },
1087
+ {
1088
+ id: 'replicas',
1089
+ type: 'number' as const,
1090
+ label: 'Number of replicas',
1091
+ default: 3,
1092
+ },
1093
+ {
1094
+ id: 'port',
1095
+ type: 'number' as const,
1096
+ label: 'Container port',
1097
+ default: 80,
1098
+ },
1099
+ ],
1100
+ },
1101
+ {
1102
+ id: 'service',
1103
+ title: 'Service Configuration',
1104
+ questions: [
1105
+ {
1106
+ id: 'service_type',
1107
+ type: 'select' as const,
1108
+ label: 'Service type',
1109
+ options: [
1110
+ { value: 'ClusterIP', label: 'ClusterIP', description: 'Internal only' },
1111
+ { value: 'NodePort', label: 'NodePort', description: 'External via node port' },
1112
+ { value: 'LoadBalancer', label: 'LoadBalancer', description: 'External load balancer' },
1113
+ ],
1114
+ default: 'ClusterIP',
1115
+ },
1116
+ {
1117
+ id: 'create_ingress',
1118
+ type: 'confirm' as const,
1119
+ label: 'Create Ingress?',
1120
+ default: false,
1121
+ },
1122
+ ],
1123
+ },
1124
+ {
1125
+ id: 'resources',
1126
+ title: 'Resource Limits',
1127
+ questions: [
1128
+ {
1129
+ id: 'cpu_request',
1130
+ type: 'text' as const,
1131
+ label: 'CPU request',
1132
+ default: '100m',
1133
+ },
1134
+ {
1135
+ id: 'cpu_limit',
1136
+ type: 'text' as const,
1137
+ label: 'CPU limit',
1138
+ default: '500m',
1139
+ },
1140
+ {
1141
+ id: 'memory_request',
1142
+ type: 'text' as const,
1143
+ label: 'Memory request',
1144
+ default: '128Mi',
1145
+ },
1146
+ {
1147
+ id: 'memory_limit',
1148
+ type: 'text' as const,
1149
+ label: 'Memory limit',
1150
+ default: '512Mi',
1151
+ },
1152
+ ],
1153
+ },
1154
+ ];
1155
+ }
1156
+
1157
+ /**
1158
+ * Helm questionnaire steps (local fallback)
1159
+ */
1160
+ function getHelmSteps() {
1161
+ return [
1162
+ {
1163
+ id: 'chart',
1164
+ title: 'Chart Information',
1165
+ description: 'Basic Helm chart configuration',
1166
+ questions: [
1167
+ {
1168
+ id: 'chart_name',
1169
+ type: 'text' as const,
1170
+ label: 'Chart name',
1171
+ default: 'my-chart',
1172
+ },
1173
+ {
1174
+ id: 'chart_version',
1175
+ type: 'text' as const,
1176
+ label: 'Chart version',
1177
+ default: '0.1.0',
1178
+ },
1179
+ {
1180
+ id: 'app_version',
1181
+ type: 'text' as const,
1182
+ label: 'Application version',
1183
+ default: '1.0.0',
1184
+ },
1185
+ {
1186
+ id: 'description',
1187
+ type: 'text' as const,
1188
+ label: 'Chart description',
1189
+ default: 'A Helm chart for my application',
1190
+ },
1191
+ ],
1192
+ },
1193
+ {
1194
+ id: 'deployment',
1195
+ title: 'Deployment Configuration',
1196
+ questions: [
1197
+ {
1198
+ id: 'image_repository',
1199
+ type: 'text' as const,
1200
+ label: 'Image repository',
1201
+ default: 'nginx',
1202
+ },
1203
+ {
1204
+ id: 'image_tag',
1205
+ type: 'text' as const,
1206
+ label: 'Image tag',
1207
+ default: 'latest',
1208
+ },
1209
+ {
1210
+ id: 'replica_count',
1211
+ type: 'number' as const,
1212
+ label: 'Replica count',
1213
+ default: 1,
1214
+ },
1215
+ ],
1216
+ },
1217
+ {
1218
+ id: 'service',
1219
+ title: 'Service Configuration',
1220
+ questions: [
1221
+ {
1222
+ id: 'service_type',
1223
+ type: 'select' as const,
1224
+ label: 'Service type',
1225
+ options: [
1226
+ { value: 'ClusterIP', label: 'ClusterIP' },
1227
+ { value: 'NodePort', label: 'NodePort' },
1228
+ { value: 'LoadBalancer', label: 'LoadBalancer' },
1229
+ ],
1230
+ default: 'ClusterIP',
1231
+ },
1232
+ {
1233
+ id: 'service_port',
1234
+ type: 'number' as const,
1235
+ label: 'Service port',
1236
+ default: 80,
1237
+ },
1238
+ ],
1239
+ },
1240
+ {
1241
+ id: 'ingress',
1242
+ title: 'Ingress Configuration',
1243
+ questions: [
1244
+ {
1245
+ id: 'ingress_enabled',
1246
+ type: 'confirm' as const,
1247
+ label: 'Enable Ingress?',
1248
+ default: false,
1249
+ },
1250
+ {
1251
+ id: 'ingress_host',
1252
+ type: 'text' as const,
1253
+ label: 'Ingress hostname',
1254
+ default: 'chart.local',
1255
+ dependsOn: { questionId: 'ingress_enabled', value: true },
1256
+ },
1257
+ ],
1258
+ },
1259
+ ];
1260
+ }
1261
+
1262
+ /**
1263
+ * Capitalize first letter
1264
+ */
1265
+ function capitalize(str: string): string {
1266
+ return str.charAt(0).toUpperCase() + str.slice(1);
1267
+ }
1268
+
1269
+ // Export as default
1270
+ export default questionnaireCommand;