feat(core): add session rename tool
This commit is contained in:
parent
a01d24e908
commit
1b78dd7f9c
4 changed files with 248 additions and 2 deletions
|
|
@ -43,6 +43,7 @@ import { QuestionTool } from "../tool/plugin/question"
|
|||
import { ReadToolFileSystem } from "../tool/read-filesystem"
|
||||
import { ReadTool } from "../tool/plugin/read"
|
||||
import { ShellTool } from "../tool/plugin/shell"
|
||||
import { SessionRenameTool } from "../tool/plugin/session-rename"
|
||||
import { SkillTool } from "../tool/plugin/skill"
|
||||
import { SubagentTool } from "../tool/plugin/subagent"
|
||||
import { Tool } from "../tool"
|
||||
|
|
@ -149,6 +150,7 @@ const pre = [
|
|||
QuestionTool.Plugin,
|
||||
ReadTool.Plugin,
|
||||
ShellTool.Plugin,
|
||||
SessionRenameTool.Plugin,
|
||||
SkillTool.Plugin,
|
||||
SubagentTool.Plugin,
|
||||
WebFetchTool.Plugin,
|
||||
|
|
|
|||
77
packages/core/src/tool/plugin/session-rename.ts
Normal file
77
packages/core/src/tool/plugin/session-rename.ts
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
export * as SessionRenameTool from "./session-rename"
|
||||
|
||||
import type { Context as PluginContext } from "@opencode-ai/plugin/effect/plugin"
|
||||
import { ToolFailure } from "@opencode-ai/ai"
|
||||
import { Effect, Schema } from "effect"
|
||||
import { Permission } from "../../permission"
|
||||
import { PluginRuntime } from "../../plugin/runtime"
|
||||
|
||||
export const name = "sessionRename"
|
||||
|
||||
export const description =
|
||||
"Rename the current session. Use a short, specific title that summarizes the work being done. This tool can only rename the session you are currently working in."
|
||||
|
||||
export const Input = Schema.Struct({
|
||||
title: Schema.String.check(
|
||||
Schema.isMinLength(1, { message: "Title must not be empty" }),
|
||||
Schema.isMaxLength(100, { message: "Title must be 100 characters or fewer" }),
|
||||
).annotate({ description: "New title for the current session" }),
|
||||
})
|
||||
|
||||
export const Output = Schema.Struct({
|
||||
title: Schema.String,
|
||||
})
|
||||
|
||||
export const Plugin = {
|
||||
id: "opencode.tool.session-rename",
|
||||
effect: Effect.fn("SessionRenameTool.Plugin")(function* (ctx: PluginContext) {
|
||||
const runtime = yield* PluginRuntime.Service
|
||||
const permission = yield* Permission.Service
|
||||
|
||||
yield* ctx.tool
|
||||
.transform((draft) =>
|
||||
draft.add(
|
||||
({
|
||||
name,
|
||||
options: { codemode: false },
|
||||
description,
|
||||
input: Input,
|
||||
output: Output,
|
||||
execute: (input, context) =>
|
||||
Effect.gen(function* () {
|
||||
const title = input.title.replace(/\s+/g, " ").trim()
|
||||
if (!title) return yield* new ToolFailure({ message: "Session title must not be empty" })
|
||||
yield* permission
|
||||
.assert({
|
||||
action: name,
|
||||
resources: ["*"],
|
||||
save: ["*"],
|
||||
metadata: { title },
|
||||
sessionID: context.sessionID,
|
||||
agent: context.agent,
|
||||
source: { type: "tool", messageID: context.messageID, callID: context.callID },
|
||||
})
|
||||
.pipe(
|
||||
Effect.mapError(
|
||||
(error) => new ToolFailure({ message: "Permission denied: sessionRename", error }),
|
||||
),
|
||||
)
|
||||
yield* runtime.session
|
||||
.rename({ sessionID: context.sessionID, title })
|
||||
.pipe(
|
||||
Effect.mapError(
|
||||
(error) => new ToolFailure({ message: "Unable to rename the current session", error }),
|
||||
),
|
||||
)
|
||||
return {
|
||||
output: { title },
|
||||
content: `Renamed the current session to: ${title}`,
|
||||
metadata: { title },
|
||||
}
|
||||
}),
|
||||
}),
|
||||
),
|
||||
)
|
||||
.pipe(Effect.orDie)
|
||||
}),
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue