Repository navigation
Extend deadweight's plugin lane: recency-based liveness, agent/MCP pricing, honest gating - #704
Conversation
…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]>
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]>
|
| 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
| 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) |
There was a problem hiding this comment.
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.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]>
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$0figure, 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
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 trailingUNUSED_RECENCY_WINDOW_DAYS(20) days, measured from timestamped transcript evidence.name: descriptionlisting only, never the body), and routed plugin-contributed MCP servers through the existingmcp_probemeasurement path instead of leaving them invisible.cost_proposals(Review inbox) and the web UI's deadweight card — previously CLI-only.~/.claude/settings.jsonhand-edit; taggeddelivery="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 checkedpluginUsage.usageCount == 0out 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 incore/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__toolcalls,Skill/Task/Agentinvocations by slug — fired anywhere in the trailing 20 days, via a new independent scan (_scan_recency_window) anchored at the report's ownuntilrather than itssince. 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 7drun 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/PluginDeadweightboth 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→unusedthroughout (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_charsonly walkedSKILL.mdfiles, 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/*.md) get the identical frontmatter-listing-line treatment skills already had (core/agent_config.PluginComponentFile,skill_listing_linereused with the agent's filename stem as fallback)..mcp.json, enumerated bycore/agent_config.scan_pluginsand tagged with the newSCOPE_PLUGINscope) are routed through the existingcore/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 (
enabledPluginsis 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 whencomponentsis non-empty, at least one component was actually priced (resident_tokens > 0), and every component's usage resolved toFalse. The non-empty/priced guard exists specifically to stop a vacuous truth:all()over an empty or entirely-unmeasured component list is triviallyTruein 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_pluginspreviously 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 theunused_pluginslist 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_reportalongside the existing_deadweight_to_proposals, same"deadweight"AggregateFamily(updated insingle_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 carriesclaude 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 anddeliverytag were wrong (told the user to hand-editenabledPlugins, tagged as a CLAUDE.md rule). Corrected to nameclaude plugin disable <name>and taggeddelivery="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:
deadweightalready clears all three actionability gates for theclaude-codepersona (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 wheneverestimated_tax_tokens_windowis 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: extractedinvoked_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-deadOptimizeConfig.min_sessions_deadweightfield 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.SKILL.mdfiles (no existing fixture had this) pinning that the$0-with-disable-arrow row cannot render.partial_use_no_fix) — no fix offered, unused components named.MIN_SESSIONS_DEADWEIGHTconfig 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.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):
ruff check tokenjam/andmypy tokenjam/are clean on every file this PR touches (mypyreports one pre-existing, unrelated error atcore/config.py:623, outside this diff).What's NOT in this PR
enabledPluginsfile-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 toclaudefrom the analyzer, a separate decision.docs/optimize/deadweight.mdproduct 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