dsh-multigameassistant 2.0.4 → 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.
Files changed (40) hide show
  1. package/cordis.patch.yml +178 -4
  2. package/lib/analyzer.js +135 -26
  3. package/lib/browser.js +279 -0
  4. package/lib/{chunk-XHP3SLMO.js → chunk-77ZYHRN7.js} +292 -6
  5. package/lib/{chunk-UOVFYP7C.js → chunk-EOWM56PA.js} +398 -58
  6. package/lib/chunk-FH64SAZU.js +605 -0
  7. package/lib/{chunk-IZENRXQ6.js → chunk-MEKSHT6V.js} +1797 -575
  8. package/lib/chunk-RESS7WVY.js +157 -0
  9. package/lib/{chunk-SA72K6M2.js → chunk-SHTX4AGU.js} +1 -3572
  10. package/lib/{chunk-4PNYIZVU.js → chunk-TWUATN5X.js} +13 -9
  11. package/lib/chunk-V2X4PLF5.js +3730 -0
  12. package/lib/emulator.js +5 -3
  13. package/lib/feishu.js +8 -5
  14. package/lib/game-intel.js +91 -8
  15. package/lib/gateway.js +9 -5
  16. package/lib/guard.js +5 -3
  17. package/lib/intervene.js +62 -17
  18. package/lib/low-context.js +71 -87
  19. package/lib/monitor.js +90 -10
  20. package/lib/notify.js +6 -4
  21. package/lib/orchestrator.js +97 -27
  22. package/lib/packs/maa/adg.script.yaml +119 -1
  23. package/lib/packs/maaend/adg.script.yaml +74 -4
  24. package/lib/packs/march7th/adg.script.yaml +116 -0
  25. package/lib/qqbot.js +8 -5
  26. package/lib/runner.js +18 -5
  27. package/lib/scheduler.js +4 -2
  28. package/lib/script-registry.js +203 -214
  29. package/package.json +5 -4
  30. package/skills/pipeline-planning.md +8 -5
  31. package/skills/script-analysis.md +70 -10
  32. package/skills/web-reading.md +2 -0
  33. package/web/assets/index-C-csjWiw.js +244 -0
  34. package/web/assets/index-C-csjWiw.js.map +1 -0
  35. package/web/assets/index-CjtVfcDS.css +1 -0
  36. package/web/index.html +2 -2
  37. package/lib/chunk-CCAB6XXZ.js +0 -34
  38. package/web/assets/index-BqeCz6LB.css +0 -1
  39. package/web/assets/index-CCaVm9ks.js +0 -242
  40. package/web/assets/index-CCaVm9ks.js.map +0 -1
@@ -30,16 +30,19 @@ import {
30
30
  SKILL_FILE,
31
31
  chooseAsset,
32
32
  globToRegExp,
33
+ guideView,
33
34
  parseManifest,
34
35
  versionOfTag
35
- } from "./chunk-XHP3SLMO.js";
36
+ } from "./chunk-77ZYHRN7.js";
36
37
  import {
37
38
  sessionConversations
38
- } from "./chunk-4PNYIZVU.js";
39
- import "./chunk-IZENRXQ6.js";
39
+ } from "./chunk-TWUATN5X.js";
40
+ import "./chunk-MEKSHT6V.js";
41
+ import "./chunk-FH64SAZU.js";
40
42
  import {
43
+ ExeIcons,
41
44
  writeFileAtomic
42
- } from "./chunk-CCAB6XXZ.js";
45
+ } from "./chunk-RESS7WVY.js";
43
46
  import {
44
47
  EnvReport,
45
48
  GitHubRepo,
@@ -55,14 +58,17 @@ import {
55
58
  ScriptSummary,
56
59
  SetupAgent,
57
60
  UPDATE_RULE,
58
- external_exports,
59
61
  optimizeScriptPrompt,
60
62
  parseGitHubLink,
61
63
  taskMessage
62
- } from "./chunk-SA72K6M2.js";
64
+ } from "./chunk-V2X4PLF5.js";
65
+ import {
66
+ external_exports
67
+ } from "./chunk-SHTX4AGU.js";
63
68
  import "./chunk-2UFLGPDY.js";
64
69
 
65
70
  // packages/script-registry/lib/index.js
71
+ import { join as join6 } from "node:path";
66
72
  import { Service } from "@deepseek-ai/cordis";
67
73
 
68
74
  // packages/script-registry/lib/role.js
@@ -87,7 +93,9 @@ var SCRIPT_ROLE = {
87
93
  "monitor_stall_*",
88
94
  "system_info",
89
95
  "skill_focus",
90
- "skill_save"
96
+ "skill_save",
97
+ // Project sites and wikis that need clicking through (the built-in browser).
98
+ "browser_*"
91
99
  ],
92
100
  duty: [
93
101
  "# \u4F60\u7684\u89D2\u8272\uFF1A\u811A\u672C",
@@ -99,13 +107,30 @@ var SCRIPT_ROLE = {
99
107
  };
100
108
 
101
109
  // packages/script-registry/lib/capability.js
102
- 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) {
103
113
  return {
104
114
  id: SCRIPTS_CAPABILITY,
105
115
  version: 1,
106
116
  methods: {
107
117
  "scripts/list": () => library.list(),
108
118
  "scripts/get": (params) => library.get(params.id),
119
+ "scripts/guide": (params) => {
120
+ const pack = library.packOf(params.id);
121
+ return { guide: pack === void 0 ? null : guideView(pack.manifest, { builtin: pack.builtin }) };
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
+ },
109
134
  "scripts/search": (params, call) => library.search(params.query, call.signal),
110
135
  "scripts/releases": (params, call) => {
111
136
  const p = params;
@@ -183,10 +208,51 @@ function scriptsCapability(library, summaries, setupAgent, review, optimizer2) {
183
208
  }
184
209
  };
185
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
+ }
186
251
 
187
252
  // packages/script-registry/lib/library.js
253
+ import { existsSync as existsSync2 } from "node:fs";
188
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";
189
- 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";
190
256
 
191
257
  // packages/script-registry/lib/jobs.js
192
258
  var KEEP_FINISHED = 20;
@@ -309,7 +375,7 @@ function mirrorResourceFor(pack, repo) {
309
375
 
310
376
  // packages/script-registry/lib/packs.js
311
377
  import { readdir, readFile } from "node:fs/promises";
312
- import { join } from "node:path";
378
+ import { join as join2 } from "node:path";
313
379
  async function loadPacks(dirs) {
314
380
  const packs = /* @__PURE__ */ new Map();
315
381
  const errors = [];
@@ -318,8 +384,8 @@ async function loadPacks(dirs) {
318
384
  for (const entry of entries) {
319
385
  if (!entry.isDirectory() || entry.name.startsWith("."))
320
386
  continue;
321
- const packDir = join(dir, entry.name);
322
- const file = join(packDir, MANIFEST_FILE);
387
+ const packDir = join2(dir, entry.name);
388
+ const file = join2(packDir, MANIFEST_FILE);
323
389
  let text;
324
390
  try {
325
391
  text = await readFile(file, "utf8");
@@ -330,8 +396,9 @@ async function loadPacks(dirs) {
330
396
  const manifest = parseManifest(text, file);
331
397
  if (manifest.id !== entry.name)
332
398
  throw new Error(`${file}: id "${manifest.id}" must match its directory name "${entry.name}"`);
333
- const skill = await readFile(join(packDir, SKILL_FILE), "utf8").catch(() => void 0);
334
- packs.set(manifest.id, { manifest, dir: packDir, builtin, ...skill === void 0 ? {} : { skill } });
399
+ const skill = await readFile(join2(packDir, SKILL_FILE), "utf8").catch(() => void 0);
400
+ const under = packs.get(manifest.id);
401
+ packs.set(manifest.id, { manifest, dir: packDir, builtin, ...skill === void 0 ? {} : { skill }, ...!builtin && under?.builtin === true ? { over: under } : {} });
335
402
  } catch (error) {
336
403
  errors.push({ id: entry.name, dir: packDir, builtin, error: error instanceof Error ? error.message : String(error) });
337
404
  }
@@ -493,6 +560,7 @@ var PRE_RUN_CHECK_MS = 3e4;
493
560
  var MAX_SETUP_ONLY_FILES = 4;
494
561
  var ScriptLibrary = class {
495
562
  toolsDir;
563
+ formerToolsDirs;
496
564
  #options;
497
565
  #store;
498
566
  #jobs;
@@ -506,12 +574,19 @@ var ScriptLibrary = class {
506
574
  constructor(options) {
507
575
  this.#options = options;
508
576
  this.toolsDir = resolve(options.toolsDir);
509
- 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"));
510
579
  this.#now = options.now ?? Date.now;
511
580
  this.#jobs = new JobBoard(options.onJob, this.#now);
512
581
  }
513
582
  get sharedDir() {
514
- 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;
515
590
  }
516
591
  async start() {
517
592
  this.#state = await this.#store.load(this.#options.defaults ?? {}, this.#options.log);
@@ -529,7 +604,7 @@ var ScriptLibrary = class {
529
604
  async reloadPacks() {
530
605
  const dirs = [
531
606
  ...this.#options.packDirs.map((dir) => ({ dir, builtin: true })),
532
- { dir: join2(this.#options.dataDir, "packs"), builtin: false }
607
+ { dir: join3(this.#options.dataDir, "packs"), builtin: false }
533
608
  ];
534
609
  const { packs, errors } = await loadPacks(dirs);
535
610
  this.#packs = packs;
@@ -563,9 +638,9 @@ var ScriptLibrary = class {
563
638
  const packId = this.#script(id).packId;
564
639
  return packId === void 0 ? void 0 : this.#packs.get(packId);
565
640
  }
566
- /** 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. */
567
642
  protectedDirs() {
568
- 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)];
569
644
  }
570
645
  pack(id) {
571
646
  return this.#packs.get(id);
@@ -732,7 +807,7 @@ var ScriptLibrary = class {
732
807
  * Needs no CDK.
733
808
  */
734
809
  async mirrorProjects(signal) {
735
- const file = join2(this.#options.dataDir, "mirrorchyan-projects.json");
810
+ const file = join3(this.#options.dataDir, "mirrorchyan-projects.json");
736
811
  if (this.#catalogue === void 0) {
737
812
  try {
738
813
  const saved = JSON.parse(await readFile3(file, "utf8"));
@@ -820,7 +895,7 @@ var ScriptLibrary = class {
820
895
  const byRepo = repo === void 0 ? [] : items.filter((i) => i.repo?.toLowerCase() === repo);
821
896
  if (byRepo.length > 0)
822
897
  return { items: byRepo.map((i) => ({ ...i, by: "repo" })), from };
823
- 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);
824
899
  const byName = items.filter((i) => {
825
900
  const keys = [squash(i.name), squash(i.rid)].filter((k) => k.length >= 3);
826
901
  return keys.some((k) => names.some((n) => n.includes(k) || k.includes(n)));
@@ -1027,7 +1102,7 @@ var ScriptLibrary = class {
1027
1102
  ctl.phase("done", { message: `${version} \u5DF2\u5B89\u88C5\uFF0C\u5DF2\u5207\u6362\u4E3A\u5F53\u524D\u7248\u672C`, version });
1028
1103
  return version;
1029
1104
  }
1030
- const versionDir = join2(this.toolsDir, scriptId, dirName(version));
1105
+ const versionDir = join3(this.toolsDir, scriptId, dirName(version));
1031
1106
  const setup = await setupKind(archive);
1032
1107
  if (setup !== void 0) {
1033
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);
@@ -1048,13 +1123,13 @@ var ScriptLibrary = class {
1048
1123
  try {
1049
1124
  await cp(previous.dir, versionDir, { recursive: true });
1050
1125
  const prefix = await patchPrefix(patch, previous.dir, root);
1051
- const from = prefix === void 0 ? patch : join2(patch, prefix);
1126
+ const from = prefix === void 0 ? patch : join3(patch, prefix);
1052
1127
  await cp(from, versionDir, { recursive: true, force: true });
1053
1128
  if (from === patch)
1054
- await rm(join2(versionDir, "changes.json"), { force: true });
1129
+ await rm(join3(versionDir, "changes.json"), { force: true });
1055
1130
  const gone = await readMirrorChanges(patch, prefix) ?? [];
1056
1131
  for (const rel of gone)
1057
- await rm(join2(versionDir, ...rel.split("/")), { recursive: true, force: true });
1132
+ await rm(join3(versionDir, ...rel.split("/")), { recursive: true, force: true });
1058
1133
  if (gone.length > 0)
1059
1134
  this.#options.log.info(`${scriptId}: the incremental package removed ${gone.length} path(s)`);
1060
1135
  } catch (error) {
@@ -1121,7 +1196,7 @@ var ScriptLibrary = class {
1121
1196
  this.#state.setups = [...this.#state.setups.filter((s) => s.scriptId !== setup.scriptId), pending];
1122
1197
  await this.#save();
1123
1198
  this.#options.onChanged(setup.scriptId);
1124
- 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`;
1125
1200
  const handed = { kind, dir: setup.dir };
1126
1201
  const sessionId = byAgent ? void 0 : await this.#options.onSetup?.(pending).catch((error) => {
1127
1202
  this.#options.log.warn(`${setup.scriptId}: setup program not handed to the agent: ${errorText(error)}`);
@@ -1145,11 +1220,11 @@ var ScriptLibrary = class {
1145
1220
  const exes = files.filter((f) => f.toLowerCase().endsWith(".exe"));
1146
1221
  if (exes.length !== 1 || files.length > MAX_SETUP_ONLY_FILES)
1147
1222
  return void 0;
1148
- const inside = join2(dir, ...exes[0].split("/"));
1223
+ const inside = join3(dir, ...exes[0].split("/"));
1149
1224
  const kind = await setupKind(inside);
1150
1225
  if (kind === void 0)
1151
1226
  return void 0;
1152
- const file = join2(dirname2(archive), basename(inside));
1227
+ const file = join3(dirname2(archive), basename2(inside));
1153
1228
  if (!samePath(file, archive)) {
1154
1229
  await rm(file, { force: true });
1155
1230
  await rename2(inside, file);
@@ -1205,7 +1280,7 @@ var ScriptLibrary = class {
1205
1280
  if (exitCode === void 0)
1206
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}` };
1207
1282
  const files = await exists(setup.dir) ? (await listFiles(setup.dir)).length : 0;
1208
- 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}`);
1209
1284
  return { dir: setup.dir, exitCode, result: setupExitText(setup.kind, exitCode), files, executables: files === 0 ? [] : (await probeProject(setup.dir)).executables };
1210
1285
  }
1211
1286
  /** The agent imported the folder a setup program installed into: the install (or update) is done. */
@@ -1217,7 +1292,7 @@ var ScriptLibrary = class {
1217
1292
  const script = this.#state.scripts.find((s) => s.id === setup.scriptId);
1218
1293
  const pack = setup.packId === void 0 ? void 0 : this.#packs.get(setup.packId);
1219
1294
  const inside = (dir) => {
1220
- const rel = relative(join2(this.toolsDir, setup.scriptId), dir);
1295
+ const rel = relative(join3(this.toolsDir, setup.scriptId), dir);
1221
1296
  return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
1222
1297
  };
1223
1298
  let id = setup.scriptId;
@@ -1259,7 +1334,7 @@ var ScriptLibrary = class {
1259
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);
1260
1335
  }
1261
1336
  const root = pack?.manifest.install.root;
1262
- const staging = join2(this.toolsDir, script.id, ".staging");
1337
+ const staging = join3(this.toolsDir, script.id, ".staging");
1263
1338
  try {
1264
1339
  ctl.phase("extracting", { message: `\u89E3\u538B ${fetched.asset.name}` });
1265
1340
  await rm(staging, { recursive: true, force: true });
@@ -1269,45 +1344,45 @@ var ScriptLibrary = class {
1269
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);
1270
1345
  }
1271
1346
  const prefix = fetched.incremental ? await patchPrefix(staging, target, root) : void 0;
1272
- const from = prefix === void 0 ? staging : join2(staging, prefix);
1347
+ const from = prefix === void 0 ? staging : join3(staging, prefix);
1273
1348
  const keep = await keptFiles(pack, target);
1274
1349
  const writes = (await listFiles(from)).filter((rel) => !keep.has(rel.toLowerCase()) && !(fetched.incremental && from === staging && rel === "changes.json"));
1275
1350
  const removes = [];
1276
1351
  for (const rel of fetched.incremental ? await readMirrorChanges(staging, prefix) ?? [] : []) {
1277
- if (!keep.has(rel.toLowerCase()) && await exists(join2(target, ...rel.split("/"))))
1352
+ if (!keep.has(rel.toLowerCase()) && await exists(join3(target, ...rel.split("/"))))
1278
1353
  removes.push(rel);
1279
1354
  }
1280
1355
  const at = this.#now();
1281
- const dir = join2(this.toolsDir, script.id, ".local-backup", String(at));
1356
+ const dir = join3(this.toolsDir, script.id, ".local-backup", String(at));
1282
1357
  const backup = { dir, to: version, at, added: [], saved: [], ...script.localVersion === void 0 ? {} : { from: script.localVersion.version } };
1283
1358
  ctl.phase("running", { message: `\u5907\u4EFD\u5C06\u88AB\u66FF\u6362\u7684\u6587\u4EF6\uFF08${target}\uFF09` });
1284
1359
  for (const rel of writes) {
1285
- const path = join2(target, ...rel.split("/"));
1360
+ const path = join3(target, ...rel.split("/"));
1286
1361
  if (await exists(path)) {
1287
- await saveCopy(path, join2(dir, "files", ...rel.split("/")));
1362
+ await saveCopy(path, join3(dir, "files", ...rel.split("/")));
1288
1363
  backup.saved.push(rel);
1289
1364
  } else {
1290
1365
  backup.added.push(rel);
1291
1366
  }
1292
1367
  }
1293
1368
  for (const rel of removes) {
1294
- await saveCopy(join2(target, ...rel.split("/")), join2(dir, "files", ...rel.split("/")));
1369
+ await saveCopy(join3(target, ...rel.split("/")), join3(dir, "files", ...rel.split("/")));
1295
1370
  backup.saved.push(rel);
1296
1371
  }
1297
- 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)}
1298
1373
  `);
1299
1374
  ctl.phase("running", { message: `\u66F4\u65B0 ${target} \u5230 ${version}` });
1300
1375
  let doing = "";
1301
1376
  try {
1302
1377
  for (const rel of writes) {
1303
1378
  doing = rel;
1304
- const path = join2(target, ...rel.split("/"));
1379
+ const path = join3(target, ...rel.split("/"));
1305
1380
  await mkdir2(dirname2(path), { recursive: true });
1306
- await copyFile(join2(from, ...rel.split("/")), path);
1381
+ await copyFile(join3(from, ...rel.split("/")), path);
1307
1382
  }
1308
1383
  for (const rel of removes) {
1309
1384
  doing = rel;
1310
- await rm(join2(target, ...rel.split("/")), { recursive: true, force: true });
1385
+ await rm(join3(target, ...rel.split("/")), { recursive: true, force: true });
1311
1386
  }
1312
1387
  } catch (error) {
1313
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}`);
@@ -1343,7 +1418,7 @@ var ScriptLibrary = class {
1343
1418
  const backup = script.backups?.at(-1);
1344
1419
  if (backup === void 0)
1345
1420
  throw new Error("\u6CA1\u6709\u53EF\u4EE5\u64A4\u9500\u7684\u66F4\u65B0");
1346
- if (!await exists(join2(backup.dir, "manifest.json")))
1421
+ if (!await exists(join3(backup.dir, "manifest.json")))
1347
1422
  throw new Error(`\u5907\u4EFD\u5DF2\u4E0D\u5B58\u5728\uFF1A${backup.dir}`);
1348
1423
  try {
1349
1424
  await putBack(script.source.path, backup);
@@ -1485,7 +1560,7 @@ var ScriptLibrary = class {
1485
1560
  const version = versionOfTag(release.tag);
1486
1561
  if (have?.(version) === true)
1487
1562
  return { version, asset: { name: asset.name, size: asset.size }, incremental: false };
1488
- const archive = join2(this.toolsDir, scriptId, ".downloads", asset.name);
1563
+ const archive = join3(this.toolsDir, scriptId, ".downloads", asset.name);
1489
1564
  ctl.phase("downloading", { message: asset.name, received: 0, total: asset.size });
1490
1565
  await download({
1491
1566
  url: asset.downloadUrl,
@@ -1517,7 +1592,7 @@ var ScriptLibrary = class {
1517
1592
  if (have?.(version) === true)
1518
1593
  return { version, asset: { name: file, size: 0 }, incremental: false, ...branch === void 0 ? {} : { branch } };
1519
1594
  const settings = this.#state.settings;
1520
- const archive = join2(this.toolsDir, scriptId, ".downloads", file);
1595
+ const archive = join3(this.toolsDir, scriptId, ".downloads", file);
1521
1596
  ctl.phase("downloading", { message: `${file}\uFF08${name} \u7684\u6E90\u7801\uFF09`, received: 0 });
1522
1597
  await download({
1523
1598
  url: github.sourceZipUrl(repo, head.sha),
@@ -1590,7 +1665,7 @@ var ScriptLibrary = class {
1590
1665
  ctl.phase("resolving", { message: "Mirror\u9171 \u6CA1\u6709\u7ED9\u51FA\u4E0B\u8F7D\u5730\u5740\uFF1B\u6539\u4ECE GitHub \u4E0B\u8F7D" });
1591
1666
  return void 0;
1592
1667
  }
1593
- 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));
1594
1669
  ctl.phase("downloading", { message: `${name}\uFF08Mirror\u9171\uFF09`, received: 0, ...latest.size === void 0 ? {} : { total: latest.size } });
1595
1670
  const downloaded = await download({
1596
1671
  url: latest.url,
@@ -1686,7 +1761,7 @@ var ScriptLibrary = class {
1686
1761
  }
1687
1762
  /** The user's pack directory: packs here override built-in ones by id. */
1688
1763
  get userPackDir() {
1689
- return join2(this.#options.dataDir, "packs");
1764
+ return join3(this.#options.dataDir, "packs");
1690
1765
  }
1691
1766
  /** Describe a script with a (reloaded) pack, e.g. after the user accepted a draft. */
1692
1767
  async attachPack(scriptId, packId) {
@@ -1719,7 +1794,7 @@ var ScriptLibrary = class {
1719
1794
  async #importLocal(path, request) {
1720
1795
  if (!await stat(path).then((s) => s.isDirectory(), () => false))
1721
1796
  throw new Error(`\u4E0D\u662F\u4E00\u4E2A\u5B58\u5728\u7684\u76EE\u5F55\uFF1A${path}`);
1722
- if (this.#ownsDir(path))
1797
+ if (this.#ownsDir(path, false))
1723
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");
1724
1799
  const same = this.#state.scripts.find((s) => s.source.kind === "local" && samePath(s.source.path, path));
1725
1800
  if (same !== void 0)
@@ -1741,11 +1816,11 @@ var ScriptLibrary = class {
1741
1816
  }
1742
1817
  const probe = await probeProject(path);
1743
1818
  const known = pack === void 0 ? await knownByDir(path) : void 0;
1744
- 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));
1745
1820
  const id = this.#freeId(base);
1746
1821
  const script = {
1747
1822
  id,
1748
- name: request.name ?? pack?.manifest.name ?? known?.name ?? basename(path),
1823
+ name: request.name ?? pack?.manifest.name ?? known?.name ?? basename2(path),
1749
1824
  source: { kind: "local", path },
1750
1825
  current: "local",
1751
1826
  versions: [{ version: "local", dir: path, installedAt: this.#now() }],
@@ -1770,13 +1845,15 @@ var ScriptLibrary = class {
1770
1845
  const script = this.#script(id);
1771
1846
  if (this.#jobs.active(id) !== void 0)
1772
1847
  throw new Error(`${id} \u6709\u4EFB\u52A1\u6B63\u5728\u8FDB\u884C\uFF0C\u8BF7\u5148\u53D6\u6D88`);
1773
- if (deleteFiles && script.source.kind !== "local") {
1774
- const dir = join2(this.toolsDir, id);
1775
- if (this.#ownsDir(dir))
1776
- 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 });
1777
1856
  }
1778
- if (script.source.kind === "local")
1779
- await rm(join2(this.toolsDir, id, ".local-backup"), { recursive: true, force: true });
1780
1857
  for (const setup of this.#state.setups.filter((s) => s.scriptId === id))
1781
1858
  await rm(setup.file, { force: true });
1782
1859
  this.#state.setups = this.#state.setups.filter((s) => s.scriptId !== id);
@@ -1980,7 +2057,7 @@ var ScriptLibrary = class {
1980
2057
  const dir = this.#info(script).dir;
1981
2058
  const files = [];
1982
2059
  for (const rel of dir === void 0 ? [] : await changelogFiles(dir)) {
1983
- const text = await readFile3(join2(dir, rel), "utf8").catch(() => void 0);
2060
+ const text = await readFile3(join3(dir, rel), "utf8").catch(() => void 0);
1984
2061
  if (text !== void 0)
1985
2062
  files.push({ file: rel, text: text.slice(0, CHANGELOG_FILE_MAX), truncated: text.length > CHANGELOG_FILE_MAX });
1986
2063
  }
@@ -2026,7 +2103,7 @@ var ScriptLibrary = class {
2026
2103
  lines.push(`\u6587\u4EF6\u5939\u91CC\uFF08${names.length} \u9879\uFF09\uFF1A${names.slice(0, 60).join(" ")}${names.length > 60 ? " \u2026" : ""}`);
2027
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];
2028
2105
  if (readme !== void 0) {
2029
- 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();
2030
2107
  if (text !== "")
2031
2108
  lines.push("", `${readme.name}\uFF08\u5F00\u5934\u90E8\u5206\uFF09\uFF1A`, text.slice(0, 6e3));
2032
2109
  }
@@ -2050,9 +2127,12 @@ var ScriptLibrary = class {
2050
2127
  if (!taken.has(`${base}-${n}`))
2051
2128
  return `${base}-${n}`;
2052
2129
  }
2053
- #ownsDir(dir) {
2054
- const rel = relative(this.toolsDir, resolve(dir));
2055
- 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
+ });
2056
2136
  }
2057
2137
  /** Write the state; a script that moved past its pack's version is asked about once (onPackReview). */
2058
2138
  async #save() {
@@ -2079,7 +2159,7 @@ var CHANGELOG_NAME = /^(changelog|changes|history|release[-_ ]?notes?|更新日
2079
2159
  async function changelogFiles(dir) {
2080
2160
  const out = [];
2081
2161
  for (const sub of ["", "docs", "doc", "\u6587\u6863"]) {
2082
- for (const name of await readdir2(join2(dir, sub)).catch(() => [])) {
2162
+ for (const name of await readdir2(join3(dir, sub)).catch(() => [])) {
2083
2163
  if (CHANGELOG_NAME.test(name))
2084
2164
  out.push(sub === "" ? name : `${sub}/${name}`);
2085
2165
  }
@@ -2124,14 +2204,14 @@ function sourceVersion(date, sha) {
2124
2204
  return `${day}-${sha.slice(0, 7)}`;
2125
2205
  }
2126
2206
  async function patchPrefix(patch, baseDir, root) {
2127
- if (root !== void 0 && await exists(join2(patch, root)))
2207
+ if (root !== void 0 && await exists(join3(patch, root)))
2128
2208
  return root.replace(/\\/g, "/");
2129
2209
  const entries = (await readdir2(patch, { withFileTypes: true })).filter((e) => e.name !== "changes.json");
2130
- 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;
2131
2211
  }
2132
2212
  async function listFiles(dir, sub = "") {
2133
2213
  const files = [];
2134
- for (const entry of await readdir2(join2(dir, sub), { withFileTypes: true })) {
2214
+ for (const entry of await readdir2(join3(dir, sub), { withFileTypes: true })) {
2135
2215
  const rel = sub === "" ? entry.name : `${sub}/${entry.name}`;
2136
2216
  if (entry.isDirectory())
2137
2217
  files.push(...await listFiles(dir, rel));
@@ -2155,9 +2235,9 @@ async function keptFiles(pack, dir) {
2155
2235
  const parts = file.path.split(/[\\/]/);
2156
2236
  const last = parts.pop();
2157
2237
  const sub = parts.join("/");
2158
- 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];
2159
2239
  for (const name of names) {
2160
- 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))
2161
2241
  kept.add((sub === "" ? name : `${sub}/${name}`).toLowerCase());
2162
2242
  }
2163
2243
  }
@@ -2169,11 +2249,11 @@ async function saveCopy(path, dest) {
2169
2249
  }
2170
2250
  async function putBack(target, backup) {
2171
2251
  for (const rel of backup.added)
2172
- await rm(join2(target, ...rel.split("/")), { force: true });
2252
+ await rm(join3(target, ...rel.split("/")), { force: true });
2173
2253
  for (const rel of backup.saved) {
2174
- const saved = join2(backup.dir, "files", ...rel.split("/"));
2254
+ const saved = join3(backup.dir, "files", ...rel.split("/"));
2175
2255
  if (await exists(saved))
2176
- await saveCopy(saved, join2(target, ...rel.split("/")));
2256
+ await saveCopy(saved, join3(target, ...rel.split("/")));
2177
2257
  }
2178
2258
  }
2179
2259
  function newName(scriptId, source, pack) {
@@ -2183,27 +2263,27 @@ function newName(scriptId, source, pack) {
2183
2263
  async function realName(file, finalUrl) {
2184
2264
  let name;
2185
2265
  try {
2186
- const served = decodeURIComponent(basename(new URL(finalUrl).pathname));
2266
+ const served = decodeURIComponent(basename2(new URL(finalUrl).pathname));
2187
2267
  if (archiveKind(served) !== void 0 && !/[\\/:*?"<>|]/.test(served))
2188
2268
  name = served;
2189
2269
  } catch {
2190
2270
  }
2191
2271
  if (name === void 0) {
2192
2272
  const found = await contentKind(file);
2193
- if (found === void 0 || archiveKind(basename(file)) === found.kind)
2273
+ if (found === void 0 || archiveKind(basename2(file)) === found.kind)
2194
2274
  return file;
2195
- 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;
2196
2276
  }
2197
- if (name === basename(file))
2277
+ if (name === basename2(file))
2198
2278
  return file;
2199
- const renamed = join2(dirname2(file), name);
2279
+ const renamed = join3(dirname2(file), name);
2200
2280
  await rm(renamed, { force: true });
2201
2281
  await rename2(file, renamed);
2202
2282
  return renamed;
2203
2283
  }
2204
2284
  function mirrorFileName(url, rid, version) {
2205
2285
  try {
2206
- const name = basename(new URL(url).pathname);
2286
+ const name = basename2(new URL(url).pathname);
2207
2287
  if (archiveKind(name) !== void 0)
2208
2288
  return name;
2209
2289
  } catch {
@@ -2239,12 +2319,12 @@ async function carryConfig(pack, fromDir, toDir) {
2239
2319
  const parts = file.path.split(/[\\/]/);
2240
2320
  const last = parts.pop();
2241
2321
  const sub = parts.join("/");
2242
- 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];
2243
2323
  for (const name of names) {
2244
- const source = join2(fromDir, sub, name);
2324
+ const source = join3(fromDir, sub, name);
2245
2325
  if (!await stat(source).then((s) => s.isFile(), () => false))
2246
2326
  continue;
2247
- const target = join2(toDir, sub, name);
2327
+ const target = join3(toDir, sub, name);
2248
2328
  await mkdir2(dirname2(target), { recursive: true });
2249
2329
  await copyFile(source, target);
2250
2330
  copied.push(sub === "" ? name : `${sub}/${name}`);
@@ -2258,9 +2338,9 @@ async function scriptCdk(pack, dir) {
2258
2338
  const parts = file.path.split(/[\\/]/);
2259
2339
  const last = parts.pop();
2260
2340
  const sub = parts.join("/");
2261
- 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];
2262
2342
  for (const name of names) {
2263
- const text = await readFile3(join2(dir, sub, name), "utf8").catch(() => "");
2343
+ const text = await readFile3(join3(dir, sub, name), "utf8").catch(() => "");
2264
2344
  const found = CDK_ENTRY.exec(text)?.[1];
2265
2345
  if (found !== void 0)
2266
2346
  return found;
@@ -2304,11 +2384,11 @@ function packReview(ctx, library, log) {
2304
2384
  "\u8BF7\u6309\u6280\u80FD script-analysis \u91CC\u300C\u811A\u672C\u66F4\u65B0\u540E\u68C0\u67E5\u811A\u672C\u5305\u300D\u7684\u6B65\u9AA4\u505A\uFF1A",
2305
2385
  `1. \u5148\u7528 script_changelog\uFF08id=${id}\uFF09\u8BFB\u8FD9\u51E0\u4E2A\u7248\u672C\u7684\u66F4\u65B0\u65E5\u5FD7\uFF0C\u6311\u51FA\u53EF\u80FD\u5F71\u54CD\u811A\u672C\u5305\u7684\u6539\u52A8\uFF08\u4EFB\u52A1\u3001\u53C2\u6570\u3001\u914D\u7F6E\u6587\u4EF6\u548C\u952E\u3001\u542F\u52A8\u65B9\u5F0F\u3001\u65E5\u5FD7\u91CC\u7684\u5B8C\u6210\u548C\u51FA\u9519\u6587\u5B57\u3001\u8FD0\u884C\u73AF\u5883\uFF09\uFF1B`,
2306
2386
  "2. \u53EA\u9488\u5BF9\u8FD9\u4E9B\u6539\u52A8\u6838\u5BF9\u65B0\u7248\u672C\u7684\u6587\u4EF6\uFF0C\u66F4\u65B0\u65E5\u5FD7\u6CA1\u5199\u6E05\u695A\u7684\u518D\u770B\u4EE3\u7801\uFF1B",
2307
- "3. \u8981\u6539\u5C31\u7528\u539F\u6765\u7684\u811A\u672C\u5305 id \u63D0\u4EA4 pack_propose\uFF08summary \u5199\u660E\u4F9D\u636E\u66F4\u65B0\u65E5\u5FD7\u6539\u4E86\u4EC0\u4E48\uFF09\uFF1B\u4E0D\u7528\u6539\u5C31\u8C03\u7528 pack_reviewed \u8BF4\u660E\u7406\u7531\uFF1B",
2387
+ "3. \u8981\u6539\u5C31\u7528\u539F\u6765\u7684\u811A\u672C\u5305 id \u8C03\u7528 pack_propose \u4FDD\u5B58\uFF08\u76F4\u63A5\u751F\u6548\uFF1Bsummary \u5199\u660E\u4F9D\u636E\u66F4\u65B0\u65E5\u5FD7\u6539\u4E86\u4EC0\u4E48\uFF09\uFF1B\u4E0D\u7528\u6539\u5C31\u8C03\u7528 pack_reviewed \u8BF4\u660E\u7406\u7531\uFF1B",
2308
2388
  "4. \u6700\u540E\u7528\u4E24\u4E09\u53E5\u8BDD\u544A\u8BC9\u7528\u6237\u7ED3\u8BBA\u3002"
2309
2389
  ].join("\n");
2310
2390
  void conversations.ask(sessionId, taskMessage("\u4F60", `\u68C0\u67E5\u811A\u672C\u5305\uFF1A${script.name}`, prompt), AbortSignal.timeout(REVIEW_TIMEOUT_MS)).catch((error) => log.warn(`pack review for ${id}: ${error instanceof Error ? error.message : String(error)}`));
2311
- close("\u5DF2\u4EA4\u7ED9\u300C\u811A\u672C\u300D\u68C0\u67E5\uFF0C\u6539\u597D\u7684\u8349\u7A3F\u4F1A\u5728\u300C\u811A\u672C\u300D\u9875\u7B49\u4F60\u786E\u8BA4");
2391
+ close("\u5DF2\u4EA4\u7ED9\u300C\u811A\u672C\u300D\u68C0\u67E5\uFF0C\u8981\u6539\u7684\u5B83\u4F1A\u76F4\u63A5\u6539\u597D\uFF0C\u7ED3\u679C\u4F1A\u544A\u8BC9\u4F60");
2312
2392
  return { sessionId };
2313
2393
  };
2314
2394
  ctx.inject(["adgNotify"], (scoped) => {
@@ -2317,7 +2397,7 @@ function packReview(ctx, library, log) {
2317
2397
  if (id === void 0 || actionId !== "check" && actionId !== "keep")
2318
2398
  throw new Error(`\u672A\u77E5\u64CD\u4F5C ${actionId}`);
2319
2399
  const { sessionId } = await decide(id, actionId);
2320
- return sessionId === void 0 ? "\u597D\u7684\uFF0C\u811A\u672C\u5305\u4FDD\u6301\u4E0D\u53D8" : "\u597D\u7684\uFF0Cagent \u5148\u8BFB\u66F4\u65B0\u65E5\u5FD7\uFF0C\u518D\u68C0\u67E5\u811A\u672C\u5305\uFF1B\u6539\u597D\u7684\u8349\u7A3F\u4F1A\u5728\u300C\u811A\u672C\u300D\u9875\u7B49\u4F60\u786E\u8BA4";
2400
+ return sessionId === void 0 ? "\u597D\u7684\uFF0C\u811A\u672C\u5305\u4FDD\u6301\u4E0D\u53D8" : "\u597D\u7684\uFF0Cagent \u5148\u8BFB\u66F4\u65B0\u65E5\u5FD7\uFF0C\u518D\u68C0\u67E5\u811A\u672C\u5305\uFF1B\u8981\u6539\u7684\u5B83\u4F1A\u76F4\u63A5\u6539\u597D\uFF0C\u7ED3\u679C\u4F1A\u544A\u8BC9\u4F60";
2321
2401
  }), "adg-scripts pack review actions");
2322
2402
  });
2323
2403
  return {
@@ -2334,7 +2414,7 @@ function packReview(ctx, library, log) {
2334
2414
  title: `${script.name} \u66F4\u65B0\u4E86\uFF1A\u811A\u672C\u5305\u8981\u4E0D\u8981\u8DDF\u7740\u6539\uFF1F`,
2335
2415
  text: [
2336
2416
  `${script.name} \u4ECE ${review.from ?? "\u65E7\u7248\u672C"} \u66F4\u65B0\u5230\u4E86 ${review.to}\uFF0C\u5B83\u7684\u811A\u672C\u5305\u662F\u6309\u65E7\u7248\u672C\u5199\u7684\uFF0C\u65B0\u7248\u672C\u7684\u4EFB\u52A1\u3001\u914D\u7F6E\u6216\u65E5\u5FD7\u53EF\u80FD\u53D8\u4E86\u3002`,
2337
- "\u8981\u8BA9 agent \u5148\u8BFB\u8FD9\u6B21\u7684\u66F4\u65B0\u65E5\u5FD7\uFF0C\u518D\u68C0\u67E5\u811A\u672C\u5305\u5417\uFF1F\u6539\u52A8\u4F1A\u5148\u4F5C\u4E3A\u8349\u7A3F\u7ED9\u4F60\u786E\u8BA4\u3002"
2417
+ "\u8981\u8BA9 agent \u5148\u8BFB\u8FD9\u6B21\u7684\u66F4\u65B0\u65E5\u5FD7\uFF0C\u518D\u68C0\u67E5\u811A\u672C\u5305\u5417\uFF1F\u8981\u6539\u7684\u5B83\u4F1A\u76F4\u63A5\u6539\u597D\uFF08\u4E4B\u524D\u7684\u7248\u672C\u7559\u5728\u5386\u53F2\u91CC\uFF09\uFF0C\u7ED3\u679C\u4F1A\u544A\u8BC9\u4F60\u3002"
2338
2418
  ].join("\n"),
2339
2419
  severity: "info",
2340
2420
  actions: [{ id: "check", label: "\u8BA9 agent \u68C0\u67E5", style: "primary" }, { id: "keep", label: "\u4E0D\u7528\u6539" }]
@@ -2402,7 +2482,7 @@ function optimizer(ctx, library, log) {
2402
2482
  title: `\u8981\u4F18\u5316\u300C${script.name}\u300D\u5417\uFF1F`,
2403
2483
  text: [
2404
2484
  `${script.name} ${why(script) ?? ""}\uFF0C\u6512\u4E0B\u7684\u8FD0\u884C\u8BB0\u5F55\u591F\u7528\u6765\u4F18\u5316\u5B83\u4E86\u3002`,
2405
- "\u8981\u8BA9\u300C\u811A\u672C\u300Dagent \u4E00\u6B21\u505A\u5B8C\uFF1A\u6309\u8FD9\u4E9B\u8FD0\u884C\u91CD\u65B0\u603B\u7ED3\u811A\u672C\u5305\u3001\u6309\u6B63\u5E38\u65F6\u7684\u65E5\u5FD7\u8282\u594F\u8C03\u300C\u591A\u4E45\u6CA1\u52A8\u9759\u7B97\u5361\u4F4F\u300D\u3001\u628A\u53CD\u590D\u8D70\u901A\u7684\u6B65\u9AA4\u5B58\u6210\u53EA\u7ED9\u5B83\u7528\u7684\u6280\u80FD\u5417\uFF1F\u811A\u672C\u5305\u7684\u6539\u52A8\u4F1A\u5148\u4F5C\u4E3A\u8349\u7A3F\u7ED9\u4F60\u786E\u8BA4\u3002"
2485
+ "\u8981\u8BA9\u300C\u811A\u672C\u300Dagent \u4E00\u6B21\u505A\u5B8C\uFF1A\u6309\u8FD9\u4E9B\u8FD0\u884C\u91CD\u65B0\u603B\u7ED3\u811A\u672C\u5305\u3001\u6309\u6B63\u5E38\u65F6\u7684\u65E5\u5FD7\u8282\u594F\u8C03\u300C\u591A\u4E45\u6CA1\u52A8\u9759\u7B97\u5361\u4F4F\u300D\u3001\u628A\u53CD\u590D\u8D70\u901A\u7684\u6B65\u9AA4\u5B58\u6210\u53EA\u7ED9\u5B83\u7528\u7684\u6280\u80FD\u5417\uFF1F\u811A\u672C\u5305\u8981\u6539\u7684\u5B83\u4F1A\u76F4\u63A5\u6539\u597D\uFF08\u4E4B\u524D\u7684\u7248\u672C\u7559\u5728\u5386\u53F2\u91CC\uFF09\uFF0C\u7ED3\u679C\u4F1A\u544A\u8BC9\u4F60\u3002"
2406
2486
  ].join("\n"),
2407
2487
  severity: "info",
2408
2488
  actions: [{ id: "run", label: "\u4F18\u5316\u811A\u672C", style: "primary" }, { id: "keep", label: "\u8FD9\u6B21\u4E0D\u7528" }]
@@ -2413,18 +2493,18 @@ function optimizer(ctx, library, log) {
2413
2493
  }
2414
2494
 
2415
2495
  // packages/script-registry/lib/skill-hub-plugin.js
2416
- import { join as join4 } from "node:path";
2496
+ import { join as join5 } from "node:path";
2417
2497
 
2418
2498
  // packages/script-registry/lib/skill-hub.js
2419
2499
  import { createHash } from "node:crypto";
2420
- 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";
2421
- 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";
2422
2502
  var DEFAULT_HUB_REPO = { repo: "MultiGameAssistant/skills", branch: "main" };
2423
2503
  var REFRESH_MS = 24 * 60 * 6e4;
2424
2504
  var SKILL_FILE2 = "SKILL.md";
2425
2505
  var NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
2426
2506
  var Owner = external_exports.object({ games: external_exports.array(external_exports.string()).optional(), scripts: external_exports.array(external_exports.string()).optional() });
2427
- 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() });
2428
2508
  var State = external_exports.object({
2429
2509
  repos: external_exports.array(external_exports.object({ repo: external_exports.string(), branch: external_exports.string() })).optional(),
2430
2510
  installed: external_exports.record(external_exports.string(), Installed).default({}),
@@ -2450,15 +2530,16 @@ var SkillHub = class {
2450
2530
  this.#now = options.now ?? Date.now;
2451
2531
  }
2452
2532
  get skillsDir() {
2453
- return join3(this.#options.dir, "skills");
2533
+ return join4(this.#options.dir, "skills");
2454
2534
  }
2455
2535
  /** Read the state and register the downloaded skills. */
2456
2536
  start() {
2457
2537
  this.#loading ??= (async () => {
2458
2538
  try {
2459
- 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")));
2460
2540
  } catch {
2461
2541
  }
2542
+ await rm2(join4(this.#options.dir, "base"), { recursive: true, force: true });
2462
2543
  for (const name of Object.keys(this.#state.installed))
2463
2544
  await this.#register(name);
2464
2545
  })();
@@ -2520,9 +2601,9 @@ var SkillHub = class {
2520
2601
  for (const [name, record] of Object.entries(this.#state.installed)) {
2521
2602
  if (items.some((i) => i.name === name))
2522
2603
  continue;
2523
- 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(() => "");
2524
2605
  const front = frontmatter(content);
2525
- 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 } });
2526
2607
  }
2527
2608
  return { items, repos: this.repos(), errors, ...fetchedAt === void 0 ? {} : { fetchedAt } };
2528
2609
  }
@@ -2536,71 +2617,19 @@ var SkillHub = class {
2536
2617
  this.#options.log.info(`skill hub: downloaded ${name} from ${skill.repo}`);
2537
2618
  return this.#item(skill, await this.#options.taken());
2538
2619
  }
2539
- /**
2540
- * Take the repository's newer version. Unchanged here: replaced. Changed:
2541
- * `conflict`, unless `resolve` says what to do — `keep` the user's (and
2542
- * stop offering this version), or `replace` it (the user's kept in
2543
- * `backup/`).
2544
- */
2545
- 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) {
2546
2622
  const record = this.#record(name);
2547
2623
  const skill = await this.#find(name, record.repo, signal);
2548
- const taken = await this.#options.taken();
2549
2624
  if (skill.hash === record.hash)
2550
- return { state: "current", item: await this.#item(skill, taken) };
2551
- const file = join3(this.skillsDir, name, SKILL_FILE2);
2552
- const mine = await readFile4(file, "utf8").catch(() => void 0);
2553
- const modified = mine !== void 0 && hash(mine) !== record.hash;
2554
- if (modified && resolve3 === void 0)
2555
- return { state: "conflict", item: await this.#item(skill, taken) };
2556
- if (modified && resolve3 === "keep") {
2557
- this.#state.installed[name] = { ...record, skipped: skill.hash };
2558
- await this.#save();
2559
- return { state: "kept", item: await this.#item(skill, taken) };
2560
- }
2561
- let backup;
2562
- if (modified) {
2563
- backup = join3(this.#options.dir, "backup", `${name}-${this.#now()}.md`);
2564
- await mkdir3(join3(this.#options.dir, "backup"), { recursive: true });
2565
- await writeFile3(backup, mine);
2566
- }
2625
+ return { state: "current", item: await this.#item(skill, await this.#options.taken()) };
2567
2626
  await this.#put(skill);
2568
- return { state: "updated", item: await this.#item(skill, taken), ...backup === void 0 ? {} : { backup } };
2569
- }
2570
- /**
2571
- * The three versions for merging a changed skill with the repository's
2572
- * newer one: what was downloaded (`base`), the user's, the new one.
2573
- */
2574
- async mergeInputs(name, signal) {
2575
- const record = this.#record(name);
2576
- const skill = await this.#find(name, record.repo, signal);
2577
- const file = join3(this.skillsDir, name, SKILL_FILE2);
2578
- const [base, mine, theirs] = await Promise.all([
2579
- readFile4(join3(this.#options.dir, "base", name, SKILL_FILE2), "utf8").catch(() => ""),
2580
- readFile4(file, "utf8"),
2581
- readFile4(this.#repoFile(skill), "utf8")
2582
- ]);
2583
- return { base, mine, theirs, file, skill };
2584
- }
2585
- /** After a merge was written into the user's file: the new version counts as taken (the file stays the user's). */
2586
- async merged(name, skill) {
2587
- const record = this.#record(name);
2588
- await mkdir3(join3(this.#options.dir, "base", name), { recursive: true });
2589
- await cp2(this.#repoFile(skill), join3(this.#options.dir, "base", name, SKILL_FILE2));
2590
- this.#state.installed[name] = { repo: record.repo, path: record.path, hash: skill.hash, at: this.#now() };
2591
- await this.#save();
2592
- await this.#register(name);
2593
- }
2594
- /** The user's version and the repository's, for showing what differs. */
2595
- async diff(name, signal) {
2596
- const { mine, theirs } = await this.mergeInputs(name, signal);
2597
- return { mine, theirs };
2627
+ return { state: "updated", item: await this.#item(skill, await this.#options.taken()) };
2598
2628
  }
2599
2629
  async remove(name) {
2600
2630
  this.#record(name);
2601
2631
  this.#options.register(name, void 0);
2602
- await rm2(join3(this.skillsDir, name), { recursive: true, force: true });
2603
- await rm2(join3(this.#options.dir, "base", name), { recursive: true, force: true });
2632
+ await rm2(join4(this.skillsDir, name), { recursive: true, force: true });
2604
2633
  delete this.#state.installed[name];
2605
2634
  await this.#save();
2606
2635
  }
@@ -2646,25 +2675,22 @@ var SkillHub = class {
2646
2675
  return skill;
2647
2676
  }
2648
2677
  #repoFile(skill) {
2649
- 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);
2650
2679
  }
2651
- /** 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. */
2652
2681
  async #put(skill) {
2653
- const from = join3(this.#options.dir, "repos", repoKey({ repo: skill.repo, branch: "" }), ...skill.path.split("/"));
2654
- 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);
2655
2684
  await rm2(to, { recursive: true, force: true });
2656
2685
  await mkdir3(this.skillsDir, { recursive: true });
2657
2686
  await cp2(from, to, { recursive: true });
2658
- await rm2(join3(this.#options.dir, "base", skill.name), { recursive: true, force: true });
2659
- await mkdir3(join3(this.#options.dir, "base", skill.name), { recursive: true });
2660
- await cp2(join3(from, SKILL_FILE2), join3(this.#options.dir, "base", skill.name, SKILL_FILE2));
2661
2687
  const owner = this.#state.installed[skill.name]?.owner;
2662
2688
  this.#state.installed[skill.name] = { repo: skill.repo, path: skill.path, hash: skill.hash, at: this.#now(), ...owner === void 0 ? {} : { owner } };
2663
2689
  await this.#save();
2664
2690
  await this.#register(skill.name);
2665
2691
  }
2666
2692
  async #register(name) {
2667
- const path = join3(this.skillsDir, name, SKILL_FILE2);
2693
+ const path = join4(this.skillsDir, name, SKILL_FILE2);
2668
2694
  const content = await readFile4(path, "utf8").catch(() => void 0);
2669
2695
  const front = content === void 0 ? void 0 : frontmatter(content);
2670
2696
  if (content === void 0 || front === void 0) {
@@ -2678,7 +2704,7 @@ var SkillHub = class {
2678
2704
  const games = ids(listed?.games);
2679
2705
  const scripts = ids(listed?.scripts);
2680
2706
  const owner = games.length + scripts.length === 0 ? void 0 : { ...games.length === 0 ? {} : { games }, ...scripts.length === 0 ? {} : { scripts } };
2681
- 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 } });
2682
2708
  }
2683
2709
  async #item(skill, taken) {
2684
2710
  const record = this.#state.installed[skill.name];
@@ -2686,26 +2712,22 @@ var SkillHub = class {
2686
2712
  const blocked = taken.get(skill.name);
2687
2713
  return { ...skill, ...blocked === void 0 ? {} : { blocked: `\u5DF2\u6709\u540C\u540D\u7684${blocked}` } };
2688
2714
  }
2689
- const content = await readFile4(join3(this.skillsDir, skill.name, SKILL_FILE2), "utf8").catch(() => "");
2690
- return {
2691
- ...skill,
2692
- installed: { at: record.at, modified: hash(content) !== record.hash, update: skill.repo === record.repo && skill.hash !== record.hash && skill.hash !== record.skipped }
2693
- };
2715
+ return { ...skill, installed: { at: record.at, update: skill.repo === record.repo && skill.hash !== record.hash } };
2694
2716
  }
2695
2717
  /** Download the repository and list its skills; the copy replaces the one before. */
2696
2718
  async #readRepo(repo, signal) {
2697
2719
  const key = repoKey(repo);
2698
- const work = join3(this.#options.dir, "downloads");
2720
+ const work = join4(this.#options.dir, "downloads");
2699
2721
  await mkdir3(work, { recursive: true });
2700
- const archive = join3(work, `${key}.zip`);
2701
- const unpacked = join3(work, `${key}-${this.#now()}`);
2722
+ const archive = join4(work, `${key}.zip`);
2723
+ const unpacked = join4(work, `${key}-${this.#now()}`);
2702
2724
  await this.#options.download(`https://codeload.github.com/${repo.repo}/zip/refs/heads/${encodeURIComponent(repo.branch)}`, archive, signal);
2703
2725
  try {
2704
2726
  await this.#options.extract(archive, unpacked, signal);
2705
2727
  const skills = await readSkills(unpacked, repo.repo);
2706
- const target = join3(this.#options.dir, "repos", key);
2728
+ const target = join4(this.#options.dir, "repos", key);
2707
2729
  await rm2(target, { recursive: true, force: true });
2708
- await mkdir3(join3(this.#options.dir, "repos"), { recursive: true });
2730
+ await mkdir3(join4(this.#options.dir, "repos"), { recursive: true });
2709
2731
  await rename3(unpacked, target);
2710
2732
  return skills;
2711
2733
  } finally {
@@ -2714,12 +2736,12 @@ var SkillHub = class {
2714
2736
  }
2715
2737
  }
2716
2738
  #save() {
2717
- 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)}
2718
2740
  `));
2719
2741
  }
2720
2742
  };
2721
2743
  async function readSkills(root, repo) {
2722
- 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);
2723
2745
  const listed = [];
2724
2746
  if (indexText !== void 0) {
2725
2747
  const parsed = Index.safeParse(JSON.parse(indexText.replace(/^/, "")));
@@ -2737,7 +2759,7 @@ async function readSkills(root, repo) {
2737
2759
  const rel = relative2(resolve2(root), full);
2738
2760
  if (path === "" || rel.startsWith("..") || rel.split(sep).includes(".."))
2739
2761
  continue;
2740
- 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);
2741
2763
  const front = content === void 0 ? void 0 : frontmatter(content);
2742
2764
  if (content === void 0 || front === void 0)
2743
2765
  continue;
@@ -2762,7 +2784,7 @@ async function readSkills(root, repo) {
2762
2784
  }
2763
2785
  async function findSkillFolders(root, sub, depth) {
2764
2786
  const out = [];
2765
- const entries = await readdir3(join3(root, sub), { withFileTypes: true }).catch(() => []);
2787
+ const entries = await readdir3(join4(root, sub), { withFileTypes: true }).catch(() => []);
2766
2788
  if (sub !== "" && entries.some((e) => e.isFile() && e.name === SKILL_FILE2))
2767
2789
  out.push(sub);
2768
2790
  if (depth === 0)
@@ -2819,7 +2841,6 @@ function takenLabel(source) {
2819
2841
  return "\u6280\u80FD\uFF08\u4F60\u7684\u6280\u80FD\u6587\u4EF6\u5939\uFF09";
2820
2842
  return "\u6280\u80FD";
2821
2843
  }
2822
- var MERGE_TIMEOUT_MS = 10 * 6e4;
2823
2844
  function startSkillHub(ctx, library, ready, approve, log) {
2824
2845
  const entries = /* @__PURE__ */ new Map();
2825
2846
  const disposers = /* @__PURE__ */ new Map();
@@ -2839,7 +2860,7 @@ function startSkillHub(ctx, library, ready, approve, log) {
2839
2860
  }
2840
2861
  };
2841
2862
  const hub = new SkillHub({
2842
- dir: join4(library.dataDir, "skill-hub"),
2863
+ dir: join5(library.dataDir, "skill-hub"),
2843
2864
  download: (url, dest, signal) => library.downloadFromGitHub(url, dest, signal),
2844
2865
  extract: async (archive, dest, signal) => {
2845
2866
  await library.unpack(archive, dest, signal);
@@ -2872,37 +2893,6 @@ function startSkillHub(ctx, library, ready, approve, log) {
2872
2893
  skills = void 0;
2873
2894
  }, "adg-skill-hub skills");
2874
2895
  });
2875
- const merge = async (name, signal) => {
2876
- const sessions = ctx.get("sessionController");
2877
- if (sessions === void 0)
2878
- throw new Error("agent \u73B0\u5728\u4E0D\u53EF\u7528\uFF08\u4F1A\u8BDD\u670D\u52A1\u6CA1\u6709\u52A0\u8F7D\uFF09");
2879
- const { base, mine, theirs, file, skill } = await hub.mergeInputs(name, signal);
2880
- const conversations = sessionConversations(sessions, () => ctx.get("adgGateway")?.workspaceDir(), void 0, () => ctx.get("adgGateway"));
2881
- const sessionId = await conversations.home(SCRIPT_ROLE.id);
2882
- const prompt = [
2883
- `\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`,
2884
- "\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",
2885
- "",
2886
- "\u4E0B\u8F7D\u65F6\u7684\u7248\u672C\uFF08\u5171\u540C\u7684\u8D77\u70B9\uFF09\uFF1A",
2887
- "```markdown",
2888
- base,
2889
- "```",
2890
- "\u7528\u6237\u73B0\u5728\u7684\u7248\u672C\uFF1A",
2891
- "```markdown",
2892
- mine,
2893
- "```",
2894
- "\u6280\u80FD\u5E93\u7684\u65B0\u7248\u672C\uFF1A",
2895
- "```markdown",
2896
- theirs,
2897
- "```"
2898
- ].join("\n");
2899
- void conversations.ask(sessionId, taskMessage("\u4F60", `\u5408\u5E76\u6280\u80FD\uFF1A${name}`, prompt), AbortSignal.timeout(MERGE_TIMEOUT_MS)).then(async () => {
2900
- await hub.merged(name, skill);
2901
- changed();
2902
- }, (error) => log.warn(`skill hub: merging ${name} failed: ${error instanceof Error ? error.message : String(error)}`));
2903
- const { items } = await hub.list();
2904
- return { sessionId, item: items.find((i) => i.name === name) };
2905
- };
2906
2896
  ctx.inject(["adgGateway"], (scoped) => {
2907
2897
  const methods = {
2908
2898
  "skillhub/list": (params, call) => hub.list({ refresh: params.refresh === true, signal: call.signal }),
@@ -2913,14 +2903,10 @@ function startSkillHub(ctx, library, ready, approve, log) {
2913
2903
  return item;
2914
2904
  },
2915
2905
  "skillhub/update": async (params, call) => {
2916
- const p = params;
2917
- if (p.resolve === "merge")
2918
- return { state: "merging", ...await merge(p.name, call.signal) };
2919
- const result = await hub.update(p.name, p.resolve, call.signal);
2906
+ const result = await hub.update(params.name, call.signal);
2920
2907
  changed();
2921
2908
  return result;
2922
2909
  },
2923
- "skillhub/diff": (params, call) => hub.diff(params.name, call.signal),
2924
2910
  "skillhub/remove": async (params) => {
2925
2911
  await hub.remove(params.name);
2926
2912
  changed();
@@ -2994,7 +2980,7 @@ function hubTools(hub, approve, changed) {
2994
2980
  },
2995
2981
  {
2996
2982
  name: "skill_hub_install",
2997
- 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",
2998
2984
  parameters: {
2999
2985
  type: "object",
3000
2986
  properties: { name: { type: "string", description: "\u6280\u80FD\u540D\uFF08skill_hub_list \u53EF\u67E5\uFF09\u3002" } },
@@ -3263,7 +3249,7 @@ function scriptTools(library, approve) {
3263
3249
  if (setup !== void 0)
3264
3250
  return { ...describeJob(job), setup };
3265
3251
  const info = job.phase === "done" ? library.get(job.scriptId) : void 0;
3266
- const next = info !== void 0 && info.packId === void 0 ? { next: `\u88C5\u597D\u4E86\uFF0C\u4F46\u8FD8\u6CA1\u6709\u811A\u672C\u5305\uFF0C\u8FD8\u4E0D\u80FD\u7528 script_run \u8FD0\u884C\u3002\u544A\u8BC9\u7528\u6237\u4E4B\u540E\uFF0C\u6309\u6280\u80FD script-analysis \u5206\u6790\u5B83\uFF08skill_focus \u8BBE\u6210 ${info.id}\uFF0C\u5148\u8BFB\u9879\u76EE\u6587\u6863\uFF1A\u4ED3\u5E93 README\u3001Wiki\u3001\u76EE\u5F55\u91CC\u7684\u8BF4\u660E\uFF0C\u518D\u770B\u4EE3\u7801\uFF09\uFF0C\u7528 pack_propose \u63D0\u4EA4\u811A\u672C\u5305\u8349\u7A3F\u7ED9\u7528\u6237\u786E\u8BA4\u3002` } : {};
3252
+ const next = info !== void 0 && info.packId === void 0 ? { next: `\u88C5\u597D\u4E86\uFF0C\u4F46\u8FD8\u6CA1\u6709\u811A\u672C\u5305\uFF0C\u8FD8\u4E0D\u80FD\u7528 script_run \u8FD0\u884C\u3002\u544A\u8BC9\u7528\u6237\u4E4B\u540E\uFF0C\u6309\u6280\u80FD script-analysis \u5206\u6790\u5B83\uFF08skill_focus \u8BBE\u6210 ${info.id}\uFF0C\u5148\u8BFB\u9879\u76EE\u6587\u6863\uFF1A\u4ED3\u5E93 README\u3001Wiki\u3001\u76EE\u5F55\u91CC\u7684\u8BF4\u660E\uFF0C\u518D\u770B\u4EE3\u7801\uFF09\uFF0C\u7528 pack_propose \u4FDD\u5B58\u811A\u672C\u5305\uFF08\u76F4\u63A5\u751F\u6548\uFF0C\u4E0D\u7528\u7528\u6237\u786E\u8BA4\uFF09\u3002` } : {};
3267
3253
  return { ...describeJob(job), dir: info?.dir, env: info?.env, family: info?.family, ...next };
3268
3254
  }
3269
3255
  }),
@@ -3452,6 +3438,8 @@ var UPDATE_CHECK_EVERY_MS = 6 * 60 * 6e4;
3452
3438
  var ConfigSchema = external_exports.object({
3453
3439
  /** Where installed scripts live: `<toolsDir>/<id>/<version>/`. */
3454
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(),
3455
3443
  /** Library state (`scripts.json`) and the user's packs (`packs/`). */
3456
3444
  dataDir: external_exports.string().min(1),
3457
3445
  /** Built-in pack directories; default: the `@adg/packs` package. */
@@ -3481,6 +3469,7 @@ var AdgScripts = class extends Service {
3481
3469
  this.optimizer = optimizer2;
3482
3470
  this.library = new ScriptLibrary({
3483
3471
  toolsDir: spec.toolsDir,
3472
+ ...spec.formerToolsDirs === void 0 ? {} : { formerToolsDirs: spec.formerToolsDirs },
3484
3473
  dataDir: spec.dataDir,
3485
3474
  packDirs: spec.packDirs ?? [PACKS_DIR],
3486
3475
  ...spec.defaults === void 0 ? {} : { defaults: stripUndefined2(spec.defaults) },
@@ -3553,7 +3542,7 @@ var AdgScripts = class extends Service {
3553
3542
  if (setup === void 0)
3554
3543
  throw new Error(`${id} \u6CA1\u6709\u7B49\u5F85\u8FD0\u884C\u7684\u5B89\u88C5\u7A0B\u5E8F`);
3555
3544
  return handOff(setup);
3556
- }, review, optimizer2);
3545
+ }, review, optimizer2, new ExeIcons(join6(spec.dataDir, "icons")));
3557
3546
  scoped.adgGateway.register({
3558
3547
  ...capability,
3559
3548
  methods: Object.fromEntries(Object.entries(capability.methods).map(([name, handler]) => [name, async (params, call) => {