Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 4, 2026

Five workflows grew to 600-748 lines with mixed concerns, impeding maintenance and reuse. This refactors two high-priority workflows by extracting common patterns into shared modules.

Refactored Workflows

copilot-session-insights.md: 748 → 403 lines (-46%)

  • Extracted chart generation → shared/session-analysis-charts.md (118 lines)
  • Extracted analysis strategies → shared/session-analysis-strategies.md (242 lines)

ci-coach.md: 725 → 281 lines (-61%)

  • Extracted CI data collection → shared/ci-data-analysis.md (173 lines)
  • Extracted optimization patterns → shared/ci-optimization-strategies.md (193 lines)

Pattern

Main workflows now compose via imports:

imports:
  - shared/copilot-session-data-fetch.md
  - shared/session-analysis-charts.md
  - shared/session-analysis-strategies.md
  - shared/reporting.md

Shared modules handle single concerns: data collection, analysis strategies, visualization, or reporting.

Additional Modules

Created shared/token-cost-analysis.md (317 lines) with reusable token aggregation and cost tracking patterns for token reporting workflows.

Documentation

Added specs/workflow-refactoring-patterns.md covering:

  • Module extraction criteria and size guidelines
  • Shared module structure patterns
  • Anti-patterns with concrete examples
  • Refactoring checklist

Remaining Work

Three workflows identified for future refactoring:

  • daily-copilot-token-report.md (680 lines)
  • prompt-clustering-analysis.md (639 lines)
  • developer-docs-consolidator.md (623 lines)
Original prompt

This section details on the original issue you should resolve

<issue_title>Workflow Complexity Reduction Initiative</issue_title>
<issue_description>## Problem

Several agentic workflows have grown to excessive complexity (600+ lines), making them difficult to maintain, debug, and test. Large workflows have multiple concerns mixed together, increasing cognitive load and reducing code quality.

Workflows Needing Refactoring

Workflow Lines Priority
copilot-session-insights.md 748 HIGH
ci-coach.md 725 HIGH
daily-copilot-token-report.md 680 MEDIUM
prompt-clustering-analysis.md 639 MEDIUM
developer-docs-consolidator.md 623 MEDIUM

Recommended Approach

1. Extract Common Functionality

  • Move reusable components to .github/workflows/shared/
  • Create focused include files for specific capabilities
  • Use imports: to compose workflows from modules

2. Split by Concern

  • Separate data collection from analysis
  • Separate analysis from reporting
  • Use workflow chaining for multi-phase operations

3. Maximum Size Guidelines

  • Target: 400-500 lines maximum per workflow
  • Ideal: 200-300 lines for most workflows
  • Hard limit: 600 lines (refactor above this)

Refactoring Template

# Before (750 lines)
---
description: Large monolithic workflow
---
[... 750 lines of mixed concerns ...]

# After (3 focused workflows)

# workflow-1-collect.md (200 lines)
---
description: Data collection phase
imports:
  - shared/data-collectors.md
---
[... focused collection logic ...]

# workflow-2-analyze.md (250 lines)
---
description: Analysis phase
imports:
  - shared/analytics.md
  - shared/trending-charts.md
---
[... focused analysis logic ...]

# workflow-3-report.md (150 lines)
---
description: Reporting phase
imports:
  - shared/reporting.md
---
[... focused reporting logic ...]

Success Criteria

  • All workflows reduced to < 600 lines
  • No single workflow has > 3 distinct concerns
  • Shared functionality extracted to reusable includes
  • Each workflow has clear, focused purpose
  • Documentation updated with refactoring patterns

Expected Benefits

  • Maintainability: +20 points (easier to understand and update)
  • Testability: +15 points (smaller units to test)
  • Reusability: +25 points (shared includes benefit multiple workflows)
  • Debugging: +30 points (easier to isolate issues)

Estimated Effort

  • Per workflow: 4-8 hours
  • Total for 5 workflows: 20-40 hours (2-5 days)

Implementation Plan

  1. Phase 1 (Week 1-2): Refactor copilot-session-insights.md and ci-coach.md
  2. Phase 2 (Week 3-4): Refactor daily-copilot-token-report.md and prompt-clustering-analysis.md
  3. Phase 3 (Week 5): Refactor developer-docs-consolidator.md
  4. Phase 4 (Week 6): Document refactoring patterns and create guidelines

Related

  • Agent Performance Report: [Discussion Link]
  • Part of technical debt reduction initiative
  • Supports long-term maintainability goals

Source: Agent Performance Analyzer
Priority: HIGH
Category: Technical Debt
Impact: High (affects maintainability of 5 critical workflows)

AI generated by Agent Performance Analyzer - Meta-Orchestrator

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits January 4, 2026 06:04
- Extract chart generation to shared/session-analysis-charts.md
- Extract analysis strategies to shared/session-analysis-strategies.md
- Remove 345 lines of redundant content (46% reduction)
- Workflow compiles successfully

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
- Extract CI data analysis to shared/ci-data-analysis.md
- Extract optimization strategies to shared/ci-optimization-strategies.md
- Remove 445 lines of redundant content (61% reduction)
- Workflow compiles successfully

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
- Document refactoring principles and patterns
- Provide examples from copilot-session-insights and ci-coach
- Define shared module structure patterns
- Include anti-patterns to avoid
- Create refactoring checklist

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
- Add concrete examples to anti-patterns section
- Document shell requirement for RANDOM variable
- Clarify YAML context in CI optimization example

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor agentic workflows for complexity reduction Refactor large workflows into modular shared components Jan 4, 2026
Copilot AI requested a review from mnkiefer January 4, 2026 06:21
@pelikhan pelikhan marked this pull request as ready for review January 4, 2026 06:38
@pelikhan pelikhan merged commit 3d6c644 into main Jan 4, 2026
4 checks passed
@pelikhan pelikhan deleted the copilot/reduce-workflow-complexity branch January 4, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Workflow Complexity Reduction Initiative

3 participants