@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,402 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS EC2 Commands
|
|
3
|
+
*
|
|
4
|
+
* EC2 instance operations with cost warnings before billable actions
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* nimbus aws ec2 list
|
|
8
|
+
* nimbus aws ec2 describe <instance-id>
|
|
9
|
+
* nimbus aws ec2 start <instance-id>
|
|
10
|
+
* nimbus aws ec2 stop <instance-id>
|
|
11
|
+
* nimbus aws ec2 terminate <instance-id>
|
|
12
|
+
*/
|
|
13
|
+
import { logger } from '../../utils';
|
|
14
|
+
import { ui } from '../../wizard/ui';
|
|
15
|
+
import { confirm } from '../../wizard/prompts';
|
|
16
|
+
import { loadSafetyPolicy, evaluateSafety, } from '../../config/safety-policy';
|
|
17
|
+
import { promptForApproval } from '../../wizard/approval';
|
|
18
|
+
import { estimateCloudCost, formatCostWarning } from '../cost/cloud-cost-estimator';
|
|
19
|
+
/**
|
|
20
|
+
* EC2 command router
|
|
21
|
+
*/
|
|
22
|
+
export async function ec2Command(action, args, options) {
|
|
23
|
+
logger.info('Running EC2 command', { action, args, options });
|
|
24
|
+
switch (action) {
|
|
25
|
+
case 'list':
|
|
26
|
+
case 'ls':
|
|
27
|
+
await listInstances(options);
|
|
28
|
+
break;
|
|
29
|
+
case 'describe':
|
|
30
|
+
if (!args[0]) {
|
|
31
|
+
ui.error('Instance ID is required');
|
|
32
|
+
ui.print('Usage: nimbus aws ec2 describe <instance-id>');
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
await describeInstance(args[0], options);
|
|
36
|
+
break;
|
|
37
|
+
case 'start':
|
|
38
|
+
if (!args[0]) {
|
|
39
|
+
ui.error('Instance ID is required');
|
|
40
|
+
ui.print('Usage: nimbus aws ec2 start <instance-id>');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
await startInstance(args[0], options);
|
|
44
|
+
break;
|
|
45
|
+
case 'stop':
|
|
46
|
+
if (!args[0]) {
|
|
47
|
+
ui.error('Instance ID is required');
|
|
48
|
+
ui.print('Usage: nimbus aws ec2 stop <instance-id>');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
await stopInstance(args[0], options);
|
|
52
|
+
break;
|
|
53
|
+
case 'terminate':
|
|
54
|
+
if (!args[0]) {
|
|
55
|
+
ui.error('Instance ID is required');
|
|
56
|
+
ui.print('Usage: nimbus aws ec2 terminate <instance-id>');
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
await terminateInstance(args[0], options);
|
|
60
|
+
break;
|
|
61
|
+
default:
|
|
62
|
+
showEc2Help();
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* List all EC2 instances
|
|
68
|
+
*/
|
|
69
|
+
async function listInstances(options) {
|
|
70
|
+
ui.header('EC2 Instances');
|
|
71
|
+
ui.startSpinner({ message: 'Fetching EC2 instances...' });
|
|
72
|
+
try {
|
|
73
|
+
const instances = await runAwsCommand('ec2 describe-instances --query "Reservations[].Instances[]"', options);
|
|
74
|
+
ui.stopSpinnerSuccess(`Found ${instances.length} instance(s)`);
|
|
75
|
+
ui.newLine();
|
|
76
|
+
if (instances.length === 0) {
|
|
77
|
+
ui.info('No EC2 instances found');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// Display table
|
|
81
|
+
displayInstanceTable(instances);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
ui.stopSpinnerFail('Failed to list instances');
|
|
85
|
+
ui.error(error.message);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Describe a specific EC2 instance
|
|
90
|
+
*/
|
|
91
|
+
async function describeInstance(instanceId, options) {
|
|
92
|
+
ui.header(`EC2 Instance: ${instanceId}`);
|
|
93
|
+
ui.startSpinner({ message: 'Fetching instance details...' });
|
|
94
|
+
try {
|
|
95
|
+
const instances = await runAwsCommand(`ec2 describe-instances --instance-ids ${instanceId} --query "Reservations[].Instances[]"`, options);
|
|
96
|
+
ui.stopSpinnerSuccess('Instance details retrieved');
|
|
97
|
+
ui.newLine();
|
|
98
|
+
if (instances.length === 0) {
|
|
99
|
+
ui.error(`Instance ${instanceId} not found`);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const instance = instances[0];
|
|
103
|
+
// Display instance details
|
|
104
|
+
ui.print(ui.bold('Instance Details:'));
|
|
105
|
+
ui.newLine();
|
|
106
|
+
ui.print(` Instance ID: ${instance.InstanceId}`);
|
|
107
|
+
ui.print(` Instance Type: ${instance.InstanceType}`);
|
|
108
|
+
ui.print(` State: ${formatState(instance.State.Name)}`);
|
|
109
|
+
ui.print(` Public IP: ${instance.PublicIpAddress || 'N/A'}`);
|
|
110
|
+
ui.print(` Private IP: ${instance.PrivateIpAddress || 'N/A'}`);
|
|
111
|
+
ui.print(` Launch Time: ${instance.LaunchTime || 'N/A'}`);
|
|
112
|
+
if (instance.Tags && instance.Tags.length > 0) {
|
|
113
|
+
ui.newLine();
|
|
114
|
+
ui.print(ui.bold('Tags:'));
|
|
115
|
+
for (const tag of instance.Tags) {
|
|
116
|
+
ui.print(` ${tag.Key}: ${tag.Value}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Show cost estimate for running instances
|
|
120
|
+
displayCostWarning(instance.InstanceType);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
ui.stopSpinnerFail('Failed to describe instance');
|
|
124
|
+
ui.error(error.message);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Display a cost warning for an EC2 instance type using the cloud cost estimator.
|
|
129
|
+
*/
|
|
130
|
+
function displayCostWarning(instanceType) {
|
|
131
|
+
const estimate = estimateCloudCost('ec2:StartInstances', { instanceType });
|
|
132
|
+
if (estimate) {
|
|
133
|
+
const color = estimate.monthly > 200 ? 'red' : estimate.monthly > 50 ? 'yellow' : 'green';
|
|
134
|
+
ui.newLine();
|
|
135
|
+
ui.print(ui.bold(' Estimated Cost:'));
|
|
136
|
+
ui.print(` Hourly: ${ui.color(`$${estimate.hourly.toFixed(4)}/hr`, color)}`);
|
|
137
|
+
ui.print(` Monthly: ${ui.color(`$${estimate.monthly.toFixed(2)}/mo`, color)} (on-demand, approximate)`);
|
|
138
|
+
ui.newLine();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Start an EC2 instance
|
|
143
|
+
*/
|
|
144
|
+
async function startInstance(instanceId, options) {
|
|
145
|
+
ui.header(`Start EC2 Instance: ${instanceId}`);
|
|
146
|
+
// Try to get instance type for cost estimate
|
|
147
|
+
try {
|
|
148
|
+
const instances = await runAwsCommand(`ec2 describe-instances --instance-ids ${instanceId} --query "Reservations[].Instances[]"`, options);
|
|
149
|
+
if (instances.length > 0) {
|
|
150
|
+
const instanceType = instances[0].InstanceType;
|
|
151
|
+
const estimate = estimateCloudCost('ec2:StartInstances', { instanceType });
|
|
152
|
+
if (estimate) {
|
|
153
|
+
ui.newLine();
|
|
154
|
+
ui.warning(formatCostWarning(estimate));
|
|
155
|
+
ui.newLine();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// Non-critical, continue without cost estimate
|
|
161
|
+
}
|
|
162
|
+
// Confirm action
|
|
163
|
+
const proceed = await confirm({
|
|
164
|
+
message: `Start instance ${instanceId}?`,
|
|
165
|
+
defaultValue: true,
|
|
166
|
+
});
|
|
167
|
+
if (!proceed) {
|
|
168
|
+
ui.info('Operation cancelled');
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
ui.startSpinner({ message: 'Starting instance...' });
|
|
172
|
+
try {
|
|
173
|
+
await runAwsCommand(`ec2 start-instances --instance-ids ${instanceId}`, options);
|
|
174
|
+
ui.stopSpinnerSuccess('Instance started');
|
|
175
|
+
ui.info(`Instance ${instanceId} is now starting`);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
ui.stopSpinnerFail('Failed to start instance');
|
|
179
|
+
ui.error(error.message);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Stop an EC2 instance
|
|
184
|
+
*/
|
|
185
|
+
async function stopInstance(instanceId, options) {
|
|
186
|
+
ui.header(`Stop EC2 Instance: ${instanceId}`);
|
|
187
|
+
// Show cost estimate for the instance being stopped
|
|
188
|
+
try {
|
|
189
|
+
const instances = await runAwsCommand(`ec2 describe-instances --instance-ids ${instanceId} --query "Reservations[].Instances[]"`, options);
|
|
190
|
+
if (instances.length > 0) {
|
|
191
|
+
displayCostWarning(instances[0].InstanceType);
|
|
192
|
+
ui.info('Stopping this instance will stop incurring compute charges.');
|
|
193
|
+
ui.newLine();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
// Non-critical, continue without cost estimate
|
|
198
|
+
}
|
|
199
|
+
// Run safety checks
|
|
200
|
+
const safetyResult = await runSafetyCheck('stop', instanceId, options);
|
|
201
|
+
if (!safetyResult.passed) {
|
|
202
|
+
ui.error('Safety checks failed');
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (safetyResult.requiresApproval) {
|
|
206
|
+
const approval = await promptForApproval({
|
|
207
|
+
title: 'Stop EC2 Instance',
|
|
208
|
+
operation: `ec2 stop ${instanceId}`,
|
|
209
|
+
risks: safetyResult.risks,
|
|
210
|
+
});
|
|
211
|
+
if (!approval.approved) {
|
|
212
|
+
ui.info('Operation cancelled');
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
const proceed = await confirm({
|
|
218
|
+
message: `Stop instance ${instanceId}?`,
|
|
219
|
+
defaultValue: false,
|
|
220
|
+
});
|
|
221
|
+
if (!proceed) {
|
|
222
|
+
ui.info('Operation cancelled');
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
ui.startSpinner({ message: 'Stopping instance...' });
|
|
227
|
+
try {
|
|
228
|
+
await runAwsCommand(`ec2 stop-instances --instance-ids ${instanceId}`, options);
|
|
229
|
+
ui.stopSpinnerSuccess('Instance stopped');
|
|
230
|
+
ui.info(`Instance ${instanceId} is now stopping`);
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
ui.stopSpinnerFail('Failed to stop instance');
|
|
234
|
+
ui.error(error.message);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Terminate an EC2 instance
|
|
239
|
+
*/
|
|
240
|
+
async function terminateInstance(instanceId, options) {
|
|
241
|
+
ui.header(`Terminate EC2 Instance: ${instanceId}`);
|
|
242
|
+
ui.warning('This action cannot be undone!');
|
|
243
|
+
ui.newLine();
|
|
244
|
+
// Show cost estimate for the instance being terminated
|
|
245
|
+
try {
|
|
246
|
+
const instances = await runAwsCommand(`ec2 describe-instances --instance-ids ${instanceId} --query "Reservations[].Instances[]"`, options);
|
|
247
|
+
if (instances.length > 0) {
|
|
248
|
+
displayCostWarning(instances[0].InstanceType);
|
|
249
|
+
ui.info('Terminating this instance will permanently stop all charges.');
|
|
250
|
+
ui.newLine();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
// Non-critical, continue without cost estimate
|
|
255
|
+
}
|
|
256
|
+
// Run safety checks
|
|
257
|
+
const safetyResult = await runSafetyCheck('terminate', instanceId, options);
|
|
258
|
+
if (!safetyResult.passed) {
|
|
259
|
+
ui.error('Safety checks failed - operation blocked');
|
|
260
|
+
for (const blocker of safetyResult.blockers) {
|
|
261
|
+
ui.print(` ${ui.color('x', 'red')} ${blocker.message}`);
|
|
262
|
+
}
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
// Always require approval for terminate
|
|
266
|
+
const approval = await promptForApproval({
|
|
267
|
+
title: 'Terminate EC2 Instance',
|
|
268
|
+
operation: `ec2 terminate ${instanceId}`,
|
|
269
|
+
risks: safetyResult.risks,
|
|
270
|
+
requireConfirmation: true,
|
|
271
|
+
confirmationWord: 'terminate',
|
|
272
|
+
});
|
|
273
|
+
if (!approval.approved) {
|
|
274
|
+
ui.info('Operation cancelled');
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
ui.startSpinner({ message: 'Terminating instance...' });
|
|
278
|
+
try {
|
|
279
|
+
await runAwsCommand(`ec2 terminate-instances --instance-ids ${instanceId}`, options);
|
|
280
|
+
ui.stopSpinnerSuccess('Instance terminated');
|
|
281
|
+
ui.info(`Instance ${instanceId} has been terminated`);
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
ui.stopSpinnerFail('Failed to terminate instance');
|
|
285
|
+
ui.error(error.message);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Run safety check for EC2 operation
|
|
290
|
+
*/
|
|
291
|
+
async function runSafetyCheck(operation, instanceId, options) {
|
|
292
|
+
const policy = loadSafetyPolicy();
|
|
293
|
+
const context = {
|
|
294
|
+
operation,
|
|
295
|
+
type: 'aws',
|
|
296
|
+
resources: [instanceId],
|
|
297
|
+
metadata: {
|
|
298
|
+
service: 'ec2',
|
|
299
|
+
region: options.region,
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
return evaluateSafety(context, policy);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Run AWS CLI command and parse JSON output
|
|
306
|
+
*/
|
|
307
|
+
async function runAwsCommand(command, options) {
|
|
308
|
+
const { execFile } = await import('child_process');
|
|
309
|
+
const { promisify } = await import('util');
|
|
310
|
+
const execFileAsync = promisify(execFile);
|
|
311
|
+
const args = command.split(' ');
|
|
312
|
+
const baseCommand = args[0];
|
|
313
|
+
const commandArgs = args.slice(1);
|
|
314
|
+
// Add common options
|
|
315
|
+
if (options.profile) {
|
|
316
|
+
commandArgs.push('--profile', options.profile);
|
|
317
|
+
}
|
|
318
|
+
if (options.region) {
|
|
319
|
+
commandArgs.push('--region', options.region);
|
|
320
|
+
}
|
|
321
|
+
commandArgs.push('--output', 'json');
|
|
322
|
+
const { stdout } = await execFileAsync('aws', [baseCommand, ...commandArgs]);
|
|
323
|
+
return JSON.parse(stdout);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Display instances in a table format
|
|
327
|
+
*/
|
|
328
|
+
function displayInstanceTable(instances) {
|
|
329
|
+
// Calculate column widths
|
|
330
|
+
const headers = ['Instance ID', 'Name', 'Type', 'State', 'Public IP', 'Private IP'];
|
|
331
|
+
const rows = instances.map(inst => {
|
|
332
|
+
const nameTag = inst.Tags?.find(t => t.Key === 'Name');
|
|
333
|
+
return [
|
|
334
|
+
inst.InstanceId,
|
|
335
|
+
nameTag?.Value || '-',
|
|
336
|
+
inst.InstanceType,
|
|
337
|
+
inst.State.Name,
|
|
338
|
+
inst.PublicIpAddress || '-',
|
|
339
|
+
inst.PrivateIpAddress || '-',
|
|
340
|
+
];
|
|
341
|
+
});
|
|
342
|
+
// Print header
|
|
343
|
+
const headerRow = headers
|
|
344
|
+
.map((h, i) => {
|
|
345
|
+
const maxWidth = Math.max(h.length, ...rows.map(r => r[i].length));
|
|
346
|
+
return h.padEnd(maxWidth);
|
|
347
|
+
})
|
|
348
|
+
.join(' ');
|
|
349
|
+
ui.print(ui.bold(headerRow));
|
|
350
|
+
ui.print('-'.repeat(headerRow.length));
|
|
351
|
+
// Print rows
|
|
352
|
+
for (const row of rows) {
|
|
353
|
+
const formattedRow = row
|
|
354
|
+
.map((cell, i) => {
|
|
355
|
+
const maxWidth = Math.max(headers[i].length, ...rows.map(r => r[i].length));
|
|
356
|
+
if (i === 3) {
|
|
357
|
+
// State column - colorize
|
|
358
|
+
return formatState(cell).padEnd(maxWidth + 10); // Extra for color codes
|
|
359
|
+
}
|
|
360
|
+
return cell.padEnd(maxWidth);
|
|
361
|
+
})
|
|
362
|
+
.join(' ');
|
|
363
|
+
ui.print(formattedRow);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Format instance state with color
|
|
368
|
+
*/
|
|
369
|
+
function formatState(state) {
|
|
370
|
+
switch (state) {
|
|
371
|
+
case 'running':
|
|
372
|
+
return ui.color(state, 'green');
|
|
373
|
+
case 'stopped':
|
|
374
|
+
return ui.color(state, 'red');
|
|
375
|
+
case 'pending':
|
|
376
|
+
case 'stopping':
|
|
377
|
+
return ui.color(state, 'yellow');
|
|
378
|
+
case 'terminated':
|
|
379
|
+
return ui.color(state, 'gray');
|
|
380
|
+
default:
|
|
381
|
+
return state;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Show EC2 command help
|
|
386
|
+
*/
|
|
387
|
+
function showEc2Help() {
|
|
388
|
+
ui.print('Usage: nimbus aws ec2 <action> [args]');
|
|
389
|
+
ui.newLine();
|
|
390
|
+
ui.print(ui.bold('Actions:'));
|
|
391
|
+
ui.print(' list List all EC2 instances');
|
|
392
|
+
ui.print(' describe <id> Describe a specific instance');
|
|
393
|
+
ui.print(' start <id> Start an instance');
|
|
394
|
+
ui.print(' stop <id> Stop an instance');
|
|
395
|
+
ui.print(' terminate <id> Terminate an instance (requires approval)');
|
|
396
|
+
ui.newLine();
|
|
397
|
+
ui.print(ui.bold('Examples:'));
|
|
398
|
+
ui.print(' nimbus aws ec2 list');
|
|
399
|
+
ui.print(' nimbus aws ec2 describe i-1234567890abcdef0');
|
|
400
|
+
ui.print(' nimbus aws ec2 stop i-1234567890abcdef0');
|
|
401
|
+
}
|
|
402
|
+
export default ec2Command;
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS IAM Commands
|
|
3
|
+
*
|
|
4
|
+
* IAM user, role, and policy operations
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* nimbus aws iam users
|
|
8
|
+
* nimbus aws iam roles
|
|
9
|
+
* nimbus aws iam policies
|
|
10
|
+
*/
|
|
11
|
+
import { logger } from '../../utils';
|
|
12
|
+
import { ui } from '../../wizard/ui';
|
|
13
|
+
/**
|
|
14
|
+
* IAM command router
|
|
15
|
+
*/
|
|
16
|
+
export async function iamCommand(action, args, options) {
|
|
17
|
+
logger.info('Running IAM command', { action, args, options });
|
|
18
|
+
switch (action) {
|
|
19
|
+
case 'users':
|
|
20
|
+
await listUsers(options);
|
|
21
|
+
break;
|
|
22
|
+
case 'roles':
|
|
23
|
+
await listRoles(options);
|
|
24
|
+
break;
|
|
25
|
+
case 'policies':
|
|
26
|
+
await listPolicies(options);
|
|
27
|
+
break;
|
|
28
|
+
case 'user':
|
|
29
|
+
if (!args[0]) {
|
|
30
|
+
ui.error('User name is required');
|
|
31
|
+
ui.print('Usage: nimbus aws iam user <username>');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
await describeUser(args[0], options);
|
|
35
|
+
break;
|
|
36
|
+
case 'role':
|
|
37
|
+
if (!args[0]) {
|
|
38
|
+
ui.error('Role name is required');
|
|
39
|
+
ui.print('Usage: nimbus aws iam role <rolename>');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
await describeRole(args[0], options);
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
showIamHelp();
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* List all IAM users
|
|
51
|
+
*/
|
|
52
|
+
async function listUsers(options) {
|
|
53
|
+
ui.header('IAM Users');
|
|
54
|
+
ui.startSpinner({ message: 'Fetching IAM users...' });
|
|
55
|
+
try {
|
|
56
|
+
const result = await runAwsCommand('iam list-users', options);
|
|
57
|
+
const users = result.Users || [];
|
|
58
|
+
ui.stopSpinnerSuccess(`Found ${users.length} user(s)`);
|
|
59
|
+
ui.newLine();
|
|
60
|
+
if (users.length === 0) {
|
|
61
|
+
ui.info('No IAM users found');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// Display table
|
|
65
|
+
const headers = ['Username', 'User ID', 'Created', 'Last Login'];
|
|
66
|
+
const rows = users.map(user => [
|
|
67
|
+
user.UserName,
|
|
68
|
+
user.UserId,
|
|
69
|
+
new Date(user.CreateDate).toLocaleDateString(),
|
|
70
|
+
user.PasswordLastUsed ? new Date(user.PasswordLastUsed).toLocaleDateString() : 'Never',
|
|
71
|
+
]);
|
|
72
|
+
displayTable(headers, rows);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
ui.stopSpinnerFail('Failed to list users');
|
|
76
|
+
ui.error(error.message);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* List all IAM roles
|
|
81
|
+
*/
|
|
82
|
+
async function listRoles(options) {
|
|
83
|
+
ui.header('IAM Roles');
|
|
84
|
+
ui.startSpinner({ message: 'Fetching IAM roles...' });
|
|
85
|
+
try {
|
|
86
|
+
const result = await runAwsCommand('iam list-roles', options);
|
|
87
|
+
const roles = result.Roles || [];
|
|
88
|
+
ui.stopSpinnerSuccess(`Found ${roles.length} role(s)`);
|
|
89
|
+
ui.newLine();
|
|
90
|
+
if (roles.length === 0) {
|
|
91
|
+
ui.info('No IAM roles found');
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
// Display table (filter out AWS service roles by default)
|
|
95
|
+
const customRoles = roles.filter(r => !r.RoleName.startsWith('AWS'));
|
|
96
|
+
const headers = ['Role Name', 'Role ID', 'Created', 'Description'];
|
|
97
|
+
const rows = customRoles.map(role => [
|
|
98
|
+
role.RoleName,
|
|
99
|
+
role.RoleId,
|
|
100
|
+
new Date(role.CreateDate).toLocaleDateString(),
|
|
101
|
+
role.Description || '-',
|
|
102
|
+
]);
|
|
103
|
+
displayTable(headers, rows);
|
|
104
|
+
if (customRoles.length < roles.length) {
|
|
105
|
+
ui.newLine();
|
|
106
|
+
ui.dim(`(${roles.length - customRoles.length} AWS service roles hidden)`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
ui.stopSpinnerFail('Failed to list roles');
|
|
111
|
+
ui.error(error.message);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* List all IAM policies
|
|
116
|
+
*/
|
|
117
|
+
async function listPolicies(options) {
|
|
118
|
+
ui.header('IAM Policies');
|
|
119
|
+
ui.startSpinner({ message: 'Fetching IAM policies...' });
|
|
120
|
+
try {
|
|
121
|
+
const result = await runAwsCommand('iam list-policies --scope Local', options);
|
|
122
|
+
const policies = result.Policies || [];
|
|
123
|
+
ui.stopSpinnerSuccess(`Found ${policies.length} custom policy(ies)`);
|
|
124
|
+
ui.newLine();
|
|
125
|
+
if (policies.length === 0) {
|
|
126
|
+
ui.info('No custom IAM policies found');
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
// Display table
|
|
130
|
+
const headers = ['Policy Name', 'Policy ID', 'Attachments', 'Created'];
|
|
131
|
+
const rows = policies.map(policy => [
|
|
132
|
+
policy.PolicyName,
|
|
133
|
+
policy.PolicyId,
|
|
134
|
+
String(policy.AttachmentCount),
|
|
135
|
+
new Date(policy.CreateDate).toLocaleDateString(),
|
|
136
|
+
]);
|
|
137
|
+
displayTable(headers, rows);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
ui.stopSpinnerFail('Failed to list policies');
|
|
141
|
+
ui.error(error.message);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Describe a specific IAM user
|
|
146
|
+
*/
|
|
147
|
+
async function describeUser(userName, options) {
|
|
148
|
+
ui.header(`IAM User: ${userName}`);
|
|
149
|
+
ui.startSpinner({ message: 'Fetching user details...' });
|
|
150
|
+
try {
|
|
151
|
+
const { execFile } = await import('child_process');
|
|
152
|
+
const { promisify } = await import('util');
|
|
153
|
+
const execFileAsync = promisify(execFile);
|
|
154
|
+
// Get user details
|
|
155
|
+
const userArgs = ['iam', 'get-user', '--user-name', userName, '--output', 'json'];
|
|
156
|
+
if (options.profile) {
|
|
157
|
+
userArgs.push('--profile', options.profile);
|
|
158
|
+
}
|
|
159
|
+
const { stdout: userOutput } = await execFileAsync('aws', userArgs);
|
|
160
|
+
const userData = JSON.parse(userOutput);
|
|
161
|
+
const user = userData.User;
|
|
162
|
+
// Get user groups
|
|
163
|
+
const groupArgs = ['iam', 'list-groups-for-user', '--user-name', userName, '--output', 'json'];
|
|
164
|
+
if (options.profile) {
|
|
165
|
+
groupArgs.push('--profile', options.profile);
|
|
166
|
+
}
|
|
167
|
+
const { stdout: groupOutput } = await execFileAsync('aws', groupArgs);
|
|
168
|
+
const groupData = JSON.parse(groupOutput);
|
|
169
|
+
const groups = groupData.Groups || [];
|
|
170
|
+
ui.stopSpinnerSuccess('User details retrieved');
|
|
171
|
+
ui.newLine();
|
|
172
|
+
ui.print(ui.bold('User Details:'));
|
|
173
|
+
ui.newLine();
|
|
174
|
+
ui.print(` Username: ${user.UserName}`);
|
|
175
|
+
ui.print(` User ID: ${user.UserId}`);
|
|
176
|
+
ui.print(` ARN: ${user.Arn}`);
|
|
177
|
+
ui.print(` Created: ${new Date(user.CreateDate).toLocaleString()}`);
|
|
178
|
+
ui.print(` Last Login: ${user.PasswordLastUsed ? new Date(user.PasswordLastUsed).toLocaleString() : 'Never'}`);
|
|
179
|
+
if (groups.length > 0) {
|
|
180
|
+
ui.newLine();
|
|
181
|
+
ui.print(ui.bold('Groups:'));
|
|
182
|
+
for (const group of groups) {
|
|
183
|
+
ui.print(` - ${group.GroupName}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
ui.stopSpinnerFail('Failed to describe user');
|
|
189
|
+
ui.error(error.message);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Describe a specific IAM role
|
|
194
|
+
*/
|
|
195
|
+
async function describeRole(roleName, options) {
|
|
196
|
+
ui.header(`IAM Role: ${roleName}`);
|
|
197
|
+
ui.startSpinner({ message: 'Fetching role details...' });
|
|
198
|
+
try {
|
|
199
|
+
const { execFile } = await import('child_process');
|
|
200
|
+
const { promisify } = await import('util');
|
|
201
|
+
const execFileAsync = promisify(execFile);
|
|
202
|
+
// Get role details
|
|
203
|
+
const roleArgs = ['iam', 'get-role', '--role-name', roleName, '--output', 'json'];
|
|
204
|
+
if (options.profile) {
|
|
205
|
+
roleArgs.push('--profile', options.profile);
|
|
206
|
+
}
|
|
207
|
+
const { stdout: roleOutput } = await execFileAsync('aws', roleArgs);
|
|
208
|
+
const roleData = JSON.parse(roleOutput);
|
|
209
|
+
const role = roleData.Role;
|
|
210
|
+
// Get attached policies
|
|
211
|
+
const policyArgs = [
|
|
212
|
+
'iam',
|
|
213
|
+
'list-attached-role-policies',
|
|
214
|
+
'--role-name',
|
|
215
|
+
roleName,
|
|
216
|
+
'--output',
|
|
217
|
+
'json',
|
|
218
|
+
];
|
|
219
|
+
if (options.profile) {
|
|
220
|
+
policyArgs.push('--profile', options.profile);
|
|
221
|
+
}
|
|
222
|
+
const { stdout: policyOutput } = await execFileAsync('aws', policyArgs);
|
|
223
|
+
const policyData = JSON.parse(policyOutput);
|
|
224
|
+
const policies = policyData.AttachedPolicies || [];
|
|
225
|
+
ui.stopSpinnerSuccess('Role details retrieved');
|
|
226
|
+
ui.newLine();
|
|
227
|
+
ui.print(ui.bold('Role Details:'));
|
|
228
|
+
ui.newLine();
|
|
229
|
+
ui.print(` Role Name: ${role.RoleName}`);
|
|
230
|
+
ui.print(` Role ID: ${role.RoleId}`);
|
|
231
|
+
ui.print(` ARN: ${role.Arn}`);
|
|
232
|
+
ui.print(` Created: ${new Date(role.CreateDate).toLocaleString()}`);
|
|
233
|
+
if (role.Description) {
|
|
234
|
+
ui.print(` Description: ${role.Description}`);
|
|
235
|
+
}
|
|
236
|
+
if (policies.length > 0) {
|
|
237
|
+
ui.newLine();
|
|
238
|
+
ui.print(ui.bold('Attached Policies:'));
|
|
239
|
+
for (const policy of policies) {
|
|
240
|
+
ui.print(` - ${policy.PolicyName}`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
ui.stopSpinnerFail('Failed to describe role');
|
|
246
|
+
ui.error(error.message);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Run AWS CLI command and parse JSON output
|
|
251
|
+
*/
|
|
252
|
+
async function runAwsCommand(command, options) {
|
|
253
|
+
const { execFile } = await import('child_process');
|
|
254
|
+
const { promisify } = await import('util');
|
|
255
|
+
const execFileAsync = promisify(execFile);
|
|
256
|
+
const args = command.split(' ');
|
|
257
|
+
const baseCommand = args[0];
|
|
258
|
+
const commandArgs = args.slice(1);
|
|
259
|
+
// Add common options
|
|
260
|
+
if (options.profile) {
|
|
261
|
+
commandArgs.push('--profile', options.profile);
|
|
262
|
+
}
|
|
263
|
+
commandArgs.push('--output', 'json');
|
|
264
|
+
const { stdout } = await execFileAsync('aws', [baseCommand, ...commandArgs]);
|
|
265
|
+
return JSON.parse(stdout);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Display a table
|
|
269
|
+
*/
|
|
270
|
+
function displayTable(headers, rows) {
|
|
271
|
+
// Calculate column widths
|
|
272
|
+
const colWidths = headers.map((h, i) => {
|
|
273
|
+
const maxDataWidth = Math.max(...rows.map(r => (r[i] || '').length));
|
|
274
|
+
return Math.max(h.length, maxDataWidth);
|
|
275
|
+
});
|
|
276
|
+
// Print header
|
|
277
|
+
const headerRow = headers.map((h, i) => h.padEnd(colWidths[i])).join(' ');
|
|
278
|
+
ui.print(ui.bold(headerRow));
|
|
279
|
+
ui.print('-'.repeat(headerRow.length));
|
|
280
|
+
// Print rows
|
|
281
|
+
for (const row of rows) {
|
|
282
|
+
const formattedRow = row.map((cell, i) => (cell || '').padEnd(colWidths[i])).join(' ');
|
|
283
|
+
ui.print(formattedRow);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Show IAM command help
|
|
288
|
+
*/
|
|
289
|
+
function showIamHelp() {
|
|
290
|
+
ui.print('Usage: nimbus aws iam <action> [args]');
|
|
291
|
+
ui.newLine();
|
|
292
|
+
ui.print(ui.bold('Actions:'));
|
|
293
|
+
ui.print(' users List all IAM users');
|
|
294
|
+
ui.print(' roles List all IAM roles');
|
|
295
|
+
ui.print(' policies List custom IAM policies');
|
|
296
|
+
ui.print(' user <name> Describe a specific user');
|
|
297
|
+
ui.print(' role <name> Describe a specific role');
|
|
298
|
+
ui.newLine();
|
|
299
|
+
ui.print(ui.bold('Examples:'));
|
|
300
|
+
ui.print(' nimbus aws iam users');
|
|
301
|
+
ui.print(' nimbus aws iam roles');
|
|
302
|
+
ui.print(' nimbus aws iam user admin');
|
|
303
|
+
}
|
|
304
|
+
export default iamCommand;
|