claude-flow-novice 2.18.29 → 2.18.32
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.
|
@@ -4,423 +4,338 @@ argument-hint: "<language> [--max-parallel=5] [--max-cycles=10]"
|
|
|
4
4
|
allowed-tools: ["Task", "TaskOutput", "TodoWrite", "Read", "Bash"]
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
# CFN Fix Errors - Coordination Mode
|
|
7
|
+
# CFN Fix Errors - Agent Coordination Mode
|
|
8
8
|
|
|
9
|
-
**Version:** 1.
|
|
9
|
+
**Version:** 1.2.0 | **Date:** 2025-12-21 | **Status:** Production Ready
|
|
10
10
|
|
|
11
11
|
## Quick Overview
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Main chat coordinates up to 5 background agents to fix compilation errors in parallel. Each agent works on one file using Cerebras acceleration and post-edit validation.
|
|
14
14
|
|
|
15
15
|
### Key Features
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
18
|
-
- **
|
|
19
|
-
- **Post-
|
|
20
|
-
- **Cerebras
|
|
21
|
-
- **
|
|
22
|
-
- **Continuous Spawning:** New agent launches immediately when slot opens
|
|
16
|
+
- **Max 5 parallel agents** with continuous spawning
|
|
17
|
+
- **Single-file focus** - each agent fixes one file only
|
|
18
|
+
- **2-attempt retry** logic per file before deferring to Phase 2
|
|
19
|
+
- **Post-edit validation** confirms fixes are correct
|
|
20
|
+
- **Cerebras gates** prevent semantic changes (12 structural validations)
|
|
21
|
+
- **Automatic Phase 2** transition at <40 errors
|
|
23
22
|
|
|
24
23
|
### When to Use
|
|
25
24
|
- 20+ compilation errors
|
|
26
|
-
-
|
|
27
|
-
- Errors are mostly mechanical (type mismatches, imports, syntax)
|
|
25
|
+
- Errors are mostly mechanical (imports, types, syntax)
|
|
28
26
|
- Want visibility into agent progress
|
|
27
|
+
- Need fast bulk error reduction
|
|
29
28
|
|
|
30
29
|
---
|
|
31
30
|
|
|
32
|
-
## Execution Instructions (
|
|
31
|
+
## Execution Instructions (Follow These Steps)
|
|
33
32
|
|
|
34
|
-
### Step 1: Parse Arguments
|
|
33
|
+
### Step 1: Parse Arguments and Initialize
|
|
34
|
+
|
|
35
|
+
**YOU SHOULD:** Parse the command arguments and set up session tracking.
|
|
35
36
|
|
|
36
37
|
```bash
|
|
37
|
-
#
|
|
38
|
-
LANGUAGE="
|
|
39
|
-
LANGUAGE=$(echo "$LANGUAGE" | sed 's/--max-parallel[[:space:]]*[0-9]*//' | sed 's/--max-cycles[[:space:]]*[0-9]*//' | xargs)
|
|
38
|
+
# Extract language from arguments (first word before any flags)
|
|
39
|
+
LANGUAGE="typescript" # or "rust" from user's command
|
|
40
40
|
|
|
41
|
+
# Parse optional flags (use defaults if not provided)
|
|
41
42
|
MAX_PARALLEL=5
|
|
42
43
|
MAX_CYCLES=10
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
--max-parallel=*) MAX_PARALLEL="${arg#*=}" ;;
|
|
47
|
-
--max-cycles=*) MAX_CYCLES="${arg#*=}" ;;
|
|
48
|
-
esac
|
|
49
|
-
done
|
|
50
|
-
|
|
51
|
-
# Validate language
|
|
52
|
-
if [[ ! "$LANGUAGE" =~ ^(rust|typescript|ts)$ ]]; then
|
|
53
|
-
echo "ERROR: Language must be: rust, typescript, ts"
|
|
54
|
-
exit 1
|
|
55
|
-
fi
|
|
56
|
-
|
|
57
|
-
# Normalize typescript
|
|
58
|
-
if [[ "$LANGUAGE" == "ts" ]]; then
|
|
59
|
-
LANGUAGE="typescript"
|
|
60
|
-
fi
|
|
61
|
-
|
|
62
|
-
SESSION_ID="cfn-fix-$(date +%s%N | tail -c 7)-${RANDOM}"
|
|
45
|
+
# Generate unique session ID
|
|
46
|
+
SESSION_ID="cfn-fix-$(date +%s | tail -c 6)-${RANDOM}"
|
|
63
47
|
echo "Session ID: $SESSION_ID | Language: $LANGUAGE | Max Parallel: $MAX_PARALLEL"
|
|
64
48
|
```
|
|
65
49
|
|
|
66
|
-
|
|
50
|
+
**VALIDATE:** Language must be "rust", "typescript", or "ts"
|
|
67
51
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
agentId: string;
|
|
80
|
-
taskId: string;
|
|
81
|
-
}>();
|
|
82
|
-
|
|
83
|
-
const phase2Queue: string[] = [];
|
|
84
|
-
let currentCycle = 0;
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
### Step 2: Get Error Files
|
|
55
|
+
|
|
56
|
+
**YOU SHOULD:** Run the appropriate type checker and get files with errors.
|
|
57
|
+
|
|
58
|
+
**For Rust:**
|
|
59
|
+
```bash
|
|
60
|
+
cd [PROJECT_ROOT]
|
|
61
|
+
# Cargo errors: file paths are on lines starting with "-->"
|
|
62
|
+
SQLX_OFFLINE=true cargo check 2>&1 | grep "^\s*-->" | awk '{print $2}' | awk -F':' '{print $1}' | sort | uniq -c | sort -rn
|
|
85
63
|
```
|
|
86
64
|
|
|
87
|
-
|
|
65
|
+
**For TypeScript (tsc):**
|
|
66
|
+
```bash
|
|
67
|
+
cd [PROJECT_ROOT]
|
|
68
|
+
# TypeScript compiler errors: file paths before first parenthesis
|
|
69
|
+
npm run typecheck 2>&1 | grep "error TS" | awk -F'(' '{print $1}' | sort | uniq -c | sort -rn
|
|
70
|
+
```
|
|
88
71
|
|
|
72
|
+
**For TypeScript (ESLint):**
|
|
89
73
|
```bash
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
sort | uniq -c | sort -rn | \
|
|
96
|
-
awk '{print $2}')
|
|
74
|
+
cd [PROJECT_ROOT]
|
|
75
|
+
# ESLint: file paths are on separate lines, extract .ts/.tsx files
|
|
76
|
+
npm run lint 2>&1 > /tmp/eslint-output.txt
|
|
77
|
+
grep -B1 "error" /tmp/eslint-output.txt | grep -v "error\|--" | grep "\.tsx\?$" | sort | uniq -c | sort -rn
|
|
78
|
+
```
|
|
97
79
|
|
|
98
|
-
|
|
99
|
-
|
|
80
|
+
**Alternative (Universal TypeScript/ESLint parser):**
|
|
81
|
+
```bash
|
|
82
|
+
# Save full output first
|
|
83
|
+
npm run lint 2>&1 > /tmp/lint-output.txt || npm run typecheck 2>&1 > /tmp/lint-output.txt
|
|
84
|
+
|
|
85
|
+
# Parse with Python for robust extraction
|
|
86
|
+
python3 << 'PARSE_SCRIPT'
|
|
87
|
+
import re
|
|
88
|
+
from collections import defaultdict
|
|
89
|
+
|
|
90
|
+
error_counts = defaultdict(int)
|
|
91
|
+
current_file = None
|
|
92
|
+
|
|
93
|
+
with open('/tmp/lint-output.txt', 'r') as f:
|
|
94
|
+
for line in f:
|
|
95
|
+
# ESLint format: file path on its own line
|
|
96
|
+
if line.strip().endswith('.ts') or line.strip().endswith('.tsx'):
|
|
97
|
+
current_file = line.strip()
|
|
98
|
+
# ESLint error line
|
|
99
|
+
elif re.search(r'^\s+\d+:\d+\s+(error|warning)', line) and current_file:
|
|
100
|
+
error_counts[current_file] += 1
|
|
101
|
+
# TSC format: file.ts(line,col): error TS
|
|
102
|
+
elif match := re.match(r'^(.+\.tsx?)\(\d+,\d+\):\s+error', line):
|
|
103
|
+
error_counts[match.group(1)] += 1
|
|
104
|
+
|
|
105
|
+
# Print sorted by error count
|
|
106
|
+
for file, count in sorted(error_counts.items(), key=lambda x: -x[1])[:30]:
|
|
107
|
+
print(f"{count:6d} {file}")
|
|
108
|
+
PARSE_SCRIPT
|
|
109
|
+
```
|
|
100
110
|
|
|
101
|
-
|
|
102
|
-
if [[ "$LANGUAGE" == "typescript" ]]; then
|
|
103
|
-
ERROR_FILES=$(npm run type-check 2>&1 | \
|
|
104
|
-
grep "error TS" | \
|
|
105
|
-
awk -F'(' '{print $1}' | \
|
|
106
|
-
sort | uniq -c | sort -rn | \
|
|
107
|
-
awk '{print $2}')
|
|
108
|
-
|
|
109
|
-
TOTAL_ERRORS=$(npm run type-check 2>&1 | grep -c "error TS")
|
|
110
|
-
fi
|
|
111
|
-
|
|
112
|
-
echo "Found $TOTAL_ERRORS errors across $(echo "$ERROR_FILES" | wc -l) files"
|
|
113
|
-
|
|
114
|
-
# Initialize file state
|
|
115
|
-
for file in $ERROR_FILES; do
|
|
116
|
-
fileState.set(file, {
|
|
117
|
-
attempts: 0,
|
|
118
|
-
status: 'queued',
|
|
119
|
-
agentId: null,
|
|
120
|
-
lastError: null
|
|
121
|
-
});
|
|
122
|
-
done
|
|
111
|
+
**OUTPUT FORMAT:**
|
|
123
112
|
```
|
|
113
|
+
45 src/api/handler.ts
|
|
114
|
+
32 src/db/models.ts
|
|
115
|
+
18 src/utils/helpers.ts
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**YOU SHOULD:** Store this list and track state for each file:
|
|
119
|
+
- `attempts`: 0-2 (retry counter)
|
|
120
|
+
- `status`: "queued" | "in_progress" | "success" | "defer"
|
|
121
|
+
- `agentId`: null | "agent-session-file"
|
|
122
|
+
|
|
123
|
+
---
|
|
124
124
|
|
|
125
|
-
### Step
|
|
125
|
+
### Step 3: Spawn Agents (Continuous Loop)
|
|
126
|
+
|
|
127
|
+
**YOU SHOULD:** Spawn agents continuously, maintaining exactly 5 active agents at any time.
|
|
128
|
+
|
|
129
|
+
**Agent Spawn Pattern:**
|
|
126
130
|
|
|
127
131
|
```typescript
|
|
128
|
-
//
|
|
129
|
-
while (fileQueue.length > 0 || activeAgents.
|
|
132
|
+
// While there are files to process OR active agents running:
|
|
133
|
+
while (fileQueue.length > 0 || activeAgents.length > 0) {
|
|
130
134
|
|
|
131
|
-
// Spawn
|
|
132
|
-
while (activeAgents.
|
|
135
|
+
// Spawn up to 5 agents
|
|
136
|
+
while (activeAgents.length < MAX_PARALLEL && fileQueue.length > 0) {
|
|
133
137
|
const file = fileQueue.shift();
|
|
134
|
-
const
|
|
138
|
+
const agentId = `${LANGUAGE}-fixer-${SESSION_ID}-${sanitize(file)}`;
|
|
139
|
+
|
|
140
|
+
// Use Task tool with background=true
|
|
141
|
+
const taskId = Task("rust-developer" OR "typescript-specialist",
|
|
142
|
+
`[SEE AGENT PROMPT BELOW]`,
|
|
143
|
+
{run_in_background: true}
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
// Track this agent
|
|
147
|
+
activeAgents.push({file, agentId, taskId, attempts: 1});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Monitor agents (non-blocking check)
|
|
151
|
+
for each activeAgent {
|
|
152
|
+
const result = TaskOutput(agent.taskId, {block: false, timeout: 0});
|
|
153
|
+
|
|
154
|
+
if (result.status === 'completed') {
|
|
155
|
+
// Parse result: SUCCESS | RETRY | DEFER
|
|
156
|
+
if (result.output.includes('SUCCESS')) {
|
|
157
|
+
// File fixed! Remove from queue
|
|
158
|
+
} else if (agent.attempts < 2) {
|
|
159
|
+
// Retry: add back to queue, increment attempts
|
|
160
|
+
fileQueue.push(file);
|
|
161
|
+
fileState[file].attempts++;
|
|
162
|
+
} else {
|
|
163
|
+
// 2 attempts failed: defer to Phase 2
|
|
164
|
+
phase2Queue.push(file);
|
|
165
|
+
}
|
|
135
166
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
continue;
|
|
167
|
+
// Remove from active agents (frees slot for next file)
|
|
168
|
+
activeAgents.remove(agent);
|
|
139
169
|
}
|
|
170
|
+
}
|
|
140
171
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
state.agentId = agentId;
|
|
172
|
+
// Small delay to prevent tight loop
|
|
173
|
+
sleep(1 second);
|
|
174
|
+
}
|
|
175
|
+
```
|
|
146
176
|
|
|
147
|
-
|
|
177
|
+
**AGENT PROMPT TEMPLATE:**
|
|
148
178
|
|
|
149
|
-
|
|
179
|
+
Use this exact prompt structure for spawned agents:
|
|
180
|
+
|
|
181
|
+
```
|
|
150
182
|
AGENT_ID="${agentId}"
|
|
151
183
|
FILE_PATH="${file}"
|
|
152
184
|
SESSION_ID="${SESSION_ID}"
|
|
153
|
-
ATTEMPT=${
|
|
185
|
+
ATTEMPT=${attempts}/2
|
|
154
186
|
|
|
155
|
-
TASK: Fix compilation errors in a single file using Cerebras acceleration
|
|
187
|
+
TASK: Fix compilation errors in a single file using Cerebras acceleration.
|
|
156
188
|
|
|
157
189
|
WORKFLOW:
|
|
158
190
|
1. Read file: ${file}
|
|
159
191
|
|
|
160
|
-
2. Call single-file
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
192
|
+
2. Call Cerebras single-file fixer:
|
|
193
|
+
[FOR RUST]
|
|
194
|
+
npx tsx /path/to/cerebras-gated-fixer-v2.ts --file="${file}" --agent-id="${agentId}"
|
|
195
|
+
|
|
196
|
+
[FOR TYPESCRIPT]
|
|
197
|
+
npx tsx /path/to/typescript-gated-fixer-v2.ts --file="${file}" --agent-id="${agentId}"
|
|
164
198
|
|
|
165
199
|
3. Validate with post-edit pipeline:
|
|
166
|
-
./.claude/hooks/cfn-invoke-post-edit.sh "${
|
|
200
|
+
./.claude/hooks/cfn-invoke-post-edit.sh "${file}" --agent-id "${agentId}"
|
|
167
201
|
|
|
168
202
|
4. Return status:
|
|
169
203
|
- If post-edit validation PASSES (exit 0): Return "SUCCESS"
|
|
170
|
-
- If post-edit validation FAILS (exit 1): Return "RETRY" (
|
|
204
|
+
- If post-edit validation FAILS (exit 1): Return "RETRY" (attempt 1) or "DEFER" (attempt 2)
|
|
171
205
|
|
|
172
|
-
CEREBRAS GATES
|
|
206
|
+
CEREBRAS GATES:
|
|
173
207
|
- Phase 1a: Cerebras generates fix
|
|
174
|
-
- Phase 1b:
|
|
175
|
-
- Up to 3 retries
|
|
208
|
+
- Phase 1b: 12 gates validate (LineCount, FnSignature, ImportDup, BraceBalance, SemanticDiff, OrphanedCode, ImportPath, PatternDup, ImplLocation, TypeCast, MatchArm, Regression)
|
|
209
|
+
- Up to 3 retries per gate rejection
|
|
176
210
|
|
|
177
211
|
CRITICAL RESTRICTIONS:
|
|
178
|
-
- DO NOT run eslint, cargo clippy, cargo
|
|
179
|
-
- DO NOT run cargo check on the entire project
|
|
180
|
-
- DO NOT run npm run type-check on the entire project
|
|
212
|
+
- DO NOT run eslint, cargo clippy, cargo check, or npm run typecheck on ENTIRE codebase
|
|
181
213
|
- Work ONLY on file: ${file}
|
|
182
|
-
- Use Cerebras
|
|
214
|
+
- Use Cerebras for speed
|
|
183
215
|
- Post-edit validation runs on this file only
|
|
184
216
|
|
|
185
|
-
POST-EDIT VALIDATION (MANDATORY):
|
|
186
|
-
After Cerebras applies fixes, run:
|
|
187
|
-
./.claude/hooks/cfn-invoke-post-edit.sh "${FILE_PATH}" --agent-id "${AGENT_ID}"
|
|
188
|
-
|
|
189
217
|
SUCCESS CRITERIA:
|
|
190
218
|
Post-edit pipeline returns exit code 0
|
|
191
219
|
|
|
192
|
-
RETURN
|
|
193
|
-
{
|
|
194
|
-
"status": "SUCCESS" | "RETRY" | "DEFER",
|
|
195
|
-
"file": "${file}",
|
|
196
|
-
"attempts": ${state.attempts},
|
|
197
|
-
"errors_fixed": <number>,
|
|
198
|
-
"validation_passed": <boolean>
|
|
199
|
-
}
|
|
200
|
-
`, {run_in_background: true});
|
|
201
|
-
|
|
202
|
-
// Track active agent
|
|
203
|
-
activeAgents.set(taskId, {
|
|
204
|
-
file,
|
|
205
|
-
agentId,
|
|
206
|
-
taskId
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
echo(`Spawned agent ${agentId} for ${file} (attempt ${state.attempts}/2)`);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// Monitor active agents (continuous)
|
|
213
|
-
if (activeAgents.size > 0) {
|
|
214
|
-
// Check for completed agents (non-blocking)
|
|
215
|
-
for (const [taskId, agent] of activeAgents.entries()) {
|
|
216
|
-
const result = TaskOutput(taskId, {block: false, timeout: 0});
|
|
217
|
-
|
|
218
|
-
if (result.status === 'completed') {
|
|
219
|
-
const state = fileState.get(agent.file);
|
|
220
|
-
|
|
221
|
-
// Parse result
|
|
222
|
-
if (result.output.includes('SUCCESS')) {
|
|
223
|
-
state.status = 'success';
|
|
224
|
-
echo(`✓ ${agent.file} - Fixed successfully`);
|
|
225
|
-
} else if (result.output.includes('DEFER') || state.attempts >= 2) {
|
|
226
|
-
state.status = 'defer_to_phase2';
|
|
227
|
-
phase2Queue.push(agent.file);
|
|
228
|
-
echo(`→ ${agent.file} - Deferred to Phase 2 (${state.attempts} attempts)`);
|
|
229
|
-
} else {
|
|
230
|
-
// Retry
|
|
231
|
-
state.status = 'queued';
|
|
232
|
-
fileQueue.push(agent.file);
|
|
233
|
-
echo(`↻ ${agent.file} - Retrying (attempt ${state.attempts + 1}/2)`);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// Remove from active agents
|
|
237
|
-
activeAgents.delete(taskId);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// Small delay to prevent tight loop
|
|
242
|
-
await sleep(1000);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
220
|
+
RETURN: Print "SUCCESS" or "DEFER" clearly in your final output.
|
|
245
221
|
```
|
|
246
222
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
```bash
|
|
250
|
-
# Wait for all agents to complete
|
|
251
|
-
echo "Waiting for all agents to complete cycle $currentCycle..."
|
|
252
|
-
|
|
253
|
-
while activeAgents.size > 0; do
|
|
254
|
-
# Block until any agent completes
|
|
255
|
-
for (const [taskId, agent] of activeAgents.entries()) {
|
|
256
|
-
const result = TaskOutput(taskId, {block: true, timeout: 30000});
|
|
257
|
-
|
|
258
|
-
if (result.status === 'completed') {
|
|
259
|
-
// Process result (same as Step 4)
|
|
260
|
-
activeAgents.delete(taskId);
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
done
|
|
265
|
-
|
|
266
|
-
# Rerun error check
|
|
267
|
-
echo "Cycle $currentCycle complete. Rechecking errors..."
|
|
223
|
+
---
|
|
268
224
|
|
|
269
|
-
|
|
270
|
-
NEW_ERROR_COUNT=$(SQLX_OFFLINE=true cargo check 2>&1 | grep -c "^error\[")
|
|
271
|
-
else
|
|
272
|
-
NEW_ERROR_COUNT=$(npm run type-check 2>&1 | grep -c "error TS")
|
|
273
|
-
fi
|
|
225
|
+
### Step 4: Cycle Completion and Phase Transition
|
|
274
226
|
|
|
275
|
-
|
|
227
|
+
**YOU SHOULD:** After all agents complete (activeAgents.length === 0), check if Phase 2 is needed.
|
|
276
228
|
|
|
277
|
-
|
|
278
|
-
PREV_ERROR_COUNT=$TOTAL_ERRORS
|
|
279
|
-
TOTAL_ERRORS=$NEW_ERROR_COUNT
|
|
280
|
-
currentCycle=$((currentCycle + 1))
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
### Step 6: Phase Transition Logic
|
|
229
|
+
**Recheck Error Count:**
|
|
284
230
|
|
|
285
231
|
```bash
|
|
286
|
-
#
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
# Condition 1: Error count below threshold
|
|
290
|
-
if [ $TOTAL_ERRORS -lt 40 ]; then
|
|
291
|
-
echo "Error count below 40 - proceeding to Phase 2"
|
|
292
|
-
PROCEED_TO_PHASE2=true
|
|
293
|
-
fi
|
|
294
|
-
|
|
295
|
-
# Condition 2: No progress made
|
|
296
|
-
if [ $TOTAL_ERRORS -eq $PREV_ERROR_COUNT ] && [ $currentCycle -gt 1 ]; then
|
|
297
|
-
echo "No progress made - proceeding to Phase 2"
|
|
298
|
-
PROCEED_TO_PHASE2=true
|
|
299
|
-
fi
|
|
300
|
-
|
|
301
|
-
# Condition 3: Max cycles reached
|
|
302
|
-
if [ $currentCycle -ge $MAX_CYCLES ]; then
|
|
303
|
-
echo "Max cycles reached - proceeding to Phase 2"
|
|
304
|
-
PROCEED_TO_PHASE2=true
|
|
305
|
-
fi
|
|
306
|
-
|
|
307
|
-
# Condition 4: All files processed
|
|
308
|
-
if [ ${#fileQueue[@]} -eq 0 ] && [ ${#phase2Queue[@]} -eq 0 ]; then
|
|
309
|
-
echo "All files processed successfully!"
|
|
310
|
-
PROCEED_TO_PHASE2=false
|
|
311
|
-
fi
|
|
312
|
-
|
|
313
|
-
if [ "$PROCEED_TO_PHASE2" = true ]; then
|
|
314
|
-
# Proceed to Phase 2
|
|
315
|
-
echo "=== PHASE 2: Dedicated Agent Cleanup ==="
|
|
316
|
-
else
|
|
317
|
-
# Continue next cycle
|
|
318
|
-
echo "=== Continuing Phase 1: Cycle $currentCycle ==="
|
|
319
|
-
# Go back to Step 3 (get new error files)
|
|
320
|
-
fi
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
### Step 7: Phase 2 (Dedicated Agent Cleanup)
|
|
232
|
+
# Rust
|
|
233
|
+
SQLX_OFFLINE=true cargo check 2>&1 | grep -c "^error\["
|
|
324
234
|
|
|
325
|
-
|
|
326
|
-
|
|
235
|
+
# TypeScript
|
|
236
|
+
npm run typecheck 2>&1 | grep -c "error TS"
|
|
237
|
+
```
|
|
327
238
|
|
|
328
|
-
|
|
239
|
+
**Phase 2 Triggers:**
|
|
240
|
+
- Error count < 40
|
|
241
|
+
- No progress made (same error count as before)
|
|
242
|
+
- Max cycles reached
|
|
243
|
+
- All files processed (queue empty, no deferrals)
|
|
329
244
|
|
|
330
|
-
|
|
331
|
-
PHASE2_FILES=$(echo "$ERROR_FILES" | head -20)
|
|
245
|
+
**IF Phase 2 needed:**
|
|
332
246
|
|
|
333
|
-
|
|
334
|
-
|
|
247
|
+
```typescript
|
|
248
|
+
// Spawn dedicated cleanup agent (NOT background - visible)
|
|
249
|
+
Task("rust-developer" OR "typescript-specialist", `
|
|
335
250
|
AGENT_ID="${LANGUAGE}-phase2-${SESSION_ID}"
|
|
336
251
|
|
|
337
252
|
TASK: Fix remaining compilation errors after Phase 1 bulk processing.
|
|
338
253
|
|
|
339
254
|
CONTEXT:
|
|
340
|
-
- Phase 1
|
|
341
|
-
-
|
|
342
|
-
-
|
|
255
|
+
- Phase 1 processed files with Cerebras acceleration
|
|
256
|
+
- ${ERROR_COUNT} errors remaining
|
|
257
|
+
- Errors require context-aware fixes
|
|
343
258
|
|
|
344
|
-
WORKING DIRECTORY:
|
|
345
|
-
${LANGUAGE === 'rust' ? 'RUST_PROJECT_PATH' : 'TYPESCRIPT_PROJECT_PATH'}
|
|
259
|
+
WORKING DIRECTORY: [PROJECT_ROOT]
|
|
346
260
|
|
|
347
|
-
STEP 1: Get
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
: 'npm run type-check 2>&1 | grep -E "error TS" | sort | uniq -c | sort -rn'}
|
|
261
|
+
STEP 1: Get error locations
|
|
262
|
+
[RUST] SQLX_OFFLINE=true cargo check 2>&1 | grep -E "^error\\[E" | sort | uniq -c
|
|
263
|
+
[TYPESCRIPT] npm run typecheck 2>&1 | grep -E "error TS" | sort | uniq -c
|
|
351
264
|
|
|
352
|
-
STEP 2: Fix each
|
|
265
|
+
STEP 2: Fix each file
|
|
353
266
|
1. Read FULL file for context
|
|
354
|
-
2. Identify root cause (not
|
|
355
|
-
3. Apply minimal fix
|
|
267
|
+
2. Identify root cause (not symptom)
|
|
268
|
+
3. Apply minimal fix
|
|
356
269
|
4. Run post-edit validation:
|
|
357
|
-
./.claude/hooks/cfn-invoke-post-edit.sh "
|
|
270
|
+
./.claude/hooks/cfn-invoke-post-edit.sh "$FILE" --agent-id "${AGENT_ID}"
|
|
358
271
|
5. Verify with compiler after EACH file
|
|
359
272
|
|
|
360
273
|
RULES:
|
|
361
274
|
- Read FULL file before editing
|
|
362
|
-
- Preserve ALL existing imports
|
|
363
|
-
-
|
|
364
|
-
- Fix root causes first (cascading errors will resolve)
|
|
275
|
+
- Preserve ALL existing imports
|
|
276
|
+
- Fix root causes first
|
|
365
277
|
- Verify after EACH file
|
|
366
278
|
- Run post-edit pipeline after EACH edit
|
|
367
279
|
|
|
368
280
|
RESTRICTIONS:
|
|
369
|
-
- DO NOT run
|
|
281
|
+
- DO NOT run linters on entire codebase
|
|
370
282
|
- Work on one file at a time
|
|
371
|
-
- Validate each fix before moving to next
|
|
372
|
-
|
|
373
|
-
COMMON ERROR TYPES:
|
|
374
|
-
${LANGUAGE === 'rust'
|
|
375
|
-
? '- E0308 (type mismatch): Add explicit casts or fix generics\n- E0412/E0433/E0425 (missing type/import): Add use statements\n- E0599 (wrong method): Fix method chain\n- E0277 (trait not implemented): Add trait implementations\n- E0382 (borrow checker): Fix ownership issues'
|
|
376
|
-
: '- TS2307 (module not found): Fix import paths\n- TS2322 (type mismatch): Add type annotations\n- TS2339 (property not exists): Add interface definitions\n- TS7006 (implicit any): Add explicit types\n- TS2688 (cannot find type): Install @types packages'}
|
|
377
283
|
|
|
378
284
|
Report final error count when done.
|
|
379
285
|
`)
|
|
380
|
-
|
|
381
|
-
fi
|
|
382
286
|
```
|
|
383
287
|
|
|
384
288
|
---
|
|
385
289
|
|
|
386
|
-
##
|
|
290
|
+
## Important Notes
|
|
291
|
+
|
|
292
|
+
### State Tracking
|
|
387
293
|
|
|
388
|
-
|
|
294
|
+
**YOU SHOULD** maintain these data structures in memory:
|
|
389
295
|
|
|
390
296
|
```typescript
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
lastError: string | null; // Last error message
|
|
297
|
+
// File state
|
|
298
|
+
fileState = {
|
|
299
|
+
"src/api.ts": {attempts: 1, status: "in_progress", agentId: "ts-fixer-123-api"},
|
|
300
|
+
"src/db.ts": {attempts: 2, status: "defer", agentId: null}
|
|
396
301
|
}
|
|
397
302
|
|
|
398
|
-
|
|
303
|
+
// Active agents
|
|
304
|
+
activeAgents = [
|
|
305
|
+
{file: "src/api.ts", agentId: "ts-fixer-123-api", taskId: "abc123", attempts: 1}
|
|
306
|
+
]
|
|
307
|
+
|
|
308
|
+
// Phase 2 queue
|
|
309
|
+
phase2Queue = ["src/db.ts", "src/models.ts"]
|
|
399
310
|
```
|
|
400
311
|
|
|
401
|
-
###
|
|
312
|
+
### Error Handling
|
|
402
313
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
agentId: string; // Agent identifier
|
|
407
|
-
taskId: string; // TaskOutput ID for monitoring
|
|
408
|
-
}
|
|
314
|
+
- If agent fails to spawn: Log error, skip file, continue
|
|
315
|
+
- If TaskOutput times out: Treat as DEFER, add to Phase 2
|
|
316
|
+
- If post-edit hook missing: Warn user, continue without validation
|
|
409
317
|
|
|
410
|
-
|
|
411
|
-
|
|
318
|
+
### Progress Reporting
|
|
319
|
+
|
|
320
|
+
**YOU SHOULD** periodically report progress to user:
|
|
321
|
+
- "Spawned agent 3/5 for src/api.ts (attempt 1/2)"
|
|
322
|
+
- "Agent completed: src/utils.ts - SUCCESS"
|
|
323
|
+
- "Agent completed: src/db.ts - DEFER (2 attempts failed)"
|
|
324
|
+
- "Cycle 1 complete: 45 → 23 errors (-22)"
|
|
412
325
|
|
|
413
326
|
---
|
|
414
327
|
|
|
415
328
|
## Related Documentation
|
|
416
329
|
|
|
417
|
-
- **
|
|
330
|
+
- **Cerebras Rust Fixer**: `.claude/skills/cfn-compilation-error-fixer/lib/fixer/cerebras-gated-fixer-v2.ts`
|
|
331
|
+
- **Cerebras TypeScript Fixer**: `.claude/skills/cfn-compilation-error-fixer/lib/fixer/typescript-gated-fixer-v2.ts`
|
|
418
332
|
- **Post-Edit Pipeline**: `.claude/hooks/cfn-invoke-post-edit.sh`
|
|
419
|
-
- **Cerebras Gated Fixer (Rust)**: `.claude/skills/cfn-compilation-error-fixer/lib/fixer/cerebras-gated-fixer-v2.ts`
|
|
420
|
-
- **Cerebras Gated Fixer (TypeScript)**: `.claude/skills/cfn-compilation-error-fixer/lib/fixer/typescript-gated-fixer-v2.ts`
|
|
421
333
|
- **Task Mode Reference**: `.claude/commands/cfn-loop-task.md`
|
|
422
334
|
|
|
423
335
|
---
|
|
424
336
|
|
|
425
|
-
|
|
337
|
+
## Version History
|
|
338
|
+
|
|
339
|
+
- v1.2.0 (2025-12-21) - Fixed error file extraction patterns for Rust and TypeScript/ESLint
|
|
340
|
+
- v1.1.0 (2025-12-21) - Clarified instructions, removed pseudocode confusion
|
|
426
341
|
- v1.0.0 (2025-12-21) - Initial coordination mode implementation
|
|
@@ -12,11 +12,15 @@
|
|
|
12
12
|
* - Targeted crate compile testing
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
+
import * as dotenv from 'dotenv';
|
|
15
16
|
import createCerebrasClient from './cerebras-wrapper.js';
|
|
16
17
|
import * as fs from 'fs';
|
|
17
18
|
import * as path from 'path';
|
|
18
19
|
import { execSync } from 'child_process';
|
|
19
20
|
|
|
21
|
+
// Load environment variables from .env file
|
|
22
|
+
dotenv.config();
|
|
23
|
+
|
|
20
24
|
// ============== CONFIGURATION ==============
|
|
21
25
|
|
|
22
26
|
// Parse --file and --agent-id parameters
|
|
@@ -9,10 +9,14 @@
|
|
|
9
9
|
* - Phase 2: Dedicated agent cleanup (high quality)
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import * as dotenv from 'dotenv';
|
|
12
13
|
import Cerebras from '@cerebras/cerebras_cloud_sdk';
|
|
13
14
|
import * as fs from 'fs';
|
|
14
15
|
import * as path from 'path';
|
|
15
16
|
import { execFileSync, spawnSync } from 'child_process';
|
|
17
|
+
|
|
18
|
+
// Load environment variables from .env file
|
|
19
|
+
dotenv.config();
|
|
16
20
|
import {
|
|
17
21
|
gateLineCountDelta,
|
|
18
22
|
gateMethodSignature,
|
|
@@ -167,9 +171,9 @@ function validateApiKey(apiKey: string | undefined): boolean {
|
|
|
167
171
|
return false;
|
|
168
172
|
}
|
|
169
173
|
|
|
170
|
-
// Check for basic format (starts with sk- and reasonable length)
|
|
171
|
-
if (!apiKey.startsWith('sk-') || apiKey.length < 20) {
|
|
172
|
-
console.error('❌ Security: Invalid API key format');
|
|
174
|
+
// Check for basic format (starts with sk- or csk- and reasonable length)
|
|
175
|
+
if ((!apiKey.startsWith('sk-') && !apiKey.startsWith('csk-')) || apiKey.length < 20) {
|
|
176
|
+
console.error('❌ Security: Invalid API key format (expected sk-* or csk-*)');
|
|
173
177
|
return false;
|
|
174
178
|
}
|
|
175
179
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-flow-novice",
|
|
3
|
-
"version": "2.18.
|
|
3
|
+
"version": "2.18.32",
|
|
4
4
|
"description": "Claude Flow Novice - Advanced orchestration platform for multi-agent AI workflows with CFN Loop architecture\n\nIncludes Local RuVector Accelerator and all CFN skills for complete functionality.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|