@napuketto/kernel 0.18.0 → 0.18.1

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.
Files changed (2) hide show
  1. package/dist/index.mjs +42 -25
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
- import { appendFileSync, chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
2
+ import { appendFileSync, chmodSync, constants, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
3
3
  import { open, readFile, rename, rm, stat } from "node:fs/promises";
4
4
  import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
5
- import process from "node:process";
5
+ import process$1 from "node:process";
6
6
  import { parse, stringify } from "smol-toml";
7
7
  import pino from "pino";
8
8
  import { homedir, hostname, platform, release, type, version } from "node:os";
@@ -276,7 +276,7 @@ var ConfigBase = class {
276
276
  const file = await open(tmpPath, "wx", 384);
277
277
  try {
278
278
  try {
279
- if (process.platform !== "win32") await file.chmod(384);
279
+ if (process$1.platform !== "win32") await file.chmod(384);
280
280
  await file.writeFile(text, "utf8");
281
281
  } finally {
282
282
  await file.close();
@@ -712,7 +712,7 @@ function renderPrettyLine(record, ctx) {
712
712
  }
713
713
  /** 创建控制台渲染流(pretty / single-line / json)。 */
714
714
  function createConsoleFormatStream(opts) {
715
- const out = opts.destination ?? process.stdout;
715
+ const out = opts.destination ?? process$1.stdout;
716
716
  const ctx = {
717
717
  timestamp: opts.timestamp,
718
718
  timeOriginMs: performance.timeOrigin,
@@ -824,7 +824,7 @@ const DEFAULT_DATA_ROOT_NAME = ".napuketto";
824
824
  const MAIN_CONFIG_FILE = "napuketto.toml";
825
825
  /** Check an actual write destination when the development launcher has set a boundary. */
826
826
  function resolveSandboxWritePath(path, field) {
827
- const sandbox = process.env["NAPUKETTO_SANDBOX_ROOT"];
827
+ const sandbox = process$1.env["NAPUKETTO_SANDBOX_ROOT"];
828
828
  if (!sandbox) return path;
829
829
  const target = resolve(path);
830
830
  if (!isPathWithin(sandbox, target)) throw configError(`${field} 必须位于调试沙箱内: ${target}`);
@@ -850,7 +850,7 @@ function expandTilde(p) {
850
850
  function resolveProjectRoot() {
851
851
  const moduleRoot = findProjectRoot(dirname(fileURLToPath(import.meta.url)), "pnpm-workspace.yaml");
852
852
  if (moduleRoot !== void 0) return moduleRoot;
853
- return findProjectRoot(process.cwd(), "pnpm-workspace.yaml") ?? findProjectRoot(process.cwd(), "package.json");
853
+ return findProjectRoot(process$1.cwd(), "pnpm-workspace.yaml") ?? findProjectRoot(process$1.cwd(), "package.json");
854
854
  }
855
855
  /**
856
856
  * 解析数据根:显式参数 > 环境变量 > `<项目根>/.napuketto`(默认)> 用户目录兜底(裸脚本)。
@@ -858,9 +858,9 @@ function resolveProjectRoot() {
858
858
  * 返回绝对路径。独立导出便于 cli / 探测脚本复用。
859
859
  */
860
860
  function resolveDataRoot(dataRoot) {
861
- const explicit = dataRoot ?? process.env["NAPUKETTO_DATA"] ?? process.env["NAPKETTO_DATA"];
861
+ const explicit = dataRoot ?? process$1.env["NAPUKETTO_DATA"] ?? process$1.env["NAPKETTO_DATA"];
862
862
  if (explicit !== void 0 && explicit !== "") return resolveSandboxWritePath(resolve(expandTilde(explicit)), "数据目录");
863
- const sandbox = process.env["NAPUKETTO_SANDBOX_ROOT"];
863
+ const sandbox = process$1.env["NAPUKETTO_SANDBOX_ROOT"];
864
864
  if (sandbox) return resolveSandboxWritePath(join(sandbox, DEFAULT_DATA_ROOT_NAME), "数据目录");
865
865
  const projectRoot = resolveProjectRoot();
866
866
  if (projectRoot !== void 0) return join(projectRoot, DEFAULT_DATA_ROOT_NAME);
@@ -888,9 +888,9 @@ function findProjectRoot(startDir, marker) {
888
888
  * 返回绝对路径。独立导出便于 cli / loader 装配链复用。
889
889
  */
890
890
  function resolveConfigPath(opts = {}) {
891
- const explicit = process.env["NAPUKETTO_CONFIG"] ?? process.env["NAPKETTO_CONFIG"];
891
+ const explicit = process$1.env["NAPUKETTO_CONFIG"] ?? process$1.env["NAPKETTO_CONFIG"];
892
892
  if (explicit !== void 0 && explicit !== "") return resolveSandboxWritePath(resolve(explicit), "配置文件");
893
- const sandbox = process.env["NAPUKETTO_SANDBOX_ROOT"];
893
+ const sandbox = process$1.env["NAPUKETTO_SANDBOX_ROOT"];
894
894
  if (sandbox) return resolveSandboxWritePath(join(sandbox, MAIN_CONFIG_FILE), "配置文件");
895
895
  const projectRoot = resolveProjectRoot();
896
896
  if (projectRoot !== void 0) return join(projectRoot, MAIN_CONFIG_FILE);
@@ -1029,7 +1029,7 @@ function mergeTargets(targets) {
1029
1029
  */
1030
1030
  function createLogger(opts = {}) {
1031
1031
  const consoleLevel = opts.level ?? "info";
1032
- const destination = opts.destination ?? process.stdout;
1032
+ const destination = opts.destination ?? process$1.stdout;
1033
1033
  const isTty = destination.isTTY === true;
1034
1034
  const format = opts.format ?? (isTty ? "pretty" : "single-line");
1035
1035
  const targets = [buildConsoleTarget(opts, {
@@ -1045,7 +1045,7 @@ function createLogger(opts = {}) {
1045
1045
  hooks: { streamWrite: redactLogLine },
1046
1046
  timestamp: () => `,"time":${wallMs()}`,
1047
1047
  ...opts.base === void 0 ? {} : { base: {
1048
- pid: process.pid,
1048
+ pid: process$1.pid,
1049
1049
  ...opts.base
1050
1050
  } }
1051
1051
  };
@@ -2534,8 +2534,25 @@ async function statFile(path, label = "图片") {
2534
2534
  /** 计算文件 md5(十六进制小写)。 */
2535
2535
  async function hashFile(path, label = "图片") {
2536
2536
  try {
2537
- const buf = await readFile(path);
2538
- return createHash("md5").update(buf).digest("hex");
2537
+ const flags = constants.O_RDONLY | (process.platform === "win32" ? 0 : constants.O_NONBLOCK);
2538
+ const handle = await open(path, flags);
2539
+ try {
2540
+ const info = await handle.stat();
2541
+ if (!info.isFile()) throw new Error("摘要输入必须是普通文件");
2542
+ const hash = createHash("md5");
2543
+ const chunk = Buffer.alloc(65536);
2544
+ let remaining = info.size;
2545
+ while (remaining > 0) {
2546
+ const { bytesRead } = await handle.read(chunk, 0, Math.min(remaining, chunk.length));
2547
+ if (bytesRead === 0) throw new Error("摘要读取期间文件缩短");
2548
+ hash.update(chunk.subarray(0, bytesRead));
2549
+ remaining -= bytesRead;
2550
+ }
2551
+ if ((await handle.read(chunk, 0, 1)).bytesRead !== 0) throw new Error("摘要读取期间文件增长");
2552
+ return hash.digest("hex");
2553
+ } finally {
2554
+ await handle.close();
2555
+ }
2539
2556
  } catch {
2540
2557
  throw kernelError(`${label}文件读取失败: ${path}`, "INVALID_PARAM");
2541
2558
  }
@@ -5615,7 +5632,7 @@ function getElectronProcessType(proc) {
5615
5632
  function defaultEngineConfig(env, qqDataPath) {
5616
5633
  const platform = detectPlatformType();
5617
5634
  const fullVersion = env.qqVersion ?? "";
5618
- const wrapperPath = env.wrapperPath ?? process.env["NAPUKETTO_WRAPPER_PATH"] ?? process.env["NAPUTO_WRAPPER_PATH"] ?? "";
5635
+ const wrapperPath = env.wrapperPath ?? process$1.env["NAPUKETTO_WRAPPER_PATH"] ?? process$1.env["NAPUTO_WRAPPER_PATH"] ?? "";
5619
5636
  const majorPath = wrapperPath !== "" ? join(dirname(wrapperPath), "major.node") : "";
5620
5637
  const qua = (majorPath !== "" ? parseQuaFromMajor(majorPath) : null) ?? (fullVersion !== "" ? buildQua(fullVersion, platform) : "");
5621
5638
  return {
@@ -5623,7 +5640,7 @@ function defaultEngineConfig(env, qqDataPath) {
5623
5640
  platform_type: platform,
5624
5641
  app_type: 4,
5625
5642
  app_version: fullVersion,
5626
- os_version: version() || process.platform,
5643
+ os_version: version() || process$1.platform,
5627
5644
  use_xlog: platform !== PlatformType.KWINDOWS,
5628
5645
  qua,
5629
5646
  global_path_config: { desktopGlobalPath: qqDataPath ?? env.dataDir ?? "" },
@@ -5641,7 +5658,7 @@ function defaultEngineConfig(env, qqDataPath) {
5641
5658
  * - "utility":utilityProcess Worker(路线 B,2026-08-06)
5642
5659
  */
5643
5660
  function electronProcessType() {
5644
- return getElectronProcessType(process);
5661
+ return getElectronProcessType(process$1);
5645
5662
  }
5646
5663
  /**
5647
5664
  * 解析 QQ 用户数据根(登录数据目录,如 `C:\Users\<user>\Documents\Tencent Files`)。
@@ -5659,13 +5676,13 @@ function electronProcessType() {
5659
5676
  * 其余 Windows 场景走官方 API + 默认位置兜底。
5660
5677
  */
5661
5678
  function resolveQqUserDataRoot(exports, opts = {}) {
5662
- if (process.env["NAPUKETTO_SANDBOX_ROOT"]) {
5663
- const dataRoot = resolveDataRoot(opts.dataRoot || process.env["NAPUKETTO_DATA_ROOT"] || process.env["NAPUTO_DATA_ROOT"]);
5679
+ if (process$1.env["NAPUKETTO_SANDBOX_ROOT"]) {
5680
+ const dataRoot = resolveDataRoot(opts.dataRoot || process$1.env["NAPUKETTO_DATA_ROOT"] || process$1.env["NAPUTO_DATA_ROOT"]);
5664
5681
  resolveSandboxWritePath(resolveQqGlobalPath(dataRoot), "QQ 数据目录");
5665
5682
  return dataRoot;
5666
5683
  }
5667
5684
  if ((opts.platform ?? detectPlatformType()) === PlatformType.KLINUX) {
5668
- const dataRoot = opts.dataRoot ?? process.env["NAPUKETTO_DATA_ROOT"] ?? process.env["NAPUTO_DATA_ROOT"] ?? process.env["NAPUKETTO_DATA"] ?? process.env["NAPKETTO_DATA"] ?? "";
5685
+ const dataRoot = opts.dataRoot ?? process$1.env["NAPUKETTO_DATA_ROOT"] ?? process$1.env["NAPUTO_DATA_ROOT"] ?? process$1.env["NAPUKETTO_DATA"] ?? process$1.env["NAPKETTO_DATA"] ?? "";
5669
5686
  if (dataRoot !== "") return dataRoot;
5670
5687
  }
5671
5688
  return extractUserDataRoot(exports) ?? join(homedir(), "Documents", "Tencent Files");
@@ -5810,7 +5827,7 @@ function startNapuketto(options) {
5810
5827
  prepareSession(ctx, hasCapturedSession, isSelfHost);
5811
5828
  initEngine(ctx, resolveEngineConfig(ctx, env, engineConfig));
5812
5829
  resolveLoginService(ctx, qqLoginService);
5813
- ctx.wrapperPath = env?.wrapperPath ?? process.env["NAPUKETTO_WRAPPER_PATH"] ?? process.env["NAPUTO_WRAPPER_PATH"];
5830
+ ctx.wrapperPath = env?.wrapperPath ?? process$1.env["NAPUKETTO_WRAPPER_PATH"] ?? process$1.env["NAPUTO_WRAPPER_PATH"];
5814
5831
  if (isSelfHost) activateO3MiscService(wrapperExports);
5815
5832
  finishSession(ctx, hasCapturedSession, isSelfHost, sessionConfig);
5816
5833
  return ctx;
@@ -5887,7 +5904,7 @@ function getOrCreateLoginService(exports) {
5887
5904
  */
5888
5905
  function dlopenWrapper(wrapperPath) {
5889
5906
  const m = { exports: {} };
5890
- process.dlopen(m, wrapperPath);
5907
+ process$1.dlopen(m, wrapperPath);
5891
5908
  if (!Object.keys(m.exports).includes("NodeIKernelLoginService")) throw kernelError("exports 无 NodeIKernelLoginService(stub 环境异常?)", "INVALID_STATE");
5892
5909
  if (!isWrapperNodeApi(m.exports)) throw kernelError(`wrapper.node at ${wrapperPath} did not export expected QQNT symbols`, "INVALID_STATE");
5893
5910
  return m.exports;
@@ -6192,7 +6209,7 @@ const WRAPPER_PATH_ENV_KEYS = ["NAPUKETTO_WRAPPER_PATH", "NAPUTO_WRAPPER_PATH"];
6192
6209
  function resolveWrapperPath$1(wrapper) {
6193
6210
  if (wrapper.wrapperPath !== void 0 && wrapper.wrapperPath !== "") return wrapper.wrapperPath;
6194
6211
  for (const key of WRAPPER_PATH_ENV_KEYS) {
6195
- const value = process.env[key];
6212
+ const value = process$1.env[key];
6196
6213
  if (value !== void 0 && value !== "") return value;
6197
6214
  }
6198
6215
  }
@@ -6897,7 +6914,7 @@ function probeRuntime(ctx, file = "napuketto-probe.json") {
6897
6914
  /** 探测结果落盘(增量与最终共用;最终写入后记 probeFile 路径)。 */
6898
6915
  function writeProbeFile(result, file) {
6899
6916
  try {
6900
- const dir = process.env["NAPUKETTO_CFG_DIR"] ?? process.env["NAPUTO_CFG_DIR"] ?? process.cwd();
6917
+ const dir = process$1.env["NAPUKETTO_CFG_DIR"] ?? process$1.env["NAPUTO_CFG_DIR"] ?? process$1.cwd();
6901
6918
  mkdirSync(dir, { recursive: true });
6902
6919
  const full = join(dir, file);
6903
6920
  writeFileSync(full, JSON.stringify(result, null, 2), "utf8");
@@ -7006,7 +7023,7 @@ function createRecordingListener(service, onEvent) {
7006
7023
  * 空壳的 service getter 函数仍在但调用返回 null(late probe 61/63 null 的根因)。
7007
7024
  */
7008
7025
  function startListenerRecording(ctx, file = "napuketto-listener-record.jsonl") {
7009
- const dir = process.env["NAPUKETTO_CFG_DIR"] ?? process.env["NAPUTO_CFG_DIR"] ?? process.cwd();
7026
+ const dir = process$1.env["NAPUKETTO_CFG_DIR"] ?? process$1.env["NAPUTO_CFG_DIR"] ?? process$1.cwd();
7010
7027
  mkdirSync(dir, { recursive: true });
7011
7028
  const full = join(dir, file);
7012
7029
  writeFileSync(full, "", "utf8");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@napuketto/kernel",
4
- "version": "0.18.0",
4
+ "version": "0.18.1",
5
5
  "type": "module",
6
6
  "description": "Core runtime kernel of NapukettoQQ",
7
7
  "keywords": [