dsh-multigameassistant 2.0.5 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/cordis.patch.yml +178 -4
  2. package/lib/analyzer.js +6 -4
  3. package/lib/browser.js +279 -0
  4. package/lib/{chunk-KHO3SRUJ.js → chunk-5PDYWE24.js} +4 -2
  5. package/lib/{chunk-YG4B5G7F.js → chunk-B4UT4NYH.js} +1 -0
  6. package/lib/{chunk-IOBYH4RN.js → chunk-FBDVN6Q2.js} +76 -1
  7. package/lib/{chunk-TD4YFQWE.js → chunk-MQG5FLOG.js} +629 -167
  8. package/lib/chunk-NM6H6WCQ.js +3753 -0
  9. package/lib/chunk-RESS7WVY.js +157 -0
  10. package/lib/{chunk-BTT2GBTQ.js → chunk-SHTX4AGU.js} +1 -3670
  11. package/lib/{chunk-4Q4EH73S.js → chunk-UQLHGLMP.js} +13 -9
  12. package/lib/{chunk-PAJOD6LV.js → chunk-VOTN4IHB.js} +384 -54
  13. package/lib/emulator.js +6 -4
  14. package/lib/feishu.js +8 -6
  15. package/lib/game-intel.js +90 -9
  16. package/lib/gateway.js +11 -6
  17. package/lib/guard.js +5 -3
  18. package/lib/intervene.js +62 -18
  19. package/lib/low-context.js +13 -2
  20. package/lib/monitor.js +90 -10
  21. package/lib/notify.js +6 -5
  22. package/lib/orchestrator.js +14 -10
  23. package/lib/qqbot.js +8 -6
  24. package/lib/runner.js +18 -5
  25. package/lib/scheduler.js +4 -2
  26. package/lib/script-registry.js +345 -216
  27. package/package.json +5 -4
  28. package/skills/pipeline-planning.md +1 -1
  29. package/skills/web-reading.md +2 -0
  30. package/web/assets/index-CL3SeTW9.css +1 -0
  31. package/web/assets/index-GYwpGP3f.js +244 -0
  32. package/web/assets/index-GYwpGP3f.js.map +1 -0
  33. package/web/index.html +2 -2
  34. package/lib/chunk-CCAB6XXZ.js +0 -34
  35. package/web/assets/index-BuStplKb.js +0 -242
  36. package/web/assets/index-BuStplKb.js.map +0 -1
  37. package/web/assets/index-CSB3B28L.css +0 -1
@@ -21,10 +21,11 @@ import {
21
21
  probeProject,
22
22
  readMirrorChanges,
23
23
  runSetup,
24
+ satisfies,
24
25
  setupExitText,
25
26
  setupKind,
26
27
  systemHost
27
- } from "./chunk-YG4B5G7F.js";
28
+ } from "./chunk-B4UT4NYH.js";
28
29
  import {
29
30
  MANIFEST_FILE,
30
31
  SKILL_FILE,
@@ -33,15 +34,18 @@ import {
33
34
  guideView,
34
35
  parseManifest,
35
36
  versionOfTag
36
- } from "./chunk-KHO3SRUJ.js";
37
+ } from "./chunk-5PDYWE24.js";
37
38
  import {
38
39
  sessionConversations
39
- } from "./chunk-4Q4EH73S.js";
40
- import "./chunk-TD4YFQWE.js";
41
- import "./chunk-IOBYH4RN.js";
40
+ } from "./chunk-UQLHGLMP.js";
42
41
  import {
42
+ pluginVersion
43
+ } from "./chunk-MQG5FLOG.js";
44
+ import "./chunk-FBDVN6Q2.js";
45
+ import {
46
+ ExeIcons,
43
47
  writeFileAtomic
44
- } from "./chunk-CCAB6XXZ.js";
48
+ } from "./chunk-RESS7WVY.js";
45
49
  import {
46
50
  EnvReport,
47
51
  GitHubRepo,
@@ -57,14 +61,17 @@ import {
57
61
  ScriptSummary,
58
62
  SetupAgent,
59
63
  UPDATE_RULE,
60
- external_exports,
61
64
  optimizeScriptPrompt,
62
65
  parseGitHubLink,
63
66
  taskMessage
64
- } from "./chunk-BTT2GBTQ.js";
67
+ } from "./chunk-NM6H6WCQ.js";
68
+ import {
69
+ external_exports
70
+ } from "./chunk-SHTX4AGU.js";
65
71
  import "./chunk-2UFLGPDY.js";
66
72
 
67
73
  // packages/script-registry/lib/index.js
74
+ import { join as join6 } from "node:path";
68
75
  import { Service } from "@deepseek-ai/cordis";
69
76
 
70
77
  // packages/script-registry/lib/role.js
@@ -89,7 +96,9 @@ var SCRIPT_ROLE = {
89
96
  "monitor_stall_*",
90
97
  "system_info",
91
98
  "skill_focus",
92
- "skill_save"
99
+ "skill_save",
100
+ // Project sites and wikis that need clicking through (the built-in browser).
101
+ "browser_*"
93
102
  ],
94
103
  duty: [
95
104
  "# \u4F60\u7684\u89D2\u8272\uFF1A\u811A\u672C",
@@ -101,7 +110,9 @@ var SCRIPT_ROLE = {
101
110
  };
102
111
 
103
112
  // packages/script-registry/lib/capability.js
104
- function scriptsCapability(library, summaries, setupAgent, review, optimizer2) {
113
+ import { existsSync, readdirSync } from "node:fs";
114
+ import { basename, join } from "node:path";
115
+ function scriptsCapability(library, summaries, setupAgent, review, optimizer2, icons) {
105
116
  return {
106
117
  id: SCRIPTS_CAPABILITY,
107
118
  version: 1,
@@ -112,6 +123,17 @@ function scriptsCapability(library, summaries, setupAgent, review, optimizer2) {
112
123
  const pack = library.packOf(params.id);
113
124
  return { guide: pack === void 0 ? null : guideView(pack.manifest, { builtin: pack.builtin }) };
114
125
  },
126
+ "scripts/icon": async (params, call) => {
127
+ const id = params.id;
128
+ const program = scriptProgram(library, id);
129
+ if (program === void 0 || icons === void 0 || process.platform !== "win32")
130
+ return {};
131
+ try {
132
+ return { icon: { mediaType: "image/png", data: (await icons.png(program, call.signal)).toString("base64") } };
133
+ } catch {
134
+ return {};
135
+ }
136
+ },
115
137
  "scripts/search": (params, call) => library.search(params.query, call.signal),
116
138
  "scripts/releases": (params, call) => {
117
139
  const p = params;
@@ -189,10 +211,51 @@ function scriptsCapability(library, summaries, setupAgent, review, optimizer2) {
189
211
  }
190
212
  };
191
213
  }
214
+ function scriptProgram(library, id) {
215
+ let info, pack;
216
+ try {
217
+ info = library.get(id);
218
+ pack = library.packOf(id);
219
+ } catch {
220
+ return void 0;
221
+ }
222
+ const launch = pack?.manifest.launch;
223
+ if (info.dir === void 0)
224
+ return void 0;
225
+ if (launch === void 0)
226
+ return mainProgram(info.dir);
227
+ for (const exe of [launch.settings?.exe, launch.exe]) {
228
+ if (exe === void 0)
229
+ continue;
230
+ const path = join(info.dir, launch.cwd ?? "", exe);
231
+ if (existsSync(path))
232
+ return path;
233
+ if (existsSync(join(info.dir, exe)))
234
+ return join(info.dir, exe);
235
+ }
236
+ return mainProgram(info.dir);
237
+ }
238
+ var HELPER = /unins|updat|setup|install|crash|report|helper|python|pythonw|pip|node|git|adb|7z|vc_?redist/i;
239
+ function mainProgram(dir) {
240
+ let exes;
241
+ try {
242
+ exes = readdirSync(dir).filter((name) => name.toLowerCase().endsWith(".exe") && !HELPER.test(name));
243
+ } catch {
244
+ return void 0;
245
+ }
246
+ const folder = basename(dir).toLowerCase();
247
+ const named = exes.find((name) => {
248
+ const stem = name.slice(0, -4).toLowerCase();
249
+ return folder.includes(stem) || stem.includes(folder);
250
+ });
251
+ const exe = named ?? (exes.length === 1 ? exes[0] : void 0);
252
+ return exe === void 0 ? void 0 : join(dir, exe);
253
+ }
192
254
 
193
255
  // packages/script-registry/lib/library.js
256
+ import { existsSync as existsSync2 } from "node:fs";
194
257
  import { copyFile, cp, mkdir as mkdir2, readdir as readdir2, readFile as readFile3, rename as rename2, rm, stat, writeFile as writeFile2 } from "node:fs/promises";
195
- import { basename, dirname as dirname2, isAbsolute, join as join2, relative, resolve } from "node:path";
258
+ import { basename as basename2, dirname as dirname2, isAbsolute, join as join3, relative, resolve } from "node:path";
196
259
 
197
260
  // packages/script-registry/lib/jobs.js
198
261
  var KEEP_FINISHED = 20;
@@ -315,7 +378,7 @@ function mirrorResourceFor(pack, repo) {
315
378
 
316
379
  // packages/script-registry/lib/packs.js
317
380
  import { readdir, readFile } from "node:fs/promises";
318
- import { join } from "node:path";
381
+ import { join as join2 } from "node:path";
319
382
  async function loadPacks(dirs) {
320
383
  const packs = /* @__PURE__ */ new Map();
321
384
  const errors = [];
@@ -324,8 +387,8 @@ async function loadPacks(dirs) {
324
387
  for (const entry of entries) {
325
388
  if (!entry.isDirectory() || entry.name.startsWith("."))
326
389
  continue;
327
- const packDir = join(dir, entry.name);
328
- const file = join(packDir, MANIFEST_FILE);
390
+ const packDir = join2(dir, entry.name);
391
+ const file = join2(packDir, MANIFEST_FILE);
329
392
  let text;
330
393
  try {
331
394
  text = await readFile(file, "utf8");
@@ -336,7 +399,7 @@ async function loadPacks(dirs) {
336
399
  const manifest = parseManifest(text, file);
337
400
  if (manifest.id !== entry.name)
338
401
  throw new Error(`${file}: id "${manifest.id}" must match its directory name "${entry.name}"`);
339
- const skill = await readFile(join(packDir, SKILL_FILE), "utf8").catch(() => void 0);
402
+ const skill = await readFile(join2(packDir, SKILL_FILE), "utf8").catch(() => void 0);
340
403
  const under = packs.get(manifest.id);
341
404
  packs.set(manifest.id, { manifest, dir: packDir, builtin, ...skill === void 0 ? {} : { skill }, ...!builtin && under?.builtin === true ? { over: under } : {} });
342
405
  } catch (error) {
@@ -500,6 +563,7 @@ var PRE_RUN_CHECK_MS = 3e4;
500
563
  var MAX_SETUP_ONLY_FILES = 4;
501
564
  var ScriptLibrary = class {
502
565
  toolsDir;
566
+ formerToolsDirs;
503
567
  #options;
504
568
  #store;
505
569
  #jobs;
@@ -513,12 +577,19 @@ var ScriptLibrary = class {
513
577
  constructor(options) {
514
578
  this.#options = options;
515
579
  this.toolsDir = resolve(options.toolsDir);
516
- this.#store = new StateStore(join2(options.dataDir, "scripts.json"));
580
+ this.formerToolsDirs = (options.formerToolsDirs ?? []).map((dir) => resolve(dir)).filter((dir) => !samePath(dir, this.toolsDir));
581
+ this.#store = new StateStore(join3(options.dataDir, "scripts.json"));
517
582
  this.#now = options.now ?? Date.now;
518
583
  this.#jobs = new JobBoard(options.onJob, this.#now);
519
584
  }
520
585
  get sharedDir() {
521
- return join2(this.toolsDir, "_shared");
586
+ const own = join3(this.toolsDir, "_shared");
587
+ if (!existsSync2(own)) {
588
+ for (const former of this.formerToolsDirs)
589
+ if (existsSync2(join3(former, "_shared")))
590
+ return join3(former, "_shared");
591
+ }
592
+ return own;
522
593
  }
523
594
  async start() {
524
595
  this.#state = await this.#store.load(this.#options.defaults ?? {}, this.#options.log);
@@ -536,7 +607,7 @@ var ScriptLibrary = class {
536
607
  async reloadPacks() {
537
608
  const dirs = [
538
609
  ...this.#options.packDirs.map((dir) => ({ dir, builtin: true })),
539
- { dir: join2(this.#options.dataDir, "packs"), builtin: false }
610
+ { dir: join3(this.#options.dataDir, "packs"), builtin: false }
540
611
  ];
541
612
  const { packs, errors } = await loadPacks(dirs);
542
613
  this.#packs = packs;
@@ -570,9 +641,9 @@ var ScriptLibrary = class {
570
641
  const packId = this.#script(id).packId;
571
642
  return packId === void 0 ? void 0 : this.#packs.get(packId);
572
643
  }
573
- /** Directories MultiGameAssistant must not let the agent rewrite: the tools directory and every imported directory. */
644
+ /** Directories MultiGameAssistant must not let the agent rewrite: the tools directories and every imported directory. */
574
645
  protectedDirs() {
575
- return [this.toolsDir, ...this.#state.scripts.filter((s) => s.source.kind === "local").map((s) => s.source.path)];
646
+ return [this.toolsDir, ...this.formerToolsDirs, ...this.#state.scripts.filter((s) => s.source.kind === "local").map((s) => s.source.path)];
576
647
  }
577
648
  pack(id) {
578
649
  return this.#packs.get(id);
@@ -739,7 +810,7 @@ var ScriptLibrary = class {
739
810
  * Needs no CDK.
740
811
  */
741
812
  async mirrorProjects(signal) {
742
- const file = join2(this.#options.dataDir, "mirrorchyan-projects.json");
813
+ const file = join3(this.#options.dataDir, "mirrorchyan-projects.json");
743
814
  if (this.#catalogue === void 0) {
744
815
  try {
745
816
  const saved = JSON.parse(await readFile3(file, "utf8"));
@@ -827,7 +898,7 @@ var ScriptLibrary = class {
827
898
  const byRepo = repo === void 0 ? [] : items.filter((i) => i.repo?.toLowerCase() === repo);
828
899
  if (byRepo.length > 0)
829
900
  return { items: byRepo.map((i) => ({ ...i, by: "repo" })), from };
830
- const names = [script.name, script.id, script.source.kind === "local" ? basename(script.source.path) : void 0].filter((n) => n !== void 0).map(squash).filter((n) => n.length >= 2);
901
+ const names = [script.name, script.id, script.source.kind === "local" ? basename2(script.source.path) : void 0].filter((n) => n !== void 0).map(squash).filter((n) => n.length >= 2);
831
902
  const byName = items.filter((i) => {
832
903
  const keys = [squash(i.name), squash(i.rid)].filter((k) => k.length >= 3);
833
904
  return keys.some((k) => names.some((n) => n.includes(k) || k.includes(n)));
@@ -1034,7 +1105,7 @@ var ScriptLibrary = class {
1034
1105
  ctl.phase("done", { message: `${version} \u5DF2\u5B89\u88C5\uFF0C\u5DF2\u5207\u6362\u4E3A\u5F53\u524D\u7248\u672C`, version });
1035
1106
  return version;
1036
1107
  }
1037
- const versionDir = join2(this.toolsDir, scriptId, dirName(version));
1108
+ const versionDir = join3(this.toolsDir, scriptId, dirName(version));
1038
1109
  const setup = await setupKind(archive);
1039
1110
  if (setup !== void 0) {
1040
1111
  return this.#handOffSetup(setup, { scriptId, file: archive, version, asset: fetched.asset, dir: versionDir, source: script?.source ?? source, ...pack === void 0 ? {} : { packId: pack.manifest.id }, update: script !== void 0 }, request.byAgent === true, ctl);
@@ -1055,13 +1126,13 @@ var ScriptLibrary = class {
1055
1126
  try {
1056
1127
  await cp(previous.dir, versionDir, { recursive: true });
1057
1128
  const prefix = await patchPrefix(patch, previous.dir, root);
1058
- const from = prefix === void 0 ? patch : join2(patch, prefix);
1129
+ const from = prefix === void 0 ? patch : join3(patch, prefix);
1059
1130
  await cp(from, versionDir, { recursive: true, force: true });
1060
1131
  if (from === patch)
1061
- await rm(join2(versionDir, "changes.json"), { force: true });
1132
+ await rm(join3(versionDir, "changes.json"), { force: true });
1062
1133
  const gone = await readMirrorChanges(patch, prefix) ?? [];
1063
1134
  for (const rel of gone)
1064
- await rm(join2(versionDir, ...rel.split("/")), { recursive: true, force: true });
1135
+ await rm(join3(versionDir, ...rel.split("/")), { recursive: true, force: true });
1065
1136
  if (gone.length > 0)
1066
1137
  this.#options.log.info(`${scriptId}: the incremental package removed ${gone.length} path(s)`);
1067
1138
  } catch (error) {
@@ -1128,7 +1199,7 @@ var ScriptLibrary = class {
1128
1199
  this.#state.setups = [...this.#state.setups.filter((s) => s.scriptId !== setup.scriptId), pending];
1129
1200
  await this.#save();
1130
1201
  this.#options.onChanged(setup.scriptId);
1131
- const what = `${basename(setup.file)} \u662F ${SETUP_NAMES[kind]} \u5B89\u88C5\u7A0B\u5E8F\uFF0C\u4E0D\u662F\u538B\u7F29\u5305`;
1202
+ const what = `${basename2(setup.file)} \u662F ${SETUP_NAMES[kind]} \u5B89\u88C5\u7A0B\u5E8F\uFF0C\u4E0D\u662F\u538B\u7F29\u5305`;
1132
1203
  const handed = { kind, dir: setup.dir };
1133
1204
  const sessionId = byAgent ? void 0 : await this.#options.onSetup?.(pending).catch((error) => {
1134
1205
  this.#options.log.warn(`${setup.scriptId}: setup program not handed to the agent: ${errorText(error)}`);
@@ -1152,11 +1223,11 @@ var ScriptLibrary = class {
1152
1223
  const exes = files.filter((f) => f.toLowerCase().endsWith(".exe"));
1153
1224
  if (exes.length !== 1 || files.length > MAX_SETUP_ONLY_FILES)
1154
1225
  return void 0;
1155
- const inside = join2(dir, ...exes[0].split("/"));
1226
+ const inside = join3(dir, ...exes[0].split("/"));
1156
1227
  const kind = await setupKind(inside);
1157
1228
  if (kind === void 0)
1158
1229
  return void 0;
1159
- const file = join2(dirname2(archive), basename(inside));
1230
+ const file = join3(dirname2(archive), basename2(inside));
1160
1231
  if (!samePath(file, archive)) {
1161
1232
  await rm(file, { force: true });
1162
1233
  await rename2(inside, file);
@@ -1212,7 +1283,7 @@ var ScriptLibrary = class {
1212
1283
  if (exitCode === void 0)
1213
1284
  return { dir: setup.dir, result: `${SETUP_NAMES[setup.kind]} \u5B89\u88C5\u7A0B\u5E8F\u7684\u7A97\u53E3\u5DF2\u7ECF\u6253\u5F00\uFF0C\u5B89\u88C5\u4F4D\u7F6E\u9884\u5148\u586B\u597D\u4E86 ${setup.dir}` };
1214
1285
  const files = await exists(setup.dir) ? (await listFiles(setup.dir)).length : 0;
1215
- this.#options.log.info(`${id}: setup ${basename(setup.file)} exited ${exitCode}, ${files} file(s) in ${setup.dir}`);
1286
+ this.#options.log.info(`${id}: setup ${basename2(setup.file)} exited ${exitCode}, ${files} file(s) in ${setup.dir}`);
1216
1287
  return { dir: setup.dir, exitCode, result: setupExitText(setup.kind, exitCode), files, executables: files === 0 ? [] : (await probeProject(setup.dir)).executables };
1217
1288
  }
1218
1289
  /** The agent imported the folder a setup program installed into: the install (or update) is done. */
@@ -1224,7 +1295,7 @@ var ScriptLibrary = class {
1224
1295
  const script = this.#state.scripts.find((s) => s.id === setup.scriptId);
1225
1296
  const pack = setup.packId === void 0 ? void 0 : this.#packs.get(setup.packId);
1226
1297
  const inside = (dir) => {
1227
- const rel = relative(join2(this.toolsDir, setup.scriptId), dir);
1298
+ const rel = relative(join3(this.toolsDir, setup.scriptId), dir);
1228
1299
  return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
1229
1300
  };
1230
1301
  let id = setup.scriptId;
@@ -1266,7 +1337,7 @@ var ScriptLibrary = class {
1266
1337
  return this.#handOffSetup(setup, { scriptId: script.id, file: archive, version, asset: fetched.asset, dir: target, source: script.source, ...pack === void 0 ? {} : { packId: pack.manifest.id }, update: true }, byAgent, ctl);
1267
1338
  }
1268
1339
  const root = pack?.manifest.install.root;
1269
- const staging = join2(this.toolsDir, script.id, ".staging");
1340
+ const staging = join3(this.toolsDir, script.id, ".staging");
1270
1341
  try {
1271
1342
  ctl.phase("extracting", { message: `\u89E3\u538B ${fetched.asset.name}` });
1272
1343
  await rm(staging, { recursive: true, force: true });
@@ -1276,45 +1347,45 @@ var ScriptLibrary = class {
1276
1347
  return this.#handOffSetup(inner.kind, { scriptId: script.id, file: inner.file, version, asset: fetched.asset, dir: target, source: script.source, ...pack === void 0 ? {} : { packId: pack.manifest.id }, update: true }, byAgent, ctl);
1277
1348
  }
1278
1349
  const prefix = fetched.incremental ? await patchPrefix(staging, target, root) : void 0;
1279
- const from = prefix === void 0 ? staging : join2(staging, prefix);
1350
+ const from = prefix === void 0 ? staging : join3(staging, prefix);
1280
1351
  const keep = await keptFiles(pack, target);
1281
1352
  const writes = (await listFiles(from)).filter((rel) => !keep.has(rel.toLowerCase()) && !(fetched.incremental && from === staging && rel === "changes.json"));
1282
1353
  const removes = [];
1283
1354
  for (const rel of fetched.incremental ? await readMirrorChanges(staging, prefix) ?? [] : []) {
1284
- if (!keep.has(rel.toLowerCase()) && await exists(join2(target, ...rel.split("/"))))
1355
+ if (!keep.has(rel.toLowerCase()) && await exists(join3(target, ...rel.split("/"))))
1285
1356
  removes.push(rel);
1286
1357
  }
1287
1358
  const at = this.#now();
1288
- const dir = join2(this.toolsDir, script.id, ".local-backup", String(at));
1359
+ const dir = join3(this.toolsDir, script.id, ".local-backup", String(at));
1289
1360
  const backup = { dir, to: version, at, added: [], saved: [], ...script.localVersion === void 0 ? {} : { from: script.localVersion.version } };
1290
1361
  ctl.phase("running", { message: `\u5907\u4EFD\u5C06\u88AB\u66FF\u6362\u7684\u6587\u4EF6\uFF08${target}\uFF09` });
1291
1362
  for (const rel of writes) {
1292
- const path = join2(target, ...rel.split("/"));
1363
+ const path = join3(target, ...rel.split("/"));
1293
1364
  if (await exists(path)) {
1294
- await saveCopy(path, join2(dir, "files", ...rel.split("/")));
1365
+ await saveCopy(path, join3(dir, "files", ...rel.split("/")));
1295
1366
  backup.saved.push(rel);
1296
1367
  } else {
1297
1368
  backup.added.push(rel);
1298
1369
  }
1299
1370
  }
1300
1371
  for (const rel of removes) {
1301
- await saveCopy(join2(target, ...rel.split("/")), join2(dir, "files", ...rel.split("/")));
1372
+ await saveCopy(join3(target, ...rel.split("/")), join3(dir, "files", ...rel.split("/")));
1302
1373
  backup.saved.push(rel);
1303
1374
  }
1304
- await writeFile2(join2(dir, "manifest.json"), `${JSON.stringify({ script: script.id, target, ...backup }, null, 2)}
1375
+ await writeFile2(join3(dir, "manifest.json"), `${JSON.stringify({ script: script.id, target, ...backup }, null, 2)}
1305
1376
  `);
1306
1377
  ctl.phase("running", { message: `\u66F4\u65B0 ${target} \u5230 ${version}` });
1307
1378
  let doing = "";
1308
1379
  try {
1309
1380
  for (const rel of writes) {
1310
1381
  doing = rel;
1311
- const path = join2(target, ...rel.split("/"));
1382
+ const path = join3(target, ...rel.split("/"));
1312
1383
  await mkdir2(dirname2(path), { recursive: true });
1313
- await copyFile(join2(from, ...rel.split("/")), path);
1384
+ await copyFile(join3(from, ...rel.split("/")), path);
1314
1385
  }
1315
1386
  for (const rel of removes) {
1316
1387
  doing = rel;
1317
- await rm(join2(target, ...rel.split("/")), { recursive: true, force: true });
1388
+ await rm(join3(target, ...rel.split("/")), { recursive: true, force: true });
1318
1389
  }
1319
1390
  } catch (error) {
1320
1391
  const back = await putBack(target, backup).then(() => "\u5DF2\u6539\u56DE\u66F4\u65B0\u524D\u7684\u6587\u4EF6", (e) => `\u6539\u56DE\u65F6\u4E5F\u51FA\u9519\u4E86\uFF08${errorText(e)}\uFF09\uFF0C\u5907\u4EFD\u5728 ${dir}`);
@@ -1350,7 +1421,7 @@ var ScriptLibrary = class {
1350
1421
  const backup = script.backups?.at(-1);
1351
1422
  if (backup === void 0)
1352
1423
  throw new Error("\u6CA1\u6709\u53EF\u4EE5\u64A4\u9500\u7684\u66F4\u65B0");
1353
- if (!await exists(join2(backup.dir, "manifest.json")))
1424
+ if (!await exists(join3(backup.dir, "manifest.json")))
1354
1425
  throw new Error(`\u5907\u4EFD\u5DF2\u4E0D\u5B58\u5728\uFF1A${backup.dir}`);
1355
1426
  try {
1356
1427
  await putBack(script.source.path, backup);
@@ -1492,7 +1563,7 @@ var ScriptLibrary = class {
1492
1563
  const version = versionOfTag(release.tag);
1493
1564
  if (have?.(version) === true)
1494
1565
  return { version, asset: { name: asset.name, size: asset.size }, incremental: false };
1495
- const archive = join2(this.toolsDir, scriptId, ".downloads", asset.name);
1566
+ const archive = join3(this.toolsDir, scriptId, ".downloads", asset.name);
1496
1567
  ctl.phase("downloading", { message: asset.name, received: 0, total: asset.size });
1497
1568
  await download({
1498
1569
  url: asset.downloadUrl,
@@ -1524,7 +1595,7 @@ var ScriptLibrary = class {
1524
1595
  if (have?.(version) === true)
1525
1596
  return { version, asset: { name: file, size: 0 }, incremental: false, ...branch === void 0 ? {} : { branch } };
1526
1597
  const settings = this.#state.settings;
1527
- const archive = join2(this.toolsDir, scriptId, ".downloads", file);
1598
+ const archive = join3(this.toolsDir, scriptId, ".downloads", file);
1528
1599
  ctl.phase("downloading", { message: `${file}\uFF08${name} \u7684\u6E90\u7801\uFF09`, received: 0 });
1529
1600
  await download({
1530
1601
  url: github.sourceZipUrl(repo, head.sha),
@@ -1597,7 +1668,7 @@ var ScriptLibrary = class {
1597
1668
  ctl.phase("resolving", { message: "Mirror\u9171 \u6CA1\u6709\u7ED9\u51FA\u4E0B\u8F7D\u5730\u5740\uFF1B\u6539\u4ECE GitHub \u4E0B\u8F7D" });
1598
1669
  return void 0;
1599
1670
  }
1600
- let archive = join2(this.toolsDir, scriptId, ".downloads", mirrorFileName(latest.url, resource.rid, latest.version));
1671
+ let archive = join3(this.toolsDir, scriptId, ".downloads", mirrorFileName(latest.url, resource.rid, latest.version));
1601
1672
  ctl.phase("downloading", { message: `${name}\uFF08Mirror\u9171\uFF09`, received: 0, ...latest.size === void 0 ? {} : { total: latest.size } });
1602
1673
  const downloaded = await download({
1603
1674
  url: latest.url,
@@ -1693,7 +1764,7 @@ var ScriptLibrary = class {
1693
1764
  }
1694
1765
  /** The user's pack directory: packs here override built-in ones by id. */
1695
1766
  get userPackDir() {
1696
- return join2(this.#options.dataDir, "packs");
1767
+ return join3(this.#options.dataDir, "packs");
1697
1768
  }
1698
1769
  /** Describe a script with a (reloaded) pack, e.g. after the user accepted a draft. */
1699
1770
  async attachPack(scriptId, packId) {
@@ -1726,7 +1797,7 @@ var ScriptLibrary = class {
1726
1797
  async #importLocal(path, request) {
1727
1798
  if (!await stat(path).then((s) => s.isDirectory(), () => false))
1728
1799
  throw new Error(`\u4E0D\u662F\u4E00\u4E2A\u5B58\u5728\u7684\u76EE\u5F55\uFF1A${path}`);
1729
- if (this.#ownsDir(path))
1800
+ if (this.#ownsDir(path, false))
1730
1801
  throw new Error("\u8FD9\u4E2A\u76EE\u5F55\u5728\u5DE5\u5177\u76EE\u5F55\u91CC\uFF0C\u7531\u5B89\u88C5\u5668\u7BA1\u7406\uFF0C\u4E0D\u9700\u8981\u5BFC\u5165");
1731
1802
  const same = this.#state.scripts.find((s) => s.source.kind === "local" && samePath(s.source.path, path));
1732
1803
  if (same !== void 0)
@@ -1748,11 +1819,11 @@ var ScriptLibrary = class {
1748
1819
  }
1749
1820
  const probe = await probeProject(path);
1750
1821
  const known = pack === void 0 ? await knownByDir(path) : void 0;
1751
- const base = request.id ?? pack?.manifest.id ?? known?.id ?? slug(basename(path));
1822
+ const base = request.id ?? pack?.manifest.id ?? known?.id ?? slug(basename2(path));
1752
1823
  const id = this.#freeId(base);
1753
1824
  const script = {
1754
1825
  id,
1755
- name: request.name ?? pack?.manifest.name ?? known?.name ?? basename(path),
1826
+ name: request.name ?? pack?.manifest.name ?? known?.name ?? basename2(path),
1756
1827
  source: { kind: "local", path },
1757
1828
  current: "local",
1758
1829
  versions: [{ version: "local", dir: path, installedAt: this.#now() }],
@@ -1777,13 +1848,15 @@ var ScriptLibrary = class {
1777
1848
  const script = this.#script(id);
1778
1849
  if (this.#jobs.active(id) !== void 0)
1779
1850
  throw new Error(`${id} \u6709\u4EFB\u52A1\u6B63\u5728\u8FDB\u884C\uFF0C\u8BF7\u5148\u53D6\u6D88`);
1780
- if (deleteFiles && script.source.kind !== "local") {
1781
- const dir = join2(this.toolsDir, id);
1782
- if (this.#ownsDir(dir))
1783
- await rm(dir, { recursive: true, force: true });
1851
+ for (const root of [this.toolsDir, ...this.formerToolsDirs]) {
1852
+ if (deleteFiles && script.source.kind !== "local") {
1853
+ const dir = join3(root, id);
1854
+ if (this.#ownsDir(dir))
1855
+ await rm(dir, { recursive: true, force: true });
1856
+ }
1857
+ if (script.source.kind === "local")
1858
+ await rm(join3(root, id, ".local-backup"), { recursive: true, force: true });
1784
1859
  }
1785
- if (script.source.kind === "local")
1786
- await rm(join2(this.toolsDir, id, ".local-backup"), { recursive: true, force: true });
1787
1860
  for (const setup of this.#state.setups.filter((s) => s.scriptId === id))
1788
1861
  await rm(setup.file, { force: true });
1789
1862
  this.#state.setups = this.#state.setups.filter((s) => s.scriptId !== id);
@@ -1987,7 +2060,7 @@ var ScriptLibrary = class {
1987
2060
  const dir = this.#info(script).dir;
1988
2061
  const files = [];
1989
2062
  for (const rel of dir === void 0 ? [] : await changelogFiles(dir)) {
1990
- const text = await readFile3(join2(dir, rel), "utf8").catch(() => void 0);
2063
+ const text = await readFile3(join3(dir, rel), "utf8").catch(() => void 0);
1991
2064
  if (text !== void 0)
1992
2065
  files.push({ file: rel, text: text.slice(0, CHANGELOG_FILE_MAX), truncated: text.length > CHANGELOG_FILE_MAX });
1993
2066
  }
@@ -2033,7 +2106,7 @@ var ScriptLibrary = class {
2033
2106
  lines.push(`\u6587\u4EF6\u5939\u91CC\uFF08${names.length} \u9879\uFF09\uFF1A${names.slice(0, 60).join(" ")}${names.length > 60 ? " \u2026" : ""}`);
2034
2107
  const readme = entries.filter((e) => e.isFile() && /^read[ _-]?me.*\.(md|txt)$|^read[ _-]?me$/i.test(e.name)).sort((a, b) => Number(/zh|cn|中文/i.test(b.name)) - Number(/zh|cn|中文/i.test(a.name)) || a.name.length - b.name.length)[0];
2035
2108
  if (readme !== void 0) {
2036
- const text = (await readFile3(join2(info.dir, readme.name), "utf8").catch(() => "")).replace(/<!--[\s\S]*?-->/g, "").replace(/\n{3,}/g, "\n\n").trim();
2109
+ const text = (await readFile3(join3(info.dir, readme.name), "utf8").catch(() => "")).replace(/<!--[\s\S]*?-->/g, "").replace(/\n{3,}/g, "\n\n").trim();
2037
2110
  if (text !== "")
2038
2111
  lines.push("", `${readme.name}\uFF08\u5F00\u5934\u90E8\u5206\uFF09\uFF1A`, text.slice(0, 6e3));
2039
2112
  }
@@ -2057,9 +2130,12 @@ var ScriptLibrary = class {
2057
2130
  if (!taken.has(`${base}-${n}`))
2058
2131
  return `${base}-${n}`;
2059
2132
  }
2060
- #ownsDir(dir) {
2061
- const rel = relative(this.toolsDir, resolve(dir));
2062
- return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
2133
+ /** Inside the tools directory (or a former one, unless `former` is false): installed by the library, its to delete. */
2134
+ #ownsDir(dir, former = true) {
2135
+ return [this.toolsDir, ...former ? this.formerToolsDirs : []].some((root) => {
2136
+ const rel = relative(root, resolve(dir));
2137
+ return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
2138
+ });
2063
2139
  }
2064
2140
  /** Write the state; a script that moved past its pack's version is asked about once (onPackReview). */
2065
2141
  async #save() {
@@ -2086,7 +2162,7 @@ var CHANGELOG_NAME = /^(changelog|changes|history|release[-_ ]?notes?|更新日
2086
2162
  async function changelogFiles(dir) {
2087
2163
  const out = [];
2088
2164
  for (const sub of ["", "docs", "doc", "\u6587\u6863"]) {
2089
- for (const name of await readdir2(join2(dir, sub)).catch(() => [])) {
2165
+ for (const name of await readdir2(join3(dir, sub)).catch(() => [])) {
2090
2166
  if (CHANGELOG_NAME.test(name))
2091
2167
  out.push(sub === "" ? name : `${sub}/${name}`);
2092
2168
  }
@@ -2131,14 +2207,14 @@ function sourceVersion(date, sha) {
2131
2207
  return `${day}-${sha.slice(0, 7)}`;
2132
2208
  }
2133
2209
  async function patchPrefix(patch, baseDir, root) {
2134
- if (root !== void 0 && await exists(join2(patch, root)))
2210
+ if (root !== void 0 && await exists(join3(patch, root)))
2135
2211
  return root.replace(/\\/g, "/");
2136
2212
  const entries = (await readdir2(patch, { withFileTypes: true })).filter((e) => e.name !== "changes.json");
2137
- return entries.length === 1 && entries[0].isDirectory() && !await exists(join2(baseDir, entries[0].name)) ? entries[0].name : void 0;
2213
+ return entries.length === 1 && entries[0].isDirectory() && !await exists(join3(baseDir, entries[0].name)) ? entries[0].name : void 0;
2138
2214
  }
2139
2215
  async function listFiles(dir, sub = "") {
2140
2216
  const files = [];
2141
- for (const entry of await readdir2(join2(dir, sub), { withFileTypes: true })) {
2217
+ for (const entry of await readdir2(join3(dir, sub), { withFileTypes: true })) {
2142
2218
  const rel = sub === "" ? entry.name : `${sub}/${entry.name}`;
2143
2219
  if (entry.isDirectory())
2144
2220
  files.push(...await listFiles(dir, rel));
@@ -2162,9 +2238,9 @@ async function keptFiles(pack, dir) {
2162
2238
  const parts = file.path.split(/[\\/]/);
2163
2239
  const last = parts.pop();
2164
2240
  const sub = parts.join("/");
2165
- const names = last.includes("*") || last.includes("?") ? (await readdir2(join2(dir, sub)).catch(() => [])).filter((n) => globToRegExp(last).test(n)) : [last];
2241
+ const names = last.includes("*") || last.includes("?") ? (await readdir2(join3(dir, sub)).catch(() => [])).filter((n) => globToRegExp(last).test(n)) : [last];
2166
2242
  for (const name of names) {
2167
- if (await stat(join2(dir, sub, name)).then((s) => s.isFile(), () => false))
2243
+ if (await stat(join3(dir, sub, name)).then((s) => s.isFile(), () => false))
2168
2244
  kept.add((sub === "" ? name : `${sub}/${name}`).toLowerCase());
2169
2245
  }
2170
2246
  }
@@ -2176,11 +2252,11 @@ async function saveCopy(path, dest) {
2176
2252
  }
2177
2253
  async function putBack(target, backup) {
2178
2254
  for (const rel of backup.added)
2179
- await rm(join2(target, ...rel.split("/")), { force: true });
2255
+ await rm(join3(target, ...rel.split("/")), { force: true });
2180
2256
  for (const rel of backup.saved) {
2181
- const saved = join2(backup.dir, "files", ...rel.split("/"));
2257
+ const saved = join3(backup.dir, "files", ...rel.split("/"));
2182
2258
  if (await exists(saved))
2183
- await saveCopy(saved, join2(target, ...rel.split("/")));
2259
+ await saveCopy(saved, join3(target, ...rel.split("/")));
2184
2260
  }
2185
2261
  }
2186
2262
  function newName(scriptId, source, pack) {
@@ -2190,27 +2266,27 @@ function newName(scriptId, source, pack) {
2190
2266
  async function realName(file, finalUrl) {
2191
2267
  let name;
2192
2268
  try {
2193
- const served = decodeURIComponent(basename(new URL(finalUrl).pathname));
2269
+ const served = decodeURIComponent(basename2(new URL(finalUrl).pathname));
2194
2270
  if (archiveKind(served) !== void 0 && !/[\\/:*?"<>|]/.test(served))
2195
2271
  name = served;
2196
2272
  } catch {
2197
2273
  }
2198
2274
  if (name === void 0) {
2199
2275
  const found = await contentKind(file);
2200
- if (found === void 0 || archiveKind(basename(file)) === found.kind)
2276
+ if (found === void 0 || archiveKind(basename2(file)) === found.kind)
2201
2277
  return file;
2202
- name = basename(file).replace(/\.(zip|7z|tar(\.\w+)?|exe|msi)$/i, "") + found.ext;
2278
+ name = basename2(file).replace(/\.(zip|7z|tar(\.\w+)?|exe|msi)$/i, "") + found.ext;
2203
2279
  }
2204
- if (name === basename(file))
2280
+ if (name === basename2(file))
2205
2281
  return file;
2206
- const renamed = join2(dirname2(file), name);
2282
+ const renamed = join3(dirname2(file), name);
2207
2283
  await rm(renamed, { force: true });
2208
2284
  await rename2(file, renamed);
2209
2285
  return renamed;
2210
2286
  }
2211
2287
  function mirrorFileName(url, rid, version) {
2212
2288
  try {
2213
- const name = basename(new URL(url).pathname);
2289
+ const name = basename2(new URL(url).pathname);
2214
2290
  if (archiveKind(name) !== void 0)
2215
2291
  return name;
2216
2292
  } catch {
@@ -2246,12 +2322,12 @@ async function carryConfig(pack, fromDir, toDir) {
2246
2322
  const parts = file.path.split(/[\\/]/);
2247
2323
  const last = parts.pop();
2248
2324
  const sub = parts.join("/");
2249
- const names = last.includes("*") || last.includes("?") ? (await readdir2(join2(fromDir, sub)).catch(() => [])).filter((n) => globToRegExp(last).test(n)) : [last];
2325
+ const names = last.includes("*") || last.includes("?") ? (await readdir2(join3(fromDir, sub)).catch(() => [])).filter((n) => globToRegExp(last).test(n)) : [last];
2250
2326
  for (const name of names) {
2251
- const source = join2(fromDir, sub, name);
2327
+ const source = join3(fromDir, sub, name);
2252
2328
  if (!await stat(source).then((s) => s.isFile(), () => false))
2253
2329
  continue;
2254
- const target = join2(toDir, sub, name);
2330
+ const target = join3(toDir, sub, name);
2255
2331
  await mkdir2(dirname2(target), { recursive: true });
2256
2332
  await copyFile(source, target);
2257
2333
  copied.push(sub === "" ? name : `${sub}/${name}`);
@@ -2265,9 +2341,9 @@ async function scriptCdk(pack, dir) {
2265
2341
  const parts = file.path.split(/[\\/]/);
2266
2342
  const last = parts.pop();
2267
2343
  const sub = parts.join("/");
2268
- const names = last.includes("*") || last.includes("?") ? (await readdir2(join2(dir, sub)).catch(() => [])).filter((n) => globToRegExp(last).test(n)) : [last];
2344
+ const names = last.includes("*") || last.includes("?") ? (await readdir2(join3(dir, sub)).catch(() => [])).filter((n) => globToRegExp(last).test(n)) : [last];
2269
2345
  for (const name of names) {
2270
- const text = await readFile3(join2(dir, sub, name), "utf8").catch(() => "");
2346
+ const text = await readFile3(join3(dir, sub, name), "utf8").catch(() => "");
2271
2347
  const found = CDK_ENTRY.exec(text)?.[1];
2272
2348
  if (found !== void 0)
2273
2349
  return found;
@@ -2420,18 +2496,31 @@ function optimizer(ctx, library, log) {
2420
2496
  }
2421
2497
 
2422
2498
  // packages/script-registry/lib/skill-hub-plugin.js
2423
- import { join as join4 } from "node:path";
2499
+ import { join as join5 } from "node:path";
2424
2500
 
2425
2501
  // packages/script-registry/lib/skill-hub.js
2426
2502
  import { createHash } from "node:crypto";
2427
- import { cp as cp2, mkdir as mkdir3, readdir as readdir3, readFile as readFile4, rename as rename3, rm as rm2, stat as stat2, writeFile as writeFile3 } from "node:fs/promises";
2428
- import { join as join3, relative as relative2, resolve as resolve2, sep } from "node:path";
2503
+ import { cp as cp2, mkdir as mkdir3, readdir as readdir3, readFile as readFile4, rename as rename3, rm as rm2, stat as stat2 } from "node:fs/promises";
2504
+ import { join as join4, relative as relative2, resolve as resolve2, sep } from "node:path";
2429
2505
  var DEFAULT_HUB_REPO = { repo: "MultiGameAssistant/skills", branch: "main" };
2430
2506
  var REFRESH_MS = 24 * 60 * 6e4;
2431
2507
  var SKILL_FILE2 = "SKILL.md";
2432
2508
  var NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
2433
2509
  var Owner = external_exports.object({ games: external_exports.array(external_exports.string()).optional(), scripts: external_exports.array(external_exports.string()).optional() });
2434
- var Installed = external_exports.object({ repo: external_exports.string(), path: external_exports.string(), hash: external_exports.string(), at: external_exports.number(), skipped: external_exports.string().optional(), owner: Owner.optional() });
2510
+ var Previous = external_exports.object({ hash: external_exports.string(), version: external_exports.string().optional(), at: external_exports.number() });
2511
+ var Installed = external_exports.object({
2512
+ repo: external_exports.string(),
2513
+ path: external_exports.string(),
2514
+ hash: external_exports.string(),
2515
+ at: external_exports.number(),
2516
+ owner: Owner.optional(),
2517
+ /** `hash` is of the whole folder; records from before were of SKILL.md alone. */
2518
+ folder: external_exports.literal(true).optional(),
2519
+ version: external_exports.string().optional(),
2520
+ previous: Previous.optional(),
2521
+ /** The repository's hash that was gone back from. */
2522
+ held: external_exports.string().optional()
2523
+ });
2435
2524
  var State = external_exports.object({
2436
2525
  repos: external_exports.array(external_exports.object({ repo: external_exports.string(), branch: external_exports.string() })).optional(),
2437
2526
  installed: external_exports.record(external_exports.string(), Installed).default({}),
@@ -2444,7 +2533,10 @@ var Index = external_exports.object({
2444
2533
  title: external_exports.string().optional(),
2445
2534
  kind: external_exports.enum(["game", "script", "general"]).optional(),
2446
2535
  games: external_exports.array(external_exports.string()).optional(),
2447
- scripts: external_exports.array(external_exports.string()).optional()
2536
+ scripts: external_exports.array(external_exports.string()).optional(),
2537
+ version: external_exports.string().max(40).optional(),
2538
+ changes: external_exports.string().max(300).optional(),
2539
+ requires: external_exports.string().max(60).optional()
2448
2540
  }))
2449
2541
  });
2450
2542
  var SkillHub = class {
@@ -2457,15 +2549,31 @@ var SkillHub = class {
2457
2549
  this.#now = options.now ?? Date.now;
2458
2550
  }
2459
2551
  get skillsDir() {
2460
- return join3(this.#options.dir, "skills");
2552
+ return join4(this.#options.dir, "skills");
2461
2553
  }
2462
2554
  /** Read the state and register the downloaded skills. */
2463
2555
  start() {
2464
2556
  this.#loading ??= (async () => {
2465
2557
  try {
2466
- this.#state = State.parse(JSON.parse(await readFile4(join3(this.#options.dir, "state.json"), "utf8")));
2558
+ this.#state = State.parse(JSON.parse(await readFile4(join4(this.#options.dir, "state.json"), "utf8")));
2467
2559
  } catch {
2468
2560
  }
2561
+ await rm2(join4(this.#options.dir, "base"), { recursive: true, force: true });
2562
+ let migrated = false;
2563
+ for (const [name, record] of Object.entries(this.#state.installed)) {
2564
+ if (record.folder === true)
2565
+ continue;
2566
+ const here = await folderHash(join4(this.skillsDir, name)).catch(() => void 0);
2567
+ if (here === void 0)
2568
+ continue;
2569
+ record.hash = here;
2570
+ record.folder = true;
2571
+ migrated = true;
2572
+ }
2573
+ if (migrated) {
2574
+ this.#state.read = {};
2575
+ await this.#save();
2576
+ }
2469
2577
  for (const name of Object.keys(this.#state.installed))
2470
2578
  await this.#register(name);
2471
2579
  })();
@@ -2527,9 +2635,9 @@ var SkillHub = class {
2527
2635
  for (const [name, record] of Object.entries(this.#state.installed)) {
2528
2636
  if (items.some((i) => i.name === name))
2529
2637
  continue;
2530
- const content = await readFile4(join3(this.skillsDir, name, SKILL_FILE2), "utf8").catch(() => "");
2638
+ const content = await readFile4(join4(this.skillsDir, name, SKILL_FILE2), "utf8").catch(() => "");
2531
2639
  const front = frontmatter(content);
2532
- items.push({ name, description: front?.description ?? "", kind: "general", games: [], scripts: [], repo: record.repo, path: record.path, hash: record.hash, installed: { at: record.at, modified: hash(content) !== record.hash, update: false } });
2640
+ items.push({ name, description: front?.description ?? "", kind: "general", games: [], scripts: [], repo: record.repo, path: record.path, hash: record.hash, installed: installedOf(record, false) });
2533
2641
  }
2534
2642
  return { items, repos: this.repos(), errors, ...fetchedAt === void 0 ? {} : { fetchedAt } };
2535
2643
  }
@@ -2539,75 +2647,46 @@ var SkillHub = class {
2539
2647
  const blocked = (await this.#options.taken()).get(name);
2540
2648
  if (blocked !== void 0)
2541
2649
  throw new Error(`\u5DF2\u6709\u540C\u540D\u7684${blocked}\u300C${name}\u300D\uFF0C\u6CA1\u6709\u4E0B\u8F7D`);
2650
+ this.#checkCompatible(skill);
2542
2651
  await this.#put(skill);
2543
2652
  this.#options.log.info(`skill hub: downloaded ${name} from ${skill.repo}`);
2544
2653
  return this.#item(skill, await this.#options.taken());
2545
2654
  }
2546
- /**
2547
- * Take the repository's newer version. Unchanged here: replaced. Changed:
2548
- * `conflict`, unless `resolve` says what to do — `keep` the user's (and
2549
- * stop offering this version), or `replace` it (the user's kept in
2550
- * `backup/`).
2551
- */
2552
- async update(name, resolve3, signal) {
2655
+ /** Take the repository's newer version, in place of this one (changed here or not). */
2656
+ async update(name, signal) {
2553
2657
  const record = this.#record(name);
2554
2658
  const skill = await this.#find(name, record.repo, signal);
2555
- const taken = await this.#options.taken();
2556
2659
  if (skill.hash === record.hash)
2557
- return { state: "current", item: await this.#item(skill, taken) };
2558
- const file = join3(this.skillsDir, name, SKILL_FILE2);
2559
- const mine = await readFile4(file, "utf8").catch(() => void 0);
2560
- const modified = mine !== void 0 && hash(mine) !== record.hash;
2561
- if (modified && resolve3 === void 0)
2562
- return { state: "conflict", item: await this.#item(skill, taken) };
2563
- if (modified && resolve3 === "keep") {
2564
- this.#state.installed[name] = { ...record, skipped: skill.hash };
2565
- await this.#save();
2566
- return { state: "kept", item: await this.#item(skill, taken) };
2567
- }
2568
- let backup;
2569
- if (modified) {
2570
- backup = join3(this.#options.dir, "backup", `${name}-${this.#now()}.md`);
2571
- await mkdir3(join3(this.#options.dir, "backup"), { recursive: true });
2572
- await writeFile3(backup, mine);
2573
- }
2660
+ return { state: "current", item: await this.#item(skill, await this.#options.taken()) };
2661
+ this.#checkCompatible(skill);
2574
2662
  await this.#put(skill);
2575
- return { state: "updated", item: await this.#item(skill, taken), ...backup === void 0 ? {} : { backup } };
2663
+ return { state: "updated", item: await this.#item(skill, await this.#options.taken()) };
2576
2664
  }
2577
- /**
2578
- * The three versions for merging a changed skill with the repository's
2579
- * newer one: what was downloaded (`base`), the user's, the new one.
2580
- */
2581
- async mergeInputs(name, signal) {
2665
+ /** Go back to the version the last update replaced; the newer one is not offered again until the repository has another. */
2666
+ async rollback(name) {
2582
2667
  const record = this.#record(name);
2583
- const skill = await this.#find(name, record.repo, signal);
2584
- const file = join3(this.skillsDir, name, SKILL_FILE2);
2585
- const [base, mine, theirs] = await Promise.all([
2586
- readFile4(join3(this.#options.dir, "base", name, SKILL_FILE2), "utf8").catch(() => ""),
2587
- readFile4(file, "utf8"),
2588
- readFile4(this.#repoFile(skill), "utf8")
2589
- ]);
2590
- return { base, mine, theirs, file, skill };
2591
- }
2592
- /** After a merge was written into the user's file: the new version counts as taken (the file stays the user's). */
2593
- async merged(name, skill) {
2594
- const record = this.#record(name);
2595
- await mkdir3(join3(this.#options.dir, "base", name), { recursive: true });
2596
- await cp2(this.#repoFile(skill), join3(this.#options.dir, "base", name, SKILL_FILE2));
2597
- this.#state.installed[name] = { repo: record.repo, path: record.path, hash: skill.hash, at: this.#now() };
2668
+ const kept = join4(this.#previousDir, name);
2669
+ const previous = record.previous;
2670
+ if (previous === void 0 || !await stat2(kept).then((st) => st.isDirectory(), () => false))
2671
+ throw new Error(`\u300C${name}\u300D\u6CA1\u6709\u4E0A\u4E00\u4E2A\u7248\u672C\u53EF\u4EE5\u56DE\u9000`);
2672
+ const held = record.hash;
2673
+ await rm2(join4(this.skillsDir, name), { recursive: true, force: true });
2674
+ await rename3(kept, join4(this.skillsDir, name));
2675
+ const { previous: _previous, version: _version, ...rest } = record;
2676
+ this.#state.installed[name] = { ...rest, hash: previous.hash, at: this.#now(), folder: true, held, ...previous.version === void 0 ? {} : { version: previous.version } };
2598
2677
  await this.#save();
2599
2678
  await this.#register(name);
2600
- }
2601
- /** The user's version and the repository's, for showing what differs. */
2602
- async diff(name, signal) {
2603
- const { mine, theirs } = await this.mergeInputs(name, signal);
2604
- return { mine, theirs };
2679
+ this.#options.log.info(`skill hub: ${name} back to ${previous.version ?? previous.hash}`);
2680
+ const listed = (await this.list()).items.find((i) => i.name === name);
2681
+ if (listed === void 0)
2682
+ throw new Error(`\u6280\u80FD\u5E93\u91CC\u6CA1\u6709\u300C${name}\u300D`);
2683
+ return listed;
2605
2684
  }
2606
2685
  async remove(name) {
2607
2686
  this.#record(name);
2608
2687
  this.#options.register(name, void 0);
2609
- await rm2(join3(this.skillsDir, name), { recursive: true, force: true });
2610
- await rm2(join3(this.#options.dir, "base", name), { recursive: true, force: true });
2688
+ await rm2(join4(this.#previousDir, name), { recursive: true, force: true });
2689
+ await rm2(join4(this.skillsDir, name), { recursive: true, force: true });
2611
2690
  delete this.#state.installed[name];
2612
2691
  await this.#save();
2613
2692
  }
@@ -2630,6 +2709,21 @@ var SkillHub = class {
2630
2709
  return this.#state.installed[name] !== void 0;
2631
2710
  }
2632
2711
  // ── internals ──
2712
+ get #previousDir() {
2713
+ return join4(this.#options.dir, "previous");
2714
+ }
2715
+ /** Why this app cannot take the skill's version; undefined: it can. */
2716
+ #incompatible(skill) {
2717
+ const app = this.#options.appVersion?.();
2718
+ if (skill.requires === void 0 || app === void 0 || satisfies(app, skill.requires))
2719
+ return void 0;
2720
+ return `\u9700\u8981\u8F6F\u4EF6\u7248\u672C ${skill.requires}\uFF08\u73B0\u5728\u662F ${app}\uFF09\uFF0C\u5148\u66F4\u65B0\u8F6F\u4EF6`;
2721
+ }
2722
+ #checkCompatible(skill) {
2723
+ const why = this.#incompatible(skill);
2724
+ if (why !== void 0)
2725
+ throw new Error(`\u300C${skill.name}\u300D${skill.version === void 0 ? "" : ` ${skill.version}`}${why}`);
2726
+ }
2633
2727
  #record(name) {
2634
2728
  const record = this.#state.installed[name];
2635
2729
  if (record === void 0)
@@ -2653,25 +2747,39 @@ var SkillHub = class {
2653
2747
  return skill;
2654
2748
  }
2655
2749
  #repoFile(skill) {
2656
- return join3(this.#options.dir, "repos", repoKey({ repo: skill.repo, branch: "" }), ...skill.path.split("/"), SKILL_FILE2);
2750
+ return join4(this.#options.dir, "repos", repoKey({ repo: skill.repo, branch: "" }), ...skill.path.split("/"), SKILL_FILE2);
2657
2751
  }
2658
- /** Copy the repository's version in as the downloaded skill (and as the base for later merges). */
2752
+ /** Copy the repository's version in as the downloaded skill. */
2659
2753
  async #put(skill) {
2660
- const from = join3(this.#options.dir, "repos", repoKey({ repo: skill.repo, branch: "" }), ...skill.path.split("/"));
2661
- const to = join3(this.skillsDir, skill.name);
2754
+ const from = join4(this.#options.dir, "repos", repoKey({ repo: skill.repo, branch: "" }), ...skill.path.split("/"));
2755
+ const to = join4(this.skillsDir, skill.name);
2756
+ const before = this.#state.installed[skill.name];
2757
+ let previous;
2758
+ if (before !== void 0 && await stat2(to).then((st) => st.isDirectory(), () => false)) {
2759
+ await rm2(join4(this.#previousDir, skill.name), { recursive: true, force: true });
2760
+ await mkdir3(this.#previousDir, { recursive: true });
2761
+ await rename3(to, join4(this.#previousDir, skill.name));
2762
+ previous = { hash: before.hash, at: before.at, ...before.version === void 0 ? {} : { version: before.version } };
2763
+ }
2662
2764
  await rm2(to, { recursive: true, force: true });
2663
2765
  await mkdir3(this.skillsDir, { recursive: true });
2664
2766
  await cp2(from, to, { recursive: true });
2665
- await rm2(join3(this.#options.dir, "base", skill.name), { recursive: true, force: true });
2666
- await mkdir3(join3(this.#options.dir, "base", skill.name), { recursive: true });
2667
- await cp2(join3(from, SKILL_FILE2), join3(this.#options.dir, "base", skill.name, SKILL_FILE2));
2668
- const owner = this.#state.installed[skill.name]?.owner;
2669
- this.#state.installed[skill.name] = { repo: skill.repo, path: skill.path, hash: skill.hash, at: this.#now(), ...owner === void 0 ? {} : { owner } };
2767
+ const owner = before?.owner;
2768
+ this.#state.installed[skill.name] = {
2769
+ repo: skill.repo,
2770
+ path: skill.path,
2771
+ hash: skill.hash,
2772
+ at: this.#now(),
2773
+ folder: true,
2774
+ ...skill.version === void 0 ? {} : { version: skill.version },
2775
+ ...owner === void 0 ? {} : { owner },
2776
+ ...previous === void 0 ? {} : { previous }
2777
+ };
2670
2778
  await this.#save();
2671
2779
  await this.#register(skill.name);
2672
2780
  }
2673
2781
  async #register(name) {
2674
- const path = join3(this.skillsDir, name, SKILL_FILE2);
2782
+ const path = join4(this.skillsDir, name, SKILL_FILE2);
2675
2783
  const content = await readFile4(path, "utf8").catch(() => void 0);
2676
2784
  const front = content === void 0 ? void 0 : frontmatter(content);
2677
2785
  if (content === void 0 || front === void 0) {
@@ -2685,34 +2793,47 @@ var SkillHub = class {
2685
2793
  const games = ids(listed?.games);
2686
2794
  const scripts = ids(listed?.scripts);
2687
2795
  const owner = games.length + scripts.length === 0 ? void 0 : { ...games.length === 0 ? {} : { games }, ...scripts.length === 0 ? {} : { scripts } };
2688
- this.#options.register(name, { description: front.description, content: front.body, path, dir: join3(this.skillsDir, name), ...owner === void 0 ? {} : { owner } });
2796
+ this.#options.register(name, { description: front.description, content: front.body, path, dir: join4(this.skillsDir, name), ...owner === void 0 ? {} : { owner } });
2689
2797
  }
2690
- async #item(skill, taken) {
2798
+ async #item(found, taken) {
2799
+ const { name, description, title, kind, games, scripts, repo, path, hash, version, changes, requires } = found;
2800
+ const skill = {
2801
+ name,
2802
+ description,
2803
+ kind,
2804
+ games,
2805
+ scripts,
2806
+ repo,
2807
+ path,
2808
+ hash,
2809
+ ...title === void 0 ? {} : { title },
2810
+ ...version === void 0 ? {} : { version },
2811
+ ...changes === void 0 ? {} : { changes },
2812
+ ...requires === void 0 ? {} : { requires }
2813
+ };
2814
+ const incompatible = this.#incompatible(skill);
2691
2815
  const record = this.#state.installed[skill.name];
2692
2816
  if (record === void 0) {
2693
2817
  const blocked = taken.get(skill.name);
2694
- return { ...skill, ...blocked === void 0 ? {} : { blocked: `\u5DF2\u6709\u540C\u540D\u7684${blocked}` } };
2818
+ return { ...skill, ...blocked === void 0 ? {} : { blocked: `\u5DF2\u6709\u540C\u540D\u7684${blocked}` }, ...incompatible === void 0 ? {} : { incompatible } };
2695
2819
  }
2696
- const content = await readFile4(join3(this.skillsDir, skill.name, SKILL_FILE2), "utf8").catch(() => "");
2697
- return {
2698
- ...skill,
2699
- installed: { at: record.at, modified: hash(content) !== record.hash, update: skill.repo === record.repo && skill.hash !== record.hash && skill.hash !== record.skipped }
2700
- };
2820
+ const newer = skill.repo === record.repo && skill.hash !== record.hash && skill.hash !== record.held;
2821
+ return { ...skill, installed: installedOf(record, newer, skill.hash === record.held), ...newer && incompatible !== void 0 ? { incompatible } : {} };
2701
2822
  }
2702
2823
  /** Download the repository and list its skills; the copy replaces the one before. */
2703
2824
  async #readRepo(repo, signal) {
2704
2825
  const key = repoKey(repo);
2705
- const work = join3(this.#options.dir, "downloads");
2826
+ const work = join4(this.#options.dir, "downloads");
2706
2827
  await mkdir3(work, { recursive: true });
2707
- const archive = join3(work, `${key}.zip`);
2708
- const unpacked = join3(work, `${key}-${this.#now()}`);
2828
+ const archive = join4(work, `${key}.zip`);
2829
+ const unpacked = join4(work, `${key}-${this.#now()}`);
2709
2830
  await this.#options.download(`https://codeload.github.com/${repo.repo}/zip/refs/heads/${encodeURIComponent(repo.branch)}`, archive, signal);
2710
2831
  try {
2711
2832
  await this.#options.extract(archive, unpacked, signal);
2712
2833
  const skills = await readSkills(unpacked, repo.repo);
2713
- const target = join3(this.#options.dir, "repos", key);
2834
+ const target = join4(this.#options.dir, "repos", key);
2714
2835
  await rm2(target, { recursive: true, force: true });
2715
- await mkdir3(join3(this.#options.dir, "repos"), { recursive: true });
2836
+ await mkdir3(join4(this.#options.dir, "repos"), { recursive: true });
2716
2837
  await rename3(unpacked, target);
2717
2838
  return skills;
2718
2839
  } finally {
@@ -2721,12 +2842,12 @@ var SkillHub = class {
2721
2842
  }
2722
2843
  }
2723
2844
  #save() {
2724
- return mkdir3(this.#options.dir, { recursive: true }).then(() => writeFileAtomic(join3(this.#options.dir, "state.json"), `${JSON.stringify(this.#state, null, 1)}
2845
+ return mkdir3(this.#options.dir, { recursive: true }).then(() => writeFileAtomic(join4(this.#options.dir, "state.json"), `${JSON.stringify(this.#state, null, 1)}
2725
2846
  `));
2726
2847
  }
2727
2848
  };
2728
2849
  async function readSkills(root, repo) {
2729
- const indexText = await readFile4(join3(root, "index.json"), "utf8").catch(() => void 0);
2850
+ const indexText = await readFile4(join4(root, "index.json"), "utf8").catch(() => void 0);
2730
2851
  const listed = [];
2731
2852
  if (indexText !== void 0) {
2732
2853
  const parsed = Index.safeParse(JSON.parse(indexText.replace(/^/, "")));
@@ -2744,8 +2865,10 @@ async function readSkills(root, repo) {
2744
2865
  const rel = relative2(resolve2(root), full);
2745
2866
  if (path === "" || rel.startsWith("..") || rel.split(sep).includes(".."))
2746
2867
  continue;
2747
- const content = await readFile4(join3(full, SKILL_FILE2), "utf8").catch(() => void 0);
2868
+ const content = await readFile4(join4(full, SKILL_FILE2), "utf8").catch(() => void 0);
2748
2869
  const front = content === void 0 ? void 0 : frontmatter(content);
2870
+ const version = entry.version ?? front?.version;
2871
+ const { changes, requires } = entry;
2749
2872
  if (content === void 0 || front === void 0)
2750
2873
  continue;
2751
2874
  const name = entry.name ?? front.name;
@@ -2761,15 +2884,18 @@ async function readSkills(root, repo) {
2761
2884
  scripts: entry.scripts ?? [],
2762
2885
  repo,
2763
2886
  path,
2764
- hash: hash(content),
2765
- ...entry.title === void 0 ? {} : { title: entry.title }
2887
+ hash: await folderHash(full),
2888
+ ...entry.title === void 0 ? {} : { title: entry.title },
2889
+ ...version === void 0 ? {} : { version },
2890
+ ...changes === void 0 ? {} : { changes },
2891
+ ...requires === void 0 ? {} : { requires }
2766
2892
  });
2767
2893
  }
2768
2894
  return skills;
2769
2895
  }
2770
2896
  async function findSkillFolders(root, sub, depth) {
2771
2897
  const out = [];
2772
- const entries = await readdir3(join3(root, sub), { withFileTypes: true }).catch(() => []);
2898
+ const entries = await readdir3(join4(root, sub), { withFileTypes: true }).catch(() => []);
2773
2899
  if (sub !== "" && entries.some((e) => e.isFile() && e.name === SKILL_FILE2))
2774
2900
  out.push(sub);
2775
2901
  if (depth === 0)
@@ -2801,10 +2927,39 @@ function frontmatter(text) {
2801
2927
  if (description === void 0 || description === "")
2802
2928
  return void 0;
2803
2929
  const name = field("name");
2804
- return { ...name === void 0 ? {} : { name }, description, body: match[2] };
2930
+ const version = field("version");
2931
+ return { ...name === void 0 ? {} : { name }, ...version === void 0 ? {} : { version }, description, body: match[2] };
2805
2932
  }
2806
- function hash(text) {
2807
- return createHash("sha256").update(text.replace(/\r\n/g, "\n")).digest("hex").slice(0, 16);
2933
+ async function folderHash(dir) {
2934
+ const files = [];
2935
+ const walk = async (sub) => {
2936
+ for (const entry of await readdir3(join4(dir, sub), { withFileTypes: true })) {
2937
+ const rel = sub === "" ? entry.name : `${sub}/${entry.name}`;
2938
+ if (entry.isDirectory()) {
2939
+ if (entry.name !== "__pycache__")
2940
+ await walk(rel);
2941
+ } else if (entry.isFile())
2942
+ files.push(rel);
2943
+ }
2944
+ };
2945
+ await walk("");
2946
+ if (!files.includes(SKILL_FILE2))
2947
+ throw new Error(`${dir} \u91CC\u6CA1\u6709 ${SKILL_FILE2}`);
2948
+ const digest = createHash("sha256");
2949
+ for (const rel of files.sort()) {
2950
+ const bytes = await readFile4(join4(dir, ...rel.split("/")));
2951
+ digest.update(rel).update("\0").update(bytes.includes(0) ? bytes : bytes.toString("utf8").replace(/\r\n/g, "\n")).update("\0");
2952
+ }
2953
+ return digest.digest("hex").slice(0, 16);
2954
+ }
2955
+ function installedOf(record, update, held = false) {
2956
+ return {
2957
+ at: record.at,
2958
+ update,
2959
+ ...record.version === void 0 ? {} : { version: record.version },
2960
+ ...record.previous === void 0 ? {} : { previous: { at: record.previous.at, ...record.previous.version === void 0 ? {} : { version: record.previous.version } } },
2961
+ ...held ? { held: true } : {}
2962
+ };
2808
2963
  }
2809
2964
  function repoKey(repo) {
2810
2965
  return repo.repo.toLowerCase().replace(/[^a-z0-9._-]+/g, "__");
@@ -2826,7 +2981,6 @@ function takenLabel(source) {
2826
2981
  return "\u6280\u80FD\uFF08\u4F60\u7684\u6280\u80FD\u6587\u4EF6\u5939\uFF09";
2827
2982
  return "\u6280\u80FD";
2828
2983
  }
2829
- var MERGE_TIMEOUT_MS = 10 * 6e4;
2830
2984
  function startSkillHub(ctx, library, ready, approve, log) {
2831
2985
  const entries = /* @__PURE__ */ new Map();
2832
2986
  const disposers = /* @__PURE__ */ new Map();
@@ -2846,7 +3000,7 @@ function startSkillHub(ctx, library, ready, approve, log) {
2846
3000
  }
2847
3001
  };
2848
3002
  const hub = new SkillHub({
2849
- dir: join4(library.dataDir, "skill-hub"),
3003
+ dir: join5(library.dataDir, "skill-hub"),
2850
3004
  download: (url, dest, signal) => library.downloadFromGitHub(url, dest, signal),
2851
3005
  extract: async (archive, dest, signal) => {
2852
3006
  await library.unpack(archive, dest, signal);
@@ -2865,6 +3019,8 @@ function startSkillHub(ctx, library, ready, approve, log) {
2865
3019
  entries.set(name, skill);
2866
3020
  apply(name);
2867
3021
  },
3022
+ // For a skill's `requires`: the desktop app passes its version; the dsh plugin has it in its manifest; from source, none.
3023
+ appVersion: () => process.env["ADG_APP_VERSION"] || pluginVersion(),
2868
3024
  log
2869
3025
  });
2870
3026
  const started = ready.then(() => hub.start());
@@ -2879,37 +3035,6 @@ function startSkillHub(ctx, library, ready, approve, log) {
2879
3035
  skills = void 0;
2880
3036
  }, "adg-skill-hub skills");
2881
3037
  });
2882
- const merge = async (name, signal) => {
2883
- const sessions = ctx.get("sessionController");
2884
- if (sessions === void 0)
2885
- throw new Error("agent \u73B0\u5728\u4E0D\u53EF\u7528\uFF08\u4F1A\u8BDD\u670D\u52A1\u6CA1\u6709\u52A0\u8F7D\uFF09");
2886
- const { base, mine, theirs, file, skill } = await hub.mergeInputs(name, signal);
2887
- const conversations = sessionConversations(sessions, () => ctx.get("adgGateway")?.workspaceDir(), void 0, () => ctx.get("adgGateway"));
2888
- const sessionId = await conversations.home(SCRIPT_ROLE.id);
2889
- const prompt = [
2890
- `\u6280\u80FD\u5E93\u91CC\u7684\u6280\u80FD\u300C${name}\u300D\u6709\u4E86\u65B0\u7248\u672C\uFF0C\u4F46\u7528\u6237\u6539\u8FC7\u81EA\u5DF1\u7684\u8FD9\u4EFD\u3002\u628A\u65B0\u7248\u672C\u7684\u6539\u52A8\u5408\u5E76\u8FDB\u7528\u6237\u7684\u7248\u672C\uFF0C\u5199\u56DE ${file}\uFF08\u53EA\u6539\u8FD9\u4E00\u4E2A\u6587\u4EF6\uFF09\u3002`,
2891
- "\u89C4\u5219\uFF1A\u7528\u6237\u6539\u8FC7\u7684\u5730\u65B9\u4FDD\u7559\u7528\u6237\u7684\uFF1B\u65B0\u7248\u672C\u65B0\u589E\u6216\u4FEE\u6B63\u3001\u7528\u6237\u6CA1\u78B0\u8FC7\u7684\u5730\u65B9\u7528\u65B0\u7248\u672C\u7684\uFF1B\u4E24\u8FB9\u6539\u4E86\u540C\u4E00\u5904\u65F6\u4EE5\u7528\u6237\u7684\u4E3A\u4E3B\uFF0C\u628A\u65B0\u7248\u672C\u91CC\u6709\u7528\u7684\u4FE1\u606F\u8865\u8FDB\u53BB\u3002\u4FDD\u6301\u5F00\u5934\u7684 frontmatter\uFF08name \u4E0D\u53D8\uFF09\u3002\u5199\u5B8C\u7528\u4E00\u4E24\u53E5\u8BDD\u8BF4\u660E\u5408\u5E76\u4E86\u4EC0\u4E48\u3001\u54EA\u91CC\u4E24\u8FB9\u51B2\u7A81\u4EE5\u53CA\u600E\u4E48\u5904\u7406\u7684\u3002",
2892
- "",
2893
- "\u4E0B\u8F7D\u65F6\u7684\u7248\u672C\uFF08\u5171\u540C\u7684\u8D77\u70B9\uFF09\uFF1A",
2894
- "```markdown",
2895
- base,
2896
- "```",
2897
- "\u7528\u6237\u73B0\u5728\u7684\u7248\u672C\uFF1A",
2898
- "```markdown",
2899
- mine,
2900
- "```",
2901
- "\u6280\u80FD\u5E93\u7684\u65B0\u7248\u672C\uFF1A",
2902
- "```markdown",
2903
- theirs,
2904
- "```"
2905
- ].join("\n");
2906
- void conversations.ask(sessionId, taskMessage("\u4F60", `\u5408\u5E76\u6280\u80FD\uFF1A${name}`, prompt), AbortSignal.timeout(MERGE_TIMEOUT_MS)).then(async () => {
2907
- await hub.merged(name, skill);
2908
- changed();
2909
- }, (error) => log.warn(`skill hub: merging ${name} failed: ${error instanceof Error ? error.message : String(error)}`));
2910
- const { items } = await hub.list();
2911
- return { sessionId, item: items.find((i) => i.name === name) };
2912
- };
2913
3038
  ctx.inject(["adgGateway"], (scoped) => {
2914
3039
  const methods = {
2915
3040
  "skillhub/list": (params, call) => hub.list({ refresh: params.refresh === true, signal: call.signal }),
@@ -2920,14 +3045,15 @@ function startSkillHub(ctx, library, ready, approve, log) {
2920
3045
  return item;
2921
3046
  },
2922
3047
  "skillhub/update": async (params, call) => {
2923
- const p = params;
2924
- if (p.resolve === "merge")
2925
- return { state: "merging", ...await merge(p.name, call.signal) };
2926
- const result = await hub.update(p.name, p.resolve, call.signal);
3048
+ const result = await hub.update(params.name, call.signal);
2927
3049
  changed();
2928
3050
  return result;
2929
3051
  },
2930
- "skillhub/diff": (params, call) => hub.diff(params.name, call.signal),
3052
+ "skillhub/rollback": async (params) => {
3053
+ const item = await hub.rollback(params.name);
3054
+ changed();
3055
+ return item;
3056
+ },
2931
3057
  "skillhub/remove": async (params) => {
2932
3058
  await hub.remove(params.name);
2933
3059
  changed();
@@ -2994,14 +3120,14 @@ function hubTools(hub, approve, changed) {
2994
3120
  const shown = items.filter((i) => (a.game == null || i.games.includes(a.game)) && (a.script == null || i.scripts.includes(a.script)));
2995
3121
  return {
2996
3122
  errors,
2997
- skills: shown.map((i) => ({ name: i.name, description: i.description, kind: i.kind, games: i.games, scripts: i.scripts, repo: i.repo, installed: i.installed, blocked: i.blocked }))
3123
+ skills: shown.map((i) => ({ name: i.name, description: i.description, kind: i.kind, games: i.games, scripts: i.scripts, repo: i.repo, version: i.version, changes: i.changes, installed: i.installed, blocked: i.blocked, incompatible: i.incompatible }))
2998
3124
  };
2999
3125
  },
3000
3126
  presentCall: () => ({ card: "generic", title: "\u67E5\u770B\u6280\u80FD\u5E93", kind: "read" })
3001
3127
  },
3002
3128
  {
3003
3129
  name: "skill_hub_install",
3004
- description: "\u4ECE\u6280\u80FD\u5E93\u4E0B\u8F7D\u4E00\u4E2A\u6280\u80FD\uFF08\u4F1A\u5148\u8BF7\u7528\u6237\u786E\u8BA4\uFF09\u3002\u4E0B\u8F7D\u540E agent \u9A6C\u4E0A\u5C31\u80FD\u7528\uFF1B\u4E0B\u8F7D\u7684\u6280\u80FD\u653E\u5728\u6570\u636E\u76EE\u5F55\u91CC\uFF0C\u53EF\u4EE5\u6539\uFF0C\u66F4\u65B0\u65F6\u4E0D\u4F1A\u8986\u76D6\u6539\u52A8\u3002",
3130
+ description: "\u4ECE\u6280\u80FD\u5E93\u4E0B\u8F7D\u4E00\u4E2A\u6280\u80FD\uFF08\u4F1A\u5148\u8BF7\u7528\u6237\u786E\u8BA4\uFF09\u3002\u4E0B\u8F7D\u540E agent \u9A6C\u4E0A\u5C31\u80FD\u7528\uFF1B\u4E0B\u8F7D\u7684\u6280\u80FD\u8DDF\u7740\u6280\u80FD\u5E93\u8D70\uFF0C\u66F4\u65B0\u65F6\u6574\u4E2A\u6362\u6210\u6280\u80FD\u5E93\u7684\u65B0\u7248\u672C\uFF0C\u5728\u8FD9\u91CC\u6539\u7684\u4E0D\u4FDD\u7559\u3002",
3005
3131
  parameters: {
3006
3132
  type: "object",
3007
3133
  properties: { name: { type: "string", description: "\u6280\u80FD\u540D\uFF08skill_hub_list \u53EF\u67E5\uFF09\u3002" } },
@@ -3459,6 +3585,8 @@ var UPDATE_CHECK_EVERY_MS = 6 * 60 * 6e4;
3459
3585
  var ConfigSchema = external_exports.object({
3460
3586
  /** Where installed scripts live: `<toolsDir>/<id>/<version>/`. */
3461
3587
  toolsDir: external_exports.string().min(1),
3588
+ /** Where scripts were installed before `toolsDir` moved: still the library's (library.ts). */
3589
+ formerToolsDirs: external_exports.array(external_exports.string().min(1)).optional(),
3462
3590
  /** Library state (`scripts.json`) and the user's packs (`packs/`). */
3463
3591
  dataDir: external_exports.string().min(1),
3464
3592
  /** Built-in pack directories; default: the `@adg/packs` package. */
@@ -3488,6 +3616,7 @@ var AdgScripts = class extends Service {
3488
3616
  this.optimizer = optimizer2;
3489
3617
  this.library = new ScriptLibrary({
3490
3618
  toolsDir: spec.toolsDir,
3619
+ ...spec.formerToolsDirs === void 0 ? {} : { formerToolsDirs: spec.formerToolsDirs },
3491
3620
  dataDir: spec.dataDir,
3492
3621
  packDirs: spec.packDirs ?? [PACKS_DIR],
3493
3622
  ...spec.defaults === void 0 ? {} : { defaults: stripUndefined2(spec.defaults) },
@@ -3560,7 +3689,7 @@ var AdgScripts = class extends Service {
3560
3689
  if (setup === void 0)
3561
3690
  throw new Error(`${id} \u6CA1\u6709\u7B49\u5F85\u8FD0\u884C\u7684\u5B89\u88C5\u7A0B\u5E8F`);
3562
3691
  return handOff(setup);
3563
- }, review, optimizer2);
3692
+ }, review, optimizer2, new ExeIcons(join6(spec.dataDir, "icons")));
3564
3693
  scoped.adgGateway.register({
3565
3694
  ...capability,
3566
3695
  methods: Object.fromEntries(Object.entries(capability.methods).map(([name, handler]) => [name, async (params, call) => {