Skip to content

Add stat filters to Tech Debt Initiatives - #120

Merged
amorde merged 4 commits into
mainfrom
tdi-stat-filters
Nov 9, 2026
Merged

amorde merged 4 commits into
mainfrom
tdi-stat-filters

Conversation

@amorde

@amorde amorde commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

A Tech Debt Initiative could only track a whole stat. This lets an initiative count part of a stat, for example only the code references whose extras match, so one collected stat can back several initiatives.

  • Add remainingFilter and completedFilter to TechDebtInitiative. A StatFilter holds extras conditions on a code references stat. Each condition is a ValueMatcher: one of a list of values, a regex, or "present", optionally negated.
  • Publish each filtered stat at build time as a derived stat, keyed by the filter's optional key or by default tdi__<id>__remaining or tdi__<id>__completed, added to every module that has the source stat. It gets totals, history, the web report and the per-stat JSON and SARIF exports like any other stat, and is left out of the aggregate stats.sarif.
  • Add effectiveRemainingStatKey and effectiveCompletedStatKey, the stat to read for an initiative (the derived stat when filtered). They are written to tdi_config.json, so consumers that show or export initiative numbers can read them directly.
  • Fail the report on an invalid filter, listing every problem.
  • Rerun the invert task when techDebtInitiatives change.
  • Add a filtered initiative to the examples project.
Additional context

Why derived stats. History only stores per-stat totals, so filtering in the browser could not produce a burndown over time. Publishing the filtered result as its own stat means everything downstream (totals, history, exports, the Stat Breakdown and Code References pages) works without changes. For example, ?page=stat_breakdown&remaining=tdi__<id>__remaining&completed=tdi__<id>__completed shows the initiative's progress.

Validation. The report fails on a filter on a stat that is not a code references stat, an extra the stat does not declare (a typo would otherwise silently report 0 remaining), an empty or invalid matcher, a blank key, a completedFilter without a completedStatKey, a derived key produced more than once (duplicate initiative ids or filter keys), or a derived key that a collected stat already uses. A source stat that was not collected only logs a warning, as unfiltered initiatives do.

Semantics.

  • A negated matcher matches items without that extra: "not X" includes missing.
  • REGEX finds a match anywhere in the value; anchor with ^…$ for a full match.
  • Only code references stats can be filtered. Numeric and boolean stats hold one value per module, so filtering them needs its own design and is left for later.
  • A derived code-references stat with no matches is still exported, so a finished initiative reads 0 rather than missing.

Compatibility.

  • The new constructor parameters have defaults, and older tdi_config.json files still decode.
  • The filter models use only concrete types and always encode their non-null defaults, so readers of tdi_config.json that are not written in Kotlin see every field.
  • The effective keys are body properties encoded with @EncodeDefault.

History. A derived stat's history is kept by its key. StatFilter.key versions a definition independently of the initiative id; changing what a filter selects without changing the key mixes two definitions in one history. This is documented on TechDebtInitiative and StatFilter. Charts that plot a stat over time show 0 for history points from before the derived stat existed.

Not included. A report page listing initiatives. The upstream report has none today: Stat Breakdown lists stats, so a filtered initiative's two derived stats appear there separately, under a "Tech Debt Initiatives" category.

Testing. ./gradlew assemble check passes (JDK 17), with new tests in StatFiltersTest, TechDebtInitiativeTest and TechDebtInitiativeStatsTest. Running ./gradlew :invert in examples/ with --rerun-tasks produces both derived stats: 15 remaining Ktor wildcard imports and 2 explicit Ktor imports, rendered as "11.8% Complete (2 of 17)".

Screenshot 2026-11-04 at 10 58 42 AM Screenshot 2026-11-04 at 10 58 49 AM

🤖 Generated with Claude Code

A Tech Debt Initiative can now count part of a stat. `remainingFilter`
and `completedFilter` take a `StatFilter`: `extras` conditions for code
references, or a `details` condition for numeric and boolean stats.

Each filtered stat is published at build time as a derived stat,
`tdi__<id>__remaining` or `tdi__<id>__completed`, so it gets totals,
history, the web report and per-stat JSON/SARIF exports like any other
stat. Derived stats are left out of the aggregate stats.sarif.
`effectiveRemainingStatKey` and `effectiveCompletedStatKey` name the
stat to read for an initiative and are written to tdi_config.json.

Invalid filters fail the report, and the invert task now reruns when
initiatives change. The examples project gains a filtered initiative.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@amorde
amorde marked this pull request as ready for review November 4, 2026 21:10
Comment thread invert-gradle-plugin/build.gradle.kts Resolved
No consumer reads tdi_config.json into the Invert models with Gson, so
the test and its test dependency are not needed. Defaults are still
encoded for readers that are not written in Kotlin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
amorde and others added 2 commits November 9, 2026 13:58
A filter can now set an explicit derived stat key, so its history can be
versioned independently of the initiative id. Filters only apply to code
references stats; the details condition for numeric and boolean stats is
removed until that case has its own design.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ng stats

- Add @jvmoverloads so Java and Groovy callers keep the constructor without filters.
- Report filter problems that do not depend on the source stat (blank key, empty extras,
  invalid matchers) even when the source stat was not collected.
- Correct the StatFilters KDoc: only the build uses it, with JVM regex syntax.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@amorde
amorde merged commit dfb162d into main Nov 9, 2026
6 of 7 checks passed
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.

2 participants