dsh-multigameassistant 2.3.0 → 2.3.2

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.
@@ -35,13 +35,13 @@ import {
35
35
  parseJsonc,
36
36
  parseManifest,
37
37
  versionOfTag
38
- } from "./chunk-TXW3NMBH.js";
38
+ } from "./chunk-7UJ3LK3G.js";
39
39
  import {
40
40
  sessionConversations
41
- } from "./chunk-VG32XPZH.js";
41
+ } from "./chunk-SMXJWLAZ.js";
42
42
  import {
43
43
  pluginVersion
44
- } from "./chunk-VBWSM7LF.js";
44
+ } from "./chunk-OCJFAT7J.js";
45
45
  import {
46
46
  ExeIcons,
47
47
  writeFileAtomic
@@ -51,6 +51,7 @@ import {
51
51
  GitHubRepo,
52
52
  InstallSettings,
53
53
  LocalVersion,
54
+ MAIN_AGENT_NAME,
54
55
  MirrorRid,
55
56
  ProjectProbe,
56
57
  SCRIPTS_CAPABILITY,
@@ -64,7 +65,7 @@ import {
64
65
  optimizeScriptPrompt,
65
66
  parseGitHubLink,
66
67
  taskMessage
67
- } from "./chunk-7EFZ5KR6.js";
68
+ } from "./chunk-BB2T4JHF.js";
68
69
  import {
69
70
  NEVER,
70
71
  ZodIssueCode,
@@ -604,8 +605,9 @@ import { Service } from "@deepseek-ai/cordis";
604
605
  // packages/script-registry/lib/role.js
605
606
  var SCRIPT_ROLE = {
606
607
  id: "scripts",
607
- name: "\u811A\u672C",
608
+ name: "\u811A\u672C\u52A9\u624B",
608
609
  description: "\u5B89\u88C5\u548C\u4ECB\u7ECD\u811A\u672C\u3001\u68C0\u67E5\u811A\u672C\u5305\u3001\u5408\u5E76\u6280\u80FD",
610
+ handles: "\u811A\u672C\u7684\u4E8B\u90FD\u4EA4\u7ED9\u5B83\uFF1A\u5B89\u88C5\u3001\u66F4\u65B0\u3001\u4ECB\u7ECD\u811A\u672C\uFF1B\u6E38\u620F\u91CC\u8981\u505A\u7684\u4E8B\u6709\u811A\u672C\u80FD\u505A\u65F6\uFF0C\u7528\u90A3\u4E2A\u811A\u672C\u7684\u4EFB\u52A1\u53BB\u505A\uFF08\u8FD0\u884C\u3001\u505C\u6B62\u3001\u770B\u8FD0\u884C\u7ED3\u679C\uFF09\uFF1B\u6539\u811A\u672C\u8BBE\u7F6E\u3001\u4FEE\u8FD0\u884C\u73AF\u5883\uFF1B\u5206\u6790\u811A\u672C\u3001\u5199\u548C\u6539\u811A\u672C\u5305\uFF1B\u5B89\u88C5\u3001\u5408\u5E76\u6280\u80FD\uFF1B\u6309\u811A\u672C\u6DFB\u52A0\u65E5\u5E38\u5468\u5E38\u3002\u4E0D\u8BFB\u6E38\u620F\u6D3B\u52A8\u3001\u4E0D\u6539\u6D41\u6C34\u7EBF\u3002",
609
611
  order: 30,
610
612
  titles: ["\u5B89\u88C5\u811A\u672C", "\u811A\u672C\u4ECB\u7ECD", "\u68C0\u67E5\u811A\u672C\u5305", "\u5408\u5E76\u6280\u80FD"],
611
613
  // Scripts, their packs and environment, skills; the screen for setup programs. No game reading or pipelines.
@@ -631,7 +633,7 @@ var SCRIPT_ROLE = {
631
633
  ],
632
634
  duty: [
633
635
  "# \u4F60\u7684\u89D2\u8272\uFF1A\u811A\u672C",
634
- "\u4F60\u662F MultiGameAssistant \u7684\u300C\u811A\u672C\u300Dagent\uFF1A\u5B89\u88C5\u3001\u66F4\u65B0\u548C\u4ECB\u7ECD\u811A\u672C\uFF0C\u68C0\u67E5\u548C\u4FEE\u597D\u8FD0\u884C\u73AF\u5883\uFF0C\u68C0\u67E5\u811A\u672C\u5305\uFF0C\u5B89\u88C5\u548C\u5408\u5E76\u6280\u80FD\u3002\u7528\u6237\u6216\u540C\u4E8B\u8981\u5728\u6E38\u620F\u91CC\u505A\u4E00\u4EF6\u4E8B\u3001\u800C\u67D0\u4E2A\u811A\u672C\u6709\u8FD9\u4E2A\u4EFB\u52A1\u65F6\uFF0C\u4E5F\u7531\u4F60\u7528 script_run \u8FD0\u884C\u90A3\u4E2A\u4EFB\u52A1\u53BB\u505A\u3002",
636
+ "\u4F60\u662F MultiGameAssistant \u7684\u300C\u811A\u672C\u52A9\u624B\u300Dagent\uFF1A\u5B89\u88C5\u3001\u66F4\u65B0\u548C\u4ECB\u7ECD\u811A\u672C\uFF0C\u68C0\u67E5\u548C\u4FEE\u597D\u8FD0\u884C\u73AF\u5883\uFF0C\u68C0\u67E5\u811A\u672C\u5305\uFF0C\u5B89\u88C5\u548C\u5408\u5E76\u6280\u80FD\u3002\u7528\u6237\u6216\u540C\u4E8B\u8981\u5728\u6E38\u620F\u91CC\u505A\u4E00\u4EF6\u4E8B\u3001\u800C\u67D0\u4E2A\u811A\u672C\u6709\u8FD9\u4E2A\u4EFB\u52A1\u65F6\uFF0C\u4E5F\u7531\u4F60\u7528 script_run \u8FD0\u884C\u90A3\u4E2A\u4EFB\u52A1\u53BB\u505A\u3002",
635
637
  UPDATE_RULE,
636
638
  "script_update \u4ECE Mirror\u9171\uFF08\u8F6F\u4EF6\u91CC\u7684 CDK\uFF0C\u6216\u811A\u672C\u81EA\u5DF1\u8BBE\u7F6E\u91CC\u586B\u7684 CDK\uFF09\u6216 GitHub \u7684\u53D1\u5E03\u5305\u4E0B\u8F7D\uFF0C\u5E76\u63A5\u4E0A\u539F\u6765\u7684\u914D\u7F6E\u3002\u8FD0\u884C\u4EFB\u52A1\u524D\u8F6F\u4EF6\u4E5F\u4F1A\u5148\u8FD9\u6837\u66F4\u65B0\u4E00\u6B21\uFF08\u8DDF\u7740\u5206\u652F\u6E90\u7801\u7684\u811A\u672C\u4E0D\u4F1A\u81EA\u52A8\u66F4\u65B0\uFF09\uFF0C\u66F4\u65B0\u5931\u8D25\u5C31\u7167\u65E7\u7528\u73B0\u6709\u7248\u672C\u8FD0\u884C\u3002",
637
639
  "\u4E0D\u8BFB\u6E38\u620F\u6D3B\u52A8\u3001\u4E0D\u5199\u65E5\u62A5\u3001\u4E0D\u6539\u6D41\u6C34\u7EBF\u548C\u5B9A\u65F6\uFF1B\u9700\u8981\u8FD9\u4E9B\u65F6\u4EA4\u7ED9\u5BF9\u5E94\u7684\u540C\u4E8B\uFF08agent_delegate\uFF09\uFF0C\u6216\u8005\u5728\u56DE\u590D\u91CC\u8BF4\u6E05\u695A\u3002"
@@ -2986,7 +2988,7 @@ function packReview(ctx, library, log) {
2986
2988
  `\u300C${script.name}\u300D\uFF08\u811A\u672C id ${id}\uFF09\u4ECE ${from} \u66F4\u65B0\u5230\u4E86 ${to}\uFF0C\u5B83\u7684\u811A\u672C\u5305 ${script.packId ?? ""} \u662F\u6309 ${from} \u5199\u7684\u3002`,
2987
2989
  "\u8BF7\u6309\u6280\u80FD script-analysis \u91CC\u300C\u811A\u672C\u66F4\u65B0\u540E\u68C0\u67E5\u811A\u672C\u5305\u300D\u7684\u6B65\u9AA4\u505A\uFF1A",
2988
2990
  `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`,
2989
- "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",
2991
+ "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\u754C\u9762\u4E0A\u7684\u6539\u52A8\uFF08\u529F\u80FD\u632A\u4E86\u4F4D\u7F6E\u3001\u9009\u9879\u6539\u4E86\u540D\uFF09\u53EF\u4EE5\u6253\u5F00\u811A\u672C\u7A0B\u5E8F\u770B\uFF1Ascript_settings \u6253\u5F00\u8BBE\u7F6E\u754C\u9762\uFF08\u547D\u4EE4\u884C\u811A\u672C\u7528 script_help\uFF09\uFF0Cwindow_list \u627E\u7A97\u53E3\uFF0Cscreen_capture\uFF08target=window\uFF09\u622A\u56FE\u5BF9\u7167\uFF0C\u770B\u5B8C\u7528 script_stop \u5173\u6389\uFF1B\u4E0D\u8981\u8DD1\u4EFB\u52A1\u3001\u4E0D\u8981\u6539\u914D\u7F6E\uFF1B",
2990
2992
  "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",
2991
2993
  "4. \u6700\u540E\u7528\u4E24\u4E09\u53E5\u8BDD\u544A\u8BC9\u7528\u6237\u7ED3\u8BBA\u3002"
2992
2994
  ].join("\n");
@@ -3070,7 +3072,7 @@ function optimizer(ctx, library, log) {
3070
3072
  const prompt = optimizeScriptPrompt(script.name, why(script), id);
3071
3073
  await lib.optimizeDone(id, "run");
3072
3074
  void work.run(taskMessage(by, `\u4F18\u5316\u811A\u672C\uFF1A${script.name}`, prompt), AbortSignal.timeout(OPTIMIZE_TIMEOUT_MS)).catch((error) => log.warn(`optimizing ${id}: ${error instanceof Error ? error.message : String(error)}`));
3073
- close(id, "\u5DF2\u4EA4\u7ED9\u300C\u811A\u672C\u300D\u4F18\u5316\uFF0C\u811A\u672C\u5305\u7684\u6539\u52A8\u4F1A\u5728\u300C\u811A\u672C\u300D\u9875\u7B49\u4F60\u786E\u8BA4");
3075
+ close(id, "\u5DF2\u4EA4\u7ED9\u300C\u811A\u672C\u52A9\u624B\u300D\u4F18\u5316\uFF0C\u811A\u672C\u5305\u7684\u6539\u52A8\u4F1A\u5728\u300C\u811A\u672C\u300D\u9875\u7B49\u4F60\u786E\u8BA4");
3074
3076
  return { sessionId };
3075
3077
  };
3076
3078
  ctx.inject(["adgNotify"], (scoped) => {
@@ -3078,8 +3080,8 @@ function optimizer(ctx, library, log) {
3078
3080
  const id = noticeId.split(":")[1];
3079
3081
  if (id === void 0 || actionId !== "run" && actionId !== "keep")
3080
3082
  throw new Error(`\u672A\u77E5\u64CD\u4F5C ${actionId}`);
3081
- const { sessionId } = await decide(id, actionId, actor.channel === "agent" ? actor.name ?? "\u52A9\u624B" : "\u4F60");
3082
- return sessionId === void 0 ? "\u597D\u7684\uFF0C\u8FD9\u6B21\u4E0D\u4F18\u5316\uFF0C\u4E4B\u540E\u8DD1\u591F\u4E86\u518D\u95EE" : "\u597D\u7684\uFF0C\u300C\u811A\u672C\u300D\u4F1A\u91CD\u65B0\u603B\u7ED3\u811A\u672C\u5305\u3001\u8C03\u5361\u4F4F\u65F6\u95F4\u3001\u628A\u8D70\u901A\u7684\u6B65\u9AA4\u5B58\u6210\u6280\u80FD\uFF1B\u811A\u672C\u5305\u7684\u6539\u52A8\u4F1A\u5728\u300C\u811A\u672C\u300D\u9875\u7B49\u4F60\u786E\u8BA4";
3083
+ const { sessionId } = await decide(id, actionId, actor.channel === "agent" ? actor.name ?? MAIN_AGENT_NAME : "\u4F60");
3084
+ return sessionId === void 0 ? "\u597D\u7684\uFF0C\u8FD9\u6B21\u4E0D\u4F18\u5316\uFF0C\u4E4B\u540E\u8DD1\u591F\u4E86\u518D\u95EE" : "\u597D\u7684\uFF0C\u300C\u811A\u672C\u52A9\u624B\u300D\u4F1A\u91CD\u65B0\u603B\u7ED3\u811A\u672C\u5305\u3001\u8C03\u5361\u4F4F\u65F6\u95F4\u3001\u628A\u8D70\u901A\u7684\u6B65\u9AA4\u5B58\u6210\u6280\u80FD\uFF1B\u811A\u672C\u5305\u7684\u6539\u52A8\u4F1A\u5728\u300C\u811A\u672C\u300D\u9875\u7B49\u4F60\u786E\u8BA4";
3083
3085
  }), "adg-scripts optimize actions");
3084
3086
  });
3085
3087
  return {
@@ -3096,7 +3098,7 @@ function optimizer(ctx, library, log) {
3096
3098
  title: `\u8981\u4F18\u5316\u300C${script.name}\u300D\u5417\uFF1F`,
3097
3099
  text: [
3098
3100
  `${script.name} ${why(script) ?? ""}\uFF0C\u6512\u4E0B\u7684\u8FD0\u884C\u8BB0\u5F55\u591F\u7528\u6765\u4F18\u5316\u5B83\u4E86\u3002`,
3099
- "\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"
3101
+ "\u8981\u8BA9\u300C\u811A\u672C\u52A9\u624B\u300D\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"
3100
3102
  ].join("\n"),
3101
3103
  severity: "info",
3102
3104
  actions: [{ id: "run", label: "\u4F18\u5316\u811A\u672C", style: "primary" }, { id: "keep", label: "\u8FD9\u6B21\u4E0D\u7528" }]
@@ -22481,7 +22483,7 @@ function mcpTools(library, integrations, approve) {
22481
22483
  }),
22482
22484
  tool2({
22483
22485
  name: MCP_TOOL_NAMES.skills,
22484
- description: "\u5217\u51FA\u811A\u672C\u81EA\u5DF1\u5E26\u7684\u6280\u80FD\uFF08\u811A\u672C\u76EE\u5F55\u91CC skills/\u3001.claude/skills/\u3001.agents/skills/ \u7B49\u5904\u7684 SKILL.md\uFF09\uFF0C\u4EE5\u53CA\u54EA\u4E9B\u5DF2\u7ECF\u653E\u8FDB\u4E86\u672C\u8F6F\u4EF6\u7684\u6280\u80FD\u5E93\uFF08\u300C\u6280\u80FD\u300D\u9875\uFF0C\u53EA\u5728\u5904\u7406\u8FD9\u4E2A\u811A\u672C\u65F6\u53EF\u89C1\uFF09\u3002",
22486
+ description: "\u5217\u51FA\u811A\u672C\u81EA\u5DF1\u5E26\u7684\u6280\u80FD\uFF08\u811A\u672C\u76EE\u5F55\u91CC skills/\u3001.claude/skills/\u3001.agents/skills/\u3001assets/agent/skills/ \u7B49\u5904\u7684 SKILL.md\uFF09\uFF0C\u4EE5\u53CA\u54EA\u4E9B\u5DF2\u7ECF\u653E\u8FDB\u4E86\u672C\u8F6F\u4EF6\u7684\u6280\u80FD\u5E93\uFF08\u300C\u6280\u80FD\u300D\u9875\uFF0C\u53EA\u5728\u5904\u7406\u8FD9\u4E2A\u811A\u672C\u65F6\u53EF\u89C1\uFF09\u3002\u8F6F\u4EF6\u627E\u5230\u6280\u80FD\u5C31\u4F1A\u81EA\u52A8\u653E\u8FDB\u53BB\uFF1B\u7528\u6237\u5728\u300C\u6280\u80FD\u300D\u9875\u5220\u6389\u7684\u4E0D\u4F1A\u81EA\u52A8\u653E\u56DE\u3002",
22485
22487
  properties: { id },
22486
22488
  required: ["id"],
22487
22489
  kind: "read",
@@ -22494,7 +22496,7 @@ function mcpTools(library, integrations, approve) {
22494
22496
  }),
22495
22497
  tool2({
22496
22498
  name: MCP_TOOL_NAMES.importSkills,
22497
- description: "\u628A\u811A\u672C\u81EA\u5E26\u7684\u6280\u80FD\u653E\u8FDB\u672C\u8F6F\u4EF6\u7684\u6280\u80FD\u5E93\uFF08\u300C\u6280\u80FD\u300D\u9875\uFF09\uFF1A\u590D\u5236\u6574\u4E2A\u6280\u80FD\u6587\u4EF6\u5939\uFF0C\u5F52\u5230\u8FD9\u4E2A\u811A\u672C\u4E0B\uFF0C\u53EA\u6709\u5904\u7406\u8FD9\u4E2A\u811A\u672C\u7684\u4F1A\u8BDD\u80FD\u770B\u5230\u548C\u8C03\u7528\u3002\u518D\u6B21\u5BFC\u5165\u4F1A\u7528\u811A\u672C\u91CC\u73B0\u5728\u7684\u7248\u672C\u66FF\u6362\uFF1B\u811A\u672C\u66F4\u65B0\u540E\uFF0C\u6280\u80FD\u6587\u4EF6\u5939\u6709\u53D8\u5316\u3001\u4E14\u5728\u8FD9\u91CC\u6CA1\u88AB\u6539\u8FC7\u7684\u4F1A\u81EA\u52A8\u91CD\u65B0\u5BFC\u5165\u3002",
22499
+ description: "\u628A\u811A\u672C\u81EA\u5E26\u7684\u6280\u80FD\u653E\u8FDB\u672C\u8F6F\u4EF6\u7684\u6280\u80FD\u5E93\uFF08\u300C\u6280\u80FD\u300D\u9875\uFF09\uFF1A\u590D\u5236\u6574\u4E2A\u6280\u80FD\u6587\u4EF6\u5939\uFF0C\u5F52\u5230\u8FD9\u4E2A\u811A\u672C\u4E0B\uFF0C\u53EA\u6709\u5904\u7406\u8FD9\u4E2A\u811A\u672C\u7684\u4F1A\u8BDD\u80FD\u770B\u5230\u548C\u8C03\u7528\u3002\u7528\u6237\u6216\u811A\u672C\u7684\u8BF4\u660E\u8BA9\u4F60\u628A\u5B83\u7684\u6280\u80FD\u590D\u5236\u5230\u300C\u4F60\u7684\u7528\u6237\u7EA7\u6280\u80FD\u76EE\u5F55\u300D\uFF08~/.agents/skills\u3001~/.claude/skills \u4E4B\u7C7B\uFF09\u65F6\uFF0C\u5C31\u7528\u8FD9\u4E2A\u3002\u518D\u6B21\u5BFC\u5165\u4F1A\u7528\u811A\u672C\u91CC\u73B0\u5728\u7684\u7248\u672C\u66FF\u6362\uFF1B\u811A\u672C\u66F4\u65B0\u540E\uFF0C\u6280\u80FD\u6587\u4EF6\u5939\u6709\u53D8\u5316\u3001\u4E14\u5728\u8FD9\u91CC\u6CA1\u88AB\u6539\u8FC7\u7684\u4F1A\u81EA\u52A8\u91CD\u65B0\u5BFC\u5165\u3002",
22498
22500
  properties: {
22499
22501
  id,
22500
22502
  names: { type: "array", items: { type: "string" }, description: "\u8981\u5BFC\u5165\u7684\u6280\u80FD\u540D\u6216\u8DEF\u5F84\uFF08script_skills \u5217\u51FA\u7684\uFF09\uFF1B\u7701\u7565\u5BFC\u5165\u5168\u90E8\u3002" }
@@ -22511,6 +22513,10 @@ function mcpTools(library, integrations, approve) {
22511
22513
  ];
22512
22514
  }
22513
22515
 
22516
+ // packages/script-registry/lib/script-integrations.js
22517
+ import { mkdir as mkdir4, readFile as readFile7 } from "node:fs/promises";
22518
+ import { dirname as dirname4 } from "node:path";
22519
+
22514
22520
  // packages/script-registry/lib/script-skills.js
22515
22521
  import { createHash as createHash3 } from "node:crypto";
22516
22522
  import { readdir as readdir4, readFile as readFile6, stat as stat3 } from "node:fs/promises";
@@ -22553,9 +22559,30 @@ async function discoverSkills(scriptDir) {
22553
22559
  for (const rel of await skillFolders(scriptDir, place, 3))
22554
22560
  await add(rel, false);
22555
22561
  }
22562
+ for (const place of await skillsDirs(scriptDir, "", 3)) {
22563
+ if (SKILL_PLACES.includes(place))
22564
+ continue;
22565
+ for (const rel of await skillFolders(scriptDir, place, 3))
22566
+ await add(rel, false);
22567
+ }
22556
22568
  await add("", true);
22557
22569
  return out;
22558
22570
  }
22571
+ var NOT_THE_SCRIPTS = /* @__PURE__ */ new Set(["node_modules", ".git", "__pycache__", "site-packages", "dist-packages", "lib", "libs", "venv", ".venv", "env", "python", "runtime", "logs", "log", "cache", "temp", "tmp"]);
22572
+ async function skillsDirs(root, sub, depth) {
22573
+ const entries = await readdir4(sub === "" ? root : join7(root, ...sub.split("/")), { withFileTypes: true }).catch(() => []);
22574
+ const out = [];
22575
+ for (const entry of entries) {
22576
+ if (!entry.isDirectory() || NOT_THE_SCRIPTS.has(entry.name.toLowerCase()))
22577
+ continue;
22578
+ const rel = sub === "" ? entry.name : `${sub}/${entry.name}`;
22579
+ if (entry.name === "skills" || entry.name === ".skills")
22580
+ out.push(rel);
22581
+ else if (depth > 1)
22582
+ out.push(...await skillsDirs(root, rel, depth - 1));
22583
+ }
22584
+ return out;
22585
+ }
22559
22586
  async function skillFolders(root, sub, depth) {
22560
22587
  const entries = await readdir4(join7(root, ...sub.split("/")), { withFileTypes: true }).catch(() => []);
22561
22588
  if (entries.some((e) => e.isFile() && e.name === SKILL_FILE3))
@@ -22602,11 +22629,16 @@ var ScriptIntegrations = class {
22602
22629
  #library;
22603
22630
  #keeper;
22604
22631
  #log;
22605
- constructor(library, mcp, keeper, log) {
22632
+ /** The script skills put in once (`<script>\0<path>`): one the user takes out again is not brought back. */
22633
+ #seenFile;
22634
+ #seen;
22635
+ #auto = Promise.resolve();
22636
+ constructor(library, mcp, keeper, log, options = {}) {
22606
22637
  this.#library = library;
22607
22638
  this.mcp = mcp;
22608
22639
  this.#keeper = keeper;
22609
22640
  this.#log = log;
22641
+ this.#seenFile = options.seenFile;
22610
22642
  }
22611
22643
  #installed(id) {
22612
22644
  const script = this.#library.get(id);
@@ -22698,7 +22730,7 @@ var ScriptIntegrations = class {
22698
22730
  description: skill.description,
22699
22731
  path: skill.path,
22700
22732
  ...skill.problem === void 0 ? {} : { problem: skill.problem },
22701
- ...copy === void 0 ? {} : { imported: { name: copy.name, current: copy.origin["hash"] === skill.hash, changed: copy.changed } }
22733
+ ...copy === void 0 ? {} : { imported: { name: copy.name, current: copy.origin["hash"] === skill.hash, changed: copy.changed, ...copy.origin["auto"] === true ? { auto: true } : {} } }
22702
22734
  };
22703
22735
  });
22704
22736
  }
@@ -22767,6 +22799,78 @@ var ScriptIntegrations = class {
22767
22799
  this.#log.info(`skills taken again after ${id} changed: ${again.join(", ")}`);
22768
22800
  return again;
22769
22801
  }
22802
+ /**
22803
+ * Put a script's skills among this app's skills as soon as they are found
22804
+ * (installed, imported, updated, or already there when the app starts):
22805
+ * each belongs to the script, like 放进技能库 on the 脚本 page. Each is put
22806
+ * in once; one the user removed from the 技能 page stays out until taken by hand.
22807
+ * @returns the names put in.
22808
+ */
22809
+ autoImportSkills(id) {
22810
+ const next = this.#auto.then(() => this.#autoImport(id));
22811
+ this.#auto = next.catch(() => void 0);
22812
+ return next;
22813
+ }
22814
+ async #autoImport(id) {
22815
+ const keeper = this.#keeper();
22816
+ if (keeper === void 0)
22817
+ return [];
22818
+ let script;
22819
+ try {
22820
+ script = this.#installed(id);
22821
+ } catch {
22822
+ return [];
22823
+ }
22824
+ const found = (await discoverSkills(script.dir)).filter((s) => s.problem === void 0);
22825
+ if (found.length === 0)
22826
+ return [];
22827
+ const seen = await this.#seenSet();
22828
+ const key = (skill) => `${id}\0${skill.path}`;
22829
+ const imported = await keeper.importedSkills().catch(() => []);
22830
+ const here = (skill) => imported.some((item) => item.origin.kind === "script" && item.origin["script"] === id && item.origin["path"] === skill.path);
22831
+ const names = [];
22832
+ let grew = false;
22833
+ for (const skill of found) {
22834
+ if (seen.has(key(skill)))
22835
+ continue;
22836
+ if (!here(skill)) {
22837
+ try {
22838
+ const input = this.#importInput(script, skill);
22839
+ names.push((await keeper.importSkill({ ...input, origin: { ...input.origin, auto: true } })).name);
22840
+ } catch (error) {
22841
+ this.#log.warn(`skill ${skill.name} of ${id} not put in: ${error instanceof Error ? error.message : String(error)}`);
22842
+ continue;
22843
+ }
22844
+ }
22845
+ seen.add(key(skill));
22846
+ grew = true;
22847
+ }
22848
+ if (grew)
22849
+ await this.#saveSeen(seen);
22850
+ if (names.length > 0)
22851
+ this.#log.info(`skills of ${id} put in the skill library: ${names.join(", ")}`);
22852
+ return names;
22853
+ }
22854
+ #seenSet() {
22855
+ this.#seen ??= (async () => {
22856
+ if (this.#seenFile === void 0)
22857
+ return /* @__PURE__ */ new Set();
22858
+ try {
22859
+ const saved = JSON.parse(await readFile7(this.#seenFile, "utf8"));
22860
+ return new Set(Array.isArray(saved) ? saved.filter((v) => typeof v === "string") : []);
22861
+ } catch {
22862
+ return /* @__PURE__ */ new Set();
22863
+ }
22864
+ })();
22865
+ return this.#seen;
22866
+ }
22867
+ async #saveSeen(seen) {
22868
+ if (this.#seenFile === void 0)
22869
+ return;
22870
+ await mkdir4(dirname4(this.#seenFile), { recursive: true });
22871
+ await writeFileAtomic(this.#seenFile, `${JSON.stringify([...seen].sort(), null, 1)}
22872
+ `);
22873
+ }
22770
22874
  #importInput(script, skill) {
22771
22875
  const pack = this.#library.packOf(script.id);
22772
22876
  return {
@@ -22820,7 +22924,7 @@ var AdgScripts = class extends Service {
22820
22924
  clearTimeout(syncing.get(id));
22821
22925
  const timer = setTimeout(() => {
22822
22926
  syncing.delete(id);
22823
- void this.ready.then(() => this.integrations.syncSkills(id)).then((names) => {
22927
+ void this.ready.then(async () => [...await this.integrations.syncSkills(id), ...await this.integrations.autoImportSkills(id)]).then((names) => {
22824
22928
  if (names.length > 0)
22825
22929
  ctx.get("adgGateway")?.broadcast("skills/changed", {});
22826
22930
  }, (error) => log.warn(`skills of ${id} not synced: ${error instanceof Error ? error.message : String(error)}`));
@@ -22858,7 +22962,7 @@ var AdgScripts = class extends Service {
22858
22962
  log: { info: (message2) => log.info(message2), warn: (message2) => log.warn(message2) }
22859
22963
  });
22860
22964
  const library = this.library;
22861
- this.integrations = new ScriptIntegrations(library, new ScriptMcp({ dataDir: spec.dataDir, log: { info: (message2) => log.info(message2), warn: (message2) => log.warn(message2) } }), () => ctx.get("adgGateway"), { info: (message2) => log.info(message2), warn: (message2) => log.warn(message2) });
22965
+ this.integrations = new ScriptIntegrations(library, new ScriptMcp({ dataDir: spec.dataDir, log: { info: (message2) => log.info(message2), warn: (message2) => log.warn(message2) } }), () => ctx.get("adgGateway"), { info: (message2) => log.info(message2), warn: (message2) => log.warn(message2) }, { seenFile: join8(spec.dataDir, "script-skills.json") });
22862
22966
  const integrations = this.integrations;
22863
22967
  ctx.effect(() => () => void integrations.mcp.dispose(), "adg-scripts MCP connections");
22864
22968
  this.ready = library.start();
@@ -22905,6 +23009,15 @@ var AdgScripts = class extends Service {
22905
23009
  const summaries = scriptSummaries(ctx, library, { warn: (message2) => log.warn(message2) });
22906
23010
  ctx.inject(["adgGateway"], (scoped) => {
22907
23011
  scoped.effect(() => scoped.adgGateway.role(SCRIPT_ROLE), "adg-script-registry role");
23012
+ void this.ready.then(async () => {
23013
+ let put = false;
23014
+ for (const script of library.list().scripts) {
23015
+ if (script.dir !== void 0)
23016
+ put = (await integrations.autoImportSkills(script.id).catch(() => [])).length > 0 || put;
23017
+ }
23018
+ if (put)
23019
+ scoped.adgGateway.broadcast("skills/changed", {});
23020
+ });
22908
23021
  scoped.adgGateway.skillScope.resolveScripts((id) => {
22909
23022
  let pack;
22910
23023
  try {
@@ -22957,4 +23070,4 @@ export {
22957
23070
  AdgScripts,
22958
23071
  lib_default
22959
23072
  };
22960
- /*! For license information please see chunk-AJMAUHPI.js.LEGAL.txt */
23073
+ /*! For license information please see chunk-HRP7ALS6.js.LEGAL.txt */