Skip to content

feat(dash): remove-mcp-and-skills backend: one question, measured savings since removal - #537

Merged
amiddavid merged 5 commits into
mainfrom
feat/remove-mcp-skills
Oct 15, 2026
Merged

amiddavid merged 5 commits into
mainfrom
feat/remove-mcp-skills

Conversation

@OsherElhadad

@OsherElhadad OsherElhadad commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Backend for /context-guru:remove-mcp-and-skills, which replaces adapt tools. The command and its rendering live in the plugin PR. Stacked on #531.

What

  • Built-in tools are never listed. That covers Claude Code's and Codex's: only MCP servers, MCP tools and skills are, and never Context Guru's own. A test declares unused built-ins of both agents and expects an empty list.
  • One ready question. recommendation.question is the best option as a single question. Alongside it: the set it removes (remove), what it would have saved over the window (saved_to_date_usd) and per week (saved_per_week_usd), and the one-off cache rewrite it costs (rewrite_usd). The full option list is unchanged.
  • Measured savings since removal. saved_so_far is what removals already made have saved, measured from the request rows:
    • Filter: the inventory reads the body before the filter, so a filtered request records both the declaration set the client sent (decl_digest) and the tokens not forwarded (filtered_decl_tokens). Each removed item is priced on exactly the requests it was stripped from, at each request's model and tier. The total is the filter's own count.
    • Client: removals made with claude mcp remove or skillOverrides come from the Inventory's existing self-removal credit, and are counted once if the item is also filtered.
    • The method is in docs/components/reformat.md.
  • would_add_usd: what the recommended change adds on top, net of its one-off rewrite.
  • carriedCost can be restricted to filtered requests, or return each priced request (used for the client estimate).
  • Behaviour change everywhere: the declaration filter's realized saving (DeclFilterSavings, also shown on the Inventory tab) now prices a request that wrote one-hour cache tokens at 2x input instead of 1.25x. It changes only on accounts with one-hour writes.
  • Client-side removals are an estimate shown apart: priced per later request at that request's model and tier, labelled "estimated (removed in the client)", never added to the measured total.
  • Measured total = per-item rows + an "unattributed" row: one pricing basis, so the rows always sum to the total.
  • The question reads as hindsight, and says how long the one-off rewrite takes to pay back. If that is longer than the history window, it recommends keeping as is.

Tests

  • Built-ins never listed.
  • Synthetic rows before and after a removal: only the post-removal requests count, and the per-item figure equals the filter's own total.
  • The question text and the saving fields.

@OsherElhadad OsherElhadad left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review: REQUEST CHANGES at e655498. The head moved past 6c113bf. (Posted as a comment: GitHub does not let the author account request changes.)

Verified:

  • Built-ins are never listed. Only mcp_tool and skill declarations become items, so every built-in of any agent, Claude Code's and Codex's alike, is excluded by kind. If KindTool is let through, TestAdaptToolsNeverListsBuiltins fails.
  • The question, payback and new recommendation fields compute as described. No recommendation is made when the rewrite costs at least the window's saving.
  • gofmt and go vet are clean, and the dash Adapt/Inventory/Tool/Decl/SelfRemoval tests pass. Both commits are signed off with no AI attribution, and the PR body has no figures. CI build-test was still running when I checked.

Blocking:

  1. The total and the per-item rows are priced on different bases, and nothing says so. saved_so_far.filter.usd (and therefore to_date.saved_usd) is DeclFilterSavings. It prices filtered_decl_tokens with accumulateDeclFilterRow, which knows no 1-hour tier: any cache write is 1.25x. The per-item rows come from carriedCost(..., onlyFiltered=true), which prices a request that wrote 1h tokens at 2x input. On a 1h-tier account the items therefore sum to more than the total they sit under. There are two more reasons they can differ:

    • the two token counts come from different paths (the filter's own count vs tool_declarations.tokens);
    • an item that was filtered earlier and is no longer on the removal list is in the total but has no row.

    The test only covers cache-read rows, so it cannot see this. Fix: either price the 1h tier the same way in accumulateDeclFilterRow (it needs cache_write_1h) and add an explicit "removed earlier / unattributed" row equal to total minus the sum of items, or make the itemized sum the figure and keep the filter's count as a check. Then add a 1h-write case to TestAdaptToolsMeasuresWhatARemovalSaved.

  2. An inferred credit is summed into a total labelled observed. SelfRemovals is an inference: an item stopped appearing, credited per session on the sessions that ran without it, and judged by sessions_after. Its own doc says it is "deliberately NOT netted into the declaration filter's realized savings". adaptToolsSaved adds Client.USD into TotalUSD, and to_date labels that total class: "observed". Keep to_date and saved_usd to the filter part, which is observed, and report the client part separately as estimated, with its sessions_after. Alternatively, label the total as mixed and stop calling it measured.

Non-blocking:

  • Question wording. "Remove 3 items (...), saving about $X a week?" states a hindsight figure as a promise. The weekly rate is what those items would have cost over this window. "would have saved about $X a week over the last N days" is honest without changing the number.
  • saved_per_week_usd and per_week_usd divide by calendar days in the window, not active days. That is fine, but say so in the field comment.

@OsherElhadad OsherElhadad left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Re-review: APPROVE at 920dc43 (8f6b9f6 and 920dc43 on top of e655498). (Posted as a comment: GitHub does not let the author account approve.)

Both blockers are fixed.

  1. Total vs items.
    • accumulateDeclFilterRow now reads cache_write_1h and prices a request that wrote any 1h tokens at 2x input, the same rule as carriedCost. The filter total and the per-item rows are therefore on one basis.
    • Any remaining difference (items filtered earlier but no longer listed, or the two token counts disagreeing) is shown as its own "unattributed" row instead of being hidden.
    • With the 1h branch disabled, or the unattributed row removed, TestAdaptToolsSavedItemsAndTotalAgree fails.
    • This also changes DeclFilterSavings wherever it is shown, which is more accurate on 1h accounts. The PR text could mention it in one line.
  2. The estimate is kept apart.
    • Client-side removals are now priced per request and labelled class: "estimated", with the Label "estimated (removed in the client)". They are excluded from total_usd and to_date, and their removed rows carry the estimated class.
    • With TotalUSD = Filter + Client restored, TestAdaptToolsEstimatesAClientSideRemovalPerRequest fails.

Also checked:

  • Payback. The payback calculation is guarded (days >= 1 && enoughUSD > 0). Without a payback the question falls back to "would have saved $X since ".
  • Question wording. It now reads as hindsight: "Over the last N days they would have saved about $X a week".
  • Checks. gofmt and go vet are clean, go test ./dash passes in full and the proxy Adapt|ToolFilter|Decl tests pass. CI is green, both commits are signed off with no AI attribution, and the PR body has no figures.

Non-blocking:

  • The cohort proxy, a later request that still carries any MCP tool or skill, assumes the removed item would still be carried there. That is reasonable, and it is labelled as an estimate.
  • SessionStart is the first request of the session within the report window, not the session's true start. A session that began before LastSeen but whose first in-window request falls after it is counted. This is minor, and only affects the estimate.
  • docs/plugin/adapt.md is not in this branch's base, so check the new renderer fields (to_date, removed, items_n, per_week_usd, range_per_week_usd) against it when #526 lands.

This approval covers 920dc43.

@OsherElhadad OsherElhadad left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Re-confirm: APPROVE at aaf87b6. It adds one test-only commit on top of the approved 920dc43: TestAdaptToolsSavedItemsAndTotalAgree now also asserts that the rows, including the unattributed row, sum to the measured total. The test passes and CI is green. Signed off. This approval covers aaf87b6.

…ed savings since removal

The recommendation is one question with the set, the saving per week and
to date, and the one-off cache rewrite. saved_so_far measures what
removals already saved from the request rows: the filter's removals on
exactly the requests it stripped them from (decl_digest plus
filtered_decl_tokens), priced per request; client-side removals from the
Inventory's self-removal credit. would_add_usd is what the recommended
change adds. Built-in tools are never listed; pinned by a test.

Signed-off-by: Osher-Elhadad <[email protected]>
@amiddavid
amiddavid changed the base branch from feat/inventory-carried-pricing to main October 15, 2026 11:10
Osher-Elhadad added 4 commits October 15, 2026 14:10
…e window; renderer fields

payback_weeks is the one-off cache rewrite in weeks of the recommended
saving. The question says when it takes more than a week to pay back,
and a payback longer than the history window recommends keeping as is.
Adds to_date and removed (the measured savings in the shared adapt
shape) and items_n, per_week_usd and range_per_week_usd on the
recommendation.

Signed-off-by: Osher-Elhadad <[email protected]>
…t apart

They were priced with the Inventory's older per-session self-removal
credit, which overstates. Now each detected removal is priced at its
tokens on every request of the later sessions that still carried MCP
tools or skills, at that request's model and tier, labelled
"estimated (removed in the client)" and never added to the measured
filter saving or to to_date.

Signed-off-by: Osher-Elhadad <[email protected]>
… show the item gap

DeclFilterSavings priced every cache write at 1.25x, while the per-item
rows price a one-hour write at 2x input, so on a one-hour account the
items summed past their total. Both now use the same rule, and any
remaining difference between the filter's own count and the items is an
"unattributed" row. The question now speaks in hindsight: what removing
the items would have saved a week over the last N days.

Signed-off-by: Osher-Elhadad <[email protected]>
@amiddavid
amiddavid force-pushed the feat/remove-mcp-skills branch from aaf87b6 to be799a1 Compare October 15, 2026 11:10
@amiddavid
amiddavid merged commit 45e1d16 into main Oct 15, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants