feat(mcp): tool-list drift classifier — groundwork for #110 C2b#114
Merged
feat(mcp): tool-list drift classifier — groundwork for #110 C2b#114
Conversation
Pure function `classifyToolListDrift(before, after) → DriftReport` encoding the cache-cost taxonomy validated by the live spike (#113): - `identity` — same names, same order, same content → free - `append` — every before-tool unchanged, new tools at the end → trivially cheap (94.8% hit observed) - `edit` — same names + positions, content of ≥1 tool changed → bounded loss past the divergence point - `reorder` — same set, different order, OR additions not at the end → catastrophic - `remove` — any before-tool missing from after → catastrophic; dominates even when other tools were added Report carries `added` / `removed` / `edited` arrays so the policy layer (next PR) can populate the warn line precisely. Pure function, no I/O. 12 unit tests cover the matrix including edge cases (empty before/after, remove-with-also-added). Refs #110.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #110.
What
Pure function
classifyToolListDrift(before, after)returning aDriftReport. Encodes the cache-cost taxonomy validated by the live DeepSeek spike (#113):identityappendeditreorderremoveReport carries
added/removed/editedarrays so the policy layer (next PR) can populate the user-facing warn line precisely without re-walking the lists.Why now
C2b (the
/mcp reconnectslash) needs to map drift → policy. Splitting the classifier into its own PR gets the ground truth landed and reviewable before the imperative teardown logic is layered on top.Touch
src/mcp/drift.ts— pure classifier +DriftReporttypetests/mcp-drift.test.ts— 12 cases covering identity, append (single + multiple), edit (description + schema), remove (alone + with adds), reorder, and edge cases (empty before / empty after)No source code outside this new module is touched.
Next PR (C2b proper)
/mcp reconnect <name>slash +rkeybind inMcpBrowsermodal. The handler will:McpClientfor<name>, snapshot its current tool listmcp.close(), drop the prefixed tools fromToolRegistryclassifyToolListDriftover old vs new tool listsidentity/append→ silent success (✓ connected)edit→ success + warn card showingeditedarray + per-tool divergence pointreorder/remove→ refuse unless--force(or--strictuser already opted in to that)↻ reconnectstart,✓ connected/✖ failedend (per design §37)Test plan
npm run verifypasses (1772 tests, +12)