refactor(core)!: call the session tools opencode.session.rename and .move in Code Mode (#65080)

This commit is contained in:
Aiden Cline
2026-11-20 01:01:46 -06:00
committed by GitHub
Unverified
parent bf93d0e752
commit 8e50929d0d
5 changed files with 29 additions and 12 deletions
+2 -2
View File
@@ -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",
])
+5 -5
View File
@@ -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
+1 -1
View File
@@ -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.",
+16
View File
@@ -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
+5 -4
View File
@@ -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