personal-bot 0.3.7 → 0.4.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/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +2 -2
- package/README.md +5 -8
- package/README.zh-CN.md +5 -8
- package/bin/pbot-pi-acp.mjs +1 -1
- package/docs/architecture/design.md +2 -2
- package/docs/architecture/extensibility.md +4 -4
- package/docs/architecture/model-context.md +6 -3
- package/docs/guides/cross-harness-workers.md +5 -5
- package/docs/guides/history.md +1 -3
- package/docs/guides/workspace-configuration.md +5 -5
- package/docs/hosts/claude-code.md +3 -3
- package/docs/hosts/codex-qoder.md +4 -2
- package/hooks/hooks.json +3 -0
- package/lib/antigravity-plugin/bin/pbot-pi-acp.mjs +1 -1
- package/lib/antigravity-plugin/lib/extension/acp/member.d.ts +1 -1
- package/lib/antigravity-plugin/lib/extension/acp/member.js +11 -10
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +349 -204
- package/lib/antigravity-plugin/lib/extension/cli.js +596 -572
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.js +1 -1
- package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.js +3 -4
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +1 -12
- package/lib/antigravity-plugin/lib/extension/mcp.js +463 -379
- package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +2 -2
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +3 -3
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.js +0 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/claude/adapter.js +1 -2
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.d.ts +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.js +4 -7
- package/lib/antigravity-plugin/lib/model/acp.d.ts +29 -35
- package/lib/antigravity-plugin/lib/model/agent.d.ts +33 -17
- package/lib/antigravity-plugin/lib/model/agent.js +0 -1
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.js +1 -1
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.js +6 -3
- package/lib/antigravity-plugin/lib/services/history/summary-runner.js +3 -3
- package/lib/antigravity-plugin/lib/storage/acp-files.d.ts +5 -8
- package/lib/antigravity-plugin/lib/storage/acp-files.js +34 -40
- package/lib/antigravity-plugin/lib/storage/agent-files.d.ts +19 -10
- package/lib/antigravity-plugin/lib/storage/agent-files.js +147 -43
- package/lib/antigravity-plugin/lib/storage/history-files.js +3 -2
- package/lib/antigravity-plugin/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +2 -2
- package/lib/antigravity-plugin/resources/agents/coordinator.md +2 -4
- package/lib/antigravity-plugin/resources/agents/general-purpose.md +2 -4
- package/lib/antigravity-plugin/resources/prompts/history-monthly-summary.md +6 -11
- package/lib/antigravity-plugin/resources/prompts/history-summary.md +6 -11
- package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -1
- package/lib/antigravity-plugin/resources/prompts/workspace.md +16 -23
- package/lib/antigravity-plugin/resources/skills/project-maintenance/SKILL.md +14 -21
- package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +23 -36
- package/lib/antigravity-plugin/resources/templates/workspace-agents.md +5 -13
- package/lib/antigravity-plugin/skills/pbot/SKILL.md +6 -23
- package/lib/antigravity-plugin/skills/project-maintenance/SKILL.md +14 -21
- package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +23 -36
- package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +2 -2
- package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +2 -2
- package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +3 -3
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +11 -3
- package/lib/extension/acp/member.d.ts +1 -1
- package/lib/extension/acp/member.js +11 -10
- package/lib/extension/acp/worker.js +34 -33
- package/lib/extension/acp-worker.js +349 -204
- package/lib/extension/cli.js +596 -572
- package/lib/extension/hosts/dsh/acp-member.js +1 -1
- package/lib/extension/hosts/dsh/command.js +2 -2
- package/lib/extension/hosts/dsh/workspace.js +5 -5
- package/lib/extension/hosts/pi/acp-member.js +3 -4
- package/lib/extension/hosts/plugin-runtime.js +1 -12
- package/lib/extension/mcp/tool-contract.d.ts +8 -50
- package/lib/extension/mcp/tool-contract.js +61 -107
- package/lib/extension/mcp/workers.d.ts +7 -27
- package/lib/extension/mcp/workers.js +40 -24
- package/lib/extension/mcp.js +463 -379
- package/lib/integrations/acp/agents.d.ts +2 -3
- package/lib/integrations/acp/agents.js +22 -22
- package/lib/integrations/acp/harnesses/claude.js +1 -1
- package/lib/integrations/agent-resources.d.ts +2 -2
- package/lib/integrations/agent-resources.js +3 -3
- package/lib/integrations/hosts/antigravity/adapter.js +0 -1
- package/lib/integrations/hosts/claude/adapter.js +1 -2
- package/lib/integrations/hosts/dsh/resources.d.ts +1 -1
- package/lib/integrations/hosts/prompt-hooks.js +4 -7
- package/lib/model/acp.d.ts +29 -35
- package/lib/model/agent.d.ts +33 -17
- package/lib/model/agent.js +0 -1
- package/lib/qoder-plugin/.mcp.json +2 -2
- package/lib/qoder-plugin/.qoder-plugin/plugin.json +2 -2
- package/lib/qoder-plugin/hooks/hooks.json +3 -3
- package/lib/qoder-plugin/skills/pbot/SKILL.md +11 -3
- package/lib/services/agents/acp-run.d.ts +6 -4
- package/lib/services/agents/acp-run.js +62 -43
- package/lib/services/agents/agent-run.d.ts +10 -6
- package/lib/services/agents/agent-run.js +142 -65
- package/lib/services/agents/agent-service.d.ts +3 -21
- package/lib/services/agents/agent-service.js +182 -128
- package/lib/services/history/summary-dimensions/monthly.js +1 -1
- package/lib/services/history/summary-dimensions/session.js +6 -3
- package/lib/services/history/summary-runner.js +3 -3
- package/lib/storage/acp-files.d.ts +5 -8
- package/lib/storage/acp-files.js +34 -40
- package/lib/storage/agent-files.d.ts +19 -10
- package/lib/storage/agent-files.js +147 -43
- package/lib/storage/history-files.js +3 -2
- package/lib/tools/history/contract.d.ts +1 -1
- package/lib/tools/history/contract.js +14 -16
- package/package.json +2 -2
- package/resources/agents/coordinator.md +2 -4
- package/resources/agents/general-purpose.md +2 -4
- package/resources/antigravity/skills/pbot/SKILL.md +6 -23
- package/resources/claude/skills/pbot/SKILL.md +6 -23
- package/resources/plugin/skills/pbot/SKILL.md +11 -3
- package/resources/prompts/history-coordinator.md +1 -1
- package/resources/prompts/history-monthly-summary.md +6 -11
- package/resources/prompts/history-summary.md +6 -11
- package/resources/prompts/plugin-coordinator.md +1 -1
- package/resources/prompts/workspace.md +16 -23
- package/resources/skills/project-maintenance/SKILL.md +14 -21
- package/resources/skills/provider-connections/SKILL.md +23 -36
- package/resources/templates/workspace-agents.md +5 -13
- package/src/extension/acp/member.ts +14 -11
- package/src/extension/acp/worker.ts +31 -28
- package/src/extension/cli/commands/mcp.ts +1 -1
- package/src/extension/cli/commands/upgrade.ts +8 -36
- package/src/extension/cli/commands/workspace.ts +3 -8
- package/src/extension/cli/index.ts +1 -2
- package/src/extension/hosts/dsh/acp-member.ts +1 -1
- package/src/extension/hosts/dsh/command.ts +2 -2
- package/src/extension/hosts/dsh/workspace.ts +5 -4
- package/src/extension/hosts/pi/acp-member.ts +3 -4
- package/src/extension/hosts/pi/command.ts +2 -2
- package/src/extension/hosts/pi/events.ts +1 -1
- package/src/extension/hosts/pi/lifecycle.ts +0 -2
- package/src/extension/hosts/plugin-runtime.ts +1 -11
- package/src/extension/mcp/tool-contract.ts +61 -108
- package/src/extension/mcp/workers.ts +39 -24
- package/src/integrations/acp/agents.ts +28 -27
- package/src/integrations/acp/harnesses/claude.ts +1 -1
- package/src/integrations/agent-resources.ts +5 -5
- package/src/integrations/hosts/antigravity/adapter.ts +0 -1
- package/src/integrations/hosts/claude/adapter.ts +1 -2
- package/src/integrations/hosts/dsh/resources.ts +1 -1
- package/src/integrations/hosts/dsh/session.ts +2 -2
- package/src/integrations/hosts/prompt-hooks.ts +3 -6
- package/src/integrations/installation/cli-update.ts +2 -2
- package/src/integrations/installation/installers/claude.ts +4 -4
- package/src/integrations/installation/installers/qoder.ts +5 -5
- package/src/integrations/installation/upgraders/antigravity.ts +57 -15
- package/src/integrations/installation/upgraders/claude.ts +1 -4
- package/src/integrations/installation/upgraders/codex.ts +85 -15
- package/src/integrations/installation/upgraders/dsh.ts +46 -24
- package/src/integrations/installation/upgraders/pi.ts +18 -11
- package/src/integrations/installation/upgraders/qoder.ts +95 -20
- package/src/model/acp.ts +27 -29
- package/src/model/agent.ts +80 -16
- package/src/model/installation.ts +0 -2
- package/src/pbot.ts +3 -3
- package/src/services/agents/acp-run.ts +81 -49
- package/src/services/agents/agent-run.ts +154 -56
- package/src/services/agents/agent-service.ts +206 -135
- package/src/services/history/summary-dimensions/monthly.ts +1 -1
- package/src/services/history/summary-dimensions/session.ts +6 -3
- package/src/services/history/summary-runner.ts +3 -3
- package/src/services/installation/upgrade-service.ts +1 -5
- package/src/storage/acp-files.ts +50 -45
- package/src/storage/agent-files.ts +159 -46
- package/src/storage/history-files.ts +3 -2
- package/src/tools/history/contract.ts +14 -16
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +0 -15
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +0 -126
- package/lib/services/workspace/plugin-releases.d.ts +0 -15
- package/lib/services/workspace/plugin-releases.js +0 -126
- package/src/services/workspace/plugin-releases.ts +0 -121
package/lib/extension/mcp.js
CHANGED
|
@@ -6,8 +6,7 @@ import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
|
6
6
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
7
7
|
import { existsSync as existsSync3 } from "node:fs";
|
|
8
8
|
import { realpath as realpath3, stat as stat3 } from "node:fs/promises";
|
|
9
|
-
import {
|
|
10
|
-
import { isAbsolute as isAbsolute5, join as join13 } from "node:path";
|
|
9
|
+
import { isAbsolute as isAbsolute5, join as join12 } from "node:path";
|
|
11
10
|
import { setTimeout as delay3 } from "node:timers/promises";
|
|
12
11
|
|
|
13
12
|
// src/common/json.ts
|
|
@@ -61,11 +60,11 @@ releaseLine(packageVersion);
|
|
|
61
60
|
// src/integrations/acp/agents.ts
|
|
62
61
|
import { fork, spawnSync } from "node:child_process";
|
|
63
62
|
import { existsSync as existsSync2 } from "node:fs";
|
|
64
|
-
import {
|
|
63
|
+
import { resolve as resolve4 } from "node:path";
|
|
65
64
|
import { setTimeout as delay } from "node:timers/promises";
|
|
66
65
|
|
|
67
66
|
// src/storage/agent-files.ts
|
|
68
|
-
import { existsSync, mkdirSync as mkdirSync3, readdirSync, rmSync } from "node:fs";
|
|
67
|
+
import { existsSync, mkdirSync as mkdirSync3, readdirSync, rmdirSync as rmdirSync2, rmSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
69
68
|
import { join as join3 } from "node:path";
|
|
70
69
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
71
70
|
|
|
@@ -191,7 +190,6 @@ function privateDirectory(root, relative3) {
|
|
|
191
190
|
// src/model/agent.ts
|
|
192
191
|
var messageDeliveries = ["steer", "followUp"];
|
|
193
192
|
var cycleStates = ["running", "completed", "failed", "cancelled", "interrupted"];
|
|
194
|
-
var cycleSources = ["parent", "interactive", "mixed"];
|
|
195
193
|
var agentStates = ["starting", "busy", "idle", "stopping", "stopped", "error"];
|
|
196
194
|
|
|
197
195
|
// src/storage/acp-files.ts
|
|
@@ -206,22 +204,21 @@ function isAcpElicitationValue(value) {
|
|
|
206
204
|
|
|
207
205
|
// src/storage/acp-files.ts
|
|
208
206
|
var text = (value) => typeof value === "string" && value.length > 0 && !value.includes("\0");
|
|
209
|
-
function
|
|
210
|
-
requireThat(object(value) &&
|
|
207
|
+
function acpConfig(value) {
|
|
208
|
+
requireThat(object(value) && isAcpBackend(value.backend) && text(value.command) && isAbsolute(value.command) && Array.isArray(value.args) && value.args.every((arg) => typeof arg === "string" && !arg.includes("\0")), "ACP \u542F\u52A8\u914D\u7F6E\u65E0\u6548\u3002");
|
|
211
209
|
if (value.env !== void 0) {
|
|
212
210
|
requireThat(object(value.env) && Object.entries(value.env).every(([k, v]) => text(k) && typeof v === "string" && !v.includes("\0")), "ACP \u73AF\u5883\u53D8\u91CF\u914D\u7F6E\u65E0\u6548\u3002");
|
|
213
211
|
}
|
|
214
212
|
requireThat(value.permission === void 0 || isOneOf(value.permission, acpPermissionPolicies), "ACP \u6743\u9650\u7B56\u7565\u65E0\u6548\u3002");
|
|
215
|
-
const capabilities = value.capabilities;
|
|
216
|
-
if (capabilities !== void 0) requireThat(object(capabilities) && ["resume", "load", "close"].every((key) => typeof capabilities[key] === "boolean"), "ACP \u4F1A\u8BDD\u80FD\u529B\u65E0\u6548\u3002");
|
|
217
|
-
return value;
|
|
218
|
-
}
|
|
219
|
-
function acpModelState(value) {
|
|
220
|
-
requireThat(object(value) && text(value.generation) && ["provider", "model", "resolvedModel", "thinking"].every((key) => value[key] === void 0 || text(value[key])), "ACP \u6A21\u578B\u9009\u62E9\u65E0\u6548\u3002");
|
|
221
213
|
return value;
|
|
222
214
|
}
|
|
223
|
-
function
|
|
224
|
-
requireThat(object(value) &&
|
|
215
|
+
function acpReference(value) {
|
|
216
|
+
requireThat(object(value) && value.host === "acp" && (value.sessionId === null || text(value.sessionId)), "ACP \u4F1A\u8BDD\u5F15\u7528\u65E0\u6548\u3002");
|
|
217
|
+
acpConfig(value);
|
|
218
|
+
const capabilities = value.capabilities;
|
|
219
|
+
if (capabilities !== void 0) {
|
|
220
|
+
requireThat(object(capabilities) && ["resume", "load", "close"].every((key) => typeof capabilities[key] === "boolean"), "ACP \u4F1A\u8BDD\u80FD\u529B\u65E0\u6548\u3002");
|
|
221
|
+
}
|
|
225
222
|
return value;
|
|
226
223
|
}
|
|
227
224
|
function acpInput(value) {
|
|
@@ -229,50 +226,45 @@ function acpInput(value) {
|
|
|
229
226
|
fileId(value.requestId);
|
|
230
227
|
return value;
|
|
231
228
|
}
|
|
232
|
-
function
|
|
233
|
-
requireThat(object(value) && text(value.generation) && text(value.cycleId) && typeof value.text === "string", "ACP \u5468\u671F\u62A5\u544A\u65E0\u6548\u3002");
|
|
234
|
-
fileId(value.cycleId);
|
|
235
|
-
return value;
|
|
236
|
-
}
|
|
237
|
-
function acpPermission(value) {
|
|
238
|
-
acpInput(value);
|
|
239
|
-
requireThat(object(value) && typeof value.description === "string" && Array.isArray(value.options) && value.options.every((option) => object(option) && text(option.optionId) && text(option.name) && isOneOf(option.kind, ["allow_once", "allow_always", "reject_once", "reject_always"])), "ACP \u786E\u8BA4\u8BF7\u6C42\u65E0\u6548\u3002");
|
|
240
|
-
return value;
|
|
241
|
-
}
|
|
242
|
-
function acpPermissionReply(value) {
|
|
243
|
-
acpInput(value);
|
|
244
|
-
requireThat(object(value) && (value.optionId === null || text(value.optionId)), "ACP \u786E\u8BA4\u7B54\u590D\u65E0\u6548\u3002");
|
|
245
|
-
return value;
|
|
246
|
-
}
|
|
247
|
-
function acpElicitation(value) {
|
|
229
|
+
function acpInteraction(value) {
|
|
248
230
|
acpInput(value);
|
|
249
|
-
requireThat(object(value)
|
|
250
|
-
if (value.
|
|
251
|
-
requireThat(
|
|
252
|
-
|
|
253
|
-
|
|
231
|
+
requireThat(object(value), "ACP \u4EA4\u4E92\u8BF7\u6C42\u65E0\u6548\u3002");
|
|
232
|
+
if (value.kind === "permission") {
|
|
233
|
+
requireThat(typeof value.description === "string" && Array.isArray(value.options) && value.options.every((option) => object(option) && text(option.optionId) && text(option.name) && isOneOf(option.kind, ["allow_once", "allow_always", "reject_once", "reject_always"])), "ACP \u786E\u8BA4\u8BF7\u6C42\u65E0\u6548\u3002");
|
|
234
|
+
return value;
|
|
235
|
+
}
|
|
236
|
+
if (value.kind === "form") {
|
|
237
|
+
requireThat(typeof value.message === "string" && object(value.schema), "ACP \u8868\u5355\u4EA4\u4E92\u8BF7\u6C42\u7F3A\u5C11\u6709\u6548 schema\u3002");
|
|
238
|
+
return value;
|
|
254
239
|
}
|
|
240
|
+
requireThat(value.kind === "url" && typeof value.message === "string" && text(value.url), "ACP URL \u4EA4\u4E92\u8BF7\u6C42\u65E0\u6548\u3002");
|
|
255
241
|
return value;
|
|
256
242
|
}
|
|
257
|
-
function
|
|
243
|
+
function acpInteractionReply(value) {
|
|
258
244
|
acpInput(value);
|
|
259
|
-
requireThat(object(value)
|
|
260
|
-
if (value.
|
|
261
|
-
requireThat(value.
|
|
245
|
+
requireThat(object(value), "ACP \u4EA4\u4E92\u7B54\u590D\u65E0\u6548\u3002");
|
|
246
|
+
if (value.kind === "permission") {
|
|
247
|
+
requireThat(value.optionId === null || text(value.optionId), "ACP \u786E\u8BA4\u7B54\u590D\u65E0\u6548\u3002");
|
|
248
|
+
return value;
|
|
249
|
+
}
|
|
250
|
+
if (value.kind === "form") {
|
|
251
|
+
requireThat(isOneOf(value.action, acpElicitationActions), "ACP \u8868\u5355\u7B54\u590D action \u65E0\u6548\u3002");
|
|
252
|
+
if (value.content !== void 0) {
|
|
253
|
+
requireThat(value.action === "accept" && object(value.content) && Object.values(value.content).every(isAcpElicitationValue), "ACP \u8868\u5355\u7B54\u590D content \u65E0\u6548\u3002");
|
|
254
|
+
}
|
|
255
|
+
return value;
|
|
262
256
|
}
|
|
257
|
+
requireThat(value.kind === "url" && isOneOf(value.action, acpElicitationActions), "ACP URL \u4EA4\u4E92\u7B54\u590D\u65E0\u6548\u3002");
|
|
263
258
|
return value;
|
|
264
259
|
}
|
|
265
260
|
|
|
266
261
|
// src/storage/agent-files.ts
|
|
267
262
|
var text2 = (v) => typeof v === "string" && v.length > 0;
|
|
268
263
|
var number = (v) => typeof v === "number" && Number.isFinite(v);
|
|
269
|
-
function
|
|
270
|
-
requireThat(object(v) && text2(v.agentId) && text2(v.release) && text2(v.workspace) && text2(v.
|
|
264
|
+
function workerRecord(v) {
|
|
265
|
+
requireThat(object(v) && text2(v.agentId) && text2(v.release) && text2(v.workspace) && text2(v.parentSessionId) && text2(v.generation) && Number.isSafeInteger(v.sequence) && typeof v.stop === "boolean" && number(v.startedAt) && (v.pid === void 0 || Number.isSafeInteger(v.pid) && Number(v.pid) > 1) && (v.options === void 0 || object(v.options)), "worker \u63A7\u5236\u8BB0\u5F55\u65E0\u6548\u3002");
|
|
271
266
|
fileId(v.agentId);
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
function launch(v) {
|
|
275
|
-
requireThat(object(v) && text2(v.generation) && text2(v.name) && Number.isSafeInteger(v.sequence) && typeof v.stop === "boolean" && number(v.startedAt), "\u5B50\u4F1A\u8BDD\u542F\u52A8\u72B6\u6001\u65E0\u6548\u3002");
|
|
267
|
+
acpConfig(v.acp);
|
|
276
268
|
return v;
|
|
277
269
|
}
|
|
278
270
|
function message(v) {
|
|
@@ -280,14 +272,56 @@ function message(v) {
|
|
|
280
272
|
return v;
|
|
281
273
|
}
|
|
282
274
|
function cycle(v) {
|
|
283
|
-
requireThat(object(v) && text2(v.cycleId) && text2(v.generation) && number(v.startedAt) && isOneOf(v.state, cycleStates) &&
|
|
275
|
+
requireThat(object(v) && text2(v.cycleId) && text2(v.generation) && number(v.startedAt) && isOneOf(v.state, cycleStates) && Array.isArray(v.requestIds) && v.requestIds.every(text2) && (v.finishedAt === void 0 || number(v.finishedAt)) && (v.error === void 0 || typeof v.error === "string"), "\u5B50\u4F1A\u8BDD\u5468\u671F\u65E0\u6548\u3002");
|
|
284
276
|
return v;
|
|
285
277
|
}
|
|
286
278
|
function status(v) {
|
|
287
279
|
requireThat(object(v) && text2(v.generation) && isOneOf(v.state, agentStates) && typeof v.activity === "string" && number(v.updatedAt), "\u5B50\u4F1A\u8BDD\u72B6\u6001\u65E0\u6548\u3002");
|
|
288
|
-
if (v.
|
|
280
|
+
if (v.sessionId !== void 0) requireThat(v.sessionId === null || text2(v.sessionId), "ACP \u4F1A\u8BDD ID \u65E0\u6548\u3002");
|
|
281
|
+
if (v.capabilities !== void 0) {
|
|
282
|
+
requireThat(object(v.capabilities) && ["resume", "load", "close"].every((key) => typeof v.capabilities[key] === "boolean"), "ACP \u4F1A\u8BDD\u80FD\u529B\u65E0\u6548\u3002");
|
|
283
|
+
}
|
|
284
|
+
if (v.selection !== void 0) {
|
|
285
|
+
requireThat(object(v.selection) && ["provider", "model", "resolvedModel", "thinking"].every((key) => v.selection[key] === void 0 || text2(v.selection[key])), "ACP \u6A21\u578B\u9009\u62E9\u65E0\u6548\u3002");
|
|
286
|
+
}
|
|
287
|
+
if (v.activeRequestId !== void 0) {
|
|
288
|
+
requireThat(text2(v.activeRequestId), "ACP \u8F93\u5165\u5173\u8054\u65E0\u6548\u3002");
|
|
289
|
+
fileId(v.activeRequestId);
|
|
290
|
+
}
|
|
291
|
+
if (v.accepted !== void 0) requireThat(Array.isArray(v.accepted) && v.accepted.every(text2), "\u5DF2\u9886\u53D6\u8BF7\u6C42\u5217\u8868\u65E0\u6548\u3002");
|
|
292
|
+
if (v.cycle !== void 0) cycle(v.cycle);
|
|
293
|
+
if (v.error !== void 0) requireThat(typeof v.error === "string", "\u5B50\u4F1A\u8BDD\u9519\u8BEF\u4FE1\u606F\u65E0\u6548\u3002");
|
|
294
|
+
return v;
|
|
295
|
+
}
|
|
296
|
+
function outputRecord(v) {
|
|
297
|
+
requireThat(object(v) && text2(v.cycleId) && text2(v.generation) && number(v.startedAt) && number(v.finishedAt) && isOneOf(v.state, ["completed", "failed", "cancelled", "interrupted"]) && Array.isArray(v.requestIds) && v.requestIds.every(text2) && typeof v.text === "string" && (v.error === void 0 || typeof v.error === "string"), "\u5B50\u4F1A\u8BDD\u8F93\u51FA\u8BB0\u5F55\u65E0\u6548\u3002");
|
|
298
|
+
fileId(v.cycleId);
|
|
289
299
|
return v;
|
|
290
300
|
}
|
|
301
|
+
function toDescriptor(record) {
|
|
302
|
+
return {
|
|
303
|
+
agentId: record.agentId,
|
|
304
|
+
release: record.release,
|
|
305
|
+
workspace: record.workspace,
|
|
306
|
+
parentSessionId: record.parentSessionId,
|
|
307
|
+
options: record.options ?? {}
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
function tryUnlink(path) {
|
|
311
|
+
try {
|
|
312
|
+
unlinkSync2(path);
|
|
313
|
+
} catch (error) {
|
|
314
|
+
if (error.code !== "ENOENT") throw error;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function tryRmdir(path) {
|
|
318
|
+
try {
|
|
319
|
+
rmdirSync2(path);
|
|
320
|
+
} catch (error) {
|
|
321
|
+
const code = error.code;
|
|
322
|
+
if (code !== "ENOENT" && code !== "ENOTEMPTY" && code !== "EEXIST") throw error;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
291
325
|
var AgentFiles = class {
|
|
292
326
|
constructor(root) {
|
|
293
327
|
this.root = root;
|
|
@@ -325,48 +359,99 @@ var AgentFiles = class {
|
|
|
325
359
|
}
|
|
326
360
|
requireThat(published, "\u5B50\u4F1A\u8BDD\u6587\u4EF6\u5DF2\u5B58\u5728\u3002");
|
|
327
361
|
}
|
|
362
|
+
remove(id, path) {
|
|
363
|
+
tryUnlink(join3(this.directory(id), path));
|
|
364
|
+
}
|
|
328
365
|
create(value, run, acp) {
|
|
329
366
|
this.check();
|
|
330
367
|
acpReference(acp);
|
|
331
368
|
mkdirSync3(this.root, { recursive: true, mode: 448 });
|
|
332
369
|
mkdirSync3(this.directory(value.agentId), { mode: 448 });
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
370
|
+
const hasOptions = Object.keys(value.options).length > 0;
|
|
371
|
+
const record = {
|
|
372
|
+
agentId: value.agentId,
|
|
373
|
+
release: value.release,
|
|
374
|
+
workspace: value.workspace,
|
|
375
|
+
parentSessionId: value.parentSessionId,
|
|
376
|
+
generation: run.generation,
|
|
377
|
+
sequence: run.sequence,
|
|
378
|
+
stop: run.stop,
|
|
379
|
+
startedAt: run.startedAt,
|
|
380
|
+
acp: {
|
|
381
|
+
backend: acp.backend,
|
|
382
|
+
command: acp.command,
|
|
383
|
+
args: acp.args,
|
|
384
|
+
...acp.env ? { env: acp.env } : {},
|
|
385
|
+
...acp.permission ? { permission: acp.permission } : {}
|
|
386
|
+
},
|
|
387
|
+
...hasOptions ? { options: value.options } : {}
|
|
388
|
+
};
|
|
389
|
+
this.write(value.agentId, "worker.json", record, workerRecord, true);
|
|
390
|
+
}
|
|
391
|
+
worker(id) {
|
|
392
|
+
return this.read(id, "worker.json", workerRecord);
|
|
337
393
|
}
|
|
338
394
|
list() {
|
|
339
395
|
if (!existsSync(this.root)) return [];
|
|
340
396
|
return readdirSync(this.root, { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith(".")).flatMap((e) => {
|
|
341
|
-
const
|
|
342
|
-
return
|
|
397
|
+
const record = this.optional(e.name, "worker.json", workerRecord);
|
|
398
|
+
return record ? [record] : [];
|
|
343
399
|
});
|
|
344
400
|
}
|
|
345
401
|
messages(id) {
|
|
346
|
-
|
|
402
|
+
const dir = join3(this.directory(id), "inbox");
|
|
403
|
+
if (!existsSync(dir)) return [];
|
|
404
|
+
return readdirSync(dir).filter((n) => n.endsWith(".json")).map((n) => this.read(id, "inbox/" + n, message)).sort((a, b) => a.sequence - b.sequence);
|
|
347
405
|
}
|
|
348
|
-
|
|
349
|
-
|
|
406
|
+
removeMessage(id, requestId) {
|
|
407
|
+
fileId(requestId);
|
|
408
|
+
const dir = join3(this.directory(id), "inbox");
|
|
409
|
+
tryUnlink(join3(dir, requestId + ".json"));
|
|
410
|
+
tryRmdir(dir);
|
|
350
411
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const dir = join3(this.directory(id), "permissions");
|
|
354
|
-
if (!existsSync(dir)) return [];
|
|
355
|
-
const names = readdirSync(dir);
|
|
356
|
-
return names.filter((n) => n.endsWith(".json") && !n.endsWith("-reply.json") && !names.includes(n.slice(0, -5) + "-reply.json")).map((n) => this.read(id, "permissions/" + n, acpPermission)).filter((item) => item.generation === generation);
|
|
412
|
+
output(id) {
|
|
413
|
+
return this.optional(id, "output.json", outputRecord);
|
|
357
414
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
const dir = join3(this.directory(id), "elicitations");
|
|
415
|
+
pendingInteractions(id, generation) {
|
|
416
|
+
const dir = join3(this.directory(id), "interactions");
|
|
361
417
|
if (!existsSync(dir)) return [];
|
|
362
418
|
const names = readdirSync(dir);
|
|
363
|
-
return names.filter((n) => n.endsWith(".json") && !n.endsWith("-reply.json") && !names.includes(n.slice(0, -5) + "-reply.json")).map((n) => this.read(id, "
|
|
419
|
+
return names.filter((n) => n.endsWith(".json") && !n.endsWith("-reply.json") && !names.includes(n.slice(0, -5) + "-reply.json")).map((n) => this.read(id, "interactions/" + n, acpInteraction)).filter((item) => item.generation === generation);
|
|
420
|
+
}
|
|
421
|
+
removeInteraction(id, requestId) {
|
|
422
|
+
fileId(requestId);
|
|
423
|
+
const dir = join3(this.directory(id), "interactions");
|
|
424
|
+
tryUnlink(join3(dir, requestId + ".json"));
|
|
425
|
+
tryUnlink(join3(dir, requestId + "-reply.json"));
|
|
426
|
+
tryRmdir(dir);
|
|
427
|
+
}
|
|
428
|
+
clearTransient(id) {
|
|
429
|
+
const base = this.directory(id);
|
|
430
|
+
if (!existsSync(base)) return;
|
|
431
|
+
rmSync(join3(base, "inbox"), { recursive: true, force: true });
|
|
432
|
+
rmSync(join3(base, "interactions"), { recursive: true, force: true });
|
|
433
|
+
tryUnlink(join3(base, "acp-answer.json"));
|
|
434
|
+
}
|
|
435
|
+
removeWorker(id) {
|
|
436
|
+
rmSync(this.directory(id), { recursive: true, force: true });
|
|
437
|
+
tryRmdir(this.root);
|
|
364
438
|
}
|
|
365
439
|
ensureSubdirectory(id, name) {
|
|
366
440
|
privateDirectory(this.directory(id), name);
|
|
367
441
|
}
|
|
368
442
|
reference(id) {
|
|
369
|
-
|
|
443
|
+
const w = this.worker(id);
|
|
444
|
+
const saved = this.optional(id, "state.json", status);
|
|
445
|
+
return {
|
|
446
|
+
host: "acp",
|
|
447
|
+
backend: w.acp.backend,
|
|
448
|
+
command: w.acp.command,
|
|
449
|
+
args: w.acp.args,
|
|
450
|
+
...w.acp.env ? { env: w.acp.env } : {},
|
|
451
|
+
...w.acp.permission ? { permission: w.acp.permission } : {},
|
|
452
|
+
sessionId: saved?.sessionId ?? null,
|
|
453
|
+
...saved?.capabilities ? { capabilities: saved.capabilities } : {}
|
|
454
|
+
};
|
|
370
455
|
}
|
|
371
456
|
/** Short controller edits are serialized; an abandoned lock fails closed. */
|
|
372
457
|
control(work) {
|
|
@@ -387,14 +472,16 @@ var AgentFiles = class {
|
|
|
387
472
|
}
|
|
388
473
|
enqueue(id, text3, delivery, files = [], requestId = randomUUID2()) {
|
|
389
474
|
fileId(requestId);
|
|
390
|
-
const
|
|
475
|
+
const w = this.worker(id);
|
|
476
|
+
const previous = this.optional(id, "inbox/" + requestId + ".json", message);
|
|
391
477
|
if (previous) {
|
|
392
|
-
requireThat(previous.generation ===
|
|
478
|
+
requireThat(previous.generation === w.generation && previous.message === text3 && previous.delivery === delivery && canonical(previous.files) === canonical(files), "\u8BF7\u6C42 ID \u5DF2\u88AB\u4E0D\u540C\u8F93\u5165\u4F7F\u7528\u3002");
|
|
393
479
|
return previous;
|
|
394
480
|
}
|
|
395
|
-
|
|
396
|
-
this.write(id, "
|
|
397
|
-
|
|
481
|
+
w.sequence++;
|
|
482
|
+
this.write(id, "worker.json", w, workerRecord);
|
|
483
|
+
this.ensureSubdirectory(id, "inbox");
|
|
484
|
+
const value = { requestId, generation: w.generation, sequence: w.sequence, message: text3, delivery, files };
|
|
398
485
|
this.write(id, "inbox/" + value.requestId + ".json", value, message, true);
|
|
399
486
|
return value;
|
|
400
487
|
}
|
|
@@ -526,7 +613,7 @@ var claudeAcpHarness = {
|
|
|
526
613
|
},
|
|
527
614
|
async prepareLaunch(context) {
|
|
528
615
|
const base = defaultPrepareLaunch(context);
|
|
529
|
-
const claude = await claudeOptions(base.command, context.
|
|
616
|
+
const claude = await claudeOptions(base.command, context.workspace, context.options.thinking, context.features?.skills !== false);
|
|
530
617
|
return {
|
|
531
618
|
...base,
|
|
532
619
|
...claude.thinking ? { defaultThinking: claude.thinking } : {},
|
|
@@ -769,13 +856,13 @@ var AcpWorkerHost = class {
|
|
|
769
856
|
return acpLaunch(backend, this.commands, options);
|
|
770
857
|
}
|
|
771
858
|
/** Probe a backend's advertised model and thinking choices in an isolated ACP process without prompting. */
|
|
772
|
-
async inspectModels(backend,
|
|
859
|
+
async inspectModels(backend, workspace, options = {}) {
|
|
773
860
|
this.available(backend);
|
|
774
861
|
const filtered = this.filterOptions(backend, options);
|
|
775
862
|
const reference = this.prepare(backend, filtered);
|
|
776
863
|
return await new Promise((resolveResult, reject) => {
|
|
777
864
|
const child = fork(this.worker, ["--probe"], {
|
|
778
|
-
cwd,
|
|
865
|
+
cwd: workspace,
|
|
779
866
|
env: { ...process.env },
|
|
780
867
|
detached: true,
|
|
781
868
|
stdio: ["ignore", "ignore", "ignore", "ipc"],
|
|
@@ -802,7 +889,7 @@ var AcpWorkerHost = class {
|
|
|
802
889
|
child.once("spawn", () => {
|
|
803
890
|
child.send({
|
|
804
891
|
reference,
|
|
805
|
-
cwd,
|
|
892
|
+
cwd: workspace,
|
|
806
893
|
...filtered.provider ? { provider: filtered.provider } : {},
|
|
807
894
|
...filtered.model ? { model: filtered.model } : {}
|
|
808
895
|
});
|
|
@@ -815,8 +902,8 @@ var AcpWorkerHost = class {
|
|
|
815
902
|
});
|
|
816
903
|
}
|
|
817
904
|
process(id) {
|
|
818
|
-
const record = this.files.optional(id, "
|
|
819
|
-
if (!record
|
|
905
|
+
const record = this.files.optional(id, "worker.json", workerRecord);
|
|
906
|
+
if (!record?.pid) return;
|
|
820
907
|
let denied = false;
|
|
821
908
|
try {
|
|
822
909
|
process.kill(-record.pid, 0);
|
|
@@ -828,7 +915,7 @@ var AcpWorkerHost = class {
|
|
|
828
915
|
}
|
|
829
916
|
const leader = spawnSync("ps", ["-p", String(record.pid), "-o", "args="], { encoding: "utf8" });
|
|
830
917
|
if (leader.status === 0 && !leader.stdout.includes("--pbot-acp-agent " + id + " --generation " + record.generation) || denied && leader.status !== 0) return;
|
|
831
|
-
return record;
|
|
918
|
+
return { generation: record.generation, pid: record.pid };
|
|
832
919
|
}
|
|
833
920
|
alive(id) {
|
|
834
921
|
return Boolean(this.process(id));
|
|
@@ -836,10 +923,11 @@ var AcpWorkerHost = class {
|
|
|
836
923
|
async validateSession(d, reference) {
|
|
837
924
|
requireThat(!this.alive(d.agentId), "ACP \u6210\u5458\u4ECD\u5728\u8FD0\u884C\uFF0C\u4E0D\u80FD\u6062\u590D\u3002");
|
|
838
925
|
if (reference.sessionId === null) {
|
|
839
|
-
|
|
926
|
+
const saved = this.files.optional(d.agentId, "state.json", status);
|
|
927
|
+
requireThat(!saved?.activeRequestId, "ACP \u8F93\u5165\u4EA4\u4ED8\u72B6\u6001\u4E0D\u660E\uFF1B\u8BF7\u6838\u5BF9\u539F\u8BF7\u6C42\u540E\u65B0\u5EFA\u6210\u5458\u3002");
|
|
840
928
|
return;
|
|
841
929
|
}
|
|
842
|
-
const generation = this.files.
|
|
930
|
+
const generation = this.files.worker(d.agentId).generation;
|
|
843
931
|
await new Promise((resolveResult, reject) => {
|
|
844
932
|
const child = this.spawn(d, generation, true);
|
|
845
933
|
let validated = false, failure;
|
|
@@ -877,7 +965,7 @@ var AcpWorkerHost = class {
|
|
|
877
965
|
this.files.directory(d.agentId),
|
|
878
966
|
...validate ? ["--validate"] : []
|
|
879
967
|
], {
|
|
880
|
-
cwd: d.
|
|
968
|
+
cwd: d.workspace,
|
|
881
969
|
env: { ...process.env },
|
|
882
970
|
detached: true,
|
|
883
971
|
stdio: ["ignore", "ignore", "ignore", "ipc"],
|
|
@@ -891,12 +979,19 @@ var AcpWorkerHost = class {
|
|
|
891
979
|
child.once("spawn", resolveResult);
|
|
892
980
|
child.once("error", reject);
|
|
893
981
|
});
|
|
894
|
-
|
|
982
|
+
const pid = child.pid;
|
|
983
|
+
requireThat(pid, "ACP worker \u6CA1\u6709\u8FDB\u7A0B\u8EAB\u4EFD\u3002");
|
|
895
984
|
try {
|
|
896
|
-
this.files.
|
|
985
|
+
this.files.control(() => {
|
|
986
|
+
const w = this.files.worker(d.agentId);
|
|
987
|
+
if (w.generation === generation) {
|
|
988
|
+
w.pid = pid;
|
|
989
|
+
this.files.write(d.agentId, "worker.json", w, workerRecord);
|
|
990
|
+
}
|
|
991
|
+
});
|
|
897
992
|
} catch (error) {
|
|
898
993
|
try {
|
|
899
|
-
process.kill(-
|
|
994
|
+
process.kill(-pid, "SIGKILL");
|
|
900
995
|
} catch (failure) {
|
|
901
996
|
if (failure.code !== "ESRCH") throw new AggregateError([error, failure], "ACP \u542F\u52A8\u4E0E\u6E05\u7406\u5931\u8D25\u3002");
|
|
902
997
|
}
|
|
@@ -929,17 +1024,11 @@ var AcpWorkerHost = class {
|
|
|
929
1024
|
const current = this.process(id);
|
|
930
1025
|
if (current?.generation === generation && current.pid === record.pid) terminate("SIGKILL");
|
|
931
1026
|
}
|
|
932
|
-
report(d, _reference, leaf) {
|
|
933
|
-
requireThat(leaf.startsWith("acp:"), "ACP \u62A5\u544A\u5F15\u7528\u65E0\u6548\u3002");
|
|
934
|
-
const cycleId = fileId(leaf.slice(4)), report = this.files.read(d.agentId, join7("reports", cycleId + ".json"), acpReport);
|
|
935
|
-
requireThat(report.cycleId === cycleId, "ACP \u62A5\u544A\u5468\u671F\u4E0D\u5339\u914D\u3002");
|
|
936
|
-
return report.text;
|
|
937
|
-
}
|
|
938
1027
|
};
|
|
939
1028
|
|
|
940
1029
|
// src/integrations/hosts/antigravity/adapter.ts
|
|
941
1030
|
import { readFile, realpath, stat } from "node:fs/promises";
|
|
942
|
-
import { dirname as dirname2, isAbsolute as isAbsolute3, join as
|
|
1031
|
+
import { dirname as dirname2, isAbsolute as isAbsolute3, join as join7, relative, resolve as resolve5, sep } from "node:path";
|
|
943
1032
|
var supportedEvents = ["SessionStart", "PreToolUse", "Stop"];
|
|
944
1033
|
function cleanUserRequest(content) {
|
|
945
1034
|
const match = content.match(/<USER_REQUEST>\s*([\s\S]*?)\s*<\/USER_REQUEST>/);
|
|
@@ -989,7 +1078,7 @@ function projectAntigravityTranscript(sessionId, content, terminationReason) {
|
|
|
989
1078
|
return { sessionId, name: "", branches: exchanges.length ? [exchanges] : [] };
|
|
990
1079
|
}
|
|
991
1080
|
async function readAntigravityTranscript(transcriptPath) {
|
|
992
|
-
const fullPath =
|
|
1081
|
+
const fullPath = join7(dirname2(transcriptPath), "transcript_full.jsonl");
|
|
993
1082
|
for (const path of [fullPath, transcriptPath]) {
|
|
994
1083
|
try {
|
|
995
1084
|
return await readFile(path, "utf8");
|
|
@@ -1028,7 +1117,6 @@ var antigravityAdapter = {
|
|
|
1028
1117
|
host: "antigravity",
|
|
1029
1118
|
nativeRootAgents: true,
|
|
1030
1119
|
nativeWorkspaceSkills: true,
|
|
1031
|
-
coordinatorPrompt: "plugin-coordinator.md",
|
|
1032
1120
|
initCommandHint: "/pbot init",
|
|
1033
1121
|
usage: "\u7528\u6CD5\uFF1Anode <\u63D2\u4EF6\u76EE\u5F55>/lib/plugin.js antigravity init|status",
|
|
1034
1122
|
resolveRoot(cwd, rawPayload) {
|
|
@@ -1103,12 +1191,9 @@ function parsePromptEvent(value) {
|
|
|
1103
1191
|
if (name !== "Stop" && name !== "UserPromptSubmit" && name !== "SessionStart") return { kind: "ignore" };
|
|
1104
1192
|
if (typeof value.agent_id === "string") return { kind: "ignore" };
|
|
1105
1193
|
requireThat(typeof value.cwd === "string", "\u63D2\u4EF6 hook \u7F3A\u5C11\u5DE5\u4F5C\u76EE\u5F55\u3002");
|
|
1106
|
-
if (name
|
|
1107
|
-
if (
|
|
1108
|
-
|
|
1109
|
-
return { kind: "inject-context", role: "coordinator", isSessionStart: true, noticesOnly: true, cwd: value.cwd, raw: value };
|
|
1110
|
-
}
|
|
1111
|
-
return { kind: "inject-context", role: "coordinator", cwd: value.cwd, raw: value };
|
|
1194
|
+
if (name !== "SessionStart") return { kind: "record-history", cwd: value.cwd, raw: value };
|
|
1195
|
+
if (value.source === "resume" || value.source === "compact") return { kind: "ignore" };
|
|
1196
|
+
return { kind: "inject-context", role: "coordinator", isSessionStart: true, cwd: value.cwd, raw: value };
|
|
1112
1197
|
}
|
|
1113
1198
|
var promptHooks = {
|
|
1114
1199
|
async extractHistory(event) {
|
|
@@ -1154,7 +1239,7 @@ var promptHooks = {
|
|
|
1154
1239
|
};
|
|
1155
1240
|
|
|
1156
1241
|
// src/integrations/hosts/claude/adapter.ts
|
|
1157
|
-
var supportedEvents2 = ["UserPromptSubmit", "PreToolUse", "UserPromptExpansion", "Stop"];
|
|
1242
|
+
var supportedEvents2 = ["SessionStart", "UserPromptSubmit", "PreToolUse", "UserPromptExpansion", "Stop"];
|
|
1158
1243
|
var boundWorkspaceRoot = () => process.env.CLAUDE_PROJECT_DIR;
|
|
1159
1244
|
async function claudeWorkspaceRoot(cwd, projectDirectory = boundWorkspaceRoot()) {
|
|
1160
1245
|
return pluginWorkspaceRoot(projectDirectory || cwd);
|
|
@@ -1163,7 +1248,6 @@ var claudeAdapter = {
|
|
|
1163
1248
|
host: "claude",
|
|
1164
1249
|
nativeRootAgents: false,
|
|
1165
1250
|
nativeWorkspaceSkills: false,
|
|
1166
|
-
coordinatorPrompt: "plugin-coordinator.md",
|
|
1167
1251
|
initCommandHint: "/personal-bot:pbot init",
|
|
1168
1252
|
usage: "\u7528\u6CD5\uFF1Anode <\u63D2\u4EF6\u76EE\u5F55>/lib/claude.js init|status",
|
|
1169
1253
|
boundWorkspaceRoot,
|
|
@@ -1265,30 +1349,27 @@ function formatBackendItem(entry, defaultBackend) {
|
|
|
1265
1349
|
if (entry.backend === defaultBackend) tags.push("\u5F53\u524D\u5BBF\u4E3B");
|
|
1266
1350
|
return tags.length ? `${entry.backend}\uFF08${tags.join("\uFF0C")}\uFF09` : entry.backend;
|
|
1267
1351
|
}
|
|
1268
|
-
function summarizeBackends(commands = {}, defaultBackend) {
|
|
1269
|
-
const entries = inspectAcpBackends(commands);
|
|
1270
|
-
const available = entries.filter((item) => item.available);
|
|
1271
|
-
const unavailable = entries.filter((item) => !item.available);
|
|
1272
|
-
const availableText = available.map((item) => formatBackendItem(item, defaultBackend)).join("\u3001");
|
|
1273
|
-
const unavailableText = unavailable.map((item) => formatBackendItem(item, defaultBackend)).join("\u3001");
|
|
1274
|
-
const overview = available.length ? unavailable.length ? `\u5F53\u524D\u53EF\u7528\u52A9\u624B\uFF1A${availableText}\uFF1B\u6682\u4E0D\u53EF\u7528\uFF1A${unavailableText}\u3002` : `\u5F53\u524D\u53EF\u7528\u52A9\u624B\uFF1A${availableText}\u3002` : `\u5F53\u524D\u65E0\u53EF\u7528\u5916\u90E8\u52A9\u624B\uFF08\u6682\u4E0D\u53EF\u7528\uFF1A${unavailableText}\uFF09\u3002`;
|
|
1275
|
-
const availableIds = available.map((item) => item.backend).join("\u3001");
|
|
1276
|
-
return { overview, availableIds };
|
|
1277
|
-
}
|
|
1278
1352
|
function workspaceProperty(workspaceBound) {
|
|
1279
1353
|
return {
|
|
1280
1354
|
type: "string",
|
|
1281
|
-
description: workspaceBound ? "\u5DE5\u4F5C\u533A\u6839\u76EE\u5F55\u7EDD\u5BF9\u8DEF\u5F84\
|
|
1355
|
+
description: workspaceBound ? "\u5DE5\u4F5C\u533A\u6839\u76EE\u5F55\u7684\u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u9ED8\u8BA4\u5F53\u524D\u7ED1\u5B9A\u7684\u5DE5\u4F5C\u533A\u3002" : "\u4F20\u76EE\u6807\u5DE5\u4F5C\u533A\u7684\u7EDD\u5BF9\u8DEF\u5F84\uFF08workspaceRoot\uFF09\u3002\u7701\u7565\u65F6\u4F7F\u7528\u670D\u52A1\u7684\u5F53\u524D\u76EE\u5F55\u3002"
|
|
1282
1356
|
};
|
|
1283
1357
|
}
|
|
1284
1358
|
function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = false) {
|
|
1285
|
-
const
|
|
1286
|
-
const
|
|
1359
|
+
const available = inspectAcpBackends(commands).filter((item) => item.available);
|
|
1360
|
+
const overview = available.length ? "\u53EF\u7528\u52A9\u624B\uFF1A" + available.map((item) => formatBackendItem(item, defaultBackend)).join("\u3001") + "\u3002" : "\u5F53\u524D\u6CA1\u6709\u53EF\u7528\u52A9\u624B\u3002\u7528 worker_discover \u7684 backends \u67E5\u770B\u63A5\u5165\u72B6\u6001\u3002";
|
|
1287
1361
|
const workspace = workspaceProperty(workspaceBound);
|
|
1362
|
+
const workerId = { type: "string", description: "\u52A9\u624B\u4F1A\u8BDD ID\u3002" };
|
|
1363
|
+
const waitMs = {
|
|
1364
|
+
type: "integer",
|
|
1365
|
+
minimum: 0,
|
|
1366
|
+
maximum: maxWaitMs,
|
|
1367
|
+
description: `\u7B49\u5F85\u672C\u8F6E\u7ED3\u679C\u7684\u6BEB\u79D2\u6570\uFF0C\u9ED8\u8BA4 ${defaultWaitMs}\u30020 \u8868\u793A\u4E0D\u7B49\u5F85\u7ED3\u679C\u3002`
|
|
1368
|
+
};
|
|
1288
1369
|
return [
|
|
1289
1370
|
{
|
|
1290
1371
|
name: "worker_create",
|
|
1291
|
-
description: "\
|
|
1372
|
+
description: "\u65B0\u5EFA\u72EC\u7ACB\u52A9\u624B\u4F1A\u8BDD\uFF0C\u8FD4\u56DE workerId\u3002\u7528 worker_request \u53D1\u9001\u9996\u4E2A\u4EFB\u52A1\u3002\n" + overview,
|
|
1292
1373
|
annotations: {
|
|
1293
1374
|
title: "Create Worker",
|
|
1294
1375
|
readOnlyHint: false,
|
|
@@ -1303,19 +1384,15 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
1303
1384
|
properties: {
|
|
1304
1385
|
backend: {
|
|
1305
1386
|
type: "string",
|
|
1306
|
-
description: "\
|
|
1387
|
+
description: "\u52A9\u624B\u6807\u8BC6\u6216\u522B\u540D\uFF0C\u5982 claude-code\u3001agy\u3002"
|
|
1307
1388
|
},
|
|
1308
1389
|
model: {
|
|
1309
1390
|
type: "string",
|
|
1310
|
-
description:
|
|
1391
|
+
description: "\u6A21\u578B ID\u3001\u663E\u793A\u540D\u6216 provider/model\u3002\u672A\u6307\u5B9A\u6A21\u578B\u65F6\u7701\u7565\uFF0C\u4F7F\u7528\u52A9\u624B\u9ED8\u8BA4\u6A21\u578B\u3002"
|
|
1311
1392
|
},
|
|
1312
1393
|
thinking: {
|
|
1313
1394
|
type: "string",
|
|
1314
|
-
description: "\u601D\u8003\u6DF1\u5EA6\
|
|
1315
|
-
},
|
|
1316
|
-
cwd: {
|
|
1317
|
-
type: "string",
|
|
1318
|
-
description: "\u6267\u884C\u76EE\u5F55\uFF08\u7EDD\u5BF9\u8DEF\u5F84\u6216\u76F8\u5BF9\u5DE5\u4F5C\u533A\u8DEF\u5F84\uFF09\uFF0C\u9ED8\u8BA4\u5DE5\u4F5C\u533A\u6839\u76EE\u5F55\u3002"
|
|
1395
|
+
description: "\u601D\u8003\u6DF1\u5EA6\uFF0C\u5982 high\u3002\u672A\u6307\u5B9A\u65F6\u7701\u7565\uFF0C\u4F7F\u7528\u52A9\u624B\u9ED8\u8BA4\u8BBE\u7F6E\u3002"
|
|
1319
1396
|
},
|
|
1320
1397
|
workspace
|
|
1321
1398
|
}
|
|
@@ -1323,7 +1400,7 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
1323
1400
|
},
|
|
1324
1401
|
{
|
|
1325
1402
|
name: "worker_close",
|
|
1326
|
-
description: "\u7ED3\u675F\
|
|
1403
|
+
description: "\u4EFB\u52A1\u7ED3\u675F\u540E\u5173\u95ED\u52A9\u624B\u3002\u63D0\u524D\u5173\u95ED\u4F1A\u4E2D\u65AD\u6267\u884C\u3002\u521B\u5EFA\u7ED3\u679C\u4E2D resume \u4E3A true \u65F6\uFF0C\u53EF\u7528\u539F workerId \u7EED\u63A5\u3002",
|
|
1327
1404
|
annotations: {
|
|
1328
1405
|
title: "Close Worker",
|
|
1329
1406
|
readOnlyHint: false,
|
|
@@ -1336,17 +1413,13 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
1336
1413
|
additionalProperties: false,
|
|
1337
1414
|
required: ["workerId"],
|
|
1338
1415
|
properties: {
|
|
1339
|
-
workerId
|
|
1340
|
-
type: "string",
|
|
1341
|
-
description: "\u52A9\u624B\u4F1A\u8BDD ID\uFF08\u6765\u81EA worker_create \u6216 worker_discover\uFF09\u3002"
|
|
1342
|
-
},
|
|
1343
|
-
workspace
|
|
1416
|
+
workerId
|
|
1344
1417
|
}
|
|
1345
1418
|
}
|
|
1346
1419
|
},
|
|
1347
1420
|
{
|
|
1348
1421
|
name: "worker_request",
|
|
1349
|
-
description:
|
|
1422
|
+
description: "\u5411\u52A9\u624B\u6D3E\u53D1\u4EFB\u52A1\u6216\u5728\u540C\u4E00\u4F1A\u8BDD\u8FFD\u95EE\u3002\u540E\u53F0\u7ED3\u679C\u7528 worker_output \u6536\u53D6\u3002",
|
|
1350
1423
|
annotations: {
|
|
1351
1424
|
title: "Send Request to Worker",
|
|
1352
1425
|
readOnlyHint: false,
|
|
@@ -1359,27 +1432,18 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
1359
1432
|
additionalProperties: false,
|
|
1360
1433
|
required: ["workerId", "message"],
|
|
1361
1434
|
properties: {
|
|
1362
|
-
workerId
|
|
1363
|
-
type: "string",
|
|
1364
|
-
description: "\u52A9\u624B\u4F1A\u8BDD ID\uFF08\u6765\u81EA worker_create \u6216 worker_discover\uFF09\u3002"
|
|
1365
|
-
},
|
|
1435
|
+
workerId,
|
|
1366
1436
|
message: {
|
|
1367
1437
|
type: "string",
|
|
1368
|
-
description: "\u4EFB\u52A1\
|
|
1438
|
+
description: "\u4EFB\u52A1\u6216\u8FFD\u95EE\u3002\u52A9\u624B\u770B\u4E0D\u5230\u4E3B\u4F1A\u8BDD\u5386\u53F2\uFF0C\u9996\u6B21\u6D3E\u53D1\u65F6\u5199\u660E\u80CC\u666F\u3001\u76EE\u6807\u3001\u6587\u4EF6\u8DEF\u5F84\u3001\u7EA6\u675F\u548C\u4EA4\u4ED8\u8981\u6C42\u3002"
|
|
1369
1439
|
},
|
|
1370
|
-
waitMs
|
|
1371
|
-
type: "integer",
|
|
1372
|
-
minimum: 0,
|
|
1373
|
-
maximum: maxWaitMs,
|
|
1374
|
-
description: `\u6700\u591A\u7B49\u5F85\u6BEB\u79D2\u6570\uFF08\u9ED8\u8BA4 ${defaultWaitMs}\uFF09\uFF1B0 \u8868\u793A\u7ACB\u5373\u8FD4\u56DE\u8F6C\u540E\u53F0\u6267\u884C\u3002`
|
|
1375
|
-
},
|
|
1376
|
-
workspace
|
|
1440
|
+
waitMs
|
|
1377
1441
|
}
|
|
1378
1442
|
}
|
|
1379
1443
|
},
|
|
1380
1444
|
{
|
|
1381
1445
|
name: "worker_response",
|
|
1382
|
-
description:
|
|
1446
|
+
description: "\u6536\u5230 needsResponse \u65F6\uFF0C\u5C06\u6743\u9650\u9009\u9879\u3001\u8868\u5355\u95EE\u9898\u6216\u94FE\u63A5\u4EA4\u7ED9\u7528\u6237\u786E\u8BA4\uFF0C\u518D\u63D0\u4EA4\u7528\u6237\u7684\u51B3\u5B9A\u3002",
|
|
1383
1447
|
annotations: {
|
|
1384
1448
|
title: "Respond to Worker Request",
|
|
1385
1449
|
readOnlyHint: false,
|
|
@@ -1392,41 +1456,32 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
1392
1456
|
additionalProperties: false,
|
|
1393
1457
|
required: ["workerId", "action"],
|
|
1394
1458
|
properties: {
|
|
1395
|
-
workerId
|
|
1396
|
-
type: "string",
|
|
1397
|
-
description: "\u7B49\u5F85\u56DE\u590D\u7684\u52A9\u624B\u4F1A\u8BDD ID\u3002"
|
|
1398
|
-
},
|
|
1459
|
+
workerId,
|
|
1399
1460
|
action: {
|
|
1400
1461
|
type: "string",
|
|
1401
1462
|
enum: [...acpElicitationActions],
|
|
1402
|
-
description: "accept \u540C\u610F
|
|
1463
|
+
description: "accept \u540C\u610F\u6216\u63D0\u4EA4\u7B54\u6848\uFF0Cdecline \u62D2\u7EDD\uFF0Ccancel \u53D6\u6D88\u8BF7\u6C42\u3002"
|
|
1403
1464
|
},
|
|
1404
1465
|
requestId: {
|
|
1405
1466
|
type: "string",
|
|
1406
|
-
description: "\u8BF7\u6C42 ID\
|
|
1467
|
+
description: "\u5F85\u56DE\u590D\u7684\u8BF7\u6C42 ID\u3002\u4EC5\u6709\u4E00\u6761\u5F85\u5904\u7406\u8BF7\u6C42\u65F6\u53EF\u7701\u7565\u3002"
|
|
1407
1468
|
},
|
|
1408
1469
|
optionId: {
|
|
1409
1470
|
type: "string",
|
|
1410
|
-
description: "\
|
|
1471
|
+
description: "\u5141\u8BB8\u6216\u62D2\u7EDD\u64CD\u4F5C\u65F6\u586B\u7528\u6237\u6240\u9009\u6743\u9650\u7684 ID\u3002\u7701\u7565\u65F6\u4F18\u5148\u5355\u6B21\uFF0C\u7F3A\u5C11\u5355\u6B21\u9009\u9879\u65F6\u53EF\u80FD\u91C7\u7528\u957F\u671F\u9009\u9879\u3002"
|
|
1411
1472
|
},
|
|
1412
1473
|
content: {
|
|
1413
1474
|
type: "object",
|
|
1414
1475
|
additionalProperties: true,
|
|
1415
|
-
description:
|
|
1416
|
-
},
|
|
1417
|
-
waitMs: {
|
|
1418
|
-
type: "integer",
|
|
1419
|
-
minimum: 0,
|
|
1420
|
-
maximum: maxWaitMs,
|
|
1421
|
-
description: `\u63D0\u4EA4\u540E\u6700\u591A\u7B49\u5F85\u6BEB\u79D2\u6570\uFF08\u9ED8\u8BA4 ${defaultWaitMs}\uFF09\uFF1B0 \u8868\u793A\u7ACB\u5373\u8FD4\u56DE\u3002`
|
|
1476
|
+
description: "\u63A5\u53D7\u8868\u5355\u65F6\uFF0C\u6309\u8868\u5355\u5B57\u6BB5\u586B\u5199\u7B54\u6848\u3002\u503C\u53EF\u4E3A\u5B57\u7B26\u4E32\u3001\u6570\u5B57\u3001\u5E03\u5C14\u503C\u6216\u5B57\u7B26\u4E32\u6570\u7EC4\u3002"
|
|
1422
1477
|
},
|
|
1423
|
-
|
|
1478
|
+
waitMs
|
|
1424
1479
|
}
|
|
1425
1480
|
}
|
|
1426
1481
|
},
|
|
1427
1482
|
{
|
|
1428
1483
|
name: "worker_output",
|
|
1429
|
-
description: "\
|
|
1484
|
+
description: "\u8BFB\u53D6\u52A9\u624B\u6700\u8FD1\u4E00\u8F6E\u7684\u7ED3\u679C\u3002\u540E\u53F0\u6267\u884C\u6216\u8FD4\u56DE timedOut \u65F6\uFF0C\u7528\u539F workerId \u7EE7\u7EED\u7B49\u5F85\u3002",
|
|
1430
1485
|
annotations: {
|
|
1431
1486
|
title: "Get Worker Output",
|
|
1432
1487
|
readOnlyHint: true,
|
|
@@ -1439,28 +1494,19 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
1439
1494
|
additionalProperties: false,
|
|
1440
1495
|
required: ["workerId"],
|
|
1441
1496
|
properties: {
|
|
1442
|
-
workerId
|
|
1443
|
-
type: "string",
|
|
1444
|
-
description: "\u52A9\u624B\u4F1A\u8BDD ID\u3002"
|
|
1445
|
-
},
|
|
1497
|
+
workerId,
|
|
1446
1498
|
offset: {
|
|
1447
1499
|
type: "integer",
|
|
1448
1500
|
minimum: 0,
|
|
1449
|
-
description: "\u8BFB\
|
|
1501
|
+
description: "\u7EED\u8BFB\u4F20\u4E0A\u9875\u7684 nextOffset\uFF0C\u9ED8\u8BA4\u4ECE 0 \u5F00\u59CB\u3002"
|
|
1450
1502
|
},
|
|
1451
|
-
waitMs
|
|
1452
|
-
type: "integer",
|
|
1453
|
-
minimum: 0,
|
|
1454
|
-
maximum: maxWaitMs,
|
|
1455
|
-
description: `\u8FD0\u884C\u4E2D\u6700\u591A\u7B49\u5F85\u6BEB\u79D2\u6570\uFF08\u9ED8\u8BA4 ${defaultWaitMs}\uFF09\uFF1B\u5DF2\u7ED3\u675F\u6216\u7FFB\u9875\u65F6\u7ACB\u5373\u8FD4\u56DE\u3002`
|
|
1456
|
-
},
|
|
1457
|
-
workspace
|
|
1503
|
+
waitMs
|
|
1458
1504
|
}
|
|
1459
1505
|
}
|
|
1460
1506
|
},
|
|
1461
1507
|
{
|
|
1462
1508
|
name: "worker_discover",
|
|
1463
|
-
description: "\u67E5\
|
|
1509
|
+
description: "\u67E5\u627E\u53EF\u590D\u7528\u7684\u4F1A\u8BDD\u3001\u67E5\u770B\u52A9\u624B\u72B6\u6001\u6216\u6838\u5BF9\u6A21\u578B\u9009\u9879\u3002\u67E5\u8BE2\u6A21\u578B\u4F1A\u4E34\u65F6\u542F\u52A8\u76EE\u6807\u52A9\u624B\u3002",
|
|
1464
1510
|
annotations: {
|
|
1465
1511
|
title: "Discover Workers, Backends & Models",
|
|
1466
1512
|
readOnlyHint: true,
|
|
@@ -1476,19 +1522,19 @@ function buildPbotWorkerTools(commands = {}, defaultBackend, workspaceBound = fa
|
|
|
1476
1522
|
target: {
|
|
1477
1523
|
type: "string",
|
|
1478
1524
|
enum: [...discoverTargets],
|
|
1479
|
-
description: "overview\uFF08\u9ED8\u8BA4\
|
|
1525
|
+
description: "overview\uFF08\u9ED8\u8BA4\uFF09\u5217\u52A9\u624B\u53CA\u5F53\u524D\u4F1A\u8BDD\u62E5\u6709\u7684 worker\uFF0Cworkers \u53EA\u67E5\u4F1A\u8BDD\uFF0Cbackends \u53EA\u67E5\u52A9\u624B\u53EF\u7528\u60C5\u51B5\uFF0Cmodels \u67E5\u6A21\u578B\u4E0E\u601D\u8003\u6DF1\u5EA6\u3002"
|
|
1480
1526
|
},
|
|
1481
1527
|
workerId: {
|
|
1482
1528
|
type: "string",
|
|
1483
|
-
description:
|
|
1529
|
+
description: "\u67E5 workers \u65F6\u53EF\u6307\u5B9A\u5355\u4E2A\u4F1A\u8BDD\uFF0C\u7701\u7565\u5217\u51FA\u5168\u90E8\u6240\u5C5E\u4F1A\u8BDD\u3002"
|
|
1484
1530
|
},
|
|
1485
1531
|
backend: {
|
|
1486
1532
|
type: "string",
|
|
1487
|
-
description:
|
|
1533
|
+
description: defaultBackend ? `\u67E5 models \u65F6\u9009\u62E9\u52A9\u624B\uFF0C\u9ED8\u8BA4 ${defaultBackend}\u3002` : "\u67E5 models \u65F6\u5FC5\u586B\u52A9\u624B\u6807\u8BC6\u3002"
|
|
1488
1534
|
},
|
|
1489
1535
|
model: {
|
|
1490
1536
|
type: "string",
|
|
1491
|
-
description:
|
|
1537
|
+
description: "\u67E5 models \u65F6\u53EF\u6307\u5B9A\u6A21\u578B\u4EE5\u67E5\u770B\u5B83\u652F\u6301\u7684\u601D\u8003\u6DF1\u5EA6\u3002"
|
|
1492
1538
|
},
|
|
1493
1539
|
workspace
|
|
1494
1540
|
}
|
|
@@ -1501,7 +1547,7 @@ function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
|
1501
1547
|
return [
|
|
1502
1548
|
{
|
|
1503
1549
|
name: "workspace_mcp_discover",
|
|
1504
|
-
description: "\u67E5\
|
|
1550
|
+
description: "\u67E5\u627E\u5DE5\u4F5C\u533A\u5171\u4EAB\u7684 MCP \u670D\u52A1\uFF0C\u4EE5\u53CA\u670D\u52A1\u63D0\u4F9B\u7684\u5DE5\u5177\u548C\u53C2\u6570\u3002",
|
|
1505
1551
|
annotations: {
|
|
1506
1552
|
title: "Discover Workspace MCP Servers & Tools",
|
|
1507
1553
|
readOnlyHint: true,
|
|
@@ -1516,7 +1562,7 @@ function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
|
1516
1562
|
properties: {
|
|
1517
1563
|
server: {
|
|
1518
1564
|
type: "string",
|
|
1519
|
-
description: "\u670D\u52A1\u540D\
|
|
1565
|
+
description: "\u586B\u670D\u52A1\u540D\u5217\u51FA\u5176\u5DE5\u5177\uFF0C\u7701\u7565\u5219\u5217\u51FA\u5DF2\u914D\u7F6E\u7684\u670D\u52A1\u3002"
|
|
1520
1566
|
},
|
|
1521
1567
|
workspace
|
|
1522
1568
|
}
|
|
@@ -1524,11 +1570,11 @@ function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
|
1524
1570
|
},
|
|
1525
1571
|
{
|
|
1526
1572
|
name: "workspace_mcp_call",
|
|
1527
|
-
description: "\
|
|
1573
|
+
description: "\u6267\u884C\u5DE5\u4F5C\u533A\u5171\u4EAB MCP \u670D\u52A1\u7684\u5DE5\u5177\uFF0C\u8BFB\u5199\u6548\u679C\u53D6\u51B3\u4E8E\u6240\u9009\u5DE5\u5177\u3002\u5DE5\u5177\u540D\u548C\u53C2\u6570\u53EF\u7528 workspace_mcp_discover \u67E5\u8BE2\u3002",
|
|
1528
1574
|
annotations: {
|
|
1529
1575
|
title: "Call Workspace MCP Tool",
|
|
1530
1576
|
readOnlyHint: false,
|
|
1531
|
-
destructiveHint:
|
|
1577
|
+
destructiveHint: true,
|
|
1532
1578
|
idempotentHint: false,
|
|
1533
1579
|
openWorldHint: true
|
|
1534
1580
|
},
|
|
@@ -1539,16 +1585,16 @@ function buildWorkspaceMcpTools(workspaceBound = false) {
|
|
|
1539
1585
|
properties: {
|
|
1540
1586
|
server: {
|
|
1541
1587
|
type: "string",
|
|
1542
|
-
description: "\
|
|
1588
|
+
description: "\u5DE5\u4F5C\u533A\u4E2D\u767B\u8BB0\u7684\u670D\u52A1\u540D\u3002"
|
|
1543
1589
|
},
|
|
1544
1590
|
tool: {
|
|
1545
1591
|
type: "string",
|
|
1546
|
-
description: "\u5DE5\u5177\u540D\
|
|
1592
|
+
description: "\u8BE5\u670D\u52A1\u63D0\u4F9B\u7684\u5DE5\u5177\u540D\u3002"
|
|
1547
1593
|
},
|
|
1548
1594
|
arguments: {
|
|
1549
1595
|
type: "object",
|
|
1550
1596
|
additionalProperties: true,
|
|
1551
|
-
description: "\
|
|
1597
|
+
description: "\u6309\u6240\u9009\u5DE5\u5177\u7684\u53C2\u6570\u5B9A\u4E49\u586B\u5199\uFF0C\u9ED8\u8BA4 {}\u3002"
|
|
1552
1598
|
},
|
|
1553
1599
|
workspace
|
|
1554
1600
|
}
|
|
@@ -1561,7 +1607,7 @@ function buildHistoryMcpTools(workspaceBound = false) {
|
|
|
1561
1607
|
return [
|
|
1562
1608
|
{
|
|
1563
1609
|
name: "history_search",
|
|
1564
|
-
description: "\
|
|
1610
|
+
description: "\u67E5\u627E\u5DE5\u4F5C\u533A\u5404\u5BBF\u4E3B\u5F52\u6863\u7684\u95EE\u7B54\u6216\u6458\u8981\u3002\u7528\u547D\u4E2D\u9879\u7684 id \u8C03\u7528 history_read \u53EF\u8BFB\u5168\u6587\u3002",
|
|
1565
1611
|
annotations: {
|
|
1566
1612
|
title: "Search Workspace History",
|
|
1567
1613
|
readOnlyHint: true,
|
|
@@ -1576,38 +1622,38 @@ function buildHistoryMcpTools(workspaceBound = false) {
|
|
|
1576
1622
|
properties: {
|
|
1577
1623
|
host: {
|
|
1578
1624
|
type: "string",
|
|
1579
|
-
description: "\u6765\u6E90\u5BBF\u4E3B\u7B5B\u9009\
|
|
1625
|
+
description: "\u6309\u6765\u6E90\u5BBF\u4E3B\u7B5B\u9009\uFF0C\u5982 pi \u6216 claude\u3002\u9ED8\u8BA4\u67E5\u5168\u90E8\u6765\u6E90\u3002"
|
|
1580
1626
|
},
|
|
1581
1627
|
dimension: {
|
|
1582
1628
|
type: "string",
|
|
1583
|
-
description: "\
|
|
1629
|
+
description: "raw \u4E3A\u539F\u59CB\u95EE\u7B54\uFF0Csession\u3001monthly \u7B49\u4E3A\u6458\u8981\u7EF4\u5EA6\u3002\u5173\u952E\u8BCD\u641C\u7D22\u9ED8\u8BA4\u67E5\u5168\u90E8\u3002"
|
|
1584
1630
|
},
|
|
1585
1631
|
query: {
|
|
1586
1632
|
type: "string",
|
|
1587
|
-
description: "\u8FDE\u7EED\
|
|
1633
|
+
description: "\u5339\u914D\u8FDE\u7EED\u6587\u672C\uFF0C\u5FFD\u7565\u5927\u5C0F\u5199\u3002\u7701\u7565\u65F6\u5217\u4F1A\u8BDD\uFF0C\u6307\u5B9A\u6458\u8981\u7EF4\u5EA6\u5219\u5217\u8BE5\u7EF4\u5EA6\u7684\u6458\u8981\u3002"
|
|
1588
1634
|
},
|
|
1589
1635
|
sessionId: {
|
|
1590
1636
|
type: "string",
|
|
1591
|
-
description: "\
|
|
1637
|
+
description: "\u6309\u539F\u59CB\u4F1A\u8BDD ID \u7B5B\u9009\u3002"
|
|
1592
1638
|
},
|
|
1593
1639
|
from: {
|
|
1594
1640
|
type: "string",
|
|
1595
|
-
description: "ISO \u65E5\u671F\u6216\u65F6\u95F4\
|
|
1641
|
+
description: "\u65F6\u95F4\u533A\u95F4\u8D77\u70B9\uFF08\u542B\uFF09\uFF0C\u7528 ISO \u65E5\u671F\u6216\u65F6\u95F4\u3002"
|
|
1596
1642
|
},
|
|
1597
1643
|
to: {
|
|
1598
1644
|
type: "string",
|
|
1599
|
-
description: "ISO \u65E5\u671F\
|
|
1645
|
+
description: "\u65F6\u95F4\u533A\u95F4\u7EC8\u70B9\uFF08\u542B\uFF09\uFF0C\u4EC5\u586B ISO \u65E5\u671F\u8868\u793A\u8BE5\u65E5 UTC \u96F6\u70B9\u3002"
|
|
1600
1646
|
},
|
|
1601
1647
|
offset: {
|
|
1602
1648
|
type: "integer",
|
|
1603
1649
|
minimum: 0,
|
|
1604
|
-
description: "\u7ED3\u679C\
|
|
1650
|
+
description: "\u7ED3\u679C\u8D77\u70B9\uFF0C\u9ED8\u8BA4 0\u3002\u7FFB\u9875\u4F20\u4E0A\u9875\u7684 nextOffset\u3002"
|
|
1605
1651
|
},
|
|
1606
1652
|
limit: {
|
|
1607
1653
|
type: "integer",
|
|
1608
1654
|
minimum: 1,
|
|
1609
1655
|
maximum: historyPageLimits.search.max,
|
|
1610
|
-
description: `\
|
|
1656
|
+
description: `\u6BCF\u9875\u6761\u6570\uFF0C\u9ED8\u8BA4 ${historyPageLimits.search.default}\u3002`
|
|
1611
1657
|
},
|
|
1612
1658
|
workspace
|
|
1613
1659
|
}
|
|
@@ -1615,7 +1661,7 @@ function buildHistoryMcpTools(workspaceBound = false) {
|
|
|
1615
1661
|
},
|
|
1616
1662
|
{
|
|
1617
1663
|
name: "history_read",
|
|
1618
|
-
description: "\
|
|
1664
|
+
description: "\u8BFB\u53D6\u5386\u53F2\u8282\u70B9\u7684\u6B63\u6587\u548C\u4E0A\u4E0B\u7EA7\u3002\u6CBF\u5B50\u8282\u70B9\u53EF\u4ECE\u6708\u5EA6\u6C47\u603B\u627E\u5230\u4F1A\u8BDD\u6458\u8981\u548C\u539F\u59CB\u95EE\u7B54\u3002",
|
|
1619
1665
|
annotations: {
|
|
1620
1666
|
title: "Read Workspace History Node",
|
|
1621
1667
|
readOnlyHint: true,
|
|
@@ -1630,27 +1676,27 @@ function buildHistoryMcpTools(workspaceBound = false) {
|
|
|
1630
1676
|
properties: {
|
|
1631
1677
|
id: {
|
|
1632
1678
|
type: "string",
|
|
1633
|
-
description: "\
|
|
1679
|
+
description: "\u641C\u7D22\u7ED3\u679C\u3001\u7236\u8282\u70B9\u6216\u5B50\u8282\u70B9\u7684 id\u3002"
|
|
1634
1680
|
},
|
|
1635
1681
|
host: {
|
|
1636
1682
|
type: "string",
|
|
1637
|
-
description: "\
|
|
1683
|
+
description: "\u8282\u70B9 id \u91CD\u540D\u65F6\u586B\u6765\u6E90\u5BBF\u4E3B\u3002"
|
|
1638
1684
|
},
|
|
1639
1685
|
offset: {
|
|
1640
1686
|
type: "integer",
|
|
1641
1687
|
minimum: 0,
|
|
1642
|
-
description: "\u6B63\u6587\u5B57\u7B26\u504F\u79FB\uFF0C\u9ED8\u8BA4 0\
|
|
1688
|
+
description: "\u6B63\u6587\u5B57\u7B26\u504F\u79FB\uFF0C\u9ED8\u8BA4 0\u3002\u7EED\u8BFB\u4F20\u4E0A\u9875\u7684 nextOffset\u3002"
|
|
1643
1689
|
},
|
|
1644
1690
|
limit: {
|
|
1645
1691
|
type: "integer",
|
|
1646
1692
|
minimum: 1,
|
|
1647
1693
|
maximum: historyPageLimits.read.max,
|
|
1648
|
-
description: `\u6B63\u6587\u5B57\u7B26\u6570\
|
|
1694
|
+
description: `\u6BCF\u9875\u6B63\u6587\u5B57\u7B26\u6570\uFF0C\u9ED8\u8BA4 ${historyPageLimits.read.default}\u3002`
|
|
1649
1695
|
},
|
|
1650
1696
|
childrenOffset: {
|
|
1651
1697
|
type: "integer",
|
|
1652
1698
|
minimum: 0,
|
|
1653
|
-
description: "\u5B50\u8282\u70B9\
|
|
1699
|
+
description: "\u5B50\u8282\u70B9\u8D77\u70B9\uFF0C\u9ED8\u8BA4 0\u3002\u7FFB\u9875\u4F20\u4E0A\u9875\u7684 nextChildrenOffset\u3002"
|
|
1654
1700
|
},
|
|
1655
1701
|
workspace
|
|
1656
1702
|
}
|
|
@@ -1693,56 +1739,50 @@ var AgentService = class {
|
|
|
1693
1739
|
check() {
|
|
1694
1740
|
requireThat(!this.#closed, "worker \u670D\u52A1\u5DF2\u5173\u95ED\u3002");
|
|
1695
1741
|
}
|
|
1696
|
-
owned(
|
|
1697
|
-
return
|
|
1742
|
+
owned(w, owner) {
|
|
1743
|
+
return w.workspace === this.root && w.parentSessionId === owner.sessionId;
|
|
1698
1744
|
}
|
|
1699
1745
|
get(id, owner) {
|
|
1700
1746
|
this.check();
|
|
1701
|
-
const
|
|
1702
|
-
requireThat(this.owned(
|
|
1703
|
-
requireThat(releaseLine(
|
|
1704
|
-
return
|
|
1747
|
+
const w = this.files.worker(id);
|
|
1748
|
+
requireThat(this.owned(w, owner), "worker \u4E0D\u5C5E\u4E8E\u5F53\u524D\u4F1A\u8BDD\u3002");
|
|
1749
|
+
requireThat(releaseLine(w.release) === releaseLine(packageVersion), "worker \u7248\u672C\u4E0D\u517C\u5BB9\uFF1B\u8BF7\u505C\u6B62\u540E\u4F7F\u7528\u5339\u914D\u7248\u672C\u3002");
|
|
1750
|
+
return w;
|
|
1705
1751
|
}
|
|
1706
1752
|
records(owner) {
|
|
1707
1753
|
this.check();
|
|
1708
|
-
return this.files.list().filter((
|
|
1754
|
+
return this.files.list().filter((w) => w.workspace === this.root && w.parentSessionId === owner.sessionId && releaseLine(w.release) === releaseLine(packageVersion));
|
|
1755
|
+
}
|
|
1756
|
+
has(id, owner) {
|
|
1757
|
+
if (this.#closed) return false;
|
|
1758
|
+
const w = this.files.optional(id, "worker.json", workerRecord);
|
|
1759
|
+
return Boolean(w && this.owned(w, owner) && releaseLine(w.release) === releaseLine(packageVersion));
|
|
1709
1760
|
}
|
|
1710
1761
|
list(owner) {
|
|
1711
|
-
return this.records(owner).map((
|
|
1762
|
+
return this.records(owner).map((w) => this.view(w, owner));
|
|
1712
1763
|
}
|
|
1713
|
-
view(
|
|
1714
|
-
const
|
|
1715
|
-
const
|
|
1716
|
-
const
|
|
1717
|
-
const alive = this.alive(d.agentId), pending = this.#starting.get(d.agentId);
|
|
1764
|
+
view(w, owner) {
|
|
1765
|
+
const saved = this.files.optional(w.agentId, "state.json", status);
|
|
1766
|
+
const current = saved?.generation === w.generation ? saved : void 0;
|
|
1767
|
+
const alive = this.alive(w.agentId), pending = this.#starting.get(w.agentId);
|
|
1718
1768
|
const starting = pending && !pending.controller.signal.aborted;
|
|
1719
|
-
const
|
|
1720
|
-
const
|
|
1721
|
-
const
|
|
1722
|
-
...model.provider ? { provider: model.provider } : {},
|
|
1723
|
-
...model.model ? { model: model.model } : {},
|
|
1724
|
-
...model.resolvedModel ? { resolvedModel: model.resolvedModel } : {},
|
|
1725
|
-
...model.thinking ? { thinking: model.thinking } : {}
|
|
1726
|
-
} : void 0;
|
|
1727
|
-
const pendingRequests = alive ? [
|
|
1728
|
-
...this.files.pendingPermissions(d.agentId, run.generation).map((item) => ({ requestId: item.requestId, kind: "permission", description: item.description, options: item.options })),
|
|
1729
|
-
...this.files.pendingElicitations(d.agentId, run.generation).map((item) => item.mode === "form" ? { requestId: item.requestId, kind: "form", message: item.message, schema: item.schema ?? { type: "object", properties: {} } } : { requestId: item.requestId, kind: "url", message: item.message, url: item.url ?? "" })
|
|
1730
|
-
] : [];
|
|
1769
|
+
const selection = current?.selection && Object.keys(current.selection).length ? current.selection : void 0;
|
|
1770
|
+
const pendingRequests = alive ? this.files.pendingInteractions(w.agentId, w.generation).map((item) => item.kind === "permission" ? { requestId: item.requestId, kind: "permission", description: item.description, options: item.options } : item.kind === "form" ? { requestId: item.requestId, kind: "form", message: item.message, schema: item.schema } : { requestId: item.requestId, kind: "url", message: item.message, url: item.url }) : [];
|
|
1771
|
+
const capabilities = saved?.capabilities;
|
|
1731
1772
|
return {
|
|
1732
|
-
...
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
owned: this.owned(d, owner),
|
|
1773
|
+
...toDescriptor(w),
|
|
1774
|
+
generation: w.generation,
|
|
1775
|
+
owned: this.owned(w, owner),
|
|
1736
1776
|
alive,
|
|
1737
|
-
backend:
|
|
1777
|
+
backend: w.acp.backend,
|
|
1738
1778
|
transport: "acp",
|
|
1739
1779
|
capabilities: {
|
|
1740
1780
|
steer: false,
|
|
1741
|
-
resume: Boolean(
|
|
1781
|
+
resume: Boolean(capabilities?.resume || capabilities?.load),
|
|
1742
1782
|
transcript: false
|
|
1743
1783
|
},
|
|
1744
1784
|
...selection ? { selection } : {},
|
|
1745
|
-
state: alive ? starting ? "starting" :
|
|
1785
|
+
state: alive ? starting ? "starting" : w.stop || pending?.controller.signal.aborted ? "stopping" : current?.state ?? "starting" : current?.state === "error" ? "error" : "stopped",
|
|
1746
1786
|
activity: starting ? "\u542F\u52A8" : alive ? current?.activity ?? "\u542F\u52A8" : current?.error ?? "\u5DF2\u505C\u6B62",
|
|
1747
1787
|
...current?.cycle ? { cycle: current.cycle } : {},
|
|
1748
1788
|
...current?.error ? { error: current.error } : {},
|
|
@@ -1751,15 +1791,16 @@ var AgentService = class {
|
|
|
1751
1791
|
}
|
|
1752
1792
|
/** Answer a pending permission or elicitation request forwarded by the worker. */
|
|
1753
1793
|
respond(id, input, owner) {
|
|
1754
|
-
const
|
|
1755
|
-
const pending = this.view(
|
|
1794
|
+
const w = this.get(id, owner);
|
|
1795
|
+
const pending = this.view(w, owner).pendingRequests ?? [];
|
|
1756
1796
|
if (!input.requestId && pending.length > 1) {
|
|
1757
1797
|
throw new Error("\u5B58\u5728\u591A\u6761\u5F85\u56DE\u590D\u8BF7\u6C42\uFF0C\u8BF7\u6307\u5B9A requestId\uFF1A" + pending.map((item) => item.requestId).join(", "));
|
|
1758
1798
|
}
|
|
1759
1799
|
const target = input.requestId ? pending.find((item) => item.requestId === input.requestId) : pending[0];
|
|
1760
|
-
requireThat(target, input.requestId ?
|
|
1800
|
+
requireThat(target, input.requestId ? `\u6CA1\u6709\u5F85\u56DE\u590D\u7684\u8BF7\u6C42 ${input.requestId}\u3002\u7528 worker_discover \u67E5\u8BE2 target="workers"\u3001workerId="${id}" \u7684\u5F53\u524D\u8BF7\u6C42\u3002` : "\u5F53\u524D\u6CA1\u6709\u5F85\u56DE\u590D\u7684\u8BF7\u6C42\u3002");
|
|
1801
|
+
this.files.ensureSubdirectory(id, "interactions");
|
|
1761
1802
|
if (target.kind === "permission") {
|
|
1762
|
-
requireThat(input.content === void 0, "\u6743\u9650\u8BF7\u6C42\
|
|
1803
|
+
requireThat(input.content === void 0, "\u8BF7\u79FB\u9664 content\u3002\u6743\u9650\u8BF7\u6C42\u7528 action \u56DE\u590D\uFF0C\u9009\u62E9\u5177\u4F53\u6743\u9650\u8303\u56F4\u65F6\u52A0\u4E0A optionId\u3002");
|
|
1763
1804
|
let resolved = null;
|
|
1764
1805
|
if (input.action === "cancel") {
|
|
1765
1806
|
requireThat(input.optionId === void 0, "action \u4E3A cancel \u65F6\u4E0D\u80FD\u540C\u65F6\u6307\u5B9A optionId\u3002");
|
|
@@ -1784,15 +1825,14 @@ var AgentService = class {
|
|
|
1784
1825
|
resolved = pick("reject_once", "reject_always") ?? null;
|
|
1785
1826
|
}
|
|
1786
1827
|
}
|
|
1787
|
-
this.files.ensureSubdirectory(id, "permissions");
|
|
1788
1828
|
this.files.write(
|
|
1789
1829
|
id,
|
|
1790
|
-
"
|
|
1791
|
-
{ generation:
|
|
1792
|
-
|
|
1830
|
+
"interactions/" + target.requestId + "-reply.json",
|
|
1831
|
+
{ generation: w.generation, requestId: target.requestId, kind: "permission", optionId: resolved },
|
|
1832
|
+
acpInteractionReply,
|
|
1793
1833
|
true
|
|
1794
1834
|
);
|
|
1795
|
-
return this.view(
|
|
1835
|
+
return this.view(w, owner);
|
|
1796
1836
|
}
|
|
1797
1837
|
if (target.kind === "form") {
|
|
1798
1838
|
requireThat(input.optionId === void 0, "\u95EE\u7B54/\u8868\u5355\u8BF7\u6C42\u4E0D\u4F7F\u7528 optionId\uFF1B\u8BF7\u5C06\u7B54\u6848\u586B\u5165 content\u3002");
|
|
@@ -1801,28 +1841,28 @@ var AgentService = class {
|
|
|
1801
1841
|
} else {
|
|
1802
1842
|
requireThat(input.content === void 0 || object(input.content), "\u95EE\u7B54/\u8868\u5355\u7B54\u590D\u7684 content \u5FC5\u987B\u662F\u5BF9\u8C61\u3002");
|
|
1803
1843
|
}
|
|
1804
|
-
this.files.
|
|
1805
|
-
|
|
1806
|
-
generation: run.generation,
|
|
1844
|
+
this.files.write(id, "interactions/" + target.requestId + "-reply.json", {
|
|
1845
|
+
generation: w.generation,
|
|
1807
1846
|
requestId: target.requestId,
|
|
1847
|
+
kind: "form",
|
|
1808
1848
|
action: input.action,
|
|
1809
1849
|
...input.action === "accept" ? { content: input.content ?? {} } : {}
|
|
1810
|
-
},
|
|
1811
|
-
return this.view(
|
|
1850
|
+
}, acpInteractionReply, true);
|
|
1851
|
+
return this.view(w, owner);
|
|
1812
1852
|
}
|
|
1813
1853
|
requireThat(input.optionId === void 0, "URL \u786E\u8BA4\u8BF7\u6C42\u4E0D\u4F7F\u7528 optionId\u3002");
|
|
1814
1854
|
requireThat(input.content === void 0, "URL \u786E\u8BA4\u8BF7\u6C42\u4E0D\u4F7F\u7528 content\u3002");
|
|
1815
|
-
this.files.
|
|
1816
|
-
|
|
1817
|
-
generation: run.generation,
|
|
1855
|
+
this.files.write(id, "interactions/" + target.requestId + "-reply.json", {
|
|
1856
|
+
generation: w.generation,
|
|
1818
1857
|
requestId: target.requestId,
|
|
1858
|
+
kind: "url",
|
|
1819
1859
|
action: input.action
|
|
1820
|
-
},
|
|
1821
|
-
return this.view(
|
|
1860
|
+
}, acpInteractionReply, true);
|
|
1861
|
+
return this.view(w, owner);
|
|
1822
1862
|
}
|
|
1823
1863
|
async start(input, owner) {
|
|
1824
1864
|
this.check();
|
|
1825
|
-
const { backend, ...supplied } = input;
|
|
1865
|
+
const { backend, message: initialMessage, files: initialFiles, ...supplied } = input;
|
|
1826
1866
|
this.host.available(backend);
|
|
1827
1867
|
const clean = Object.fromEntries(Object.entries(supplied).filter(([, v]) => v !== void 0));
|
|
1828
1868
|
const options = this.host.filterOptions ? this.host.filterOptions(backend, clean) : clean;
|
|
@@ -1830,27 +1870,26 @@ var AgentService = class {
|
|
|
1830
1870
|
const prepared = this.files.control(() => {
|
|
1831
1871
|
requireThat(this.list(owner).filter((v) => v.alive).length < 50, "\u6700\u591A 50 \u4E2A\u5B58\u6D3B\u6216\u542F\u52A8\u4E2D worker\uFF1B\u8BF7\u5148\u505C\u6B62\u4E00\u4E2A\u7A7A\u95F2\u4F1A\u8BDD\u3002");
|
|
1832
1872
|
const agentId = randomUUID3();
|
|
1833
|
-
const
|
|
1834
|
-
const files = (options.files ?? []).map((p) => realpathSync3(resolve6(this.root, p)));
|
|
1873
|
+
const files = (initialFiles ?? []).map((p) => realpathSync3(resolve6(this.root, p)));
|
|
1835
1874
|
const d = {
|
|
1836
1875
|
agentId,
|
|
1837
1876
|
release: packageVersion,
|
|
1838
1877
|
workspace: this.root,
|
|
1839
|
-
cwd,
|
|
1840
1878
|
parentSessionId: owner.sessionId,
|
|
1841
|
-
|
|
1842
|
-
createdAt: Date.now(),
|
|
1843
|
-
options: { ...options, files, cwd }
|
|
1879
|
+
options
|
|
1844
1880
|
};
|
|
1845
|
-
const run = { generation: randomUUID3(),
|
|
1881
|
+
const run = { generation: randomUUID3(), sequence: 0, stop: false, startedAt: Date.now() };
|
|
1846
1882
|
this.files.create(d, run, reference);
|
|
1847
|
-
const initial =
|
|
1883
|
+
const initial = initialMessage ?? "";
|
|
1848
1884
|
const request = initial || files.length ? this.files.enqueue(agentId, initial, "steer", files) : void 0;
|
|
1849
1885
|
this.#starting.set(agentId, { generation: run.generation, controller: new AbortController(), stage: "launch" });
|
|
1850
1886
|
return { d, run, request };
|
|
1851
1887
|
});
|
|
1852
1888
|
await this.launch(prepared.d, prepared.run.generation);
|
|
1853
|
-
return {
|
|
1889
|
+
return {
|
|
1890
|
+
...this.view(this.files.worker(prepared.d.agentId), owner),
|
|
1891
|
+
...prepared.request ? { requestId: prepared.request.requestId, messageStatus: "queued" } : {}
|
|
1892
|
+
};
|
|
1854
1893
|
}
|
|
1855
1894
|
async launch(d, generation, resume = false) {
|
|
1856
1895
|
const pending = this.#starting.get(d.agentId);
|
|
@@ -1860,18 +1899,21 @@ var AgentService = class {
|
|
|
1860
1899
|
await this.host.launch(d, this.files.directory(d.agentId), generation, this.files.reference(d.agentId), resume, pending.controller.signal);
|
|
1861
1900
|
requireThat(!this.#closed || this.#preserve, "worker \u670D\u52A1\u5DF2\u5173\u95ED\u3002");
|
|
1862
1901
|
pending.controller.signal.throwIfAborted();
|
|
1863
|
-
const
|
|
1864
|
-
requireThat(
|
|
1902
|
+
const w = this.files.worker(d.agentId);
|
|
1903
|
+
requireThat(w.generation === generation && !w.stop, "worker \u542F\u52A8\u5DF2\u53D6\u6D88\u6216\u4EE3\u6B21\u53D8\u5316\u3002");
|
|
1865
1904
|
} catch (error) {
|
|
1866
|
-
const
|
|
1867
|
-
if (
|
|
1905
|
+
const w = this.files.worker(d.agentId);
|
|
1906
|
+
if (w.generation === generation) {
|
|
1868
1907
|
if (this.host.alive(d.agentId)) await this.release(d.agentId);
|
|
1869
|
-
this.files.
|
|
1908
|
+
const existing = this.files.optional(d.agentId, "state.json", status);
|
|
1909
|
+
this.files.write(d.agentId, "state.json", {
|
|
1870
1910
|
generation,
|
|
1871
|
-
state:
|
|
1872
|
-
activity:
|
|
1911
|
+
state: w.stop ? "stopped" : "error",
|
|
1912
|
+
activity: w.stop ? "\u5DF2\u505C\u6B62" : "\u542F\u52A8\u5931\u8D25",
|
|
1873
1913
|
updatedAt: Date.now(),
|
|
1874
|
-
...
|
|
1914
|
+
...existing?.sessionId !== void 0 ? { sessionId: existing.sessionId } : {},
|
|
1915
|
+
...existing?.capabilities ? { capabilities: existing.capabilities } : {},
|
|
1916
|
+
...w.stop ? {} : { error: String(error) }
|
|
1875
1917
|
}, status);
|
|
1876
1918
|
}
|
|
1877
1919
|
throw error;
|
|
@@ -1887,57 +1929,40 @@ var AgentService = class {
|
|
|
1887
1929
|
}
|
|
1888
1930
|
}
|
|
1889
1931
|
send(id, text3, delivery, owner, attachments = []) {
|
|
1890
|
-
const
|
|
1932
|
+
const w = this.get(id, owner);
|
|
1891
1933
|
return this.files.control(() => {
|
|
1892
|
-
|
|
1893
|
-
|
|
1934
|
+
const latest = this.files.worker(id);
|
|
1935
|
+
requireThat(this.alive(id) && this.#starting.get(id)?.stage !== "validate" && !latest.stop, "worker \u5DF2\u505C\u6B62\u6216\u4ECD\u5728\u6062\u590D\u6821\u9A8C\uFF0C\u8BF7\u7B49\u5F85\u663E\u5F0F\u6062\u590D\u5B8C\u6210\u3002");
|
|
1936
|
+
const view = this.view(latest, owner);
|
|
1894
1937
|
requireThat(!(delivery === "steer" && view.state !== "idle"), "\u8BE5 ACP worker \u8FD0\u884C\u4E2D\u4E0D\u652F\u6301 steer\uFF1B\u8BF7\u7528 delivery: followUp \u6392\u961F\u3002");
|
|
1895
1938
|
const files = attachments.map((path) => realpathSync3(resolve6(this.root, path)));
|
|
1896
1939
|
const request = this.files.enqueue(id, text3, delivery, files);
|
|
1897
|
-
return { ...this.view(
|
|
1940
|
+
return { ...this.view(this.files.worker(w.agentId), owner), requestId: request.requestId, messageStatus: "queued" };
|
|
1898
1941
|
});
|
|
1899
1942
|
}
|
|
1900
|
-
rename(id, name, owner) {
|
|
1901
|
-
requireThat(name.trim().length > 0 && name.length <= 64 && !/[\x00-\x1f]/.test(name), "\u540D\u79F0\u5FC5\u987B\u662F 1 \u5230 64 \u5B57\u7B26\u7684\u5355\u884C\u6587\u672C\u3002");
|
|
1902
|
-
const d = this.get(id, owner);
|
|
1903
|
-
this.files.control(() => {
|
|
1904
|
-
const run = this.files.read(id, "launch.json", launch);
|
|
1905
|
-
run.name = name;
|
|
1906
|
-
this.files.write(id, "launch.json", run, launch);
|
|
1907
|
-
});
|
|
1908
|
-
return this.view(d, owner);
|
|
1909
|
-
}
|
|
1910
1943
|
stop(id, owner) {
|
|
1911
|
-
|
|
1944
|
+
this.get(id, owner);
|
|
1912
1945
|
this.requestStop(id);
|
|
1913
|
-
return this.view(
|
|
1946
|
+
return this.view(this.files.worker(id), owner);
|
|
1914
1947
|
}
|
|
1915
1948
|
requestStop(id) {
|
|
1916
1949
|
this.files.control(() => {
|
|
1917
|
-
const
|
|
1918
|
-
|
|
1919
|
-
this.files.write(id, "
|
|
1950
|
+
const w = this.files.worker(id);
|
|
1951
|
+
w.stop = true;
|
|
1952
|
+
this.files.write(id, "worker.json", w, workerRecord);
|
|
1920
1953
|
});
|
|
1921
1954
|
this.#starting.get(id)?.controller.abort();
|
|
1922
1955
|
}
|
|
1923
|
-
async enter(id, owner) {
|
|
1924
|
-
const d = this.get(id, owner);
|
|
1925
|
-
if (this.alive(id)) {
|
|
1926
|
-
requireThat(!this.files.read(id, "launch.json", launch).stop, "worker \u6B63\u5728\u505C\u6B62\uFF0C\u8BF7\u7A0D\u540E\u64CD\u4F5C\u3002");
|
|
1927
|
-
return this.view(d, owner);
|
|
1928
|
-
}
|
|
1929
|
-
return this.restart(id, owner);
|
|
1930
|
-
}
|
|
1931
1956
|
resume(id, text3, owner) {
|
|
1932
1957
|
return this.restart(id, owner, text3);
|
|
1933
1958
|
}
|
|
1934
1959
|
async restart(id, owner, text3) {
|
|
1935
|
-
const
|
|
1960
|
+
const w = this.get(id, owner), d = toDescriptor(w), reference = this.files.reference(id);
|
|
1936
1961
|
this.host.available(reference.backend);
|
|
1937
1962
|
const reserved = this.files.control(() => {
|
|
1938
1963
|
requireThat(!this.alive(id), "worker \u4ECD\u5728\u8FD0\u884C\u3002");
|
|
1939
1964
|
requireThat(this.list(owner).filter((v) => v.alive).length < 50, "\u6700\u591A 50 \u4E2A\u5B58\u6D3B\u6216\u542F\u52A8\u4E2D worker\u3002");
|
|
1940
|
-
const previous = this.files.
|
|
1965
|
+
const previous = this.files.worker(id), interrupted = this.cycles(id, owner);
|
|
1941
1966
|
const pending = { generation: previous.generation, controller: new AbortController(), stage: "validate" };
|
|
1942
1967
|
this.#starting.set(id, pending);
|
|
1943
1968
|
return { previous, interrupted, pending };
|
|
@@ -1947,21 +1972,43 @@ var AgentService = class {
|
|
|
1947
1972
|
requireThat(!this.#closed || this.#preserve, "worker \u670D\u52A1\u5DF2\u5173\u95ED\u3002");
|
|
1948
1973
|
reserved.pending.controller.signal.throwIfAborted();
|
|
1949
1974
|
const prepared = this.files.control(() => {
|
|
1950
|
-
requireThat(!this.host.alive(id) && this.files.
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1975
|
+
requireThat(!this.host.alive(id) && this.files.worker(id).generation === reserved.previous.generation, "worker \u5DF2\u7531\u5176\u4ED6\u64CD\u4F5C\u6062\u590D\u3002");
|
|
1976
|
+
const existingOutput = this.files.output(id);
|
|
1977
|
+
const lastInterrupted = reserved.interrupted.findLast(
|
|
1978
|
+
(ended) => ended.generation === reserved.previous.generation && existingOutput?.cycleId !== ended.cycleId
|
|
1979
|
+
);
|
|
1980
|
+
if (lastInterrupted && lastInterrupted.state !== "running") {
|
|
1981
|
+
this.files.write(id, "output.json", {
|
|
1982
|
+
cycleId: lastInterrupted.cycleId,
|
|
1983
|
+
generation: lastInterrupted.generation,
|
|
1984
|
+
startedAt: lastInterrupted.startedAt,
|
|
1985
|
+
finishedAt: lastInterrupted.finishedAt ?? Date.now(),
|
|
1986
|
+
state: lastInterrupted.state,
|
|
1987
|
+
requestIds: lastInterrupted.requestIds,
|
|
1988
|
+
text: "",
|
|
1989
|
+
...lastInterrupted.error ? { error: lastInterrupted.error } : {}
|
|
1990
|
+
}, outputRecord);
|
|
1955
1991
|
}
|
|
1956
|
-
|
|
1957
|
-
|
|
1992
|
+
this.files.clearTransient(id);
|
|
1993
|
+
const next = {
|
|
1994
|
+
...reserved.previous,
|
|
1995
|
+
generation: randomUUID3(),
|
|
1996
|
+
sequence: 0,
|
|
1997
|
+
stop: false,
|
|
1998
|
+
startedAt: Date.now()
|
|
1999
|
+
};
|
|
2000
|
+
delete next.pid;
|
|
2001
|
+
this.files.write(id, "worker.json", next, workerRecord);
|
|
1958
2002
|
const request = text3 === void 0 ? void 0 : this.files.enqueue(id, text3, "steer");
|
|
1959
|
-
reserved.pending.generation =
|
|
2003
|
+
reserved.pending.generation = next.generation;
|
|
1960
2004
|
reserved.pending.stage = "launch";
|
|
1961
|
-
return { run, request };
|
|
2005
|
+
return { run: next, request };
|
|
1962
2006
|
});
|
|
1963
2007
|
await this.launch(d, prepared.run.generation, true);
|
|
1964
|
-
return {
|
|
2008
|
+
return {
|
|
2009
|
+
...this.view(this.files.worker(id), owner),
|
|
2010
|
+
...prepared.request ? { requestId: prepared.request.requestId, messageStatus: "queued" } : {}
|
|
2011
|
+
};
|
|
1965
2012
|
})();
|
|
1966
2013
|
this.#launches.add(operation);
|
|
1967
2014
|
try {
|
|
@@ -1976,36 +2023,44 @@ var AgentService = class {
|
|
|
1976
2023
|
}
|
|
1977
2024
|
cyclesFor(view) {
|
|
1978
2025
|
const id = view.agentId;
|
|
1979
|
-
const values =
|
|
2026
|
+
const values = [];
|
|
2027
|
+
const output = this.files.output(id);
|
|
2028
|
+
if (output) {
|
|
2029
|
+
values.push({
|
|
2030
|
+
cycleId: output.cycleId,
|
|
2031
|
+
generation: output.generation,
|
|
2032
|
+
startedAt: output.startedAt,
|
|
2033
|
+
finishedAt: output.finishedAt,
|
|
2034
|
+
state: output.state,
|
|
2035
|
+
requestIds: output.requestIds,
|
|
2036
|
+
...output.error ? { error: output.error } : {}
|
|
2037
|
+
});
|
|
2038
|
+
}
|
|
1980
2039
|
if (view.cycle && !values.some((c) => c.cycleId === view.cycle.cycleId)) {
|
|
1981
2040
|
values.push(view.state === "stopped" || view.state === "error" ? { ...view.cycle, state: "interrupted", finishedAt: view.cycle.finishedAt ?? Date.now() } : view.cycle);
|
|
1982
2041
|
}
|
|
1983
2042
|
if (["stopped", "error"].includes(view.state)) {
|
|
1984
|
-
const
|
|
1985
|
-
for (const requestId of saved?.generation ===
|
|
1986
|
-
if (values.some((c) => c.generation ===
|
|
2043
|
+
const w = this.files.worker(id), saved = this.files.optional(id, "state.json", status);
|
|
2044
|
+
for (const requestId of saved?.generation === w.generation ? saved.accepted ?? [] : []) {
|
|
2045
|
+
if (values.some((c) => c.generation === w.generation && c.requestIds.includes(requestId))) continue;
|
|
1987
2046
|
values.push({
|
|
1988
2047
|
cycleId: requestId,
|
|
1989
|
-
generation:
|
|
1990
|
-
startedAt:
|
|
2048
|
+
generation: w.generation,
|
|
2049
|
+
startedAt: w.startedAt,
|
|
1991
2050
|
finishedAt: Date.now(),
|
|
1992
2051
|
state: "interrupted",
|
|
1993
|
-
leaf: null,
|
|
1994
2052
|
requestIds: [requestId],
|
|
1995
|
-
source: "parent",
|
|
1996
2053
|
error: "\u9886\u53D6\u540E\u6267\u884C\u7ED3\u679C\u4E0D\u660E\uFF1B\u672A\u91CD\u8DD1\u3002"
|
|
1997
2054
|
});
|
|
1998
2055
|
}
|
|
1999
|
-
if (
|
|
2056
|
+
if (w.sequence > 0 && !values.some((c) => c.generation === view.generation)) {
|
|
2000
2057
|
values.push({
|
|
2001
|
-
cycleId:
|
|
2002
|
-
generation:
|
|
2003
|
-
startedAt:
|
|
2004
|
-
finishedAt:
|
|
2058
|
+
cycleId: w.generation,
|
|
2059
|
+
generation: w.generation,
|
|
2060
|
+
startedAt: w.startedAt,
|
|
2061
|
+
finishedAt: w.startedAt,
|
|
2005
2062
|
state: "interrupted",
|
|
2006
|
-
leaf: null,
|
|
2007
2063
|
requestIds: [],
|
|
2008
|
-
source: "parent",
|
|
2009
2064
|
error: view.error ?? "\u5B50\u8FDB\u7A0B\u5728\u4EA4\u4ED8\u524D\u9000\u51FA\u3002"
|
|
2010
2065
|
});
|
|
2011
2066
|
}
|
|
@@ -2030,14 +2085,15 @@ var AgentService = class {
|
|
|
2030
2085
|
return { current, cycle: cycle2, terminal };
|
|
2031
2086
|
}
|
|
2032
2087
|
async read(id, owner, cycleId, offset = 0, limit = 16e3) {
|
|
2033
|
-
const
|
|
2088
|
+
const w = this.get(id, owner), cycles = this.cycles(id, owner);
|
|
2034
2089
|
const c = cycleId ? cycles.find((v) => v.cycleId === cycleId) : cycles.at(-1);
|
|
2035
2090
|
requireThat(!cycleId || c, "\u5468\u671F\u4E0D\u5B58\u5728\u3002");
|
|
2036
|
-
const
|
|
2091
|
+
const output = this.files.output(id);
|
|
2092
|
+
const report = c && output?.cycleId === c.cycleId ? output.text : "";
|
|
2037
2093
|
this.check();
|
|
2038
2094
|
requireThat(offset <= report.length, "\u5206\u9875\u4F4D\u7F6E\u8D85\u51FA\u62A5\u544A\u3002");
|
|
2039
2095
|
return {
|
|
2040
|
-
...this.view(
|
|
2096
|
+
...this.view(w, owner),
|
|
2041
2097
|
...c ? { cycle: c } : {},
|
|
2042
2098
|
cycles: cycles.map((v) => ({ cycleId: v.cycleId, state: v.state })),
|
|
2043
2099
|
report: report.slice(offset, offset + limit),
|
|
@@ -2045,16 +2101,15 @@ var AgentService = class {
|
|
|
2045
2101
|
nextOffset: offset + limit < report.length ? offset + limit : null
|
|
2046
2102
|
};
|
|
2047
2103
|
}
|
|
2048
|
-
report(d, c) {
|
|
2049
|
-
if (c.leaf === null) return "";
|
|
2050
|
-
return this.host.report(d, this.files.reference(d.agentId), c.leaf);
|
|
2051
|
-
}
|
|
2052
2104
|
release(id) {
|
|
2053
2105
|
let pending = this.#releasing.get(id);
|
|
2054
2106
|
if (!pending) {
|
|
2055
|
-
const generation = this.files.
|
|
2107
|
+
const generation = this.files.worker(id).generation;
|
|
2056
2108
|
pending = Promise.resolve().then(async () => {
|
|
2057
|
-
if (this.files.
|
|
2109
|
+
if (this.files.worker(id).generation === generation) {
|
|
2110
|
+
await this.host.release(id, generation);
|
|
2111
|
+
this.files.clearTransient(id);
|
|
2112
|
+
}
|
|
2058
2113
|
}).finally(() => this.#releasing.delete(id));
|
|
2059
2114
|
this.#releasing.set(id, pending);
|
|
2060
2115
|
}
|
|
@@ -2065,11 +2120,12 @@ var AgentService = class {
|
|
|
2065
2120
|
}
|
|
2066
2121
|
async dispose(owner, preserve = false) {
|
|
2067
2122
|
if (this.#closed) return;
|
|
2068
|
-
const
|
|
2123
|
+
const ownedRecords = !preserve && owner ? this.records(owner) : [];
|
|
2124
|
+
const aliveIds = ownedRecords.filter((w) => this.alive(w.agentId)).map((w) => w.agentId);
|
|
2069
2125
|
this.#closed = true;
|
|
2070
2126
|
this.#preserve = preserve;
|
|
2071
2127
|
const errors = [];
|
|
2072
|
-
for (const id of
|
|
2128
|
+
for (const id of aliveIds) {
|
|
2073
2129
|
try {
|
|
2074
2130
|
this.requestStop(id);
|
|
2075
2131
|
} catch (error) {
|
|
@@ -2078,18 +2134,29 @@ var AgentService = class {
|
|
|
2078
2134
|
}
|
|
2079
2135
|
if (!preserve) for (const pending of this.#starting.values()) pending.controller.abort();
|
|
2080
2136
|
const deadline = Date.now() + 5e3;
|
|
2081
|
-
while (
|
|
2082
|
-
const released = await Promise.allSettled(
|
|
2137
|
+
while (aliveIds.some((id) => this.alive(id)) && Date.now() < deadline) await new Promise((r) => setTimeout(r, 100));
|
|
2138
|
+
const released = await Promise.allSettled(aliveIds.filter((id) => this.host.alive(id)).map((id) => this.release(id)));
|
|
2083
2139
|
for (const value of released) if (value.status === "rejected") errors.push(value.reason);
|
|
2084
2140
|
await Promise.allSettled([...this.#launches]);
|
|
2141
|
+
if (!preserve && owner) {
|
|
2142
|
+
for (const w of ownedRecords) {
|
|
2143
|
+
if (!this.host.alive(w.agentId)) {
|
|
2144
|
+
try {
|
|
2145
|
+
this.files.removeWorker(w.agentId);
|
|
2146
|
+
} catch (error) {
|
|
2147
|
+
errors.push(error);
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2085
2152
|
if (errors.length) throw new AggregateError(errors, "\u505C\u6B62\u6216\u91CA\u653E worker \u5931\u8D25\uFF1B\u8BF7\u6838\u5BF9\u4ECD\u5B58\u6D3B\u7684\u6267\u884C\u8D44\u6E90\u3002");
|
|
2086
2153
|
}
|
|
2087
2154
|
};
|
|
2088
2155
|
|
|
2089
2156
|
// src/storage/history-files.ts
|
|
2090
2157
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
2091
|
-
import { linkSync as linkSync2, lstatSync as lstatSync3, mkdirSync as mkdirSync4, readdirSync as readdirSync2, readFileSync as readFileSync3, realpathSync as realpathSync4, rmdirSync as
|
|
2092
|
-
import { basename as basename2, dirname as dirname3, join as
|
|
2158
|
+
import { linkSync as linkSync2, lstatSync as lstatSync3, mkdirSync as mkdirSync4, readdirSync as readdirSync2, readFileSync as readFileSync3, realpathSync as realpathSync4, rmdirSync as rmdirSync3, unlinkSync as unlinkSync3 } from "node:fs";
|
|
2159
|
+
import { basename as basename2, dirname as dirname3, join as join8, relative as relative2, resolve as resolve7 } from "node:path";
|
|
2093
2160
|
import { isDeepStrictEqual } from "node:util";
|
|
2094
2161
|
|
|
2095
2162
|
// src/storage/history-format.ts
|
|
@@ -2234,7 +2301,7 @@ function bucketDirs(directory, depth) {
|
|
|
2234
2301
|
buckets.push(...years);
|
|
2235
2302
|
} else {
|
|
2236
2303
|
for (const year of years) {
|
|
2237
|
-
const yearDir =
|
|
2304
|
+
const yearDir = join8(directory, year);
|
|
2238
2305
|
const months = readdirSync2(yearDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.isSymbolicLink() && monthPattern.test(entry.name)).map((entry) => entry.name).sort((a, b) => b.localeCompare(a));
|
|
2239
2306
|
for (const month of months) buckets.push(`${year}/${month}`);
|
|
2240
2307
|
}
|
|
@@ -2249,7 +2316,7 @@ function listLayoutJsonFiles(directory, layout, depth = "month") {
|
|
|
2249
2316
|
if (layout === "flat") return topLevelJsonNames(directory);
|
|
2250
2317
|
const results = [];
|
|
2251
2318
|
for (const bucket of bucketDirs(directory, depth)) {
|
|
2252
|
-
const dir =
|
|
2319
|
+
const dir = join8(directory, bucket);
|
|
2253
2320
|
for (const name of topLevelJsonNames(dir)) {
|
|
2254
2321
|
results.push(`${bucket}/${name}`);
|
|
2255
2322
|
}
|
|
@@ -2259,10 +2326,10 @@ function listLayoutJsonFiles(directory, layout, depth = "month") {
|
|
|
2259
2326
|
function locateLayoutFile(directory, name, layout, depth = "month") {
|
|
2260
2327
|
if (!ordinaryDirectory(directory)) return void 0;
|
|
2261
2328
|
if (layout === "flat") {
|
|
2262
|
-
return ordinaryFile(
|
|
2329
|
+
return ordinaryFile(join8(directory, name)) ? name : void 0;
|
|
2263
2330
|
}
|
|
2264
2331
|
for (const bucket of bucketDirs(directory, depth)) {
|
|
2265
|
-
if (ordinaryFile(
|
|
2332
|
+
if (ordinaryFile(join8(directory, bucket, name))) return `${bucket}/${name}`;
|
|
2266
2333
|
}
|
|
2267
2334
|
return void 0;
|
|
2268
2335
|
}
|
|
@@ -2329,7 +2396,7 @@ function findCandidateJsonFiles(directory, query, layout = "monthly", depth = "m
|
|
|
2329
2396
|
const matched = [];
|
|
2330
2397
|
for (const rel of listLayoutJsonFiles(directory, layout, depth)) {
|
|
2331
2398
|
try {
|
|
2332
|
-
const content = readFileSync3(
|
|
2399
|
+
const content = readFileSync3(join8(directory, rel), "utf8");
|
|
2333
2400
|
if (content.toLowerCase().includes(needle)) matched.push(rel);
|
|
2334
2401
|
} catch {
|
|
2335
2402
|
}
|
|
@@ -2352,18 +2419,18 @@ var HistoryFiles = class {
|
|
|
2352
2419
|
return this.#rawWarnings;
|
|
2353
2420
|
}
|
|
2354
2421
|
get rawDirectory() {
|
|
2355
|
-
return
|
|
2422
|
+
return join8(this.directory, "raw");
|
|
2356
2423
|
}
|
|
2357
2424
|
get summariesDirectory() {
|
|
2358
|
-
return
|
|
2425
|
+
return join8(this.directory, "summaries");
|
|
2359
2426
|
}
|
|
2360
2427
|
summaryDirectory(dimension) {
|
|
2361
2428
|
requireThat(isHistoryIdentifier(dimension), "\u5386\u53F2\u6458\u8981\u7EF4\u5EA6\u65E0\u6548\uFF1A" + dimension);
|
|
2362
|
-
return
|
|
2429
|
+
return join8(this.summariesDirectory, dimension);
|
|
2363
2430
|
}
|
|
2364
2431
|
withLock(lockName, label, operation) {
|
|
2365
2432
|
ensureDirectory(this.directory);
|
|
2366
|
-
const lock =
|
|
2433
|
+
const lock = join8(this.directory, lockName);
|
|
2367
2434
|
try {
|
|
2368
2435
|
mkdirSync4(lock, { mode: 448 });
|
|
2369
2436
|
} catch (error) {
|
|
@@ -2375,7 +2442,7 @@ var HistoryFiles = class {
|
|
|
2375
2442
|
try {
|
|
2376
2443
|
return operation();
|
|
2377
2444
|
} finally {
|
|
2378
|
-
|
|
2445
|
+
rmdirSync3(lock);
|
|
2379
2446
|
}
|
|
2380
2447
|
}
|
|
2381
2448
|
/** Synchronous host write lock for raw history files. */
|
|
@@ -2409,7 +2476,7 @@ var HistoryFiles = class {
|
|
|
2409
2476
|
rawCount,
|
|
2410
2477
|
summaryCount,
|
|
2411
2478
|
total,
|
|
2412
|
-
message: `\
|
|
2479
|
+
message: `\u5F53\u524D\u6309\u5E74\u6708\u8BFB\u53D6\u5386\u53F2\uFF0C\u5E73\u94FA\u76EE\u5F55\u4E2D\u7684 ${rawCount} \u4EFD\u539F\u6587\u548C ${summaryCount} \u4EFD\u6458\u8981\u5C1A\u672A\u7EB3\u5165\u68C0\u7D22\u3002\u53EF\u5728\u5DE5\u4F5C\u533A\u6839\u76EE\u5F55\u7528 pbot history migrate --dry-run \u9884\u89C8\uFF0C\u7528 pbot history migrate \u6267\u884C\uFF08Pi\u3001dsh \u53EF\u7528 /pbot history migrate\uFF09\u3002\u8981\u7EE7\u7EED\u4F7F\u7528\u5E73\u94FA\u76EE\u5F55\uFF0C\u53EF\u5728 .pbot/config.json \u4E2D\u8BBE\u7F6E "history": { "layout": "flat" }\u3002`
|
|
2413
2480
|
};
|
|
2414
2481
|
}
|
|
2415
2482
|
listFlatRawFiles() {
|
|
@@ -2448,7 +2515,7 @@ var HistoryFiles = class {
|
|
|
2448
2515
|
throw error;
|
|
2449
2516
|
}
|
|
2450
2517
|
syncDirectory(dirname3(dst));
|
|
2451
|
-
|
|
2518
|
+
unlinkSync3(src);
|
|
2452
2519
|
syncDirectory(dirname3(src));
|
|
2453
2520
|
return "moved";
|
|
2454
2521
|
}
|
|
@@ -2459,7 +2526,7 @@ var HistoryFiles = class {
|
|
|
2459
2526
|
const files = onlyFiles ?? listLayoutJsonFiles(this.rawDirectory, this.layout);
|
|
2460
2527
|
const results = [];
|
|
2461
2528
|
for (const rel of files) {
|
|
2462
|
-
const path =
|
|
2529
|
+
const path = join8(this.rawDirectory, rel);
|
|
2463
2530
|
try {
|
|
2464
2531
|
const raw = readJsonFile(this.directory, "raw/" + rel, (value) => namedRaw(value, rel));
|
|
2465
2532
|
if (filterHost !== void 0 && raw.host !== filterHost) continue;
|
|
@@ -2513,7 +2580,7 @@ var HistoryFiles = class {
|
|
|
2513
2580
|
const files = onlyFiles ?? listLayoutJsonFiles(dir, this.layout, this.summaryBucketDepth(dimension));
|
|
2514
2581
|
const results = [];
|
|
2515
2582
|
for (const rel of files) {
|
|
2516
|
-
const path =
|
|
2583
|
+
const path = join8(dir, rel);
|
|
2517
2584
|
try {
|
|
2518
2585
|
results.push(readJsonFile(this.directory, `summaries/${dimension}/${rel}`, (value) => namedSummary(value, rel, dimension)));
|
|
2519
2586
|
} catch (error) {
|
|
@@ -2564,12 +2631,12 @@ var HistoryFiles = class {
|
|
|
2564
2631
|
};
|
|
2565
2632
|
|
|
2566
2633
|
// src/services/history/workspace-history.ts
|
|
2567
|
-
import { join as
|
|
2634
|
+
import { join as join10 } from "node:path";
|
|
2568
2635
|
|
|
2569
2636
|
// src/services/workspace/workspace-config.ts
|
|
2570
2637
|
import { readFileSync as readFileSync4 } from "node:fs";
|
|
2571
2638
|
import { mkdir, readFile as readFile2 } from "node:fs/promises";
|
|
2572
|
-
import { dirname as dirname4, join as
|
|
2639
|
+
import { dirname as dirname4, join as join9 } from "node:path";
|
|
2573
2640
|
|
|
2574
2641
|
// src/model/workspace-config.ts
|
|
2575
2642
|
var summaryConcurrency = { default: 3, max: 8 };
|
|
@@ -2596,8 +2663,8 @@ function config(value) {
|
|
|
2596
2663
|
throw new Error("acp \u952E\u540D\u5FC5\u987B\u4E3A\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26\uFF081\u201364 \u5B57\u7B26\uFF09\u3002");
|
|
2597
2664
|
}
|
|
2598
2665
|
for (const command of Object.values(value.acp)) {
|
|
2599
|
-
const
|
|
2600
|
-
if (!object(command) || !
|
|
2666
|
+
const launch = !object(command) ? false : command.command === void 0 ? command.args === void 0 : typeof command.command === "string" && command.command.trim() && !command.command.includes("\0") && (command.args === void 0 || Array.isArray(command.args) && command.args.every((arg) => typeof arg === "string" && !arg.includes("\0")));
|
|
2667
|
+
if (!object(command) || !launch || command.env !== void 0 && (!object(command.env) || Object.entries(command.env).some(([k, v]) => !k || k.includes("\0") || typeof v !== "string" || v.includes("\0"))) || command.permission !== void 0 && !isOneOf(command.permission, acpPermissionPolicies) || Object.keys(command).some((key) => !["command", "args", "env", "permission"].includes(key))) {
|
|
2601
2668
|
throw new Error("ACP \u914D\u7F6E\u9700\u8981 command\uFF08\u5185\u7F6E\u76EE\u6807\u53EF\u7701\u7565\uFF09\u53CA\u53EF\u9009 args \u5B57\u7B26\u4E32\u6570\u7EC4\u3001env \u5B57\u7B26\u4E32\u6620\u5C04\u3001permission\uFF08ask\u3001allow \u6216 deny\uFF09\u3002");
|
|
2602
2669
|
}
|
|
2603
2670
|
}
|
|
@@ -2645,7 +2712,7 @@ function workspaceHistoryConfig(configuration) {
|
|
|
2645
2712
|
};
|
|
2646
2713
|
}
|
|
2647
2714
|
function workspaceConfigPath(root) {
|
|
2648
|
-
return
|
|
2715
|
+
return join9(root, ".pbot", "config.json");
|
|
2649
2716
|
}
|
|
2650
2717
|
function readWorkspaceHistoryLayoutSync(root) {
|
|
2651
2718
|
const path = workspaceConfigPath(root);
|
|
@@ -2688,7 +2755,7 @@ function workspaceDisabledMessage(configuration) {
|
|
|
2688
2755
|
|
|
2689
2756
|
// src/services/history/workspace-history.ts
|
|
2690
2757
|
function workspaceHistoryFiles(root, host) {
|
|
2691
|
-
return new HistoryFiles(
|
|
2758
|
+
return new HistoryFiles(join10(root, ".pbot/history"), host, readWorkspaceHistoryLayoutSync(root));
|
|
2692
2759
|
}
|
|
2693
2760
|
|
|
2694
2761
|
// src/services/history/history-index.ts
|
|
@@ -3032,7 +3099,7 @@ import { setTimeout as delay2 } from "node:timers/promises";
|
|
|
3032
3099
|
|
|
3033
3100
|
// src/services/workspace/workspace-mcp.ts
|
|
3034
3101
|
import { mkdir as mkdir2, readFile as readFile3 } from "node:fs/promises";
|
|
3035
|
-
import { dirname as dirname5, join as
|
|
3102
|
+
import { dirname as dirname5, join as join11, resolve as resolve8 } from "node:path";
|
|
3036
3103
|
var serverNamePattern = /^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$/;
|
|
3037
3104
|
var reservedServerNames = /* @__PURE__ */ new Set(["pbot"]);
|
|
3038
3105
|
var stdioKeys = /* @__PURE__ */ new Set(["command", "args", "env", "cwd", "description", "timeout", "enabled"]);
|
|
@@ -3142,7 +3209,7 @@ function validateMcpFile(value) {
|
|
|
3142
3209
|
return { ...value, mcpServers: servers };
|
|
3143
3210
|
}
|
|
3144
3211
|
function workspaceMcpPath(root) {
|
|
3145
|
-
return
|
|
3212
|
+
return join11(root, ".pbot", "mcp.json");
|
|
3146
3213
|
}
|
|
3147
3214
|
async function readWorkspaceMcpConfig(root) {
|
|
3148
3215
|
const path = workspaceMcpPath(root);
|
|
@@ -3560,21 +3627,20 @@ var protocolVersion2 = "2025-03-26";
|
|
|
3560
3627
|
var readyTimeoutMs = 45e3;
|
|
3561
3628
|
var reportPageSize = 16e3;
|
|
3562
3629
|
var progressIntervalMs = 5e3;
|
|
3563
|
-
var workerCapabilityInstruction = "\
|
|
3564
|
-
var workspaceMcpCapabilityInstruction = "\
|
|
3565
|
-
var historyCapabilityInstruction = "\
|
|
3630
|
+
var workerCapabilityInstruction = "\u7528\u6237\u6216\u5DE5\u4F5C\u533A\u5206\u5DE5\u6307\u5B9A\u5176\u4ED6\u52A9\u624B\u6216\u7279\u5B9A\u6A21\u578B\u65F6\uFF0C\u53EF\u5728\u5F53\u524D\u5DE5\u4F5C\u533A\u59D4\u6D3E\u4EFB\u52A1\u3002\u5E38\u89C4\u4EFB\u52A1\u4F18\u5148\u81EA\u884C\u5904\u7406\u6216\u4F7F\u7528\u5BBF\u4E3B\u5185\u7F6E\u5B50\u4EE3\u7406\u3002";
|
|
3631
|
+
var workspaceMcpCapabilityInstruction = "\u53EF\u8C03\u7528\u672C\u5DE5\u4F5C\u533A .pbot/mcp.json \u4E2D\u767B\u8BB0\u7684 MCP \u5DE5\u5177\u3002";
|
|
3632
|
+
var historyCapabilityInstruction = "\u53EF\u68C0\u7D22\u672C\u5DE5\u4F5C\u533A\u5404\u5BBF\u4E3B\u5F52\u6863\u7684\u95EE\u7B54\u548C\u6458\u8981\u3002";
|
|
3566
3633
|
function buildMcpInstructions(options) {
|
|
3567
3634
|
const parts = [workerCapabilityInstruction];
|
|
3568
3635
|
if (options.workspaceMcp) parts.push(workspaceMcpCapabilityInstruction);
|
|
3569
3636
|
if (options.history) parts.push(historyCapabilityInstruction);
|
|
3570
|
-
return parts.
|
|
3637
|
+
return parts.join("\n");
|
|
3571
3638
|
}
|
|
3572
3639
|
var mcpWorkerOnlyInstructions = buildMcpInstructions({ workspaceMcp: false, history: false });
|
|
3573
3640
|
var mcpInstructions = buildMcpInstructions({ workspaceMcp: true, history: true });
|
|
3574
|
-
function defaultWorkerDirectory() {
|
|
3641
|
+
function defaultWorkerDirectory(workspaceRoot) {
|
|
3575
3642
|
if (process.env.PBOT_MCP_AGENT_DIR) return process.env.PBOT_MCP_AGENT_DIR;
|
|
3576
|
-
|
|
3577
|
-
return join13(homedir(), ".pbot/subagents");
|
|
3643
|
+
return join12(workspaceRoot, ".pbot", "subagents");
|
|
3578
3644
|
}
|
|
3579
3645
|
function asString(args, key, required = false) {
|
|
3580
3646
|
const value = args[key];
|
|
@@ -3633,6 +3699,7 @@ function presentWorker(value) {
|
|
|
3633
3699
|
}
|
|
3634
3700
|
var McpWorkerRuntime = class {
|
|
3635
3701
|
#services = /* @__PURE__ */ new Map();
|
|
3702
|
+
#workerWorkspaces = /* @__PURE__ */ new Map();
|
|
3636
3703
|
#bridge = new WorkspaceMcpBridge();
|
|
3637
3704
|
#sessionId;
|
|
3638
3705
|
#directory;
|
|
@@ -3640,7 +3707,7 @@ var McpWorkerRuntime = class {
|
|
|
3640
3707
|
#nativeWorkspaceMcp;
|
|
3641
3708
|
#nativeHistory;
|
|
3642
3709
|
#closing;
|
|
3643
|
-
constructor(directory
|
|
3710
|
+
constructor(directory, sessionId = process.env.PBOT_MCP_SESSION_ID || "mcp-" + randomUUID4(), defaultBackend = process.env.PBOT_HOST || void 0, nativeWorkspaceMcp = /^(1|true)$/i.test(process.env.PBOT_NATIVE_WORKSPACE_MCP ?? ""), nativeHistory = /^(1|true)$/i.test(process.env.PBOT_NATIVE_HISTORY ?? "")) {
|
|
3644
3711
|
this.#directory = directory;
|
|
3645
3712
|
this.#sessionId = sessionId;
|
|
3646
3713
|
this.#defaultBackend = defaultBackend?.trim() || void 0;
|
|
@@ -3649,7 +3716,7 @@ var McpWorkerRuntime = class {
|
|
|
3649
3716
|
}
|
|
3650
3717
|
/** Mount the stdio sibling with the same worker ownership as the native host command. */
|
|
3651
3718
|
nativeServer(root) {
|
|
3652
|
-
const entry =
|
|
3719
|
+
const entry = join12(resourceRoot, "../lib/extension/mcp.js");
|
|
3653
3720
|
if (!existsSync3(entry)) return void 0;
|
|
3654
3721
|
requireThat(this.#defaultBackend, "\u539F\u751F MCP \u6302\u8F7D\u9700\u8981\u5BBF\u4E3B\u540D\u79F0\u3002");
|
|
3655
3722
|
return {
|
|
@@ -3658,7 +3725,7 @@ var McpWorkerRuntime = class {
|
|
|
3658
3725
|
env: {
|
|
3659
3726
|
PBOT_HOST: this.#defaultBackend,
|
|
3660
3727
|
PBOT_WORKSPACE_ROOT: root,
|
|
3661
|
-
PBOT_MCP_AGENT_DIR: this.#directory,
|
|
3728
|
+
PBOT_MCP_AGENT_DIR: this.#directory ?? defaultWorkerDirectory(root),
|
|
3662
3729
|
PBOT_MCP_SESSION_ID: this.#sessionId,
|
|
3663
3730
|
PBOT_NATIVE_WORKSPACE_MCP: "1",
|
|
3664
3731
|
PBOT_NATIVE_HISTORY: "1"
|
|
@@ -3685,13 +3752,25 @@ var McpWorkerRuntime = class {
|
|
|
3685
3752
|
requireThat((await stat3(root)).isDirectory(), "\u5DE5\u4F5C\u533A\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\u3002");
|
|
3686
3753
|
return root;
|
|
3687
3754
|
}
|
|
3755
|
+
async resolveWorkerWorkspace(workerId, defaultWorkspace) {
|
|
3756
|
+
const known = this.#workerWorkspaces.get(workerId);
|
|
3757
|
+
if (known) return known;
|
|
3758
|
+
for (const [root, entry] of this.#services) {
|
|
3759
|
+
if (entry.service.has(workerId, entry.owner)) {
|
|
3760
|
+
this.#workerWorkspaces.set(workerId, root);
|
|
3761
|
+
return root;
|
|
3762
|
+
}
|
|
3763
|
+
}
|
|
3764
|
+
return this.resolveWorkspace(defaultWorkspace);
|
|
3765
|
+
}
|
|
3688
3766
|
workerService(root, commands = {}) {
|
|
3689
3767
|
let entry = this.#services.get(root);
|
|
3690
3768
|
if (!entry) {
|
|
3691
|
-
const
|
|
3769
|
+
const directory = this.#directory ?? defaultWorkerDirectory(root);
|
|
3770
|
+
const host = new AcpWorkerHost(directory, commands);
|
|
3692
3771
|
entry = {
|
|
3693
3772
|
host,
|
|
3694
|
-
service: new AgentService(root,
|
|
3773
|
+
service: new AgentService(root, directory, host),
|
|
3695
3774
|
owner: { sessionId: this.#sessionId, leaf: null, branch: [] }
|
|
3696
3775
|
};
|
|
3697
3776
|
this.#services.set(root, entry);
|
|
@@ -3793,17 +3872,18 @@ var McpWorkerRuntime = class {
|
|
|
3793
3872
|
await delay3(100);
|
|
3794
3873
|
}
|
|
3795
3874
|
}
|
|
3796
|
-
async callTool(toolName, input, progress) {
|
|
3875
|
+
async callTool(toolName, input, progress, defaultWorkspace) {
|
|
3797
3876
|
const { name, args: rawArgs } = parseMcpToolCall(toolName, input);
|
|
3798
3877
|
requireThat(!this.#closing, "Personal Bot MCP \u670D\u52A1\u5DF2\u5173\u95ED\u3002");
|
|
3799
|
-
const
|
|
3878
|
+
const isWorkerScoped = name === "worker_close" || name === "worker_request" || name === "worker_response" || name === "worker_output";
|
|
3879
|
+
const root = isWorkerScoped ? await this.resolveWorkerWorkspace(asString(rawArgs, "workerId", true), defaultWorkspace) : await this.resolveWorkspace(asString(rawArgs, "workspace") ?? defaultWorkspace);
|
|
3800
3880
|
const configuration = await readWorkspaceConfig(root);
|
|
3801
3881
|
requireThat(!this.#closing, "Personal Bot MCP \u670D\u52A1\u5DF2\u5173\u95ED\u3002");
|
|
3802
3882
|
requireThat(configuration.enabled, workspaceDisabledMessage(configuration));
|
|
3803
3883
|
switch (name) {
|
|
3804
3884
|
case "workspace_mcp_discover":
|
|
3805
3885
|
case "workspace_mcp_call": {
|
|
3806
|
-
requireThat(!this.#nativeWorkspaceMcp, "\u5F53\u524D\u5BBF\u4E3B\u5DF2\u539F\u751F\u6302\u8F7D\u5DE5\u4F5C\u533A
|
|
3886
|
+
requireThat(!this.#nativeWorkspaceMcp, "\u5F53\u524D\u5BBF\u4E3B\u5DF2\u539F\u751F\u6302\u8F7D\u5DE5\u4F5C\u533A MCP \u670D\u52A1\uFF0C\u8BF7\u76F4\u63A5\u8C03\u7528\u5BF9\u5E94\u5DE5\u5177\u3002");
|
|
3807
3887
|
requireThat(workspaceFeatures(configuration).mcp, `\u5DE5\u4F5C\u533A\u7EDF\u4E00 MCP \u529F\u80FD\u5DF2\u5728 ${configuration.path} \u4E2D\u505C\u7528\uFF08features.mcp: false\uFF09\u3002`);
|
|
3808
3888
|
if (name === "workspace_mcp_discover") return this.#bridge.discover(root, asString(rawArgs, "server"));
|
|
3809
3889
|
const server = asString(rawArgs, "server", true);
|
|
@@ -3854,13 +3934,12 @@ var McpWorkerRuntime = class {
|
|
|
3854
3934
|
const backend = this.resolveBackend(rawArgs, configuration.acp, false);
|
|
3855
3935
|
const model = asString(rawArgs, "model");
|
|
3856
3936
|
const thinking = asString(rawArgs, "thinking");
|
|
3857
|
-
const cwd = asString(rawArgs, "cwd");
|
|
3858
3937
|
const created = await service.start({
|
|
3859
3938
|
backend,
|
|
3860
3939
|
...model ? { model } : {},
|
|
3861
|
-
...thinking ? { thinking } : {}
|
|
3862
|
-
...cwd ? { cwd } : {}
|
|
3940
|
+
...thinking ? { thinking } : {}
|
|
3863
3941
|
}, owner);
|
|
3942
|
+
this.#workerWorkspaces.set(created.agentId, root);
|
|
3864
3943
|
const ready = await this.waitReady(service, owner, created.agentId, readyTimeoutMs, progress);
|
|
3865
3944
|
return {
|
|
3866
3945
|
...presentWorker(ready),
|
|
@@ -3935,19 +4014,23 @@ var McpWorkerRuntime = class {
|
|
|
3935
4014
|
requireThat(backendRaw === void 0 && model === void 0, '\u53C2\u6570 backend / model \u4EC5\u5728 target="models" \u65F6\u53EF\u7528\u3002');
|
|
3936
4015
|
}
|
|
3937
4016
|
if (target === "overview") {
|
|
4017
|
+
const workers = service.list(owner);
|
|
4018
|
+
for (const item of workers) this.#workerWorkspaces.set(item.agentId, root);
|
|
3938
4019
|
return {
|
|
3939
4020
|
target,
|
|
3940
4021
|
backends: inspectAcpBackends(configuration.acp),
|
|
3941
|
-
workers:
|
|
4022
|
+
workers: workers.map(presentWorker)
|
|
3942
4023
|
};
|
|
3943
4024
|
}
|
|
3944
4025
|
if (target === "backends") {
|
|
3945
4026
|
return { target, backends: inspectAcpBackends(configuration.acp) };
|
|
3946
4027
|
}
|
|
3947
4028
|
if (target === "workers") {
|
|
4029
|
+
const workers = workerId ? [service.status(workerId, owner)] : service.list(owner);
|
|
4030
|
+
for (const item of workers) this.#workerWorkspaces.set(item.agentId, root);
|
|
3948
4031
|
return {
|
|
3949
4032
|
target,
|
|
3950
|
-
workers:
|
|
4033
|
+
workers: workers.map(presentWorker)
|
|
3951
4034
|
};
|
|
3952
4035
|
}
|
|
3953
4036
|
const backend = this.resolveBackend(rawArgs, configuration.acp, true);
|
|
@@ -3963,6 +4046,7 @@ var McpWorkerRuntime = class {
|
|
|
3963
4046
|
if (this.#closing) return this.#closing;
|
|
3964
4047
|
const entries = [...this.#services.values()];
|
|
3965
4048
|
this.#services.clear();
|
|
4049
|
+
this.#workerWorkspaces.clear();
|
|
3966
4050
|
this.#closing = Promise.allSettled([
|
|
3967
4051
|
this.#bridge.close(),
|
|
3968
4052
|
...entries.map(({ service, owner }) => service.close(owner, preserve))
|