feat: Claude Code Monitor — lanes, pipelines and a merged workspace
Internal SmartGift build of a Claude Code monitoring dashboard. Lanes: a durable unit of parallel agent work, one per working directory, tracked across session restarts. Managed lanes are git worktrees the dashboard provisions and can reset or remove behind a three-check destroy guard and a counted preflight; adopted lanes are directories you already own and are never destroyable. Pipelines: a lane moves through pipeline stages. A stage the agent declares with evidence renders green; a stage inferred from the tool-event stream renders dashed amber and never counts as done. Detection is forward-only within a 30-minute window, and never writes the declared stage. Workspace: one page at /run with a lane grid, the selected lane's pipeline, and a full Claude console behind a disclosure.
This commit is contained in:
@@ -0,0 +1,264 @@
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# AWS Provider – Full implementation for Claude Code Agent Monitor
|
||||
#
|
||||
# Composes the generic modules into a production-ready AWS stack:
|
||||
# VPC → ECS Fargate → EFS → ALB → CloudWatch → ACM
|
||||
#
|
||||
# Features:
|
||||
# - Multi-AZ deployment
|
||||
# - Blue/green deployment slots
|
||||
# - EFS for persistent SQLite storage
|
||||
# - ALB with WebSocket support and sticky sessions
|
||||
# - Auto-scaling with CPU/memory targets
|
||||
# - CloudWatch monitoring, alarms, and dashboards
|
||||
# - IAM least-privilege roles
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
provider "aws" {
|
||||
region = var.region
|
||||
|
||||
default_tags {
|
||||
tags = local.common_tags
|
||||
}
|
||||
}
|
||||
|
||||
# ── Data sources ────────────────────────────────────────────────────────────
|
||||
|
||||
data "aws_caller_identity" "current" {}
|
||||
data "aws_region" "current" {}
|
||||
|
||||
data "aws_availability_zones" "available" {
|
||||
state = "available"
|
||||
}
|
||||
|
||||
# ── Locals ──────────────────────────────────────────────────────────────────
|
||||
|
||||
locals {
|
||||
name_prefix = lower(replace("${var.project_name}-${var.environment}", "_", "-"))
|
||||
|
||||
common_tags = merge(
|
||||
{
|
||||
project = var.project_name
|
||||
environment = var.environment
|
||||
managed_by = "terraform"
|
||||
cloud_provider = "aws"
|
||||
repository = "Claude-Code-Agent-Monitor"
|
||||
},
|
||||
var.tags,
|
||||
)
|
||||
|
||||
# Use first 3 available AZs when none specified
|
||||
availability_zones = length(var.availability_zones) > 0 ? var.availability_zones : slice(data.aws_availability_zones.available.names, 0, min(3, length(data.aws_availability_zones.available.names)))
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# Networking
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
module "networking" {
|
||||
source = "../../modules/networking"
|
||||
|
||||
project_name = var.project_name
|
||||
environment = var.environment
|
||||
cloud_provider = "aws"
|
||||
region = var.region
|
||||
vpc_cidr = var.vpc_cidr
|
||||
availability_zones = local.availability_zones
|
||||
public_subnet_cidrs = var.public_subnet_cidrs
|
||||
private_subnet_cidrs = var.private_subnet_cidrs
|
||||
app_port = var.app_port
|
||||
mcp_port = var.mcp_port
|
||||
tags = local.common_tags
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# Database (EFS for SQLite persistence)
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
module "database" {
|
||||
source = "../../modules/database"
|
||||
|
||||
project_name = var.project_name
|
||||
environment = var.environment
|
||||
cloud_provider = "aws"
|
||||
region = var.region
|
||||
storage_size_gb = var.storage_size_gb
|
||||
enable_backup = var.enable_storage_backup
|
||||
private_subnet_ids = module.networking.private_subnet_ids
|
||||
vpc_id = module.networking.vpc_id
|
||||
allowed_security_group_ids = module.networking.storage_security_group_ids
|
||||
tags = local.common_tags
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# Compute – Blue slot
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
module "compute_blue" {
|
||||
source = "../../modules/compute"
|
||||
|
||||
project_name = var.project_name
|
||||
environment = var.environment
|
||||
cloud_provider = "aws"
|
||||
region = var.region
|
||||
deployment_slot = "blue"
|
||||
container_image = var.app_container_image
|
||||
mcp_container_image = var.mcp_container_image
|
||||
app_port = var.app_port
|
||||
mcp_port = var.mcp_port
|
||||
cpu = var.cpu
|
||||
memory = var.memory
|
||||
desired_count = var.active_deployment_slot == "blue" ? var.desired_replicas : 0
|
||||
min_count = var.active_deployment_slot == "blue" ? var.min_replicas : 0
|
||||
max_count = var.active_deployment_slot == "blue" ? var.max_replicas : 0
|
||||
environment_variables = var.environment_variables
|
||||
health_check_path = var.health_check_path
|
||||
vpc_id = module.networking.vpc_id
|
||||
private_subnet_ids = module.networking.private_subnet_ids
|
||||
security_group_ids = module.networking.private_security_group_ids
|
||||
storage_filesystem_id = module.database.filesystem_id
|
||||
storage_mount_targets = module.database.mount_target_ids
|
||||
autoscaling_cpu_target = var.autoscaling_cpu_target
|
||||
autoscaling_memory_target = var.autoscaling_memory_target
|
||||
tags = local.common_tags
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# Compute – Green slot
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
module "compute_green" {
|
||||
source = "../../modules/compute"
|
||||
|
||||
project_name = var.project_name
|
||||
environment = var.environment
|
||||
cloud_provider = "aws"
|
||||
region = var.region
|
||||
deployment_slot = "green"
|
||||
container_image = var.app_container_image
|
||||
mcp_container_image = var.mcp_container_image
|
||||
app_port = var.app_port
|
||||
mcp_port = var.mcp_port
|
||||
cpu = var.cpu
|
||||
memory = var.memory
|
||||
desired_count = var.active_deployment_slot == "green" ? var.desired_replicas : 0
|
||||
min_count = var.active_deployment_slot == "green" ? var.min_replicas : 0
|
||||
max_count = var.active_deployment_slot == "green" ? var.max_replicas : 0
|
||||
environment_variables = var.environment_variables
|
||||
health_check_path = var.health_check_path
|
||||
vpc_id = module.networking.vpc_id
|
||||
private_subnet_ids = module.networking.private_subnet_ids
|
||||
security_group_ids = module.networking.private_security_group_ids
|
||||
storage_filesystem_id = module.database.filesystem_id
|
||||
storage_mount_targets = module.database.mount_target_ids
|
||||
autoscaling_cpu_target = var.autoscaling_cpu_target
|
||||
autoscaling_memory_target = var.autoscaling_memory_target
|
||||
tags = local.common_tags
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# ACM Certificate (optional – when domain_name is specified)
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
resource "aws_acm_certificate" "main" {
|
||||
count = var.domain_name != "" && var.tls_certificate_arn == "" ? 1 : 0
|
||||
|
||||
domain_name = var.domain_name
|
||||
validation_method = "DNS"
|
||||
|
||||
tags = merge(local.common_tags, {
|
||||
Name = "${local.name_prefix}-cert"
|
||||
})
|
||||
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
locals {
|
||||
tls_cert_arn = var.tls_certificate_arn != "" ? var.tls_certificate_arn : (
|
||||
length(aws_acm_certificate.main) > 0 ? aws_acm_certificate.main[0].arn : ""
|
||||
)
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# Load Balancer
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
module "loadbalancer" {
|
||||
source = "../../modules/loadbalancer"
|
||||
|
||||
project_name = var.project_name
|
||||
environment = var.environment
|
||||
cloud_provider = "aws"
|
||||
region = var.region
|
||||
vpc_id = module.networking.vpc_id
|
||||
public_subnet_ids = module.networking.public_subnet_ids
|
||||
security_group_ids = module.networking.public_security_group_ids
|
||||
app_port = var.app_port
|
||||
mcp_port = var.mcp_port
|
||||
tls_certificate_arn = local.tls_cert_arn
|
||||
domain_name = var.domain_name
|
||||
|
||||
blue_target_group_arn = module.compute_blue.target_group_arn
|
||||
green_target_group_arn = module.compute_green.target_group_arn
|
||||
blue_weight = var.blue_weight
|
||||
green_weight = var.green_weight
|
||||
|
||||
health_check_path = var.health_check_path
|
||||
health_check_interval = var.health_check_interval
|
||||
health_check_timeout = var.health_check_timeout
|
||||
health_check_healthy_threshold = var.health_check_healthy_threshold
|
||||
health_check_unhealthy_threshold = var.health_check_unhealthy_threshold
|
||||
|
||||
enable_deletion_protection = var.environment == "production"
|
||||
|
||||
tags = local.common_tags
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# Monitoring
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
module "monitoring" {
|
||||
source = "../../modules/monitoring"
|
||||
count = var.enable_monitoring ? 1 : 0
|
||||
|
||||
project_name = var.project_name
|
||||
environment = var.environment
|
||||
cloud_provider = "aws"
|
||||
region = var.region
|
||||
alert_email = var.alert_email
|
||||
log_retention_days = var.log_retention_days
|
||||
|
||||
loadbalancer_arn = module.loadbalancer.loadbalancer_arn
|
||||
target_group_arns = [module.compute_blue.target_group_arn, module.compute_green.target_group_arn]
|
||||
compute_cluster_name = module.compute_blue.cluster_name
|
||||
filesystem_id = module.database.filesystem_id
|
||||
|
||||
tags = local.common_tags
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# Route53 DNS record (optional)
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
data "aws_route53_zone" "main" {
|
||||
count = var.domain_name != "" && var.route53_zone_id != "" ? 1 : 0
|
||||
|
||||
zone_id = var.route53_zone_id
|
||||
}
|
||||
|
||||
resource "aws_route53_record" "app" {
|
||||
count = var.domain_name != "" && var.route53_zone_id != "" ? 1 : 0
|
||||
|
||||
zone_id = data.aws_route53_zone.main[0].zone_id
|
||||
name = var.domain_name
|
||||
type = "A"
|
||||
|
||||
alias {
|
||||
name = module.loadbalancer.dns_name
|
||||
zone_id = module.loadbalancer.zone_id
|
||||
evaluate_target_health = true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# AWS provider outputs
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
output "application_url" {
|
||||
description = "Public URL of the Claude Code Agent Monitor dashboard"
|
||||
value = module.loadbalancer.application_url
|
||||
}
|
||||
|
||||
output "alb_dns_name" {
|
||||
description = "DNS name of the Application Load Balancer"
|
||||
value = module.loadbalancer.dns_name
|
||||
}
|
||||
|
||||
output "vpc_id" {
|
||||
description = "ID of the VPC"
|
||||
value = module.networking.vpc_id
|
||||
}
|
||||
|
||||
output "ecs_cluster_name" {
|
||||
description = "Name of the ECS cluster"
|
||||
value = module.compute_blue.cluster_name
|
||||
}
|
||||
|
||||
output "blue_service_name" {
|
||||
description = "Name of the blue ECS service"
|
||||
value = module.compute_blue.service_name
|
||||
}
|
||||
|
||||
output "green_service_name" {
|
||||
description = "Name of the green ECS service"
|
||||
value = module.compute_green.service_name
|
||||
}
|
||||
|
||||
output "efs_filesystem_id" {
|
||||
description = "ID of the EFS file system"
|
||||
value = module.database.filesystem_id
|
||||
}
|
||||
|
||||
output "acm_certificate_arn" {
|
||||
description = "ARN of the ACM certificate (if auto-created)"
|
||||
value = length(aws_acm_certificate.main) > 0 ? aws_acm_certificate.main[0].arn : var.tls_certificate_arn
|
||||
}
|
||||
|
||||
output "monitoring_dashboard_url" {
|
||||
description = "CloudWatch dashboard URL"
|
||||
value = var.enable_monitoring ? module.monitoring[0].dashboard_url : "monitoring disabled"
|
||||
}
|
||||
|
||||
output "account_id" {
|
||||
description = "AWS account ID"
|
||||
value = data.aws_caller_identity.current.account_id
|
||||
}
|
||||
|
||||
output "region" {
|
||||
description = "AWS region"
|
||||
value = data.aws_region.current.name
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# AWS provider – Terraform and provider constraints
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
terraform {
|
||||
required_version = ">= 1.5.0"
|
||||
|
||||
required_providers {
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = "~> 5.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# AWS provider variables
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
# ── Core ────────────────────────────────────────────────────────────────────
|
||||
|
||||
variable "project_name" {
|
||||
description = "Project identifier used in resource naming and tagging"
|
||||
type = string
|
||||
default = "claude-agent-monitor"
|
||||
}
|
||||
|
||||
variable "environment" {
|
||||
description = "Deployment environment: dev, staging, or production"
|
||||
type = string
|
||||
validation {
|
||||
condition = contains(["dev", "staging", "production"], var.environment)
|
||||
error_message = "environment must be one of: dev, staging, production."
|
||||
}
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
description = "AWS region for resource deployment"
|
||||
type = string
|
||||
default = "us-east-1"
|
||||
}
|
||||
|
||||
variable "tags" {
|
||||
description = "Additional tags to apply to all resources"
|
||||
type = map(string)
|
||||
default = {}
|
||||
}
|
||||
|
||||
# ── Networking ──────────────────────────────────────────────────────────────
|
||||
|
||||
variable "vpc_cidr" {
|
||||
description = "CIDR block for the VPC"
|
||||
type = string
|
||||
default = "10.0.0.0/16"
|
||||
}
|
||||
|
||||
variable "availability_zones" {
|
||||
description = "List of AZs (auto-detected if empty)"
|
||||
type = list(string)
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "public_subnet_cidrs" {
|
||||
description = "CIDR blocks for public subnets"
|
||||
type = list(string)
|
||||
default = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
|
||||
}
|
||||
|
||||
variable "private_subnet_cidrs" {
|
||||
description = "CIDR blocks for private subnets"
|
||||
type = list(string)
|
||||
default = ["10.0.11.0/24", "10.0.12.0/24", "10.0.13.0/24"]
|
||||
}
|
||||
|
||||
# ── Compute ─────────────────────────────────────────────────────────────────
|
||||
|
||||
variable "app_container_image" {
|
||||
description = "Docker image URI for the main application"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "mcp_container_image" {
|
||||
description = "Docker image URI for the MCP sidecar (empty to disable)"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "app_port" {
|
||||
description = "Application container port"
|
||||
type = number
|
||||
default = 4820
|
||||
}
|
||||
|
||||
variable "mcp_port" {
|
||||
description = "MCP sidecar container port"
|
||||
type = number
|
||||
default = 8819
|
||||
}
|
||||
|
||||
variable "cpu" {
|
||||
description = "CPU units for Fargate tasks (256, 512, 1024, 2048, 4096)"
|
||||
type = number
|
||||
default = 512
|
||||
}
|
||||
|
||||
variable "memory" {
|
||||
description = "Memory in MiB for Fargate tasks"
|
||||
type = number
|
||||
default = 1024
|
||||
}
|
||||
|
||||
variable "min_replicas" {
|
||||
description = "Minimum number of ECS tasks"
|
||||
type = number
|
||||
default = 1
|
||||
}
|
||||
|
||||
variable "max_replicas" {
|
||||
description = "Maximum number of ECS tasks for auto-scaling"
|
||||
type = number
|
||||
default = 3
|
||||
}
|
||||
|
||||
variable "desired_replicas" {
|
||||
description = "Desired number of ECS tasks at steady state"
|
||||
type = number
|
||||
default = 1
|
||||
}
|
||||
|
||||
variable "environment_variables" {
|
||||
description = "Environment variables for the application container"
|
||||
type = map(string)
|
||||
default = {
|
||||
NODE_ENV = "production"
|
||||
DASHBOARD_PORT = "4820"
|
||||
}
|
||||
}
|
||||
|
||||
# ── Deployment ──────────────────────────────────────────────────────────────
|
||||
|
||||
variable "active_deployment_slot" {
|
||||
description = "Active deployment slot: blue or green"
|
||||
type = string
|
||||
default = "blue"
|
||||
validation {
|
||||
condition = contains(["blue", "green"], var.active_deployment_slot)
|
||||
error_message = "active_deployment_slot must be blue or green."
|
||||
}
|
||||
}
|
||||
|
||||
variable "blue_weight" {
|
||||
description = "Traffic weight for blue target group (0-100)"
|
||||
type = number
|
||||
default = 100
|
||||
validation {
|
||||
condition = var.blue_weight >= 0 && var.blue_weight <= 100
|
||||
error_message = "blue_weight must be between 0 and 100."
|
||||
}
|
||||
}
|
||||
|
||||
variable "green_weight" {
|
||||
description = "Traffic weight for green target group (0-100)"
|
||||
type = number
|
||||
default = 0
|
||||
validation {
|
||||
condition = var.green_weight >= 0 && var.green_weight <= 100
|
||||
error_message = "green_weight must be between 0 and 100."
|
||||
}
|
||||
}
|
||||
|
||||
# ── TLS / Domain ────────────────────────────────────────────────────────────
|
||||
|
||||
variable "domain_name" {
|
||||
description = "FQDN for the application (empty to skip DNS/TLS)"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "tls_certificate_arn" {
|
||||
description = "ARN of an existing ACM certificate (auto-created if domain_name set)"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "route53_zone_id" {
|
||||
description = "Route53 hosted zone ID for DNS records (empty to skip)"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
# ── Storage ─────────────────────────────────────────────────────────────────
|
||||
|
||||
variable "storage_size_gb" {
|
||||
description = "EFS storage does not require pre-provisioning; kept for interface compatibility"
|
||||
type = number
|
||||
default = 20
|
||||
}
|
||||
|
||||
variable "enable_storage_backup" {
|
||||
description = "Enable AWS Backup for EFS"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
# ── Health check ────────────────────────────────────────────────────────────
|
||||
|
||||
variable "health_check_path" {
|
||||
description = "HTTP path for health checks"
|
||||
type = string
|
||||
default = "/api/health"
|
||||
}
|
||||
|
||||
variable "health_check_interval" {
|
||||
description = "Seconds between health checks"
|
||||
type = number
|
||||
default = 30
|
||||
}
|
||||
|
||||
variable "health_check_timeout" {
|
||||
description = "Seconds before a health check request times out"
|
||||
type = number
|
||||
default = 5
|
||||
}
|
||||
|
||||
variable "health_check_healthy_threshold" {
|
||||
description = "Consecutive successes to mark target healthy"
|
||||
type = number
|
||||
default = 2
|
||||
}
|
||||
|
||||
variable "health_check_unhealthy_threshold" {
|
||||
description = "Consecutive failures to mark target unhealthy"
|
||||
type = number
|
||||
default = 3
|
||||
}
|
||||
|
||||
# ── Auto-scaling ────────────────────────────────────────────────────────────
|
||||
|
||||
variable "autoscaling_cpu_target" {
|
||||
description = "Target CPU utilization percentage for auto-scaling"
|
||||
type = number
|
||||
default = 70
|
||||
}
|
||||
|
||||
variable "autoscaling_memory_target" {
|
||||
description = "Target memory utilization percentage for auto-scaling"
|
||||
type = number
|
||||
default = 80
|
||||
}
|
||||
|
||||
# ── Monitoring ──────────────────────────────────────────────────────────────
|
||||
|
||||
variable "enable_monitoring" {
|
||||
description = "Enable CloudWatch monitoring, alarms, and dashboards"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "alert_email" {
|
||||
description = "Email address for SNS alert notifications"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "log_retention_days" {
|
||||
description = "CloudWatch log retention in days"
|
||||
type = number
|
||||
default = 30
|
||||
}
|
||||
Reference in New Issue
Block a user