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,8 +1,12 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { connect } from "node:net";
|
||||
// 沙箱任务表(docs/adr/ADR-005-sandbox.md):只放「外部不可信字节 → 结构化数据」的纯函数。
|
||||
// 子进程加载完本表后撤销全部权限(文件 / 网络 / 环境变量 / 子进程),所以任务里不能有任何 I/O;
|
||||
// 输入输出必须能 JSON 化(二进制用 base64)。新增任务:在这里加一项,调用方用 runSandbox(名字, 输入)。
|
||||
import { parseBangumiBrowser, parseTorrent } from "@umt/adapters";
|
||||
import { decodeSubtitle, detectSubtitleLanguage, subtitleEpisode, subtitleExtOf } from "@umt/domain";
|
||||
import { runtimeReadTextFileSync } from "@umt/runtime";
|
||||
import { buildPreview } from "../modules/file-manager/preview-build.ts";
|
||||
import { PAGE_PARSERS, type PageKind } from "../modules/subtitles/online/parse.ts";
|
||||
import { archiveKindOf, extractArchive, prepareArchives } from "./archives.ts";
|
||||
@@ -96,14 +100,30 @@ function torrentParse(input: { base64: string }) {
|
||||
}
|
||||
|
||||
/** 测试用:按指令卡死 / 吃内存 / 抛错,验证父进程的超时强杀与内存上限 */
|
||||
function selfTest(input: { mode: "ok" | "hang" | "memory" | "throw" | "io" }) {
|
||||
async function selfTest(input: {
|
||||
mode: "ok" | "hang" | "memory" | "throw" | "io" | "async-io" | "write" | "net" | "exec" | "env";
|
||||
}) {
|
||||
if (input.mode === "hang") for (;;) {}
|
||||
if (input.mode === "memory") {
|
||||
const keep: Uint8Array[] = [];
|
||||
for (;;) keep.push(new Uint8Array(16 * 1024 * 1024).fill(1));
|
||||
}
|
||||
if (input.mode === "throw") throw new Error("任务自己抛的错");
|
||||
if (input.mode === "io") return { read: Deno.readTextFileSync("/etc/hostname") };
|
||||
if (input.mode === "env") return { keys: Object.keys(process.env) };
|
||||
if (input.mode === "async-io") return { read: await readFile("/etc/hostname", "utf8") };
|
||||
if (input.mode === "write") return await writeFile("/tmp/umt-sandbox-denied", "denied");
|
||||
if (input.mode === "net") {
|
||||
return await new Promise((resolve, reject) => {
|
||||
const socket = connect({ host: "127.0.0.1", port: 9 });
|
||||
socket.once("error", reject);
|
||||
socket.once("connect", () => {
|
||||
socket.destroy();
|
||||
resolve({ connected: true });
|
||||
});
|
||||
});
|
||||
}
|
||||
if (input.mode === "exec") return { stdout: execFileSync("/bin/echo", ["escaped"], { encoding: "utf8" }) };
|
||||
if (input.mode === "io") return { read: runtimeReadTextFileSync("/etc/hostname") };
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user