perf(directory-agents-injector): migrate sync FS to fs.promises

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-04-18 14:10:18 +09:00
parent 9677c7daf3
commit 51f1fc1df3
2 changed files with 12 additions and 8 deletions
@@ -1,4 +1,4 @@
import { existsSync } from "node:fs";
import { constants, promises as fsPromises } from "node:fs";
import { dirname, isAbsolute, join, resolve } from "node:path";
import { AGENTS_FILENAME } from "./constants";
@@ -9,10 +9,10 @@ export function resolveFilePath(rootDirectory: string, path: string): string | n
return resolve(rootDirectory, path);
}
export function findAgentsMdUp(input: {
export async function findAgentsMdUp(input: {
startDir: string;
rootDir: string;
}): string[] {
}): Promise<string[]> {
const found: string[] = [];
let current = input.startDir;
@@ -22,7 +22,11 @@ export function findAgentsMdUp(input: {
const isRootDir = current === input.rootDir;
if (!isRootDir) {
const agentsPath = join(current, AGENTS_FILENAME);
if (existsSync(agentsPath)) {
const exists = await fsPromises
.access(agentsPath, constants.F_OK)
.then(() => true)
.catch(() => false);
if (exists) {
found.push(agentsPath);
}
}
@@ -1,5 +1,5 @@
import type { PluginInput } from "@opencode-ai/plugin";
import { readFileSync } from "node:fs";
import { promises as fsPromises } from "node:fs";
import { dirname } from "node:path";
import type { createDynamicTruncator } from "../../shared/dynamic-truncator";
@@ -31,7 +31,7 @@ export async function processFilePathForAgentsInjection(input: {
const dir = dirname(resolved);
const cache = getSessionCache(input.sessionCaches, input.sessionID);
const agentsPaths = findAgentsMdUp({ startDir: dir, rootDir: input.ctx.directory });
const agentsPaths = await findAgentsMdUp({ startDir: dir, rootDir: input.ctx.directory });
let dirty = false;
for (const agentsPath of agentsPaths) {
@@ -39,7 +39,8 @@ export async function processFilePathForAgentsInjection(input: {
if (cache.has(agentsDir)) continue;
try {
const content = readFileSync(agentsPath, "utf-8");
const content = await fsPromises.readFile(agentsPath, "utf-8");
cache.add(agentsDir);
const { result, truncated } = await input.truncator.truncate(
input.sessionID,
content,
@@ -48,7 +49,6 @@ export async function processFilePathForAgentsInjection(input: {
? `\n\n[Note: Content was truncated to save context window space. For full context, please read the file directly: ${agentsPath}]`
: "";
input.output.output += `\n\n[Directory Context: ${agentsPath}]\n${result}${truncationNotice}`;
cache.add(agentsDir);
dirty = true;
} catch {}
}