Просмотр исходного кода

Improve logging and simplify fzf implementation

- Refactor fzf search to use Bun's $ syntax for cleaner command execution
- Add request/response duration logging to server middleware
- Set default service name for logging to improve log clarity

🤖 Generated with [OpenCode](https://opencode.ai)

Co-Authored-By: OpenCode <[email protected]>
Dax Raad 8 месяцев назад
Родитель
Сommit
6a261dedb4

+ 11 - 11
packages/opencode/src/external/fzf.ts

@@ -1,4 +1,3 @@
-import { App } from "../app/app"
 import path from "path"
 import { Global } from "../global"
 import fs from "fs/promises"
@@ -6,6 +5,7 @@ import { z } from "zod"
 import { NamedError } from "../util/error"
 import { lazy } from "../util/lazy"
 import { Log } from "../util/log"
+import { $ } from "bun"
 
 export namespace Fzf {
   const log = Log.create({ service: "fzf" })
@@ -117,18 +117,18 @@ export namespace Fzf {
   }
 
   export async function search(cwd: string, query: string) {
-    const process = Bun.spawn({
-      cwd,
-      stdin: "inherit",
-      stdout: "pipe",
-      stderr: "pipe",
-      cmd: [await filepath(), "--filter", query],
-    })
-    await process.exited
-    const stdout = await Bun.readableStreamToText(process.stdout)
-    return stdout
+    const results = await $`${await filepath()} --filter ${query}`
+      .quiet()
+      .throws(false)
+      .cwd(cwd)
+      .text()
+    const split = results
       .trim()
       .split("\n")
       .filter((line) => line.length > 0)
+    log.info("results", {
+      count: split.length,
+    })
+    return split
   }
 }

+ 6 - 2
packages/opencode/src/server/server.ts

@@ -56,12 +56,16 @@ export namespace Server {
           },
         )
       })
-      .use((c, next) => {
+      .use(async (c, next) => {
         log.info("request", {
           method: c.req.method,
           path: c.req.path,
         })
-        return next()
+        const start = Date.now()
+        await next()
+        log.info("response", {
+          duration: Date.now() - start,
+        })
       })
       .get(
         "/openapi",

+ 1 - 1
packages/opencode/src/util/log.ts

@@ -2,7 +2,7 @@ import path from "path"
 import fs from "fs/promises"
 import { Global } from "../global"
 export namespace Log {
-  export const Default = create()
+  export const Default = create({ service: "default" })
 
   export interface Options {
     print: boolean