diff --git a/docs/reference/configuration.md b/docs/reference/configuration.md index ad582c258..b739d36b7 100644 --- a/docs/reference/configuration.md +++ b/docs/reference/configuration.md @@ -955,7 +955,7 @@ When enabled, two companion hooks are active: `hashline-read-enhancer` (annotate | `aggressive_truncation` | `false` | Aggressively truncate when token limit exceeded | | `auto_resume` | `false` | Auto-resume after thinking block recovery | | `disable_omo_env` | `false` | Disable auto-injected `` block (date/time/locale). Improves cache hit rate. | -| `task_system` | `true` | Enable Sisyphus task system | +| `task_system` | `false` | Enable Sisyphus task system | | `dynamic_context_pruning.enabled` | `false` | Auto-prune old tool outputs to manage context window | | `dynamic_context_pruning.notification` | `detailed` | Pruning notifications: `off` / `minimal` / `detailed` | | `turn_protection.turns` | `3` | Recent turns protected from pruning (1–10) | diff --git a/src/hooks/tasks-todowrite-disabler/hook.test.ts b/src/hooks/tasks-todowrite-disabler/hook.test.ts new file mode 100644 index 000000000..e737cc03c --- /dev/null +++ b/src/hooks/tasks-todowrite-disabler/hook.test.ts @@ -0,0 +1,40 @@ +import { describe, expect, test } from "bun:test" + +import { REPLACEMENT_MESSAGE } from "./constants" +import { createTasksTodowriteDisablerHook } from "./hook" + +describe("createTasksTodowriteDisablerHook", () => { + describe("#given experimental.task_system is omitted", () => { + test("#when TodoWrite runs #then it is allowed by default", async () => { + // given + const hook = createTasksTodowriteDisablerHook({}) + + // when + const result = hook["tool.execute.before"]( + { tool: "TodoWrite", sessionID: "ses_123", callID: "call_123" }, + { args: {} }, + ) + + // then + await expect(result).resolves.toBeUndefined() + }) + }) + + describe("#given experimental.task_system is enabled", () => { + test("#when TodoWrite runs #then it is blocked", async () => { + // given + const hook = createTasksTodowriteDisablerHook({ + experimental: { task_system: true }, + }) + + // when + const result = hook["tool.execute.before"]( + { tool: "TodoWrite", sessionID: "ses_123", callID: "call_123" }, + { args: {} }, + ) + + // then + await expect(result).rejects.toThrow(REPLACEMENT_MESSAGE) + }) + }) +}) diff --git a/src/hooks/tasks-todowrite-disabler/hook.ts b/src/hooks/tasks-todowrite-disabler/hook.ts index 9449cfea8..8e07ece4a 100644 --- a/src/hooks/tasks-todowrite-disabler/hook.ts +++ b/src/hooks/tasks-todowrite-disabler/hook.ts @@ -1,3 +1,4 @@ +import { isTaskSystemEnabled } from "../../shared"; import { BLOCKED_TOOLS, REPLACEMENT_MESSAGE } from "./constants"; export interface TasksTodowriteDisablerConfig { @@ -9,14 +10,14 @@ export interface TasksTodowriteDisablerConfig { export function createTasksTodowriteDisablerHook( config: TasksTodowriteDisablerConfig, ) { - const isTaskSystemEnabled = config.experimental?.task_system ?? true; + const taskSystemEnabled = isTaskSystemEnabled(config); return { "tool.execute.before": async ( input: { tool: string; sessionID: string; callID: string }, _output: { args: Record }, ) => { - if (!isTaskSystemEnabled) { + if (!taskSystemEnabled) { return; } diff --git a/src/hooks/tasks-todowrite-disabler/index.test.ts b/src/hooks/tasks-todowrite-disabler/index.test.ts index ebb7bb798..2f93b6d59 100644 --- a/src/hooks/tasks-todowrite-disabler/index.test.ts +++ b/src/hooks/tasks-todowrite-disabler/index.test.ts @@ -78,7 +78,7 @@ describe("tasks-todowrite-disabler", () => { ).resolves.toBeUndefined() }) - test("should block TodoWrite when experimental is undefined because task_system defaults to enabled", async () => { + test("should not block TodoWrite when experimental is undefined because task_system defaults to disabled", async () => { // given const hook = createTasksTodowriteDisablerHook({}) const input = { @@ -93,7 +93,7 @@ describe("tasks-todowrite-disabler", () => { // when / then await expect( hook["tool.execute.before"](input, output) - ).rejects.toThrow("TodoRead/TodoWrite are DISABLED") + ).resolves.toBeUndefined() }) test("should not block TodoRead when flag is false", async () => { diff --git a/src/plugin-handlers/agent-config-handler.ts b/src/plugin-handlers/agent-config-handler.ts index 14993cda3..8a8d9ea1d 100644 --- a/src/plugin-handlers/agent-config-handler.ts +++ b/src/plugin-handlers/agent-config-handler.ts @@ -1,7 +1,7 @@ import { createBuiltinAgents } from "../agents"; import { createSisyphusJuniorAgentWithOverrides } from "../agents/sisyphus-junior"; import type { OhMyOpenCodeConfig } from "../config"; -import { log, migrateAgentConfig } from "../shared"; +import { isTaskSystemEnabled, log, migrateAgentConfig } from "../shared"; import { AGENT_NAME_MAP } from "../shared/migration"; import { getAgentDisplayName } from "../shared/agent-display-names"; import { registerAgentName } from "../features/claude-code-session-state"; @@ -90,7 +90,7 @@ export async function applyAgentConfig(params: { params.pluginConfig.browser_automation_engine?.provider ?? "playwright"; const currentModel = params.config.model as string | undefined; const disabledSkills = new Set(params.pluginConfig.disabled_skills ?? []); - const useTaskSystem = params.pluginConfig.experimental?.task_system ?? false; + const useTaskSystem = isTaskSystemEnabled(params.pluginConfig); const disableOmoEnv = params.pluginConfig.experimental?.disable_omo_env ?? false; const includeClaudeAgents = params.pluginConfig.claude_code?.agents ?? true; diff --git a/src/plugin-handlers/config-handler.test.ts b/src/plugin-handlers/config-handler.test.ts index 3c0af3a84..e4d681104 100644 --- a/src/plugin-handlers/config-handler.test.ts +++ b/src/plugin-handlers/config-handler.test.ts @@ -1281,6 +1281,10 @@ describe("per-agent todowrite/todoread deny when task_system enabled", () => { await handler(config) //#then + const lastCall = + createBuiltinAgentsMock.mock.calls[createBuiltinAgentsMock.mock.calls.length - 1] + expect(lastCall?.[11]).toBe(false) + const agentResult = config.agent as Record }> expect(agentResult[getAgentDisplayName("sisyphus")]?.permission?.todowrite).toBeUndefined() expect(agentResult[getAgentDisplayName("sisyphus")]?.permission?.todoread).toBeUndefined() @@ -1315,6 +1319,10 @@ describe("per-agent todowrite/todoread deny when task_system enabled", () => { await handler(config) //#then + const lastCall = + createBuiltinAgentsMock.mock.calls[createBuiltinAgentsMock.mock.calls.length - 1] + expect(lastCall?.[11]).toBe(false) + const agentResult = config.agent as Record }> expect(agentResult[getAgentDisplayName("sisyphus")]?.permission?.todowrite).toBeUndefined() expect(agentResult[getAgentDisplayName("sisyphus")]?.permission?.todoread).toBeUndefined() diff --git a/src/plugin-handlers/tool-config-handler.test.ts b/src/plugin-handlers/tool-config-handler.test.ts index 0fff60f5e..609d8386f 100644 --- a/src/plugin-handlers/tool-config-handler.test.ts +++ b/src/plugin-handlers/tool-config-handler.test.ts @@ -218,6 +218,16 @@ describe("applyToolConfig", () => { describe("#given task_system is undefined", () => { describe("#when applying tool config", () => { + it("#then should not disable todo tools globally by default", () => { + const params = createParams({}) + + applyToolConfig(params) + + const tools = params.config.tools as Record + expect(tools.todowrite).toBeUndefined() + expect(tools.todoread).toBeUndefined() + }) + it.each([ "atlas", "sisyphus", diff --git a/src/plugin-handlers/tool-config-handler.ts b/src/plugin-handlers/tool-config-handler.ts index 5953fd018..dae34fda6 100644 --- a/src/plugin-handlers/tool-config-handler.ts +++ b/src/plugin-handlers/tool-config-handler.ts @@ -1,5 +1,6 @@ import type { OhMyOpenCodeConfig } from "../config"; import { getAgentDisplayName, getAgentListDisplayName } from "../shared/agent-display-names"; +import { isTaskSystemEnabled } from "../shared"; type AgentWithPermission = { permission?: Record }; @@ -25,7 +26,7 @@ export function applyToolConfig(params: { pluginConfig: OhMyOpenCodeConfig; agentResult: Record; }): void { - const taskSystemEnabled = params.pluginConfig.experimental?.task_system ?? false + const taskSystemEnabled = isTaskSystemEnabled(params.pluginConfig) const denyTodoTools = taskSystemEnabled ? { todowrite: "deny", todoread: "deny" } : {} diff --git a/src/plugin/tool-registry.test.ts b/src/plugin/tool-registry.test.ts index bb8d40c4d..7cf6d2374 100644 --- a/src/plugin/tool-registry.test.ts +++ b/src/plugin/tool-registry.test.ts @@ -2,7 +2,7 @@ import { describe, expect, test } from "bun:test" import { tool } from "@opencode-ai/plugin" import type { ToolsRecord } from "./types" -import { trimToolsToCap } from "./tool-registry" +import { createToolRegistry, trimToolsToCap } from "./tool-registry" const fakeTool = tool({ description: "test tool", @@ -27,3 +27,57 @@ describe("#given tool trimming prioritization", () => { expect(filteredTools).toHaveProperty("read") }) }) + +describe("#given task_system configuration", () => { + test("#when task_system is omitted #then task tools are not registered by default", () => { + const result = createToolRegistry({ + ctx: { directory: "/tmp" } as Parameters[0]["ctx"], + pluginConfig: {}, + managers: { + backgroundManager: {}, + tmuxSessionManager: {}, + skillMcpManager: {}, + } as Parameters[0]["managers"], + skillContext: { + mergedSkills: [], + availableSkills: [], + browserProvider: "playwright", + disabledSkills: new Set(), + }, + availableCategories: [], + }) + + expect(result.taskSystemEnabled).toBe(false) + expect(result.filteredTools).not.toHaveProperty("task_create") + expect(result.filteredTools).not.toHaveProperty("task_get") + expect(result.filteredTools).not.toHaveProperty("task_list") + expect(result.filteredTools).not.toHaveProperty("task_update") + }) + + test("#when task_system is enabled #then task tools are registered", () => { + const result = createToolRegistry({ + ctx: { directory: "/tmp" } as Parameters[0]["ctx"], + pluginConfig: { + experimental: { task_system: true }, + }, + managers: { + backgroundManager: {}, + tmuxSessionManager: {}, + skillMcpManager: {}, + } as Parameters[0]["managers"], + skillContext: { + mergedSkills: [], + availableSkills: [], + browserProvider: "playwright", + disabledSkills: new Set(), + }, + availableCategories: [], + }) + + expect(result.taskSystemEnabled).toBe(true) + expect(result.filteredTools).toHaveProperty("task_create") + expect(result.filteredTools).toHaveProperty("task_get") + expect(result.filteredTools).toHaveProperty("task_list") + expect(result.filteredTools).toHaveProperty("task_update") + }) +}) diff --git a/src/plugin/tool-registry.ts b/src/plugin/tool-registry.ts index a493dde51..81d4c9ba0 100644 --- a/src/plugin/tool-registry.ts +++ b/src/plugin/tool-registry.ts @@ -29,7 +29,7 @@ import { } from "../tools" import { getMainSessionID } from "../features/claude-code-session-state" import { filterDisabledTools } from "../shared/disabled-tools" -import { log } from "../shared" +import { isTaskSystemEnabled, log } from "../shared" import type { Managers } from "../create-managers" import type { SkillContext } from "./skill-context" @@ -175,8 +175,7 @@ export function createToolRegistry(args: { nativeSkills: "skills" in ctx ? (ctx as { skills: SkillLoadOptions["nativeSkills"] }).skills : undefined, }) - // task_system defaults to true since v3.14 — delegation (oracle, subagents) requires it - const taskSystemEnabled = pluginConfig.experimental?.task_system ?? true + const taskSystemEnabled = isTaskSystemEnabled(pluginConfig) const taskToolsRecord: Record = taskSystemEnabled ? { task_create: createTaskCreateTool(pluginConfig, ctx), diff --git a/src/shared/index.ts b/src/shared/index.ts index da70aee2f..32f428cc8 100644 --- a/src/shared/index.ts +++ b/src/shared/index.ts @@ -72,3 +72,4 @@ export * from "./plugin-command-discovery" export { SessionCategoryRegistry } from "./session-category-registry" export * from "./plugin-identity" export * from "./log-legacy-plugin-startup-warning" +export * from "./task-system-enabled" diff --git a/src/shared/task-system-enabled.ts b/src/shared/task-system-enabled.ts new file mode 100644 index 000000000..0c2b7f6c3 --- /dev/null +++ b/src/shared/task-system-enabled.ts @@ -0,0 +1,9 @@ +export interface TaskSystemConfig { + experimental?: { + task_system?: boolean + } +} + +export function isTaskSystemEnabled(config: TaskSystemConfig): boolean { + return config.experimental?.task_system ?? false +}