Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/trusted-plugin-skills.md
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.
21 changes: 21 additions & 0 deletions packages/opencode/src/kilocode/config/plugin-skill-origins.ts
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"
3 changes: 3 additions & 0 deletions packages/opencode/src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type { WorkspaceAdapter } from "@/control-plane/types"
import { RuntimeFlags } from "@/effect/runtime-flags"
import { EventV2Bridge } from "@/event-v2-bridge"
import { InstallationChannel } from "@opencode-ai/core/installation/version"
import { PluginSkillOrigins } from "@/kilocode/config/plugin-skill-origins" // kilocode_change

type State = {
hooks: Hooks[]
Expand Down Expand Up @@ -247,6 +248,7 @@ export const layer = Layer.effect(
}

// Notify plugins of current config
const configuredSkillPaths = new Set(cfg.skills?.paths ?? []) // kilocode_change

Copy link
Copy Markdown
Contributor

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.md asks for single-word locals unless a compound is genuinely needed; mark() already calls this parameter before, so the compound adds nothing and makes the shared upstream line longer than it needs to be.

Suggested change
const configuredSkillPaths = new Set(cfg.skills?.paths ?? []) // kilocode_change
const before = new Set(cfg.skills?.paths ?? []) // kilocode_change

The call on the line below would become PluginSkillOrigins.mark(cfg, before).


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

Copy link
Copy Markdown
Contributor

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.

for (const hook of hooks) {
yield* Effect.tryPromise({
try: () => Promise.resolve((hook as any).config?.(cfg)),
Expand All @@ -256,6 +258,7 @@ export const layer = Layer.effect(
Effect.ignore,
)
}
PluginSkillOrigins.mark(cfg, configuredSkillPaths) // kilocode_change - retain provenance for skill paths added by config hooks

const unsubscribe = yield* events.listen((event) => {
if (event.location?.directory !== ctx.directory) return Effect.void
Expand Down
11 changes: 11 additions & 0 deletions packages/opencode/test/kilocode/fixtures/plugin-skill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import path from "node:path"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Unused import

path is no longer used now that the directory is built with a template string, so this import is dead.

Suggested change
import path from "node:path"
export default async (input: { directory: string }) => ({

(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 @kilocode-bot fix it to have Kilo Code address this issue.

Copy link
Copy Markdown
Contributor

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.


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`]
},
})
78 changes: 78 additions & 0 deletions packages/opencode/test/kilocode/plugin-skill-path.test.ts
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.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 trusted: true to the matched object pins the actual behavior being fixed, so a future regression that discovers the skill as untrusted (which changes substitution and shell-execution behavior) still fails the test.

Suggested change
description: "Registered by a plugin config hook.",
description: "Registered by a plugin config hook.",
trusted: true,

Reply with @kilocode-bot fix it to have Kilo Code address this issue.

content: expect.stringContaining("plugin payload"),
})
}),
{
config: { plugin: [plugin] },
init: (dir) =>
Effect.promise(async () => {
await Bun.write(
path.join(`${dir}-plugin-skills`, "example", "SKILL.md"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: The sibling skills directory is never removed

Using ${dir}-plugin-skills fixes the shared-name problem from the earlier revision, but the scoped finalizer in tmpdirScoped (test/fixture/fixture.ts:157) only cleans dir itself, so each run leaves an opencode-test-<random>-plugin-skills tree behind in the system temp dir. init runs inside the tmpdir scope, so a yield* Effect.addFinalizer(() => Effect.promise(() => fs.rm(${dir}-plugin-skills, { recursive: true, force: true }))) inside the init effect (or wrapping the promise body in Effect.gen) would clean it up with the rest of the fixture.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

Copy link
Copy Markdown
Contributor

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.

`---
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")
}),
},
)
Loading