Skip to content

Intelligence Layer

The Intelligence Layer provides internal agent capabilities that make Commander smarter over time. These are automatic systems — users see the results, not the mechanism.

Components

ComponentPurposeUser sees
Cost PredictorEstimates task cost before execution"Estimated $0.09, continue?"
Failure Pattern LearnerLearns from past failures"You've hit this issue before"
Impact AnalyzerPredicts change side effects"Changing this affects 3 files"
Skill ExtractorExtracts reusable patterns from successes"Solution saved for reuse"

Cost Predictor

Estimates the cost of a task before execution using historical data from MetaLearner and deliberation estimates.

typescript
import { getCostPredictor } from '@commander/core';

const predictor = getCostPredictor();

const estimate = await predictor.estimate({
  task: 'refactor the auth module',
  topology: 'ORCHESTRATOR',
  effortLevel: 'COMPLEX',
  agentCount: 4,
});

console.log(`Estimated cost: $${estimate.estimatedCostUsd}`);
console.log(`Estimated duration: ${estimate.estimatedDurationMs}ms`);
console.log(`Confidence: ${estimate.confidence}`);

Cost Breakdown

┌─────────────────────────────────┐
│         Total Estimate          │
├─────────────────────────────────┤
│  Deliberation:  $0.002         │
│  Execution:     $0.06          │
│  Synthesis:     $0.02          │
│  Quality Gates: $0.008         │
├─────────────────────────────────┤
│  Total:         $0.09          │
└─────────────────────────────────┘

Failure Pattern Learner

Tracks failure patterns and provides proactive warnings about repeated mistakes.

typescript
import { getFailurePatternLearner } from '@commander/core';

const learner = getFailurePatternLearner();

// Check for warnings before executing
const warnings = learner.checkPatterns({
  task: 'deploy to production',
  context: 'after database migration',
});

for (const warning of warnings) {
  console.log(`[${warning.severity}] ${warning.suggestion}`);
  // "You've deployed without running migrations 3 times before"
}

Pattern Categories

CategoryExamples
deployDeploy without migration, missing env vars
testSkipping tests, flaky test ignored
configWrong config format, missing required field
dependencyBreaking change in upgrade, missing peer dep
securityHardcoded secret, exposed endpoint

Impact Analyzer

Analyzes code change impact before execution using AST analysis and dependency tracking.

typescript
import { getImpactAnalyzer } from '@commander/core';

const analyzer = getImpactAnalyzer();

const impact = await analyzer.analyze('src/auth/login.ts');

console.log(`Direct dependencies: ${impact.directDependencies.length}`);
console.log(`Indirect dependencies: ${impact.indirectDependencies.length}`);
console.log(`Affected tests: ${impact.affectedTests.length}`);
console.log(`Risk level: ${impact.riskLevel}`);
// "Changing this affects 3 files, 2 test suites, risk: medium"

Risk Levels

LevelCriteria
lowNo dependencies, no tests affected
mediumFew direct dependencies or tests affected
highMany indirect dependencies or critical path
criticalCore module, many dependents, security-sensitive

Skill Extractor

Automatically extracts reusable skills from successful executions.

typescript
import { getSkillExtractor } from '@commander/core';

const extractor = getSkillExtractor();

// After a successful run, extract skills
const result = await extractor.extract({
  runId: 'run-123',
  task: 'fix the failing test',
  success: true,
});

if (result.extracted) {
  console.log(`Skill extracted: ${result.skill.name}`);
  // "fix-failing-test: Analyze error → check imports → run test → fix"
}

Skill Lifecycle

Successful execution → Pattern extraction → Skill created

                                    ┌───────────────┘

                            Used in future tasks

                    ┌───────────────┼───────────────┐
                    ▼               ▼               ▼
              High usage      Low usage       30 days unused
              (confidence↑)   (confidence→)   (decay starts)

Skill Decay

Skills decay over time if unused:

  • 30 days without use → decay starts
  • 0.05 confidence/day reduction
  • Below 0.2 confidence → auto-pruned

Configuration

ModuleSettingDefaultDescription
Cost PredictorhistorySize100Max historical records per task type
Failure PatternspatternsPath.commander/intelligence/failure-patterns.jsonPersistence path
Impact AnalyzerscanIntervalMs60000Re-scan dependency graph interval
Skill ExtractordecayDays30Days before skill starts decaying
Skill ExtractorminConfidence0.2Below this, skill is pruned

MIT Licensed — Built for multi-agent orchestration.