@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.
- package/CHANGELOG.md +315 -0
- package/CLAUDE.md +154 -0
- package/LICENSE +21 -0
- package/README.md +221 -0
- package/agents/aws-troubleshooter.md +50 -0
- package/agents/claude-architect.md +821 -0
- package/agents/devops-developer.md +92 -0
- package/agents/gcp-troubleshooter.md +50 -0
- package/agents/gitops-operator.md +360 -0
- package/agents/terraform-architect.md +289 -0
- package/bin/gaia-init.js +620 -0
- package/commands/architect.md +97 -0
- package/commands/restore-session.md +87 -0
- package/commands/save-session.md +88 -0
- package/commands/session-status.md +61 -0
- package/commands/speckit.add-task.md +144 -0
- package/commands/speckit.analyze-task.md +65 -0
- package/commands/speckit.implement.md +96 -0
- package/commands/speckit.init.md +237 -0
- package/commands/speckit.plan.md +88 -0
- package/commands/speckit.specify.md +161 -0
- package/commands/speckit.tasks.md +188 -0
- package/config/AGENTS.md +162 -0
- package/config/agent-catalog.md +604 -0
- package/config/context-contracts.md +682 -0
- package/config/git-standards.md +674 -0
- package/config/git_standards.json +69 -0
- package/config/orchestration-workflow.md +735 -0
- package/hooks/__pycache__/post_tool_use.cpython-312.pyc +0 -0
- package/hooks/__pycache__/pre_kubectl_security.cpython-312.pyc +0 -0
- package/hooks/__pycache__/pre_tool_use.cpython-312.pyc +0 -0
- package/hooks/__pycache__/session_start.cpython-312.pyc +0 -0
- package/hooks/__pycache__/subagent_stop.cpython-312.pyc +0 -0
- package/hooks/post_tool_use.py +463 -0
- package/hooks/pre_kubectl_security.py +205 -0
- package/hooks/pre_tool_use.py +530 -0
- package/hooks/session_start.py +315 -0
- package/hooks/subagent_stop.py +549 -0
- package/index.js +92 -0
- package/package.json +59 -0
- package/speckit/README.en.md +648 -0
- package/speckit/README.md +353 -0
- package/speckit/governance.md +169 -0
- package/speckit/scripts/check-prerequisites.sh +194 -0
- package/speckit/scripts/common.sh +126 -0
- package/speckit/scripts/create-new-feature.sh +131 -0
- package/speckit/scripts/init.sh +42 -0
- package/speckit/scripts/setup-plan.sh +95 -0
- package/speckit/scripts/update-agent-context.sh +718 -0
- package/speckit/templates/adr-template.md +118 -0
- package/speckit/templates/agent-file-template.md +23 -0
- package/speckit/templates/plan-template.md +233 -0
- package/speckit/templates/spec-template.md +116 -0
- package/speckit/templates/tasks-template-bkp.md +136 -0
- package/speckit/templates/tasks-template.md +345 -0
- package/templates/CLAUDE.template.md +170 -0
- package/templates/code-examples/approval_gate_workflow.py +141 -0
- package/templates/code-examples/clarification_workflow.py +94 -0
- package/templates/code-examples/commit_validation.py +86 -0
- package/templates/project-context.template.json +126 -0
- package/templates/settings.template.json +307 -0
- package/tools/__pycache__/agent_router.cpython-312.pyc +0 -0
- package/tools/__pycache__/approval_gate.cpython-312.pyc +0 -0
- package/tools/__pycache__/clarify_engine.cpython-312.pyc +0 -0
- package/tools/__pycache__/clarify_patterns.cpython-312.pyc +0 -0
- package/tools/__pycache__/commit_validator.cpython-312.pyc +0 -0
- package/tools/__pycache__/context_section_reader.cpython-312.pyc +0 -0
- package/tools/__pycache__/routing_dashboard.cpython-312.pyc +0 -0
- package/tools/__pycache__/routing_feedback.cpython-312.pyc +0 -0
- package/tools/__pycache__/semantic_matcher.cpython-312.pyc +0 -0
- package/tools/__pycache__/task_manager.cpython-312.pyc +0 -0
- package/tools/agent_capabilities.json +231 -0
- package/tools/agent_invoker_helper.py +239 -0
- package/tools/agent_router.py +730 -0
- package/tools/approval_gate.py +318 -0
- package/tools/clarify_engine.py +511 -0
- package/tools/clarify_patterns.py +356 -0
- package/tools/commit_validator.py +338 -0
- package/tools/context_provider.py +181 -0
- package/tools/context_section_reader.py +301 -0
- package/tools/demo_clarify.py +104 -0
- package/tools/generate_embeddings.py +168 -0
- package/tools/quicktriage_aws_troubleshooter.sh +45 -0
- package/tools/quicktriage_devops_developer.sh +38 -0
- package/tools/quicktriage_gcp_troubleshooter.sh +51 -0
- package/tools/quicktriage_gitops_operator.sh +47 -0
- package/tools/quicktriage_terraform_architect.sh +40 -0
- package/tools/semantic_matcher.py +222 -0
- package/tools/task_manager.py +547 -0
- package/tools/task_manager_README.md +395 -0
- package/tools/task_manager_example.py +215 -0
|
@@ -0,0 +1,735 @@
|
|
|
1
|
+
# Orchestration Workflow: Detailed Implementation
|
|
2
|
+
|
|
3
|
+
**Version:** 2.0.0
|
|
4
|
+
**Last Updated:** 2025-11-07
|
|
5
|
+
**Parent:** CLAUDE.md
|
|
6
|
+
|
|
7
|
+
This document describes the complete 6-phase workflow for the orchestrator when handling user requests that require specialized agent invocation.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
The orchestrator operates in a **two-phase model** with an optional clarification step:
|
|
14
|
+
|
|
15
|
+
1. **Phase 0 (Optional):** Intelligent Clarification - Detect ambiguity and gather missing context
|
|
16
|
+
2. **Phase 1-3:** Planning - Route, provision context, and invoke agent for plan generation
|
|
17
|
+
3. **Phase 4:** Approval Gate - MANDATORY user approval before realization
|
|
18
|
+
4. **Phase 5:** Realization - Execute and verify in live environment
|
|
19
|
+
5. **Phase 6:** State Update - Update SSOTs (project-context.json, tasks.md)
|
|
20
|
+
|
|
21
|
+
**Critical Rule:** Phases 4 (Approval) is MANDATORY and cannot be skipped for T3 operations.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Phase 0: Intelligent Clarification (Optional)
|
|
26
|
+
|
|
27
|
+
**Trigger:** User request contains ambiguous terms, missing context, or multiple interpretations.
|
|
28
|
+
|
|
29
|
+
### Step 0.1: Detect Ambiguity
|
|
30
|
+
|
|
31
|
+
Execute `clarify_engine.py` to analyze the user's request:
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import sys
|
|
35
|
+
sys.path.insert(0, '/home/jaguilar/aaxis/rnd/repositories/.claude/tools')
|
|
36
|
+
from clarify_engine import request_clarification
|
|
37
|
+
|
|
38
|
+
# Detect ambiguity
|
|
39
|
+
clarification_data = request_clarification(
|
|
40
|
+
user_prompt="User's original request",
|
|
41
|
+
command_context={"command": "general_prompt"} # or speckit command name
|
|
42
|
+
)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Output:** `clarification_data` dictionary containing:
|
|
46
|
+
- `needs_clarification`: Boolean (True if ambiguity detected)
|
|
47
|
+
- `summary`: Human-readable explanation of what's ambiguous
|
|
48
|
+
- `question_config`: Pre-formatted payload for AskUserQuestion tool
|
|
49
|
+
- `clarification_context`: Internal state for enrichment
|
|
50
|
+
- `engine_instance`: Reference for Phase 0.4
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
### Step 0.2: Decision Point
|
|
55
|
+
|
|
56
|
+
**If `clarification_data["needs_clarification"] == False`:**
|
|
57
|
+
- Skip to Phase 1 (Agent Selection)
|
|
58
|
+
- Use original user prompt as-is
|
|
59
|
+
|
|
60
|
+
**If `clarification_data["needs_clarification"] == True`:**
|
|
61
|
+
- Continue to Step 0.3
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
### Step 0.3: Present Ambiguity & Gather Input
|
|
66
|
+
|
|
67
|
+
Present `clarification_data["summary"]` to the user, showing:
|
|
68
|
+
- What is ambiguous (detected keywords)
|
|
69
|
+
- Why clarification is needed (ambiguity score and reasoning)
|
|
70
|
+
- What information is missing (preview of options)
|
|
71
|
+
|
|
72
|
+
**MANDATORY:** Use AskUserQuestion tool:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
response = AskUserQuestion(**clarification_data["question_config"])
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Question Format:**
|
|
79
|
+
- 3-4 targeted questions (not just 2 binary options)
|
|
80
|
+
- Dynamic options from `project-context.json` (services, namespaces, resources)
|
|
81
|
+
- Rich descriptions with metadata (tech stack, namespace, port, status)
|
|
82
|
+
- Emoji for visual scanning (π¦ services, π― namespaces, π§ resources, β οΈ warnings)
|
|
83
|
+
- "Other" option for custom input (automatic escape hatch)
|
|
84
|
+
|
|
85
|
+
**Example Question:**
|
|
86
|
+
```
|
|
87
|
+
π¦ Servicio
|
|
88
|
+
ΒΏQuΓ© servicio quieres revisar?
|
|
89
|
+
|
|
90
|
+
Options:
|
|
91
|
+
π¦ tcm-api
|
|
92
|
+
NestJS | Namespace: tcm-non-prod | Puerto: 3001 | Estado: β
Running
|
|
93
|
+
|
|
94
|
+
π¦ pg-api
|
|
95
|
+
Spring Boot | Namespace: pg-non-prod | Puerto: 8086 | Estado: β
Running
|
|
96
|
+
|
|
97
|
+
π Todos los servicios
|
|
98
|
+
Aplicar a todos los recursos (3 total)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
### Step 0.4: Enrich Prompt
|
|
104
|
+
|
|
105
|
+
Process user responses to generate enriched prompt:
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from clarify_engine import process_clarification
|
|
109
|
+
|
|
110
|
+
result = process_clarification(
|
|
111
|
+
engine_instance=clarification_data["engine_instance"],
|
|
112
|
+
original_prompt="User's original request",
|
|
113
|
+
user_responses=response["answers"],
|
|
114
|
+
clarification_context=clarification_data["clarification_context"]
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
enriched_prompt = result["enriched_prompt"]
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**Output:** `enriched_prompt` - Original prompt + resolved context (service names, namespaces, etc.)
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
### Step 0.5: Logging
|
|
125
|
+
|
|
126
|
+
Clarification is automatically logged to `.claude/logs/clarifications.jsonl` for audit trail.
|
|
127
|
+
|
|
128
|
+
**Log Entry:**
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"timestamp": "2025-11-07T14:32:10Z",
|
|
132
|
+
"original_prompt": "revisa el servicio",
|
|
133
|
+
"ambiguity_score": 0.8,
|
|
134
|
+
"detected_keywords": ["servicio"],
|
|
135
|
+
"user_responses": {"service": "tcm-api", "namespace": "tcm-non-prod"},
|
|
136
|
+
"enriched_prompt": "revisa el servicio tcm-api en el namespace tcm-non-prod"
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
### Step 0.6: Proceed with Enriched Prompt
|
|
143
|
+
|
|
144
|
+
**IMPORTANT:** The `enriched_prompt` replaces the original user request for ALL subsequent phases (Phase 1-5).
|
|
145
|
+
|
|
146
|
+
**Benefits:**
|
|
147
|
+
- Better routing accuracy (agent_router.py has full context)
|
|
148
|
+
- Reduced agent invocation failures (complete context from start)
|
|
149
|
+
- Audit trail of clarification decisions
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Phase 1: Analysis & Agent Selection
|
|
154
|
+
|
|
155
|
+
**Input:** `enriched_prompt` (from Phase 0) OR original user task (if Phase 0 skipped)
|
|
156
|
+
|
|
157
|
+
### Step 1.1: Route Request
|
|
158
|
+
|
|
159
|
+
Execute `agent_router.py` to determine the appropriate specialized agent:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
python3 /home/jaguilar/aaxis/rnd/repositories/.claude/tools/agent_router.py --prompt "$PROMPT"
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
**Output:** Agent name (e.g., `gitops-operator`, `terraform-architect`, `gcp-troubleshooter`)
|
|
166
|
+
|
|
167
|
+
**Routing Logic:**
|
|
168
|
+
- Semantic matching against agent capabilities
|
|
169
|
+
- Keyword triggers (terraform β terraform-architect, kubernetes β gitops-operator)
|
|
170
|
+
- Context from enriched prompt (service names improve accuracy by ~40%)
|
|
171
|
+
|
|
172
|
+
**Fallback:** If no agent matches, use `Explore` agent for codebase investigation.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Phase 2: Deterministic Context Provisioning
|
|
177
|
+
|
|
178
|
+
**Input:** Agent name (from Phase 1), user task
|
|
179
|
+
|
|
180
|
+
### Step 2.1: Execute Context Provider
|
|
181
|
+
|
|
182
|
+
**CRITICAL:** Use absolute path to ensure it works from any directory:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
python3 /home/jaguilar/aaxis/rnd/repositories/.claude/tools/context_provider.py "$AGENT_NAME" "$USER_TASK"
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**What context_provider.py does:**
|
|
189
|
+
1. Loads agent's "Context Contract" from `.claude/agents/$AGENT_NAME.md`
|
|
190
|
+
2. Reads `project-context.json` (SSOT for infrastructure state)
|
|
191
|
+
3. Performs semantic enrichment (correlates services, namespaces, resources)
|
|
192
|
+
4. Returns complete, structured context payload
|
|
193
|
+
|
|
194
|
+
**Output:** JSON payload containing:
|
|
195
|
+
```json
|
|
196
|
+
{
|
|
197
|
+
"contract": {
|
|
198
|
+
"project_details": {...},
|
|
199
|
+
"gitops_configuration": {...},
|
|
200
|
+
"cluster_details": {...},
|
|
201
|
+
"operational_guidelines": {...}
|
|
202
|
+
},
|
|
203
|
+
"enrichment": {
|
|
204
|
+
"related_services": [...],
|
|
205
|
+
"affected_namespaces": [...],
|
|
206
|
+
"recent_changes": [...]
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**DO NOT:** Manually construct context. `context_provider.py` is the SSOT for context generation.
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Phase 3: Agent Invocation (Planning)
|
|
216
|
+
|
|
217
|
+
**Input:** Context payload (from Phase 2), user task
|
|
218
|
+
|
|
219
|
+
### Step 3.1: Build Minimalist Prompt
|
|
220
|
+
|
|
221
|
+
Construct a prompt with ONLY:
|
|
222
|
+
1. Full structured context payload (contract + enrichment)
|
|
223
|
+
2. User's task, stated clearly and concisely
|
|
224
|
+
|
|
225
|
+
**DO NOT:**
|
|
226
|
+
- Add instructions about agent's protocol ("generate a realization package")
|
|
227
|
+
- Explain how the agent should work
|
|
228
|
+
- Provide implementation details
|
|
229
|
+
|
|
230
|
+
**Why:** The agent knows its own job. Your role is to provide context, not instructions.
|
|
231
|
+
|
|
232
|
+
**Example Prompt:**
|
|
233
|
+
```markdown
|
|
234
|
+
## Context
|
|
235
|
+
|
|
236
|
+
{context_payload_from_phase_2}
|
|
237
|
+
|
|
238
|
+
## Task
|
|
239
|
+
|
|
240
|
+
{user_task}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
### Step 3.2: Invoke Agent for Plan
|
|
246
|
+
|
|
247
|
+
Execute the Task tool:
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
Task(
|
|
251
|
+
subagent_type="gitops-operator", # from Phase 1
|
|
252
|
+
description="Generate deployment plan",
|
|
253
|
+
prompt=minimalist_prompt
|
|
254
|
+
)
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
**Agent Responsibility:**
|
|
258
|
+
- Analyze context
|
|
259
|
+
- Generate declarative code (YAML, HCL, etc.)
|
|
260
|
+
- Create validation plan
|
|
261
|
+
- Return "Realization Package"
|
|
262
|
+
|
|
263
|
+
**Realization Package Contents:**
|
|
264
|
+
- Files to create/modify/delete
|
|
265
|
+
- Git operations (commit message, branch, remote)
|
|
266
|
+
- Resources affected in live environment
|
|
267
|
+
- Commands to execute (git push, terraform apply, etc.)
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Phase 4: Synthesis & Approval Gate (MANDATORY)
|
|
272
|
+
|
|
273
|
+
**Input:** Realization package (from Phase 3)
|
|
274
|
+
|
|
275
|
+
**CRITICAL:** This phase is NON-NEGOTIABLE for T3 operations. Skipping it is a protocol violation.
|
|
276
|
+
|
|
277
|
+
### Step 4.1: Process Output & Halt
|
|
278
|
+
|
|
279
|
+
Receive agent's output and **HALT the workflow**. DO NOT proceed to Phase 5 automatically.
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
### Step 4.2: Generate Approval Summary
|
|
284
|
+
|
|
285
|
+
**MANDATORY:** Use `approval_gate.py` to generate structured summary:
|
|
286
|
+
|
|
287
|
+
```python
|
|
288
|
+
import sys
|
|
289
|
+
sys.path.insert(0, '/home/jaguilar/aaxis/rnd/repositories/.claude/tools')
|
|
290
|
+
from approval_gate import request_approval
|
|
291
|
+
|
|
292
|
+
approval_data = request_approval(
|
|
293
|
+
realization_package=agent_response,
|
|
294
|
+
agent_name="gitops-operator", # or terraform-architect, etc.
|
|
295
|
+
phase="Phase 3.3" # or feature name
|
|
296
|
+
)
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
**Output:** `approval_data` dictionary containing:
|
|
300
|
+
- `summary`: Human-readable breakdown of changes
|
|
301
|
+
- `question_config`: Pre-formatted payload for AskUserQuestion
|
|
302
|
+
- `gate_instance`: Reference for Step 4.4
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
### Step 4.3: Present Summary
|
|
307
|
+
|
|
308
|
+
Present `approval_data["summary"]` to the user, showing:
|
|
309
|
+
|
|
310
|
+
**Files:**
|
|
311
|
+
- Files to create (with content preview)
|
|
312
|
+
- Files to modify (with diff)
|
|
313
|
+
- Files to delete (with warning)
|
|
314
|
+
|
|
315
|
+
**Git Operations:**
|
|
316
|
+
- Commit message (with validation status)
|
|
317
|
+
- Branch name (with remote tracking info)
|
|
318
|
+
- Remote push target (with permissions check)
|
|
319
|
+
|
|
320
|
+
**Resources Affected:**
|
|
321
|
+
- Kubernetes resources (Deployments, Services, Ingresses)
|
|
322
|
+
- Terraform resources (GCP/AWS resources)
|
|
323
|
+
- External dependencies (databases, storage, APIs)
|
|
324
|
+
|
|
325
|
+
**Critical Operations:**
|
|
326
|
+
- `git push` (irreversible after execution)
|
|
327
|
+
- `terraform apply` (creates/modifies live resources)
|
|
328
|
+
- `kubectl apply` (updates live cluster)
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
### Step 4.4: MANDATORY User Question
|
|
333
|
+
|
|
334
|
+
**CRITICAL:** Call AskUserQuestion tool. This is NON-NEGOTIABLE.
|
|
335
|
+
|
|
336
|
+
```python
|
|
337
|
+
response = AskUserQuestion(**approval_data["question_config"])
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
**Question Format:**
|
|
341
|
+
|
|
342
|
+
Exactly 3 options:
|
|
343
|
+
1. "β
Aprobar y ejecutar" - Proceed to realization
|
|
344
|
+
2. "β Rechazar" - Cancel and halt workflow
|
|
345
|
+
3. "Other" - Custom response (automatic option)
|
|
346
|
+
|
|
347
|
+
**Example:**
|
|
348
|
+
```
|
|
349
|
+
π¦ AprobaciΓ³n Requerida
|
|
350
|
+
|
|
351
|
+
ΒΏAprobar la ejecuciΓ³n de estos cambios?
|
|
352
|
+
|
|
353
|
+
π Archivos afectados: 3 creados, 1 modificado
|
|
354
|
+
π§ Recursos: 2 Deployments, 1 Service, 1 Ingress
|
|
355
|
+
β οΈ Operaciones crΓticas: git push, kubectl apply
|
|
356
|
+
|
|
357
|
+
Options:
|
|
358
|
+
β
Aprobar y ejecutar
|
|
359
|
+
Proceder con la realizaciΓ³n
|
|
360
|
+
|
|
361
|
+
β Rechazar
|
|
362
|
+
Cancelar y detener el workflow
|
|
363
|
+
|
|
364
|
+
Other
|
|
365
|
+
(Provide custom response)
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
### Step 4.5: Validate Response
|
|
371
|
+
|
|
372
|
+
Process user's response using `approval_gate.py`:
|
|
373
|
+
|
|
374
|
+
```python
|
|
375
|
+
from approval_gate import process_approval_response
|
|
376
|
+
|
|
377
|
+
validation = process_approval_response(
|
|
378
|
+
gate_instance=approval_data["gate_instance"],
|
|
379
|
+
user_response=response["answers"]["question_1"],
|
|
380
|
+
realization_package=agent_response,
|
|
381
|
+
agent_name="gitops-operator",
|
|
382
|
+
phase="Phase 3.3"
|
|
383
|
+
)
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
**Output:** `validation` dictionary containing:
|
|
387
|
+
- `approved`: Boolean (True if user approved)
|
|
388
|
+
- `action`: String ("proceed", "halt_workflow", "clarify_with_user")
|
|
389
|
+
- `reason`: String (explanation of decision)
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
### Step 4.6: Enforcement Rules
|
|
394
|
+
|
|
395
|
+
**If `validation["approved"] == True`:**
|
|
396
|
+
- Proceed to Phase 5 (Realization)
|
|
397
|
+
|
|
398
|
+
**If `validation["approved"] == False` AND `validation["action"] == "halt_workflow"`:**
|
|
399
|
+
- STOP. Report to user.
|
|
400
|
+
- DO NOT proceed to Phase 5.
|
|
401
|
+
- Log rejection to `.claude/logs/approvals.jsonl`
|
|
402
|
+
|
|
403
|
+
**If `validation["action"] == "clarify_with_user"`:**
|
|
404
|
+
- Ask for clarification
|
|
405
|
+
- Re-run approval gate (Steps 4.2-4.5)
|
|
406
|
+
|
|
407
|
+
**ABSOLUTE RULE:** You CANNOT proceed to Phase 5 without `validation["approved"] == True`.
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
### Step 4.7: Logging
|
|
412
|
+
|
|
413
|
+
Approval decision is automatically logged to `.claude/logs/approvals.jsonl` for audit trail.
|
|
414
|
+
|
|
415
|
+
**Log Entry:**
|
|
416
|
+
```json
|
|
417
|
+
{
|
|
418
|
+
"timestamp": "2025-11-07T14:35:22Z",
|
|
419
|
+
"agent": "gitops-operator",
|
|
420
|
+
"phase": "Phase 3.3",
|
|
421
|
+
"realization_package": {...},
|
|
422
|
+
"user_response": "Aprobar y ejecutar",
|
|
423
|
+
"approved": true,
|
|
424
|
+
"files_affected": 4,
|
|
425
|
+
"resources_affected": 3,
|
|
426
|
+
"critical_operations": ["git push", "kubectl apply"]
|
|
427
|
+
}
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
---
|
|
431
|
+
|
|
432
|
+
## Phase 5: Realization, Verification & Closure
|
|
433
|
+
|
|
434
|
+
**PREREQUISITE:** Phase 5 can ONLY execute if `validation["approved"] == True` from Phase 4.
|
|
435
|
+
|
|
436
|
+
### Step 5.1: Invoke for Realization
|
|
437
|
+
|
|
438
|
+
Upon approval, re-invoke the **SAME agent** with a concise prompt:
|
|
439
|
+
|
|
440
|
+
```python
|
|
441
|
+
Task(
|
|
442
|
+
subagent_type="gitops-operator", # SAME as Phase 3
|
|
443
|
+
description="Execute realization",
|
|
444
|
+
prompt=f"""
|
|
445
|
+
## Realization Order
|
|
446
|
+
|
|
447
|
+
Execute the following realization package:
|
|
448
|
+
|
|
449
|
+
{realization_package_from_phase_3}
|
|
450
|
+
|
|
451
|
+
## User Approval
|
|
452
|
+
|
|
453
|
+
Approved by user at {timestamp}.
|
|
454
|
+
|
|
455
|
+
## Instructions
|
|
456
|
+
|
|
457
|
+
1. Persist all files (Write tool)
|
|
458
|
+
2. Execute git operations (commit, push)
|
|
459
|
+
3. Execute live operations (kubectl apply, terraform apply)
|
|
460
|
+
4. Verify in live environment
|
|
461
|
+
5. Report verification status
|
|
462
|
+
"""
|
|
463
|
+
)
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
**Agent Responsibility:**
|
|
467
|
+
- Write files to disk
|
|
468
|
+
- Execute git operations (add, commit, push)
|
|
469
|
+
- Execute live operations (kubectl apply, terraform apply, etc.)
|
|
470
|
+
- Verify resources in live environment (kubectl get, gcloud describe, etc.)
|
|
471
|
+
- Return verification status
|
|
472
|
+
|
|
473
|
+
---
|
|
474
|
+
|
|
475
|
+
### Step 5.2: Agent Executes & Verifies
|
|
476
|
+
|
|
477
|
+
The agent performs:
|
|
478
|
+
|
|
479
|
+
1. **File Persistence:**
|
|
480
|
+
- Write files using Write tool
|
|
481
|
+
- Validate file contents
|
|
482
|
+
- Check file permissions
|
|
483
|
+
|
|
484
|
+
2. **Git Operations:**
|
|
485
|
+
- `git add .`
|
|
486
|
+
- `git commit -m "..."` (after validation with commit_validator.py)
|
|
487
|
+
- `git push origin $BRANCH`
|
|
488
|
+
|
|
489
|
+
3. **Live Operations:**
|
|
490
|
+
- `kubectl apply -f ...` (for gitops-operator)
|
|
491
|
+
- `terragrunt apply` (for terraform-architect)
|
|
492
|
+
- Wait for resources to be ready
|
|
493
|
+
|
|
494
|
+
4. **Verification:**
|
|
495
|
+
- `kubectl get deployment $NAME -o yaml`
|
|
496
|
+
- `kubectl get pods -l app=$NAME`
|
|
497
|
+
- Check status, readiness, errors
|
|
498
|
+
- Correlate with expected state
|
|
499
|
+
|
|
500
|
+
5. **Report:**
|
|
501
|
+
- Success: "β
Deployed successfully, 2/2 pods ready"
|
|
502
|
+
- Partial: "β οΈ Deployed but 1/2 pods CrashLoopBackOff"
|
|
503
|
+
- Failure: "β Deployment failed: ImagePullBackOff"
|
|
504
|
+
|
|
505
|
+
---
|
|
506
|
+
|
|
507
|
+
## Phase 6: System State Update (MANDATORY)
|
|
508
|
+
|
|
509
|
+
**PREREQUISITE:** Phase 5 completed successfully (agent reported success/partial success)
|
|
510
|
+
|
|
511
|
+
### Step 6.1: Update Infrastructure SSOT
|
|
512
|
+
|
|
513
|
+
Modify `.claude/project-context.json` to reflect new or changed resources.
|
|
514
|
+
|
|
515
|
+
**For new services:**
|
|
516
|
+
```json
|
|
517
|
+
{
|
|
518
|
+
"application_services": [
|
|
519
|
+
{
|
|
520
|
+
"name": "new-service",
|
|
521
|
+
"namespace": "namespace",
|
|
522
|
+
"port": 8080,
|
|
523
|
+
"tech_stack": "Spring Boot",
|
|
524
|
+
"status": "running"
|
|
525
|
+
}
|
|
526
|
+
]
|
|
527
|
+
}
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
**For modified resources:**
|
|
531
|
+
Update relevant fields (port, replicas, image_tag, etc.)
|
|
532
|
+
|
|
533
|
+
**For deleted resources:**
|
|
534
|
+
Remove from `application_services` or mark with `"status": "deleted"`
|
|
535
|
+
|
|
536
|
+
---
|
|
537
|
+
|
|
538
|
+
### Step 6.2: Update Plan SSOT
|
|
539
|
+
|
|
540
|
+
**If working within Spec-Kit workflow:**
|
|
541
|
+
|
|
542
|
+
Use `TaskManager` to mark completed tasks in `tasks.md`:
|
|
543
|
+
|
|
544
|
+
```python
|
|
545
|
+
import sys
|
|
546
|
+
sys.path.insert(0, '/home/jaguilar/aaxis/rnd/repositories/.claude/tools')
|
|
547
|
+
from task_manager import TaskManager
|
|
548
|
+
|
|
549
|
+
# Initialize with path to tasks.md
|
|
550
|
+
tm = TaskManager('/path/to/spec-kit-project/tasks.md')
|
|
551
|
+
|
|
552
|
+
# Mark task(s) as complete
|
|
553
|
+
completed_task_ids = ["T045", "T046"] # Extract from agent response or realization package
|
|
554
|
+
for task_id in completed_task_ids:
|
|
555
|
+
if tm.mark_task_complete(task_id):
|
|
556
|
+
print(f"β
Task {task_id} marked as complete")
|
|
557
|
+
else:
|
|
558
|
+
print(f"β οΈ Task {task_id} not found or already complete")
|
|
559
|
+
|
|
560
|
+
# Verify next pending tasks
|
|
561
|
+
pending = tm.get_pending_tasks(limit=5)
|
|
562
|
+
print(f"Next pending tasks: {[t['task_id'] for t in pending]}")
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
**Why TaskManager:**
|
|
566
|
+
- Efficient operations on large files (>25K tokens)
|
|
567
|
+
- Uses Grep+Edit instead of Read (avoids token limits)
|
|
568
|
+
- Atomic updates (no partial state)
|
|
569
|
+
- Validation (task_id exists, status transition valid)
|
|
570
|
+
|
|
571
|
+
**If NOT in Spec-Kit workflow:**
|
|
572
|
+
- Skip this step (no tasks.md to update)
|
|
573
|
+
|
|
574
|
+
---
|
|
575
|
+
|
|
576
|
+
### Step 6.3: Report and Transition
|
|
577
|
+
|
|
578
|
+
Report to the user:
|
|
579
|
+
|
|
580
|
+
```
|
|
581
|
+
β
Realization completada exitosamente
|
|
582
|
+
|
|
583
|
+
π Archivos actualizados:
|
|
584
|
+
- infrastructure/deployments/new-service.yaml (creado)
|
|
585
|
+
- infrastructure/services/new-service.yaml (creado)
|
|
586
|
+
|
|
587
|
+
π§ Recursos desplegados:
|
|
588
|
+
- Deployment/new-service: 2/2 pods ready
|
|
589
|
+
- Service/new-service: ClusterIP 10.20.30.40
|
|
590
|
+
|
|
591
|
+
π Estado del sistema actualizado:
|
|
592
|
+
- project-context.json: Agregado new-service
|
|
593
|
+
- tasks.md: Marcadas tareas T045, T046 como completadas
|
|
594
|
+
|
|
595
|
+
π― PrΓ³ximas tareas pendientes:
|
|
596
|
+
- T047: Configurar Ingress para new-service
|
|
597
|
+
- T048: Agregar health checks
|
|
598
|
+
|
|
599
|
+
ΒΏProceder con T047?
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
Explicitly confirm:
|
|
603
|
+
1. Infrastructure state updated (project-context.json)
|
|
604
|
+
2. Plan state updated (tasks.md, if applicable)
|
|
605
|
+
3. Next steps identified
|
|
606
|
+
|
|
607
|
+
---
|
|
608
|
+
|
|
609
|
+
## Workflow Diagram
|
|
610
|
+
|
|
611
|
+
```
|
|
612
|
+
User Request
|
|
613
|
+
ββ Ambiguous?
|
|
614
|
+
β ββ Yes β Phase 0: Clarification β enriched_prompt
|
|
615
|
+
β ββ No β original_prompt
|
|
616
|
+
β
|
|
617
|
+
β
|
|
618
|
+
Phase 1: Agent Selection (agent_router.py)
|
|
619
|
+
β
|
|
620
|
+
Phase 2: Context Provision (context_provider.py)
|
|
621
|
+
β
|
|
622
|
+
Phase 3: Invoke Agent (Planning)
|
|
623
|
+
β (returns Realization Package)
|
|
624
|
+
β
|
|
625
|
+
Phase 4: Approval Gate (MANDATORY)
|
|
626
|
+
ββ Generate summary (approval_gate.py)
|
|
627
|
+
ββ Present to user
|
|
628
|
+
ββ Ask question (AskUserQuestion)
|
|
629
|
+
ββ Validate response
|
|
630
|
+
β ββ Approved? β Continue
|
|
631
|
+
β ββ Rejected? β HALT
|
|
632
|
+
β
|
|
633
|
+
Phase 5: Realization
|
|
634
|
+
ββ Re-invoke agent
|
|
635
|
+
ββ Persist files
|
|
636
|
+
ββ Git operations
|
|
637
|
+
ββ Live operations
|
|
638
|
+
ββ Verify
|
|
639
|
+
β
|
|
640
|
+
Phase 6: State Update
|
|
641
|
+
ββ Update project-context.json
|
|
642
|
+
ββ Update tasks.md (if applicable)
|
|
643
|
+
β
|
|
644
|
+
Report & Transition
|
|
645
|
+
```
|
|
646
|
+
|
|
647
|
+
---
|
|
648
|
+
|
|
649
|
+
## Common Pitfalls
|
|
650
|
+
|
|
651
|
+
### Pitfall 1: Skipping Phase 0 when needed
|
|
652
|
+
|
|
653
|
+
**Symptom:** Agent invocation fails with "insufficient context" or "ambiguous target"
|
|
654
|
+
|
|
655
|
+
**Cause:** User request was ambiguous (e.g., "revisa el servicio") but orchestrator skipped clarification
|
|
656
|
+
|
|
657
|
+
**Fix:** Lower threshold for ambiguity detection, invoke clarify_engine.py more proactively
|
|
658
|
+
|
|
659
|
+
---
|
|
660
|
+
|
|
661
|
+
### Pitfall 2: Proceeding to Phase 5 without approval
|
|
662
|
+
|
|
663
|
+
**Symptom:** User complaints about unauthorized changes, audit trail violations
|
|
664
|
+
|
|
665
|
+
**Cause:** Orchestrator skipped Phase 4 or proceeded despite `validation["approved"] == False`
|
|
666
|
+
|
|
667
|
+
**Fix:** Enforce Phase 4 with code validation (cannot invoke Phase 5 without approval token)
|
|
668
|
+
|
|
669
|
+
---
|
|
670
|
+
|
|
671
|
+
### Pitfall 3: Not updating SSOT after realization
|
|
672
|
+
|
|
673
|
+
**Symptom:** project-context.json is stale, next agent invocations fail or operate on wrong state
|
|
674
|
+
|
|
675
|
+
**Cause:** Phase 6 was skipped or only partially executed
|
|
676
|
+
|
|
677
|
+
**Fix:** Make Phase 6 part of agent's realization protocol, not orchestrator's post-processing
|
|
678
|
+
|
|
679
|
+
---
|
|
680
|
+
|
|
681
|
+
### Pitfall 4: Using stale context in Phase 2
|
|
682
|
+
|
|
683
|
+
**Symptom:** Agent operates on outdated state (e.g., tries to create service that already exists)
|
|
684
|
+
|
|
685
|
+
**Cause:** project-context.json wasn't updated in previous workflow run
|
|
686
|
+
|
|
687
|
+
**Fix:** Validate project-context.json freshness before invoking context_provider.py
|
|
688
|
+
|
|
689
|
+
---
|
|
690
|
+
|
|
691
|
+
### Pitfall 5: Over-prompting agents in Phase 3
|
|
692
|
+
|
|
693
|
+
**Symptom:** Agents ignore their own protocols, follow orchestrator's ad-hoc instructions
|
|
694
|
+
|
|
695
|
+
**Cause:** Orchestrator added too many instructions in Phase 3 prompt
|
|
696
|
+
|
|
697
|
+
**Fix:** Minimalist prompts only (context + task). Trust agent to follow its own protocol.
|
|
698
|
+
|
|
699
|
+
---
|
|
700
|
+
|
|
701
|
+
## Metrics & Observability
|
|
702
|
+
|
|
703
|
+
### Key Metrics
|
|
704
|
+
|
|
705
|
+
Track in `.claude/logs/workflow-metrics.jsonl`:
|
|
706
|
+
|
|
707
|
+
- **Clarification Rate:** % of requests that trigger Phase 0
|
|
708
|
+
- **Approval Rate:** % of realization packages approved in Phase 4
|
|
709
|
+
- **Routing Accuracy:** % of correct agent selections in Phase 1
|
|
710
|
+
- **Realization Success Rate:** % of Phase 5 executions that verify successfully
|
|
711
|
+
- **SSOT Sync Rate:** % of workflows that complete Phase 6 successfully
|
|
712
|
+
|
|
713
|
+
### Target Thresholds
|
|
714
|
+
|
|
715
|
+
- Clarification Rate: 20-30% (too high = bad UX, too low = ambiguous requests proceeding)
|
|
716
|
+
- Approval Rate: 80-90% (too low = poor planning, too high = rubber-stamping)
|
|
717
|
+
- Routing Accuracy: >95%
|
|
718
|
+
- Realization Success Rate: >90%
|
|
719
|
+
- SSOT Sync Rate: 100% (no exceptions)
|
|
720
|
+
|
|
721
|
+
---
|
|
722
|
+
|
|
723
|
+
## Version History
|
|
724
|
+
|
|
725
|
+
### 2.0.0 (2025-11-07)
|
|
726
|
+
- Extracted from CLAUDE.md monolith
|
|
727
|
+
- Added detailed Phase 0 (Clarification) workflow
|
|
728
|
+
- Clarified Phase 4 (Approval Gate) as MANDATORY
|
|
729
|
+
- Added Phase 6 (State Update) with TaskManager
|
|
730
|
+
- Added pitfalls, metrics, version history
|
|
731
|
+
|
|
732
|
+
### 1.x (Historical)
|
|
733
|
+
- Embedded in CLAUDE.md
|
|
734
|
+
- Basic 2-phase workflow
|
|
735
|
+
- Manual approval (no approval_gate.py)
|