瀏覽代碼

Consolidate session context handling and add global config support

Refactored context file discovery by removing separate SessionContext module and integrating functionality into SystemPrompt.context(). Added support for finding AGENTS.md and CLAUDE.md files in global config directories.

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

Co-Authored-By: opencode <[email protected]>
Dax Raad 10 月之前
父節點
當前提交
98734ff28c
共有 2 個文件被更改,包括 14 次插入20 次删除
  1. 0 19
      packages/opencode/src/session/context.ts
  2. 14 1
      packages/opencode/src/session/system.ts

+ 0 - 19
packages/opencode/src/session/context.ts

@@ -1,19 +0,0 @@
-import { App } from "../app/app"
-import { Filesystem } from "../util/filesystem"
-
-export namespace SessionContext {
-  const FILES = [
-    "AGENTS.md",
-    "CLAUDE.md",
-    "CONTEXT.md", // deprecated
-  ]
-  export async function find() {
-    const { cwd, root } = App.info().path
-    const found = []
-    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"))
-  }
-}

+ 14 - 1
packages/opencode/src/session/system.ts

@@ -1,6 +1,9 @@
 import { App } from "../app/app"
 import { Ripgrep } from "../external/ripgrep"
+import { Global } from "../global"
 import { Filesystem } from "../util/filesystem"
+import path from "path"
+import os from "os"
 
 import PROMPT_ANTHROPIC from "./prompt/anthropic.txt"
 import PROMPT_ANTHROPIC_SPOOF from "./prompt/anthropic_spoof.txt"
@@ -101,7 +104,17 @@ export namespace SystemPrompt {
       const matches = await Filesystem.findUp(item, cwd, root)
       found.push(...matches.map((x) => Bun.file(x).text()))
     }
-    return Promise.all(found)
+    found.push(
+      Bun.file(path.join(Global.Path.config, "AGENTS.md"))
+        .text()
+        .catch(() => ""),
+    )
+    found.push(
+      Bun.file(path.join(os.homedir(), ".claude", "CLAUDE.md"))
+        .text()
+        .catch(() => ""),
+    )
+    return Promise.all(found).then(Boolean)
   }
 
   export function summarize(providerID: string) {