From 7bab85a3804cf93ec9d7459bfcbfd9bded0aa556 Mon Sep 17 00:00:00 2001 From: dbpolito Date: Thu, 26 Mar 2026 17:15:49 -0300 Subject: [PATCH] refactor: remove opencode subtask command mode - remove the adapter config and schema for subtask command stripping - simplify the OpenCode plugin by dropping conditional subtask command removal - delete tests that covered the removed configuration path --- kompass.jsonc | 1 - kompass.schema.json | 4 - packages/core/kompass.jsonc | 1 - packages/core/lib/config.ts | 5 - packages/core/test/config.test.ts | 13 -- packages/opencode/.opencode/kompass.jsonc | 3 +- packages/opencode/index.ts | 50 -------- packages/opencode/kompass.jsonc | 1 - packages/opencode/test/task-hook.test.ts | 67 ---------- .../opencode/test/tool-registration.test.ts | 121 ------------------ 10 files changed, 1 insertion(+), 265 deletions(-) diff --git a/kompass.jsonc b/kompass.jsonc index 85c14f6..fd614b4 100644 --- a/kompass.jsonc +++ b/kompass.jsonc @@ -65,7 +65,6 @@ "adapters": { "opencode": { "agentMode": "all", - "subtaskCommandMode": "kompass", }, }, } diff --git a/kompass.schema.json b/kompass.schema.json index d8b22c7..eeb0e2d 100644 --- a/kompass.schema.json +++ b/kompass.schema.json @@ -332,10 +332,6 @@ "agentMode": { "type": "string", "enum": ["subagent", "primary", "all"] - }, - "subtaskCommandMode": { - "type": "string", - "enum": ["kompass", "all", "off"] } } } diff --git a/packages/core/kompass.jsonc b/packages/core/kompass.jsonc index 85c14f6..fd614b4 100644 --- a/packages/core/kompass.jsonc +++ b/packages/core/kompass.jsonc @@ -65,7 +65,6 @@ "adapters": { "opencode": { "agentMode": "all", - "subtaskCommandMode": "kompass", }, }, } diff --git a/packages/core/lib/config.ts b/packages/core/lib/config.ts index fb710f0..d4e4ce1 100644 --- a/packages/core/lib/config.ts +++ b/packages/core/lib/config.ts @@ -162,7 +162,6 @@ export interface KompassConfig { adapters?: { opencode?: { agentMode?: "subagent" | "primary" | "all"; - subtaskCommandMode?: "kompass" | "all" | "off"; }; }; } @@ -210,7 +209,6 @@ export interface MergedKompassConfig { adapters: { opencode: { agentMode: "subagent" | "primary" | "all"; - subtaskCommandMode: "kompass" | "all" | "off"; }; }; } @@ -701,9 +699,6 @@ export function mergeWithDefaults( config?.adapters?.opencode?.agentMode ?? config?.defaults?.agentMode ?? "all", - subtaskCommandMode: - config?.adapters?.opencode?.subtaskCommandMode ?? - "kompass", }, }, }; diff --git a/packages/core/test/config.test.ts b/packages/core/test/config.test.ts index 0cdb3fa..7d66dbe 100644 --- a/packages/core/test/config.test.ts +++ b/packages/core/test/config.test.ts @@ -266,19 +266,6 @@ describe("object-based config", () => { assert.equal(config.agents.enabled.includes("reviewer"), false); assert.equal(config.components.enabled.includes("dev-flow"), false); assert.equal(config.components.paths.commit, "components/custom-commit.md"); - assert.equal(config.adapters.opencode.subtaskCommandMode, "kompass"); - }); - - test("supports adapter-specific subtask command stripping mode", () => { - const config = mergeWithDefaults({ - adapters: { - opencode: { - subtaskCommandMode: "all", - }, - }, - }); - - assert.equal(config.adapters.opencode.subtaskCommandMode, "all"); }); test("supports skill entry maps", () => { diff --git a/packages/opencode/.opencode/kompass.jsonc b/packages/opencode/.opencode/kompass.jsonc index d665225..46806e6 100644 --- a/packages/opencode/.opencode/kompass.jsonc +++ b/packages/opencode/.opencode/kompass.jsonc @@ -104,8 +104,7 @@ }, "adapters": { "opencode": { - "agentMode": "all", - "subtaskCommandMode": "kompass" + "agentMode": "all" } } } diff --git a/packages/opencode/index.ts b/packages/opencode/index.ts index 99b0382..bb3e2fd 100644 --- a/packages/opencode/index.ts +++ b/packages/opencode/index.ts @@ -14,7 +14,6 @@ import { type MergedKompassConfig, type Shell, } from "../core/index.ts"; -import { DEFAULT_COMMAND_NAMES } from "../core/lib/config.ts"; import { applyAgentsConfig, applyCommandsConfig, applySkillsConfig } from "./config.ts"; import { createPluginLogger, getErrorDetails, type PluginLogger } from "./logging.ts"; import { @@ -204,33 +203,6 @@ export function getCommandExecution( }; } -export function removeSubtaskCommands(output: CommandExecuteBeforeOutput): number { - let removed = 0; - - for (const part of output.parts) { - if (part.type !== "subtask") continue; - if (!("command" in part) || typeof part.command !== "string") continue; - - delete (part as { command?: string }).command; - removed++; - } - - return removed; -} - -export function shouldRemoveSubtaskCommand( - command: string, - config: MergedKompassConfig, - kompassCommands = new Set(DEFAULT_COMMAND_NAMES), -): boolean { - const mode = config.adapters.opencode.subtaskCommandMode; - - if (mode === "off") return false; - if (mode === "all") return true; - - return kompassCommands.has(command); -} - export function removeSyntheticAgentHandoff(output: ChatMessageOutput): boolean { const filteredParts = output.parts.filter((part) => !( part.type === "text" && @@ -437,16 +409,6 @@ export const OpenCodeCompassPlugin: Plugin = async (input: PluginInput) => { } const tools = await createToolsSafely(); - let config = mergeWithDefaults(null); - try { - config = mergeWithDefaults(await loadKompassConfig(worktree)); - } catch (error) { - await logger.warn("Falling back to default Kompass runtime config", { - worktree, - ...getErrorDetails(error), - }); - } - const kompassCommands = new Set(DEFAULT_COMMAND_NAMES); return { tool: tools, @@ -476,20 +438,8 @@ export const OpenCodeCompassPlugin: Plugin = async (input: PluginInput) => { }, async "command.execute.before"(input, output) { try { - const removedSubtaskCommands = shouldRemoveSubtaskCommand(input.command, config, kompassCommands) - ? removeSubtaskCommands(output) - : 0; const commandExecution = getCommandExecution(input, output); - if (removedSubtaskCommands > 0) { - await logger.info("Removed subtask command payload", { - command: input.command, - arguments: input.arguments, - sessionID: input.sessionID, - removedSubtaskCommands, - }); - } - if (!commandExecution) return; await logger.info("Executing Kompass command", commandExecution as Record); diff --git a/packages/opencode/kompass.jsonc b/packages/opencode/kompass.jsonc index 85c14f6..fd614b4 100644 --- a/packages/opencode/kompass.jsonc +++ b/packages/opencode/kompass.jsonc @@ -65,7 +65,6 @@ "adapters": { "opencode": { "agentMode": "all", - "subtaskCommandMode": "kompass", }, }, } diff --git a/packages/opencode/test/task-hook.test.ts b/packages/opencode/test/task-hook.test.ts index fab9015..4e14c40 100644 --- a/packages/opencode/test/task-hook.test.ts +++ b/packages/opencode/test/task-hook.test.ts @@ -6,10 +6,7 @@ import { getCommandExecution, getTaskToolExecution, removeSyntheticAgentHandoff, - removeSubtaskCommands, - shouldRemoveSubtaskCommand, } from "../index.ts"; -import { mergeWithDefaults } from "../../core/lib/config.ts"; describe("getTaskToolExecution", () => { test("expands slash commands for task tool calls", async () => { @@ -170,70 +167,6 @@ describe("getCommandExecution", () => { }); }); -describe("removeSubtaskCommands", () => { - test("removes command from subtask parts", () => { - const output = { - parts: [ - { - id: "part-1", - sessionID: "session-3", - messageID: "message-1", - type: "subtask", - prompt: "expanded command prompt", - description: "Run review command", - agent: "general", - command: "review", - }, - { - id: "part-2", - sessionID: "session-3", - messageID: "message-1", - type: "text", - text: "keep this", - }, - ], - }; - - const removed = removeSubtaskCommands(output as never); - - assert.equal(removed, 1); - assert.equal("command" in output.parts[0], false); - }); -}); - -describe("shouldRemoveSubtaskCommand", () => { - test("defaults to stripping commands only for Kompass commands", () => { - const config = mergeWithDefaults(null); - - assert.equal(shouldRemoveSubtaskCommand("review", config), true); - assert.equal(shouldRemoveSubtaskCommand("third-party", config), false); - }); - - test("supports enabling stripping for all commands", () => { - const config = mergeWithDefaults({ - adapters: { - opencode: { - subtaskCommandMode: "all", - }, - }, - }); - - assert.equal(shouldRemoveSubtaskCommand("third-party", config), true); - }); - - test("supports disabling stripping entirely", () => { - const config = mergeWithDefaults({ - adapters: { - opencode: { - subtaskCommandMode: "off", - }, - }, - }); - - assert.equal(shouldRemoveSubtaskCommand("review", config), false); - }); -}); - describe("removeSyntheticAgentHandoff", () => { test("removes the legacy synthetic agent handoff text", () => { const output = { diff --git a/packages/opencode/test/tool-registration.test.ts b/packages/opencode/test/tool-registration.test.ts index 0b23e38..339791d 100644 --- a/packages/opencode/test/tool-registration.test.ts +++ b/packages/opencode/test/tool-registration.test.ts @@ -254,125 +254,4 @@ describe("createOpenCodeTools", () => { }); }); - test("strips subtask command payload only for Kompass commands by default", async () => { - await withTempHome(async () => { - const plugin = await OpenCodeCompassPlugin({ - $: (() => { - throw new Error("not implemented"); - }) as never, - client: createMockClient() as never, - directory: process.cwd(), - worktree: process.cwd(), - } as never); - - const kompassOutput = { - parts: [ - { - id: "part-1", - sessionID: "session-1", - messageID: "message-1", - type: "subtask", - prompt: "expanded", - description: "Run review command", - agent: "reviewer", - command: "review", - }, - ], - }; - - await plugin["command.execute.before"]?.( - { - command: "review", - sessionID: "session-1", - arguments: "", - } as never, - kompassOutput as never, - ); - - assert.equal("command" in kompassOutput.parts[0], false); - - const thirdPartyOutput = { - parts: [ - { - id: "part-2", - sessionID: "session-1", - messageID: "message-2", - type: "subtask", - prompt: "expanded", - description: "Run external command", - agent: "reviewer", - command: "third-party", - }, - ], - }; - - await plugin["command.execute.before"]?.( - { - command: "third-party", - sessionID: "session-1", - arguments: "", - } as never, - thirdPartyOutput as never, - ); - - assert.equal((thirdPartyOutput.parts[0] as { command?: string }).command, "third-party"); - }); - }); - - test("supports stripping subtask command payload for all commands via config", async () => { - await withTempHome(async () => { - const tempDir = await mkdtemp(path.join(os.tmpdir(), "kompass-tools-subtask-mode-")); - - try { - await mkdir(path.join(tempDir, ".opencode"), { recursive: true }); - await writeFile( - path.join(tempDir, ".opencode", "kompass.jsonc"), - `{ - "adapters": { - "opencode": { - "subtaskCommandMode": "all" - } - } - }`, - ); - - const plugin = await OpenCodeCompassPlugin({ - $: (() => { - throw new Error("not implemented"); - }) as never, - client: createMockClient() as never, - directory: tempDir, - worktree: tempDir, - } as never); - - const output = { - parts: [ - { - id: "part-1", - sessionID: "session-1", - messageID: "message-1", - type: "subtask", - prompt: "expanded", - description: "Run external command", - agent: "reviewer", - command: "third-party", - }, - ], - }; - - await plugin["command.execute.before"]?.( - { - command: "third-party", - sessionID: "session-1", - arguments: "", - } as never, - output as never, - ); - - assert.equal("command" in output.parts[0], false); - } finally { - await rm(tempDir, { recursive: true, force: true }); - } - }); - }); });