-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix: prevent recursive skill removal #11240
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
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,6 @@ | ||
| --- | ||
| "@kilocode/cli": patch | ||
| "kilo-code": patch | ||
| --- | ||
|
|
||
| Prevent skill removal from recursively deleting working directories. |
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,37 @@ | ||
| import { unlink } from "node:fs/promises" | ||
| import path from "node:path" | ||
| import { Global } from "@opencode-ai/core/global" | ||
| import { Skill } from "@/skill" | ||
|
|
||
| const LEGACY_BUILTIN_LOCATION = "<built-in>" | ||
|
|
||
| type Info = Pick<Skill.Info, "location"> | ||
|
|
||
| export function builtin(location: string) { | ||
| return location === Skill.BUILTIN_LOCATION || location === LEGACY_BUILTIN_LOCATION | ||
| } | ||
|
|
||
| export function target(location: string, skills: readonly Info[]) { | ||
| if (builtin(location)) throw new Error("cannot remove built-in skill") | ||
|
|
||
| const skill = skills.find((item) => item.location === location) | ||
| if (!skill) throw new Error("skill not found in registry") | ||
| if (builtin(skill.location)) throw new Error("cannot remove built-in skill") | ||
| if (!path.isAbsolute(skill.location)) throw new Error("skill location must be absolute") | ||
|
|
||
| const file = path.resolve(skill.location) | ||
| if (path.basename(file) !== "SKILL.md") throw new Error("skill location must reference SKILL.md") | ||
|
|
||
| const cache = path.join(Global.Path.cache, "skills") | ||
| const relative = path.relative(cache, file) | ||
| if (relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative))) { | ||
| throw new Error("remove URL-backed skills from configuration") | ||
| } | ||
| return file | ||
| } | ||
|
|
||
| export async function remove(location: string, skills: readonly Info[]) { | ||
| const file = target(location, skills) | ||
| // Removing only the manifest disables discovery without recursively deleting user files. | ||
| await unlink(file) | ||
| } |
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,46 @@ | ||
| import { describe, expect, test } from "bun:test" | ||
| import path from "node:path" | ||
| import { Global } from "@opencode-ai/core/global" | ||
| import { target } from "../../src/kilocode/skill-remove" | ||
|
|
||
| const info = (location: string) => ({ | ||
| name: "synthetic", | ||
| description: "Synthetic skill used for path validation.", | ||
| location, | ||
| content: "synthetic", | ||
| }) | ||
|
|
||
| describe("skill removal target", () => { | ||
| test("rejects the canonical built-in location", () => { | ||
| expect(() => target("builtin", [info("builtin")])).toThrow("cannot remove built-in skill") | ||
| }) | ||
|
|
||
| test("rejects the legacy customize-opencode built-in location", () => { | ||
| expect(() => target("<built-in>", [info("<built-in>")])).toThrow("cannot remove built-in skill") | ||
| }) | ||
|
|
||
| test("rejects locations that are not in the active skill registry", () => { | ||
| const location = path.join(path.parse(process.cwd()).root, "__kilo_synthetic__", "SKILL.md") | ||
| expect(() => target(location, [])).toThrow("skill not found in registry") | ||
| }) | ||
|
|
||
| test("rejects relative registered locations", () => { | ||
| const location = path.join("synthetic", "SKILL.md") | ||
| expect(() => target(location, [info(location)])).toThrow("skill location must be absolute") | ||
| }) | ||
|
|
||
| test("rejects registered locations that are not manifests", () => { | ||
| const location = path.join(path.parse(process.cwd()).root, "__kilo_synthetic__", "skill") | ||
| expect(() => target(location, [info(location)])).toThrow("skill location must reference SKILL.md") | ||
| }) | ||
|
|
||
| test("rejects URL-backed cache entries", () => { | ||
| const location = path.join(Global.Path.cache, "skills", "synthetic", "SKILL.md") | ||
| expect(() => target(location, [info(location)])).toThrow("remove URL-backed skills from configuration") | ||
| }) | ||
|
|
||
| test("returns only the registered skill manifest", () => { | ||
| const location = path.join(path.parse(process.cwd()).root, "__kilo_synthetic__", "skill", "SKILL.md") | ||
| expect(target(location, [info(location)])).toBe(location) | ||
| }) | ||
| }) |
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.