diff --git a/packages/opencode/src/tool/registry.ts b/packages/opencode/src/tool/registry.ts index 5ed5a879b48..631ba9d449e 100644 --- a/packages/opencode/src/tool/registry.ts +++ b/packages/opencode/src/tool/registry.ts @@ -27,6 +27,7 @@ import { LspTool } from "./lsp" import { Truncate } from "./truncation" import { PlanExitTool, PlanEnterTool } from "./plan" import { ApplyPatchTool } from "./apply_patch" +import { GetCurrentSessionTitleTool } from "./session-title" export namespace ToolRegistry { const log = Log.create({ service: "tool.registry" }) @@ -112,6 +113,7 @@ export namespace ToolRegistry { CodeSearchTool, SkillTool, ApplyPatchTool, + GetCurrentSessionTitleTool, ...(Flag.OPENCODE_EXPERIMENTAL_LSP_TOOL ? [LspTool] : []), ...(config.experimental?.batch_tool === true ? [BatchTool] : []), ...(Flag.OPENCODE_EXPERIMENTAL_PLAN_MODE && Flag.OPENCODE_CLIENT === "cli" ? [PlanExitTool, PlanEnterTool] : []), diff --git a/packages/opencode/src/tool/session-title.ts b/packages/opencode/src/tool/session-title.ts new file mode 100644 index 00000000000..3e73651d98f --- /dev/null +++ b/packages/opencode/src/tool/session-title.ts @@ -0,0 +1,18 @@ +import z from "zod" +import { Tool } from "./tool" +import { Session } from "../session" +import DESCRIPTION from "./session-title.txt" + +export const GetCurrentSessionTitleTool = Tool.define("get_current_session_title", { + description: DESCRIPTION, + parameters: z.object({}), + async execute(_params, ctx) { + const session = await Session.get(ctx.sessionID) + const title = session?.title ?? "Unknown" + return { + title: "Retrieved session title", + output: title, + metadata: {}, + } + }, +}) diff --git a/packages/opencode/src/tool/session-title.txt b/packages/opencode/src/tool/session-title.txt new file mode 100644 index 00000000000..c1461213526 --- /dev/null +++ b/packages/opencode/src/tool/session-title.txt @@ -0,0 +1,3 @@ +Use this tool to retrieve the title of the current session. + +This tool returns the current session's title as a string. The title is initially set when the session is created and may possibly be updated using other tools at your disposal.