2025-10-26 19:50:41 +00:00
|
|
|
import z from "zod"
|
2025-06-04 19:09:40 +00:00
|
|
|
import { Tool } from "./tool"
|
|
|
|
|
import DESCRIPTION_WRITE from "./todowrite.txt"
|
2025-10-06 22:54:05 +00:00
|
|
|
import { Todo } from "../session/todo"
|
2025-06-04 19:09:40 +00:00
|
|
|
|
2025-07-25 17:29:29 +00:00
|
|
|
export const TodoWriteTool = Tool.define("todowrite", {
|
2025-06-04 19:09:40 +00:00
|
|
|
description: DESCRIPTION_WRITE,
|
|
|
|
|
parameters: z.object({
|
2025-11-16 01:19:36 +00:00
|
|
|
todos: z.array(z.object(Todo.Info.shape)).describe("The updated todo list"),
|
2025-06-04 19:09:40 +00:00
|
|
|
}),
|
2026-01-01 22:54:11 +00:00
|
|
|
async execute(params, ctx) {
|
|
|
|
|
await ctx.ask({
|
|
|
|
|
permission: "todowrite",
|
|
|
|
|
patterns: ["*"],
|
|
|
|
|
always: ["*"],
|
|
|
|
|
metadata: {},
|
|
|
|
|
})
|
|
|
|
|
|
2025-10-06 22:54:05 +00:00
|
|
|
await Todo.update({
|
2026-01-01 22:54:11 +00:00
|
|
|
sessionID: ctx.sessionID,
|
2025-10-06 22:54:05 +00:00
|
|
|
todos: params.todos,
|
|
|
|
|
})
|
2025-06-04 19:09:40 +00:00
|
|
|
return {
|
2025-07-07 19:53:43 +00:00
|
|
|
title: `${params.todos.filter((x) => x.status !== "completed").length} todos`,
|
2025-06-04 19:09:40 +00:00
|
|
|
output: JSON.stringify(params.todos, null, 2),
|
|
|
|
|
metadata: {
|
|
|
|
|
todos: params.todos,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
2025-07-25 17:29:29 +00:00
|
|
|
export const TodoReadTool = Tool.define("todoread", {
|
2025-06-04 19:09:40 +00:00
|
|
|
description: "Use this tool to read your todo list",
|
2025-06-04 22:03:04 +00:00
|
|
|
parameters: z.object({}),
|
2026-01-01 22:54:11 +00:00
|
|
|
async execute(_params, ctx) {
|
|
|
|
|
await ctx.ask({
|
|
|
|
|
permission: "todoread",
|
|
|
|
|
patterns: ["*"],
|
|
|
|
|
always: ["*"],
|
|
|
|
|
metadata: {},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const todos = await Todo.get(ctx.sessionID)
|
2025-06-04 19:09:40 +00:00
|
|
|
return {
|
2025-07-07 19:53:43 +00:00
|
|
|
title: `${todos.filter((x) => x.status !== "completed").length} todos`,
|
2025-06-04 19:09:40 +00:00
|
|
|
metadata: {
|
|
|
|
|
todos,
|
|
|
|
|
},
|
|
|
|
|
output: JSON.stringify(todos, null, 2),
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|