perf(directory-readme-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:
@@ -1,4 +1,4 @@
|
|||||||
import { existsSync } from "node:fs";
|
import { access } from "node:fs/promises";
|
||||||
import { dirname, isAbsolute, join, resolve } from "node:path";
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
||||||
|
|
||||||
import { README_FILENAME } from "./constants";
|
import { README_FILENAME } from "./constants";
|
||||||
@@ -9,17 +9,19 @@ export function resolveFilePath(rootDirectory: string, path: string): string | n
|
|||||||
return resolve(rootDirectory, path);
|
return resolve(rootDirectory, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function findReadmeMdUp(input: {
|
export async function findReadmeMdUp(input: {
|
||||||
startDir: string;
|
startDir: string;
|
||||||
rootDir: string;
|
rootDir: string;
|
||||||
}): string[] {
|
}): Promise<string[]> {
|
||||||
const found: string[] = [];
|
const found: string[] = [];
|
||||||
let current = input.startDir;
|
let current = input.startDir;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const readmePath = join(current, README_FILENAME);
|
const readmePath = join(current, README_FILENAME);
|
||||||
if (existsSync(readmePath)) {
|
try {
|
||||||
|
await access(readmePath);
|
||||||
found.push(readmePath);
|
found.push(readmePath);
|
||||||
|
} catch {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current === input.rootDir) break;
|
if (current === input.rootDir) break;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { PluginInput } from "@opencode-ai/plugin";
|
import type { PluginInput } from "@opencode-ai/plugin";
|
||||||
import { readFileSync } from "node:fs";
|
import { readFile } from "node:fs/promises";
|
||||||
import { dirname } from "node:path";
|
import { dirname } from "node:path";
|
||||||
|
|
||||||
import type { createDynamicTruncator } from "../../shared/dynamic-truncator";
|
import type { createDynamicTruncator } from "../../shared/dynamic-truncator";
|
||||||
@@ -31,7 +31,7 @@ export async function processFilePathForReadmeInjection(input: {
|
|||||||
|
|
||||||
const dir = dirname(resolved);
|
const dir = dirname(resolved);
|
||||||
const cache = getSessionCache(input.sessionCaches, input.sessionID);
|
const cache = getSessionCache(input.sessionCaches, input.sessionID);
|
||||||
const readmePaths = findReadmeMdUp({ startDir: dir, rootDir: input.ctx.directory });
|
const readmePaths = await findReadmeMdUp({ startDir: dir, rootDir: input.ctx.directory });
|
||||||
|
|
||||||
let dirty = false;
|
let dirty = false;
|
||||||
for (const readmePath of readmePaths) {
|
for (const readmePath of readmePaths) {
|
||||||
@@ -39,7 +39,7 @@ export async function processFilePathForReadmeInjection(input: {
|
|||||||
if (cache.has(readmeDir)) continue;
|
if (cache.has(readmeDir)) continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const content = readFileSync(readmePath, "utf-8");
|
const content = await readFile(readmePath, "utf-8");
|
||||||
const { result, truncated } = await input.truncator.truncate(
|
const { result, truncated } = await input.truncator.truncate(
|
||||||
input.sessionID,
|
input.sessionID,
|
||||||
content,
|
content,
|
||||||
|
|||||||
Reference in New Issue
Block a user