refactor(core): migrate to Bun and converge acquisition policies and Agent boundaries
This commit is contained in:
1 parent
3f1c6d02f6
commit
27c0f27434
268 files changed
+7468
-7852
No files matched your search
@@ -1,29 +1,9 @@
|
||||
// 读 /proc 与 /sys 的伪文件。
|
||||
// Deno 2 把这两处当特权路径:不带 --allow-all 时 Deno.readTextFile 一律 NotCapable(--allow-read 及按路径授权都不行)。
|
||||
// 开发 / 测试用 -A 能直接读;编译产物按最小权限运行,只能借 `cat` 子进程读(编译与 start 任务的 --allow-run 已含 cat)。
|
||||
// 第一次遇到 NotCapable 后记住,后续直接走 cat。
|
||||
|
||||
let viaCat = false;
|
||||
|
||||
async function catText(path: string): Promise<string | null> {
|
||||
import { readFile } from "node:fs/promises";
|
||||
/** Linux 资源监控和子进程 RSS;权限不足或进程已退出时返回 null。 */
|
||||
export async function readProcText(path: string): Promise<string | null> {
|
||||
try {
|
||||
const o = await new Deno.Command("cat", { args: [path], stdout: "piped", stderr: "null" }).output();
|
||||
return o.success ? new TextDecoder().decode(o.stdout) : null;
|
||||
return await readFile(path, "utf8");
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** 读不到(不存在、无权限、cat 不可用)返回 null */
|
||||
export async function readProcText(path: string): Promise<string | null> {
|
||||
if (viaCat) return await catText(path);
|
||||
try {
|
||||
return await Deno.readTextFile(path);
|
||||
} catch (e) {
|
||||
if (e instanceof Deno.errors.NotCapable) {
|
||||
viaCat = true;
|
||||
return await catText(path);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user