Browse Source

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 4 weeks ago
parent
commit
3937e88286
1 changed files with 12 additions and 1 deletions
  1. 12 1
      src/index.ts

+ 12 - 1
src/index.ts

@@ -146,6 +146,9 @@ const OhMyOpenCodeLite: Plugin = async (ctx) => {
   let multiplexerSessionManager: MultiplexerSessionManager;
   let multiplexerSessionManager: MultiplexerSessionManager;
   let autoUpdateChecker: ReturnType<typeof createAutoUpdateCheckerHook>;
   let autoUpdateChecker: ReturnType<typeof createAutoUpdateCheckerHook>;
   let sessionAgentMap: Map<string, string>;
   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 sessionLifecycle: SessionLifecycle;
 
 
   let chatHeadersHook: ReturnType<typeof createChatHeadersHook>;
   let chatHeadersHook: ReturnType<typeof createChatHeadersHook>;
@@ -865,6 +868,7 @@ const OhMyOpenCodeLite: Plugin = async (ctx) => {
               modelID?: string;
               modelID?: string;
             };
             };
             sessionID?: string;
             sessionID?: string;
+            directory?: string;
           };
           };
           sessionID?: string;
           sessionID?: string;
           id?: string;
           id?: string;
@@ -897,7 +901,8 @@ const OhMyOpenCodeLite: Plugin = async (ctx) => {
               model,
               model,
               variant: variant ?? null,
               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) {
         if (depthTracker && childSessionId && parentSessionId) {
           depthTracker.registerChild(parentSessionId, childSessionId);
           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
       // Handle multiplexer pane spawning for OpenCode's Task tool sessions
@@ -987,6 +997,7 @@ const OhMyOpenCodeLite: Plugin = async (ctx) => {
         }
         }
         if (sessionID) {
         if (sessionID) {
           sessionAgentMap.delete(sessionID);
           sessionAgentMap.delete(sessionID);
+          sessionDirectories.delete(sessionID);
         }
         }
       }
       }
     },
     },