@comfanion/usethis_todo 0.1.15-dev.1 → 0.1.15-dev.2
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 -7
- package/package.json +1 -1
- package/tools.ts +15 -1
package/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Plugin } from "@opencode-ai/plugin"
|
|
2
|
+
import path from "path"
|
|
3
|
+
import fs from "fs/promises"
|
|
2
4
|
|
|
3
|
-
import { write, read, read_five, read_by_id, update } from "./tools"
|
|
5
|
+
import { write, read, read_five, read_by_id, update, setNativeStorageBase } from "./tools"
|
|
4
6
|
|
|
5
7
|
interface TodoPruneState {
|
|
6
8
|
lastToolCallId: string | null
|
|
@@ -17,6 +19,18 @@ const UsethisTodoPlugin: Plugin = async ({ directory, client }) => {
|
|
|
17
19
|
// ignore
|
|
18
20
|
}
|
|
19
21
|
|
|
22
|
+
// Resolve native storage path (non-blocking — MUST NOT await in init)
|
|
23
|
+
client.path.get().then((res) => {
|
|
24
|
+
try {
|
|
25
|
+
const state = (res as any)?.data?.state
|
|
26
|
+
if (state && typeof state === "string") {
|
|
27
|
+
setNativeStorageBase(state)
|
|
28
|
+
}
|
|
29
|
+
} catch {
|
|
30
|
+
// ignore
|
|
31
|
+
}
|
|
32
|
+
}).catch(() => {})
|
|
33
|
+
|
|
20
34
|
return {
|
|
21
35
|
"experimental.chat.messages.transform": async (_input: unknown, output: { messages: any[] }) => {
|
|
22
36
|
const messages = output.messages || []
|
|
@@ -127,17 +141,28 @@ const UsethisTodoPlugin: Plugin = async ({ directory, client }) => {
|
|
|
127
141
|
output.title = "📋 Task details"
|
|
128
142
|
}
|
|
129
143
|
|
|
130
|
-
//
|
|
131
|
-
const
|
|
144
|
+
// Only publish for our write/update tools
|
|
145
|
+
const writeTools = new Set([
|
|
132
146
|
"usethis_todo_write",
|
|
133
147
|
"usethis_todo_update",
|
|
134
|
-
"usethis_todo_read",
|
|
135
|
-
"usethis_todo_read_five",
|
|
136
|
-
"usethis_todo_read_by_id",
|
|
137
148
|
])
|
|
138
149
|
|
|
139
|
-
if (!
|
|
150
|
+
if (!writeTools.has(input.tool)) return
|
|
151
|
+
|
|
152
|
+
// Attempt sidebar refresh via tui.command.execute hack
|
|
153
|
+
// The server may recognize a command that forces re-read of todo storage
|
|
154
|
+
try {
|
|
155
|
+
await (client as any)?.tui?.publish?.({
|
|
156
|
+
body: {
|
|
157
|
+
type: "tui.command.execute",
|
|
158
|
+
properties: { command: "session.todo.refresh" },
|
|
159
|
+
},
|
|
160
|
+
})
|
|
161
|
+
} catch {
|
|
162
|
+
// ignore — experimental
|
|
163
|
+
}
|
|
140
164
|
|
|
165
|
+
// Fallback: publish snapshot into chat (helps when sidebar doesn't refresh)
|
|
141
166
|
const text = ["## TODO", "", out].join("\n")
|
|
142
167
|
|
|
143
168
|
try {
|
package/package.json
CHANGED
package/tools.ts
CHANGED
|
@@ -111,6 +111,13 @@ interface TodoGraph {
|
|
|
111
111
|
// Storage — dual write
|
|
112
112
|
// ============================================================================
|
|
113
113
|
|
|
114
|
+
// Native storage base path (resolved from client.path.get() at runtime)
|
|
115
|
+
let nativeStorageBase: string | null = null
|
|
116
|
+
|
|
117
|
+
export function setNativeStorageBase(statePath: string): void {
|
|
118
|
+
nativeStorageBase = statePath
|
|
119
|
+
}
|
|
120
|
+
|
|
114
121
|
// Resolve project directory (context.directory may be undefined via MCP)
|
|
115
122
|
function dir(directory?: string): string {
|
|
116
123
|
return directory || process.env.OPENCODE_PROJECT_DIR || process.cwd()
|
|
@@ -157,8 +164,15 @@ async function getNativeDataDirs(): Promise<string[]> {
|
|
|
157
164
|
}
|
|
158
165
|
|
|
159
166
|
async function getNativePaths(sid: string): Promise<string[]> {
|
|
160
|
-
const baseDirs = await getNativeDataDirs()
|
|
161
167
|
const file = `${sid || "current"}.json`
|
|
168
|
+
|
|
169
|
+
// Prefer resolved path from client.path.get()
|
|
170
|
+
if (nativeStorageBase) {
|
|
171
|
+
return [path.join(nativeStorageBase, "storage", "todo", file)]
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Fallback to guessed paths
|
|
175
|
+
const baseDirs = await getNativeDataDirs()
|
|
162
176
|
return baseDirs.map((base) => path.join(base, "opencode", "storage", "todo", file))
|
|
163
177
|
}
|
|
164
178
|
|