claude-flow-novice 2.15.2 → 2.15.3
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/.claude/hooks/cfn-BACKUP_USAGE.md +243 -243
- package/.claude/hooks/cfn-invoke-security-validation.sh +69 -69
- package/.claude/hooks/cfn-post-edit-cfn-retrospective.sh +78 -78
- package/.claude/hooks/cfn-post-edit.config.json +44 -44
- package/.claude/skills/agent-lifecycle/SKILL.md +60 -0
- package/.claude/skills/agent-lifecycle/execute-lifecycle-hook.sh +573 -0
- package/.claude/skills/agent-lifecycle/simple-audit.sh +31 -0
- package/.claude/skills/cfn-hybrid-routing/check-dependencies.sh +51 -51
- package/.claude/skills/cfn-loop-validation/orchestrate-cfn-loop.sh +252 -252
- package/.claude/skills/cfn-redis-coordination/agent-recovery.sh +74 -74
- package/.claude/skills/cfn-redis-coordination/get-context.sh +112 -112
- package/.claude/skills/cfn-transparency-middleware/middleware-config.sh +28 -28
- package/.claude/skills/cfn-transparency-middleware/performance-benchmark.sh +78 -78
- package/.claude/skills/cfn-transparency-middleware/test-integration.sh +161 -161
- package/.claude/skills/cfn-transparency-middleware/test-transparency-skill.sh +367 -367
- package/.claude/skills/cfn-transparency-middleware/tests/input-validation.sh +92 -92
- package/.claude/skills/cfn-transparency-middleware/wrap-agent.sh +131 -131
- package/claude-assets/hooks/cfn-BACKUP_USAGE.md +243 -243
- package/claude-assets/hooks/cfn-invoke-security-validation.sh +69 -69
- package/claude-assets/hooks/cfn-post-edit-cfn-retrospective.sh +78 -78
- package/claude-assets/hooks/cfn-post-edit.config.json +44 -44
- package/claude-assets/hooks/cfn-post-execution/memory-cleanup.sh +19 -19
- package/claude-assets/hooks/cfn-pre-execution/memory-check.sh +19 -19
- package/claude-assets/skills/agent-lifecycle/execute-lifecycle-hook.sh +572 -572
- package/claude-assets/skills/agent-lifecycle/simple-audit.sh +30 -30
- package/claude-assets/skills/cfn-automatic-memory-persistence/persist-agent-output.sh +48 -48
- package/claude-assets/skills/cfn-automatic-memory-persistence/query-agent-history.sh +34 -34
- package/claude-assets/skills/cfn-deliverable-validation/confidence-calculator.sh +261 -261
- package/claude-assets/skills/cfn-expert-update/update-expert.sh +345 -345
- package/claude-assets/skills/cfn-hybrid-routing/check-dependencies.sh +51 -51
- package/claude-assets/skills/cfn-intervention-detector/detect-intervention.sh +110 -110
- package/claude-assets/skills/cfn-intervention-orchestrator/execute-intervention.sh +58 -58
- package/claude-assets/skills/cfn-loop-validation/orchestrate-cfn-loop.sh +252 -252
- package/claude-assets/skills/cfn-loop2-output-processing/process-validator-output.sh +275 -275
- package/claude-assets/skills/cfn-memory-management/check-memory.sh +159 -159
- package/claude-assets/skills/cfn-memory-management/cleanup-memory.sh +196 -196
- package/claude-assets/skills/cfn-node-heap-sizer/task-mode-heap-limiter.sh +325 -325
- package/claude-assets/skills/cfn-playbook-auto-update/auto-update-playbook.sh +85 -85
- package/claude-assets/skills/cfn-redis-coordination/agent-recovery.sh +74 -74
- package/claude-assets/skills/cfn-redis-coordination/get-context.sh +112 -112
- package/claude-assets/skills/cfn-scope-simplifier/simplify-scope.sh +67 -67
- package/claude-assets/skills/cfn-specialist-injection/recommend-specialist.sh +56 -56
- package/claude-assets/skills/cfn-standardized-error-handling/capture-agent-error.sh +86 -86
- package/claude-assets/skills/cfn-standardized-error-handling/test-error-handling.sh +165 -165
- package/claude-assets/skills/cfn-task-config-init/initialize-config.sh +264 -264
- package/claude-assets/skills/cfn-task-decomposition/task-decomposer.sh +278 -278
- package/claude-assets/skills/cfn-transparency-middleware/middleware-config.sh +28 -28
- package/claude-assets/skills/cfn-transparency-middleware/performance-benchmark.sh +78 -78
- package/claude-assets/skills/cfn-transparency-middleware/test-integration.sh +161 -161
- package/claude-assets/skills/cfn-transparency-middleware/test-transparency-skill.sh +367 -367
- package/claude-assets/skills/cfn-transparency-middleware/tests/input-validation.sh +92 -92
- package/claude-assets/skills/cfn-transparency-middleware/wrap-agent.sh +131 -131
- package/claude-assets/skills/docker-build/SKILL.md +96 -203
- package/claude-assets/skills/docker-build/build.sh +73 -73
- package/claude-assets/skills/integration/agent-handoff.sh +494 -0
- package/claude-assets/skills/integration/file-operations.sh +414 -0
- package/claude-assets/skills/workflow-codification/APPROVAL_WORKFLOW.md +806 -0
- package/claude-assets/skills/workflow-codification/COST_TRACKING.md +637 -0
- package/claude-assets/skills/workflow-codification/EDGE_CASE_TRACKING.md +404 -0
- package/claude-assets/skills/workflow-codification/README_PHASE4.md +457 -0
- package/claude-assets/skills/workflow-codification/SKILL.md +110 -0
- package/claude-assets/skills/workflow-codification/analyze-patterns.sh +899 -0
- package/claude-assets/skills/workflow-codification/approval-workflow.sh +514 -0
- package/claude-assets/skills/workflow-codification/generate-skill-update.sh +525 -0
- package/claude-assets/skills/workflow-codification/review-skill.sh +643 -0
- package/claude-assets/skills/workflow-codification/templates/email-notification.txt +114 -0
- package/claude-assets/skills/workflow-codification/templates/slack-notification.md +85 -0
- package/claude-assets/skills/workflow-codification/test-integration.sh +281 -0
- package/claude-assets/skills/workflow-codification/track-cost-savings.sh +445 -0
- package/claude-assets/skills/workflow-codification/track-edge-case.sh +323 -0
- package/dist/cli/config-manager.js +91 -109
- package/dist/cli/config-manager.js.map +1 -1
- package/dist/integration/DatabaseHandoff.js +507 -0
- package/dist/integration/DatabaseHandoff.js.map +1 -0
- package/dist/integration/StandardAdapter.js +291 -0
- package/dist/integration/StandardAdapter.js.map +1 -0
- package/dist/lib/agent-output-parser.js +518 -0
- package/dist/lib/agent-output-parser.js.map +1 -0
- package/dist/lib/agent-output-validator.js +950 -0
- package/dist/lib/agent-output-validator.js.map +1 -0
- package/dist/lib/artifact-registry.js +443 -0
- package/dist/lib/artifact-registry.js.map +1 -0
- package/dist/lib/config-validator.js +687 -0
- package/dist/lib/config-validator.js.map +1 -0
- package/dist/types/agent-output.js +44 -0
- package/dist/types/agent-output.js.map +1 -0
- package/dist/types/config.js +28 -0
- package/dist/types/config.js.map +1 -0
- package/package.json +2 -1
- package/scripts/artifact-cleanup.sh +392 -0
- package/scripts/deploy-production.sh +355 -355
- package/scripts/docker-playwright-fix.sh +311 -311
- package/scripts/docker-rebuild-all-agents.sh +127 -127
- package/scripts/memory-leak-prevention.sh +305 -305
- package/scripts/migrate-artifacts.sh +563 -0
- package/scripts/migrate-yaml-to-json.sh +465 -0
- package/scripts/run-marketing-tests.sh +42 -42
- package/scripts/update_paths.sh +46 -46
|
@@ -0,0 +1,806 @@
|
|
|
1
|
+
# Approval Workflow Engine - Documentation
|
|
2
|
+
|
|
3
|
+
**Version:** 1.0.0
|
|
4
|
+
**Status:** Production Ready
|
|
5
|
+
**Last Updated:** 2025-11-15
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
|
|
11
|
+
1. [Overview](#overview)
|
|
12
|
+
2. [State Machine Architecture](#state-machine-architecture)
|
|
13
|
+
3. [Components](#components)
|
|
14
|
+
4. [Database Schema](#database-schema)
|
|
15
|
+
5. [Usage Guide](#usage-guide)
|
|
16
|
+
6. [SLA Management](#sla-management)
|
|
17
|
+
7. [Audit Trail](#audit-trail)
|
|
18
|
+
8. [Integration Guide](#integration-guide)
|
|
19
|
+
9. [Troubleshooting](#troubleshooting)
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Overview
|
|
24
|
+
|
|
25
|
+
The Approval Workflow Engine manages the lifecycle of auto-generated skills from detection through deployment, ensuring human expert oversight through a robust state machine with audit trails and SLA tracking.
|
|
26
|
+
|
|
27
|
+
### Key Features
|
|
28
|
+
|
|
29
|
+
- **State Machine:** Enforces valid state transitions with transaction safety
|
|
30
|
+
- **Expert Review:** CLI for approve/reject/correct actions
|
|
31
|
+
- **SLA Tracking:** 48h for high priority, 7 days for medium/low
|
|
32
|
+
- **Audit Logging:** Complete history of all state changes and expert actions
|
|
33
|
+
- **Notifications:** Email and Slack templates for expert alerts
|
|
34
|
+
- **Rollback Support:** Safe rollback to previous states
|
|
35
|
+
- **Concurrent Safety:** PostgreSQL row-level locking prevents race conditions
|
|
36
|
+
|
|
37
|
+
### Business Value
|
|
38
|
+
|
|
39
|
+
- **60-80% cost reduction** for codified workflows
|
|
40
|
+
- **95% faster execution** (scripts vs AI agents)
|
|
41
|
+
- **Expert oversight** maintains quality standards
|
|
42
|
+
- **Complete audit trail** for compliance and debugging
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## State Machine Architecture
|
|
47
|
+
|
|
48
|
+
### States
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
DETECTED → GENERATING → PENDING_REVIEW → {APPROVED, REJECTED, NEEDS_CORRECTION} → DEPLOYED
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
#### State Descriptions
|
|
55
|
+
|
|
56
|
+
| State | Description | Next States |
|
|
57
|
+
|-------|-------------|-------------|
|
|
58
|
+
| **DETECTED** | Workflow pattern detected by analyzer | GENERATING |
|
|
59
|
+
| **GENERATING** | AI agent generating skill code | PENDING_REVIEW, DETECTED (rollback) |
|
|
60
|
+
| **PENDING_REVIEW** | Awaiting expert review | APPROVED, REJECTED, NEEDS_CORRECTION |
|
|
61
|
+
| **NEEDS_CORRECTION** | Expert requested changes | GENERATING, REJECTED |
|
|
62
|
+
| **APPROVED** | Expert approved, ready for deployment | DEPLOYED, REJECTED (rollback) |
|
|
63
|
+
| **REJECTED** | Expert or system rejected | (terminal state) |
|
|
64
|
+
| **DEPLOYED** | Deployed to production | APPROVED (rollback) |
|
|
65
|
+
|
|
66
|
+
### Valid Transitions
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
DETECTED → GENERATING # Pattern detection complete
|
|
70
|
+
GENERATING → PENDING_REVIEW # Skill generation complete
|
|
71
|
+
GENERATING → DETECTED # Generation failed, retry
|
|
72
|
+
PENDING_REVIEW → APPROVED # Expert approved
|
|
73
|
+
PENDING_REVIEW → REJECTED # Expert rejected
|
|
74
|
+
PENDING_REVIEW → NEEDS_CORRECTION # Expert wants changes
|
|
75
|
+
NEEDS_CORRECTION → GENERATING # Re-generate with feedback
|
|
76
|
+
NEEDS_CORRECTION → REJECTED # Give up after multiple corrections
|
|
77
|
+
APPROVED → DEPLOYED # Deploy to production
|
|
78
|
+
APPROVED → REJECTED # Rollback approval (rare)
|
|
79
|
+
DEPLOYED → APPROVED # Rollback deployment
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Concurrency Control
|
|
83
|
+
|
|
84
|
+
The state machine uses PostgreSQL row-level locking to prevent race conditions:
|
|
85
|
+
|
|
86
|
+
```sql
|
|
87
|
+
-- Lock pattern row for update
|
|
88
|
+
SELECT status FROM workflow_patterns WHERE id = 'pattern-id' FOR UPDATE;
|
|
89
|
+
|
|
90
|
+
-- Verify current state matches expected state
|
|
91
|
+
-- Update only if state matches
|
|
92
|
+
-- Commit transaction
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
This ensures that concurrent state transitions are serialized and conflicting updates fail gracefully.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Components
|
|
100
|
+
|
|
101
|
+
### 1. approval-workflow.sh
|
|
102
|
+
|
|
103
|
+
**Purpose:** Core state machine implementation
|
|
104
|
+
|
|
105
|
+
**Commands:**
|
|
106
|
+
- `transition` - Perform state transition with validation
|
|
107
|
+
- `get-state` - Query current state
|
|
108
|
+
- `rollback` - Safe rollback to previous state
|
|
109
|
+
- `history` - View state transition history
|
|
110
|
+
- `init` - Initialize database schema
|
|
111
|
+
|
|
112
|
+
**Features:**
|
|
113
|
+
- Transaction safety (BEGIN/COMMIT/ROLLBACK)
|
|
114
|
+
- Row-level locking for concurrency
|
|
115
|
+
- Validation of state transitions
|
|
116
|
+
- Audit logging for all changes
|
|
117
|
+
- Metadata support for context
|
|
118
|
+
|
|
119
|
+
**Example:**
|
|
120
|
+
```bash
|
|
121
|
+
# Transition skill from PENDING_REVIEW to APPROVED
|
|
122
|
+
./approval-workflow.sh transition \
|
|
123
|
+
--pattern-id "123e4567-e89b-12d3-a456-426614174000" \
|
|
124
|
+
--from-state PENDING_REVIEW \
|
|
125
|
+
--to-state APPROVED \
|
|
126
|
+
--metadata '{"approved_by": "expert@example.com"}'
|
|
127
|
+
|
|
128
|
+
# Rollback deployment due to bug
|
|
129
|
+
./approval-workflow.sh rollback \
|
|
130
|
+
--pattern-id "123e4567-e89b-12d3-a456-426614174000" \
|
|
131
|
+
--to-state APPROVED \
|
|
132
|
+
--reason "Critical bug found in production"
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
### 2. review-skill.sh
|
|
138
|
+
|
|
139
|
+
**Purpose:** Expert review CLI for skill approval workflow
|
|
140
|
+
|
|
141
|
+
**Commands:**
|
|
142
|
+
- `--action approve` - Approve skill for deployment
|
|
143
|
+
- `--action reject` - Reject skill with reason
|
|
144
|
+
- `--action correct` - Request corrections with feedback
|
|
145
|
+
- `--list-pending` - List all pending reviews
|
|
146
|
+
- `--check-sla` - Check SLA compliance status
|
|
147
|
+
- `--init` - Initialize skill_approvals table
|
|
148
|
+
|
|
149
|
+
**Features:**
|
|
150
|
+
- Three-way review actions (approve/reject/correct)
|
|
151
|
+
- Mandatory feedback for reject/correct
|
|
152
|
+
- SLA status tracking
|
|
153
|
+
- Team-based filtering
|
|
154
|
+
- Automatic audit logging
|
|
155
|
+
|
|
156
|
+
**Example:**
|
|
157
|
+
```bash
|
|
158
|
+
# Approve a skill
|
|
159
|
+
./review-skill.sh \
|
|
160
|
+
--skill-id "123e4567-e89b-12d3-a456-426614174000" \
|
|
161
|
+
--action approve \
|
|
162
|
+
--feedback "Code looks good, tests pass"
|
|
163
|
+
|
|
164
|
+
# Reject with reason
|
|
165
|
+
./review-skill.sh \
|
|
166
|
+
--skill-id "123e4567-e89b-12d3-a456-426614174000" \
|
|
167
|
+
--action reject \
|
|
168
|
+
--feedback "Security vulnerability: SQL injection in line 45"
|
|
169
|
+
|
|
170
|
+
# Request corrections
|
|
171
|
+
./review-skill.sh \
|
|
172
|
+
--skill-id "123e4567-e89b-12d3-a456-426614174000" \
|
|
173
|
+
--action correct \
|
|
174
|
+
--feedback "Add input validation for email parameter. Use regex pattern."
|
|
175
|
+
|
|
176
|
+
# List pending reviews for frontend team
|
|
177
|
+
./review-skill.sh --list-pending --team frontend
|
|
178
|
+
|
|
179
|
+
# Check SLA status
|
|
180
|
+
./review-skill.sh --check-sla
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
### 3. Notification Templates
|
|
186
|
+
|
|
187
|
+
#### Email Template (templates/email-notification.txt)
|
|
188
|
+
|
|
189
|
+
**Purpose:** Notify experts of new skills awaiting review
|
|
190
|
+
|
|
191
|
+
**Placeholders:**
|
|
192
|
+
- `{{SKILL_NAME}}` - Skill pattern name
|
|
193
|
+
- `{{PATTERN_ID}}` - UUID of the pattern
|
|
194
|
+
- `{{PRIORITY}}` - high/medium/low
|
|
195
|
+
- `{{PRIMARY_TEAM}}` - Team responsible for review
|
|
196
|
+
- `{{ESTIMATED_SAVINGS}}` - Monthly cost savings estimate
|
|
197
|
+
- `{{OCCURRENCE_COUNT}}` - Number of workflow occurrences
|
|
198
|
+
- `{{TEAMS_AFFECTED}}` - Comma-separated team list
|
|
199
|
+
- `{{CONFIDENCE_SCORE}}` - Pattern detection confidence
|
|
200
|
+
- `{{SIMILARITY_SCORE}}` - Workflow similarity score
|
|
201
|
+
- `{{WORKFLOW_STEPS}}` - Formatted workflow steps
|
|
202
|
+
- `{{SKILL_ID}}` - UUID for review commands
|
|
203
|
+
- `{{TEST_COUNT}}` - Number of test cases
|
|
204
|
+
- `{{EDGE_CASE_COUNT}}` - Number of edge cases
|
|
205
|
+
- `{{SLA_DEADLINE}}` - Review deadline
|
|
206
|
+
- `{{SLA_HOURS}}` - Hours until SLA breach
|
|
207
|
+
|
|
208
|
+
#### Slack Template (templates/slack-notification.md)
|
|
209
|
+
|
|
210
|
+
**Purpose:** Send Slack notifications for skill reviews
|
|
211
|
+
|
|
212
|
+
**Format:** Markdown with emoji support
|
|
213
|
+
|
|
214
|
+
**Additional Placeholders:**
|
|
215
|
+
- `{{PRIORITY_EMOJI}}` - Visual priority indicator (🔴/🟡/🟢)
|
|
216
|
+
- `{{EXPERT_SLACK_HANDLE}}` - Slack @mention for expert
|
|
217
|
+
- `{{WORKFLOW_STEP_N}}` - Individual workflow steps
|
|
218
|
+
- `{{TEAMS_AFFECTED_COUNT}}` - Number of teams affected
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Database Schema
|
|
223
|
+
|
|
224
|
+
### workflow_patterns
|
|
225
|
+
|
|
226
|
+
**Purpose:** Core table for workflow patterns and skill metadata
|
|
227
|
+
|
|
228
|
+
```sql
|
|
229
|
+
CREATE TABLE workflow_patterns (
|
|
230
|
+
id UUID PRIMARY KEY,
|
|
231
|
+
pattern_name VARCHAR(255) NOT NULL,
|
|
232
|
+
workflow_steps JSONB NOT NULL,
|
|
233
|
+
occurrence_count INTEGER NOT NULL,
|
|
234
|
+
teams_affected TEXT[] NOT NULL,
|
|
235
|
+
similarity_score DECIMAL(3,2) NOT NULL,
|
|
236
|
+
deterministic BOOLEAN DEFAULT FALSE,
|
|
237
|
+
confidence_score DECIMAL(3,2) NOT NULL,
|
|
238
|
+
estimated_savings_usd DECIMAL(10,2),
|
|
239
|
+
priority VARCHAR(20),
|
|
240
|
+
created_at TIMESTAMP DEFAULT NOW(),
|
|
241
|
+
updated_at TIMESTAMP DEFAULT NOW(),
|
|
242
|
+
status VARCHAR(50) DEFAULT 'DETECTED'
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
CREATE INDEX idx_pattern_status ON workflow_patterns(status);
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### pattern_state_history
|
|
249
|
+
|
|
250
|
+
**Purpose:** Track all state transitions for audit trail
|
|
251
|
+
|
|
252
|
+
```sql
|
|
253
|
+
CREATE TABLE pattern_state_history (
|
|
254
|
+
id SERIAL PRIMARY KEY,
|
|
255
|
+
pattern_id UUID REFERENCES workflow_patterns(id) ON DELETE CASCADE,
|
|
256
|
+
from_state VARCHAR(50) NOT NULL,
|
|
257
|
+
to_state VARCHAR(50) NOT NULL,
|
|
258
|
+
metadata JSONB DEFAULT '{}',
|
|
259
|
+
timestamp TIMESTAMP DEFAULT NOW()
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
CREATE INDEX idx_pattern_state_history_pattern_id ON pattern_state_history(pattern_id);
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### skill_approvals
|
|
266
|
+
|
|
267
|
+
**Purpose:** Log all expert review actions
|
|
268
|
+
|
|
269
|
+
```sql
|
|
270
|
+
CREATE TABLE skill_approvals (
|
|
271
|
+
id SERIAL PRIMARY KEY,
|
|
272
|
+
skill_id UUID REFERENCES workflow_patterns(id) ON DELETE CASCADE,
|
|
273
|
+
expert_id VARCHAR(255) NOT NULL,
|
|
274
|
+
action VARCHAR(50) NOT NULL,
|
|
275
|
+
feedback TEXT,
|
|
276
|
+
timestamp TIMESTAMP DEFAULT NOW()
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
CREATE INDEX idx_skill_approvals_skill_id ON skill_approvals(skill_id);
|
|
280
|
+
CREATE INDEX idx_skill_approvals_expert_id ON skill_approvals(expert_id);
|
|
281
|
+
CREATE INDEX idx_skill_approvals_timestamp ON skill_approvals(timestamp);
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### workflow_audit_log
|
|
285
|
+
|
|
286
|
+
**Purpose:** General audit log for all workflow events
|
|
287
|
+
|
|
288
|
+
```sql
|
|
289
|
+
CREATE TABLE workflow_audit_log (
|
|
290
|
+
id SERIAL PRIMARY KEY,
|
|
291
|
+
pattern_id UUID,
|
|
292
|
+
event_type VARCHAR(100) NOT NULL,
|
|
293
|
+
description TEXT,
|
|
294
|
+
metadata JSONB DEFAULT '{}',
|
|
295
|
+
timestamp TIMESTAMP DEFAULT NOW()
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
CREATE INDEX idx_audit_log_pattern_id ON workflow_audit_log(pattern_id);
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## Usage Guide
|
|
304
|
+
|
|
305
|
+
### Setup
|
|
306
|
+
|
|
307
|
+
#### 1. Configure Database Connection
|
|
308
|
+
|
|
309
|
+
Create `.env` file in project root:
|
|
310
|
+
|
|
311
|
+
```bash
|
|
312
|
+
# PostgreSQL Configuration
|
|
313
|
+
CFN_DB_HOST=localhost
|
|
314
|
+
CFN_DB_PORT=5432
|
|
315
|
+
CFN_DB_NAME=cfn_workflow
|
|
316
|
+
CFN_DB_USER=postgres
|
|
317
|
+
CFN_DB_PASSWORD=your_secure_password
|
|
318
|
+
|
|
319
|
+
# Expert Configuration
|
|
320
|
+
CFN_EXPERT_ID=$(whoami)
|
|
321
|
+
CFN_EXPERT_EMAIL=expert@example.com
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
#### 2. Initialize Database Schema
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
# Initialize workflow_patterns and related tables
|
|
328
|
+
./approval-workflow.sh init
|
|
329
|
+
|
|
330
|
+
# Initialize skill_approvals table
|
|
331
|
+
./review-skill.sh --init
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
#### 3. Verify Setup
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
# Check database connection
|
|
338
|
+
psql -h localhost -U postgres -d cfn_workflow -c "SELECT COUNT(*) FROM workflow_patterns;"
|
|
339
|
+
|
|
340
|
+
# Verify schema
|
|
341
|
+
psql -h localhost -U postgres -d cfn_workflow -c "\dt"
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
### Workflow Example
|
|
347
|
+
|
|
348
|
+
#### Scenario: Auto-generated skill needs review
|
|
349
|
+
|
|
350
|
+
**Step 1: Pattern Detected**
|
|
351
|
+
```bash
|
|
352
|
+
# System detects pattern and creates record
|
|
353
|
+
# Status: DETECTED
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
**Step 2: Skill Generation**
|
|
357
|
+
```bash
|
|
358
|
+
# Transition to GENERATING
|
|
359
|
+
./approval-workflow.sh transition \
|
|
360
|
+
--pattern-id "abc123..." \
|
|
361
|
+
--from-state DETECTED \
|
|
362
|
+
--to-state GENERATING
|
|
363
|
+
|
|
364
|
+
# AI agent generates skill...
|
|
365
|
+
|
|
366
|
+
# Transition to PENDING_REVIEW
|
|
367
|
+
./approval-workflow.sh transition \
|
|
368
|
+
--pattern-id "abc123..." \
|
|
369
|
+
--from-state GENERATING \
|
|
370
|
+
--to-state PENDING_REVIEW
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
**Step 3: Expert Notification**
|
|
374
|
+
```bash
|
|
375
|
+
# System sends email using templates/email-notification.txt
|
|
376
|
+
# System sends Slack message using templates/slack-notification.md
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
**Step 4: Expert Review**
|
|
380
|
+
```bash
|
|
381
|
+
# Expert lists pending reviews
|
|
382
|
+
./review-skill.sh --list-pending
|
|
383
|
+
|
|
384
|
+
# Expert reviews code, runs tests
|
|
385
|
+
cd .claude/skills/staging/codified-abc123/
|
|
386
|
+
./test.sh
|
|
387
|
+
|
|
388
|
+
# Expert approves
|
|
389
|
+
./review-skill.sh \
|
|
390
|
+
--skill-id "abc123..." \
|
|
391
|
+
--action approve \
|
|
392
|
+
--feedback "All tests pass, code looks secure"
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
**Step 5: Deployment**
|
|
396
|
+
```bash
|
|
397
|
+
# Transition to DEPLOYED
|
|
398
|
+
./approval-workflow.sh transition \
|
|
399
|
+
--pattern-id "abc123..." \
|
|
400
|
+
--from-state APPROVED \
|
|
401
|
+
--to-state DEPLOYED
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
---
|
|
405
|
+
|
|
406
|
+
### Rollback Example
|
|
407
|
+
|
|
408
|
+
#### Scenario: Bug found in production skill
|
|
409
|
+
|
|
410
|
+
```bash
|
|
411
|
+
# Step 1: Rollback deployment
|
|
412
|
+
./approval-workflow.sh rollback \
|
|
413
|
+
--pattern-id "abc123..." \
|
|
414
|
+
--to-state APPROVED \
|
|
415
|
+
--reason "Critical bug: fails on empty input"
|
|
416
|
+
|
|
417
|
+
# Step 2: Request correction
|
|
418
|
+
./review-skill.sh \
|
|
419
|
+
--skill-id "abc123..." \
|
|
420
|
+
--action correct \
|
|
421
|
+
--feedback "Add null check before processing input parameter"
|
|
422
|
+
|
|
423
|
+
# Step 3: Re-generate skill
|
|
424
|
+
./approval-workflow.sh transition \
|
|
425
|
+
--pattern-id "abc123..." \
|
|
426
|
+
--from-state NEEDS_CORRECTION \
|
|
427
|
+
--to-state GENERATING
|
|
428
|
+
|
|
429
|
+
# (AI regenerates with feedback)
|
|
430
|
+
|
|
431
|
+
# Step 4: Re-review and re-deploy
|
|
432
|
+
./approval-workflow.sh transition \
|
|
433
|
+
--pattern-id "abc123..." \
|
|
434
|
+
--from-state GENERATING \
|
|
435
|
+
--to-state PENDING_REVIEW
|
|
436
|
+
|
|
437
|
+
./review-skill.sh \
|
|
438
|
+
--skill-id "abc123..." \
|
|
439
|
+
--action approve
|
|
440
|
+
|
|
441
|
+
./approval-workflow.sh transition \
|
|
442
|
+
--pattern-id "abc123..." \
|
|
443
|
+
--from-state APPROVED \
|
|
444
|
+
--to-state DEPLOYED
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
---
|
|
448
|
+
|
|
449
|
+
## SLA Management
|
|
450
|
+
|
|
451
|
+
### SLA Thresholds
|
|
452
|
+
|
|
453
|
+
| Priority | SLA | Description |
|
|
454
|
+
|----------|-----|-------------|
|
|
455
|
+
| High | 48 hours | Critical workflows, high savings potential |
|
|
456
|
+
| Medium | 7 days | Standard workflows, moderate savings |
|
|
457
|
+
| Low | 7 days | Nice-to-have workflows, low savings |
|
|
458
|
+
|
|
459
|
+
### SLA Tracking
|
|
460
|
+
|
|
461
|
+
```bash
|
|
462
|
+
# Check current SLA status
|
|
463
|
+
./review-skill.sh --check-sla
|
|
464
|
+
|
|
465
|
+
# Example output:
|
|
466
|
+
# High Priority Breaches (>48h): 2
|
|
467
|
+
# Medium/Low Priority Breaches (>7d): 1
|
|
468
|
+
# Total Pending Reviews: 15
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
### SLA Breach Handling
|
|
472
|
+
|
|
473
|
+
1. **Automated Alerts:** System sends reminder emails at 75% of SLA
|
|
474
|
+
2. **Escalation:** Product Owner notified at 100% SLA breach
|
|
475
|
+
3. **Metrics:** SLA compliance tracked in dashboard
|
|
476
|
+
|
|
477
|
+
### Monitoring Query
|
|
478
|
+
|
|
479
|
+
```sql
|
|
480
|
+
SELECT
|
|
481
|
+
wp.id,
|
|
482
|
+
wp.pattern_name,
|
|
483
|
+
wp.priority,
|
|
484
|
+
ROUND(EXTRACT(EPOCH FROM (NOW() - wp.created_at))/3600, 1) as hours_pending,
|
|
485
|
+
CASE
|
|
486
|
+
WHEN wp.priority = 'high' AND EXTRACT(EPOCH FROM (NOW() - wp.created_at))/3600 > 48 THEN 'BREACH'
|
|
487
|
+
WHEN wp.priority IN ('medium', 'low') AND EXTRACT(EPOCH FROM (NOW() - wp.created_at))/3600 > 168 THEN 'BREACH'
|
|
488
|
+
ELSE 'OK'
|
|
489
|
+
END as sla_status
|
|
490
|
+
FROM workflow_patterns wp
|
|
491
|
+
WHERE wp.status IN ('PENDING_REVIEW', 'NEEDS_CORRECTION')
|
|
492
|
+
ORDER BY hours_pending DESC;
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
---
|
|
496
|
+
|
|
497
|
+
## Audit Trail
|
|
498
|
+
|
|
499
|
+
### Complete History Tracking
|
|
500
|
+
|
|
501
|
+
Every action in the approval workflow is logged:
|
|
502
|
+
|
|
503
|
+
1. **State Transitions:** `pattern_state_history` table
|
|
504
|
+
2. **Expert Actions:** `skill_approvals` table
|
|
505
|
+
3. **System Events:** `workflow_audit_log` table
|
|
506
|
+
|
|
507
|
+
### Querying Audit Trail
|
|
508
|
+
|
|
509
|
+
#### Get full history for a skill
|
|
510
|
+
```sql
|
|
511
|
+
SELECT
|
|
512
|
+
psh.from_state,
|
|
513
|
+
psh.to_state,
|
|
514
|
+
psh.timestamp,
|
|
515
|
+
psh.metadata
|
|
516
|
+
FROM pattern_state_history psh
|
|
517
|
+
WHERE psh.pattern_id = 'abc123...'
|
|
518
|
+
ORDER BY psh.timestamp ASC;
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
#### Get expert actions for a skill
|
|
522
|
+
```sql
|
|
523
|
+
SELECT
|
|
524
|
+
sa.expert_id,
|
|
525
|
+
sa.action,
|
|
526
|
+
sa.feedback,
|
|
527
|
+
sa.timestamp
|
|
528
|
+
FROM skill_approvals sa
|
|
529
|
+
WHERE sa.skill_id = 'abc123...'
|
|
530
|
+
ORDER BY sa.timestamp ASC;
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
#### Get all audit events for a skill
|
|
534
|
+
```sql
|
|
535
|
+
SELECT
|
|
536
|
+
wal.event_type,
|
|
537
|
+
wal.description,
|
|
538
|
+
wal.metadata,
|
|
539
|
+
wal.timestamp
|
|
540
|
+
FROM workflow_audit_log wal
|
|
541
|
+
WHERE wal.pattern_id = 'abc123...'
|
|
542
|
+
ORDER BY wal.timestamp ASC;
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
### Compliance Reports
|
|
546
|
+
|
|
547
|
+
Generate compliance reports for audits:
|
|
548
|
+
|
|
549
|
+
```bash
|
|
550
|
+
# Export audit trail for date range
|
|
551
|
+
psql -h localhost -U postgres -d cfn_workflow -c "
|
|
552
|
+
SELECT
|
|
553
|
+
wp.pattern_name,
|
|
554
|
+
sa.expert_id,
|
|
555
|
+
sa.action,
|
|
556
|
+
sa.feedback,
|
|
557
|
+
sa.timestamp
|
|
558
|
+
FROM skill_approvals sa
|
|
559
|
+
JOIN workflow_patterns wp ON wp.id = sa.skill_id
|
|
560
|
+
WHERE sa.timestamp BETWEEN '2025-01-01' AND '2025-12-31'
|
|
561
|
+
ORDER BY sa.timestamp DESC;
|
|
562
|
+
" -o audit_report_2025.csv -A -F ','
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
---
|
|
566
|
+
|
|
567
|
+
## Integration Guide
|
|
568
|
+
|
|
569
|
+
### Email Integration
|
|
570
|
+
|
|
571
|
+
**Setup:**
|
|
572
|
+
1. Configure SMTP server in `.env`
|
|
573
|
+
2. Update `send_approval_notification()` in `review-skill.sh`
|
|
574
|
+
3. Replace placeholders in `templates/email-notification.txt`
|
|
575
|
+
|
|
576
|
+
**Example Integration (using sendmail):**
|
|
577
|
+
```bash
|
|
578
|
+
send_email() {
|
|
579
|
+
local to="$1"
|
|
580
|
+
local subject="$2"
|
|
581
|
+
local body="$3"
|
|
582
|
+
|
|
583
|
+
echo -e "Subject: ${subject}\n\n${body}" | sendmail "$to"
|
|
584
|
+
}
|
|
585
|
+
```
|
|
586
|
+
|
|
587
|
+
### Slack Integration
|
|
588
|
+
|
|
589
|
+
**Setup:**
|
|
590
|
+
1. Create Slack webhook URL
|
|
591
|
+
2. Update `send_approval_notification()` in `review-skill.sh`
|
|
592
|
+
3. Format message using `templates/slack-notification.md`
|
|
593
|
+
|
|
594
|
+
**Example Integration (using curl):**
|
|
595
|
+
```bash
|
|
596
|
+
send_slack() {
|
|
597
|
+
local webhook_url="$SLACK_WEBHOOK_URL"
|
|
598
|
+
local message="$1"
|
|
599
|
+
|
|
600
|
+
curl -X POST "$webhook_url" \
|
|
601
|
+
-H 'Content-Type: application/json' \
|
|
602
|
+
-d "{\"text\": \"${message}\"}"
|
|
603
|
+
}
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
### CI/CD Integration
|
|
607
|
+
|
|
608
|
+
**GitHub Actions Example:**
|
|
609
|
+
```yaml
|
|
610
|
+
name: Skill Approval Workflow
|
|
611
|
+
|
|
612
|
+
on:
|
|
613
|
+
schedule:
|
|
614
|
+
- cron: '0 */6 * * *' # Check every 6 hours
|
|
615
|
+
|
|
616
|
+
jobs:
|
|
617
|
+
check-sla:
|
|
618
|
+
runs-on: ubuntu-latest
|
|
619
|
+
steps:
|
|
620
|
+
- uses: actions/checkout@v2
|
|
621
|
+
- name: Check SLA Status
|
|
622
|
+
run: |
|
|
623
|
+
./.claude/skills/workflow-codification/review-skill.sh --check-sla
|
|
624
|
+
if [ $? -ne 0 ]; then
|
|
625
|
+
echo "SLA breaches detected!"
|
|
626
|
+
exit 1
|
|
627
|
+
fi
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
---
|
|
631
|
+
|
|
632
|
+
## Troubleshooting
|
|
633
|
+
|
|
634
|
+
### Common Issues
|
|
635
|
+
|
|
636
|
+
#### 1. Database Connection Failed
|
|
637
|
+
|
|
638
|
+
**Symptom:**
|
|
639
|
+
```
|
|
640
|
+
ERROR: Database connection failed
|
|
641
|
+
```
|
|
642
|
+
|
|
643
|
+
**Solution:**
|
|
644
|
+
```bash
|
|
645
|
+
# Verify .env configuration
|
|
646
|
+
cat .env | grep CFN_DB_
|
|
647
|
+
|
|
648
|
+
# Test connection
|
|
649
|
+
psql -h $CFN_DB_HOST -p $CFN_DB_PORT -U $CFN_DB_USER -d $CFN_DB_NAME -c "SELECT 1;"
|
|
650
|
+
|
|
651
|
+
# Check PostgreSQL is running
|
|
652
|
+
systemctl status postgresql
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
#### 2. Invalid State Transition
|
|
656
|
+
|
|
657
|
+
**Symptom:**
|
|
658
|
+
```
|
|
659
|
+
ERROR: Invalid state transition: PENDING_REVIEW → DEPLOYED. Allowed transitions: APPROVED,REJECTED,NEEDS_CORRECTION
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
**Solution:**
|
|
663
|
+
- Cannot skip states in the workflow
|
|
664
|
+
- Must transition through intermediate states
|
|
665
|
+
- Use `get-state` to verify current state
|
|
666
|
+
- Example: PENDING_REVIEW → APPROVED → DEPLOYED
|
|
667
|
+
|
|
668
|
+
#### 3. SLA Breach Alert
|
|
669
|
+
|
|
670
|
+
**Symptom:**
|
|
671
|
+
```
|
|
672
|
+
⚠ SLA breaches detected! Please review pending skills urgently.
|
|
673
|
+
High Priority Breaches (>48h): 3
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
**Solution:**
|
|
677
|
+
```bash
|
|
678
|
+
# List pending reviews by priority
|
|
679
|
+
./review-skill.sh --list-pending
|
|
680
|
+
|
|
681
|
+
# Prioritize high-priority reviews
|
|
682
|
+
# Escalate to Product Owner if necessary
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
#### 4. Concurrent Modification Error
|
|
686
|
+
|
|
687
|
+
**Symptom:**
|
|
688
|
+
```
|
|
689
|
+
ERROR: State mismatch: expected PENDING_REVIEW, got APPROVED
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
**Solution:**
|
|
693
|
+
- Another expert already reviewed the skill
|
|
694
|
+
- Check state history: `./approval-workflow.sh history --pattern-id "abc123..."`
|
|
695
|
+
- Verify current state before retrying
|
|
696
|
+
|
|
697
|
+
---
|
|
698
|
+
|
|
699
|
+
## Best Practices
|
|
700
|
+
|
|
701
|
+
### For Experts
|
|
702
|
+
|
|
703
|
+
1. **Review Code Thoroughly:**
|
|
704
|
+
- Check for security vulnerabilities
|
|
705
|
+
- Verify input validation
|
|
706
|
+
- Test edge cases
|
|
707
|
+
- Run shellcheck validation
|
|
708
|
+
|
|
709
|
+
2. **Provide Clear Feedback:**
|
|
710
|
+
- Be specific about what needs correction
|
|
711
|
+
- Reference line numbers when applicable
|
|
712
|
+
- Suggest solutions, not just problems
|
|
713
|
+
|
|
714
|
+
3. **Meet SLA Deadlines:**
|
|
715
|
+
- Check pending reviews daily
|
|
716
|
+
- Prioritize high-priority skills
|
|
717
|
+
- Escalate blockers early
|
|
718
|
+
|
|
719
|
+
4. **Use Meaningful Approval Comments:**
|
|
720
|
+
- Document why you approved/rejected
|
|
721
|
+
- Note any concerns for future reference
|
|
722
|
+
- Suggest improvements for next iteration
|
|
723
|
+
|
|
724
|
+
### For System Administrators
|
|
725
|
+
|
|
726
|
+
1. **Monitor SLA Compliance:**
|
|
727
|
+
- Run `--check-sla` daily
|
|
728
|
+
- Set up automated alerts
|
|
729
|
+
- Track trends over time
|
|
730
|
+
|
|
731
|
+
2. **Review Audit Logs:**
|
|
732
|
+
- Weekly audit of expert actions
|
|
733
|
+
- Identify patterns in rejections
|
|
734
|
+
- Improve skill generation based on feedback
|
|
735
|
+
|
|
736
|
+
3. **Backup Database:**
|
|
737
|
+
- Daily backups of workflow database
|
|
738
|
+
- Test restore procedures
|
|
739
|
+
- Retain audit trail for compliance
|
|
740
|
+
|
|
741
|
+
4. **Optimize Performance:**
|
|
742
|
+
- Monitor database query performance
|
|
743
|
+
- Add indexes as needed
|
|
744
|
+
- Archive old patterns (>90 days)
|
|
745
|
+
|
|
746
|
+
---
|
|
747
|
+
|
|
748
|
+
## Metrics and KPIs
|
|
749
|
+
|
|
750
|
+
### Success Metrics
|
|
751
|
+
|
|
752
|
+
- **Approval Rate:** % of skills approved on first review
|
|
753
|
+
- **SLA Compliance:** % of reviews completed within SLA
|
|
754
|
+
- **Cost Savings:** Monthly savings from deployed skills
|
|
755
|
+
- **Cycle Time:** Average time from DETECTED to DEPLOYED
|
|
756
|
+
- **Correction Rate:** % of skills requiring corrections
|
|
757
|
+
|
|
758
|
+
### Monitoring Queries
|
|
759
|
+
|
|
760
|
+
```sql
|
|
761
|
+
-- Approval rate (last 30 days)
|
|
762
|
+
SELECT
|
|
763
|
+
COUNT(*) FILTER (WHERE action = 'approve') * 100.0 / COUNT(*) as approval_rate
|
|
764
|
+
FROM skill_approvals
|
|
765
|
+
WHERE timestamp > NOW() - INTERVAL '30 days';
|
|
766
|
+
|
|
767
|
+
-- SLA compliance (last 30 days)
|
|
768
|
+
SELECT
|
|
769
|
+
COUNT(*) FILTER (WHERE
|
|
770
|
+
(priority = 'high' AND EXTRACT(EPOCH FROM (completed_at - created_at))/3600 <= 48) OR
|
|
771
|
+
(priority IN ('medium', 'low') AND EXTRACT(EPOCH FROM (completed_at - created_at))/3600 <= 168)
|
|
772
|
+
) * 100.0 / COUNT(*) as sla_compliance
|
|
773
|
+
FROM workflow_patterns
|
|
774
|
+
WHERE created_at > NOW() - INTERVAL '30 days' AND status IN ('APPROVED', 'DEPLOYED');
|
|
775
|
+
|
|
776
|
+
-- Total cost savings
|
|
777
|
+
SELECT
|
|
778
|
+
SUM(estimated_savings_usd) as total_monthly_savings
|
|
779
|
+
FROM workflow_patterns
|
|
780
|
+
WHERE status = 'DEPLOYED';
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
---
|
|
784
|
+
|
|
785
|
+
## Version History
|
|
786
|
+
|
|
787
|
+
- **1.0.0** (2025-11-15): Initial release
|
|
788
|
+
- State machine implementation
|
|
789
|
+
- Expert review CLI
|
|
790
|
+
- Email and Slack templates
|
|
791
|
+
- Complete audit trail
|
|
792
|
+
- SLA tracking
|
|
793
|
+
|
|
794
|
+
---
|
|
795
|
+
|
|
796
|
+
## Support
|
|
797
|
+
|
|
798
|
+
For issues or questions:
|
|
799
|
+
- **Documentation:** This file
|
|
800
|
+
- **Bug Reports:** Create issue in project repository
|
|
801
|
+
- **Feature Requests:** Submit via project backlog
|
|
802
|
+
- **Emergency:** Contact CFN System Administrator
|
|
803
|
+
|
|
804
|
+
---
|
|
805
|
+
|
|
806
|
+
**End of Documentation**
|