diff --git a/packages/core/src/automation/code.ts b/packages/core/src/automation/code.ts index fbebf720b53..98aea975a85 100644 --- a/packages/core/src/automation/code.ts +++ b/packages/core/src/automation/code.ts @@ -43,8 +43,8 @@ const FORBIDDEN_TOOLS = new Set([ "opencode.automation_pause", "opencode.automation_resume", "opencode.automation_delete", - "opencode.session_move", - "opencode.session_rename", + "opencode.session.move", + "opencode.session.rename", "opencode.worktree_create", "opencode.worktree_remove", ]) diff --git a/packages/core/src/tool/plugin/opencode.ts b/packages/core/src/tool/plugin/opencode.ts index ae229f1ad41..7b076f8725b 100644 --- a/packages/core/src/tool/plugin/opencode.ts +++ b/packages/core/src/tool/plugin/opencode.ts @@ -103,7 +103,7 @@ export const Plugin = { Effect.sync(() => { const text = "execute" in event.tools - ? "When you create a worktree outside the current working directory and intend to use it as your primary working directory, consider using `execute` to call `tools.opencode.session_move` and make the worktree the session's working directory." + ? "When you create a worktree outside the current working directory and intend to use it as your primary working directory, consider using `execute` to call `tools.opencode.session.move` and make the worktree the session's working directory." : "opencode_session_move" in event.tools ? "When you create a worktree outside the current working directory and intend to use it as your primary working directory, consider calling `opencode_session_move` to make the worktree the session's working directory." : undefined @@ -120,12 +120,12 @@ export const Plugin = { "Tools for managing OpenCode itself, such as working with sessions and worktrees, searching the available models, and reading MCP resources.", }) draft.add({ - name: "session_rename", + name: "rename", description: "Rename a session, or omit sessionID to rename the current session. Use a short, specific title that summarizes the work being done.", input: RenameInput, output: RenameOutput, - options: { namespace: "opencode", codemode: true }, + options: { namespace: "opencode.session", codemode: true }, execute: (input, context) => { const sessionID = input.sessionID ?? context.sessionID const title = input.title.trim() @@ -140,12 +140,12 @@ export const Plugin = { }, }) draft.add({ - name: "session_move", + name: "move", description: "Move a session to another directory, or omit sessionID to move the current session. The current session moves at the next safe boundary; do not run destination-dependent tools in the same execute call.", input: MoveInput, output: MoveOutput, - options: { namespace: "opencode", codemode: { pinned: true } }, + options: { namespace: "opencode.session", codemode: { pinned: true } }, execute: (input, context) => Effect.gen(function* () { const sessionID = input.sessionID ?? context.sessionID diff --git a/packages/core/test/tool-opencode.test.ts b/packages/core/test/tool-opencode.test.ts index 76fa6cabbb9..005d5eaa2bf 100644 --- a/packages/core/test/tool-opencode.test.ts +++ b/packages/core/test/tool-opencode.test.ts @@ -283,7 +283,7 @@ it.effect("adapts the worktree session_move hint to execute, direct tools, or ne .pipe(Effect.map((event) => event.system.map((part) => part.text))) expect(yield* trigger({ execute: { description: "execute", input: {} } })).toEqual([ - "When you create a worktree outside the current working directory and intend to use it as your primary working directory, consider using `execute` to call `tools.opencode.session_move` and make the worktree the session's working directory.", + "When you create a worktree outside the current working directory and intend to use it as your primary working directory, consider using `execute` to call `tools.opencode.session.move` and make the worktree the session's working directory.", ]) expect(yield* trigger({ opencode_session_move: { description: "move", input: {} } })).toEqual([ "When you create a worktree outside the current working directory and intend to use it as your primary working directory, consider calling `opencode_session_move` to make the worktree the session's working directory.", diff --git a/packages/core/test/tool-registry.test.ts b/packages/core/test/tool-registry.test.ts index c2d3ef1ec49..43cd364cd60 100644 --- a/packages/core/test/tool-registry.test.ts +++ b/packages/core/test/tool-registry.test.ts @@ -1008,6 +1008,22 @@ describe("Tool", () => { }), ) + it.effect("denies a nested-namespace tool by its flattened name in Code Mode and as a direct tool", () => + Effect.gen(function* () { + const service = yield* Tool.Service + yield* transform(service, { move: make(), rename: make() }, { namespace: "opencode.session" }) + const deny: Permission.Ruleset = [{ action: "opencode_session_move", resource: "*", effect: "deny" }] + + const codeMode = yield* service.snapshot(deny) + const paths = codeModeListings(codeMode.codeModeCatalog!).map((entry) => entry.path) + expect(paths).toContain("opencode.session.rename") + expect(paths).not.toContain("opencode.session.move") + + const direct = yield* service.snapshot([...deny, { action: "execute", resource: "*", effect: "deny" }]) + expect(direct.definitions.map((tool) => tool.name)).toEqual(["opencode_session_rename"]) + }), + ) + it.effect("filters disabled tools with edit aliases and ordered wildcard precedence", () => Effect.gen(function* () { const service = yield* Tool.Service diff --git a/services/site/src/docs/content/tools.mdx b/services/site/src/docs/content/tools.mdx index a40e088456c..8b49e025787 100644 --- a/services/site/src/docs/content/tools.mdx +++ b/services/site/src/docs/content/tools.mdx @@ -246,11 +246,12 @@ tools enforce the permissions they assert. ### Sessions -The `opencode` Code Mode namespace contains session utilities: +The `opencode.session` Code Mode namespace contains session utilities. Without Code +Mode they are listed as `opencode_session_rename` and `opencode_session_move`. -- `session_rename` changes the title of the current session, or another session +- `rename` changes the title of the current session, or another session selected by `sessionID`. -- `session_move` moves the current session, or another selected session, to a +- `move` moves the current session, or another selected session, to a relative or absolute `directory`. The move takes effect at a safe boundary, so destination-dependent work belongs in a later call. @@ -260,7 +261,7 @@ Rename this session to "Timeout cleanup", then move it to the new worktree. ### Worktrees -The same namespace manages worktrees for the session's project: +The `opencode` namespace manages worktrees for the session's project: - `worktree_create` creates a worktree from a `name` and returns its `directory`. The project's worktree configuration selects the destination and