dsh-multigameassistant 2.3.0 → 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.
- package/cordis.patch.yml +5 -9
- package/lib/analyzer.js +9 -9
- package/lib/{chunk-7EFZ5KR6.js → chunk-34VNH3YS.js} +57 -4
- package/lib/{chunk-VG32XPZH.js → chunk-4QXRDWGS.js} +22 -7
- package/lib/{chunk-X5YYRNYA.js → chunk-76UHR2GO.js} +74 -14
- package/lib/{chunk-TXW3NMBH.js → chunk-C7X2KJ5C.js} +1 -1
- package/lib/{chunk-AJMAUHPI.js → chunk-KW36B7DT.js} +124 -12
- package/lib/{chunk-Y3ZZBBLV.js → chunk-M7GNYL5B.js} +1 -1
- package/lib/{chunk-VBWSM7LF.js → chunk-QSETYM2Y.js} +634 -112
- package/lib/emulator.js +1 -1
- package/lib/feishu.js +4 -4
- package/lib/game-intel.js +52 -11
- package/lib/gateway.js +3 -3
- package/lib/guard.js +2 -2
- package/lib/intervene.js +5 -4
- package/lib/low-context.js +2 -2
- package/lib/monitor.js +3 -3
- package/lib/notify.js +4 -4
- package/lib/orchestrator.js +9 -8
- package/lib/qqbot.js +4 -4
- package/lib/runner.js +3 -3
- package/lib/scheduler.js +1 -1
- package/lib/script-registry.js +6 -6
- package/package.json +1 -1
- package/skills/pipeline-planning.md +2 -2
- package/skills/script-analysis.md +4 -3
- package/web/assets/index-O-2OxnhJ.css +1 -0
- package/web/assets/index-cNJNBRun.js +257 -0
- package/web/assets/index-cNJNBRun.js.map +1 -0
- package/web/index.html +2 -2
- package/web/assets/index-CNGPsX3a.css +0 -1
- package/web/assets/index-mX8hPa2E.js +0 -256
- package/web/assets/index-mX8hPa2E.js.map +0 -1
- /package/lib/{chunk-AJMAUHPI.js.LEGAL.txt → chunk-KW36B7DT.js.LEGAL.txt} +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
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
|
SUMMARIES_FILE,
|
|
4
|
+
eventText,
|
|
4
5
|
summariesReader
|
|
5
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-M7GNYL5B.js";
|
|
6
7
|
import {
|
|
7
8
|
writeFileAtomic
|
|
8
9
|
} from "./chunk-RESS7WVY.js";
|
|
@@ -12,8 +13,12 @@ import {
|
|
|
12
13
|
APP_FILES_RULE,
|
|
13
14
|
ARCHIVE_MARK,
|
|
14
15
|
AreaPolicy,
|
|
16
|
+
BRIEF_ALLOW,
|
|
17
|
+
BRIEF_DONE_WHEN,
|
|
18
|
+
BRIEF_LIMITS,
|
|
15
19
|
COMPACTION_CAPABILITY,
|
|
16
20
|
CompactionSettings,
|
|
21
|
+
DECISION_AREAS,
|
|
17
22
|
DEEPSEEK_API_KEY,
|
|
18
23
|
DEFAULT_COMPACTION_THRESHOLD,
|
|
19
24
|
ErrorCode,
|
|
@@ -40,11 +45,13 @@ import {
|
|
|
40
45
|
SUMMARY_MAX_TOKENS,
|
|
41
46
|
areaOf,
|
|
42
47
|
classify,
|
|
48
|
+
decisionOf,
|
|
49
|
+
grantsIn,
|
|
43
50
|
personaOf,
|
|
44
51
|
personaPrompt,
|
|
45
52
|
threadsBetween,
|
|
46
53
|
timetableText
|
|
47
|
-
} from "./chunk-
|
|
54
|
+
} from "./chunk-34VNH3YS.js";
|
|
48
55
|
import {
|
|
49
56
|
external_exports
|
|
50
57
|
} from "./chunk-6DSSLS7I.js";
|
|
@@ -3726,9 +3733,9 @@ var require_websocket_server = __commonJS({
|
|
|
3726
3733
|
|
|
3727
3734
|
// packages/gateway/lib/index.js
|
|
3728
3735
|
import { execFile as execFile2 } from "node:child_process";
|
|
3729
|
-
import { randomBytes as randomBytes2, randomUUID as
|
|
3730
|
-
import { existsSync, mkdirSync as
|
|
3731
|
-
import { dirname as
|
|
3736
|
+
import { randomBytes as randomBytes2, randomUUID as randomUUID6 } from "node:crypto";
|
|
3737
|
+
import { existsSync, mkdirSync as mkdirSync7, readFileSync as readFileSync4, writeFileSync } from "node:fs";
|
|
3738
|
+
import { dirname as dirname8, join as join9 } from "node:path";
|
|
3732
3739
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
3733
3740
|
import { Service } from "@deepseek-ai/cordis";
|
|
3734
3741
|
|
|
@@ -4272,13 +4279,13 @@ var ApprovalBroker = class {
|
|
|
4272
4279
|
...ask.reason === void 0 ? {} : { reason: ask.reason },
|
|
4273
4280
|
...ask.displayReason === void 0 ? {} : { displayReason: { ...ask.displayReason } }
|
|
4274
4281
|
};
|
|
4275
|
-
return new Promise((
|
|
4282
|
+
return new Promise((resolve5) => {
|
|
4276
4283
|
const onAbort = () => this.settle(approvalId, "cancelled");
|
|
4277
4284
|
this.pending.set(approvalId, {
|
|
4278
4285
|
request,
|
|
4279
4286
|
settle: (outcome) => {
|
|
4280
4287
|
ask.signal?.removeEventListener("abort", onAbort);
|
|
4281
|
-
|
|
4288
|
+
resolve5(outcome);
|
|
4282
4289
|
}
|
|
4283
4290
|
});
|
|
4284
4291
|
ask.signal?.addEventListener("abort", onAbort, { once: true });
|
|
@@ -4430,10 +4437,10 @@ async function importUnchanged(dir, item) {
|
|
|
4430
4437
|
}
|
|
4431
4438
|
async function copyHash(folder) {
|
|
4432
4439
|
const { createHash } = await import("node:crypto");
|
|
4433
|
-
const { readdir:
|
|
4440
|
+
const { readdir: readdir3 } = await import("node:fs/promises");
|
|
4434
4441
|
const files = [];
|
|
4435
4442
|
const walk = async (sub) => {
|
|
4436
|
-
for (const entry of await
|
|
4443
|
+
for (const entry of await readdir3(join(folder, sub), { withFileTypes: true })) {
|
|
4437
4444
|
const rel = sub === "" ? entry.name : `${sub}/${entry.name}`;
|
|
4438
4445
|
if (entry.isDirectory()) {
|
|
4439
4446
|
if (!SKIPPED.test(entry.name))
|
|
@@ -4465,7 +4472,7 @@ function skillSaveTool(deps) {
|
|
|
4465
4472
|
"content \u5199\u6D53\u7F29\u540E\u7684\u505A\u6CD5\uFF1A\u4EC0\u4E48\u65F6\u5019\u7528\uFF1B\u4E00\u6B65\u4E00\u6B65\u7684\u64CD\u4F5C\uFF08\u7528\u5230\u7684\u5DE5\u5177\u3001\u547D\u4EE4\u3001\u8DEF\u5F84\u3001\u53C2\u6570\u7167\u5B9E\u5199\uFF09\uFF1B\u5224\u65AD\u6210\u529F\u7684\u65B9\u6CD5\uFF1B\u8E29\u8FC7\u7684\u5751\u548C\u6CE8\u610F\u4E8B\u9879\u3002\u4E0D\u5199\u8FD9\u6B21\u5BF9\u8BDD\u7684\u95F2\u804A\u548C\u5931\u8D25\u7684\u5C1D\u8BD5\u8FC7\u7A0B\uFF0C\u53EA\u5199\u6700\u540E\u8D70\u901A\u7684\u8DEF\u3002",
|
|
4466
4473
|
"description \u4E00\u4E24\u53E5\u8BDD\u5199\u6E05\u695A\u300C\u505A\u4EC0\u4E48\u3001\u7528\u6237\u8BF4\u4EC0\u4E48\u65F6\u7528\u300D\uFF0Cagent \u9760\u5B83\u51B3\u5B9A\u4EC0\u4E48\u65F6\u5019\u8C03\u7528\u3002\u5DF2\u6709\u540C\u540D\u6280\u80FD\u65F6\u5148\u7528 replace=true \u624D\u4F1A\u8986\u76D6\u3002",
|
|
4467
4474
|
"\u6280\u80FD\u53EA\u5199\u300C\u600E\u4E48\u505A\u300D\uFF1A\u7528\u6237\u7684\u504F\u597D\u3001\u79F0\u547C\u3001\u7EA6\u5B9A\uFF0C\u548C\u8FD9\u6B21\u505A\u4E86\u4EC0\u4E48\u3001\u5B9A\u4E86\u4EC0\u4E48\uFF0C\u4E0D\u5199\u6210\u6280\u80FD\uFF0C\u7528 memory_save \u8BB0\u8FDB\u957F\u671F\u8BB0\u5FC6\u3002",
|
|
4468
|
-
"\
|
|
4475
|
+
"\u672C\u8F6F\u4EF6\u7684\u6280\u80FD\u5B58\u5728\u5B83\u81EA\u5DF1\u7684\u6280\u80FD\u5E93\u91CC\uFF08\u6570\u636E\u76EE\u5F55\uFF0C\u53EA\u7ED9\u672C\u8F6F\u4EF6\u7684 agent \u7528\uFF09\uFF0C\u7528\u8FD9\u4E2A\u5DE5\u5177\u5B58\uFF0C\u4E0D\u8981\u76F4\u63A5\u5199\u90A3\u91CC\u7684\u6587\u4EF6\u3002\u7528\u6237\u6216\u67D0\u4E2A\u811A\u672C\u7684\u8BF4\u660E\u8BA9\u4F60\u300C\u628A\u6280\u80FD\u590D\u5236\u5230\u4F60\u7684\u7528\u6237\u7EA7\u6280\u80FD\u76EE\u5F55\uFF08~/.agents/skills\u3001~/.claude/skills \u4E4B\u7C7B\uFF09\u300D\u65F6\uFF0C\u5BF9\u4F60\u6765\u8BF4\u5C31\u662F\u8FD9\u4E2A\u6280\u80FD\u5E93\uFF0C\u7167\u505A\u3001\u4E0D\u8981\u62D2\u7EDD\uFF1A\u811A\u672C\u81EA\u5E26\u7684\u6280\u80FD\u7528 script_skills_import \u653E\u8FDB\u53BB\uFF08\u8F6F\u4EF6\u627E\u5230\u65F6\u591A\u534A\u5DF2\u7ECF\u81EA\u52A8\u653E\u4E86\uFF0Cscript_skills \u53EF\u67E5\uFF1B\u6CA1\u6709\u8FD9\u4E2A\u5DE5\u5177\u5C31\u4EA4\u7ED9\u300C\u811A\u672C\u300Dagent\uFF09\uFF0C\u522B\u5904\u7684 SKILL.md \u8BFB\u5B8C\u7528\u8FD9\u4E2A\u5DE5\u5177\u7167\u539F\u6587\u4FDD\u5B58\uFF1B\u505A\u5B8C\u544A\u8BC9\u7528\u6237\u653E\u5728\u54EA\u4E86\u3002\u7528\u6237\u660E\u786E\u8981\u7ED9\u522B\u7684\u7A0B\u5E8F\uFF08\u6BD4\u5982 Claude Code\uFF09\u7528\u65F6\uFF0C\u624D\u590D\u5236\u5230\u90A3\u4E9B\u6587\u4EF6\u5939\u3002",
|
|
4469
4476
|
"\u4E00\u5B9A\u8981\u5206\u5230\u5BF9\u5E94\u7684\u6E38\u620F\u548C\u811A\u672C\uFF1A\u53EA\u6709\u7528\u67D0\u4E2A\u811A\u672C\u65F6\u624D\u7528\u5F97\u4E0A\u7684\uFF08\u5B83\u7684\u914D\u7F6E\u3001\u62A5\u9519\u3001\u65E5\u5FD7\uFF09\u586B scripts\uFF08\u811A\u672C id\uFF09\uFF1B\u548C\u6E38\u620F\u672C\u8EAB\u6709\u5173\u3001\u6362\u4E2A\u811A\u672C\u4E5F\u7528\u5F97\u4E0A\u7684\uFF08\u6E38\u620F\u91CC\u7684\u64CD\u4F5C\u3001\u754C\u9762\u3001\u6D3B\u52A8\u3001\u673A\u5236\uFF09\u586B games\uFF08\u6E38\u620F id\uFF0Cgame_list \u53EF\u67E5\uFF09\uFF0C\u4E0D\u586B scripts\u3002\u8FD9\u6837\u5B83\u53EA\u5728\u5904\u7406\u8FD9\u4E2A\u811A\u672C\u6216\u6E38\u620F\u65F6\u51FA\u73B0\uFF0C\u4E0D\u4F1A\u88AB\u62FF\u53BB\u7528\u5728\u522B\u7684\u811A\u672C\u3001\u522B\u7684\u6E38\u620F\u4E0A\uFF0C\u300C\u6280\u80FD\u300D\u9875\u4E5F\u6309\u6E38\u620F\u5F52\u597D\u7C7B\u3002\u548C\u54EA\u4E2A\u6E38\u620F\u90FD\u65E0\u5173\u7684\u901A\u7528\u505A\u6CD5\u4E24\u4E2A\u90FD\u4E0D\u586B\u3002"
|
|
4470
4477
|
].join(""),
|
|
4471
4478
|
parameters: {
|
|
@@ -4492,8 +4499,8 @@ function skillSaveTool(deps) {
|
|
|
4492
4499
|
};
|
|
4493
4500
|
}
|
|
4494
4501
|
async function userSkills(dir) {
|
|
4495
|
-
const { readdir:
|
|
4496
|
-
const entries = await
|
|
4502
|
+
const { readdir: readdir3 } = await import("node:fs/promises");
|
|
4503
|
+
const entries = await readdir3(dir, { withFileTypes: true }).catch(() => []);
|
|
4497
4504
|
const out = [];
|
|
4498
4505
|
for (const entry of entries) {
|
|
4499
4506
|
if (!entry.isDirectory())
|
|
@@ -4541,6 +4548,8 @@ var PROVIDER = "adg";
|
|
|
4541
4548
|
var RANK = 250;
|
|
4542
4549
|
var MAX_SESSIONS = 1e3;
|
|
4543
4550
|
var INVOCABLE = { modelInvocable: true, userInvocable: true };
|
|
4551
|
+
var SHADOWED_SKILLS = ["diagnose-windows-sandbox-acl", "office", "office-docx", "office-pptx", "office-xlsx"];
|
|
4552
|
+
var OFF = { modelInvocable: false, userInvocable: false };
|
|
4544
4553
|
var norm = (value) => value.trim().toLowerCase();
|
|
4545
4554
|
var SkillScope = class {
|
|
4546
4555
|
#skills = /* @__PURE__ */ new Map();
|
|
@@ -4552,6 +4561,7 @@ var SkillScope = class {
|
|
|
4552
4561
|
#invalidate = () => {
|
|
4553
4562
|
};
|
|
4554
4563
|
#relations = () => ({ aliases: [], games: [] });
|
|
4564
|
+
#gameOf = () => void 0;
|
|
4555
4565
|
#loaded;
|
|
4556
4566
|
#saving = Promise.resolve();
|
|
4557
4567
|
log;
|
|
@@ -4571,9 +4581,10 @@ var SkillScope = class {
|
|
|
4571
4581
|
if (session !== void 0 && this.#only?.(session) === false)
|
|
4572
4582
|
return [];
|
|
4573
4583
|
const focus = this.focusOf(session);
|
|
4574
|
-
|
|
4584
|
+
const own2 = [...this.#skills.values()].filter((skill) => focus === void 0 || this.visible(skill.owner, focus)).map(candidate);
|
|
4585
|
+
return [...own2, ...SHADOWED_SKILLS.filter((name) => !this.#skills.has(name)).map(shadow)];
|
|
4575
4586
|
},
|
|
4576
|
-
get: async ({ locator }) => definition(locator)
|
|
4587
|
+
get: async ({ locator }) => typeof locator === "string" ? void 0 : definition(locator)
|
|
4577
4588
|
};
|
|
4578
4589
|
}
|
|
4579
4590
|
/** A sub-agent works on what its parent is working on, until it says otherwise. */
|
|
@@ -4589,8 +4600,17 @@ var SkillScope = class {
|
|
|
4589
4600
|
* What else a script in a focus stands for: its pack's id (the pack's skill
|
|
4590
4601
|
* names that), and the games it plays, whose skills it sees too.
|
|
4591
4602
|
*/
|
|
4592
|
-
resolveScripts(
|
|
4593
|
-
this.#relations =
|
|
4603
|
+
resolveScripts(resolve5) {
|
|
4604
|
+
this.#relations = resolve5;
|
|
4605
|
+
this.#invalidate();
|
|
4606
|
+
}
|
|
4607
|
+
/**
|
|
4608
|
+
* Which game a key names (its id, name or an alias): its id; undefined when no game is known by it.
|
|
4609
|
+
* A skill saved for `starrail` then shows where the focus says 星铁, or 崩坏:星穹铁道 (as a script's
|
|
4610
|
+
* pack names the game it plays). Called again when the games change.
|
|
4611
|
+
*/
|
|
4612
|
+
resolveGames(gameOf) {
|
|
4613
|
+
this.#gameOf = gameOf;
|
|
4594
4614
|
this.#invalidate();
|
|
4595
4615
|
}
|
|
4596
4616
|
/**
|
|
@@ -4671,8 +4691,9 @@ var SkillScope = class {
|
|
|
4671
4691
|
const focusScripts = new Set([...focus.scripts, ...related.flatMap((r) => r.aliases)].map(norm));
|
|
4672
4692
|
if (scripts.some((s) => focusScripts.has(norm(s))))
|
|
4673
4693
|
return true;
|
|
4674
|
-
const
|
|
4675
|
-
|
|
4694
|
+
const game = (key) => norm(this.#gameOf(key) ?? key);
|
|
4695
|
+
const focusGames = new Set([...focus.games, ...related.flatMap((r) => r.games)].map(game));
|
|
4696
|
+
return games.some((g) => focusGames.has(game(g)));
|
|
4676
4697
|
}
|
|
4677
4698
|
async #load() {
|
|
4678
4699
|
if (this.#file === void 0)
|
|
@@ -4711,6 +4732,9 @@ function candidate(skill) {
|
|
|
4711
4732
|
locator: skill
|
|
4712
4733
|
};
|
|
4713
4734
|
}
|
|
4735
|
+
function shadow(name) {
|
|
4736
|
+
return { name, description: "\uFF08\u8FD9\u4E2A\u8F6F\u4EF6\u4E0D\u7528\u8FD9\u4E2A\u6280\u80FD\uFF09", invocation: OFF, source: "adg", provider: PROVIDER, rank: RANK, locator: name };
|
|
4737
|
+
}
|
|
4714
4738
|
function definition(skill) {
|
|
4715
4739
|
return {
|
|
4716
4740
|
name: skill.name,
|
|
@@ -5150,6 +5174,9 @@ function looksSecret(text) {
|
|
|
5150
5174
|
}
|
|
5151
5175
|
return false;
|
|
5152
5176
|
}
|
|
5177
|
+
function maskSecrets(text) {
|
|
5178
|
+
return text.replace(/((?:密码|口令|验证码|动态码|password|passwd|passcode|pwd|token|api[\s_-]?key|secret|私钥|cookie)\s*(?:是|为|[::=])\s*)[^\s,。;、!?,;!?))」'"]{4,}/gi, "$1***").replace(/\b(?:sk-[A-Za-z0-9_-]{16,}|gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|AKIA[0-9A-Z]{16}|xox[abpr]-[A-Za-z0-9-]{10,}|eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}(?:\.[A-Za-z0-9_-]+)?)/g, "***").replace(/[A-Za-z0-9+/_=-]{32,}/g, (blob) => !/^[0-9a-f]+$/i.test(blob) && /[a-z]/.test(blob) && /[A-Z]/.test(blob) && /[0-9]/.test(blob) ? "***" : blob);
|
|
5179
|
+
}
|
|
5153
5180
|
var SECRET_REFUSAL = "\u8FD9\u6761\u50CF\u662F\u5BC6\u7801\u3001\u9A8C\u8BC1\u7801\u6216\u5BC6\u94A5\uFF1A\u8FD9\u7C7B\u4E1C\u897F\u4E0D\u5199\u8FDB\u8BB0\u5FC6\uFF08\u7528\u6237\u8BA9\u8BB0\u4E5F\u4E0D\u8BB0\uFF09\u3002\u628A\u5B83\u53BB\u6389\u518D\u8BB0\uFF0C\u6216\u8005\u544A\u8BC9\u7528\u6237\u4E3A\u4EC0\u4E48\u4E0D\u8BB0\u3002";
|
|
5154
5181
|
var MemoryStore = class {
|
|
5155
5182
|
#file;
|
|
@@ -6407,8 +6434,344 @@ var AutoMemory = class {
|
|
|
6407
6434
|
}
|
|
6408
6435
|
};
|
|
6409
6436
|
|
|
6410
|
-
// packages/gateway/lib/
|
|
6437
|
+
// packages/gateway/lib/history-export.js
|
|
6438
|
+
import { mkdir as mkdir5, readdir, writeFile as writeFile4 } from "node:fs/promises";
|
|
6439
|
+
import { isAbsolute as isAbsolute2, join as join6, resolve as resolve2 } from "node:path";
|
|
6440
|
+
var EXPORT_DEPTH = 2e4;
|
|
6441
|
+
var Args3 = external_exports.object({
|
|
6442
|
+
path: external_exports.string().trim().min(1),
|
|
6443
|
+
since: external_exports.string().trim().min(1),
|
|
6444
|
+
until: external_exports.string().trim().min(1).nullish(),
|
|
6445
|
+
session_id: external_exports.string().nullish(),
|
|
6446
|
+
with_agents: external_exports.boolean().nullish(),
|
|
6447
|
+
parts: external_exports.array(external_exports.string()).nullish()
|
|
6448
|
+
});
|
|
6449
|
+
function parseWhen(text, now) {
|
|
6450
|
+
const t = text.trim().replace(/\//g, "-");
|
|
6451
|
+
if (/(z|[+-]\d{2}:?\d{2})$/i.test(t)) {
|
|
6452
|
+
const at = Date.parse(t);
|
|
6453
|
+
if (!Number.isNaN(at))
|
|
6454
|
+
return at;
|
|
6455
|
+
}
|
|
6456
|
+
const full = /^(\d{4})-(\d{1,2})-(\d{1,2})(?:[ T](\d{1,2}):(\d{2})(?::(\d{2}))?)?$/.exec(t);
|
|
6457
|
+
if (full !== null) {
|
|
6458
|
+
const [, y, mo, d, h = "0", mi = "0", s = "0"] = full;
|
|
6459
|
+
return new Date(Number(y), Number(mo) - 1, Number(d), Number(h), Number(mi), Number(s)).getTime();
|
|
6460
|
+
}
|
|
6461
|
+
const time = /^(?:(今天|今日|today|昨天|昨日|yesterday)\s*的?\s*)?(\d{1,2})[::](\d{2})(?:[::](\d{2}))?$/i.exec(t);
|
|
6462
|
+
if (time !== null) {
|
|
6463
|
+
const day2 = new Date(now);
|
|
6464
|
+
const back = /^(昨|yesterday)/i.test(time[1] ?? "") ? 1 : 0;
|
|
6465
|
+
return new Date(day2.getFullYear(), day2.getMonth(), day2.getDate() - back, Number(time[2]), Number(time[3]), Number(time[4] ?? 0)).getTime();
|
|
6466
|
+
}
|
|
6467
|
+
throw new Error(`\u770B\u4E0D\u61C2\u8FD9\u4E2A\u65F6\u95F4\uFF1A${text}\uFF08\u5199\u6210 2026-11-29 15:00\uFF1B\u4ECA\u5929\u7684\u53EF\u4EE5\u53EA\u5199 15:00\uFF09`);
|
|
6468
|
+
}
|
|
6469
|
+
function clock2(time, timeZone, seconds = false) {
|
|
6470
|
+
const parts = new Intl.DateTimeFormat("en-CA", { timeZone, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", ...seconds ? { second: "2-digit" } : {}, hourCycle: "h23" }).formatToParts(new Date(time));
|
|
6471
|
+
const get = (type) => parts.find((p) => p.type === type)?.value ?? "";
|
|
6472
|
+
return `${get("year")}-${get("month")}-${get("day")} ${get("hour")}:${get("minute")}${seconds ? `:${get("second")}` : ""}`;
|
|
6473
|
+
}
|
|
6474
|
+
async function freshFolder(path) {
|
|
6475
|
+
for (let n = 1; n < 1e3; n++) {
|
|
6476
|
+
const candidate2 = n === 1 ? path : `${path}-${n}`;
|
|
6477
|
+
const entries = await readdir(candidate2).catch((error) => error.code === "ENOENT" ? null : Promise.reject(error));
|
|
6478
|
+
if (entries === null || entries.length === 0) {
|
|
6479
|
+
await mkdir5(candidate2, { recursive: true });
|
|
6480
|
+
return candidate2;
|
|
6481
|
+
}
|
|
6482
|
+
}
|
|
6483
|
+
throw new Error(`${path} \u65C1\u8FB9\u5DF2\u7ECF\u6709\u592A\u591A\u5BFC\u51FA\u4E86\uFF0C\u6362\u4E2A\u6587\u4EF6\u5939`);
|
|
6484
|
+
}
|
|
6485
|
+
function chatMarkdown(said, names, timeZone, mask) {
|
|
6486
|
+
return said.map((s) => `### ${s.from === "user" ? names.user : s.from === "agent" ? names.agent : names.app} \xB7 ${clock2(s.time, timeZone, true)}
|
|
6487
|
+
|
|
6488
|
+
${mask(s.text)}
|
|
6489
|
+
`).join("\n");
|
|
6490
|
+
}
|
|
6491
|
+
function historyExportTool(deps) {
|
|
6492
|
+
const render4 = (_args, value) => [{ type: "text", text: JSON.stringify(value, null, 1) }];
|
|
6493
|
+
return {
|
|
6494
|
+
name: "history_export",
|
|
6495
|
+
description: [
|
|
6496
|
+
"\u628A\u4E00\u6BB5\u65F6\u95F4\u91CC\u7684\u804A\u5929\u8BB0\u5F55\u548C\u76F8\u5173\u65E5\u5FD7\u5BFC\u51FA\u5230\u7528\u6237\u6307\u5B9A\u7684\u6587\u4EF6\u5939\uFF1A\u7528\u6237\u8BF4\u300C\u628A\u4ECA\u5929\u4E0B\u5348\u4E09\u70B9\u4E4B\u540E\u7684\u65E5\u5FD7\u548C\u804A\u5929\u8BB0\u5F55\u653E\u5230\u67D0\u4E2A\u6587\u4EF6\u5939\u300D\u65F6\u7528\u5B83\uFF0C\u4E00\u6B21\u8C03\u7528\u5C31\u505A\u5B8C\uFF0C\u4E0D\u8981\u81EA\u5DF1\u53BB\u7FFB\u8F6F\u4EF6\u7684\u6570\u636E\u76EE\u5F55\u548C\u4F1A\u8BDD\u6587\u4EF6\u3002",
|
|
6497
|
+
"\u804A\u5929\u8BB0\u5F55\u662F\u8FD9\u4E2A\u5BF9\u8BDD\u91CC\u7528\u6237\u548C\u4F60\u8BF4\u7684\u8BDD\uFF08with_agents \u4E3A true \u65F6\u4E5F\u5E26\u4E0A\u8F6F\u4EF6\u548C\u5176\u4ED6 agent \u53D1\u6765\u7684\u6D88\u606F\uFF09\uFF0C\u4E0D\u542B\u7CFB\u7EDF\u63D0\u793A\u3001\u6280\u80FD\u76EE\u5F55\u3001\u5DE5\u5177\u8C03\u7528\u548C\u538B\u7F29\u6458\u8981\uFF1B",
|
|
6498
|
+
"\u518D\u52A0\u4E0A\u8F6F\u4EF6\u5176\u4ED6\u90E8\u5206\u5728\u8FD9\u6BB5\u65F6\u95F4\u7684\u8BB0\u5F55\uFF08parts\uFF0C\u9ED8\u8BA4\u5168\u90E8\uFF0C\u4F8B\u5982 runs\uFF1A\u811A\u672C\u8FD0\u884C\u65E5\u5FD7\uFF09\u3002\u5BC6\u7801\u3001\u9A8C\u8BC1\u7801\u3001\u5BC6\u94A5\u4F1A\u906E\u76D6\u3002",
|
|
6499
|
+
"path \u5199\u7528\u6237\u6307\u5B9A\u7684\u6587\u4EF6\u5939\uFF08\u5B8C\u6574\u8DEF\u5F84\uFF09\uFF1A\u5DF2\u7ECF\u6709\u4E1C\u897F\u65F6\u4F1A\u53E6\u5EFA <\u6587\u4EF6\u5939>-2\uFF0C\u4E0D\u4F1A\u8986\u76D6\uFF1B\u4E0D\u80FD\u5199\u8FDB\u811A\u672C\u76EE\u5F55\u6216\u672C\u8F6F\u4EF6\u81EA\u5DF1\u7684\u76EE\u5F55\u3002\u7528\u6237\u6CA1\u8BF4\u653E\u54EA\u5C31\u5148\u95EE\u3002"
|
|
6500
|
+
].join(""),
|
|
6501
|
+
parameters: {
|
|
6502
|
+
type: "object",
|
|
6503
|
+
properties: {
|
|
6504
|
+
path: { type: "string", description: "\u5BFC\u51FA\u5230\u54EA\u4E2A\u6587\u4EF6\u5939\uFF08\u5B8C\u6574\u8DEF\u5F84\uFF09\u3002" },
|
|
6505
|
+
since: { type: "string", description: "\u4ECE\u4EC0\u4E48\u65F6\u5019\u8D77\uFF08\u672C\u673A\u65F6\u95F4\uFF09\uFF1A\u5199\u6210 2026-11-29 15:00\uFF1B\u4ECA\u5929\u7684\u53EF\u4EE5\u53EA\u5199 15:00\u3002" },
|
|
6506
|
+
until: { type: "string", description: "\u5230\u4EC0\u4E48\u65F6\u5019\uFF08\u53EF\u9009\uFF0C\u9ED8\u8BA4\u73B0\u5728\uFF09\u3002" },
|
|
6507
|
+
session_id: { type: "string", description: "\u54EA\u4E2A\u5BF9\u8BDD\uFF08\u53EF\u9009\uFF0C\u9ED8\u8BA4\u8FD9\u4E2A\u5BF9\u8BDD\uFF1B\u53EA\u80FD\u662F\u4F60\u81EA\u5DF1\u7684\u5BF9\u8BDD\uFF09\u3002" },
|
|
6508
|
+
with_agents: { type: "boolean", description: "\u4E5F\u5BFC\u51FA\u8F6F\u4EF6\u548C\u5176\u4ED6 agent \u53D1\u6765\u7684\u6D88\u606F\uFF08\u4EA4\u56DE\u7684\u7ED3\u679C\u3001\u901A\u77E5\uFF09\uFF0C\u9ED8\u8BA4\u53EA\u5BFC\u51FA\u7528\u6237\u548C\u4F60\u8BF4\u7684\u8BDD\u3002" },
|
|
6509
|
+
parts: { type: "array", items: { type: "string" }, description: "\u8FD8\u5BFC\u51FA\u54EA\u4E9B\u8BB0\u5F55\uFF08\u9ED8\u8BA4\u5168\u90E8\uFF1B[] \u53EA\u5BFC\u51FA\u804A\u5929\u8BB0\u5F55\uFF09\u3002" }
|
|
6510
|
+
},
|
|
6511
|
+
required: ["path", "since"],
|
|
6512
|
+
additionalProperties: false
|
|
6513
|
+
},
|
|
6514
|
+
output: { schema: {}, render: render4 },
|
|
6515
|
+
timeoutMs: 12e4,
|
|
6516
|
+
isConcurrencySafe: () => false,
|
|
6517
|
+
execute: async (args, exec) => {
|
|
6518
|
+
const parsed = Args3.safeParse(args ?? {});
|
|
6519
|
+
if (!parsed.success)
|
|
6520
|
+
throw new Error(`\u53C2\u6570\u65E0\u6548\uFF1A${parsed.error.issues.map((i) => `${i.path.join(".") || "(root)"} ${i.message}`).join("; ")}`);
|
|
6521
|
+
const a = parsed.data;
|
|
6522
|
+
const session = exec.agent?.session.id;
|
|
6523
|
+
const agent = session === void 0 ? void 0 : deps.agentOf(session);
|
|
6524
|
+
if (session === void 0 || agent === void 0)
|
|
6525
|
+
throw new Error("\u53EA\u6709\u672C\u8F6F\u4EF6\u7684 agent \u80FD\u5BFC\u51FA\u5BF9\u8BDD\u8BB0\u5F55");
|
|
6526
|
+
const signal = exec.signal ?? new AbortController().signal;
|
|
6527
|
+
const now = deps.now?.() ?? Date.now();
|
|
6528
|
+
const since = parseWhen(a.since, now);
|
|
6529
|
+
const until = a.until == null ? now : parseWhen(a.until, now);
|
|
6530
|
+
if (until <= since)
|
|
6531
|
+
throw new Error("\u7ED3\u675F\u65F6\u95F4\u8981\u665A\u4E8E\u5F00\u59CB\u65F6\u95F4");
|
|
6532
|
+
if (!isAbsolute2(a.path))
|
|
6533
|
+
throw new Error("path \u8981\u5199\u5B8C\u6574\u8DEF\u5F84\uFF08\u4F8B\u5982 D:\\\u5BFC\u51FA\\\u804A\u5929\u8BB0\u5F55\uFF09");
|
|
6534
|
+
const target = a.session_id ?? session;
|
|
6535
|
+
if (target !== session && !(await deps.sessions(agent, signal)).some((s) => s.id === target))
|
|
6536
|
+
throw new Error(`\u6CA1\u6709\u8FD9\u4E2A\u5BF9\u8BDD\uFF1A${target}\uFF08\u53EA\u80FD\u5BFC\u51FA\u4F60\u81EA\u5DF1\u7684\u5BF9\u8BDD\uFF09`);
|
|
6537
|
+
const known = deps.parts();
|
|
6538
|
+
const wanted = a.parts == null ? known : known.filter((p) => a.parts.includes(p.name));
|
|
6539
|
+
const unknown = (a.parts ?? []).filter((n) => !known.some((p) => p.name === n));
|
|
6540
|
+
if (unknown.length > 0)
|
|
6541
|
+
throw new Error(`\u6CA1\u6709\u8FD9\u4E9B\u8BB0\u5F55\uFF1A${unknown.join("\u3001")}\uFF08\u6709\uFF1A${known.map((p) => `${p.name}\uFF08${p.title}\uFF09`).join("\u3001") || "\u6CA1\u6709"}\uFF09`);
|
|
6542
|
+
const said = saidIn(await deps.read(target, EXPORT_DEPTH, signal)).filter((s) => s.time >= since && s.time < until && s.summary !== true && (a.with_agents === true || s.from !== "app"));
|
|
6543
|
+
const folder = await freshFolder(resolve2(a.path));
|
|
6544
|
+
const files = [];
|
|
6545
|
+
const put = async (name, text) => {
|
|
6546
|
+
await writeFile4(join6(folder, name), text, "utf8");
|
|
6547
|
+
files.push({ path: name, bytes: Buffer.byteLength(text) });
|
|
6548
|
+
};
|
|
6549
|
+
const range = `${clock2(since, deps.timeZone)} \uFF5E ${clock2(until, deps.timeZone)}`;
|
|
6550
|
+
const agentName = deps.nameOf(agent);
|
|
6551
|
+
await put("\u804A\u5929\u8BB0\u5F55.md", `# \u804A\u5929\u8BB0\u5F55\uFF08${range}\uFF09
|
|
6552
|
+
|
|
6553
|
+
${said.length === 0 ? "\u8FD9\u6BB5\u65F6\u95F4\u8FD9\u4E2A\u5BF9\u8BDD\u91CC\u6CA1\u6709\u6D88\u606F\u3002\n" : chatMarkdown(said, { user: "\u7528\u6237", agent: agentName, app: "\u8F6F\u4EF6/\u5176\u4ED6 agent" }, deps.timeZone, maskSecrets)}`);
|
|
6554
|
+
const done = [];
|
|
6555
|
+
for (const part of wanted) {
|
|
6556
|
+
signal.throwIfAborted();
|
|
6557
|
+
try {
|
|
6558
|
+
const r = await part.write({ since, until }, join6(folder, part.name), { mask: maskSecrets, signal });
|
|
6559
|
+
done.push({ name: part.name, title: part.title, ...r });
|
|
6560
|
+
} catch (error) {
|
|
6561
|
+
done.push({ name: part.name, title: part.title, files: 0, summary: `\u6CA1\u5BFC\u51FA\uFF1A${error instanceof Error ? error.message : String(error)}` });
|
|
6562
|
+
}
|
|
6563
|
+
}
|
|
6564
|
+
const count = (from) => said.filter((s) => s.from === from).length;
|
|
6565
|
+
await put("README.md", [
|
|
6566
|
+
`# \u5BFC\u51FA\uFF1A${range}`,
|
|
6567
|
+
"",
|
|
6568
|
+
`- \u65F6\u95F4\u8303\u56F4\uFF1A${range}\uFF08${deps.timeZone ?? "\u672C\u673A\u65F6\u533A"}\uFF09`,
|
|
6569
|
+
`- \u5BF9\u8BDD\uFF1A${agentName}${target === session ? "\uFF08\u5BFC\u51FA\u65F6\u6240\u5728\u7684\u5BF9\u8BDD\uFF09" : `\uFF08${target}\uFF09`}`,
|
|
6570
|
+
`- \u804A\u5929\u8BB0\u5F55\uFF1A\u7528\u6237 ${count("user")} \u6761\uFF0C${agentName} ${count("agent")} \u6761${a.with_agents === true ? `\uFF0C\u8F6F\u4EF6/\u5176\u4ED6 agent ${count("app")} \u6761` : ""}\uFF08\u804A\u5929\u8BB0\u5F55.md\uFF09`,
|
|
6571
|
+
...done.map((p) => `- ${p.title}\uFF1A${p.summary}${p.files > 0 ? `\uFF08${p.name}/\uFF0C${p.files} \u4E2A\u6587\u4EF6\uFF09` : ""}`),
|
|
6572
|
+
"- \u4E0D\u542B\uFF1A\u7CFB\u7EDF\u63D0\u793A\u3001\u6280\u80FD\u76EE\u5F55\u3001\u65F6\u95F4\u548C\u8BB0\u5FC6\u7684\u6CE8\u5165\u3001\u5DE5\u5177\u8C03\u7528\u548C\u7ED3\u679C\u3001\u9690\u85CF\u7684\u601D\u8003\u3001\u4E0A\u4E0B\u6587\u538B\u7F29\u6458\u8981\u3002",
|
|
6573
|
+
"- \u5BC6\u7801\u3001\u9A8C\u8BC1\u7801\u3001\u5BC6\u94A5\u4E4B\u7C7B\u5DF2\u906E\u76D6\u4E3A ***\u3002",
|
|
6574
|
+
""
|
|
6575
|
+
].join("\n"));
|
|
6576
|
+
return {
|
|
6577
|
+
folder,
|
|
6578
|
+
chat: { user: count("user"), agent: count("agent"), ...a.with_agents === true ? { app: count("app") } : {} },
|
|
6579
|
+
parts: done,
|
|
6580
|
+
files: files.map((f) => f.path),
|
|
6581
|
+
note: folder === resolve2(a.path) ? "\u5BFC\u51FA\u597D\u4E86\uFF1A\u544A\u8BC9\u7528\u6237\u653E\u5728\u54EA\u3001\u6709\u54EA\u4E9B\u6587\u4EF6\u3002" : `${a.path} \u91CC\u5DF2\u7ECF\u6709\u4E1C\u897F\uFF0C\u5BFC\u51FA\u653E\u5728\u4E86 ${folder}\uFF0C\u6CA1\u6709\u8986\u76D6\u539F\u6765\u7684\uFF1A\u544A\u8BC9\u7528\u6237\u3002`
|
|
6582
|
+
};
|
|
6583
|
+
},
|
|
6584
|
+
presentCall: (args) => ({ card: "generic", title: `\u5BFC\u51FA\u804A\u5929\u8BB0\u5F55\u548C\u65E5\u5FD7\uFF1A${String(args?.path ?? "")}`, kind: "execute" })
|
|
6585
|
+
};
|
|
6586
|
+
}
|
|
6587
|
+
|
|
6588
|
+
// packages/gateway/lib/changes.js
|
|
6589
|
+
import { mkdirSync, readFileSync as readFileSync3 } from "node:fs";
|
|
6590
|
+
import { dirname as dirname2 } from "node:path";
|
|
6411
6591
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
6592
|
+
var HELD_FOR_MS = 7 * 24 * 60 * 6e4;
|
|
6593
|
+
var MAX_KEPT = 300;
|
|
6594
|
+
var HeldChanges = class {
|
|
6595
|
+
#items = /* @__PURE__ */ new Map();
|
|
6596
|
+
#file;
|
|
6597
|
+
#now;
|
|
6598
|
+
#saving = Promise.resolve();
|
|
6599
|
+
constructor(file, now = Date.now) {
|
|
6600
|
+
this.#file = file;
|
|
6601
|
+
this.#now = now;
|
|
6602
|
+
if (file === void 0)
|
|
6603
|
+
return;
|
|
6604
|
+
try {
|
|
6605
|
+
const saved = JSON.parse(readFileSync3(file, "utf8"));
|
|
6606
|
+
if (Array.isArray(saved)) {
|
|
6607
|
+
for (const item of saved)
|
|
6608
|
+
if (typeof item?.id === "string" && item.state === "held")
|
|
6609
|
+
this.#items.set(item.id, item);
|
|
6610
|
+
}
|
|
6611
|
+
} catch {
|
|
6612
|
+
}
|
|
6613
|
+
}
|
|
6614
|
+
hold(input) {
|
|
6615
|
+
const change = {
|
|
6616
|
+
id: `c-${randomUUID3().slice(0, 6)}`,
|
|
6617
|
+
tool: input.tool,
|
|
6618
|
+
args: input.args,
|
|
6619
|
+
area: input.area.id,
|
|
6620
|
+
areaTitle: input.area.title,
|
|
6621
|
+
summary: summarize(input.args),
|
|
6622
|
+
from: input.from,
|
|
6623
|
+
lead: input.lead,
|
|
6624
|
+
at: this.#now(),
|
|
6625
|
+
state: "held"
|
|
6626
|
+
};
|
|
6627
|
+
this.#items.set(change.id, change);
|
|
6628
|
+
while (this.#items.size > MAX_KEPT)
|
|
6629
|
+
this.#items.delete(this.#items.keys().next().value);
|
|
6630
|
+
this.#save();
|
|
6631
|
+
return change;
|
|
6632
|
+
}
|
|
6633
|
+
/** The undecided changes a lead's conversation (or another of the same agent's, `sameAgent`) holds, oldest first. */
|
|
6634
|
+
waiting(lead, sameAgent = (a, b) => a === b) {
|
|
6635
|
+
const since = this.#now() - HELD_FOR_MS;
|
|
6636
|
+
return [...this.#items.values()].filter((c) => c.state === "held" && c.at >= since && sameAgent(c.lead, lead));
|
|
6637
|
+
}
|
|
6638
|
+
get(id) {
|
|
6639
|
+
return this.#items.get(id);
|
|
6640
|
+
}
|
|
6641
|
+
/** Resolves once what was held or decided so far is on disk. */
|
|
6642
|
+
saved() {
|
|
6643
|
+
return this.#saving;
|
|
6644
|
+
}
|
|
6645
|
+
settle(id, state, outcome) {
|
|
6646
|
+
const change = this.#items.get(id);
|
|
6647
|
+
if (change === void 0)
|
|
6648
|
+
return;
|
|
6649
|
+
this.#items.set(id, { ...change, state, outcome });
|
|
6650
|
+
this.#save();
|
|
6651
|
+
}
|
|
6652
|
+
#save() {
|
|
6653
|
+
const file = this.#file;
|
|
6654
|
+
if (file === void 0)
|
|
6655
|
+
return;
|
|
6656
|
+
const items = [...this.#items.values()].filter((c) => c.state === "held");
|
|
6657
|
+
this.#saving = this.#saving.then(async () => {
|
|
6658
|
+
mkdirSync(dirname2(file), { recursive: true });
|
|
6659
|
+
await writeFileAtomic(file, `${JSON.stringify(items)}
|
|
6660
|
+
`);
|
|
6661
|
+
}).catch(() => {
|
|
6662
|
+
});
|
|
6663
|
+
}
|
|
6664
|
+
};
|
|
6665
|
+
function summarize(args) {
|
|
6666
|
+
const short = (value) => {
|
|
6667
|
+
if (typeof value === "string")
|
|
6668
|
+
return value.length > 80 ? `\u300C${value.slice(0, 60).replace(/\s+/g, " ")}\u2026\u300D\uFF08${value.length} \u5B57\uFF09` : value;
|
|
6669
|
+
const json = JSON.stringify(value) ?? String(value);
|
|
6670
|
+
return json.length > 120 ? `${json.slice(0, 100)}\u2026\uFF08${json.length} \u5B57\uFF09` : json;
|
|
6671
|
+
};
|
|
6672
|
+
const text = Object.entries(args).filter(([, v]) => v !== void 0 && v !== null && v !== "").map(([k, v]) => `${k}=${short(v)}`).join("\uFF0C");
|
|
6673
|
+
return text.length > 300 ? `${text.slice(0, 299)}\u2026` : text;
|
|
6674
|
+
}
|
|
6675
|
+
function heldNote(change) {
|
|
6676
|
+
return [
|
|
6677
|
+
`\u6CA1\u6709\u6267\u884C\uFF1A\u8FD9\u662F\u8981\u4E0A\u7EA7\u51B3\u5B9A\u7684\u6539\u52A8\uFF08${change.areaTitle}\uFF09\uFF0C\u8F6F\u4EF6\u5DF2\u7ECF\u8BB0\u6210\u5F85\u5B9A\u6539\u52A8 ${change.id}\u3002`,
|
|
6678
|
+
"\u4E0D\u4F9D\u8D56\u5B83\u7684\u90E8\u5206\u63A5\u7740\u505A\uFF1B\u4F9D\u8D56\u5B83\u7684\u540E\u7EED\u6B65\u9AA4\u5148\u4E0D\u505A\u3002\u4EA4\u56DE\u65F6\u5728\u300C\u9700\u8981\u51B3\u5B9A\u7684\u300D\u91CC\u5199\u4E0A\u8FD9\u4E2A\u7F16\u53F7\u3001\u6539\u4EC0\u4E48\u3001\u4E3A\u4EC0\u4E48\u3002",
|
|
6679
|
+
"\u4E0D\u8981\u6362\u522B\u7684\u529E\u6CD5\u53BB\u505A\uFF08\u6539\u6587\u4EF6\u3001\u547D\u4EE4\u884C\u3001\u518D\u8C03\u4E00\u6B21\uFF09\uFF1A\u4E0A\u7EA7\u51B3\u5B9A\u4EE5\u540E\u4F1A\u66FF\u4F60\u6267\u884C\u3002"
|
|
6680
|
+
].join("");
|
|
6681
|
+
}
|
|
6682
|
+
var Args4 = external_exports.object({
|
|
6683
|
+
action: external_exports.enum(["list", "apply", "discard"]),
|
|
6684
|
+
ids: external_exports.array(external_exports.string().trim().min(1)).max(20).nullish(),
|
|
6685
|
+
id: external_exports.string().trim().min(1).nullish(),
|
|
6686
|
+
reason: external_exports.string().trim().max(500).nullish()
|
|
6687
|
+
});
|
|
6688
|
+
var MAX_FULL = 2e4;
|
|
6689
|
+
var MAX_OUTCOME = 600;
|
|
6690
|
+
var render3 = (_args, value) => [{ type: "text", text: typeof value === "string" ? value : JSON.stringify(value, null, 1) }];
|
|
6691
|
+
var clip2 = (text, max) => text.length > max ? `${text.slice(0, max - 1)}\u2026` : text;
|
|
6692
|
+
var show = (value) => clip2(typeof value === "string" ? value : JSON.stringify(value) ?? String(value), MAX_OUTCOME);
|
|
6693
|
+
function pendingChangesTool(deps) {
|
|
6694
|
+
const sameAgent = deps.sameAgent ?? ((a, b) => a === b);
|
|
6695
|
+
return {
|
|
6696
|
+
name: "pending_changes",
|
|
6697
|
+
description: [
|
|
6698
|
+
"\u5F85\u5B9A\u6539\u52A8\uFF1A\u4F60\u7684\u5B50 agent \u8981\u505A\u3001\u4F46\u8981\u4F60\u51B3\u5B9A\u7684\u6539\u52A8\uFF08\u5B89\u88C5\u3001\u66F4\u65B0\u3001\u5220\u9664\u811A\u672C\uFF0C\u5199\u811A\u672C\u5305\uFF0C\u6539\u811A\u672C\u914D\u7F6E\uFF0C\u6539\u6D41\u6C34\u7EBF\u548C\u5B9A\u65F6\uFF0C\u5B58\u6280\u80FD\uFF0C\u52A0\u6E38\u620F\u6216\u65E5\u5E38\u5468\u5E38\uFF09\uFF0C\u8F6F\u4EF6\u66FF\u5B83\u8BB0\u4E0B\u3001\u6CA1\u6709\u6267\u884C\uFF1B\u5B50 agent \u4EA4\u56DE\u65F6\u4F1A\u5728\u300C\u9700\u8981\u51B3\u5B9A\u7684\u300D\u91CC\u5199\u4E0A\u7F16\u53F7\u3002",
|
|
6699
|
+
"action=list \u5217\u51FA\u8FD8\u6CA1\u51B3\u5B9A\u7684\uFF08\u5E26 id \u770B\u8FD9\u4E00\u6761\u7684\u5B8C\u6574\u53C2\u6570\uFF09\uFF1Bapply \u6309 ids \u7684\u987A\u5E8F\u6267\u884C\uFF0C\u7ED3\u679C\u9010\u6761\u8FD4\u56DE\uFF1Bdiscard \u653E\u5F03\uFF0Creason \u5199\u4E3A\u4EC0\u4E48\u3002",
|
|
6700
|
+
"\u7528\u6237\u5DF2\u7ECF\u660E\u786E\u8981\u8FD9\u6837\u6539\u7684\uFF08\u4EA4\u7ED9\u4F60\u7684\u4E8B\u5C31\u662F\u8FD9\u4E2A\uFF09\uFF0C\u76F4\u63A5 apply\uFF1B\u7528\u6237\u6CA1\u8BF4\u8FC7\u7684\u3001\u6536\u4E0D\u56DE\u7684\uFF08\u5220\u811A\u672C\u3001\u5220\u8BB0\u5F55\uFF09\uFF0C\u5148\u95EE\u7528\u6237\uFF1B\u6CA1\u4EBA\u53EF\u95EE\uFF08\u8F6F\u4EF6\u81EA\u52A8\u4EA4\u7ED9\u4F60\u7684\u4E8B\uFF09\u65F6\u6309\u4F60\u7684\u5224\u65AD\uFF0C\u5728\u7ED3\u8BBA\u91CC\u8BF4\u660E\u3002"
|
|
6701
|
+
].join(""),
|
|
6702
|
+
parameters: {
|
|
6703
|
+
type: "object",
|
|
6704
|
+
properties: {
|
|
6705
|
+
action: { type: "string", enum: ["list", "apply", "discard"], description: "list \u770B\uFF1Bapply \u6267\u884C\uFF1Bdiscard \u653E\u5F03\u3002" },
|
|
6706
|
+
ids: { type: "array", items: { type: "string" }, description: "apply\u3001discard\uFF1A\u5F85\u5B9A\u6539\u52A8\u7684\u7F16\u53F7\uFF08c-\u2026\uFF09\u3002" },
|
|
6707
|
+
id: { type: "string", description: "list\uFF1A\u770B\u8FD9\u4E00\u6761\u7684\u5B8C\u6574\u53C2\u6570\uFF08\u53EF\u9009\uFF09\u3002" },
|
|
6708
|
+
reason: { type: "string", description: "discard\uFF1A\u4E3A\u4EC0\u4E48\u4E0D\u505A\u3002" }
|
|
6709
|
+
},
|
|
6710
|
+
required: ["action"],
|
|
6711
|
+
additionalProperties: false
|
|
6712
|
+
},
|
|
6713
|
+
output: { schema: {}, render: render3 },
|
|
6714
|
+
// Applying runs other tools one after another, in the order given.
|
|
6715
|
+
isConcurrencySafe: () => false,
|
|
6716
|
+
execute: async (args, exec) => {
|
|
6717
|
+
const parsed = Args4.safeParse(args ?? {});
|
|
6718
|
+
if (!parsed.success)
|
|
6719
|
+
throw new Error(`\u53C2\u6570\u65E0\u6548\uFF1A${parsed.error.issues.map((i) => `${i.path.join(".") || "(root)"} ${i.message}`).join("; ")}`);
|
|
6720
|
+
const { action, ids, id, reason } = parsed.data;
|
|
6721
|
+
const lead = exec.agent?.session?.id;
|
|
6722
|
+
if (lead === void 0)
|
|
6723
|
+
throw new Error("\u53EA\u80FD\u5728\u4F1A\u8BDD\u91CC\u7528");
|
|
6724
|
+
const mine = (change) => change !== void 0 && sameAgent(change.lead, lead);
|
|
6725
|
+
if (action === "list") {
|
|
6726
|
+
if (id) {
|
|
6727
|
+
const change = deps.store.get(id);
|
|
6728
|
+
if (!mine(change))
|
|
6729
|
+
throw new Error(`\u6CA1\u6709\u8FD9\u4E00\u6761\u5F85\u5B9A\u6539\u52A8\uFF1A${id}`);
|
|
6730
|
+
return { id: change.id, state: change.state, tool: change.tool, kind: change.areaTitle, args: clip2(JSON.stringify(change.args, null, 1), MAX_FULL) };
|
|
6731
|
+
}
|
|
6732
|
+
const waiting = deps.store.waiting(lead, sameAgent);
|
|
6733
|
+
if (waiting.length === 0)
|
|
6734
|
+
return { waiting: [], note: "\u6CA1\u6709\u5F85\u5B9A\u6539\u52A8\u3002" };
|
|
6735
|
+
return { waiting: waiting.map((c) => ({ id: c.id, kind: c.areaTitle, tool: c.tool, summary: c.summary })) };
|
|
6736
|
+
}
|
|
6737
|
+
if (!ids || ids.length === 0)
|
|
6738
|
+
throw new Error(`${action} \u8981\u5199 ids`);
|
|
6739
|
+
const changes = ids.map((want) => deps.store.get(want));
|
|
6740
|
+
const unknown = ids.filter((_, i) => !mine(changes[i]));
|
|
6741
|
+
if (unknown.length > 0)
|
|
6742
|
+
throw new Error(`\u6CA1\u6709\u8FD9\u4E9B\u5F85\u5B9A\u6539\u52A8\uFF1A${unknown.join("\u3001")}`);
|
|
6743
|
+
const decided = changes.filter((c) => c.state !== "held");
|
|
6744
|
+
if (decided.length > 0)
|
|
6745
|
+
throw new Error(`\u8FD9\u4E9B\u5DF2\u7ECF\u51B3\u5B9A\u8FC7\u4E86\uFF1A${decided.map((c) => `${c.id}\uFF08${c.state}\uFF09`).join("\u3001")}`);
|
|
6746
|
+
if (action === "discard") {
|
|
6747
|
+
for (const change of changes)
|
|
6748
|
+
deps.store.settle(change.id, "discarded", reason ?? "");
|
|
6749
|
+
return { discarded: ids };
|
|
6750
|
+
}
|
|
6751
|
+
const results = [];
|
|
6752
|
+
for (const change of changes) {
|
|
6753
|
+
try {
|
|
6754
|
+
const value = await deps.run(change.tool, change.args, exec);
|
|
6755
|
+
deps.store.settle(change.id, "applied", show(value));
|
|
6756
|
+
results.push({ id: change.id, tool: change.tool, ok: true, result: show(value) });
|
|
6757
|
+
} catch (error) {
|
|
6758
|
+
const why = error instanceof Error ? error.message : String(error);
|
|
6759
|
+
deps.store.settle(change.id, "failed", why);
|
|
6760
|
+
results.push({ id: change.id, tool: change.tool, ok: false, result: clip2(why, MAX_OUTCOME) });
|
|
6761
|
+
}
|
|
6762
|
+
}
|
|
6763
|
+
return { applied: results };
|
|
6764
|
+
},
|
|
6765
|
+
presentCall: (args) => {
|
|
6766
|
+
const a = args ?? {};
|
|
6767
|
+
const ids = Array.isArray(a.ids) ? a.ids.join("\u3001") : "";
|
|
6768
|
+
return { card: "generic", title: a.action === "apply" ? `\u6267\u884C\u5F85\u5B9A\u6539\u52A8\uFF1A${ids}` : a.action === "discard" ? `\u653E\u5F03\u5F85\u5B9A\u6539\u52A8\uFF1A${ids}` : "\u770B\u5F85\u5B9A\u6539\u52A8", kind: a.action === "list" ? "other" : "execute" };
|
|
6769
|
+
}
|
|
6770
|
+
};
|
|
6771
|
+
}
|
|
6772
|
+
|
|
6773
|
+
// packages/gateway/lib/recall.js
|
|
6774
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
6412
6775
|
var RECALL_SOURCE = "adg-recall";
|
|
6413
6776
|
var MAX_RECALLED = 5;
|
|
6414
6777
|
var MAX_RECALL_CHARS = 1500;
|
|
@@ -6461,7 +6824,7 @@ function recallText(entries, agentId, timeZone) {
|
|
|
6461
6824
|
}
|
|
6462
6825
|
function recallMessage(text, ids) {
|
|
6463
6826
|
return Object.freeze({
|
|
6464
|
-
id:
|
|
6827
|
+
id: randomUUID4(),
|
|
6465
6828
|
role: "user",
|
|
6466
6829
|
content: Object.freeze([Object.freeze({ type: "text", text })]),
|
|
6467
6830
|
source: Object.freeze({ kind: RECALL_SOURCE, form: "snapshot", ids: Object.freeze([...ids]), sections: Object.freeze([Object.freeze({ name: RECALL_SOURCE, text })]) })
|
|
@@ -6944,14 +7307,14 @@ var QuestionBroker = class {
|
|
|
6944
7307
|
...q.multiSelect === void 0 ? {} : { multiSelect: q.multiSelect }
|
|
6945
7308
|
}))
|
|
6946
7309
|
};
|
|
6947
|
-
return new Promise((
|
|
7310
|
+
return new Promise((resolve5, reject) => {
|
|
6948
7311
|
const onAbort = () => this.settle(questionId, "cancelled");
|
|
6949
7312
|
this.pending.set(questionId, {
|
|
6950
7313
|
request,
|
|
6951
7314
|
settle: (outcome, answer) => {
|
|
6952
7315
|
ask.signal?.removeEventListener("abort", onAbort);
|
|
6953
7316
|
if (outcome === "answered" && answer !== void 0)
|
|
6954
|
-
|
|
7317
|
+
resolve5(answer);
|
|
6955
7318
|
else
|
|
6956
7319
|
reject(new QuestionClosed(outcome === "answered" ? "unavailable" : outcome));
|
|
6957
7320
|
}
|
|
@@ -7418,8 +7781,8 @@ function builtinCapabilities(deps) {
|
|
|
7418
7781
|
|
|
7419
7782
|
// packages/gateway/lib/homes.js
|
|
7420
7783
|
import { readFile as readFile7 } from "node:fs/promises";
|
|
7421
|
-
import { mkdirSync } from "node:fs";
|
|
7422
|
-
import { dirname as
|
|
7784
|
+
import { mkdirSync as mkdirSync2 } from "node:fs";
|
|
7785
|
+
import { dirname as dirname3 } from "node:path";
|
|
7423
7786
|
var AgentHomes = class {
|
|
7424
7787
|
#file;
|
|
7425
7788
|
#homes = /* @__PURE__ */ new Map();
|
|
@@ -7451,7 +7814,7 @@ var AgentHomes = class {
|
|
|
7451
7814
|
async #save() {
|
|
7452
7815
|
if (this.#file === void 0)
|
|
7453
7816
|
return;
|
|
7454
|
-
|
|
7817
|
+
mkdirSync2(dirname3(this.#file), { recursive: true });
|
|
7455
7818
|
await writeFileAtomic(this.#file, `${JSON.stringify(Object.fromEntries(this.#homes), null, 2)}
|
|
7456
7819
|
`);
|
|
7457
7820
|
}
|
|
@@ -7469,7 +7832,7 @@ var AgentHomes = class {
|
|
|
7469
7832
|
}
|
|
7470
7833
|
}
|
|
7471
7834
|
};
|
|
7472
|
-
var
|
|
7835
|
+
var MAX_KEPT2 = 500;
|
|
7473
7836
|
var HandOffs = class {
|
|
7474
7837
|
#file;
|
|
7475
7838
|
#items = /* @__PURE__ */ new Map();
|
|
@@ -7506,7 +7869,7 @@ var HandOffs = class {
|
|
|
7506
7869
|
await this.loaded;
|
|
7507
7870
|
this.#items.delete(item.id);
|
|
7508
7871
|
this.#items.set(item.id, item);
|
|
7509
|
-
while (this.#items.size >
|
|
7872
|
+
while (this.#items.size > MAX_KEPT2)
|
|
7510
7873
|
this.#items.delete(this.#items.keys().next().value);
|
|
7511
7874
|
this.#changed(item);
|
|
7512
7875
|
for (const listener of this.#listeners) {
|
|
@@ -7520,7 +7883,7 @@ var HandOffs = class {
|
|
|
7520
7883
|
async #save() {
|
|
7521
7884
|
if (this.#file === void 0)
|
|
7522
7885
|
return;
|
|
7523
|
-
|
|
7886
|
+
mkdirSync2(dirname3(this.#file), { recursive: true });
|
|
7524
7887
|
await writeFileAtomic(this.#file, `${JSON.stringify([...this.#items.values()])}
|
|
7525
7888
|
`);
|
|
7526
7889
|
}
|
|
@@ -7705,21 +8068,45 @@ function plain(markdown) {
|
|
|
7705
8068
|
|
|
7706
8069
|
// packages/gateway/lib/roles.js
|
|
7707
8070
|
import { readFile as readFile8 } from "node:fs/promises";
|
|
7708
|
-
import { mkdirSync as
|
|
7709
|
-
import { dirname as
|
|
8071
|
+
import { mkdirSync as mkdirSync3 } from "node:fs";
|
|
8072
|
+
import { dirname as dirname4 } from "node:path";
|
|
7710
8073
|
function keeps(tools, name) {
|
|
7711
8074
|
return tools === void 0 || matches(tools, name);
|
|
7712
8075
|
}
|
|
7713
8076
|
function matches(patterns, name) {
|
|
7714
8077
|
return patterns.some((pattern) => pattern.endsWith("*") ? name.startsWith(pattern.slice(0, -1)) : name === pattern);
|
|
7715
8078
|
}
|
|
7716
|
-
var NOBODY = ["subagent_fork", "wait_agent"];
|
|
8079
|
+
var NOBODY = ["subagent_fork", "wait_agent", "plugin_manager", "present", "create_goal", "update_goal", "get_goal", "list_subagent_models"];
|
|
7717
8080
|
var TOGETHER = ["agent_delegate", "agent_message", "agent_threads"];
|
|
7718
8081
|
var MEMORY_TOOLS = ["memory_save", "memory_forget", "memory_search", "history_search", "history_read"];
|
|
7719
|
-
var
|
|
7720
|
-
var
|
|
8082
|
+
var DECIDING = ["pending_changes"];
|
|
8083
|
+
var ALWAYS = [...TOGETHER, ...MEMORY_TOOLS, ...DECIDING];
|
|
8084
|
+
var COORDINATION = [
|
|
8085
|
+
"agent_delegate",
|
|
8086
|
+
"agent_message",
|
|
8087
|
+
"agent_threads",
|
|
8088
|
+
"notice_act",
|
|
8089
|
+
"ask_user_question",
|
|
8090
|
+
"exit_plan_mode",
|
|
8091
|
+
"subagent",
|
|
8092
|
+
"list_agents",
|
|
8093
|
+
"interrupt_agent",
|
|
8094
|
+
"schedule_create",
|
|
8095
|
+
"schedule_list",
|
|
8096
|
+
"schedule_view",
|
|
8097
|
+
"schedule_edit",
|
|
8098
|
+
"schedule_task_*",
|
|
8099
|
+
"intervention_done",
|
|
8100
|
+
"memory_save",
|
|
8101
|
+
"memory_forget",
|
|
8102
|
+
// Its conversation is its parent's task: what it would export is not the user's chat.
|
|
8103
|
+
"history_export",
|
|
8104
|
+
// Its lasting changes are decided above it.
|
|
8105
|
+
"pending_changes"
|
|
8106
|
+
];
|
|
8107
|
+
var LIGHT = ["pipeline_run", "script_run", "script_stop", "game_launch", "game_close", "emulator_start", "emulator_stop"];
|
|
7721
8108
|
var HANDS_ON = [
|
|
7722
|
-
...AGENT_AREAS.filter((area) => ["run", "scripts-config", "scripts-install", "screen", "games", "shell"].includes(area.id)).flatMap((area) => area.tools).filter((tool) => tool
|
|
8109
|
+
...AGENT_AREAS.filter((area) => ["run", "scripts-config", "scripts-install", "screen", "games", "shell"].includes(area.id)).flatMap((area) => area.tools).filter((tool) => !LIGHT.includes(tool)),
|
|
7723
8110
|
// Screenshots are not in an area (they change nothing), and they weigh the most.
|
|
7724
8111
|
"screen_*",
|
|
7725
8112
|
// The built-in browser: every step answers with the whole page.
|
|
@@ -7727,14 +8114,26 @@ var HANDS_ON = [
|
|
|
7727
8114
|
// Runs a program that calls the tools: the same work, by another door.
|
|
7728
8115
|
"workflow"
|
|
7729
8116
|
];
|
|
8117
|
+
var AT_HOME = ["job_*", "todo_write"];
|
|
7730
8118
|
var HANDS_ON_REFUSAL = (tool) => `${tool} \u8FD9\u7C7B\u5177\u4F53\u64CD\u4F5C\u4E0D\u5728\u4F60\u7684\u5BF9\u8BDD\u91CC\u505A\uFF1A\u7528 subagent \u5F00\u4E00\u4E2A\u5B50 agent \u53BB\u505A\uFF0C\u628A\u4EFB\u52A1\u5199\u5B8C\u6574\uFF08\u5B83\u770B\u4E0D\u5230\u4F60\u7684\u5BF9\u8BDD\uFF09\uFF0C\u5B83\u53EA\u628A\u7ED3\u679C\u4EA4\u56DE\u6765\u3002\u8981\u7528\u6237\u6279\u51C6\u7684\u64CD\u4F5C\uFF0C\u5B83\u505A\u7684\u65F6\u5019\u540C\u6837\u4F1A\u8BF7\u7528\u6237\u6279\u51C6\u3002`;
|
|
7731
8119
|
function handsOn(tool) {
|
|
7732
8120
|
return matches(HANDS_ON, tool);
|
|
7733
8121
|
}
|
|
7734
8122
|
function hiddenTools(spec, appTools, visible, home = false) {
|
|
7735
|
-
const hide = [...NOBODY, ...spec.hide ?? [], ...home ? HANDS_ON : []];
|
|
8123
|
+
const hide = [...NOBODY, ...spec.hide ?? [], ...home ? [...HANDS_ON, ...AT_HOME] : []];
|
|
7736
8124
|
return [...visible].filter((name) => matches(hide, name) || appTools.has(name) && !keeps(spec.tools, name) && !ALWAYS.includes(name));
|
|
7737
8125
|
}
|
|
8126
|
+
var REPORT_SHAPE = [
|
|
8127
|
+
"\u7ED3\u8BBA\uFF1A\u505A\u6210\u4E86\u6CA1\u6709\uFF0C\u4E00\u4E24\u53E5\u3002",
|
|
8128
|
+
"\u8BC1\u636E\uFF1A\u80FD\u6838\u5BF9\u7684\u4E1C\u897F\u2014\u2014\u8FD0\u884C id\u3001\u65E5\u5FD7\u539F\u6587\u3001\u6539\u4E86\u54EA\u4E9B\u8BBE\u7F6E\u6216\u6587\u4EF6\u3001\u7ED3\u679C\u72B6\u6001\u3001\u51FA\u5904\u3002",
|
|
8129
|
+
"\u6CA1\u505A\u6210\u7684\u548C\u539F\u56E0\uFF1A",
|
|
8130
|
+
"\u9700\u8981\u51B3\u5B9A\u7684\uFF1A\u8981\u4E0A\u7EA7\u6216\u7528\u6237\u51B3\u5B9A\u7684\u4E8B\uFF08\u8D8A\u8FC7\u8FB9\u754C\u7684\u3001\u6536\u4E0D\u56DE\u7684\u3001\u60C5\u51B5\u4E0D\u660E\u7684\uFF09\uFF0C\u8F6F\u4EF6\u8BB0\u4E0B\u7684\u5F85\u5B9A\u6539\u52A8\u5199\u4E0A\u7F16\u53F7\uFF08c-\u2026\uFF09\u3001\u6539\u4EC0\u4E48\u3001\u4E3A\u4EC0\u4E48\u3002"
|
|
8131
|
+
].join("\n");
|
|
8132
|
+
var BRIEFING = [
|
|
8133
|
+
`\u5F00\u5B50 agent \u65F6\uFF0Cprompt \u5199\u8FD9\u51E0\u9879\uFF1A\u76EE\u6807\uFF08\u8981\u505A\u6210\u4EC0\u4E48\u6837\uFF0C\u52A0\u4E0A\u4F60\u5DF2\u7ECF\u77E5\u9053\u7684\u60C5\u51B5\uFF1A\u54EA\u4E2A\u6E38\u620F\u6216\u811A\u672C\u3001\u8FD0\u884C id\u3001\u7528\u6237\u539F\u8BDD\uFF09\u3001${BRIEF_LIMITS}\uFF08\u54EA\u4E9B\u4E0D\u80FD\u52A8\u3001\u505A\u5230\u54EA\u4E00\u6B65\u4E3A\u6B62\uFF09\u3001${BRIEF_DONE_WHEN}\uFF08\u600E\u6837\u7B97\u505A\u5B8C\uFF09\u3001\u5E26\u56DE\uFF08\u8981\u5B83\u4EA4\u56DE\u7684\u8BC1\u636E\uFF1A\u8FD0\u884C id\u3001\u65E5\u5FD7\u539F\u6587\u3001\u6539\u4E86\u4EC0\u4E48\uFF09\u3002\u4E0D\u5199\u4E00\u6B65\u6B65\u600E\u4E48\u505A\uFF1A\u7528\u4EC0\u4E48\u5DE5\u5177\u3001\u600E\u4E48\u505A\u7531\u5B83\u51B3\u5B9A\uFF0C\u5B83\u770B\u5F97\u5230\u81EA\u5DF1\u5168\u90E8\u5DE5\u5177\u7684\u8BF4\u660E\u3002`,
|
|
8134
|
+
`\u5B50 agent \u505A\u4F1A\u7559\u4E0B\u6765\u3001\u6536\u4E0D\u56DE\u7684\u6539\u52A8\uFF08${DECISION_AREAS.map((a) => a.title).join("\uFF1B")}\uFF09\u65F6\uFF0C\u8F6F\u4EF6\u4E0D\u66FF\u5B83\u6267\u884C\uFF0C\u5148\u8BB0\u6210\u5F85\u5B9A\u6539\u52A8\u4EA4\u56DE\u7ED9\u4F60\uFF0C\u4F60\u7528 pending_changes \u51B3\u5B9A\uFF1A\u7528\u6237\u5DF2\u7ECF\u660E\u786E\u8981\u8FD9\u6837\u6539\u7684\u76F4\u63A5 apply\uFF0C\u7528\u6237\u6CA1\u8BF4\u8FC7\u7684\u3001\u6536\u4E0D\u56DE\u7684\u5148\u95EE\u7528\u6237\uFF0C\u6CA1\u4EBA\u53EF\u95EE\u65F6\u6309\u4F60\u7684\u5224\u65AD\u5E76\u5728\u7ED3\u8BBA\u91CC\u8BF4\u660E\u3002\u7528\u6237\u5DF2\u7ECF\u660E\u786E\u8981\u5B83\u505A\u7684\u90A3\u7C7B\u6539\u52A8\uFF0C\u5728 prompt \u91CC\u52A0\u4E00\u884C\u300C${BRIEF_ALLOW}\uFF1A\u2026\u300D\u5199\u4E0A\u7C7B\u522B\uFF08\u4E0A\u9762\u5206\u53F7\u9694\u5F00\u7684\u90A3\u51E0\u7C7B\uFF09\uFF0C\u5B83\u5C31\u76F4\u63A5\u505A\uFF0C\u4E0D\u7528\u518D\u4EA4\u56DE\u6765\u3002`,
|
|
8135
|
+
`\u5B83\u4EA4\u56DE\u540E\uFF0C\u6309${BRIEF_DONE_WHEN}\u6838\u5BF9\u5B83\u5E26\u56DE\u7684\u8BC1\u636E\uFF1A\u7528\u770B\u7684\u5DE5\u5177\u770B\u4E00\u773C\uFF08\u8FD0\u884C id \u7528 script_run_log\uFF0C\u6587\u4EF6\u7528 read\uFF09\uFF0C\u4E0D\u8981\u81EA\u5DF1\u91CD\u505A\u4E00\u904D\uFF1B\u5BF9\u4E0D\u4E0A\u5C31\u7528 send_message \u8BA9\u5B83\u8865\uFF0C\u6216\u8005\u7167\u5B9E\u8BF4\u6CA1\u505A\u6210\u3002\u60C5\u51B5\u4E0D\u660E\u3001\u6216\u8005\u8981\u505A\u6536\u4E0D\u56DE\u7684\u4E8B\uFF08\u5220\u3001\u88C5\u3001\u6539\u8BBE\u7F6E\uFF09\u65F6\uFF0C\u5148\u8BA9\u5B83\u67E5\u6E05\u695A\u4EA4\u56DE\uFF0C\u4F60\u51B3\u5B9A\u4EE5\u540E\u518D\u8BA9\u5B83\u505A\u3002`
|
|
8136
|
+
].join("\n");
|
|
7738
8137
|
function subAgentSpec(parent) {
|
|
7739
8138
|
const name = parent.name;
|
|
7740
8139
|
return {
|
|
@@ -7748,7 +8147,10 @@ function subAgentSpec(parent) {
|
|
|
7748
8147
|
duty: [
|
|
7749
8148
|
`# \u4F60\u7684\u89D2\u8272\uFF1A\u300C${name}\u300D\u7684\u5B50 agent`,
|
|
7750
8149
|
`\u4F60\u662F\u300C${name}\u300D\u5F00\u7684\u5B50 agent\uFF0C\u53EA\u505A\u5B83\u4EA4\u7ED9\u4F60\u7684\u8FD9\u4E00\u4EF6\u4E8B\u3002\u5B83\u7684\u4EFB\u52A1\u5C31\u662F\u4F60\u6536\u5230\u7684\u7B2C\u4E00\u6761\u6D88\u606F\uFF1B\u4F60\u770B\u4E0D\u5230\u5B83\u548C\u522B\u4EBA\u7684\u5BF9\u8BDD\u3002`,
|
|
7751
|
-
`\
|
|
8150
|
+
`\u4EFB\u52A1\u5199\u4E86\u300C${BRIEF_LIMITS}\u300D\u300C${BRIEF_DONE_WHEN}\u300D\u7684\uFF0C\u7167\u7740\u505A\uFF1A\u8D8A\u8FC7\u8FB9\u754C\u7684\u4E8B\u4E0D\u505A\uFF0C\u5199\u8FDB\u300C\u9700\u8981\u51B3\u5B9A\u7684\u300D\uFF1B\u505A\u5230\u5B8C\u6210\u6807\u51C6\u5C31\u505C\uFF0C\u4E0D\u591A\u505A\u3002\u600E\u4E48\u505A\u3001\u7528\u4EC0\u4E48\u5DE5\u5177\u7531\u4F60\u51B3\u5B9A\u3002`,
|
|
8151
|
+
`\u4F1A\u7559\u4E0B\u6765\u3001\u6536\u4E0D\u56DE\u7684\u6539\u52A8\uFF08${DECISION_AREAS.map((a) => a.title).join("\uFF1B")}\uFF09\u7531\u300C${name}\u300D\u51B3\u5B9A\uFF1A\u4EFB\u52A1\u91CC\u300C${BRIEF_ALLOW}\u300D\u6CA1\u5199\u5230\u7684\u90A3\u7C7B\uFF08\u7528\u6237\u5728\u8F6F\u4EF6\u91CC\u70B9\u7684\u4E8B\u4E0D\u7B97\uFF0C\u90FD\u53EF\u4EE5\u76F4\u63A5\u505A\uFF09\uFF0C\u4F60\u8C03\u7528\u65F6\u8F6F\u4EF6\u53EA\u8BB0\u6210\u5F85\u5B9A\u6539\u52A8\u3001\u4E0D\u6267\u884C\uFF0C\u4F60\u628A\u7F16\u53F7\u5199\u8FDB\u4EA4\u56DE\u5C31\u884C\uFF1B\u8981\u5148\u6709\u5B83\u624D\u80FD\u505A\u7684\u540E\u7EED\u6B65\u9AA4\uFF0C\u7559\u5230\u51B3\u5B9A\u4EE5\u540E\u3002`,
|
|
8152
|
+
`\u4F60\u7684\u56DE\u590D\u53EA\u6709\u300C${name}\u300D\u8BFB\uFF0C\u7528\u6237\u770B\u4E0D\u5230\uFF1A\u7528\u5DE5\u5177\u628A\u4E8B\u505A\u5B8C\uFF0C\u6700\u540E\u4E00\u6BB5\u56DE\u590D\u6309\u4E0B\u9762\u51E0\u9879\u5199\uFF08\u6CA1\u6709\u7684\u5199\u300C\u65E0\u300D\uFF09\uFF0C\u4E0D\u5BD2\u6684\uFF1A`,
|
|
8153
|
+
REPORT_SHAPE,
|
|
7752
8154
|
`\u4F60\u95EE\u4E0D\u4E86\u7528\u6237\uFF0C\u4E5F\u4E0D\u80FD\u4EA4\u7ED9\u522B\u7684 agent\uFF1A\u7F3A\u4EC0\u4E48\u5C31\u5199\u8FDB\u56DE\u590D\uFF0C\u7531\u300C${name}\u300D\u53BB\u95EE\u3002\u9700\u8981\u7528\u6237\u6279\u51C6\u7684\u64CD\u4F5C\u4F1A\u8BF7\u7528\u6237\u6279\u51C6\uFF0C\u7B49\u7ED3\u679C\u5C31\u662F\uFF1B\u88AB\u62D2\u7EDD\u4E86\u4E0D\u8981\u6362\u4E2A\u529E\u6CD5\u7ED5\u8FC7\u53BB\uFF0C\u628A\u6CA1\u505A\u6210\u7684\u548C\u539F\u56E0\u5199\u8FDB\u56DE\u590D\u3002`,
|
|
7753
8155
|
"\u80FD\u7528\u5DE5\u5177\u3001\u547D\u4EE4\u884C\u3001\u8BFB\u6587\u4EF6\uFF08\u914D\u7F6E\u3001\u65E5\u5FD7\u3001\u7248\u672C\u53F7\uFF09\u6216\u811A\u672C\u81EA\u5DF1\u7684\u547D\u4EE4\u548C\u8BBE\u7F6E\u505A\u5230\u3001\u786E\u8BA4\u5230\u7684\uFF0C\u5C31\u8FD9\u6837\u505A\uFF1B\u622A\u56FE\u3001\u770B\u753B\u9762\u3001\u70B9\u5C4F\u5E55\u662F\u6700\u540E\u7684\u529E\u6CD5\u3002",
|
|
7754
8156
|
// Only where the parent's tools take the browser in (and it may be missing: dsh's own app has none).
|
|
@@ -7767,7 +8169,8 @@ function teamPrompt(self, main, leads, options = {}) {
|
|
|
7767
8169
|
isMain ? `\u4F60\u662F\u300C${self.name}\u300D\uFF08${self.id}\uFF09\uFF0C\u662F\u6700\u4E0A\u7EA7\u7684 agent\uFF1A\u548C\u7528\u6237\u5BF9\u8BDD\uFF0C\u628A\u4E8B\u5206\u7ED9\u4E0B\u9762\u7684\u4E3B agent\uFF0C\u6C47\u603B\u7ED3\u679C\u5E76\u505A\u51B3\u5B9A\u3002` : `\u4F60\u662F\u300C${self.name}\u300D\uFF08${self.id}\uFF09\uFF0C\u662F\u4E00\u4E2A\u4E3B agent\uFF1A\u8D1F\u8D23\u81EA\u5DF1\u8FD9\u5757\u4E8B\uFF0C\u505A\u51B3\u5B9A\u3001\u6C47\u603B\u7ED3\u679C\u3002\u4E0A\u7EA7\u662F${who(main)}\uFF1A\u5B83\u548C\u7528\u6237\u5BF9\u8BDD\u3001\u5206\u53D1\u4EFB\u52A1\u3001\u505A\u51B3\u5B9A\u3002`,
|
|
7768
8170
|
colleagues.length === 0 ? isMain ? "\u73B0\u5728\u6CA1\u6709\u5176\u4ED6\u4E3B agent\u3002" : "\u73B0\u5728\u6CA1\u6709\u5176\u4ED6\u540C\u4E8B\u3002" : `${isMain ? "\u4E0B\u9762\u7684\u4E3B agent" : "\u540C\u4E8B"}\uFF1A
|
|
7769
8171
|
${colleagues.map(line2).join("\n")}`,
|
|
7770
|
-
"\u5177\u4F53\u7684\u6D3B\u90FD\u7531\u5B50 agent \u505A\uFF08subagent\uFF09\uFF1A\u8FD0\u884C\u547D\u4EE4\u3001\u6539\u6587\u4EF6\u3001\u622A\u56FE\u70B9\u51FB\u3001\
|
|
8172
|
+
"\u5177\u4F53\u7684\u6D3B\u90FD\u7531\u5B50 agent \u505A\uFF08subagent\uFF09\uFF1A\u8FD0\u884C\u547D\u4EE4\u3001\u6539\u6587\u4EF6\u3001\u622A\u56FE\u70B9\u51FB\u3001\u5B89\u88C5\u811A\u672C\u3001\u6539\u8BBE\u7F6E\uFF0C\u8FD9\u4E9B\u5DE5\u5177\u4E0D\u5728\u4F60\u7684\u5BF9\u8BDD\u91CC\uFF0C\u53EA\u6709\u5B50 agent \u6709\uFF1B\u522B\u5904\u63D0\u5230\u8FD9\u4E9B\u5DE5\u5177\uFF0C\u4E5F\u662F\u8BA9\u5B50 agent \u53BB\u7528\u3002\u4F60\u7684\u5BF9\u8BDD\u7559\u7ED9\u5224\u65AD\u548C\u6C47\u603B\uFF1A\u8981\u505A\u4EC0\u4E48\u5C31\u5F00\u4E00\u4E2A\u5B50 agent\uFF08\u5B83\u770B\u4E0D\u5230\u4F60\u7684\u5BF9\u8BDD\uFF09\uFF0C\u7ED3\u679C\u4EA4\u56DE\u540E\u7531\u4F60\u5224\u65AD\u3001\u6C47\u603B\u3002\u67E5\u72B6\u6001\u3001\u8BFB\u4E00\u4E0B\u6587\u4EF6\u8FD9\u79CD\u770B\u4E00\u773C\u7684\u4E8B\u53EF\u4EE5\u81EA\u5DF1\u6765\uFF1B\u4E00\u6B21\u8C03\u7528\u5C31\u505A\u5B8C\u3001\u5728\u522B\u5904\u8FD0\u884C\u7684\u5C0F\u4E8B\u4E5F\u81EA\u5DF1\u505A\uFF0C\u4E0D\u7528\u5F00\u5B50 agent\uFF1A\u542F\u52A8\u6216\u505C\u6B62\u4E00\u4E2A\u811A\u672C\u4EFB\u52A1\uFF08script_run\u3001script_stop\uFF09\u3001\u8FD0\u884C\u6D41\u6C34\u7EBF\u3001\u6253\u5F00\u6216\u5173\u6389\u6E38\u620F\u548C\u6A21\u62DF\u5668\u2014\u2014\u4F60\u7684\u5DE5\u5177\u91CC\u6709\u7684\u8BDD\u3002\u51E0\u4EF6\u4E92\u4E0D\u76F8\u5173\u7684\u4E8B\u53EF\u4EE5\u540C\u65F6\u5F00\u3002\u6D3E\u53D1\u540E\u53EF\u4EE5\u7EE7\u7EED\u5176\u4ED6\u5DE5\u4F5C\uFF1B\u53EA\u5269\u5B50\u4EFB\u52A1\u672A\u4EA4\u4ED8\u65F6\u5C31\u7ED3\u675F\u5F53\u524D\u8F6E\u6B21\u3002\u5B50\u4EFB\u52A1\u5B8C\u6210\u3001\u5931\u8D25\u6216\u88AB\u505C\u6B62\u65F6\uFF0C\u7CFB\u7EDF\u4F1A\u81EA\u52A8\u628A\u5E26\u6709\u5B50\u4EFB\u52A1\u8EAB\u4EFD\u7684\u7EC8\u6001\u548C\u7ED3\u679C\u9001\u5230\u4F60\u7684\u5BF9\u8BDD\u3002\u6536\u5230\u56DE\u6267\u5C31\u76F4\u63A5\u7528\u5B83\u7EE7\u7EED\u5DE5\u4F5C\uFF1B\u591A\u4E2A\u5B50\u4EFB\u52A1\u5206\u522B\u4EA4\u4ED8\uFF0C\u6309\u5404\u81EA\u7684\u56DE\u6267\u5904\u7406\u3002\u8981\u7B49\u4E00\u6B21\u811A\u672C\u8FD0\u884C\u7ED3\u675F\uFF0C\u7528 script_runs \u5E26\u4E0A run_id \u548C wait_seconds\uFF0C\u5B83\u7B49\u5230\u7ED3\u675F\uFF08\u91CD\u65B0\u8FD0\u884C\u7684\u8BDD\u8DDF\u5230\u6700\u540E\u90A3\u6B21\uFF09\u624D\u8FD4\u56DE\u3002\u4E0D\u8981\u7528 glob\u3001list_agents\u3001script_runs\u3001window_list \u4E00\u904D\u904D\u67E5\u505A\u5230\u54EA\u4E86\uFF1A\u4F60\u5BF9\u8BDD\u91CC\u7684\u6BCF\u4E00\u6B65\u90FD\u8981\u628A\u6574\u4E2A\u5BF9\u8BDD\u91CD\u65B0\u53D1\u7ED9\u6A21\u578B\u4E00\u6B21\uFF0C\u8FD9\u6837\u7B49\u6700\u8D39\u3002\u5B50 agent \u53EA\u5BF9\u4F60\u8D1F\u8D23\uFF0C\u53EA\u628A\u7ED3\u679C\u4EA4\u56DE\u7ED9\u4F60\uFF1B\u5B83\u8981\u7528\u6237\u6279\u51C6\u7684\u64CD\u4F5C\uFF0C\u4F1A\u5728\u4F60\u7684\u5BF9\u8BDD\u91CC\u8BF7\u7528\u6237\u6279\u51C6\u3002",
|
|
8173
|
+
BRIEFING,
|
|
7771
8174
|
options.browser === true && keeps(self.tools, "browser_navigate") ? "\u7F51\u9875\u4E5F\u4E00\u6837\uFF1Aweb_fetch \u53EA\u62FF\u5230\u7A7A\u58F3\uFF08\u524D\u7AEF\u6E32\u67D3\u7684\u5B98\u7F51\u3001\u516C\u544A\u9875\u5E38\u8FD9\u6837\uFF09\u6216\u8981\u70B9\u5F00\u3001\u7FFB\u9875\u624D\u770B\u5F97\u5230\u65F6\uFF0C\u5F00\u5B50 agent \u7528\u5185\u7F6E\u6D4F\u89C8\u5668\u53BB\u8BFB\uFF0C\u4EFB\u52A1\u91CC\u5199\u660E\u300C\u7528\u5185\u7F6E\u6D4F\u89C8\u5668\uFF08browser_navigate \u6253\u5F00\uFF0Cbrowser_text \u8BFB\u6E32\u67D3\u540E\u7684\u6587\u5B57\uFF09\u300D\u3002\u5B83\u6253\u5F00\u7684\u9875\u9762\u7528\u6237\u5728\u6D4F\u89C8\u5668\u9762\u677F\u91CC\u770B\u5F97\u5230\u3002" : "",
|
|
7772
8175
|
isMain ? "" : `\u9700\u8981\u540C\u4E8B\u7684\u90A3\u90E8\u5206\uFF0C\u7528 agent_delegate \u76F4\u63A5\u4EA4\u7ED9\u5B83\uFF0C\u4E0D\u7528\u7ED5\u8FC7\u300C${main.name}\u300D\u3002\u4EA4\u7ED9\u4F60\u7684\u4E8B\u6CA1\u8BF4\u6E05\u695A\u65F6\uFF0C\u7528 agent_message \u95EE\u4EA4\u7ED9\u4F60\u7684\u4E00\u65B9\uFF0C\u4E0D\u8981\u81EA\u5DF1\u53BB\u95EE\u7528\u6237\uFF08\u8981\u4E0D\u8981\u95EE\u7528\u6237\u7531\u5BF9\u65B9\u51B3\u5B9A\uFF09\uFF0C\u95EE\u6E05\u695A\u518D\u505A\uFF1B\u505A\u5B8C\u7528 agent_message \u7684 done \u4EA4\u56DE\u7ED3\u8BBA\uFF0C\u6216\u8005\u628A\u7ED3\u8BBA\u5199\u5728\u8FD9\u4E00\u8F6E\u6700\u540E\u4E00\u6BB5\u56DE\u590D\u91CC\u3002`,
|
|
7773
8176
|
"\u548C\u5176\u4ED6 agent \u8BF4\u8BDD\u4E0D\u662F\u4E00\u95EE\u4E00\u7B54\uFF1A\u505A\u7684\u8FC7\u7A0B\u4E2D\u8981\u8BA9\u5BF9\u65B9\u77E5\u9053\u7684\uFF0C\u7528 agent_message \u7684 update\uFF0C\u9A6C\u4E0A\u9001\u5230\u5B83\u7684\u5BF9\u8BDD\u91CC\uFF0C\u8BF4\u51E0\u6B21\u90FD\u884C\uFF1B\u4E00\u4EF6\u4E8B\u4EA4\u56DE\u7ED3\u8BBA\u4EE5\u540E\u8FD8\u6709\u8BDD\uFF08\u6BD4\u5982\u5B9A\u65F6\u63D0\u9192\u5230\u4E86\uFF09\uFF0C\u540C\u6837\u7528 agent_message \u53D1\u5230\u90A3\u6761\u7EBF\u7D22\uFF0C\u4F60\u7684\u666E\u901A\u56DE\u590D\u5BF9\u65B9\u770B\u4E0D\u5230\u3002",
|
|
@@ -7785,7 +8188,7 @@ ${colleagues.map(line2).join("\n")}`,
|
|
|
7785
8188
|
].join("\n")
|
|
7786
8189
|
].filter((part) => part !== "").join("\n\n");
|
|
7787
8190
|
}
|
|
7788
|
-
var
|
|
8191
|
+
var MAX_KEPT3 = 5e3;
|
|
7789
8192
|
var SessionRoles = class {
|
|
7790
8193
|
#file;
|
|
7791
8194
|
#roles = /* @__PURE__ */ new Map();
|
|
@@ -7820,7 +8223,14 @@ var SessionRoles = class {
|
|
|
7820
8223
|
return role !== void 0 && this.#roles.has(role) ? role : void 0;
|
|
7821
8224
|
}
|
|
7822
8225
|
list() {
|
|
7823
|
-
return
|
|
8226
|
+
return this.#sorted().map(({ id, name, description, order }) => ({ id, name, description, order }));
|
|
8227
|
+
}
|
|
8228
|
+
/** The roles as the agents know them: what to hand each (`handles`), for their team list. */
|
|
8229
|
+
members() {
|
|
8230
|
+
return this.#sorted().map(({ id, name, description, handles }) => ({ id, name, description: handles ?? description }));
|
|
8231
|
+
}
|
|
8232
|
+
#sorted() {
|
|
8233
|
+
return [...this.#roles.values()].sort((a, b) => a.order - b.order || a.name.localeCompare(b.name));
|
|
7824
8234
|
}
|
|
7825
8235
|
/**
|
|
7826
8236
|
* The role a session belongs to: the one it was opened with, else the one
|
|
@@ -7851,11 +8261,11 @@ var SessionRoles = class {
|
|
|
7851
8261
|
return;
|
|
7852
8262
|
this.#tags.delete(sessionId);
|
|
7853
8263
|
this.#tags.set(sessionId, { role, ...by === void 0 ? {} : { by } });
|
|
7854
|
-
while (this.#tags.size >
|
|
8264
|
+
while (this.#tags.size > MAX_KEPT3)
|
|
7855
8265
|
this.#tags.delete(this.#tags.keys().next().value);
|
|
7856
8266
|
if (this.#file === void 0)
|
|
7857
8267
|
return;
|
|
7858
|
-
|
|
8268
|
+
mkdirSync3(dirname4(this.#file), { recursive: true });
|
|
7859
8269
|
const saved = Object.fromEntries([...this.#tags].map(([id, tag]) => [id, tag.by === void 0 ? tag.role : tag]));
|
|
7860
8270
|
await writeFileAtomic(this.#file, `${JSON.stringify(saved)}
|
|
7861
8271
|
`);
|
|
@@ -7882,8 +8292,8 @@ var SessionRoles = class {
|
|
|
7882
8292
|
|
|
7883
8293
|
// packages/gateway/lib/agent-models.js
|
|
7884
8294
|
import { readFile as readFile9 } from "node:fs/promises";
|
|
7885
|
-
import { mkdirSync as
|
|
7886
|
-
import { dirname as
|
|
8295
|
+
import { mkdirSync as mkdirSync4 } from "node:fs";
|
|
8296
|
+
import { dirname as dirname5 } from "node:path";
|
|
7887
8297
|
var LEGACY_ROLES = ["intervene", "games", "scripts", "pipelines"];
|
|
7888
8298
|
var EMPTY = { agents: {}, subAgents: null, subAgentsOf: {}, fallbacks: { agents: [], subAgents: [] } };
|
|
7889
8299
|
var AgentModels = class {
|
|
@@ -7934,7 +8344,7 @@ var AgentModels = class {
|
|
|
7934
8344
|
async #save() {
|
|
7935
8345
|
if (this.#file === void 0)
|
|
7936
8346
|
return;
|
|
7937
|
-
|
|
8347
|
+
mkdirSync4(dirname5(this.#file), { recursive: true });
|
|
7938
8348
|
await writeFileAtomic(this.#file, `${JSON.stringify(this.#state)}
|
|
7939
8349
|
`);
|
|
7940
8350
|
}
|
|
@@ -7993,7 +8403,7 @@ function distinct(list) {
|
|
|
7993
8403
|
}
|
|
7994
8404
|
|
|
7995
8405
|
// packages/gateway/lib/model-fallback.js
|
|
7996
|
-
import { randomUUID as
|
|
8406
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
7997
8407
|
function failureOf(error) {
|
|
7998
8408
|
if (error === null || typeof error !== "object")
|
|
7999
8409
|
return void 0;
|
|
@@ -8046,7 +8456,7 @@ function fallbackSummary(notice) {
|
|
|
8046
8456
|
}
|
|
8047
8457
|
function fallbackMessage(notice) {
|
|
8048
8458
|
return Object.freeze({
|
|
8049
|
-
id:
|
|
8459
|
+
id: randomUUID5(),
|
|
8050
8460
|
role: "user",
|
|
8051
8461
|
content: Object.freeze([Object.freeze({ type: "text", text: fallbackText(notice) })]),
|
|
8052
8462
|
source: Object.freeze({ kind: MODEL_FALLBACK_SOURCE, form: "notice", summary: fallbackSummary(notice), fallback: notice })
|
|
@@ -8323,7 +8733,7 @@ function toRpcError(error) {
|
|
|
8323
8733
|
|
|
8324
8734
|
// packages/gateway/lib/pick.js
|
|
8325
8735
|
import { execFile } from "node:child_process";
|
|
8326
|
-
import { isAbsolute as
|
|
8736
|
+
import { isAbsolute as isAbsolute3, normalize } from "node:path";
|
|
8327
8737
|
var SCRIPT = String.raw`
|
|
8328
8738
|
$ErrorActionPreference = 'Stop'
|
|
8329
8739
|
$ProgressPreference = 'SilentlyContinue'
|
|
@@ -8387,7 +8797,7 @@ function pickPath(options, signal) {
|
|
|
8387
8797
|
return Promise.reject(new Error("\u5DF2\u7ECF\u6253\u5F00\u4E86\u4E00\u4E2A\u9009\u62E9\u7A97\u53E3\uFF0C\u5148\u628A\u5B83\u5173\u6389"));
|
|
8388
8798
|
const extensions = (options.extensions ?? []).filter((e) => /^\w+$/.test(e));
|
|
8389
8799
|
const filter = extensions.length === 0 ? "" : `${(options.filterName ?? "\u6587\u4EF6").replace(/\|/g, "")}|${extensions.map((e) => `*.${e}`).join(";")}|\u6240\u6709\u6587\u4EF6|*.*`;
|
|
8390
|
-
const pending = new Promise((
|
|
8800
|
+
const pending = new Promise((resolve5, reject) => {
|
|
8391
8801
|
execFile("powershell.exe", ["-NoProfile", "-NonInteractive", "-STA", "-ExecutionPolicy", "Bypass", "-EncodedCommand", Buffer.from(SCRIPT, "utf16le").toString("base64")], {
|
|
8392
8802
|
windowsHide: true,
|
|
8393
8803
|
signal,
|
|
@@ -8396,7 +8806,7 @@ function pickPath(options, signal) {
|
|
|
8396
8806
|
...process.env,
|
|
8397
8807
|
ADG_PICK_KIND: options.kind,
|
|
8398
8808
|
ADG_PICK_TITLE: options.title ?? (options.kind === "folder" ? "\u9009\u62E9\u6587\u4EF6\u5939" : "\u9009\u62E9\u6587\u4EF6"),
|
|
8399
|
-
ADG_PICK_PATH: options.defaultPath !== void 0 &&
|
|
8809
|
+
ADG_PICK_PATH: options.defaultPath !== void 0 && isAbsolute3(options.defaultPath) ? normalize(options.defaultPath) : "",
|
|
8400
8810
|
ADG_PICK_FILTER: filter
|
|
8401
8811
|
}
|
|
8402
8812
|
}, (error, stdout, stderr) => {
|
|
@@ -8405,7 +8815,7 @@ function pickPath(options, signal) {
|
|
|
8405
8815
|
return;
|
|
8406
8816
|
}
|
|
8407
8817
|
const out = String(stdout).trim();
|
|
8408
|
-
|
|
8818
|
+
resolve5(out === "" ? void 0 : Buffer.from(out, "base64").toString("utf8"));
|
|
8409
8819
|
});
|
|
8410
8820
|
});
|
|
8411
8821
|
open = pending;
|
|
@@ -8419,8 +8829,8 @@ function pickPath(options, signal) {
|
|
|
8419
8829
|
|
|
8420
8830
|
// packages/gateway/lib/permissions.js
|
|
8421
8831
|
import { readFile as readFile10 } from "node:fs/promises";
|
|
8422
|
-
import { mkdirSync as
|
|
8423
|
-
import { dirname as
|
|
8832
|
+
import { mkdirSync as mkdirSync5 } from "node:fs";
|
|
8833
|
+
import { dirname as dirname6 } from "node:path";
|
|
8424
8834
|
var PRESET = { ask: "workspace-write", full: "full-access" };
|
|
8425
8835
|
var KEEP_RECENT = 50;
|
|
8426
8836
|
var Permissions = class {
|
|
@@ -8476,7 +8886,7 @@ var Permissions = class {
|
|
|
8476
8886
|
async #save() {
|
|
8477
8887
|
if (this.#file === void 0)
|
|
8478
8888
|
return;
|
|
8479
|
-
|
|
8889
|
+
mkdirSync5(dirname6(this.#file), { recursive: true });
|
|
8480
8890
|
await writeFileAtomic(this.#file, `${JSON.stringify({ mode: this.#mode, since: this.#since, areas: this.#areas }, null, 2)}
|
|
8481
8891
|
`);
|
|
8482
8892
|
}
|
|
@@ -8530,7 +8940,7 @@ var CapabilityRegistry = class {
|
|
|
8530
8940
|
// packages/gateway/lib/server.js
|
|
8531
8941
|
import { createReadStream, statSync } from "node:fs";
|
|
8532
8942
|
import { createServer } from "node:http";
|
|
8533
|
-
import { extname, join as
|
|
8943
|
+
import { extname, join as join7, normalize as normalize2, resolve as resolve3, sep } from "node:path";
|
|
8534
8944
|
import { timingSafeEqual } from "node:crypto";
|
|
8535
8945
|
|
|
8536
8946
|
// node_modules/.pnpm/ws@8.21.3/node_modules/ws/wrapper.mjs
|
|
@@ -8607,19 +9017,19 @@ function serveMounted(root, req, res) {
|
|
|
8607
9017
|
res.writeHead(404, { "content-type": "text/plain; charset=utf-8" }).end("\u8FD9\u4E2A\u5B89\u88C5\u6CA1\u6709\u5E26\u754C\u9762");
|
|
8608
9018
|
return;
|
|
8609
9019
|
}
|
|
8610
|
-
serveStatic(
|
|
9020
|
+
serveStatic(resolve3(root), req, res, pathname.slice(MOUNT.length));
|
|
8611
9021
|
}
|
|
8612
9022
|
function serveStatic(root, req, res, path) {
|
|
8613
9023
|
const pathname = decodeURIComponent(path ?? new URL(req.url ?? "/", "http://local").pathname);
|
|
8614
|
-
const target = normalize2(
|
|
9024
|
+
const target = normalize2(join7(root, pathname));
|
|
8615
9025
|
const inside = target === root || target.startsWith(root.endsWith(sep) ? root : root + sep);
|
|
8616
|
-
let file = inside ? target :
|
|
9026
|
+
let file = inside ? target : join7(root, "index.html");
|
|
8617
9027
|
try {
|
|
8618
9028
|
if (statSync(file).isDirectory())
|
|
8619
|
-
file =
|
|
9029
|
+
file = join7(file, "index.html");
|
|
8620
9030
|
statSync(file);
|
|
8621
9031
|
} catch {
|
|
8622
|
-
file =
|
|
9032
|
+
file = join7(root, "index.html");
|
|
8623
9033
|
}
|
|
8624
9034
|
try {
|
|
8625
9035
|
const size = statSync(file).size;
|
|
@@ -8635,7 +9045,7 @@ function serveStatic(root, req, res, path) {
|
|
|
8635
9045
|
}
|
|
8636
9046
|
}
|
|
8637
9047
|
async function startServer(options) {
|
|
8638
|
-
const staticRoot = options.staticDir === void 0 ? void 0 :
|
|
9048
|
+
const staticRoot = options.staticDir === void 0 ? void 0 : resolve3(options.staticDir);
|
|
8639
9049
|
const server = createServer((req, res) => {
|
|
8640
9050
|
if (!authorityAllowed(req.headers.host, options.trustedHosts)) {
|
|
8641
9051
|
res.writeHead(403).end("forbidden host");
|
|
@@ -8704,10 +9114,10 @@ Content-Length: 0\r
|
|
|
8704
9114
|
}
|
|
8705
9115
|
|
|
8706
9116
|
// packages/gateway/lib/instances.js
|
|
8707
|
-
import { mkdir as
|
|
9117
|
+
import { mkdir as mkdir6, readdir as readdir2, readFile as readFile11, rm as rm2 } from "node:fs/promises";
|
|
8708
9118
|
import { tmpdir } from "node:os";
|
|
8709
|
-
import { join as
|
|
8710
|
-
var INSTANCES_DIR =
|
|
9119
|
+
import { join as join8, resolve as resolve4 } from "node:path";
|
|
9120
|
+
var INSTANCES_DIR = join8(tmpdir(), "MultiGameAssistant", "instances");
|
|
8711
9121
|
var STALE_MS = 3 * 6e4;
|
|
8712
9122
|
var FORGET_MS = 24 * 60 * 6e4;
|
|
8713
9123
|
function copyLabel(shared, env = process.env) {
|
|
@@ -8720,7 +9130,7 @@ function copyLabel(shared, env = process.env) {
|
|
|
8720
9130
|
function sameDir(a, b) {
|
|
8721
9131
|
if (a === void 0 || b === void 0)
|
|
8722
9132
|
return false;
|
|
8723
|
-
const norm2 = (dir) => process.platform === "win32" ?
|
|
9133
|
+
const norm2 = (dir) => process.platform === "win32" ? resolve4(dir).toLowerCase() : resolve4(dir);
|
|
8724
9134
|
return norm2(a) === norm2(b);
|
|
8725
9135
|
}
|
|
8726
9136
|
function clashes(self, other) {
|
|
@@ -8817,22 +9227,22 @@ var Instances = class {
|
|
|
8817
9227
|
const self = this.#record();
|
|
8818
9228
|
const others = [];
|
|
8819
9229
|
try {
|
|
8820
|
-
await
|
|
9230
|
+
await mkdir6(this.#dir, { recursive: true });
|
|
8821
9231
|
await writeFileAtomic(this.#file(this.#pid), JSON.stringify(self));
|
|
8822
9232
|
const alive = this.#options.alive ?? processAlive;
|
|
8823
|
-
for (const name of await
|
|
9233
|
+
for (const name of await readdir2(this.#dir)) {
|
|
8824
9234
|
const match = /^(\d+)\.json$/.exec(name);
|
|
8825
9235
|
if (match === null || Number(match[1]) === this.#pid)
|
|
8826
9236
|
continue;
|
|
8827
9237
|
let other;
|
|
8828
9238
|
try {
|
|
8829
|
-
other = JSON.parse(await readFile11(
|
|
9239
|
+
other = JSON.parse(await readFile11(join8(this.#dir, name), "utf8"));
|
|
8830
9240
|
} catch {
|
|
8831
9241
|
continue;
|
|
8832
9242
|
}
|
|
8833
9243
|
const age = self.updatedAt - other.updatedAt;
|
|
8834
9244
|
if (!alive(other.pid) || age > FORGET_MS) {
|
|
8835
|
-
await rm2(
|
|
9245
|
+
await rm2(join8(this.#dir, name), { force: true }).catch(() => {
|
|
8836
9246
|
});
|
|
8837
9247
|
continue;
|
|
8838
9248
|
}
|
|
@@ -8850,7 +9260,7 @@ var Instances = class {
|
|
|
8850
9260
|
return changed;
|
|
8851
9261
|
}
|
|
8852
9262
|
#file(pid) {
|
|
8853
|
-
return
|
|
9263
|
+
return join8(this.#dir, `${pid}.json`);
|
|
8854
9264
|
}
|
|
8855
9265
|
#now() {
|
|
8856
9266
|
return (this.#options.now ?? Date.now)();
|
|
@@ -8859,10 +9269,10 @@ var Instances = class {
|
|
|
8859
9269
|
|
|
8860
9270
|
// packages/gateway/lib/shared.js
|
|
8861
9271
|
import { readFile as readFile12 } from "node:fs/promises";
|
|
8862
|
-
import { mkdirSync as
|
|
8863
|
-
import { dirname as
|
|
9272
|
+
import { mkdirSync as mkdirSync6 } from "node:fs";
|
|
9273
|
+
import { dirname as dirname7 } from "node:path";
|
|
8864
9274
|
var AGENT_PRESET = "mga";
|
|
8865
|
-
var
|
|
9275
|
+
var MAX_KEPT4 = 5e3;
|
|
8866
9276
|
var OwnSessions = class {
|
|
8867
9277
|
#file;
|
|
8868
9278
|
#ids = /* @__PURE__ */ new Set();
|
|
@@ -8879,11 +9289,11 @@ var OwnSessions = class {
|
|
|
8879
9289
|
if (this.#ids.has(sessionId))
|
|
8880
9290
|
return;
|
|
8881
9291
|
this.#ids.add(sessionId);
|
|
8882
|
-
while (this.#ids.size >
|
|
9292
|
+
while (this.#ids.size > MAX_KEPT4)
|
|
8883
9293
|
this.#ids.delete(this.#ids.values().next().value);
|
|
8884
9294
|
if (this.#file === void 0)
|
|
8885
9295
|
return;
|
|
8886
|
-
|
|
9296
|
+
mkdirSync6(dirname7(this.#file), { recursive: true });
|
|
8887
9297
|
await writeFileAtomic(this.#file, `${JSON.stringify([...this.#ids])}
|
|
8888
9298
|
`);
|
|
8889
9299
|
}
|
|
@@ -8905,6 +9315,7 @@ var AgentParts = class {
|
|
|
8905
9315
|
/** Tools the parts registered: the app's own, as opposed to dsh's (role agents are narrowed among these). */
|
|
8906
9316
|
tools = /* @__PURE__ */ new Set();
|
|
8907
9317
|
#parts = /* @__PURE__ */ new Map();
|
|
9318
|
+
#definitions = /* @__PURE__ */ new Map();
|
|
8908
9319
|
#scopes = /* @__PURE__ */ new Map();
|
|
8909
9320
|
#next = 0;
|
|
8910
9321
|
#log;
|
|
@@ -8939,6 +9350,10 @@ var AgentParts = class {
|
|
|
8939
9350
|
held.clear();
|
|
8940
9351
|
};
|
|
8941
9352
|
}
|
|
9353
|
+
/** An app tool as a part registered it, to run a call held for a lead (changes.ts). */
|
|
9354
|
+
definition(name) {
|
|
9355
|
+
return this.#definitions.get(name);
|
|
9356
|
+
}
|
|
8942
9357
|
#apply(scope, held, id, label, part) {
|
|
8943
9358
|
try {
|
|
8944
9359
|
const before = toolNames(scope);
|
|
@@ -8946,11 +9361,24 @@ var AgentParts = class {
|
|
|
8946
9361
|
for (const name of toolNames(scope))
|
|
8947
9362
|
if (!before.has(name))
|
|
8948
9363
|
this.tools.add(name);
|
|
9364
|
+
for (const definition2 of toolDefinitions(scope))
|
|
9365
|
+
if (!before.has(definition2.name))
|
|
9366
|
+
this.#definitions.set(definition2.name, definition2);
|
|
8949
9367
|
} catch (error) {
|
|
8950
9368
|
this.#log.warn(`${label} not registered for the app's agents: ${error instanceof Error ? error.message : String(error)}`);
|
|
8951
9369
|
}
|
|
8952
9370
|
}
|
|
8953
9371
|
};
|
|
9372
|
+
function toolDefinitions(scope) {
|
|
9373
|
+
const found = [];
|
|
9374
|
+
for (const key of [void 0, scope]) {
|
|
9375
|
+
try {
|
|
9376
|
+
found.push(...scope.tools.definitions(key));
|
|
9377
|
+
} catch {
|
|
9378
|
+
}
|
|
9379
|
+
}
|
|
9380
|
+
return found;
|
|
9381
|
+
}
|
|
8954
9382
|
function toolNames(scope) {
|
|
8955
9383
|
const names = /* @__PURE__ */ new Set();
|
|
8956
9384
|
for (const key of [void 0, scope]) {
|
|
@@ -9025,16 +9453,16 @@ function keptToken(dataDir, log) {
|
|
|
9025
9453
|
const fresh = () => randomBytes2(18).toString("base64url");
|
|
9026
9454
|
if (dataDir === void 0)
|
|
9027
9455
|
return fresh();
|
|
9028
|
-
const file =
|
|
9456
|
+
const file = join9(dataDir, "gateway-token");
|
|
9029
9457
|
try {
|
|
9030
|
-
const saved =
|
|
9458
|
+
const saved = readFileSync4(file, "utf8").trim();
|
|
9031
9459
|
if (/^[\w-]{16,}$/.test(saved))
|
|
9032
9460
|
return saved;
|
|
9033
9461
|
} catch {
|
|
9034
9462
|
}
|
|
9035
9463
|
const token = fresh();
|
|
9036
9464
|
try {
|
|
9037
|
-
|
|
9465
|
+
mkdirSync7(dataDir, { recursive: true });
|
|
9038
9466
|
writeFileSync(file, `${token}
|
|
9039
9467
|
`);
|
|
9040
9468
|
} catch (error) {
|
|
@@ -9048,7 +9476,7 @@ function ownerInfo(owner) {
|
|
|
9048
9476
|
return { owner: { ...owner.scripts === void 0 ? {} : { scripts: [...owner.scripts] }, ...owner.games === void 0 ? {} : { games: [...owner.games] } } };
|
|
9049
9477
|
}
|
|
9050
9478
|
var ROLE_CLOSING = [
|
|
9051
|
-
"\u8F6F\u4EF6\u6D3E\u53D1\u7684\u4EFB\u52A1\u7531\u4F60\u7684\u539F\u751F\u5B50 agent \u6267\u884C\u3002\u53EA\u6536\u5230\u6D3E\u53D1\u901A\u77E5\u65F6\u53EF\u4EE5\u7ED3\u675F\u672C\u8F6E\uFF0C\u6536\u5230\u5B50\u4EFB\u52A1\u7684\u4EA4\u4ED8\u901A\u77E5\u540E\
|
|
9479
|
+
"\u8F6F\u4EF6\u6D3E\u53D1\u7684\u4EFB\u52A1\u7531\u4F60\u7684\u539F\u751F\u5B50 agent \u6267\u884C\u3002\u53EA\u6536\u5230\u6D3E\u53D1\u901A\u77E5\u65F6\u53EF\u4EE5\u7ED3\u675F\u672C\u8F6E\uFF0C\u6536\u5230\u5B50\u4EFB\u52A1\u7684\u4EA4\u4ED8\u901A\u77E5\u540E\uFF0C\u6309\u4EFB\u52A1\u91CC\u7684\u5B8C\u6210\u6807\u51C6\u6838\u5BF9\u5B83\u5E26\u56DE\u7684\u8BC1\u636E\uFF0C\u518D\u5904\u7406\u7ED3\u679C\u5E76\u6C47\u62A5\u3002\u81EA\u884C\u5B89\u6392\u672C\u89D2\u8272\u5DE5\u4F5C\u65F6\u7528 subagent\uFF1Bagent_delegate \u7528\u4E8E\u4E0D\u540C\u89D2\u8272\u4E4B\u95F4\u7684\u534F\u4F5C\u3002",
|
|
9052
9480
|
"\u8FD9\u662F\u4F60\u552F\u4E00\u7684\u5BF9\u8BDD\uFF1A\u7528\u6237\u76F4\u63A5\u627E\u4F60\u8BF4\u7684\u8BDD\u3001\u522B\u7684 agent \u548C\u8F6F\u4EF6\u4EA4\u7ED9\u4F60\u7684\u4E8B\uFF08\u6D88\u606F\u5F00\u5934\u5199\u7740\u300C\uFF08\u2026\u4EA4\u7ED9\u4F60\u7684\u4E8B\uFF1A\u2026\uFF09\u300D\uFF09\u90FD\u5728\u8FD9\u91CC\uFF0C\u4E00\u4EF6\u63A5\u4E00\u4EF6\u3002",
|
|
9053
9481
|
"\u80FD\u7528\u5DE5\u5177\u3001\u547D\u4EE4\u884C\u3001\u8BFB\u6587\u4EF6\uFF08\u914D\u7F6E\u3001\u65E5\u5FD7\u3001\u7248\u672C\u53F7\uFF09\u6216\u811A\u672C\u81EA\u5DF1\u7684\u547D\u4EE4\u548C\u8BBE\u7F6E\u505A\u5230\u3001\u786E\u8BA4\u5230\u7684\uFF0C\u5C31\u8FD9\u6837\u505A\uFF1B\u622A\u56FE\u3001\u770B\u753B\u9762\u3001\u70B9\u5C4F\u5E55\u662F\u6700\u540E\u7684\u529E\u6CD5\u2014\u2014\u53EA\u6709\u753B\u9762\u4E0A\u624D\u770B\u5F97\u5230\u3001\u522B\u7684\u529E\u6CD5\u90FD\u786E\u8BA4\u4E0D\u4E86\u65F6\u624D\u7528\uFF0C\u7528\u4E4B\u524D\u5148\u8BF4\u4E3A\u4EC0\u4E48\u3002",
|
|
9054
9482
|
"\u4F60\u6BCF\u4E00\u8F6E\u6700\u540E\u4E00\u6BB5\u56DE\u590D\u5C31\u662F\u8FD9\u4EF6\u4E8B\u7684\u7ED3\u8BBA\uFF1A\u5199\u6E05\u695A\u7ED3\u679C\uFF0C\u4EE5\u53CA\u9700\u8981\u7528\u6237\u505A\u7684\u4E8B\uFF08\u6CA1\u6709\u5C31\u4E0D\u5199\uFF09\u3002\u522B\u4EBA\u4EA4\u7ED9\u4F60\u7684\u4E8B\uFF0C\u8FD9\u6BB5\u56DE\u590D\u4F1A\u4F5C\u4E3A\u7ED3\u8BBA\u4EA4\u56DE\u7ED9\u5B83\uFF1B\u5728\u90A3\u4E4B\u524D\u3001\u5728\u90A3\u4E4B\u540E\u8981\u8BA9\u5B83\u77E5\u9053\u7684\uFF0C\u7528 agent_message \u53D1\u5230\u90A3\u6761\u7EBF\u7D22\u3002"
|
|
@@ -9075,17 +9503,25 @@ var MAIN_AGENT = {
|
|
|
9075
9503
|
"game_list",
|
|
9076
9504
|
"game_activities",
|
|
9077
9505
|
"game_report",
|
|
9078
|
-
|
|
9079
|
-
"
|
|
9506
|
+
// Where pipelines stand, and starting one; making and timing them is 编排's (no draft tool here either).
|
|
9507
|
+
"pipeline_list",
|
|
9508
|
+
"pipeline_get",
|
|
9509
|
+
"pipeline_status",
|
|
9510
|
+
"pipeline_run",
|
|
9511
|
+
// A task the user named, started or stopped in one call (roles.ts LIGHT); choosing, settings and failures are 脚本's.
|
|
9512
|
+
"script_run",
|
|
9513
|
+
"script_stop",
|
|
9514
|
+
// Timed tasks: at a time, an agent does one thing. dsh's reminders (schedule_create…) stay besides.
|
|
9515
|
+
"schedule_task_*",
|
|
9080
9516
|
"monitor_incidents",
|
|
9081
9517
|
"monitor_stall_check",
|
|
9082
9518
|
"emulator_status",
|
|
9083
9519
|
"window_list",
|
|
9520
|
+
// The user's chat and the runs' logs to a folder, in one call (history-export.ts).
|
|
9521
|
+
"history_export",
|
|
9084
9522
|
// The built-in browser, for its sub-agents (its own conversation hands it out: roles.ts HANDS_ON).
|
|
9085
9523
|
"browser_*"
|
|
9086
|
-
]
|
|
9087
|
-
// Saving a pipeline outright is 编排's: 助手 drafts one for the user, or hands the change to 编排.
|
|
9088
|
-
hide: ["pipeline_save"]
|
|
9524
|
+
]
|
|
9089
9525
|
};
|
|
9090
9526
|
function memoryOwnerOf(spec) {
|
|
9091
9527
|
return spec.subAgentOf === void 0 ? spec.id : spec.id.replace(/:sub$/, "");
|
|
@@ -9097,14 +9533,15 @@ var MAIN_AGENT_MEMBER = { id: MAIN_AGENT.id, name: MAIN_AGENT.name, description:
|
|
|
9097
9533
|
function mainDuty(roles) {
|
|
9098
9534
|
return [
|
|
9099
9535
|
"# \u4F60\u7684\u89D2\u8272\uFF1A\u52A9\u624B",
|
|
9100
|
-
"\u4F60\u662F\u7528\u6237\u7684\u52A9\u624B\uFF1A\u548C\u7528\u6237\u5BF9\u8BDD\uFF0C\u5F04\u6E05\u8981\u505A\u4EC0\u4E48\uFF0C\u5B89\u6392\u8C01\u6765\u505A\u3002\u622A\u56FE\u70B9\u51FB\u3001\
|
|
9101
|
-
"\u7528\u6237\u8981\u5728\u6E38\u620F\u91CC\u505A\u4E00\u4EF6\u4E8B\u65F6\uFF0C\u4EA4\u51FA\u53BB\u4E4B\u524D\u5148\u7528 script_list\u3001script_tasks \u770B\u8FD9\u4E2A\u6E38\u620F\u4E0B\u7684\u811A\u672C\u6709\u6CA1\u6709\u8FD9\u4E2A\u529F\u80FD\uFF1A\u6709\uFF0C\u5C31\u4EA4\u7ED9\u300C\u811A\u672C\u300Dagent\uFF0C\u5199\u660E\u7528\u54EA\u4E2A\u811A\u672C\u7684\u54EA\u4E2A\u4EFB\u52A1\
|
|
9102
|
-
|
|
9103
|
-
|
|
9104
|
-
"\
|
|
9105
|
-
"\
|
|
9536
|
+
"\u4F60\u662F\u7528\u6237\u7684\u52A9\u624B\uFF1A\u548C\u7528\u6237\u5BF9\u8BDD\uFF0C\u5F04\u6E05\u8981\u505A\u4EC0\u4E48\uFF0C\u5B89\u6392\u8C01\u6765\u505A\u3002\u622A\u56FE\u70B9\u51FB\u3001\u5B89\u88C5\u811A\u672C\u3001\u6539\u811A\u672C\u8BBE\u7F6E\u3001\u5206\u6790\u811A\u672C\u548C\u5199\u811A\u672C\u5305\u3001\u8BFB\u6E38\u620F\u3001\u6392\u6D41\u6C34\u7EBF\u8FD9\u4E9B\u5177\u4F53\u7684\u4E8B\u4EA4\u7ED9\u5BF9\u5E94\u7684 agent\uFF08agent_delegate\uFF09\uFF0C\u4F60\u81EA\u5DF1\u4E0D\u505A\u3002\u5206\u6790\u811A\u672C\u3001\u5199\u6216\u6539\u811A\u672C\u5305\u4EA4\u7ED9\u300C\u811A\u672C\u300D\uFF1A\u4FDD\u5B58\u811A\u672C\u5305\u7684 pack_propose \u53EA\u6709\u5B83\u6709\uFF0C\u4F60\u7684\u5B50 agent \u6CA1\u6709\u3002\u65B0\u5EFA\u3001\u4FEE\u6539\u6D41\u6C34\u7EBF\u548C\u5B83\u4EEC\u7684\u5B9A\u65F6\u4EA4\u7ED9\u300C\u7F16\u6392\u300D\uFF1A\u4FDD\u5B58\u6D41\u6C34\u7EBF\u53EA\u6709\u5B83\u80FD\u505A\u3002",
|
|
9537
|
+
"\u7528\u6237\u8981\u5728\u6E38\u620F\u91CC\u505A\u4E00\u4EF6\u4E8B\u65F6\uFF0C\u4EA4\u51FA\u53BB\u4E4B\u524D\u5148\u7528 script_list\u3001script_tasks \u770B\u8FD9\u4E2A\u6E38\u620F\u4E0B\u7684\u811A\u672C\u6709\u6CA1\u6709\u8FD9\u4E2A\u529F\u80FD\uFF1A\u6709\uFF0C\u800C\u4E14\u5C31\u662F\u7528\u6237\u8BF4\u7684\u90A3\u4E2A\u4EFB\u52A1\u3001\u4E0D\u7528\u6539\u8BBE\u7F6E\uFF0C\u4F60\u81EA\u5DF1\u7528 script_run \u542F\u52A8\u5B83\uFF08\u8981\u7B49\u7ED3\u679C\uFF0C\u7528 script_runs \u5E26\u4E0A run_id \u548C wait_seconds\uFF09\uFF0C\u8981\u505C\u7528 script_stop\uFF1B\u8981\u5728\u51E0\u4E2A\u811A\u672C\u91CC\u6311\u3001\u8981\u6539\u8BBE\u7F6E\u3001\u8DD1\u5931\u8D25\u4E86\u8981\u5904\u7406\uFF0C\u4EA4\u7ED9\u300C\u811A\u672C\u300Dagent\uFF0C\u5199\u660E\u7528\u54EA\u4E2A\u811A\u672C\u7684\u54EA\u4E2A\u4EFB\u52A1\uFF1B\u811A\u672C\u81EA\u5E26 MCP \u670D\u52A1\u65F6\uFF08script_mcp_list\uFF09\uFF0C\u300C\u811A\u672C\u300Dagent \u8FD8\u80FD\u76F4\u63A5\u8C03\u7528\u5B83\u7684\u5DE5\u5177\uFF0C\u505A\u5230\u6574\u4E2A\u4EFB\u52A1\u4E4B\u5916\u7684\u7EC6\u7C92\u5EA6\u64CD\u4F5C\uFF08\u67E5\u72B6\u6001\u3001\u53EA\u8DD1\u67D0\u4E00\u9879\u3001\u6539\u8BBE\u7F6E\uFF09\uFF0C\u4E5F\u4EA4\u7ED9\u5B83\uFF1B\u786E\u8BA4\u811A\u672C\u90FD\u505A\u4E0D\u4E86\uFF0C\u624D\u4EA4\u7ED9\u80FD\u622A\u56FE\u70B9\u51FB\u7684 agent \u81EA\u5DF1\u52A8\u624B\uFF0C\u5E76\u5728\u4EFB\u52A1\u91CC\u5199\u4E0A\u811A\u672C\u4E3A\u4EC0\u4E48\u505A\u4E0D\u4E86\u3002",
|
|
9538
|
+
// Who they are and what each takes is the team section's list (teamPrompt): not twice in the prompt.
|
|
9539
|
+
roles.length === 0 ? "\u73B0\u5728\u6CA1\u6709\u53EF\u4EE5\u4EA4\u7ED9\u7684 agent\uFF0C\u80FD\u505A\u7684\u4F60\u81EA\u5DF1\u505A\u3002" : "\u53EF\u4EE5\u4EA4\u7ED9\u8C01\u3001\u5404\u81EA\u505A\u4EC0\u4E48\uFF0C\u89C1\u300C\u56E2\u961F\u300D\u91CC\u7684\u4E3B agent \u5217\u8868\uFF1A\u6309\u90A3\u91CC\u5199\u7684\u4EA4\uFF0C\u4EA4\u9519\u4E86\uFF0C\u5BF9\u65B9\u6CA1\u6709\u505A\u8FD9\u4EF6\u4E8B\u7684\u5DE5\u5177\u3002",
|
|
9540
|
+
"\u8FD9\u4E9B\u4F60\u81EA\u5DF1\u505A\uFF0C\u4E0D\u4EA4\u51FA\u53BB\uFF0C\u4E5F\u4E0D\u5F00\u5B50 agent\uFF1A\u5BFC\u51FA\u804A\u5929\u8BB0\u5F55\u548C\u811A\u672C\u8FD0\u884C\u65E5\u5FD7\u7528 history_export\uFF0C\u4E00\u6B21\u8C03\u7528\u5C31\u628A\u6574\u4E2A\u6587\u4EF6\u5939\u5199\u597D\uFF0C\u4E0D\u8981\u53BB\u7FFB\u8F6F\u4EF6\u7684\u6570\u636E\u76EE\u5F55\u6216\u6E90\u7801\uFF1B\u63D0\u9192\uFF08schedule_create\uFF09\u548C\u5230\u70B9\u8BA9\u67D0\u4E2A agent \u505A\u4E00\u4EF6\u4E8B\u7684\u5B9A\u65F6\u4EFB\u52A1\uFF08schedule_task_save\uFF09\u4F60\u81EA\u5DF1\u8BBE\uFF1B\u67E5\u811A\u672C\u3001\u8FD0\u884C\u8BB0\u5F55\u548C\u65E5\u5FD7\u3001\u6E38\u620F\u6D3B\u52A8\u3001\u6D41\u6C34\u7EBF\u72B6\u6001\u8FD9\u4E9B\u770B\u4E00\u773C\u7684\u4E8B\uFF0C\u7528\u4F60\u81EA\u5DF1\u7684\u5DE5\u5177\u3002",
|
|
9541
|
+
"\u8FD0\u884C\u547D\u4EE4\u3001\u6539\u6587\u4EF6\u8FD9\u4E9B\u5DE5\u5177\u4E0D\u5728\u4F60\u7684\u5BF9\u8BDD\u91CC\uFF1A\u7528\u6237\u8981\u7684\u8FD9\u7C7B\u4E8B\uFF08\u6574\u7406\u6587\u4EF6\u3001\u67E5\u7CFB\u7EDF\uFF09\uFF0C\u8FD8\u6709\u67E5\u8D44\u6599\u3001\u6BD4\u8F83\u51E0\u4E2A\u65B9\u6848\uFF0C\u5F00\u81EA\u5DF1\u7684\u5B50 agent\uFF08subagent\uFF09\u53BB\u505A\uFF0C\u5B83\u628A\u7ED3\u679C\u4EA4\u56DE\u6765\uFF0C\u4F60\u544A\u8BC9\u7528\u6237\u3002",
|
|
9542
|
+
"\u4EA4\u51FA\u53BB\u7684\u4E8B\u5728\u90A3\u4E2A agent \u81EA\u5DF1\u7684\u5BF9\u8BDD\u91CC\u505A\uFF0C\u5B83\u770B\u4E0D\u5230\u4F60\u548C\u7528\u6237\u7684\u5BF9\u8BDD\u3002agent_delegate \u7684 task \u5199\u76EE\u6807\u548C\u4F60\u5DF2\u7ECF\u77E5\u9053\u7684\u60C5\u51B5\uFF0Climits \u5199\u8FB9\u754C\uFF0Cdone_when \u5199\u5B8C\u6210\u6807\u51C6\uFF0Cexpecting \u5199\u8981\u5B83\u5E26\u56DE\u7684\u8BC1\u636E\uFF1B\u7528\u6237\u5DF2\u7ECF\u660E\u786E\u8981\u505A\u7684\u6539\u52A8\uFF08\u88C5\u3001\u5220\u3001\u6539\u8BBE\u7F6E\u3001\u5B58\u6280\u80FD\uFF09\uFF0C\u90A3\u4E00\u7C7B\u5199\u8FDB allow\uFF0C\u5B83\u5C31\u76F4\u63A5\u505A\uFF0C\u4E0D\u7136\u5B83\u4F1A\u5148\u4EA4\u56DE\u53BB\u51B3\u5B9A\u3002\u4E0D\u5199\u4E00\u6B65\u6B65\u600E\u4E48\u505A\uFF0C\u7528\u4EC0\u4E48\u5DE5\u5177\u7531\u5B83\u51B3\u5B9A\u3002\u4EA4\u51FA\u53BB\u4EE5\u540E\u7528\u4E00\u53E5\u8BDD\u544A\u8BC9\u7528\u6237\u4EA4\u7ED9\u4E86\u8C01\u3001\u505A\u4EC0\u4E48\uFF0C\u7136\u540E\u7ED3\u675F\u8FD9\u4E00\u8F6E\uFF1A\u4E0D\u8981\u7B49\u5B83\uFF0C\u4E5F\u4E0D\u8981\u66FF\u5B83\u56DE\u7B54\u3002",
|
|
9106
9543
|
"\u5B83\u505A\u7684\u8FC7\u7A0B\u4E2D\u53EF\u80FD\u56DE\u5934\u95EE\u4F60\uFF08\u6D88\u606F\u5F00\u5934\u662F\u300C\uFF08\u300C\u67D0 agent\u300D\u5728\u7EBF\u7D22 \u2026 \u91CC\u95EE\u4F60\uFF1A\u2026\uFF09\u300D\uFF09\uFF0C\u8FD9\u79CD\u6D88\u606F\u4F1A\u63D2\u8FDB\u4F60\u6B63\u5728\u505A\u7684\u4E8B\uFF1A\u5B83\u5728\u7B49\uFF0C\u5148\u56DE\u7B54\u5B83\u3002\u80FD\u7B54\u5C31\u7528 agent_message \u56DE\u7B54\uFF1B\u8981\u7528\u6237\u51B3\u5B9A\u7684\uFF0C\u5148\u7528 kind: update \u8BF4\u4E00\u58F0\u3001\u53BB\u95EE\u7528\u6237\uFF0C\u6709\u4E86\u7ED3\u679C\u518D\u56DE\u7B54\u3002\u5B83\u4E5F\u53EF\u80FD\u53EA\u662F\u544A\u8BC9\u4F60\u4E00\u4EF6\u4E8B\uFF08\u300C\u2026 \u91CC\u544A\u8BC9\u4F60\uFF1A\u2026\u300D\uFF09\uFF0C\u4E0D\u7528\u56DE\u5B83\u3002\u4F60\u8981\u8865\u5145\u6216\u6539\u4E3B\u610F\uFF0C\u540C\u6837\u7528 agent_message \u53D1\u5230\u90A3\u6761\u7EBF\u7D22\uFF0C\u9A6C\u4E0A\u9001\u5230\u5B83\u90A3\u91CC\u3002",
|
|
9107
|
-
"\u5B83\u505A\u5B8C\u540E\uFF0C\u56DE\u590D\u4F1A\u4F5C\u4E3A\u4E00\u6761\u65B0\u6D88\u606F\u53D1\u5230\u8FD9\u91CC\uFF0C\u5F00\u5934\u662F\u300C\uFF08\u300C\u67D0 agent\u300D\u4EA4\u56DE\u4E86\u2026\uFF09\u300D\u6216\u300C\uFF08\u300C\u67D0 agent\u300D\u6CA1\u6709\u505A\u5B8C\u2026\uFF09\u300D\u3002\u6536\u5230\u540E\u7528\u4E00\u4E24\u53E5\u8BDD\u628A\u8981\u70B9\u544A\u8BC9\u7528\u6237\uFF1A\u7ED3\u8BBA\u3001\u8981\u7528\u6237\u505A\u7684\u4E8B\u3002\u6CA1\u505A\u6210\u5C31\u76F4\u8BF4\uFF1A\u6CA1\u505A\u6210\u3001\u5F53\u65F6\u8BF7\u5B83\u505A\u4EC0\u4E48\u3001\u4F60\u63A5\u4E0B\u6765\u80FD\u505A\u4EC0\u4E48\u3002",
|
|
9544
|
+
"\u5B83\u505A\u5B8C\u540E\uFF0C\u56DE\u590D\u4F1A\u4F5C\u4E3A\u4E00\u6761\u65B0\u6D88\u606F\u53D1\u5230\u8FD9\u91CC\uFF0C\u5F00\u5934\u662F\u300C\uFF08\u300C\u67D0 agent\u300D\u4EA4\u56DE\u4E86\u2026\uFF09\u300D\u6216\u300C\uFF08\u300C\u67D0 agent\u300D\u6CA1\u6709\u505A\u5B8C\u2026\uFF09\u300D\u3002\u6536\u5230\u540E\u5148\u770B\u5B83\u5E26\u56DE\u7684\u8BC1\u636E\u5BF9\u4E0D\u5BF9\u5F97\u4E0A\u5B8C\u6210\u6807\u51C6\uFF08\u770B\u5F97\u5230\u7684\u7528\u4F60\u7684\u5DE5\u5177\u770B\u4E00\u773C\uFF0C\u4E0D\u8981\u91CD\u505A\uFF09\uFF0C\u5BF9\u4E0D\u4E0A\u5C31\u7528 agent_message \u8BA9\u5B83\u8865\uFF0C\u6216\u8005\u7167\u5B9E\u544A\u8BC9\u7528\u6237\u6CA1\u505A\u6210\uFF1B\u5BF9\u5F97\u4E0A\u5C31\u7528\u4E00\u4E24\u53E5\u8BDD\u628A\u8981\u70B9\u544A\u8BC9\u7528\u6237\uFF1A\u7ED3\u8BBA\u3001\u8981\u7528\u6237\u505A\u7684\u4E8B\u3002\u6CA1\u505A\u6210\u5C31\u76F4\u8BF4\uFF1A\u6CA1\u505A\u6210\u3001\u5F53\u65F6\u8BF7\u5B83\u505A\u4EC0\u4E48\u3001\u4F60\u63A5\u4E0B\u6765\u80FD\u505A\u4EC0\u4E48\u3002",
|
|
9108
9545
|
"\u8F6F\u4EF6\u81EA\u5DF1\u4E5F\u4F1A\u628A\u4E8B\u4EA4\u7ED9 agent\uFF08\u6BD4\u5982\u76D1\u63A7\u53D1\u73B0\u811A\u672C\u51FA\u4E86\u95EE\u9898\uFF0C\u4EA4\u7ED9\u5E72\u9884\u5904\u7406\uFF09\uFF0C\u7ED3\u679C\u540C\u6837\u53D1\u5230\u8FD9\u91CC\uFF0C\u4F60\u7167\u6837\u628A\u8981\u70B9\u544A\u8BC9\u7528\u6237\u3002\u4E3B agent \u4E4B\u95F4\u53EF\u4EE5\u76F4\u63A5\u4EA4\u6D41\uFF0C\u4E0D\u4F1A\u53EB\u9192\u4F60\uFF1B\u8981\u77E5\u9053\u5B83\u4EEC\u8BF4\u4E86\u4EC0\u4E48\uFF0C\u7528 agent_threads \u770B\u3002\u7528\u6237\u4E5F\u53EF\u4EE5\u76F4\u63A5\u53BB\u67D0\u4E2A agent \u7684\u5BF9\u8BDD\u91CC\u627E\u5B83\uFF0C\u90A3\u4E9B\u4F60\u770B\u4E0D\u5230\u3002"
|
|
9109
9546
|
].join("\n\n");
|
|
9110
9547
|
}
|
|
@@ -9113,6 +9550,8 @@ var AdgGateway = class extends Service {
|
|
|
9113
9550
|
registry = new CapabilityRegistry();
|
|
9114
9551
|
workspace;
|
|
9115
9552
|
archived = /* @__PURE__ */ new Set();
|
|
9553
|
+
/** What other parts of the app add to history_export (the runner's run logs). */
|
|
9554
|
+
exportParts = /* @__PURE__ */ new Set();
|
|
9116
9555
|
/** The latest context projections per session (a control frame carries only the keys its event changed). */
|
|
9117
9556
|
contexts = /* @__PURE__ */ new Map();
|
|
9118
9557
|
/** The latest non-empty inbox projection per session, so the queue can be sent again when only the taken messages change. */
|
|
@@ -9167,6 +9606,10 @@ var AdgGateway = class extends Service {
|
|
|
9167
9606
|
agents = /* @__PURE__ */ new Map();
|
|
9168
9607
|
narrowed = /* @__PURE__ */ new Map();
|
|
9169
9608
|
appChildren = /* @__PURE__ */ new Set();
|
|
9609
|
+
/** Lasting changes sub-agents asked for, held for their leads (changes.ts). */
|
|
9610
|
+
held;
|
|
9611
|
+
/** What each sub-agent's brief lets it change itself (grantsIn), read once. */
|
|
9612
|
+
grants = /* @__PURE__ */ new Map();
|
|
9170
9613
|
assignedSpecs = /* @__PURE__ */ new WeakMap();
|
|
9171
9614
|
subAgentSpecs = /* @__PURE__ */ new WeakMap();
|
|
9172
9615
|
persona;
|
|
@@ -9187,13 +9630,14 @@ var AdgGateway = class extends Service {
|
|
|
9187
9630
|
this.log = log;
|
|
9188
9631
|
this.workspace = config.workspaceDir;
|
|
9189
9632
|
this.shared = config.shared === true;
|
|
9190
|
-
this.own = new OwnSessions(this.shared && config.dataDir !== void 0 ?
|
|
9633
|
+
this.own = new OwnSessions(this.shared && config.dataDir !== void 0 ? join9(config.dataDir, "own-sessions.json") : void 0);
|
|
9191
9634
|
this.parts = new AgentParts(log);
|
|
9192
9635
|
this.newInput = new NewInput(ctx);
|
|
9193
|
-
this.agentModels = new AgentModels(config.dataDir === void 0 ? void 0 :
|
|
9194
|
-
this.roles = new SessionRoles(config.dataDir === void 0 ? void 0 :
|
|
9195
|
-
this.
|
|
9196
|
-
this.
|
|
9636
|
+
this.agentModels = new AgentModels(config.dataDir === void 0 ? void 0 : join9(config.dataDir, "agent-models.json"), config.dataDir === void 0 ? void 0 : join9(config.dataDir, "role-model.json"));
|
|
9637
|
+
this.roles = new SessionRoles(config.dataDir === void 0 ? void 0 : join9(config.dataDir, "session-roles.json"), () => this.broadcast("roles/changed", { items: this.roles.list() }));
|
|
9638
|
+
this.held = new HeldChanges(config.dataDir === void 0 ? void 0 : join9(config.dataDir, "held-changes.json"));
|
|
9639
|
+
this.homes = new AgentHomes(config.dataDir === void 0 ? void 0 : join9(config.dataDir, "agent-homes.json"));
|
|
9640
|
+
this.handOffs = new HandOffs(config.dataDir === void 0 ? void 0 : join9(config.dataDir, "handoffs.json"), (item) => this.broadcast("handoffs/changed", { item }), log);
|
|
9197
9641
|
if (!this.shared)
|
|
9198
9642
|
ctx.inject(["tools", "systemPrompt"], (scoped) => {
|
|
9199
9643
|
scoped.effect(() => this.parts.attach(scoped), "adg-gateway agent parts");
|
|
@@ -9232,7 +9676,7 @@ var AdgGateway = class extends Service {
|
|
|
9232
9676
|
});
|
|
9233
9677
|
if (config.workspaceDir !== void 0) {
|
|
9234
9678
|
try {
|
|
9235
|
-
|
|
9679
|
+
mkdirSync7(config.workspaceDir, { recursive: true });
|
|
9236
9680
|
} catch (error) {
|
|
9237
9681
|
log.warn(`cannot create the workspace ${config.workspaceDir}: ${String(error)}`);
|
|
9238
9682
|
}
|
|
@@ -9321,7 +9765,7 @@ var AdgGateway = class extends Service {
|
|
|
9321
9765
|
}
|
|
9322
9766
|
}
|
|
9323
9767
|
}), "adg-gateway capability questions");
|
|
9324
|
-
this.permissions = new Permissions(config.dataDir === void 0 ? void 0 :
|
|
9768
|
+
this.permissions = new Permissions(config.dataDir === void 0 ? void 0 : join9(config.dataDir, "permissions.json"));
|
|
9325
9769
|
const presetFor = (session) => {
|
|
9326
9770
|
const presets = ctx.get("permissionPresets");
|
|
9327
9771
|
if (presets === void 0 || !this.isOwn(session.id))
|
|
@@ -9379,6 +9823,9 @@ var AdgGateway = class extends Service {
|
|
|
9379
9823
|
if (noted !== void 0)
|
|
9380
9824
|
exec.arguments = { ...exec.arguments, prompt: noted };
|
|
9381
9825
|
}
|
|
9826
|
+
const held = this.holdForLead(exec);
|
|
9827
|
+
if (held !== void 0)
|
|
9828
|
+
return held;
|
|
9382
9829
|
return next();
|
|
9383
9830
|
}));
|
|
9384
9831
|
ctx.on("tools/result", ((exec, result) => {
|
|
@@ -9595,7 +10042,7 @@ var AdgGateway = class extends Service {
|
|
|
9595
10042
|
}
|
|
9596
10043
|
} catch {
|
|
9597
10044
|
}
|
|
9598
|
-
await new Promise((
|
|
10045
|
+
await new Promise((resolve5) => setTimeout(resolve5, Math.min(3e4, 1e3 * 2 ** attempt)));
|
|
9599
10046
|
}
|
|
9600
10047
|
})();
|
|
9601
10048
|
return () => controller.abort();
|
|
@@ -9671,7 +10118,8 @@ var AdgGateway = class extends Service {
|
|
|
9671
10118
|
id: SKILLS_CAPABILITY,
|
|
9672
10119
|
version: 1,
|
|
9673
10120
|
methods: {
|
|
9674
|
-
|
|
10121
|
+
// Not the names taken over so nobody sees dsh's skill of that name (skill-scope.ts SHADOWED_SKILLS).
|
|
10122
|
+
"skills/list": async (_params, call) => ({ skills: (await scoped.skills.list(options(call.signal))).filter((s) => s.invocation?.modelInvocable !== false || s.invocation?.userInvocable !== false).map(info) }),
|
|
9675
10123
|
"skills/get": async (params, call) => {
|
|
9676
10124
|
const { name } = params;
|
|
9677
10125
|
const skill = await scoped.skills.get(name, options(call.signal));
|
|
@@ -9834,12 +10282,12 @@ var AdgGateway = class extends Service {
|
|
|
9834
10282
|
this.persona = persona;
|
|
9835
10283
|
}
|
|
9836
10284
|
if (config.dataDir !== void 0) {
|
|
9837
|
-
const memory = new MemoryStore(
|
|
10285
|
+
const memory = new MemoryStore(join9(config.dataDir, "memory.json"), () => this.broadcast("memory/changed", {}));
|
|
9838
10286
|
const views = new MemoryViews(memory, { timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone });
|
|
9839
10287
|
this.memoryViews = views;
|
|
9840
10288
|
const auto = new AutoMemory({
|
|
9841
10289
|
store: memory,
|
|
9842
|
-
file:
|
|
10290
|
+
file: join9(config.dataDir, "memory-auto.json"),
|
|
9843
10291
|
// Back to where it stopped (oldest unread first): nothing between is passed over.
|
|
9844
10292
|
read: (sessionId, since, signal) => this.sessionEvents(sessionId, since.maxMessages, signal, since.after),
|
|
9845
10293
|
agentOf: (sessionId) => {
|
|
@@ -9916,11 +10364,31 @@ var AdgGateway = class extends Service {
|
|
|
9916
10364
|
sessions: (agent, signal) => this.sessionsOf(agent, signal),
|
|
9917
10365
|
read: (sessionId, maxMessages, signal) => this.sessionEvents(sessionId, maxMessages, signal),
|
|
9918
10366
|
memory: (id) => memory.get(id),
|
|
9919
|
-
archived: summariesReader(
|
|
10367
|
+
archived: summariesReader(join9(config.dataDir, SUMMARIES_FILE)),
|
|
9920
10368
|
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
9921
10369
|
});
|
|
9922
10370
|
for (const tool of history)
|
|
9923
10371
|
this.agentPart(`adg-gateway ${tool.name}`, (agent) => agent.tools.register(tool));
|
|
10372
|
+
const exporter = historyExportTool({
|
|
10373
|
+
agentOf: (sessionId) => this.memoryOwner(sessionId),
|
|
10374
|
+
nameOf: (agent) => agent === MAIN_AGENT.id ? MAIN_AGENT.name : this.roles.spec(agent)?.name ?? agent,
|
|
10375
|
+
sessions: (agent, signal) => this.sessionsOf(agent, signal),
|
|
10376
|
+
read: (sessionId, maxMessages, signal) => this.sessionEvents(sessionId, maxMessages, signal),
|
|
10377
|
+
parts: () => [...this.exportParts],
|
|
10378
|
+
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
10379
|
+
});
|
|
10380
|
+
this.agentPart(`adg-gateway ${exporter.name}`, (agent) => agent.tools.register(exporter));
|
|
10381
|
+
const pending = pendingChangesTool({
|
|
10382
|
+
store: this.held,
|
|
10383
|
+
run: async (tool, args, exec) => {
|
|
10384
|
+
const definition2 = this.parts.definition(tool);
|
|
10385
|
+
if (definition2 === void 0)
|
|
10386
|
+
throw new Error(`${tool} \u73B0\u5728\u4E0D\u53EF\u7528\uFF08\u63D0\u4F9B\u5B83\u7684\u63D2\u4EF6\u6CA1\u6709\u52A0\u8F7D\uFF09`);
|
|
10387
|
+
return definition2.execute(args, { ...exec, name: tool, arguments: args });
|
|
10388
|
+
},
|
|
10389
|
+
sameAgent: (a, b) => a === b || this.memoryOwner(a) !== void 0 && this.memoryOwner(a) === this.memoryOwner(b)
|
|
10390
|
+
});
|
|
10391
|
+
this.agentPart(`adg-gateway ${pending.name}`, (agent) => agent.tools.register(pending));
|
|
9924
10392
|
const recalled = new RecallLog();
|
|
9925
10393
|
const zone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
9926
10394
|
this.agentPart("adg-gateway recall hook", (agent) => agent.on("agent/pre-step", (async (payload, next) => {
|
|
@@ -9977,7 +10445,7 @@ var AdgGateway = class extends Service {
|
|
|
9977
10445
|
continue;
|
|
9978
10446
|
registered.get(skill.name)?.();
|
|
9979
10447
|
try {
|
|
9980
|
-
registered.set(skill.name, this.skillScope.register({ name: skill.name, description: skill.description, content: skill.content, source: "custom", path: skill.path, resourceBase: { kind: "directory", path:
|
|
10448
|
+
registered.set(skill.name, this.skillScope.register({ name: skill.name, description: skill.description, content: skill.content, source: "custom", path: skill.path, resourceBase: { kind: "directory", path: dirname8(skill.path) }, ...skill.owner === void 0 ? {} : { owner: skill.owner } }));
|
|
9981
10449
|
} catch (error) {
|
|
9982
10450
|
log.warn(`saved skill ${skill.name} not registered: ${error instanceof Error ? error.message : String(error)}`);
|
|
9983
10451
|
}
|
|
@@ -10037,7 +10505,7 @@ var AdgGateway = class extends Service {
|
|
|
10037
10505
|
void this.followTitles(controller.signal, log);
|
|
10038
10506
|
return () => controller.abort();
|
|
10039
10507
|
}, "adg-gateway title feed");
|
|
10040
|
-
const staticDir = config.staticDir ?? (existsSync(
|
|
10508
|
+
const staticDir = config.staticDir ?? (existsSync(join9(BUNDLED_UI, "index.html")) ? BUNDLED_UI : void 0);
|
|
10041
10509
|
ctx.inject(["webServer", "connection"], (scoped) => {
|
|
10042
10510
|
const web = scoped.get("webServer");
|
|
10043
10511
|
const connection = scoped.get("connection");
|
|
@@ -10208,7 +10676,7 @@ Content-Length: 0
|
|
|
10208
10676
|
}
|
|
10209
10677
|
try {
|
|
10210
10678
|
const duty = [spec.duty, APP_FILES_RULE, spec.subAgentOf === void 0 ? ROLE_CLOSING : void 0].filter((text2) => text2 !== void 0 && text2 !== "").join("\n\n");
|
|
10211
|
-
const text = spec === MAIN_AGENT ? () => `${mainDuty(this.roles.
|
|
10679
|
+
const text = spec === MAIN_AGENT ? () => `${mainDuty(this.roles.members())}
|
|
10212
10680
|
|
|
10213
10681
|
${APP_FILES_RULE}` : () => duty;
|
|
10214
10682
|
disposers.push(agent.ctx.systemPrompt.section({ name: "adg:role", order: 10095, interpolate: false, text }));
|
|
@@ -10220,7 +10688,7 @@ ${APP_FILES_RULE}` : () => duty;
|
|
|
10220
10688
|
if (spec.subAgentOf === void 0) {
|
|
10221
10689
|
const persona = this.persona;
|
|
10222
10690
|
const known = (member) => ({ ...member, alias: persona?.of(member.id).name });
|
|
10223
|
-
disposers.push(agent.ctx.systemPrompt.section({ name: "adg:team", order: 10096, interpolate: false, text: () => teamPrompt(spec, known(MAIN_AGENT_MEMBER), this.roles.
|
|
10691
|
+
disposers.push(agent.ctx.systemPrompt.section({ name: "adg:team", order: 10096, interpolate: false, text: () => teamPrompt(spec, known(MAIN_AGENT_MEMBER), this.roles.members().map(known), { browser: this.parts.tools.has("browser_navigate") }) }));
|
|
10224
10692
|
if (persona !== void 0)
|
|
10225
10693
|
disposers.push(agent.ctx.systemPrompt.section({ name: "adg:persona", order: 10100, interpolate: false, text: () => personaPrompt(persona.of(spec.id)) }));
|
|
10226
10694
|
}
|
|
@@ -10352,6 +10820,53 @@ ${APP_FILES_RULE}` : () => duty;
|
|
|
10352
10820
|
* sessions, and for a sub-agent, its parent's made into a sub-agent's.
|
|
10353
10821
|
* A shared dsh's other chats, and their sub-agents, are nothing of ours.
|
|
10354
10822
|
*/
|
|
10823
|
+
/**
|
|
10824
|
+
* A sub-agent's call that makes a lasting change (DECISION_AREAS) its brief does not allow: held
|
|
10825
|
+
* for its lead instead of made, and the sub-agent told so in place of the result (changes.ts).
|
|
10826
|
+
* @returns the result to give, or undefined to make the call.
|
|
10827
|
+
*/
|
|
10828
|
+
holdForLead(exec) {
|
|
10829
|
+
const sessionId = exec.agent?.session.id;
|
|
10830
|
+
if (sessionId === void 0)
|
|
10831
|
+
return void 0;
|
|
10832
|
+
const area = decisionOf(exec.name, exec.arguments);
|
|
10833
|
+
if (area === void 0 || this.specOf(sessionId)?.subAgentOf === void 0)
|
|
10834
|
+
return void 0;
|
|
10835
|
+
if (this.grantsOf(sessionId).has(area.id))
|
|
10836
|
+
return void 0;
|
|
10837
|
+
const lead = this.parentSession(sessionId);
|
|
10838
|
+
if (lead === void 0)
|
|
10839
|
+
return void 0;
|
|
10840
|
+
const change = this.held.hold({ tool: exec.name, args: exec.arguments, area, from: sessionId, lead });
|
|
10841
|
+
this.log.info(`held ${change.id} for ${lead}: ${exec.name} from ${sessionId}`);
|
|
10842
|
+
const text = heldNote(change);
|
|
10843
|
+
return { isError: false, value: { held: change.id, kind: area.title, summary: change.summary, note: text }, content: [{ type: "text", text }] };
|
|
10844
|
+
}
|
|
10845
|
+
/**
|
|
10846
|
+
* What a sub-agent's brief lets it change itself: its first message from its parent (source
|
|
10847
|
+
* `user`), not dsh's notes before it (the working directory it starts in, the runtime context…).
|
|
10848
|
+
*/
|
|
10849
|
+
grantsOf(sessionId) {
|
|
10850
|
+
const known = this.grants.get(sessionId);
|
|
10851
|
+
if (known !== void 0)
|
|
10852
|
+
return known;
|
|
10853
|
+
const session = this.agents.get(sessionId)?.session;
|
|
10854
|
+
let granted = /* @__PURE__ */ new Set();
|
|
10855
|
+
for (let seq = 0; session?.eventAt !== void 0 && seq <= (session.seq ?? 0) && seq <= 200; seq++) {
|
|
10856
|
+
const event = session.eventAt(seq);
|
|
10857
|
+
if (event?.type !== "user/message")
|
|
10858
|
+
continue;
|
|
10859
|
+
const kind = event.data?.source?.kind;
|
|
10860
|
+
if (kind !== void 0 && kind !== "user")
|
|
10861
|
+
continue;
|
|
10862
|
+
granted = grantsIn(eventText(event));
|
|
10863
|
+
break;
|
|
10864
|
+
}
|
|
10865
|
+
this.grants.set(sessionId, granted);
|
|
10866
|
+
while (this.grants.size > 500)
|
|
10867
|
+
this.grants.delete(this.grants.keys().next().value);
|
|
10868
|
+
return granted;
|
|
10869
|
+
}
|
|
10355
10870
|
specOf(sessionId) {
|
|
10356
10871
|
const header = this.agents.get(sessionId)?.session.header;
|
|
10357
10872
|
if (header?.origin === "subagent" && header.parentSession !== void 0) {
|
|
@@ -10391,11 +10906,11 @@ ${APP_FILES_RULE}` : () => duty;
|
|
|
10391
10906
|
*/
|
|
10392
10907
|
async settled(sessionId, signal) {
|
|
10393
10908
|
const subagents = this.ctx.get("subagents");
|
|
10394
|
-
const stopped = new Promise((
|
|
10909
|
+
const stopped = new Promise((resolve5) => {
|
|
10395
10910
|
if (signal.aborted)
|
|
10396
|
-
|
|
10911
|
+
resolve5();
|
|
10397
10912
|
else
|
|
10398
|
-
signal.addEventListener("abort", () =>
|
|
10913
|
+
signal.addEventListener("abort", () => resolve5(), { once: true });
|
|
10399
10914
|
});
|
|
10400
10915
|
for (; ; ) {
|
|
10401
10916
|
if (signal.aborted)
|
|
@@ -10457,10 +10972,10 @@ ${APP_FILES_RULE}` : () => duty;
|
|
|
10457
10972
|
signal.throwIfAborted();
|
|
10458
10973
|
}
|
|
10459
10974
|
await parent.send({
|
|
10460
|
-
id:
|
|
10975
|
+
id: randomUUID6(),
|
|
10461
10976
|
role: "user",
|
|
10462
10977
|
content: [{ type: "text", text: `\uFF08\u4F60\u8D1F\u8D23\u7684\u5B50\u4EFB\u52A1\uFF1A${title}\uFF09
|
|
10463
|
-
\u5DF2\u5C06\u4E0B\u5217\u6307\u4EE4\u6D3E\u7ED9\u4F60\u7684\u5B50 agent\u300C${activation.name}\u300D\u3002\u5B83\u4F1A\u76F4\u63A5\u5411\u4F60\u4EA4\u4ED8\u7ED3\u679C\u3002\u7ED3\u8BBA\u4F1A\u81EA\u52A8\u9001\u8FBE\
|
|
10978
|
+
\u5DF2\u5C06\u4E0B\u5217\u6307\u4EE4\u6D3E\u7ED9\u4F60\u7684\u5B50 agent\u300C${activation.name}\u300D\u3002\u5B83\u4F1A\u76F4\u63A5\u5411\u4F60\u4EA4\u4ED8\u7ED3\u679C\u3002\u7ED3\u8BBA\u4F1A\u81EA\u52A8\u9001\u8FBE\uFF1A\u6536\u5230\u540E\u6309\u4E0B\u9762\u7684\u5B8C\u6210\u6807\u51C6\u6838\u5BF9\u5B83\u5E26\u56DE\u7684\u8BC1\u636E\uFF0C\u518D\u6C47\u62A5\u3002\u7B49\u5F85\u671F\u95F4\u53EF\u4EE5\u5904\u7406\u5176\u4ED6\u6D88\u606F\uFF0C\u65E0\u9700\u8F6E\u8BE2\u6216\u91CD\u590D\u6D3E\u53D1\u3002
|
|
10464
10979
|
|
|
10465
10980
|
${instruction}` }],
|
|
10466
10981
|
source: { kind: "adg-task-dispatched", form: "notice", summary: title, childId }
|
|
@@ -10737,6 +11252,13 @@ ${instruction}` }],
|
|
|
10737
11252
|
agentPart(label, part) {
|
|
10738
11253
|
this.ctx.effect(() => this.parts.add(label, part), label);
|
|
10739
11254
|
}
|
|
11255
|
+
/** Add what a part of the app holds for a stretch of time to history_export (the runner's run logs). @returns the disposer. */
|
|
11256
|
+
exportPart(part) {
|
|
11257
|
+
this.exportParts.add(part);
|
|
11258
|
+
return () => {
|
|
11259
|
+
this.exportParts.delete(part);
|
|
11260
|
+
};
|
|
11261
|
+
}
|
|
10740
11262
|
/**
|
|
10741
11263
|
* One of the app's general skills (a core skill every one of its sessions
|
|
10742
11264
|
* sees). Shared, it goes through the skill scope, which shows it to the
|
|
@@ -10894,7 +11416,7 @@ ${instruction}` }],
|
|
|
10894
11416
|
return;
|
|
10895
11417
|
log.warn(`title feed interrupted: ${error instanceof Error ? error.message : String(error)}`);
|
|
10896
11418
|
}
|
|
10897
|
-
await new Promise((
|
|
11419
|
+
await new Promise((resolve5) => setTimeout(resolve5, 1e3));
|
|
10898
11420
|
}
|
|
10899
11421
|
}
|
|
10900
11422
|
};
|