-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat(vscode): notify on matching marketplace items #11698
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
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "kilo-code": minor | ||
| --- | ||
|
|
||
| Notify when a marketplace item matches your workspace, with a one-click install button and a "Don't show again" option per suggestion. |
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
123 changes: 123 additions & 0 deletions
123
packages/kilo-vscode/src/services/marketplace/notifier.ts
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,123 @@ | ||
| import * as os from "os" | ||
| import * as vscode from "vscode" | ||
| import { MarketplaceService } from "." | ||
| import { fetchMarketplaceData, type MarketplaceActionContext } from "./actions" | ||
| import { selectSuggestions, showSuggestionNotification, suggestionSlug } from "./notify" | ||
| import type { KiloConnectionService } from "../cli-backend" | ||
| import type { MarketplaceItem } from "./types" | ||
|
|
||
| const DISMISSED_KEY = "kilo.marketplace.dismissedSuggestions" | ||
| const DEBOUNCE = 1500 | ||
|
|
||
| /** Opens the marketplace install flow for a suggested item. */ | ||
| export type InstallHandler = (item: MarketplaceItem) => void | ||
|
|
||
| /** | ||
| * Scans the workspace for marketplace items annotated with relevant `suggest_for` | ||
| * metadata and surfaces a discardable VS Code notification offering a one-click | ||
| * install. Runs in the background, independent of the marketplace panel. | ||
| */ | ||
| export class MarketplaceNotifier implements vscode.Disposable { | ||
| private readonly marketplace = new MarketplaceService() | ||
| private disposables: vscode.Disposable[] = [] | ||
| private timer: ReturnType<typeof setTimeout> | undefined | ||
| private generation = 0 | ||
| private disposed = false | ||
| /** Slugs already shown this session so a single scan burst doesn't re-toast. */ | ||
| private shown = new Set<string>() | ||
|
|
||
| constructor( | ||
| private readonly connection: KiloConnectionService, | ||
| private readonly context: vscode.ExtensionContext, | ||
| private readonly install: InstallHandler, | ||
| ) { | ||
| this.disposables.push( | ||
| vscode.workspace.onDidChangeWorkspaceFolders(() => this.schedule()), | ||
| vscode.extensions.onDidChange(() => this.schedule()), | ||
| vscode.workspace.onDidCreateFiles(() => this.schedule()), | ||
| ) | ||
| } | ||
|
|
||
| /** Begin the first background scan. Safe to call once after activation. */ | ||
| start(): void { | ||
| this.schedule() | ||
| } | ||
|
|
||
| dispose(): void { | ||
| this.disposed = true | ||
| if (this.timer) clearTimeout(this.timer) | ||
| this.timer = undefined | ||
| this.generation++ | ||
| for (const disposable of this.disposables) disposable.dispose() | ||
| this.disposables = [] | ||
| this.marketplace.dispose() | ||
| } | ||
|
|
||
| private schedule(): void { | ||
| if (this.timer) clearTimeout(this.timer) | ||
| this.timer = setTimeout(() => { | ||
| this.timer = undefined | ||
| void this.scan() | ||
| }, DEBOUNCE) | ||
| } | ||
|
|
||
| private dismissed(): string[] { | ||
| return this.context.globalState.get<string[]>(DISMISSED_KEY, []) ?? [] | ||
| } | ||
|
|
||
| private async dismiss(slug: string): Promise<void> { | ||
| const existing = this.dismissed() | ||
| if (existing.includes(slug)) return | ||
| await this.context.globalState.update(DISMISSED_KEY, [...existing, slug]) | ||
| } | ||
|
|
||
| private project(): string | undefined { | ||
| return vscode.workspace.workspaceFolders?.[0]?.uri.fsPath | ||
| } | ||
|
|
||
| private directory(): string { | ||
| return this.project() ?? os.homedir() | ||
| } | ||
|
|
||
| private roots(): vscode.Uri[] { | ||
| return vscode.workspace.workspaceFolders?.map((folder) => folder.uri) ?? [] | ||
| } | ||
|
|
||
| private get ctx(): MarketplaceActionContext { | ||
| return { connection: this.connection, marketplace: this.marketplace, storage: this.context.globalStorageUri } | ||
| } | ||
|
|
||
| private async scan(): Promise<void> { | ||
| const generation = ++this.generation | ||
| const data = await fetchMarketplaceData(this.ctx, this.project(), this.directory(), this.roots()).catch( | ||
| (err: unknown) => { | ||
| console.warn("[Kilo New] Marketplace suggestion scan failed:", err) | ||
| return undefined | ||
| }, | ||
| ) | ||
| if (!data || generation !== this.generation) return | ||
|
|
||
| const installed = new Set([ | ||
| ...Object.keys(data.marketplaceInstalledMetadata.project), | ||
| ...Object.keys(data.marketplaceInstalledMetadata.global), | ||
| ]) | ||
| const suggestions = selectSuggestions(data.marketplaceItems, data.marketplaceRelevance, [ | ||
| ...this.dismissed(), | ||
| ...this.shown, | ||
| ...installed, | ||
| ]) | ||
| if (suggestions.length === 0) return | ||
|
|
||
| // Surface one suggestion at a time to avoid stacking toasts. | ||
| const item = suggestions[0] | ||
| const slug = suggestionSlug(item) | ||
| this.shown.add(slug) | ||
|
|
||
| // A later rescan must never void the user's explicit choice, so only a | ||
| // disposed notifier short-circuits here — not a bumped generation. | ||
| const choice = await showSuggestionNotification(item) | ||
| if (this.disposed) return | ||
| if (choice?.action === "install") this.install(item) | ||
| if (choice?.action === "dismiss") await this.dismiss(slug) | ||
| } | ||
| } | ||
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,52 @@ | ||
| import * as vscode from "vscode" | ||
| import type { MarketplaceItem, MarketplaceRelevanceMetadata } from "./types" | ||
|
|
||
| /** Stable, discardable identifier for a suggestion. Matches the relevance map key. */ | ||
| export function suggestionSlug(item: Pick<MarketplaceItem, "id" | "type">): string { | ||
| return `${item.type}:${item.id}` | ||
| } | ||
|
|
||
| /** | ||
| * Pick the items worth surfacing as a notification: relevant to the workspace and | ||
| * not previously dismissed. Pure so it can be unit tested without VS Code. | ||
| */ | ||
| export function selectSuggestions( | ||
| items: MarketplaceItem[], | ||
| relevance: MarketplaceRelevanceMetadata, | ||
| dismissed: Iterable<string>, | ||
| ): MarketplaceItem[] { | ||
| const skip = new Set(dismissed) | ||
| return items.filter((item) => { | ||
| const slug = suggestionSlug(item) | ||
| return Boolean(relevance[slug]) && !skip.has(slug) | ||
| }) | ||
| } | ||
|
|
||
| export interface SuggestionChoice { | ||
| action: "install" | "dismiss" | ||
| item: MarketplaceItem | ||
| } | ||
|
|
||
| function describe(item: MarketplaceItem): string { | ||
| if (item.type === "agent") return `the ${item.name} agent` | ||
| if (item.type === "skill") return `the ${item.name} skill` | ||
| return `the ${item.name} MCP server` | ||
| } | ||
|
|
||
| /** | ||
| * Show a native VS Code notification for a matched item, offering a direct install | ||
| * and a persistent "Don't show again" dismissal. Resolves with the user's choice, | ||
| * or `undefined` if the toast was closed without picking an action. | ||
| */ | ||
| export async function showSuggestionNotification(item: MarketplaceItem): Promise<SuggestionChoice | undefined> { | ||
| const install = "Install" | ||
| const dismiss = "Don't show again" | ||
| const picked = await vscode.window.showInformationMessage( | ||
| `Kilo found ${describe(item)} that matches this workspace. Install it?`, | ||
| install, | ||
| dismiss, | ||
| ) | ||
| if (picked === install) return { action: "install", item } | ||
| if (picked === dismiss) return { action: "dismiss", item } | ||
| return undefined | ||
| } |
49 changes: 49 additions & 0 deletions
49
packages/kilo-vscode/tests/unit/marketplace-notify.test.ts
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,49 @@ | ||
| import { describe, expect, it } from "bun:test" | ||
| import { selectSuggestions, suggestionSlug } from "../../src/services/marketplace/notify" | ||
| import type { MarketplaceItem, MarketplaceRelevanceMetadata } from "../../src/services/marketplace/types" | ||
|
|
||
| const agent: MarketplaceItem = { | ||
| type: "agent", | ||
| id: "angular", | ||
| name: "Angular", | ||
| description: "Angular specialist", | ||
| category: "development", | ||
| content: { mode: "all", description: "Angular specialist", prompt: "Help with Angular" }, | ||
| suggest_for: { filename: ["*.component.ts"] }, | ||
| } | ||
|
|
||
| const mcp: MarketplaceItem = { | ||
| type: "mcp", | ||
| id: "jupyter", | ||
| name: "Jupyter", | ||
| description: "Jupyter notebooks", | ||
| category: "data", | ||
| url: "https://example.com", | ||
| content: "{}", | ||
| suggest_for: { vscode_extension: ["ms-toolsai.jupyter"] }, | ||
| } | ||
|
|
||
| const items = [agent, mcp] | ||
|
|
||
| describe("Marketplace suggestion notification", () => { | ||
| it("derives a stable discardable slug from type and id", () => { | ||
| expect(suggestionSlug(agent)).toBe("agent:angular") | ||
| expect(suggestionSlug(mcp)).toBe("mcp:jupyter") | ||
| }) | ||
|
|
||
| it("selects only relevant, non-dismissed items", () => { | ||
| const relevance: MarketplaceRelevanceMetadata = { | ||
| "agent:angular": { filename: ["*.component.ts"] }, | ||
| "mcp:jupyter": { vscodeExtension: ["ms-toolsai.jupyter"] }, | ||
| } | ||
|
|
||
| expect(selectSuggestions(items, relevance, [])).toEqual([agent, mcp]) | ||
| expect(selectSuggestions(items, relevance, ["agent:angular"])).toEqual([mcp]) | ||
| expect(selectSuggestions(items, relevance, ["agent:angular", "mcp:jupyter"])).toEqual([]) | ||
| }) | ||
|
|
||
| it("ignores items without a relevance match", () => { | ||
| const relevance: MarketplaceRelevanceMetadata = { "mcp:jupyter": { vscodeExtension: ["ms-toolsai.jupyter"] } } | ||
| expect(selectSuggestions(items, relevance, [])).toEqual([mcp]) | ||
| }) | ||
| }) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.