@galaxy-blackhole/blackhole-harness 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/apps/cli/lib/main.js
CHANGED
|
@@ -388,8 +388,9 @@ function linkSelfPackages() {
|
|
|
388
388
|
|
|
389
389
|
// apps/cli/src/link-dir.ts
|
|
390
390
|
import { symlinkSync as symlinkSync2 } from "node:fs";
|
|
391
|
+
import { resolve as resolve2 } from "node:path";
|
|
391
392
|
function linkDirSync(source, link) {
|
|
392
|
-
symlinkSync2(source, link, process.platform === "win32" ? "junction" : "dir");
|
|
393
|
+
symlinkSync2(resolve2(source), resolve2(link), process.platform === "win32" ? "junction" : "dir");
|
|
393
394
|
}
|
|
394
395
|
|
|
395
396
|
// apps/cli/src/mount-gate.ts
|
|
@@ -901,7 +902,7 @@ function readPeers(gbh) {
|
|
|
901
902
|
|
|
902
903
|
// apps/cli/src/prebuilt.ts
|
|
903
904
|
import { cpSync as cpSync2, existsSync as existsSync6, mkdirSync as mkdirSync2, readlinkSync, rmSync as rmSync2, statSync as statSync2 } from "node:fs";
|
|
904
|
-
import { dirname as dirname4, join as join6, resolve as
|
|
905
|
+
import { dirname as dirname4, join as join6, resolve as resolve3 } from "node:path";
|
|
905
906
|
function embeddedHost() {
|
|
906
907
|
return existsSync6(join6(repoRoot(), ".gbh-embedded"));
|
|
907
908
|
}
|
|
@@ -921,7 +922,7 @@ function buildRuntimeAvailable() {
|
|
|
921
922
|
function ensureLink(link, target) {
|
|
922
923
|
try {
|
|
923
924
|
const current = readlinkSync(link);
|
|
924
|
-
if (existsSync6(
|
|
925
|
+
if (existsSync6(resolve3(dirname4(link), current)))
|
|
925
926
|
return false;
|
|
926
927
|
rmSync2(link, { force: true });
|
|
927
928
|
} catch {
|
|
@@ -1012,8 +1013,12 @@ function blockedPackages() {
|
|
|
1012
1013
|
const blocked = new Map;
|
|
1013
1014
|
const script = join7(repoRoot(), "tools", "check", "rows.ts");
|
|
1014
1015
|
if (!existsSync7(script)) {
|
|
1015
|
-
|
|
1016
|
-
|
|
1016
|
+
const message = "[bh] thiếu cổng chặn mount: " + script + " — bản đóng gói phải kèm tools/check; đặt GBH_REPO_ROOT về repo hoặc GBH_ALLOW_NO_GATE=1 để bỏ qua có ý thức";
|
|
1017
|
+
if (process.env.GBH_ALLOW_NO_GATE === "1") {
|
|
1018
|
+
console.warn(message + " (đang bỏ qua vì GBH_ALLOW_NO_GATE=1)");
|
|
1019
|
+
return blocked;
|
|
1020
|
+
}
|
|
1021
|
+
throw new Error(message);
|
|
1017
1022
|
}
|
|
1018
1023
|
const gate = timePhase("cong chan mount", () => runMountGate({ script, cwd: repoRoot(), home: appHome() }));
|
|
1019
1024
|
console.log("[bh] cổng chặn mount: " + gate.detail);
|
|
@@ -1304,7 +1309,8 @@ function linkNativeAddonPackages() {
|
|
|
1304
1309
|
return linked;
|
|
1305
1310
|
}
|
|
1306
1311
|
function ensureRewriteMounts() {
|
|
1307
|
-
|
|
1312
|
+
if (!embeddedHost())
|
|
1313
|
+
linkSelfPackages();
|
|
1308
1314
|
const disabled = (process.env.GBH_DISABLE_REWRITES ?? "").trim() !== "";
|
|
1309
1315
|
const blocked = disabled ? new Map : blockedPackages();
|
|
1310
1316
|
const results = rewritePackages().map((pkg) => disabled ? {
|
|
@@ -2178,7 +2184,7 @@ function spawnHost(options) {
|
|
|
2178
2184
|
};
|
|
2179
2185
|
const relayOut = relayTo(process.stdout);
|
|
2180
2186
|
const relayErr = relayTo(process.stderr);
|
|
2181
|
-
const ready = new Promise((
|
|
2187
|
+
const ready = new Promise((resolve4, reject) => {
|
|
2182
2188
|
child.stdout?.setEncoding("utf8");
|
|
2183
2189
|
child.stdout?.on("data", (chunk) => {
|
|
2184
2190
|
relayOut(chunk);
|
|
@@ -2195,7 +2201,7 @@ function spawnHost(options) {
|
|
|
2195
2201
|
try {
|
|
2196
2202
|
writeFileSync6(launch.home + "/" + name, url);
|
|
2197
2203
|
} catch {}
|
|
2198
|
-
|
|
2204
|
+
resolve4(url);
|
|
2199
2205
|
});
|
|
2200
2206
|
child.stderr?.setEncoding("utf8");
|
|
2201
2207
|
child.stderr?.on("data", (chunk) => {
|
|
@@ -2237,7 +2243,7 @@ import { join as join11 } from "node:path";
|
|
|
2237
2243
|
|
|
2238
2244
|
// apps/cli/src/oracle.ts
|
|
2239
2245
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
2240
|
-
import { resolve as
|
|
2246
|
+
import { resolve as resolve4 } from "node:path";
|
|
2241
2247
|
function run(command, args) {
|
|
2242
2248
|
try {
|
|
2243
2249
|
const probe = spawnSync5(command, args, { encoding: "utf8", timeout: 5000 });
|
|
@@ -2247,7 +2253,7 @@ function run(command, args) {
|
|
|
2247
2253
|
}
|
|
2248
2254
|
}
|
|
2249
2255
|
function readRuntimeVersionFromBin(binPath) {
|
|
2250
|
-
return readManifestVersion(
|
|
2256
|
+
return readManifestVersion(resolve4(binPath, "..", "..", "package.json"));
|
|
2251
2257
|
}
|
|
2252
2258
|
function findOracle(port = ORACLE_PORT) {
|
|
2253
2259
|
const listed = run("lsof", ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN", "-t"]);
|
|
@@ -2275,14 +2281,14 @@ import { createServer } from "node:net";
|
|
|
2275
2281
|
function isPortAvailable(port, host = LOOPBACK_HOST) {
|
|
2276
2282
|
if (port === 0)
|
|
2277
2283
|
return Promise.resolve(true);
|
|
2278
|
-
return new Promise((
|
|
2284
|
+
return new Promise((resolve5) => {
|
|
2279
2285
|
const probe = createServer();
|
|
2280
2286
|
probe.once("error", () => {
|
|
2281
2287
|
probe.close();
|
|
2282
|
-
|
|
2288
|
+
resolve5(false);
|
|
2283
2289
|
});
|
|
2284
2290
|
probe.once("listening", () => {
|
|
2285
|
-
probe.close(() =>
|
|
2291
|
+
probe.close(() => resolve5(true));
|
|
2286
2292
|
});
|
|
2287
2293
|
probe.listen(port, host);
|
|
2288
2294
|
});
|
|
@@ -2742,8 +2748,8 @@ async function main(argv) {
|
|
|
2742
2748
|
const onTerminate = () => void host.child.kill("SIGTERM");
|
|
2743
2749
|
process.once("SIGINT", onInterrupt);
|
|
2744
2750
|
process.once("SIGTERM", onTerminate);
|
|
2745
|
-
const code = await new Promise((
|
|
2746
|
-
host.child.once("exit", (exitCode) =>
|
|
2751
|
+
const code = await new Promise((resolve5) => {
|
|
2752
|
+
host.child.once("exit", (exitCode) => resolve5(exitCode ?? EXIT.error));
|
|
2747
2753
|
});
|
|
2748
2754
|
process.off("SIGINT", onInterrupt);
|
|
2749
2755
|
process.off("SIGTERM", onTerminate);
|
package/apps/cli/src/link-dir.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { symlinkSync } from "node:fs";
|
|
13
|
+
import { resolve } from "node:path";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Tao lien ket thư mục từ `source` tới `link`, chọn kiểu phù hợp với hệ điều hành.
|
|
@@ -21,5 +22,9 @@ import { symlinkSync } from "node:fs";
|
|
|
21
22
|
* @throws khi không tạo được liên kết (để nơi gọi báo rõ, không im lặng).
|
|
22
23
|
*/
|
|
23
24
|
export function linkDirSync(source: string, link: string): void {
|
|
24
|
-
|
|
25
|
+
// 16/11/2026 (Lead): junction của Windows LƯU ĐƯỜNG DẪN TUYỆT ĐỐI trong đích, nên nếu `source` là
|
|
26
|
+
// đường dẫn tương đối thì junction tạo ra trỏ về chính nó ⇒ ESM báo
|
|
27
|
+
// "Cannot find module '<link>' imported from '<link>'" (đúng lỗi Windows 16/11/2026, 183 plugin
|
|
28
|
+
// không activate). resolve() cả hai đầu để junction luôn tuyệt đối, trên POSIX thì vô hại.
|
|
29
|
+
symlinkSync(resolve(source), resolve(link), process.platform === "win32" ? "junction" : "dir");
|
|
25
30
|
}
|
package/apps/cli/src/mount.ts
CHANGED
|
@@ -170,11 +170,16 @@ export function parseRowVerdicts(output: string): RowVerdict[] {
|
|
|
170
170
|
function blockedPackages(): Map<string, string> {
|
|
171
171
|
const blocked = new Map<string, string>();
|
|
172
172
|
const script = join(repoRoot(), 'tools', 'check', 'rows.ts');
|
|
173
|
-
//
|
|
174
|
-
//
|
|
173
|
+
// 19/11/2026 — FAIL-CLOSED: bản đóng gói phải kèm cổng chặn mount. Trước đây thiếu `tools/check` thì
|
|
174
|
+
// in cảnh báo rồi mount tiếp — nghĩa là bản người dùng chạy không có 12 luật kiểm. Nay mặc định DỪNG;
|
|
175
|
+
// chỉ bỏ qua khi người vận hành đặt GBH_ALLOW_NO_GATE=1 (có ý thức, để debug).
|
|
175
176
|
if (!existsSync(script)) {
|
|
176
|
-
|
|
177
|
-
|
|
177
|
+
const message = '[bh] thiếu cổng chặn mount: ' + script + ' — bản đóng gói phải kèm tools/check; đặt GBH_REPO_ROOT về repo hoặc GBH_ALLOW_NO_GATE=1 để bỏ qua có ý thức';
|
|
178
|
+
if (process.env.GBH_ALLOW_NO_GATE === '1') {
|
|
179
|
+
console.warn(message + ' (đang bỏ qua vì GBH_ALLOW_NO_GATE=1)');
|
|
180
|
+
return blocked;
|
|
181
|
+
}
|
|
182
|
+
throw new Error(message);
|
|
178
183
|
}
|
|
179
184
|
// 12/11/2026 — LOI TINH DUNG: `process.execPath run <script>` chi dung khi tien trinh la Bun. App desktop
|
|
180
185
|
// chay launcher bang Node ⇒ lenh vo nghia, tien trinh con chet ngay, output rong ⇒ cong chan mount IM LANG
|
|
@@ -607,7 +612,10 @@ export function linkNativeAddonPackages(): string[] {
|
|
|
607
612
|
*/
|
|
608
613
|
export function ensureRewriteMounts(): MountResult[] {
|
|
609
614
|
// 12/11/2026 — chay TRUOC moi buoc mount: import cheo giua cac goi GBH phai phan giai duoc tu cay goi.
|
|
610
|
-
linkSelfPackages()
|
|
615
|
+
// 19/11/2026 — KHÔNG làm việc này với host NHÚNG: `linkSelfPackages()` ghi symlink vào
|
|
616
|
+
// `repoRoot()/node_modules` (trong .app là `Resources/host/apps/host/node_modules`) ⇒ mỗi lượt boot
|
|
617
|
+
// sửa bundle SAU khi ký ⇒ `codesign --verify` báo "file added". Bản nhúng đã có node_modules đi kèm.
|
|
618
|
+
if (!embeddedHost()) linkSelfPackages();
|
|
611
619
|
const disabled = (process.env.GBH_DISABLE_REWRITES ?? "").trim() !== "";
|
|
612
620
|
// 12/11/2026: che do TAT (A/B) khong mount gi ⇒ khong can chay cong chan mount (tiet kiem ~2,6 s).
|
|
613
621
|
const blocked = disabled ? new Map<string, string>() : blockedPackages();
|
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
1
2
|
import { readFile } from "node:fs/promises";
|
|
2
3
|
import { createServer } from "node:http";
|
|
3
4
|
import { createServer as createServer$1 } from "node:https";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
4
6
|
import { isIP } from "node:net";
|
|
5
|
-
import { resolve } from "node:path";
|
|
7
|
+
import { dirname, extname, join, resolve } from "node:path";
|
|
6
8
|
import { Service } from "@deepseek-ai/cordis";
|
|
7
9
|
import z from "@deepseek-ai/schemastery";
|
|
8
10
|
import compressionMiddleware from "compression";
|
|
@@ -379,6 +381,38 @@ var WebServer = class extends Service {
|
|
|
379
381
|
/* v8 ignore next -- `?? '/'` arm: node:http always sets url on server
|
|
380
382
|
requests; the field is only optional on the client-side IncomingMessage type */
|
|
381
383
|
const rawPath = new URL(req.url ?? "/", "http://x").pathname;
|
|
384
|
+
// GBH_STATIC_FALLBACK: bản npm/Windows có thể không mount web-app fallback; phục vụ UI
|
|
385
|
+
// trực tiếp trước route "/" để tránh 404, chỉ khi có cookie dsh-auth (API auth giữ nguyên).
|
|
386
|
+
if (req.method === "GET" || req.method === "HEAD") {
|
|
387
|
+
try {
|
|
388
|
+
const parsed = new URL(req.url ?? "/", "http://x");
|
|
389
|
+
const pathname = decodeURIComponent(parsed.pathname);
|
|
390
|
+
const isUi = pathname === "/" || pathname.startsWith("/assets/") || /^\/(favicon|manifest|icon)/u.test(pathname);
|
|
391
|
+
const hasAuthCookie = String(req.headers.cookie ?? "").includes("dsh-auth-");
|
|
392
|
+
if (isUi && hasAuthCookie && !parsed.searchParams.has("token")) {
|
|
393
|
+
const require = createRequire(import.meta.url);
|
|
394
|
+
const candidates = [];
|
|
395
|
+
if (process.env.GBH_FRONTEND_DIST) candidates.push(process.env.GBH_FRONTEND_DIST);
|
|
396
|
+
candidates.push(join(process.cwd(), "node_modules", "@deepseek-ai", "dsh-web-frontend", "dist"));
|
|
397
|
+
try { candidates.push(join(dirname(require.resolve("@deepseek-ai/dsh-web-frontend/package.json")), "dist")); } catch {}
|
|
398
|
+
const dist = candidates.find((candidate) => existsSync(join(candidate, "index.html")));
|
|
399
|
+
if (dist !== void 0) {
|
|
400
|
+
const rel = pathname === "/" ? "index.html" : pathname.replace(/^\//u, "");
|
|
401
|
+
const target = join(dist, rel);
|
|
402
|
+
if (target.startsWith(dist) && existsSync(target)) {
|
|
403
|
+
const MIME = { ".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".css": "text/css; charset=utf-8", ".svg": "image/svg+xml", ".webmanifest": "application/manifest+json", ".json": "application/json" };
|
|
404
|
+
let body = readFileSync(target);
|
|
405
|
+
if (rel === "index.html" && typeof this.renderIndex === "function") body = this.renderIndex(body.toString("utf8"));
|
|
406
|
+
res.writeHead(200, { "content-type": MIME[extname(target)] ?? "application/octet-stream" });
|
|
407
|
+
res.end(body);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
} catch (error) {
|
|
413
|
+
this.ctx.logger.warn(error instanceof Error ? error : new Error(String(error)));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
382
416
|
const route = this.match(rawPath);
|
|
383
417
|
if (route !== void 0) {
|
|
384
418
|
await route.handler(req, res);
|