diff --git a/packages/opencode/src/agent/agent.ts b/packages/opencode/src/agent/agent.ts index b26c2c4445b..4d6db08ef6e 100644 --- a/packages/opencode/src/agent/agent.ts +++ b/packages/opencode/src/agent/agent.ts @@ -21,9 +21,9 @@ import { PermissionNext } from "@/permission/next" import { NamedError } from "@opencode-ai/util/error" // kilocode_change import { Glob } from "../util/glob" // kilocode_change import { mergeDeep, pipe, sortBy, values } from "remeda" -import { Global } from "@/global" -import { KilocodePaths } from "@/kilocode/paths" -import path from "path" +import { Global } from "@/global" // kilocode_change +import { KilocodePaths } from "@/kilocode/paths" // kilocode_change +import path from "path" // kilocode_change import { Plugin } from "@/plugin" import { Skill } from "../skill" @@ -64,10 +64,12 @@ export namespace Agent { const skillDirs = await Skill.dirs() const whitelistedDirs = [Truncate.GLOB, ...skillDirs.map((dir) => path.join(dir, "*"))] + // kilocode_change start — allow reading global config dirs without prompts const readableDirs = [ path.join(Global.Path.config, "*"), ...KilocodePaths.globalDirs().map((dir) => path.join(dir, "*")), ] + // kilocode_change end // kilocode_change start — safe bash commands that don't need user approval. // only commands that cannot execute arbitrary code or subprocesses. const bash: Record = { diff --git a/packages/opencode/src/tool/glob.ts b/packages/opencode/src/tool/glob.ts index 4156bea68ae..093d3b3cdfd 100644 --- a/packages/opencode/src/tool/glob.ts +++ b/packages/opencode/src/tool/glob.ts @@ -7,6 +7,7 @@ import { Ripgrep } from "../file/ripgrep" import { Instance } from "../project/instance" import { assertExternalDirectory } from "./external-directory" +// kilocode_change start — support absolute glob patterns (e.g. ~/.config/kilo/command/*.md) function normalize(p: string) { return p.replaceAll("\\", "/") } @@ -22,6 +23,7 @@ function split(pattern: string) { const next = normalized.slice(cut + 1) return { dir, pattern: next || "*" } } +// kilocode_change end export const GlobTool = Tool.define("glob", { description: DESCRIPTION, @@ -35,7 +37,7 @@ export const GlobTool = Tool.define("glob", { ), }), async execute(params, ctx) { - const absolute = split(params.pattern) + const absolute = split(params.pattern) // kilocode_change await ctx.ask({ permission: "glob", patterns: [params.pattern], @@ -46,7 +48,7 @@ export const GlobTool = Tool.define("glob", { }, }) - let search = absolute?.dir ?? params.path ?? Instance.directory + let search = absolute?.dir ?? params.path ?? Instance.directory // kilocode_change search = path.isAbsolute(search) ? search : path.resolve(Instance.directory, search) await assertExternalDirectory(ctx, search, { kind: "directory" }) @@ -55,7 +57,7 @@ export const GlobTool = Tool.define("glob", { let truncated = false for await (const file of Ripgrep.files({ cwd: search, - glob: [absolute?.pattern ?? params.pattern], + glob: [absolute?.pattern ?? params.pattern], // kilocode_change signal: ctx.abort, })) { if (files.length >= limit) { diff --git a/packages/opencode/test/agent/agent.test.ts b/packages/opencode/test/agent/agent.test.ts index 1d7c3cef3bd..ff8882f438e 100644 --- a/packages/opencode/test/agent/agent.test.ts +++ b/packages/opencode/test/agent/agent.test.ts @@ -4,7 +4,7 @@ import { tmpdir } from "../fixture/fixture" import { Instance } from "../../src/project/instance" import { Agent } from "../../src/agent/agent" import { PermissionNext } from "../../src/permission/next" -import { Global } from "../../src/global" +import { Global } from "../../src/global" // kilocode_change // Helper to evaluate permission for a tool with wildcard pattern function evalPerm(agent: Agent.Info | undefined, permission: string): PermissionNext.Action | undefined { @@ -159,6 +159,7 @@ test("explore agent asks for external directories and allows Truncate.GLOB", asy }) }) +// kilocode_change start test("code agent allows global config directory reads by default", async () => { await using tmp = await tmpdir() await Instance.provide({ @@ -172,6 +173,7 @@ test("code agent allows global config directory reads by default", async () => { }, }) }) +// kilocode_change end test("general agent denies todo tools", async () => { await using tmp = await tmpdir() diff --git a/packages/opencode/test/tool/glob.test.ts b/packages/opencode/test/tool/glob.test.ts index d2ea679516e..35e963d3710 100644 --- a/packages/opencode/test/tool/glob.test.ts +++ b/packages/opencode/test/tool/glob.test.ts @@ -1,3 +1,4 @@ +// kilocode_change - new file import { describe, expect, test } from "bun:test" import path from "path" import { GlobTool } from "../../src/tool/glob"