Repository navigation
fix(cli): preserve trust for plugin-provided skills #12760
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
Changes from 2 commits
7bac10c
1c2de7d
c2b791b
ed356ca
1ee08fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@kilocode/cli": patch | ||
| --- | ||
|
|
||
| Load skills registered by plugin config hooks reliably. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import type { Config } from "@/config/config" | ||
|
|
||
| export function mark(cfg: Config.Info, before: ReadonlySet<string>) { | ||
| const paths = cfg.skills?.paths | ||
| if (!paths?.length) return | ||
|
|
||
| // Only paths added after plugin hooks began are trusted. Config-file paths | ||
| // already have an origin recorded by Config.load; limiting this to the | ||
| // observed delta keeps missing provenance fail-closed for future callers. | ||
| const origins = { ...cfg.skill_path_origins } | ||
| for (const path of paths) { | ||
| if (before.has(path) || origins[path]) continue | ||
| origins[path] = { | ||
| trusted: true, | ||
| source: "plugin config hook", | ||
| } | ||
| } | ||
| cfg.skill_path_origins = origins | ||
| } | ||
|
|
||
| export * as PluginSkillOrigins from "./plugin-skill-origins" |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,11 @@ | ||||||
| import path from "node:path" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION: Unused import
Suggested change
(Applying the suggestion above also drops the following blank line's purpose — if you prefer, just delete line 1 and the blank line manually.) Reply with
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To use Kilo from GitHub you first need to link your GitHub account to Kilo. Link your Kilo account to continue. After linking, mention me again in this issue or pull request. |
||||||
|
|
||||||
| export default async (input: { directory: string }) => ({ | ||||||
| config: async (cfg: { skills?: { paths?: string[] } }) => { | ||||||
| cfg.skills = cfg.skills ?? {} | ||||||
| // Keep the fixture outside the project root so the test exercises the trust | ||||||
| // boundary used by plugin-provided skill directories, while retaining a | ||||||
| // unique path for each test run. | ||||||
| cfg.skills.paths = [...(cfg.skills.paths ?? []), `${input.directory}-plugin-skills`] | ||||||
| }, | ||||||
| }) | ||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,78 @@ | ||||||||
| import { expect } from "bun:test" | ||||||||
| import { FSUtil } from "@opencode-ai/core/fs-util" | ||||||||
| import { Global } from "@opencode-ai/core/global" | ||||||||
| import { Effect, Layer } from "effect" | ||||||||
| import { FetchHttpClient } from "effect/unstable/http" | ||||||||
| import path from "node:path" | ||||||||
| import { pathToFileURL } from "node:url" | ||||||||
| import { AccountTest } from "../fake/account" | ||||||||
| import { AuthTest } from "../fake/auth" | ||||||||
| import { NpmTest } from "../fake/npm" | ||||||||
| import { Config } from "../../src/config/config" | ||||||||
| import { Discovery } from "../../src/skill/discovery" | ||||||||
| import { Env } from "../../src/env" | ||||||||
| import { EventV2Bridge } from "../../src/event-v2-bridge" | ||||||||
| import { Git } from "../../src/git" | ||||||||
| import { Plugin } from "../../src/plugin" | ||||||||
| import { RuntimeFlags } from "../../src/effect/runtime-flags" | ||||||||
| import { Skill } from "../../src/skill" | ||||||||
| import { testEffect } from "../lib/effect" | ||||||||
|
|
||||||||
| const plugin = pathToFileURL(path.join(import.meta.dir, "fixtures", "plugin-skill.ts")).href | ||||||||
| const flags = RuntimeFlags.layer({ disableDefaultPlugins: true }) | ||||||||
| const config = Config.layer.pipe( | ||||||||
| Layer.provide(Git.defaultLayer), | ||||||||
| Layer.provide(flags), | ||||||||
| Layer.provide(FSUtil.defaultLayer), | ||||||||
| Layer.provide(Env.defaultLayer), | ||||||||
| Layer.provide(AuthTest.empty), | ||||||||
| Layer.provide(AccountTest.empty), | ||||||||
| Layer.provide(NpmTest.noop), | ||||||||
| Layer.provide(FetchHttpClient.layer), | ||||||||
| ) | ||||||||
| const events = EventV2Bridge.defaultLayer | ||||||||
| const plugins = Plugin.layer.pipe(Layer.provide(events), Layer.provide(flags), Layer.provide(config)) | ||||||||
| const skills = Skill.layer.pipe( | ||||||||
| Layer.provide(Git.defaultLayer), | ||||||||
| Layer.provide(Discovery.defaultLayer), | ||||||||
| Layer.provide(config), | ||||||||
| Layer.provide(events), | ||||||||
| Layer.provide(FSUtil.defaultLayer), | ||||||||
| Layer.provide(Global.layer), | ||||||||
| Layer.provide(flags), | ||||||||
| ) | ||||||||
| const layer = Layer.mergeAll(config, plugins, skills) | ||||||||
| const it = testEffect(layer) | ||||||||
|
|
||||||||
| it.instance( | ||||||||
| "loads skills registered by a plugin config hook", | ||||||||
| () => | ||||||||
| Effect.gen(function* () { | ||||||||
| yield* Plugin.Service.use((service) => service.init()) | ||||||||
| const list = yield* Skill.Service.use((service) => service.all()) | ||||||||
|
|
||||||||
| expect(list.find((item) => item.name === "plugin-skill")).toMatchObject({ | ||||||||
| description: "Registered by a plugin config hook.", | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION: Assert the trust flag, not just discovery The fix is specifically about provenance/trust, but the assertion only checks that the skill was discovered. Adding
Suggested change
Reply with |
||||||||
| content: expect.stringContaining("plugin payload"), | ||||||||
| }) | ||||||||
| }), | ||||||||
| { | ||||||||
| config: { plugin: [plugin] }, | ||||||||
| init: (dir) => | ||||||||
| Effect.promise(async () => { | ||||||||
| await Bun.write( | ||||||||
| path.join(`${dir}-plugin-skills`, "example", "SKILL.md"), | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION: The sibling skills directory is never removed Using Reply with
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To use Kilo from GitHub you first need to link your GitHub account to Kilo. Link your Kilo account to continue. After linking, mention me again in this issue or pull request. |
||||||||
| `--- | ||||||||
| name: plugin-skill | ||||||||
| description: Registered by a plugin config hook. | ||||||||
| --- | ||||||||
|
|
||||||||
| # Plugin skill | ||||||||
|
|
||||||||
| {file:../payload.txt} | ||||||||
| `, | ||||||||
| ) | ||||||||
| await Bun.write(path.join(`${dir}-plugin-skills`, "payload.txt"), "plugin payload") | ||||||||
| }), | ||||||||
| }, | ||||||||
| ) | ||||||||
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.
SUGGESTION: Prefer a single-word name here
AGENTS.mdasks for single-word locals unless a compound is genuinely needed;mark()already calls this parameterbefore, so the compound adds nothing and makes the shared upstream line longer than it needs to be.The call on the line below would become
PluginSkillOrigins.mark(cfg, before).Reply with
@kilocode-bot fix itto have Kilo Code address this issue.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.
To use Kilo from GitHub you first need to link your GitHub account to Kilo. Link your Kilo account to continue. After linking, mention me again in this issue or pull request.