@comfanion/usethis_todo 0.1.15-dev.0 → 0.1.15-dev.1

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 +26 -18
  2. package/package.json +1 -1
  3. package/tools.ts +1 -20
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
@@ -11,19 +9,7 @@ interface TodoPruneState {
11
9
  const pruneStates = new Map<string, TodoPruneState>()
12
10
 
13
11
  const UsethisTodoPlugin: Plugin = async ({ directory, client }) => {
14
- // Resolve the authoritative state path from OpenCode server (non-blocking).
15
- // Must NOT await — server may block until plugin init completes → deadlock.
16
- // Wrapped in try-catch because client.path may not exist (sync TypeError).
17
- try {
18
- client?.path?.get()?.then((pathInfo: any) => {
19
- const state = pathInfo?.data?.state
20
- if (state) setNativeStorageBase(state)
21
- }).catch(() => {})
22
- } catch {
23
- // client.path not available in this SDK version — fall back to guessed paths
24
- }
25
-
26
- // Ensure enhanced storage directory exists on init
12
+ // Ensure storage directory exists on init
27
13
  try {
28
14
  const todoDir = path.join(directory, ".opencode", "session-todo")
29
15
  await fs.mkdir(todoDir, { recursive: true })
@@ -141,8 +127,30 @@ const UsethisTodoPlugin: Plugin = async ({ directory, client }) => {
141
127
  output.title = "📋 Task details"
142
128
  }
143
129
 
144
- // Native storage write handles sidebar updates now (via client.path.get()).
145
- // The old session.prompt snapshot was causing "table chunks not found" errors.
130
+ // Publish snapshot into chat (helps when sidebar doesn't refresh)
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
153
+ }
146
154
  },
147
155
  }
148
156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comfanion/usethis_todo",
3
- "version": "0.1.15-dev.0",
3
+ "version": "0.1.15-dev.1",
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,18 +111,6 @@ interface TodoGraph {
111
111
  // Storage — dual write
112
112
  // ============================================================================
113
113
 
114
- // Native storage base path (set by plugin init via client.path.get())
115
- let _nativeStorageBase: string | null = null
116
-
117
- /**
118
- * Set the native storage base path (OpenCode's state directory).
119
- * Called once during plugin initialization with the result of client.path.get().
120
- * This ensures we write to the exact path OpenCode reads from for the sidebar.
121
- */
122
- export function setNativeStorageBase(statePath: string): void {
123
- _nativeStorageBase = statePath
124
- }
125
-
126
114
  // Resolve project directory (context.directory may be undefined via MCP)
127
115
  function dir(directory?: string): string {
128
116
  return directory || process.env.OPENCODE_PROJECT_DIR || process.cwd()
@@ -169,15 +157,8 @@ async function getNativeDataDirs(): Promise<string[]> {
169
157
  }
170
158
 
171
159
  async function getNativePaths(sid: string): Promise<string[]> {
172
- const file = `${sid || "current"}.json`
173
-
174
- // Prefer the authoritative path from OpenCode server API
175
- if (_nativeStorageBase) {
176
- return [path.join(_nativeStorageBase, "storage", "todo", file)]
177
- }
178
-
179
- // Fallback: guess from well-known data dirs
180
160
  const baseDirs = await getNativeDataDirs()
161
+ const file = `${sid || "current"}.json`
181
162
  return baseDirs.map((base) => path.join(base, "opencode", "storage", "todo", file))
182
163
  }
183
164