claude-flow-novice 2.14.36 → 2.15.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 (34) hide show
  1. package/.claude/commands/cfn-loop-cli.md +491 -456
  2. package/.claude/commands/switch-api.md +33 -12
  3. package/.claude/skills/cfn-agent-spawning/get-agent-provider-env.sh +107 -0
  4. package/.claude/skills/cfn-agent-spawning/parse-agent-provider.sh +59 -0
  5. package/.claude/skills/cfn-docker-agent-spawning/spawn-agent.sh +24 -6
  6. package/.claude/skills/cfn-loop-orchestration/helpers/spawn-agents.sh +18 -9
  7. package/.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh +220 -220
  8. package/claude-assets/agents/cfn-dev-team/developers/backend-developer.md +5 -0
  9. package/claude-assets/agents/custom/claude-code-expert.md +151 -2
  10. package/claude-assets/agents/docker-coordinators/cfn-docker-v3-coordinator.md +43 -3
  11. package/claude-assets/commands/cfn-loop-cli.md +491 -456
  12. package/claude-assets/commands/switch-api.md +33 -12
  13. package/claude-assets/skills/cfn-agent-spawning/get-agent-provider-env.sh +107 -0
  14. package/claude-assets/skills/cfn-agent-spawning/parse-agent-provider.sh +59 -0
  15. package/claude-assets/skills/cfn-docker-agent-spawning/spawn-agent.sh +24 -6
  16. package/claude-assets/skills/cfn-error-logging/SKILL.md +339 -0
  17. package/claude-assets/skills/cfn-error-logging/cleanup-error-logs.sh +334 -0
  18. package/claude-assets/skills/cfn-error-logging/integrate-cli.sh +232 -0
  19. package/claude-assets/skills/cfn-error-logging/integrate-docker.sh +294 -0
  20. package/claude-assets/skills/cfn-error-logging/invoke-error-logging.sh +839 -0
  21. package/claude-assets/skills/cfn-error-logging/test-error-logging.sh +475 -0
  22. package/claude-assets/skills/cfn-loop-orchestration/helpers/spawn-agents.sh +18 -9
  23. package/claude-assets/skills/cfn-process-instrumentation/instrument-process.sh +5 -3
  24. package/claude-assets/skills/cfn-redis-coordination/invoke-waiting-mode.sh +220 -220
  25. package/claude-assets/skills/cfn-task-mode-sanitize/task-mode-env-sanitizer.sh +21 -9
  26. package/claude-assets/skills/cfn-validation-runner-instrumentation/wrapped-executor.sh +3 -1
  27. package/dist/hello.js +27 -3
  28. package/dist/hello.js.map +1 -1
  29. package/dist/server.js +194 -0
  30. package/dist/server.js.map +1 -0
  31. package/dist/server.test.js +207 -0
  32. package/dist/server.test.js.map +1 -0
  33. package/package.json +2 -1
  34. package/scripts/switch-api.sh +140 -12
@@ -1,30 +1,47 @@
1
1
  ---
2
- description: Switch Main Chat and Task tool between Z.ai and Anthropic providers
2
+ description: Switch Main Chat and Task tool between Z.ai, Kimi, OpenRouter, and Anthropic providers
3
3
  tags: [config, api, cost-optimization]
4
4
  ---
5
5
 
6
- Switch Main Chat and Task() tool API provider between Z.ai (cost-optimized) and Anthropic (high-quality).
6
+ Switch Main Chat and Task() tool API provider between multiple AI providers.
7
7
 
8
- **Important:** CLI agents always use Z.ai (from `.env`). This command only affects Main Chat and Task() spawned agents.
8
+ **Important:** CLI agents support custom routing when enabled. This command affects Main Chat and Task() spawned agents.
9
9
 
10
10
  **Usage:**
11
11
  - `/switch-api` - Show current status
12
- - `/switch-api zai` - Main Chat/Task tool use Z.ai ($0.50/1M tokens)
13
- - `/switch-api max` - Main Chat/Task tool use Anthropic ($15/1M tokens, requires re-login)
12
+ - `/switch-api [zai|kimi|openrouter|max]` - Switch provider
13
+ - `zai` - Z.ai ($0.50/1M tokens)
14
+ - `kimi` - Moonshot Kimi ($2/1M tokens)
15
+ - `openrouter` - OpenRouter (varies by model)
16
+ - `max` or `claude` - Anthropic ($15/1M tokens, requires re-login)
14
17
 
15
18
  **Arguments:**
16
19
  - `status` - Show current routing configuration (default)
17
20
  - `zai` - Route Main Chat + Task tool to Z.ai for cost savings
21
+ - `kimi` - Route Main Chat + Task tool to Moonshot Kimi
22
+ - `openrouter` - Route Main Chat + Task tool to OpenRouter
18
23
  - `max` or `claude` - Route Main Chat + Task tool to Anthropic for quality
19
24
 
20
25
  **What This Does:**
21
26
 
22
27
  `/switch-api zai`:
23
- - Adds env vars to `.claude/settings.json`
28
+ - Adds Z.ai env vars to `.claude/settings.json`
24
29
  - Main Chat + Task() agents use Z.ai
25
30
  - Cost: $0.50/1M tokens (97% savings)
26
31
  - No login required
27
32
 
33
+ `/switch-api kimi`:
34
+ - Adds Kimi env vars to `.claude/settings.json`
35
+ - Main Chat + Task() agents use Moonshot Kimi
36
+ - Cost: ~$2/1M tokens
37
+ - Requires `KIMI_API_KEY` in root `.env`
38
+
39
+ `/switch-api openrouter`:
40
+ - Adds OpenRouter env vars to `.claude/settings.json`
41
+ - Main Chat + Task() agents use OpenRouter
42
+ - Cost: Varies by model
43
+ - Requires `OPENROUTER_API_KEY` in root `.env`
44
+
28
45
  `/switch-api max`:
29
46
  - Removes env vars from `.claude/settings.json`
30
47
  - Main Chat + Task() agents use Anthropic
@@ -33,21 +50,25 @@ Switch Main Chat and Task() tool API provider between Z.ai (cost-optimized) and
33
50
 
34
51
  **Combined Architecture:**
35
52
  ```
36
- Main Chat (Anthropic or Z.ai - your choice)
53
+ Main Chat (Anthropic/Z.ai/Kimi/OpenRouter - your choice)
37
54
 
38
55
  Task() → Coordinator (uses Main Chat provider)
39
56
 
40
- CLI spawn → Workers (always Z.ai from .env)
57
+ CLI spawn → Workers (custom routing when enabled, see agent profiles)
41
58
  ```
42
59
 
43
60
  **Execute:**
44
61
  ```bash
45
- bash scripts/switch-api.sh {{args}}
62
+ bash "$(git rev-parse --show-toplevel 2>/dev/null || pwd)/scripts/switch-api.sh" {{args}}
46
63
  ```
47
64
 
65
+ **Note:** Script automatically resolves to project root directory.
66
+
48
67
  **Examples:**
49
68
  ```bash
50
- /switch-api # Show current routing
51
- /switch-api zai # Cost-optimize Main Chat
52
- /switch-api max # Quality-optimize Main Chat (requires re-login)
69
+ /switch-api # Show current routing
70
+ /switch-api zai # Cost-optimize with Z.ai
71
+ /switch-api kimi # Use Moonshot Kimi
72
+ /switch-api openrouter # Use OpenRouter (access 400+ models)
73
+ /switch-api max # Quality-optimize with Anthropic (requires re-login)
53
74
  ```
@@ -0,0 +1,107 @@
1
+ #!/bin/bash
2
+
3
+ # Get Agent Provider Environment Variables
4
+ # Determines which provider environment variables to use for CLI/Docker agent spawning
5
+ #
6
+ # Logic:
7
+ # 1. If custom routing is disabled, use Main Chat settings (from .claude/settings.json)
8
+ # 2. If custom routing is enabled:
9
+ # a. Check agent profile for PROVIDER_PARAMETERS
10
+ # b. If found, use agent-specific provider/model
11
+ # c. If not found, use Main Chat settings
12
+ #
13
+ # Usage: source get-agent-provider-env.sh AGENT_TYPE
14
+ # Exports: ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_MODEL, ANTHROPIC_SMALL_FAST_MODEL
15
+
16
+ set -euo pipefail
17
+
18
+ AGENT_TYPE="${1:-}"
19
+ CUSTOM_ROUTING_ENABLED="${CFN_CUSTOM_ROUTING:-false}"
20
+ SETTINGS_FILE=".claude/settings.json"
21
+
22
+ if [[ -z "$AGENT_TYPE" ]]; then
23
+ echo "Usage: source $0 AGENT_TYPE" >&2
24
+ return 1 2>/dev/null || exit 1
25
+ fi
26
+
27
+ # Function to get provider config (zai, kimi, openrouter, anthropic)
28
+ get_provider_config() {
29
+ local provider="$1"
30
+ local model="${2:-}"
31
+
32
+ case "$provider" in
33
+ zai)
34
+ export ANTHROPIC_BASE_URL="https://api.z.ai/api/anthropic"
35
+ export ANTHROPIC_AUTH_TOKEN="${ZAI_API_KEY:-}"
36
+ export ANTHROPIC_MODEL="${model:-glm-4.6}"
37
+ export ANTHROPIC_SMALL_FAST_MODEL="${model:-glm-4.6}"
38
+ ;;
39
+ kimi)
40
+ export ANTHROPIC_BASE_URL="https://api.moonshot.ai/anthropic"
41
+ export ANTHROPIC_AUTH_TOKEN="${KIMI_API_KEY:-}"
42
+ export ANTHROPIC_MODEL="${model:-kimi-k2-turbo-preview}"
43
+ export ANTHROPIC_SMALL_FAST_MODEL="${model:-kimi-k2-turbo-preview}"
44
+ ;;
45
+ openrouter)
46
+ export ANTHROPIC_BASE_URL="https://openrouter.ai/api/v1"
47
+ export ANTHROPIC_AUTH_TOKEN="${OPENROUTER_API_KEY:-}"
48
+ export ANTHROPIC_MODEL="${model:-anthropic/claude-sonnet-4.5}"
49
+ export ANTHROPIC_SMALL_FAST_MODEL="${model:-anthropic/claude-sonnet-4.5}"
50
+ ;;
51
+ anthropic|*)
52
+ # Use default Anthropic settings (remove custom env vars)
53
+ unset ANTHROPIC_BASE_URL
54
+ unset ANTHROPIC_AUTH_TOKEN
55
+ unset ANTHROPIC_MODEL
56
+ unset ANTHROPIC_SMALL_FAST_MODEL
57
+ ;;
58
+ esac
59
+ }
60
+
61
+ # Function to detect provider from base URL
62
+ detect_provider_from_url() {
63
+ local base_url="$1"
64
+
65
+ if [[ "$base_url" == *"z.ai"* ]]; then
66
+ echo "zai"
67
+ elif [[ "$base_url" == *"moonshot.ai"* ]]; then
68
+ echo "kimi"
69
+ elif [[ "$base_url" == *"openrouter.ai"* ]]; then
70
+ echo "openrouter"
71
+ else
72
+ echo "anthropic"
73
+ fi
74
+ }
75
+
76
+ # Step 1: Check if custom routing is enabled
77
+ if [[ "$CUSTOM_ROUTING_ENABLED" != "true" ]]; then
78
+ # Custom routing disabled - use Main Chat settings from .claude/settings.json
79
+ if [[ -f "$SETTINGS_FILE" ]]; then
80
+ BASE_URL=$(jq -r '.env.ANTHROPIC_BASE_URL // empty' "$SETTINGS_FILE" 2>/dev/null || echo "")
81
+
82
+ if [[ -n "$BASE_URL" ]]; then
83
+ # Main Chat has custom provider configured
84
+ export ANTHROPIC_BASE_URL="$BASE_URL"
85
+ export ANTHROPIC_AUTH_TOKEN=$(jq -r '.env.ANTHROPIC_AUTH_TOKEN // empty' "$SETTINGS_FILE" 2>/dev/null || echo "")
86
+ export ANTHROPIC_MODEL=$(jq -r '.env.ANTHROPIC_MODEL // empty' "$SETTINGS_FILE" 2>/dev/null || echo "")
87
+ export ANTHROPIC_SMALL_FAST_MODEL=$(jq -r '.env.ANTHROPIC_SMALL_FAST_MODEL // empty' "$SETTINGS_FILE" 2>/dev/null || echo "")
88
+ fi
89
+ # else: No custom provider, use default Anthropic
90
+ fi
91
+ return 0 2>/dev/null || exit 0
92
+ fi
93
+
94
+ # Step 2: Custom routing enabled - check agent profile for PROVIDER_PARAMETERS
95
+ AGENT_PROVIDER=$(bash .claude/skills/cfn-agent-spawning/parse-agent-provider.sh "$AGENT_TYPE" --field provider)
96
+ AGENT_MODEL=$(bash .claude/skills/cfn-agent-spawning/parse-agent-provider.sh "$AGENT_TYPE" --field model)
97
+
98
+ if [[ -n "$AGENT_PROVIDER" ]]; then
99
+ # Agent has provider parameters - use them
100
+ get_provider_config "$AGENT_PROVIDER" "$AGENT_MODEL"
101
+ else
102
+ # No agent-specific provider - default to Z.ai with glm-4.6
103
+ export ANTHROPIC_BASE_URL="https://api.z.ai/api/anthropic"
104
+ export ANTHROPIC_AUTH_TOKEN="${ZAI_API_KEY:-}"
105
+ export ANTHROPIC_MODEL="glm-4.6"
106
+ export ANTHROPIC_SMALL_FAST_MODEL="glm-4.6"
107
+ fi
@@ -0,0 +1,59 @@
1
+ #!/bin/bash
2
+
3
+ # Parse Agent Provider Parameters
4
+ # Extracts provider and model from agent profile's PROVIDER_PARAMETERS section
5
+ # Usage: parse-agent-provider.sh AGENT_TYPE [--field provider|model]
6
+
7
+ set -euo pipefail
8
+
9
+ AGENT_TYPE="${1:-}"
10
+ FIELD="${2:---field}"
11
+ FIELD_VALUE="${3:-provider}"
12
+
13
+ if [[ -z "$AGENT_TYPE" ]]; then
14
+ echo "Usage: $0 AGENT_TYPE [--field provider|model]" >&2
15
+ exit 1
16
+ fi
17
+
18
+ # Find agent file in multiple locations
19
+ AGENT_FILE=""
20
+ SEARCH_PATHS=(
21
+ ".claude/agents/cfn-dev-team/**/${AGENT_TYPE}.md"
22
+ ".claude/agents/custom/${AGENT_TYPE}.md"
23
+ ".claude/agents/${AGENT_TYPE}.md"
24
+ )
25
+
26
+ for pattern in "${SEARCH_PATHS[@]}"; do
27
+ # Use find with glob pattern
28
+ while IFS= read -r -d '' file; do
29
+ if [[ -f "$file" ]]; then
30
+ AGENT_FILE="$file"
31
+ break 2
32
+ fi
33
+ done < <(find .claude/agents -type f -name "${AGENT_TYPE}.md" -print0 2>/dev/null)
34
+ done
35
+
36
+ if [[ -z "$AGENT_FILE" ]]; then
37
+ # Agent file not found, return empty (will fallback to main chat settings)
38
+ echo ""
39
+ exit 0
40
+ fi
41
+
42
+ # Extract PROVIDER_PARAMETERS section
43
+ # Format:
44
+ # <!-- PROVIDER_PARAMETERS
45
+ # provider: kimi
46
+ # model: kimi-k2-turbo-preview
47
+ # -->
48
+
49
+ PARAM_VALUE=$(awk '
50
+ /<!-- PROVIDER_PARAMETERS/,/-->/ {
51
+ if ($0 ~ /^'"${FIELD_VALUE}"':/) {
52
+ sub(/^'"${FIELD_VALUE}"':[ \t]*/, "")
53
+ print $0
54
+ exit
55
+ }
56
+ }
57
+ ' "$AGENT_FILE" | tr -d '\r' | xargs)
58
+
59
+ echo "$PARAM_VALUE"
@@ -208,8 +208,12 @@ if ! docker image inspect "$IMAGE" &> /dev/null; then
208
208
  exit 1
209
209
  fi
210
210
 
211
- # Get project root directory
212
- PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../../.." && pwd)"
211
+ # Get project root directory (use git root for reliability)
212
+ PROJECT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null)"
213
+ if [[ -z "$PROJECT_ROOT" ]]; then
214
+ # Fallback to script-relative path
215
+ PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../../.." && pwd -P)"
216
+ fi
213
217
  cd "$PROJECT_ROOT"
214
218
 
215
219
  # Create workspace directory with proper permissions
@@ -328,16 +332,30 @@ DOCKER_CMD="$DOCKER_CMD --env AGENT_TYPE=${AGENT_TYPE}"
328
332
  DOCKER_CMD="$DOCKER_CMD --env TASK_ID=${TASK_ID}"
329
333
  DOCKER_CMD="$DOCKER_CMD --env PROJECT_ROOT=/app"
330
334
 
331
- # Add Redis URL if Redis is available
332
- if command -v redis-cli &> /dev/null && redis-cli ping &> /dev/null; then
333
- DOCKER_CMD="$DOCKER_CMD --env REDIS_URL=redis://redis:6379"
334
- fi
335
+ # Add Redis URL for container-to-container networking
336
+ # Always set Redis URL regardless of host Redis status
337
+ DOCKER_CMD="$DOCKER_CMD --env REDIS_URL=redis://redis:6379"
335
338
 
336
339
  # Add MCP tokens file path if tokens generated
337
340
  if [[ -n "$TOKENS_FILE" ]]; then
338
341
  DOCKER_CMD="$DOCKER_CMD --env MCP_TOKENS_FILE=/app/workspace/mcp-tokens.json"
339
342
  fi
340
343
 
344
+ # Add provider routing environment variables (custom routing support)
345
+ source .claude/skills/cfn-agent-spawning/get-agent-provider-env.sh "$AGENT_TYPE"
346
+ if [[ -n "${ANTHROPIC_BASE_URL:-}" ]]; then
347
+ DOCKER_CMD="$DOCKER_CMD --env ANTHROPIC_BASE_URL=${ANTHROPIC_BASE_URL}"
348
+ fi
349
+ if [[ -n "${ANTHROPIC_AUTH_TOKEN:-}" ]]; then
350
+ DOCKER_CMD="$DOCKER_CMD --env ANTHROPIC_AUTH_TOKEN=${ANTHROPIC_AUTH_TOKEN}"
351
+ fi
352
+ if [[ -n "${ANTHROPIC_MODEL:-}" ]]; then
353
+ DOCKER_CMD="$DOCKER_CMD --env ANTHROPIC_MODEL=${ANTHROPIC_MODEL}"
354
+ fi
355
+ if [[ -n "${ANTHROPIC_SMALL_FAST_MODEL:-}" ]]; then
356
+ DOCKER_CMD="$DOCKER_CMD --env ANTHROPIC_SMALL_FAST_MODEL=${ANTHROPIC_SMALL_FAST_MODEL}"
357
+ fi
358
+
341
359
  # Add custom environment variables
342
360
  if [[ -n "$ENVIRONMENT" ]]; then
343
361
  IFS=',' read -ra ENV_ARRAY <<< "$ENVIRONMENT"
@@ -0,0 +1,339 @@
1
+ # CFN Error Logging Skill
2
+
3
+ ## Metadata
4
+ - **Skill ID:** cfn-error-logging
5
+ - **Version:** 1.0.0
6
+ - **Category:** Error Management & Debugging
7
+ - **Dependencies:** redis-coordination, system-diagnostics
8
+ - **Maturity:** Production
9
+ - **Last Updated:** 2025-11-10
10
+
11
+ ## Purpose
12
+ Comprehensive error logging and diagnostic capture for CFN Loop failures. Creates detailed error reports that users can send for debugging when CFN loops fail in CLI or Docker modes.
13
+
14
+ ## Responsibilities
15
+ 1. **Error Detection**: Monitor CFN Loop execution for failures and exceptions
16
+ 2. **Diagnostic Capture**: Collect system state, logs, and configuration data
17
+ 3. **Report Generation**: Create user-friendly error reports with actionable information
18
+ 4. **Log Management**: Store, organize, and clean up error logs
19
+ 5. **Integration**: Hook into CLI and Docker CFN Loop failure points
20
+
21
+ ## Interface
22
+
23
+ ### Main Entry Point
24
+ ```bash
25
+ ./.claude/skills/cfn-error-logging/invoke-error-logging.sh \
26
+ --action <capture|report|cleanup|list> \
27
+ --task-id <unique-id> \
28
+ [--error-type <orchestrator|agent-spawn|timeout|consensus|resource>] \
29
+ [--error-message <description>] \
30
+ [--exit-code <number>] \
31
+ [--context <json>]
32
+ ```
33
+
34
+ ### Parameters
35
+ - `action`: Operation to perform (capture, report, cleanup, list)
36
+ - `task-id`: Unique CFN Loop task identifier
37
+ - `error-type`: Type of error that occurred
38
+ - `error-message`: Human-readable error description
39
+ - `exit-code`: Process exit code (if available)
40
+ - `context`: Additional context data (JSON format)
41
+
42
+ ### Available Actions
43
+
44
+ #### **capture** - Capture Error Data
45
+ ```bash
46
+ # Automatic capture on CFN Loop failure
47
+ ./.claude/skills/cfn-error-logging/invoke-error-logging.sh \
48
+ --action capture \
49
+ --task-id "cfn-cli-1731234567" \
50
+ --error-type "orchestrator" \
51
+ --error-message "Agent spawning failed" \
52
+ --exit-code 1
53
+ ```
54
+
55
+ #### **report** - Generate User Report
56
+ ```bash
57
+ # Generate user-friendly error report
58
+ ./.claude/skills/cfn-error-logging/invoke-error-logging.sh \
59
+ --action report \
60
+ --task-id "cfn-cli-1731234567" \
61
+ --format "markdown"
62
+ ```
63
+
64
+ #### **cleanup** - Manage Error Logs
65
+ ```bash
66
+ # Clean old error logs (older than 7 days)
67
+ ./.claude/skills/cfn-error-logging/invoke-error-logging.sh \
68
+ --action cleanup \
69
+ --retention-days 7
70
+ ```
71
+
72
+ #### **list** - List Error Logs
73
+ ```bash
74
+ # List all error logs
75
+ ./.claude/skills/cfn-error-logging/invoke-error-logging.sh \
76
+ --action list \
77
+ --format "table"
78
+ ```
79
+
80
+ ## Data Captured
81
+
82
+ ### System Diagnostics
83
+ - **Hardware**: CPU, memory, disk space usage
84
+ - **Software**: OS version, Node.js version, npx version
85
+ - **Dependencies**: Redis connectivity, Docker status
86
+ - **Network**: Connection status, latency
87
+
88
+ ### CFN Loop State
89
+ - **Configuration**: Task ID, mode, agent lists, thresholds
90
+ - **Execution**: Current iteration, agent PIDs, timeouts
91
+ - **Redis Data**: Task context, agent states, confidence scores
92
+ - **Checkpoints**: Last successful iteration, saved state
93
+
94
+ ### Error Context
95
+ - **Error Details**: Type, message, exit code, timestamp
96
+ - **Stack Traces**: Process logs, error messages, debug output
97
+ - **Environment**: Working directory, environment variables
98
+ - **Process Tree**: Parent/child process relationships
99
+
100
+ ## Integration Points
101
+
102
+ ### CLI Loop Integration
103
+ ```bash
104
+ # Add to orchestrate.sh error handling
105
+ if [ $EXIT_CODE -ne 0 ]; then
106
+ ./.claude/skills/cfn-error-logging/invoke-error-logging.sh \
107
+ --action capture \
108
+ --task-id "$TASK_ID" \
109
+ --error-type "orchestrator" \
110
+ --error-message "CFN Loop failed at iteration $ITERATION" \
111
+ --exit-code $EXIT_CODE
112
+ fi
113
+ ```
114
+
115
+ ### Docker Loop Integration
116
+ ```bash
117
+ # Add to cfn-docker-loop-orchestration error handling
118
+ if [ $CONTAINER_EXIT_CODE -ne 0 ]; then
119
+ ./.claude/skills/cfn-error-logging/invoke-error-logging.sh \
120
+ --action capture \
121
+ --task-id "$TASK_ID" \
122
+ --error-type "docker" \
123
+ --error-message "Container failed: $CONTAINER_NAME" \
124
+ --exit-code $CONTAINER_EXIT_CODE
125
+ fi
126
+ ```
127
+
128
+ ### Agent Spawning Integration
129
+ ```bash
130
+ # Add to agent spawning error handling
131
+ if ! $SPAWN_COMMAND; then
132
+ ./.claude/skills/cfn-error-logging/invoke-error-logging.sh \
133
+ --action capture \
134
+ --task-id "$TASK_ID" \
135
+ --error-type "agent-spawn" \
136
+ --error-message "Failed to spawn agent: $AGENT_TYPE" \
137
+ --exit-code $?
138
+ fi
139
+ ```
140
+
141
+ ## Error Report Format
142
+
143
+ ### Markdown Report (User-Friendly)
144
+ ```markdown
145
+ # CFN Loop Error Report
146
+
147
+ ## 🚨 Error Summary
148
+ - **Task ID**: cfn-cli-1731234567
149
+ - **Error Type**: orchestrator
150
+ - **Message**: Agent spawning failed
151
+ - **Timestamp**: 2025-11-10 04:30:15 UTC
152
+ - **Exit Code**: 1
153
+
154
+ ## 📋 Quick Diagnosis
155
+ **Most Likely Cause**: npx not found or Redis connection failed
156
+ **Recommended Action**: Check dependencies with pre-flight validation
157
+
158
+ ## 🔧 Troubleshooting Steps
159
+ 1. ✅ Check Node.js installation: `node --version`
160
+ 2. ✅ Check npx availability: `npx --version`
161
+ 3. ❌ Check Redis connection: `redis-cli ping`
162
+ 4. ✅ Check available memory: `free -h`
163
+
164
+ ## 📊 System State
165
+ - **Memory Usage**: 65% (2.6GB/4GB)
166
+ - **Disk Space**: 45GB available
167
+ - **CPU Load**: 0.8
168
+ - **Concurrent CFN Loops**: 3
169
+
170
+ ## 📝 Send This Report
171
+ **To**: Your Claude assistant
172
+ **Include**:
173
+ - Complete error details above
174
+ - Any recent changes to your setup
175
+ - Steps you were trying to perform
176
+ ```
177
+
178
+ ## JSON Report (Machine-Readable)
179
+ ```json
180
+ {
181
+ "task_id": "cfn-cli-1731234567",
182
+ "error_type": "orchestrator",
183
+ "error_message": "Agent spawning failed",
184
+ "timestamp": "2025-11-10T04:30:15Z",
185
+ "exit_code": 1,
186
+ "system_diagnostics": {...},
187
+ "cfn_state": {...},
188
+ "troubleshooting_steps": [...]
189
+ }
190
+ ```
191
+
192
+ ## Storage and Management
193
+
194
+ ### Log Location
195
+ - **Base Directory**: `/tmp/cfn_error_logs/`
196
+ - **Individual Logs**: `/tmp/cfn_error_logs/cfn-error-<task-id>-<timestamp>.json`
197
+ - **Reports**: `/tmp/cfn_error_logs/reports/cfn-report-<task-id>-<timestamp>.md`
198
+
199
+ ### Log Rotation
200
+ - **Retention**: 7 days by default
201
+ - **Cleanup**: Automatic cleanup on skill invocation
202
+ - **Compression**: Compress logs older than 1 day
203
+ - **Size Limit**: Maximum 100MB of error logs total
204
+
205
+ ### Privacy Considerations
206
+ - **No Code**: Never captures source code content
207
+ - **No Credentials**: Strips sensitive environment variables
208
+ - **Local Storage**: All logs stored locally, user-controlled
209
+ - **User Consent**: Error capture only on explicit failures
210
+
211
+ ## Usage Examples
212
+
213
+ ### Capture Error on CLI Loop Failure
214
+ ```bash
215
+ # In cfn-loop-cli command
216
+ if ! npx claude-flow-novice agent cfn-v3-coordinator ...; then
217
+ ./.claude/skills/cfn-error-logging/invoke-error-logging.sh \
218
+ --action capture \
219
+ --task-id "$TASK_ID" \
220
+ --error-type "cli-coordinator" \
221
+ --error-message "CLI coordinator failed to start"
222
+ fi
223
+ ```
224
+
225
+ ### Generate Debug Report
226
+ ```bash
227
+ # After CFN Loop failure
228
+ ./.claude/skills/cfn-error-logging/invoke-error-logging.sh \
229
+ --action report \
230
+ --task-id "cfn-cli-1731234567" \
231
+ --format markdown > /tmp/cfn_error_report.md
232
+
233
+ echo "📋 Error report saved to: /tmp/cfn_error_report.md"
234
+ echo "📤 Send this file to your Claude assistant for debugging help"
235
+ ```
236
+
237
+ ### List Recent Errors
238
+ ```bash
239
+ # List all recent errors
240
+ ./.claude/skills/cfn-error-logging/invoke-error-logging.sh \
241
+ --action list \
242
+ --format table
243
+
244
+ # List errors from last 24 hours
245
+ ./.claude/skills/cfn-error-logging/invoke-error-logging.sh \
246
+ --action list \
247
+ --since "24h" \
248
+ --format json
249
+ ```
250
+
251
+ ## Error Categories
252
+
253
+ ### Orchestrator Errors
254
+ - Configuration validation failures
255
+ - Parameter parsing errors
256
+ - Mode threshold mismatches
257
+ - Resource allocation failures
258
+
259
+ ### Agent Spawning Errors
260
+ - npx command failures
261
+ - Node.js environment issues
262
+ - Agent binary not found
263
+ - Container runtime errors
264
+
265
+ ### Coordination Errors
266
+ - Redis connection failures
267
+ - Key conflicts and race conditions
268
+ - Timeout errors
269
+ - Consensus calculation failures
270
+
271
+ ### Resource Errors
272
+ - Memory exhaustion
273
+ - Disk space shortage
274
+ - Process limit exceeded
275
+ - Network connectivity issues
276
+
277
+ ### System Errors
278
+ - Permission denied
279
+ - File system errors
280
+ - Signal termination
281
+ - Unexpected crashes
282
+
283
+ ## Troubleshooting Guide
284
+
285
+ ### Common Error Patterns
286
+ 1. **"npx not found"**: Install Node.js and npx globally
287
+ 2. **"Redis connection failed"**: Start Redis server or check configuration
288
+ 3. **"Memory exhaustion"**: Close other applications or increase system memory
289
+ 4. **"Permission denied"**: Check file permissions and user access
290
+
291
+ ### Diagnostic Commands
292
+ ```bash
293
+ # System health check
294
+ ./.claude/skills/cfn-error-logging/invoke-error-logging.sh \
295
+ --action diagnostics
296
+
297
+ # Dependency validation
298
+ ./.claude/skills/cfn-error-logging/invoke-error-logging.sh \
299
+ --action validate-dependencies
300
+
301
+ # Resource monitoring
302
+ ./.claude/skills/cfn-error-logging/invoke-error-logging.sh \
303
+ --action monitor-resources
304
+ ```
305
+
306
+ ## Best Practices
307
+
308
+ ### For Users
309
+ 1. **Send Complete Reports**: Include the full error report when asking for help
310
+ 2. **Provide Context**: Describe what you were trying to accomplish
311
+ 3. **Check Dependencies**: Run pre-flight validation before complex tasks
312
+ 4. **Monitor Resources**: Watch memory and disk usage during long-running tasks
313
+
314
+ ### For Developers
315
+ 1. **Integration Points**: Add error logging to all CFN Loop failure points
316
+ 2. **Error Categories**: Use appropriate error types for better classification
317
+ 3. **Context Capture**: Include relevant state information for debugging
318
+ 4. **Privacy**: Never capture sensitive data or code content
319
+
320
+ ### For System Administrators
321
+ 1. **Log Management**: Regular cleanup of old error logs
322
+ 2. **Monitoring**: Track error frequency and patterns
323
+ 3. **Resource Planning**: Ensure adequate memory and disk space
324
+ 4. **Dependency Management**: Keep Node.js, Redis, and Docker updated
325
+
326
+ ## Troubleshooting
327
+
328
+ ### Skill Failures
329
+ If the error logging skill itself fails:
330
+ 1. **Check Permissions**: Ensure write access to `/tmp/`
331
+ 2. **Disk Space**: Verify available space for log files
332
+ 3. **Dependencies**: Check for required system tools (jq, bc, etc.)
333
+ 4. **Fallback**: Use manual error reporting with basic system diagnostics
334
+
335
+ ### Common Issues
336
+ - **Permission Denied**: Fix directory permissions
337
+ - **Disk Full**: Clean up old error logs
338
+ - **Missing Tools**: Install required dependencies
339
+ - **Timezone Issues**: Use UTC timestamps consistently