@napuketto/loader 0.0.13 → 0.0.15

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.
Binary file
@@ -0,0 +1,144 @@
1
+ 7-Zip for Linux and macOS
2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
3
+ License for use and distribution
4
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
+
6
+ 7-Zip Copyright (C) 1999-2025 Igor Pavlov.
7
+
8
+ The licenses for 7zz and 7zzs files are:
9
+
10
+ - The "GNU LGPL" as main license for most of the code
11
+ - The "GNU LGPL" with "unRAR license restriction" for some code
12
+ - The "BSD 3-clause License" for some code
13
+ - The "BSD 2-clause License" for some code
14
+
15
+ Redistributions in binary form must reproduce related license information from this file.
16
+
17
+ Note:
18
+ You can use 7-Zip on any computer, including a computer in a commercial
19
+ organization. You don't need to register or pay for 7-Zip.
20
+
21
+
22
+ GNU LGPL information
23
+ --------------------
24
+
25
+ This library is free software; you can redistribute it and/or
26
+ modify it under the terms of the GNU Lesser General Public
27
+ License as published by the Free Software Foundation; either
28
+ version 2.1 of the License, or (at your option) any later version.
29
+
30
+ This library is distributed in the hope that it will be useful,
31
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
32
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33
+ Lesser General Public License for more details.
34
+
35
+ You can receive a copy of the GNU Lesser General Public License from
36
+ http://www.gnu.org/
37
+
38
+
39
+
40
+
41
+ BSD 3-clause License in 7-Zip code
42
+ ----------------------------------
43
+
44
+ The "BSD 3-clause License" is used for the following code in 7z.dll
45
+ 1) LZFSE data decompression.
46
+ That code was derived from the code in the "LZFSE compression library" developed by Apple Inc,
47
+ that also uses the "BSD 3-clause License".
48
+ 2) ZSTD data decompression.
49
+ that code was developed using original zstd decoder code as reference code.
50
+ The original zstd decoder code was developed by Facebook Inc,
51
+ that also uses the "BSD 3-clause License".
52
+
53
+ Copyright (c) 2015-2016, Apple Inc. All rights reserved.
54
+ Copyright (c) Facebook, Inc. All rights reserved.
55
+ Copyright (c) 2023-2024 Igor Pavlov.
56
+
57
+ Text of the "BSD 3-clause License"
58
+ ----------------------------------
59
+
60
+ Redistribution and use in source and binary forms, with or without modification,
61
+ are permitted provided that the following conditions are met:
62
+
63
+ 1. Redistributions of source code must retain the above copyright notice, this
64
+ list of conditions and the following disclaimer.
65
+
66
+ 2. Redistributions in binary form must reproduce the above copyright notice,
67
+ this list of conditions and the following disclaimer in the documentation
68
+ and/or other materials provided with the distribution.
69
+
70
+ 3. Neither the name of the copyright holder nor the names of its contributors may
71
+ be used to endorse or promote products derived from this software without
72
+ specific prior written permission.
73
+
74
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
75
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
76
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
77
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
78
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
79
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
80
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
81
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
82
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
83
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
84
+
85
+ ---
86
+
87
+
88
+
89
+
90
+ BSD 2-clause License in 7-Zip code
91
+ ----------------------------------
92
+
93
+ The "BSD 2-clause License" is used for the XXH64 code in 7-Zip.
94
+
95
+ XXH64 code in 7-Zip was derived from the original XXH64 code developed by Yann Collet.
96
+
97
+ Copyright (c) 2012-2021 Yann Collet.
98
+ Copyright (c) 2023-2024 Igor Pavlov.
99
+
100
+ Text of the "BSD 2-clause License"
101
+ ----------------------------------
102
+
103
+ Redistribution and use in source and binary forms, with or without modification,
104
+ are permitted provided that the following conditions are met:
105
+
106
+ 1. Redistributions of source code must retain the above copyright notice, this
107
+ list of conditions and the following disclaimer.
108
+
109
+ 2. Redistributions in binary form must reproduce the above copyright notice,
110
+ this list of conditions and the following disclaimer in the documentation
111
+ and/or other materials provided with the distribution.
112
+
113
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
114
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
115
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
116
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
117
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
118
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
119
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
120
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
121
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
122
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
123
+
124
+ ---
125
+
126
+
127
+
128
+
129
+ unRAR license restriction
130
+ -------------------------
131
+
132
+ The decompression engine for RAR archives was developed using source
133
+ code of unRAR program.
134
+ All copyrights to original unRAR code are owned by Alexander Roshal.
135
+
136
+ The license for original unRAR code has the following restriction:
137
+
138
+ The unRAR sources cannot be used to re-create the RAR compression algorithm,
139
+ which is proprietary. Distribution of modified unRAR sources in separate form
140
+ or as a part of other software is permitted, provided that it is clearly
141
+ stated in the documentation and source comments that the code may
142
+ not be used to develop a RAR (WinRAR) compatible archiver.
143
+
144
+ --
@@ -25,6 +25,7 @@ let node_path = require("node:path");
25
25
  let node_process = require("node:process");
26
26
  node_process = __toESM(node_process, 1);
27
27
  let node_os = require("node:os");
28
+ let zod = require("zod");
28
29
  let node_readline = require("node:readline");
29
30
  //#region src/instance-lock.ts
30
31
  /**
@@ -459,20 +460,156 @@ function errorCodeOf(err) {
459
460
  }
460
461
  return "UNKNOWN";
461
462
  }
462
- //#endregion
463
- //#region src/host/ipc/ipc-types.ts
464
- /** 消息类型集合(解码校验用)。 */
465
- const IPC_MESSAGE_TYPES = /* @__PURE__ */ new Set([
466
- "status",
467
- "login",
468
- "qr",
469
- "event",
470
- "result",
471
- "log",
472
- "ping",
473
- "pong",
474
- "action",
475
- "control"
463
+ /** 引导阶段(status 消息)。 */
464
+ const IpcBootPhaseSchema = zod.z.enum([
465
+ "booting",
466
+ "dlopening",
467
+ "logging",
468
+ "sessioning",
469
+ "ready",
470
+ "failed"
471
+ ]);
472
+ /** 结构化日志级别(pino level)。 */
473
+ const IpcLogLevelSchema = zod.z.enum([
474
+ "trace",
475
+ "debug",
476
+ "info",
477
+ "warn",
478
+ "error",
479
+ "fatal"
480
+ ]);
481
+ /** 登录状态(与 kernel LoginState 结构等价)。 */
482
+ const LoginStateSchema = zod.z.enum([
483
+ "idle",
484
+ "waiting_scan",
485
+ "scanned",
486
+ "logged_in",
487
+ "failed"
488
+ ]);
489
+ /** selfInfo(与 kernel SelfInfo 结构等价)。 */
490
+ const SelfInfoSchema = zod.z.object({
491
+ uin: zod.z.string(),
492
+ uid: zod.z.string(),
493
+ nick: zod.z.string()
494
+ });
495
+ /** status 消息 payload。 */
496
+ const IpcStatusPayloadSchema = zod.z.object({
497
+ phase: IpcBootPhaseSchema,
498
+ message: zod.z.string().optional(),
499
+ error: zod.z.object({
500
+ code: zod.z.string(),
501
+ message: zod.z.string()
502
+ }).optional()
503
+ });
504
+ /** login 消息 payload。 */
505
+ const IpcLoginPayloadSchema = zod.z.object({
506
+ state: LoginStateSchema,
507
+ selfInfo: SelfInfoSchema.optional(),
508
+ /** 失败原因(state=failed 时;如「登录超时,请刷新页面重试」)。 */
509
+ message: zod.z.string().optional()
510
+ });
511
+ /** event 消息 payload(kernel 事件通道形状,翻译层按 service/name 断言具体类型)。 */
512
+ const IpcEventPayloadSchema = zod.z.object({
513
+ service: zod.z.string(),
514
+ name: zod.z.string(),
515
+ args: zod.z.array(zod.z.unknown())
516
+ });
517
+ /** log 消息 payload。 */
518
+ const IpcLogPayloadSchema = zod.z.object({
519
+ level: IpcLogLevelSchema,
520
+ message: zod.z.string()
521
+ });
522
+ /** 动作响应 payload(result 消息)。 */
523
+ const IpcResultPayloadSchema = zod.z.union([zod.z.object({
524
+ ok: zod.z.literal(true),
525
+ value: zod.z.unknown().optional()
526
+ }), zod.z.object({
527
+ ok: zod.z.literal(false),
528
+ error: zod.z.object({
529
+ code: zod.z.string(),
530
+ message: zod.z.string()
531
+ })
532
+ })]);
533
+ /** 动作请求 payload(action 消息)。 */
534
+ const IpcActionPayloadSchema = zod.z.object({
535
+ action: zod.z.string(),
536
+ params: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
537
+ });
538
+ /** 控制指令 payload(control 消息,父→子)。 */
539
+ const IpcControlPayloadSchema = zod.z.union([
540
+ zod.z.object({ command: zod.z.literal("stop") }),
541
+ zod.z.object({ command: zod.z.literal("restart") }),
542
+ zod.z.object({
543
+ command: zod.z.literal("login"),
544
+ uin: zod.z.string().optional(),
545
+ qr: zod.z.boolean().optional()
546
+ })
547
+ ]);
548
+ const IpcStatusMessageSchema = zod.z.object({
549
+ v: zod.z.literal(1),
550
+ type: zod.z.literal("status"),
551
+ payload: IpcStatusPayloadSchema
552
+ });
553
+ const IpcLoginMessageSchema = zod.z.object({
554
+ v: zod.z.literal(1),
555
+ type: zod.z.literal("login"),
556
+ payload: IpcLoginPayloadSchema
557
+ });
558
+ const IpcQrMessageSchema = zod.z.object({
559
+ v: zod.z.literal(1),
560
+ type: zod.z.literal("qr"),
561
+ payload: zod.z.object({
562
+ pngBase64: zod.z.string(),
563
+ qrcodeUrl: zod.z.string()
564
+ })
565
+ });
566
+ const IpcEventMessageSchema = zod.z.object({
567
+ v: zod.z.literal(1),
568
+ type: zod.z.literal("event"),
569
+ payload: IpcEventPayloadSchema
570
+ });
571
+ const IpcResultMessageSchema = zod.z.object({
572
+ v: zod.z.literal(1),
573
+ type: zod.z.literal("result"),
574
+ id: zod.z.number(),
575
+ payload: IpcResultPayloadSchema
576
+ });
577
+ const IpcLogMessageSchema = zod.z.object({
578
+ v: zod.z.literal(1),
579
+ type: zod.z.literal("log"),
580
+ payload: IpcLogPayloadSchema
581
+ });
582
+ const IpcPingMessageSchema = zod.z.object({
583
+ v: zod.z.literal(1),
584
+ type: zod.z.literal("ping")
585
+ });
586
+ const IpcPongMessageSchema = zod.z.object({
587
+ v: zod.z.literal(1),
588
+ type: zod.z.literal("pong")
589
+ });
590
+ const IpcActionMessageSchema = zod.z.object({
591
+ v: zod.z.literal(1),
592
+ type: zod.z.literal("action"),
593
+ id: zod.z.number(),
594
+ payload: IpcActionPayloadSchema
595
+ });
596
+ const IpcControlMessageSchema = zod.z.object({
597
+ v: zod.z.literal(1),
598
+ type: zod.z.literal("control"),
599
+ payload: IpcControlPayloadSchema
600
+ });
601
+ /** IPC 消息判别联合(协议边界,运行时经 safeParse 校验)。 */
602
+ const IpcMessageSchema = zod.z.discriminatedUnion("type", [
603
+ IpcStatusMessageSchema,
604
+ IpcLoginMessageSchema,
605
+ IpcQrMessageSchema,
606
+ IpcEventMessageSchema,
607
+ IpcResultMessageSchema,
608
+ IpcLogMessageSchema,
609
+ IpcPingMessageSchema,
610
+ IpcPongMessageSchema,
611
+ IpcActionMessageSchema,
612
+ IpcControlMessageSchema
476
613
  ]);
477
614
  //#endregion
478
615
  //#region src/host/ipc/ipc-sender.ts
@@ -615,29 +752,39 @@ function attachIpcServices(actions, services) {
615
752
  /**
616
753
  * ipc-codec.ts:IPC 消息编解码(JSON 行协议,与 koishi 插件侧 src/ipc/codec.ts 对齐)。
617
754
  *
618
- * 每行一条 JSON 消息,`\n` 结尾。解码宽松:非法行 / 空行 / v 不匹配 /
619
- * 未知 type → null,调用方忽略,不崩通道。
755
+ * 每行一条 JSON 消息,`\n` 结尾。解码用 IpcMessageSchema.safeParse 校验:
756
+ * 非法行 / 空行 / v 不匹配 / type 未知 / payload 形状非法 → null,调用方忽略,
757
+ * 不崩通道。
620
758
  */
621
- /** 类型守卫:v 匹配 + type 合法。 */
622
- function isIpcMessage(value) {
623
- if (typeof value !== "object" || value === null) return false;
624
- const record = value;
625
- return record["v"] === 1 && typeof record["type"] === "string" && IPC_MESSAGE_TYPES.has(record["type"]);
626
- }
627
- /** 解码一行 JSON;非法行/空行返回 null。 */
759
+ /** 解码一行 JSON;非法行/空行/形状不合法返回 null。 */
628
760
  function decodeIpcMessage(line) {
629
761
  const trimmed = line.trim();
630
762
  if (trimmed === "") return null;
631
763
  try {
632
764
  const parsed = JSON.parse(trimmed);
633
- return isIpcMessage(parsed) ? parsed : null;
765
+ const result = IpcMessageSchema.safeParse(parsed);
766
+ return result.success ? result.data : null;
634
767
  } catch {
635
768
  return null;
636
769
  }
637
770
  }
771
+ //#endregion
772
+ //#region src/host/ipc/ipc-server.ts
773
+ /**
774
+ * ipc-server.ts:IPC 服务端(self-host 子进程侧)。
775
+ *
776
+ * 职责(design.md §5.6 / §7):
777
+ * - stdin readline 收 action / control / ping
778
+ * - action → 动作表执行 → result 响应(请求 id 匹配)
779
+ * - control stop/restart → 退出回调(默认 process.exit(0),由驱动层重启)
780
+ * - ping → 自动回 pong
781
+ * - 心跳:定期发 ping(koishi 插件探活)
782
+ */
783
+ /** 心跳间隔(毫秒)。 */
784
+ const HEARTBEAT_INTERVAL_MS = 15e3;
638
785
  /** 启动 IPC 服务端(stdin 接收 + 心跳)。返回停止函数。 */
639
786
  function startIpcServer(options) {
640
- const heartbeatMs = options.heartbeatMs ?? 15e3;
787
+ const heartbeatMs = options.heartbeatMs ?? HEARTBEAT_INTERVAL_MS;
641
788
  const onExit = options.onExit ?? (() => process.exit(0));
642
789
  const rl = (0, node_readline.createInterface)({
643
790
  input: process.stdin,