dsh-plugin-tool-management 0.22.3 → 0.22.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/CHANGELOG.md +1415 -1363
- package/README.md +177 -176
- package/README_EN.md +177 -176
- package/docs/ARCHITECTURE.md +134 -0
- package/docs/COMPATIBILITY.md +107 -0
- package/docs/TROUBLESHOOTING.md +285 -0
- package/docs/UPDATE.md +50 -48
- package/lib/client.js +4693 -4626
- package/lib/compat/host-contracts.js +4 -2
- package/lib/confirm-gate.js +49 -18
- package/lib/context-inject-surface.js +45 -13
- package/lib/context-inject.js +1 -1
- package/lib/imports/unzip.js +144 -26
- package/lib/index.js +245 -93
- package/lib/legacy-tool-names.js +46 -0
- package/lib/mcp/manager.js +12 -1
- package/lib/mcp/secret-guard.js +27 -0
- package/lib/mcp/state-section.js +17 -8
- package/lib/mcp/tool-visibility.js +86 -10
- package/lib/memories/archive.js +44 -0
- package/lib/memories/index-io.js +4 -1
- package/lib/memories/service.js +94 -3
- package/lib/op-registry.js +5 -1
- package/lib/ops/scene-capture.js +72 -0
- package/lib/prompts/service.js +27 -0
- package/lib/scope/scope-overrides.js +9 -2
- package/lib/skills/catalog.js +18 -9
- package/lib/skills/dir-watch.js +49 -22
- package/lib/skills/service.js +2 -2
- package/lib/subagents/catalog.js +13 -7
- package/lib/subagents/run-provider.js +41 -10
- package/lib/subagents/tools.js +63 -7
- package/lib/tool-table-switch.js +41 -4
- package/lib/tools/control.js +158 -0
- package/lib/tools/deps.js +88 -0
- package/lib/tools/mcp.js +35 -10
- package/lib/tools/memory.js +9 -5
- package/lib/tools/prompt.js +7 -8
- package/lib/tools/remove.js +84 -65
- package/lib/tools/scene.js +179 -76
- package/lib/tools/skills.js +13 -8
- package/lib/tools/subagent.js +19 -10
- package/lib/tools/table.js +92 -57
- package/lib/trash-id.js +3 -2
- package/package.json +156 -152
|
@@ -212,10 +212,12 @@ export const HOST_BEHAVIOR_CONTRACTS = [
|
|
|
212
212
|
},
|
|
213
213
|
{
|
|
214
214
|
package: '@deepseek-ai/dsh-session',
|
|
215
|
-
feature: '
|
|
216
|
-
impact: '
|
|
215
|
+
feature: '会话事件序号与可见消息',
|
|
216
|
+
impact: '注入表面的事件定位与去重会失配',
|
|
217
217
|
markers: [
|
|
218
218
|
{ needle: 'SessionSeq', why: '会话事件序号(注入表面按它定位事件)' },
|
|
219
|
+
{ needle: 'deriveMessages', why: '模型可见消息的公开出口(注入表面按它读各域最新正文)' },
|
|
220
|
+
{ needle: 'eventAt', why: '同步事件读取(deriveMessages 缺席时的兜底路径)' },
|
|
219
221
|
],
|
|
220
222
|
},
|
|
221
223
|
{
|
package/lib/confirm-gate.js
CHANGED
|
@@ -21,16 +21,13 @@
|
|
|
21
21
|
* 不在这张表里的工具仍走 `CONFIRM_LABELS` 的既有分支(无条件问,或按设置开关问)。
|
|
22
22
|
*/
|
|
23
23
|
export const ARG_CONDITIONAL_CONFIRM_TOOLS = new Set([
|
|
24
|
-
'
|
|
25
|
-
'skill_manager_remove',
|
|
26
|
-
'subagent_manager_remove',
|
|
27
|
-
'scene_manager_remove',
|
|
28
|
-
'prompt_manager_remove',
|
|
24
|
+
'plugin_manager_remove',
|
|
29
25
|
'prompt_manager_apply',
|
|
30
26
|
'mcp_manager_switch',
|
|
31
27
|
'memory_manager_switch',
|
|
32
28
|
'skill_manager_switch',
|
|
33
29
|
'subagent_manager_switch',
|
|
30
|
+
'tool_manager_tools',
|
|
34
31
|
]);
|
|
35
32
|
/** 取一个必填字符串参数;不是非空字符串就返回空串。 */
|
|
36
33
|
function text(value) {
|
|
@@ -40,18 +37,21 @@ function text(value) {
|
|
|
40
37
|
function machineWide(args, mode) {
|
|
41
38
|
return mode === 'global' || args.scope === 'global';
|
|
42
39
|
}
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
40
|
+
/**
|
|
41
|
+
* 删除类工具的域 → 卡上回显的名词。
|
|
42
|
+
*
|
|
43
|
+
* 删除是一条**跨域**工具(`plugin_manager_remove`),所以名词由 `domain` 参数决定,
|
|
44
|
+
* 不由工具名决定 —— 五个域合进一条之后,工具名不再携带是删什么。
|
|
45
|
+
*
|
|
46
|
+
* 域不认识(或没给)时返回 undefined:那种调用注定失败,问了也是一次无效审批。
|
|
47
|
+
*/
|
|
48
|
+
const REMOVE_SUBJECT = {
|
|
49
|
+
memory: 'memory',
|
|
50
|
+
skill: 'skill',
|
|
51
|
+
persona: 'persona',
|
|
52
|
+
preset: 'AGENTS.md preset',
|
|
53
|
+
scene: 'scene',
|
|
54
|
+
};
|
|
55
55
|
/**
|
|
56
56
|
* 这一次调用要不要问用户;要问就返回卡上那句理由,不问返回 `null`。
|
|
57
57
|
*
|
|
@@ -75,7 +75,10 @@ export function argConditionalConfirmReason(name, rawArgs, mode) {
|
|
|
75
75
|
// 缺 id 时工具自己会拒;先弹一张卡等于让用户批准一次注定失败的删除。
|
|
76
76
|
if (id === '')
|
|
77
77
|
return null;
|
|
78
|
-
|
|
78
|
+
const subject = REMOVE_SUBJECT[text(args.domain)];
|
|
79
|
+
if (subject === undefined)
|
|
80
|
+
return null;
|
|
81
|
+
return `Delete ${subject}「${id}」 — moved to the trash, restorable from the panel.`;
|
|
79
82
|
}
|
|
80
83
|
if (name === 'prompt_manager_apply') {
|
|
81
84
|
// apply=false 是撤销(回到本轮应用之前),可逆,不问。
|
|
@@ -130,5 +133,33 @@ export function argConditionalConfirmReason(name, rawArgs, mode) {
|
|
|
130
133
|
}
|
|
131
134
|
return `${args.prefer ? 'Make' : 'Stop preferring'} the copy of ${label}「${key}」 win its name collision, machine-wide.`;
|
|
132
135
|
}
|
|
136
|
+
if (name === 'tool_manager_tools') {
|
|
137
|
+
// 会话层自开不弹(只动管着这个对话的那一层,随时可退);隔离关掉时那一层就是全局,
|
|
138
|
+
// 动的是所有对话 —— 与三个 `_switch` 在全局粒度下的口径一致,要问。
|
|
139
|
+
// 修复类动作要问:它会把**已损坏的侧车改名留存**、按空表继续 —— 那是一次不可逆的
|
|
140
|
+
// 数据处置(原始文件还在,但插件从此不再读它),与「换个开关」不是一档。
|
|
141
|
+
if (action === 'repair') {
|
|
142
|
+
const target = text(args.target);
|
|
143
|
+
if (target === '')
|
|
144
|
+
return null;
|
|
145
|
+
const subject = target === 'memory-index' ? '记忆索引'
|
|
146
|
+
: target === 'scope' ? '作用域侧车'
|
|
147
|
+
: target === 'mcp-disabled' ? 'MCP 停用表'
|
|
148
|
+
: '';
|
|
149
|
+
if (subject === '')
|
|
150
|
+
return null;
|
|
151
|
+
return `Repair the ${subject} — the damaged file is renamed aside and the plugin continues with an empty table. Anything it held is no longer applied.`;
|
|
152
|
+
}
|
|
153
|
+
if (action !== 'enable' && action !== 'disable')
|
|
154
|
+
return null;
|
|
155
|
+
if (!machineWide(args, mode))
|
|
156
|
+
return null;
|
|
157
|
+
const names = Array.isArray(args.tools)
|
|
158
|
+
? args.tools.map((n) => text(n)).filter((n) => n !== '')
|
|
159
|
+
: [];
|
|
160
|
+
if (names.length === 0)
|
|
161
|
+
return null;
|
|
162
|
+
return `Turn ${action === 'enable' ? 'on' : 'off'} ${names.join(', ')} for every conversation (machine-wide tool table).`;
|
|
163
|
+
}
|
|
133
164
|
return null;
|
|
134
165
|
}
|
|
@@ -73,29 +73,22 @@ export const LIVE_KINDS = new Map([
|
|
|
73
73
|
export function newestDomainTexts(agent, kinds) {
|
|
74
74
|
const out = new Map();
|
|
75
75
|
const session = agent?.session;
|
|
76
|
-
if (!session
|
|
76
|
+
if (!session)
|
|
77
77
|
return out;
|
|
78
78
|
// 每个域只收两条信息:**最后一条内容**(`body` / `form`)与**最新一条是不是通知**(`cleared`)。
|
|
79
79
|
// 自新到旧扫,第一次遇到该域时:
|
|
80
80
|
// · 是通知 → 记下 `cleared = true`(内容字段留空,等更早那条内容消息来填);
|
|
81
81
|
// · 是内容 → 直接填内容字段(`cleared` 保持 false:通知之后已有新内容 = 已经"不清空"了)。
|
|
82
82
|
// 内容字段填好之后就跳过该域更早的消息;只遇到通知、没遇到内容的域停在 `cleared` 上。
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
if (!event || event.type !== 'user/message')
|
|
92
|
-
return false;
|
|
93
|
-
const source = event.data && event.data.source;
|
|
83
|
+
//
|
|
84
|
+
// `message` 是模型可见的那条消息(`Message`),`source` 是它携带的来源标记。两条路径
|
|
85
|
+
// (`deriveMessages()` 与 `eventAt()` 兜底)只在这两个实参的取法上不同。
|
|
86
|
+
const absorb = (message, source) => {
|
|
94
87
|
const mapping = source && typeof source.kind === 'string' ? kinds.get(source.kind) : undefined;
|
|
95
88
|
if (mapping === undefined)
|
|
96
89
|
return false;
|
|
97
90
|
const seen = out.get(mapping.key);
|
|
98
|
-
const text = textOf(
|
|
91
|
+
const text = textOf(message);
|
|
99
92
|
if (text === undefined)
|
|
100
93
|
return false;
|
|
101
94
|
const form = source && typeof source.form === 'string' ? source.form : '';
|
|
@@ -124,6 +117,45 @@ export function newestDomainTexts(agent, kinds) {
|
|
|
124
117
|
// 提前收工的条件是"六个域都拿到了**内容**":只有通知的域(`form === 'notice'`)还得继续
|
|
125
118
|
// 往更早找它的正文,否则内容恢复时 `body` 是空的,只能当成"内容变了"多发一条。
|
|
126
119
|
const done = () => out.size === INJECT_DOMAIN_KEYS.length && [...out.values()].every((entry) => entry.form !== 'notice');
|
|
120
|
+
// 主路径:`deriveMessages()` 是官方面向"模型可见消息"的公开出口,返回**模型可见顺序**
|
|
121
|
+
// 的 `Message[]`,`source` 完整保留。它内部按 `contentGeneration` 增量缓存 —— 实测 3000
|
|
122
|
+
// 节点 0.004 ms/次,比下面那条自建路径(读 `surface.nodes`、排序、逐个 `eventAt`)
|
|
123
|
+
// 快一个量级。
|
|
124
|
+
//
|
|
125
|
+
// 为什么仍留兜底:`eventAt` / `surface.nodes` 这一代里都在,而 `deriveMessages` 只在
|
|
126
|
+
// 宿主 `Session` 上有;契约测试的假 session 也只实现了前者。两条路径的结果必须逐字一致
|
|
127
|
+
// (`absorb` 是同一份实现),差异只在"怎么拿到消息"。
|
|
128
|
+
if (typeof session.deriveMessages === 'function') {
|
|
129
|
+
let messages;
|
|
130
|
+
try {
|
|
131
|
+
messages = session.deriveMessages();
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
messages = undefined;
|
|
135
|
+
}
|
|
136
|
+
if (Array.isArray(messages)) {
|
|
137
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
138
|
+
const message = messages[i];
|
|
139
|
+
if (absorb(message, message && message.source))
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (typeof session.seq !== 'number' || typeof session.eventAt !== 'function')
|
|
146
|
+
return out;
|
|
147
|
+
const scan = (seq) => {
|
|
148
|
+
let event;
|
|
149
|
+
try {
|
|
150
|
+
event = session.eventAt(SessionSeq(seq));
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
if (!event || event.type !== 'user/message')
|
|
156
|
+
return false;
|
|
157
|
+
return absorb(event.data, event.data && event.data.source);
|
|
158
|
+
};
|
|
127
159
|
const nodes = session.surface && Array.isArray(session.surface.nodes) ? session.surface.nodes : undefined;
|
|
128
160
|
if (nodes !== undefined) {
|
|
129
161
|
const seqs = [];
|
package/lib/context-inject.js
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
// skill-catalog 同样只带 kind)。
|
|
28
28
|
//
|
|
29
29
|
// 本模块的实现口径:
|
|
30
|
-
// - 每个 step
|
|
30
|
+
// - 每个 step 同步算一遍各域文本(各域自带缓存,这里不直接读盘);
|
|
31
31
|
// - 与会话**可见表面上**该域最新的己方消息逐字节比对:一样就不发(零 token、零重复),
|
|
32
32
|
// 不一样才追加一条新消息;被压缩移出表面后比对不到 → 自动重发(与 skill-catalog、
|
|
33
33
|
// agent-instructions 同款做法:两者都直接扫 `session.surface.nodes`);
|
package/lib/imports/unzip.js
CHANGED
|
@@ -1,48 +1,166 @@
|
|
|
1
1
|
// ZIP 解包的限额层(无 I/O):条目数、单条字节、解压后累计。
|
|
2
2
|
//
|
|
3
3
|
// 上传链路与整机迁移快照共用这一份。单条目与条目数都挡不住「2000 × 8 MiB」这种组合,
|
|
4
|
-
//
|
|
5
|
-
// 在 `filter` 里完成(fflate 在 inflate 之前调用 filter)。
|
|
4
|
+
// 只有解压后累计量挡得住。
|
|
6
5
|
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
|
|
6
|
+
// ## 为什么按**实际解出**的字节计
|
|
7
|
+
//
|
|
8
|
+
// `unzipSync` 的 `filter` 里拿到的是档案自报的 `info.originalSize`(来自中央目录),
|
|
9
|
+
// 不是真实产出,而它把这个申报值直接当输出缓冲区大小(`inflateSync(…, { out: new u8(su) })`)。
|
|
10
|
+
// 两个方向都错:
|
|
11
|
+
// · 申报**偏小**:内容被静默截断 —— 实测申报 1 KiB、实际 8 MiB,返回的就是 1 KiB,
|
|
12
|
+
// 导入进来的文件是坏的,而没有任何一处报错。比"解压失败"更糟:用户拿到的是残缺数据。
|
|
13
|
+
// · 申报**偏大**:缓冲区按申报值分配,2000 条 × 8 MiB 就是 16 GiB,宿主与插件同进程,
|
|
14
|
+
// 直接拖死宿主。
|
|
15
|
+
// 两道闸门都建在"实际解出多少"上,才两头都挡得住。
|
|
16
|
+
//
|
|
17
|
+
// 所以改用 fflate 的流式 `Unzip`:`file.ondata` 拿到的是**真正解出来的字节**,按它累加
|
|
18
|
+
// 单条与总量。超限的条目立刻停止收集(`terminate()` 只对实现了它的解码器生效,
|
|
19
|
+
// 因此**同时**靠分块喂数据来中断)—— `push()` 是同步的,一次喂 1 MiB 并在块与块之间
|
|
20
|
+
// 检查中止标记,CPU 与内存都被限住。
|
|
21
|
+
//
|
|
22
|
+
// 条目数上限仍在 `onfile` 里判:超了就不 `start()`,后续条目一个字节都不解。
|
|
23
|
+
//
|
|
24
|
+
// 已知边界:解压器本身仍会按压缩流解到超限点为止(这是"发现超限"的固有代价),
|
|
25
|
+
// 但超出的部分不再进内存,且总量一旦越界整份解包立即停止。
|
|
26
|
+
import { Unzip, UnzipInflate } from 'fflate';
|
|
27
|
+
/**
|
|
28
|
+
* 一次喂给解压器的块大小。
|
|
29
|
+
*
|
|
30
|
+
* 为什么要分块:`Unzip.push()` 是同步的,一次喂完整份档案就等于"在发现超限之前先把
|
|
31
|
+
* 它全解了"。1 MiB 让中止检查的粒度足够细(单块最多解出 1 MiB 量级),又不至于让
|
|
32
|
+
* 每次 push 的固定开销成为负担。
|
|
33
|
+
*/
|
|
34
|
+
const PUSH_CHUNK_BYTES = 1024 * 1024;
|
|
35
|
+
/**
|
|
36
|
+
* 档案尾部有没有中央目录结束记录(EOCD)。
|
|
37
|
+
*
|
|
38
|
+
* 流式 `Unzip` 只顺着局部文件头往下读,**不校验**整份档案的结构:随机字节、纯文本、
|
|
39
|
+
* 被截断的 zip 都可能"读到 0 个条目"或"读到前几条"就正常结束。`unzipSync` 则先找 EOCD,
|
|
40
|
+
* 找不到就抛 `invalid zip data` —— 调用方据此报「ZIP 解压失败」。少了这道判据,损坏的
|
|
41
|
+
* 上传会静默变成「导入成功 0 个文件」,用户不知道是自己传错了还是插件没干活。
|
|
42
|
+
*
|
|
43
|
+
* 判据与 `unzipSync` 逐字一致:从末尾 22 字节处往前找,最多回看 65558 字节(22 + 64 KiB
|
|
44
|
+
* 注释上限)。ZIP64 档案同样带这条记录(只是字段填占位值),所以这里不必特判。
|
|
45
|
+
*/
|
|
46
|
+
function hasEndOfCentralDirectory(bytes) {
|
|
47
|
+
const floor = Math.max(0, bytes.length - 65558);
|
|
48
|
+
for (let i = bytes.length - 22; i >= floor; i -= 1) {
|
|
49
|
+
if (bytes[i] === 0x50 && bytes[i + 1] === 0x4b && bytes[i + 2] === 0x05 && bytes[i + 3] === 0x06)
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
10
54
|
/**
|
|
11
55
|
* 解包并丢弃超限条目;返回被丢弃的条目清单。
|
|
12
|
-
*
|
|
56
|
+
*
|
|
57
|
+
* 条目顺序与 `unzipSync` 的返回一致(档案内出现顺序)。超限的条目**不进** `entries`,
|
|
58
|
+
* 并在 `problems` 里留一条 —— 静默丢弃会让用户以为「全都导入成功了」。
|
|
59
|
+
*
|
|
60
|
+
* @param bytes 整份 zip 字节
|
|
61
|
+
* @param limits 四道上限
|
|
62
|
+
* @returns `entries` 是放行的条目(路径 → 字节);`problems` 是被挡下的条目与原因
|
|
63
|
+
* @throws 解压器本身报错(压缩流损坏、未知压缩算法)时抛错,由调用方转成该文件 / 该域的失败回执
|
|
13
64
|
*/
|
|
14
65
|
export function unzipLimited(bytes, limits) {
|
|
66
|
+
// 先确认这是一份结构完整的 zip:流式读取不会替我们报这个错(见 `hasEndOfCentralDirectory`)。
|
|
67
|
+
if (!hasEndOfCentralDirectory(bytes))
|
|
68
|
+
throw new Error('invalid zip data');
|
|
15
69
|
const problems = [];
|
|
16
70
|
const sourceName = limits.sourceName || '(zip)';
|
|
71
|
+
const entries = Object.create(null);
|
|
17
72
|
let count = 0;
|
|
18
|
-
let
|
|
73
|
+
let total = 0;
|
|
19
74
|
let totalReported = false;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
75
|
+
let entriesReported = false;
|
|
76
|
+
/** 整份解包是否应当停止(条目数超限 / 累计超限)。 */
|
|
77
|
+
let aborted = false;
|
|
78
|
+
/** 解压器自身的错误(压缩流损坏等):喂完再抛,保持与 `unzipSync` 一致的失败语义。 */
|
|
79
|
+
let decodeError = null;
|
|
80
|
+
const unzipper = new Unzip((file) => {
|
|
81
|
+
if (aborted)
|
|
82
|
+
return;
|
|
83
|
+
count += 1;
|
|
84
|
+
if (count > limits.maxEntries) {
|
|
85
|
+
if (!entriesReported) {
|
|
86
|
+
entriesReported = true;
|
|
87
|
+
problems.push({ name: sourceName, reason: `zip 内条目超过 ${limits.maxEntries} 个,其余条目已忽略` });
|
|
29
88
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
89
|
+
aborted = true;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
// 目录条目:不占解压预算,但仍进 `entries`(与 `unzipSync` 的返回同形 —— 调用方
|
|
93
|
+
// 按名字结尾的 `/` 自己跳过,`ops/snapshot.ts` 还用它数条目)。
|
|
94
|
+
if (file.name.endsWith('/')) {
|
|
95
|
+
entries[file.name] = new Uint8Array(0);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
// 自报大小已经越界 → 连解都不解(这一条只是省开销;真实判据是下面的实际字节)。
|
|
99
|
+
if (typeof file.originalSize === 'number' && file.originalSize > limits.maxEntryBytes) {
|
|
100
|
+
problems.push({ name: file.name, reason: `zip 内单条目超过 ${limits.maxEntryBytes >> 20} MiB,已跳过` });
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
let size = 0;
|
|
104
|
+
let dropped = false;
|
|
105
|
+
const chunks = [];
|
|
106
|
+
file.ondata = (err, chunk, final) => {
|
|
107
|
+
if (err) {
|
|
108
|
+
decodeError = err;
|
|
109
|
+
aborted = true;
|
|
110
|
+
return;
|
|
33
111
|
}
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
112
|
+
if (dropped || aborted)
|
|
113
|
+
return;
|
|
114
|
+
// `chunk` 在部分实现里可能是空视图(终止信号),按长度处理即可。
|
|
115
|
+
const part = chunk && chunk.length ? chunk : null;
|
|
116
|
+
if (part !== null) {
|
|
117
|
+
size += part.length;
|
|
118
|
+
if (size > limits.maxEntryBytes) {
|
|
119
|
+
dropped = true;
|
|
120
|
+
problems.push({ name: file.name, reason: `zip 内单条目超过 ${limits.maxEntryBytes >> 20} MiB,已跳过` });
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
total += part.length;
|
|
124
|
+
if (total > limits.maxTotalUncompressedBytes) {
|
|
125
|
+
dropped = true;
|
|
126
|
+
aborted = true;
|
|
37
127
|
if (!totalReported) {
|
|
38
128
|
totalReported = true;
|
|
39
|
-
problems.push({ name:
|
|
129
|
+
problems.push({ name: file.name, reason: `zip 解压后合计超过 ${limits.maxTotalUncompressedBytes >> 20} MiB,该条目及其后条目已忽略` });
|
|
40
130
|
}
|
|
41
|
-
return
|
|
131
|
+
return;
|
|
42
132
|
}
|
|
133
|
+
chunks.push(part);
|
|
43
134
|
}
|
|
44
|
-
|
|
45
|
-
|
|
135
|
+
if (final && !dropped)
|
|
136
|
+
entries[file.name] = concatChunks(chunks, size);
|
|
137
|
+
};
|
|
138
|
+
try {
|
|
139
|
+
file.start();
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
decodeError = e;
|
|
143
|
+
aborted = true;
|
|
144
|
+
}
|
|
46
145
|
});
|
|
146
|
+
unzipper.register(UnzipInflate);
|
|
147
|
+
for (let offset = 0; offset < bytes.length && !aborted; offset += PUSH_CHUNK_BYTES) {
|
|
148
|
+
const end = Math.min(offset + PUSH_CHUNK_BYTES, bytes.length);
|
|
149
|
+
unzipper.push(bytes.subarray(offset, end), end === bytes.length);
|
|
150
|
+
}
|
|
151
|
+
if (decodeError !== null)
|
|
152
|
+
throw decodeError;
|
|
47
153
|
return { entries, problems };
|
|
48
154
|
}
|
|
155
|
+
/** 把若干块拼成一段(只有一块时直接返回,省一次拷贝)。 */
|
|
156
|
+
function concatChunks(chunks, size) {
|
|
157
|
+
if (chunks.length === 1)
|
|
158
|
+
return chunks[0];
|
|
159
|
+
const out = new Uint8Array(size);
|
|
160
|
+
let at = 0;
|
|
161
|
+
for (const chunk of chunks) {
|
|
162
|
+
out.set(chunk, at);
|
|
163
|
+
at += chunk.length;
|
|
164
|
+
}
|
|
165
|
+
return out;
|
|
166
|
+
}
|