core: add permission checks to lsp and todo tools
This commit is contained in:
parent
4a07bb561f
commit
e0438bc318
3 changed files with 27 additions and 5 deletions
|
|
@ -407,6 +407,7 @@ export namespace Config {
|
||||||
webfetch: PermissionAction.optional(),
|
webfetch: PermissionAction.optional(),
|
||||||
websearch: PermissionAction.optional(),
|
websearch: PermissionAction.optional(),
|
||||||
codesearch: PermissionAction.optional(),
|
codesearch: PermissionAction.optional(),
|
||||||
|
lsp: PermissionRule.optional(),
|
||||||
doom_loop: PermissionAction.optional(),
|
doom_loop: PermissionAction.optional(),
|
||||||
})
|
})
|
||||||
.catchall(PermissionRule)
|
.catchall(PermissionRule)
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,14 @@ export const LspTool = Tool.define("lsp", {
|
||||||
line: z.number().int().min(1).describe("The line number (1-based, as shown in editors)"),
|
line: z.number().int().min(1).describe("The line number (1-based, as shown in editors)"),
|
||||||
character: z.number().int().min(1).describe("The character offset (1-based, as shown in editors)"),
|
character: z.number().int().min(1).describe("The character offset (1-based, as shown in editors)"),
|
||||||
}),
|
}),
|
||||||
execute: async (args) => {
|
execute: async (args, ctx) => {
|
||||||
|
await ctx.ask({
|
||||||
|
permission: "lsp",
|
||||||
|
patterns: ["*"],
|
||||||
|
always: ["*"],
|
||||||
|
metadata: {},
|
||||||
|
})
|
||||||
|
|
||||||
const file = path.isAbsolute(args.filePath) ? args.filePath : path.join(Instance.directory, args.filePath)
|
const file = path.isAbsolute(args.filePath) ? args.filePath : path.join(Instance.directory, args.filePath)
|
||||||
const uri = pathToFileURL(file).href
|
const uri = pathToFileURL(file).href
|
||||||
const position = {
|
const position = {
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,16 @@ export const TodoWriteTool = Tool.define("todowrite", {
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
todos: z.array(z.object(Todo.Info.shape)).describe("The updated todo list"),
|
todos: z.array(z.object(Todo.Info.shape)).describe("The updated todo list"),
|
||||||
}),
|
}),
|
||||||
async execute(params, opts) {
|
async execute(params, ctx) {
|
||||||
|
await ctx.ask({
|
||||||
|
permission: "todowrite",
|
||||||
|
patterns: ["*"],
|
||||||
|
always: ["*"],
|
||||||
|
metadata: {},
|
||||||
|
})
|
||||||
|
|
||||||
await Todo.update({
|
await Todo.update({
|
||||||
sessionID: opts.sessionID,
|
sessionID: ctx.sessionID,
|
||||||
todos: params.todos,
|
todos: params.todos,
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
|
|
@ -26,8 +33,15 @@ export const TodoWriteTool = Tool.define("todowrite", {
|
||||||
export const TodoReadTool = Tool.define("todoread", {
|
export const TodoReadTool = Tool.define("todoread", {
|
||||||
description: "Use this tool to read your todo list",
|
description: "Use this tool to read your todo list",
|
||||||
parameters: z.object({}),
|
parameters: z.object({}),
|
||||||
async execute(_params, opts) {
|
async execute(_params, ctx) {
|
||||||
const todos = await Todo.get(opts.sessionID)
|
await ctx.ask({
|
||||||
|
permission: "todoread",
|
||||||
|
patterns: ["*"],
|
||||||
|
always: ["*"],
|
||||||
|
metadata: {},
|
||||||
|
})
|
||||||
|
|
||||||
|
const todos = await Todo.get(ctx.sessionID)
|
||||||
return {
|
return {
|
||||||
title: `${todos.filter((x) => x.status !== "completed").length} todos`,
|
title: `${todos.filter((x) => x.status !== "completed").length} todos`,
|
||||||
metadata: {
|
metadata: {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue