mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 09:44:21 +01:00
Update todo tool to use centralized Todo module
This commit is contained in:
@@ -1,31 +1,18 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod/v4"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
import DESCRIPTION_WRITE from "./todowrite.txt"
|
import DESCRIPTION_WRITE from "./todowrite.txt"
|
||||||
import { Instance } from "../project/instance"
|
import { Todo } from "../session/todo"
|
||||||
|
|
||||||
const TodoInfo = z.object({
|
|
||||||
content: z.string().describe("Brief description of the task"),
|
|
||||||
status: z.string().describe("Current status of the task: pending, in_progress, completed, cancelled"),
|
|
||||||
priority: z.string().describe("Priority level of the task: high, medium, low"),
|
|
||||||
id: z.string().describe("Unique identifier for the todo item"),
|
|
||||||
})
|
|
||||||
type TodoInfo = z.infer<typeof TodoInfo>
|
|
||||||
|
|
||||||
const state = Instance.state(() => {
|
|
||||||
const todos: {
|
|
||||||
[sessionId: string]: TodoInfo[]
|
|
||||||
} = {}
|
|
||||||
return todos
|
|
||||||
})
|
|
||||||
|
|
||||||
export const TodoWriteTool = Tool.define("todowrite", {
|
export const TodoWriteTool = Tool.define("todowrite", {
|
||||||
description: DESCRIPTION_WRITE,
|
description: DESCRIPTION_WRITE,
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
todos: z.array(TodoInfo).describe("The updated todo list"),
|
todos: z.array(Todo.Info).describe("The updated todo list"),
|
||||||
}),
|
}),
|
||||||
async execute(params, opts) {
|
async execute(params, opts) {
|
||||||
const todos = state()
|
await Todo.update({
|
||||||
todos[opts.sessionID] = params.todos
|
sessionID: opts.sessionID,
|
||||||
|
todos: params.todos,
|
||||||
|
})
|
||||||
return {
|
return {
|
||||||
title: `${params.todos.filter((x) => x.status !== "completed").length} todos`,
|
title: `${params.todos.filter((x) => x.status !== "completed").length} todos`,
|
||||||
output: JSON.stringify(params.todos, null, 2),
|
output: JSON.stringify(params.todos, null, 2),
|
||||||
@@ -40,7 +27,7 @@ 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, opts) {
|
||||||
const todos = state()[opts.sessionID] ?? []
|
const todos = await Todo.get(opts.sessionID)
|
||||||
return {
|
return {
|
||||||
title: `${todos.filter((x) => x.status !== "completed").length} todos`,
|
title: `${todos.filter((x) => x.status !== "completed").length} todos`,
|
||||||
metadata: {
|
metadata: {
|
||||||
|
|||||||
Reference in New Issue
Block a user