Dax Raad 8 mesi fa
parent
commit
a2884b08cc

+ 1 - 1
packages/opencode/src/app/app.ts

@@ -37,7 +37,7 @@ export namespace App {
       cwd: input.cwd,
       cwd: input.cwd,
       version: input.version,
       version: input.version,
     })
     })
-    const git = await Filesystem.findUp(".git", input.cwd).then((x) =>
+    const git = await Filesystem.findUp(".git", input.cwd).then(([x]) =>
       x ? path.dirname(x) : undefined,
       x ? path.dirname(x) : undefined,
     )
     )
     log.info("git", { git })
     log.info("git", { git })

+ 1 - 1
packages/opencode/src/config/config.ts

@@ -9,7 +9,7 @@ export namespace Config {
   export const state = App.state("config", async (app) => {
   export const state = App.state("config", async (app) => {
     let result: Info = {}
     let result: Info = {}
     for (const file of ["opencode.jsonc", "opencode.json"]) {
     for (const file of ["opencode.jsonc", "opencode.json"]) {
-      const resolved = await Filesystem.findUp(
+      const [resolved] = await Filesystem.findUp(
         file,
         file,
         app.path.cwd,
         app.path.cwd,
         app.path.root,
         app.path.root,

+ 4 - 14
packages/opencode/src/session/context.ts

@@ -1,5 +1,5 @@
 import { App } from "../app/app"
 import { App } from "../app/app"
-import path from "path"
+import { Filesystem } from "../util/filesystem"
 
 
 export namespace SessionContext {
 export namespace SessionContext {
   const FILES = [
   const FILES = [
@@ -9,20 +9,10 @@ export namespace SessionContext {
   ]
   ]
   export async function find() {
   export async function find() {
     const { cwd, root } = App.info().path
     const { cwd, root } = App.info().path
-    let current = cwd
     const found = []
     const found = []
-    while (true) {
-      for (const item of FILES) {
-        const file = Bun.file(path.join(current, item))
-        if (await file.exists()) {
-          found.push(file.text())
-        }
-      }
-
-      if (current === root) break
-      const parent = path.dirname(current)
-      if (parent === current) break
-      current = parent
+    for (const item of FILES) {
+      const matches = await Filesystem.findUp(item, cwd, root)
+      found.push(...matches.map((x) => Bun.file(x).text()))
     }
     }
     return Promise.all(found).then((parts) => parts.join("\n\n"))
     return Promise.all(found).then((parts) => parts.join("\n\n"))
   }
   }

+ 2 - 1
packages/opencode/src/session/index.ts

@@ -683,6 +683,7 @@ export namespace Session {
     modelID: string
     modelID: string
     providerID: string
     providerID: string
   }) {
   }) {
+    const app = App.info()
     await Session.chat({
     await Session.chat({
       sessionID: input.sessionID,
       sessionID: input.sessionID,
       providerID: input.providerID,
       providerID: input.providerID,
@@ -690,7 +691,7 @@ export namespace Session {
       parts: [
       parts: [
         {
         {
           type: "text",
           type: "text",
-          text: PROMPT_INITIALIZE,
+          text: PROMPT_INITIALIZE.replace("${path}", app.path.root),
         },
         },
       ],
       ],
     })
     })

+ 2 - 1
packages/opencode/src/session/prompt/initialize.txt

@@ -3,5 +3,6 @@ Please analyze this codebase and create an AGENTS.md file containing:
 2. Code style guidelines including imports, formatting, types, naming conventions, error handling, etc.
 2. Code style guidelines including imports, formatting, types, naming conventions, error handling, etc.
 
 
 The file you create will be given to agentic coding agents (such as yourself) that operate in this repository. Make it about 20 lines long.
 The file you create will be given to agentic coding agents (such as yourself) that operate in this repository. Make it about 20 lines long.
-If there's already an AGENTS.md, improve it.
 If there are Cursor rules (in .cursor/rules/ or .cursorrules) or Copilot rules (in .github/copilot-instructions.md), make sure to include them.
 If there are Cursor rules (in .cursor/rules/ or .cursorrules) or Copilot rules (in .github/copilot-instructions.md), make sure to include them.
+
+If there's already an AGENTS.md, improve it if it's located in ${path}

+ 9 - 9
packages/opencode/src/util/filesystem.ts

@@ -3,16 +3,16 @@ import { dirname, join } from "path"
 
 
 export namespace Filesystem {
 export namespace Filesystem {
   export async function findUp(target: string, start: string, stop?: string) {
   export async function findUp(target: string, start: string, stop?: string) {
-    let currentDir = start
+    let current = start
+    const result = []
     while (true) {
     while (true) {
-      const targetPath = join(currentDir, target)
-      if (await exists(targetPath)) return targetPath
-      if (stop === currentDir) return
-      const parentDir = dirname(currentDir)
-      if (parentDir === currentDir) {
-        return
-      }
-      currentDir = parentDir
+      const search = join(current, target)
+      if (await exists(search)) result.push(search)
+      if (stop === current) break
+      const parent = dirname(current)
+      if (parent === current) break
+      current = parent
     }
     }
+    return result
   }
   }
 }
 }