Skip to content

Extend deadweight's plugin lane: recency-based liveness, agent/MCP pricing, honest gating - #704

Merged
anshss merged 4 commits into
mainfrom
deadweight-plugin-coverage
Aug 7, 2026
Merged

anshss merged 4 commits into
mainfrom
deadweight-plugin-coverage

Conversation

@anshss

@anshss anshss commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

deadweight's plugin lane (PluginDeadweight, _plugin_rows, scan_plugins, DEADWEIGHT_DISABLE_PLUGIN) already flagged enabled-but-unused Claude Code plugins, but it was half-built: it used a liveness signal that can't answer the question it was being asked, it only priced skills (never agents or a plugin's own MCP servers), it could render a confident "disable it" arrow next to a $0 figure, and it never reached the web UI or the Review inbox. This closes those gaps and reconciles the plugin lane with the MCP server lane so both answer the same "is this actually unused" question the same way.

Summary

  • Retired the two disagreeing liveness standards (MIN_SESSIONS_DEADWEIGHT, a session-count floor for MCP servers; pluginUsage.usageCount, a non-timestamped cumulative counter for plugins) in favor of one recency window: an item is unused when nothing attributable to it fired in the trailing UNUSED_RECENCY_WINDOW_DAYS (20) days, measured from timestamped transcript evidence.
  • Priced agents the same way skills already were (name: description listing only, never the body), and routed plugin-contributed MCP servers through the existing mcp_probe measurement path instead of leaving them invisible.
  • Rolled components up to one plugin-level verdict, since enable/disable is whole-plugin only, with an explicit three-state gate (unused / partial-use-no-fix / insufficient-history) so a partially-used or under-measured plugin never renders a tempting number with no action behind it.
  • Wired the plugin lane into cost_proposals (Review inbox) and the web UI's deadweight card — previously CLI-only.
  • Fixed the plugin fix record, which named the wrong mechanism (~/.claude/settings.json hand-edit; tagged delivery="claude_md_rule") instead of the real one (claude plugin disable <name>).

One recency question, answered the same way everywhere

The MCP lane required a server to be configured-present in >= MIN_SESSIONS_DEADWEIGHT (5) distinct sessions with zero invocations across all of them. The plugin lane instead checked pluginUsage.usageCount == 0 out of ~/.claude.json — a cumulative counter with no timestamps, so it structurally cannot answer "used recently?"

Both are retired in favor of UNUSED_RECENCY_WINDOW_DAYS = 20, a named constant in core/optimize/analyzers/deadweight.py. A server or plugin component is unused when it was present at least once (so there's a real standing tax to report) and nothing attributable to it — mcp__server__tool calls, Skill/Task/Agent invocations by slug — fired anywhere in the trailing 20 days, via a new independent scan (_scan_recency_window) anchored at the report's own until rather than its since. That's deliberate: the report window (--since, default 30d) is a user-facing knob that can be narrower than the recency window, and anchoring the liveness check to it would make a --since 7d run flag everything as unused regardless of actual usage.

A corpus that doesn't reach back the full 20 days can't support an unused claim at all — that renders as insufficient_history, never a finding. This is checked explicitly (ServerDeadweight/PluginDeadweight both carry the flag) rather than left to infer from an empty result, per the product's standing rule that "not yet known" and "known and empty" must never collapse into the same rendering.

Renamed dead → unused throughout (DeadweightFinding.dead_servers → unused_servers, dead_plugins → unused_plugins) since the field no longer means "flagged by a heuristic bar" — it's a direct recency observation.

Every always-on component priced

_plugin_resident_chars only walked SKILL.md files, so a plugin shipping only agents or an MCP server scored zero tokens while the analyzer had no cost term to gate on, meaning it could still render a confident disable arrow next to ~0 tokens. Fixed two ways:

  • Agents (agents/*.md) get the identical frontmatter-listing-line treatment skills already had (core/agent_config.PluginComponentFile, skill_listing_line reused with the agent's filename stem as fallback).
  • Plugin-contributed MCP servers (a plugin's own .mcp.json, enumerated by core/agent_config.scan_plugins and tagged with the new SCOPE_PLUGIN scope) are routed through the existing core/optimize/mcp_probe.resolve_schema_measurements — the same live-probe, same caching, same "excluded rather than billed a default when unmeasured" discipline the MCP server lane already has. No second pricing model.

Honest rollup

Verified against the shipping CLI: enable/disable is whole-plugin only (enabledPlugins is a binary map; claude plugin disable <name> is the real command — there's no way to disable one skill inside a plugin). So components roll up to ONE verdict per plugin:

  • unused — only when components is non-empty, at least one component was actually priced (resident_tokens > 0), and every component's usage resolved to False. The non-empty/priced guard exists specifically to stop a vacuous truth: all() over an empty or entirely-unmeasured component list is trivially True in Python, which would otherwise flag a plugin with nothing to disable.
  • partial_use_no_fix — some components fired, some didn't. The card names the unused ones and states plainly that no fix is available, because the toggle would remove a component something else still relies on. No dollar figure is shown for this case.
  • insufficient_history — corpus too shallow to say either way.

cli/cmd_optimize.py:_render_deadweight_plugins previously fell through to the "no priced model observed, so no dollar figure" string whenever a plugin had nothing priced — the wrong reason, since the real cause was "nothing was measurable," not "no rate was found." That fallback is gone; a plugin with nothing priced no longer reaches the unused_plugins list at all (see the vacuous-truth guard above), so the row is suppressed rather than mislabeled.

Both surfaces

  • core/optimize/cost_proposals.py: new _deadweight_plugin_to_proposals, wired into _adapt_report alongside the existing _deadweight_to_proposals, same "deadweight" AggregateFamily (updated in single_derivation.py). Advise-only — unlike the MCP server's deterministic config-file splice, there's no file this adapter can edit on the user's behalf; the real fix is the CLI command, so every card carries claude plugin disable <name> as its copy-pasteable suggestion.
  • tokenjam/ui/index.html: the deadweight detail card now renders the plugin lane (resident/installed count, unused rows, partial-use notice, insufficient-history notice) mirroring the CLI's three-state gating — previously the web card only ever rendered MCP servers.
  • core/fixes/registry.py: DEADWEIGHT_DISABLE_PLUGIN's text and delivery tag were wrong (told the user to hand-edit enabledPlugins, tagged as a CLAUDE.md rule). Corrected to name claude plugin disable <name> and tagged delivery="cli_command". Added a second record, DEADWEIGHT_PLUGIN_PARTIAL_USE, for the partial-use case's "no fix available" text.

Deliberately not gated on persona or a dollar floor. The plugin cost-proposal adapter mirrors the sibling MCP-server adapter exactly: deadweight already clears all three actionability gates for the claude-code persona (it's one of the two archetypes the product judges every other analyzer against), and the MCP lane carries no dollar floor either — a card is offered whenever estimated_tax_tokens_window is nonzero. This follows existing precedent rather than introducing a new product decision, so I didn't stop to ask.

What's also in this PR

  • core/summarize/invocations.py: extracted invoked_names_in_record (was inlined in the private _scan_record) so the new recency scan can reuse the exact same Skill/command/Task/Agent detection instead of a second copy of the regexes.
  • core/config.py: removed the now-dead OptimizeConfig.min_sessions_deadweight field and its TOML-loading wire-up.

Tests

  • tests/unit/test_deadweight.py / tests/unit/test_deadweight_plugins.py: pin all three recency behaviors for both lanes — used within the window is not unused, last used outside it (with enough corpus depth) is unused, a shallow corpus is insufficient history rather than a finding.
  • New: a plugin with zero SKILL.md files (no existing fixture had this) pinning that the $0-with-disable-arrow row cannot render.
  • New: a plugin where only some components fire (partial_use_no_fix) — no fix offered, unused components named.
  • Retired 4 tests that exercised the deleted MIN_SESSIONS_DEADWEIGHT config surface (test_below_threshold_is_not_flagged_dead, test_default_min_sessions_preserved_when_unspecified, test_lower_min_sessions_flags_previously_hidden_server, test_run_reads_min_sessions_deadweight_from_ctx_config — the mechanism they tested no longer exists); replaced with a positive pin that a single present-and-unused session is now enough to flag a server (no hidden session-count minimum survives).
  • tests/unit/test_deadweight.py's fixtures write every session at effectively "now," which would read as a shallow corpus to the new recency scan; added an automatic, idempotent corpus-depth anchor (_ensure_corpus_depth, threaded through the module's one low-level _write_transcript) so individual tests don't need to know about it.
  • Updated field-rename fallout across test_cost_proposals.py, test_single_derivation.py, test_config.py, test_optimize_threshold_rendering.py, test_past_overspend.py, test_optimize_scoreboard.py, test_advertised_commands_are_invocable.py.

Ran locally (not the full suite):

pytest tests/unit/test_deadweight.py tests/unit/test_deadweight_plugins.py tests/unit/test_deadweight_apply.py \
  tests/unit/test_cost_proposals.py tests/unit/test_single_derivation.py tests/unit/test_config.py \
  tests/unit/test_optimize_threshold_rendering.py tests/unit/test_past_overspend.py \
  tests/unit/test_optimize_scoreboard.py tests/unit/test_fix_catalog.py tests/unit/test_fix_grounding.py \
  tests/unit/test_no_fix_prose_outside_the_catalog.py tests/unit/test_ui_offline.py \
  tests/unit/test_report_roundtrip.py tests/unit/test_agent_config.py tests/unit/test_transcript_cache.py \
  tests/unit/test_advertised_commands_are_invocable.py tests/unit/test_analyzer_scope_isolation.py \
  tests/unit/test_analyzer_scope.py tests/unit/test_batch_placement.py tests/unit/test_cost_accounting_guards.py \
  tests/unit/test_cost_proposal_verbs.py tests/unit/test_lens_ui_regression.py \
  tests/unit/test_optimize_resend_render.py tests/unit/test_optimize_summarize.py \
  tests/unit/test_persona_analyzer_gate.py tests/unit/test_quickstart.py tests/unit/test_scan_cycle_provenance.py
# 834 passed, 2 xfailed

ruff check tokenjam/ and mypy tokenjam/ are clean on every file this PR touches (mypy reports one pre-existing, unrelated error at core/config.py:623, outside this diff).

What's NOT in this PR

  • No deterministic apply path for the plugin disable (no enabledPlugins file-splice). The card is advise-only with the real CLI command as its copy-paste suggestion — building an apply path wasn't asked for and would mean shelling out to claude from the analyzer, a separate decision.
  • No new docs/optimize/deadweight.md product page — none existed before this PR either; out of scope.
  • .claude/product-state/ANALYZER-PERSONA-MATRIX.md §8 is left untouched at the maintainer's request (handled separately in the main checkout to avoid a double-edit across worktrees).

🤖 Generated with Claude Code

…icing, honest gating

The plugin lane (PluginDeadweight, scan_plugins, DEADWEIGHT_DISABLE_PLUGIN) was
half-built and made claims its data couldn't support. This closes the gaps.

## One recency question, answered the same way everywhere

The MCP lane required MIN_SESSIONS_DEADWEIGHT (5) distinct sessions with zero
invocations; the plugin lane used pluginUsage.usageCount, a cumulative counter
with no timestamps that structurally cannot answer "used recently?" Both are
retired in favour of UNUSED_RECENCY_WINDOW_DAYS (20): an item is unused when
nothing attributable to it fired in the trailing 20 days, measured from
timestamped transcript evidence (Skill/Task/Agent calls, mcp__server__tool
invocations) via a new independent scan (_scan_recency_window), anchored at
the report's own `until` rather than its `since` so a narrow --since window
can't make everything look unused. A corpus shorter than the window renders
as "not enough history yet" (insufficient_history), never a finding — this
is checked before any negative claim: `ServerDeadweight`/`PluginDeadweight`
both carry the flag now instead of `dead`, which is renamed `unused`
throughout (DeadweightFinding.unused_servers/unused_plugins).

## Every always-on component priced, not just skills

`_plugin_resident_chars` only summed SKILL.md frontmatter, so a plugin
shipping only agents or MCP servers scored 0 tokens while still rendering a
confident disable arrow. Agents now get the same name/description listing
treatment (core/agent_config.PluginComponentFile), and plugin-contributed MCP
servers (read from each install's own .mcp.json) route through the EXISTING
mcp_probe measurement path, tagged by plugin origin (agent_config.SCOPE_PLUGIN)
rather than a second pricing model.

## Honest rollup

Enable/disable is whole-plugin only (verified against the shipping CLI), so
components roll up to one verdict: `unused` only when EVERY component agrees
(with a vacuous-truth guard — an empty or all-unmeasured component set never
reads as "every component agrees"), `partial_use_no_fix` when some fired and
some didn't (states plainly that no fix is available rather than dangling a
number with no action behind it), `insufficient_history` otherwise. A plugin
with nothing priced can no longer render a $0 row with a disable arrow — the
old CLI code reused the "no priced model observed" string for that case,
which was the wrong reason.

## Both surfaces

Wired unused-plugin rows through cost_proposals (_deadweight_plugin_to_proposals,
same lifecycle as the MCP removal's Review-inbox card, advise-only via
`claude plugin disable <name>` since there's no deterministic file-splice apply
path here) and through the web UI's deadweight card (ui/index.html), mirroring
the CLI's three-state gating. The plugin fix record's delivery tag was
"claude_md_rule" and its text said to hand-edit `~/.claude/settings.json`;
both were wrong (it's a CLI command, not a rule written into an instruction
file) and are corrected, plus a new record for the partial-use case.

No persona gating or dollar floor added to the plugin cost-proposal adapter:
it mirrors the sibling MCP-server adapter exactly (deadweight passes all
three actionability gates for claude-code; no floor exists on that lane
either), so this follows existing precedent rather than a new decision.

## Tests

- Pins the three recency behaviors: used within the window is not unused,
  last used outside it (with enough corpus depth) is unused, a shallow corpus
  is insufficient history rather than a finding — for both the MCP and plugin
  lanes.
- Pins that a plugin with zero SKILL.md files (no existing fixture had this)
  never renders the $0-with-disable-arrow row.
- Retired 4 tests exercising the deleted MIN_SESSIONS_DEADWEIGHT config
  surface; replaced with a positive pin that a single present-and-unused
  session is now enough (no hidden session-count minimum survives).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@anshss
anshss requested a review from anilmurty as a code owner August 6, 2026 14:50
Promoting the durable lesson from the deadweight plugin-lane work: the
plugin lane rendered in the CLI for a long stretch before its fix ever
reached cost_proposals and the Review inbox, which is where most users
actually see and act on a finding. Naming the pattern so the next new
lane wires both surfaces from the start instead of needing a follow-up
PR to catch up.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@greptile-apps

greptile-apps Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR expands deadweight analysis to use a shared recency model, price plugin agents and MCP servers, roll component state into plugin-level verdicts, and expose plugin recommendations through the CLI, dashboard, and Review inbox.

  • Replaces session-count and cumulative-usage heuristics with a 20-day transcript recency scan.
  • Adds agent and plugin MCP-server resident-cost measurement.
  • Introduces unused, partial-use, and insufficient-history plugin states.
  • Wires plugin findings into cost proposals and web rendering.
  • Corrects plugin-disable guidance to use the Claude CLI.

Confidence Score: 3/5

The PR does not appear safe to merge because transcript recency and plugin ownership attribution can still suppress valid unused-plugin recommendations.

The recency scan treats every invocation in a recently modified transcript as recent, while bare-slug matching lets activity from one plugin or local component mark another plugin’s same-named component as used; both behaviors leave the analyzer’s central unused verdict incorrect for reachable transcript and plugin configurations.

Files Needing Attention: tokenjam/core/optimize/analyzers/deadweight.py, tokenjam/core/agent_config.py

Important Files Changed

Filename Overview
tokenjam/core/optimize/analyzers/deadweight.py Implements the new recency and plugin rollup logic, but both previously reported liveness-attribution defects remain present.
tokenjam/core/agent_config.py Adds plugin agent and MCP component discovery, while component records still lack ownership-qualified identifiers needed for unambiguous liveness attribution.
tokenjam/core/optimize/cost_proposals.py Adapts unused plugin findings into advise-only Review inbox proposals.
tokenjam/ui/index.html Extends the deadweight card to display plugin unused, partial-use, and insufficient-history states.
tokenjam/cli/cmd_optimize.py Updates CLI deadweight rendering for the new plugin-level verdict states.
tokenjam/core/summarize/invocations.py Extracts reusable invocation-name detection consumed by the recency scan.

Reviews (3): Last reviewed commit: "Merge branch 'main' into deadweight-plug..." | Re-trigger Greptile

Comment on lines +729 to +740
def _recency_matches(used_names: frozenset[str], name: str) -> bool:
"""Whether `name` (a slug/server name a caller is asking about) was seen
in the recency scan — bare name OR, for a plugin-namespaced invocation
(`plugin:slug`), its bare suffix, mirroring
`core.summarize.invocations._bump`'s aliasing so a plugin's own skill
directory name (never namespaced on disk) still matches an invocation
Claude Code recorded with the plugin prefix."""
if not name:
return False
if name in used_names:
return True
return any(u.rsplit(":", 1)[-1] == name for u in used_names if ":" in u)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Component ownership is lost

When two enabled plugins expose the same skill or agent slug and only one qualified component is invoked, bare-suffix matching marks both plugins' components as used. The actually unused plugin is then omitted from unused_plugins, so no disable proposal reaches the Review inbox.

Prompt To Fix With AI
This is a comment left during a code review.
Path: tokenjam/core/optimize/analyzers/deadweight.py
Line: 729-740

Comment:
**Component ownership is lost**

When two enabled plugins expose the same skill or agent slug and only one qualified component is invoked, bare-suffix matching marks both plugins' components as used. The actually unused plugin is then omitted from `unused_plugins`, so no disable proposal reaches the Review inbox.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

anshss and others added 2 commits August 6, 2026 20:29
core/agent_config.py cited "Critical Rule 44" as covering why commands are
excluded from plugin pricing. No such rule exists (Critical Rule 44 is about
advertised CLI commands being invocable, an unrelated topic) -- deleted the
citation and kept the substantive prose (commands are excluded because their
standing context cost is near zero).

Two other citations pointed at "tokenjam's CLAUDE.md" for Critical Rule 42,
which actually lives in .claude/rules/optimize-analyzers.md -- the repo's own
citation convention names the file a rule is defined in, so corrected both to
the right path. Their subject matter was already accurate.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@anshss
anshss merged commit d11cb97 into main Aug 7, 2026
6 checks passed
@anilmurty
anilmurty deleted the deadweight-plugin-coverage branch September 18, 2026 21:02
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.

1 participant