-
Notifications
You must be signed in to change notification settings - Fork 12
feat(toolkit-docs-generator): latest-version coherence filter #907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
51174db
feat(toolkit-docs-generator): add majority-version coherence filter
jottakka ffd37c4
fix: address review — deduplicate extractVersion, fix semver comparison
jottakka 651b4be
fix: handle pre-release and build metadata in version comparison
jottakka ea5ab6b
fix: use highest version, not majority count, to filter stale tools
jottakka 498d9e8
fix: remove ambiguous extractVersion re-export from data-merger
jottakka 5947dde
fix: update toolkit-diff to import extractVersion from utils
jottakka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import type { ToolDefinition } from "../types/index.js"; | ||
| import { extractVersion } from "./fp.js"; | ||
|
|
||
| /** | ||
| * Parse the numeric MAJOR.MINOR.PATCH tuple from a semver string, | ||
| * stripping pre-release (`-alpha.1`) and build metadata (`+build.456`). | ||
| * | ||
| * Handles formats produced by arcade-mcp's normalize_version(): | ||
| * "3.1.3", "1.2.3-beta.1", "1.2.3+build.456", "1.2.3-rc.1+build.789" | ||
| */ | ||
| const parseNumericVersion = (version: string): number[] => { | ||
| // Strip build metadata (after +) then pre-release (after -) | ||
| const core = version.split("+")[0]?.split("-")[0] ?? version; | ||
| return core.split(".").map((s) => { | ||
| const n = Number(s); | ||
| return Number.isNaN(n) ? 0 : n; | ||
| }); | ||
| }; | ||
|
|
||
| /** | ||
| * Compare two semver version strings numerically by MAJOR.MINOR.PATCH. | ||
| * Pre-release and build metadata are ignored for ordering purposes | ||
| * (they are unlikely to appear in Engine API responses, but we handle | ||
| * them defensively since arcade-mcp's semver allows them). | ||
| * | ||
| * Returns a positive number if a > b, negative if a < b, 0 if equal. | ||
| */ | ||
| const compareVersions = (a: string, b: string): number => { | ||
| const aParts = parseNumericVersion(a); | ||
| const bParts = parseNumericVersion(b); | ||
| const len = Math.max(aParts.length, bParts.length); | ||
| for (let i = 0; i < len; i++) { | ||
| const diff = (aParts[i] ?? 0) - (bParts[i] ?? 0); | ||
| if (diff !== 0) return diff; | ||
| } | ||
| return 0; | ||
| }; | ||
|
|
||
| /** | ||
| * Find the highest version among all tools in a toolkit. | ||
| * This is the version we keep — stale tools from older releases are dropped. | ||
| */ | ||
| export const getHighestVersion = ( | ||
| tools: readonly ToolDefinition[] | ||
| ): string | null => { | ||
| if (tools.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| let best = ""; | ||
| for (const tool of tools) { | ||
| const version = extractVersion(tool.fullyQualifiedName); | ||
| if (best === "" || compareVersions(version, best) > 0) { | ||
| best = version; | ||
| } | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| return best || null; | ||
| }; | ||
|
jottakka marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Keep only tools whose @version matches the highest version for | ||
| * their toolkit. If all tools share the same version (the common | ||
| * case), returns the original array unchanged. | ||
| * | ||
| * This drops stale tools from older releases that Engine still serves, | ||
| * while always preserving the newest version — even if it has fewer tools | ||
| * (e.g. tools were removed/consolidated in the new release). | ||
| */ | ||
| export const filterToolsByHighestVersion = ( | ||
| tools: readonly ToolDefinition[] | ||
| ): readonly ToolDefinition[] => { | ||
| const highest = getHighestVersion(tools); | ||
| if (highest === null) { | ||
| return tools; | ||
| } | ||
|
|
||
| // Fast path: if every tool is already at the highest version, skip filtering | ||
| const allSame = tools.every( | ||
| (t) => extractVersion(t.fullyQualifiedName) === highest | ||
| ); | ||
| if (allSame) { | ||
| return tools; | ||
| } | ||
|
|
||
| return tools.filter((t) => extractVersion(t.fullyQualifiedName) === highest); | ||
| }; | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not a new issue in this PR, but i did notice that we do a deeper hunt for toolkit data when looking up one toolkit than we do when listing... which means the listed toolkit's data (icon, url, etc.) might differ from a single fetch toolkit's data.