codexmate 0.0.27 → 0.0.28

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 (137) hide show
  1. package/README.md +421 -421
  2. package/README.zh.md +354 -354
  3. package/cli/agents-files.js +224 -224
  4. package/cli/archive-helpers.js +446 -446
  5. package/cli/auth-profiles.js +375 -375
  6. package/cli/builtin-proxy.js +1620 -1299
  7. package/cli/claude-proxy.js +1022 -1022
  8. package/cli/config-bootstrap.js +384 -384
  9. package/cli/config-health.js +338 -338
  10. package/cli/doctor-core.js +903 -903
  11. package/cli/import-skills-url.js +356 -356
  12. package/cli/openai-bridge.js +1489 -1091
  13. package/cli/openclaw-config.js +629 -629
  14. package/cli/session-convert-args.js +65 -65
  15. package/cli/session-convert-io.js +82 -82
  16. package/cli/session-convert.js +43 -43
  17. package/cli/session-usage.concurrent.js +28 -28
  18. package/cli/session-usage.js +118 -118
  19. package/cli/session-usage.models.js +176 -176
  20. package/cli/skills.js +1141 -1141
  21. package/cli/zip-commands.js +510 -510
  22. package/cli.js +15264 -15251
  23. package/lib/automation.js +404 -404
  24. package/lib/cli-file-utils.js +151 -151
  25. package/lib/cli-models-utils.js +440 -379
  26. package/lib/cli-network-utils.js +190 -190
  27. package/lib/cli-path-utils.js +85 -85
  28. package/lib/cli-session-utils.js +121 -121
  29. package/lib/cli-sessions.js +417 -417
  30. package/lib/cli-utils.js +155 -155
  31. package/lib/download-artifacts.js +92 -92
  32. package/lib/mcp-stdio.js +453 -453
  33. package/lib/task-orchestrator.js +869 -869
  34. package/lib/text-diff.js +303 -303
  35. package/lib/workflow-engine.js +340 -340
  36. package/package.json +3 -1
  37. package/plugins/README.md +20 -20
  38. package/plugins/README.zh-CN.md +20 -20
  39. package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
  40. package/plugins/prompt-templates/computed.mjs +253 -253
  41. package/plugins/prompt-templates/index.mjs +8 -8
  42. package/plugins/prompt-templates/manifest.mjs +15 -15
  43. package/plugins/prompt-templates/methods.mjs +553 -619
  44. package/plugins/prompt-templates/overview.mjs +91 -90
  45. package/plugins/prompt-templates/ownership.mjs +19 -19
  46. package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
  47. package/plugins/prompt-templates/storage.mjs +64 -64
  48. package/plugins/registry.mjs +16 -16
  49. package/web-ui/app.js +625 -634
  50. package/web-ui/index.html +35 -35
  51. package/web-ui/logic.agents-diff.mjs +386 -386
  52. package/web-ui/logic.claude.mjs +168 -168
  53. package/web-ui/logic.codex.mjs +56 -0
  54. package/web-ui/logic.mjs +5 -5
  55. package/web-ui/logic.runtime.mjs +128 -128
  56. package/web-ui/logic.session-convert.mjs +70 -70
  57. package/web-ui/logic.sessions.mjs +765 -765
  58. package/web-ui/modules/api.mjs +90 -90
  59. package/web-ui/modules/app.computed.dashboard.mjs +225 -171
  60. package/web-ui/modules/app.computed.index.mjs +17 -17
  61. package/web-ui/modules/app.computed.main-tabs.mjs +205 -205
  62. package/web-ui/modules/app.computed.session.mjs +994 -994
  63. package/web-ui/modules/app.constants.mjs +15 -15
  64. package/web-ui/modules/app.methods.agents.mjs +632 -632
  65. package/web-ui/modules/app.methods.claude-config.mjs +190 -184
  66. package/web-ui/modules/app.methods.codex-config.mjs +892 -860
  67. package/web-ui/modules/app.methods.index.mjs +92 -92
  68. package/web-ui/modules/app.methods.install.mjs +205 -205
  69. package/web-ui/modules/app.methods.navigation.mjs +743 -743
  70. package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
  71. package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -372
  72. package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -369
  73. package/web-ui/modules/app.methods.providers.mjs +412 -404
  74. package/web-ui/modules/app.methods.runtime.mjs +345 -345
  75. package/web-ui/modules/app.methods.session-actions.mjs +593 -596
  76. package/web-ui/modules/app.methods.session-browser.mjs +984 -989
  77. package/web-ui/modules/app.methods.session-timeline.mjs +479 -479
  78. package/web-ui/modules/app.methods.session-trash.mjs +439 -439
  79. package/web-ui/modules/app.methods.startup-claude.mjs +533 -526
  80. package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
  81. package/web-ui/modules/config-mode.computed.mjs +124 -124
  82. package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
  83. package/web-ui/modules/i18n.dict.mjs +2109 -2131
  84. package/web-ui/modules/i18n.mjs +56 -56
  85. package/web-ui/modules/plugins.computed.mjs +3 -3
  86. package/web-ui/modules/plugins.methods.mjs +3 -3
  87. package/web-ui/modules/plugins.storage.mjs +11 -11
  88. package/web-ui/modules/provider-url-display.mjs +17 -0
  89. package/web-ui/modules/sessions-filters-url.mjs +85 -85
  90. package/web-ui/modules/skills.computed.mjs +107 -107
  91. package/web-ui/modules/skills.methods.mjs +481 -481
  92. package/web-ui/partials/index/layout-footer.html +13 -13
  93. package/web-ui/partials/index/layout-header.html +475 -475
  94. package/web-ui/partials/index/modal-config-template-agents.html +174 -174
  95. package/web-ui/partials/index/modal-confirm-toast.html +32 -32
  96. package/web-ui/partials/index/modal-health-check.html +45 -45
  97. package/web-ui/partials/index/modal-openclaw-config.html +280 -280
  98. package/web-ui/partials/index/modal-skills.html +200 -200
  99. package/web-ui/partials/index/modals-basic.html +165 -165
  100. package/web-ui/partials/index/panel-config-claude.html +188 -187
  101. package/web-ui/partials/index/panel-config-codex.html +312 -283
  102. package/web-ui/partials/index/panel-config-openclaw.html +83 -83
  103. package/web-ui/partials/index/panel-dashboard.html +186 -186
  104. package/web-ui/partials/index/panel-docs.html +147 -147
  105. package/web-ui/partials/index/panel-market.html +177 -177
  106. package/web-ui/partials/index/panel-orchestration.html +391 -391
  107. package/web-ui/partials/index/panel-plugins.html +253 -279
  108. package/web-ui/partials/index/panel-sessions.html +316 -326
  109. package/web-ui/partials/index/panel-settings.html +253 -274
  110. package/web-ui/partials/index/panel-usage.html +371 -371
  111. package/web-ui/res/json5.min.js +1 -1
  112. package/web-ui/res/vue.global.prod.js +13 -13
  113. package/web-ui/session-helpers.mjs +576 -576
  114. package/web-ui/source-bundle.cjs +233 -233
  115. package/web-ui/styles/base-theme.css +281 -268
  116. package/web-ui/styles/controls-forms.css +422 -423
  117. package/web-ui/styles/dashboard.css +274 -274
  118. package/web-ui/styles/docs-panel.css +247 -247
  119. package/web-ui/styles/feedback.css +108 -108
  120. package/web-ui/styles/health-check-dialog.css +144 -144
  121. package/web-ui/styles/layout-shell.css +606 -603
  122. package/web-ui/styles/modals-core.css +466 -464
  123. package/web-ui/styles/navigation-panels.css +391 -390
  124. package/web-ui/styles/openclaw-structured.css +266 -266
  125. package/web-ui/styles/plugins-panel.css +523 -523
  126. package/web-ui/styles/responsive.css +454 -454
  127. package/web-ui/styles/sessions-list.css +419 -415
  128. package/web-ui/styles/sessions-preview.css +411 -411
  129. package/web-ui/styles/sessions-toolbar-trash.css +330 -330
  130. package/web-ui/styles/sessions-usage.css +1040 -1040
  131. package/web-ui/styles/settings-panel.css +185 -185
  132. package/web-ui/styles/skills-list.css +303 -303
  133. package/web-ui/styles/skills-market.css +406 -406
  134. package/web-ui/styles/task-orchestration.css +822 -822
  135. package/web-ui/styles/titles-cards.css +472 -408
  136. package/web-ui/styles.css +21 -21
  137. package/web-ui.html +17 -17
@@ -1,510 +1,510 @@
1
- function createZipCommandController(deps = {}) {
2
- const {
3
- fs,
4
- path,
5
- execSync,
6
- process,
7
- yauzl,
8
- ensureDir,
9
- formatTimestampForFileName,
10
- inspectZipArchiveLimits,
11
- resolveZipTool,
12
- resolveUnzipTool,
13
- zipWithLibrary,
14
- unzipWithLibrary,
15
- DEFAULT_EXTRACT_SUFFIXES,
16
- MAX_SKILLS_ZIP_ENTRY_COUNT,
17
- MAX_SKILLS_ZIP_UNCOMPRESSED_BYTES,
18
- } = deps;
19
-
20
- if (!fs) throw new Error('createZipCommandController 缺少 fs');
21
- if (!path) throw new Error('createZipCommandController 缺少 path');
22
- if (typeof execSync !== 'function') throw new Error('createZipCommandController 缺少 execSync');
23
- if (!process) throw new Error('createZipCommandController 缺少 process');
24
- if (!yauzl) throw new Error('createZipCommandController 缺少 yauzl');
25
- if (typeof ensureDir !== 'function') throw new Error('createZipCommandController 缺少 ensureDir');
26
- if (typeof formatTimestampForFileName !== 'function') throw new Error('createZipCommandController 缺少 formatTimestampForFileName');
27
- if (typeof inspectZipArchiveLimits !== 'function') throw new Error('createZipCommandController 缺少 inspectZipArchiveLimits');
28
- if (typeof resolveZipTool !== 'function') throw new Error('createZipCommandController 缺少 resolveZipTool');
29
- if (typeof resolveUnzipTool !== 'function') throw new Error('createZipCommandController 缺少 resolveUnzipTool');
30
- if (typeof zipWithLibrary !== 'function') throw new Error('createZipCommandController 缺少 zipWithLibrary');
31
- if (typeof unzipWithLibrary !== 'function') throw new Error('createZipCommandController 缺少 unzipWithLibrary');
32
- if (!Array.isArray(DEFAULT_EXTRACT_SUFFIXES)) throw new Error('createZipCommandController 缺少 DEFAULT_EXTRACT_SUFFIXES');
33
- if (!Number.isFinite(MAX_SKILLS_ZIP_ENTRY_COUNT)) throw new Error('createZipCommandController 缺少 MAX_SKILLS_ZIP_ENTRY_COUNT');
34
- if (!Number.isFinite(MAX_SKILLS_ZIP_UNCOMPRESSED_BYTES)) throw new Error('createZipCommandController 缺少 MAX_SKILLS_ZIP_UNCOMPRESSED_BYTES');
35
-
36
- async function cmdZip(targetPath, options = {}) {
37
- if (!targetPath) {
38
- console.error('用法: codexmate zip <文件或文件夹路径> [--max:压缩级别]');
39
- console.log('\n示例:');
40
- console.log(' codexmate zip ./myproject');
41
- console.log(' codexmate zip ./myproject --max:9');
42
- console.log(' codexmate zip D:/data/folder --max:1');
43
- console.log('\n压缩级别: 0(仅存储) ~ 9(极限压缩), 默认: 5');
44
- process.exit(1);
45
- }
46
-
47
- const absPath = path.resolve(targetPath);
48
- if (!fs.existsSync(absPath)) {
49
- console.error('错误: 路径不存在:', absPath);
50
- process.exit(1);
51
- }
52
-
53
- const compressionLevel = options.max !== undefined ? options.max : 5;
54
- if (compressionLevel < 0 || compressionLevel > 9) {
55
- console.error('错误: 压缩级别必须在 0-9 之间');
56
- process.exit(1);
57
- }
58
-
59
- const baseName = path.basename(absPath);
60
- const outputDir = path.dirname(absPath);
61
- const outputPath = path.join(outputDir, `${baseName}.zip`);
62
-
63
- const zipTool = resolveZipTool();
64
- const useZipCmd = zipTool.type === 'zip';
65
-
66
- console.log('\n压缩配置:');
67
- console.log(' 源路径:', absPath);
68
- console.log(' 输出文件:', outputPath);
69
- console.log(' 压缩工具:', useZipCmd ? '系统 zip' : 'zip-lib');
70
- if (useZipCmd) {
71
- console.log(' 压缩级别:', compressionLevel);
72
- } else {
73
- console.log(' 压缩级别: 固定(zip-lib 不支持 --max,已忽略)');
74
- }
75
- console.log('\n开始压缩...\n');
76
-
77
- try {
78
- if (useZipCmd) {
79
- const cmd = `"${zipTool.cmd}" -${compressionLevel} -q -r "${outputPath}" "${absPath}"`;
80
- execSync(cmd, { stdio: 'ignore' });
81
- } else {
82
- await zipWithLibrary(absPath, outputPath);
83
- }
84
-
85
- console.log('✓ 压缩完成!');
86
- console.log(' 输出文件:', outputPath);
87
- console.log();
88
- } catch (e) {
89
- console.error('压缩失败:', e.message);
90
- process.exit(1);
91
- }
92
- }
93
-
94
- async function cmdUnzip(zipPath, outputDir) {
95
- if (!zipPath) {
96
- console.error('用法: codexmate unzip <zip文件路径> [输出目录]');
97
- console.log('\n示例:');
98
- console.log(' codexmate unzip ./archive.zip');
99
- console.log(' codexmate unzip ./archive.zip ./output');
100
- console.log(' codexmate unzip D:/data/file.zip D:/extracted');
101
- process.exit(1);
102
- }
103
-
104
- const absZipPath = path.resolve(zipPath);
105
- if (!fs.existsSync(absZipPath)) {
106
- console.error('错误: 文件不存在:', absZipPath);
107
- process.exit(1);
108
- }
109
-
110
- if (!absZipPath.toLowerCase().endsWith('.zip')) {
111
- console.error('错误: 仅支持 .zip 文件');
112
- process.exit(1);
113
- }
114
-
115
- const baseName = path.basename(absZipPath, '.zip');
116
- const defaultOutputDir = path.join(path.dirname(absZipPath), baseName);
117
- const absOutputDir = outputDir ? path.resolve(outputDir) : defaultOutputDir;
118
-
119
- resolveUnzipTool();
120
-
121
- console.log('\n解压配置:');
122
- console.log(' 源文件:', absZipPath);
123
- console.log(' 输出目录:', absOutputDir);
124
- console.log(' 解压工具:', 'zip-lib');
125
- console.log('\n开始解压...\n');
126
-
127
- try {
128
- await unzipWithLibrary(absZipPath, absOutputDir);
129
- console.log('✓ 解压完成!');
130
- console.log(' 输出目录:', absOutputDir);
131
- console.log();
132
- } catch (e) {
133
- console.error('解压失败:', e.message);
134
- process.exit(1);
135
- }
136
- }
137
-
138
- function splitExtractSuffixInput(rawValue) {
139
- if (Array.isArray(rawValue)) {
140
- return rawValue.flatMap((item) => splitExtractSuffixInput(item));
141
- }
142
- if (typeof rawValue !== 'string') {
143
- return [];
144
- }
145
- return rawValue
146
- .split(/[,\s]+/g)
147
- .map((item) => item.trim())
148
- .filter(Boolean);
149
- }
150
-
151
- function normalizeExtractSuffix(rawSuffix, fallbackSuffixes = DEFAULT_EXTRACT_SUFFIXES) {
152
- const fallbackItems = splitExtractSuffixInput(fallbackSuffixes);
153
- const sourceItems = splitExtractSuffixInput(rawSuffix);
154
- const source = sourceItems.length > 0 ? sourceItems : fallbackItems;
155
- const dedup = new Set();
156
-
157
- for (const item of source) {
158
- const lower = item.toLowerCase();
159
- if (!lower) {
160
- continue;
161
- }
162
- const normalized = lower.startsWith('.') ? lower : `.${lower}`;
163
- if (normalized.length > 1) {
164
- dedup.add(normalized);
165
- }
166
- }
167
-
168
- if (dedup.size === 0) {
169
- return [...DEFAULT_EXTRACT_SUFFIXES];
170
- }
171
- return Array.from(dedup);
172
- }
173
-
174
- function buildDefaultExtractOutputDir(baseCwd = process.cwd()) {
175
- const normalizedCwd = path.resolve(baseCwd);
176
- const parentDir = path.dirname(normalizedCwd);
177
- const timestamp = formatTimestampForFileName().replace(/-/g, '');
178
- return path.join(parentDir, timestamp);
179
- }
180
-
181
- function sanitizeNameSegment(rawValue, fallback = 'item') {
182
- const value = typeof rawValue === 'string' ? rawValue.trim() : '';
183
- const sanitized = value
184
- .replace(/[^\w.-]+/g, '_')
185
- .replace(/^_+|_+$/g, '');
186
- return sanitized || fallback;
187
- }
188
-
189
- function resolveDuplicateOutputPath(outputDir, originalFileName, zipPath = '', counters = new Map()) {
190
- const fallbackName = `file${path.extname(originalFileName || '')}`;
191
- const fileName = path.basename(originalFileName || '') || fallbackName;
192
- const firstChoice = path.join(outputDir, fileName);
193
- const firstChoiceKey = `exact:${fileName}`;
194
- if (!counters.has(firstChoiceKey)) {
195
- counters.set(firstChoiceKey, true);
196
- if (!fs.existsSync(firstChoice)) {
197
- return firstChoice;
198
- }
199
- }
200
-
201
- const ext = path.extname(fileName);
202
- const baseName = path.basename(fileName, ext);
203
- const safeBaseName = sanitizeNameSegment(baseName, 'file');
204
- const zipBaseName = sanitizeNameSegment(path.basename(zipPath || '', '.zip'), 'zip');
205
- const duplicateKey = `dup:${safeBaseName}|${zipBaseName}|${ext}`;
206
- let index = counters.has(duplicateKey) ? counters.get(duplicateKey) : 1;
207
-
208
- for (; index <= 100000; index++) {
209
- const candidateName = `${safeBaseName}__${zipBaseName}__${index}${ext}`;
210
- const candidatePath = path.join(outputDir, candidateName);
211
- if (!fs.existsSync(candidatePath)) {
212
- counters.set(duplicateKey, index + 1);
213
- return candidatePath;
214
- }
215
- }
216
-
217
- throw new Error(`重名文件过多,无法生成唯一文件名: ${fileName}`);
218
- }
219
-
220
- function collectZipFilesFromDir(rootDir, recursive = true) {
221
- const queue = [rootDir];
222
- const result = [];
223
-
224
- while (queue.length > 0) {
225
- const currentDir = queue.shift();
226
- let entries = [];
227
- try {
228
- entries = fs.readdirSync(currentDir, { withFileTypes: true });
229
- } catch (e) {
230
- throw new Error(`读取目录失败: ${currentDir} (${e.message})`);
231
- }
232
-
233
- for (const entry of entries) {
234
- const entryPath = path.join(currentDir, entry.name);
235
- if (entry.isDirectory()) {
236
- if (recursive) {
237
- queue.push(entryPath);
238
- }
239
- continue;
240
- }
241
- if (entry.isFile() && entry.name.toLowerCase().endsWith('.zip')) {
242
- result.push(entryPath);
243
- }
244
- }
245
- }
246
-
247
- result.sort((a, b) => a.localeCompare(b));
248
- return result;
249
- }
250
-
251
- function extractMatchedEntriesFromZip(zipPath, outputDir, suffixes, duplicateCounters = new Map()) {
252
- const normalizedSuffixes = normalizeExtractSuffix(suffixes);
253
- return new Promise((resolve, reject) => {
254
- yauzl.open(zipPath, { lazyEntries: true, autoClose: false }, (openErr, zipFile) => {
255
- if (openErr) {
256
- reject(openErr);
257
- return;
258
- }
259
- if (!zipFile) {
260
- reject(new Error('无法读取 ZIP 文件'));
261
- return;
262
- }
263
-
264
- let settled = false;
265
- let matched = 0;
266
- let extracted = 0;
267
- let skippedDir = 0;
268
- let skippedExt = 0;
269
-
270
- const finish = (err) => {
271
- if (settled) return;
272
- settled = true;
273
- try {
274
- zipFile.close();
275
- } catch (_) {}
276
- if (err) {
277
- reject(err);
278
- } else {
279
- resolve({ matched, extracted, skippedDir, skippedExt });
280
- }
281
- };
282
-
283
- zipFile.on('entry', (entry) => {
284
- if (settled) return;
285
- const rawEntryName = typeof entry.fileName === 'string' ? entry.fileName : '';
286
- const normalizedEntryName = rawEntryName.replace(/\\/g, '/');
287
-
288
- if (!normalizedEntryName || normalizedEntryName.endsWith('/')) {
289
- skippedDir += 1;
290
- zipFile.readEntry();
291
- return;
292
- }
293
-
294
- const entryBaseName = path.basename(normalizedEntryName);
295
- const lowerBaseName = entryBaseName.toLowerCase();
296
- const matchedSuffix = normalizedSuffixes.some((suffix) => lowerBaseName.endsWith(suffix));
297
- if (!entryBaseName || !matchedSuffix) {
298
- skippedExt += 1;
299
- zipFile.readEntry();
300
- return;
301
- }
302
-
303
- matched += 1;
304
- zipFile.openReadStream(entry, (streamErr, readStream) => {
305
- if (streamErr || !readStream) {
306
- finish(streamErr || new Error('无法读取 ZIP 条目流'));
307
- return;
308
- }
309
-
310
- let completed = false;
311
- const outputPath = resolveDuplicateOutputPath(outputDir, entryBaseName, zipPath, duplicateCounters);
312
- const writeStream = fs.createWriteStream(outputPath);
313
- const fail = (writeErr) => {
314
- if (completed) return;
315
- completed = true;
316
- try {
317
- readStream.destroy();
318
- } catch (_) {}
319
- try {
320
- writeStream.destroy();
321
- } catch (_) {}
322
- try {
323
- if (fs.existsSync(outputPath)) {
324
- fs.unlinkSync(outputPath);
325
- }
326
- } catch (_) {}
327
- finish(writeErr);
328
- };
329
-
330
- readStream.on('error', fail);
331
- writeStream.on('error', fail);
332
- writeStream.on('finish', () => {
333
- if (completed || settled) return;
334
- completed = true;
335
- extracted += 1;
336
- zipFile.readEntry();
337
- });
338
-
339
- readStream.pipe(writeStream);
340
- });
341
- });
342
-
343
- zipFile.on('end', () => {
344
- finish(null);
345
- });
346
- zipFile.on('error', (zipErr) => {
347
- finish(zipErr);
348
- });
349
-
350
- zipFile.readEntry();
351
- });
352
- });
353
- }
354
-
355
- async function cmdUnzipExt(zipDirPath, outputDir, options = {}) {
356
- if (!zipDirPath) {
357
- console.error('用法: codexmate unzip-ext <zip目录> [输出目录] [--ext:后缀[,后缀...]] [--no-recursive]');
358
- console.log('\n示例:');
359
- console.log(' codexmate unzip-ext ./archives');
360
- console.log(' codexmate unzip-ext ./archives ./output --ext:json,txt');
361
- console.log(' codexmate unzip-ext D:/data/zips --ext:txt --no-recursive');
362
- console.log(' 说明: 默认递归扫描子目录,可通过 --no-recursive 关闭递归');
363
- process.exit(1);
364
- }
365
-
366
- const recursive = options.recursive !== false;
367
- const suffixes = normalizeExtractSuffix(options.ext);
368
- const absZipDir = path.resolve(zipDirPath);
369
- const absOutputDir = outputDir ? path.resolve(outputDir) : buildDefaultExtractOutputDir(process.cwd());
370
-
371
- if (!fs.existsSync(absZipDir)) {
372
- console.error('错误: 目录不存在:', absZipDir);
373
- process.exit(1);
374
- }
375
- try {
376
- if (!fs.statSync(absZipDir).isDirectory()) {
377
- console.error('错误: 仅支持目录路径:', absZipDir);
378
- process.exit(1);
379
- }
380
- } catch (e) {
381
- console.error('错误: 无法读取目录信息:', e.message);
382
- process.exit(1);
383
- }
384
-
385
- let zipFiles = [];
386
- try {
387
- zipFiles = collectZipFilesFromDir(absZipDir, recursive);
388
- } catch (e) {
389
- console.error('扫描 ZIP 文件失败:', e.message);
390
- process.exit(1);
391
- }
392
-
393
- if (zipFiles.length === 0) {
394
- console.error('错误: 未找到任何 ZIP 文件');
395
- process.exit(1);
396
- }
397
-
398
- ensureDir(absOutputDir);
399
-
400
- console.log('\n批量解压配置:');
401
- console.log(' ZIP 目录:', absZipDir);
402
- console.log(' 输出目录:', absOutputDir);
403
- console.log(' 后缀过滤:', suffixes.join(', '));
404
- console.log(' 递归扫描:', recursive ? '是' : '否');
405
- console.log(' ZIP 数量:', zipFiles.length);
406
- console.log('\n开始提取...\n');
407
-
408
- let totalMatched = 0;
409
- let totalExtracted = 0;
410
- let totalSkippedDir = 0;
411
- let totalSkippedExt = 0;
412
- const failed = [];
413
- const duplicateCounters = new Map();
414
-
415
- for (const zipFilePath of zipFiles) {
416
- try {
417
- await inspectZipArchiveLimits(zipFilePath, {
418
- maxEntryCount: MAX_SKILLS_ZIP_ENTRY_COUNT,
419
- maxUncompressedBytes: MAX_SKILLS_ZIP_UNCOMPRESSED_BYTES
420
- });
421
- const result = await extractMatchedEntriesFromZip(zipFilePath, absOutputDir, suffixes, duplicateCounters);
422
- totalMatched += result.matched;
423
- totalExtracted += result.extracted;
424
- totalSkippedDir += result.skippedDir;
425
- totalSkippedExt += result.skippedExt;
426
- console.log(`✓ ${path.basename(zipFilePath)}: 命中 ${result.matched},提取 ${result.extracted}`);
427
- } catch (e) {
428
- failed.push({ zipFilePath, message: e && e.message ? e.message : String(e) });
429
- console.error(`✗ ${path.basename(zipFilePath)}: ${e && e.message ? e.message : e}`);
430
- }
431
- }
432
-
433
- console.log('\n提取结果:');
434
- console.log(' 输出目录:', absOutputDir);
435
- console.log(' 扫描 ZIP:', zipFiles.length);
436
- console.log(' 命中条目:', totalMatched);
437
- console.log(' 已提取:', totalExtracted);
438
- console.log(' 已跳过(目录条目):', totalSkippedDir);
439
- console.log(' 已跳过(后缀不匹配):', totalSkippedExt);
440
- if (failed.length > 0) {
441
- console.error(' 失败数量:', failed.length);
442
- for (const item of failed) {
443
- console.error(` - ${item.zipFilePath}: ${item.message}`);
444
- }
445
- process.exit(1);
446
- }
447
- console.log();
448
- }
449
-
450
- function parseZipCommandArgs(args = []) {
451
- const options = {};
452
- let targetPath = null;
453
- for (let i = 0; i < args.length; i++) {
454
- const arg = args[i];
455
- if (typeof arg !== 'string' || !arg) continue;
456
- if (arg.startsWith('--max:')) {
457
- options.max = parseInt(arg.substring(6), 10);
458
- } else if (!targetPath) {
459
- targetPath = arg;
460
- }
461
- }
462
- return { targetPath, options };
463
- }
464
-
465
- function parseUnzipExtCommandArgs(args = []) {
466
- const options = {
467
- ext: [],
468
- recursive: true
469
- };
470
- let zipDirPath = null;
471
- let outputDir = null;
472
- for (let i = 0; i < args.length; i++) {
473
- const arg = args[i];
474
- if (typeof arg !== 'string' || !arg) continue;
475
- if (arg.startsWith('--ext:')) {
476
- options.ext.push(...splitExtractSuffixInput(arg.substring(6)));
477
- } else if (arg.startsWith('--ext=')) {
478
- options.ext.push(...splitExtractSuffixInput(arg.substring(6)));
479
- } else if (arg === '--ext') {
480
- const nextArg = args[i + 1];
481
- if (typeof nextArg === 'string' && !nextArg.startsWith('--')) {
482
- options.ext.push(...splitExtractSuffixInput(nextArg));
483
- i += 1;
484
- }
485
- } else if (arg === '--recursive') {
486
- options.recursive = true;
487
- } else if (arg === '--no-recursive') {
488
- options.recursive = false;
489
- } else if (!zipDirPath) {
490
- zipDirPath = arg;
491
- } else if (!outputDir) {
492
- outputDir = arg;
493
- }
494
- }
495
- return { zipDirPath, outputDir, options };
496
- }
497
-
498
- return {
499
- cmdZip,
500
- cmdUnzip,
501
- cmdUnzipExt,
502
- splitExtractSuffixInput,
503
- parseZipCommandArgs,
504
- parseUnzipExtCommandArgs
505
- };
506
- }
507
-
508
- module.exports = {
509
- createZipCommandController
510
- };
1
+ function createZipCommandController(deps = {}) {
2
+ const {
3
+ fs,
4
+ path,
5
+ execSync,
6
+ process,
7
+ yauzl,
8
+ ensureDir,
9
+ formatTimestampForFileName,
10
+ inspectZipArchiveLimits,
11
+ resolveZipTool,
12
+ resolveUnzipTool,
13
+ zipWithLibrary,
14
+ unzipWithLibrary,
15
+ DEFAULT_EXTRACT_SUFFIXES,
16
+ MAX_SKILLS_ZIP_ENTRY_COUNT,
17
+ MAX_SKILLS_ZIP_UNCOMPRESSED_BYTES,
18
+ } = deps;
19
+
20
+ if (!fs) throw new Error('createZipCommandController 缺少 fs');
21
+ if (!path) throw new Error('createZipCommandController 缺少 path');
22
+ if (typeof execSync !== 'function') throw new Error('createZipCommandController 缺少 execSync');
23
+ if (!process) throw new Error('createZipCommandController 缺少 process');
24
+ if (!yauzl) throw new Error('createZipCommandController 缺少 yauzl');
25
+ if (typeof ensureDir !== 'function') throw new Error('createZipCommandController 缺少 ensureDir');
26
+ if (typeof formatTimestampForFileName !== 'function') throw new Error('createZipCommandController 缺少 formatTimestampForFileName');
27
+ if (typeof inspectZipArchiveLimits !== 'function') throw new Error('createZipCommandController 缺少 inspectZipArchiveLimits');
28
+ if (typeof resolveZipTool !== 'function') throw new Error('createZipCommandController 缺少 resolveZipTool');
29
+ if (typeof resolveUnzipTool !== 'function') throw new Error('createZipCommandController 缺少 resolveUnzipTool');
30
+ if (typeof zipWithLibrary !== 'function') throw new Error('createZipCommandController 缺少 zipWithLibrary');
31
+ if (typeof unzipWithLibrary !== 'function') throw new Error('createZipCommandController 缺少 unzipWithLibrary');
32
+ if (!Array.isArray(DEFAULT_EXTRACT_SUFFIXES)) throw new Error('createZipCommandController 缺少 DEFAULT_EXTRACT_SUFFIXES');
33
+ if (!Number.isFinite(MAX_SKILLS_ZIP_ENTRY_COUNT)) throw new Error('createZipCommandController 缺少 MAX_SKILLS_ZIP_ENTRY_COUNT');
34
+ if (!Number.isFinite(MAX_SKILLS_ZIP_UNCOMPRESSED_BYTES)) throw new Error('createZipCommandController 缺少 MAX_SKILLS_ZIP_UNCOMPRESSED_BYTES');
35
+
36
+ async function cmdZip(targetPath, options = {}) {
37
+ if (!targetPath) {
38
+ console.error('用法: codexmate zip <文件或文件夹路径> [--max:压缩级别]');
39
+ console.log('\n示例:');
40
+ console.log(' codexmate zip ./myproject');
41
+ console.log(' codexmate zip ./myproject --max:9');
42
+ console.log(' codexmate zip D:/data/folder --max:1');
43
+ console.log('\n压缩级别: 0(仅存储) ~ 9(极限压缩), 默认: 5');
44
+ process.exit(1);
45
+ }
46
+
47
+ const absPath = path.resolve(targetPath);
48
+ if (!fs.existsSync(absPath)) {
49
+ console.error('错误: 路径不存在:', absPath);
50
+ process.exit(1);
51
+ }
52
+
53
+ const compressionLevel = options.max !== undefined ? options.max : 5;
54
+ if (compressionLevel < 0 || compressionLevel > 9) {
55
+ console.error('错误: 压缩级别必须在 0-9 之间');
56
+ process.exit(1);
57
+ }
58
+
59
+ const baseName = path.basename(absPath);
60
+ const outputDir = path.dirname(absPath);
61
+ const outputPath = path.join(outputDir, `${baseName}.zip`);
62
+
63
+ const zipTool = resolveZipTool();
64
+ const useZipCmd = zipTool.type === 'zip';
65
+
66
+ console.log('\n压缩配置:');
67
+ console.log(' 源路径:', absPath);
68
+ console.log(' 输出文件:', outputPath);
69
+ console.log(' 压缩工具:', useZipCmd ? '系统 zip' : 'zip-lib');
70
+ if (useZipCmd) {
71
+ console.log(' 压缩级别:', compressionLevel);
72
+ } else {
73
+ console.log(' 压缩级别: 固定(zip-lib 不支持 --max,已忽略)');
74
+ }
75
+ console.log('\n开始压缩...\n');
76
+
77
+ try {
78
+ if (useZipCmd) {
79
+ const cmd = `"${zipTool.cmd}" -${compressionLevel} -q -r "${outputPath}" "${absPath}"`;
80
+ execSync(cmd, { stdio: 'ignore' });
81
+ } else {
82
+ await zipWithLibrary(absPath, outputPath);
83
+ }
84
+
85
+ console.log('✓ 压缩完成!');
86
+ console.log(' 输出文件:', outputPath);
87
+ console.log();
88
+ } catch (e) {
89
+ console.error('压缩失败:', e.message);
90
+ process.exit(1);
91
+ }
92
+ }
93
+
94
+ async function cmdUnzip(zipPath, outputDir) {
95
+ if (!zipPath) {
96
+ console.error('用法: codexmate unzip <zip文件路径> [输出目录]');
97
+ console.log('\n示例:');
98
+ console.log(' codexmate unzip ./archive.zip');
99
+ console.log(' codexmate unzip ./archive.zip ./output');
100
+ console.log(' codexmate unzip D:/data/file.zip D:/extracted');
101
+ process.exit(1);
102
+ }
103
+
104
+ const absZipPath = path.resolve(zipPath);
105
+ if (!fs.existsSync(absZipPath)) {
106
+ console.error('错误: 文件不存在:', absZipPath);
107
+ process.exit(1);
108
+ }
109
+
110
+ if (!absZipPath.toLowerCase().endsWith('.zip')) {
111
+ console.error('错误: 仅支持 .zip 文件');
112
+ process.exit(1);
113
+ }
114
+
115
+ const baseName = path.basename(absZipPath, '.zip');
116
+ const defaultOutputDir = path.join(path.dirname(absZipPath), baseName);
117
+ const absOutputDir = outputDir ? path.resolve(outputDir) : defaultOutputDir;
118
+
119
+ resolveUnzipTool();
120
+
121
+ console.log('\n解压配置:');
122
+ console.log(' 源文件:', absZipPath);
123
+ console.log(' 输出目录:', absOutputDir);
124
+ console.log(' 解压工具:', 'zip-lib');
125
+ console.log('\n开始解压...\n');
126
+
127
+ try {
128
+ await unzipWithLibrary(absZipPath, absOutputDir);
129
+ console.log('✓ 解压完成!');
130
+ console.log(' 输出目录:', absOutputDir);
131
+ console.log();
132
+ } catch (e) {
133
+ console.error('解压失败:', e.message);
134
+ process.exit(1);
135
+ }
136
+ }
137
+
138
+ function splitExtractSuffixInput(rawValue) {
139
+ if (Array.isArray(rawValue)) {
140
+ return rawValue.flatMap((item) => splitExtractSuffixInput(item));
141
+ }
142
+ if (typeof rawValue !== 'string') {
143
+ return [];
144
+ }
145
+ return rawValue
146
+ .split(/[,\s]+/g)
147
+ .map((item) => item.trim())
148
+ .filter(Boolean);
149
+ }
150
+
151
+ function normalizeExtractSuffix(rawSuffix, fallbackSuffixes = DEFAULT_EXTRACT_SUFFIXES) {
152
+ const fallbackItems = splitExtractSuffixInput(fallbackSuffixes);
153
+ const sourceItems = splitExtractSuffixInput(rawSuffix);
154
+ const source = sourceItems.length > 0 ? sourceItems : fallbackItems;
155
+ const dedup = new Set();
156
+
157
+ for (const item of source) {
158
+ const lower = item.toLowerCase();
159
+ if (!lower) {
160
+ continue;
161
+ }
162
+ const normalized = lower.startsWith('.') ? lower : `.${lower}`;
163
+ if (normalized.length > 1) {
164
+ dedup.add(normalized);
165
+ }
166
+ }
167
+
168
+ if (dedup.size === 0) {
169
+ return [...DEFAULT_EXTRACT_SUFFIXES];
170
+ }
171
+ return Array.from(dedup);
172
+ }
173
+
174
+ function buildDefaultExtractOutputDir(baseCwd = process.cwd()) {
175
+ const normalizedCwd = path.resolve(baseCwd);
176
+ const parentDir = path.dirname(normalizedCwd);
177
+ const timestamp = formatTimestampForFileName().replace(/-/g, '');
178
+ return path.join(parentDir, timestamp);
179
+ }
180
+
181
+ function sanitizeNameSegment(rawValue, fallback = 'item') {
182
+ const value = typeof rawValue === 'string' ? rawValue.trim() : '';
183
+ const sanitized = value
184
+ .replace(/[^\w.-]+/g, '_')
185
+ .replace(/^_+|_+$/g, '');
186
+ return sanitized || fallback;
187
+ }
188
+
189
+ function resolveDuplicateOutputPath(outputDir, originalFileName, zipPath = '', counters = new Map()) {
190
+ const fallbackName = `file${path.extname(originalFileName || '')}`;
191
+ const fileName = path.basename(originalFileName || '') || fallbackName;
192
+ const firstChoice = path.join(outputDir, fileName);
193
+ const firstChoiceKey = `exact:${fileName}`;
194
+ if (!counters.has(firstChoiceKey)) {
195
+ counters.set(firstChoiceKey, true);
196
+ if (!fs.existsSync(firstChoice)) {
197
+ return firstChoice;
198
+ }
199
+ }
200
+
201
+ const ext = path.extname(fileName);
202
+ const baseName = path.basename(fileName, ext);
203
+ const safeBaseName = sanitizeNameSegment(baseName, 'file');
204
+ const zipBaseName = sanitizeNameSegment(path.basename(zipPath || '', '.zip'), 'zip');
205
+ const duplicateKey = `dup:${safeBaseName}|${zipBaseName}|${ext}`;
206
+ let index = counters.has(duplicateKey) ? counters.get(duplicateKey) : 1;
207
+
208
+ for (; index <= 100000; index++) {
209
+ const candidateName = `${safeBaseName}__${zipBaseName}__${index}${ext}`;
210
+ const candidatePath = path.join(outputDir, candidateName);
211
+ if (!fs.existsSync(candidatePath)) {
212
+ counters.set(duplicateKey, index + 1);
213
+ return candidatePath;
214
+ }
215
+ }
216
+
217
+ throw new Error(`重名文件过多,无法生成唯一文件名: ${fileName}`);
218
+ }
219
+
220
+ function collectZipFilesFromDir(rootDir, recursive = true) {
221
+ const queue = [rootDir];
222
+ const result = [];
223
+
224
+ while (queue.length > 0) {
225
+ const currentDir = queue.shift();
226
+ let entries = [];
227
+ try {
228
+ entries = fs.readdirSync(currentDir, { withFileTypes: true });
229
+ } catch (e) {
230
+ throw new Error(`读取目录失败: ${currentDir} (${e.message})`);
231
+ }
232
+
233
+ for (const entry of entries) {
234
+ const entryPath = path.join(currentDir, entry.name);
235
+ if (entry.isDirectory()) {
236
+ if (recursive) {
237
+ queue.push(entryPath);
238
+ }
239
+ continue;
240
+ }
241
+ if (entry.isFile() && entry.name.toLowerCase().endsWith('.zip')) {
242
+ result.push(entryPath);
243
+ }
244
+ }
245
+ }
246
+
247
+ result.sort((a, b) => a.localeCompare(b));
248
+ return result;
249
+ }
250
+
251
+ function extractMatchedEntriesFromZip(zipPath, outputDir, suffixes, duplicateCounters = new Map()) {
252
+ const normalizedSuffixes = normalizeExtractSuffix(suffixes);
253
+ return new Promise((resolve, reject) => {
254
+ yauzl.open(zipPath, { lazyEntries: true, autoClose: false }, (openErr, zipFile) => {
255
+ if (openErr) {
256
+ reject(openErr);
257
+ return;
258
+ }
259
+ if (!zipFile) {
260
+ reject(new Error('无法读取 ZIP 文件'));
261
+ return;
262
+ }
263
+
264
+ let settled = false;
265
+ let matched = 0;
266
+ let extracted = 0;
267
+ let skippedDir = 0;
268
+ let skippedExt = 0;
269
+
270
+ const finish = (err) => {
271
+ if (settled) return;
272
+ settled = true;
273
+ try {
274
+ zipFile.close();
275
+ } catch (_) {}
276
+ if (err) {
277
+ reject(err);
278
+ } else {
279
+ resolve({ matched, extracted, skippedDir, skippedExt });
280
+ }
281
+ };
282
+
283
+ zipFile.on('entry', (entry) => {
284
+ if (settled) return;
285
+ const rawEntryName = typeof entry.fileName === 'string' ? entry.fileName : '';
286
+ const normalizedEntryName = rawEntryName.replace(/\\/g, '/');
287
+
288
+ if (!normalizedEntryName || normalizedEntryName.endsWith('/')) {
289
+ skippedDir += 1;
290
+ zipFile.readEntry();
291
+ return;
292
+ }
293
+
294
+ const entryBaseName = path.basename(normalizedEntryName);
295
+ const lowerBaseName = entryBaseName.toLowerCase();
296
+ const matchedSuffix = normalizedSuffixes.some((suffix) => lowerBaseName.endsWith(suffix));
297
+ if (!entryBaseName || !matchedSuffix) {
298
+ skippedExt += 1;
299
+ zipFile.readEntry();
300
+ return;
301
+ }
302
+
303
+ matched += 1;
304
+ zipFile.openReadStream(entry, (streamErr, readStream) => {
305
+ if (streamErr || !readStream) {
306
+ finish(streamErr || new Error('无法读取 ZIP 条目流'));
307
+ return;
308
+ }
309
+
310
+ let completed = false;
311
+ const outputPath = resolveDuplicateOutputPath(outputDir, entryBaseName, zipPath, duplicateCounters);
312
+ const writeStream = fs.createWriteStream(outputPath);
313
+ const fail = (writeErr) => {
314
+ if (completed) return;
315
+ completed = true;
316
+ try {
317
+ readStream.destroy();
318
+ } catch (_) {}
319
+ try {
320
+ writeStream.destroy();
321
+ } catch (_) {}
322
+ try {
323
+ if (fs.existsSync(outputPath)) {
324
+ fs.unlinkSync(outputPath);
325
+ }
326
+ } catch (_) {}
327
+ finish(writeErr);
328
+ };
329
+
330
+ readStream.on('error', fail);
331
+ writeStream.on('error', fail);
332
+ writeStream.on('finish', () => {
333
+ if (completed || settled) return;
334
+ completed = true;
335
+ extracted += 1;
336
+ zipFile.readEntry();
337
+ });
338
+
339
+ readStream.pipe(writeStream);
340
+ });
341
+ });
342
+
343
+ zipFile.on('end', () => {
344
+ finish(null);
345
+ });
346
+ zipFile.on('error', (zipErr) => {
347
+ finish(zipErr);
348
+ });
349
+
350
+ zipFile.readEntry();
351
+ });
352
+ });
353
+ }
354
+
355
+ async function cmdUnzipExt(zipDirPath, outputDir, options = {}) {
356
+ if (!zipDirPath) {
357
+ console.error('用法: codexmate unzip-ext <zip目录> [输出目录] [--ext:后缀[,后缀...]] [--no-recursive]');
358
+ console.log('\n示例:');
359
+ console.log(' codexmate unzip-ext ./archives');
360
+ console.log(' codexmate unzip-ext ./archives ./output --ext:json,txt');
361
+ console.log(' codexmate unzip-ext D:/data/zips --ext:txt --no-recursive');
362
+ console.log(' 说明: 默认递归扫描子目录,可通过 --no-recursive 关闭递归');
363
+ process.exit(1);
364
+ }
365
+
366
+ const recursive = options.recursive !== false;
367
+ const suffixes = normalizeExtractSuffix(options.ext);
368
+ const absZipDir = path.resolve(zipDirPath);
369
+ const absOutputDir = outputDir ? path.resolve(outputDir) : buildDefaultExtractOutputDir(process.cwd());
370
+
371
+ if (!fs.existsSync(absZipDir)) {
372
+ console.error('错误: 目录不存在:', absZipDir);
373
+ process.exit(1);
374
+ }
375
+ try {
376
+ if (!fs.statSync(absZipDir).isDirectory()) {
377
+ console.error('错误: 仅支持目录路径:', absZipDir);
378
+ process.exit(1);
379
+ }
380
+ } catch (e) {
381
+ console.error('错误: 无法读取目录信息:', e.message);
382
+ process.exit(1);
383
+ }
384
+
385
+ let zipFiles = [];
386
+ try {
387
+ zipFiles = collectZipFilesFromDir(absZipDir, recursive);
388
+ } catch (e) {
389
+ console.error('扫描 ZIP 文件失败:', e.message);
390
+ process.exit(1);
391
+ }
392
+
393
+ if (zipFiles.length === 0) {
394
+ console.error('错误: 未找到任何 ZIP 文件');
395
+ process.exit(1);
396
+ }
397
+
398
+ ensureDir(absOutputDir);
399
+
400
+ console.log('\n批量解压配置:');
401
+ console.log(' ZIP 目录:', absZipDir);
402
+ console.log(' 输出目录:', absOutputDir);
403
+ console.log(' 后缀过滤:', suffixes.join(', '));
404
+ console.log(' 递归扫描:', recursive ? '是' : '否');
405
+ console.log(' ZIP 数量:', zipFiles.length);
406
+ console.log('\n开始提取...\n');
407
+
408
+ let totalMatched = 0;
409
+ let totalExtracted = 0;
410
+ let totalSkippedDir = 0;
411
+ let totalSkippedExt = 0;
412
+ const failed = [];
413
+ const duplicateCounters = new Map();
414
+
415
+ for (const zipFilePath of zipFiles) {
416
+ try {
417
+ await inspectZipArchiveLimits(zipFilePath, {
418
+ maxEntryCount: MAX_SKILLS_ZIP_ENTRY_COUNT,
419
+ maxUncompressedBytes: MAX_SKILLS_ZIP_UNCOMPRESSED_BYTES
420
+ });
421
+ const result = await extractMatchedEntriesFromZip(zipFilePath, absOutputDir, suffixes, duplicateCounters);
422
+ totalMatched += result.matched;
423
+ totalExtracted += result.extracted;
424
+ totalSkippedDir += result.skippedDir;
425
+ totalSkippedExt += result.skippedExt;
426
+ console.log(`✓ ${path.basename(zipFilePath)}: 命中 ${result.matched},提取 ${result.extracted}`);
427
+ } catch (e) {
428
+ failed.push({ zipFilePath, message: e && e.message ? e.message : String(e) });
429
+ console.error(`✗ ${path.basename(zipFilePath)}: ${e && e.message ? e.message : e}`);
430
+ }
431
+ }
432
+
433
+ console.log('\n提取结果:');
434
+ console.log(' 输出目录:', absOutputDir);
435
+ console.log(' 扫描 ZIP:', zipFiles.length);
436
+ console.log(' 命中条目:', totalMatched);
437
+ console.log(' 已提取:', totalExtracted);
438
+ console.log(' 已跳过(目录条目):', totalSkippedDir);
439
+ console.log(' 已跳过(后缀不匹配):', totalSkippedExt);
440
+ if (failed.length > 0) {
441
+ console.error(' 失败数量:', failed.length);
442
+ for (const item of failed) {
443
+ console.error(` - ${item.zipFilePath}: ${item.message}`);
444
+ }
445
+ process.exit(1);
446
+ }
447
+ console.log();
448
+ }
449
+
450
+ function parseZipCommandArgs(args = []) {
451
+ const options = {};
452
+ let targetPath = null;
453
+ for (let i = 0; i < args.length; i++) {
454
+ const arg = args[i];
455
+ if (typeof arg !== 'string' || !arg) continue;
456
+ if (arg.startsWith('--max:')) {
457
+ options.max = parseInt(arg.substring(6), 10);
458
+ } else if (!targetPath) {
459
+ targetPath = arg;
460
+ }
461
+ }
462
+ return { targetPath, options };
463
+ }
464
+
465
+ function parseUnzipExtCommandArgs(args = []) {
466
+ const options = {
467
+ ext: [],
468
+ recursive: true
469
+ };
470
+ let zipDirPath = null;
471
+ let outputDir = null;
472
+ for (let i = 0; i < args.length; i++) {
473
+ const arg = args[i];
474
+ if (typeof arg !== 'string' || !arg) continue;
475
+ if (arg.startsWith('--ext:')) {
476
+ options.ext.push(...splitExtractSuffixInput(arg.substring(6)));
477
+ } else if (arg.startsWith('--ext=')) {
478
+ options.ext.push(...splitExtractSuffixInput(arg.substring(6)));
479
+ } else if (arg === '--ext') {
480
+ const nextArg = args[i + 1];
481
+ if (typeof nextArg === 'string' && !nextArg.startsWith('--')) {
482
+ options.ext.push(...splitExtractSuffixInput(nextArg));
483
+ i += 1;
484
+ }
485
+ } else if (arg === '--recursive') {
486
+ options.recursive = true;
487
+ } else if (arg === '--no-recursive') {
488
+ options.recursive = false;
489
+ } else if (!zipDirPath) {
490
+ zipDirPath = arg;
491
+ } else if (!outputDir) {
492
+ outputDir = arg;
493
+ }
494
+ }
495
+ return { zipDirPath, outputDir, options };
496
+ }
497
+
498
+ return {
499
+ cmdZip,
500
+ cmdUnzip,
501
+ cmdUnzipExt,
502
+ splitExtractSuffixInput,
503
+ parseZipCommandArgs,
504
+ parseUnzipExtCommandArgs
505
+ };
506
+ }
507
+
508
+ module.exports = {
509
+ createZipCommandController
510
+ };