@build-astron-co/nimbus 0.2.0 → 0.4.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.
- package/bin/nimbus +26 -10
- package/bin/nimbus.cmd +41 -0
- package/bin/nimbus.mjs +70 -0
- package/completions/nimbus.bash +38 -0
- package/completions/nimbus.fish +48 -0
- package/completions/nimbus.zsh +81 -0
- package/dist/src/agent/compaction-agent.js +215 -0
- package/dist/src/agent/context-manager.js +385 -0
- package/dist/src/agent/context.js +322 -0
- package/dist/src/agent/deploy-preview.js +395 -0
- package/dist/src/agent/expand-files.js +95 -0
- package/dist/src/agent/index.js +18 -0
- package/dist/src/agent/loop.js +1535 -0
- package/dist/src/agent/modes.js +347 -0
- package/dist/src/agent/permissions.js +396 -0
- package/dist/src/agent/subagents/base.js +67 -0
- package/dist/src/agent/subagents/cost.js +45 -0
- package/dist/src/agent/subagents/explore.js +36 -0
- package/dist/src/agent/subagents/general.js +41 -0
- package/dist/src/agent/subagents/index.js +88 -0
- package/dist/src/agent/subagents/infra.js +52 -0
- package/dist/src/agent/subagents/security.js +60 -0
- package/dist/src/agent/system-prompt.js +860 -0
- package/dist/src/app.js +152 -0
- package/dist/src/audit/activity-log.js +209 -0
- package/dist/src/audit/compliance-checker.js +419 -0
- package/dist/src/audit/cost-tracker.js +231 -0
- package/dist/src/audit/index.js +10 -0
- package/dist/src/audit/security-scanner.js +490 -0
- package/dist/src/auth/guard.js +64 -0
- package/dist/src/auth/index.js +19 -0
- package/dist/src/auth/keychain.js +79 -0
- package/dist/src/auth/oauth.js +389 -0
- package/dist/src/auth/providers.js +415 -0
- package/dist/src/auth/sso.js +87 -0
- package/dist/src/auth/store.js +424 -0
- package/dist/src/auth/types.js +5 -0
- package/dist/src/cli/index.js +8 -0
- package/dist/src/cli/init.js +1048 -0
- package/dist/src/cli/openapi-spec.js +346 -0
- package/dist/src/cli/run.js +505 -0
- package/dist/src/cli/serve-auth.js +56 -0
- package/dist/src/cli/serve.js +432 -0
- package/dist/src/cli/web.js +50 -0
- package/dist/src/cli.js +1574 -0
- package/dist/src/clients/core-engine-client.js +156 -0
- package/dist/src/clients/enterprise-client.js +246 -0
- package/dist/src/clients/generator-client.js +219 -0
- package/dist/src/clients/git-client.js +367 -0
- package/dist/src/clients/github-client.js +229 -0
- package/dist/src/clients/helm-client.js +299 -0
- package/dist/src/clients/index.js +18 -0
- package/dist/src/clients/k8s-client.js +270 -0
- package/dist/src/clients/llm-client.js +119 -0
- package/dist/src/clients/rest-client.js +104 -0
- package/dist/src/clients/service-discovery.js +35 -0
- package/dist/src/clients/terraform-client.js +302 -0
- package/dist/src/clients/tools-client.js +1227 -0
- package/dist/src/clients/ws-client.js +93 -0
- package/dist/src/commands/alias.js +91 -0
- package/dist/src/commands/analyze/index.js +313 -0
- package/dist/src/commands/apply/helm.js +375 -0
- package/dist/src/commands/apply/index.js +176 -0
- package/dist/src/commands/apply/k8s.js +350 -0
- package/dist/src/commands/apply/terraform.js +465 -0
- package/dist/src/commands/ask.js +137 -0
- package/dist/src/commands/audit/index.js +322 -0
- package/dist/src/commands/auth-cloud.js +345 -0
- package/dist/src/commands/auth-list.js +112 -0
- package/dist/src/commands/auth-profile.js +104 -0
- package/dist/src/commands/auth-refresh.js +161 -0
- package/dist/src/commands/auth-status.js +122 -0
- package/dist/src/commands/aws/ec2.js +402 -0
- package/dist/src/commands/aws/iam.js +304 -0
- package/dist/src/commands/aws/index.js +108 -0
- package/dist/src/commands/aws/lambda.js +317 -0
- package/dist/src/commands/aws/rds.js +345 -0
- package/dist/src/commands/aws/s3.js +346 -0
- package/dist/src/commands/aws/vpc.js +302 -0
- package/dist/src/commands/aws-discover.js +413 -0
- package/dist/src/commands/aws-terraform.js +618 -0
- package/dist/src/commands/azure/aks.js +305 -0
- package/dist/src/commands/azure/functions.js +200 -0
- package/dist/src/commands/azure/index.js +93 -0
- package/dist/src/commands/azure/storage.js +378 -0
- package/dist/src/commands/azure/vm.js +291 -0
- package/dist/src/commands/billing/index.js +224 -0
- package/dist/src/commands/chat.js +259 -0
- package/dist/src/commands/completions.js +255 -0
- package/dist/src/commands/config.js +291 -0
- package/dist/src/commands/cost/cloud-cost-estimator.js +211 -0
- package/dist/src/commands/cost/estimator.js +73 -0
- package/dist/src/commands/cost/index.js +625 -0
- package/dist/src/commands/cost/parsers/terraform.js +234 -0
- package/dist/src/commands/cost/parsers/types.js +4 -0
- package/dist/src/commands/cost/pricing/aws.js +501 -0
- package/dist/src/commands/cost/pricing/azure.js +462 -0
- package/dist/src/commands/cost/pricing/gcp.js +359 -0
- package/dist/src/commands/cost/pricing/index.js +24 -0
- package/dist/src/commands/demo.js +196 -0
- package/dist/src/commands/deploy.js +215 -0
- package/dist/src/commands/doctor.js +1291 -0
- package/dist/src/commands/drift/index.js +674 -0
- package/dist/src/commands/explain.js +235 -0
- package/dist/src/commands/export.js +120 -0
- package/dist/src/commands/feedback.js +319 -0
- package/dist/src/commands/fix.js +263 -0
- package/dist/src/commands/fs/index.js +338 -0
- package/dist/src/commands/gcp/compute.js +266 -0
- package/dist/src/commands/gcp/functions.js +221 -0
- package/dist/src/commands/gcp/gke.js +357 -0
- package/dist/src/commands/gcp/iam.js +295 -0
- package/dist/src/commands/gcp/index.js +105 -0
- package/dist/src/commands/gcp/storage.js +232 -0
- package/dist/src/commands/generate-helm.js +1026 -0
- package/dist/src/commands/generate-k8s.js +1263 -0
- package/dist/src/commands/generate-terraform.js +1058 -0
- package/dist/src/commands/gh/index.js +663 -0
- package/dist/src/commands/git/index.js +1208 -0
- package/dist/src/commands/helm/index.js +985 -0
- package/dist/src/commands/help.js +639 -0
- package/dist/src/commands/history.js +120 -0
- package/dist/src/commands/import.js +782 -0
- package/dist/src/commands/incident.js +144 -0
- package/dist/src/commands/index.js +109 -0
- package/dist/src/commands/init.js +955 -0
- package/dist/src/commands/k8s/index.js +979 -0
- package/dist/src/commands/login.js +588 -0
- package/dist/src/commands/logout.js +61 -0
- package/dist/src/commands/logs.js +160 -0
- package/dist/src/commands/onboarding.js +382 -0
- package/dist/src/commands/pipeline.js +153 -0
- package/dist/src/commands/plan/display.js +216 -0
- package/dist/src/commands/plan/index.js +525 -0
- package/dist/src/commands/plugin.js +325 -0
- package/dist/src/commands/preview.js +356 -0
- package/dist/src/commands/profile.js +297 -0
- package/dist/src/commands/questionnaire.js +1021 -0
- package/dist/src/commands/resume.js +35 -0
- package/dist/src/commands/rollback.js +259 -0
- package/dist/src/commands/rollout.js +74 -0
- package/dist/src/commands/runbook.js +307 -0
- package/dist/src/commands/schedule.js +202 -0
- package/dist/src/commands/status.js +213 -0
- package/dist/src/commands/team/index.js +309 -0
- package/dist/src/commands/team-context.js +200 -0
- package/dist/src/commands/template.js +204 -0
- package/dist/src/commands/tf/index.js +989 -0
- package/dist/src/commands/upgrade.js +515 -0
- package/dist/src/commands/usage/index.js +118 -0
- package/dist/src/commands/version.js +145 -0
- package/dist/src/commands/watch.js +127 -0
- package/dist/src/compat/index.js +2 -0
- package/dist/src/compat/runtime.js +10 -0
- package/dist/src/compat/sqlite.js +144 -0
- package/dist/src/config/index.js +6 -0
- package/dist/src/config/manager.js +469 -0
- package/dist/src/config/mode-store.js +57 -0
- package/dist/src/config/profiles.js +66 -0
- package/dist/src/config/safety-policy.js +251 -0
- package/dist/src/config/schema.js +107 -0
- package/dist/src/config/types.js +311 -0
- package/dist/src/config/workspace-state.js +38 -0
- package/dist/src/context/context-db.js +138 -0
- package/dist/src/demo/index.js +295 -0
- package/dist/src/demo/scenarios/full-journey.js +226 -0
- package/dist/src/demo/scenarios/getting-started.js +124 -0
- package/dist/src/demo/scenarios/helm-release.js +334 -0
- package/dist/src/demo/scenarios/k8s-deployment.js +190 -0
- package/dist/src/demo/scenarios/terraform-vpc.js +167 -0
- package/dist/src/demo/types.js +6 -0
- package/dist/src/engine/cost-estimator.js +334 -0
- package/dist/src/engine/diagram-generator.js +192 -0
- package/dist/src/engine/drift-detector.js +688 -0
- package/dist/src/engine/executor.js +832 -0
- package/dist/src/engine/index.js +39 -0
- package/dist/src/engine/orchestrator.js +436 -0
- package/dist/src/engine/planner.js +616 -0
- package/dist/src/engine/safety.js +609 -0
- package/dist/src/engine/verifier.js +664 -0
- package/dist/src/enterprise/audit.js +241 -0
- package/dist/src/enterprise/auth.js +189 -0
- package/dist/src/enterprise/billing.js +512 -0
- package/dist/src/enterprise/index.js +16 -0
- package/dist/src/enterprise/teams.js +315 -0
- package/dist/src/generator/best-practices.js +1375 -0
- package/dist/src/generator/helm.js +495 -0
- package/dist/src/generator/index.js +11 -0
- package/dist/src/generator/intent-parser.js +420 -0
- package/dist/src/generator/kubernetes.js +773 -0
- package/dist/src/generator/terraform.js +1472 -0
- package/dist/src/history/index.js +6 -0
- package/dist/src/history/manager.js +199 -0
- package/dist/src/history/types.js +6 -0
- package/dist/src/hooks/config.js +318 -0
- package/dist/src/hooks/engine.js +317 -0
- package/dist/src/hooks/index.js +2 -0
- package/dist/src/llm/auth-bridge.js +157 -0
- package/dist/src/llm/circuit-breaker.js +116 -0
- package/dist/src/llm/config-loader.js +172 -0
- package/dist/src/llm/cost-calculator.js +137 -0
- package/dist/src/llm/index.js +7 -0
- package/dist/src/llm/model-aliases.js +99 -0
- package/dist/src/llm/provider-registry.js +57 -0
- package/dist/src/llm/providers/anthropic.js +430 -0
- package/dist/src/llm/providers/bedrock.js +409 -0
- package/dist/src/llm/providers/google.js +344 -0
- package/dist/src/llm/providers/ollama.js +661 -0
- package/dist/src/llm/providers/openai-compatible.js +289 -0
- package/dist/src/llm/providers/openai.js +284 -0
- package/dist/src/llm/providers/openrouter.js +293 -0
- package/dist/src/llm/router.js +844 -0
- package/dist/src/llm/types.js +69 -0
- package/dist/src/lsp/client.js +239 -0
- package/dist/src/lsp/languages.js +95 -0
- package/dist/src/lsp/manager.js +243 -0
- package/dist/src/mcp/client.js +289 -0
- package/dist/src/mcp/index.js +5 -0
- package/dist/src/mcp/manager.js +113 -0
- package/dist/src/nimbus.js +212 -0
- package/dist/src/plugins/index.js +13 -0
- package/dist/src/plugins/loader.js +280 -0
- package/dist/src/plugins/manager.js +282 -0
- package/dist/src/plugins/types.js +23 -0
- package/dist/src/scanners/cicd-scanner.js +230 -0
- package/dist/src/scanners/cloud-scanner.js +415 -0
- package/dist/src/scanners/framework-scanner.js +430 -0
- package/dist/src/scanners/iac-scanner.js +350 -0
- package/dist/src/scanners/index.js +454 -0
- package/dist/src/scanners/language-scanner.js +258 -0
- package/dist/src/scanners/package-manager-scanner.js +252 -0
- package/dist/src/scanners/types.js +6 -0
- package/dist/src/sessions/manager.js +395 -0
- package/dist/src/sessions/types.js +4 -0
- package/dist/src/sharing/sync.js +238 -0
- package/dist/src/sharing/viewer.js +131 -0
- package/dist/src/snapshots/index.js +1 -0
- package/dist/src/snapshots/manager.js +432 -0
- package/dist/src/state/artifacts.js +94 -0
- package/dist/src/state/audit.js +73 -0
- package/dist/src/state/billing.js +126 -0
- package/dist/src/state/checkpoints.js +81 -0
- package/dist/src/state/config.js +58 -0
- package/dist/src/state/conversations.js +7 -0
- package/dist/src/state/credentials.js +96 -0
- package/dist/src/state/db.js +53 -0
- package/dist/src/state/index.js +23 -0
- package/dist/src/state/messages.js +76 -0
- package/dist/src/state/projects.js +92 -0
- package/dist/src/state/schema.js +233 -0
- package/dist/src/state/sessions.js +79 -0
- package/dist/src/state/teams.js +131 -0
- package/dist/src/telemetry.js +91 -0
- package/dist/src/tools/aws-ops.js +747 -0
- package/dist/src/tools/azure-ops.js +491 -0
- package/dist/src/tools/file-ops.js +451 -0
- package/dist/src/tools/gcp-ops.js +559 -0
- package/dist/src/tools/git-ops.js +557 -0
- package/dist/src/tools/github-ops.js +460 -0
- package/dist/src/tools/helm-ops.js +634 -0
- package/dist/src/tools/index.js +16 -0
- package/dist/src/tools/k8s-ops.js +579 -0
- package/dist/src/tools/schemas/converter.js +129 -0
- package/dist/src/tools/schemas/devops.js +3319 -0
- package/dist/src/tools/schemas/index.js +19 -0
- package/dist/src/tools/schemas/standard.js +966 -0
- package/dist/src/tools/schemas/types.js +409 -0
- package/dist/src/tools/spawn-exec.js +109 -0
- package/dist/src/tools/terraform-ops.js +627 -0
- package/dist/src/types/config.js +1 -0
- package/dist/src/types/drift.js +4 -0
- package/dist/src/types/enterprise.js +5 -0
- package/dist/src/types/index.js +14 -0
- package/dist/src/types/plan.js +1 -0
- package/dist/src/types/request.js +1 -0
- package/dist/src/types/response.js +1 -0
- package/dist/src/types/service.js +1 -0
- package/dist/src/ui/App.js +1672 -0
- package/dist/src/ui/DeployPreview.js +60 -0
- package/dist/src/ui/FileDiffModal.js +108 -0
- package/dist/src/ui/Header.js +46 -0
- package/dist/src/ui/HelpModal.js +9 -0
- package/dist/src/ui/InputBox.js +408 -0
- package/dist/src/ui/MessageList.js +795 -0
- package/dist/src/ui/PermissionPrompt.js +72 -0
- package/dist/src/ui/StatusBar.js +109 -0
- package/dist/src/ui/TerminalPane.js +31 -0
- package/dist/src/ui/ToolCallDisplay.js +303 -0
- package/dist/src/ui/TreePane.js +83 -0
- package/dist/src/ui/chat-ui.js +721 -0
- package/dist/src/ui/index.js +11 -0
- package/dist/src/ui/ink/index.js +1325 -0
- package/dist/src/ui/streaming.js +137 -0
- package/dist/src/ui/theme.js +78 -0
- package/dist/src/ui/types.js +7 -0
- package/dist/src/utils/analytics.js +61 -0
- package/dist/src/utils/cost-warning.js +25 -0
- package/dist/src/utils/env.js +42 -0
- package/dist/src/utils/errors.js +54 -0
- package/dist/src/utils/event-bus.js +22 -0
- package/dist/src/utils/index.js +16 -0
- package/dist/src/utils/logger.js +150 -0
- package/dist/src/utils/rate-limiter.js +90 -0
- package/dist/src/utils/service-auth.js +36 -0
- package/dist/src/utils/validation.js +39 -0
- package/dist/src/version.js +3 -0
- package/dist/src/watcher/index.js +192 -0
- package/dist/src/wizard/approval.js +275 -0
- package/dist/src/wizard/index.js +13 -0
- package/dist/src/wizard/prompts.js +273 -0
- package/dist/src/wizard/types.js +4 -0
- package/dist/src/wizard/ui.js +453 -0
- package/dist/src/wizard/wizard.js +227 -0
- package/package.json +31 -23
- package/src/__tests__/alias.test.ts +133 -0
- package/src/__tests__/app.test.ts +1 -1
- package/src/__tests__/audit.test.ts +1 -1
- package/src/__tests__/circuit-breaker.test.ts +1 -1
- package/src/__tests__/cli-run.test.ts +237 -1
- package/src/__tests__/compat-sqlite.test.ts +68 -0
- package/src/__tests__/context-manager.test.ts +131 -1
- package/src/__tests__/context.test.ts +1 -1
- package/src/__tests__/devops-terminal-gaps.test.ts +718 -0
- package/src/__tests__/doctor.test.ts +48 -0
- package/src/__tests__/enterprise.test.ts +1 -1
- package/src/__tests__/export.test.ts +236 -0
- package/src/__tests__/gap-11-18-20.test.ts +958 -0
- package/src/__tests__/generator.test.ts +1 -1
- package/src/__tests__/helm-streaming.test.ts +127 -0
- package/src/__tests__/hooks.test.ts +1 -1
- package/src/__tests__/incident.test.ts +179 -0
- package/src/__tests__/init.test.ts +55 -4
- package/src/__tests__/intent-parser.test.ts +1 -1
- package/src/__tests__/llm-router.test.ts +1 -1
- package/src/__tests__/logs.test.ts +107 -0
- package/src/__tests__/loop-errors.test.ts +244 -0
- package/src/__tests__/lsp.test.ts +1 -1
- package/src/__tests__/modes.test.ts +1 -1
- package/src/__tests__/perf-optimizations.test.ts +847 -0
- package/src/__tests__/permissions.test.ts +1 -1
- package/src/__tests__/pipeline.test.ts +50 -0
- package/src/__tests__/polish-phase3.test.ts +340 -0
- package/src/__tests__/profile.test.ts +237 -0
- package/src/__tests__/rollback.test.ts +83 -0
- package/src/__tests__/runbook.test.ts +219 -0
- package/src/__tests__/schedule.test.ts +206 -0
- package/src/__tests__/serve.test.ts +1 -1
- package/src/__tests__/sessions.test.ts +96 -1
- package/src/__tests__/sharing.test.ts +53 -1
- package/src/__tests__/snapshots.test.ts +1 -1
- package/src/__tests__/standalone-migration.test.ts +199 -0
- package/src/__tests__/state-db.test.ts +1 -1
- package/src/__tests__/status.test.ts +158 -0
- package/src/__tests__/stream-with-tools.test.ts +71 -25
- package/src/__tests__/subagents.test.ts +1 -1
- package/src/__tests__/system-prompt.test.ts +82 -3
- package/src/__tests__/terminal-gap-v2.test.ts +395 -0
- package/src/__tests__/terminal-parity.test.ts +393 -0
- package/src/__tests__/tf-apply.test.ts +187 -0
- package/src/__tests__/tool-converter.test.ts +1 -1
- package/src/__tests__/tool-schemas.test.ts +209 -4
- package/src/__tests__/tools.test.ts +4 -3
- package/src/__tests__/version-json.test.ts +184 -0
- package/src/__tests__/version.test.ts +1 -1
- package/src/__tests__/watch.test.ts +129 -0
- package/src/agent/compaction-agent.ts +40 -1
- package/src/agent/context-manager.ts +67 -3
- package/src/agent/deploy-preview.ts +62 -1
- package/src/agent/expand-files.ts +108 -0
- package/src/agent/loop.ts +1312 -31
- package/src/agent/permissions.ts +51 -4
- package/src/agent/system-prompt.ts +573 -19
- package/src/app.ts +58 -0
- package/src/audit/security-scanner.ts +45 -0
- package/src/auth/keychain.ts +82 -0
- package/src/auth/oauth.ts +15 -5
- package/src/cli/init.ts +378 -5
- package/src/cli/run.ts +407 -16
- package/src/cli/serve.ts +78 -1
- package/src/cli/web.ts +10 -6
- package/src/cli.ts +312 -1
- package/src/clients/service-discovery.ts +30 -25
- package/src/commands/alias.ts +100 -0
- package/src/commands/audit/index.ts +121 -2
- package/src/commands/auth-cloud.ts +113 -0
- package/src/commands/auth-refresh.ts +187 -0
- package/src/commands/aws-discover.ts +144 -251
- package/src/commands/aws-terraform.ts +68 -118
- package/src/commands/chat.ts +9 -3
- package/src/commands/completions.ts +268 -0
- package/src/commands/config.ts +26 -0
- package/src/commands/cost/index.ts +218 -2
- package/src/commands/deploy.ts +260 -0
- package/src/commands/doctor.ts +744 -152
- package/src/commands/drift/index.ts +371 -23
- package/src/commands/export.ts +146 -0
- package/src/commands/generate-k8s.ts +9 -61
- package/src/commands/generate-terraform.ts +191 -449
- package/src/commands/help.ts +212 -36
- package/src/commands/history.ts +8 -1
- package/src/commands/incident.ts +166 -0
- package/src/commands/init.ts +5 -0
- package/src/commands/login.ts +86 -1
- package/src/commands/logs.ts +167 -0
- package/src/commands/onboarding.ts +211 -34
- package/src/commands/pipeline.ts +186 -0
- package/src/commands/plugin.ts +398 -0
- package/src/commands/profile.ts +342 -0
- package/src/commands/questionnaire.ts +0 -98
- package/src/commands/resume.ts +26 -34
- package/src/commands/rollback.ts +315 -0
- package/src/commands/rollout.ts +88 -0
- package/src/commands/runbook.ts +346 -0
- package/src/commands/schedule.ts +236 -0
- package/src/commands/status.ts +252 -0
- package/src/commands/team-context.ts +220 -0
- package/src/commands/template.ts +58 -57
- package/src/commands/tf/index.ts +70 -11
- package/src/commands/upgrade.ts +57 -0
- package/src/commands/version.ts +54 -50
- package/src/commands/watch.ts +153 -0
- package/src/compat/runtime.ts +1 -1
- package/src/compat/sqlite.ts +75 -5
- package/src/config/mode-store.ts +62 -0
- package/src/config/profiles.ts +84 -0
- package/src/config/types.ts +83 -1
- package/src/config/workspace-state.ts +53 -0
- package/src/engine/cost-estimator.ts +52 -10
- package/src/engine/executor.ts +33 -2
- package/src/engine/planner.ts +68 -1
- package/src/generator/terraform.ts +8 -0
- package/src/history/manager.ts +2 -74
- package/src/hooks/engine.ts +5 -4
- package/src/llm/cost-calculator.ts +2 -2
- package/src/llm/providers/anthropic.ts +50 -21
- package/src/llm/router.ts +76 -7
- package/src/lsp/languages.ts +3 -0
- package/src/lsp/manager.ts +21 -5
- package/src/nimbus.ts +37 -18
- package/src/sessions/manager.ts +108 -1
- package/src/sharing/sync.ts +4 -0
- package/src/sharing/viewer.ts +66 -0
- package/src/tools/file-ops.ts +22 -0
- package/src/tools/schemas/devops.ts +3007 -117
- package/src/tools/schemas/standard.ts +5 -1
- package/src/tools/schemas/types.ts +31 -1
- package/src/tools/spawn-exec.ts +148 -0
- package/src/ui/App.tsx +1183 -66
- package/src/ui/DeployPreview.tsx +62 -57
- package/src/ui/FileDiffModal.tsx +162 -0
- package/src/ui/Header.tsx +87 -24
- package/src/ui/HelpModal.tsx +57 -0
- package/src/ui/InputBox.tsx +163 -10
- package/src/ui/MessageList.tsx +487 -40
- package/src/ui/PermissionPrompt.tsx +17 -5
- package/src/ui/StatusBar.tsx +122 -3
- package/src/ui/TerminalPane.tsx +84 -0
- package/src/ui/ToolCallDisplay.tsx +252 -18
- package/src/ui/TreePane.tsx +132 -0
- package/src/ui/chat-ui.ts +41 -44
- package/src/ui/ink/index.ts +771 -38
- package/src/ui/streaming.ts +1 -1
- package/src/ui/theme.ts +104 -0
- package/src/ui/types.ts +18 -0
- package/src/version.ts +1 -1
- package/src/watcher/index.ts +66 -15
- package/src/wizard/types.ts +1 -0
- package/src/wizard/ui.ts +1 -1
- package/tsconfig.json +2 -2
|
@@ -0,0 +1,782 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import Command
|
|
3
|
+
*
|
|
4
|
+
* Import existing cloud resources into Terraform state
|
|
5
|
+
*/
|
|
6
|
+
import { ui } from '../wizard/ui';
|
|
7
|
+
import { select, input, multiSelect } from '../wizard/prompts';
|
|
8
|
+
import * as fs from 'node:fs';
|
|
9
|
+
import * as path from 'node:path';
|
|
10
|
+
import { execSync } from 'node:child_process';
|
|
11
|
+
// ==========================================
|
|
12
|
+
// Constants
|
|
13
|
+
// ==========================================
|
|
14
|
+
const IMPORTABLE_RESOURCES = [
|
|
15
|
+
// AWS
|
|
16
|
+
{
|
|
17
|
+
terraformType: 'aws_vpc',
|
|
18
|
+
cloudType: 'vpc',
|
|
19
|
+
description: 'Virtual Private Cloud',
|
|
20
|
+
provider: 'aws',
|
|
21
|
+
},
|
|
22
|
+
{ terraformType: 'aws_subnet', cloudType: 'subnet', description: 'VPC Subnet', provider: 'aws' },
|
|
23
|
+
{
|
|
24
|
+
terraformType: 'aws_security_group',
|
|
25
|
+
cloudType: 'security-group',
|
|
26
|
+
description: 'Security Group',
|
|
27
|
+
provider: 'aws',
|
|
28
|
+
},
|
|
29
|
+
{ terraformType: 'aws_instance', cloudType: 'ec2', description: 'EC2 Instance', provider: 'aws' },
|
|
30
|
+
{
|
|
31
|
+
terraformType: 'aws_db_instance',
|
|
32
|
+
cloudType: 'rds',
|
|
33
|
+
description: 'RDS Database',
|
|
34
|
+
provider: 'aws',
|
|
35
|
+
},
|
|
36
|
+
{ terraformType: 'aws_s3_bucket', cloudType: 's3', description: 'S3 Bucket', provider: 'aws' },
|
|
37
|
+
{
|
|
38
|
+
terraformType: 'aws_lambda_function',
|
|
39
|
+
cloudType: 'lambda',
|
|
40
|
+
description: 'Lambda Function',
|
|
41
|
+
provider: 'aws',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
terraformType: 'aws_iam_role',
|
|
45
|
+
cloudType: 'iam-role',
|
|
46
|
+
description: 'IAM Role',
|
|
47
|
+
provider: 'aws',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
terraformType: 'aws_eks_cluster',
|
|
51
|
+
cloudType: 'eks',
|
|
52
|
+
description: 'EKS Cluster',
|
|
53
|
+
provider: 'aws',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
terraformType: 'aws_elasticache_cluster',
|
|
57
|
+
cloudType: 'elasticache',
|
|
58
|
+
description: 'ElastiCache Cluster',
|
|
59
|
+
provider: 'aws',
|
|
60
|
+
},
|
|
61
|
+
// GCP
|
|
62
|
+
{
|
|
63
|
+
terraformType: 'google_compute_network',
|
|
64
|
+
cloudType: 'vpc',
|
|
65
|
+
description: 'VPC Network',
|
|
66
|
+
provider: 'gcp',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
terraformType: 'google_compute_subnetwork',
|
|
70
|
+
cloudType: 'subnet',
|
|
71
|
+
description: 'VPC Subnet',
|
|
72
|
+
provider: 'gcp',
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
terraformType: 'google_compute_instance',
|
|
76
|
+
cloudType: 'gce',
|
|
77
|
+
description: 'Compute Instance',
|
|
78
|
+
provider: 'gcp',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
terraformType: 'google_sql_database_instance',
|
|
82
|
+
cloudType: 'cloudsql',
|
|
83
|
+
description: 'Cloud SQL Instance',
|
|
84
|
+
provider: 'gcp',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
terraformType: 'google_storage_bucket',
|
|
88
|
+
cloudType: 'gcs',
|
|
89
|
+
description: 'Cloud Storage Bucket',
|
|
90
|
+
provider: 'gcp',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
terraformType: 'google_cloudfunctions_function',
|
|
94
|
+
cloudType: 'functions',
|
|
95
|
+
description: 'Cloud Function',
|
|
96
|
+
provider: 'gcp',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
terraformType: 'google_container_cluster',
|
|
100
|
+
cloudType: 'gke',
|
|
101
|
+
description: 'GKE Cluster',
|
|
102
|
+
provider: 'gcp',
|
|
103
|
+
},
|
|
104
|
+
// Azure
|
|
105
|
+
{
|
|
106
|
+
terraformType: 'azurerm_virtual_network',
|
|
107
|
+
cloudType: 'vnet',
|
|
108
|
+
description: 'Virtual Network',
|
|
109
|
+
provider: 'azure',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
terraformType: 'azurerm_subnet',
|
|
113
|
+
cloudType: 'subnet',
|
|
114
|
+
description: 'Subnet',
|
|
115
|
+
provider: 'azure',
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
terraformType: 'azurerm_virtual_machine',
|
|
119
|
+
cloudType: 'vm',
|
|
120
|
+
description: 'Virtual Machine',
|
|
121
|
+
provider: 'azure',
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
terraformType: 'azurerm_sql_database',
|
|
125
|
+
cloudType: 'sql',
|
|
126
|
+
description: 'SQL Database',
|
|
127
|
+
provider: 'azure',
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
terraformType: 'azurerm_storage_account',
|
|
131
|
+
cloudType: 'storage',
|
|
132
|
+
description: 'Storage Account',
|
|
133
|
+
provider: 'azure',
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
terraformType: 'azurerm_function_app',
|
|
137
|
+
cloudType: 'functions',
|
|
138
|
+
description: 'Function App',
|
|
139
|
+
provider: 'azure',
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
terraformType: 'azurerm_kubernetes_cluster',
|
|
143
|
+
cloudType: 'aks',
|
|
144
|
+
description: 'AKS Cluster',
|
|
145
|
+
provider: 'azure',
|
|
146
|
+
},
|
|
147
|
+
];
|
|
148
|
+
// ==========================================
|
|
149
|
+
// Parsers
|
|
150
|
+
// ==========================================
|
|
151
|
+
/**
|
|
152
|
+
* Parse import options
|
|
153
|
+
*/
|
|
154
|
+
export function parseImportOptions(args) {
|
|
155
|
+
const options = {};
|
|
156
|
+
for (let i = 0; i < args.length; i++) {
|
|
157
|
+
const arg = args[i];
|
|
158
|
+
if (arg === '--provider' && args[i + 1]) {
|
|
159
|
+
options.provider = args[++i];
|
|
160
|
+
}
|
|
161
|
+
else if (arg === '--resource-type' && args[i + 1]) {
|
|
162
|
+
options.resourceType = args[++i];
|
|
163
|
+
}
|
|
164
|
+
else if (arg === '--resource-id' && args[i + 1]) {
|
|
165
|
+
options.resourceId = args[++i];
|
|
166
|
+
}
|
|
167
|
+
else if (arg === '--output' && args[i + 1]) {
|
|
168
|
+
options.output = args[++i];
|
|
169
|
+
}
|
|
170
|
+
else if (arg === '-o' && args[i + 1]) {
|
|
171
|
+
options.output = args[++i];
|
|
172
|
+
}
|
|
173
|
+
else if (arg === '--region' && args[i + 1]) {
|
|
174
|
+
options.region = args[++i];
|
|
175
|
+
}
|
|
176
|
+
else if (arg === '--non-interactive' || arg === '-y') {
|
|
177
|
+
options.nonInteractive = true;
|
|
178
|
+
}
|
|
179
|
+
else if (!arg.startsWith('-') && !options.provider) {
|
|
180
|
+
options.provider = arg;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return options;
|
|
184
|
+
}
|
|
185
|
+
// ==========================================
|
|
186
|
+
// Discovery Functions
|
|
187
|
+
// ==========================================
|
|
188
|
+
/**
|
|
189
|
+
* Discover AWS resources
|
|
190
|
+
*/
|
|
191
|
+
function discoverAwsResources(resourceType, region) {
|
|
192
|
+
const resources = [];
|
|
193
|
+
try {
|
|
194
|
+
switch (resourceType) {
|
|
195
|
+
case 'vpc': {
|
|
196
|
+
const output = execSync(`aws ec2 describe-vpcs --region ${region} --query 'Vpcs[*].{id:VpcId,name:Tags[?Key==\`Name\`].Value|[0]}' --output json`, { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] });
|
|
197
|
+
const vpcs = JSON.parse(output);
|
|
198
|
+
for (const vpc of vpcs) {
|
|
199
|
+
resources.push({
|
|
200
|
+
id: vpc.id,
|
|
201
|
+
name: vpc.name || vpc.id,
|
|
202
|
+
type: 'aws_vpc',
|
|
203
|
+
region,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
case 's3': {
|
|
209
|
+
const output = execSync(`aws s3api list-buckets --query 'Buckets[*].Name' --output json`, {
|
|
210
|
+
encoding: 'utf-8',
|
|
211
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
212
|
+
});
|
|
213
|
+
const buckets = JSON.parse(output);
|
|
214
|
+
for (const bucket of buckets) {
|
|
215
|
+
resources.push({
|
|
216
|
+
id: bucket,
|
|
217
|
+
name: bucket,
|
|
218
|
+
type: 'aws_s3_bucket',
|
|
219
|
+
region: 'global',
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case 'ec2': {
|
|
225
|
+
const output = execSync(`aws ec2 describe-instances --region ${region} --query 'Reservations[*].Instances[*].{id:InstanceId,name:Tags[?Key==\`Name\`].Value|[0],state:State.Name}' --output json`, { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] });
|
|
226
|
+
const reservations = JSON.parse(output);
|
|
227
|
+
for (const instances of reservations) {
|
|
228
|
+
for (const instance of instances) {
|
|
229
|
+
if (instance.state !== 'terminated') {
|
|
230
|
+
resources.push({
|
|
231
|
+
id: instance.id,
|
|
232
|
+
name: instance.name || instance.id,
|
|
233
|
+
type: 'aws_instance',
|
|
234
|
+
region,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
case 'rds': {
|
|
242
|
+
const output = execSync(`aws rds describe-db-instances --region ${region} --query 'DBInstances[*].{id:DBInstanceIdentifier,arn:DBInstanceArn}' --output json`, { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] });
|
|
243
|
+
const instances = JSON.parse(output);
|
|
244
|
+
for (const db of instances) {
|
|
245
|
+
resources.push({
|
|
246
|
+
id: db.id,
|
|
247
|
+
name: db.id,
|
|
248
|
+
type: 'aws_db_instance',
|
|
249
|
+
region,
|
|
250
|
+
arn: db.arn,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
case 'security-group': {
|
|
256
|
+
const output = execSync(`aws ec2 describe-security-groups --region ${region} --query 'SecurityGroups[*].{id:GroupId,name:GroupName}' --output json`, { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] });
|
|
257
|
+
const groups = JSON.parse(output);
|
|
258
|
+
for (const sg of groups) {
|
|
259
|
+
resources.push({
|
|
260
|
+
id: sg.id,
|
|
261
|
+
name: sg.name,
|
|
262
|
+
type: 'aws_security_group',
|
|
263
|
+
region,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
// AWS CLI not available or not authenticated
|
|
272
|
+
}
|
|
273
|
+
return resources;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Discover GCP resources
|
|
277
|
+
*/
|
|
278
|
+
function discoverGcpResources(resourceType, project) {
|
|
279
|
+
const resources = [];
|
|
280
|
+
const projectFlag = project ? `--project=${project}` : '';
|
|
281
|
+
try {
|
|
282
|
+
switch (resourceType) {
|
|
283
|
+
case 'vpc': {
|
|
284
|
+
const output = execSync(`gcloud compute networks list ${projectFlag} --format=json`, {
|
|
285
|
+
encoding: 'utf-8',
|
|
286
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
287
|
+
});
|
|
288
|
+
const networks = JSON.parse(output);
|
|
289
|
+
for (const net of networks) {
|
|
290
|
+
resources.push({
|
|
291
|
+
id: net.name,
|
|
292
|
+
name: net.name,
|
|
293
|
+
type: 'google_compute_network',
|
|
294
|
+
region: 'global',
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
case 'gce': {
|
|
300
|
+
const output = execSync(`gcloud compute instances list ${projectFlag} --format=json`, {
|
|
301
|
+
encoding: 'utf-8',
|
|
302
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
303
|
+
});
|
|
304
|
+
const instances = JSON.parse(output);
|
|
305
|
+
for (const inst of instances) {
|
|
306
|
+
const zone = inst.zone?.split('/').pop() || 'unknown';
|
|
307
|
+
resources.push({
|
|
308
|
+
id: inst.name,
|
|
309
|
+
name: inst.name,
|
|
310
|
+
type: 'google_compute_instance',
|
|
311
|
+
region: zone,
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
case 'cloudsql': {
|
|
317
|
+
const output = execSync(`gcloud sql instances list ${projectFlag} --format=json`, {
|
|
318
|
+
encoding: 'utf-8',
|
|
319
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
320
|
+
});
|
|
321
|
+
const instances = JSON.parse(output);
|
|
322
|
+
for (const db of instances) {
|
|
323
|
+
resources.push({
|
|
324
|
+
id: db.name,
|
|
325
|
+
name: db.name,
|
|
326
|
+
type: 'google_sql_database_instance',
|
|
327
|
+
region: db.region || 'unknown',
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
case 'gcs': {
|
|
333
|
+
const output = execSync(`gcloud storage buckets list ${projectFlag} --format=json`, {
|
|
334
|
+
encoding: 'utf-8',
|
|
335
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
336
|
+
});
|
|
337
|
+
const buckets = JSON.parse(output);
|
|
338
|
+
for (const bucket of buckets) {
|
|
339
|
+
const name = bucket.name || bucket.id?.replace('projects/_/buckets/', '') || 'unknown';
|
|
340
|
+
resources.push({
|
|
341
|
+
id: name,
|
|
342
|
+
name,
|
|
343
|
+
type: 'google_storage_bucket',
|
|
344
|
+
region: bucket.location || 'global',
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
catch (error) {
|
|
352
|
+
// gcloud CLI not available or not authenticated
|
|
353
|
+
}
|
|
354
|
+
return resources;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Discover Azure resources
|
|
358
|
+
*/
|
|
359
|
+
function discoverAzureResources(resourceType, subscription) {
|
|
360
|
+
const resources = [];
|
|
361
|
+
const subFlag = subscription ? `--subscription "${subscription}"` : '';
|
|
362
|
+
try {
|
|
363
|
+
switch (resourceType) {
|
|
364
|
+
case 'vm': {
|
|
365
|
+
const output = execSync(`az vm list ${subFlag} -o json`, {
|
|
366
|
+
encoding: 'utf-8',
|
|
367
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
368
|
+
});
|
|
369
|
+
const vms = JSON.parse(output);
|
|
370
|
+
for (const vm of vms) {
|
|
371
|
+
resources.push({
|
|
372
|
+
id: vm.id,
|
|
373
|
+
name: vm.name,
|
|
374
|
+
type: 'azurerm_virtual_machine',
|
|
375
|
+
region: vm.location || 'unknown',
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
case 'vnet': {
|
|
381
|
+
const output = execSync(`az network vnet list ${subFlag} -o json`, {
|
|
382
|
+
encoding: 'utf-8',
|
|
383
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
384
|
+
});
|
|
385
|
+
const vnets = JSON.parse(output);
|
|
386
|
+
for (const vnet of vnets) {
|
|
387
|
+
resources.push({
|
|
388
|
+
id: vnet.id,
|
|
389
|
+
name: vnet.name,
|
|
390
|
+
type: 'azurerm_virtual_network',
|
|
391
|
+
region: vnet.location || 'unknown',
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
case 'sql': {
|
|
397
|
+
const output = execSync(`az sql server list ${subFlag} -o json`, {
|
|
398
|
+
encoding: 'utf-8',
|
|
399
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
400
|
+
});
|
|
401
|
+
const servers = JSON.parse(output);
|
|
402
|
+
for (const server of servers) {
|
|
403
|
+
resources.push({
|
|
404
|
+
id: server.id,
|
|
405
|
+
name: server.name,
|
|
406
|
+
type: 'azurerm_sql_database',
|
|
407
|
+
region: server.location || 'unknown',
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
case 'storage': {
|
|
413
|
+
const output = execSync(`az storage account list ${subFlag} -o json`, {
|
|
414
|
+
encoding: 'utf-8',
|
|
415
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
416
|
+
});
|
|
417
|
+
const accounts = JSON.parse(output);
|
|
418
|
+
for (const acct of accounts) {
|
|
419
|
+
resources.push({
|
|
420
|
+
id: acct.id,
|
|
421
|
+
name: acct.name,
|
|
422
|
+
type: 'azurerm_storage_account',
|
|
423
|
+
region: acct.location || 'unknown',
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
catch (error) {
|
|
431
|
+
// az CLI not available or not authenticated
|
|
432
|
+
}
|
|
433
|
+
return resources;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Generate Terraform import block
|
|
437
|
+
*/
|
|
438
|
+
function generateImportBlock(resource, terraformName) {
|
|
439
|
+
return `import {
|
|
440
|
+
to = ${resource.type}.${terraformName}
|
|
441
|
+
id = "${resource.id}"
|
|
442
|
+
}
|
|
443
|
+
`;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Generate Terraform resource skeleton
|
|
447
|
+
*/
|
|
448
|
+
function generateResourceSkeleton(resource, terraformName) {
|
|
449
|
+
const lines = [`resource "${resource.type}" "${terraformName}" {`];
|
|
450
|
+
switch (resource.type) {
|
|
451
|
+
case 'aws_vpc':
|
|
452
|
+
lines.push(' # cidr_block = "10.0.0.0/16"');
|
|
453
|
+
lines.push(' # enable_dns_hostnames = true');
|
|
454
|
+
lines.push(' # enable_dns_support = true');
|
|
455
|
+
break;
|
|
456
|
+
case 'aws_s3_bucket':
|
|
457
|
+
lines.push(` bucket = "${resource.id}"`);
|
|
458
|
+
break;
|
|
459
|
+
case 'aws_instance':
|
|
460
|
+
lines.push(' # ami = "ami-..."');
|
|
461
|
+
lines.push(' # instance_type = "t3.micro"');
|
|
462
|
+
break;
|
|
463
|
+
case 'aws_db_instance':
|
|
464
|
+
lines.push(` identifier = "${resource.id}"`);
|
|
465
|
+
lines.push(' # instance_class = "db.t3.micro"');
|
|
466
|
+
lines.push(' # engine = "mysql"');
|
|
467
|
+
break;
|
|
468
|
+
case 'aws_security_group':
|
|
469
|
+
lines.push(` name = "${resource.name}"`);
|
|
470
|
+
lines.push(' # vpc_id = aws_vpc.main.id');
|
|
471
|
+
break;
|
|
472
|
+
// GCP resources
|
|
473
|
+
case 'google_compute_network':
|
|
474
|
+
lines.push(` name = "${resource.id}"`);
|
|
475
|
+
lines.push(' auto_create_subnetworks = false');
|
|
476
|
+
break;
|
|
477
|
+
case 'google_compute_instance':
|
|
478
|
+
lines.push(` name = "${resource.id}"`);
|
|
479
|
+
lines.push(' # machine_type = "e2-medium"');
|
|
480
|
+
lines.push(` # zone = "${resource.region}"`);
|
|
481
|
+
break;
|
|
482
|
+
case 'google_sql_database_instance':
|
|
483
|
+
lines.push(` name = "${resource.id}"`);
|
|
484
|
+
lines.push(' # database_version = "MYSQL_8_0"');
|
|
485
|
+
lines.push(` # region = "${resource.region}"`);
|
|
486
|
+
break;
|
|
487
|
+
case 'google_storage_bucket':
|
|
488
|
+
lines.push(` name = "${resource.id}"`);
|
|
489
|
+
lines.push(` location = "${resource.region}"`);
|
|
490
|
+
break;
|
|
491
|
+
// Azure resources
|
|
492
|
+
case 'azurerm_virtual_network':
|
|
493
|
+
lines.push(` name = "${resource.name}"`);
|
|
494
|
+
lines.push(` location = "${resource.region}"`);
|
|
495
|
+
lines.push(' # resource_group_name = "my-rg"');
|
|
496
|
+
lines.push(' # address_space = ["10.0.0.0/16"]');
|
|
497
|
+
break;
|
|
498
|
+
case 'azurerm_virtual_machine':
|
|
499
|
+
lines.push(` name = "${resource.name}"`);
|
|
500
|
+
lines.push(` location = "${resource.region}"`);
|
|
501
|
+
lines.push(' # resource_group_name = "my-rg"');
|
|
502
|
+
lines.push(' # vm_size = "Standard_DS1_v2"');
|
|
503
|
+
break;
|
|
504
|
+
case 'azurerm_sql_database':
|
|
505
|
+
lines.push(` name = "${resource.name}"`);
|
|
506
|
+
lines.push(' # server_name = "my-sql-server"');
|
|
507
|
+
lines.push(' # resource_group_name = "my-rg"');
|
|
508
|
+
break;
|
|
509
|
+
case 'azurerm_storage_account':
|
|
510
|
+
lines.push(` name = "${resource.name}"`);
|
|
511
|
+
lines.push(` location = "${resource.region}"`);
|
|
512
|
+
lines.push(' # resource_group_name = "my-rg"');
|
|
513
|
+
lines.push(' # account_tier = "Standard"');
|
|
514
|
+
lines.push(' # account_replication_type = "LRS"');
|
|
515
|
+
break;
|
|
516
|
+
default:
|
|
517
|
+
// Generate sensible stubs for unknown resource types using available metadata
|
|
518
|
+
if (resource.name) {
|
|
519
|
+
lines.push(` name = "${resource.name}"`);
|
|
520
|
+
}
|
|
521
|
+
if (resource.region) {
|
|
522
|
+
lines.push(` location = "${resource.region}"`);
|
|
523
|
+
}
|
|
524
|
+
lines.push('');
|
|
525
|
+
lines.push(' # Nimbus could not determine the exact attributes for this resource type.');
|
|
526
|
+
lines.push(` # Resource type: ${resource.type}`);
|
|
527
|
+
lines.push(` # Resource ID: ${resource.id}`);
|
|
528
|
+
lines.push(' #');
|
|
529
|
+
lines.push(' # Next steps:');
|
|
530
|
+
lines.push(' # 1. Run: terraform plan');
|
|
531
|
+
lines.push(' # 2. Review the plan output for required attributes.');
|
|
532
|
+
lines.push(' # 3. Add any missing attributes below with placeholder values.');
|
|
533
|
+
lines.push(' #');
|
|
534
|
+
lines.push(' # Common attributes for most resources:');
|
|
535
|
+
lines.push(' # description = "REPLACE_ME"');
|
|
536
|
+
lines.push(' # tags = {');
|
|
537
|
+
lines.push(' # Environment = "production"');
|
|
538
|
+
lines.push(' # ManagedBy = "terraform"');
|
|
539
|
+
lines.push(' # }');
|
|
540
|
+
}
|
|
541
|
+
if (resource.name && resource.name !== resource.id) {
|
|
542
|
+
lines.push('');
|
|
543
|
+
lines.push(' tags = {');
|
|
544
|
+
lines.push(` Name = "${resource.name}"`);
|
|
545
|
+
lines.push(' }');
|
|
546
|
+
}
|
|
547
|
+
lines.push('}');
|
|
548
|
+
return lines.join('\n');
|
|
549
|
+
}
|
|
550
|
+
// ==========================================
|
|
551
|
+
// Command
|
|
552
|
+
// ==========================================
|
|
553
|
+
/**
|
|
554
|
+
* Import command
|
|
555
|
+
*/
|
|
556
|
+
export async function importCommand(options) {
|
|
557
|
+
ui.header('Nimbus Import', 'Import existing cloud resources into Terraform');
|
|
558
|
+
// Select provider
|
|
559
|
+
let provider = options.provider;
|
|
560
|
+
if (!provider) {
|
|
561
|
+
provider = (await select({
|
|
562
|
+
message: 'Select cloud provider:',
|
|
563
|
+
options: [
|
|
564
|
+
{ label: 'AWS', value: 'aws', description: 'Amazon Web Services' },
|
|
565
|
+
{ label: 'GCP', value: 'gcp', description: 'Google Cloud Platform' },
|
|
566
|
+
{ label: 'Azure', value: 'azure', description: 'Microsoft Azure' },
|
|
567
|
+
],
|
|
568
|
+
}));
|
|
569
|
+
}
|
|
570
|
+
// Get region/project/subscription
|
|
571
|
+
let region = options.region;
|
|
572
|
+
if (!region) {
|
|
573
|
+
if (provider === 'aws') {
|
|
574
|
+
region = await input({
|
|
575
|
+
message: 'AWS Region:',
|
|
576
|
+
defaultValue: process.env.AWS_DEFAULT_REGION || 'us-east-1',
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
else if (provider === 'gcp') {
|
|
580
|
+
region = await input({
|
|
581
|
+
message: 'GCP Project ID:',
|
|
582
|
+
defaultValue: process.env.GCLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT || '',
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
else if (provider === 'azure') {
|
|
586
|
+
region = await input({
|
|
587
|
+
message: 'Azure Subscription ID (optional):',
|
|
588
|
+
defaultValue: process.env.AZURE_SUBSCRIPTION_ID || '',
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
// Get available resource types for this provider
|
|
593
|
+
const providerResources = IMPORTABLE_RESOURCES.filter(r => r.provider === provider);
|
|
594
|
+
// Select resource type
|
|
595
|
+
let resourceType = options.resourceType;
|
|
596
|
+
if (!resourceType) {
|
|
597
|
+
resourceType = (await select({
|
|
598
|
+
message: 'Select resource type to import:',
|
|
599
|
+
options: providerResources.map(r => ({
|
|
600
|
+
label: r.description,
|
|
601
|
+
value: r.cloudType,
|
|
602
|
+
description: r.terraformType,
|
|
603
|
+
})),
|
|
604
|
+
}));
|
|
605
|
+
}
|
|
606
|
+
const resourceInfo = providerResources.find(r => r.cloudType === resourceType);
|
|
607
|
+
if (!resourceInfo) {
|
|
608
|
+
ui.error(`Unknown resource type: ${resourceType}`);
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
ui.newLine();
|
|
612
|
+
ui.startSpinner({ message: `Discovering ${resourceInfo.description}s...` });
|
|
613
|
+
// Discover resources
|
|
614
|
+
let discovered = [];
|
|
615
|
+
if (provider === 'aws') {
|
|
616
|
+
discovered = discoverAwsResources(resourceType, region || 'us-east-1');
|
|
617
|
+
}
|
|
618
|
+
else if (provider === 'gcp') {
|
|
619
|
+
discovered = discoverGcpResources(resourceType, region);
|
|
620
|
+
}
|
|
621
|
+
else if (provider === 'azure') {
|
|
622
|
+
discovered = discoverAzureResources(resourceType, region);
|
|
623
|
+
}
|
|
624
|
+
if (discovered.length === 0) {
|
|
625
|
+
ui.stopSpinnerSuccess('Discovery complete');
|
|
626
|
+
ui.warning(`No ${resourceInfo.description}s found`);
|
|
627
|
+
ui.info(`Make sure you have the correct ${provider.toUpperCase()} credentials configured`);
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
ui.stopSpinnerSuccess(`Found ${discovered.length} ${resourceInfo.description}(s)`);
|
|
631
|
+
// Display discovered resources
|
|
632
|
+
ui.newLine();
|
|
633
|
+
ui.section('Discovered Resources');
|
|
634
|
+
for (const resource of discovered) {
|
|
635
|
+
ui.print(` ${ui.color('•', 'blue')} ${resource.name || resource.id}`);
|
|
636
|
+
ui.print(` ${ui.dim('ID:')} ${resource.id}`);
|
|
637
|
+
if (resource.region !== 'global') {
|
|
638
|
+
ui.print(` ${ui.dim('Region:')} ${resource.region}`);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
// Select resources to import
|
|
642
|
+
ui.newLine();
|
|
643
|
+
const selectedIds = await multiSelect({
|
|
644
|
+
message: 'Select resources to import:',
|
|
645
|
+
options: discovered.map(r => ({
|
|
646
|
+
label: r.name || r.id,
|
|
647
|
+
value: r.id,
|
|
648
|
+
description: r.id,
|
|
649
|
+
})),
|
|
650
|
+
});
|
|
651
|
+
if (selectedIds.length === 0) {
|
|
652
|
+
ui.info('No resources selected');
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
const selectedResources = discovered.filter(r => selectedIds.includes(r.id));
|
|
656
|
+
// Output directory
|
|
657
|
+
const outputDir = options.output ||
|
|
658
|
+
(await input({
|
|
659
|
+
message: 'Output directory:',
|
|
660
|
+
defaultValue: './terraform',
|
|
661
|
+
}));
|
|
662
|
+
// Create output directory
|
|
663
|
+
if (!fs.existsSync(outputDir)) {
|
|
664
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
665
|
+
}
|
|
666
|
+
// Generate Terraform files
|
|
667
|
+
ui.newLine();
|
|
668
|
+
ui.startSpinner({ message: 'Generating Terraform configuration...' });
|
|
669
|
+
const importBlocks = [];
|
|
670
|
+
const resourceBlocks = [];
|
|
671
|
+
for (const resource of selectedResources) {
|
|
672
|
+
// Generate a terraform-friendly name
|
|
673
|
+
const tfName = (resource.name || resource.id)
|
|
674
|
+
.toLowerCase()
|
|
675
|
+
.replace(/[^a-z0-9]/g, '_')
|
|
676
|
+
.replace(/_+/g, '_')
|
|
677
|
+
.replace(/^_|_$/g, '');
|
|
678
|
+
importBlocks.push(generateImportBlock(resource, tfName));
|
|
679
|
+
resourceBlocks.push(generateResourceSkeleton(resource, tfName));
|
|
680
|
+
}
|
|
681
|
+
// Write import.tf
|
|
682
|
+
const importFile = path.join(outputDir, 'import.tf');
|
|
683
|
+
const importContent = `# Terraform Import Configuration
|
|
684
|
+
# Generated by Nimbus
|
|
685
|
+
# Run: terraform init && terraform plan
|
|
686
|
+
|
|
687
|
+
${importBlocks.join('\n')}
|
|
688
|
+
`;
|
|
689
|
+
fs.writeFileSync(importFile, importContent);
|
|
690
|
+
// Write resources.tf
|
|
691
|
+
const resourceFile = path.join(outputDir, 'imported_resources.tf');
|
|
692
|
+
const resourceContent = `# Imported Resources
|
|
693
|
+
# Generated by Nimbus
|
|
694
|
+
#
|
|
695
|
+
# How to use this file:
|
|
696
|
+
# 1. Run: terraform init
|
|
697
|
+
# 2. Run: terraform plan -generate-config-out=generated.tf
|
|
698
|
+
# This will auto-generate configuration for imported resources.
|
|
699
|
+
# 3. Merge the generated attributes into the resource blocks below.
|
|
700
|
+
# 4. Run: terraform plan (verify no unexpected changes)
|
|
701
|
+
# 5. Run: terraform apply (lock the state)
|
|
702
|
+
#
|
|
703
|
+
# Example attributes you may need to fill in per resource:
|
|
704
|
+
# - name, location/region, tags
|
|
705
|
+
# - Provider-specific required fields (e.g., ami + instance_type for aws_instance)
|
|
706
|
+
#
|
|
707
|
+
# Tip: Use 'terraform state show <resource_address>' after import to see all current attributes.
|
|
708
|
+
|
|
709
|
+
${resourceBlocks.join('\n\n')}
|
|
710
|
+
`;
|
|
711
|
+
fs.writeFileSync(resourceFile, resourceContent);
|
|
712
|
+
// Check if provider.tf exists, if not create it
|
|
713
|
+
const providerFile = path.join(outputDir, 'provider.tf');
|
|
714
|
+
if (!fs.existsSync(providerFile)) {
|
|
715
|
+
let providerContent = '';
|
|
716
|
+
if (provider === 'aws') {
|
|
717
|
+
providerContent = `terraform {
|
|
718
|
+
required_providers {
|
|
719
|
+
aws = {
|
|
720
|
+
source = "hashicorp/aws"
|
|
721
|
+
version = "~> 5.0"
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
provider "aws" {
|
|
727
|
+
region = "${region || 'us-east-1'}"
|
|
728
|
+
}
|
|
729
|
+
`;
|
|
730
|
+
}
|
|
731
|
+
else if (provider === 'gcp') {
|
|
732
|
+
providerContent = `terraform {
|
|
733
|
+
required_providers {
|
|
734
|
+
google = {
|
|
735
|
+
source = "hashicorp/google"
|
|
736
|
+
version = "~> 5.0"
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
provider "google" {
|
|
742
|
+
project = "${region || 'my-project'}"
|
|
743
|
+
}
|
|
744
|
+
`;
|
|
745
|
+
}
|
|
746
|
+
else if (provider === 'azure') {
|
|
747
|
+
providerContent = `terraform {
|
|
748
|
+
required_providers {
|
|
749
|
+
azurerm = {
|
|
750
|
+
source = "hashicorp/azurerm"
|
|
751
|
+
version = "~> 3.0"
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
provider "azurerm" {
|
|
757
|
+
features {}
|
|
758
|
+
}
|
|
759
|
+
`;
|
|
760
|
+
}
|
|
761
|
+
fs.writeFileSync(providerFile, providerContent);
|
|
762
|
+
}
|
|
763
|
+
ui.stopSpinnerSuccess('Configuration generated');
|
|
764
|
+
// Summary
|
|
765
|
+
ui.newLine();
|
|
766
|
+
ui.success(`Generated Terraform configuration for ${selectedResources.length} resource(s)`);
|
|
767
|
+
ui.newLine();
|
|
768
|
+
ui.print(' Files created:');
|
|
769
|
+
ui.print(` ${ui.dim('•')} ${importFile}`);
|
|
770
|
+
ui.print(` ${ui.dim('•')} ${resourceFile}`);
|
|
771
|
+
ui.newLine();
|
|
772
|
+
ui.section('Next Steps');
|
|
773
|
+
ui.print(' 1. Review the generated configuration');
|
|
774
|
+
ui.print(` 2. Run ${ui.color(`cd ${outputDir}`, 'cyan')}`);
|
|
775
|
+
ui.print(` 3. Run ${ui.color('terraform init', 'cyan')}`);
|
|
776
|
+
ui.print(` 4. Run ${ui.color('terraform plan', 'cyan')} to import and verify`);
|
|
777
|
+
ui.print(' 5. Fill in any missing required attributes');
|
|
778
|
+
ui.print(` 6. Run ${ui.color('terraform apply', 'cyan')} to complete the import`);
|
|
779
|
+
ui.newLine();
|
|
780
|
+
ui.warning('Important: Review the generated resources.tf file and fill in required attributes');
|
|
781
|
+
ui.info('After import, run "terraform state show <resource>" to see the actual configuration');
|
|
782
|
+
}
|