@galaxy-blackhole/blackhole-harness 0.1.2 → 0.1.4

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.
@@ -110,7 +110,7 @@ import { existsSync as existsSync10, writeFileSync as writeFileSync6 } from "nod
110
110
  import { spawnSync as spawnSync2 } from "node:child_process";
111
111
  import { tmpdir } from "node:os";
112
112
  import { createHash as createHash4 } from "node:crypto";
113
- import { cpSync as cpSync3, existsSync as existsSync7, lstatSync as lstatSync4, mkdirSync as mkdirSync3, mkdtempSync, readFileSync as readFileSync5, readdirSync as readdirSync5, realpathSync as realpathSync2, rmSync as rmSync3, statSync as statSync3, symlinkSync as symlinkSync3, writeFileSync as writeFileSync4 } from "node:fs";
113
+ import { cpSync as cpSync3, existsSync as existsSync7, lstatSync as lstatSync4, mkdirSync as mkdirSync3, mkdtempSync, readFileSync as readFileSync5, readdirSync as readdirSync5, realpathSync as realpathSync2, rmSync as rmSync3, statSync as statSync3, writeFileSync as writeFileSync4 } from "node:fs";
114
114
 
115
115
  // tools/p1b/denta-profile.ts
116
116
  import { createHash } from "node:crypto";
@@ -346,6 +346,7 @@ import { dirname as dirname2, join as join3 } from "node:path";
346
346
  function linkSelfPackages() {
347
347
  const modules = join3(repoRoot(), "node_modules");
348
348
  let added = 0;
349
+ const failed = [];
349
350
  for (const tang of ["host", "client", "tools"]) {
350
351
  const root = join3(repoRoot(), "packages", tang);
351
352
  let names;
@@ -370,18 +371,27 @@ function linkSelfPackages() {
370
371
  continue;
371
372
  try {
372
373
  mkdirSync(dirname2(link), { recursive: true });
373
- symlinkSync(dir, link, "dir");
374
+ symlinkSync(dir, link, process.platform === "win32" ? "junction" : "dir");
374
375
  added += 1;
375
- } catch {
376
- continue;
376
+ } catch (error) {
377
+ failed.push(specifier + " → " + dir + " (" + (error instanceof Error ? error.message : String(error)) + ")");
377
378
  }
378
379
  }
379
380
  }
380
381
  if (added > 0)
381
382
  console.log("[bh] tu link " + String(added) + " goi GBH vao node_modules cua goi (ban npm)");
383
+ if (failed.length > 0) {
384
+ console.error("[bh] KHÔNG tao duoc " + String(failed.length) + " lien ket goi GBH" + (process.platform === "win32" ? " (Windows: bat Developer Mode hoac chay bang quyen Administrator)" : "") + "; 3 cai dau: " + failed.slice(0, 3).join(" · "));
385
+ }
382
386
  return added;
383
387
  }
384
388
 
389
+ // apps/cli/src/link-dir.ts
390
+ import { symlinkSync as symlinkSync2 } from "node:fs";
391
+ function linkDirSync(source, link) {
392
+ symlinkSync2(source, link, process.platform === "win32" ? "junction" : "dir");
393
+ }
394
+
385
395
  // apps/cli/src/mount-gate.ts
386
396
  import { spawnSync } from "node:child_process";
387
397
  import { createHash as createHash2 } from "node:crypto";
@@ -890,7 +900,7 @@ function readPeers(gbh) {
890
900
  }
891
901
 
892
902
  // apps/cli/src/prebuilt.ts
893
- import { cpSync as cpSync2, existsSync as existsSync6, mkdirSync as mkdirSync2, readlinkSync, rmSync as rmSync2, statSync as statSync2, symlinkSync as symlinkSync2 } from "node:fs";
903
+ import { cpSync as cpSync2, existsSync as existsSync6, mkdirSync as mkdirSync2, readlinkSync, rmSync as rmSync2, statSync as statSync2 } from "node:fs";
894
904
  import { dirname as dirname4, join as join6, resolve as resolve2 } from "node:path";
895
905
  function embeddedHost() {
896
906
  return existsSync6(join6(repoRoot(), ".gbh-embedded"));
@@ -920,7 +930,7 @@ function ensureLink(link, target) {
920
930
  }
921
931
  try {
922
932
  mkdirSync2(dirname4(link), { recursive: true });
923
- symlinkSync2(target, link, "dir");
933
+ linkDirSync(target, link);
924
934
  return true;
925
935
  } catch {
926
936
  return false;
@@ -1219,7 +1229,7 @@ function mountRewritePackage(pkg) {
1219
1229
  }
1220
1230
  mkdirSync3(dirname5(link), { recursive: true });
1221
1231
  rmSync3(link, { recursive: true, force: true });
1222
- symlinkSync3(source, link, "dir");
1232
+ linkDirSync(source, link);
1223
1233
  peers.push(peer);
1224
1234
  }
1225
1235
  trace("xong");
@@ -1251,7 +1261,7 @@ function linkInfrastructurePackages() {
1251
1261
  } catch {}
1252
1262
  try {
1253
1263
  mkdirSync3(dirname5(link), { recursive: true });
1254
- symlinkSync3(nguon, link, "dir");
1264
+ linkDirSync(nguon, link);
1255
1265
  linked.push(specifier);
1256
1266
  } catch {
1257
1267
  continue;
@@ -1283,7 +1293,7 @@ function linkNativeAddonPackages() {
1283
1293
  } catch {}
1284
1294
  try {
1285
1295
  mkdirSync3(dirname5(link), { recursive: true });
1286
- symlinkSync3(nguon, link, "dir");
1296
+ linkDirSync(nguon, link);
1287
1297
  linked.push("@deepseek-ai/" + goi);
1288
1298
  } catch {
1289
1299
  continue;
@@ -1455,7 +1465,7 @@ function applyHostAliases(results) {
1455
1465
  try {
1456
1466
  mkdirSync3(dirname5(link), { recursive: true });
1457
1467
  rmSync3(link, { recursive: true, force: true });
1458
- symlinkSync3(result.dir, link, "dir");
1468
+ linkDirSync(result.dir, link);
1459
1469
  applied.push(alias + " -> " + result.specifier);
1460
1470
  } catch (error) {
1461
1471
  console.warn("[bh] khong tao duoc host alias " + alias + " -> " + result.dir + ": " + String(error));
@@ -1564,7 +1574,7 @@ function applyProvenanceAliases() {
1564
1574
  rmSync3(link, { recursive: true, force: true });
1565
1575
  const thuMucKernel = join7(kernelModulesDir2(), stock);
1566
1576
  const nguonAlias = chiCoKhaiKieu(dir) && existsSync7(thuMucKernel) ? thuMucKernel : dich;
1567
- symlinkSync3(realpathSync2(nguonAlias), link, "dir");
1577
+ linkDirSync(realpathSync2(nguonAlias), link);
1568
1578
  applied.push(stock + " -> " + ours);
1569
1579
  } catch {
1570
1580
  continue;
@@ -2154,6 +2164,7 @@ function spawnHost(options) {
2154
2164
  });
2155
2165
  let settled = false;
2156
2166
  let buffer = "";
2167
+ let errBuffer = "";
2157
2168
  const relayTo = (sink) => {
2158
2169
  let pending = "";
2159
2170
  return (chunk) => {
@@ -2189,6 +2200,7 @@ function spawnHost(options) {
2189
2200
  child.stderr?.setEncoding("utf8");
2190
2201
  child.stderr?.on("data", (chunk) => {
2191
2202
  relayErr(chunk);
2203
+ errBuffer = `${errBuffer}${chunk}`.slice(-4096);
2192
2204
  });
2193
2205
  child.once("error", (error) => {
2194
2206
  if (settled)
@@ -2200,7 +2212,11 @@ function spawnHost(options) {
2200
2212
  if (settled)
2201
2213
  return;
2202
2214
  settled = true;
2203
- reject(new Error(`harness exited before printing a URL (code ${String(code)}, signal ${String(signal)})`));
2215
+ const tail = (errBuffer.trim() === "" ? buffer : errBuffer).trim().split(/\r?\n/u).slice(-8).join(`
2216
+ `);
2217
+ reject(new Error(`harness exited before printing a URL (code ${String(code)}, signal ${String(signal)})` + (tail === "" ? "" : `
2218
+ --- 8 dòng cuối của harness ---
2219
+ ${tail}`)));
2204
2220
  });
2205
2221
  });
2206
2222
  return { child, ready, launch };
@@ -205,6 +205,8 @@ export function spawnHost(options: HostOptions): HostProcess {
205
205
  });
206
206
  let settled = false;
207
207
  let buffer = "";
208
+ /** Đuôi stderr của harness con, để báo lỗi thật thay vì chỉ "thoát trước khi in URL". */
209
+ let errBuffer = "";
208
210
  /**
209
211
  * Relay one child stream to one of ours, a complete line at a time, so every line can be
210
212
  * relabelled and a partial line never splits a UTF-8 sequence mid-write.
@@ -248,6 +250,7 @@ export function spawnHost(options: HostOptions): HostProcess {
248
250
  child.stderr?.setEncoding("utf8");
249
251
  child.stderr?.on("data", (chunk: string) => {
250
252
  relayErr(chunk);
253
+ errBuffer = `${errBuffer}${chunk}`.slice(-4096);
251
254
  });
252
255
  child.once("error", (error) => {
253
256
  if (settled) return;
@@ -257,7 +260,15 @@ export function spawnHost(options: HostOptions): HostProcess {
257
260
  child.once("exit", (code, signal) => {
258
261
  if (settled) return;
259
262
  settled = true;
260
- reject(new Error(`harness exited before printing a URL (code ${String(code)}, signal ${String(signal)})`));
263
+ // 13/11/2026 (Lead): kèm 8 dòng cuối của luồng con. Trên Windows người dùng chỉ thấy câu "exited before
264
+ // printing a URL" còn nguyên nhân thật (ERR_MODULE_NOT_FOUND) nằm trong log — không tự đi tìm.
265
+ const tail = (errBuffer.trim() === "" ? buffer : errBuffer).trim().split(/\r?\n/u).slice(-8).join("\n");
266
+ reject(
267
+ new Error(
268
+ `harness exited before printing a URL (code ${String(code)}, signal ${String(signal)})` +
269
+ (tail === "" ? "" : `\n--- 8 dòng cuối của harness ---\n${tail}`),
270
+ ),
271
+ );
261
272
  });
262
273
  });
263
274
  return { child, ready, launch };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * author Bùi Trọng Hiếu
3
+ * email kevinbui210191@gmail.com
4
+ * create date 15/10/2026
5
+ * modify date 16/11/2026
6
+ * desc Tao lien ket THU MUC chay duoc tren moi he: Windows khong cho symlink thu muc neu thieu quyen
7
+ * (EPERM) nhung JUNCTION thi khong can quyen. 16/11/2026: loi Windows that — profile thieu
8
+ * @galaxy-blackhole/gbh-brand, gbh-typert-protocol, gbh-cordis-plugin-timer ⇒ 4 plugin khong
9
+ * activate ⇒ harness khong in URL.
10
+ */
11
+
12
+ import { symlinkSync } from "node:fs";
13
+
14
+ /**
15
+ * 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.
16
+ *
17
+ * @param source - thư mục đích (thật) của liên kết.
18
+ * @param link - đường dẫn liên kết cần tạo.
19
+ * @remarks Windows chỉ tạo được **junction** khi không có quyền Administrator/Developer Mode; symlink
20
+ * thư mục sẽ ném EPERM và trước 16/11/2026 lỗi đó bị `catch {}` nuốt ⇒ profile thiếu gói ⇒ harness chết.
21
+ * @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
+ export function linkDirSync(source: string, link: string): void {
24
+ symlinkSync(source, link, process.platform === "win32" ? "junction" : "dir");
25
+ }
@@ -19,6 +19,7 @@ import { suaIdProfile } from "../../../tools/p1b/denta-profile.ts";
19
19
  import { dirname, join, relative } from "node:path";
20
20
  import { appHome, kernelModulesDir as kernelModulesDirFromPaths, repoRoot } from "./paths.ts";
21
21
  import { linkSelfPackages } from "./self-links.ts";
22
+ import { linkDirSync } from "./link-dir.ts";
22
23
  import { bunOnlyCommand, runMountGate } from "./mount-gate.ts";
23
24
  import { timePhase } from "./boot-timing.ts";
24
25
 
@@ -491,7 +492,7 @@ const trace = process.env.BH_TRACE === "1" ? (step: string): void => { console.l
491
492
  }
492
493
  mkdirSync(dirname(link), { recursive: true });
493
494
  rmSync(link, { recursive: true, force: true });
494
- symlinkSync(source, link, "dir");
495
+ linkDirSync(source, link);
495
496
  peers.push(peer);
496
497
  }
497
498
  // Host alias KHÔNG tạo ở đây: vòng peer của những gói mount SAU sẽ ghi đè cùng đường dẫn
@@ -544,7 +545,7 @@ export function linkInfrastructurePackages(): string[] {
544
545
  }
545
546
  try {
546
547
  mkdirSync(dirname(link), { recursive: true });
547
- symlinkSync(nguon, link, "dir");
548
+ linkDirSync(nguon, link);
548
549
  linked.push(specifier);
549
550
  } catch {
550
551
  continue;
@@ -589,7 +590,7 @@ export function linkNativeAddonPackages(): string[] {
589
590
  }
590
591
  try {
591
592
  mkdirSync(dirname(link), { recursive: true });
592
- symlinkSync(nguon, link, "dir");
593
+ linkDirSync(nguon, link);
593
594
  linked.push("@deepseek-ai/" + goi);
594
595
  } catch {
595
596
  continue;
@@ -825,7 +826,7 @@ export function applyHostAliases(results: readonly MountResult[]): string[] {
825
826
  try {
826
827
  mkdirSync(dirname(link), { recursive: true });
827
828
  rmSync(link, { recursive: true, force: true });
828
- symlinkSync(result.dir, link, "dir");
829
+ linkDirSync(result.dir, link);
829
830
  applied.push(alias + " -> " + result.specifier);
830
831
  } catch (error) {
831
832
  console.warn("[bh] khong tao duoc host alias " + alias + " -> " + result.dir + ": " + String(error));
@@ -963,7 +964,7 @@ export function applyProvenanceAliases(): string[] {
963
964
  // activate"). Khi gói ta CHỈ có khai kiểu mà KERNEL có bản đầy đủ thì alias phải trỏ KERNEL.
964
965
  const thuMucKernel = join(kernelModulesDir(), stock);
965
966
  const nguonAlias = chiCoKhaiKieu(dir) && existsSync(thuMucKernel) ? thuMucKernel : dich;
966
- symlinkSync(realpathSync(nguonAlias), link, 'dir');
967
+ linkDirSync(realpathSync(nguonAlias), link);
967
968
  applied.push(stock + ' -> ' + ours);
968
969
  } catch {
969
970
  continue;
@@ -11,6 +11,7 @@
11
11
 
12
12
  import { cpSync, existsSync, mkdirSync, readlinkSync, rmSync, statSync, symlinkSync } from "node:fs";
13
13
  import { dirname, join, resolve } from "node:path";
14
+ import { linkDirSync } from "./link-dir.ts";
14
15
  import { repoRoot } from "./paths.ts";
15
16
 
16
17
  /**
@@ -69,7 +70,7 @@ export function ensureLink(link: string, target: string): boolean {
69
70
  }
70
71
  try {
71
72
  mkdirSync(dirname(link), { recursive: true });
72
- symlinkSync(target, link, "dir");
73
+ linkDirSync(target, link);
73
74
  return true;
74
75
  } catch {
75
76
  return false;
@@ -26,6 +26,8 @@ import { repoRoot } from "./paths.ts";
26
26
  export function linkSelfPackages(): number {
27
27
  const modules = join(repoRoot(), "node_modules");
28
28
  let added = 0;
29
+ /** Những gói không tạo được liên kết, kèm lý do — in ra thay vì nuốt lỗi. */
30
+ const failed: string[] = [];
29
31
  for (const tang of ["host", "client", "tools"]) {
30
32
  const root = join(repoRoot(), "packages", tang);
31
33
  let names: string[];
@@ -48,13 +50,27 @@ export function linkSelfPackages(): number {
48
50
  if (daCo === true) continue;
49
51
  try {
50
52
  mkdirSync(dirname(link), { recursive: true });
51
- symlinkSync(dir, link, "dir");
53
+ // 13/11/2026 (Lead): Windows KHÔNG cho tạo symlink thư mục nếu không bật Developer Mode / không elevated
54
+ // (EPERM), mà `catch { continue }` cũ nuốt lỗi ⇒ bản cài npm thiếu link ⇒ import chéo
55
+ // @galaxy-blackhole/* nổ ERR_MODULE_NOT_FOUND, harness chết không in URL. Junction thì không cần quyền.
56
+ symlinkSync(dir, link, process.platform === "win32" ? "junction" : "dir");
52
57
  added += 1;
53
- } catch {
54
- continue;
58
+ } catch (error) {
59
+ failed.push(specifier + " → " + dir + " (" + (error instanceof Error ? error.message : String(error)) + ")");
55
60
  }
56
61
  }
57
62
  }
58
63
  if (added > 0) console.log("[bh] tu link " + String(added) + " goi GBH vao node_modules cua goi (ban npm)");
64
+ if (failed.length > 0) {
65
+ // Không im lặng: thiếu link ⇒ import chéo chết, mà triệu chứng lại xuất hiện ở chỗ khác (harness không in URL).
66
+ console.error(
67
+ "[bh] KHÔNG tao duoc " +
68
+ String(failed.length) +
69
+ " lien ket goi GBH" +
70
+ (process.platform === "win32" ? " (Windows: bat Developer Mode hoac chay bang quyen Administrator)" : "") +
71
+ "; 3 cai dau: " +
72
+ failed.slice(0, 3).join(" · "),
73
+ );
74
+ }
59
75
  return added;
60
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galaxy-blackhole/blackhole-harness",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Galaxy Blackhole harness — boot the DSH host with the blackhole profile (lean npm build)",