@comfanion/usethis_todo 0.1.15-dev.2 → 0.1.15-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.
Files changed (3) hide show
  1. package/index.ts +23 -33
  2. package/package.json +1 -1
  3. package/tools.ts +1 -15
package/index.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  import type { Plugin } from "@opencode-ai/plugin"
2
- import path from "path"
3
- import fs from "fs/promises"
4
2
 
5
- import { write, read, read_five, read_by_id, update, setNativeStorageBase } from "./tools"
3
+ import { write, read, read_five, read_by_id, update } from "./tools"
6
4
 
7
5
  interface TodoPruneState {
8
6
  lastToolCallId: string | null
@@ -19,18 +17,6 @@ const UsethisTodoPlugin: Plugin = async ({ directory, client }) => {
19
17
  // ignore
20
18
  }
21
19
 
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
-
34
20
  return {
35
21
  "experimental.chat.messages.transform": async (_input: unknown, output: { messages: any[] }) => {
36
22
  const messages = output.messages || []
@@ -141,28 +127,32 @@ const UsethisTodoPlugin: Plugin = async ({ directory, client }) => {
141
127
  output.title = "📋 Task details"
142
128
  }
143
129
 
144
- // Only publish for our write/update tools
145
- const writeTools = new Set([
130
+ // After write/update — try to refresh sidebar via session re-select
131
+ const writeTools = new Set(["usethis_todo_write", "usethis_todo_update"])
132
+ if (writeTools.has(input.tool) && sessionID) {
133
+ try {
134
+ await (client as any)?.tui?.publish?.({
135
+ body: {
136
+ type: "tui.session.select",
137
+ properties: { sessionID },
138
+ },
139
+ })
140
+ } catch {
141
+ // non-fatal — experimental sidebar refresh
142
+ }
143
+ }
144
+
145
+ // Publish snapshot into chat (fallback when sidebar doesn't refresh)
146
+ const publishTools = new Set([
146
147
  "usethis_todo_write",
147
148
  "usethis_todo_update",
149
+ "usethis_todo_read",
150
+ "usethis_todo_read_five",
151
+ "usethis_todo_read_by_id",
148
152
  ])
149
153
 
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
- }
154
+ if (!publishTools.has(input.tool)) return
164
155
 
165
- // Fallback: publish snapshot into chat (helps when sidebar doesn't refresh)
166
156
  const text = ["## TODO", "", out].join("\n")
167
157
 
168
158
  try {
@@ -180,4 +170,4 @@ const UsethisTodoPlugin: Plugin = async ({ directory, client }) => {
180
170
  }
181
171
  }
182
172
 
183
- export default UsethisTodoPlugin;
173
+ export default UsethisTodoPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comfanion/usethis_todo",
3
- "version": "0.1.15-dev.2",
3
+ "version": "0.1.15-dev.4",
4
4
  "description": "OpenCode plugin: enhanced TODO tools (dual storage + dependency graph)",
5
5
  "type": "module",
6
6
  "main": "./index.ts",
package/tools.ts CHANGED
@@ -111,13 +111,6 @@ 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
-
121
114
  // Resolve project directory (context.directory may be undefined via MCP)
122
115
  function dir(directory?: string): string {
123
116
  return directory || process.env.OPENCODE_PROJECT_DIR || process.cwd()
@@ -164,15 +157,8 @@ async function getNativeDataDirs(): Promise<string[]> {
164
157
  }
165
158
 
166
159
  async function getNativePaths(sid: string): Promise<string[]> {
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
160
  const baseDirs = await getNativeDataDirs()
161
+ const file = `${sid || "current"}.json`
176
162
  return baseDirs.map((base) => path.join(base, "opencode", "storage", "todo", file))
177
163
  }
178
164