mirror of
https://github.com/sst/opencode.git
synced 2025-08-04 05:28:16 +00:00
feat: configurable instructions (#624)
This commit is contained in:
parent
67aa7ce04d
commit
b99565959b
4 changed files with 50 additions and 0 deletions
|
@ -297,6 +297,13 @@
|
||||||
},
|
},
|
||||||
"description": "MCP (Model Context Protocol) server configurations"
|
"description": "MCP (Model Context Protocol) server configurations"
|
||||||
},
|
},
|
||||||
|
"instructions": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"description": "Additional instruction files or patterns to include"
|
||||||
|
},
|
||||||
"experimental": {
|
"experimental": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
|
@ -176,6 +176,10 @@ export namespace Config {
|
||||||
.record(z.string(), Mcp)
|
.record(z.string(), Mcp)
|
||||||
.optional()
|
.optional()
|
||||||
.describe("MCP (Model Context Protocol) server configurations"),
|
.describe("MCP (Model Context Protocol) server configurations"),
|
||||||
|
instructions: z
|
||||||
|
.array(z.string())
|
||||||
|
.optional()
|
||||||
|
.describe("Additional instruction files or patterns to include"),
|
||||||
experimental: z
|
experimental: z
|
||||||
.object({
|
.object({
|
||||||
hook: z
|
hook: z
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { App } from "../app/app"
|
||||||
import { Ripgrep } from "../file/ripgrep"
|
import { Ripgrep } from "../file/ripgrep"
|
||||||
import { Global } from "../global"
|
import { Global } from "../global"
|
||||||
import { Filesystem } from "../util/filesystem"
|
import { Filesystem } from "../util/filesystem"
|
||||||
|
import { Config } from "../config/config"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import os from "os"
|
import os from "os"
|
||||||
|
|
||||||
|
@ -55,8 +56,10 @@ export namespace SystemPrompt {
|
||||||
"CLAUDE.md",
|
"CLAUDE.md",
|
||||||
"CONTEXT.md", // deprecated
|
"CONTEXT.md", // deprecated
|
||||||
]
|
]
|
||||||
|
|
||||||
export async function custom() {
|
export async function custom() {
|
||||||
const { cwd, root } = App.info().path
|
const { cwd, root } = App.info().path
|
||||||
|
const config = await Config.get()
|
||||||
const found = []
|
const found = []
|
||||||
for (const item of CUSTOM_FILES) {
|
for (const item of CUSTOM_FILES) {
|
||||||
const matches = await Filesystem.findUp(item, cwd, root)
|
const matches = await Filesystem.findUp(item, cwd, root)
|
||||||
|
@ -72,6 +75,18 @@ export namespace SystemPrompt {
|
||||||
.text()
|
.text()
|
||||||
.catch(() => ""),
|
.catch(() => ""),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (config.instructions) {
|
||||||
|
for (const instruction of config.instructions) {
|
||||||
|
try {
|
||||||
|
const matches = await Filesystem.globUp(instruction, cwd, root)
|
||||||
|
found.push(...matches.map((x) => Bun.file(x).text()))
|
||||||
|
} catch {
|
||||||
|
continue // Skip invalid glob patterns
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.all(found).then((result) => result.filter(Boolean))
|
return Promise.all(found).then((result) => result.filter(Boolean))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,4 +15,28 @@ export namespace Filesystem {
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function globUp(pattern: string, start: string, stop?: string) {
|
||||||
|
let current = start
|
||||||
|
const result = []
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
const glob = new Bun.Glob(pattern)
|
||||||
|
for await (const match of glob.scan({
|
||||||
|
cwd: current,
|
||||||
|
onlyFiles: true,
|
||||||
|
dot: true,
|
||||||
|
})) {
|
||||||
|
result.push(join(current, match))
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Skip invalid glob patterns
|
||||||
|
}
|
||||||
|
if (stop === current) break
|
||||||
|
const parent = dirname(current)
|
||||||
|
if (parent === current) break
|
||||||
|
current = parent
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue