dsh-multigameassistant 2.2.3 → 2.3.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.
package/lib/gateway.js CHANGED
@@ -23,10 +23,10 @@ import {
23
23
  pluginVersion,
24
24
  streamFacts,
25
25
  userSkills
26
- } from "./chunk-6NJSSOB6.js";
27
- import "./chunk-KMVQK5CI.js";
26
+ } from "./chunk-VBWSM7LF.js";
27
+ import "./chunk-Y3ZZBBLV.js";
28
28
  import "./chunk-RESS7WVY.js";
29
- import "./chunk-LXHF6AKU.js";
29
+ import "./chunk-7EFZ5KR6.js";
30
30
  import "./chunk-6DSSLS7I.js";
31
31
  import "./chunk-2UFLGPDY.js";
32
32
  export {
package/lib/guard.js CHANGED
@@ -1,49 +1,104 @@
1
1
  import { createRequire as __adgCreateRequire } from 'node:module'; import { dirname as __adgDirname } from 'node:path'; import { fileURLToPath as __adgFileURLToPath } from 'node:url'; const require = __adgCreateRequire(import.meta.url); const __filename = __adgFileURLToPath(import.meta.url); const __dirname = __adgDirname(__filename);
2
2
  import {
3
3
  GUARD_CAPABILITY
4
- } from "./chunk-LXHF6AKU.js";
4
+ } from "./chunk-7EFZ5KR6.js";
5
5
  import "./chunk-6DSSLS7I.js";
6
6
  import "./chunk-2UFLGPDY.js";
7
7
 
8
8
  // packages/guard/lib/index.js
9
9
  import { Service } from "@deepseek-ai/cordis";
10
+ import { existsSync } from "node:fs";
11
+ import { basename, dirname, isAbsolute as isAbsolute2, join, relative as relative2, resolve as resolve2 } from "node:path";
10
12
  import { fileURLToPath } from "node:url";
11
13
 
12
14
  // packages/guard/lib/policy.js
13
15
  import { isAbsolute, relative, resolve } from "node:path";
14
- var FILE_TOOLS = /* @__PURE__ */ new Set(["write", "edit", "str_replace_based_edit_tool", "apply_patch", "notebook_edit"]);
16
+ var TOOLS = "_tools";
17
+ var APP_FILES = "_app";
18
+ var APP_DATA = "_app_data";
19
+ var APP_SETTINGS = "_app_settings";
20
+ var APP_ENTRIES = /* @__PURE__ */ new Set([APP_FILES, APP_DATA, APP_SETTINGS]);
21
+ var isAppEntry = (scriptId) => APP_ENTRIES.has(scriptId);
22
+ var FILE_TOOLS = /* @__PURE__ */ new Set(["write", "edit", "multi_edit", "str_replace_editor", "str_replace_based_edit_tool", "apply_patch", "notebook_edit"]);
15
23
  var SHELL_TOOLS = /* @__PURE__ */ new Set(["pwsh", "bash", "powershell", "shell", "cmd"]);
16
- var WRITING = /(\bset-content\b|\badd-content\b|\bout-file\b|\bnew-item\b|\bremove-item\b|\bmove-item\b|\bcopy-item\b|\brename-item\b|\bclear-content\b|\bexpand-archive\b|\bcompress-archive\b|\bdel\b|\berase\b|\brd\b|\brmdir\b|\bren\b|\bmove\b|\bcopy\b|\bxcopy\b|\brobocopy\b|\brm\b|\bmv\b|\bcp\b|\btouch\b|\btee\b|\bsed\s+-i\b|\btruncate\b|\bgit\s+(apply|checkout|reset|restore|clean|stash|am|merge|pull)\b|\[io\.file\]::write|\bwritealltext\b|\bwriteallbytes\b|>{1,2})/i;
24
+ var CODE_TOOLS = /* @__PURE__ */ new Set(["run_code"]);
25
+ var AGENT_TOOLS = /* @__PURE__ */ new Set(["subagent"]);
26
+ var WRITING = /(\bset-content\b|\badd-content\b|\bout-file\b|\bnew-item\b|\bremove-item\b|\bmove-item\b|\bcopy-item\b|\brename-item\b|\bclear-content\b|\bexpand-archive\b|\bcompress-archive\b|\bdel\b|\berase\b|\brd\b|\brmdir\b|\bren\b|\bmove\b|\bcopy\b|\bxcopy\b|\brobocopy\b|\brm\b|\bmv\b|\bcp\b|\btouch\b|\btee\b|\bsed\s+-i\b|\btruncate\b|\bgit\b[^;&|\n]*?\s(apply|checkout|reset|restore|clean|stash|am|merge|pull|switch|rebase|cherry-pick|revert|commit)\b|\b(pnpm|npm|yarn|npx|pip3?|uv|poetry|tsc|vite|esbuild|cargo|msbuild|dotnet)\b|\[io\.file\]::write|\bwritealltext\b|\bwriteallbytes\b|>{1,2})/i;
27
+ var CODE_WRITING = /\b(writeFile|appendFile|rm|rmdir|unlink|rename|mkdir|mkdtemp|copyFile|cp|truncate|symlink|chmod|utimes|createWriteStream|execSync|execFile|execFileSync|spawn|spawnSync|fork)(Sync)?\s*\(|\bopen(Sync)?\s*\([^)]*['"`][wa]|\bchild_process\b[\s\S]*\bexec\s*\(/;
28
+ function guardDirs(state) {
29
+ const protectedDirs = [];
30
+ const opened = new Set(state.grants.map((g) => g.scriptId));
31
+ if (!state.fullAccess) {
32
+ for (const script of state.scripts)
33
+ if (!opened.has(script.id))
34
+ for (const dir of script.dirs)
35
+ protectedDirs.push({ scriptId: script.id, dir });
36
+ for (const dir of state.toolsDirs)
37
+ protectedDirs.push({ scriptId: TOOLS, dir });
38
+ }
39
+ protectedDirs.push(...state.app);
40
+ const workspace = state.workspace;
41
+ const allowed = [
42
+ ...workspace !== void 0 && owner(resolve(workspace), state.app) !== void 0 ? [workspace] : [],
43
+ ...state.fullAccess ? [] : state.grants.flatMap((g) => g.dirs)
44
+ ];
45
+ return { protectedDirs, allowed };
46
+ }
17
47
  function judgeCall(call, protectedDirs, allowedDirs = []) {
18
48
  const args = call.args ?? {};
19
49
  const allowed = allowedDirs.map((dir) => ({ scriptId: "", dir }));
50
+ const inside = (path) => owner(path, allowed) === void 0 ? owner(path, protectedDirs) : void 0;
20
51
  if (FILE_TOOLS.has(call.toolName)) {
21
- const path = [args["file_path"], args["path"]].find((v) => typeof v === "string");
22
- if (path === void 0)
23
- return void 0;
24
- const absolute = resolvePath(path, call.cwd);
25
- if (owner(absolute, allowed) !== void 0)
52
+ if (call.toolName === "str_replace_editor" && args["command"] === "view")
26
53
  return void 0;
27
- const hit = owner(absolute, protectedDirs);
28
- return hit === void 0 ? void 0 : { blocked: true, scriptId: hit.scriptId, target: path };
54
+ for (const path of filePaths(call.toolName, args)) {
55
+ const hit = inside(resolvePath(path, call.cwd));
56
+ if (hit !== void 0)
57
+ return { blocked: true, scriptId: hit.scriptId, target: path };
58
+ }
59
+ return void 0;
29
60
  }
30
61
  if (SHELL_TOOLS.has(call.toolName)) {
31
62
  const command = typeof args["command"] === "string" ? args["command"] : "";
32
63
  if (!WRITING.test(stripReadonlyRedirects(command)))
33
64
  return void 0;
34
- const workdir = typeof args["workdir"] === "string" ? resolvePath(args["workdir"], call.cwd) : void 0;
35
- if (workdir !== void 0 && owner(workdir, allowed) === void 0) {
36
- const inWorkdir = owner(workdir, protectedDirs);
37
- if (inWorkdir !== void 0)
38
- return { blocked: true, scriptId: inWorkdir.scriptId, target: workdir };
39
- }
40
- let text = normalize(command);
41
- for (const dir of allowedDirs)
42
- text = text.split(normalize(dir)).join("");
43
- for (const entry of protectedDirs) {
44
- if (text.includes(normalize(entry.dir)))
45
- return { blocked: true, scriptId: entry.scriptId, target: entry.dir };
46
- }
65
+ const workdir = typeof args["workdir"] === "string" ? resolvePath(args["workdir"], call.cwd) : call.cwd === void 0 ? void 0 : resolve(call.cwd);
66
+ const here = workdir === void 0 ? void 0 : inside(workdir);
67
+ if (here !== void 0)
68
+ return { blocked: true, scriptId: here.scriptId, target: workdir };
69
+ return named(command, protectedDirs, allowedDirs);
70
+ }
71
+ if (CODE_TOOLS.has(call.toolName)) {
72
+ const code = typeof args["code"] === "string" ? args["code"] : "";
73
+ if (!CODE_WRITING.test(code))
74
+ return void 0;
75
+ const here = call.cwd === void 0 ? void 0 : inside(resolve(call.cwd));
76
+ if (here !== void 0)
77
+ return { blocked: true, scriptId: here.scriptId, target: call.cwd };
78
+ return named(code, protectedDirs, allowedDirs);
79
+ }
80
+ if (AGENT_TOOLS.has(call.toolName) && typeof args["cwd"] === "string") {
81
+ const dir = resolvePath(args["cwd"], call.cwd);
82
+ const hit = inside(dir);
83
+ if (hit !== void 0 && isAppEntry(hit.scriptId))
84
+ return { blocked: true, scriptId: hit.scriptId, target: args["cwd"] };
85
+ }
86
+ return void 0;
87
+ }
88
+ function filePaths(toolName, args) {
89
+ if (toolName === "apply_patch") {
90
+ const patch = [args["input"], args["patch"]].find((v) => typeof v === "string") ?? "";
91
+ return [...patch.matchAll(/^\*\*\* (?:(?:Add|Update|Delete) File|Move to): *(.+?) *$/gm)].map((m) => m[1]);
92
+ }
93
+ return [args["file_path"], args["path"], args["notebook_path"]].filter((v) => typeof v === "string");
94
+ }
95
+ function named(text, protectedDirs, allowedDirs) {
96
+ let normalized = normalize(text);
97
+ for (const dir of allowedDirs)
98
+ normalized = normalized.split(normalize(dir)).join("");
99
+ for (const entry of protectedDirs) {
100
+ if (normalized.includes(normalize(entry.dir)))
101
+ return { blocked: true, scriptId: entry.scriptId, target: entry.dir };
47
102
  }
48
103
  return void 0;
49
104
  }
@@ -62,14 +117,25 @@ function resolvePath(path, cwd) {
62
117
  function normalize(text) {
63
118
  return text.replace(/\\/g, "/").replace(/\/+/g, "/").replace(/\/$/, "").toLowerCase();
64
119
  }
65
- var APP_FILES = "_app";
66
120
  function denialReason(verdict, scriptName) {
121
+ const always = "\u8FD9\u4E00\u6761\u4E0D\u80FD\u7531 agent \u89E3\u9664\uFF0C\u5B8C\u5168\u8BBF\u95EE\u4E5F\u4E00\u6837\u3002";
67
122
  if (verdict.scriptId === APP_FILES) {
68
123
  return [
69
- `\u5DF2\u62E6\u622A\uFF1A\u8FD9\u662F MultiGameAssistant \u81EA\u5E26\u7684\u6587\u4EF6\uFF08\u5185\u7F6E\u6280\u80FD\u3001\u811A\u672C\u5305\u3001\u6E38\u620F\u5305\uFF09\uFF0C\u4E0D\u80FD\u4FEE\u6539\uFF08${verdict.target}\uFF09\u3002`,
70
- "\u8F6F\u4EF6\u66F4\u65B0\u65F6\u4F1A\u6574\u4F53\u66FF\u6362\u5B83\u4EEC\u3002\u8981\u8865\u5145\u505A\u6CD5\uFF0C\u7528 skill_save \u53E6\u5B58\u4E00\u4E2A\u81EA\u5DF1\u7684\u6280\u80FD\uFF08\u6280\u80FD\u5E93\u4E0B\u8F7D\u7684\u6280\u80FD\u4E5F\u4E00\u6837\uFF1A\u5B83\u8DDF\u7740\u6280\u80FD\u5E93\u66F4\u65B0\uFF0C\u5728\u672C\u5730\u6539\u4E86\u4F1A\u88AB\u65B0\u7248\u672C\u6362\u6389\uFF09\u3002"
124
+ `\u5DF2\u62E6\u622A\uFF1A\u8FD9\u662F MultiGameAssistant \u81EA\u5DF1\u7684\u7A0B\u5E8F\u6587\u4EF6\uFF08\u6E90\u7801\u3001\u5B89\u88C5\u76EE\u5F55\u3001\u5185\u7F6E\u6280\u80FD\u548C\u5305\uFF09\uFF0Cagent \u4E0D\u80FD\u4FEE\u6539\uFF0C\u4E5F\u4E0D\u8981\u5728\u8FD9\u91CC\u5F00\u5B50 agent \u53BB\u6539\uFF08${verdict.target}\uFF09\u3002`,
125
+ "\u53D1\u73B0\u8F6F\u4EF6\u672C\u8EAB\u7684\u95EE\u9898\u6216\u7F3A\u7684\u529F\u80FD\uFF0C\u544A\u8BC9\u7528\u6237\u73B0\u8C61\u548C\u4F60\u7684\u5224\u65AD\uFF0C\u7531\u7528\u6237\u51B3\u5B9A\u600E\u4E48\u6539\u3002\u8981\u8865\u5145\u505A\u6CD5\uFF0C\u7528 skill_save \u53E6\u5B58\u4E00\u4E2A\u81EA\u5DF1\u7684\u6280\u80FD\u3002",
126
+ always
71
127
  ].join("");
72
128
  }
129
+ if (verdict.scriptId === APP_DATA) {
130
+ return [
131
+ `\u5DF2\u62E6\u622A\uFF1A\u8FD9\u662F MultiGameAssistant \u7684\u6570\u636E\u548C\u8BBE\u7F6E\uFF0C\u4E0D\u80FD\u76F4\u63A5\u6539\u6587\u4EF6\uFF08${verdict.target}\uFF09\u3002`,
132
+ "\u7528\u5BF9\u5E94\u7684\u5DE5\u5177\uFF1A\u811A\u672C\u5305\u7528 pack_propose\uFF0C\u6280\u80FD\u7528 skill_save\uFF0C\u65E5\u5E38\u5468\u5E38\u7528 game_routine\uFF0C\u811A\u672C\u8BBE\u7F6E\u7528 script_config_set\uFF1B\u6743\u9650\u3001\u6A21\u578B\u8FD9\u4E9B\u8BBE\u7F6E\u8BF7\u7528\u6237\u5728\u8F6F\u4EF6\u91CC\u6539\u3002",
133
+ always
134
+ ].join("");
135
+ }
136
+ if (verdict.scriptId === APP_SETTINGS) {
137
+ return `\u5DF2\u62E6\u622A\uFF1A\u8FD9\u662F\u8F6F\u4EF6\u8FD0\u884C\u7528\u7684 dsh \u914D\u7F6E\uFF08\u63D2\u4EF6\u3001\u6743\u9650\u3001\u9884\u8BBE\uFF09\uFF0Cagent \u4E0D\u80FD\u4FEE\u6539\uFF08${verdict.target}\uFF09\u3002\u9700\u8981\u6539\u65F6\u544A\u8BC9\u7528\u6237\u3002${always}`;
138
+ }
73
139
  return [
74
140
  `\u5DF2\u62E6\u622A\uFF1A${scriptName} \u7684\u811A\u672C\u76EE\u5F55\u53D7\u4FDD\u62A4\uFF08${verdict.target}\uFF09\u3002`,
75
141
  "\u6CA1\u6709\u7528\u6237\u7684\u660E\u786E\u6388\u6743\u65F6\uFF0C\u4E0D\u80FD\u4FEE\u6539\u811A\u672C\u81EA\u5DF1\u7684\u6587\u4EF6\u3002",
@@ -80,34 +146,75 @@ function denialReason(verdict, scriptName) {
80
146
 
81
147
  // packages/guard/lib/index.js
82
148
  var APP_FILES_DIR = fileURLToPath(new URL("../../", import.meta.url));
83
- var TOOLS = "_tools";
149
+ function appRoot(moduleDir, exists = existsSync) {
150
+ let pkg = resolve2(moduleDir);
151
+ while (!exists(join(pkg, "package.json"))) {
152
+ const up = dirname(pkg);
153
+ if (up === pkg)
154
+ return resolve2(moduleDir);
155
+ pkg = up;
156
+ }
157
+ const parent = dirname(pkg);
158
+ if (basename(parent) === "packages" && exists(join(dirname(parent), "pnpm-workspace.yaml")))
159
+ return dirname(parent);
160
+ if (basename(parent) === "@adg" && basename(dirname(parent)) === "node_modules") {
161
+ const app = dirname(dirname(parent));
162
+ return basename(app).toLowerCase() === "app" && basename(dirname(app)).toLowerCase() === "resources" ? dirname(dirname(app)) : app;
163
+ }
164
+ return pkg;
165
+ }
166
+ var APP_ROOT = appRoot(fileURLToPath(new URL(".", import.meta.url)));
167
+ var within = (path, dir) => {
168
+ const rel = relative2(resolve2(dir), resolve2(path));
169
+ return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
170
+ };
84
171
  var AdgGuard = class extends Service {
85
172
  static inject = ["adgScripts"];
86
173
  grantMap = /* @__PURE__ */ new Map();
87
174
  blocked = 0;
88
- constructor(ctx) {
175
+ constructor(ctx, config = {}) {
89
176
  super(ctx, "adgGuard");
90
177
  const log = ctx.logger("adg-guard");
91
178
  const scripts = ctx.adgScripts;
179
+ const appEdits = process.env["ADG_GUARD_ALLOW_APP_EDITS"] === "1";
180
+ if (appEdits)
181
+ log.warn("ADG_GUARD_ALLOW_APP_EDITS=1: agents may change the app's own program, data and settings");
182
+ const appDirs = () => {
183
+ if (appEdits)
184
+ return [];
185
+ const dirs2 = [{ scriptId: APP_DATA, dir: scripts.library.dataDir }];
186
+ if (ctx.get("adgGateway")?.shared !== true)
187
+ for (const dir of config.settingsDirs ?? [])
188
+ dirs2.push({ scriptId: APP_SETTINGS, dir });
189
+ dirs2.push({ scriptId: APP_FILES, dir: APP_ROOT });
190
+ return dirs2;
191
+ };
92
192
  const dirs = () => {
93
- const open = new Map(this.grants().map((g) => [g.scriptId, g]));
94
- const protectedDirs = [];
95
- for (const script of scripts.library.list().scripts) {
96
- if (open.has(script.id))
97
- continue;
98
- for (const version of script.versions)
99
- protectedDirs.push({ scriptId: script.id, dir: version.dir });
193
+ const gateway = ctx.get("adgGateway");
194
+ return guardDirs({
195
+ fullAccess: gateway?.fullAccess() === true,
196
+ scripts: scripts.library.list().scripts.map((s) => ({ id: s.id, dirs: s.versions.map((v) => v.dir) })),
197
+ toolsDirs: [scripts.library.toolsDir, ...scripts.library.formerToolsDirs],
198
+ grants: this.grants(),
199
+ app: appDirs(),
200
+ workspace: gateway?.workspaceDir()
201
+ });
202
+ };
203
+ const cwdOf = (agent) => {
204
+ if (agent === void 0)
205
+ return void 0;
206
+ try {
207
+ const service = ctx.get("workingDirectory");
208
+ return service?.get(agent.session);
209
+ } catch {
210
+ return void 0;
100
211
  }
101
- for (const dir of [scripts.library.toolsDir, ...scripts.library.formerToolsDirs])
102
- protectedDirs.push({ scriptId: TOOLS, dir });
103
- protectedDirs.push({ scriptId: APP_FILES, dir: APP_FILES_DIR });
104
- return { protectedDirs, allowed: [...open.values()].flatMap((g) => g.dirs) };
105
212
  };
106
213
  ctx.on("tools/pre-execute", async (exec, next) => {
107
- if (ctx.get("adgGateway")?.fullAccess() === true)
108
- return next();
109
214
  const { protectedDirs, allowed } = dirs();
110
- const verdict = judgeCall({ toolName: exec.name, args: exec.arguments }, protectedDirs, allowed);
215
+ if (protectedDirs.length === 0)
216
+ return next();
217
+ const verdict = judgeCall({ toolName: exec.name, args: exec.arguments, cwd: cwdOf(exec.agent) }, protectedDirs, allowed);
111
218
  if (verdict === void 0)
112
219
  return next();
113
220
  this.blocked += 1;
@@ -132,6 +239,9 @@ var AdgGuard = class extends Service {
132
239
  "guard/grant": (params) => {
133
240
  const p = params;
134
241
  const script = scripts.library.get(p.scriptId);
242
+ const app = appDirs().find((entry) => script.versions.some((v) => within(v.dir, entry.dir)));
243
+ if (app !== void 0)
244
+ throw new Error(`${script.name} \u5728\u8F6F\u4EF6\u81EA\u5DF1\u7684\u6587\u4EF6\u5939\u91CC\uFF08${app.dir}\uFF09\uFF0C\u4E0D\u80FD\u5F00\u542F\u4FEE\u6539\u6388\u6743`);
135
245
  const now = Date.now();
136
246
  const grant = { scriptId: p.scriptId, dir: script.dir ?? "", grantedAt: now, expiresAt: now + p.minutes * 6e4, dirs: script.versions.map((v) => v.dir) };
137
247
  this.grantMap.set(p.scriptId, grant);
@@ -160,10 +270,17 @@ var AdgGuard = class extends Service {
160
270
  };
161
271
  var lib_default = AdgGuard;
162
272
  export {
273
+ APP_DATA,
163
274
  APP_FILES,
164
275
  APP_FILES_DIR,
276
+ APP_ROOT,
277
+ APP_SETTINGS,
165
278
  AdgGuard,
279
+ TOOLS,
280
+ appRoot,
166
281
  lib_default as default,
167
282
  denialReason,
283
+ guardDirs,
284
+ isAppEntry,
168
285
  judgeCall
169
286
  };
package/lib/intervene.js CHANGED
@@ -2,16 +2,16 @@ import { createRequire as __adgCreateRequire } from 'node:module'; import { dirn
2
2
  import {
3
3
  finalText,
4
4
  sessionConversations
5
- } from "./chunk-A6YQRWHZ.js";
6
- import "./chunk-6NJSSOB6.js";
7
- import "./chunk-KMVQK5CI.js";
5
+ } from "./chunk-VG32XPZH.js";
6
+ import "./chunk-VBWSM7LF.js";
7
+ import "./chunk-Y3ZZBBLV.js";
8
8
  import {
9
9
  writeFileAtomic
10
10
  } from "./chunk-RESS7WVY.js";
11
11
  import {
12
12
  INTERVENE_CAPABILITY,
13
13
  UPDATE_RULE
14
- } from "./chunk-LXHF6AKU.js";
14
+ } from "./chunk-7EFZ5KR6.js";
15
15
  import {
16
16
  external_exports
17
17
  } from "./chunk-6DSSLS7I.js";
@@ -38,8 +38,8 @@ import {
38
38
  summaryTarget,
39
39
  summaryText,
40
40
  taskOver
41
- } from "./chunk-KMVQK5CI.js";
42
- import "./chunk-LXHF6AKU.js";
41
+ } from "./chunk-Y3ZZBBLV.js";
42
+ import "./chunk-7EFZ5KR6.js";
43
43
  import "./chunk-6DSSLS7I.js";
44
44
  import "./chunk-2UFLGPDY.js";
45
45
  export {
package/lib/monitor.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { createRequire as __adgCreateRequire } from 'node:module'; import { dirname as __adgDirname } from 'node:path'; import { fileURLToPath as __adgFileURLToPath } from 'node:url'; const require = __adgCreateRequire(import.meta.url); const __filename = __adgFileURLToPath(import.meta.url); const __dirname = __adgDirname(__filename);
2
2
  import {
3
3
  parseDuration
4
- } from "./chunk-TELJUUBZ.js";
5
- import "./chunk-RGEGJH6R.js";
4
+ } from "./chunk-X5YYRNYA.js";
5
+ import "./chunk-TXW3NMBH.js";
6
6
  import {
7
7
  writeFileAtomic
8
8
  } from "./chunk-RESS7WVY.js";
@@ -10,7 +10,7 @@ import {
10
10
  Incident,
11
11
  MONITOR_CAPABILITY,
12
12
  MonitorSettings
13
- } from "./chunk-LXHF6AKU.js";
13
+ } from "./chunk-7EFZ5KR6.js";
14
14
  import {
15
15
  external_exports
16
16
  } from "./chunk-6DSSLS7I.js";
package/lib/notify.js CHANGED
@@ -16,11 +16,11 @@ import {
16
16
  replyPlain,
17
17
  sessionConversations,
18
18
  textReply
19
- } from "./chunk-A6YQRWHZ.js";
20
- import "./chunk-6NJSSOB6.js";
21
- import "./chunk-KMVQK5CI.js";
19
+ } from "./chunk-VG32XPZH.js";
20
+ import "./chunk-VBWSM7LF.js";
21
+ import "./chunk-Y3ZZBBLV.js";
22
22
  import "./chunk-RESS7WVY.js";
23
- import "./chunk-LXHF6AKU.js";
23
+ import "./chunk-7EFZ5KR6.js";
24
24
  import "./chunk-6DSSLS7I.js";
25
25
  import "./chunk-2UFLGPDY.js";
26
26
  export {
@@ -4,18 +4,18 @@ import {
4
4
  PARAMS_SCHEMA,
5
5
  parseDuration,
6
6
  taskParams
7
- } from "./chunk-TELJUUBZ.js";
7
+ } from "./chunk-X5YYRNYA.js";
8
8
  import {
9
9
  TaskInputError,
10
10
  renderTask
11
- } from "./chunk-RGEGJH6R.js";
11
+ } from "./chunk-TXW3NMBH.js";
12
12
  import {
13
13
  MAIN,
14
14
  finalText,
15
15
  sessionConversations
16
- } from "./chunk-A6YQRWHZ.js";
17
- import "./chunk-6NJSSOB6.js";
18
- import "./chunk-KMVQK5CI.js";
16
+ } from "./chunk-VG32XPZH.js";
17
+ import "./chunk-VBWSM7LF.js";
18
+ import "./chunk-Y3ZZBBLV.js";
19
19
  import {
20
20
  writeFileAtomic
21
21
  } from "./chunk-RESS7WVY.js";
@@ -33,7 +33,7 @@ import {
33
33
  isMarker,
34
34
  taskMessage,
35
35
  withStartEnd
36
- } from "./chunk-LXHF6AKU.js";
36
+ } from "./chunk-7EFZ5KR6.js";
37
37
  import {
38
38
  external_exports
39
39
  } from "./chunk-6DSSLS7I.js";
package/lib/qqbot.js CHANGED
@@ -4,9 +4,9 @@ import {
4
4
  questionText,
5
5
  replyMarkdown,
6
6
  replyPlain
7
- } from "./chunk-A6YQRWHZ.js";
8
- import "./chunk-6NJSSOB6.js";
9
- import "./chunk-KMVQK5CI.js";
7
+ } from "./chunk-VG32XPZH.js";
8
+ import "./chunk-VBWSM7LF.js";
9
+ import "./chunk-Y3ZZBBLV.js";
10
10
  import {
11
11
  writeFileAtomic
12
12
  } from "./chunk-RESS7WVY.js";
@@ -15,7 +15,7 @@ import {
15
15
  QQBOT_SECRET_REF,
16
16
  QQPending,
17
17
  QQSettings
18
- } from "./chunk-LXHF6AKU.js";
18
+ } from "./chunk-7EFZ5KR6.js";
19
19
  import {
20
20
  external_exports
21
21
  } from "./chunk-6DSSLS7I.js";
package/lib/runner.js CHANGED
@@ -25,9 +25,9 @@ import {
25
25
  setIn,
26
26
  taskParams,
27
27
  tidyRuns
28
- } from "./chunk-TELJUUBZ.js";
29
- import "./chunk-RGEGJH6R.js";
30
- import "./chunk-LXHF6AKU.js";
28
+ } from "./chunk-X5YYRNYA.js";
29
+ import "./chunk-TXW3NMBH.js";
30
+ import "./chunk-7EFZ5KR6.js";
31
31
  import "./chunk-6DSSLS7I.js";
32
32
  import "./chunk-2UFLGPDY.js";
33
33
  export {
package/lib/scheduler.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __adgCreateRequire } from 'node:module'; import { dirname as __adgDirname } from 'node:path'; import { fileURLToPath as __adgFileURLToPath } from 'node:url'; const require = __adgCreateRequire(import.meta.url); const __filename = __adgFileURLToPath(import.meta.url); const __dirname = __adgDirname(__filename);
2
2
  import {
3
3
  SCHEDULE_CAPABILITY
4
- } from "./chunk-LXHF6AKU.js";
4
+ } from "./chunk-7EFZ5KR6.js";
5
5
  import {
6
6
  external_exports
7
7
  } from "./chunk-6DSSLS7I.js";
@@ -17,14 +17,14 @@ import {
17
17
  packForRepo,
18
18
  parseMcpConfig,
19
19
  readSkills
20
- } from "./chunk-YTIR5JW4.js";
20
+ } from "./chunk-AJMAUHPI.js";
21
21
  import "./chunk-B4UT4NYH.js";
22
- import "./chunk-RGEGJH6R.js";
23
- import "./chunk-A6YQRWHZ.js";
24
- import "./chunk-6NJSSOB6.js";
25
- import "./chunk-KMVQK5CI.js";
22
+ import "./chunk-TXW3NMBH.js";
23
+ import "./chunk-VG32XPZH.js";
24
+ import "./chunk-VBWSM7LF.js";
25
+ import "./chunk-Y3ZZBBLV.js";
26
26
  import "./chunk-RESS7WVY.js";
27
- import "./chunk-LXHF6AKU.js";
27
+ import "./chunk-7EFZ5KR6.js";
28
28
  import "./chunk-6DSSLS7I.js";
29
29
  import "./chunk-2UFLGPDY.js";
30
30
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-multigameassistant",
3
- "version": "2.2.3",
3
+ "version": "2.3.0",
4
4
  "description": "多游戏助手 MultiGameAssistant 的 dsh 插件版:让 agent 管好各个游戏的日常脚本(安装、编排定时流水线、看护运行、查活动),界面在自己的网页里。",
5
5
  "keywords": [
6
6
  "dsh",
@@ -14,6 +14,18 @@ description: 游戏活动信息:查有什么活动、还剩几天、商店换
14
14
  用户想看更多游戏(原神、绝区零、鸣潮等没有游戏包的):告诉他在「游戏 → 全部活动 → 更多游戏」里勾上,活动来自 SRA 公共 API,每天自动刷新。
15
15
  3. 游戏包里没有可直接读的数据站(`game_list` 里 auto 都是 false):按技能 web-reading 的顺序查(先公开 API,如 SRA 公共 API,再 Wiki 接口,最后官网公告页),找到活动名和起止时间后 `game_record`(source=site,带上 `url`,有配图把图片地址写进 `cover`)。
16
16
 
17
+ ## 卡池、日常和周常
18
+
19
+ - `game_list` 里每个游戏带着 `pools`(卡池)。明日方舟、原神、终末地的卡池插件每天自己读;其他游戏(星穹铁道、绝区零、鸣潮等)没有能直接读的卡池数据:读官方公告、游戏内公告时看到卡池(祈愿、跃迁、调频、唤取、寻访),用 `game_pool` 记下名称、UP 的角色或武器、起止时间(游戏服务器时间)。
20
+ - 游戏页的「日常 · 周常」由游戏包和脚本包的 routines 列出,脚本日志或任务成功时自动勾上,到游戏的每日 / 每周重置时间清空;用户也可以自己勾、自己加。混沌回忆、卫戍协议这类周期玩法列在「活动日程」的「周期玩法」里,做完一期就是那个活动 `finished`。
21
+ - 看日常周常用 `game_routine`(action=list):每一项这一期做没做完、谁勾的(脚本日志 / 脚本任务成功 / agent 记的 / 用户自己勾的)、靠哪条日志或哪个任务自动勾、什么时候重置。list 之前插件已经把这一期早些时候的运行记录读过一遍,脚本包后来才加的 routines 也会补上,**不用**为此重跑脚本,也不用自己去勾。
22
+ - 用户问「日常周常为什么没显示完成」:先 `game_routine` list,对没勾上的一项看它的 auto:
23
+ - 「没有:只能手动勾」→ 脚本包没写这一项的 routines:交给「脚本」(agent_delegate)在脚本包里补,log 用运行日志里的原文;
24
+ - 有日志规则却没勾 → `script_run_log` 在这一期的运行里搜那段原文:搜不到说明日志里的写法不一样(交给「脚本」改 log)或者这一项确实没做(例如剿灭被跳过、实训失败);
25
+ - 结论用一两句话告诉用户:哪几项已经自动勾上、哪几项缺规则正在补、哪几项今天确实没做。
26
+ - 只有亲眼看到完成证据(运行日志原文、游戏画面上的完成文字)才用 `game_routine` action=set 勾,evidence 写原文和出处;页面会显示成「agent 记的」。**不要**用浏览器点游戏页的勾选框,也不要自己调接口——那样会被记成用户勾的。跳过、失败、只开始了的不算完成。
27
+ - 日报里每个游戏先写日常周常还差哪几项、什么时候重置,插件发日报前也会先读一遍运行记录。
28
+
17
29
  ## 公告和版本更新(单机游戏主要看这个)
18
30
 
19
31
  不是限时活动的消息记在游戏的「公告」里:版本更新、补丁说明、长期有效的公告、其他资讯。`game_activities` 每个游戏带着最近的 `notices`(`single_player` 为 true 的是单机游戏)。
@@ -14,6 +14,7 @@ description: 分析脚本库里的一个游戏自动化脚本(包括没见过
14
14
 
15
15
  - **先文档,后代码**:项目作者写的文档(README、使用说明、帮助、Wiki、文档站、更新日志)最权威,先把它们读完;代码和配置用来核对、补全文档没写的细节;只有确实找不到任何文档时,才直接从代码分析。
16
16
  - **只读**:分析期间不修改脚本目录里的任何文件(守卫也会拦截)。要看配置用 `script_config_get` 或读文件工具。
17
+ - **脚本包只用 `pack_propose` 改**:不要用写文件、shell 或 run_code 直接改软件数据目录里的 `adg.script.yaml`——软件不会重新读它,校验和历史版本也都跳过了。
17
18
  - **不猜**:每一条启动方式、任务、配置键、日志规则都要有依据(文档、`--help` 输出、interface.json、配置文件内容、日志样本、源码)。没有依据的写进 SKILL.md 的「待确认」,不要写进 manifest。文档和代码对不上时以代码(实际行为)为准,并在「待确认」里写明。
18
19
  - 成败判定取自脚本自己的输出(退出码、日志),不要自造信号。
19
20
  - 先 `skill_focus`(scripts 写这个脚本的 id):它已有的技能才看得到,也不会混进别的脚本的技能。
@@ -33,9 +34,13 @@ description: 分析脚本库里的一个游戏自动化脚本(包括没见过
33
34
  - `cli`:有命令行参数。用 `script_help` 看 `--help` / `-h` / `-l` 输出,把每个子命令或任务名写成一个 task。
34
35
  - `gui-config`:GUI 程序,靠配置文件决定做什么、能设置「启动后直接运行」。写 `patches` 改配置,`success: done-log` + 完成日志规则,`launch.stopAfterDone: true`(GUI 完成后不自己退出时)。
35
36
  - `generic-process`:只能启动程序,看退出码和日志。
37
+ - 只有 `.bat` / `.cmd` / `.ps1` 启动器(常见于 Python 项目的「启动.bat」):先读它的内容,`launch.exe` 优先写它调用的真正程序、`launch.args` 写入口文件(例如 `exe: runtime\python.exe`、`args: [main.py]`),任务参数接在后面;看不出来才直接写启动器(软件会经 cmd.exe 运行它,参数里不能有双引号)。启动器不认 `--help` 时别用它跑 `script_help`,它会直接开始跑任务。
36
38
  - `visual`:以上都不行(需要截图点击,M5 支持),先写清楚现状。
37
39
  6. 找日志:报告里的 `logFiles` 有样本;没有就根据文档写,标注「待运行后校准」。完成标志写 `level: done`,错误写 `level: error`。
38
40
  7. 判断资源:前台操作 PC 游戏 = `desktop`;模拟器 = `adb`(会自动启动模拟器,ADB 地址用 `{adb}` 占位符);不占用 = `none`。同一游戏账号写 `account`。
41
+ - 有 `adb` 任务就要写 `game.android.package`(平台靠它启动、关闭游戏,游戏页用它的图标):用 `emulator_apps`(`name` 写游戏名,知道或猜到的包名写进 `packages`)查模拟器里真正装的应用,不要凭记忆写。写官服的包名(只装了渠道服时写它本身);脚本自己的配置或文档里有客户端/包名对照表(例如 MAA 的 `packageName`)也要核对。
42
+ - 用户装的不是官服(B服、国际服等):用 `game_path_set` 的 `android_package` 存给这个脚本,脚本包里仍写官服的。
43
+ - `pack_propose` 保存后,模拟器开着时会自己再查一遍:只有一个版本就直接存给这个脚本;结果里的 `android` 和 `next` 会说还缺什么,照着做。
39
44
  8. **MCP 和自带技能**:`script_analyze` 的 `mcp` 不为空时,脚本自带 MCP 服务,按下面「MCP」一节写 manifest 的 `mcp` 和 SKILL.md 的「MCP」一节(缺了 `pack_propose` 会失败);`skills` 不为空时,脚本自带给 agent 的技能,读一读,SKILL.md 里提一句它们讲什么,用户想用时用 `script_skills_import` 放进技能库。
40
45
  9. 写使用说明(下面「使用说明」一节)和 SKILL.md(「SKILL.md」一节)。
41
46
  10. 写好后用 `pack_propose` 保存:`docs` 写读过的文档(出处和从中得到了什么);确实没有文档时用 `no_docs` 说明找过哪些地方。校验失败(包括使用说明的检查)会返回具体位置,修正后再提交。
@@ -108,7 +113,7 @@ recovery: # 出问题时平台自动做的事(每条最
108
113
  - { on: adb-disconnected, do: restart } # do:reconnect-adb | restart | stop
109
114
  game: # 脚本玩的游戏:脚本自己不启动游戏时,平台在运行前启动它
110
115
  name: 明日方舟
111
- android: { package: com.example.game } # 模拟器任务:运行前在模拟器里启动
116
+ android: { package: com.example.game } # 模拟器任务:运行前在模拟器里启动;写官服的包名,拿不准用 emulator_apps 在模拟器里查
112
117
  pc: { process: Game.exe } # PC 任务:进程名(程序位置由用户在界面里设置)
113
118
  selfLaunch: never # 脚本自己会启动游戏时写 always,或写配置条件:
114
119
  # [{ file: config/gui.json, path: [Start, StartGame], equals: 'True' }]
@@ -126,7 +131,27 @@ game: # 脚本玩的游戏:脚本自己不启动游
126
131
  - 脚本自己也会启动模拟器时(例如它有「启动后打开模拟器」),平台已经启动了模拟器,就用 `when: emulator-managed` 的临时修改把它关掉;用户填的是手动 ADB 地址时这条不生效,脚本照常自己启动模拟器。
127
132
  - 脚本会自己启动游戏,就在 `game.selfLaunch` 里写明,平台不再重复启动;平台也会先看游戏是否已经在运行。
128
133
 
129
- 日志规则只写在源码、文档或真实日志里确实出现过的原文;拿不准的错误先写成 `warning`。`recovery` 只给确定安全的情况写(重启任务会从头再跑一遍)。
134
+ 日志规则只写在源码、文档或真实日志里确实出现过的原文;拿不准的错误先写成 `warning`。`recovery` 只给确定安全的情况写(重启任务会从头再跑一遍);脚本自己会重试的警告上不要写 stop / restart。
135
+
136
+ 正则写在 YAML 单引号里,反斜杠只写一个:`'\[咖啡厅\] 完成'`、`'\| ERROR \|'`。写成 `'\\| ERROR \\|'` 会变成「反斜杠、或者空」,匹配每一行;`pack_propose` 会拒绝这种写法。写好后拿日志样本里真实的一行对一下。
137
+
138
+ ### 日常周常(routines)
139
+
140
+ 游戏页的「日常 · 周常」清单按脚本包的 `routines` 自动勾选:脚本日志里出现某一项真正做完的那一行,或某个任务运行成功,就勾上这一期(每日 / 每周重置后清空)。
141
+
142
+ ```yaml
143
+ routines:
144
+ - { id: base, name: 基建换班, period: daily, log: '完成任务: ?基建换班' }
145
+ - { id: annihilation, name: 剿灭作战, period: weekly, log: '本周剿灭已完成' }
146
+ - { id: daily-training, name: 每日实训, period: daily, log: '每日实训已完成', tasks: [daily] }
147
+ - { id: memory-of-chaos, name: 混沌回忆, period: event, events: ['^混沌回忆'], tasks: [forgottenhall] }
148
+ ```
149
+
150
+ - `log` 写运行日志里那一项**做完**时的原文(可以是正则,写成数组表示几种写法都算);开始、跳过不了、失败的行不要写。脚本把好几项放在一个任务里、日志看不出单项时,用 `tasks`(这些任务运行成功就算)。
151
+ - `period`:daily 每天重置,weekly 每周重置,event 是数据站列出的周期活动(`events` 写活动名的正则),每一期做一次。
152
+ - id 用游戏包里已有的(`game_routine` list 能看到),同一项就不会出现两次。
153
+ - 改已有的脚本包时原来的 routines 要保留:`pack_propose` 发现少了会拒绝。脚本包里不认识的字段(例如顶层的 `troubleshooting`)也会被拒绝,常见问题写在 `guide.troubleshooting` 下。
154
+ - 保存后不用重跑脚本:插件会回头读这一期的运行记录补勾。
130
155
 
131
156
  ## MCP(脚本自带 MCP 服务时)
132
157