Repository navigation
Description
Problem
Sequant has accumulated significant operational data from dogfooding — 81 structured run logs, 20KB of aggregated metrics, 148 Claude Code conversation transcripts (164MB), and live state/GitHub data — but no systematic process for mining this data to identify optimization opportunities, complexity hotspots, or workflow inefficiencies.
The existing sequant stats command (770 LOC) already provides solid aggregate analytics — success/failure rates, phase duration averages, token breakdown, chain-mode vs single-issue comparison, and auto-generated insights. The existing /reflect skill provides per-run observations. The /improve skill focuses on code patterns. What's missing is cross-run trend analysis, failure forensics, and a structured process for turning data into workflow improvements.
What Already Exists
Before building anything new, acknowledge the existing analytics surface:
| Tool | What It Does | Gap |
|---|---|---|
sequant stats |
Success rates, phase durations, token usage, insights, CSV/JSON export | No temporal trends, no per-issue-type segmentation, no QA verdict analysis |
sequant stats --json |
Machine-readable aggregate output | Could pipe directly into context for analysis — may not need new tooling |
run-reflect.ts |
Per-run timing patterns, phase mismatches, improvement suggestions | Single-run only, no cross-run patterns |
/reflect skill |
Session-level workflow analysis | Conversation-scoped, no historical data |
sequant logs |
View individual run details | Display-focused, not analytical |
Step zero of this issue is running sequant stats --json and assessing whether the gaps are worth filling.
Strategy
Phase A: Investigation (No Code)
The goal is to look at the data we have, establish baselines, and let findings drive decisions. No tooling until we know what's valuable.
A1: Baseline Establishment
Run sequant stats --json and document current baselines:
- Overall success rate
- Average duration per phase
- Token cost per run
- Chain mode vs single issue performance
- Failure rate and common failure patterns
These baselines become the reference point for all future measurement. Without them, we can't tell if changes help.
A2: Bulk Log Analysis
Load all 81 run logs into a conversation. Token budget reality check: 620KB of JSON is ~150-200K tokens (not 50K — JSON averages 3-4 chars/token), which is 15-20% of the context window. Still feasible, but be precise.
Questions to answer, in priority order:
Temporal trends (most basic, currently missing from stats):
- Are success rates improving, declining, or flat over the Jan 9 → Mar 25 window?
- Are phase durations trending down as skills improve?
- Is token cost per issue decreasing?
Phase-level analysis:
- What's the first-pass QA rate (QA passes without quality loop)?
statstracks overall success but not QA-specific first-pass rate. - Which phases fail most often, and is it the phase's fault or the preceding phase's output?
- Is spec duration correlated with issue complexity, or is it constant regardless? (run-reflect.ts checks this per-run; we need it cross-run)
Segmentation (currently missing from stats):
- Break all metrics by: issue labels, lines changed, number of AC items, single vs batch, flags used
- Which segments have the worst outcomes?
- Are there issue characteristics that predict failure?
Quality loop effectiveness:
- When quality loop triggers, how often does iteration 2 fix the issue? Iteration 3?
- What's the token cost of loop iterations vs just re-running from scratch?
Expected output: Baselines documented, top 3-5 optimization targets ranked by impact, and hypotheses that emerged from the data (not pre-assumed).
A3: Failure Forensics
Identify all runs where status: "failure" or verdict: "AC_NOT_MET". For each:
- Examine the run log for phase-level detail
- Categorize the failure mode:
- Tooling failure (build error, test infrastructure, worktree issue)
- Wrong approach (agent took fundamentally wrong path)
- Unclear AC (spec produced ambiguous criteria)
- Scope overflow (changes exceeded issue boundaries)
- Timeout (agent was making progress but ran out of time)
- Skill prompt gap (skill instructions didn't cover this case)
- Count frequency of each category
- For the top 2-3 categories, identify specific fixes
Note on conversation logs: The 164MB of .jsonl transcripts in ~/.claude/projects/ could provide deeper forensics (exact tool call sequences, error messages, agent reasoning). However:
- These are Claude Code's internal format, not a Sequant data source
- The schema isn't documented or stable
- 164MB ≈ 40M tokens — 40x the context window, requires selective loading
- Not portable to Sequant users — only usable for internal dogfooding
Conversation log analysis should be treated as an internal-only supplement, not a product feature. For portable analysis, only run logs and metrics are available.
A4: Decision Framework
For each finding from A2/A3, define what action it implies:
| Finding Pattern | Action Type | Decision Maker |
|---|---|---|
| Phase X adds no value for issue type Y | Change default phase mapping in phase-mapper.ts |
Code change |
| Skill prompt causes consistent failure mode | Update SKILL.md in all 3 directories | Prompt change |
| Quality loop iteration N has diminishing returns | Adjust maxIterations default or add early-exit logic |
Config + code |
| Success rate differs by 20%+ between segments | Surface in stats insights to guide users |
Stats enhancement |
| Specific error accounts for >10% of failures | Fix the root cause directly | Bug fix |
This prevents the common failure mode of "we analyzed the data, found interesting things, and then did nothing."
Phase B: Targeted Tooling (Only If A Reveals Gaps)
Build only what the investigation proves is needed. Likely candidates based on known stats gaps:
B1: Fill stats Gaps
Specific enhancements that stats.ts doesn't currently have:
- Temporal trends — success rate, duration, cost over time (weekly/monthly buckets)
- Per-issue-type segmentation — break metrics by label (bug vs feature vs refactor)
- First-pass QA rate — QA pass rate without quality loop (distinct from overall success)
- QA verdict distribution — READY_FOR_MERGE vs AC_MET_BUT_NOT_A_PLUS vs AC_NOT_MET counts
These are additive to the existing 770 LOC, not a rewrite.
B2: Metrics Extraction for Context Loading
If manual context-loading proves valuable in Phase A, formalize it:
- Script that concatenates run logs into a context-loadable summary format
- One row per issue-phase, not per run (more granular than current CSV export)
- Include fields that current CSV omits: verdict, loop iterations, labels, lines changed
This may just be an enhancement to sequant stats --csv rather than a new script.
B3: /analyze Skill (Evaluate After A)
A skill that automates the Tier 1 analysis from Phase A. Architectural constraint: skills can't efficiently read 81 files. Viable approaches:
- Preprocessing:
sequant stats --json --detailedproduces a single JSON blob, skill reads one file - Pipe approach: Skill instructions say "run
sequant stats --jsonvia Bash, then analyze the output" - MCP resource: New
sequant://analyticsresource that returns pre-computed analysis
Decide which approach after Phase A reveals what analysis is actually valuable. Don't build the skill speculatively.
Context Window Budget (Corrected)
| Analysis | What to Load | Actual Token Estimate |
|---|---|---|
| Run performance audit | All 81 run logs (620KB JSON) | ~150-200K (15-20%) |
| Failure deep-dive | 5-10 failed run logs + notes | ~30-50K (3-5%) |
| Stats JSON output | sequant stats --json |
~5-10K (<1%) |
| Skill prompt audit | All 18 SKILL.md files | ~50-80K (5-8%) |
| Conversation log (single) | One full /fullsolve transcript |
~100-300K (10-30%) |
| Conversation logs (selective) | 5-10 failed run transcripts | ~200-500K (20-50%) |
Key constraint: Conversation logs (~40M tokens total) cannot be bulk-loaded. Must be highly selective — pick specific sessions by run ID correlation.
What's Portable for Sequant Users
Only data sources that Sequant controls are portable:
| Portable (ship it) | Internal Only (dogfooding) |
|---|---|
Run logs (.sequant/logs/) |
Conversation transcripts (~/.claude/) |
Metrics (.sequant/metrics.json) |
Claude Code session data |
State (.sequant/state.json) |
Internal usage patterns |
| GitHub data (issues, PRs, comments) | |
sequant stats output |
Any analysis tool we build should work exclusively with portable data sources. Conversation log mining is valuable for us but cannot be a product feature.
Acceptance Criteria
Investigation (Phase A)
- Current
sequant statsoutput reviewed and gaps documented - Baselines established from existing data (success rate, avg duration, cost per run)
- Bulk log analysis completed: temporal trends, phase-level analysis, segmentation
- First-pass QA rate calculated (not currently in
stats) - All failed runs categorized by failure mode with frequency counts
- Top 3-5 optimization targets identified and ranked by impact
- Decision framework applied: each finding mapped to a specific action type
Tooling (Phase B — only after A is complete)
- Specific
statsenhancements identified from Phase A gaps (if any) - At least 2 actionable follow-up issues created from findings
- Analysis approach documented so it can be repeated after workflow changes
Non-Goals
- Building dashboards, data warehouses, or persistent analytics infrastructure
- Telemetry or data collection that leaves the user's machine
- Automated regression detection (future scope)
- Benchmarking against other tools
- Treating conversation log analysis as a portable/product feature
- A/B testing (sample sizes are too small for statistical rigor; use qualitative before/after comparison instead)
Related
src/commands/stats.ts— existing 770 LOC analytics command (substantial overlap, must build on top of)src/lib/workflow/run-reflect.ts— per-run reflection (subset of cross-run analysis)/reflectskill — session-level workflow analysis/improveskill — code pattern analysis (complementary, different focus)- sequant_logs: include QA verdict summary in structured output #434 — QA verdict summary in logs (supports failure forensics)
Activity
admarble commentedon Mar 25, 2026
Spec Plan: #437 — Data-Driven Workflow Optimization
AC Quality Check
AC format uses nested markdown headings — parser didn't auto-extract. Manual extraction below. Quality assessment:
statsenhancements identified" — clear (conditional on Phase A)No vague or unmeasurable AC items.
Scope Assessment
Non-Goals (from issue)
Verdict:⚠️ SCOPE_WARNING — 10 AC items across 2 phases, but Phase B is explicitly conditional on Phase A. The issue is well-structured with clear phase boundaries.
Acceptance Criteria
Phase A: Investigation
AC-1: Current
sequant statsoutput reviewed and gaps documentedVerification Method: Manual Test
sequant stats --jsonoutputAC-2: Baselines established from existing data
Verification Method: Integration Test
AC-3: Bulk log analysis completed (temporal trends, phase-level, segmentation)
Verification Method: Integration Test
AC-4: First-pass QA rate calculated
Verification Method: Unit Test
AC-5: All failed runs categorized by failure mode
Verification Method: Integration Test
AC-6: Top 3-5 optimization targets identified and ranked by impact
Verification Method: Manual Test
AC-7: Decision framework applied
Verification Method: Manual Test
Phase B: Tooling
AC-8: Specific
statsenhancements identified from Phase A gapsVerification Method: Integration Test
stats.tsenhancementsAC-9: At least 2 actionable follow-up issues created
Verification Method: Manual Test
gh issue createAC-10: Analysis approach documented so it can be repeated
Verification Method: Manual Test
docs/reference/or as a repeatable scriptImplementation Plan
Phase 1: Analysis Script (AC-1, AC-2, AC-3, AC-4, AC-5)
Create
scripts/analytics/analyze-runs.tsthat:.sequant/logs/Key data points already known:
Phase 2: Findings Report (AC-6, AC-7)
Synthesize analysis output into:
docs/reference/workflow-analysis-2026-03.mdPhase 3: Stats Enhancements (AC-8)
Based on Phase A gaps, enhance
stats.tswith:--detailedflag for expanded analysis (temporal trends, QA verdicts, segmentation)Phase 4: Follow-up Issues + Documentation (AC-9, AC-10)
Design Review
Where does this logic belong? Analysis script in
scripts/analytics/(one-time investigation), with targeted enhancements tosrc/commands/stats.ts(durable tooling). Report indocs/reference/.What's the simplest correct approach? A TypeScript analysis script that loads all logs, computes everything in-memory, and outputs JSON. Stats enhancements are additive to the existing 770 LOC — no rewrite. Follow-up issues created via
gh issue create.What existing pattern does this follow? Follows
scripts/qa/*.tspattern for one-off analysis scripts. Stats enhancements follow existingstats.tspatterns (AggregateStats interface, display functions).What would a senior reviewer challenge? (1) "Why a script vs just loading logs into a conversation?" — Script is repeatable (AC-10) and produces structured output for stats integration. (2) "Is the analysis script worth keeping long-term?" — Yes, it enables re-running after workflow changes per AC-10.
Feature Quality Planning
Completeness Check
Error Handling
Code Quality
Test Coverage Plan
Best Practices
Derived ACs
Recommended Workflow
Phases: spec → exec → qa
Quality Loop: enabled (auto-enabled due to scope warning)
Reasoning: Investigation + tooling issue, no UI components. Quality loop ensures analysis completeness.
Label Review
Current: enhancement, roadmap
Recommended: enhancement, roadmap, cli
Reason: Stats command is CLI-facing; analysis enhances CLI output
Quality Loop: Auto-enabled due to scope warning
→
gh issue edit 437 --add-label clifeat(#437): add bulk run log analysis and detailed stats
admarble commentedon Mar 25, 2026
QA Review for Issue #437
AC Coverage
--detailedflag adds QA verdicts, weekly trends, label segmentationCoverage: 11/11 AC items fully met
Quality Metrics
any)Test Coverage Analysis
scripts/analytics/analyze-runs.tsscripts/analytics/analyze-runs.test.tssrc/commands/stats.tssrc/commands/stats.test.tsbin/cli.tsdocs/reference/workflow-analysis-2026-03.mdCHANGELOG.mdCoverage: 3/3 changed source files have corresponding tests
CLI Registration Verification
detailedoptions.detailed(stats.ts)--detailedin bin/cli.tsVerification Status: Passed
Code Review
Strengths:
RunLogSchemaand patterns from stats.tsIssues found and fixed:
IssueLog,QaVerdict,Phase) in analyze-runs.ts — fixed in follow-up commitSuggestions:
Smoke Test
npx tsx scripts/analytics/analyze-runs.ts --jsonnpx tsx scripts/analytics/analyze-runs.tsnpx tsx bin/cli.ts stats --helpSmoke Test Status: Complete
CHANGELOG Verification
Result: CHANGELOG requirements met
Self-Evaluation
Verdict: READY_FOR_MERGE
All 11 AC items are met. Analysis script produces accurate findings from 82 run logs. Stats
--detailedflag is properly wired from CLI to implementation. Tests cover all new code. Two actionable follow-up issues (#447, #448) created from the highest-impact findings.Documentation
Next Steps
PR: #450
feat(#437): data-driven workflow analysis and detailed stats (#450)