lsp-max 26.6.24

Law-state LSP runtime: max LSP 3.18 coverage, process-mining conformance, receipt-chain admission
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
# Deployment Guides for lsp-max

Complete step-by-step deployment instructions for lsp-max in various environments: Kubernetes, Docker Compose, AWS, GCP, GitHub Actions, and custom agent systems.

---

## 1. Kubernetes Deployment

### 1.1 Namespace Setup

Create a dedicated namespace and service account:

```yaml
apiVersion: v1
kind: Namespace
metadata:
  name: lsp-max
  labels:
    name: lsp-max

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: lsp-max
  namespace: lsp-max

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: lsp-max
rules:
  # Service discovery
  - apiGroups: [""]
    resources: ["services", "endpoints"]
    verbs: ["get", "list", "watch"]
  # ConfigMaps / Secrets
  - apiGroups: [""]
    resources: ["configmaps", "secrets"]
    verbs: ["get", "list", "watch"]

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: lsp-max
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: lsp-max
subjects:
  - kind: ServiceAccount
    name: lsp-max
    namespace: lsp-max
```

Apply:

```bash
kubectl apply -f namespace.yaml
```

### 1.2 ConfigMap & Secrets

```yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: lsp-max-config
  namespace: lsp-max
data:
  config.yaml: |
    server:
      bind: "0.0.0.0:8080"
      max_connections: 500
    logging:
      level: info
      format: json
    observability:
      otel_endpoint: "http://otel-collector.observability:4317"
      metrics:
        enabled: true
        prometheus_port: 9091

---
apiVersion: v1
kind: Secret
metadata:
  name: lsp-max-secrets
  namespace: lsp-max
type: Opaque
stringData:
  # Base64-encoded credentials for external systems
  git-token: "ghp_xxxxxxxxxxxxxxxxxxxx"
  otel-api-key: "your-api-key-here"
```

Apply:

```bash
kubectl apply -f configmap-secret.yaml
```

### 1.3 Deployment

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: lsp-max
  namespace: lsp-max
  labels:
    app: lsp-max
    version: v26.7
spec:
  replicas: 3
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  selector:
    matchLabels:
      app: lsp-max
  template:
    metadata:
      labels:
        app: lsp-max
        version: v26.7
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9091"
        prometheus.io/path: "/metrics"
    spec:
      serviceAccountName: lsp-max
      securityContext:
        runAsNonRoot: true
        runAsUser: 1000
        fsGroup: 1000
      
      containers:
        - name: lsp-max
          image: gcr.io/my-project/lsp-max:26.7.1
          imagePullPolicy: IfNotPresent
          
          ports:
            - name: lsp
              containerPort: 8080
              protocol: TCP
            - name: metrics
              containerPort: 9091
              protocol: TCP
          
          env:
            - name: LSP_MAX_BIND_ADDRESS
              value: "0.0.0.0:8080"
            - name: LSP_MAX_LOG_LEVEL
              value: "info"
            - name: OTEL_EXPORTER_OTLP_ENDPOINT
              value: "http://otel-collector.observability:4317"
            - name: GIT_TOKEN
              valueFrom:
                secretKeyRef:
                  name: lsp-max-secrets
                  key: git-token
            - name: OTEL_API_KEY
              valueFrom:
                secretKeyRef:
                  name: lsp-max-secrets
                  key: otel-api-key
          
          volumeMounts:
            - name: config
              mountPath: /etc/lsp-max
              readOnly: true
            - name: session-tmp
              mountPath: /tmp/lsp-max-sessions
            - name: logs
              mountPath: /var/log/lsp-max
          
          livenessProbe:
            httpGet:
              path: /healthz
              port: 8080
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          
          readinessProbe:
            httpGet:
              path: /ready
              port: 8080
            initialDelaySeconds: 10
            periodSeconds: 5
            timeoutSeconds: 3
            failureThreshold: 2
          
          resources:
            requests:
              cpu: "500m"
              memory: "512Mi"
            limits:
              cpu: "2000m"
              memory: "2Gi"
          
          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              drop:
                - ALL
            readOnlyRootFilesystem: true
      
      volumes:
        - name: config
          configMap:
            name: lsp-max-config
        - name: session-tmp
          emptyDir:
            medium: Memory
            sizeLimit: 512Mi
        - name: logs
          emptyDir:
            sizeLimit: 1Gi
      
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 100
              podAffinityTerm:
                labelSelector:
                  matchExpressions:
                    - key: app
                      operator: In
                      values:
                        - lsp-max
                topologyKey: kubernetes.io/hostname
```

Apply:

```bash
kubectl apply -f deployment.yaml
kubectl rollout status deployment/lsp-max -n lsp-max
```

### 1.4 Service & Ingress

```yaml
apiVersion: v1
kind: Service
metadata:
  name: lsp-max
  namespace: lsp-max
  labels:
    app: lsp-max
spec:
  type: ClusterIP
  ports:
    - name: lsp
      port: 8080
      targetPort: 8080
      protocol: TCP
    - name: metrics
      port: 9091
      targetPort: 9091
      protocol: TCP
  selector:
    app: lsp-max

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: lsp-max
  namespace: lsp-max
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    nginx.ingress.kubernetes.io/websocket-services: lsp-max
    nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - lsp-max.example.com
      secretName: lsp-max-tls
  rules:
    - host: lsp-max.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: lsp-max
                port:
                  number: 8080
```

Apply:

```bash
kubectl apply -f service-ingress.yaml
kubectl get ingress -n lsp-max
```

### 1.5 Network Policy

```yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: lsp-max
  namespace: lsp-max
spec:
  podSelector:
    matchLabels:
      app: lsp-max
  policyTypes:
    - Ingress
    - Egress
  ingress:
    # From agents/clients
    - from:
        - namespaceSelector:
            matchLabels:
              name: agents
      ports:
        - protocol: TCP
          port: 8080
    # From monitoring/scraping
    - from:
        - namespaceSelector:
            matchLabels:
              name: monitoring
      ports:
        - protocol: TCP
          port: 9091
    # From ingress controller
    - from:
        - namespaceSelector:
            matchLabels:
              name: ingress-nginx
      ports:
        - protocol: TCP
          port: 8080
  egress:
    # DNS
    - to:
        - namespaceSelector: {}
      ports:
        - protocol: UDP
          port: 53
    # OTel collector
    - to:
        - namespaceSelector:
            matchLabels:
              name: observability
      ports:
        - protocol: TCP
          port: 4317
    # Kubernetes API
    - to:
        - namespaceSelector:
            matchLabels:
              name: kube-system
      ports:
        - protocol: TCP
          port: 443
```

Apply:

```bash
kubectl apply -f networkpolicy.yaml
```

### 1.6 Horizontal Pod Autoscaling

```yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: lsp-max
  namespace: lsp-max
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: lsp-max
  minReplicas: 2
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
    - type: Resource
      resource:
        name: memory
        target:
          type: Utilization
          averageUtilization: 80
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 300
      policies:
        - type: Percent
          value: 50
          periodSeconds: 60
    scaleUp:
      stabilizationWindowSeconds: 0
      policies:
        - type: Percent
          value: 100
          periodSeconds: 30
```

Apply:

```bash
kubectl apply -f hpa.yaml
```

---

## 2. Docker Compose Deployment

### 2.1 Single Container with Dependencies

```yaml
version: '3.8'

services:
  lsp-max:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: lsp-max
    ports:
      - "8080:8080"
      - "9091:9091"
    environment:
      LSP_MAX_LOG_LEVEL: info
      OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4317
      GIT_TOKEN: ${GIT_TOKEN}
    volumes:
      - ./config.yaml:/etc/lsp-max/config.yaml:ro
      - lsp-sessions:/tmp/lsp-max-sessions
      - lsp-logs:/var/log/lsp-max
      - /path/to/workspace:/workspace:ro
    depends_on:
      otel-collector:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/healthz"]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 30s
    networks:
      - lsp-max-network

  otel-collector:
    image: otel/opentelemetry-collector-contrib:latest
    container_name: otel-collector
    command:
      - "--config=/etc/otel-collector-config.yml"
    volumes:
      - ./otel-config.yml:/etc/otel-collector-config.yml:ro
    ports:
      - "4317:4317"  # gRPC
      - "4318:4318"  # HTTP
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:13133"]
      interval: 10s
      timeout: 5s
      retries: 3
    networks:
      - lsp-max-network

  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    ports:
      - "9090:9090"
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prometheus-data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
    networks:
      - lsp-max-network

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    ports:
      - "3000:3000"
    environment:
      GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD:-admin}
    volumes:
      - grafana-data:/var/lib/grafana
      - ./grafana-datasources.yml:/etc/grafana/provisioning/datasources/datasources.yml:ro
    depends_on:
      - prometheus
    networks:
      - lsp-max-network

volumes:
  lsp-sessions:
  lsp-logs:
  prometheus-data:
  grafana-data:

networks:
  lsp-max-network:
    driver: bridge
```

**Environment file** (`.env`):

```bash
GIT_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxx
GRAFANA_PASSWORD=secure_password_here
```

**Start:**

```bash
docker-compose up -d
docker-compose logs -f lsp-max
```

### 2.2 Multi-Region Deployment

```yaml
version: '3.8'

services:
  # Primary region (us-west-2)
  lsp-max-primary:
    build: .
    container_name: lsp-max-primary
    ports:
      - "8080:8080"
    environment:
      LSP_MAX_REGION: us-west-2
      LSP_MAX_INSTANCE_ID: primary-001
    volumes:
      - lsp-primary-logs:/var/log/lsp-max
    networks:
      - lsp-max-mesh

  # Secondary region (us-east-1)
  lsp-max-secondary:
    build: .
    container_name: lsp-max-secondary
    ports:
      - "8081:8080"
    environment:
      LSP_MAX_REGION: us-east-1
      LSP_MAX_INSTANCE_ID: secondary-001
    volumes:
      - lsp-secondary-logs:/var/log/lsp-max
    networks:
      - lsp-max-mesh

  # Load balancer
  nginx:
    image: nginx:latest
    container_name: lsp-max-lb
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    depends_on:
      - lsp-max-primary
      - lsp-max-secondary
    networks:
      - lsp-max-mesh

volumes:
  lsp-primary-logs:
  lsp-secondary-logs:

networks:
  lsp-max-mesh:
    driver: bridge
```

---

## 3. AWS Deployment

### 3.1 ECS on Fargate

```json
{
  "family": "lsp-max",
  "networkMode": "awsvpc",
  "requiresCompatibilities": ["FARGATE"],
  "cpu": "1024",
  "memory": "2048",
  "containerDefinitions": [
    {
      "name": "lsp-max",
      "image": "123456789.dkr.ecr.us-west-2.amazonaws.com/lsp-max:26.7.1",
      "portMappings": [
        {
          "containerPort": 8080,
          "hostPort": 8080,
          "protocol": "tcp"
        },
        {
          "containerPort": 9091,
          "hostPort": 9091,
          "protocol": "tcp"
        }
      ],
      "environment": [
        {
          "name": "LSP_MAX_LOG_LEVEL",
          "value": "info"
        },
        {
          "name": "OTEL_EXPORTER_OTLP_ENDPOINT",
          "value": "http://otel-collector.internal:4317"
        }
      ],
      "secrets": [
        {
          "name": "GIT_TOKEN",
          "valueFrom": "arn:aws:secretsmanager:us-west-2:123456789:secret:lsp-max/git-token:token::"
        }
      ],
      "logConfiguration": {
        "logDriver": "awslogs",
        "options": {
          "awslogs-group": "/ecs/lsp-max",
          "awslogs-region": "us-west-2",
          "awslogs-stream-prefix": "ecs"
        }
      },
      "healthCheck": {
        "command": ["CMD-SHELL", "curl -f http://localhost:8080/healthz || exit 1"],
        "interval": 10,
        "timeout": 5,
        "retries": 3,
        "startPeriod": 30
      }
    }
  ],
  "taskRoleArn": "arn:aws:iam::123456789:role/ecsTaskRole",
  "executionRoleArn": "arn:aws:iam::123456789:role/ecsTaskExecutionRole"
}
```

**CloudFormation template** (`lsp-max-stack.yaml`):

```yaml
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Deploy lsp-max on ECS Fargate'

Parameters:
  VpcId:
    Type: AWS::EC2::VPC::Id
  SubnetIds:
    Type: List<AWS::EC2::Subnet::Id>
  SecurityGroupIds:
    Type: List<AWS::EC2::SecurityGroup::Id>

Resources:
  LspMaxCluster:
    Type: AWS::ECS::Cluster
    Properties:
      ClusterName: lsp-max-cluster

  LspMaxService:
    Type: AWS::ECS::Service
    Properties:
      Cluster: !Ref LspMaxCluster
      TaskDefinition: lsp-max:1
      DesiredCount: 3
      LaunchType: FARGATE
      NetworkConfiguration:
        AwsvpcConfiguration:
          AssignPublicIp: ENABLED
          Subnets: !Ref SubnetIds
          SecurityGroups: !Ref SecurityGroupIds
      LoadBalancers:
        - ContainerName: lsp-max
          ContainerPort: 8080
          TargetGroupArn: !Ref TargetGroup

  TargetGroup:
    Type: AWS::ElasticLoadBalancingV2::TargetGroup
    Properties:
      Port: 8080
      Protocol: HTTP
      TargetType: ip
      VpcId: !Ref VpcId
      HealthCheckPath: /healthz
      HealthCheckProtocol: HTTP

  LoadBalancer:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      Subnets: !Ref SubnetIds
      SecurityGroups: !Ref SecurityGroupIds

Outputs:
  LoadBalancerDNS:
    Value: !GetAtt LoadBalancer.DNSName
```

**Deploy:**

```bash
aws cloudformation create-stack \
  --stack-name lsp-max-stack \
  --template-body file://lsp-max-stack.yaml \
  --parameters ParameterKey=VpcId,ParameterValue=vpc-xxx \
                ParameterKey=SubnetIds,ParameterValue=subnet-xxx,subnet-yyy

aws ecs create-service \
  --cluster lsp-max-cluster \
  --service-name lsp-max \
  --task-definition lsp-max:1 \
  --desired-count 3 \
  --launch-type FARGATE
```

### 3.2 EC2 Auto Scaling Group

```yaml
AWSTemplateFormatVersion: '2010-09-09'

Resources:
  LaunchTemplate:
    Type: AWS::EC2::LaunchTemplate
    Properties:
      LaunchTemplateData:
        ImageId: ami-0c55b159cbfafe1f0  # Ubuntu 22.04
        InstanceType: t3.large
        KeyName: my-key-pair
        SecurityGroupIds:
          - sg-0123456789abcdef0
        UserData:
          Fn::Base64: |
            #!/bin/bash
            set -e
            
            # Install Docker
            apt-get update
            apt-get install -y docker.io docker-compose
            systemctl start docker
            
            # Clone lsp-max repository
            cd /opt
            git clone https://github.com/seanchatmangpt/lsp-max.git
            cd lsp-max
            
            # Start container
            docker-compose up -d
            
            # CloudWatch agent
            wget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
            dpkg -i amazon-cloudwatch-agent.deb
            /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl \
              -a fetch-config \
              -m ec2 \
              -s \
              -c ssm:lsp-max-cloudwatch-config

  AutoScalingGroup:
    Type: AWS::AutoScaling::AutoScalingGroup
    Properties:
      LaunchTemplate:
        LaunchTemplateId: !Ref LaunchTemplate
        Version: !GetAtt LaunchTemplate.LatestVersionNumber
      MinSize: 2
      MaxSize: 10
      DesiredCapacity: 3
      VPCZoneIdentifier:
        - subnet-0123456789abcdef0
        - subnet-fedcba9876543210
      TargetGroupARNs:
        - !Ref TargetGroup

  ScalingPolicy:
    Type: AWS::AutoScaling::ScalingPolicy
    Properties:
      AdjustmentType: ChangeInCapacity
      AutoScalingGroupName: !Ref AutoScalingGroup
      PolicyType: TargetTrackingScaling
      TargetTrackingConfiguration:
        PredefinedMetricSpecification:
          PredefinedMetricType: ASGAverageCPUUtilization
        TargetValue: 70.0
```

---

## 4. Google Cloud Platform (GCP)

### 4.1 Cloud Run Deployment

```bash
# Build and push to Container Registry
gcloud builds submit --tag gcr.io/$PROJECT_ID/lsp-max:26.7.1

# Deploy to Cloud Run
gcloud run deploy lsp-max \
  --image gcr.io/$PROJECT_ID/lsp-max:26.7.1 \
  --platform managed \
  --region us-central1 \
  --memory 2Gi \
  --cpu 2 \
  --timeout 3600 \
  --set-env-vars LSP_MAX_LOG_LEVEL=info,OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317 \
  --set-secrets GIT_TOKEN=lsp-max-git-token:latest \
  --no-allow-unauthenticated \
  --min-instances 1 \
  --max-instances 10
```

### 4.2 GKE (Google Kubernetes Engine)

```bash
# Create cluster
gcloud container clusters create lsp-max-cluster \
  --zone us-central1-a \
  --num-nodes 3 \
  --machine-type n2-standard-4 \
  --enable-autoscaling \
  --min-nodes 2 \
  --max-nodes 10 \
  --enable-ip-alias \
  --enable-network-policy

# Deploy application (use Kubernetes manifests from section 1)
kubectl apply -f namespace.yaml
kubectl apply -f deployment.yaml
kubectl apply -f service-ingress.yaml
```

### 4.3 Cloud Firestore for State (Optional)

For stateful deployments, store session metadata in Firestore:

```rust
use google_cloud_firestore::Client;

async fn store_session_metadata(
    client: &Client,
    session_id: &str,
    metadata: SessionMetadata,
) -> Result<()> {
    client
        .collection("sessions")
        .document(session_id)
        .set(serde_json::to_value(&metadata)?)
        .await?;
    Ok(())
}
```

---

## 5. Custom Agent Integration

### 5.1 Agent Client Setup

```rust
// agent/src/lsp_client.rs
use lsp_max_client::Client;
use lsp_max_client::transport::stdio::PipeTransport;
use tokio::process::Command;

async fn spawn_lsp_server() -> Result<Client> {
    let mut cmd = Command::new("lsp-max-server");
    
    let process = cmd
        .stdin(Stdio::piped())
        .stdout(Stdio::piped())
        .spawn()?;
    
    let transport = PipeTransport::new(
        process.stdout.unwrap(),
        process.stdin.unwrap(),
    );
    
    let client = Client::new(transport);
    
    // Initialize
    let init_result = client
        .send_request::<InitializeRequest>(InitializeParams {
            ..Default::default()
        })
        .await?;
    
    client.notify::<InitializedNotification>(InitializedParams {}).await?;
    
    Ok(client)
}
```

### 5.2 Agent Query Pattern

```rust
// agent/src/analysis.rs
async fn analyze_document(
    client: &Client,
    uri: Url,
    content: String,
) -> Result<AnalysisResult> {
    // Open document
    client.notify::<DidOpenTextDocument>(
        DidOpenTextDocumentParams {
            textDocument: TextDocumentItem {
                uri: uri.clone(),
                languageId: "rust".to_string(),
                version: 1,
                text: content,
            },
        }
    ).await?;
    
    // Query hover at multiple positions
    let hovers = futures::future::join_all(
        (0..100).map(|pos| {
            client.send_request::<HoverRequest>(HoverParams {
                textDocument: TextDocumentPositionParams {
                    textDocument: TextDocumentIdentifier {
                        uri: uri.clone(),
                    },
                    position: Position {
                        line: 0,
                        character: pos,
                    },
                },
                workDoneProgressParams: Default::default(),
            })
        })
    ).await;
    
    // Check gate status
    let gate_status = client.send_request::<MaxGateStatusRequest>(json!({})).await?;
    
    Ok(AnalysisResult {
        hovers,
        gate_open: gate_status.state == "OPEN",
    })
}
```

### 5.3 Docker Network for Agent System

```yaml
version: '3.8'

services:
  agent-orchestrator:
    build:
      context: ./agent
      dockerfile: Dockerfile
    container_name: agent-orchestrator
    environment:
      LSP_MAX_SERVER: http://lsp-max:8080
      AGENT_ID: orchestrator-001
    networks:
      - agent-mesh
    depends_on:
      - lsp-max

  lsp-max:
    build:
      context: ./lsp-max
    container_name: lsp-max
    environment:
      LSP_MAX_LOG_LEVEL: debug
    networks:
      - agent-mesh
    expose:
      - "8080"

  # Worker agents
  agent-worker-1:
    build:
      context: ./agent
      dockerfile: Dockerfile
    container_name: agent-worker-1
    environment:
      LSP_MAX_SERVER: http://lsp-max:8080
      AGENT_ID: worker-001
      WORKER_POOL_SIZE: 10
    networks:
      - agent-mesh
    depends_on:
      - lsp-max

  agent-worker-2:
    build:
      context: ./agent
      dockerfile: Dockerfile
    container_name: agent-worker-2
    environment:
      LSP_MAX_SERVER: http://lsp-max:8080
      AGENT_ID: worker-002
      WORKER_POOL_SIZE: 10
    networks:
      - agent-mesh
    depends_on:
      - lsp-max

networks:
  agent-mesh:
    driver: bridge
```

---

## 6. GitHub Actions Workflow

### 6.1 Matrix Testing

```yaml
name: lsp-max-matrix-test

on:
  push:
    branches: [main, release/*]
  pull_request:
    branches: [main, release/*]

jobs:
  test:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        rust: [stable, nightly]
        include:
          - os: ubuntu-latest
            rust: stable
            coverage: true
    
    runs-on: ${{ matrix.os }}
    
    steps:
      - uses: actions/checkout@v3
      
      - name: Checkout dependencies
        run: |
          cd ..
          for repo in lsp-types-max wasm4pm-compat wasm4pm; do
            [ -d "$repo" ] || git clone "https://github.com/seanchatmangpt/$repo.git"
          done
      
      - name: Install Rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}
          components: rustfmt, clippy
      
      - name: Cache Cargo
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/bin
            ~/.cargo/registry/index
            ~/.cargo/registry/cache
            ~/.cargo/git/db
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ${{ runner.os }}-cargo-
      
      - name: Run tests
        run: cargo test --workspace --locked
      
      - name: Run clippy
        if: matrix.rust == 'stable'
        run: cargo clippy --workspace --all-targets -- -D warnings
      
      - name: Generate coverage
        if: matrix.coverage
        run: |
          cargo install tarpaulin
          cargo tarpaulin --out Xml --output-dir coverage
      
      - name: Upload coverage
        if: matrix.coverage
        uses: codecov/codecov-action@v3
        with:
          files: coverage/cobertura.xml
```

### 6.2 Release Workflow

```yaml
name: release

on:
  push:
    tags:
      - 'v*'

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Checkout dependencies
        run: |
          cd ..
          for repo in lsp-types-max wasm4pm-compat wasm4pm; do
            [ -d "$repo" ] || git clone "https://github.com/seanchatmangpt/$repo.git"
          done
      
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
      
      - name: Verify version
        run: |
          VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name=="lsp-max") | .version')
          TAG=${GITHUB_REF#refs/tags/}
          if [ "$VERSION" != "$TAG" ]; then
            echo "Version mismatch: $VERSION vs $TAG"
            exit 1
          fi
      
      - name: Test
        run: cargo test --release --locked
      
      - name: Publish to crates.io
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }}
        run: cargo publish
      
      - name: Create Release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.ref }}
          release_name: Release ${{ github.ref }}
          body: |
            ## Changes
            - See CHANGELOG.md for details
          draft: false
          prerelease: false
      
      - name: Build and push Docker image
        run: |
          docker build -t gcr.io/my-project/lsp-max:${GITHUB_REF#refs/tags/} .
          docker push gcr.io/my-project/lsp-max:${GITHUB_REF#refs/tags/}
```

---

## 7. Monitoring & Logging Setup

### 7.1 Prometheus Configuration

`prometheus.yml`:

```yaml
global:
  scrape_interval: 15s
  evaluation_interval: 15s

scrape_configs:
  - job_name: 'lsp-max'
    static_configs:
      - targets: ['localhost:9091']
    scrape_interval: 10s
    scrape_timeout: 5s
    metrics_path: /metrics
```

### 7.2 Grafana Dashboard

```json
{
  "dashboard": {
    "title": "lsp-max",
    "panels": [
      {
        "title": "Request Latency (P95)",
        "targets": [
          {
            "expr": "histogram_quantile(0.95, lsp_max_request_duration_ms)"
          }
        ]
      },
      {
        "title": "Active Sessions",
        "targets": [
          {
            "expr": "lsp_max_session_active"
          }
        ]
      },
      {
        "title": "Gate State",
        "targets": [
          {
            "expr": "lsp_max_gate_state"
          }
        ]
      }
    ]
  }
}
```

---

## Summary

This guide covers deployment to:
- **Kubernetes**: Production-grade multi-replica deployments with HPA and network policies
- **Docker Compose**: Local development and single-machine deployments
- **AWS**: ECS Fargate, EC2 Auto Scaling
- **GCP**: Cloud Run and GKE
- **Custom agents**: Integration with agent orchestration systems
- **GitHub Actions**: CI/CD automation and releases

For additional reference, see:
- `/home/user/lsp-max/docs/REMOTE_EXECUTION.md` — Container isolation and resource limits
- `/home/user/lsp-max/CLAUDE.md` — Claude Code integration
- `/home/user/lsp-max/.github/workflows/ci.yml` — Existing CI configuration