Output

From masharratt/claude-flow-novice · View interactive version

Output is an AI agent skill from the GitHub repository masharratt/claude-flow-novice. Type-safe output processing for Loop 2 validators and Loop 3 implementers. Use when parsing agent confidence scores, feedback, or calculating consensus from multiple validators.

How to use this skill

Skill file

CFN Loop Output Processing - Unified TypeScript Module

Version: 1.0.0

Status: Production

Purpose: Type-safe, consolidated output processing for Loop 2 (Validators) and Loop 3 (Implementers) agents


Overview

Problem Solved

Previously, output processing was scattered across multiple bash scripts with duplicate logic:

Solution

Single TypeScript module (cfn-loop-output-processing) providing:


Architecture

Module Structure

.claude/skills/cfn-loop-orchestration-v2/lib/output/
├── src/
│   ├── output-processor.ts          # Core module (type-safe)
│   └── cli/
│       ├── process-loop3.ts         # Loop 3 CLI tool
│       └── process-loop2.ts         # Loop 2 CLI tool
├── tests/
│   └── output-processor.test.ts     # Comprehensive test suite (90%+ coverage)
├── SKILL.md                         # This file
└── package.json                     # Dependencies

Key Types

// Loop 3 Result (Implementers)
interface Loop3Result {
  agentId: string;
  confidence: number;
  confidenceSource: 'explicit' | 'calculated' | 'fallback';
  filesChanged: number;
  deliverables: string[];
  testsPassedCount?: number;
  testsFailed?: number;
  passRate?: number;
  output: string;
  iteration: number;
  timestamp: string;
}

// Loop 2 Result (Validators)
interface Loop2Result {
  validatorId: string;
  score: number;
  scoreSource: 'explicit' | 'calculated' | 'qualitative';
  issues: FeedbackItem[];
  criticalCount: number;
  warningCount: number;
  suggestionCount: number;
  recommendations: string[];
  output: string;
  iteration: number;
  timestamp: string;
}

// Consensus Result
interface ConsensusResult {
  averageScore: number;
  threshold: number;
  passed: boolean;
  validatorCount: number;
  scoredCount: number;
  minScore: number;
  maxScore: number;
  summary: string;
  details: {
    criticalIssuesTotal: number;
    warningIssuesTotal: number;
    suggestionsTotal: number;
  };
}

Core Functions

Confidence Extraction

`parseConfidence(output, config?)`

Extracts confidence score using 5-pattern fallback approach.

Patterns (priority order):

  1. Explicit header: ## Validation Confidence: 0.85
  2. Generic field: confidence: 0.92 or Confidence: 0.92
  3. Score field: Score: 0.78
  4. Percentage: 92% or 92 percent
  5. Parentheses: (0.87)
  6. Qualitative: high confidence → 0.90, medium → 0.75, low → 0.50

Returns:

{
  score: number;          // 0.0-1.0
  source: 'explicit' | 'qualitative' | 'none';
}

Examples:

parseConfidence('Confidence: 0.85');           // { score: 0.85, source: 'explicit' }
parseConfidence('92%');                        // { score: 0.92, source: 'explicit' }
parseConfidence('high confidence');            // { score: 0.90, source: 'qualitative' }
parseConfidence('No score provided');          // { score: 0.0, source: 'none' }

Feedback Extraction

`extractFeedback(output)`

Extracts feedback items from validator output, categorized by severity.

Supported formats:

Returns:

FeedbackItem[] = [
  { severity: 'CRITICAL', text: 'Missing error handling' },
  { severity: 'WARNING', text: 'Performance issue' },
  { severity: 'SUGGESTION', text: 'Add documentation' }
]

Example:

### CRITICAL Issues
- SQL injection vulnerability
- Missing authentication

### WARNING Issues
- Performance concern in loop

### SUGGESTION Items
- Add unit tests
`extractRecommendations(output)`

Extracts recommendations/suggestions from validator output.

Supported headers: Recommendations:, Recommendation:, Suggestions:

Returns: string[] of recommendations

Consensus Calculation

`calculateConsensus(results, threshold?)`

Calculates consensus from multiple validator results.

Parameters:

Returns:

{
  averageScore: number;
  threshold: number;
  passed: boolean;
  validatorCount: number;
  scoredCount: number;
  minScore: number;
  maxScore: number;
  summary: string;
  details: {
    criticalIssuesTotal: number;
    warningIssuesTotal: number;
    suggestionsTotal: number;
  };
}

Example:

const consensus = calculateConsensus([
  { validatorId: 'v1', score: 0.9, ... },
  { validatorId: 'v2', score: 0.85, ... }
], 0.80);

// Result: { averageScore: 0.875, passed: true, ... }

Loop-Specific Parsers

`parseLoop3Output(agentOutput, agentId, iteration?, gitStatus?)`

Complete Loop 3 parser combining all extraction logic.

Features:

Example:

const result = parseLoop3Output(
  agentOutput,
  'coder-1',
  1,
  { before: '...', after: '...' }
);

// Result: Loop3Result with confidence, deliverables, test info
`parseLoop2Output(validatorOutput, validatorId, iteration?)`

Complete Loop 2 parser for validator feedback.

Features:

Example:

const result = parseLoop2Output(
  validatorOutput,
  'reviewer-1',
  1
);

// Result: Loop2Result with score, issues, recommendations

CLI Tools

Loop 3 Processor

npx ts-node src/cli/process-loop3.ts [OPTIONS]

Options:

Output: JSON with Loop3Result

Example:

npx ts-node src/cli/process-loop3.ts \
  --agent-id "coder-1" \
  --output "Implementation complete. Confidence: 0.85" \
  --files-changed 5

# Output:
# {
#   "agentId": "coder-1",
#   "confidence": 0.85,
#   "confidenceSource": "explicit",
#   "filesChanged": 5,
#   ...
# }

Loop 2 Processor (Single Validator)

npx ts-node src/cli/process-loop2.ts [OPTIONS]

Options:

Output: JSON with Loop2Result

Example:

npx ts-node src/cli/process-loop2.ts \
  --validator-id "reviewer-1" \
  --output "Validation: confidence 0.92"

# Output:
# {
#   "validatorId": "reviewer-1",
#   "score": 0.92,
#   ...
# }

Loop 2 Consensus Mode

npx ts-node src/cli/process-loop2.ts --consensus [OPTIONS]

Options:

Output: JSON with ConsensusResult

Example:

npx ts-node src/cli/process-loop2.ts \
  --consensus \
  --results-file ./validator-results.json \
  --threshold 0.75

# Output:
# {
#   "averageScore": 0.88,
#   "passed": true,
#   "summary": "PASS: 88% consensus from 3 validators...",
#   ...
# }

Integration with Orchestrator

Loop 3 Integration

# From orchestrator: process implementer output
RESULT=$(npx ts-node $HOME/.claude/skills/cfn-loop-orchestration-v2/lib/output/src/cli/process-loop3.ts \
  --agent-id "$AGENT_ID" \
  --output "$AGENT_OUTPUT" \
  --iteration "$ITERATION")

CONFIDENCE=$(echo "$RESULT" | jq -r '.confidence')
FILES_CHANGED=$(echo "$RESULT" | jq -r '.filesChanged')

# Report to Redis
redis-cli LPUSH "swarm:${TASK_ID}:${AGENT_ID}:confidence" "$CONFIDENCE"
redis-cli LPUSH "swarm:${TASK_ID}:${AGENT_ID}:done" "complete"

Loop 2 Integration (Single Validator)

# Process validator output
RESULT=$(npx ts-node $HOME/.claude/skills/cfn-loop-orchestration-v2/lib/output/src/cli/process-loop2.ts \
  --validator-id "$VALIDATOR_ID" \
  --output "$VALIDATOR_OUTPUT" \
  --iteration "$ITERATION")

SCORE=$(echo "$RESULT" | jq -r '.score')

# Store for later consensus calculation
echo "$RESULT" >> ./validator-results.json

Loop 2 Integration (Consensus)

# Calculate consensus from all validators
CONSENSUS=$(npx ts-node $HOME/.claude/skills/cfn-loop-orchestration-v2/lib/output/src/cli/process-loop2.ts \
  --consensus \
  --results-file ./validator-results.json \
  --threshold "$CONSENSUS_THRESHOLD")

PASSED=$(echo "$CONSENSUS" | jq -r '.passed')

if [ "$PASSED" = "true" ]; then
  echo "Validators consensus PASSED"
else
  echo "Validators consensus FAILED - average score below threshold"
fi

Confidence Extraction Patterns

NOTE: this 5-pattern extraction ladder is RECOVERY-ONLY. It exists to salvage confidence from malformed agent output. Orchestrator prompts must demand the JSON contract as primary (agents report an explicit JSON block with a decimal confidence field, computed by the mechanical rubric in lib/validation/SKILL.md). If you find yourself relying on patterns 3-5, fix the spawn prompt, not the parser.

Priority Order

  1. Explicit Header (Priority 1)
  1. Generic Field (Priority 2)
  1. Percentage (Priority 3)
  1. Parentheses (Priority 4)
  1. Qualitative (Priority 5)

Fallback Strategy

If no explicit confidence found:

  1. Check qualitative mappings
  2. For Loop 3 only: Calculate from file changes + tests
  3. Return 0.0 with source="none"

Feedback Categorization

CRITICAL Issues

WARNING Issues

SUGGESTION Items


Test Coverage

Test Suite

File: tests/output-processor.test.ts

Coverage: 90%+ (lines, functions, branches)

Test Categories

Running Tests

# Install dependencies
npm install

# Run all tests with coverage
npm run test

# Run specific test suite
npm test -- --testNamePattern="parseConfidence"

# Watch mode for development
npm test -- --watch

Migration Guide

From Bash to TypeScript

Old (Bash):

CONFIDENCE=$(./parse-confidence.sh "$AGENT_OUTPUT")
DELIVERABLES=$(./verify-deliverables.sh --before "$BEFORE" --after "$AFTER")

New (TypeScript):

import { parseConfidence, parseLoop3Output } from './output-processor';

const { score, source } = parseConfidence(agentOutput);
const result = parseLoop3Output(agentOutput, agentId, iteration, gitStatus);

CLI (Same interface):

npx ts-node src/cli/process-loop3.ts \
  --agent-id "coder-1" \
  --output "$AGENT_OUTPUT"

Deprecation Timeline

Immediate (Now):

30 days: Bash scripts continue to work (deprecated status)

60 days: Orchestrator fully migrated to TypeScript

90 days: Bash scripts removed


Benefits

| Aspect | Bash Scripts | TypeScript Module |

|--------|--------------|-------------------|

| Type Safety | ❌ No | ✅ Yes |

| Code Reuse | ❌ Duplicate logic | ✅ Shared functions |

| Test Coverage | ❌ Limited | ✅ 90%+ |

| Documentation | ❌ Inline comments | ✅ Comprehensive |

| Maintainability | ❌ Hard to modify | ✅ Easy to extend |

| Performance | ✅ Fast | ✅ Fast (Node.js) |

| Debuggability | ⚠️ Bash errors | ✅ Stack traces |

| IDE Support | ❌ None | ✅ Full IntelliSense |


Error Handling

Invalid Input

// Empty input
parseConfidence('');                    // { score: 0.0, source: 'none' }

// Invalid JSON in results file
const results = parseJson(invalidJson); // null

// Out of range score
isValidConfidence(1.5);                 // false

CLI Error Messages

# Missing required argument
$ npx ts-node src/cli/process-loop3.ts
Error: --agent-id is required

# File not found
$ npx ts-node src/cli/process-loop3.ts --output-file missing.txt
Error: Output file not found: missing.txt

Performance

Memory efficient with minimal allocations.


Backward Compatibility

Breaking Changes

None. This module consolidates without changing external interfaces.

CLI Compatibility

All CLI tools accept same arguments as predecessor bash scripts.

Integration Points

Orchestrator integration remains identical - only internal implementation changes.


Related Documentation


Version History

1.0.0 (2025-11-19)


Summary

This skill provides type-safe, consolidated output processing for all CFN Loop agents. By consolidating previously scattered bash scripts into a single TypeScript module, we achieve:

The module is production-ready and replaces cfn-loop2-output-processing and cfn-loop3-output-processing bash skills.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.