@comfanion/usethis_todo 0.1.15-dev.5 → 0.1.15-dev.7
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 +17 -68
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ interface TodoPruneState {
|
|
|
8
8
|
|
|
9
9
|
const pruneStates = new Map<string, TodoPruneState>()
|
|
10
10
|
|
|
11
|
-
const UsethisTodoPlugin: Plugin = async ({ directory
|
|
11
|
+
const UsethisTodoPlugin: Plugin = async ({ directory }) => {
|
|
12
12
|
// Ensure storage directory exists on init
|
|
13
13
|
try {
|
|
14
14
|
const todoDir = path.join(directory, ".opencode", "session-todo")
|
|
@@ -37,67 +37,41 @@ const UsethisTodoPlugin: Plugin = async ({ directory, client }) => {
|
|
|
37
37
|
"todoread",
|
|
38
38
|
])
|
|
39
39
|
|
|
40
|
-
//
|
|
40
|
+
// Collect all TODO-related tool parts
|
|
41
41
|
const toolParts: { part: any; isLast: boolean }[] = []
|
|
42
|
-
const snapshotParts = new Set<any>()
|
|
43
|
-
let lastSnapshotPart: any = null
|
|
44
42
|
|
|
45
43
|
for (const msg of messages) {
|
|
46
44
|
for (const part of (msg.parts || [])) {
|
|
47
|
-
// Tool parts (contain both state.input and state.output)
|
|
48
45
|
if (part.type === "tool" && prunedToolNames.has(part.tool) && part.state?.status === "completed") {
|
|
49
46
|
toolParts.push({ part, isLast: part.callID === state.lastToolCallId })
|
|
50
47
|
}
|
|
51
|
-
// User "## TODO" snapshot text parts
|
|
52
|
-
if (part.type === "text" && typeof part.text === "string" && part.text.startsWith("## TODO")) {
|
|
53
|
-
snapshotParts.add(part)
|
|
54
|
-
lastSnapshotPart = part
|
|
55
|
-
}
|
|
56
48
|
}
|
|
57
49
|
}
|
|
58
50
|
|
|
59
|
-
if (toolParts.length === 0
|
|
60
|
-
|
|
61
|
-
// 2. Check if all tasks are done by parsing the latest snapshot
|
|
62
|
-
const lastSnapshotText = lastSnapshotPart?.text || ""
|
|
63
|
-
const doneMatch = lastSnapshotText.match(/\[(\d+)\/(\d+) done/)
|
|
64
|
-
const allDone = doneMatch && doneMatch[1] === doneMatch[2] && parseInt(doneMatch[1]) > 0
|
|
51
|
+
if (toolParts.length === 0) return
|
|
65
52
|
|
|
66
|
-
//
|
|
53
|
+
// Prune old tool parts — clear BOTH input and output, keep only last
|
|
67
54
|
for (const { part, isLast } of toolParts) {
|
|
68
|
-
if (
|
|
55
|
+
if (!isLast) {
|
|
69
56
|
part.state.output = "[TODO pruned]"
|
|
70
57
|
if (part.state.input) part.state.input = {}
|
|
71
58
|
}
|
|
72
59
|
}
|
|
73
|
-
|
|
74
|
-
// 4. Remove old "## TODO" snapshot parts entirely from messages
|
|
75
|
-
// Keep only the last snapshot (or none if allDone)
|
|
76
|
-
const snapshotsToRemove = new Set(snapshotParts)
|
|
77
|
-
if (!allDone && lastSnapshotPart) {
|
|
78
|
-
snapshotsToRemove.delete(lastSnapshotPart)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (snapshotsToRemove.size > 0) {
|
|
82
|
-
for (const msg of messages) {
|
|
83
|
-
if (!Array.isArray(msg.parts)) continue
|
|
84
|
-
msg.parts = msg.parts.filter((p: any) => !snapshotsToRemove.has(p))
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// 5. Remove messages that became empty after part removal
|
|
89
|
-
output.messages = messages.filter((msg: any) => (msg.parts || []).length > 0)
|
|
90
60
|
},
|
|
91
61
|
|
|
92
62
|
tool: {
|
|
63
|
+
// Enhanced tools (original names)
|
|
93
64
|
usethis_todo_write: write,
|
|
94
65
|
usethis_todo_read: read,
|
|
95
66
|
usethis_todo_read_five: read_five,
|
|
96
67
|
usethis_todo_read_by_id: read_by_id,
|
|
97
68
|
usethis_todo_update: update,
|
|
69
|
+
// Override native tools — same implementation, native names
|
|
70
|
+
todowrite: write,
|
|
71
|
+
todoread: read,
|
|
98
72
|
},
|
|
99
73
|
|
|
100
|
-
//
|
|
74
|
+
// Set nicer titles in TUI + track prune state
|
|
101
75
|
"tool.execute.after": async (input, output) => {
|
|
102
76
|
if (!input.tool.startsWith("usethis_todo_") && input.tool !== "todowrite" && input.tool !== "todoread") return
|
|
103
77
|
|
|
@@ -112,44 +86,19 @@ const UsethisTodoPlugin: Plugin = async ({ directory, client }) => {
|
|
|
112
86
|
const out = output.output || ""
|
|
113
87
|
|
|
114
88
|
// Set a nicer title in TUI
|
|
115
|
-
if (input.tool === "usethis_todo_write") {
|
|
89
|
+
if (input.tool === "usethis_todo_write" || input.tool === "todowrite") {
|
|
116
90
|
const match = out.match(/\[(\d+)\/(\d+) done/)
|
|
117
|
-
output.title = match ?
|
|
91
|
+
output.title = match ? `TODO: ${match[2]} tasks` : "TODO updated"
|
|
118
92
|
} else if (input.tool === "usethis_todo_update") {
|
|
119
93
|
const match = out.match(/^✅ (.+)$/m)
|
|
120
|
-
output.title = match ?
|
|
121
|
-
} else if (input.tool === "usethis_todo_read") {
|
|
94
|
+
output.title = match ? match[1] : "Task updated"
|
|
95
|
+
} else if (input.tool === "usethis_todo_read" || input.tool === "todoread") {
|
|
122
96
|
const match = out.match(/\[(\d+)\/(\d+) done, (\d+) in progress\]/)
|
|
123
|
-
output.title = match ?
|
|
97
|
+
output.title = match ? `TODO [${match[1]}/${match[2]} done]` : "TODO list"
|
|
124
98
|
} else if (input.tool === "usethis_todo_read_five") {
|
|
125
|
-
output.title = "
|
|
99
|
+
output.title = "Next 5 tasks"
|
|
126
100
|
} else if (input.tool === "usethis_todo_read_by_id") {
|
|
127
|
-
output.title = "
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Publish snapshot into chat (sidebar doesn't refresh from plugin writes)
|
|
131
|
-
const publishTools = new Set([
|
|
132
|
-
"usethis_todo_write",
|
|
133
|
-
"usethis_todo_update",
|
|
134
|
-
"usethis_todo_read",
|
|
135
|
-
"usethis_todo_read_five",
|
|
136
|
-
"usethis_todo_read_by_id",
|
|
137
|
-
])
|
|
138
|
-
|
|
139
|
-
if (!publishTools.has(input.tool)) return
|
|
140
|
-
|
|
141
|
-
const text = ["## TODO", "", out].join("\n")
|
|
142
|
-
|
|
143
|
-
try {
|
|
144
|
-
await client?.session?.prompt?.({
|
|
145
|
-
path: { id: input.sessionID },
|
|
146
|
-
body: {
|
|
147
|
-
noReply: true,
|
|
148
|
-
parts: [{ type: "text", text }],
|
|
149
|
-
},
|
|
150
|
-
})
|
|
151
|
-
} catch {
|
|
152
|
-
// non-fatal
|
|
101
|
+
output.title = "Task details"
|
|
153
102
|
}
|
|
154
103
|
},
|
|
155
104
|
}
|