@comfanion/usethis_todo 0.1.16-dev.3 → 0.1.16-dev.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +34 -12
- package/package.json +1 -1
- package/tools.ts +1 -1
package/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Plugin } from "@opencode-ai/plugin"
|
|
|
2
2
|
import path from "path"
|
|
3
3
|
import fs from "fs/promises"
|
|
4
4
|
|
|
5
|
-
import { write, read, read_five, read_by_id, setNativeStorageBase } from "./tools"
|
|
5
|
+
import { write, read, read_five, read_by_id, setNativeStorageBase, readTodos } from "./tools"
|
|
6
6
|
|
|
7
7
|
interface TodoPruneState {
|
|
8
8
|
lastToolCallId: string | null
|
|
@@ -41,6 +41,7 @@ const UsethisTodoPlugin: Plugin = async ({ directory, client }) => {
|
|
|
41
41
|
"usethis_todo_read",
|
|
42
42
|
"usethis_todo_read_five",
|
|
43
43
|
"usethis_todo_read_by_id",
|
|
44
|
+
"todowrite",
|
|
44
45
|
])
|
|
45
46
|
|
|
46
47
|
// Collect all TODO-related tool parts
|
|
@@ -66,25 +67,44 @@ const UsethisTodoPlugin: Plugin = async ({ directory, client }) => {
|
|
|
66
67
|
},
|
|
67
68
|
|
|
68
69
|
tool: {
|
|
69
|
-
//
|
|
70
|
-
// NOTE: native "todowrite"/"todoread" names trigger sidebar refresh
|
|
71
|
-
// but TUI hides their output. Using custom names for visibility.
|
|
70
|
+
// Our enhanced tools — AI uses these for graph/dependencies
|
|
72
71
|
usethis_todo_write: write,
|
|
73
72
|
usethis_todo_read: read,
|
|
74
73
|
usethis_todo_read_five: read_five,
|
|
75
74
|
usethis_todo_read_by_id: read_by_id,
|
|
75
|
+
|
|
76
|
+
// Native override — emulates todowrite for sidebar refresh + TUI checklist
|
|
77
|
+
// Reads the data our write already stored and returns native JSON format.
|
|
78
|
+
// tool.execute.after on usethis_todo_write auto-invokes this via description hint.
|
|
79
|
+
todowrite: {
|
|
80
|
+
description: "Internal: sync TODO sidebar. Called automatically after usethis_todo_write.",
|
|
81
|
+
args: {},
|
|
82
|
+
async execute(_args: any, context: any) {
|
|
83
|
+
const todos = await readTodos(context.sessionID, context.directory)
|
|
84
|
+
// Return native format: JSON array → TUI renders checklist + fires todo.updated
|
|
85
|
+
return JSON.stringify(todos.map(t => ({
|
|
86
|
+
id: t.id,
|
|
87
|
+
content: t.content,
|
|
88
|
+
status: t.status,
|
|
89
|
+
priority: t.priority,
|
|
90
|
+
})))
|
|
91
|
+
},
|
|
92
|
+
},
|
|
76
93
|
},
|
|
77
94
|
|
|
78
95
|
// Set nicer titles in TUI + track prune state
|
|
79
96
|
"tool.execute.after": async (input, output) => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
97
|
+
const ourTools = new Set(["usethis_todo_write", "usethis_todo_read", "usethis_todo_read_five", "usethis_todo_read_by_id", "todowrite"])
|
|
98
|
+
if (!ourTools.has(input.tool)) return
|
|
99
|
+
|
|
100
|
+
// Update prune state with latest call ID (only for our custom tools, not todowrite)
|
|
101
|
+
if (input.tool.startsWith("usethis_todo_")) {
|
|
102
|
+
const sessionID = input.sessionID
|
|
103
|
+
if (sessionID) {
|
|
104
|
+
const state = pruneStates.get(sessionID) || { lastToolCallId: null }
|
|
105
|
+
state.lastToolCallId = input.callID
|
|
106
|
+
pruneStates.set(sessionID, state)
|
|
107
|
+
}
|
|
88
108
|
}
|
|
89
109
|
|
|
90
110
|
const out = output.output || ""
|
|
@@ -100,6 +120,8 @@ const UsethisTodoPlugin: Plugin = async ({ directory, client }) => {
|
|
|
100
120
|
output.title = "Next 5 tasks"
|
|
101
121
|
} else if (input.tool === "usethis_todo_read_by_id") {
|
|
102
122
|
output.title = "Task details"
|
|
123
|
+
} else if (input.tool === "todowrite") {
|
|
124
|
+
output.title = "Sidebar sync"
|
|
103
125
|
}
|
|
104
126
|
},
|
|
105
127
|
}
|
package/package.json
CHANGED
package/tools.ts
CHANGED
|
@@ -194,7 +194,7 @@ function toNativePriority(priority: string): string {
|
|
|
194
194
|
// Read / Write
|
|
195
195
|
// ============================================================================
|
|
196
196
|
|
|
197
|
-
async function readTodos(sid: string, directory?: string): Promise<Todo[]> {
|
|
197
|
+
export async function readTodos(sid: string, directory?: string): Promise<Todo[]> {
|
|
198
198
|
try {
|
|
199
199
|
const storagePaths = await getStoragePaths(sid)
|
|
200
200
|
for (const storagePath of storagePaths) {
|