diff --git a/packages/coding-agent/src/config/settings-schema.ts b/packages/coding-agent/src/config/settings-schema.ts index 70b2ff934..858a67079 100644 --- a/packages/coding-agent/src/config/settings-schema.ts +++ b/packages/coding-agent/src/config/settings-schema.ts @@ -1612,6 +1612,22 @@ export const SETTINGS_SCHEMA = { ui: { tab: "tasks", label: "Claude Project Commands", description: "Load commands from .claude/commands/" }, }, + "commands.enableOpencodeUser": { + type: "boolean", + default: true, + ui: { + tab: "tasks", + label: "OpenCode User Commands", + description: "Load commands from ~/.config/opencode/commands/", + }, + }, + + "commands.enableOpencodeProject": { + type: "boolean", + default: true, + ui: { tab: "tasks", label: "OpenCode Project Commands", description: "Load commands from .opencode/commands/" }, + }, + // ──────────────────────────────────────────────────────────────────────── // Providers // ──────────────────────────────────────────────────────────────────────── diff --git a/packages/coding-agent/src/discovery/claude.ts b/packages/coding-agent/src/discovery/claude.ts index 1159e3521..1f86bebe8 100644 --- a/packages/coding-agent/src/discovery/claude.ts +++ b/packages/coding-agent/src/discovery/claude.ts @@ -18,6 +18,7 @@ import { type SlashCommand, slashCommandCapability } from "../capability/slash-c import { type SystemPrompt, systemPromptCapability } from "../capability/system-prompt"; import { type CustomTool, toolCapability } from "../capability/tool"; import type { LoadContext, LoadResult } from "../capability/types"; +import { settings } from "../config/settings"; import { calculateDepth, createSourceMeta, @@ -252,48 +253,69 @@ async function loadExtensionModules(ctx: LoadContext): Promise> { const items: SlashCommand[] = []; const warnings: string[] = []; + const { enableUser, enableProject } = readClaudeCommandToggles(); - const userBase = getUserClaude(ctx); - const userCommandsDir = path.join(userBase, "commands"); + if (enableUser) { + const userBase = getUserClaude(ctx); + const userCommandsDir = path.join(userBase, "commands"); - const userResult = await loadFilesFromDir(ctx, userCommandsDir, PROVIDER_ID, "user", { - extensions: ["md"], - transform: (name, content, path, source) => { - const cmdName = name.replace(/\.md$/, ""); - return { - name: cmdName, - path, - content, - level: "user", - _source: source, - }; - }, - }); + const userResult = await loadFilesFromDir(ctx, userCommandsDir, PROVIDER_ID, "user", { + extensions: ["md"], + transform: (name, content, path, source) => { + const cmdName = name.replace(/\.md$/, ""); + return { + name: cmdName, + path, + content, + level: "user", + _source: source, + }; + }, + }); - items.push(...userResult.items); - if (userResult.warnings) warnings.push(...userResult.warnings); + items.push(...userResult.items); + if (userResult.warnings) warnings.push(...userResult.warnings); + } - const projectCommandsDir = path.join(ctx.cwd, CONFIG_DIR, "commands"); + if (enableProject) { + const projectCommandsDir = path.join(ctx.cwd, CONFIG_DIR, "commands"); - const projectResult = await loadFilesFromDir(ctx, projectCommandsDir, PROVIDER_ID, "project", { - extensions: ["md"], - transform: (name, content, path, source) => { - const cmdName = name.replace(/\.md$/, ""); - return { - name: cmdName, - path, - content, - level: "project", - _source: source, - }; - }, - }); + const projectResult = await loadFilesFromDir(ctx, projectCommandsDir, PROVIDER_ID, "project", { + extensions: ["md"], + transform: (name, content, path, source) => { + const cmdName = name.replace(/\.md$/, ""); + return { + name: cmdName, + path, + content, + level: "project", + _source: source, + }; + }, + }); - items.push(...projectResult.items); - if (projectResult.warnings) warnings.push(...projectResult.warnings); + items.push(...projectResult.items); + if (projectResult.warnings) warnings.push(...projectResult.warnings); + } return { items, warnings }; } diff --git a/packages/coding-agent/src/discovery/opencode.ts b/packages/coding-agent/src/discovery/opencode.ts index a8987e163..cc2054dbf 100644 --- a/packages/coding-agent/src/discovery/opencode.ts +++ b/packages/coding-agent/src/discovery/opencode.ts @@ -26,6 +26,7 @@ import { type Settings, settingsCapability } from "../capability/settings"; import { type Skill, skillCapability } from "../capability/skill"; import { type SlashCommand, slashCommandCapability } from "../capability/slash-command"; import type { LoadContext, LoadResult, SourceMeta } from "../capability/types"; +import { settings } from "../config/settings"; import { buildExtensionModuleItems, @@ -236,9 +237,26 @@ async function loadExtensionModules(ctx: LoadContext): Promise> { - const userCommandsDir = getUserPath(ctx, "opencode", "commands"); - const projectCommandsDir = getProjectPath(ctx, "opencode", "commands"); + const { enableUser, enableProject } = readOpencodeCommandToggles(); + const userCommandsDir = enableUser ? getUserPath(ctx, "opencode", "commands") : null; + const projectCommandsDir = enableProject ? getProjectPath(ctx, "opencode", "commands") : null; const transformCommand = (level: "user" | "project") => (name: string, content: string, filePath: string, source: SourceMeta) => { diff --git a/packages/coding-agent/test/tools/sqlite.test.ts b/packages/coding-agent/test/tools/sqlite.test.ts index 198918dcd..d190cfd47 100644 --- a/packages/coding-agent/test/tools/sqlite.test.ts +++ b/packages/coding-agent/test/tools/sqlite.test.ts @@ -292,9 +292,7 @@ describe("SQLite tool support", () => { expect(() => parseSqliteSelector("users", "where=1=1 LIMIT 1000000 --&limit=2&offset=0")).toThrow( /comments or statement terminators/i, ); - expect(() => parseSqliteSelector("users", "where=status='active' LIMIT 1")).toThrow( - /LIMIT\/OFFSET\/UNION/i, - ); + expect(() => parseSqliteSelector("users", "where=status='active' LIMIT 1")).toThrow(/LIMIT\/OFFSET\/UNION/i); expect(() => parseSqliteSelector("users", "where=1=1; DROP TABLE users")).toThrow( /comments or statement terminators/i, );