瀏覽代碼

fix: resolve live project directory via session cache for TUI writes

The message.updated handler wrote TUI agent-model state using ctx.directory,
which is captured at plugin init and goes stale after a project switch within
the same server instance. Cache sessionID -> directory from session.created
events and look up the live directory per message, falling back to
ctx.directory.

Replaces the earlier info.path.cwd approach, which was dead code (UserMessage
carries agent but no path, so the guard never sees a path).

Fixes greptile comment on PR #767.
Michael Henke 3 周之前
父節點
當前提交
3937e88286
共有 1 個文件被更改,包括 12 次插入1 次删除
  1. 12 1
      src/index.ts

+ 12 - 1
src/index.ts

@@ -146,6 +146,9 @@ const OhMyOpenCodeLite: Plugin = async (ctx) => {
   let multiplexerSessionManager: MultiplexerSessionManager;
   let autoUpdateChecker: ReturnType<typeof createAutoUpdateCheckerHook>;
   let sessionAgentMap: Map<string, string>;
+  // ponytail: cache sessionID -> project directory so TUI model writes
+  // land in the right per-project file after a project switch (ctx.directory is stale)
+  const sessionDirectories = new Map<string, string>();
   let sessionLifecycle: SessionLifecycle;
 
   let chatHeadersHook: ReturnType<typeof createChatHeadersHook>;
@@ -865,6 +868,7 @@ const OhMyOpenCodeLite: Plugin = async (ctx) => {
               modelID?: string;
             };
             sessionID?: string;
+            directory?: string;
           };
           sessionID?: string;
           id?: string;
@@ -897,7 +901,8 @@ const OhMyOpenCodeLite: Plugin = async (ctx) => {
               model,
               variant: variant ?? null,
             },
-            ctx.directory,
+            (info?.sessionID && sessionDirectories.get(info.sessionID)) ??
+              ctx.directory,
           );
         }
       }
@@ -908,6 +913,11 @@ const OhMyOpenCodeLite: Plugin = async (ctx) => {
         if (depthTracker && childSessionId && parentSessionId) {
           depthTracker.registerChild(parentSessionId, childSessionId);
         }
+        const createdSessionId = event.properties?.info?.id;
+        const createdSessionDir = event.properties?.info?.directory;
+        if (createdSessionId && createdSessionDir) {
+          sessionDirectories.set(createdSessionId, createdSessionDir);
+        }
       }
 
       // Handle multiplexer pane spawning for OpenCode's Task tool sessions
@@ -987,6 +997,7 @@ const OhMyOpenCodeLite: Plugin = async (ctx) => {
         }
         if (sessionID) {
           sessionAgentMap.delete(sessionID);
+          sessionDirectories.delete(sessionID);
         }
       }
     },