claude-flow-novice 2.15.1 → 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.
Files changed (107) hide show
  1. package/.claude/cfn-extras/agents/google-sheets-specialist.md +614 -0
  2. package/.claude/commands/cfn/create-handoff.md +224 -0
  3. package/.claude/hooks/cfn-BACKUP_USAGE.md +243 -243
  4. package/.claude/hooks/cfn-invoke-security-validation.sh +69 -69
  5. package/.claude/hooks/cfn-post-edit-cfn-retrospective.sh +78 -78
  6. package/.claude/hooks/cfn-post-edit.config.json +44 -44
  7. package/.claude/skills/agent-lifecycle/SKILL.md +60 -0
  8. package/.claude/skills/agent-lifecycle/execute-lifecycle-hook.sh +573 -0
  9. package/.claude/skills/agent-lifecycle/simple-audit.sh +31 -0
  10. package/.claude/skills/cfn-hybrid-routing/check-dependencies.sh +51 -51
  11. package/.claude/skills/cfn-loop-validation/orchestrate-cfn-loop.sh +252 -252
  12. package/.claude/skills/cfn-redis-coordination/agent-recovery.sh +74 -74
  13. package/.claude/skills/cfn-redis-coordination/get-context.sh +112 -112
  14. package/.claude/skills/cfn-transparency-middleware/middleware-config.sh +28 -28
  15. package/.claude/skills/cfn-transparency-middleware/performance-benchmark.sh +78 -78
  16. package/.claude/skills/cfn-transparency-middleware/test-integration.sh +161 -161
  17. package/.claude/skills/cfn-transparency-middleware/test-transparency-skill.sh +367 -367
  18. package/.claude/skills/cfn-transparency-middleware/tests/input-validation.sh +92 -92
  19. package/.claude/skills/cfn-transparency-middleware/wrap-agent.sh +131 -131
  20. package/claude-assets/agents/cfn-dev-team/coordinators/handoff-coordinator.md +662 -0
  21. package/claude-assets/agents/cfn-dev-team/dev-ops/docker-specialist.md +29 -0
  22. package/claude-assets/cfn-extras/agents/google-sheets-specialist.md +614 -0
  23. package/claude-assets/commands/cfn/create-handoff.md +224 -0
  24. package/claude-assets/hooks/cfn-BACKUP_USAGE.md +243 -243
  25. package/claude-assets/hooks/cfn-invoke-security-validation.sh +69 -69
  26. package/claude-assets/hooks/cfn-post-edit-cfn-retrospective.sh +78 -78
  27. package/claude-assets/hooks/cfn-post-edit.config.json +44 -44
  28. package/claude-assets/hooks/cfn-post-execution/memory-cleanup.sh +19 -19
  29. package/claude-assets/hooks/cfn-pre-execution/memory-check.sh +19 -19
  30. package/claude-assets/skills/agent-lifecycle/execute-lifecycle-hook.sh +572 -572
  31. package/claude-assets/skills/agent-lifecycle/simple-audit.sh +30 -30
  32. package/claude-assets/skills/cfn-automatic-memory-persistence/persist-agent-output.sh +48 -48
  33. package/claude-assets/skills/cfn-automatic-memory-persistence/query-agent-history.sh +34 -34
  34. package/claude-assets/skills/cfn-deliverable-validation/confidence-calculator.sh +261 -261
  35. package/claude-assets/skills/cfn-expert-update/update-expert.sh +345 -345
  36. package/claude-assets/skills/cfn-hybrid-routing/check-dependencies.sh +51 -51
  37. package/claude-assets/skills/cfn-intervention-detector/detect-intervention.sh +110 -110
  38. package/claude-assets/skills/cfn-intervention-orchestrator/execute-intervention.sh +58 -58
  39. package/claude-assets/skills/cfn-loop-validation/orchestrate-cfn-loop.sh +252 -252
  40. package/claude-assets/skills/cfn-loop2-output-processing/process-validator-output.sh +275 -275
  41. package/claude-assets/skills/cfn-memory-management/check-memory.sh +159 -159
  42. package/claude-assets/skills/cfn-memory-management/cleanup-memory.sh +196 -196
  43. package/claude-assets/skills/cfn-node-heap-sizer/task-mode-heap-limiter.sh +325 -325
  44. package/claude-assets/skills/cfn-playbook-auto-update/auto-update-playbook.sh +85 -85
  45. package/claude-assets/skills/cfn-redis-coordination/agent-recovery.sh +74 -74
  46. package/claude-assets/skills/cfn-redis-coordination/get-context.sh +112 -112
  47. package/claude-assets/skills/cfn-scope-simplifier/simplify-scope.sh +67 -67
  48. package/claude-assets/skills/cfn-specialist-injection/recommend-specialist.sh +56 -56
  49. package/claude-assets/skills/cfn-standardized-error-handling/capture-agent-error.sh +86 -86
  50. package/claude-assets/skills/cfn-standardized-error-handling/test-error-handling.sh +165 -165
  51. package/claude-assets/skills/cfn-task-config-init/initialize-config.sh +264 -264
  52. package/claude-assets/skills/cfn-task-decomposition/task-decomposer.sh +278 -278
  53. package/claude-assets/skills/cfn-transparency-middleware/middleware-config.sh +28 -28
  54. package/claude-assets/skills/cfn-transparency-middleware/performance-benchmark.sh +78 -78
  55. package/claude-assets/skills/cfn-transparency-middleware/test-integration.sh +161 -161
  56. package/claude-assets/skills/cfn-transparency-middleware/test-transparency-skill.sh +367 -367
  57. package/claude-assets/skills/cfn-transparency-middleware/tests/input-validation.sh +92 -92
  58. package/claude-assets/skills/cfn-transparency-middleware/wrap-agent.sh +131 -131
  59. package/claude-assets/skills/docker-build/SKILL.md +96 -203
  60. package/claude-assets/skills/docker-build/build.sh +73 -73
  61. package/claude-assets/skills/integration/agent-handoff.sh +494 -0
  62. package/claude-assets/skills/integration/file-operations.sh +414 -0
  63. package/claude-assets/skills/workflow-codification/APPROVAL_WORKFLOW.md +806 -0
  64. package/claude-assets/skills/workflow-codification/COST_TRACKING.md +637 -0
  65. package/claude-assets/skills/workflow-codification/EDGE_CASE_TRACKING.md +404 -0
  66. package/claude-assets/skills/workflow-codification/README_PHASE4.md +457 -0
  67. package/claude-assets/skills/workflow-codification/SKILL.md +110 -0
  68. package/claude-assets/skills/workflow-codification/analyze-patterns.sh +899 -0
  69. package/claude-assets/skills/workflow-codification/approval-workflow.sh +514 -0
  70. package/claude-assets/skills/workflow-codification/generate-skill-update.sh +525 -0
  71. package/claude-assets/skills/workflow-codification/review-skill.sh +643 -0
  72. package/claude-assets/skills/workflow-codification/templates/email-notification.txt +114 -0
  73. package/claude-assets/skills/workflow-codification/templates/slack-notification.md +85 -0
  74. package/claude-assets/skills/workflow-codification/test-integration.sh +281 -0
  75. package/claude-assets/skills/workflow-codification/track-cost-savings.sh +445 -0
  76. package/claude-assets/skills/workflow-codification/track-edge-case.sh +323 -0
  77. package/dist/agents/agent-loader.js +165 -146
  78. package/dist/agents/agent-loader.js.map +1 -1
  79. package/dist/cli/config-manager.js +91 -109
  80. package/dist/cli/config-manager.js.map +1 -1
  81. package/dist/integration/DatabaseHandoff.js +507 -0
  82. package/dist/integration/DatabaseHandoff.js.map +1 -0
  83. package/dist/integration/StandardAdapter.js +291 -0
  84. package/dist/integration/StandardAdapter.js.map +1 -0
  85. package/dist/lib/agent-output-parser.js +518 -0
  86. package/dist/lib/agent-output-parser.js.map +1 -0
  87. package/dist/lib/agent-output-validator.js +950 -0
  88. package/dist/lib/agent-output-validator.js.map +1 -0
  89. package/dist/lib/artifact-registry.js +443 -0
  90. package/dist/lib/artifact-registry.js.map +1 -0
  91. package/dist/lib/config-validator.js +687 -0
  92. package/dist/lib/config-validator.js.map +1 -0
  93. package/dist/types/agent-output.js +44 -0
  94. package/dist/types/agent-output.js.map +1 -0
  95. package/dist/types/config.js +28 -0
  96. package/dist/types/config.js.map +1 -0
  97. package/package.json +2 -1
  98. package/scripts/artifact-cleanup.sh +392 -0
  99. package/scripts/build-linux.sh +78 -0
  100. package/scripts/deploy-production.sh +355 -355
  101. package/scripts/docker-playwright-fix.sh +311 -311
  102. package/scripts/docker-rebuild-all-agents.sh +127 -127
  103. package/scripts/memory-leak-prevention.sh +305 -305
  104. package/scripts/migrate-artifacts.sh +563 -0
  105. package/scripts/migrate-yaml-to-json.sh +465 -0
  106. package/scripts/run-marketing-tests.sh +42 -42
  107. package/scripts/update_paths.sh +46 -46
@@ -0,0 +1,514 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # approval-workflow.sh - State Machine for Workflow Codification Approval Process
4
+ #
5
+ # States: DETECTED → GENERATING → PENDING_REVIEW → APPROVED/REJECTED/NEEDS_CORRECTION → DEPLOYED
6
+ #
7
+ # Usage:
8
+ # ./approval-workflow.sh transition --pattern-id UUID --from-state STATE --to-state STATE
9
+ # ./approval-workflow.sh get-state --pattern-id UUID
10
+ # ./approval-workflow.sh rollback --pattern-id UUID --to-state STATE
11
+ #
12
+
13
+ set -euo pipefail
14
+
15
+ # Configuration
16
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
17
+ PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../../.." && pwd)"
18
+
19
+ # PostgreSQL connection (read from .env or use defaults)
20
+ if [ -f "${PROJECT_ROOT}/.env" ]; then
21
+ # shellcheck source=/dev/null
22
+ source "${PROJECT_ROOT}/.env"
23
+ fi
24
+
25
+ DB_HOST="${CFN_DB_HOST:-localhost}"
26
+ DB_PORT="${CFN_DB_PORT:-5432}"
27
+ DB_NAME="${CFN_DB_NAME:-cfn_workflow}"
28
+ DB_USER="${CFN_DB_USER:-postgres}"
29
+ DB_PASSWORD="${CFN_DB_PASSWORD:-}"
30
+
31
+ # Valid state transitions
32
+ declare -A VALID_TRANSITIONS=(
33
+ ["DETECTED"]="GENERATING"
34
+ ["GENERATING"]="PENDING_REVIEW,DETECTED" # Can rollback to DETECTED on failure
35
+ ["PENDING_REVIEW"]="APPROVED,REJECTED,NEEDS_CORRECTION"
36
+ ["NEEDS_CORRECTION"]="GENERATING,REJECTED" # Re-generate or give up
37
+ ["APPROVED"]="DEPLOYED,REJECTED" # Can rollback approval
38
+ ["DEPLOYED"]="APPROVED" # Can rollback deployment
39
+ )
40
+
41
+ # Color codes for output
42
+ RED='\033[0;31m'
43
+ GREEN='\033[0;32m'
44
+ YELLOW='\033[1;33m'
45
+ BLUE='\033[0;34m'
46
+ NC='\033[0m' # No Color
47
+
48
+ #######################################
49
+ # Print error message and exit
50
+ # Arguments:
51
+ # $1 - Error message
52
+ #######################################
53
+ error_exit() {
54
+ echo -e "${RED}ERROR: $1${NC}" >&2
55
+ exit 1
56
+ }
57
+
58
+ #######################################
59
+ # Print success message
60
+ # Arguments:
61
+ # $1 - Success message
62
+ #######################################
63
+ success_msg() {
64
+ echo -e "${GREEN}✓ $1${NC}"
65
+ }
66
+
67
+ #######################################
68
+ # Print warning message
69
+ # Arguments:
70
+ # $1 - Warning message
71
+ #######################################
72
+ warn_msg() {
73
+ echo -e "${YELLOW}⚠ $1${NC}"
74
+ }
75
+
76
+ #######################################
77
+ # Print info message
78
+ # Arguments:
79
+ # $1 - Info message
80
+ #######################################
81
+ info_msg() {
82
+ echo -e "${BLUE}ℹ $1${NC}"
83
+ }
84
+
85
+ #######################################
86
+ # Execute PostgreSQL query
87
+ # Arguments:
88
+ # $1 - SQL query
89
+ # $@ - Query parameters
90
+ # Returns:
91
+ # Query result
92
+ #######################################
93
+ execute_query() {
94
+ local query="$1"
95
+ shift
96
+
97
+ # Build psql command with password
98
+ local psql_cmd="PGPASSWORD='${DB_PASSWORD}' psql -h ${DB_HOST} -p ${DB_PORT} -U ${DB_USER} -d ${DB_NAME} -t -A"
99
+
100
+ # Execute query with parameters
101
+ if [ $# -gt 0 ]; then
102
+ # Use parameterized query
103
+ echo "$query" | $psql_cmd -v ON_ERROR_STOP=1 "$@" 2>&1
104
+ else
105
+ echo "$query" | $psql_cmd -v ON_ERROR_STOP=1 2>&1
106
+ fi
107
+ }
108
+
109
+ #######################################
110
+ # Get current state of a pattern
111
+ # Arguments:
112
+ # $1 - Pattern ID (UUID)
113
+ # Returns:
114
+ # Current state or empty string if not found
115
+ #######################################
116
+ get_current_state() {
117
+ local pattern_id="$1"
118
+
119
+ local query="SELECT status FROM workflow_patterns WHERE id = '${pattern_id}' LIMIT 1;"
120
+ local result
121
+ result=$(execute_query "$query")
122
+
123
+ # Check if pattern exists
124
+ if [ -z "$result" ]; then
125
+ error_exit "Pattern ID '${pattern_id}' not found"
126
+ fi
127
+
128
+ echo "$result"
129
+ }
130
+
131
+ #######################################
132
+ # Validate state transition
133
+ # Arguments:
134
+ # $1 - From state
135
+ # $2 - To state
136
+ # Returns:
137
+ # 0 if valid, 1 if invalid
138
+ #######################################
139
+ validate_transition() {
140
+ local from_state="$1"
141
+ local to_state="$2"
142
+
143
+ # Check if from_state exists in valid transitions
144
+ if [ -z "${VALID_TRANSITIONS[$from_state]:-}" ]; then
145
+ error_exit "Invalid from_state: ${from_state}"
146
+ fi
147
+
148
+ # Get allowed transitions for from_state
149
+ local allowed_transitions="${VALID_TRANSITIONS[$from_state]}"
150
+
151
+ # Check if to_state is in allowed transitions (comma-separated)
152
+ if [[ ",${allowed_transitions}," =~ ",${to_state}," ]]; then
153
+ return 0
154
+ else
155
+ return 1
156
+ fi
157
+ }
158
+
159
+ #######################################
160
+ # Perform state transition with transaction support
161
+ # Arguments:
162
+ # $1 - Pattern ID (UUID)
163
+ # $2 - From state
164
+ # $3 - To state
165
+ # $4 - Metadata (JSON, optional)
166
+ #######################################
167
+ transition_state() {
168
+ local pattern_id="$1"
169
+ local from_state="$2"
170
+ local to_state="$3"
171
+ local metadata="${4:-{}}"
172
+ local timestamp
173
+ timestamp=$(date -u +"%Y-%m-%d %H:%M:%S")
174
+
175
+ info_msg "Attempting state transition: ${from_state} → ${to_state}"
176
+
177
+ # Validate transition
178
+ if ! validate_transition "$from_state" "$to_state"; then
179
+ error_exit "Invalid state transition: ${from_state} → ${to_state}. Allowed transitions: ${VALID_TRANSITIONS[$from_state]}"
180
+ fi
181
+
182
+ # Begin transaction
183
+ local transaction_query="
184
+ BEGIN;
185
+
186
+ -- Lock the row for update (prevents concurrent modifications)
187
+ SELECT status FROM workflow_patterns WHERE id = '${pattern_id}' FOR UPDATE;
188
+
189
+ -- Verify current state matches expected from_state
190
+ DO \$\$
191
+ DECLARE
192
+ current_state TEXT;
193
+ BEGIN
194
+ SELECT status INTO current_state FROM workflow_patterns WHERE id = '${pattern_id}';
195
+
196
+ IF current_state IS NULL THEN
197
+ RAISE EXCEPTION 'Pattern not found: ${pattern_id}';
198
+ END IF;
199
+
200
+ IF current_state != '${from_state}' THEN
201
+ RAISE EXCEPTION 'State mismatch: expected ${from_state}, got %', current_state;
202
+ END IF;
203
+ END \$\$;
204
+
205
+ -- Update pattern status
206
+ UPDATE workflow_patterns
207
+ SET
208
+ status = '${to_state}',
209
+ updated_at = '${timestamp}'
210
+ WHERE id = '${pattern_id}';
211
+
212
+ -- Log state transition
213
+ INSERT INTO pattern_state_history (
214
+ pattern_id,
215
+ from_state,
216
+ to_state,
217
+ metadata,
218
+ timestamp
219
+ ) VALUES (
220
+ '${pattern_id}',
221
+ '${from_state}',
222
+ '${to_state}',
223
+ '${metadata}'::jsonb,
224
+ '${timestamp}'
225
+ );
226
+
227
+ COMMIT;
228
+ "
229
+
230
+ # Execute transaction
231
+ if execute_query "$transaction_query" > /dev/null 2>&1; then
232
+ success_msg "State transition successful: ${from_state} → ${to_state}"
233
+
234
+ # Log audit trail
235
+ log_audit_event "$pattern_id" "STATE_TRANSITION" "${from_state} → ${to_state}" "$metadata"
236
+
237
+ return 0
238
+ else
239
+ error_exit "State transition failed. Transaction rolled back."
240
+ fi
241
+ }
242
+
243
+ #######################################
244
+ # Rollback to a previous state
245
+ # Arguments:
246
+ # $1 - Pattern ID (UUID)
247
+ # $2 - Target state
248
+ # $3 - Reason (optional)
249
+ #######################################
250
+ rollback_state() {
251
+ local pattern_id="$1"
252
+ local target_state="$2"
253
+ local reason="${3:-Manual rollback}"
254
+
255
+ # Get current state
256
+ local current_state
257
+ current_state=$(get_current_state "$pattern_id")
258
+
259
+ warn_msg "Rolling back from ${current_state} to ${target_state}"
260
+ warn_msg "Reason: ${reason}"
261
+
262
+ # Validate rollback transition
263
+ if ! validate_transition "$current_state" "$target_state"; then
264
+ error_exit "Cannot rollback from ${current_state} to ${target_state}. Not a valid transition."
265
+ fi
266
+
267
+ # Perform rollback transition
268
+ local metadata="{\"rollback\": true, \"reason\": \"${reason}\"}"
269
+ transition_state "$pattern_id" "$current_state" "$target_state" "$metadata"
270
+
271
+ success_msg "Rollback completed successfully"
272
+ }
273
+
274
+ #######################################
275
+ # Log audit event
276
+ # Arguments:
277
+ # $1 - Pattern ID
278
+ # $2 - Event type
279
+ # $3 - Event description
280
+ # $4 - Event metadata (JSON, optional)
281
+ #######################################
282
+ log_audit_event() {
283
+ local pattern_id="$1"
284
+ local event_type="$2"
285
+ local description="$3"
286
+ local event_metadata="${4:-{}}"
287
+ local timestamp
288
+ timestamp=$(date -u +"%Y-%m-%d %H:%M:%S")
289
+
290
+ local audit_query="
291
+ INSERT INTO workflow_audit_log (
292
+ pattern_id,
293
+ event_type,
294
+ description,
295
+ metadata,
296
+ timestamp
297
+ ) VALUES (
298
+ '${pattern_id}',
299
+ '${event_type}',
300
+ '${description}',
301
+ '${event_metadata}'::jsonb,
302
+ '${timestamp}'
303
+ );
304
+ "
305
+
306
+ execute_query "$audit_query" > /dev/null 2>&1 || warn_msg "Failed to log audit event"
307
+ }
308
+
309
+ #######################################
310
+ # Get state transition history
311
+ # Arguments:
312
+ # $1 - Pattern ID (UUID)
313
+ #######################################
314
+ get_state_history() {
315
+ local pattern_id="$1"
316
+
317
+ local query="
318
+ SELECT
319
+ from_state,
320
+ to_state,
321
+ timestamp,
322
+ metadata
323
+ FROM pattern_state_history
324
+ WHERE pattern_id = '${pattern_id}'
325
+ ORDER BY timestamp DESC
326
+ LIMIT 20;
327
+ "
328
+
329
+ info_msg "State transition history for pattern ${pattern_id}:"
330
+ execute_query "$query"
331
+ }
332
+
333
+ #######################################
334
+ # Initialize database schema (if needed)
335
+ #######################################
336
+ init_schema() {
337
+ info_msg "Initializing workflow_patterns schema..."
338
+
339
+ local schema_query="
340
+ -- Create workflow_patterns table if not exists
341
+ CREATE TABLE IF NOT EXISTS workflow_patterns (
342
+ id UUID PRIMARY KEY,
343
+ pattern_name VARCHAR(255) NOT NULL,
344
+ workflow_steps JSONB NOT NULL,
345
+ occurrence_count INTEGER NOT NULL,
346
+ teams_affected TEXT[] NOT NULL,
347
+ similarity_score DECIMAL(3,2) NOT NULL,
348
+ deterministic BOOLEAN DEFAULT FALSE,
349
+ confidence_score DECIMAL(3,2) NOT NULL,
350
+ estimated_savings_usd DECIMAL(10,2),
351
+ priority VARCHAR(20),
352
+ created_at TIMESTAMP DEFAULT NOW(),
353
+ updated_at TIMESTAMP DEFAULT NOW(),
354
+ status VARCHAR(50) DEFAULT 'DETECTED'
355
+ );
356
+
357
+ -- Create state history table
358
+ CREATE TABLE IF NOT EXISTS pattern_state_history (
359
+ id SERIAL PRIMARY KEY,
360
+ pattern_id UUID REFERENCES workflow_patterns(id) ON DELETE CASCADE,
361
+ from_state VARCHAR(50) NOT NULL,
362
+ to_state VARCHAR(50) NOT NULL,
363
+ metadata JSONB DEFAULT '{}',
364
+ timestamp TIMESTAMP DEFAULT NOW()
365
+ );
366
+
367
+ -- Create audit log table
368
+ CREATE TABLE IF NOT EXISTS workflow_audit_log (
369
+ id SERIAL PRIMARY KEY,
370
+ pattern_id UUID,
371
+ event_type VARCHAR(100) NOT NULL,
372
+ description TEXT,
373
+ metadata JSONB DEFAULT '{}',
374
+ timestamp TIMESTAMP DEFAULT NOW()
375
+ );
376
+
377
+ -- Create index for faster queries
378
+ CREATE INDEX IF NOT EXISTS idx_pattern_status ON workflow_patterns(status);
379
+ CREATE INDEX IF NOT EXISTS idx_pattern_state_history_pattern_id ON pattern_state_history(pattern_id);
380
+ CREATE INDEX IF NOT EXISTS idx_audit_log_pattern_id ON workflow_audit_log(pattern_id);
381
+ "
382
+
383
+ if execute_query "$schema_query" > /dev/null 2>&1; then
384
+ success_msg "Schema initialized successfully"
385
+ else
386
+ error_exit "Failed to initialize schema"
387
+ fi
388
+ }
389
+
390
+ #######################################
391
+ # Show usage information
392
+ #######################################
393
+ usage() {
394
+ cat << EOF
395
+ Usage: $0 COMMAND [OPTIONS]
396
+
397
+ Commands:
398
+ transition Perform state transition
399
+ get-state Get current state of a pattern
400
+ rollback Rollback to a previous state
401
+ history Get state transition history
402
+ init Initialize database schema
403
+
404
+ Options:
405
+ --pattern-id UUID Pattern ID (required for most commands)
406
+ --from-state STATE Current state (required for transition)
407
+ --to-state STATE Target state (required for transition/rollback)
408
+ --reason TEXT Rollback reason (optional)
409
+ --metadata JSON Additional metadata (optional)
410
+
411
+ Valid States:
412
+ DETECTED, GENERATING, PENDING_REVIEW, APPROVED, REJECTED, NEEDS_CORRECTION, DEPLOYED
413
+
414
+ Examples:
415
+ # Transition from DETECTED to GENERATING
416
+ $0 transition --pattern-id "123e4567-e89b-12d3-a456-426614174000" \\
417
+ --from-state DETECTED --to-state GENERATING
418
+
419
+ # Get current state
420
+ $0 get-state --pattern-id "123e4567-e89b-12d3-a456-426614174000"
421
+
422
+ # Rollback deployment
423
+ $0 rollback --pattern-id "123e4567-e89b-12d3-a456-426614174000" \\
424
+ --to-state APPROVED --reason "Bug found in production"
425
+
426
+ # View history
427
+ $0 history --pattern-id "123e4567-e89b-12d3-a456-426614174000"
428
+
429
+ EOF
430
+ exit 1
431
+ }
432
+
433
+ #######################################
434
+ # Main execution
435
+ #######################################
436
+ main() {
437
+ if [ $# -eq 0 ]; then
438
+ usage
439
+ fi
440
+
441
+ local command="$1"
442
+ shift
443
+
444
+ # Parse arguments
445
+ local pattern_id=""
446
+ local from_state=""
447
+ local to_state=""
448
+ local reason=""
449
+ local metadata="{}"
450
+
451
+ while [ $# -gt 0 ]; do
452
+ case "$1" in
453
+ --pattern-id)
454
+ pattern_id="$2"
455
+ shift 2
456
+ ;;
457
+ --from-state)
458
+ from_state="$2"
459
+ shift 2
460
+ ;;
461
+ --to-state)
462
+ to_state="$2"
463
+ shift 2
464
+ ;;
465
+ --reason)
466
+ reason="$2"
467
+ shift 2
468
+ ;;
469
+ --metadata)
470
+ metadata="$2"
471
+ shift 2
472
+ ;;
473
+ *)
474
+ error_exit "Unknown option: $1"
475
+ ;;
476
+ esac
477
+ done
478
+
479
+ # Execute command
480
+ case "$command" in
481
+ transition)
482
+ [ -z "$pattern_id" ] && error_exit "--pattern-id required"
483
+ [ -z "$from_state" ] && error_exit "--from-state required"
484
+ [ -z "$to_state" ] && error_exit "--to-state required"
485
+
486
+ transition_state "$pattern_id" "$from_state" "$to_state" "$metadata"
487
+ ;;
488
+ get-state)
489
+ [ -z "$pattern_id" ] && error_exit "--pattern-id required"
490
+
491
+ current_state=$(get_current_state "$pattern_id")
492
+ echo "Current state: ${current_state}"
493
+ ;;
494
+ rollback)
495
+ [ -z "$pattern_id" ] && error_exit "--pattern-id required"
496
+ [ -z "$to_state" ] && error_exit "--to-state required"
497
+
498
+ rollback_state "$pattern_id" "$to_state" "$reason"
499
+ ;;
500
+ history)
501
+ [ -z "$pattern_id" ] && error_exit "--pattern-id required"
502
+
503
+ get_state_history "$pattern_id"
504
+ ;;
505
+ init)
506
+ init_schema
507
+ ;;
508
+ *)
509
+ error_exit "Unknown command: $command"
510
+ ;;
511
+ esac
512
+ }
513
+
514
+ main "$@"