فهرست منبع

fix(opencode): await run event loop (#31389)

Aiden Cline 3 ماه پیش
والد
کامیت
0a7cb20e66
1فایلهای تغییر یافته به همراه11 افزوده شده و 2 حذف شده
  1. 11 2
      packages/opencode/src/cli/cmd/run.ts

+ 11 - 2
packages/opencode/src/cli/cmd/run.ts

@@ -762,10 +762,15 @@ export const RunCommand = effectCmd({
 
         if (!args.interactive) {
           const events = await client.event.subscribe()
-          loop(client, events).catch((e) => {
+          const completed = loop(client, events).catch((e) => {
             console.error(e)
-            process.exit(1)
+            process.exitCode = 1
           })
+          async function finish() {
+            if (args.attach) return
+            const error = await completed
+            if (error) process.exitCode = 1
+          }
 
           if (args.command) {
             const result = await client.session.command({
@@ -779,7 +784,9 @@ export const RunCommand = effectCmd({
             if (result.error) {
               if (!emit("error", { error: result.error })) UI.error(formatRunError(result.error))
               process.exitCode = 1
+              return
             }
+            await finish()
             return
           }
 
@@ -794,7 +801,9 @@ export const RunCommand = effectCmd({
           if (result.error) {
             if (!emit("error", { error: result.error })) UI.error(formatRunError(result.error))
             process.exitCode = 1
+            return
           }
+          await finish()
           return
         }