@comfanion/usethis_todo 0.1.7-dev.2 → 0.1.7-dev.3
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 +32 -24
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -37,48 +37,56 @@ const UsethisTodoPlugin: Plugin = async ({ directory, client }) => {
|
|
|
37
37
|
"todoread",
|
|
38
38
|
])
|
|
39
39
|
|
|
40
|
-
// 1. Collect all
|
|
41
|
-
const
|
|
42
|
-
const
|
|
40
|
+
// 1. Collect all TODO-related parts
|
|
41
|
+
const toolParts: { part: any; isLast: boolean }[] = []
|
|
42
|
+
const snapshotParts = new Set<any>()
|
|
43
|
+
let lastSnapshotPart: any = null
|
|
43
44
|
|
|
44
45
|
for (const msg of messages) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
// Tool outputs
|
|
46
|
+
for (const part of (msg.parts || [])) {
|
|
47
|
+
// Tool parts (contain both state.input and state.output)
|
|
48
48
|
if (part.type === "tool" && prunedToolNames.has(part.tool) && part.state?.status === "completed") {
|
|
49
|
-
|
|
49
|
+
toolParts.push({ part, isLast: part.callID === state.lastToolCallId })
|
|
50
50
|
}
|
|
51
|
-
// User "## TODO"
|
|
51
|
+
// User "## TODO" snapshot text parts
|
|
52
52
|
if (part.type === "text" && typeof part.text === "string" && part.text.startsWith("## TODO")) {
|
|
53
|
-
|
|
53
|
+
snapshotParts.add(part)
|
|
54
|
+
lastSnapshotPart = part
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
|
|
59
|
+
if (toolParts.length === 0 && snapshotParts.size === 0) return
|
|
60
|
+
|
|
58
61
|
// 2. Check if all tasks are done by parsing the latest snapshot
|
|
59
|
-
const
|
|
60
|
-
const doneMatch =
|
|
62
|
+
const lastSnapshotText = lastSnapshotPart?.text || ""
|
|
63
|
+
const doneMatch = lastSnapshotText.match(/\[(\d+)\/(\d+) done/)
|
|
61
64
|
const allDone = doneMatch && doneMatch[1] === doneMatch[2] && parseInt(doneMatch[1]) > 0
|
|
62
65
|
|
|
63
|
-
// 3. Prune tool
|
|
64
|
-
for (const { part, isLast } of
|
|
66
|
+
// 3. Prune old tool parts — clear BOTH input and output
|
|
67
|
+
for (const { part, isLast } of toolParts) {
|
|
65
68
|
if (allDone || !isLast) {
|
|
66
|
-
part.state.output = "[TODO
|
|
69
|
+
part.state.output = "[TODO pruned]"
|
|
70
|
+
if (part.state.input) part.state.input = {}
|
|
67
71
|
}
|
|
68
72
|
}
|
|
69
73
|
|
|
70
|
-
// 4.
|
|
71
|
-
if
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
for (
|
|
79
|
-
|
|
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))
|
|
80
85
|
}
|
|
81
86
|
}
|
|
87
|
+
|
|
88
|
+
// 5. Remove messages that became empty after part removal
|
|
89
|
+
output.messages = messages.filter((msg: any) => (msg.parts || []).length > 0)
|
|
82
90
|
},
|
|
83
91
|
|
|
84
92
|
tool: {
|