You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(stats): add --label and --since filters for cohort measurement #640
sequant stats --detailed already shows label segmentation, but there's no way to filter the report to a single label or date window. This blocks automatic measurement of cohort success rates — e.g. AC-1 from #462 wanted "docs-labeled issues post-#451," which today requires a one-off jq script over .sequant/logs/run-*.json (see #462 closeout comment).
Acceptance Criteria
AC-1:sequant stats --label <name> filters all output (table, --json, --csv, --detailed) to runs whose issues carry the given label
AC-2:sequant stats --since <YYYY-MM-DD> filters by run startTime (UTC)
AC-3:--label and --since compose (both filters apply)
AC-4: When filters yield zero matches, output is a clear "no matching runs" message in the same format as the existing empty-data branch (no crash)
AC-5:src/commands/stats.test.ts covers: label match, label miss, date filter, combined filter, zero-match case
AC-6:bin/cli.ts registers both flags with .option(); README stats section documents them with a one-line example
Method
Filter happens after parseLogFile, before calculateStats / calculateDetailedAnalytics
A run is included if any issue in log.issues[] carries the label (matches existing label-segment logic in calculateDetailedAnalytics)
For per-issue stats with --label, count only the matching issues, not all issues in qualifying runs
AC-1:stats --label <name> filters all output (table, --json, --csv, --detailed) to runs whose issues carry the given label
AC-2:stats --since <YYYY-MM-DD> filters by run startTime (UTC)
AC-3:--label and --since compose (both filters apply)
AC-4: Zero-match yields a clear "no matching runs" message in the same format as the existing empty branch (no crash)
AC-5:src/commands/stats.test.ts covers: label match, label miss, date filter, combined, zero-match
AC-6:bin/cli.ts registers both flags; README + docs/reference/analytics.md document them with one-line examples
Implementation Plan
Phase 1 — Filter helper + CLI wiring
bin/cli.ts:360-370 — register .option("--label <name>", ...) and .option("--since <date>", ...) on the stats command.
src/commands/stats.ts —
Extend StatsOptions with label?: string; since?: string.
Add filterLogs(logs, { label, since }): RunLog[] helper (runs after parseLogFile, before calculateStats).
Per-run inclusion: --label keeps run iff any issue in log.issues[] carries the label (matches stats.ts:744-761 shape); --since keeps run iff log.startTime >= <since>T00:00:00Z.
Force log-mode when either filter is set — metrics schema has no per-issue labels (metrics-schema.ts:84 is issues: number[]), so bypass the metrics short-circuit at stats.ts:941.
Reuse existing empty-branch messages (no new format) when filtering yields zero.
Phase 2 — Tests
3. src/commands/stats.test.ts — new describe("--label and --since filters") block with 5 cases: label match, label miss (zero-match), --since cutoff, combined filters, invalid date.
Phase 3 — Docs
4. README.md §CLI Commands — append one-line example.
5. docs/reference/analytics.md §Viewing Analytics — short "Filtering" subsection with both flags.
Key Decisions
Filter at the run-log layer, not metrics. Metrics has no per-issue labels — the only way to satisfy AC-1 is to use .sequant/logs/run-*.json. When --label/--since are set, skip the metrics-first path.
Single helper applied at three call sites (JSON / CSV / human). Avoids threading filters into every analytics function.
Empty-result reuses existing empty branches — no new "no matching runs" string format; the existing "No data found" / {error, runs: []} / header-only-CSV outputs already satisfy AC-4 verbatim.
Open Questions
--until upper bound? Recommendation: defer; composable later without breaking change.
Repeated --label for OR-of-labels? Recommendation: defer; AC-1 says single label.
Recommended Workflow
Phases: spec → exec → qa (no /test: backend CLI; no /testgen: AC-5 covered by the unit-test work in exec).
Added entry under ## [Unreleased] / ### Added referencing (#640).
Risk Assessment
Likely failure mode: User passes a --since that excludes all their runs and assumes the filter is broken. Mitigation: unambiguous "No matching runs" message; syntactically invalid dates exit with code 1.
Not tested: Positive-result combined filter (where both --label and --since survive). The AND-composition test covers the zero-match path; smoke-verified manually with Jan/Mar fixture. Low risk — filterLogs is two independent if checks chained, both single-filter positive paths are tested.
Sibling sites: N/A — new feature; precheck siblingGrep found 0 cross-file siblings for filterLogs / emitNoMatchingRuns.
Documentation
✅ README — one-line example in §CLI Commands
✅ docs/reference/analytics.md — new §"Filtering by Label or Date" subsection
Activity
admarble commentedon May 14, 2026
Plan Complete
AC Checklist
stats --label <name>filters all output (table,--json,--csv,--detailed) to runs whose issues carry the given labelstats --since <YYYY-MM-DD>filters by runstartTime(UTC)--labeland--sincecompose (both filters apply)src/commands/stats.test.tscovers: label match, label miss, date filter, combined, zero-matchbin/cli.tsregisters both flags; README +docs/reference/analytics.mddocument them with one-line examplesImplementation Plan
Phase 1 — Filter helper + CLI wiring
bin/cli.ts:360-370— register.option("--label <name>", ...)and.option("--since <date>", ...)on the stats command.src/commands/stats.ts—StatsOptionswithlabel?: string; since?: string.filterLogs(logs, { label, since }): RunLog[]helper (runs afterparseLogFile, beforecalculateStats).--labelkeeps run iff any issue inlog.issues[]carries the label (matchesstats.ts:744-761shape);--sincekeeps run ifflog.startTime >= <since>T00:00:00Z.metrics-schema.ts:84isissues: number[]), so bypass the metrics short-circuit atstats.ts:941.--since:Date.parseNaN → throwInvalid --since date: <value>. Expected YYYY-MM-DD.Phase 2 — Tests
3.
src/commands/stats.test.ts— newdescribe("--label and --since filters")block with 5 cases: label match, label miss (zero-match),--sincecutoff, combined filters, invalid date.Phase 3 — Docs
4. README.md §CLI Commands — append one-line example.
5.
docs/reference/analytics.md§Viewing Analytics — short "Filtering" subsection with both flags.Key Decisions
.sequant/logs/run-*.json. When--label/--sinceare set, skip the metrics-first path.{error, runs: []}/ header-only-CSV outputs already satisfy AC-4 verbatim.Open Questions
--untilupper bound? Recommendation: defer; composable later without breaking change.--labelfor OR-of-labels? Recommendation: defer; AC-1 says single label.Recommended Workflow
Phases: spec → exec → qa (no
/test: backend CLI; no/testgen: AC-5 covered by the unit-test work in exec).docs(#640): add CHANGELOG entry for stats filters
admarble commentedon May 14, 2026
QA Review for Issue #640
Verdict: READY_FOR_MERGE
All 6 ACs literally verified, 18/18 unit tests pass, build + lint clean, CLI flags wired and smoke-verified end-to-end.
AC Coverage
--labelfilters all outputfilterLogsapplied at JSON, CSV, human, and--detailedsites.log.issues.some(i => i.labels.includes(label))matches the AC text.--since YYYY-MM-DDfilters by run startTime UTC<since>T00:00:00Z; compared againstlog.startTime.filterLogsANDs both predicates; smoke-tested in both positive and negative composed cases.emitNoMatchingRunsmirrors existing empty shapes — JSON{error,runs:[]}, header-only CSV, headerBox + warning for human.--sincecutoff, composed AND, invalid date.bin/cli.tsregisters both.option()calls; README +docs/reference/analytics.mdboth updated.Quality Metrics
stats.ts,bin/cli.ts,stats.test.ts,README.md,analytics.md,CHANGELOG.md)any)Smoke Test (end-to-end)
CHANGELOG
Added entry under
## [Unreleased] / ### Addedreferencing(#640).Risk Assessment
--sincethat excludes all their runs and assumes the filter is broken. Mitigation: unambiguous "No matching runs" message; syntactically invalid dates exit with code 1.--labeland--sincesurvive). The AND-composition test covers the zero-match path; smoke-verified manually with Jan/Mar fixture. Low risk —filterLogsis two independentifchecks chained, both single-filter positive paths are tested.siblingGrepfound 0 cross-file siblings forfilterLogs/emitNoMatchingRuns.Documentation
docs/reference/analytics.md— new §"Filtering by Label or Date" subsection[Unreleased] / AddedentryNext Steps
PR is ready. Closes #640.
fix(#640): close QA gaps — strict --since regex, AND-positive test, -…
feat(#640): stats --label and --since filters for cohort measurement (#…
docs: refresh README "What's new" for 2.x
feat(#783): surface failureCategory breakdown from metrics.json in se…
feat(#783): surface failureCategory breakdown in sequant stats