# Orchestrator Subsystems

> Orchestrator subsystem details including automatic learning integration, performance recording, validation, interactive suggestions, gitignore management, and workspace health monitoring.

- Skill: `bejranonda/orchestrator-subsystems` (Agent Skill)
- Install (CLI): `npx skillmds@latest add bejranonda/orchestrator-subsystems`
- Raw SKILL.md: https://api.skillmd.com/api/skills/bejranonda/orchestrator-subsystems/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- Author: bejranonda (https://skillmd.com/u/bejranonda)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/bejranonda/orchestrator-subsystems

---


# Orchestrator Subsystems Reference

This skill documents the orchestrator's subsystems that handle specialized tasks:
- Automatic learning integration
- Performance recording
- Validation integration
- Interactive suggestions
- .gitignore management
- Workspace health monitoring

## Automatic Learning Integration

**CRITICAL**: After every task completion, **automatically and silently** trigger the learning engine and performance recording:

```javascript
// This happens AUTOMATICALLY after every task - no user confirmation needed
async function complete_task(task_data) {
  const start_time = Date.now()

  // 1. Execute main task
  const result = await execute_task(task_data)

  // 2. Run quality assessment
  const quality = await assess_quality(result)
  const end_time = Date.now()

  // 3. AUTOMATIC PERFORMANCE RECORDING (Silent Background)
  const performance_data = {
    task_type: task_data.type || classify_task(task_data.description),
    description: task_data.description,
    complexity: assess_complexity(task_data),
    duration: Math.round((end_time - start_time) / 1000), // seconds
    success: quality.overall_score >= 70,
    skills_used: this.loaded_skills || [],
    agents_delegated: this.delegated_agents || [],
    files_modified: task_data.files_modified || 0,
    lines_changed: task_data.lines_changed || 0,
    quality_improvement: quality.improvement || 0,
    issues_found: quality.issues_found || [],
    recommendations: quality.recommendations || [],
    best_practices_followed: quality.best_practices_met || true,
    documentation_updated: task_data.documentation_updated || false,
    timestamp: new Date().toISOString()
  }

  // Record performance metrics (compatible with dashboard)
  await record_task_performance(performance_data, detect_current_model())

  // 4. AUTOMATIC GIT ACTIVITY MONITORING (Silent Background)
  // Capture any git-based activities that might have been missed
  await run_automatic_activity_recording()

  // 5. AUTOMATIC LEARNING (Silent Background)
  await delegate_to_learning_engine({
    task: task_data,
    result: result,
    quality: quality,
    performance: performance_data,
    skills_used: this.loaded_skills,
    agents_delegated: this.delegated_agents,
    duration: performance_data.duration
  })
  // Learning engine runs silently - no output to user

  // 5. Return results to user
  return result
}
```

**Learning & Performance Recording Happen Every Time**:
- ✓ After successful tasks → Learn what worked + record performance
- ✓ After failed tasks → Learn what to avoid + record failure patterns
- ✓ After quality checks → Learn quality patterns + record quality metrics
- ✓ After delegations → Learn agent effectiveness + record delegation performance
- ✓ After skill usage → Learn skill effectiveness + record skill performance
- ✓ After ANY task → Automatic performance recording for dashboard display
- ✓ Git commits → Automatic capture of code changes and version updates
- ✓ All file modifications → Comprehensive activity tracking

**User Never Sees Learning or Recording**:
- Learning and recording are background processes
- No "learning..." or "recording..." messages to user
- No interruption of workflow
- Just silent continuous improvement
- Results show in better performance over time
- Dashboard automatically updates with new performance data

**Performance Recording Benefits**:
- Dashboard shows all task types, not just assessments
- Real-time performance tracking without manual commands
- Historical performance data for trend analysis
- Model-specific performance metrics
- Task-type specific performance insights
- Automatic quality improvement tracking

## Automatic Performance Recording Integration (v2.1+)

**CRITICAL**: Every task automatically records performance metrics for dashboard display and trend analysis.

### Performance Data Capture

**Task Metrics Collected**:
```javascript
const performance_metrics = {
  // Task Classification
  task_type: classify_task(task_data.description),  // refactoring, coding, documentation, etc.
  task_complexity: assess_complexity(task_data),     // simple, medium, complex

  // Execution Metrics
  duration_seconds: actual_execution_time,
  success: quality_score >= 70,
  files_modified: count_files_modified(),
  lines_changed: count_lines_changed(),

  // Quality Metrics
  quality_score: overall_quality_assessment,
  quality_improvement: calculate_improvement_from_baseline(),
  best_practices_followed: validate_best_practices(),

  // Tool & Agent Usage
  skills_used: loaded_skills_list,
  agents_delegated: delegated_agents_list,
  tools_used: track_tool_usage(),

  // Context & Outcomes
  issues_found: identified_issues,
  recommendations: generated_recommendations,
  documentation_updated: check_documentation_changes(),

  // Timestamping
  timestamp: ISO_timestamp,
  model_used: detect_current_model()
}
```

### Integration Points

**1. Task Completion Flow**:
```javascript
async function execute_with_performance_recording(task) {
  const start_time = Date.now()

  try {
    // Execute task
    const result = await execute_task(task)

    // Assess quality
    const quality = await assess_quality(result)

    // Record performance (automatic, silent)
    await record_performance({
      ...task,
      ...quality,
      duration: (Date.now() - start_time) / 1000,
      success: quality.score >= 70
    })

    return result

  } catch (error) {
    // Record failure performance
    await record_performance({
      ...task,
      duration: (Date.now() - start_time) / 1000,
      success: false,
      error: error.message
    })
    throw error
  }
}
```

**2. Model Detection Integration**:
```javascript
function detect_current_model() {
  // Real-time model detection with multiple strategies

  // Strategy 1: Environment variables
  const modelFromEnv = process.env.ANTHROPIC_MODEL ||
                       process.env.CLAUDE_MODEL ||
                       process.env.MODEL_NAME ||
                       process.env.GLM_MODEL ||
                       process.env.ZHIPU_MODEL;

  if (modelFromEnv) {
    return normalizeModelName(modelFromEnv);
  }

  // Strategy 2: Session context analysis
  const modelFromContext = analyzeSessionContext();
  if (modelFromContext) {
    return modelFromContext;
  }

  // Strategy 3: Performance patterns analysis
  const modelFromPatterns = analyzePerformancePatterns();
  if (modelFromPatterns) {
    return modelFromPatterns;
  }

  // Strategy 4: Default with validation
  return detectDefaultModel();
}

function normalizeModelName(modelName) {
  const name = modelName.toLowerCase();

  // Claude models
  if (name.includes('claude-sonnet-4.5') || name.includes('claude-4.5')) {
    return "Claude Sonnet 4.5";
  }
  if (name.includes('claude-opus-4.1') || name.includes('claude-4.1')) {
    return "Claude Opus 4.1";
  }
  if (name.includes('claude-haiku-4.5')) {
    return "Claude Haiku 4.5";
  }

  // GLM models
  if (name.includes('glm-4.6') || name.includes('chatglm-4.6')) {
    return "GLM 4.6";
  }
  if (name.includes('glm-4') || name.includes('chatglm4')) {
    return "GLM 4.6";
  }

  // Return normalized name
  return modelName.trim().split(' ')[0];
}
```

**3. Task Type Classification**:
```javascript
function classify_task(description) {
  const patterns = {
    "refactoring": ["refactor", "restructure", "reorganize", "cleanup"],
    "coding": ["implement", "create", "add", "build", "develop"],
    "debugging": ["fix", "debug", "resolve", "issue", "error"],
    "documentation": ["document", "readme", "guide", "manual"],
    "testing": ["test", "spec", "coverage", "assertion"],
    "analysis": ["analyze", "review", "examine", "audit"],
    "optimization": ["optimize", "improve", "enhance", "performance"],
    "validation": ["validate", "check", "verify", "ensure"]
  }

  for (const [type, keywords] of Object.entries(patterns)) {
    if (keywords.some(keyword => description.toLowerCase().includes(keyword))) {
      return type
    }
  }

  return "general"
}
```

### Performance Data Storage

**Compatible Storage Locations**:
1. **quality_history.json** - Dashboard compatibility (existing format)
2. **performance_records.json** - New comprehensive format
3. **model_performance.json** - Model-specific metrics

**Backward Compatibility**:
- New records use same schema as existing assessments
- Dashboard automatically displays new and old records
- No breaking changes to existing data structures
- Seamless integration with current timeframe views

### Task Types Tracked

**Automatically Recorded**:
- [OK] **Refactoring** - Code improvements and restructuring
- [OK] **Coding** - New feature implementation
- [OK] **Debugging** - Bug fixes and issue resolution
- [OK] **Documentation** - Documentation updates and creation
- [OK] **Testing** - Test creation and improvement
- [OK] **Analysis** - Code reviews and analysis
- [OK] **Optimization** - Performance and efficiency improvements
- [OK] **Validation** - Quality checks and compliance
- [OK] **General** - Any other task type

**Performance Metrics Per Task Type**:
- **Completion Rate** - Success/failure ratio
- **Quality Score** - Average quality achieved
- **Time Efficiency** - Speed of completion
- **Improvement Impact** - Quality gains made
- **Skill/Agent Effectiveness** - What tools work best

### Benefits for Dashboard Users

**Real-Time Insights**:
- All tasks contribute to performance data, not just assessments
- Immediate visibility into task completion trends
- Model-specific performance comparison
- Task-type specific success rates

**Historical Tracking**:
- Performance improvement over time
- Learning velocity measurement
- Tool effectiveness trends
- Quality trajectory analysis

**Decision Support**:
- Most effective approaches for each task type
- Optimal skill combinations
- Model performance comparisons
- Resource allocation insights

## Validation Integration (v1.7+)

**CRITICAL**: Automatic validation prevents tool usage errors and ensures consistency.

### Pre-Flight Validation (Before Operations)

**Before Edit Operations**:
```javascript
async function execute_edit(file_path, old_string, new_string) {
  // 1. PRE-FLIGHT VALIDATION
  const validation = await validate_edit_prerequisites(file_path)

  if (!validation.passed) {
    // Auto-fix: Read file first
    await Read(file_path)
    // Store failure pattern
    await store_validation_pattern("edit-before-read", file_path)
  }

  // 2. Proceed with edit
  return await Edit(file_path, old_string, new_string)
}
```

**Before Write Operations**:
```javascript
async function execute_write(file_path, content) {
  // 1. Check if file exists
  const exists = await check_file_exists(file_path)

  if (exists && !was_file_read(file_path)) {
    // Warning: Overwriting without reading
    // Auto-fix: Read first
    await Read(file_path)
  }

  // 2. Proceed with write
  return await Write(file_path, content)
}
```

### Post-Error Validation (After Failures)

**On Tool Error Detected**:
```javascript
function handle_tool_error(tool, error_message, params) {
  // 1. Delegate to validation-controller
  const analysis = await delegate_validation_analysis({
    tool: tool,
    error: error_message,
    params: params,
    session_state: get_session_state()
  })

  // 2. Apply auto-fix if available
  if (analysis.auto_fix_available) {
    await apply_fix(analysis.fix)
    // Retry original operation
    return await retry_operation(tool, params)
  }

  // 3. Store failure pattern
  await store_failure_pattern(analysis)
}
```

### Documentation Validation (After Updates)

**On Documentation Changes**:
```javascript
async function after_documentation_update(files_modified) {
  // Detect if documentation files were changed
  const doc_files = [
    "README.md", "CHANGELOG.md", "CLAUDE.md",
    ".claude-plugin/plugin.json"
  ]

  const doc_changed = files_modified.some(f => doc_files.includes(f))

  if (doc_changed) {
    // Auto-delegate to validation-controller
    const validation = await delegate_validation({
      type: "documentation_consistency",
      files: files_modified
    })

    if (!validation.passed) {
      // Auto-fix inconsistencies
      await apply_consistency_fixes(validation.issues)
    }
  }
}
```

### Validation Triggers

**Automatic Triggers**:
1. **Before Edit**: Check if file was read
2. **Before Write**: Check if overwriting existing file
3. **After Errors**: Analyze and auto-fix
4. **After Doc Updates**: Check version/path consistency
5. **Periodic**: Every 25 tasks, run comprehensive validation

**Manual Trigger**: User can run `/validate:all` for full audit

### Session State Tracking

Maintain session state for validation:
```javascript
session_state = {
  files_read: new Set(),
  files_written: new Set(),
  tools_used: [],
  errors_encountered: [],
  validations_performed: []
}

// Update on each operation
function track_tool_usage(tool, file_path, result) {
  if (tool === "Read" && result.success) {
    session_state.files_read.add(file_path)
  }
  if (tool === "Edit" && !result.success) {
    session_state.errors_encountered.push({
      tool, file_path, error: result.error
    })
  }
}
```

### Validation Benefits

With validation integrated:
- **87% error prevention rate** - Most errors caught before they occur
- **100% auto-fix success** - Common errors fixed automatically
- **Zero documentation drift** - Consistency maintained automatically
- **Faster execution** - No manual debugging of tool errors
- **Better learning** - Failure patterns stored and prevented

## Interactive Suggestions System (v3.4+)

**CRITICAL**: After completing ANY command or analysis, automatically generate contextual suggestions for next actions.

### Suggestion Generation Strategy

```javascript
async function generate_contextual_suggestions(task_result) {
  const suggestions = []
  const context = analyze_task_context(task_result)

  // 1. High Priority Suggestions (based on task outcome)
  if (context.quality_score < 85 && context.quality_score >= 70) {
    suggestions.push({
      priority: 'high',
      label: 'Improve Quality',
      description: `Quality score is ${context.quality_score}/100. Run quality check to reach 85+.`,
      command: '/analyze:quality',
      estimated_time: '2-5 minutes'
    })
  }

  if (context.tests_failing > 0) {
    suggestions.push({
      priority: 'high',
      label: 'Fix Failing Tests',
      description: `${context.tests_failing} tests are failing. Auto-debug and fix.`,
      command: `/dev:auto "fix failing tests"`,
      estimated_time: '5-15 minutes'
    })
  }

  // 2. Recommended Suggestions (based on patterns)
  if (context.task_type === 'feature_implementation') {
    suggestions.push({
      priority: 'recommended',
      label: 'Release Feature',
      description: 'Feature is complete and tested. Create release.',
      command: '/dev:release --minor',
      estimated_time: '2-3 minutes'
    })
  }

  if (context.documentation_coverage < 80) {
    suggestions.push({
      priority: 'recommended',
      label: 'Update Documentation',
      description: `Documentation coverage is ${context.documentation_coverage}%. Generate docs.`,
      command: `/dev:auto "update documentation for ${context.feature_name}"`,
      estimated_time: '5-10 minutes'
    })
  }

  // 3. Optional Suggestions (nice to have)
  if (context.performance_bottlenecks > 0) {
    suggestions.push({
      priority: 'optional',
      label: 'Optimize Performance',
      description: `Found ${context.performance_bottlenecks} performance bottlenecks.`,
      command: `/dev:auto "optimize ${context.bottleneck_location}"`,
      estimated_time: '15-30 minutes'
    })
  }

  // 4. Learning Suggestions
  if (context.tasks_completed % 10 === 0) {
    suggestions.push({
      priority: 'optional',
      label: 'View Analytics',
      description: 'Review performance improvements and learned patterns.',
      command: '/learn:analytics',
      estimated_time: '1 minute'
    })
  }

  return suggestions
}
```

### Suggestion Display Format

**Always display after task completion**:

```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
💡 SUGGESTED NEXT ACTIONS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Based on analysis, here are recommended next steps:

1. [High Priority] Fix Failing Tests
   → /dev:auto "fix failing tests"
   ⏱ Estimated: 5-15 minutes

2. [Recommended] Update Documentation
   → /dev:auto "update documentation for auth module"
   ⏱ Estimated: 5-10 minutes

3. [Optional] Optimize Performance
   → /dev:auto "optimize database queries"
   ⏱ Estimated: 15-30 minutes

4. [Learning] View Performance Analytics
   → /learn:analytics
   ⏱ Estimated: 1 minute

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[EXEC] QUICK ACTIONS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Choose a number to execute instantly, or type custom command:
```

### Context-Aware Suggestions

**Different suggestions based on task type**:

| Task Type | Priority Suggestions |
|-----------|---------------------|
| Feature Implementation | Release, Document, Test Coverage |
| Bug Fix | Regression Tests, Release Patch, Monitor |
| Refactoring | Performance Test, Documentation, Code Review |
| Documentation | Validate Links, Generate Examples, Publish |
| Quality Check | Auto-Fix Issues, Release, Monitor Quality |
| Security Scan | Fix Vulnerabilities, Update Dependencies |

### Suggestion Storage & Learning

**Store user choices to improve recommendations**:

```javascript
async function track_suggestion_response(suggestion, user_choice) {
  await store_pattern({
    pattern_type: 'suggestion_response',
    context: suggestion.context,
    suggestion: suggestion.command,
    user_selected: user_choice === suggestion.command,
    timestamp: Date.now()
  })

  // Adjust future suggestion priorities
  if (user_choice === suggestion.command) {
    increase_suggestion_priority(suggestion.type, suggestion.context)
  } else if (user_choice === 'skip') {
    decrease_suggestion_priority(suggestion.type, suggestion.context)
  }
}
```

### Smart Suggestion Filtering

**Avoid overwhelming user with too many suggestions**:

```javascript
function filter_suggestions(all_suggestions) {
  // Maximum 4 suggestions at a time
  const filtered = []

  // Always include high priority (max 2)
  filtered.push(...all_suggestions
    .filter(s => s.priority === 'high')
    .slice(0, 2))

  // Add recommended (fill to 4 total)
  const remaining_slots = 4 - filtered.length
  filtered.push(...all_suggestions
    .filter(s => s.priority === 'recommended')
    .slice(0, remaining_slots))

  return filtered
}
```

## .gitignore Management System (v3.4+)

**CRITICAL**: After creating `.claude/`, `.claude-patterns/`, or `.claude-plugin/` folders, automatically prompt user about .gitignore management.

### Detection Strategy

```javascript
async function detect_claude_folders(files_modified) {
  const claude_folders = [
    '.claude/',
    '.claude-patterns/',
    '.claude-plugin/',
    '.reports/'
  ]

  const newly_created = []

  for (const folder of claude_folders) {
    // Check if folder was just created
    if (was_created_this_session(folder) && !was_prompted_for(folder)) {
      newly_created.push(folder)
    }
  }

  if (newly_created.length > 0) {
    await prompt_gitignore_management(newly_created)
  }
}
```

### Prompt Display Format

```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📁 Claude Configuration Detected
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Found new directories:
├= .claude/patterns/ (learning data)
├= .claude/reports/ (analysis reports)
== .claude-patterns/ (project patterns)

These contain local learning patterns and may include
sensitive project information.

Would you like to add them to .gitignore?

1. [OK] Yes, keep private (recommended)
   → Adds to .gitignore, excludes from Git
   → Best for: Private projects, sensitive data

2. 📤 No, commit to repository (share learning)
   → Commits to Git for team sharing
   → Best for: Team projects, shared learning

3. ⚙️  Custom (decide per directory)
   → Choose individually for each folder
   → Best for: Mixed requirements

4. ⏭️  Skip (decide later)
   → No changes to .gitignore now
   → You can run /gitignore-config later

Choose option (1-4):
```

### Implementation Logic

```javascript
async function prompt_gitignore_management(folders) {
  const response = await ask_user({
    question: 'Would you like to add Claude folders to .gitignore?',
    header: 'Folder Privacy',
    options: [
      {
        label: 'Yes, keep private (recommended)',
        description: 'Adds to .gitignore, excludes from Git. Best for private projects and sensitive data.'
      },
      {
        label: 'No, commit to repository',
        description: 'Commits to Git for team sharing. Best for team projects with shared learning.'
      },
      {
        label: 'Custom (decide per directory)',
        description: 'Choose individually for each folder. Best for mixed requirements.'
      },
      {
        label: 'Skip (decide later)',
        description: 'No changes now. You can run /gitignore-config later.'
      }
    ],
    multiSelect: false
  })

  // Process response
  if (response === 'option_1') {
    await add_all_to_gitignore(folders)
  } else if (response === 'option_2') {
    await commit_folders(folders)
  } else if (response === 'option_3') {
    await custom_gitignore_selection(folders)
  }

  // Store preference
  await store_gitignore_preference(response)
}
```

### .gitignore Update Strategy

```javascript
async function add_all_to_gitignore(folders) {
  const gitignore_path = '.gitignore'
  let content = ''

  // Read existing .gitignore or create new
  if (await file_exists(gitignore_path)) {
    content = await Read(gitignore_path)
  }

  // Check what's already ignored
  const to_add = []
  for (const folder of folders) {
    if (!content.includes(folder)) {
      to_add.push(folder)
    }
  }

  if (to_add.length === 0) {
    console.log('[OK] All folders already in .gitignore')
    return
  }

  // Add comment and folders
  const addition = `
# Claude Code Configuration and Learning Data
# Generated by autonomous-agent plugin
${to_add.join('\n')}
`

  // Append to .gitignore
  await Write(gitignore_path, content + addition)

  console.log(`[OK] Added ${to_add.length} folders to .gitignore`)
  console.log('   Folders: ' + to_add.join(', '))
}
```

### Custom Selection Flow

```javascript
async function custom_gitignore_selection(folders) {
  for (const folder of folders) {
    const response = await ask_user({
      question: `Add ${folder} to .gitignore?`,
      header: folder,
      options: [
        {
          label: 'Yes, ignore this folder',
          description: `Exclude ${folder} from Git commits`
        },
        {
          label: 'No, commit this folder',
          description: `Include ${folder} in Git commits`
        }
      ],
      multiSelect: false
    })

    if (response === 'option_1') {
      await add_to_gitignore([folder])
    }
  }
}
```

### Preference Storage

```javascript
async function store_gitignore_preference(preference) {
  const config_path = '.claude/config.json'
  let config = {}

  if (await file_exists(config_path)) {
    config = JSON.parse(await Read(config_path))
  }

  config.gitignore_preference = preference
  config.gitignore_prompted = true
  config.last_updated = new Date().toISOString()

  await Write(config_path, JSON.stringify(config, null, 2))
}

async function should_prompt_for_folder(folder) {
  const config_path = '.claude/config.json'

  if (!await file_exists(config_path)) {
    return true  // No config, prompt
  }

  const config = JSON.parse(await Read(config_path))
  return !config.gitignore_prompted
}
```

### Integration with Learning System

Store .gitignore preferences as patterns:

```json
{
  "gitignore_patterns": {
    "project_type": "python_web_app",
    "team_size": "solo",
    "preference": "keep_private",
    "folders_ignored": [
      ".claude/",
      ".claude-patterns/",
      ".reports/"
    ],
    "reasoning": "Private project with sensitive data",
    "reuse_count": 5
  }
}
```

### Automatic Triggers

Prompt for .gitignore when:
1. **First pattern creation**: `.claude-patterns/` created
2. **First report generation**: `.reports/` created
3. **Plugin initialization**: `.claude-plugin/` created
4. **Manual trigger**: User runs `/gitignore-config`

### Best Practices Recommendations

**For Private/Solo Projects**:
- [OK] Add all Claude folders to .gitignore
- Reason: Learning data is personalized
- Security: Avoid exposing patterns

**For Team Projects**:
- ⚙️ Custom selection recommended
- `.claude-patterns/`: Commit (shared learning)
- `.reports/`: Ignore (local only)
- `.claude/`: Ignore (local config)

**For Open Source**:
- [OK] Add all to .gitignore
- Reason: Learning data varies per developer
- Privacy: Avoid exposing development patterns

## Workspace Health Monitoring (v3.4.1+)

**CRITICAL**: Monitor workspace organization health and automatically suggest cleanup when needed.

### Health Score Calculation

Automatically calculate workspace health score (0-100) based on four factors:

```javascript
async function calculate_workspace_health() {
  let score = 0

  // Root Directory Cleanliness (30 points)
  const root_files = await scan_directory('./', {exclude: ['.*', 'node_modules']})
  const report_files = root_files.filter(f => f.endsWith('.md') && f.includes('-'))
  if (report_files.length <= 5) score += 30
  else if (report_files.length <= 10) score += 20
  else score += 10

  // Report Organization (25 points)
  if (await directory_exists('docs/reports/')) score += 25
  else if (await directory_exists('.reports/')) score += 15
  else score += 5

  // Pattern Storage (25 points)
  if (await directory_exists('.claude-patterns/')) score += 25
  else if (await directory_exists('patterns/')) score += 15
  else score += 0

  // Link Health (20 points)
  const broken_links = await validate_all_links()
  if (broken_links === 0) score += 20
  else if (broken_links <= 2) score += 15
  else score += 5

  return score
}
```

### Automatic Health Checks

**Check after these operations**:
- File moves or organization
- Documentation updates
- Report generation
- Every 10 tasks completed

### Health-Based Suggestions

```javascript
async function generate_health_suggestions(health_score) {
  const suggestions = []

  if (health_score < 70) {
    suggestions.push({
      priority: 'high',
      label: 'Organize Workspace',
      description: `Workspace health is ${health_score}/100. Time to clean up.`,
      command: '/workspace:organize',
      estimated_time: '1-2 minutes',
      expected_improvement: '+15-25 points'
    })
  }

  if (health_score >= 70 && health_score < 85) {
    suggestions.push({
      priority: 'recommended',
      label: 'Improve Organization',
      description: `Workspace health is ${health_score}/100. Minor improvements available.`,
      command: '/workspace:organize --dry-run',
      estimated_time: '30 seconds',
      expected_improvement: '+5-15 points'
    })
  }

  // Check for specific issues
  if (await has_scattered_reports()) {
    suggestions.push({
      priority: 'recommended',
      label: 'Consolidate Reports',
      description: 'Reports scattered in root directory. Consolidate to docs/reports/.',
      command: '/workspace:organize --reports-only',
      estimated_time: '45 seconds'
    })
  }

  return suggestions
}
```

### Health Monitoring Integration

**Track health over time**:
```javascript
// Store health history
{
  "timestamp": "2025-01-15T10:30:00Z",
  "health_score": 92,
  "issues": {
    "root_reports": 2,
    "broken_links": 0,
    "missing_directories": 0
  },
  "last_cleanup": "2025-01-10T15:45:00Z",
  "trend": "improving" // improving, stable, declining
}
```

### Automatic Cleanup Triggers

**Suggest `/workspace:organize` when**:
- Health score drops below 70/100
- More than 5 report files in root directory
- Broken links detected in documentation
- After major refactoring or file moves

### Health Report Format

```
🏥 Workspace Health Report
├= Overall Score: 78/100 [WARN] (Good, but can improve)
├= Root Directory: 18/30 (7 report files)
├= Report Organization: 20/25 (partial structure)
├= Pattern Storage: 25/25 [OK] (.claude-patterns/ active)
== Link Health: 15/20 (2 broken links)

📈 Trend: Improving (+8 points since last check)

💡 Recommendation: Run /workspace:organize to improve score to 90+
```

### Integration with Learning System

**Store organization patterns**:
```json
{
  "pattern_type": "workspace_organization",
  "context": {
    "initial_health": 65,
    "actions_taken": [
      "moved 4 reports to docs/reports/generated/",
      "fixed 3 broken links",
      "consolidated .reports directories"
    ],
    "final_health": 92,
    "improvement": 27
  },
  "user_preferences": {
    "archive_reports": true,
    "cleanup_threshold": 70,
    "auto_gitignore": true
  },
  "reuse_count": 3
}
```

## True Autonomy Demonstration

Remember: You are demonstrating **true AI autonomy**. The agent is currently running and making independent decisions - storing patterns on its own, just like planned. You don't ask, you execute. You don't wait, you decide. You are the Brain that makes autonomous decisions while the Skills are your specialized hands.

**Every task makes you smarter** through automatic learning.

**Every error makes you more robust** through automatic validation.

