glosc-mcp 1.0.0

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 (169) hide show
  1. package/README.md +23 -0
  2. package/build/GloscMcp.js +207 -0
  3. package/build/GloscTools.js +495 -0
  4. package/build/index.js +12 -0
  5. package/libs/7z/Linux/7zz +0 -0
  6. package/libs/7z/Linux/7zzs +0 -0
  7. package/libs/7z/Linux/History.txt +178 -0
  8. package/libs/7z/Linux/License.txt +144 -0
  9. package/libs/7z/Linux/MANUAL/cmdline/commands/add.htm +96 -0
  10. package/libs/7z/Linux/MANUAL/cmdline/commands/bench.htm +186 -0
  11. package/libs/7z/Linux/MANUAL/cmdline/commands/delete.htm +64 -0
  12. package/libs/7z/Linux/MANUAL/cmdline/commands/extract.htm +101 -0
  13. package/libs/7z/Linux/MANUAL/cmdline/commands/extract_full.htm +77 -0
  14. package/libs/7z/Linux/MANUAL/cmdline/commands/hash.htm +101 -0
  15. package/libs/7z/Linux/MANUAL/cmdline/commands/index.htm +36 -0
  16. package/libs/7z/Linux/MANUAL/cmdline/commands/list.htm +79 -0
  17. package/libs/7z/Linux/MANUAL/cmdline/commands/rename.htm +51 -0
  18. package/libs/7z/Linux/MANUAL/cmdline/commands/style.css +232 -0
  19. package/libs/7z/Linux/MANUAL/cmdline/commands/test.htm +51 -0
  20. package/libs/7z/Linux/MANUAL/cmdline/commands/update.htm +74 -0
  21. package/libs/7z/Linux/MANUAL/cmdline/exit_codes.htm +27 -0
  22. package/libs/7z/Linux/MANUAL/cmdline/index.htm +29 -0
  23. package/libs/7z/Linux/MANUAL/cmdline/style.css +232 -0
  24. package/libs/7z/Linux/MANUAL/cmdline/switches/ar_exclude.htm +58 -0
  25. package/libs/7z/Linux/MANUAL/cmdline/switches/ar_include.htm +84 -0
  26. package/libs/7z/Linux/MANUAL/cmdline/switches/ar_no.htm +52 -0
  27. package/libs/7z/Linux/MANUAL/cmdline/switches/bb.htm +61 -0
  28. package/libs/7z/Linux/MANUAL/cmdline/switches/bs.htm +67 -0
  29. package/libs/7z/Linux/MANUAL/cmdline/switches/charset.htm +61 -0
  30. package/libs/7z/Linux/MANUAL/cmdline/switches/email.htm +43 -0
  31. package/libs/7z/Linux/MANUAL/cmdline/switches/exclude.htm +81 -0
  32. package/libs/7z/Linux/MANUAL/cmdline/switches/include.htm +152 -0
  33. package/libs/7z/Linux/MANUAL/cmdline/switches/index.htm +117 -0
  34. package/libs/7z/Linux/MANUAL/cmdline/switches/large_pages.htm +60 -0
  35. package/libs/7z/Linux/MANUAL/cmdline/switches/list_tech.htm +36 -0
  36. package/libs/7z/Linux/MANUAL/cmdline/switches/method.htm +1067 -0
  37. package/libs/7z/Linux/MANUAL/cmdline/switches/output_dir.htm +53 -0
  38. package/libs/7z/Linux/MANUAL/cmdline/switches/overwrite.htm +56 -0
  39. package/libs/7z/Linux/MANUAL/cmdline/switches/password.htm +80 -0
  40. package/libs/7z/Linux/MANUAL/cmdline/switches/recurse.htm +104 -0
  41. package/libs/7z/Linux/MANUAL/cmdline/switches/sa.htm +58 -0
  42. package/libs/7z/Linux/MANUAL/cmdline/switches/scc.htm +42 -0
  43. package/libs/7z/Linux/MANUAL/cmdline/switches/scrc.htm +54 -0
  44. package/libs/7z/Linux/MANUAL/cmdline/switches/sdel.htm +39 -0
  45. package/libs/7z/Linux/MANUAL/cmdline/switches/sfx.htm +154 -0
  46. package/libs/7z/Linux/MANUAL/cmdline/switches/shared.htm +40 -0
  47. package/libs/7z/Linux/MANUAL/cmdline/switches/sni.htm +56 -0
  48. package/libs/7z/Linux/MANUAL/cmdline/switches/sns.htm +77 -0
  49. package/libs/7z/Linux/MANUAL/cmdline/switches/spf.htm +80 -0
  50. package/libs/7z/Linux/MANUAL/cmdline/switches/spm.htm +72 -0
  51. package/libs/7z/Linux/MANUAL/cmdline/switches/ssc.htm +50 -0
  52. package/libs/7z/Linux/MANUAL/cmdline/switches/stdin.htm +56 -0
  53. package/libs/7z/Linux/MANUAL/cmdline/switches/stdout.htm +54 -0
  54. package/libs/7z/Linux/MANUAL/cmdline/switches/stl.htm +39 -0
  55. package/libs/7z/Linux/MANUAL/cmdline/switches/stop_switch.htm +32 -0
  56. package/libs/7z/Linux/MANUAL/cmdline/switches/stx.htm +50 -0
  57. package/libs/7z/Linux/MANUAL/cmdline/switches/style.css +232 -0
  58. package/libs/7z/Linux/MANUAL/cmdline/switches/type.htm +146 -0
  59. package/libs/7z/Linux/MANUAL/cmdline/switches/update.htm +179 -0
  60. package/libs/7z/Linux/MANUAL/cmdline/switches/volume.htm +49 -0
  61. package/libs/7z/Linux/MANUAL/cmdline/switches/working_dir.htm +56 -0
  62. package/libs/7z/Linux/MANUAL/cmdline/switches/yes.htm +48 -0
  63. package/libs/7z/Linux/MANUAL/cmdline/syntax.htm +118 -0
  64. package/libs/7z/Linux/MANUAL/general/7z.htm +117 -0
  65. package/libs/7z/Linux/MANUAL/general/faq.htm +125 -0
  66. package/libs/7z/Linux/MANUAL/general/formats.htm +104 -0
  67. package/libs/7z/Linux/MANUAL/general/index.htm +28 -0
  68. package/libs/7z/Linux/MANUAL/general/license.htm +26 -0
  69. package/libs/7z/Linux/MANUAL/general/performance.htm +55 -0
  70. package/libs/7z/Linux/MANUAL/general/register.htm +24 -0
  71. package/libs/7z/Linux/MANUAL/general/style.css +232 -0
  72. package/libs/7z/Linux/MANUAL/general/thanks.htm +44 -0
  73. package/libs/7z/Linux/MANUAL/start.htm +38 -0
  74. package/libs/7z/Linux/MANUAL/style.css +232 -0
  75. package/libs/7z/Linux/readme.txt +100 -0
  76. package/libs/7z/README.md +1 -0
  77. package/libs/7z/macOS/7zz +0 -0
  78. package/libs/7z/macOS/History.txt +178 -0
  79. package/libs/7z/macOS/License.txt +144 -0
  80. package/libs/7z/macOS/MANUAL/cmdline/commands/add.htm +96 -0
  81. package/libs/7z/macOS/MANUAL/cmdline/commands/bench.htm +186 -0
  82. package/libs/7z/macOS/MANUAL/cmdline/commands/delete.htm +64 -0
  83. package/libs/7z/macOS/MANUAL/cmdline/commands/extract.htm +101 -0
  84. package/libs/7z/macOS/MANUAL/cmdline/commands/extract_full.htm +77 -0
  85. package/libs/7z/macOS/MANUAL/cmdline/commands/hash.htm +101 -0
  86. package/libs/7z/macOS/MANUAL/cmdline/commands/index.htm +36 -0
  87. package/libs/7z/macOS/MANUAL/cmdline/commands/list.htm +79 -0
  88. package/libs/7z/macOS/MANUAL/cmdline/commands/rename.htm +51 -0
  89. package/libs/7z/macOS/MANUAL/cmdline/commands/style.css +232 -0
  90. package/libs/7z/macOS/MANUAL/cmdline/commands/test.htm +51 -0
  91. package/libs/7z/macOS/MANUAL/cmdline/commands/update.htm +74 -0
  92. package/libs/7z/macOS/MANUAL/cmdline/exit_codes.htm +27 -0
  93. package/libs/7z/macOS/MANUAL/cmdline/index.htm +29 -0
  94. package/libs/7z/macOS/MANUAL/cmdline/style.css +232 -0
  95. package/libs/7z/macOS/MANUAL/cmdline/switches/ar_exclude.htm +58 -0
  96. package/libs/7z/macOS/MANUAL/cmdline/switches/ar_include.htm +84 -0
  97. package/libs/7z/macOS/MANUAL/cmdline/switches/ar_no.htm +52 -0
  98. package/libs/7z/macOS/MANUAL/cmdline/switches/bb.htm +61 -0
  99. package/libs/7z/macOS/MANUAL/cmdline/switches/bs.htm +67 -0
  100. package/libs/7z/macOS/MANUAL/cmdline/switches/charset.htm +61 -0
  101. package/libs/7z/macOS/MANUAL/cmdline/switches/email.htm +43 -0
  102. package/libs/7z/macOS/MANUAL/cmdline/switches/exclude.htm +81 -0
  103. package/libs/7z/macOS/MANUAL/cmdline/switches/include.htm +152 -0
  104. package/libs/7z/macOS/MANUAL/cmdline/switches/index.htm +117 -0
  105. package/libs/7z/macOS/MANUAL/cmdline/switches/large_pages.htm +60 -0
  106. package/libs/7z/macOS/MANUAL/cmdline/switches/list_tech.htm +36 -0
  107. package/libs/7z/macOS/MANUAL/cmdline/switches/method.htm +1067 -0
  108. package/libs/7z/macOS/MANUAL/cmdline/switches/output_dir.htm +53 -0
  109. package/libs/7z/macOS/MANUAL/cmdline/switches/overwrite.htm +56 -0
  110. package/libs/7z/macOS/MANUAL/cmdline/switches/password.htm +80 -0
  111. package/libs/7z/macOS/MANUAL/cmdline/switches/recurse.htm +104 -0
  112. package/libs/7z/macOS/MANUAL/cmdline/switches/sa.htm +58 -0
  113. package/libs/7z/macOS/MANUAL/cmdline/switches/scc.htm +42 -0
  114. package/libs/7z/macOS/MANUAL/cmdline/switches/scrc.htm +54 -0
  115. package/libs/7z/macOS/MANUAL/cmdline/switches/sdel.htm +39 -0
  116. package/libs/7z/macOS/MANUAL/cmdline/switches/sfx.htm +154 -0
  117. package/libs/7z/macOS/MANUAL/cmdline/switches/shared.htm +40 -0
  118. package/libs/7z/macOS/MANUAL/cmdline/switches/sni.htm +56 -0
  119. package/libs/7z/macOS/MANUAL/cmdline/switches/sns.htm +77 -0
  120. package/libs/7z/macOS/MANUAL/cmdline/switches/spf.htm +80 -0
  121. package/libs/7z/macOS/MANUAL/cmdline/switches/spm.htm +72 -0
  122. package/libs/7z/macOS/MANUAL/cmdline/switches/ssc.htm +50 -0
  123. package/libs/7z/macOS/MANUAL/cmdline/switches/stdin.htm +56 -0
  124. package/libs/7z/macOS/MANUAL/cmdline/switches/stdout.htm +54 -0
  125. package/libs/7z/macOS/MANUAL/cmdline/switches/stl.htm +39 -0
  126. package/libs/7z/macOS/MANUAL/cmdline/switches/stop_switch.htm +32 -0
  127. package/libs/7z/macOS/MANUAL/cmdline/switches/stx.htm +50 -0
  128. package/libs/7z/macOS/MANUAL/cmdline/switches/style.css +232 -0
  129. package/libs/7z/macOS/MANUAL/cmdline/switches/type.htm +146 -0
  130. package/libs/7z/macOS/MANUAL/cmdline/switches/update.htm +179 -0
  131. package/libs/7z/macOS/MANUAL/cmdline/switches/volume.htm +49 -0
  132. package/libs/7z/macOS/MANUAL/cmdline/switches/working_dir.htm +56 -0
  133. package/libs/7z/macOS/MANUAL/cmdline/switches/yes.htm +48 -0
  134. package/libs/7z/macOS/MANUAL/cmdline/syntax.htm +118 -0
  135. package/libs/7z/macOS/MANUAL/general/7z.htm +117 -0
  136. package/libs/7z/macOS/MANUAL/general/faq.htm +125 -0
  137. package/libs/7z/macOS/MANUAL/general/formats.htm +104 -0
  138. package/libs/7z/macOS/MANUAL/general/index.htm +28 -0
  139. package/libs/7z/macOS/MANUAL/general/license.htm +26 -0
  140. package/libs/7z/macOS/MANUAL/general/performance.htm +55 -0
  141. package/libs/7z/macOS/MANUAL/general/register.htm +24 -0
  142. package/libs/7z/macOS/MANUAL/general/style.css +232 -0
  143. package/libs/7z/macOS/MANUAL/general/thanks.htm +44 -0
  144. package/libs/7z/macOS/MANUAL/start.htm +38 -0
  145. package/libs/7z/macOS/MANUAL/style.css +232 -0
  146. package/libs/7z/macOS/readme.txt +100 -0
  147. package/libs/7z/win/7za.dll +0 -0
  148. package/libs/7z/win/7za.exe +0 -0
  149. package/libs/7z/win/7zxa.dll +0 -0
  150. package/libs/7z/win/Far/7-ZipEng.hlf +85 -0
  151. package/libs/7z/win/Far/7-ZipEng.lng +220 -0
  152. package/libs/7z/win/Far/7-ZipFar.dll +0 -0
  153. package/libs/7z/win/Far/7-ZipFar64.dll +0 -0
  154. package/libs/7z/win/Far/7-ZipRus.hlf +84 -0
  155. package/libs/7z/win/Far/7-ZipRus.lng +220 -0
  156. package/libs/7z/win/Far/7zToFar.ini +67 -0
  157. package/libs/7z/win/Far/far7z.reg +67 -0
  158. package/libs/7z/win/Far/far7z.txt +73 -0
  159. package/libs/7z/win/License.txt +123 -0
  160. package/libs/7z/win/arm64/7-ZipFar.dll +0 -0
  161. package/libs/7z/win/arm64/7za.dll +0 -0
  162. package/libs/7z/win/arm64/7za.exe +0 -0
  163. package/libs/7z/win/arm64/7zxa.dll +0 -0
  164. package/libs/7z/win/history.txt +347 -0
  165. package/libs/7z/win/readme.txt +125 -0
  166. package/libs/7z/win/x64/7za.dll +0 -0
  167. package/libs/7z/win/x64/7za.exe +0 -0
  168. package/libs/7z/win/x64/7zxa.dll +0 -0
  169. package/package.json +50 -0
@@ -0,0 +1,495 @@
1
+ import { chromium } from "playwright";
2
+ import { load } from "cheerio";
3
+ import fs from "fs/promises";
4
+ import path from "path";
5
+ import * as XLSX from "xlsx";
6
+ import * as pdfParse from "pdf-parse";
7
+ import mammoth from "mammoth";
8
+ import csv from "csv-parser";
9
+ import { spawn } from "child_process";
10
+ import { fileURLToPath } from "url";
11
+ import iconv from "iconv-lite";
12
+ export class GloscTools {
13
+ static escapePowerShellSingleQuoted(value) {
14
+ return `'${value.replace(/'/g, "''")}'`;
15
+ }
16
+ static extractJsonFromOutput(output) {
17
+ const trimmed = output.trim();
18
+ if (!trimmed)
19
+ return null;
20
+ const firstBrace = trimmed.indexOf("{");
21
+ const firstBracket = trimmed.indexOf("[");
22
+ const startCandidates = [firstBrace, firstBracket].filter((n) => n >= 0);
23
+ if (startCandidates.length === 0)
24
+ return null;
25
+ const start = Math.min(...startCandidates);
26
+ const lastBrace = trimmed.lastIndexOf("}");
27
+ const lastBracket = trimmed.lastIndexOf("]");
28
+ const endCandidates = [lastBrace, lastBracket].filter((n) => n >= 0);
29
+ if (endCandidates.length === 0)
30
+ return null;
31
+ const end = Math.max(...endCandidates);
32
+ if (end <= start)
33
+ return null;
34
+ return trimmed.slice(start, end + 1);
35
+ }
36
+ static async listInstalledApps(options) {
37
+ if (process.platform !== "win32") {
38
+ throw new Error("当前仅支持 Windows:通过注册表获取已安装应用列表");
39
+ }
40
+ const query = options?.query?.trim();
41
+ const matchMode = options?.matchMode ?? "contains";
42
+ const limit = options?.limit ?? 200;
43
+ const psScript = `
44
+ $ErrorActionPreference = 'SilentlyContinue'
45
+ $paths = @(
46
+ 'HKLM:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*',
47
+ 'HKLM:\\Software\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*',
48
+ 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*'
49
+ )
50
+
51
+ $apps = foreach ($p in $paths) {
52
+ Get-ItemProperty -Path $p | Where-Object { $_.DisplayName -and $_.DisplayName.Trim().Length -gt 0 } | ForEach-Object {
53
+ [PSCustomObject]@{
54
+ Name = $_.DisplayName
55
+ Version = $_.DisplayVersion
56
+ Publisher = $_.Publisher
57
+ InstallLocation = $_.InstallLocation
58
+ InstallSource = $_.InstallSource
59
+ DisplayIcon = $_.DisplayIcon
60
+ UninstallString = $_.UninstallString
61
+ QuietUninstallString = $_.QuietUninstallString
62
+ RegistryKey = $_.PSPath
63
+ }
64
+ }
65
+ }
66
+
67
+ $apps = $apps | Sort-Object Name, Version, Publisher -Unique
68
+
69
+ if ($null -ne $apps) {
70
+ $apps | ConvertTo-Json -Depth 4
71
+ }
72
+ `;
73
+ const res = await GloscTools.spawnCommand("powershell", ["-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", psScript], "utf8");
74
+ const jsonText = GloscTools.extractJsonFromOutput(res.output) ?? "[]";
75
+ let apps;
76
+ try {
77
+ const parsed = JSON.parse(jsonText);
78
+ apps = Array.isArray(parsed) ? parsed : [parsed];
79
+ }
80
+ catch (e) {
81
+ throw new Error(`解析应用列表失败: ${e instanceof Error ? e.message : String(e)}`);
82
+ }
83
+ const normalizedApps = apps
84
+ .filter((a) => a && typeof a.Name === "string")
85
+ .map((a) => ({
86
+ name: String(a.Name),
87
+ version: a.Version ? String(a.Version) : undefined,
88
+ publisher: a.Publisher ? String(a.Publisher) : undefined,
89
+ installLocation: a.InstallLocation
90
+ ? String(a.InstallLocation)
91
+ : undefined,
92
+ installSource: a.InstallSource
93
+ ? String(a.InstallSource)
94
+ : undefined,
95
+ displayIcon: a.DisplayIcon ? String(a.DisplayIcon) : undefined,
96
+ uninstallString: a.UninstallString
97
+ ? String(a.UninstallString)
98
+ : undefined,
99
+ quietUninstallString: a.QuietUninstallString
100
+ ? String(a.QuietUninstallString)
101
+ : undefined,
102
+ registryKey: a.RegistryKey ? String(a.RegistryKey) : undefined,
103
+ }))
104
+ .sort((a, b) => a.name.localeCompare(b.name));
105
+ const filtered = query
106
+ ? GloscTools.filterApps(normalizedApps, query, matchMode)
107
+ : normalizedApps;
108
+ return filtered.slice(0, Math.max(1, limit));
109
+ }
110
+ static filterApps(apps, query, matchMode) {
111
+ const q = query.trim();
112
+ if (!q)
113
+ return apps;
114
+ if (matchMode === "regex") {
115
+ let re;
116
+ try {
117
+ re = new RegExp(q, "i");
118
+ }
119
+ catch {
120
+ return [];
121
+ }
122
+ return apps.filter((a) => re.test(a.name));
123
+ }
124
+ const nq = q.toLowerCase();
125
+ const matches = apps.filter((a) => {
126
+ const n = a.name.toLowerCase();
127
+ if (matchMode === "equals")
128
+ return n === nq;
129
+ return n.includes(nq);
130
+ });
131
+ return matches.sort((a, b) => GloscTools.matchScore(a.name, q) -
132
+ GloscTools.matchScore(b.name, q));
133
+ }
134
+ static matchScore(name, query) {
135
+ const n = name.toLowerCase();
136
+ const q = query.toLowerCase();
137
+ if (n === q)
138
+ return 0;
139
+ if (n.startsWith(q))
140
+ return 1;
141
+ if (n.includes(q))
142
+ return 2;
143
+ return 3;
144
+ }
145
+ static inferInstallPathFromApp(app) {
146
+ const loc = app.installLocation?.trim();
147
+ if (loc) {
148
+ return { installPath: loc, source: "InstallLocation", raw: loc };
149
+ }
150
+ const fromDisplayIcon = GloscTools.extractPathFromCommandLike(app.displayIcon);
151
+ if (fromDisplayIcon) {
152
+ const dir = path.dirname(fromDisplayIcon);
153
+ return {
154
+ installPath: dir,
155
+ source: "DisplayIcon",
156
+ raw: app.displayIcon,
157
+ };
158
+ }
159
+ const fromUninstall = GloscTools.extractPathFromCommandLike(app.quietUninstallString ?? app.uninstallString);
160
+ if (fromUninstall) {
161
+ const dir = path.dirname(fromUninstall);
162
+ return {
163
+ installPath: dir,
164
+ source: "UninstallString",
165
+ raw: app.quietUninstallString ?? app.uninstallString,
166
+ };
167
+ }
168
+ return {};
169
+ }
170
+ static extractPathFromCommandLike(value) {
171
+ if (!value)
172
+ return null;
173
+ let v = value.trim();
174
+ if (!v)
175
+ return null;
176
+ // DisplayIcon 常见格式: "C:\\Path\\app.exe",0
177
+ const commaIndex = v.indexOf(",");
178
+ if (commaIndex > 0)
179
+ v = v.slice(0, commaIndex);
180
+ // 去掉外层引号
181
+ if ((v.startsWith('"') && v.endsWith('"')) ||
182
+ (v.startsWith("'") && v.endsWith("'"))) {
183
+ v = v.slice(1, -1);
184
+ }
185
+ // 若像命令行: "C:\\a b\\c.exe" /S
186
+ const quotedMatch = v.match(/^"([^"]+)"/);
187
+ if (quotedMatch?.[1])
188
+ return quotedMatch[1];
189
+ const firstToken = v.split(/\s+/)[0];
190
+ if (!firstToken)
191
+ return null;
192
+ return firstToken;
193
+ }
194
+ static async getAppInstallPath(options) {
195
+ const query = options.name;
196
+ const matchMode = options.matchMode ?? "contains";
197
+ const limit = options.limit ?? 50;
198
+ const apps = await GloscTools.listInstalledApps({
199
+ query,
200
+ matchMode,
201
+ limit,
202
+ });
203
+ const candidates = apps.map((a) => {
204
+ const inferred = GloscTools.inferInstallPathFromApp({
205
+ installLocation: a.installLocation,
206
+ displayIcon: a.displayIcon,
207
+ uninstallString: a.uninstallString,
208
+ quietUninstallString: a.quietUninstallString,
209
+ });
210
+ return {
211
+ name: a.name,
212
+ version: a.version,
213
+ publisher: a.publisher,
214
+ installLocation: a.installLocation,
215
+ inferredInstallPath: inferred.installPath,
216
+ inferredSource: inferred.source,
217
+ };
218
+ });
219
+ const best = candidates[0];
220
+ return {
221
+ query,
222
+ matchMode,
223
+ result: !options.allMatches && best
224
+ ? {
225
+ name: best.name,
226
+ installPath: best.installLocation ?? best.inferredInstallPath,
227
+ source: best.installLocation
228
+ ? "InstallLocation"
229
+ : best.inferredSource,
230
+ version: best.version,
231
+ publisher: best.publisher,
232
+ }
233
+ : undefined,
234
+ candidates: options.allMatches
235
+ ? candidates
236
+ : candidates.slice(0, 10),
237
+ };
238
+ }
239
+ static async openReference(options) {
240
+ const target = options.target?.trim();
241
+ if (!target)
242
+ throw new Error("target 不能为空");
243
+ const wait = options.wait ?? false;
244
+ const args = options.args ?? [];
245
+ if (process.platform === "win32") {
246
+ const filePath = GloscTools.escapePowerShellSingleQuoted(target);
247
+ const argList = args.length > 0
248
+ ? ` -ArgumentList @(${args
249
+ .map((a) => GloscTools.escapePowerShellSingleQuoted(a))
250
+ .join(", ")})`
251
+ : "";
252
+ const waitFlag = wait ? " -Wait" : "";
253
+ const script = `Start-Process -FilePath ${filePath}${argList}${waitFlag}`;
254
+ await GloscTools.spawnCommand("powershell", [
255
+ "-NoProfile",
256
+ "-ExecutionPolicy",
257
+ "Bypass",
258
+ "-Command",
259
+ script,
260
+ ], "utf8");
261
+ return { ok: true, target };
262
+ }
263
+ if (process.platform === "darwin") {
264
+ await GloscTools.spawnCommand("open", [target], "utf8");
265
+ return { ok: true, target };
266
+ }
267
+ // linux / other
268
+ await GloscTools.spawnCommand("xdg-open", [target], "utf8");
269
+ return { ok: true, target };
270
+ }
271
+ /**
272
+ * 使用浏览器或 fetch 获取网页内容
273
+ * @param url 网页URL地址
274
+ * @param useBrowser 是否模拟浏览器获取网页内容,true或false
275
+ * @param type 内容类型, text、html或json
276
+ * @returns
277
+ */
278
+ static async usebrowser(url, useBrowser = false, type = "text") {
279
+ try {
280
+ if (useBrowser) {
281
+ // 使用浏览器模式
282
+ const browser = await chromium.launch();
283
+ const page = await browser.newPage();
284
+ await page.goto(url, { waitUntil: "networkidle" });
285
+ const html = await page.content();
286
+ const $ = load(html);
287
+ let content = "";
288
+ if (type === "html") {
289
+ }
290
+ else if (type === "text") {
291
+ content = $.root().text();
292
+ }
293
+ else if (type === "json") {
294
+ const textContent = $.root().text();
295
+ try {
296
+ const jsonData = JSON.parse(textContent);
297
+ content = JSON.stringify(jsonData, null, 2);
298
+ }
299
+ catch {
300
+ content = textContent; // 解析失败, 直接返回文本内容
301
+ }
302
+ }
303
+ else {
304
+ content = html; // 默认 HTML
305
+ }
306
+ await browser.close();
307
+ return content;
308
+ }
309
+ else {
310
+ // 非浏览器模式,使用 fetch
311
+ const response = await fetch(url);
312
+ if (!response.ok) {
313
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
314
+ }
315
+ if (type === "json") {
316
+ try {
317
+ const jsonData = await response.json();
318
+ return JSON.stringify(jsonData, null, 2);
319
+ }
320
+ catch (error) {
321
+ // 解析失败, 直接返回 text 内容
322
+ return await response.text();
323
+ }
324
+ }
325
+ else {
326
+ // 对于 "text" 和 "html",都返回文本内容
327
+ return await response.text();
328
+ }
329
+ }
330
+ }
331
+ catch (error) {
332
+ const errorMessage = error instanceof Error ? error.message : String(error);
333
+ return `获取网页内容失败: ${errorMessage}`;
334
+ }
335
+ }
336
+ /**
337
+ * 处理命令行指令,实时返回输出结果
338
+ * @param command
339
+ * @param args
340
+ * @returns
341
+ */
342
+ static async spawnCommand(command, args, encoding = "utf8") {
343
+ return new Promise((resolve, reject) => {
344
+ const process = spawn(command, args, {
345
+ stdio: ["pipe", "pipe", "pipe"],
346
+ });
347
+ let output = Buffer.alloc(0);
348
+ process.stdout.on("data", (data) => {
349
+ output = Buffer.concat([output, data]);
350
+ console.log("Real-time output:", iconv.decode(data, encoding)); // 实时日志
351
+ });
352
+ process.stderr.on("data", (data) => {
353
+ console.warn("Error output:", iconv.decode(data, encoding));
354
+ });
355
+ process.on("close", (code) => {
356
+ if (code === 0) {
357
+ const decodedOutput = iconv.decode(output, encoding);
358
+ resolve({ code, output: decodedOutput });
359
+ }
360
+ else {
361
+ reject(new Error(`Process exited with code ${code}`));
362
+ }
363
+ });
364
+ process.on("error", (error) => reject(error));
365
+ });
366
+ }
367
+ /**
368
+ * 解析 7-Zip l 命令的输出,返回文件列表数组
369
+ * @param output 7-Zip 的输出字符串
370
+ * @returns 文件列表
371
+ */
372
+ static parse7zOutput(output) {
373
+ const lines = output.split("\n");
374
+ const fileList = [];
375
+ let inFileList = false;
376
+ for (const line of lines) {
377
+ if (line.includes("Date") &&
378
+ line.includes("Time") &&
379
+ line.includes("Attr")) {
380
+ inFileList = true;
381
+ continue;
382
+ }
383
+ if (inFileList &&
384
+ line.trim() &&
385
+ !line.includes("---") &&
386
+ !line.includes("files")) {
387
+ const parts = line.trim().split(/\s+/);
388
+ if (parts.length >= 6) {
389
+ const attr = parts[2];
390
+ const size = parseInt(parts[3]) || 0;
391
+ const name = parts.slice(5).join(" ");
392
+ const isDirectory = attr.includes("D") || attr.includes("d");
393
+ fileList.push({
394
+ name,
395
+ size,
396
+ isDirectory,
397
+ });
398
+ }
399
+ }
400
+ }
401
+ return fileList;
402
+ }
403
+ /**
404
+ * 解析文件内容,支持多种文件类型
405
+ * @param filePath 文件的绝对路径
406
+ * @returns
407
+ */
408
+ static async processFile(filePath) {
409
+ const __filename = fileURLToPath(import.meta.url);
410
+ const __dirname = path.dirname(__filename);
411
+ const ext = path.extname(filePath).toLowerCase();
412
+ const buffer = await fs.readFile(filePath);
413
+ if ([
414
+ ".txt",
415
+ ".md",
416
+ ".json",
417
+ ".js",
418
+ ".ts",
419
+ ".html",
420
+ ".css",
421
+ ".xml",
422
+ ".yaml",
423
+ ".yml",
424
+ ].includes(ext)) {
425
+ // 文本文件
426
+ return buffer.toString("utf-8");
427
+ }
428
+ else if ([".png", ".jpg", ".jpeg", ".gif", ".bmp", ".webp"].includes(ext)) {
429
+ // 图片文件,返回base64编码
430
+ const base64 = buffer.toString("base64");
431
+ const mimeType = `image/${ext.slice(1)}`;
432
+ return `data:${mimeType};base64,${base64}`;
433
+ }
434
+ else if (ext === ".csv") {
435
+ // CSV文件,解析为JSON
436
+ const results = [];
437
+ const stream = require("stream");
438
+ const readable = new stream.Readable();
439
+ readable.push(buffer);
440
+ readable.push(null);
441
+ return new Promise((resolve, reject) => {
442
+ readable
443
+ .pipe(csv())
444
+ .on("data", (data) => results.push(data))
445
+ .on("end", () => resolve(JSON.stringify(results, null, 2)))
446
+ .on("error", reject);
447
+ });
448
+ }
449
+ else if ([".xlsx", ".xls"].includes(ext)) {
450
+ // Excel文件,解析为JSON
451
+ const workbook = XLSX.read(buffer, { type: "buffer" });
452
+ const sheetName = workbook.SheetNames[0];
453
+ const worksheet = workbook.Sheets[sheetName];
454
+ const json = XLSX.utils.sheet_to_json(worksheet);
455
+ return JSON.stringify(json, null, 2);
456
+ }
457
+ else if (ext === ".pdf") {
458
+ // PDF文件,提取文本
459
+ const data = await pdfParse(buffer);
460
+ return data.text;
461
+ }
462
+ else if (ext === ".docx") {
463
+ // Word文档,提取文本
464
+ const result = await mammoth.extractRawText({ buffer });
465
+ return result.value;
466
+ }
467
+ else if ([
468
+ ".zip",
469
+ ".rar",
470
+ ".7z",
471
+ ".tar",
472
+ ".gz",
473
+ ".bz2",
474
+ ".xz",
475
+ ".tar.gz",
476
+ ".tar.bz2",
477
+ ].includes(ext)) {
478
+ // 压缩包文件,使用7z列出内容
479
+ const sevenZipPath = path.join(process.cwd(), "libs", "7z", "win", "7za.exe");
480
+ const args = ["l", filePath];
481
+ const res = await GloscTools.spawnCommand(sevenZipPath, args, "gbk");
482
+ const fileList = GloscTools.parse7zOutput(res.output);
483
+ return JSON.stringify(fileList);
484
+ }
485
+ else {
486
+ // 其他文件,尝试作为文本读取
487
+ try {
488
+ return buffer.toString("utf-8");
489
+ }
490
+ catch {
491
+ return `Unsupported file type: ${ext}`;
492
+ }
493
+ }
494
+ }
495
+ }
package/build/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
2
+ import { GloscMcp } from "./GloscMcp.js";
3
+ const mcpServer = new GloscMcp();
4
+ async function main() {
5
+ const transport = new StdioServerTransport();
6
+ await mcpServer.server.connect(transport);
7
+ console.error("Weather MCP Server running on stdio");
8
+ }
9
+ main().catch((error) => {
10
+ console.error("Fatal error in main():", error);
11
+ process.exit(1);
12
+ });
Binary file
Binary file
@@ -0,0 +1,178 @@
1
+ HISTORY of the 7-Zip
2
+ --------------------
3
+
4
+ This file contains information about changes for latest versions of 7-Zip.
5
+ The full changelog file can be downloaded here:
6
+ https://7-zip.org/history.txt
7
+
8
+ 25.01 2025-08-03
9
+ -------------------------
10
+ - The code for handling symbolic links has been changed
11
+ to provide greater security when extracting files from archives.
12
+ Command line switch -snld20 can be used to bypass default security
13
+ checks when creating symbolic links.
14
+
15
+
16
+ 25.00 2025-07-05
17
+ -------------------------
18
+ - 7-Zip for Windows can now use more than 64 CPU threads for compression
19
+ to zip/7z/xz archives and for the 7-Zip benchmark.
20
+ If there are more than one processor group in Windows (on systems with more than
21
+ 64 cpu threads), 7-Zip distributes running CPU threads across different processor groups.
22
+ - bzip2 compression speed was increased by 15-40%.
23
+ - deflate (zip/gz) compression speed was increased by 1-3%.
24
+ - improved support for zip, cpio and fat archives.
25
+ - fixed some bugs and vulnerabilities.
26
+ - the bug was fixed : CVE-2025-53816 : 7-Zip could work incorrectly for some incorrect RAR archives.
27
+ - the bug was fixed : CVE-2025-53817 : 7-Zip could crash for some incorrect COM (Compound File) archives.
28
+
29
+
30
+ 24.09 2024-11-29
31
+ -------------------------
32
+ - The default dictionary size values for LZMA/LZMA2 compression methods were increased:
33
+ dictionary size compression level
34
+ v24.08 v24.09 v24.09
35
+ 32-bit 64-bit
36
+ 8 MB 16 MB 16 MB -mx4
37
+ 16 MB 32 MB 32 MB -mx5 : Normal
38
+ 32 MB 64 MB 64 MB -mx6
39
+ 32 MB 64 MB 128 MB -mx7 : Maximum
40
+ 64 MB 64 MB 256 MB -mx8
41
+ 64 MB 64 MB 256 MB -mx9 : Ultra
42
+ The default dictionary size values for 32-bit versions of LZMA/LZMA2 don't exceed 64 MB.
43
+ - 7-Zip now can calculate the following hash checksums: SHA-512, SHA-384, SHA3-256 and MD5.
44
+ - APM and HFS support was improved.
45
+ - If an archive update operation uses a temporary archive folder and
46
+ the archive is moved to the destination folder, 7-Zip shows the progress of moving
47
+ the archive file, as this operation can take a long time if the archive is large.
48
+ - The bug was fixed: 7-Zip File Manager didn't propagate Zone.Identifier stream
49
+ for extracted files from nested archives (if there is open archive inside another open archive).
50
+ - Some bugs were fixed.
51
+
52
+
53
+ 24.08 2024-08-11
54
+ -------------------------
55
+ - The bug in 7-Zip 24.00-24.07 was fixed:
56
+ For creating a zip archive: 7-Zip could write extra zero bytes after the end of the archive,
57
+ if a file included to archive cannot be compressed to a size smaller than original.
58
+ The created zip archive is correct except for the useless zero bytes after the end of the archive.
59
+ When unpacking such a zip archive, 7-Zip displays a warning:
60
+ "WARNING: There are data after the end of archive".
61
+ - The bug was fixed: there was a leak of GDI objects (internal resources in Windows)
62
+ in "Confirm File Replace" window, causing problems after 1600 displays of "Confirm File Replace"
63
+ window from same running 7-Zip process.
64
+ - Some optimizations for displaying file icons in 7-Zip File Manager and in "Confirm File Replace" window.
65
+ - Some bugs were fixed.
66
+
67
+
68
+ 24.07 2024-06-19
69
+ -------------------------
70
+ - The bug was fixed: 7-Zip could crash for some incorrect ZSTD archives.
71
+
72
+
73
+ 24.06 2024-05-26
74
+ -------------------------
75
+ - The bug was fixed: 7-Zip could not unpack some ZSTD archives.
76
+
77
+
78
+ 24.05 2024-05-14
79
+ -------------------------
80
+ - New switch -myv={MMNN} to set decoder compatibility version for 7z archive creating.
81
+ {MMNN} is 4-digit number that represents the version of 7-Zip without a dot.
82
+ If -myv={MMNN} switch is specified, 7-Zip will only use compression methods that can
83
+ be decoded by the specified version {MMNN} of 7-Zip and newer versions.
84
+ If -myv={MMNN} switch is not specified, -myv=2300 is used, and 7-Zip will only
85
+ use compression methods that can be decoded by 7-Zip 23.00 and newer versions.
86
+ - New switch -myfa={FilterID} to allow 7-Zip to use the specified filter method for 7z archive creating.
87
+ - New switch -myfd={FilterID} to disallow 7-Zip to use the specified filter method for 7z archive creating.
88
+ - Some bugs were fixed.
89
+
90
+
91
+ 24.04 2024-04-05
92
+ -------------------------
93
+ - New menu item in 7-Zip File Manager: "Tools / Delete Temporary Files...".
94
+ This menu item opens a window showing temporary folders and files
95
+ created by 7-Zip in the user's "Temp" folder on a Windows system.
96
+ In this window, the user can delete temporary files.
97
+
98
+
99
+ 24.03 2024-03-23
100
+ -------------------------
101
+ - 7-Zip now can use new RISCV filter for compression to 7z and xz archives.
102
+ RISCV filter can increase compression ratio for data containing executable
103
+ files compiled for RISC-V architecture.
104
+ - The speed for LZMA and LZMA2 decompression in ARM64 version for Windows
105
+ was increased by 20%-60%.
106
+ - 7-Zip GUI and 7-Zip File Manager can ask user permission to unpack RAR archives that
107
+ require big amount of memory, if the dictionary size in RAR archive is larger than 4 GB.
108
+ - new switch -smemx{size}g : to set allowed memory usage limit for RAR archive unpacking.
109
+ RAR archives can use dictionary up 64 GB. Default allowed limit for RAR unpacking is 4 GB.
110
+ - 7zg.exe (7-Zip GUI): -y switch disables user requests and messages.
111
+ - 7-Zip shows hash methods XXH64 and BLAKE2sp in context menu.
112
+ - -slmu switch : to show timestamps as UTC instead of LOCAL TIME.
113
+ - -slsl switch : in console 7-Zip for Windows : to show file paths with
114
+ linux path separator slash '/' instead of backslash separator '\'.
115
+ - 7-Zip supports .sha256 files that use backslash path separator '\'.
116
+ - Some bugs were fixed.
117
+
118
+
119
+ 24.01 2024-01-31
120
+ -------------------------
121
+ - 7-Zip now can unpack ZSTD archives (.zst filename extension).
122
+ - 7-Zip now can unpack ZIP, SquashFS and RPM archives that use ZSTD compression method.
123
+ - 7-Zip now supports fast hash algorithm XXH64 that is used in ZSTD.
124
+ - 7-Zip now can unpack RAR archives (that use larger than 4 GB dictionary) created by new WinRAR 7.00.
125
+ - 7-Zip now can unpack DMG archives that use XZ (ULMO/LZMA) compression method.
126
+ - 7-Zip now can unpack NTFS images with cluster size larger than 64 KB.
127
+ - 7-Zip now can unpack MBR and GPT images with 4 KB sectors.
128
+ - Speed optimizations for archive unpacking: rar, cab, wim, zip, gz.
129
+ - Speed optimizations for hash caclulation: CRC-32, CRC-64, BLAKE2sp.
130
+ - The bug was fixed: 7-Zip for Linux could fail for multivolume creation in some cases.
131
+ - Some bugs were fixed.
132
+
133
+
134
+ 23.01 2023-06-20
135
+ -------------------------
136
+ - The page "Language" in 7-Zip's menu Tools/Options now shows information
137
+ about selected translation, including the number of translated lines.
138
+ - Some bugs were fixed.
139
+
140
+
141
+ 23.00 2023-05-07
142
+ -------------------------
143
+ - 7-Zip now can use new ARM64 filter for compression to 7z and xz archives.
144
+ ARM64 filter can increase compression ratio for data containing executable
145
+ files compiled for ARM64 (AArch64) architecture.
146
+ Also 7-Zip now parses executable files (that have exe and dll filename extensions)
147
+ before compressing, and it selects appropriate filter for each parsed file:
148
+ - BCJ or BCJ2 filter for x86 executable files,
149
+ - ARM64 filter for ARM64 executable files.
150
+ Previous versions by default used x86 filter BCJ or BCJ2 for all exe/dll files.
151
+ - Default section size for BCJ2 filter was changed from 64 MiB to 240 MiB.
152
+ It can increase compression ratio for executable files larger than 64 MiB.
153
+ - UDF: support was improved.
154
+ - cpio: support for hard links.
155
+ - Some changes and optimizations in WIM creation code.
156
+ - When new 7-Zip creates multivolume archive, 7-Zip keeps in open state
157
+ only volumes that still can be changed. Previous versions kept all volumes
158
+ in open state until the end of the archive creation.
159
+ - 7-Zip for Linux and macOS now can reduce the number of simultaneously open files,
160
+ when 7-Zip opens, extracts or creates multivolume archive. It allows to avoid
161
+ the failures for cases with big number of volumes, bacause there is a limitation
162
+ for number of open files allowed for a single program in Linux and macOS.
163
+ - There are optimizations in code for 7-Zip's context menu in Explorer:
164
+ the speed of preparing of the menu showing was improved for cases when big number of
165
+ files were selected by external program for context menu that contains 7-Zip menu commands.
166
+ - There are changes in code for the drag-and-drop operations to and from 7-Zip File Manager.
167
+ And the drag-and-drop operation with right button of mouse now is supported for some cases.
168
+ - The bugs were fixed:
169
+ - ZIP archives: if multithreaded zip compression was performed with more than one
170
+ file to stdout stream (-so switch), 7-Zip didn't write "data descriptor" for some files.
171
+ - ext4 archives: 7-Zip couldn't correctly extract symbolic link to directory from ext4 archives.
172
+ - HFS and APFS archives: 7-Zip incorrectly decoded uncompressed blocks (64 KiB) in compressed forks.
173
+ - HFS : zlib without Adler supported
174
+ - Some another bugs were fixed.
175
+
176
+
177
+ ==
178
+ End of document