Prechádzať zdrojové kódy

fix(tui): handle events across workspaces (#30281)

James Long 2 mesiacov pred
rodič
commit
fa23fb5d38

+ 8 - 4
packages/opencode/src/cli/cmd/tui/app.tsx

@@ -958,11 +958,13 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
     bindings: tuiConfig.keybinds.gather("app_exit", ["app.exit"]),
   }))
 
-  event.on(TuiEvent.CommandExecute.type, (evt) => {
+  event.on(TuiEvent.CommandExecute.type, (evt, { workspace }) => {
+    if (workspace !== project.workspace.current()) return
     keymap.dispatchCommand(evt.properties.command)
   })
 
-  event.on(TuiEvent.ToastShow.type, (evt) => {
+  event.on(TuiEvent.ToastShow.type, (evt, { workspace }) => {
+    if (workspace !== project.workspace.current()) return
     toast.show({
       title: evt.properties.title,
       message: evt.properties.message,
@@ -971,7 +973,8 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
     })
   })
 
-  event.on(TuiEvent.SessionSelect.type, (evt) => {
+  event.on(TuiEvent.SessionSelect.type, (evt, { workspace }) => {
+    if (workspace !== project.workspace.current()) return
     route.navigate({
       type: "session",
       sessionID: evt.properties.sessionID,
@@ -988,7 +991,8 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
     }
   })
 
-  event.on("session.error", (evt) => {
+  event.on("session.error", (evt, { workspace }) => {
+    if (workspace !== project.workspace.current()) return
     const error = evt.properties.error
     if (error && typeof error === "object" && error.name === "MessageAbortedError") return
     const message = errorMessage(error)

+ 2 - 1
packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

@@ -319,7 +319,8 @@ export function Prompt(props: PromptProps) {
   let promptPartTypeId = 0
   const event = useEvent()
 
-  event.on(TuiEvent.PromptAppend.type, (evt) => {
+  event.on(TuiEvent.PromptAppend.type, (evt, { workspace }) => {
+    if (workspace !== project.workspace.current()) return
     if (!input || input.isDestroyed) return
     input.insertText(evt.properties.text)
     setTimeout(() => {

+ 2 - 3
packages/opencode/src/cli/cmd/tui/context/event.ts

@@ -1,4 +1,5 @@
 import type { Event } from "@opencode-ai/sdk/v2"
+import * as Log from "@opencode-ai/core/util/log"
 import { useProject } from "./project"
 import { useSDK } from "./sdk"
 
@@ -16,9 +17,7 @@ export function useEvent() {
         return
       }
 
-      if (event.directory === "global" || event.project === project.project()) {
-        handler(event.payload, { workspace: event.workspace })
-      }
+      handler(event.payload, { workspace: event.workspace })
     })
   }
 

+ 0 - 13
packages/opencode/test/cli/tui/use-event.test.tsx

@@ -113,19 +113,6 @@ describe("useEvent", () => {
     }
   })
 
-  test("ignores events for other projects", async () => {
-    const { app, emit, seen } = await mount()
-
-    try {
-      emit(event(vcs("other"), { directory, project: "proj_other" }))
-      await Bun.sleep(30)
-
-      expect(seen).toHaveLength(0)
-    } finally {
-      app.renderer.destroy()
-    }
-  })
-
   test("delivers current project events regardless of active workspace", async () => {
     const { app, emit, project, seen } = await mount()