dsh-multigameassistant 2.2.3 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,13 +2,14 @@ import { createRequire as __adgCreateRequire } from 'node:module'; import { dirn
2
2
  import {
3
3
  globToRegExp,
4
4
  guideView,
5
+ launchCommand,
5
6
  renderTask,
6
7
  require_dist
7
- } from "./chunk-RGEGJH6R.js";
8
+ } from "./chunk-C7X2KJ5C.js";
8
9
  import {
9
10
  RUNS_CAPABILITY,
10
11
  ScriptId
11
- } from "./chunk-LXHF6AKU.js";
12
+ } from "./chunk-34VNH3YS.js";
12
13
  import {
13
14
  external_exports
14
15
  } from "./chunk-6DSSLS7I.js";
@@ -1207,7 +1208,7 @@ import { copyFile as copyFile2, readdir as readdir3, readFile as readFile4, rena
1207
1208
  import { join as join5 } from "node:path";
1208
1209
  import { pipeline } from "node:stream/promises";
1209
1210
  import { promisify } from "node:util";
1210
- import { createGzip, gunzip } from "node:zlib";
1211
+ import { constants as zlib, createGzip, gunzip } from "node:zlib";
1211
1212
  var LOG_FILE = "log.jsonl";
1212
1213
  var PREV_LOG_FILE = "log.prev.jsonl";
1213
1214
  var PACKED_LOG_FILE = "log.jsonl.gz";
@@ -1305,7 +1306,7 @@ async function packLog(dir) {
1305
1306
  return true;
1306
1307
  }
1307
1308
  async function readRunLog(dir) {
1308
- const packed = await readFile4(join5(dir, PACKED_LOG_FILE)).then((bytes) => gunzipAsync(bytes), () => void 0);
1309
+ const packed = await readFile4(join5(dir, PACKED_LOG_FILE)).then((bytes) => gunzipAsync(bytes, { finishFlush: zlib.Z_SYNC_FLUSH }), () => void 0);
1309
1310
  const prev = await readFile4(join5(dir, PREV_LOG_FILE), "utf8").catch(() => void 0);
1310
1311
  const current = await readFile4(join5(dir, LOG_FILE), "utf8").catch(() => void 0);
1311
1312
  if (packed === void 0 && prev === void 0 && current === void 0)
@@ -1510,16 +1511,7 @@ var Runner = class {
1510
1511
  */
1511
1512
  async readLog(runId, query = {}) {
1512
1513
  const dir = join6(this.#options.dataDir, "runs", runId);
1513
- let all = await readRunLog(dir);
1514
- if (all === void 0) {
1515
- const memory = this.#runs.get(runId);
1516
- if (memory !== void 0 && (memory.archived !== true || memory.lines.length > 0))
1517
- all = memory.lines;
1518
- else if (await stat4(join6(dir, "run.json")).then(() => true, () => false))
1519
- throw new Error(`${runId} \u7684\u65E5\u5FD7\u5DF2\u6309\u4FDD\u7559\u89C4\u5219\u6E05\u7406\uFF08\u6BCF\u4E2A\u811A\u672C\u53EA\u7559\u6700\u8FD1\u7EA6 ${SCRIPT_LOG_BUDGET / 1024 / 1024} MiB \u7684\u8FD0\u884C\u65E5\u5FD7\uFF09`);
1520
- else
1521
- throw new Error(`\u6CA1\u6709\u8FD0\u884C\u8BB0\u5F55 ${runId}`);
1522
- }
1514
+ const all = await this.allLines(runId);
1523
1515
  const file = await runLogFile(dir);
1524
1516
  const pattern = query.search === void 0 || query.search === "" ? void 0 : toPattern(query.search);
1525
1517
  const numbered = all.map((line, i) => ({ ...line, n: i + 1 })).filter((l) => (query.levels === void 0 || query.levels.length === 0 || l.level !== void 0 && query.levels.includes(l.level)) && (pattern === void 0 || pattern.test(l.text)));
@@ -1527,6 +1519,19 @@ var Runner = class {
1527
1519
  const lines = query.fromLine === void 0 ? numbered.slice(-limit) : numbered.filter((l) => l.n >= query.fromLine).slice(0, limit);
1528
1520
  return { file, total: all.length, matched: numbered.length, lines };
1529
1521
  }
1522
+ /** Every line of a run's log: the saved one, or what is in memory for a run not saved yet. */
1523
+ async allLines(runId) {
1524
+ const dir = join6(this.#options.dataDir, "runs", runId);
1525
+ const saved = await readRunLog(dir);
1526
+ if (saved !== void 0)
1527
+ return saved;
1528
+ const memory = this.#runs.get(runId);
1529
+ if (memory !== void 0 && (memory.archived !== true || memory.lines.length > 0))
1530
+ return memory.lines;
1531
+ if (await stat4(join6(dir, "run.json")).then(() => true, () => false))
1532
+ throw new Error(`${runId} \u7684\u65E5\u5FD7\u5DF2\u6309\u4FDD\u7559\u89C4\u5219\u6E05\u7406\uFF08\u6BCF\u4E2A\u811A\u672C\u53EA\u7559\u6700\u8FD1\u7EA6 ${SCRIPT_LOG_BUDGET / 1024 / 1024} MiB \u7684\u8FD0\u884C\u65E5\u5FD7\uFF09`);
1533
+ throw new Error(`\u6CA1\u6709\u8FD0\u884C\u8BB0\u5F55 ${runId}`);
1534
+ }
1530
1535
  /**
1531
1536
  * Runs from before a restart, from their saved records; a run cut off by
1532
1537
  * the restart is marked failed. Old run folders are removed.
@@ -1891,9 +1896,9 @@ var Runner = class {
1891
1896
  }
1892
1897
  const exe = inside(dir, rendered.exe);
1893
1898
  const cwd = rendered.cwd === void 0 ? dir : inside(dir, rendered.cwd);
1894
- const command = (this.#options.command ?? ((file, args) => ({ file, args })))(exe, rendered.args);
1899
+ const command = (this.#options.command ?? ((file, args) => launchCommand(file, args, process.platform, process.env["ComSpec"])))(exe, rendered.args);
1895
1900
  run.info.command = [exe, ...rendered.args];
1896
- const child = spawn2(command.file, [...command.args], { cwd, windowsHide: false, stdio: ["ignore", "pipe", "pipe"] });
1901
+ const child = spawn2(command.file, [...command.args], { cwd, windowsHide: false, stdio: ["ignore", "pipe", "pipe"], windowsVerbatimArguments: command.verbatim === true });
1897
1902
  run.child = child;
1898
1903
  await new Promise((resolve2, reject) => {
1899
1904
  child.once("spawn", () => resolve2());
@@ -2411,8 +2416,8 @@ async function writeConfig(library, profiles, dataDir, scriptId, file, path, val
2411
2416
  const { manifest, dir } = packFor(library, scriptId);
2412
2417
  allowed(manifest, file);
2413
2418
  const profile = await profiles.resolve(scriptId, profileRef);
2414
- const stamp = new Date(now).toISOString().replace(/[:.]/g, "-");
2415
- const historyDir = join7(dataDir, "config-history", scriptId, profile.id === DEFAULT_PROFILE ? stamp : `${stamp}-${profile.id}`);
2419
+ const stamp2 = new Date(now).toISOString().replace(/[:.]/g, "-");
2420
+ const historyDir = join7(dataDir, "config-history", scriptId, profile.id === DEFAULT_PROFILE ? stamp2 : `${stamp2}-${profile.id}`);
2416
2421
  await profiles.write(scriptId, dir, manifest, file, path, value, historyDir, profile.id);
2417
2422
  return { file, backup: join7(historyDir, file), copy: "local", profile: profile.name };
2418
2423
  }
@@ -2864,25 +2869,88 @@ function runnerTools(runner, config) {
2864
2869
  }),
2865
2870
  tool({
2866
2871
  name: TOOL_NAMES.gamePathSet,
2867
- description: "\u4FDD\u5B58\u67D0\u4E2A\u811A\u672C\u7684 PC \u6E38\u620F\u7A0B\u5E8F\u4F4D\u7F6E\uFF08\u8FD0\u884C\u524D\u7531\u672C\u5E94\u7528\u542F\u52A8\u6E38\u620F\u65F6\u7528\uFF09\u3002\u53EA\u5728\u627E\u5230\u5E76\u786E\u8BA4\u4E86\u7A0B\u5E8F\u540E\u8C03\u7528\uFF1B\u8DEF\u5F84\u5FC5\u987B\u662F\u5B58\u5728\u7684 .exe\u3002",
2868
- properties: { id, path: { type: "string", description: "\u6E38\u620F\u7A0B\u5E8F\u7684\u5B8C\u6574\u8DEF\u5F84\uFF0C\u4F8B\u5982 D:\\Games\\Endfield\\Endfield.exe\u3002" } },
2869
- required: ["id", "path"],
2872
+ description: "\u4FDD\u5B58\u67D0\u4E2A\u811A\u672C\u8981\u73A9\u7684\u6E38\u620F\u5728\u54EA\uFF1APC \u6E38\u620F\u7A0B\u5E8F\u7684\u4F4D\u7F6E\uFF08path\uFF09\uFF0C\u6216\u6A21\u62DF\u5668\u91CC\u7528\u6237\u88C5\u7684\u90A3\u4E2A\u7248\u672C\u7684\u5305\u540D\uFF08android_package\uFF0C\u4F8B\u5982 B\u670D com.hypergryph.arknights.bilibili\uFF1B\u7528 emulator_apps \u67E5\u5230\u7684\uFF09\u3002\u8FD0\u884C\u524D\u7531\u672C\u5E94\u7528\u542F\u52A8\u3001\u5173\u95ED\u6E38\u620F\u65F6\u7528\uFF0C\u6E38\u620F\u9875\u7684\u5934\u50CF\u4E5F\u7528\u5B83\u3002\u53EA\u5728\u627E\u5230\u5E76\u786E\u8BA4\u540E\u8C03\u7528\uFF1Bpath \u5FC5\u987B\u662F\u5B58\u5728\u7684 .exe\u3002",
2873
+ properties: {
2874
+ id,
2875
+ path: { type: "string", description: "\u6E38\u620F\u7A0B\u5E8F\u7684\u5B8C\u6574\u8DEF\u5F84\uFF0C\u4F8B\u5982 D:\\Games\\Endfield\\Endfield.exe\u3002" },
2876
+ android_package: { type: "string", description: "\u6A21\u62DF\u5668\u91CC\u8FD9\u4E2A\u6E38\u620F\u7684\u5305\u540D\uFF0C\u4F8B\u5982 com.hypergryph.arknights\u3002" }
2877
+ },
2878
+ required: ["id"],
2870
2879
  kind: "other",
2871
- title: (a) => `\u4FDD\u5B58\u6E38\u620F\u4F4D\u7F6E\uFF1A${String(a["path"] ?? "")}`,
2880
+ title: (a) => `\u4FDD\u5B58\u6E38\u620F\u4F4D\u7F6E\uFF1A${String(a["path"] ?? a["android_package"] ?? "")}`,
2872
2881
  execute: async (args) => {
2873
- const a = parse(external_exports.object({ id: ScriptId, path: external_exports.string().trim().min(1) }), args);
2882
+ const a = parse(external_exports.object({ id: ScriptId, path: external_exports.string().trim().min(1).optional(), android_package: external_exports.string().trim().regex(/^[A-Za-z][\w]*(\.[A-Za-z_][\w]*)+$/, "\u5B89\u5353\u5305\u540D\u50CF com.example.game").optional() }), args);
2883
+ if (a.path === void 0 && a.android_package === void 0)
2884
+ throw new Error("\u5199 path\uFF08PC \u6E38\u620F\u7A0B\u5E8F\uFF09\u6216 android_package\uFF08\u6A21\u62DF\u5668\u91CC\u7684\u5305\u540D\uFF09");
2885
+ if (a.path === void 0) {
2886
+ const settings2 = await runner.launch.set(a.id, { androidPackage: a.android_package });
2887
+ return { saved: settings2.androidPackage, note: "\u5DF2\u4FDD\u5B58\uFF0C\u4E0B\u6B21\u8FD0\u884C\u751F\u6548" };
2888
+ }
2874
2889
  const path = a.path.replace(/^"|"$/g, "");
2875
2890
  if (!isAbsolute2(path) || !/\.exe$/i.test(path))
2876
2891
  throw new Error("\u8981\u586B .exe \u7A0B\u5E8F\u7684\u5B8C\u6574\u8DEF\u5F84");
2877
2892
  if (!existsSync2(path) || !statSync(path).isFile())
2878
2893
  throw new Error(`\u627E\u4E0D\u5230 ${path}`);
2879
- const settings = await runner.launch.set(a.id, { pcExe: path });
2880
- return { saved: settings.pcExe, process: settings.pcProcess ?? basename4(path), note: "\u5DF2\u4FDD\u5B58\uFF0C\u4E0B\u6B21\u8FD0\u884C\u751F\u6548" };
2894
+ const settings = await runner.launch.set(a.id, { pcExe: path, ...a.android_package === void 0 ? {} : { androidPackage: a.android_package } });
2895
+ return { saved: settings.pcExe, process: settings.pcProcess ?? basename4(path), ...settings.androidPackage === void 0 ? {} : { android_package: settings.androidPackage }, note: "\u5DF2\u4FDD\u5B58\uFF0C\u4E0B\u6B21\u8FD0\u884C\u751F\u6548" };
2881
2896
  }
2882
2897
  })
2883
2898
  ];
2884
2899
  }
2885
2900
 
2901
+ // packages/runner/lib/export.js
2902
+ import { mkdir as mkdir5, writeFile as writeFile5 } from "node:fs/promises";
2903
+ import { join as join8 } from "node:path";
2904
+ var pad = (n) => String(n).padStart(2, "0");
2905
+ var stamp = (at) => {
2906
+ const d = new Date(at);
2907
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}_${pad(d.getHours())}-${pad(d.getMinutes())}-${pad(d.getSeconds())}`;
2908
+ };
2909
+ var full = (at) => {
2910
+ const d = new Date(at);
2911
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
2912
+ };
2913
+ var clock = (at) => {
2914
+ const d = new Date(at);
2915
+ return `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
2916
+ };
2917
+ var safe = (name) => name.replace(/[\\/:*?"<>|]/g, "_");
2918
+ function runLogsPart(runner) {
2919
+ return {
2920
+ name: "runs",
2921
+ title: "\u811A\u672C\u8FD0\u884C\u65E5\u5FD7",
2922
+ async write({ since, until }, dir, { mask, signal }) {
2923
+ const runs = runner.list().filter((r) => r.startedAt >= since && r.startedAt < until).sort((a, b) => a.startedAt - b.startedAt);
2924
+ if (runs.length === 0)
2925
+ return { files: 0, summary: "\u8FD9\u6BB5\u65F6\u95F4\u6CA1\u6709\u811A\u672C\u8FD0\u884C" };
2926
+ await mkdir5(dir, { recursive: true });
2927
+ const gone = [];
2928
+ for (const run of runs) {
2929
+ signal.throwIfAborted();
2930
+ let lines = [];
2931
+ try {
2932
+ lines = await runner.allLines(run.id);
2933
+ } catch (error) {
2934
+ gone.push(`${run.id}\uFF08${error instanceof Error ? error.message : String(error)}\uFF09`);
2935
+ }
2936
+ const head = [
2937
+ `\u8FD0\u884C ${run.id}`,
2938
+ `\u811A\u672C ${run.scriptName}\uFF08${run.scriptId}\uFF09\uFF0C${run.kind === "settings" ? "\u8BBE\u7F6E\u754C\u9762" : `\u4EFB\u52A1 ${run.taskTitle}\uFF08${run.taskId}\uFF09`}`,
2939
+ `\u5F00\u59CB ${full(run.startedAt)}${run.endedAt === void 0 ? "\uFF0C\u8FD8\u5728\u8FD0\u884C" : `\uFF0C\u7ED3\u675F ${full(run.endedAt)}`}`,
2940
+ `\u7ED3\u679C ${run.state}${run.outcome === void 0 ? "" : `\uFF1A${mask(run.outcome)}`}${run.exitCode === void 0 ? "" : `\uFF08\u9000\u51FA\u7801 ${run.exitCode}\uFF09`}`,
2941
+ `\u65E5\u5FD7 ${lines.length} \u884C`,
2942
+ ""
2943
+ ];
2944
+ const body = lines.map((l) => `${clock(l.at)} [${l.source}]${l.level === void 0 ? "" : `[${l.level}]`} ${mask(l.text)}`);
2945
+ await writeFile5(join8(dir, safe(`${stamp(run.startedAt)}-${run.scriptId}-${run.taskId}-${run.state}.log`)), `${[...head, ...body].join("\n")}
2946
+ `, "utf8");
2947
+ }
2948
+ const scripts = [...new Set(runs.map((r) => r.scriptName))];
2949
+ return { files: runs.length, summary: `${runs.length} \u6B21\u8FD0\u884C\uFF08${scripts.join("\u3001")}\uFF09${gone.length === 0 ? "" : `\uFF1B\u5176\u4E2D ${gone.length} \u6B21\u7684\u65E5\u5FD7\u62FF\u4E0D\u5230\uFF1A${gone.join("\uFF1B")}`}` };
2950
+ }
2951
+ };
2952
+ }
2953
+
2886
2954
  // packages/runner/lib/index.js
2887
2955
  var ConfigSchema = external_exports.object({
2888
2956
  /** Run records, logs and config backups: `<dataDir>/runs/<id>/`. */
@@ -2945,6 +3013,9 @@ var AdgRunner = class extends Service {
2945
3013
  dispose();
2946
3014
  };
2947
3015
  }));
3016
+ ctx.inject(["adgGateway"], (scoped) => {
3017
+ scoped.effect(() => scoped.adgGateway.exportPart(runLogsPart(runner)), "adg-runner run logs export");
3018
+ });
2948
3019
  ctx.inject(["adgGateway"], (scoped) => {
2949
3020
  scoped.adgGateway.register({
2950
3021
  id: RUNS_CAPABILITY,
@@ -2,7 +2,7 @@ import { createRequire as __adgCreateRequire } from 'node:module'; import { dirn
2
2
  import {
3
3
  ScriptFamily,
4
4
  ScriptId
5
- } from "./chunk-LXHF6AKU.js";
5
+ } from "./chunk-34VNH3YS.js";
6
6
  import {
7
7
  external_exports
8
8
  } from "./chunk-6DSSLS7I.js";
@@ -7342,6 +7342,52 @@ var require_dist = __commonJS({
7342
7342
  }
7343
7343
  });
7344
7344
 
7345
+ // packages/pack-schema/lib/routine.js
7346
+ var Id = external_exports.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "lowercase letters, digits and dashes");
7347
+ var Regex = external_exports.string().min(1).refine((value) => {
7348
+ try {
7349
+ new RegExp(value);
7350
+ return true;
7351
+ } catch {
7352
+ return false;
7353
+ }
7354
+ }, "invalid regular expression");
7355
+ var RoutinePeriod = external_exports.enum(["daily", "weekly", "event"]);
7356
+ var routineFields = {
7357
+ id: Id,
7358
+ name: external_exports.string().trim().min(1),
7359
+ period: RoutinePeriod,
7360
+ description: external_exports.string().trim().min(1).optional(),
7361
+ /**
7362
+ * Log lines that show it was done (regular expressions, tested on every
7363
+ * line of a run): in a Script Pack, that script's runs; in a Game Pack, the
7364
+ * runs of every script that plays the game.
7365
+ */
7366
+ log: external_exports.union([Regex, external_exports.array(Regex).min(1)]).optional(),
7367
+ /**
7368
+ * period=event: the data sites' events it is (their names, as regular
7369
+ * expressions). They are listed apart from the other events, as 周期玩法.
7370
+ */
7371
+ events: external_exports.array(Regex).min(1).optional()
7372
+ };
7373
+ function eventsNeeded(routine, issues) {
7374
+ if (routine.period === "event" && routine.events === void 0)
7375
+ issues.addIssue({ code: "custom", path: ["events"], message: "period event needs the events it is (their names)" });
7376
+ }
7377
+ var GameRoutine = external_exports.object(routineFields).superRefine(eventsNeeded);
7378
+ var ScriptRoutine = external_exports.object({
7379
+ ...routineFields,
7380
+ /** This script's tasks: a run of one that succeeds did it. */
7381
+ tasks: external_exports.array(external_exports.string().regex(/^[a-z0-9][a-z0-9_-]*$/)).min(1).optional()
7382
+ }).superRefine(eventsNeeded);
7383
+ var WeeklyReset = external_exports.object({
7384
+ day: external_exports.number().int().min(1).max(7).default(1),
7385
+ at: external_exports.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "HH:mm").optional()
7386
+ });
7387
+ function routineLogs(routine) {
7388
+ return routine.log === void 0 ? [] : typeof routine.log === "string" ? [routine.log] : [...routine.log];
7389
+ }
7390
+
7345
7391
  // packages/pack-schema/lib/manifest.js
7346
7392
  var Requirement = external_exports.object({
7347
7393
  /** e.g. `dotnet-desktop-runtime`, `vcredist`, `adb`, `python`, `node`, `emulator`. */
@@ -7365,7 +7411,7 @@ var ConfigFile = external_exports.object({
7365
7411
  });
7366
7412
  var open = external_exports.record(external_exports.string(), external_exports.unknown());
7367
7413
  var RelativePath = external_exports.string().min(1).refine((p) => !p.split(/[\\/]/).includes("..") && !/^([A-Za-z]:|[\\/])/.test(p), "must stay inside the script directory");
7368
- var Regex = external_exports.string().min(1).refine((value) => {
7414
+ var Regex2 = external_exports.string().min(1).refine((value) => {
7369
7415
  try {
7370
7416
  new RegExp(value);
7371
7417
  return true;
@@ -7385,7 +7431,7 @@ var ParamChoices = external_exports.object({
7385
7431
  /** Field shown beside it, e.g. the controller. */
7386
7432
  detail: external_exports.string().optional(),
7387
7433
  /** Only items whose `field` matches (a regular expression, case-insensitive). */
7388
- where: external_exports.object({ field: external_exports.string().min(1), match: Regex }).optional(),
7434
+ where: external_exports.object({ field: external_exports.string().min(1), match: Regex2 }).optional(),
7389
7435
  /**
7390
7436
  * New items may be made by copying an existing one (the first that
7391
7437
  * matches `where`), so the structure stays the script's own; `set` fields
@@ -7677,7 +7723,7 @@ var ScriptManifest = external_exports.object({
7677
7723
  * are tried (interface.json, version.txt…, the programs' file versions).
7678
7724
  */
7679
7725
  version: external_exports.union([
7680
- external_exports.object({ file: RelativePath, json: external_exports.array(external_exports.string().min(1)).min(1).optional(), pattern: Regex.optional() }),
7726
+ external_exports.object({ file: RelativePath, json: external_exports.array(external_exports.string().min(1)).min(1).optional(), pattern: Regex2.optional() }),
7681
7727
  external_exports.object({ exe: RelativePath })
7682
7728
  ]).optional()
7683
7729
  }).default({ requires: [] }),
@@ -7691,6 +7737,8 @@ var ScriptManifest = external_exports.object({
7691
7737
  tasks: external_exports.array(Task).default([]),
7692
7738
  logs: Logs.default({ sources: [{ stdout: true, encoding: "auto" }], rules: [] }),
7693
7739
  recovery: external_exports.array(Recovery).default([]),
7740
+ /** The game's 日常 / 周常 this script does, and how a run shows each was done (routine.ts). */
7741
+ routines: external_exports.array(ScriptRoutine).default([]),
7694
7742
  game: Game.optional(),
7695
7743
  /** The user guide shown on the 脚本 page. */
7696
7744
  guide: Guide.optional(),
@@ -7707,6 +7755,16 @@ var ScriptManifest = external_exports.object({
7707
7755
  if (manifest.launch === void 0)
7708
7756
  issues.addIssue({ code: "custom", path: ["launch"], message: "tasks need a launch section" });
7709
7757
  });
7758
+ const routineIds = /* @__PURE__ */ new Set();
7759
+ manifest.routines.forEach((routine, index) => {
7760
+ if (routineIds.has(routine.id))
7761
+ issues.addIssue({ code: "custom", path: ["routines", index, "id"], message: `duplicate routine id ${routine.id}` });
7762
+ routineIds.add(routine.id);
7763
+ routine.tasks?.forEach((task, at) => {
7764
+ if (!ids.has(task))
7765
+ issues.addIssue({ code: "custom", path: ["routines", index, "tasks", at], message: `no task ${task}` });
7766
+ });
7767
+ });
7710
7768
  const tags = /* @__PURE__ */ new Set(["stalled", "failed", ...manifest.logs.rules.map((r) => r.tag ?? r.level)]);
7711
7769
  manifest.recovery.forEach((entry, index) => {
7712
7770
  if (!tags.has(entry.on))
@@ -7890,6 +7948,7 @@ var TOOLS = [
7890
7948
  "skill_save",
7891
7949
  "skill_hub_install",
7892
7950
  "skill_hub_list",
7951
+ "emulator_apps",
7893
7952
  "emulator_configure",
7894
7953
  "emulator_install",
7895
7954
  "emulator_start",
@@ -7979,10 +8038,42 @@ function parseManifest(text, file = "adg.script.yaml") {
7979
8038
  }
7980
8039
  return parsed.data;
7981
8040
  }
8041
+ function strayKeys(text) {
8042
+ let raw;
8043
+ try {
8044
+ raw = (0, import_yaml.parse)(text, { maxAliasCount: 100 });
8045
+ } catch {
8046
+ return [];
8047
+ }
8048
+ const out = [];
8049
+ const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
8050
+ const check = (value, shape, where) => {
8051
+ if (!isObject(value))
8052
+ return;
8053
+ for (const key of Object.keys(value))
8054
+ if (!(key in shape))
8055
+ out.push(where === "" ? key : `${where}.${key}`);
8056
+ };
8057
+ const each = (value, shape, where) => {
8058
+ if (Array.isArray(value))
8059
+ value.forEach((item, i) => check(item, shape, `${where}[${i}]`));
8060
+ };
8061
+ check(raw, ScriptManifest.shape, "");
8062
+ if (!isObject(raw))
8063
+ return out;
8064
+ check(raw["guide"], Guide.shape, "guide");
8065
+ check(raw["launch"], Launch.shape, "launch");
8066
+ check(raw["logs"], Logs.shape, "logs");
8067
+ if (isObject(raw["logs"]))
8068
+ each(raw["logs"]["rules"], LogRule.shape, "logs.rules");
8069
+ each(raw["tasks"], Task.shape, "tasks");
8070
+ each(raw["routines"], ScriptRoutine.shape, "routines");
8071
+ return out;
8072
+ }
7982
8073
 
7983
8074
  // packages/pack-schema/lib/game.js
7984
8075
  var import_yaml2 = __toESM(require_dist(), 1);
7985
- var Id = external_exports.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "lowercase letters, digits and dashes");
8076
+ var Id2 = external_exports.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "lowercase letters, digits and dashes");
7986
8077
  var Url = external_exports.string().url().refine((u) => /^https?:\/\//.test(u), "an http(s) address");
7987
8078
  var SmwSource = external_exports.object({
7988
8079
  /** The wiki's `api.php`. */
@@ -8014,31 +8105,79 @@ var SraSource = external_exports.object({
8014
8105
  locale: external_exports.string().regex(/^[a-z]{2}-[A-Z]{2}$/).optional(),
8015
8106
  api: Url.default("https://starrailassistant.top/api/v1")
8016
8107
  });
8108
+ var PoolSource = external_exports.object({
8109
+ api: Url,
8110
+ /** SMW conditions picking banner pages, e.g. `[[分类:跃迁]]`. */
8111
+ conditions: external_exports.string().min(2),
8112
+ /** Property holding the banner's name; the page name when absent. */
8113
+ title: external_exports.string().min(1).optional(),
8114
+ /** Property holding its kind (角色 / 光锥 / 限定寻访…). */
8115
+ type: external_exports.string().min(1).optional(),
8116
+ start: external_exports.string().min(1),
8117
+ end: external_exports.string().min(1),
8118
+ /**
8119
+ * How the dates are stored: `date` and `text` as in `SmwSource.dates`;
8120
+ * `local`, SMW dates that hold the game's wall clock as if it were UTC
8121
+ * (a wiki that typed server time into a date property).
8122
+ */
8123
+ dates: external_exports.enum(["date", "text", "local"]).default("date"),
8124
+ /** Properties listing who (or what) is on rate-up, in order. */
8125
+ up: external_exports.array(external_exports.string().min(1)).default([]),
8126
+ /** Pages per query. @default 50 */
8127
+ limit: external_exports.number().int().min(1).max(500).default(50),
8128
+ /** A wiki file named after each banner's page, used as its picture; a page that is itself a file (PRTS) is its own picture. */
8129
+ image: external_exports.string().includes("{page}").optional()
8130
+ });
8131
+ var HoyoSource = external_exports.object({
8132
+ game: external_exports.enum(["genshin", "starrail", "zzz"]),
8133
+ lang: external_exports.string().regex(/^[a-z]{2}(?:-[a-z]{2})?$/).default("zh-cn"),
8134
+ api: Url.default("https://api.ennead.cc/mihoyo")
8135
+ });
8017
8136
  var SteamSource = external_exports.object({
8018
8137
  /** The game's Steam app id (the number in store.steampowered.com/app/<id>/). */
8019
8138
  appid: external_exports.number().int().positive()
8020
8139
  });
8021
8140
  var GameSource = external_exports.object({
8022
- id: Id,
8141
+ id: Id2,
8023
8142
  name: external_exports.string().min(1),
8024
8143
  /** Where a person (or the agent, with web_fetch) reads it. */
8025
8144
  homepage: Url.optional(),
8026
8145
  /** Read by the plugin itself (smw, sra or steam); without one the source is only for the agent. */
8027
8146
  smw: SmwSource.optional(),
8028
8147
  sra: SraSource.optional(),
8029
- steam: SteamSource.optional()
8030
- }).refine((s) => [s.smw, s.sra, s.steam].filter((x) => x !== void 0).length <= 1, "smw\u3001sra \u548C steam \u53EA\u80FD\u5199\u4E00\u4E2A");
8148
+ steam: SteamSource.optional(),
8149
+ /** Banners on a wiki (a source of its own: a game may read its events from one site and its banners from another). */
8150
+ pools: PoolSource.optional(),
8151
+ /** miHoYo banners from ennead's API (HoyoSource). */
8152
+ hoyo: HoyoSource.optional()
8153
+ }).refine((s) => [s.smw, s.sra, s.steam, s.pools, s.hoyo].filter((x) => x !== void 0).length <= 1, "smw\u3001sra\u3001steam\u3001pools \u548C hoyo \u53EA\u80FD\u5199\u4E00\u4E2A");
8031
8154
  var GameManifest = external_exports.object({
8032
- id: Id,
8155
+ id: Id2,
8033
8156
  name: external_exports.string().min(1),
8034
8157
  /** Other names people call it, to match the user's words and script packs' `game.name`. */
8035
8158
  aliases: external_exports.array(external_exports.string().min(1)).default([]),
8036
8159
  /** Script Packs that play it. */
8037
- scripts: external_exports.array(Id).default([]),
8160
+ scripts: external_exports.array(Id2).default([]),
8038
8161
  /** The server's time zone: dates written without one, and where a day starts. */
8039
8162
  timezone: external_exports.string().min(1).default("Asia/Shanghai"),
8040
8163
  /** When the game's day rolls over, `HH:mm` server time. */
8041
8164
  dailyReset: external_exports.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "HH:mm").default("04:00"),
8165
+ /** When its week starts over (周常): Monday at the daily reset unless said. */
8166
+ weeklyReset: WeeklyReset.default({ day: 1 }),
8167
+ /** Its 日常 and 周常, and the recurring events that are one (routine.ts); the scripts that play it add theirs. */
8168
+ routines: external_exports.array(GameRoutine).default([]),
8169
+ /**
8170
+ * Its Android builds, one per client, as MAA's resource/config.json
8171
+ * `packageName` lists Arknights' (Official, Bilibili, YoStarEN…): matched
8172
+ * against the apps installed in the emulator to find which one the user plays.
8173
+ */
8174
+ android: external_exports.object({
8175
+ packages: external_exports.array(external_exports.object({
8176
+ package: external_exports.string().regex(/^[A-Za-z][\w]*(\.[A-Za-z_][\w]*)+$/, "an Android package name like com.example.game"),
8177
+ /** Which client, for people: 官服, B服, 国际服… */
8178
+ client: external_exports.string().min(1).optional()
8179
+ })).min(1)
8180
+ }).optional(),
8042
8181
  /** How the agent sees the game: in the emulator, or its PC window. */
8043
8182
  screen: external_exports.object({
8044
8183
  target: external_exports.enum(["emulator", "window"]),
@@ -8141,6 +8280,60 @@ function parseJsonc(source) {
8141
8280
  return JSON.parse(stripJsonc(source.replace(/^/, "")));
8142
8281
  }
8143
8282
 
8283
+ // packages/pack-schema/lib/launch.js
8284
+ function launchCommand(file, args, platform, comspec) {
8285
+ if (platform === "win32" && /\.(bat|cmd)$/i.test(file)) {
8286
+ const unsafe = args.find((a) => /["\r\n]/.test(a));
8287
+ if (unsafe !== void 0)
8288
+ throw new Error(`\u53C2\u6570\u300C${unsafe.slice(0, 40)}\u300D\u91CC\u6709\u53CC\u5F15\u53F7\u6216\u6362\u884C\uFF0C\u4E0D\u80FD\u5B89\u5168\u5730\u4EA4\u7ED9\u6279\u5904\u7406\u542F\u52A8\u5668 ${file.split(/[\\/]/).at(-1)}`);
8289
+ const line = [escapeCommand(file), ...args.map(escapeArgument)].join(" ");
8290
+ return { file: comspec ?? "cmd.exe", args: ["/d", "/s", "/c", `"${line}"`], verbatim: true };
8291
+ }
8292
+ if (platform === "win32" && /\.ps1$/i.test(file)) {
8293
+ return { file: "powershell.exe", args: ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", file, ...args], verbatim: false };
8294
+ }
8295
+ return { file, args: [...args], verbatim: false };
8296
+ }
8297
+ var isScriptLauncher = (file) => /\.(bat|cmd|ps1)$/i.test(file);
8298
+ var META = /([()\][%!^"`<>&|;, *?])/g;
8299
+ function escapeCommand(file) {
8300
+ return file.replace(META, "^$1");
8301
+ }
8302
+ function escapeArgument(arg) {
8303
+ const quoted = `"${arg.replace(/(?=(\\+?)?)\1"/g, '$1$1\\"').replace(/(?=(\\+?)?)\1$/, "$1$1")}"`;
8304
+ return quoted.replace(META, "^$1");
8305
+ }
8306
+
8307
+ // packages/pack-schema/lib/patterns.js
8308
+ function patternIssues(manifest) {
8309
+ const issues = [];
8310
+ const check = (where, pattern) => {
8311
+ let re;
8312
+ try {
8313
+ re = new RegExp(pattern);
8314
+ } catch {
8315
+ return;
8316
+ }
8317
+ if (re.test(""))
8318
+ issues.push(`${where} \u7684\u300C${pattern}\u300D\u4F1A\u5339\u914D\u6BCF\u4E00\u884C\uFF08\u300C|\u300D\u4E24\u8FB9\u6709\u4E00\u8FB9\u662F\u7A7A\u7684\uFF1F\uFF09`);
8319
+ else if (/\\\\[[\]().|*+?{}]/.test(pattern))
8320
+ issues.push(`${where} \u7684\u300C${pattern}\u300D\u91CC\u53CD\u659C\u6760\u5199\u4E86\u4E24\u6B21\uFF1A\u5355\u5F15\u53F7 YAML \u91CC \\[ \u5C31\u662F\u6B63\u5219\u7684 \\[\uFF0C\u5199\u6210 \\\\[ \u4F1A\u53BB\u627E\u4E00\u4E2A\u53CD\u659C\u6760\uFF0C\u65E5\u5FD7\u91CC\u90A3\u4E00\u884C\u5C31\u5BF9\u4E0D\u4E0A\u4E86`);
8321
+ };
8322
+ manifest.logs?.rules.forEach((rule, i) => check(`logs.rules[${i}].match`, rule.match));
8323
+ manifest.routines?.forEach((routine, i) => {
8324
+ for (const p of routineLogs(routine))
8325
+ check(`routines[${i}]\uFF08${routine.name}\uFF09.log`, p);
8326
+ });
8327
+ const warnings = new Set((manifest.logs?.rules ?? []).filter((r) => r.level === "warning" && r.tag !== void 0).map((r) => r.tag));
8328
+ const errors = new Set((manifest.logs?.rules ?? []).filter((r) => r.level === "error" && r.tag !== void 0).map((r) => r.tag));
8329
+ for (const [i, r] of (manifest.recovery ?? []).entries()) {
8330
+ if ((r.do === "stop" || r.do === "restart") && warnings.has(r.on) && !errors.has(r.on)) {
8331
+ issues.push(`recovery[${i}] \u5728\u8B66\u544A\u300C${r.on}\u300D\u4E0A ${r.do}\uFF1A\u8B66\u544A\u591A\u534A\u662F\u811A\u672C\u81EA\u5DF1\u4F1A\u91CD\u8BD5\u7684\u60C5\u51B5\uFF0C${r.do === "stop" ? "\u505C\u6389" : "\u91CD\u8DD1"}\u4F1A\u6253\u65AD\u672C\u6765\u80FD\u8DD1\u5B8C\u7684\u4EFB\u52A1\uFF1B\u53EA\u7ED9\u786E\u5B9A\u8DD1\u4E0D\u4E0B\u53BB\u7684\u9519\u8BEF\uFF08level: error\uFF09\u5199\uFF0C\u6216\u8005\u53BB\u6389\u8FD9\u6761`);
8332
+ }
8333
+ }
8334
+ return issues;
8335
+ }
8336
+
8144
8337
  // packages/pack-schema/lib/render.js
8145
8338
  var TaskInputError = class extends Error {
8146
8339
  constructor(message) {
@@ -8322,6 +8515,7 @@ var MANIFEST_FILE = "adg.script.yaml";
8322
8515
  var SKILL_FILE = "SKILL.md";
8323
8516
 
8324
8517
  export {
8518
+ routineLogs,
8325
8519
  MCP_SERVER_NAME,
8326
8520
  guideView,
8327
8521
  guideIssues,
@@ -8329,6 +8523,8 @@ export {
8329
8523
  renderTask,
8330
8524
  require_dist,
8331
8525
  parseManifest,
8526
+ strayKeys,
8527
+ GameSource,
8332
8528
  GameManifest,
8333
8529
  GAME_MANIFEST_FILE,
8334
8530
  GAME_GUIDE_FILE,
@@ -8338,6 +8534,9 @@ export {
8338
8534
  globToRegExp,
8339
8535
  versionOfTag,
8340
8536
  chooseAsset,
8537
+ launchCommand,
8538
+ isScriptLauncher,
8539
+ patternIssues,
8341
8540
  MANIFEST_FILE,
8342
8541
  SKILL_FILE
8343
8542
  };