claude-flow-novice 2.18.28 → 2.18.30

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.
@@ -0,0 +1,300 @@
1
+ ---
2
+ description: "Coordinate agents to fix compilation errors using post-edit validation and Cerebras gates"
3
+ argument-hint: "<language> [--max-parallel=5] [--max-cycles=10]"
4
+ allowed-tools: ["Task", "TaskOutput", "TodoWrite", "Read", "Bash"]
5
+ ---
6
+
7
+ # CFN Fix Errors - Agent Coordination Mode
8
+
9
+ **Version:** 1.1.0 | **Date:** 2025-12-21 | **Status:** Production Ready
10
+
11
+ ## Quick Overview
12
+
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
+
15
+ ### Key Features
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
22
+
23
+ ### When to Use
24
+ - 20+ compilation errors
25
+ - Errors are mostly mechanical (imports, types, syntax)
26
+ - Want visibility into agent progress
27
+ - Need fast bulk error reduction
28
+
29
+ ---
30
+
31
+ ## Execution Instructions (Follow These Steps)
32
+
33
+ ### Step 1: Parse Arguments and Initialize
34
+
35
+ **YOU SHOULD:** Parse the command arguments and set up session tracking.
36
+
37
+ ```bash
38
+ # Extract language from arguments (first word before any flags)
39
+ LANGUAGE="typescript" # or "rust" from user's command
40
+
41
+ # Parse optional flags (use defaults if not provided)
42
+ MAX_PARALLEL=5
43
+ MAX_CYCLES=10
44
+
45
+ # Generate unique session ID
46
+ SESSION_ID="cfn-fix-$(date +%s | tail -c 6)-${RANDOM}"
47
+ echo "Session ID: $SESSION_ID | Language: $LANGUAGE | Max Parallel: $MAX_PARALLEL"
48
+ ```
49
+
50
+ **VALIDATE:** Language must be "rust", "typescript", or "ts"
51
+
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
+ SQLX_OFFLINE=true cargo check 2>&1 | grep "^error\[" | awk -F':' '{print $1}' | sort | uniq -c | sort -rn
62
+ ```
63
+
64
+ **For TypeScript:**
65
+ ```bash
66
+ cd [PROJECT_ROOT]
67
+ # Try common script names: typecheck, type-check, or tsc
68
+ npm run typecheck 2>&1 | grep "error TS" | awk -F'(' '{print $1}' | sort | uniq -c | sort -rn
69
+ ```
70
+
71
+ **OUTPUT FORMAT:**
72
+ ```
73
+ 45 src/api/handler.ts
74
+ 32 src/db/models.ts
75
+ 18 src/utils/helpers.ts
76
+ ```
77
+
78
+ **YOU SHOULD:** Store this list and track state for each file:
79
+ - `attempts`: 0-2 (retry counter)
80
+ - `status`: "queued" | "in_progress" | "success" | "defer"
81
+ - `agentId`: null | "agent-session-file"
82
+
83
+ ---
84
+
85
+ ### Step 3: Spawn Agents (Continuous Loop)
86
+
87
+ **YOU SHOULD:** Spawn agents continuously, maintaining exactly 5 active agents at any time.
88
+
89
+ **Agent Spawn Pattern:**
90
+
91
+ ```typescript
92
+ // While there are files to process OR active agents running:
93
+ while (fileQueue.length > 0 || activeAgents.length > 0) {
94
+
95
+ // Spawn up to 5 agents
96
+ while (activeAgents.length < MAX_PARALLEL && fileQueue.length > 0) {
97
+ const file = fileQueue.shift();
98
+ const agentId = `${LANGUAGE}-fixer-${SESSION_ID}-${sanitize(file)}`;
99
+
100
+ // Use Task tool with background=true
101
+ const taskId = Task("rust-developer" OR "typescript-specialist",
102
+ `[SEE AGENT PROMPT BELOW]`,
103
+ {run_in_background: true}
104
+ );
105
+
106
+ // Track this agent
107
+ activeAgents.push({file, agentId, taskId, attempts: 1});
108
+ }
109
+
110
+ // Monitor agents (non-blocking check)
111
+ for each activeAgent {
112
+ const result = TaskOutput(agent.taskId, {block: false, timeout: 0});
113
+
114
+ if (result.status === 'completed') {
115
+ // Parse result: SUCCESS | RETRY | DEFER
116
+ if (result.output.includes('SUCCESS')) {
117
+ // File fixed! Remove from queue
118
+ } else if (agent.attempts < 2) {
119
+ // Retry: add back to queue, increment attempts
120
+ fileQueue.push(file);
121
+ fileState[file].attempts++;
122
+ } else {
123
+ // 2 attempts failed: defer to Phase 2
124
+ phase2Queue.push(file);
125
+ }
126
+
127
+ // Remove from active agents (frees slot for next file)
128
+ activeAgents.remove(agent);
129
+ }
130
+ }
131
+
132
+ // Small delay to prevent tight loop
133
+ sleep(1 second);
134
+ }
135
+ ```
136
+
137
+ **AGENT PROMPT TEMPLATE:**
138
+
139
+ Use this exact prompt structure for spawned agents:
140
+
141
+ ```
142
+ AGENT_ID="${agentId}"
143
+ FILE_PATH="${file}"
144
+ SESSION_ID="${SESSION_ID}"
145
+ ATTEMPT=${attempts}/2
146
+
147
+ TASK: Fix compilation errors in a single file using Cerebras acceleration.
148
+
149
+ WORKFLOW:
150
+ 1. Read file: ${file}
151
+
152
+ 2. Call Cerebras single-file fixer:
153
+ [FOR RUST]
154
+ npx tsx /path/to/cerebras-gated-fixer-v2.ts --file="${file}" --agent-id="${agentId}"
155
+
156
+ [FOR TYPESCRIPT]
157
+ npx tsx /path/to/typescript-gated-fixer-v2.ts --file="${file}" --agent-id="${agentId}"
158
+
159
+ 3. Validate with post-edit pipeline:
160
+ ./.claude/hooks/cfn-invoke-post-edit.sh "${file}" --agent-id "${agentId}"
161
+
162
+ 4. Return status:
163
+ - If post-edit validation PASSES (exit 0): Return "SUCCESS"
164
+ - If post-edit validation FAILS (exit 1): Return "RETRY" (attempt 1) or "DEFER" (attempt 2)
165
+
166
+ CEREBRAS GATES:
167
+ - Phase 1a: Cerebras generates fix
168
+ - Phase 1b: 12 gates validate (LineCount, FnSignature, ImportDup, BraceBalance, SemanticDiff, OrphanedCode, ImportPath, PatternDup, ImplLocation, TypeCast, MatchArm, Regression)
169
+ - Up to 3 retries per gate rejection
170
+
171
+ CRITICAL RESTRICTIONS:
172
+ - DO NOT run eslint, cargo clippy, cargo check, or npm run typecheck on ENTIRE codebase
173
+ - Work ONLY on file: ${file}
174
+ - Use Cerebras for speed
175
+ - Post-edit validation runs on this file only
176
+
177
+ SUCCESS CRITERIA:
178
+ Post-edit pipeline returns exit code 0
179
+
180
+ RETURN: Print "SUCCESS" or "DEFER" clearly in your final output.
181
+ ```
182
+
183
+ ---
184
+
185
+ ### Step 4: Cycle Completion and Phase Transition
186
+
187
+ **YOU SHOULD:** After all agents complete (activeAgents.length === 0), check if Phase 2 is needed.
188
+
189
+ **Recheck Error Count:**
190
+
191
+ ```bash
192
+ # Rust
193
+ SQLX_OFFLINE=true cargo check 2>&1 | grep -c "^error\["
194
+
195
+ # TypeScript
196
+ npm run typecheck 2>&1 | grep -c "error TS"
197
+ ```
198
+
199
+ **Phase 2 Triggers:**
200
+ - Error count < 40
201
+ - No progress made (same error count as before)
202
+ - Max cycles reached
203
+ - All files processed (queue empty, no deferrals)
204
+
205
+ **IF Phase 2 needed:**
206
+
207
+ ```typescript
208
+ // Spawn dedicated cleanup agent (NOT background - visible)
209
+ Task("rust-developer" OR "typescript-specialist", `
210
+ AGENT_ID="${LANGUAGE}-phase2-${SESSION_ID}"
211
+
212
+ TASK: Fix remaining compilation errors after Phase 1 bulk processing.
213
+
214
+ CONTEXT:
215
+ - Phase 1 processed files with Cerebras acceleration
216
+ - ${ERROR_COUNT} errors remaining
217
+ - Errors require context-aware fixes
218
+
219
+ WORKING DIRECTORY: [PROJECT_ROOT]
220
+
221
+ STEP 1: Get error locations
222
+ [RUST] SQLX_OFFLINE=true cargo check 2>&1 | grep -E "^error\\[E" | sort | uniq -c
223
+ [TYPESCRIPT] npm run typecheck 2>&1 | grep -E "error TS" | sort | uniq -c
224
+
225
+ STEP 2: Fix each file
226
+ 1. Read FULL file for context
227
+ 2. Identify root cause (not symptom)
228
+ 3. Apply minimal fix
229
+ 4. Run post-edit validation:
230
+ ./.claude/hooks/cfn-invoke-post-edit.sh "$FILE" --agent-id "${AGENT_ID}"
231
+ 5. Verify with compiler after EACH file
232
+
233
+ RULES:
234
+ - Read FULL file before editing
235
+ - Preserve ALL existing imports
236
+ - Fix root causes first
237
+ - Verify after EACH file
238
+ - Run post-edit pipeline after EACH edit
239
+
240
+ RESTRICTIONS:
241
+ - DO NOT run linters on entire codebase
242
+ - Work on one file at a time
243
+
244
+ Report final error count when done.
245
+ `)
246
+ ```
247
+
248
+ ---
249
+
250
+ ## Important Notes
251
+
252
+ ### State Tracking
253
+
254
+ **YOU SHOULD** maintain these data structures in memory:
255
+
256
+ ```typescript
257
+ // File state
258
+ fileState = {
259
+ "src/api.ts": {attempts: 1, status: "in_progress", agentId: "ts-fixer-123-api"},
260
+ "src/db.ts": {attempts: 2, status: "defer", agentId: null}
261
+ }
262
+
263
+ // Active agents
264
+ activeAgents = [
265
+ {file: "src/api.ts", agentId: "ts-fixer-123-api", taskId: "abc123", attempts: 1}
266
+ ]
267
+
268
+ // Phase 2 queue
269
+ phase2Queue = ["src/db.ts", "src/models.ts"]
270
+ ```
271
+
272
+ ### Error Handling
273
+
274
+ - If agent fails to spawn: Log error, skip file, continue
275
+ - If TaskOutput times out: Treat as DEFER, add to Phase 2
276
+ - If post-edit hook missing: Warn user, continue without validation
277
+
278
+ ### Progress Reporting
279
+
280
+ **YOU SHOULD** periodically report progress to user:
281
+ - "Spawned agent 3/5 for src/api.ts (attempt 1/2)"
282
+ - "Agent completed: src/utils.ts - SUCCESS"
283
+ - "Agent completed: src/db.ts - DEFER (2 attempts failed)"
284
+ - "Cycle 1 complete: 45 → 23 errors (-22)"
285
+
286
+ ---
287
+
288
+ ## Related Documentation
289
+
290
+ - **Cerebras Rust Fixer**: `.claude/skills/cfn-compilation-error-fixer/lib/fixer/cerebras-gated-fixer-v2.ts`
291
+ - **Cerebras TypeScript Fixer**: `.claude/skills/cfn-compilation-error-fixer/lib/fixer/typescript-gated-fixer-v2.ts`
292
+ - **Post-Edit Pipeline**: `.claude/hooks/cfn-invoke-post-edit.sh`
293
+ - **Task Mode Reference**: `.claude/commands/cfn-loop-task.md`
294
+
295
+ ---
296
+
297
+ ## Version History
298
+
299
+ - v1.1.0 (2025-12-21) - Clarified instructions, removed pseudocode confusion
300
+ - v1.0.0 (2025-12-21) - Initial coordination mode implementation
@@ -19,6 +19,10 @@ import { execSync } from 'child_process';
19
19
 
20
20
  // ============== CONFIGURATION ==============
21
21
 
22
+ // Parse --file and --agent-id parameters
23
+ const fileArg = process.argv.find(arg => arg.startsWith('--file='));
24
+ const agentIdArg = process.argv.find(arg => arg.startsWith('--agent-id='));
25
+
22
26
  const CONFIG = {
23
27
  maxGlobalIterations: 5,
24
28
  maxFileRetries: 2,
@@ -32,6 +36,8 @@ const CONFIG = {
32
36
  dryRun: process.argv.includes('--dry-run'),
33
37
  patchDir: '/tmp/rust-fix-patches',
34
38
  verbose: process.argv.includes('--verbose'),
39
+ singleFile: fileArg ? fileArg.split('=')[1] : null, // Single-file mode
40
+ agentId: agentIdArg ? agentIdArg.split('=')[1] : null, // Agent ID for coordination mode
35
41
  };
36
42
 
37
43
  // ============== TYPE DEFINITIONS ==============
@@ -1342,6 +1348,12 @@ async function main() {
1342
1348
  console.log(`Layer 3 LLM Review: ${CONFIG.enableLayer3 ? 'ON' : 'OFF'}`);
1343
1349
  console.log(`Clippy: ${CONFIG.enableClippy ? 'ON' : 'OFF'}`);
1344
1350
  console.log(`Dry-Run: ${CONFIG.dryRun ? 'ON' : 'OFF'}`);
1351
+ if (CONFIG.singleFile) {
1352
+ console.log(`Single-File Mode: ${CONFIG.singleFile}`);
1353
+ if (CONFIG.agentId) {
1354
+ console.log(`Agent ID: ${CONFIG.agentId}`);
1355
+ }
1356
+ }
1345
1357
  console.log();
1346
1358
 
1347
1359
  const apiKey = loadCerebrasKey();
@@ -1380,7 +1392,17 @@ async function main() {
1380
1392
  const fileFeedback = new Map<string, Map<number, string>>();
1381
1393
 
1382
1394
  let totalApplied = 0;
1383
- const files = [...allErrors.entries()];
1395
+ let files = [...allErrors.entries()];
1396
+
1397
+ // Single-file mode: filter to only the specified file
1398
+ if (CONFIG.singleFile) {
1399
+ files = files.filter(([filePath]) => filePath === CONFIG.singleFile);
1400
+ if (files.length === 0) {
1401
+ console.log(`\nSingle-file mode: No errors found in ${CONFIG.singleFile}`);
1402
+ console.log('File may have already been fixed or has no compilation errors.');
1403
+ break;
1404
+ }
1405
+ }
1384
1406
 
1385
1407
  for (const [filePath, errors] of files) {
1386
1408
  const fullPath = path.join(CONFIG.projectPath, filePath);
@@ -33,6 +33,10 @@ import {
33
33
 
34
34
  // ============== CONFIGURATION ==============
35
35
 
36
+ // Parse --file and --agent-id parameters
37
+ const fileArg = process.argv.find(arg => arg.startsWith('--file='));
38
+ const agentIdArg = process.argv.find(arg => arg.startsWith('--agent-id='));
39
+
36
40
  const CONFIG = {
37
41
  maxGlobalIterations: 5,
38
42
  maxFileRetries: 2,
@@ -47,6 +51,8 @@ const CONFIG = {
47
51
  verbose: process.argv.includes('--verbose'),
48
52
  includeTypes: process.argv.includes('--types') ? ['ts', 'tsx'] : ['ts', 'tsx'],
49
53
  excludePattern: process.env.TS_EXCLUDE_PATTERN || 'node_modules|dist|build|\\.git',
54
+ singleFile: fileArg ? fileArg.split('=')[1] : null, // Single-file mode
55
+ agentId: agentIdArg ? agentIdArg.split('=')[1] : null, // Agent ID for coordination mode
50
56
  // Security limits
51
57
  maxFileSize: 1024 * 1024, // 1MB
52
58
  maxLineLength: 1000,
@@ -867,6 +873,13 @@ async function main() {
867
873
  console.log(` Model: ${CONFIG.model}`);
868
874
  console.log(` Dry run: ${CONFIG.dryRun}`);
869
875
 
876
+ if (CONFIG.singleFile) {
877
+ console.log(` Single-File Mode: ${CONFIG.singleFile}`);
878
+ if (CONFIG.agentId) {
879
+ console.log(` Agent ID: ${CONFIG.agentId}`);
880
+ }
881
+ }
882
+
870
883
  if (CONFIG.dryRun) {
871
884
  console.log(` Patch dir: ${CONFIG.patchDir}`);
872
885
  }
@@ -900,6 +913,30 @@ async function main() {
900
913
  errorsByFile.get(error.file)!.push(error);
901
914
  }
902
915
 
916
+ // Single-file mode: filter to only the specified file
917
+ if (CONFIG.singleFile) {
918
+ const normalizedPath = path.normalize(CONFIG.singleFile);
919
+ const matchingFiles = Array.from(errorsByFile.keys()).filter(f =>
920
+ f === normalizedPath || f.endsWith(normalizedPath) || normalizedPath.endsWith(f)
921
+ );
922
+
923
+ if (matchingFiles.length === 0) {
924
+ console.log(`\n✅ Single-file mode: No errors found in ${CONFIG.singleFile}`);
925
+ console.log(' File may have already been fixed or has no compilation errors.');
926
+ return;
927
+ }
928
+
929
+ // Keep only the matching file
930
+ const singleFileErrors = new Map<string, TypeScriptError[]>();
931
+ for (const file of matchingFiles) {
932
+ singleFileErrors.set(file, errorsByFile.get(file)!);
933
+ }
934
+ errorsByFile.clear();
935
+ for (const [k, v] of singleFileErrors) {
936
+ errorsByFile.set(k, v);
937
+ }
938
+ }
939
+
903
940
  console.log(` Across ${errorsByFile.size} files\n`);
904
941
 
905
942
  // Process errors
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-flow-novice",
3
- "version": "2.18.28",
3
+ "version": "2.18.30",
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",