fix: Node 20 兼容,去掉 fs.globSync

This commit is contained in:
czm
2026-09-14 09:34:32 +08:00
parent 9c90759aec
commit 2aef219faf
+16 -3
View File
@@ -2,8 +2,21 @@
* Shared structural source of truth for the Agent Note tree.
* Portable: resolves .agents/notes from cwd (or AGENT_NOTE_ROOT env).
*/
import { globSync, readdirSync, existsSync } from 'node:fs'
import { resolve, sep } from 'node:path'
import { readdirSync, existsSync } from 'node:fs'
import { resolve } from 'node:path'
/** Recurse `dir` and return posix-relative `.md` paths prefixed with `prefix`. Node 18 compatible (no fs.globSync). */
function listMd(dir: string, prefix: string): string[] {
if (!existsSync(dir)) return []
const out: string[] = []
for (const entry of readdirSync(dir, { withFileTypes: true })) {
if (entry.name.startsWith('.')) continue
const rel = prefix ? `${prefix}/${entry.name}` : entry.name
if (entry.isDirectory()) out.push(...listMd(resolve(dir, entry.name), rel))
else if (entry.isFile() && entry.name.endsWith('.md')) out.push(rel)
}
return out
}
function resolveAgentNoteRoot(): string {
if (process.env.AGENT_NOTE_ROOT) return resolve(process.env.AGENT_NOTE_ROOT)
@@ -37,7 +50,7 @@ export function walkAgentNoteTree(): { notes: AgentNote[]; errors: string[] } {
}
}
for (const lifecycle of AGENT_NOTE_LIFECYCLES) {
for (const match of globSync(`${lifecycle}/**/*.md`, { cwd: agentNoteRoot }).map(p => p.split(sep).join('/')).sort()) {
for (const match of listMd(resolve(agentNoteRoot, lifecycle), lifecycle).sort()) {
const segs = match.split('/')
if (segs.length === 2 && ROOT_ALLOWLIST.has(segs[1] ?? '')) continue
if (match.endsWith('.zh.md')) continue