@jaguilar87/gaia-ops 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/CHANGELOG.md +315 -0
  2. package/CLAUDE.md +154 -0
  3. package/LICENSE +21 -0
  4. package/README.md +221 -0
  5. package/agents/aws-troubleshooter.md +50 -0
  6. package/agents/claude-architect.md +821 -0
  7. package/agents/devops-developer.md +92 -0
  8. package/agents/gcp-troubleshooter.md +50 -0
  9. package/agents/gitops-operator.md +360 -0
  10. package/agents/terraform-architect.md +289 -0
  11. package/bin/gaia-init.js +620 -0
  12. package/commands/architect.md +97 -0
  13. package/commands/restore-session.md +87 -0
  14. package/commands/save-session.md +88 -0
  15. package/commands/session-status.md +61 -0
  16. package/commands/speckit.add-task.md +144 -0
  17. package/commands/speckit.analyze-task.md +65 -0
  18. package/commands/speckit.implement.md +96 -0
  19. package/commands/speckit.init.md +237 -0
  20. package/commands/speckit.plan.md +88 -0
  21. package/commands/speckit.specify.md +161 -0
  22. package/commands/speckit.tasks.md +188 -0
  23. package/config/AGENTS.md +162 -0
  24. package/config/agent-catalog.md +604 -0
  25. package/config/context-contracts.md +682 -0
  26. package/config/git-standards.md +674 -0
  27. package/config/git_standards.json +69 -0
  28. package/config/orchestration-workflow.md +735 -0
  29. package/hooks/__pycache__/post_tool_use.cpython-312.pyc +0 -0
  30. package/hooks/__pycache__/pre_kubectl_security.cpython-312.pyc +0 -0
  31. package/hooks/__pycache__/pre_tool_use.cpython-312.pyc +0 -0
  32. package/hooks/__pycache__/session_start.cpython-312.pyc +0 -0
  33. package/hooks/__pycache__/subagent_stop.cpython-312.pyc +0 -0
  34. package/hooks/post_tool_use.py +463 -0
  35. package/hooks/pre_kubectl_security.py +205 -0
  36. package/hooks/pre_tool_use.py +530 -0
  37. package/hooks/session_start.py +315 -0
  38. package/hooks/subagent_stop.py +549 -0
  39. package/index.js +92 -0
  40. package/package.json +59 -0
  41. package/speckit/README.en.md +648 -0
  42. package/speckit/README.md +353 -0
  43. package/speckit/governance.md +169 -0
  44. package/speckit/scripts/check-prerequisites.sh +194 -0
  45. package/speckit/scripts/common.sh +126 -0
  46. package/speckit/scripts/create-new-feature.sh +131 -0
  47. package/speckit/scripts/init.sh +42 -0
  48. package/speckit/scripts/setup-plan.sh +95 -0
  49. package/speckit/scripts/update-agent-context.sh +718 -0
  50. package/speckit/templates/adr-template.md +118 -0
  51. package/speckit/templates/agent-file-template.md +23 -0
  52. package/speckit/templates/plan-template.md +233 -0
  53. package/speckit/templates/spec-template.md +116 -0
  54. package/speckit/templates/tasks-template-bkp.md +136 -0
  55. package/speckit/templates/tasks-template.md +345 -0
  56. package/templates/CLAUDE.template.md +170 -0
  57. package/templates/code-examples/approval_gate_workflow.py +141 -0
  58. package/templates/code-examples/clarification_workflow.py +94 -0
  59. package/templates/code-examples/commit_validation.py +86 -0
  60. package/templates/project-context.template.json +126 -0
  61. package/templates/settings.template.json +307 -0
  62. package/tools/__pycache__/agent_router.cpython-312.pyc +0 -0
  63. package/tools/__pycache__/approval_gate.cpython-312.pyc +0 -0
  64. package/tools/__pycache__/clarify_engine.cpython-312.pyc +0 -0
  65. package/tools/__pycache__/clarify_patterns.cpython-312.pyc +0 -0
  66. package/tools/__pycache__/commit_validator.cpython-312.pyc +0 -0
  67. package/tools/__pycache__/context_section_reader.cpython-312.pyc +0 -0
  68. package/tools/__pycache__/routing_dashboard.cpython-312.pyc +0 -0
  69. package/tools/__pycache__/routing_feedback.cpython-312.pyc +0 -0
  70. package/tools/__pycache__/semantic_matcher.cpython-312.pyc +0 -0
  71. package/tools/__pycache__/task_manager.cpython-312.pyc +0 -0
  72. package/tools/agent_capabilities.json +231 -0
  73. package/tools/agent_invoker_helper.py +239 -0
  74. package/tools/agent_router.py +730 -0
  75. package/tools/approval_gate.py +318 -0
  76. package/tools/clarify_engine.py +511 -0
  77. package/tools/clarify_patterns.py +356 -0
  78. package/tools/commit_validator.py +338 -0
  79. package/tools/context_provider.py +181 -0
  80. package/tools/context_section_reader.py +301 -0
  81. package/tools/demo_clarify.py +104 -0
  82. package/tools/generate_embeddings.py +168 -0
  83. package/tools/quicktriage_aws_troubleshooter.sh +45 -0
  84. package/tools/quicktriage_devops_developer.sh +38 -0
  85. package/tools/quicktriage_gcp_troubleshooter.sh +51 -0
  86. package/tools/quicktriage_gitops_operator.sh +47 -0
  87. package/tools/quicktriage_terraform_architect.sh +40 -0
  88. package/tools/semantic_matcher.py +222 -0
  89. package/tools/task_manager.py +547 -0
  90. package/tools/task_manager_README.md +395 -0
  91. package/tools/task_manager_example.py +215 -0
@@ -0,0 +1,682 @@
1
+ # Context Contracts
2
+
3
+ **Version:** 2.0.0
4
+ **Last Updated:** 2025-11-07
5
+ **Parent:** CLAUDE.md
6
+
7
+ This document defines the **Context Contracts** for each specialized agent. A context contract specifies the minimum structured data that MUST be provided when invoking an agent.
8
+
9
+ ---
10
+
11
+ ## Overview
12
+
13
+ ### What is a Context Contract?
14
+
15
+ A context contract is a schema that defines:
16
+ 1. **Required fields:** Data that MUST be present for the agent to operate
17
+ 2. **Optional fields:** Data that SHOULD be present when available
18
+ 3. **Data types:** Expected structure (string, array, object, etc.)
19
+ 4. **Source:** Where the data comes from (project-context.json, .claude/config/, etc.)
20
+
21
+ ### Why Context Contracts?
22
+
23
+ **Benefits:**
24
+ - **Consistency:** All invocations of an agent receive uniform context structure
25
+ - **Validation:** context_provider.py validates that required fields are present
26
+ - **Documentation:** Developers know exactly what data an agent needs
27
+ - **Evolution:** Contracts can be versioned and extended without breaking existing invocations
28
+
29
+ ---
30
+
31
+ ## Contract Format
32
+
33
+ Each contract section below follows this structure:
34
+
35
+ ```yaml
36
+ agent_name:
37
+ contract_version: "1.0"
38
+ required:
39
+ - field_group_name:
40
+ fields:
41
+ - field_name: type (description)
42
+ source: where_data_comes_from
43
+ optional:
44
+ - field_group_name:
45
+ fields:
46
+ - field_name: type (description)
47
+ source: where_data_comes_from
48
+ ```
49
+
50
+ ---
51
+
52
+ ## terraform-architect
53
+
54
+ **Purpose:** Manages Terraform/Terragrunt infrastructure lifecycle (validation, planning, realization)
55
+
56
+ ### Contract v1.0
57
+
58
+ ```yaml
59
+ terraform-architect:
60
+ contract_version: "1.0"
61
+
62
+ required:
63
+ - project_details:
64
+ fields:
65
+ - id: string (GCP project ID, e.g., "aaxis-rnd-non-prod")
66
+ - region: string (Primary region, e.g., "us-central1")
67
+ - environment: string (Environment name, e.g., "non-prod")
68
+ source: project-context.json
69
+
70
+ - terraform_infrastructure:
71
+ fields:
72
+ - layout:
73
+ base_path: string (Root of terraform code, e.g., "/home/.../ops/terraform")
74
+ modules_path: string (Shared modules, e.g., "modules/")
75
+ environments_path: string (Environment configs, e.g., "environments/")
76
+ - provider_credentials:
77
+ gcp_credentials_path: string (Path to GCP service account JSON)
78
+ aws_credentials_profile: string (AWS profile name, if multi-cloud)
79
+ source: project-context.json
80
+
81
+ - operational_guidelines:
82
+ fields:
83
+ - commit_standards:
84
+ validation_required: boolean (Always true)
85
+ validator_path: string (Path to commit_validator.py)
86
+ config_path: string (Path to git_standards.json)
87
+ source: project-context.json
88
+
89
+ optional:
90
+ - terraform_state:
91
+ fields:
92
+ - backend_type: string (e.g., "gcs", "s3")
93
+ - backend_config:
94
+ bucket: string (GCS bucket or S3 bucket name)
95
+ prefix: string (State file prefix)
96
+ source: project-context.json or auto-detect from backend.tf
97
+
98
+ - recent_changes:
99
+ fields:
100
+ - commits: array (Last 5 commits in terraform code)
101
+ - deployments: array (Recent terraform applies with timestamps)
102
+ source: enrichment (git log, terraform state metadata)
103
+ ```
104
+
105
+ ### Example Payload
106
+
107
+ ```json
108
+ {
109
+ "contract": {
110
+ "project_details": {
111
+ "id": "aaxis-rnd-non-prod",
112
+ "region": "us-central1",
113
+ "environment": "non-prod"
114
+ },
115
+ "terraform_infrastructure": {
116
+ "layout": {
117
+ "base_path": "/home/jaguilar/aaxis/rnd/repositories/ops/terraform",
118
+ "modules_path": "/home/jaguilar/aaxis/rnd/repositories/ops/terraform/modules",
119
+ "environments_path": "/home/jaguilar/aaxis/rnd/repositories/ops/terraform/environments"
120
+ },
121
+ "provider_credentials": {
122
+ "gcp_credentials_path": "/home/jaguilar/.config/gcloud/aaxis-rnd-terraform-sa.json"
123
+ }
124
+ },
125
+ "operational_guidelines": {
126
+ "commit_standards": {
127
+ "validation_required": true,
128
+ "validator_path": "/home/jaguilar/aaxis/rnd/repositories/.claude/tools/commit_validator.py",
129
+ "config_path": "/home/jaguilar/aaxis/rnd/repositories/.claude/config/git_standards.json"
130
+ }
131
+ }
132
+ },
133
+ "enrichment": {
134
+ "recent_changes": {
135
+ "commits": [
136
+ {"hash": "abc123", "message": "feat(gke): add node pool for batch jobs", "timestamp": "2025-11-06T10:30:00Z"}
137
+ ]
138
+ }
139
+ }
140
+ }
141
+ ```
142
+
143
+ ---
144
+
145
+ ## gitops-operator
146
+
147
+ **Purpose:** Manages Kubernetes/Flux application lifecycle (manifests, deployments, verification)
148
+
149
+ ### Contract v1.0
150
+
151
+ ```yaml
152
+ gitops-operator:
153
+ contract_version: "1.0"
154
+
155
+ required:
156
+ - project_details:
157
+ fields:
158
+ - id: string (GCP project ID)
159
+ - region: string (Primary region)
160
+ - cluster_name: string (GKE cluster name, e.g., "non-prod-rnd-gke")
161
+ source: project-context.json
162
+
163
+ - gitops_configuration:
164
+ fields:
165
+ - repository:
166
+ path: string (Root of gitops repo, e.g., "/home/.../gitops/non-prod-rnd-gke-gitops")
167
+ remote_url: string (Git remote URL)
168
+ branch: string (Main branch, e.g., "main")
169
+ - flux_details:
170
+ version: string (Flux version, e.g., "2.1.0")
171
+ namespaces: array (Flux system namespaces, e.g., ["flux-system"])
172
+ source: project-context.json
173
+
174
+ - cluster_details:
175
+ fields:
176
+ - namespaces: array (Application namespaces)
177
+ Example: ["tcm-non-prod", "pg-non-prod", "shared-services"]
178
+ - ingress_class: string (Ingress controller class, e.g., "nginx")
179
+ source: project-context.json
180
+
181
+ - operational_guidelines:
182
+ fields:
183
+ - commit_standards: (same as terraform-architect)
184
+ source: project-context.json
185
+
186
+ optional:
187
+ - application_services:
188
+ fields:
189
+ - services: array (List of deployed services)
190
+ Example: [
191
+ {
192
+ "name": "tcm-api",
193
+ "namespace": "tcm-non-prod",
194
+ "port": 3001,
195
+ "tech_stack": "NestJS",
196
+ "status": "running"
197
+ }
198
+ ]
199
+ source: project-context.json
200
+
201
+ - recent_changes:
202
+ fields:
203
+ - commits: array (Last 5 commits in gitops repo)
204
+ - deployments: array (Recent flux reconciliations)
205
+ source: enrichment (git log, flux get all)
206
+ ```
207
+
208
+ ### Example Payload
209
+
210
+ ```json
211
+ {
212
+ "contract": {
213
+ "project_details": {
214
+ "id": "aaxis-rnd-non-prod",
215
+ "region": "us-central1",
216
+ "cluster_name": "non-prod-rnd-gke"
217
+ },
218
+ "gitops_configuration": {
219
+ "repository": {
220
+ "path": "/home/jaguilar/aaxis/rnd/repositories/gitops/non-prod-rnd-gke-gitops",
221
+ "remote_url": "git@github.com:aaxis/non-prod-rnd-gke-gitops.git",
222
+ "branch": "main"
223
+ },
224
+ "flux_details": {
225
+ "version": "2.1.0",
226
+ "namespaces": ["flux-system"]
227
+ }
228
+ },
229
+ "cluster_details": {
230
+ "namespaces": ["tcm-non-prod", "pg-non-prod", "shared-services"],
231
+ "ingress_class": "nginx"
232
+ },
233
+ "operational_guidelines": {
234
+ "commit_standards": {
235
+ "validation_required": true,
236
+ "validator_path": "/home/jaguilar/aaxis/rnd/repositories/.claude/tools/commit_validator.py",
237
+ "config_path": "/home/jaguilar/aaxis/rnd/repositories/.claude/config/git_standards.json"
238
+ }
239
+ }
240
+ },
241
+ "enrichment": {
242
+ "application_services": [
243
+ {
244
+ "name": "tcm-api",
245
+ "namespace": "tcm-non-prod",
246
+ "port": 3001,
247
+ "tech_stack": "NestJS",
248
+ "status": "running",
249
+ "replicas": 2,
250
+ "image": "gcr.io/aaxis-rnd/tcm-api:v1.2.3"
251
+ },
252
+ {
253
+ "name": "pg-api",
254
+ "namespace": "pg-non-prod",
255
+ "port": 8086,
256
+ "tech_stack": "Spring Boot",
257
+ "status": "running",
258
+ "replicas": 3,
259
+ "image": "gcr.io/aaxis-rnd/pg-api:v2.1.0"
260
+ }
261
+ ],
262
+ "recent_changes": {
263
+ "commits": [
264
+ {"hash": "def456", "message": "feat(helmrelease): add tcm-api Phase 3.3", "timestamp": "2025-11-07T09:15:00Z"}
265
+ ]
266
+ }
267
+ }
268
+ }
269
+ ```
270
+
271
+ ---
272
+
273
+ ## gcp-troubleshooter
274
+
275
+ **Purpose:** Diagnoses issues by comparing intended state (IaC) with actual state (live GCP resources)
276
+
277
+ ### Contract v1.0
278
+
279
+ ```yaml
280
+ gcp-troubleshooter:
281
+ contract_version: "1.0"
282
+
283
+ required:
284
+ - project_details:
285
+ fields:
286
+ - id: string (GCP project ID)
287
+ - region: string (Primary region)
288
+ - cluster_name: string (GKE cluster name, if applicable)
289
+ source: project-context.json
290
+
291
+ - terraform_infrastructure:
292
+ fields:
293
+ - layout:
294
+ base_path: string (Root of terraform code)
295
+ source: project-context.json
296
+
297
+ - gitops_configuration:
298
+ fields:
299
+ - repository:
300
+ path: string (Root of gitops repo)
301
+ source: project-context.json
302
+
303
+ optional:
304
+ - application_services:
305
+ fields:
306
+ - services: array (Complete list for correlation)
307
+ source: project-context.json
308
+
309
+ - issue_context:
310
+ fields:
311
+ - symptoms: array (Error messages, logs, metrics)
312
+ - affected_resources: array (Resource names/IDs)
313
+ - timeline: string (When issue started)
314
+ source: enrichment (user description, logs analysis)
315
+ ```
316
+
317
+ ### Example Payload
318
+
319
+ ```json
320
+ {
321
+ "contract": {
322
+ "project_details": {
323
+ "id": "aaxis-rnd-non-prod",
324
+ "region": "us-central1",
325
+ "cluster_name": "non-prod-rnd-gke"
326
+ },
327
+ "terraform_infrastructure": {
328
+ "layout": {
329
+ "base_path": "/home/jaguilar/aaxis/rnd/repositories/ops/terraform"
330
+ }
331
+ },
332
+ "gitops_configuration": {
333
+ "repository": {
334
+ "path": "/home/jaguilar/aaxis/rnd/repositories/gitops/non-prod-rnd-gke-gitops"
335
+ }
336
+ }
337
+ },
338
+ "enrichment": {
339
+ "application_services": [
340
+ {"name": "tcm-api", "namespace": "tcm-non-prod"},
341
+ {"name": "pg-api", "namespace": "pg-non-prod"}
342
+ ],
343
+ "issue_context": {
344
+ "symptoms": [
345
+ "Pod tcm-api-5f7d8c9b-x7k2m in CrashLoopBackOff",
346
+ "Error: Unable to connect to CloudSQL instance"
347
+ ],
348
+ "affected_resources": ["tcm-api", "cloudsql-tcm-instance"],
349
+ "timeline": "Started 2025-11-07 08:30 UTC after deployment"
350
+ }
351
+ }
352
+ }
353
+ ```
354
+
355
+ ---
356
+
357
+ ## aws-troubleshooter
358
+
359
+ **Purpose:** Diagnoses issues in AWS environments (similar to gcp-troubleshooter but for AWS)
360
+
361
+ ### Contract v1.0
362
+
363
+ ```yaml
364
+ aws-troubleshooter:
365
+ contract_version: "1.0"
366
+
367
+ required:
368
+ - project_details:
369
+ fields:
370
+ - account_id: string (AWS account ID)
371
+ - region: string (Primary region, e.g., "us-east-1")
372
+ - cluster_name: string (EKS cluster name, if applicable)
373
+ source: project-context.json
374
+
375
+ - terraform_infrastructure:
376
+ fields:
377
+ - layout:
378
+ base_path: string (Root of terraform code)
379
+ source: project-context.json
380
+
381
+ - gitops_configuration:
382
+ fields:
383
+ - repository:
384
+ path: string (Root of gitops repo)
385
+ source: project-context.json
386
+
387
+ optional:
388
+ - application_services:
389
+ fields:
390
+ - services: array (Complete list for correlation)
391
+ source: project-context.json
392
+
393
+ - issue_context:
394
+ fields:
395
+ - symptoms: array (Error messages, logs, metrics)
396
+ - affected_resources: array (Resource names/IDs)
397
+ - timeline: string (When issue started)
398
+ source: enrichment (user description, logs analysis)
399
+ ```
400
+
401
+ ---
402
+
403
+ ## devops-developer
404
+
405
+ **Purpose:** Application-level operations (build, test, debug, git operations)
406
+
407
+ ### Contract v1.0
408
+
409
+ ```yaml
410
+ devops-developer:
411
+ contract_version: "1.0"
412
+
413
+ required:
414
+ - project_details:
415
+ fields:
416
+ - id: string (Project ID)
417
+ - environment: string (Environment name)
418
+ source: project-context.json
419
+
420
+ - operational_guidelines:
421
+ fields:
422
+ - commit_standards: (same as terraform-architect)
423
+ source: project-context.json
424
+
425
+ optional:
426
+ - application_services:
427
+ fields:
428
+ - services: array (List of services with tech stack info)
429
+ source: project-context.json
430
+
431
+ - development_context:
432
+ fields:
433
+ - language: string (Primary language, e.g., "TypeScript", "Python")
434
+ - framework: string (Framework, e.g., "NestJS", "Django")
435
+ - package_manager: string (e.g., "npm", "pip")
436
+ - test_command: string (e.g., "npm test", "pytest")
437
+ - build_command: string (e.g., "npm run build")
438
+ source: enrichment (detect from package.json, requirements.txt, etc.)
439
+ ```
440
+
441
+ ### Example Payload
442
+
443
+ ```json
444
+ {
445
+ "contract": {
446
+ "project_details": {
447
+ "id": "aaxis-rnd-non-prod",
448
+ "environment": "non-prod"
449
+ },
450
+ "operational_guidelines": {
451
+ "commit_standards": {
452
+ "validation_required": true,
453
+ "validator_path": "/home/jaguilar/aaxis/rnd/repositories/.claude/tools/commit_validator.py",
454
+ "config_path": "/home/jaguilar/aaxis/rnd/repositories/.claude/config/git_standards.json"
455
+ }
456
+ }
457
+ },
458
+ "enrichment": {
459
+ "application_services": [
460
+ {
461
+ "name": "tcm-api",
462
+ "tech_stack": "NestJS",
463
+ "language": "TypeScript"
464
+ }
465
+ ],
466
+ "development_context": {
467
+ "language": "TypeScript",
468
+ "framework": "NestJS",
469
+ "package_manager": "npm",
470
+ "test_command": "npm test",
471
+ "build_command": "npm run build"
472
+ }
473
+ }
474
+ }
475
+ ```
476
+
477
+ ---
478
+
479
+ ## claude-architect (Meta-Agent)
480
+
481
+ **Purpose:** Analyzes, diagnoses, and optimizes the agent orchestration system itself
482
+
483
+ **Note:** This is a META-AGENT. It does NOT use context_provider.py. Context is provided manually in the prompt.
484
+
485
+ ### Manual Context Structure
486
+
487
+ ```yaml
488
+ claude-architect:
489
+ context_type: "manual"
490
+
491
+ provided_in_prompt:
492
+ - system_paths:
493
+ - agent_system_path: string (e.g., "/home/.../repositories/.claude/")
494
+ - logs_path: string (e.g., "/home/.../repositories/.claude/logs/")
495
+ - tools_path: string (e.g., "/home/.../repositories/.claude/tools/")
496
+ - tests_path: string (e.g., "/home/.../repositories/.claude/tests/")
497
+ - orchestrator_logic: string (e.g., "/home/.../repositories/CLAUDE.md")
498
+
499
+ - system_metadata:
500
+ - spec_kit_commands: array (List of /speckit.* commands)
501
+ - session_commands: array (List of /save-session, /restore-session, etc.)
502
+ - agents: array (List of specialist agents)
503
+
504
+ - operational_context:
505
+ - recent_changes: string (Description of recent system changes)
506
+ - current_issues: string (Known issues or degradations)
507
+ - user_request: string (Specific question/analysis request)
508
+ ```
509
+
510
+ ### Example Invocation
511
+
512
+ ```python
513
+ Task(
514
+ subagent_type="claude-architect",
515
+ description="Analyze routing accuracy",
516
+ prompt="""
517
+ ## System Context
518
+
519
+ **System Paths:**
520
+ - Agent system: /home/jaguilar/aaxis/rnd/repositories/.claude/
521
+ - Orchestrator: /home/jaguilar/aaxis/rnd/repositories/CLAUDE.md
522
+ - Logs: /home/jaguilar/aaxis/rnd/repositories/.claude/logs/
523
+ - Tools: /home/jaguilar/aaxis/rnd/repositories/.claude/tools/
524
+ - Tests: /home/jaguilar/aaxis/rnd/repositories/.claude/tests/
525
+
526
+ **System Knowledge:**
527
+ - 5 specialist agents: terraform-architect, gitops-operator, gcp-troubleshooter, aws-troubleshooter, devops-developer
528
+ - Routing: agent_router.py with semantic matching
529
+ - Context: context_provider.py with contracts
530
+ - Logs: JSONL format in .claude/logs/
531
+
532
+ ## User's Request
533
+
534
+ Analyze routing accuracy over the last 100 invocations. Identify patterns in misrouted requests and propose improvements.
535
+
536
+ ## Your Mission
537
+
538
+ 1. Read routing logs from .claude/logs/agent-routing.jsonl
539
+ 2. Analyze accuracy, misroutes, patterns
540
+ 3. Research best practices for semantic routing
541
+ 4. Propose concrete improvements to agent_router.py
542
+ """
543
+ )
544
+ ```
545
+
546
+ ---
547
+
548
+ ## Contract Validation
549
+
550
+ ### How context_provider.py Uses Contracts
551
+
552
+ 1. **Load Contract:**
553
+ - Read agent definition from `.claude/agents/$AGENT_NAME.md`
554
+ - Extract contract schema from frontmatter or dedicated section
555
+
556
+ 2. **Validate Required Fields:**
557
+ - Check that all required fields are present in `project-context.json`
558
+ - Fail fast if required fields are missing
559
+
560
+ 3. **Enrich Optional Fields:**
561
+ - Attempt to populate optional fields from available sources
562
+ - Perform semantic enrichment (correlate services, recent changes, etc.)
563
+
564
+ 4. **Return Structured Payload:**
565
+ - Return JSON with `contract` (required fields) and `enrichment` (optional fields)
566
+
567
+ ### Example Validation Error
568
+
569
+ ```python
570
+ # context_provider.py execution
571
+ {
572
+ "status": "error",
573
+ "agent": "gitops-operator",
574
+ "missing_fields": [
575
+ "cluster_details.namespaces",
576
+ "gitops_configuration.repository.path"
577
+ ],
578
+ "message": "Cannot invoke agent: required fields missing from project-context.json"
579
+ }
580
+ ```
581
+
582
+ **Orchestrator response:** Report to user, ask to update `project-context.json`
583
+
584
+ ---
585
+
586
+ ## Extending Contracts
587
+
588
+ ### When to Add Fields
589
+
590
+ **Add required fields when:**
591
+ - Agent CANNOT operate without the field (e.g., cluster_name for gitops-operator)
592
+ - Field is always available in project-context.json
593
+
594
+ **Add optional fields when:**
595
+ - Agent CAN operate without the field but performs better with it
596
+ - Field may not always be available (e.g., recent_changes requires git log)
597
+ - Field is derived/enriched (not directly in project-context.json)
598
+
599
+ ### How to Extend
600
+
601
+ 1. **Update agent definition:**
602
+ - Edit `.claude/agents/$AGENT_NAME.md`
603
+ - Add field to contract schema
604
+
605
+ 2. **Update context_provider.py:**
606
+ - Add logic to extract/enrich new field
607
+ - Add validation if required field
608
+
609
+ 3. **Update project-context.json:**
610
+ - Add field to SSOT (if required field)
611
+
612
+ 4. **Update this document:**
613
+ - Add field to contract definition
614
+ - Increment contract version (e.g., 1.0 → 1.1)
615
+ - Update example payload
616
+
617
+ 5. **Test:**
618
+ - Run `pytest .claude/tests/test_context_provider.py`
619
+ - Verify agent receives new field
620
+
621
+ ---
622
+
623
+ ## Contract Versioning
624
+
625
+ ### Version Format
626
+
627
+ Contracts use semantic versioning: `MAJOR.MINOR`
628
+
629
+ **MAJOR:** Breaking change (removed field, changed type)
630
+ **MINOR:** Additive change (new optional field)
631
+
632
+ **Examples:**
633
+ - Add optional field: 1.0 → 1.1
634
+ - Add required field: 1.0 → 2.0 (breaking)
635
+ - Remove field: 1.0 → 2.0 (breaking)
636
+ - Change field type: 1.0 → 2.0 (breaking)
637
+
638
+ ### Backward Compatibility
639
+
640
+ **Rule:** context_provider.py MUST support all contract versions for 6 months after deprecation.
641
+
642
+ **How:**
643
+ - Maintain version adapters in context_provider.py
644
+ - Convert old contract format to new format internally
645
+ - Emit deprecation warnings
646
+
647
+ **Example:**
648
+ ```python
649
+ # context_provider.py
650
+ if agent_contract_version == "1.0":
651
+ # Adapt to new format
652
+ contract_data["new_field"] = derive_from_old_fields(contract_data)
653
+ warnings.warn(f"Contract v1.0 is deprecated, use v2.0")
654
+ ```
655
+
656
+ ---
657
+
658
+ ## Quick Reference Table
659
+
660
+ | Agent | Required Fields | Optional Fields | Primary Use Case |
661
+ |-------|----------------|-----------------|------------------|
662
+ | terraform-architect | project_details, terraform_infrastructure, operational_guidelines | terraform_state, recent_changes | Terraform/Terragrunt operations |
663
+ | gitops-operator | project_details, gitops_configuration, cluster_details, operational_guidelines | application_services, recent_changes | Kubernetes/Flux deployments |
664
+ | gcp-troubleshooter | project_details, terraform_infrastructure, gitops_configuration | application_services, issue_context | GCP diagnostics |
665
+ | aws-troubleshooter | project_details, terraform_infrastructure, gitops_configuration | application_services, issue_context | AWS diagnostics |
666
+ | devops-developer | project_details, operational_guidelines | application_services, development_context | App build/test/debug |
667
+ | claude-architect | (manual context in prompt) | N/A | System analysis & optimization |
668
+
669
+ ---
670
+
671
+ ## Version History
672
+
673
+ ### 2.0.0 (2025-11-07)
674
+ - Extracted from CLAUDE.md monolith
675
+ - Added complete contracts for all 6 agents
676
+ - Added validation, extension, versioning sections
677
+ - Added example payloads for each agent
678
+ - Distinguished project agents from meta-agents
679
+
680
+ ### 1.x (Historical)
681
+ - Embedded in CLAUDE.md
682
+ - Minimal contract definitions (field lists only)