mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-31 22:32:28 +00:00
Refactor app context system to use Zod schemas and sync access pattern
🤖 Generated with opencode Co-Authored-By: opencode <noreply@opencode.ai>
This commit is contained in:
29
packages/opencode/src/session/context.ts
Normal file
29
packages/opencode/src/session/context.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { App } from "../app/app"
|
||||
import path from "path"
|
||||
|
||||
export namespace SessionContext {
|
||||
const FILES = [
|
||||
"AGENTS.md",
|
||||
"CLAUDE.md",
|
||||
"CONTEXT.md", // deprecated
|
||||
]
|
||||
export async function find() {
|
||||
const { cwd, root } = App.info().path
|
||||
let current = cwd
|
||||
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
|
||||
}
|
||||
return Promise.all(found).then((parts) => parts.join("\n\n"))
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import { Share } from "../share/share"
|
||||
import { Message } from "./message"
|
||||
import { Bus } from "../bus"
|
||||
import { Provider } from "../provider/provider"
|
||||
import { SessionContext } from "./context"
|
||||
|
||||
export namespace Session {
|
||||
const log = Log.create({ service: "session" })
|
||||
@@ -201,7 +202,6 @@ export namespace Session {
|
||||
(msg) => msg.role === "system" || msg.id >= lastSummary.id,
|
||||
)
|
||||
|
||||
const app = await App.use()
|
||||
if (msgs.length === 0) {
|
||||
const system: Message.Info = {
|
||||
id: Identifier.ascending("message"),
|
||||
@@ -220,9 +220,8 @@ export namespace Session {
|
||||
tool: {},
|
||||
},
|
||||
}
|
||||
const contextFile = Bun.file(path.join(app.path.root, "CONTEXT.md"))
|
||||
if (await contextFile.exists()) {
|
||||
const context = await contextFile.text()
|
||||
const context = await SessionContext.find()
|
||||
if (context) {
|
||||
system.parts.push({
|
||||
type: "text",
|
||||
text: context,
|
||||
|
||||
Reference in New Issue
Block a user