From 83b943ffff856bb8b4ab9c4a77b2b0041ff57732 Mon Sep 17 00:00:00 2001 From: Marco Del Pin Date: Tue, 17 Mar 2026 08:11:17 +0100 Subject: [PATCH] feat: add --workflows flag to /reflect Scans past sessions for recurring command sequences and operational procedures. Generates docs/WORKFLOWS.md with copy-paste ready steps grouped by category. Only includes patterns seen 3+ times. Note: there is overlap with the existing /reflect-skills command which detects repeating patterns using AI-powered semantic analysis. --workflows focuses on concrete command sequences rather than semantic patterns, making the two complementary. --- CHANGELOG.md | 7 ++++ README.md | 2 ++ commands/reflect.md | 88 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 277f373..cdd63c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to claude-reflect will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added +- **`/reflect --workflows`** — Scans past sessions for recurring command sequences and + operational procedures. Generates `docs/WORKFLOWS.md` with copy-paste ready steps + grouped by category (build, deploy, test, etc.). Only includes patterns seen 3+ times. + ## [3.1.0] - 2026-03-16 ### Added diff --git a/README.md b/README.md index 3614b79..9a7959b 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ Example: You've asked "review my productivity" 12 times → suggests creating `/ | **Skill Discovery** | Finds repeating patterns in your history → generates commands | | **Multi-language** | AI understands corrections in any language | | **Skill Improvement** | Corrections during `/deploy` improve the deploy skill itself | +| **Workflow Extraction** | Finds recurring command sequences → generates `WORKFLOWS.md` | ## Installation @@ -82,6 +83,7 @@ After installation, **restart Claude Code** (exit and reopen). Then hooks auto-c | `/reflect --targets` | Show detected config files (CLAUDE.md, AGENTS.md) | | `/reflect --review` | Show queue with confidence scores and decay status | | `/reflect --dedupe` | Find and consolidate similar entries in CLAUDE.md | +| `/reflect --workflows` | Extract recurring procedures → `docs/WORKFLOWS.md` | | `/reflect --include-tool-errors` | Include tool execution errors in scan | | `/reflect-skills` | Discover skill candidates from repeating patterns | | `/reflect-skills --days N` | Analyze last N days (default: 14) | diff --git a/commands/reflect.md b/commands/reflect.md index aa6fd8f..987b786 100644 --- a/commands/reflect.md +++ b/commands/reflect.md @@ -13,6 +13,7 @@ allowed-tools: Read, Edit, Write, Glob, Bash, Grep, AskUserQuestion, TodoWrite - `--organize`: Analyze memory hierarchy and suggest reorganization across tiers. - `--include-tool-errors`: Include project-specific tool execution errors in scan (auto-enabled with `--scan-history`). - `--model MODEL`: Model for semantic analysis (default: `sonnet`). Use `haiku` for faster/cheaper runs or `opus` for maximum accuracy. +- `--workflows`: Extract recurring command sequences from past sessions → generate `docs/WORKFLOWS.md` with copy-paste ready procedures. ## Context - Project CLAUDE.md: @CLAUDE.md @@ -444,6 +445,93 @@ Use AskUserQuestion for each proposed reorganization: **6. Exit after reorganization (don't process queue).** +### Handle --workflows Argument + +**If user passed `--workflows`:** + +Scan past sessions for recurring command sequences and operational procedures, then generate +`docs/WORKFLOWS.md` with copy-paste ready instructions. + +**1. Find session files (same method as `--scan-history` Step 0.5a).** + +**2. Extract command patterns:** + +Search for tool calls, command sequences, and "how to do X" discussions: + +```bash +# Find assistant messages with multiple bash commands in sequence +grep -h '"type":"tool_use"' SESSION_FILES | grep '"name":"Bash"' | head -100 + +# Find user messages asking for procedures +grep -h -o '"content":"[^"]*\(how to\|how do I\|steps to\|procedure\|workflow\)[^"]*"' SESSION_FILES | head -50 +``` + +**3. Identify workflow categories by frequency:** + +Group extracted commands by purpose. Common categories to look for: +- File transfer (rsync, scp, cp) +- Build processes (make, npm, cargo, go build) +- Deployment (deploy, push, restart) +- Testing (test, pytest, jest, cargo test) +- Debugging (logs, status checks, diagnostics) +- Database operations (migrate, seed, query) +- Git operations (common multi-step sequences) + +Only include categories that appear **3 or more times** across sessions. + +**4. Generate `docs/WORKFLOWS.md`:** + +```markdown +# Operational Workflows + +> Auto-generated by /reflect --workflows from session history. +> Update manually as procedures evolve. + +## Index +1. [Workflow A] +2. [Workflow B] + +--- + +## [Workflow Name] + +**Frequency:** Used N times across M sessions. + +### Prerequisites +- [requirement] + +### Steps + +\`\`\`bash +# Step 1: [Description] +[exact command from session history] + +# Step 2: [Description] +[exact command from session history] +\`\`\` + +### Notes +- [Any caveats or gotchas observed in sessions] + +### Troubleshooting +- **Problem:** [X] → **Solution:** [Y] +``` + +**5. Show summary and ask user to review before writing:** + +``` +Found N workflow categories (M total procedures): + - Build & Deploy: 12 occurrences + - Database: 7 occurrences + - Testing: 5 occurrences + +Write docs/WORKFLOWS.md? (Y/n) +``` + +**6. Exit after workflow extraction (don't process queue).** + +--- + ### First-Run Detection (Per-Project) Check if /reflect has been run in THIS project before. Run these commands separately: