fix: config loading not considering symlinks (#2800)

This commit is contained in:
Yihui Khuu
2025-09-27 00:46:49 +10:00
committed by GitHub
parent 39917a35ce
commit 7ecdc1b5d8

View File

@@ -120,7 +120,13 @@ export namespace Config {
async function assertValid(dir: string) {
const ALLOWED_DIRS = new Set(["agent", "command", "mode", "plugin", "tool", "themes"])
const UNEXPECTED_DIR_GLOB = new Bun.Glob("*/")
for await (const item of UNEXPECTED_DIR_GLOB.scan({ absolute: true, cwd: dir, onlyFiles: false })) {
for await (const item of UNEXPECTED_DIR_GLOB.scan({
absolute: true,
followSymlinks: true,
dot: true,
cwd: dir,
onlyFiles: false,
})) {
const dirname = path.basename(item)
if (!ALLOWED_DIRS.has(dirname)) {
throw new InvalidError({
@@ -134,7 +140,7 @@ export namespace Config {
const COMMAND_GLOB = new Bun.Glob("command/**/*.md")
async function loadCommand(dir: string) {
const result: Record<string, Command> = {}
for await (const item of COMMAND_GLOB.scan({ absolute: true, cwd: dir })) {
for await (const item of COMMAND_GLOB.scan({ absolute: true, followSymlinks: true, dot: true, cwd: dir })) {
const content = await Bun.file(item).text()
const md = matter(content)
if (!md.data) continue
@@ -169,7 +175,7 @@ export namespace Config {
async function loadAgent(dir: string) {
const result: Record<string, Agent> = {}
for await (const item of AGENT_GLOB.scan({ absolute: true, cwd: dir })) {
for await (const item of AGENT_GLOB.scan({ absolute: true, followSymlinks: true, dot: true, cwd: dir })) {
const content = await Bun.file(item).text()
const md = matter(content)
if (!md.data) continue
@@ -207,7 +213,7 @@ export namespace Config {
const MODE_GLOB = new Bun.Glob("mode/*.md")
async function loadMode(dir: string) {
const result: Record<string, Agent> = {}
for await (const item of MODE_GLOB.scan({ absolute: true, cwd: dir })) {
for await (const item of MODE_GLOB.scan({ absolute: true, followSymlinks: true, dot: true, cwd: dir })) {
const content = await Bun.file(item).text()
const md = matter(content)
if (!md.data) continue
@@ -233,7 +239,7 @@ export namespace Config {
async function loadPlugin(dir: string) {
const plugins: string[] = []
for await (const item of PLUGIN_GLOB.scan({ absolute: true, cwd: dir })) {
for await (const item of PLUGIN_GLOB.scan({ absolute: true, followSymlinks: true, dot: true, cwd: dir })) {
plugins.push("file://" + item)
}
return plugins