dsh-multigameassistant 2.0.5 → 2.1.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.
@@ -33,15 +33,16 @@ import {
33
33
  guideView,
34
34
  parseManifest,
35
35
  versionOfTag
36
- } from "./chunk-KHO3SRUJ.js";
36
+ } from "./chunk-77ZYHRN7.js";
37
37
  import {
38
38
  sessionConversations
39
- } from "./chunk-4Q4EH73S.js";
40
- import "./chunk-TD4YFQWE.js";
41
- import "./chunk-IOBYH4RN.js";
39
+ } from "./chunk-TWUATN5X.js";
40
+ import "./chunk-MEKSHT6V.js";
41
+ import "./chunk-FH64SAZU.js";
42
42
  import {
43
+ ExeIcons,
43
44
  writeFileAtomic
44
- } from "./chunk-CCAB6XXZ.js";
45
+ } from "./chunk-RESS7WVY.js";
45
46
  import {
46
47
  EnvReport,
47
48
  GitHubRepo,
@@ -57,14 +58,17 @@ import {
57
58
  ScriptSummary,
58
59
  SetupAgent,
59
60
  UPDATE_RULE,
60
- external_exports,
61
61
  optimizeScriptPrompt,
62
62
  parseGitHubLink,
63
63
  taskMessage
64
- } from "./chunk-BTT2GBTQ.js";
64
+ } from "./chunk-V2X4PLF5.js";
65
+ import {
66
+ external_exports
67
+ } from "./chunk-SHTX4AGU.js";
65
68
  import "./chunk-2UFLGPDY.js";
66
69
 
67
70
  // packages/script-registry/lib/index.js
71
+ import { join as join6 } from "node:path";
68
72
  import { Service } from "@deepseek-ai/cordis";
69
73
 
70
74
  // packages/script-registry/lib/role.js
@@ -89,7 +93,9 @@ var SCRIPT_ROLE = {
89
93
  "monitor_stall_*",
90
94
  "system_info",
91
95
  "skill_focus",
92
- "skill_save"
96
+ "skill_save",
97
+ // Project sites and wikis that need clicking through (the built-in browser).
98
+ "browser_*"
93
99
  ],
94
100
  duty: [
95
101
  "# \u4F60\u7684\u89D2\u8272\uFF1A\u811A\u672C",
@@ -101,7 +107,9 @@ var SCRIPT_ROLE = {
101
107
  };
102
108
 
103
109
  // packages/script-registry/lib/capability.js
104
- function scriptsCapability(library, summaries, setupAgent, review, optimizer2) {
110
+ import { existsSync, readdirSync } from "node:fs";
111
+ import { basename, join } from "node:path";
112
+ function scriptsCapability(library, summaries, setupAgent, review, optimizer2, icons) {
105
113
  return {
106
114
  id: SCRIPTS_CAPABILITY,
107
115
  version: 1,
@@ -112,6 +120,17 @@ function scriptsCapability(library, summaries, setupAgent, review, optimizer2) {
112
120
  const pack = library.packOf(params.id);
113
121
  return { guide: pack === void 0 ? null : guideView(pack.manifest, { builtin: pack.builtin }) };
114
122
  },
123
+ "scripts/icon": async (params, call) => {
124
+ const id = params.id;
125
+ const program = scriptProgram(library, id);
126
+ if (program === void 0 || icons === void 0 || process.platform !== "win32")
127
+ return {};
128
+ try {
129
+ return { icon: { mediaType: "image/png", data: (await icons.png(program, call.signal)).toString("base64") } };
130
+ } catch {
131
+ return {};
132
+ }
133
+ },
115
134
  "scripts/search": (params, call) => library.search(params.query, call.signal),
116
135
  "scripts/releases": (params, call) => {
117
136
  const p = params;
@@ -189,10 +208,51 @@ function scriptsCapability(library, summaries, setupAgent, review, optimizer2) {
189
208
  }
190
209
  };
191
210
  }
211
+ function scriptProgram(library, id) {
212
+ let info, pack;
213
+ try {
214
+ info = library.get(id);
215
+ pack = library.packOf(id);
216
+ } catch {
217
+ return void 0;
218
+ }
219
+ const launch = pack?.manifest.launch;
220
+ if (info.dir === void 0)
221
+ return void 0;
222
+ if (launch === void 0)
223
+ return mainProgram(info.dir);
224
+ for (const exe of [launch.settings?.exe, launch.exe]) {
225
+ if (exe === void 0)
226
+ continue;
227
+ const path = join(info.dir, launch.cwd ?? "", exe);
228
+ if (existsSync(path))
229
+ return path;
230
+ if (existsSync(join(info.dir, exe)))
231
+ return join(info.dir, exe);
232
+ }
233
+ return mainProgram(info.dir);
234
+ }
235
+ var HELPER = /unins|updat|setup|install|crash|report|helper|python|pythonw|pip|node|git|adb|7z|vc_?redist/i;
236
+ function mainProgram(dir) {
237
+ let exes;
238
+ try {
239
+ exes = readdirSync(dir).filter((name) => name.toLowerCase().endsWith(".exe") && !HELPER.test(name));
240
+ } catch {
241
+ return void 0;
242
+ }
243
+ const folder = basename(dir).toLowerCase();
244
+ const named = exes.find((name) => {
245
+ const stem = name.slice(0, -4).toLowerCase();
246
+ return folder.includes(stem) || stem.includes(folder);
247
+ });
248
+ const exe = named ?? (exes.length === 1 ? exes[0] : void 0);
249
+ return exe === void 0 ? void 0 : join(dir, exe);
250
+ }
192
251
 
193
252
  // packages/script-registry/lib/library.js
253
+ import { existsSync as existsSync2 } from "node:fs";
194
254
  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";
255
+ import { basename as basename2, dirname as dirname2, isAbsolute, join as join3, relative, resolve } from "node:path";
196
256
 
197
257
  // packages/script-registry/lib/jobs.js
198
258
  var KEEP_FINISHED = 20;
@@ -315,7 +375,7 @@ function mirrorResourceFor(pack, repo) {
315
375
 
316
376
  // packages/script-registry/lib/packs.js
317
377
  import { readdir, readFile } from "node:fs/promises";
318
- import { join } from "node:path";
378
+ import { join as join2 } from "node:path";
319
379
  async function loadPacks(dirs) {
320
380
  const packs = /* @__PURE__ */ new Map();
321
381
  const errors = [];
@@ -324,8 +384,8 @@ async function loadPacks(dirs) {
324
384
  for (const entry of entries) {
325
385
  if (!entry.isDirectory() || entry.name.startsWith("."))
326
386
  continue;
327
- const packDir = join(dir, entry.name);
328
- const file = join(packDir, MANIFEST_FILE);
387
+ const packDir = join2(dir, entry.name);
388
+ const file = join2(packDir, MANIFEST_FILE);
329
389
  let text;
330
390
  try {
331
391
  text = await readFile(file, "utf8");
@@ -336,7 +396,7 @@ async function loadPacks(dirs) {
336
396
  const manifest = parseManifest(text, file);
337
397
  if (manifest.id !== entry.name)
338
398
  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);
399
+ const skill = await readFile(join2(packDir, SKILL_FILE), "utf8").catch(() => void 0);
340
400
  const under = packs.get(manifest.id);
341
401
  packs.set(manifest.id, { manifest, dir: packDir, builtin, ...skill === void 0 ? {} : { skill }, ...!builtin && under?.builtin === true ? { over: under } : {} });
342
402
  } catch (error) {
@@ -500,6 +560,7 @@ var PRE_RUN_CHECK_MS = 3e4;
500
560
  var MAX_SETUP_ONLY_FILES = 4;
501
561
  var ScriptLibrary = class {
502
562
  toolsDir;
563
+ formerToolsDirs;
503
564
  #options;
504
565
  #store;
505
566
  #jobs;
@@ -513,12 +574,19 @@ var ScriptLibrary = class {
513
574
  constructor(options) {
514
575
  this.#options = options;
515
576
  this.toolsDir = resolve(options.toolsDir);
516
- this.#store = new StateStore(join2(options.dataDir, "scripts.json"));
577
+ this.formerToolsDirs = (options.formerToolsDirs ?? []).map((dir) => resolve(dir)).filter((dir) => !samePath(dir, this.toolsDir));
578
+ this.#store = new StateStore(join3(options.dataDir, "scripts.json"));
517
579
  this.#now = options.now ?? Date.now;
518
580
  this.#jobs = new JobBoard(options.onJob, this.#now);
519
581
  }
520
582
  get sharedDir() {
521
- return join2(this.toolsDir, "_shared");
583
+ const own = join3(this.toolsDir, "_shared");
584
+ if (!existsSync2(own)) {
585
+ for (const former of this.formerToolsDirs)
586
+ if (existsSync2(join3(former, "_shared")))
587
+ return join3(former, "_shared");
588
+ }
589
+ return own;
522
590
  }
523
591
  async start() {
524
592
  this.#state = await this.#store.load(this.#options.defaults ?? {}, this.#options.log);
@@ -536,7 +604,7 @@ var ScriptLibrary = class {
536
604
  async reloadPacks() {
537
605
  const dirs = [
538
606
  ...this.#options.packDirs.map((dir) => ({ dir, builtin: true })),
539
- { dir: join2(this.#options.dataDir, "packs"), builtin: false }
607
+ { dir: join3(this.#options.dataDir, "packs"), builtin: false }
540
608
  ];
541
609
  const { packs, errors } = await loadPacks(dirs);
542
610
  this.#packs = packs;
@@ -570,9 +638,9 @@ var ScriptLibrary = class {
570
638
  const packId = this.#script(id).packId;
571
639
  return packId === void 0 ? void 0 : this.#packs.get(packId);
572
640
  }
573
- /** Directories MultiGameAssistant must not let the agent rewrite: the tools directory and every imported directory. */
641
+ /** Directories MultiGameAssistant must not let the agent rewrite: the tools directories and every imported directory. */
574
642
  protectedDirs() {
575
- return [this.toolsDir, ...this.#state.scripts.filter((s) => s.source.kind === "local").map((s) => s.source.path)];
643
+ return [this.toolsDir, ...this.formerToolsDirs, ...this.#state.scripts.filter((s) => s.source.kind === "local").map((s) => s.source.path)];
576
644
  }
577
645
  pack(id) {
578
646
  return this.#packs.get(id);
@@ -739,7 +807,7 @@ var ScriptLibrary = class {
739
807
  * Needs no CDK.
740
808
  */
741
809
  async mirrorProjects(signal) {
742
- const file = join2(this.#options.dataDir, "mirrorchyan-projects.json");
810
+ const file = join3(this.#options.dataDir, "mirrorchyan-projects.json");
743
811
  if (this.#catalogue === void 0) {
744
812
  try {
745
813
  const saved = JSON.parse(await readFile3(file, "utf8"));
@@ -827,7 +895,7 @@ var ScriptLibrary = class {
827
895
  const byRepo = repo === void 0 ? [] : items.filter((i) => i.repo?.toLowerCase() === repo);
828
896
  if (byRepo.length > 0)
829
897
  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);
898
+ 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
899
  const byName = items.filter((i) => {
832
900
  const keys = [squash(i.name), squash(i.rid)].filter((k) => k.length >= 3);
833
901
  return keys.some((k) => names.some((n) => n.includes(k) || k.includes(n)));
@@ -1034,7 +1102,7 @@ var ScriptLibrary = class {
1034
1102
  ctl.phase("done", { message: `${version} \u5DF2\u5B89\u88C5\uFF0C\u5DF2\u5207\u6362\u4E3A\u5F53\u524D\u7248\u672C`, version });
1035
1103
  return version;
1036
1104
  }
1037
- const versionDir = join2(this.toolsDir, scriptId, dirName(version));
1105
+ const versionDir = join3(this.toolsDir, scriptId, dirName(version));
1038
1106
  const setup = await setupKind(archive);
1039
1107
  if (setup !== void 0) {
1040
1108
  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 +1123,13 @@ var ScriptLibrary = class {
1055
1123
  try {
1056
1124
  await cp(previous.dir, versionDir, { recursive: true });
1057
1125
  const prefix = await patchPrefix(patch, previous.dir, root);
1058
- const from = prefix === void 0 ? patch : join2(patch, prefix);
1126
+ const from = prefix === void 0 ? patch : join3(patch, prefix);
1059
1127
  await cp(from, versionDir, { recursive: true, force: true });
1060
1128
  if (from === patch)
1061
- await rm(join2(versionDir, "changes.json"), { force: true });
1129
+ await rm(join3(versionDir, "changes.json"), { force: true });
1062
1130
  const gone = await readMirrorChanges(patch, prefix) ?? [];
1063
1131
  for (const rel of gone)
1064
- await rm(join2(versionDir, ...rel.split("/")), { recursive: true, force: true });
1132
+ await rm(join3(versionDir, ...rel.split("/")), { recursive: true, force: true });
1065
1133
  if (gone.length > 0)
1066
1134
  this.#options.log.info(`${scriptId}: the incremental package removed ${gone.length} path(s)`);
1067
1135
  } catch (error) {
@@ -1128,7 +1196,7 @@ var ScriptLibrary = class {
1128
1196
  this.#state.setups = [...this.#state.setups.filter((s) => s.scriptId !== setup.scriptId), pending];
1129
1197
  await this.#save();
1130
1198
  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`;
1199
+ const what = `${basename2(setup.file)} \u662F ${SETUP_NAMES[kind]} \u5B89\u88C5\u7A0B\u5E8F\uFF0C\u4E0D\u662F\u538B\u7F29\u5305`;
1132
1200
  const handed = { kind, dir: setup.dir };
1133
1201
  const sessionId = byAgent ? void 0 : await this.#options.onSetup?.(pending).catch((error) => {
1134
1202
  this.#options.log.warn(`${setup.scriptId}: setup program not handed to the agent: ${errorText(error)}`);
@@ -1152,11 +1220,11 @@ var ScriptLibrary = class {
1152
1220
  const exes = files.filter((f) => f.toLowerCase().endsWith(".exe"));
1153
1221
  if (exes.length !== 1 || files.length > MAX_SETUP_ONLY_FILES)
1154
1222
  return void 0;
1155
- const inside = join2(dir, ...exes[0].split("/"));
1223
+ const inside = join3(dir, ...exes[0].split("/"));
1156
1224
  const kind = await setupKind(inside);
1157
1225
  if (kind === void 0)
1158
1226
  return void 0;
1159
- const file = join2(dirname2(archive), basename(inside));
1227
+ const file = join3(dirname2(archive), basename2(inside));
1160
1228
  if (!samePath(file, archive)) {
1161
1229
  await rm(file, { force: true });
1162
1230
  await rename2(inside, file);
@@ -1212,7 +1280,7 @@ var ScriptLibrary = class {
1212
1280
  if (exitCode === void 0)
1213
1281
  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
1282
  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}`);
1283
+ this.#options.log.info(`${id}: setup ${basename2(setup.file)} exited ${exitCode}, ${files} file(s) in ${setup.dir}`);
1216
1284
  return { dir: setup.dir, exitCode, result: setupExitText(setup.kind, exitCode), files, executables: files === 0 ? [] : (await probeProject(setup.dir)).executables };
1217
1285
  }
1218
1286
  /** The agent imported the folder a setup program installed into: the install (or update) is done. */
@@ -1224,7 +1292,7 @@ var ScriptLibrary = class {
1224
1292
  const script = this.#state.scripts.find((s) => s.id === setup.scriptId);
1225
1293
  const pack = setup.packId === void 0 ? void 0 : this.#packs.get(setup.packId);
1226
1294
  const inside = (dir) => {
1227
- const rel = relative(join2(this.toolsDir, setup.scriptId), dir);
1295
+ const rel = relative(join3(this.toolsDir, setup.scriptId), dir);
1228
1296
  return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
1229
1297
  };
1230
1298
  let id = setup.scriptId;
@@ -1266,7 +1334,7 @@ var ScriptLibrary = class {
1266
1334
  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
1335
  }
1268
1336
  const root = pack?.manifest.install.root;
1269
- const staging = join2(this.toolsDir, script.id, ".staging");
1337
+ const staging = join3(this.toolsDir, script.id, ".staging");
1270
1338
  try {
1271
1339
  ctl.phase("extracting", { message: `\u89E3\u538B ${fetched.asset.name}` });
1272
1340
  await rm(staging, { recursive: true, force: true });
@@ -1276,45 +1344,45 @@ var ScriptLibrary = class {
1276
1344
  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
1345
  }
1278
1346
  const prefix = fetched.incremental ? await patchPrefix(staging, target, root) : void 0;
1279
- const from = prefix === void 0 ? staging : join2(staging, prefix);
1347
+ const from = prefix === void 0 ? staging : join3(staging, prefix);
1280
1348
  const keep = await keptFiles(pack, target);
1281
1349
  const writes = (await listFiles(from)).filter((rel) => !keep.has(rel.toLowerCase()) && !(fetched.incremental && from === staging && rel === "changes.json"));
1282
1350
  const removes = [];
1283
1351
  for (const rel of fetched.incremental ? await readMirrorChanges(staging, prefix) ?? [] : []) {
1284
- if (!keep.has(rel.toLowerCase()) && await exists(join2(target, ...rel.split("/"))))
1352
+ if (!keep.has(rel.toLowerCase()) && await exists(join3(target, ...rel.split("/"))))
1285
1353
  removes.push(rel);
1286
1354
  }
1287
1355
  const at = this.#now();
1288
- const dir = join2(this.toolsDir, script.id, ".local-backup", String(at));
1356
+ const dir = join3(this.toolsDir, script.id, ".local-backup", String(at));
1289
1357
  const backup = { dir, to: version, at, added: [], saved: [], ...script.localVersion === void 0 ? {} : { from: script.localVersion.version } };
1290
1358
  ctl.phase("running", { message: `\u5907\u4EFD\u5C06\u88AB\u66FF\u6362\u7684\u6587\u4EF6\uFF08${target}\uFF09` });
1291
1359
  for (const rel of writes) {
1292
- const path = join2(target, ...rel.split("/"));
1360
+ const path = join3(target, ...rel.split("/"));
1293
1361
  if (await exists(path)) {
1294
- await saveCopy(path, join2(dir, "files", ...rel.split("/")));
1362
+ await saveCopy(path, join3(dir, "files", ...rel.split("/")));
1295
1363
  backup.saved.push(rel);
1296
1364
  } else {
1297
1365
  backup.added.push(rel);
1298
1366
  }
1299
1367
  }
1300
1368
  for (const rel of removes) {
1301
- await saveCopy(join2(target, ...rel.split("/")), join2(dir, "files", ...rel.split("/")));
1369
+ await saveCopy(join3(target, ...rel.split("/")), join3(dir, "files", ...rel.split("/")));
1302
1370
  backup.saved.push(rel);
1303
1371
  }
1304
- await writeFile2(join2(dir, "manifest.json"), `${JSON.stringify({ script: script.id, target, ...backup }, null, 2)}
1372
+ await writeFile2(join3(dir, "manifest.json"), `${JSON.stringify({ script: script.id, target, ...backup }, null, 2)}
1305
1373
  `);
1306
1374
  ctl.phase("running", { message: `\u66F4\u65B0 ${target} \u5230 ${version}` });
1307
1375
  let doing = "";
1308
1376
  try {
1309
1377
  for (const rel of writes) {
1310
1378
  doing = rel;
1311
- const path = join2(target, ...rel.split("/"));
1379
+ const path = join3(target, ...rel.split("/"));
1312
1380
  await mkdir2(dirname2(path), { recursive: true });
1313
- await copyFile(join2(from, ...rel.split("/")), path);
1381
+ await copyFile(join3(from, ...rel.split("/")), path);
1314
1382
  }
1315
1383
  for (const rel of removes) {
1316
1384
  doing = rel;
1317
- await rm(join2(target, ...rel.split("/")), { recursive: true, force: true });
1385
+ await rm(join3(target, ...rel.split("/")), { recursive: true, force: true });
1318
1386
  }
1319
1387
  } catch (error) {
1320
1388
  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 +1418,7 @@ var ScriptLibrary = class {
1350
1418
  const backup = script.backups?.at(-1);
1351
1419
  if (backup === void 0)
1352
1420
  throw new Error("\u6CA1\u6709\u53EF\u4EE5\u64A4\u9500\u7684\u66F4\u65B0");
1353
- if (!await exists(join2(backup.dir, "manifest.json")))
1421
+ if (!await exists(join3(backup.dir, "manifest.json")))
1354
1422
  throw new Error(`\u5907\u4EFD\u5DF2\u4E0D\u5B58\u5728\uFF1A${backup.dir}`);
1355
1423
  try {
1356
1424
  await putBack(script.source.path, backup);
@@ -1492,7 +1560,7 @@ var ScriptLibrary = class {
1492
1560
  const version = versionOfTag(release.tag);
1493
1561
  if (have?.(version) === true)
1494
1562
  return { version, asset: { name: asset.name, size: asset.size }, incremental: false };
1495
- const archive = join2(this.toolsDir, scriptId, ".downloads", asset.name);
1563
+ const archive = join3(this.toolsDir, scriptId, ".downloads", asset.name);
1496
1564
  ctl.phase("downloading", { message: asset.name, received: 0, total: asset.size });
1497
1565
  await download({
1498
1566
  url: asset.downloadUrl,
@@ -1524,7 +1592,7 @@ var ScriptLibrary = class {
1524
1592
  if (have?.(version) === true)
1525
1593
  return { version, asset: { name: file, size: 0 }, incremental: false, ...branch === void 0 ? {} : { branch } };
1526
1594
  const settings = this.#state.settings;
1527
- const archive = join2(this.toolsDir, scriptId, ".downloads", file);
1595
+ const archive = join3(this.toolsDir, scriptId, ".downloads", file);
1528
1596
  ctl.phase("downloading", { message: `${file}\uFF08${name} \u7684\u6E90\u7801\uFF09`, received: 0 });
1529
1597
  await download({
1530
1598
  url: github.sourceZipUrl(repo, head.sha),
@@ -1597,7 +1665,7 @@ var ScriptLibrary = class {
1597
1665
  ctl.phase("resolving", { message: "Mirror\u9171 \u6CA1\u6709\u7ED9\u51FA\u4E0B\u8F7D\u5730\u5740\uFF1B\u6539\u4ECE GitHub \u4E0B\u8F7D" });
1598
1666
  return void 0;
1599
1667
  }
1600
- let archive = join2(this.toolsDir, scriptId, ".downloads", mirrorFileName(latest.url, resource.rid, latest.version));
1668
+ let archive = join3(this.toolsDir, scriptId, ".downloads", mirrorFileName(latest.url, resource.rid, latest.version));
1601
1669
  ctl.phase("downloading", { message: `${name}\uFF08Mirror\u9171\uFF09`, received: 0, ...latest.size === void 0 ? {} : { total: latest.size } });
1602
1670
  const downloaded = await download({
1603
1671
  url: latest.url,
@@ -1693,7 +1761,7 @@ var ScriptLibrary = class {
1693
1761
  }
1694
1762
  /** The user's pack directory: packs here override built-in ones by id. */
1695
1763
  get userPackDir() {
1696
- return join2(this.#options.dataDir, "packs");
1764
+ return join3(this.#options.dataDir, "packs");
1697
1765
  }
1698
1766
  /** Describe a script with a (reloaded) pack, e.g. after the user accepted a draft. */
1699
1767
  async attachPack(scriptId, packId) {
@@ -1726,7 +1794,7 @@ var ScriptLibrary = class {
1726
1794
  async #importLocal(path, request) {
1727
1795
  if (!await stat(path).then((s) => s.isDirectory(), () => false))
1728
1796
  throw new Error(`\u4E0D\u662F\u4E00\u4E2A\u5B58\u5728\u7684\u76EE\u5F55\uFF1A${path}`);
1729
- if (this.#ownsDir(path))
1797
+ if (this.#ownsDir(path, false))
1730
1798
  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
1799
  const same = this.#state.scripts.find((s) => s.source.kind === "local" && samePath(s.source.path, path));
1732
1800
  if (same !== void 0)
@@ -1748,11 +1816,11 @@ var ScriptLibrary = class {
1748
1816
  }
1749
1817
  const probe = await probeProject(path);
1750
1818
  const known = pack === void 0 ? await knownByDir(path) : void 0;
1751
- const base = request.id ?? pack?.manifest.id ?? known?.id ?? slug(basename(path));
1819
+ const base = request.id ?? pack?.manifest.id ?? known?.id ?? slug(basename2(path));
1752
1820
  const id = this.#freeId(base);
1753
1821
  const script = {
1754
1822
  id,
1755
- name: request.name ?? pack?.manifest.name ?? known?.name ?? basename(path),
1823
+ name: request.name ?? pack?.manifest.name ?? known?.name ?? basename2(path),
1756
1824
  source: { kind: "local", path },
1757
1825
  current: "local",
1758
1826
  versions: [{ version: "local", dir: path, installedAt: this.#now() }],
@@ -1777,13 +1845,15 @@ var ScriptLibrary = class {
1777
1845
  const script = this.#script(id);
1778
1846
  if (this.#jobs.active(id) !== void 0)
1779
1847
  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 });
1848
+ for (const root of [this.toolsDir, ...this.formerToolsDirs]) {
1849
+ if (deleteFiles && script.source.kind !== "local") {
1850
+ const dir = join3(root, id);
1851
+ if (this.#ownsDir(dir))
1852
+ await rm(dir, { recursive: true, force: true });
1853
+ }
1854
+ if (script.source.kind === "local")
1855
+ await rm(join3(root, id, ".local-backup"), { recursive: true, force: true });
1784
1856
  }
1785
- if (script.source.kind === "local")
1786
- await rm(join2(this.toolsDir, id, ".local-backup"), { recursive: true, force: true });
1787
1857
  for (const setup of this.#state.setups.filter((s) => s.scriptId === id))
1788
1858
  await rm(setup.file, { force: true });
1789
1859
  this.#state.setups = this.#state.setups.filter((s) => s.scriptId !== id);
@@ -1987,7 +2057,7 @@ var ScriptLibrary = class {
1987
2057
  const dir = this.#info(script).dir;
1988
2058
  const files = [];
1989
2059
  for (const rel of dir === void 0 ? [] : await changelogFiles(dir)) {
1990
- const text = await readFile3(join2(dir, rel), "utf8").catch(() => void 0);
2060
+ const text = await readFile3(join3(dir, rel), "utf8").catch(() => void 0);
1991
2061
  if (text !== void 0)
1992
2062
  files.push({ file: rel, text: text.slice(0, CHANGELOG_FILE_MAX), truncated: text.length > CHANGELOG_FILE_MAX });
1993
2063
  }
@@ -2033,7 +2103,7 @@ var ScriptLibrary = class {
2033
2103
  lines.push(`\u6587\u4EF6\u5939\u91CC\uFF08${names.length} \u9879\uFF09\uFF1A${names.slice(0, 60).join(" ")}${names.length > 60 ? " \u2026" : ""}`);
2034
2104
  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
2105
  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();
2106
+ const text = (await readFile3(join3(info.dir, readme.name), "utf8").catch(() => "")).replace(/<!--[\s\S]*?-->/g, "").replace(/\n{3,}/g, "\n\n").trim();
2037
2107
  if (text !== "")
2038
2108
  lines.push("", `${readme.name}\uFF08\u5F00\u5934\u90E8\u5206\uFF09\uFF1A`, text.slice(0, 6e3));
2039
2109
  }
@@ -2057,9 +2127,12 @@ var ScriptLibrary = class {
2057
2127
  if (!taken.has(`${base}-${n}`))
2058
2128
  return `${base}-${n}`;
2059
2129
  }
2060
- #ownsDir(dir) {
2061
- const rel = relative(this.toolsDir, resolve(dir));
2062
- return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
2130
+ /** Inside the tools directory (or a former one, unless `former` is false): installed by the library, its to delete. */
2131
+ #ownsDir(dir, former = true) {
2132
+ return [this.toolsDir, ...former ? this.formerToolsDirs : []].some((root) => {
2133
+ const rel = relative(root, resolve(dir));
2134
+ return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
2135
+ });
2063
2136
  }
2064
2137
  /** Write the state; a script that moved past its pack's version is asked about once (onPackReview). */
2065
2138
  async #save() {
@@ -2086,7 +2159,7 @@ var CHANGELOG_NAME = /^(changelog|changes|history|release[-_ ]?notes?|更新日
2086
2159
  async function changelogFiles(dir) {
2087
2160
  const out = [];
2088
2161
  for (const sub of ["", "docs", "doc", "\u6587\u6863"]) {
2089
- for (const name of await readdir2(join2(dir, sub)).catch(() => [])) {
2162
+ for (const name of await readdir2(join3(dir, sub)).catch(() => [])) {
2090
2163
  if (CHANGELOG_NAME.test(name))
2091
2164
  out.push(sub === "" ? name : `${sub}/${name}`);
2092
2165
  }
@@ -2131,14 +2204,14 @@ function sourceVersion(date, sha) {
2131
2204
  return `${day}-${sha.slice(0, 7)}`;
2132
2205
  }
2133
2206
  async function patchPrefix(patch, baseDir, root) {
2134
- if (root !== void 0 && await exists(join2(patch, root)))
2207
+ if (root !== void 0 && await exists(join3(patch, root)))
2135
2208
  return root.replace(/\\/g, "/");
2136
2209
  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;
2210
+ return entries.length === 1 && entries[0].isDirectory() && !await exists(join3(baseDir, entries[0].name)) ? entries[0].name : void 0;
2138
2211
  }
2139
2212
  async function listFiles(dir, sub = "") {
2140
2213
  const files = [];
2141
- for (const entry of await readdir2(join2(dir, sub), { withFileTypes: true })) {
2214
+ for (const entry of await readdir2(join3(dir, sub), { withFileTypes: true })) {
2142
2215
  const rel = sub === "" ? entry.name : `${sub}/${entry.name}`;
2143
2216
  if (entry.isDirectory())
2144
2217
  files.push(...await listFiles(dir, rel));
@@ -2162,9 +2235,9 @@ async function keptFiles(pack, dir) {
2162
2235
  const parts = file.path.split(/[\\/]/);
2163
2236
  const last = parts.pop();
2164
2237
  const sub = parts.join("/");
2165
- const names = last.includes("*") || last.includes("?") ? (await readdir2(join2(dir, sub)).catch(() => [])).filter((n) => globToRegExp(last).test(n)) : [last];
2238
+ const names = last.includes("*") || last.includes("?") ? (await readdir2(join3(dir, sub)).catch(() => [])).filter((n) => globToRegExp(last).test(n)) : [last];
2166
2239
  for (const name of names) {
2167
- if (await stat(join2(dir, sub, name)).then((s) => s.isFile(), () => false))
2240
+ if (await stat(join3(dir, sub, name)).then((s) => s.isFile(), () => false))
2168
2241
  kept.add((sub === "" ? name : `${sub}/${name}`).toLowerCase());
2169
2242
  }
2170
2243
  }
@@ -2176,11 +2249,11 @@ async function saveCopy(path, dest) {
2176
2249
  }
2177
2250
  async function putBack(target, backup) {
2178
2251
  for (const rel of backup.added)
2179
- await rm(join2(target, ...rel.split("/")), { force: true });
2252
+ await rm(join3(target, ...rel.split("/")), { force: true });
2180
2253
  for (const rel of backup.saved) {
2181
- const saved = join2(backup.dir, "files", ...rel.split("/"));
2254
+ const saved = join3(backup.dir, "files", ...rel.split("/"));
2182
2255
  if (await exists(saved))
2183
- await saveCopy(saved, join2(target, ...rel.split("/")));
2256
+ await saveCopy(saved, join3(target, ...rel.split("/")));
2184
2257
  }
2185
2258
  }
2186
2259
  function newName(scriptId, source, pack) {
@@ -2190,27 +2263,27 @@ function newName(scriptId, source, pack) {
2190
2263
  async function realName(file, finalUrl) {
2191
2264
  let name;
2192
2265
  try {
2193
- const served = decodeURIComponent(basename(new URL(finalUrl).pathname));
2266
+ const served = decodeURIComponent(basename2(new URL(finalUrl).pathname));
2194
2267
  if (archiveKind(served) !== void 0 && !/[\\/:*?"<>|]/.test(served))
2195
2268
  name = served;
2196
2269
  } catch {
2197
2270
  }
2198
2271
  if (name === void 0) {
2199
2272
  const found = await contentKind(file);
2200
- if (found === void 0 || archiveKind(basename(file)) === found.kind)
2273
+ if (found === void 0 || archiveKind(basename2(file)) === found.kind)
2201
2274
  return file;
2202
- name = basename(file).replace(/\.(zip|7z|tar(\.\w+)?|exe|msi)$/i, "") + found.ext;
2275
+ name = basename2(file).replace(/\.(zip|7z|tar(\.\w+)?|exe|msi)$/i, "") + found.ext;
2203
2276
  }
2204
- if (name === basename(file))
2277
+ if (name === basename2(file))
2205
2278
  return file;
2206
- const renamed = join2(dirname2(file), name);
2279
+ const renamed = join3(dirname2(file), name);
2207
2280
  await rm(renamed, { force: true });
2208
2281
  await rename2(file, renamed);
2209
2282
  return renamed;
2210
2283
  }
2211
2284
  function mirrorFileName(url, rid, version) {
2212
2285
  try {
2213
- const name = basename(new URL(url).pathname);
2286
+ const name = basename2(new URL(url).pathname);
2214
2287
  if (archiveKind(name) !== void 0)
2215
2288
  return name;
2216
2289
  } catch {
@@ -2246,12 +2319,12 @@ async function carryConfig(pack, fromDir, toDir) {
2246
2319
  const parts = file.path.split(/[\\/]/);
2247
2320
  const last = parts.pop();
2248
2321
  const sub = parts.join("/");
2249
- const names = last.includes("*") || last.includes("?") ? (await readdir2(join2(fromDir, sub)).catch(() => [])).filter((n) => globToRegExp(last).test(n)) : [last];
2322
+ const names = last.includes("*") || last.includes("?") ? (await readdir2(join3(fromDir, sub)).catch(() => [])).filter((n) => globToRegExp(last).test(n)) : [last];
2250
2323
  for (const name of names) {
2251
- const source = join2(fromDir, sub, name);
2324
+ const source = join3(fromDir, sub, name);
2252
2325
  if (!await stat(source).then((s) => s.isFile(), () => false))
2253
2326
  continue;
2254
- const target = join2(toDir, sub, name);
2327
+ const target = join3(toDir, sub, name);
2255
2328
  await mkdir2(dirname2(target), { recursive: true });
2256
2329
  await copyFile(source, target);
2257
2330
  copied.push(sub === "" ? name : `${sub}/${name}`);
@@ -2265,9 +2338,9 @@ async function scriptCdk(pack, dir) {
2265
2338
  const parts = file.path.split(/[\\/]/);
2266
2339
  const last = parts.pop();
2267
2340
  const sub = parts.join("/");
2268
- const names = last.includes("*") || last.includes("?") ? (await readdir2(join2(dir, sub)).catch(() => [])).filter((n) => globToRegExp(last).test(n)) : [last];
2341
+ const names = last.includes("*") || last.includes("?") ? (await readdir2(join3(dir, sub)).catch(() => [])).filter((n) => globToRegExp(last).test(n)) : [last];
2269
2342
  for (const name of names) {
2270
- const text = await readFile3(join2(dir, sub, name), "utf8").catch(() => "");
2343
+ const text = await readFile3(join3(dir, sub, name), "utf8").catch(() => "");
2271
2344
  const found = CDK_ENTRY.exec(text)?.[1];
2272
2345
  if (found !== void 0)
2273
2346
  return found;
@@ -2420,18 +2493,18 @@ function optimizer(ctx, library, log) {
2420
2493
  }
2421
2494
 
2422
2495
  // packages/script-registry/lib/skill-hub-plugin.js
2423
- import { join as join4 } from "node:path";
2496
+ import { join as join5 } from "node:path";
2424
2497
 
2425
2498
  // packages/script-registry/lib/skill-hub.js
2426
2499
  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";
2500
+ 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";
2501
+ import { join as join4, relative as relative2, resolve as resolve2, sep } from "node:path";
2429
2502
  var DEFAULT_HUB_REPO = { repo: "MultiGameAssistant/skills", branch: "main" };
2430
2503
  var REFRESH_MS = 24 * 60 * 6e4;
2431
2504
  var SKILL_FILE2 = "SKILL.md";
2432
2505
  var NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
2433
2506
  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() });
2507
+ var Installed = external_exports.object({ repo: external_exports.string(), path: external_exports.string(), hash: external_exports.string(), at: external_exports.number(), owner: Owner.optional() });
2435
2508
  var State = external_exports.object({
2436
2509
  repos: external_exports.array(external_exports.object({ repo: external_exports.string(), branch: external_exports.string() })).optional(),
2437
2510
  installed: external_exports.record(external_exports.string(), Installed).default({}),
@@ -2457,15 +2530,16 @@ var SkillHub = class {
2457
2530
  this.#now = options.now ?? Date.now;
2458
2531
  }
2459
2532
  get skillsDir() {
2460
- return join3(this.#options.dir, "skills");
2533
+ return join4(this.#options.dir, "skills");
2461
2534
  }
2462
2535
  /** Read the state and register the downloaded skills. */
2463
2536
  start() {
2464
2537
  this.#loading ??= (async () => {
2465
2538
  try {
2466
- this.#state = State.parse(JSON.parse(await readFile4(join3(this.#options.dir, "state.json"), "utf8")));
2539
+ this.#state = State.parse(JSON.parse(await readFile4(join4(this.#options.dir, "state.json"), "utf8")));
2467
2540
  } catch {
2468
2541
  }
2542
+ await rm2(join4(this.#options.dir, "base"), { recursive: true, force: true });
2469
2543
  for (const name of Object.keys(this.#state.installed))
2470
2544
  await this.#register(name);
2471
2545
  })();
@@ -2527,9 +2601,9 @@ var SkillHub = class {
2527
2601
  for (const [name, record] of Object.entries(this.#state.installed)) {
2528
2602
  if (items.some((i) => i.name === name))
2529
2603
  continue;
2530
- const content = await readFile4(join3(this.skillsDir, name, SKILL_FILE2), "utf8").catch(() => "");
2604
+ const content = await readFile4(join4(this.skillsDir, name, SKILL_FILE2), "utf8").catch(() => "");
2531
2605
  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 } });
2606
+ items.push({ name, description: front?.description ?? "", kind: "general", games: [], scripts: [], repo: record.repo, path: record.path, hash: record.hash, installed: { at: record.at, update: false } });
2533
2607
  }
2534
2608
  return { items, repos: this.repos(), errors, ...fetchedAt === void 0 ? {} : { fetchedAt } };
2535
2609
  }
@@ -2543,71 +2617,19 @@ var SkillHub = class {
2543
2617
  this.#options.log.info(`skill hub: downloaded ${name} from ${skill.repo}`);
2544
2618
  return this.#item(skill, await this.#options.taken());
2545
2619
  }
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) {
2620
+ /** Take the repository's newer version, in place of this one (changed here or not). */
2621
+ async update(name, signal) {
2553
2622
  const record = this.#record(name);
2554
2623
  const skill = await this.#find(name, record.repo, signal);
2555
- const taken = await this.#options.taken();
2556
2624
  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
- }
2625
+ return { state: "current", item: await this.#item(skill, await this.#options.taken()) };
2574
2626
  await this.#put(skill);
2575
- return { state: "updated", item: await this.#item(skill, taken), ...backup === void 0 ? {} : { backup } };
2576
- }
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) {
2582
- 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() };
2598
- await this.#save();
2599
- 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 };
2627
+ return { state: "updated", item: await this.#item(skill, await this.#options.taken()) };
2605
2628
  }
2606
2629
  async remove(name) {
2607
2630
  this.#record(name);
2608
2631
  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 });
2632
+ await rm2(join4(this.skillsDir, name), { recursive: true, force: true });
2611
2633
  delete this.#state.installed[name];
2612
2634
  await this.#save();
2613
2635
  }
@@ -2653,25 +2675,22 @@ var SkillHub = class {
2653
2675
  return skill;
2654
2676
  }
2655
2677
  #repoFile(skill) {
2656
- return join3(this.#options.dir, "repos", repoKey({ repo: skill.repo, branch: "" }), ...skill.path.split("/"), SKILL_FILE2);
2678
+ return join4(this.#options.dir, "repos", repoKey({ repo: skill.repo, branch: "" }), ...skill.path.split("/"), SKILL_FILE2);
2657
2679
  }
2658
- /** Copy the repository's version in as the downloaded skill (and as the base for later merges). */
2680
+ /** Copy the repository's version in as the downloaded skill. */
2659
2681
  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);
2682
+ const from = join4(this.#options.dir, "repos", repoKey({ repo: skill.repo, branch: "" }), ...skill.path.split("/"));
2683
+ const to = join4(this.skillsDir, skill.name);
2662
2684
  await rm2(to, { recursive: true, force: true });
2663
2685
  await mkdir3(this.skillsDir, { recursive: true });
2664
2686
  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
2687
  const owner = this.#state.installed[skill.name]?.owner;
2669
2688
  this.#state.installed[skill.name] = { repo: skill.repo, path: skill.path, hash: skill.hash, at: this.#now(), ...owner === void 0 ? {} : { owner } };
2670
2689
  await this.#save();
2671
2690
  await this.#register(skill.name);
2672
2691
  }
2673
2692
  async #register(name) {
2674
- const path = join3(this.skillsDir, name, SKILL_FILE2);
2693
+ const path = join4(this.skillsDir, name, SKILL_FILE2);
2675
2694
  const content = await readFile4(path, "utf8").catch(() => void 0);
2676
2695
  const front = content === void 0 ? void 0 : frontmatter(content);
2677
2696
  if (content === void 0 || front === void 0) {
@@ -2685,7 +2704,7 @@ var SkillHub = class {
2685
2704
  const games = ids(listed?.games);
2686
2705
  const scripts = ids(listed?.scripts);
2687
2706
  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 } });
2707
+ this.#options.register(name, { description: front.description, content: front.body, path, dir: join4(this.skillsDir, name), ...owner === void 0 ? {} : { owner } });
2689
2708
  }
2690
2709
  async #item(skill, taken) {
2691
2710
  const record = this.#state.installed[skill.name];
@@ -2693,26 +2712,22 @@ var SkillHub = class {
2693
2712
  const blocked = taken.get(skill.name);
2694
2713
  return { ...skill, ...blocked === void 0 ? {} : { blocked: `\u5DF2\u6709\u540C\u540D\u7684${blocked}` } };
2695
2714
  }
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
- };
2715
+ return { ...skill, installed: { at: record.at, update: skill.repo === record.repo && skill.hash !== record.hash } };
2701
2716
  }
2702
2717
  /** Download the repository and list its skills; the copy replaces the one before. */
2703
2718
  async #readRepo(repo, signal) {
2704
2719
  const key = repoKey(repo);
2705
- const work = join3(this.#options.dir, "downloads");
2720
+ const work = join4(this.#options.dir, "downloads");
2706
2721
  await mkdir3(work, { recursive: true });
2707
- const archive = join3(work, `${key}.zip`);
2708
- const unpacked = join3(work, `${key}-${this.#now()}`);
2722
+ const archive = join4(work, `${key}.zip`);
2723
+ const unpacked = join4(work, `${key}-${this.#now()}`);
2709
2724
  await this.#options.download(`https://codeload.github.com/${repo.repo}/zip/refs/heads/${encodeURIComponent(repo.branch)}`, archive, signal);
2710
2725
  try {
2711
2726
  await this.#options.extract(archive, unpacked, signal);
2712
2727
  const skills = await readSkills(unpacked, repo.repo);
2713
- const target = join3(this.#options.dir, "repos", key);
2728
+ const target = join4(this.#options.dir, "repos", key);
2714
2729
  await rm2(target, { recursive: true, force: true });
2715
- await mkdir3(join3(this.#options.dir, "repos"), { recursive: true });
2730
+ await mkdir3(join4(this.#options.dir, "repos"), { recursive: true });
2716
2731
  await rename3(unpacked, target);
2717
2732
  return skills;
2718
2733
  } finally {
@@ -2721,12 +2736,12 @@ var SkillHub = class {
2721
2736
  }
2722
2737
  }
2723
2738
  #save() {
2724
- return mkdir3(this.#options.dir, { recursive: true }).then(() => writeFileAtomic(join3(this.#options.dir, "state.json"), `${JSON.stringify(this.#state, null, 1)}
2739
+ return mkdir3(this.#options.dir, { recursive: true }).then(() => writeFileAtomic(join4(this.#options.dir, "state.json"), `${JSON.stringify(this.#state, null, 1)}
2725
2740
  `));
2726
2741
  }
2727
2742
  };
2728
2743
  async function readSkills(root, repo) {
2729
- const indexText = await readFile4(join3(root, "index.json"), "utf8").catch(() => void 0);
2744
+ const indexText = await readFile4(join4(root, "index.json"), "utf8").catch(() => void 0);
2730
2745
  const listed = [];
2731
2746
  if (indexText !== void 0) {
2732
2747
  const parsed = Index.safeParse(JSON.parse(indexText.replace(/^/, "")));
@@ -2744,7 +2759,7 @@ async function readSkills(root, repo) {
2744
2759
  const rel = relative2(resolve2(root), full);
2745
2760
  if (path === "" || rel.startsWith("..") || rel.split(sep).includes(".."))
2746
2761
  continue;
2747
- const content = await readFile4(join3(full, SKILL_FILE2), "utf8").catch(() => void 0);
2762
+ const content = await readFile4(join4(full, SKILL_FILE2), "utf8").catch(() => void 0);
2748
2763
  const front = content === void 0 ? void 0 : frontmatter(content);
2749
2764
  if (content === void 0 || front === void 0)
2750
2765
  continue;
@@ -2769,7 +2784,7 @@ async function readSkills(root, repo) {
2769
2784
  }
2770
2785
  async function findSkillFolders(root, sub, depth) {
2771
2786
  const out = [];
2772
- const entries = await readdir3(join3(root, sub), { withFileTypes: true }).catch(() => []);
2787
+ const entries = await readdir3(join4(root, sub), { withFileTypes: true }).catch(() => []);
2773
2788
  if (sub !== "" && entries.some((e) => e.isFile() && e.name === SKILL_FILE2))
2774
2789
  out.push(sub);
2775
2790
  if (depth === 0)
@@ -2826,7 +2841,6 @@ function takenLabel(source) {
2826
2841
  return "\u6280\u80FD\uFF08\u4F60\u7684\u6280\u80FD\u6587\u4EF6\u5939\uFF09";
2827
2842
  return "\u6280\u80FD";
2828
2843
  }
2829
- var MERGE_TIMEOUT_MS = 10 * 6e4;
2830
2844
  function startSkillHub(ctx, library, ready, approve, log) {
2831
2845
  const entries = /* @__PURE__ */ new Map();
2832
2846
  const disposers = /* @__PURE__ */ new Map();
@@ -2846,7 +2860,7 @@ function startSkillHub(ctx, library, ready, approve, log) {
2846
2860
  }
2847
2861
  };
2848
2862
  const hub = new SkillHub({
2849
- dir: join4(library.dataDir, "skill-hub"),
2863
+ dir: join5(library.dataDir, "skill-hub"),
2850
2864
  download: (url, dest, signal) => library.downloadFromGitHub(url, dest, signal),
2851
2865
  extract: async (archive, dest, signal) => {
2852
2866
  await library.unpack(archive, dest, signal);
@@ -2879,37 +2893,6 @@ function startSkillHub(ctx, library, ready, approve, log) {
2879
2893
  skills = void 0;
2880
2894
  }, "adg-skill-hub skills");
2881
2895
  });
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
2896
  ctx.inject(["adgGateway"], (scoped) => {
2914
2897
  const methods = {
2915
2898
  "skillhub/list": (params, call) => hub.list({ refresh: params.refresh === true, signal: call.signal }),
@@ -2920,14 +2903,10 @@ function startSkillHub(ctx, library, ready, approve, log) {
2920
2903
  return item;
2921
2904
  },
2922
2905
  "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);
2906
+ const result = await hub.update(params.name, call.signal);
2927
2907
  changed();
2928
2908
  return result;
2929
2909
  },
2930
- "skillhub/diff": (params, call) => hub.diff(params.name, call.signal),
2931
2910
  "skillhub/remove": async (params) => {
2932
2911
  await hub.remove(params.name);
2933
2912
  changed();
@@ -3001,7 +2980,7 @@ function hubTools(hub, approve, changed) {
3001
2980
  },
3002
2981
  {
3003
2982
  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",
2983
+ 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
2984
  parameters: {
3006
2985
  type: "object",
3007
2986
  properties: { name: { type: "string", description: "\u6280\u80FD\u540D\uFF08skill_hub_list \u53EF\u67E5\uFF09\u3002" } },
@@ -3459,6 +3438,8 @@ var UPDATE_CHECK_EVERY_MS = 6 * 60 * 6e4;
3459
3438
  var ConfigSchema = external_exports.object({
3460
3439
  /** Where installed scripts live: `<toolsDir>/<id>/<version>/`. */
3461
3440
  toolsDir: external_exports.string().min(1),
3441
+ /** Where scripts were installed before `toolsDir` moved: still the library's (library.ts). */
3442
+ formerToolsDirs: external_exports.array(external_exports.string().min(1)).optional(),
3462
3443
  /** Library state (`scripts.json`) and the user's packs (`packs/`). */
3463
3444
  dataDir: external_exports.string().min(1),
3464
3445
  /** Built-in pack directories; default: the `@adg/packs` package. */
@@ -3488,6 +3469,7 @@ var AdgScripts = class extends Service {
3488
3469
  this.optimizer = optimizer2;
3489
3470
  this.library = new ScriptLibrary({
3490
3471
  toolsDir: spec.toolsDir,
3472
+ ...spec.formerToolsDirs === void 0 ? {} : { formerToolsDirs: spec.formerToolsDirs },
3491
3473
  dataDir: spec.dataDir,
3492
3474
  packDirs: spec.packDirs ?? [PACKS_DIR],
3493
3475
  ...spec.defaults === void 0 ? {} : { defaults: stripUndefined2(spec.defaults) },
@@ -3560,7 +3542,7 @@ var AdgScripts = class extends Service {
3560
3542
  if (setup === void 0)
3561
3543
  throw new Error(`${id} \u6CA1\u6709\u7B49\u5F85\u8FD0\u884C\u7684\u5B89\u88C5\u7A0B\u5E8F`);
3562
3544
  return handOff(setup);
3563
- }, review, optimizer2);
3545
+ }, review, optimizer2, new ExeIcons(join6(spec.dataDir, "icons")));
3564
3546
  scoped.adgGateway.register({
3565
3547
  ...capability,
3566
3548
  methods: Object.fromEntries(Object.entries(capability.methods).map(([name, handler]) => [name, async (params, call) => {