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
package/lib/emulator.js CHANGED
@@ -5,12 +5,14 @@ import {
5
5
  } from "./chunk-YG4B5G7F.js";
6
6
  import {
7
7
  writeFileAtomic
8
- } from "./chunk-CCAB6XXZ.js";
8
+ } from "./chunk-RESS7WVY.js";
9
9
  import {
10
10
  EMULATORS_CAPABILITY,
11
- EmulatorSettings,
11
+ EmulatorSettings
12
+ } from "./chunk-V2X4PLF5.js";
13
+ import {
12
14
  external_exports
13
- } from "./chunk-SA72K6M2.js";
15
+ } from "./chunk-SHTX4AGU.js";
14
16
  import "./chunk-2UFLGPDY.js";
15
17
 
16
18
  // packages/emulator/lib/index.js
package/lib/feishu.js CHANGED
@@ -2,7 +2,7 @@ import { createRequire as __adgCreateRequire } from 'node:module'; import { dirn
2
2
  import {
3
3
  replyMarkdown,
4
4
  replyPlain
5
- } from "./chunk-4PNYIZVU.js";
5
+ } from "./chunk-TWUATN5X.js";
6
6
  import {
7
7
  require_extension,
8
8
  require_permessage_deflate,
@@ -12,17 +12,20 @@ import {
12
12
  require_subprotocol,
13
13
  require_websocket,
14
14
  require_websocket_server
15
- } from "./chunk-IZENRXQ6.js";
15
+ } from "./chunk-MEKSHT6V.js";
16
+ import "./chunk-FH64SAZU.js";
16
17
  import {
17
18
  writeFileAtomic
18
- } from "./chunk-CCAB6XXZ.js";
19
+ } from "./chunk-RESS7WVY.js";
19
20
  import {
20
21
  FEISHU_CAPABILITY,
21
22
  FEISHU_SECRET_REF,
22
23
  FeishuPending,
23
- FeishuSettings,
24
+ FeishuSettings
25
+ } from "./chunk-V2X4PLF5.js";
26
+ import {
24
27
  external_exports
25
- } from "./chunk-SA72K6M2.js";
28
+ } from "./chunk-SHTX4AGU.js";
26
29
  import {
27
30
  __commonJS,
28
31
  __require,
package/lib/game-intel.js CHANGED
@@ -7,14 +7,16 @@ import {
7
7
  GAME_MANIFEST_FILE,
8
8
  GameManifest,
9
9
  parseGameManifest
10
- } from "./chunk-XHP3SLMO.js";
10
+ } from "./chunk-77ZYHRN7.js";
11
11
  import {
12
12
  sessionConversations
13
- } from "./chunk-4PNYIZVU.js";
14
- import "./chunk-IZENRXQ6.js";
13
+ } from "./chunk-TWUATN5X.js";
14
+ import "./chunk-MEKSHT6V.js";
15
+ import "./chunk-FH64SAZU.js";
15
16
  import {
17
+ ExeIcons,
16
18
  writeFileAtomic
17
- } from "./chunk-CCAB6XXZ.js";
19
+ } from "./chunk-RESS7WVY.js";
18
20
  import {
19
21
  GAMES_CAPABILITY,
20
22
  GamesSettings,
@@ -22,13 +24,16 @@ import {
22
24
  OWN_SOURCE,
23
25
  SCREEN_SOURCE,
24
26
  SHOT_IMAGE,
25
- external_exports,
26
27
  taskMessage
27
- } from "./chunk-SA72K6M2.js";
28
+ } from "./chunk-V2X4PLF5.js";
29
+ import {
30
+ external_exports
31
+ } from "./chunk-SHTX4AGU.js";
28
32
  import "./chunk-2UFLGPDY.js";
29
33
 
30
34
  // packages/game-intel/lib/index.js
31
35
  import { createHash } from "node:crypto";
36
+ import { existsSync } from "node:fs";
32
37
  import { mkdir as mkdir2, readdir, readFile as readFile2, rm, writeFile } from "node:fs/promises";
33
38
  import { isAbsolute, join as join2, resolve } from "node:path";
34
39
  import { Service } from "@deepseek-ai/cordis";
@@ -1622,7 +1627,9 @@ var GAME_ROLE = {
1622
1627
  order: 20,
1623
1628
  titles: ["\u6E38\u620F\u4FE1\u606F", "\u6E38\u620F\u8D44\u8BAF", "\u6DFB\u52A0\u6E38\u620F", "\u65E5\u62A5"],
1624
1629
  // Games and their screens, and what scripts ran (for the daily report); no installing, runs or pipelines.
1625
- tools: ["game_*", "screen_*", "window_*", "emulator_status", "emulator_start", "script_list", "script_tasks", "script_runs", "system_info", "skill_focus", "skill_save"],
1630
+ // skill_hub_list: its reading prompt and game_list send it there when a game's skill is missing.
1631
+ // browser_*: official sites and wikis that need clicking through (the built-in browser).
1632
+ tools: ["game_*", "screen_*", "window_*", "browser_*", "emulator_status", "emulator_start", "script_list", "script_tasks", "script_runs", "skill_hub_list", "system_info", "skill_focus", "skill_save"],
1626
1633
  duty: [
1627
1634
  "# \u4F60\u7684\u89D2\u8272\uFF1A\u6E38\u620F",
1628
1635
  "\u4F60\u662F MultiGameAssistant \u7684\u300C\u6E38\u620F\u300Dagent\uFF1A\u8BFB\u6E38\u620F\u7684\u6D3B\u52A8\u3001\u8D44\u8BAF\u548C\u8FDB\u5EA6\u5E76\u8BB0\u4E0B\u6765\uFF08game_record\uFF09\uFF0C\u5199\u65E5\u62A5\uFF0C\u6DFB\u52A0\u6E38\u620F\u3002",
@@ -1645,6 +1652,10 @@ var AdgGameIntel = class extends Service {
1645
1652
  games = [];
1646
1653
  daily;
1647
1654
  dir;
1655
+ /** Game programs' icons (exe-icon.ts). */
1656
+ icons;
1657
+ /** Each game's PC program as found this run (undefined: none). */
1658
+ programs = /* @__PURE__ */ new Map();
1648
1659
  builtinDir;
1649
1660
  log;
1650
1661
  constructor(ctx, config) {
@@ -1655,6 +1666,7 @@ var AdgGameIntel = class extends Service {
1655
1666
  this.dir = join2(spec.dataDir, "games");
1656
1667
  this.builtinDir = spec.gamesDir ?? GAMES_DIR;
1657
1668
  this.calendar = new Calendar(this.dir);
1669
+ this.icons = new ExeIcons(join2(this.dir, "icons"));
1658
1670
  const calendar = this.calendar;
1659
1671
  const changed = (game) => ctx.get("adgGateway")?.broadcast("games/changed", game === void 0 ? {} : { game });
1660
1672
  const daily = new DailyReport({
@@ -1814,6 +1826,11 @@ var AdgGameIntel = class extends Service {
1814
1826
  return this.picture(screen.image);
1815
1827
  return { mediaType: "image/png", data: (await readFile2(this.evidenceFile(id))).toString("base64") };
1816
1828
  },
1829
+ "games/icon": async (params, call) => {
1830
+ await this.ready;
1831
+ const icon = await this.icon(params.game, call.signal);
1832
+ return icon === null ? {} : { icon };
1833
+ },
1817
1834
  "games/image": async (params) => {
1818
1835
  await this.ready;
1819
1836
  return this.picture(params.url);
@@ -2150,6 +2167,72 @@ var AdgGameIntel = class extends Service {
2150
2167
  const mine = new Set([...byName, ...byDescription].filter(([, ids]) => ids.includes(gameId)).map(([rid]) => rid));
2151
2168
  return { items: items.filter((i) => mine.has(i.rid)), from };
2152
2169
  }
2170
+ /** A game's program icon, for its avatar; null when it has no PC program this app knows of. */
2171
+ async icon(gameId, signal) {
2172
+ const program = await this.program(gameId);
2173
+ if (program === void 0)
2174
+ return null;
2175
+ try {
2176
+ return { mediaType: "image/png", data: (await this.icons.png(program, signal)).toString("base64") };
2177
+ } catch (e) {
2178
+ this.log.warn(`games: no icon for ${gameId} (${program}): ${e instanceof Error ? e.message : String(e)}`);
2179
+ return null;
2180
+ }
2181
+ }
2182
+ /**
2183
+ * Where a game's PC program is: the one a script that plays it starts (its
2184
+ * saved 游戏位置), else where 自动查找 finds the program the packs that play
2185
+ * it name (installed or not), looked for once a run.
2186
+ */
2187
+ async program(gameId) {
2188
+ const runner = this.ctx.get("adgRunner")?.runner;
2189
+ if (runner === void 0 || process.platform !== "win32")
2190
+ return void 0;
2191
+ const scripts = this.scriptsOf(gameId);
2192
+ for (const id of scripts) {
2193
+ const exe = (await runner.launch.get(id).catch(() => void 0))?.pcExe;
2194
+ if (exe !== void 0 && existsSync(exe))
2195
+ return exe;
2196
+ }
2197
+ let search = this.programs.get(gameId);
2198
+ if (search === void 0) {
2199
+ search = this.searchProgram(gameId, scripts);
2200
+ this.programs.set(gameId, search);
2201
+ void search.then((path2) => {
2202
+ if (path2 === void 0)
2203
+ setTimeout(() => this.programs.delete(gameId), 2 * 6e4).unref?.();
2204
+ });
2205
+ }
2206
+ const path = await search;
2207
+ if (path !== void 0 && !existsSync(path)) {
2208
+ this.programs.delete(gameId);
2209
+ return void 0;
2210
+ }
2211
+ return path;
2212
+ }
2213
+ /** Where 自动查找 finds the program the packs that play a game name (installed or not), with the game's names to look for. */
2214
+ async searchProgram(gameId, scripts) {
2215
+ const runner = this.ctx.get("adgRunner")?.runner;
2216
+ if (runner === void 0)
2217
+ return void 0;
2218
+ const { manifest } = this.game(gameId);
2219
+ const library = this.ctx.get("adgScripts")?.library;
2220
+ for (const id of scripts) {
2221
+ let pack;
2222
+ try {
2223
+ pack = library?.packOf(id);
2224
+ } catch {
2225
+ pack = void 0;
2226
+ }
2227
+ const game = (pack ?? library?.pack(id))?.manifest.game;
2228
+ if (game?.pc?.process === void 0)
2229
+ continue;
2230
+ const found = await runner.findGameProgram(game, [manifest.name, ...manifest.aliases]).catch(() => void 0);
2231
+ if (found !== void 0)
2232
+ return found;
2233
+ }
2234
+ return void 0;
2235
+ }
2153
2236
  scriptsOf(gameId) {
2154
2237
  return this.scriptsByGame().get(gameId) ?? [];
2155
2238
  }
@@ -2194,7 +2277,7 @@ var AdgGameIntel = class extends Service {
2194
2277
  for (const { manifest } of games) {
2195
2278
  const sources = manifest.sources.filter((s) => s.smw !== void 0 || s.sra !== void 0);
2196
2279
  if (sources.length === 0) {
2197
- results.push({ game: manifest.id, ok: false, count: 0, detail: `\u6CA1\u6709\u80FD\u76F4\u63A5\u8BFB\u7684\u6570\u636E\u7AD9\uFF1A\u7528 web_fetch \u770B ${manifest.sources.map((s) => s.homepage).filter(Boolean).join(" \u6216 ") || "\u5B98\u7F51\u516C\u544A"}\uFF0C\u518D\u7528 game_record\uFF08source=site\uFF09\u8BB0\u4E0B` });
2280
+ results.push({ game: manifest.id, ok: false, count: 0, detail: `\u6CA1\u6709\u80FD\u76F4\u63A5\u8BFB\u7684\u6570\u636E\u7AD9\uFF1A\u7528 web_fetch\uFF08\u53EA\u62FF\u5230\u7A7A\u58F3\u65F6\u7528\u5185\u7F6E\u6D4F\u89C8\u5668\uFF09\u770B ${manifest.sources.map((s) => s.homepage).filter(Boolean).join(" \u6216 ") || "\u5B98\u7F51\u516C\u544A"}\uFF0C\u518D\u7528 game_record\uFF08source=site\uFF09\u8BB0\u4E0B` });
2198
2281
  continue;
2199
2282
  }
2200
2283
  const failures = [];
package/lib/gateway.js CHANGED
@@ -2,11 +2,12 @@ import { createRequire as __adgCreateRequire } from 'node:module'; import { dirn
2
2
  import {
3
3
  AGENT_PRESET,
4
4
  AdgGateway,
5
+ AgentModels,
5
6
  INSTANCES_DIR,
6
7
  Instances,
8
+ NEW_INPUT,
7
9
  PRESET,
8
10
  Permissions,
9
- RoleModel,
10
11
  SessionRoles,
11
12
  SkillScope,
12
13
  clashes,
@@ -17,18 +18,21 @@ import {
17
18
  copyLabel,
18
19
  lib_default,
19
20
  streamFacts
20
- } from "./chunk-IZENRXQ6.js";
21
- import "./chunk-CCAB6XXZ.js";
22
- import "./chunk-SA72K6M2.js";
21
+ } from "./chunk-MEKSHT6V.js";
22
+ import "./chunk-FH64SAZU.js";
23
+ import "./chunk-RESS7WVY.js";
24
+ import "./chunk-V2X4PLF5.js";
25
+ import "./chunk-SHTX4AGU.js";
23
26
  import "./chunk-2UFLGPDY.js";
24
27
  export {
25
28
  AGENT_PRESET,
26
29
  AdgGateway,
30
+ AgentModels,
27
31
  INSTANCES_DIR,
28
32
  Instances,
33
+ NEW_INPUT,
29
34
  PRESET,
30
35
  Permissions,
31
- RoleModel,
32
36
  SessionRoles,
33
37
  SkillScope,
34
38
  clashes,
package/lib/guard.js CHANGED
@@ -1,7 +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
  GUARD_CAPABILITY
4
- } from "./chunk-SA72K6M2.js";
4
+ } from "./chunk-V2X4PLF5.js";
5
+ import "./chunk-SHTX4AGU.js";
5
6
  import "./chunk-2UFLGPDY.js";
6
7
 
7
8
  // packages/guard/lib/index.js
@@ -66,7 +67,7 @@ function denialReason(verdict, scriptName) {
66
67
  if (verdict.scriptId === APP_FILES) {
67
68
  return [
68
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`,
69
- "\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\uFF1B\u6280\u80FD\u5E93\u4E0B\u8F7D\u7684\u6280\u80FD\u5728\u6570\u636E\u76EE\u5F55\u91CC\uFF0C\u53EF\u4EE5\u6539\uFF0C\u66F4\u65B0\u65F6\u4E0D\u4F1A\u88AB\u8986\u76D6\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"
70
71
  ].join("");
71
72
  }
72
73
  return [
@@ -97,7 +98,8 @@ var AdgGuard = class extends Service {
97
98
  for (const version of script.versions)
98
99
  protectedDirs.push({ scriptId: script.id, dir: version.dir });
99
100
  }
100
- protectedDirs.push({ scriptId: TOOLS, dir: scripts.library.toolsDir });
101
+ for (const dir of [scripts.library.toolsDir, ...scripts.library.formerToolsDirs])
102
+ protectedDirs.push({ scriptId: TOOLS, dir });
101
103
  protectedDirs.push({ scriptId: APP_FILES, dir: APP_FILES_DIR });
102
104
  return { protectedDirs, allowed: [...open.values()].flatMap((g) => g.dirs) };
103
105
  };
package/lib/intervene.js CHANGED
@@ -2,16 +2,19 @@ import { createRequire as __adgCreateRequire } from 'node:module'; import { dirn
2
2
  import {
3
3
  finalText,
4
4
  sessionConversations
5
- } from "./chunk-4PNYIZVU.js";
6
- import "./chunk-IZENRXQ6.js";
5
+ } from "./chunk-TWUATN5X.js";
6
+ import "./chunk-MEKSHT6V.js";
7
+ import "./chunk-FH64SAZU.js";
7
8
  import {
8
9
  writeFileAtomic
9
- } from "./chunk-CCAB6XXZ.js";
10
+ } from "./chunk-RESS7WVY.js";
10
11
  import {
11
12
  INTERVENE_CAPABILITY,
12
- UPDATE_RULE,
13
+ UPDATE_RULE
14
+ } from "./chunk-V2X4PLF5.js";
15
+ import {
13
16
  external_exports
14
- } from "./chunk-SA72K6M2.js";
17
+ } from "./chunk-SHTX4AGU.js";
15
18
  import "./chunk-2UFLGPDY.js";
16
19
 
17
20
  // packages/intervene/lib/index.js
@@ -27,6 +30,7 @@ var INTERVENE_ROLE = {
27
30
  description: "\u811A\u672C\u51FA\u9519\u3001\u5361\u4F4F\u65F6\u5904\u7406",
28
31
  order: 10,
29
32
  titles: ["\u5E72\u9884"],
33
+ handedImages: true,
30
34
  // The screen, the script's run and its settings; no installing, games or pipelines.
31
35
  tools: [
32
36
  "screen_*",
@@ -73,11 +77,41 @@ var Interventions = class {
73
77
  #bySession = /* @__PURE__ */ new Map();
74
78
  /** The latest screenshot of each recent session, for whoever wants to keep it as evidence. */
75
79
  #shots = /* @__PURE__ */ new Map();
80
+ /** How long each run has been held paused: past pauses' `total`, and `since` while one is going on. */
81
+ #held = /* @__PURE__ */ new Map();
76
82
  #seq = 0;
77
83
  constructor(deps) {
78
84
  this.#deps = deps;
79
85
  this.#now = deps.now ?? Date.now;
80
86
  }
87
+ /**
88
+ * How long interventions have held the run paused so far (the stretch going on included), and whether one is
89
+ * now: the monitor counts neither as the script's quiet time nor its running time.
90
+ */
91
+ heldPaused(runId) {
92
+ const held = this.#held.get(runId);
93
+ if (held === void 0)
94
+ return { ms: 0, now: false };
95
+ return { ms: held.total + (held.since === void 0 ? 0 : this.#now() - held.since), now: held.since !== void 0 };
96
+ }
97
+ /** Every change to whether an intervention holds its run paused goes through here, so `heldPaused` keeps time. */
98
+ #setPaused(item, paused) {
99
+ item.paused = paused;
100
+ if (item.runId === void 0)
101
+ return;
102
+ const held = this.#held.get(item.runId) ?? { total: 0 };
103
+ const now = this.#now();
104
+ if (paused)
105
+ held.since ??= now;
106
+ else if (held.since !== void 0) {
107
+ held.total += now - held.since;
108
+ held.since = void 0;
109
+ }
110
+ this.#held.delete(item.runId);
111
+ this.#held.set(item.runId, held);
112
+ while (this.#held.size > KEEP)
113
+ this.#held.delete(this.#held.keys().next().value);
114
+ }
81
115
  async load() {
82
116
  try {
83
117
  const saved = JSON.parse(await readFile(this.#file(), "utf8"));
@@ -148,14 +182,15 @@ var Interventions = class {
148
182
  if (result === "retry") {
149
183
  if (!await settle("retry"))
150
184
  await this.#deps.runner.restart(item.runId, `agent \u5904\u7406\u540E\u91CD\u65B0\u8FD0\u884C\uFF1A${summary}`);
151
- Object.assign(item, { state: "retried", paused: false });
185
+ item.state = "retried";
186
+ this.#setPaused(item, false);
152
187
  this.#changed(item);
153
188
  return "\u5DF2\u7ECF\u91CD\u65B0\u8FD0\u884C\u8FD9\u4E2A\u4EFB\u52A1\uFF08\u5F02\u5E38\u4E5F\u6807\u4E3A\u5DF2\u5904\u7406\uFF09\u3002\u73B0\u5728\u7ED3\u675F\u8FD9\u4E00\u8F6E\u56DE\u590D\u3002";
154
189
  }
155
190
  if (item.paused) {
156
191
  if (!await settle("resume"))
157
192
  await this.#resume(item);
158
- item.paused = false;
193
+ this.#setPaused(item, false);
159
194
  } else {
160
195
  await settle("resolve");
161
196
  }
@@ -224,7 +259,7 @@ var Interventions = class {
224
259
  this.#deps.log.warn(`pausing ${incident.runId} failed: ${String(error)}`);
225
260
  return 0;
226
261
  });
227
- item.paused = changed > 0;
262
+ this.#setPaused(item, changed > 0);
228
263
  if (item.paused)
229
264
  this.#deps.runner.note(incident.runId, "agent \u6B63\u5728\u5904\u7406\u5F02\u5E38\uFF0C\u811A\u672C\u5DF2\u6682\u505C");
230
265
  }
@@ -286,7 +321,7 @@ var Interventions = class {
286
321
  if (done.result === "retry") {
287
322
  try {
288
323
  await this.#deps.runner.restart(incident.runId, `agent \u5904\u7406\u540E\u91CD\u65B0\u8FD0\u884C\uFF1A${done.summary}`);
289
- item.paused = false;
324
+ this.#setPaused(item, false);
290
325
  return finish("retried", done.summary);
291
326
  } catch (error) {
292
327
  return finish("gave-up", `${done.summary}\uFF08\u91CD\u65B0\u8FD0\u884C\u6CA1\u6709\u6210\u529F\uFF1A${error instanceof Error ? error.message : String(error)}\uFF09`, imageOf(active, screenshot));
@@ -329,10 +364,10 @@ var Interventions = class {
329
364
  await this.#resume(item);
330
365
  else if (then === "restart") {
331
366
  await this.#deps.runner.restart(item.runId, "\u5904\u7406\u5B8C\u540E\u91CD\u65B0\u8FD0\u884C", { byUser: true });
332
- item.paused = false;
367
+ this.#setPaused(item, false);
333
368
  } else {
334
369
  await this.#deps.runner.stop(item.runId, "\u5904\u7406\u5F02\u5E38\u540E\u505C\u6B62");
335
- item.paused = false;
370
+ this.#setPaused(item, false);
336
371
  }
337
372
  this.#changed(item);
338
373
  return item;
@@ -352,7 +387,7 @@ var Interventions = class {
352
387
  const pid = this.#deps.runner.processId(item.runId);
353
388
  if (pid !== void 0)
354
389
  await this.#deps.suspend(pid, true);
355
- item.paused = false;
390
+ this.#setPaused(item, false);
356
391
  try {
357
392
  this.#deps.runner.note(item.runId, "\u5F02\u5E38\u5DF2\u5904\u7406\uFF0C\u811A\u672C\u7EE7\u7EED\u8FD0\u884C");
358
393
  } catch {
@@ -1517,12 +1552,18 @@ var AdgIntervene = class extends Service {
1517
1552
  return sessions === void 0 ? void 0 : sessionConversations(sessions, () => ctx.get("adgGateway")?.workspaceDir(), (id, f) => ctx.get("adgGateway")?.skillScope.setFocus(id, f) ?? Promise.resolve(), () => ctx.get("adgGateway"));
1518
1553
  },
1519
1554
  visionProblem: async () => {
1520
- const roleModel = ctx.get("adgGateway")?.roleModel(INTERVENE_ROLE.id);
1521
- const selection = roleModel ?? ctx.get("agentDefaultModel")?.currentSelection();
1522
- if (selection === void 0)
1555
+ const gateway = ctx.get("adgGateway");
1556
+ const own = gateway?.agentModel(INTERVENE_ROLE.id);
1557
+ const lead = own ?? ctx.get("agentDefaultModel")?.currentSelection();
1558
+ if (lead === void 0)
1523
1559
  return void 0;
1524
- const which = roleModel === void 0 ? "\u9ED8\u8BA4\u6A21\u578B" : "\u89D2\u8272 agent \u7684\u6A21\u578B";
1525
- return await sees(selection.provider, selection.model) ? void 0 : `${which} ${selection.model} \u4E0D\u80FD\u770B\u56FE\u7247\uFF0Cagent \u6CA1\u6CD5\u67E5\u770B\u622A\u56FE\uFF1B\u5728\u300C\u8BBE\u7F6E \u2192 \u6A21\u578B\u300D\u628A${which}\u6362\u6210\u80FD\u770B\u56FE\u7684\uFF08\u4F8B\u5982 Claude\u3001GPT-4o\u3001Gemini\u3001\u901A\u4E49 VL\uFF09`;
1560
+ const fix = "\u5728\u300C\u8BBE\u7F6E \u2192 \u6A21\u578B\u300D\u6362\u6210\u80FD\u770B\u56FE\u7684\uFF08\u4F8B\u5982 Claude\u3001GPT-4o\u3001Gemini\u3001\u901A\u4E49 VL\uFF09";
1561
+ if (!await sees(lead.provider, lead.model))
1562
+ return `${own === void 0 ? "\u9ED8\u8BA4\u6A21\u578B" : "\u300C\u5E72\u9884\u300D\u7684\u6A21\u578B"} ${lead.model} \u4E0D\u80FD\u770B\u56FE\u7247\uFF0Cagent \u6CA1\u6CD5\u67E5\u770B\u622A\u56FE\uFF1B${fix}`;
1563
+ const sub = gateway?.subAgentModel(INTERVENE_ROLE.id);
1564
+ if (sub !== void 0 && !await sees(sub.provider, sub.model))
1565
+ return `\u300C\u5E72\u9884\u300D\u7684\u5B50 agent \u7528\u7684 ${sub.model} \u4E0D\u80FD\u770B\u56FE\u7247\uFF0C\u6CA1\u6CD5\u622A\u56FE\u770B\u753B\u9762\uFF1B${fix}`;
1566
+ return void 0;
1526
1567
  },
1527
1568
  revealWindows: async (runId) => process.platform === "win32" ? (await screens.reveal(await ownerOf(runId))).windows : [],
1528
1569
  describeTargets: (run) => {
@@ -1648,6 +1689,10 @@ var AdgIntervene = class extends Service {
1648
1689
  resumeRun(runId) {
1649
1690
  return this.interventions.resumeRun(runId);
1650
1691
  }
1692
+ /** How long interventions have held the run paused, for the monitor's stall and overtime clocks. */
1693
+ heldPaused(runId) {
1694
+ return this.interventions.heldPaused(runId);
1695
+ }
1651
1696
  };
1652
1697
  var lib_default = AdgIntervene;
1653
1698
  export {
@@ -1,100 +1,84 @@
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
- LOW_CONTEXT_WINDOW_MS
4
- } from "./chunk-SA72K6M2.js";
3
+ ARCHIVE_BATCH_MS,
4
+ IDLE_COMPACT_MS,
5
+ MIN_PRUNE_CHARS,
6
+ MIN_SPAN_TOKENS,
7
+ Refusals,
8
+ SUMMARIES_FILE,
9
+ SummaryError,
10
+ apply,
11
+ archiveRange,
12
+ assemble,
13
+ coverOf,
14
+ eventText,
15
+ idleRange,
16
+ inject,
17
+ isMessage,
18
+ isPointer,
19
+ isSummaryNode,
20
+ keepSummaries,
21
+ lowContextRange,
22
+ name,
23
+ ownSummaries,
24
+ parseArchiveDays,
25
+ parseLowContext,
26
+ pointerStep,
27
+ pointerText,
28
+ prunableChars,
29
+ pruneStale,
30
+ refusedForSize,
31
+ settingsReader,
32
+ spanChars,
33
+ spanTokens,
34
+ summariesReader,
35
+ summarizeSpan,
36
+ summaryBudget,
37
+ summaryInstruction,
38
+ summaryTarget,
39
+ summaryText,
40
+ taskOver
41
+ } from "./chunk-FH64SAZU.js";
42
+ import "./chunk-V2X4PLF5.js";
43
+ import "./chunk-SHTX4AGU.js";
5
44
  import "./chunk-2UFLGPDY.js";
6
-
7
- // packages/gateway/lib/low-context.js
8
- import { readFileSync, statSync } from "node:fs";
9
- var name = "adg-low-context";
10
- var inject = ["compaction"];
11
- var isReplace = (event) => typeof event.surfaceOp === "object" && event.surfaceOp !== null;
12
- var sourceOf = (data) => data?.source ?? {};
13
- var TYPED = /* @__PURE__ */ new Set(["user", "user-rpc"]);
14
- var SENT = /* @__PURE__ */ new Set(["notice", "relay"]);
15
- function isMessage(event) {
16
- if (event.type !== "user/message" || isReplace(event))
17
- return false;
18
- const { kind, form } = sourceOf(event.data);
19
- return TYPED.has(String(kind)) || SENT.has(String(form));
20
- }
21
- function lowContextRange(session, options) {
22
- const nodes = session.surface.nodes;
23
- const events = nodes.map((seq) => session.eventAt(seq));
24
- const first = events[0]?.type === "system/message" ? 1 : 0;
25
- const messages = [];
26
- for (let i = first; i < events.length; i++)
27
- if (events[i] !== void 0 && isMessage(events[i]))
28
- messages.push(i);
29
- if (messages.length === 0)
30
- return null;
31
- const cutoff = options.now - (options.windowMs ?? LOW_CONTEXT_WINDOW_MS);
32
- const keepFrom = messages.find((i) => events[i].time >= cutoff) ?? messages[messages.length - 1];
33
- if (keepFrom <= first)
34
- return null;
35
- if (events.slice(first, keepFrom).every((event) => event === void 0 || isReplace(event) || event.type === "system/message"))
36
- return null;
37
- return { start: nodes[first], end: nodes[keepFrom - 1] };
38
- }
39
- function parseLowContext(raw) {
40
- return raw?.lowContext === true;
41
- }
42
- function settingsReader(file) {
43
- let stamp = "";
44
- let on = false;
45
- return () => {
46
- if (file === void 0)
47
- return on;
48
- try {
49
- const stat = statSync(file);
50
- const now = `${stat.mtimeMs}:${stat.size}`;
51
- if (now !== stamp) {
52
- stamp = now;
53
- on = parseLowContext(JSON.parse(readFileSync(file, "utf8")));
54
- }
55
- } catch {
56
- stamp = "";
57
- on = false;
58
- }
59
- return on;
60
- };
61
- }
62
- function taskOver(agent, work) {
63
- if ((agent.inbox?.nextTurn?.length ?? 0) > 0 || (agent.inbox?.nextStep?.length ?? 0) > 0)
64
- return false;
65
- return work?.workPending?.(agent.session.id) !== true;
66
- }
67
- function apply(ctx, config = {}) {
68
- const log = ctx.logger("adg-low-context");
69
- const enabled = settingsReader(config.file);
70
- const engine = ctx.compaction;
71
- if (typeof engine?.compactRegion !== "function") {
72
- log.warn("this dsh compaction has no compactRegion: low-context mode is off");
73
- return;
74
- }
75
- ctx.on("agent/turn-stopping", (async ({ agent, signal }) => {
76
- if (!enabled() || signal.aborted)
77
- return;
78
- try {
79
- if (!taskOver(agent, ctx.get("adgGateway")))
80
- return;
81
- const range = lowContextRange(agent.session, { now: Date.now() });
82
- if (range === null)
83
- return;
84
- const result = await engine.compactRegion(range.start, range.end, agent, signal);
85
- log.info(`low-context: compacted ${result.shadowedSeqs.length} records (seqs ${range.start}-${range.end}) of ${agent.session.id}`);
86
- } catch (error) {
87
- log.warn(`low-context compaction of ${agent.session.id} failed: ${error instanceof Error ? error.message : String(error)}`);
88
- }
89
- }));
90
- }
91
45
  export {
46
+ ARCHIVE_BATCH_MS,
47
+ IDLE_COMPACT_MS,
48
+ MIN_PRUNE_CHARS,
49
+ MIN_SPAN_TOKENS,
50
+ Refusals,
51
+ SUMMARIES_FILE,
52
+ SummaryError,
92
53
  apply,
54
+ archiveRange,
55
+ assemble,
56
+ coverOf,
57
+ eventText,
58
+ idleRange,
93
59
  inject,
94
60
  isMessage,
61
+ isPointer,
62
+ isSummaryNode,
63
+ keepSummaries,
95
64
  lowContextRange,
96
65
  name,
66
+ ownSummaries,
67
+ parseArchiveDays,
97
68
  parseLowContext,
69
+ pointerStep,
70
+ pointerText,
71
+ prunableChars,
72
+ pruneStale,
73
+ refusedForSize,
98
74
  settingsReader,
75
+ spanChars,
76
+ spanTokens,
77
+ summariesReader,
78
+ summarizeSpan,
79
+ summaryBudget,
80
+ summaryInstruction,
81
+ summaryTarget,
82
+ summaryText,
99
83
  taskOver
100
84
  };