dsh-multigameassistant 2.2.3 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cordis.patch.yml +10 -10
- package/lib/analyzer.js +82 -17
- package/lib/{chunk-LXHF6AKU.js → chunk-34VNH3YS.js} +155 -9
- package/lib/{chunk-A6YQRWHZ.js → chunk-4QXRDWGS.js} +22 -7
- package/lib/{chunk-TELJUUBZ.js → chunk-76UHR2GO.js} +96 -25
- package/lib/{chunk-RGEGJH6R.js → chunk-C7X2KJ5C.js} +209 -10
- package/lib/{chunk-YTIR5JW4.js → chunk-KW36B7DT.js} +126 -12
- package/lib/{chunk-KMVQK5CI.js → chunk-M7GNYL5B.js} +1 -1
- package/lib/{chunk-6NJSSOB6.js → chunk-QSETYM2Y.js} +639 -114
- package/lib/emulator.js +810 -12
- package/lib/feishu.js +4 -4
- package/lib/game-intel.js +1047 -53
- package/lib/gateway.js +3 -3
- package/lib/guard.js +159 -42
- 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/game-intel.md +12 -0
- package/skills/pipeline-planning.md +2 -2
- package/skills/script-analysis.md +31 -5
- 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-DwItOcWq.css +0 -1
- package/web/assets/index-YiJ--jV1.js +0 -255
- package/web/assets/index-YiJ--jV1.js.map +0 -1
- /package/lib/{chunk-YTIR5JW4.js.LEGAL.txt → chunk-KW36B7DT.js.LEGAL.txt} +0 -0
|
@@ -1,18 +1,24 @@
|
|
|
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";
|
|
9
10
|
import {
|
|
10
11
|
AGENTS_CAPABILITY,
|
|
11
12
|
AGENT_AREAS,
|
|
13
|
+
APP_FILES_RULE,
|
|
12
14
|
ARCHIVE_MARK,
|
|
13
15
|
AreaPolicy,
|
|
16
|
+
BRIEF_ALLOW,
|
|
17
|
+
BRIEF_DONE_WHEN,
|
|
18
|
+
BRIEF_LIMITS,
|
|
14
19
|
COMPACTION_CAPABILITY,
|
|
15
20
|
CompactionSettings,
|
|
21
|
+
DECISION_AREAS,
|
|
16
22
|
DEEPSEEK_API_KEY,
|
|
17
23
|
DEFAULT_COMPACTION_THRESHOLD,
|
|
18
24
|
ErrorCode,
|
|
@@ -39,11 +45,13 @@ import {
|
|
|
39
45
|
SUMMARY_MAX_TOKENS,
|
|
40
46
|
areaOf,
|
|
41
47
|
classify,
|
|
48
|
+
decisionOf,
|
|
49
|
+
grantsIn,
|
|
42
50
|
personaOf,
|
|
43
51
|
personaPrompt,
|
|
44
52
|
threadsBetween,
|
|
45
53
|
timetableText
|
|
46
|
-
} from "./chunk-
|
|
54
|
+
} from "./chunk-34VNH3YS.js";
|
|
47
55
|
import {
|
|
48
56
|
external_exports
|
|
49
57
|
} from "./chunk-6DSSLS7I.js";
|
|
@@ -3725,9 +3733,9 @@ var require_websocket_server = __commonJS({
|
|
|
3725
3733
|
|
|
3726
3734
|
// packages/gateway/lib/index.js
|
|
3727
3735
|
import { execFile as execFile2 } from "node:child_process";
|
|
3728
|
-
import { randomBytes as randomBytes2, randomUUID as
|
|
3729
|
-
import { existsSync, mkdirSync as
|
|
3730
|
-
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";
|
|
3731
3739
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
3732
3740
|
import { Service } from "@deepseek-ai/cordis";
|
|
3733
3741
|
|
|
@@ -4271,13 +4279,13 @@ var ApprovalBroker = class {
|
|
|
4271
4279
|
...ask.reason === void 0 ? {} : { reason: ask.reason },
|
|
4272
4280
|
...ask.displayReason === void 0 ? {} : { displayReason: { ...ask.displayReason } }
|
|
4273
4281
|
};
|
|
4274
|
-
return new Promise((
|
|
4282
|
+
return new Promise((resolve5) => {
|
|
4275
4283
|
const onAbort = () => this.settle(approvalId, "cancelled");
|
|
4276
4284
|
this.pending.set(approvalId, {
|
|
4277
4285
|
request,
|
|
4278
4286
|
settle: (outcome) => {
|
|
4279
4287
|
ask.signal?.removeEventListener("abort", onAbort);
|
|
4280
|
-
|
|
4288
|
+
resolve5(outcome);
|
|
4281
4289
|
}
|
|
4282
4290
|
});
|
|
4283
4291
|
ask.signal?.addEventListener("abort", onAbort, { once: true });
|
|
@@ -4429,10 +4437,10 @@ async function importUnchanged(dir, item) {
|
|
|
4429
4437
|
}
|
|
4430
4438
|
async function copyHash(folder) {
|
|
4431
4439
|
const { createHash } = await import("node:crypto");
|
|
4432
|
-
const { readdir:
|
|
4440
|
+
const { readdir: readdir3 } = await import("node:fs/promises");
|
|
4433
4441
|
const files = [];
|
|
4434
4442
|
const walk = async (sub) => {
|
|
4435
|
-
for (const entry of await
|
|
4443
|
+
for (const entry of await readdir3(join(folder, sub), { withFileTypes: true })) {
|
|
4436
4444
|
const rel = sub === "" ? entry.name : `${sub}/${entry.name}`;
|
|
4437
4445
|
if (entry.isDirectory()) {
|
|
4438
4446
|
if (!SKIPPED.test(entry.name))
|
|
@@ -4464,7 +4472,7 @@ function skillSaveTool(deps) {
|
|
|
4464
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",
|
|
4465
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",
|
|
4466
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",
|
|
4467
|
-
"\
|
|
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",
|
|
4468
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"
|
|
4469
4477
|
].join(""),
|
|
4470
4478
|
parameters: {
|
|
@@ -4491,8 +4499,8 @@ function skillSaveTool(deps) {
|
|
|
4491
4499
|
};
|
|
4492
4500
|
}
|
|
4493
4501
|
async function userSkills(dir) {
|
|
4494
|
-
const { readdir:
|
|
4495
|
-
const entries = await
|
|
4502
|
+
const { readdir: readdir3 } = await import("node:fs/promises");
|
|
4503
|
+
const entries = await readdir3(dir, { withFileTypes: true }).catch(() => []);
|
|
4496
4504
|
const out = [];
|
|
4497
4505
|
for (const entry of entries) {
|
|
4498
4506
|
if (!entry.isDirectory())
|
|
@@ -4540,6 +4548,8 @@ var PROVIDER = "adg";
|
|
|
4540
4548
|
var RANK = 250;
|
|
4541
4549
|
var MAX_SESSIONS = 1e3;
|
|
4542
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 };
|
|
4543
4553
|
var norm = (value) => value.trim().toLowerCase();
|
|
4544
4554
|
var SkillScope = class {
|
|
4545
4555
|
#skills = /* @__PURE__ */ new Map();
|
|
@@ -4551,6 +4561,7 @@ var SkillScope = class {
|
|
|
4551
4561
|
#invalidate = () => {
|
|
4552
4562
|
};
|
|
4553
4563
|
#relations = () => ({ aliases: [], games: [] });
|
|
4564
|
+
#gameOf = () => void 0;
|
|
4554
4565
|
#loaded;
|
|
4555
4566
|
#saving = Promise.resolve();
|
|
4556
4567
|
log;
|
|
@@ -4570,9 +4581,10 @@ var SkillScope = class {
|
|
|
4570
4581
|
if (session !== void 0 && this.#only?.(session) === false)
|
|
4571
4582
|
return [];
|
|
4572
4583
|
const focus = this.focusOf(session);
|
|
4573
|
-
|
|
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)];
|
|
4574
4586
|
},
|
|
4575
|
-
get: async ({ locator }) => definition(locator)
|
|
4587
|
+
get: async ({ locator }) => typeof locator === "string" ? void 0 : definition(locator)
|
|
4576
4588
|
};
|
|
4577
4589
|
}
|
|
4578
4590
|
/** A sub-agent works on what its parent is working on, until it says otherwise. */
|
|
@@ -4588,8 +4600,17 @@ var SkillScope = class {
|
|
|
4588
4600
|
* What else a script in a focus stands for: its pack's id (the pack's skill
|
|
4589
4601
|
* names that), and the games it plays, whose skills it sees too.
|
|
4590
4602
|
*/
|
|
4591
|
-
resolveScripts(
|
|
4592
|
-
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;
|
|
4593
4614
|
this.#invalidate();
|
|
4594
4615
|
}
|
|
4595
4616
|
/**
|
|
@@ -4670,8 +4691,9 @@ var SkillScope = class {
|
|
|
4670
4691
|
const focusScripts = new Set([...focus.scripts, ...related.flatMap((r) => r.aliases)].map(norm));
|
|
4671
4692
|
if (scripts.some((s) => focusScripts.has(norm(s))))
|
|
4672
4693
|
return true;
|
|
4673
|
-
const
|
|
4674
|
-
|
|
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)));
|
|
4675
4697
|
}
|
|
4676
4698
|
async #load() {
|
|
4677
4699
|
if (this.#file === void 0)
|
|
@@ -4710,6 +4732,9 @@ function candidate(skill) {
|
|
|
4710
4732
|
locator: skill
|
|
4711
4733
|
};
|
|
4712
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
|
+
}
|
|
4713
4738
|
function definition(skill) {
|
|
4714
4739
|
return {
|
|
4715
4740
|
name: skill.name,
|
|
@@ -5149,6 +5174,9 @@ function looksSecret(text) {
|
|
|
5149
5174
|
}
|
|
5150
5175
|
return false;
|
|
5151
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
|
+
}
|
|
5152
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";
|
|
5153
5181
|
var MemoryStore = class {
|
|
5154
5182
|
#file;
|
|
@@ -6406,8 +6434,344 @@ var AutoMemory = class {
|
|
|
6406
6434
|
}
|
|
6407
6435
|
};
|
|
6408
6436
|
|
|
6409
|
-
// 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";
|
|
6410
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";
|
|
6411
6775
|
var RECALL_SOURCE = "adg-recall";
|
|
6412
6776
|
var MAX_RECALLED = 5;
|
|
6413
6777
|
var MAX_RECALL_CHARS = 1500;
|
|
@@ -6460,7 +6824,7 @@ function recallText(entries, agentId, timeZone) {
|
|
|
6460
6824
|
}
|
|
6461
6825
|
function recallMessage(text, ids) {
|
|
6462
6826
|
return Object.freeze({
|
|
6463
|
-
id:
|
|
6827
|
+
id: randomUUID4(),
|
|
6464
6828
|
role: "user",
|
|
6465
6829
|
content: Object.freeze([Object.freeze({ type: "text", text })]),
|
|
6466
6830
|
source: Object.freeze({ kind: RECALL_SOURCE, form: "snapshot", ids: Object.freeze([...ids]), sections: Object.freeze([Object.freeze({ name: RECALL_SOURCE, text })]) })
|
|
@@ -6943,14 +7307,14 @@ var QuestionBroker = class {
|
|
|
6943
7307
|
...q.multiSelect === void 0 ? {} : { multiSelect: q.multiSelect }
|
|
6944
7308
|
}))
|
|
6945
7309
|
};
|
|
6946
|
-
return new Promise((
|
|
7310
|
+
return new Promise((resolve5, reject) => {
|
|
6947
7311
|
const onAbort = () => this.settle(questionId, "cancelled");
|
|
6948
7312
|
this.pending.set(questionId, {
|
|
6949
7313
|
request,
|
|
6950
7314
|
settle: (outcome, answer) => {
|
|
6951
7315
|
ask.signal?.removeEventListener("abort", onAbort);
|
|
6952
7316
|
if (outcome === "answered" && answer !== void 0)
|
|
6953
|
-
|
|
7317
|
+
resolve5(answer);
|
|
6954
7318
|
else
|
|
6955
7319
|
reject(new QuestionClosed(outcome === "answered" ? "unavailable" : outcome));
|
|
6956
7320
|
}
|
|
@@ -7417,8 +7781,8 @@ function builtinCapabilities(deps) {
|
|
|
7417
7781
|
|
|
7418
7782
|
// packages/gateway/lib/homes.js
|
|
7419
7783
|
import { readFile as readFile7 } from "node:fs/promises";
|
|
7420
|
-
import { mkdirSync } from "node:fs";
|
|
7421
|
-
import { dirname as
|
|
7784
|
+
import { mkdirSync as mkdirSync2 } from "node:fs";
|
|
7785
|
+
import { dirname as dirname3 } from "node:path";
|
|
7422
7786
|
var AgentHomes = class {
|
|
7423
7787
|
#file;
|
|
7424
7788
|
#homes = /* @__PURE__ */ new Map();
|
|
@@ -7450,7 +7814,7 @@ var AgentHomes = class {
|
|
|
7450
7814
|
async #save() {
|
|
7451
7815
|
if (this.#file === void 0)
|
|
7452
7816
|
return;
|
|
7453
|
-
|
|
7817
|
+
mkdirSync2(dirname3(this.#file), { recursive: true });
|
|
7454
7818
|
await writeFileAtomic(this.#file, `${JSON.stringify(Object.fromEntries(this.#homes), null, 2)}
|
|
7455
7819
|
`);
|
|
7456
7820
|
}
|
|
@@ -7468,7 +7832,7 @@ var AgentHomes = class {
|
|
|
7468
7832
|
}
|
|
7469
7833
|
}
|
|
7470
7834
|
};
|
|
7471
|
-
var
|
|
7835
|
+
var MAX_KEPT2 = 500;
|
|
7472
7836
|
var HandOffs = class {
|
|
7473
7837
|
#file;
|
|
7474
7838
|
#items = /* @__PURE__ */ new Map();
|
|
@@ -7505,7 +7869,7 @@ var HandOffs = class {
|
|
|
7505
7869
|
await this.loaded;
|
|
7506
7870
|
this.#items.delete(item.id);
|
|
7507
7871
|
this.#items.set(item.id, item);
|
|
7508
|
-
while (this.#items.size >
|
|
7872
|
+
while (this.#items.size > MAX_KEPT2)
|
|
7509
7873
|
this.#items.delete(this.#items.keys().next().value);
|
|
7510
7874
|
this.#changed(item);
|
|
7511
7875
|
for (const listener of this.#listeners) {
|
|
@@ -7519,7 +7883,7 @@ var HandOffs = class {
|
|
|
7519
7883
|
async #save() {
|
|
7520
7884
|
if (this.#file === void 0)
|
|
7521
7885
|
return;
|
|
7522
|
-
|
|
7886
|
+
mkdirSync2(dirname3(this.#file), { recursive: true });
|
|
7523
7887
|
await writeFileAtomic(this.#file, `${JSON.stringify([...this.#items.values()])}
|
|
7524
7888
|
`);
|
|
7525
7889
|
}
|
|
@@ -7704,21 +8068,45 @@ function plain(markdown) {
|
|
|
7704
8068
|
|
|
7705
8069
|
// packages/gateway/lib/roles.js
|
|
7706
8070
|
import { readFile as readFile8 } from "node:fs/promises";
|
|
7707
|
-
import { mkdirSync as
|
|
7708
|
-
import { dirname as
|
|
8071
|
+
import { mkdirSync as mkdirSync3 } from "node:fs";
|
|
8072
|
+
import { dirname as dirname4 } from "node:path";
|
|
7709
8073
|
function keeps(tools, name) {
|
|
7710
8074
|
return tools === void 0 || matches(tools, name);
|
|
7711
8075
|
}
|
|
7712
8076
|
function matches(patterns, name) {
|
|
7713
8077
|
return patterns.some((pattern) => pattern.endsWith("*") ? name.startsWith(pattern.slice(0, -1)) : name === pattern);
|
|
7714
8078
|
}
|
|
7715
|
-
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"];
|
|
7716
8080
|
var TOGETHER = ["agent_delegate", "agent_message", "agent_threads"];
|
|
7717
8081
|
var MEMORY_TOOLS = ["memory_save", "memory_forget", "memory_search", "history_search", "history_read"];
|
|
7718
|
-
var
|
|
7719
|
-
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"];
|
|
7720
8108
|
var HANDS_ON = [
|
|
7721
|
-
...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)),
|
|
7722
8110
|
// Screenshots are not in an area (they change nothing), and they weigh the most.
|
|
7723
8111
|
"screen_*",
|
|
7724
8112
|
// The built-in browser: every step answers with the whole page.
|
|
@@ -7726,14 +8114,26 @@ var HANDS_ON = [
|
|
|
7726
8114
|
// Runs a program that calls the tools: the same work, by another door.
|
|
7727
8115
|
"workflow"
|
|
7728
8116
|
];
|
|
8117
|
+
var AT_HOME = ["job_*", "todo_write"];
|
|
7729
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`;
|
|
7730
8119
|
function handsOn(tool) {
|
|
7731
8120
|
return matches(HANDS_ON, tool);
|
|
7732
8121
|
}
|
|
7733
8122
|
function hiddenTools(spec, appTools, visible, home = false) {
|
|
7734
|
-
const hide = [...NOBODY, ...spec.hide ?? [], ...home ? HANDS_ON : []];
|
|
8123
|
+
const hide = [...NOBODY, ...spec.hide ?? [], ...home ? [...HANDS_ON, ...AT_HOME] : []];
|
|
7735
8124
|
return [...visible].filter((name) => matches(hide, name) || appTools.has(name) && !keeps(spec.tools, name) && !ALWAYS.includes(name));
|
|
7736
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");
|
|
7737
8137
|
function subAgentSpec(parent) {
|
|
7738
8138
|
const name = parent.name;
|
|
7739
8139
|
return {
|
|
@@ -7747,7 +8147,10 @@ function subAgentSpec(parent) {
|
|
|
7747
8147
|
duty: [
|
|
7748
8148
|
`# \u4F60\u7684\u89D2\u8272\uFF1A\u300C${name}\u300D\u7684\u5B50 agent`,
|
|
7749
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`,
|
|
7750
|
-
`\
|
|
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,
|
|
7751
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`,
|
|
7752
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",
|
|
7753
8156
|
// Only where the parent's tools take the browser in (and it may be missing: dsh's own app has none).
|
|
@@ -7766,7 +8169,8 @@ function teamPrompt(self, main, leads, options = {}) {
|
|
|
7766
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`,
|
|
7767
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
|
|
7768
8171
|
${colleagues.map(line2).join("\n")}`,
|
|
7769
|
-
"\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,
|
|
7770
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" : "",
|
|
7771
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`,
|
|
7772
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",
|
|
@@ -7784,7 +8188,7 @@ ${colleagues.map(line2).join("\n")}`,
|
|
|
7784
8188
|
].join("\n")
|
|
7785
8189
|
].filter((part) => part !== "").join("\n\n");
|
|
7786
8190
|
}
|
|
7787
|
-
var
|
|
8191
|
+
var MAX_KEPT3 = 5e3;
|
|
7788
8192
|
var SessionRoles = class {
|
|
7789
8193
|
#file;
|
|
7790
8194
|
#roles = /* @__PURE__ */ new Map();
|
|
@@ -7819,7 +8223,14 @@ var SessionRoles = class {
|
|
|
7819
8223
|
return role !== void 0 && this.#roles.has(role) ? role : void 0;
|
|
7820
8224
|
}
|
|
7821
8225
|
list() {
|
|
7822
|
-
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));
|
|
7823
8234
|
}
|
|
7824
8235
|
/**
|
|
7825
8236
|
* The role a session belongs to: the one it was opened with, else the one
|
|
@@ -7850,11 +8261,11 @@ var SessionRoles = class {
|
|
|
7850
8261
|
return;
|
|
7851
8262
|
this.#tags.delete(sessionId);
|
|
7852
8263
|
this.#tags.set(sessionId, { role, ...by === void 0 ? {} : { by } });
|
|
7853
|
-
while (this.#tags.size >
|
|
8264
|
+
while (this.#tags.size > MAX_KEPT3)
|
|
7854
8265
|
this.#tags.delete(this.#tags.keys().next().value);
|
|
7855
8266
|
if (this.#file === void 0)
|
|
7856
8267
|
return;
|
|
7857
|
-
|
|
8268
|
+
mkdirSync3(dirname4(this.#file), { recursive: true });
|
|
7858
8269
|
const saved = Object.fromEntries([...this.#tags].map(([id, tag]) => [id, tag.by === void 0 ? tag.role : tag]));
|
|
7859
8270
|
await writeFileAtomic(this.#file, `${JSON.stringify(saved)}
|
|
7860
8271
|
`);
|
|
@@ -7881,8 +8292,8 @@ var SessionRoles = class {
|
|
|
7881
8292
|
|
|
7882
8293
|
// packages/gateway/lib/agent-models.js
|
|
7883
8294
|
import { readFile as readFile9 } from "node:fs/promises";
|
|
7884
|
-
import { mkdirSync as
|
|
7885
|
-
import { dirname as
|
|
8295
|
+
import { mkdirSync as mkdirSync4 } from "node:fs";
|
|
8296
|
+
import { dirname as dirname5 } from "node:path";
|
|
7886
8297
|
var LEGACY_ROLES = ["intervene", "games", "scripts", "pipelines"];
|
|
7887
8298
|
var EMPTY = { agents: {}, subAgents: null, subAgentsOf: {}, fallbacks: { agents: [], subAgents: [] } };
|
|
7888
8299
|
var AgentModels = class {
|
|
@@ -7933,7 +8344,7 @@ var AgentModels = class {
|
|
|
7933
8344
|
async #save() {
|
|
7934
8345
|
if (this.#file === void 0)
|
|
7935
8346
|
return;
|
|
7936
|
-
|
|
8347
|
+
mkdirSync4(dirname5(this.#file), { recursive: true });
|
|
7937
8348
|
await writeFileAtomic(this.#file, `${JSON.stringify(this.#state)}
|
|
7938
8349
|
`);
|
|
7939
8350
|
}
|
|
@@ -7992,7 +8403,7 @@ function distinct(list) {
|
|
|
7992
8403
|
}
|
|
7993
8404
|
|
|
7994
8405
|
// packages/gateway/lib/model-fallback.js
|
|
7995
|
-
import { randomUUID as
|
|
8406
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
7996
8407
|
function failureOf(error) {
|
|
7997
8408
|
if (error === null || typeof error !== "object")
|
|
7998
8409
|
return void 0;
|
|
@@ -8045,7 +8456,7 @@ function fallbackSummary(notice) {
|
|
|
8045
8456
|
}
|
|
8046
8457
|
function fallbackMessage(notice) {
|
|
8047
8458
|
return Object.freeze({
|
|
8048
|
-
id:
|
|
8459
|
+
id: randomUUID5(),
|
|
8049
8460
|
role: "user",
|
|
8050
8461
|
content: Object.freeze([Object.freeze({ type: "text", text: fallbackText(notice) })]),
|
|
8051
8462
|
source: Object.freeze({ kind: MODEL_FALLBACK_SOURCE, form: "notice", summary: fallbackSummary(notice), fallback: notice })
|
|
@@ -8322,7 +8733,7 @@ function toRpcError(error) {
|
|
|
8322
8733
|
|
|
8323
8734
|
// packages/gateway/lib/pick.js
|
|
8324
8735
|
import { execFile } from "node:child_process";
|
|
8325
|
-
import { isAbsolute as
|
|
8736
|
+
import { isAbsolute as isAbsolute3, normalize } from "node:path";
|
|
8326
8737
|
var SCRIPT = String.raw`
|
|
8327
8738
|
$ErrorActionPreference = 'Stop'
|
|
8328
8739
|
$ProgressPreference = 'SilentlyContinue'
|
|
@@ -8386,7 +8797,7 @@ function pickPath(options, signal) {
|
|
|
8386
8797
|
return Promise.reject(new Error("\u5DF2\u7ECF\u6253\u5F00\u4E86\u4E00\u4E2A\u9009\u62E9\u7A97\u53E3\uFF0C\u5148\u628A\u5B83\u5173\u6389"));
|
|
8387
8798
|
const extensions = (options.extensions ?? []).filter((e) => /^\w+$/.test(e));
|
|
8388
8799
|
const filter = extensions.length === 0 ? "" : `${(options.filterName ?? "\u6587\u4EF6").replace(/\|/g, "")}|${extensions.map((e) => `*.${e}`).join(";")}|\u6240\u6709\u6587\u4EF6|*.*`;
|
|
8389
|
-
const pending = new Promise((
|
|
8800
|
+
const pending = new Promise((resolve5, reject) => {
|
|
8390
8801
|
execFile("powershell.exe", ["-NoProfile", "-NonInteractive", "-STA", "-ExecutionPolicy", "Bypass", "-EncodedCommand", Buffer.from(SCRIPT, "utf16le").toString("base64")], {
|
|
8391
8802
|
windowsHide: true,
|
|
8392
8803
|
signal,
|
|
@@ -8395,7 +8806,7 @@ function pickPath(options, signal) {
|
|
|
8395
8806
|
...process.env,
|
|
8396
8807
|
ADG_PICK_KIND: options.kind,
|
|
8397
8808
|
ADG_PICK_TITLE: options.title ?? (options.kind === "folder" ? "\u9009\u62E9\u6587\u4EF6\u5939" : "\u9009\u62E9\u6587\u4EF6"),
|
|
8398
|
-
ADG_PICK_PATH: options.defaultPath !== void 0 &&
|
|
8809
|
+
ADG_PICK_PATH: options.defaultPath !== void 0 && isAbsolute3(options.defaultPath) ? normalize(options.defaultPath) : "",
|
|
8399
8810
|
ADG_PICK_FILTER: filter
|
|
8400
8811
|
}
|
|
8401
8812
|
}, (error, stdout, stderr) => {
|
|
@@ -8404,7 +8815,7 @@ function pickPath(options, signal) {
|
|
|
8404
8815
|
return;
|
|
8405
8816
|
}
|
|
8406
8817
|
const out = String(stdout).trim();
|
|
8407
|
-
|
|
8818
|
+
resolve5(out === "" ? void 0 : Buffer.from(out, "base64").toString("utf8"));
|
|
8408
8819
|
});
|
|
8409
8820
|
});
|
|
8410
8821
|
open = pending;
|
|
@@ -8418,8 +8829,8 @@ function pickPath(options, signal) {
|
|
|
8418
8829
|
|
|
8419
8830
|
// packages/gateway/lib/permissions.js
|
|
8420
8831
|
import { readFile as readFile10 } from "node:fs/promises";
|
|
8421
|
-
import { mkdirSync as
|
|
8422
|
-
import { dirname as
|
|
8832
|
+
import { mkdirSync as mkdirSync5 } from "node:fs";
|
|
8833
|
+
import { dirname as dirname6 } from "node:path";
|
|
8423
8834
|
var PRESET = { ask: "workspace-write", full: "full-access" };
|
|
8424
8835
|
var KEEP_RECENT = 50;
|
|
8425
8836
|
var Permissions = class {
|
|
@@ -8475,7 +8886,7 @@ var Permissions = class {
|
|
|
8475
8886
|
async #save() {
|
|
8476
8887
|
if (this.#file === void 0)
|
|
8477
8888
|
return;
|
|
8478
|
-
|
|
8889
|
+
mkdirSync5(dirname6(this.#file), { recursive: true });
|
|
8479
8890
|
await writeFileAtomic(this.#file, `${JSON.stringify({ mode: this.#mode, since: this.#since, areas: this.#areas }, null, 2)}
|
|
8480
8891
|
`);
|
|
8481
8892
|
}
|
|
@@ -8529,7 +8940,7 @@ var CapabilityRegistry = class {
|
|
|
8529
8940
|
// packages/gateway/lib/server.js
|
|
8530
8941
|
import { createReadStream, statSync } from "node:fs";
|
|
8531
8942
|
import { createServer } from "node:http";
|
|
8532
|
-
import { extname, join as
|
|
8943
|
+
import { extname, join as join7, normalize as normalize2, resolve as resolve3, sep } from "node:path";
|
|
8533
8944
|
import { timingSafeEqual } from "node:crypto";
|
|
8534
8945
|
|
|
8535
8946
|
// node_modules/.pnpm/ws@8.21.3/node_modules/ws/wrapper.mjs
|
|
@@ -8606,19 +9017,19 @@ function serveMounted(root, req, res) {
|
|
|
8606
9017
|
res.writeHead(404, { "content-type": "text/plain; charset=utf-8" }).end("\u8FD9\u4E2A\u5B89\u88C5\u6CA1\u6709\u5E26\u754C\u9762");
|
|
8607
9018
|
return;
|
|
8608
9019
|
}
|
|
8609
|
-
serveStatic(
|
|
9020
|
+
serveStatic(resolve3(root), req, res, pathname.slice(MOUNT.length));
|
|
8610
9021
|
}
|
|
8611
9022
|
function serveStatic(root, req, res, path) {
|
|
8612
9023
|
const pathname = decodeURIComponent(path ?? new URL(req.url ?? "/", "http://local").pathname);
|
|
8613
|
-
const target = normalize2(
|
|
9024
|
+
const target = normalize2(join7(root, pathname));
|
|
8614
9025
|
const inside = target === root || target.startsWith(root.endsWith(sep) ? root : root + sep);
|
|
8615
|
-
let file = inside ? target :
|
|
9026
|
+
let file = inside ? target : join7(root, "index.html");
|
|
8616
9027
|
try {
|
|
8617
9028
|
if (statSync(file).isDirectory())
|
|
8618
|
-
file =
|
|
9029
|
+
file = join7(file, "index.html");
|
|
8619
9030
|
statSync(file);
|
|
8620
9031
|
} catch {
|
|
8621
|
-
file =
|
|
9032
|
+
file = join7(root, "index.html");
|
|
8622
9033
|
}
|
|
8623
9034
|
try {
|
|
8624
9035
|
const size = statSync(file).size;
|
|
@@ -8634,7 +9045,7 @@ function serveStatic(root, req, res, path) {
|
|
|
8634
9045
|
}
|
|
8635
9046
|
}
|
|
8636
9047
|
async function startServer(options) {
|
|
8637
|
-
const staticRoot = options.staticDir === void 0 ? void 0 :
|
|
9048
|
+
const staticRoot = options.staticDir === void 0 ? void 0 : resolve3(options.staticDir);
|
|
8638
9049
|
const server = createServer((req, res) => {
|
|
8639
9050
|
if (!authorityAllowed(req.headers.host, options.trustedHosts)) {
|
|
8640
9051
|
res.writeHead(403).end("forbidden host");
|
|
@@ -8703,10 +9114,10 @@ Content-Length: 0\r
|
|
|
8703
9114
|
}
|
|
8704
9115
|
|
|
8705
9116
|
// packages/gateway/lib/instances.js
|
|
8706
|
-
import { mkdir as
|
|
9117
|
+
import { mkdir as mkdir6, readdir as readdir2, readFile as readFile11, rm as rm2 } from "node:fs/promises";
|
|
8707
9118
|
import { tmpdir } from "node:os";
|
|
8708
|
-
import { join as
|
|
8709
|
-
var INSTANCES_DIR =
|
|
9119
|
+
import { join as join8, resolve as resolve4 } from "node:path";
|
|
9120
|
+
var INSTANCES_DIR = join8(tmpdir(), "MultiGameAssistant", "instances");
|
|
8710
9121
|
var STALE_MS = 3 * 6e4;
|
|
8711
9122
|
var FORGET_MS = 24 * 60 * 6e4;
|
|
8712
9123
|
function copyLabel(shared, env = process.env) {
|
|
@@ -8719,7 +9130,7 @@ function copyLabel(shared, env = process.env) {
|
|
|
8719
9130
|
function sameDir(a, b) {
|
|
8720
9131
|
if (a === void 0 || b === void 0)
|
|
8721
9132
|
return false;
|
|
8722
|
-
const norm2 = (dir) => process.platform === "win32" ?
|
|
9133
|
+
const norm2 = (dir) => process.platform === "win32" ? resolve4(dir).toLowerCase() : resolve4(dir);
|
|
8723
9134
|
return norm2(a) === norm2(b);
|
|
8724
9135
|
}
|
|
8725
9136
|
function clashes(self, other) {
|
|
@@ -8816,22 +9227,22 @@ var Instances = class {
|
|
|
8816
9227
|
const self = this.#record();
|
|
8817
9228
|
const others = [];
|
|
8818
9229
|
try {
|
|
8819
|
-
await
|
|
9230
|
+
await mkdir6(this.#dir, { recursive: true });
|
|
8820
9231
|
await writeFileAtomic(this.#file(this.#pid), JSON.stringify(self));
|
|
8821
9232
|
const alive = this.#options.alive ?? processAlive;
|
|
8822
|
-
for (const name of await
|
|
9233
|
+
for (const name of await readdir2(this.#dir)) {
|
|
8823
9234
|
const match = /^(\d+)\.json$/.exec(name);
|
|
8824
9235
|
if (match === null || Number(match[1]) === this.#pid)
|
|
8825
9236
|
continue;
|
|
8826
9237
|
let other;
|
|
8827
9238
|
try {
|
|
8828
|
-
other = JSON.parse(await readFile11(
|
|
9239
|
+
other = JSON.parse(await readFile11(join8(this.#dir, name), "utf8"));
|
|
8829
9240
|
} catch {
|
|
8830
9241
|
continue;
|
|
8831
9242
|
}
|
|
8832
9243
|
const age = self.updatedAt - other.updatedAt;
|
|
8833
9244
|
if (!alive(other.pid) || age > FORGET_MS) {
|
|
8834
|
-
await rm2(
|
|
9245
|
+
await rm2(join8(this.#dir, name), { force: true }).catch(() => {
|
|
8835
9246
|
});
|
|
8836
9247
|
continue;
|
|
8837
9248
|
}
|
|
@@ -8849,7 +9260,7 @@ var Instances = class {
|
|
|
8849
9260
|
return changed;
|
|
8850
9261
|
}
|
|
8851
9262
|
#file(pid) {
|
|
8852
|
-
return
|
|
9263
|
+
return join8(this.#dir, `${pid}.json`);
|
|
8853
9264
|
}
|
|
8854
9265
|
#now() {
|
|
8855
9266
|
return (this.#options.now ?? Date.now)();
|
|
@@ -8858,10 +9269,10 @@ var Instances = class {
|
|
|
8858
9269
|
|
|
8859
9270
|
// packages/gateway/lib/shared.js
|
|
8860
9271
|
import { readFile as readFile12 } from "node:fs/promises";
|
|
8861
|
-
import { mkdirSync as
|
|
8862
|
-
import { dirname as
|
|
9272
|
+
import { mkdirSync as mkdirSync6 } from "node:fs";
|
|
9273
|
+
import { dirname as dirname7 } from "node:path";
|
|
8863
9274
|
var AGENT_PRESET = "mga";
|
|
8864
|
-
var
|
|
9275
|
+
var MAX_KEPT4 = 5e3;
|
|
8865
9276
|
var OwnSessions = class {
|
|
8866
9277
|
#file;
|
|
8867
9278
|
#ids = /* @__PURE__ */ new Set();
|
|
@@ -8878,11 +9289,11 @@ var OwnSessions = class {
|
|
|
8878
9289
|
if (this.#ids.has(sessionId))
|
|
8879
9290
|
return;
|
|
8880
9291
|
this.#ids.add(sessionId);
|
|
8881
|
-
while (this.#ids.size >
|
|
9292
|
+
while (this.#ids.size > MAX_KEPT4)
|
|
8882
9293
|
this.#ids.delete(this.#ids.values().next().value);
|
|
8883
9294
|
if (this.#file === void 0)
|
|
8884
9295
|
return;
|
|
8885
|
-
|
|
9296
|
+
mkdirSync6(dirname7(this.#file), { recursive: true });
|
|
8886
9297
|
await writeFileAtomic(this.#file, `${JSON.stringify([...this.#ids])}
|
|
8887
9298
|
`);
|
|
8888
9299
|
}
|
|
@@ -8904,6 +9315,7 @@ var AgentParts = class {
|
|
|
8904
9315
|
/** Tools the parts registered: the app's own, as opposed to dsh's (role agents are narrowed among these). */
|
|
8905
9316
|
tools = /* @__PURE__ */ new Set();
|
|
8906
9317
|
#parts = /* @__PURE__ */ new Map();
|
|
9318
|
+
#definitions = /* @__PURE__ */ new Map();
|
|
8907
9319
|
#scopes = /* @__PURE__ */ new Map();
|
|
8908
9320
|
#next = 0;
|
|
8909
9321
|
#log;
|
|
@@ -8938,6 +9350,10 @@ var AgentParts = class {
|
|
|
8938
9350
|
held.clear();
|
|
8939
9351
|
};
|
|
8940
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
|
+
}
|
|
8941
9357
|
#apply(scope, held, id, label, part) {
|
|
8942
9358
|
try {
|
|
8943
9359
|
const before = toolNames(scope);
|
|
@@ -8945,11 +9361,24 @@ var AgentParts = class {
|
|
|
8945
9361
|
for (const name of toolNames(scope))
|
|
8946
9362
|
if (!before.has(name))
|
|
8947
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);
|
|
8948
9367
|
} catch (error) {
|
|
8949
9368
|
this.#log.warn(`${label} not registered for the app's agents: ${error instanceof Error ? error.message : String(error)}`);
|
|
8950
9369
|
}
|
|
8951
9370
|
}
|
|
8952
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
|
+
}
|
|
8953
9382
|
function toolNames(scope) {
|
|
8954
9383
|
const names = /* @__PURE__ */ new Set();
|
|
8955
9384
|
for (const key of [void 0, scope]) {
|
|
@@ -9024,16 +9453,16 @@ function keptToken(dataDir, log) {
|
|
|
9024
9453
|
const fresh = () => randomBytes2(18).toString("base64url");
|
|
9025
9454
|
if (dataDir === void 0)
|
|
9026
9455
|
return fresh();
|
|
9027
|
-
const file =
|
|
9456
|
+
const file = join9(dataDir, "gateway-token");
|
|
9028
9457
|
try {
|
|
9029
|
-
const saved =
|
|
9458
|
+
const saved = readFileSync4(file, "utf8").trim();
|
|
9030
9459
|
if (/^[\w-]{16,}$/.test(saved))
|
|
9031
9460
|
return saved;
|
|
9032
9461
|
} catch {
|
|
9033
9462
|
}
|
|
9034
9463
|
const token = fresh();
|
|
9035
9464
|
try {
|
|
9036
|
-
|
|
9465
|
+
mkdirSync7(dataDir, { recursive: true });
|
|
9037
9466
|
writeFileSync(file, `${token}
|
|
9038
9467
|
`);
|
|
9039
9468
|
} catch (error) {
|
|
@@ -9047,7 +9476,7 @@ function ownerInfo(owner) {
|
|
|
9047
9476
|
return { owner: { ...owner.scripts === void 0 ? {} : { scripts: [...owner.scripts] }, ...owner.games === void 0 ? {} : { games: [...owner.games] } } };
|
|
9048
9477
|
}
|
|
9049
9478
|
var ROLE_CLOSING = [
|
|
9050
|
-
"\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",
|
|
9051
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",
|
|
9052
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",
|
|
9053
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"
|
|
@@ -9074,17 +9503,25 @@ var MAIN_AGENT = {
|
|
|
9074
9503
|
"game_list",
|
|
9075
9504
|
"game_activities",
|
|
9076
9505
|
"game_report",
|
|
9077
|
-
|
|
9078
|
-
"
|
|
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_*",
|
|
9079
9516
|
"monitor_incidents",
|
|
9080
9517
|
"monitor_stall_check",
|
|
9081
9518
|
"emulator_status",
|
|
9082
9519
|
"window_list",
|
|
9520
|
+
// The user's chat and the runs' logs to a folder, in one call (history-export.ts).
|
|
9521
|
+
"history_export",
|
|
9083
9522
|
// The built-in browser, for its sub-agents (its own conversation hands it out: roles.ts HANDS_ON).
|
|
9084
9523
|
"browser_*"
|
|
9085
|
-
]
|
|
9086
|
-
// Saving a pipeline outright is 编排's: 助手 drafts one for the user, or hands the change to 编排.
|
|
9087
|
-
hide: ["pipeline_save"]
|
|
9524
|
+
]
|
|
9088
9525
|
};
|
|
9089
9526
|
function memoryOwnerOf(spec) {
|
|
9090
9527
|
return spec.subAgentOf === void 0 ? spec.id : spec.id.replace(/:sub$/, "");
|
|
@@ -9096,14 +9533,15 @@ var MAIN_AGENT_MEMBER = { id: MAIN_AGENT.id, name: MAIN_AGENT.name, description:
|
|
|
9096
9533
|
function mainDuty(roles) {
|
|
9097
9534
|
return [
|
|
9098
9535
|
"# \u4F60\u7684\u89D2\u8272\uFF1A\u52A9\u624B",
|
|
9099
|
-
"\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\
|
|
9100
|
-
"\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\
|
|
9101
|
-
|
|
9102
|
-
|
|
9103
|
-
"\
|
|
9104
|
-
"\
|
|
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",
|
|
9105
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",
|
|
9106
|
-
"\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",
|
|
9107
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"
|
|
9108
9546
|
].join("\n\n");
|
|
9109
9547
|
}
|
|
@@ -9112,6 +9550,8 @@ var AdgGateway = class extends Service {
|
|
|
9112
9550
|
registry = new CapabilityRegistry();
|
|
9113
9551
|
workspace;
|
|
9114
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();
|
|
9115
9555
|
/** The latest context projections per session (a control frame carries only the keys its event changed). */
|
|
9116
9556
|
contexts = /* @__PURE__ */ new Map();
|
|
9117
9557
|
/** The latest non-empty inbox projection per session, so the queue can be sent again when only the taken messages change. */
|
|
@@ -9166,6 +9606,10 @@ var AdgGateway = class extends Service {
|
|
|
9166
9606
|
agents = /* @__PURE__ */ new Map();
|
|
9167
9607
|
narrowed = /* @__PURE__ */ new Map();
|
|
9168
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();
|
|
9169
9613
|
assignedSpecs = /* @__PURE__ */ new WeakMap();
|
|
9170
9614
|
subAgentSpecs = /* @__PURE__ */ new WeakMap();
|
|
9171
9615
|
persona;
|
|
@@ -9186,13 +9630,14 @@ var AdgGateway = class extends Service {
|
|
|
9186
9630
|
this.log = log;
|
|
9187
9631
|
this.workspace = config.workspaceDir;
|
|
9188
9632
|
this.shared = config.shared === true;
|
|
9189
|
-
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);
|
|
9190
9634
|
this.parts = new AgentParts(log);
|
|
9191
9635
|
this.newInput = new NewInput(ctx);
|
|
9192
|
-
this.agentModels = new AgentModels(config.dataDir === void 0 ? void 0 :
|
|
9193
|
-
this.roles = new SessionRoles(config.dataDir === void 0 ? void 0 :
|
|
9194
|
-
this.
|
|
9195
|
-
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);
|
|
9196
9641
|
if (!this.shared)
|
|
9197
9642
|
ctx.inject(["tools", "systemPrompt"], (scoped) => {
|
|
9198
9643
|
scoped.effect(() => this.parts.attach(scoped), "adg-gateway agent parts");
|
|
@@ -9231,7 +9676,7 @@ var AdgGateway = class extends Service {
|
|
|
9231
9676
|
});
|
|
9232
9677
|
if (config.workspaceDir !== void 0) {
|
|
9233
9678
|
try {
|
|
9234
|
-
|
|
9679
|
+
mkdirSync7(config.workspaceDir, { recursive: true });
|
|
9235
9680
|
} catch (error) {
|
|
9236
9681
|
log.warn(`cannot create the workspace ${config.workspaceDir}: ${String(error)}`);
|
|
9237
9682
|
}
|
|
@@ -9320,7 +9765,7 @@ var AdgGateway = class extends Service {
|
|
|
9320
9765
|
}
|
|
9321
9766
|
}
|
|
9322
9767
|
}), "adg-gateway capability questions");
|
|
9323
|
-
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"));
|
|
9324
9769
|
const presetFor = (session) => {
|
|
9325
9770
|
const presets = ctx.get("permissionPresets");
|
|
9326
9771
|
if (presets === void 0 || !this.isOwn(session.id))
|
|
@@ -9378,6 +9823,9 @@ var AdgGateway = class extends Service {
|
|
|
9378
9823
|
if (noted !== void 0)
|
|
9379
9824
|
exec.arguments = { ...exec.arguments, prompt: noted };
|
|
9380
9825
|
}
|
|
9826
|
+
const held = this.holdForLead(exec);
|
|
9827
|
+
if (held !== void 0)
|
|
9828
|
+
return held;
|
|
9381
9829
|
return next();
|
|
9382
9830
|
}));
|
|
9383
9831
|
ctx.on("tools/result", ((exec, result) => {
|
|
@@ -9594,7 +10042,7 @@ var AdgGateway = class extends Service {
|
|
|
9594
10042
|
}
|
|
9595
10043
|
} catch {
|
|
9596
10044
|
}
|
|
9597
|
-
await new Promise((
|
|
10045
|
+
await new Promise((resolve5) => setTimeout(resolve5, Math.min(3e4, 1e3 * 2 ** attempt)));
|
|
9598
10046
|
}
|
|
9599
10047
|
})();
|
|
9600
10048
|
return () => controller.abort();
|
|
@@ -9670,7 +10118,8 @@ var AdgGateway = class extends Service {
|
|
|
9670
10118
|
id: SKILLS_CAPABILITY,
|
|
9671
10119
|
version: 1,
|
|
9672
10120
|
methods: {
|
|
9673
|
-
|
|
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) }),
|
|
9674
10123
|
"skills/get": async (params, call) => {
|
|
9675
10124
|
const { name } = params;
|
|
9676
10125
|
const skill = await scoped.skills.get(name, options(call.signal));
|
|
@@ -9833,12 +10282,12 @@ var AdgGateway = class extends Service {
|
|
|
9833
10282
|
this.persona = persona;
|
|
9834
10283
|
}
|
|
9835
10284
|
if (config.dataDir !== void 0) {
|
|
9836
|
-
const memory = new MemoryStore(
|
|
10285
|
+
const memory = new MemoryStore(join9(config.dataDir, "memory.json"), () => this.broadcast("memory/changed", {}));
|
|
9837
10286
|
const views = new MemoryViews(memory, { timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone });
|
|
9838
10287
|
this.memoryViews = views;
|
|
9839
10288
|
const auto = new AutoMemory({
|
|
9840
10289
|
store: memory,
|
|
9841
|
-
file:
|
|
10290
|
+
file: join9(config.dataDir, "memory-auto.json"),
|
|
9842
10291
|
// Back to where it stopped (oldest unread first): nothing between is passed over.
|
|
9843
10292
|
read: (sessionId, since, signal) => this.sessionEvents(sessionId, since.maxMessages, signal, since.after),
|
|
9844
10293
|
agentOf: (sessionId) => {
|
|
@@ -9915,11 +10364,31 @@ var AdgGateway = class extends Service {
|
|
|
9915
10364
|
sessions: (agent, signal) => this.sessionsOf(agent, signal),
|
|
9916
10365
|
read: (sessionId, maxMessages, signal) => this.sessionEvents(sessionId, maxMessages, signal),
|
|
9917
10366
|
memory: (id) => memory.get(id),
|
|
9918
|
-
archived: summariesReader(
|
|
10367
|
+
archived: summariesReader(join9(config.dataDir, SUMMARIES_FILE)),
|
|
9919
10368
|
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
9920
10369
|
});
|
|
9921
10370
|
for (const tool of history)
|
|
9922
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));
|
|
9923
10392
|
const recalled = new RecallLog();
|
|
9924
10393
|
const zone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
9925
10394
|
this.agentPart("adg-gateway recall hook", (agent) => agent.on("agent/pre-step", (async (payload, next) => {
|
|
@@ -9976,7 +10445,7 @@ var AdgGateway = class extends Service {
|
|
|
9976
10445
|
continue;
|
|
9977
10446
|
registered.get(skill.name)?.();
|
|
9978
10447
|
try {
|
|
9979
|
-
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 } }));
|
|
9980
10449
|
} catch (error) {
|
|
9981
10450
|
log.warn(`saved skill ${skill.name} not registered: ${error instanceof Error ? error.message : String(error)}`);
|
|
9982
10451
|
}
|
|
@@ -10036,7 +10505,7 @@ var AdgGateway = class extends Service {
|
|
|
10036
10505
|
void this.followTitles(controller.signal, log);
|
|
10037
10506
|
return () => controller.abort();
|
|
10038
10507
|
}, "adg-gateway title feed");
|
|
10039
|
-
const staticDir = config.staticDir ?? (existsSync(
|
|
10508
|
+
const staticDir = config.staticDir ?? (existsSync(join9(BUNDLED_UI, "index.html")) ? BUNDLED_UI : void 0);
|
|
10040
10509
|
ctx.inject(["webServer", "connection"], (scoped) => {
|
|
10041
10510
|
const web = scoped.get("webServer");
|
|
10042
10511
|
const connection = scoped.get("connection");
|
|
@@ -10206,8 +10675,10 @@ Content-Length: 0
|
|
|
10206
10675
|
this.log.warn(`tools of the ${spec.name} agent (${agent.session.id}): ${error instanceof Error ? error.message : String(error)}`);
|
|
10207
10676
|
}
|
|
10208
10677
|
try {
|
|
10209
|
-
const duty = [spec.duty, spec.subAgentOf === void 0 ? ROLE_CLOSING : void 0].filter((text2) => text2 !== void 0 && text2 !== "").join("\n\n");
|
|
10210
|
-
const text = spec === MAIN_AGENT ? () => mainDuty(this.roles.
|
|
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");
|
|
10679
|
+
const text = spec === MAIN_AGENT ? () => `${mainDuty(this.roles.members())}
|
|
10680
|
+
|
|
10681
|
+
${APP_FILES_RULE}` : () => duty;
|
|
10211
10682
|
disposers.push(agent.ctx.systemPrompt.section({ name: "adg:role", order: 10095, interpolate: false, text }));
|
|
10212
10683
|
const views = this.memoryViews;
|
|
10213
10684
|
if (views !== void 0) {
|
|
@@ -10217,7 +10688,7 @@ Content-Length: 0
|
|
|
10217
10688
|
if (spec.subAgentOf === void 0) {
|
|
10218
10689
|
const persona = this.persona;
|
|
10219
10690
|
const known = (member) => ({ ...member, alias: persona?.of(member.id).name });
|
|
10220
|
-
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") }) }));
|
|
10221
10692
|
if (persona !== void 0)
|
|
10222
10693
|
disposers.push(agent.ctx.systemPrompt.section({ name: "adg:persona", order: 10100, interpolate: false, text: () => personaPrompt(persona.of(spec.id)) }));
|
|
10223
10694
|
}
|
|
@@ -10349,6 +10820,53 @@ Content-Length: 0
|
|
|
10349
10820
|
* sessions, and for a sub-agent, its parent's made into a sub-agent's.
|
|
10350
10821
|
* A shared dsh's other chats, and their sub-agents, are nothing of ours.
|
|
10351
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
|
+
}
|
|
10352
10870
|
specOf(sessionId) {
|
|
10353
10871
|
const header = this.agents.get(sessionId)?.session.header;
|
|
10354
10872
|
if (header?.origin === "subagent" && header.parentSession !== void 0) {
|
|
@@ -10388,11 +10906,11 @@ Content-Length: 0
|
|
|
10388
10906
|
*/
|
|
10389
10907
|
async settled(sessionId, signal) {
|
|
10390
10908
|
const subagents = this.ctx.get("subagents");
|
|
10391
|
-
const stopped = new Promise((
|
|
10909
|
+
const stopped = new Promise((resolve5) => {
|
|
10392
10910
|
if (signal.aborted)
|
|
10393
|
-
|
|
10911
|
+
resolve5();
|
|
10394
10912
|
else
|
|
10395
|
-
signal.addEventListener("abort", () =>
|
|
10913
|
+
signal.addEventListener("abort", () => resolve5(), { once: true });
|
|
10396
10914
|
});
|
|
10397
10915
|
for (; ; ) {
|
|
10398
10916
|
if (signal.aborted)
|
|
@@ -10454,10 +10972,10 @@ Content-Length: 0
|
|
|
10454
10972
|
signal.throwIfAborted();
|
|
10455
10973
|
}
|
|
10456
10974
|
await parent.send({
|
|
10457
|
-
id:
|
|
10975
|
+
id: randomUUID6(),
|
|
10458
10976
|
role: "user",
|
|
10459
10977
|
content: [{ type: "text", text: `\uFF08\u4F60\u8D1F\u8D23\u7684\u5B50\u4EFB\u52A1\uFF1A${title}\uFF09
|
|
10460
|
-
\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
|
|
10461
10979
|
|
|
10462
10980
|
${instruction}` }],
|
|
10463
10981
|
source: { kind: "adg-task-dispatched", form: "notice", summary: title, childId }
|
|
@@ -10734,6 +11252,13 @@ ${instruction}` }],
|
|
|
10734
11252
|
agentPart(label, part) {
|
|
10735
11253
|
this.ctx.effect(() => this.parts.add(label, part), label);
|
|
10736
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
|
+
}
|
|
10737
11262
|
/**
|
|
10738
11263
|
* One of the app's general skills (a core skill every one of its sessions
|
|
10739
11264
|
* sees). Shared, it goes through the skill scope, which shows it to the
|
|
@@ -10832,7 +11357,7 @@ ${instruction}` }],
|
|
|
10832
11357
|
workspaceDir() {
|
|
10833
11358
|
return this.workspace;
|
|
10834
11359
|
}
|
|
10835
|
-
/** The user turned on full access (设置 → 权限): no sandbox, no approvals, no guard. */
|
|
11360
|
+
/** The user turned on full access (设置 → 权限): no sandbox, no approvals, no guard on scripts (the app's own folders stay guarded). */
|
|
10836
11361
|
fullAccess() {
|
|
10837
11362
|
return this.permissions.mode === "full";
|
|
10838
11363
|
}
|
|
@@ -10891,7 +11416,7 @@ ${instruction}` }],
|
|
|
10891
11416
|
return;
|
|
10892
11417
|
log.warn(`title feed interrupted: ${error instanceof Error ? error.message : String(error)}`);
|
|
10893
11418
|
}
|
|
10894
|
-
await new Promise((
|
|
11419
|
+
await new Promise((resolve5) => setTimeout(resolve5, 1e3));
|
|
10895
11420
|
}
|
|
10896
11421
|
}
|
|
10897
11422
|
};
|