personal-bot 0.3.7 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- 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 +1 -1
- package/docs/guides/cross-harness-workers.md +4 -4
- package/docs/guides/history.md +1 -3
- package/docs/guides/workspace-configuration.md +4 -4
- package/docs/hosts/claude-code.md +2 -2
- package/docs/hosts/codex-qoder.md +1 -1
- 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 +346 -201
- package/lib/antigravity-plugin/lib/extension/cli.js +563 -538
- 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 +0 -11
- package/lib/antigravity-plugin/lib/extension/mcp.js +397 -278
- 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/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/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +1 -1
- package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +1 -1
- 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 +1 -1
- 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 +346 -201
- package/lib/extension/cli.js +563 -538
- package/lib/extension/hosts/dsh/acp-member.js +1 -1
- package/lib/extension/hosts/dsh/command.js +1 -1
- package/lib/extension/hosts/dsh/workspace.js +1 -3
- package/lib/extension/hosts/pi/acp-member.js +3 -4
- package/lib/extension/hosts/plugin-runtime.js +0 -11
- package/lib/extension/mcp/tool-contract.d.ts +8 -50
- package/lib/extension/mcp/tool-contract.js +0 -8
- package/lib/extension/mcp/workers.d.ts +7 -27
- package/lib/extension/mcp/workers.js +35 -17
- package/lib/extension/mcp.js +397 -278
- 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/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 +1 -1
- package/lib/qoder-plugin/hooks/hooks.json +3 -3
- package/lib/qoder-plugin/skills/pbot/SKILL.md +1 -1
- 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 +180 -126
- 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/package.json +1 -1
- package/src/extension/acp/member.ts +14 -11
- package/src/extension/acp/worker.ts +31 -28
- 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 +1 -1
- package/src/extension/hosts/dsh/workspace.ts +1 -3
- package/src/extension/hosts/pi/acp-member.ts +3 -4
- package/src/extension/hosts/pi/command.ts +1 -1
- package/src/extension/hosts/pi/lifecycle.ts +0 -2
- package/src/extension/hosts/plugin-runtime.ts +0 -10
- package/src/extension/mcp/tool-contract.ts +0 -8
- package/src/extension/mcp/workers.ts +34 -17
- package/src/integrations/acp/agents.ts +28 -27
- package/src/integrations/acp/harnesses/claude.ts +1 -1
- package/src/integrations/hosts/dsh/session.ts +2 -2
- 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 +1 -1
- 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 +204 -133
- 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/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
|
@@ -9,7 +9,7 @@ import { randomUUID as randomUUID5 } from "node:crypto";
|
|
|
9
9
|
import { dirname as dirname4, join as join11, resolve as resolve6 } from "node:path";
|
|
10
10
|
|
|
11
11
|
// src/storage/agent-files.ts
|
|
12
|
-
import { existsSync, mkdirSync as mkdirSync3, readdirSync, rmSync } from "node:fs";
|
|
12
|
+
import { existsSync, mkdirSync as mkdirSync3, readdirSync, rmdirSync as rmdirSync2, rmSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
13
13
|
import { join as join3 } from "node:path";
|
|
14
14
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
15
15
|
|
|
@@ -161,7 +161,6 @@ function privateDirectory(root, relative) {
|
|
|
161
161
|
// src/model/agent.ts
|
|
162
162
|
var messageDeliveries = ["steer", "followUp"];
|
|
163
163
|
var cycleStates = ["running", "completed", "failed", "cancelled", "interrupted"];
|
|
164
|
-
var cycleSources = ["parent", "interactive", "mixed"];
|
|
165
164
|
var agentStates = ["starting", "busy", "idle", "stopping", "stopped", "error"];
|
|
166
165
|
|
|
167
166
|
// src/storage/acp-files.ts
|
|
@@ -177,18 +176,21 @@ function isAcpElicitationValue(value) {
|
|
|
177
176
|
|
|
178
177
|
// src/storage/acp-files.ts
|
|
179
178
|
var text = (value) => typeof value === "string" && value.length > 0 && !value.includes("\0");
|
|
180
|
-
function
|
|
181
|
-
requireThat(object(value) &&
|
|
179
|
+
function acpConfig(value) {
|
|
180
|
+
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");
|
|
182
181
|
if (value.env !== void 0) {
|
|
183
182
|
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");
|
|
184
183
|
}
|
|
185
184
|
requireThat(value.permission === void 0 || isOneOf(value.permission, acpPermissionPolicies), "ACP \u6743\u9650\u7B56\u7565\u65E0\u6548\u3002");
|
|
186
|
-
const capabilities = value.capabilities;
|
|
187
|
-
if (capabilities !== void 0) requireThat(object(capabilities) && ["resume", "load", "close"].every((key) => typeof capabilities[key] === "boolean"), "ACP \u4F1A\u8BDD\u80FD\u529B\u65E0\u6548\u3002");
|
|
188
185
|
return value;
|
|
189
186
|
}
|
|
190
|
-
function
|
|
191
|
-
requireThat(object(value) &&
|
|
187
|
+
function acpReference(value) {
|
|
188
|
+
requireThat(object(value) && value.host === "acp" && (value.sessionId === null || text(value.sessionId)), "ACP \u4F1A\u8BDD\u5F15\u7528\u65E0\u6548\u3002");
|
|
189
|
+
acpConfig(value);
|
|
190
|
+
const capabilities = value.capabilities;
|
|
191
|
+
if (capabilities !== void 0) {
|
|
192
|
+
requireThat(object(capabilities) && ["resume", "load", "close"].every((key) => typeof capabilities[key] === "boolean"), "ACP \u4F1A\u8BDD\u80FD\u529B\u65E0\u6548\u3002");
|
|
193
|
+
}
|
|
192
194
|
return value;
|
|
193
195
|
}
|
|
194
196
|
function acpInput(value) {
|
|
@@ -201,50 +203,45 @@ function acpAnswer(value) {
|
|
|
201
203
|
requireThat(object(value) && typeof value.answer === "string" && isOneOf(value.state, acpAnswerStates) && (value.error === void 0 || typeof value.error === "string"), "ACP \u6700\u7EC8\u56DE\u7B54\u65E0\u6548\u3002");
|
|
202
204
|
return value;
|
|
203
205
|
}
|
|
204
|
-
function
|
|
205
|
-
requireThat(object(value) && text(value.generation) && text(value.cycleId) && typeof value.text === "string", "ACP \u5468\u671F\u62A5\u544A\u65E0\u6548\u3002");
|
|
206
|
-
fileId(value.cycleId);
|
|
207
|
-
return value;
|
|
208
|
-
}
|
|
209
|
-
function acpPermission(value) {
|
|
210
|
-
acpInput(value);
|
|
211
|
-
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");
|
|
212
|
-
return value;
|
|
213
|
-
}
|
|
214
|
-
function acpPermissionReply(value) {
|
|
206
|
+
function acpInteraction(value) {
|
|
215
207
|
acpInput(value);
|
|
216
|
-
requireThat(object(value)
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
acpInput(value);
|
|
221
|
-
requireThat(object(value) && (value.mode === "form" || value.mode === "url") && typeof value.message === "string", "ACP \u4EA4\u4E92\u8BF7\u6C42\u65E0\u6548\u3002");
|
|
222
|
-
if (value.mode === "form") {
|
|
223
|
-
requireThat(object(value.schema) && value.url === void 0, "ACP \u8868\u5355\u4EA4\u4E92\u8BF7\u6C42\u7F3A\u5C11\u6709\u6548 schema\u3002");
|
|
224
|
-
} else {
|
|
225
|
-
requireThat(text(value.url) && value.schema === void 0, "ACP URL \u4EA4\u4E92\u8BF7\u6C42\u7F3A\u5C11\u6709\u6548 url\u3002");
|
|
208
|
+
requireThat(object(value), "ACP \u4EA4\u4E92\u8BF7\u6C42\u65E0\u6548\u3002");
|
|
209
|
+
if (value.kind === "permission") {
|
|
210
|
+
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");
|
|
211
|
+
return value;
|
|
226
212
|
}
|
|
213
|
+
if (value.kind === "form") {
|
|
214
|
+
requireThat(typeof value.message === "string" && object(value.schema), "ACP \u8868\u5355\u4EA4\u4E92\u8BF7\u6C42\u7F3A\u5C11\u6709\u6548 schema\u3002");
|
|
215
|
+
return value;
|
|
216
|
+
}
|
|
217
|
+
requireThat(value.kind === "url" && typeof value.message === "string" && text(value.url), "ACP URL \u4EA4\u4E92\u8BF7\u6C42\u65E0\u6548\u3002");
|
|
227
218
|
return value;
|
|
228
219
|
}
|
|
229
|
-
function
|
|
220
|
+
function acpInteractionReply(value) {
|
|
230
221
|
acpInput(value);
|
|
231
|
-
requireThat(object(value)
|
|
232
|
-
if (value.
|
|
233
|
-
requireThat(value.
|
|
222
|
+
requireThat(object(value), "ACP \u4EA4\u4E92\u7B54\u590D\u65E0\u6548\u3002");
|
|
223
|
+
if (value.kind === "permission") {
|
|
224
|
+
requireThat(value.optionId === null || text(value.optionId), "ACP \u786E\u8BA4\u7B54\u590D\u65E0\u6548\u3002");
|
|
225
|
+
return value;
|
|
234
226
|
}
|
|
227
|
+
if (value.kind === "form") {
|
|
228
|
+
requireThat(isOneOf(value.action, acpElicitationActions), "ACP \u8868\u5355\u7B54\u590D action \u65E0\u6548\u3002");
|
|
229
|
+
if (value.content !== void 0) {
|
|
230
|
+
requireThat(value.action === "accept" && object(value.content) && Object.values(value.content).every(isAcpElicitationValue), "ACP \u8868\u5355\u7B54\u590D content \u65E0\u6548\u3002");
|
|
231
|
+
}
|
|
232
|
+
return value;
|
|
233
|
+
}
|
|
234
|
+
requireThat(value.kind === "url" && isOneOf(value.action, acpElicitationActions), "ACP URL \u4EA4\u4E92\u7B54\u590D\u65E0\u6548\u3002");
|
|
235
235
|
return value;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
// src/storage/agent-files.ts
|
|
239
239
|
var text2 = (v) => typeof v === "string" && v.length > 0;
|
|
240
240
|
var number = (v) => typeof v === "number" && Number.isFinite(v);
|
|
241
|
-
function
|
|
242
|
-
requireThat(object(v) && text2(v.agentId) && text2(v.release) && text2(v.workspace) && text2(v.
|
|
241
|
+
function workerRecord(v) {
|
|
242
|
+
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");
|
|
243
243
|
fileId(v.agentId);
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
function launch(v) {
|
|
247
|
-
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");
|
|
244
|
+
acpConfig(v.acp);
|
|
248
245
|
return v;
|
|
249
246
|
}
|
|
250
247
|
function message(v) {
|
|
@@ -252,14 +249,56 @@ function message(v) {
|
|
|
252
249
|
return v;
|
|
253
250
|
}
|
|
254
251
|
function cycle(v) {
|
|
255
|
-
requireThat(object(v) && text2(v.cycleId) && text2(v.generation) && number(v.startedAt) && isOneOf(v.state, cycleStates) &&
|
|
252
|
+
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");
|
|
256
253
|
return v;
|
|
257
254
|
}
|
|
258
255
|
function status(v) {
|
|
259
256
|
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");
|
|
260
|
-
if (v.
|
|
257
|
+
if (v.sessionId !== void 0) requireThat(v.sessionId === null || text2(v.sessionId), "ACP \u4F1A\u8BDD ID \u65E0\u6548\u3002");
|
|
258
|
+
if (v.capabilities !== void 0) {
|
|
259
|
+
requireThat(object(v.capabilities) && ["resume", "load", "close"].every((key) => typeof v.capabilities[key] === "boolean"), "ACP \u4F1A\u8BDD\u80FD\u529B\u65E0\u6548\u3002");
|
|
260
|
+
}
|
|
261
|
+
if (v.selection !== void 0) {
|
|
262
|
+
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");
|
|
263
|
+
}
|
|
264
|
+
if (v.activeRequestId !== void 0) {
|
|
265
|
+
requireThat(text2(v.activeRequestId), "ACP \u8F93\u5165\u5173\u8054\u65E0\u6548\u3002");
|
|
266
|
+
fileId(v.activeRequestId);
|
|
267
|
+
}
|
|
268
|
+
if (v.accepted !== void 0) requireThat(Array.isArray(v.accepted) && v.accepted.every(text2), "\u5DF2\u9886\u53D6\u8BF7\u6C42\u5217\u8868\u65E0\u6548\u3002");
|
|
269
|
+
if (v.cycle !== void 0) cycle(v.cycle);
|
|
270
|
+
if (v.error !== void 0) requireThat(typeof v.error === "string", "\u5B50\u4F1A\u8BDD\u9519\u8BEF\u4FE1\u606F\u65E0\u6548\u3002");
|
|
261
271
|
return v;
|
|
262
272
|
}
|
|
273
|
+
function outputRecord(v) {
|
|
274
|
+
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");
|
|
275
|
+
fileId(v.cycleId);
|
|
276
|
+
return v;
|
|
277
|
+
}
|
|
278
|
+
function toDescriptor(record2) {
|
|
279
|
+
return {
|
|
280
|
+
agentId: record2.agentId,
|
|
281
|
+
release: record2.release,
|
|
282
|
+
workspace: record2.workspace,
|
|
283
|
+
parentSessionId: record2.parentSessionId,
|
|
284
|
+
options: record2.options ?? {}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
function tryUnlink(path) {
|
|
288
|
+
try {
|
|
289
|
+
unlinkSync2(path);
|
|
290
|
+
} catch (error2) {
|
|
291
|
+
if (error2.code !== "ENOENT") throw error2;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
function tryRmdir(path) {
|
|
295
|
+
try {
|
|
296
|
+
rmdirSync2(path);
|
|
297
|
+
} catch (error2) {
|
|
298
|
+
const code = error2.code;
|
|
299
|
+
if (code !== "ENOENT" && code !== "ENOTEMPTY" && code !== "EEXIST") throw error2;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
263
302
|
var AgentFiles = class {
|
|
264
303
|
constructor(root) {
|
|
265
304
|
this.root = root;
|
|
@@ -297,48 +336,99 @@ var AgentFiles = class {
|
|
|
297
336
|
}
|
|
298
337
|
requireThat(published, "\u5B50\u4F1A\u8BDD\u6587\u4EF6\u5DF2\u5B58\u5728\u3002");
|
|
299
338
|
}
|
|
339
|
+
remove(id, path) {
|
|
340
|
+
tryUnlink(join3(this.directory(id), path));
|
|
341
|
+
}
|
|
300
342
|
create(value, run, acp) {
|
|
301
343
|
this.check();
|
|
302
344
|
acpReference(acp);
|
|
303
345
|
mkdirSync3(this.root, { recursive: true, mode: 448 });
|
|
304
346
|
mkdirSync3(this.directory(value.agentId), { mode: 448 });
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
347
|
+
const hasOptions = Object.keys(value.options).length > 0;
|
|
348
|
+
const record2 = {
|
|
349
|
+
agentId: value.agentId,
|
|
350
|
+
release: value.release,
|
|
351
|
+
workspace: value.workspace,
|
|
352
|
+
parentSessionId: value.parentSessionId,
|
|
353
|
+
generation: run.generation,
|
|
354
|
+
sequence: run.sequence,
|
|
355
|
+
stop: run.stop,
|
|
356
|
+
startedAt: run.startedAt,
|
|
357
|
+
acp: {
|
|
358
|
+
backend: acp.backend,
|
|
359
|
+
command: acp.command,
|
|
360
|
+
args: acp.args,
|
|
361
|
+
...acp.env ? { env: acp.env } : {},
|
|
362
|
+
...acp.permission ? { permission: acp.permission } : {}
|
|
363
|
+
},
|
|
364
|
+
...hasOptions ? { options: value.options } : {}
|
|
365
|
+
};
|
|
366
|
+
this.write(value.agentId, "worker.json", record2, workerRecord, true);
|
|
367
|
+
}
|
|
368
|
+
worker(id) {
|
|
369
|
+
return this.read(id, "worker.json", workerRecord);
|
|
309
370
|
}
|
|
310
371
|
list() {
|
|
311
372
|
if (!existsSync(this.root)) return [];
|
|
312
373
|
return readdirSync(this.root, { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith(".")).flatMap((e) => {
|
|
313
|
-
const
|
|
314
|
-
return
|
|
374
|
+
const record2 = this.optional(e.name, "worker.json", workerRecord);
|
|
375
|
+
return record2 ? [record2] : [];
|
|
315
376
|
});
|
|
316
377
|
}
|
|
317
378
|
messages(id) {
|
|
318
|
-
|
|
379
|
+
const dir = join3(this.directory(id), "inbox");
|
|
380
|
+
if (!existsSync(dir)) return [];
|
|
381
|
+
return readdirSync(dir).filter((n) => n.endsWith(".json")).map((n) => this.read(id, "inbox/" + n, message)).sort((a, b) => a.sequence - b.sequence);
|
|
319
382
|
}
|
|
320
|
-
|
|
321
|
-
|
|
383
|
+
removeMessage(id, requestId) {
|
|
384
|
+
fileId(requestId);
|
|
385
|
+
const dir = join3(this.directory(id), "inbox");
|
|
386
|
+
tryUnlink(join3(dir, requestId + ".json"));
|
|
387
|
+
tryRmdir(dir);
|
|
322
388
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
const dir = join3(this.directory(id), "permissions");
|
|
326
|
-
if (!existsSync(dir)) return [];
|
|
327
|
-
const names = readdirSync(dir);
|
|
328
|
-
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);
|
|
389
|
+
output(id) {
|
|
390
|
+
return this.optional(id, "output.json", outputRecord);
|
|
329
391
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const dir = join3(this.directory(id), "elicitations");
|
|
392
|
+
pendingInteractions(id, generation) {
|
|
393
|
+
const dir = join3(this.directory(id), "interactions");
|
|
333
394
|
if (!existsSync(dir)) return [];
|
|
334
395
|
const names = readdirSync(dir);
|
|
335
|
-
return names.filter((n) => n.endsWith(".json") && !n.endsWith("-reply.json") && !names.includes(n.slice(0, -5) + "-reply.json")).map((n) => this.read(id, "
|
|
396
|
+
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);
|
|
397
|
+
}
|
|
398
|
+
removeInteraction(id, requestId) {
|
|
399
|
+
fileId(requestId);
|
|
400
|
+
const dir = join3(this.directory(id), "interactions");
|
|
401
|
+
tryUnlink(join3(dir, requestId + ".json"));
|
|
402
|
+
tryUnlink(join3(dir, requestId + "-reply.json"));
|
|
403
|
+
tryRmdir(dir);
|
|
404
|
+
}
|
|
405
|
+
clearTransient(id) {
|
|
406
|
+
const base = this.directory(id);
|
|
407
|
+
if (!existsSync(base)) return;
|
|
408
|
+
rmSync(join3(base, "inbox"), { recursive: true, force: true });
|
|
409
|
+
rmSync(join3(base, "interactions"), { recursive: true, force: true });
|
|
410
|
+
tryUnlink(join3(base, "acp-answer.json"));
|
|
411
|
+
}
|
|
412
|
+
removeWorker(id) {
|
|
413
|
+
rmSync(this.directory(id), { recursive: true, force: true });
|
|
414
|
+
tryRmdir(this.root);
|
|
336
415
|
}
|
|
337
416
|
ensureSubdirectory(id, name) {
|
|
338
417
|
privateDirectory(this.directory(id), name);
|
|
339
418
|
}
|
|
340
419
|
reference(id) {
|
|
341
|
-
|
|
420
|
+
const w = this.worker(id);
|
|
421
|
+
const saved = this.optional(id, "state.json", status);
|
|
422
|
+
return {
|
|
423
|
+
host: "acp",
|
|
424
|
+
backend: w.acp.backend,
|
|
425
|
+
command: w.acp.command,
|
|
426
|
+
args: w.acp.args,
|
|
427
|
+
...w.acp.env ? { env: w.acp.env } : {},
|
|
428
|
+
...w.acp.permission ? { permission: w.acp.permission } : {},
|
|
429
|
+
sessionId: saved?.sessionId ?? null,
|
|
430
|
+
...saved?.capabilities ? { capabilities: saved.capabilities } : {}
|
|
431
|
+
};
|
|
342
432
|
}
|
|
343
433
|
/** Short controller edits are serialized; an abandoned lock fails closed. */
|
|
344
434
|
control(work) {
|
|
@@ -359,14 +449,16 @@ var AgentFiles = class {
|
|
|
359
449
|
}
|
|
360
450
|
enqueue(id, text3, delivery, files = [], requestId = randomUUID2()) {
|
|
361
451
|
fileId(requestId);
|
|
362
|
-
const
|
|
452
|
+
const w = this.worker(id);
|
|
453
|
+
const previous = this.optional(id, "inbox/" + requestId + ".json", message);
|
|
363
454
|
if (previous) {
|
|
364
|
-
requireThat(previous.generation ===
|
|
455
|
+
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");
|
|
365
456
|
return previous;
|
|
366
457
|
}
|
|
367
|
-
|
|
368
|
-
this.write(id, "
|
|
369
|
-
|
|
458
|
+
w.sequence++;
|
|
459
|
+
this.write(id, "worker.json", w, workerRecord);
|
|
460
|
+
this.ensureSubdirectory(id, "inbox");
|
|
461
|
+
const value = { requestId, generation: w.generation, sequence: w.sequence, message: text3, delivery, files };
|
|
370
462
|
this.write(id, "inbox/" + value.requestId + ".json", value, message, true);
|
|
371
463
|
return value;
|
|
372
464
|
}
|
|
@@ -383,19 +475,32 @@ var AgentRun = class {
|
|
|
383
475
|
this.files = files;
|
|
384
476
|
this.id = id;
|
|
385
477
|
this.generation = generation;
|
|
386
|
-
const
|
|
387
|
-
this.#saved =
|
|
478
|
+
const existing = files.optional(id, "state.json", status);
|
|
479
|
+
this.#saved = existing?.generation === generation ? existing : void 0;
|
|
388
480
|
const requests = new Set(files.messages(id).filter((m) => m.generation === generation).map((m) => m.requestId));
|
|
389
|
-
for (const requestId of this.#saved?.accepted ?? [])
|
|
390
|
-
|
|
481
|
+
for (const requestId of this.#saved?.accepted ?? []) {
|
|
482
|
+
if (requests.has(requestId)) {
|
|
483
|
+
this.#accepted.add(requestId);
|
|
484
|
+
this.#inflight.add(requestId);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
this.#snapshot = {
|
|
488
|
+
generation,
|
|
489
|
+
state: "starting",
|
|
490
|
+
activity: "\u542F\u52A8",
|
|
491
|
+
updatedAt: Date.now(),
|
|
492
|
+
...existing?.sessionId !== void 0 ? { sessionId: existing.sessionId } : {},
|
|
493
|
+
...existing?.capabilities ? { capabilities: existing.capabilities } : {},
|
|
494
|
+
...this.#saved?.selection ? { selection: this.#saved.selection } : {},
|
|
495
|
+
...this.#saved?.activeRequestId ? { activeRequestId: this.#saved.activeRequestId } : {}
|
|
496
|
+
};
|
|
391
497
|
}
|
|
392
498
|
#accepted = /* @__PURE__ */ new Set();
|
|
499
|
+
#inflight = /* @__PURE__ */ new Set();
|
|
393
500
|
#assigned = /* @__PURE__ */ new Set();
|
|
394
501
|
#consumed = /* @__PURE__ */ new Set();
|
|
395
502
|
#queued = [];
|
|
396
503
|
#saved;
|
|
397
|
-
#interactive = false;
|
|
398
|
-
#humanConsumed = false;
|
|
399
504
|
#current;
|
|
400
505
|
#snapshot;
|
|
401
506
|
get current() {
|
|
@@ -407,21 +512,61 @@ var AgentRun = class {
|
|
|
407
512
|
get pending() {
|
|
408
513
|
return this.#queued.length;
|
|
409
514
|
}
|
|
410
|
-
get interactive() {
|
|
411
|
-
return this.#interactive;
|
|
412
|
-
}
|
|
413
515
|
accepted(requestId) {
|
|
414
516
|
return this.#accepted.has(requestId);
|
|
415
517
|
}
|
|
518
|
+
setSession(sessionId, capabilities) {
|
|
519
|
+
this.#snapshot = {
|
|
520
|
+
...this.#snapshot,
|
|
521
|
+
sessionId,
|
|
522
|
+
...capabilities ? { capabilities } : {},
|
|
523
|
+
updatedAt: Date.now()
|
|
524
|
+
};
|
|
525
|
+
this.persist();
|
|
526
|
+
}
|
|
527
|
+
setSelection(selection) {
|
|
528
|
+
const clean = Object.fromEntries(Object.entries(selection).filter(([, value]) => value !== void 0));
|
|
529
|
+
this.#snapshot = {
|
|
530
|
+
...this.#snapshot,
|
|
531
|
+
...Object.keys(clean).length ? { selection: clean } : {},
|
|
532
|
+
updatedAt: Date.now()
|
|
533
|
+
};
|
|
534
|
+
this.persist();
|
|
535
|
+
}
|
|
536
|
+
setActiveRequest(requestId) {
|
|
537
|
+
const next = { ...this.#snapshot, updatedAt: Date.now() };
|
|
538
|
+
if (requestId) next.activeRequestId = requestId;
|
|
539
|
+
else delete next.activeRequestId;
|
|
540
|
+
this.#snapshot = next;
|
|
541
|
+
this.persist();
|
|
542
|
+
}
|
|
416
543
|
save(patch) {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
544
|
+
const next = {
|
|
545
|
+
...this.#snapshot,
|
|
546
|
+
state: patch.state,
|
|
547
|
+
activity: patch.activity,
|
|
548
|
+
updatedAt: Date.now()
|
|
549
|
+
};
|
|
550
|
+
if (patch.error !== void 0) next.error = patch.error;
|
|
551
|
+
else delete next.error;
|
|
552
|
+
this.#snapshot = next;
|
|
553
|
+
this.persist();
|
|
554
|
+
}
|
|
555
|
+
persist() {
|
|
556
|
+
const record2 = {
|
|
557
|
+
...this.#snapshot,
|
|
558
|
+
...this.#inflight.size ? { accepted: [...this.#inflight] } : {},
|
|
559
|
+
...this.#current ? { cycle: structuredClone(this.#current) } : {}
|
|
560
|
+
};
|
|
561
|
+
if (!this.#inflight.size) delete record2.accepted;
|
|
562
|
+
if (!this.#current) delete record2.cycle;
|
|
563
|
+
this.files.write(this.id, "state.json", record2, status);
|
|
420
564
|
}
|
|
421
565
|
/** A receipt is durable before input is passed to the native execution boundary. */
|
|
422
566
|
claim(requestId) {
|
|
423
567
|
requireThat(this.files.messages(this.id).some((m) => m.requestId === requestId && m.generation === this.generation), "\u8BF7\u6C42\u4E0D\u5C5E\u4E8E\u5F53\u524D\u542F\u52A8\u4EE3\u6B21\u3002");
|
|
424
568
|
this.#accepted.add(requestId);
|
|
569
|
+
this.#inflight.add(requestId);
|
|
425
570
|
this.save({ state: "busy", activity: "\u6D88\u606F\u5DF2\u9886\u53D6" });
|
|
426
571
|
}
|
|
427
572
|
/** Native ownership associates work even when preparation fails before model admission. */
|
|
@@ -431,8 +576,9 @@ var AgentRun = class {
|
|
|
431
576
|
this.#assigned.add(requestId);
|
|
432
577
|
if (this.#current) {
|
|
433
578
|
if (!this.#current.requestIds.includes(requestId)) this.#current.requestIds.push(requestId);
|
|
434
|
-
|
|
435
|
-
|
|
579
|
+
} else if (!this.#queued.includes(requestId)) {
|
|
580
|
+
this.#queued.push(requestId);
|
|
581
|
+
}
|
|
436
582
|
this.save({ state: "busy", activity: "\u6D88\u606F\u5DF2\u63A5\u6536" });
|
|
437
583
|
}
|
|
438
584
|
/** Model admission is a separate fact from a native inbox claim. */
|
|
@@ -441,31 +587,6 @@ var AgentRun = class {
|
|
|
441
587
|
this.#consumed.add(requestId);
|
|
442
588
|
this.enter(requestId);
|
|
443
589
|
}
|
|
444
|
-
cancelQueued(requestId) {
|
|
445
|
-
if (!this.#accepted.has(requestId) || this.#assigned.has(requestId)) return;
|
|
446
|
-
const value = {
|
|
447
|
-
cycleId: requestId,
|
|
448
|
-
generation: this.generation,
|
|
449
|
-
startedAt: this.files.read(this.id, "launch.json", launch).startedAt,
|
|
450
|
-
finishedAt: Date.now(),
|
|
451
|
-
state: "cancelled",
|
|
452
|
-
leaf: null,
|
|
453
|
-
requestIds: [requestId],
|
|
454
|
-
source: "parent"
|
|
455
|
-
};
|
|
456
|
-
this.files.write(this.id, "completions/" + requestId + ".json", value, cycle, true);
|
|
457
|
-
this.#assigned.add(requestId);
|
|
458
|
-
}
|
|
459
|
-
humanInput() {
|
|
460
|
-
this.#humanConsumed = true;
|
|
461
|
-
this.enterHuman();
|
|
462
|
-
}
|
|
463
|
-
enterHuman() {
|
|
464
|
-
if (this.#current) {
|
|
465
|
-
if (this.#current.source === "parent") this.#current.source = this.#current.requestIds.length ? "mixed" : "interactive";
|
|
466
|
-
} else this.#interactive = true;
|
|
467
|
-
this.save({ state: "busy", activity: "\u4EBA\u5DE5\u8F93\u5165" });
|
|
468
|
-
}
|
|
469
590
|
begin() {
|
|
470
591
|
if (!this.#current) {
|
|
471
592
|
const requestIds = this.#queued.splice(0);
|
|
@@ -474,55 +595,79 @@ var AgentRun = class {
|
|
|
474
595
|
generation: this.generation,
|
|
475
596
|
startedAt: Date.now(),
|
|
476
597
|
state: "running",
|
|
477
|
-
|
|
478
|
-
requestIds,
|
|
479
|
-
source: this.#interactive ? requestIds.length ? "mixed" : "interactive" : "parent"
|
|
598
|
+
requestIds
|
|
480
599
|
};
|
|
481
|
-
this.#interactive = false;
|
|
482
600
|
}
|
|
483
601
|
this.save({ state: "busy", activity: "\u601D\u8003" });
|
|
484
602
|
}
|
|
485
603
|
finish(end) {
|
|
486
604
|
if (!this.#current) return;
|
|
487
|
-
const valid = end.
|
|
488
|
-
|
|
489
|
-
|
|
605
|
+
const valid = end.answer.trim().length > 0 && this.#current.requestIds.length > 0 && this.#current.requestIds.every((id) => this.#consumed.has(id));
|
|
606
|
+
const finalState = end.state === "completed" && !valid ? "failed" : end.state;
|
|
607
|
+
const error2 = end.error ?? (end.state === "completed" && !valid ? "\u6CA1\u6709\u5DF2\u6D88\u8D39\u7684\u8BF7\u6C42\u6216\u6709\u6548\u6700\u7EC8\u56DE\u7B54\u3002" : void 0);
|
|
608
|
+
const finished = {
|
|
609
|
+
cycleId: this.#current.cycleId,
|
|
610
|
+
generation: this.generation,
|
|
611
|
+
startedAt: this.#current.startedAt,
|
|
490
612
|
finishedAt: Date.now(),
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
613
|
+
state: finalState,
|
|
614
|
+
requestIds: [...this.#current.requestIds],
|
|
615
|
+
text: end.answer,
|
|
616
|
+
...error2 ? { error: error2 } : {}
|
|
494
617
|
};
|
|
495
|
-
|
|
496
|
-
|
|
618
|
+
const completedRequests = [...this.#current.requestIds];
|
|
619
|
+
for (const requestId of completedRequests) {
|
|
620
|
+
this.#inflight.delete(requestId);
|
|
621
|
+
this.files.removeMessage(this.id, requestId);
|
|
622
|
+
}
|
|
623
|
+
this.files.write(this.id, "output.json", finished, outputRecord);
|
|
497
624
|
this.#current = void 0;
|
|
498
|
-
this.#
|
|
625
|
+
delete this.#snapshot.activeRequestId;
|
|
626
|
+
this.save({ state: "idle", activity: finished.state });
|
|
499
627
|
}
|
|
500
628
|
/** Reload seals uncertainty. It never turns a receipt into permission to replay. */
|
|
501
629
|
recover(receipts = []) {
|
|
502
630
|
const requests = new Set(this.files.messages(this.id).filter((m) => m.generation === this.generation).map((m) => m.requestId));
|
|
503
|
-
for (const receipt of receipts)
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
631
|
+
for (const receipt of receipts) {
|
|
632
|
+
if (receipt.generation === this.generation && requests.has(receipt.requestId)) {
|
|
633
|
+
this.#accepted.add(receipt.requestId);
|
|
634
|
+
this.#inflight.add(receipt.requestId);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
let latest = this.files.output(this.id);
|
|
638
|
+
if (latest?.generation === this.generation) {
|
|
639
|
+
for (const id of latest.requestIds) this.#assigned.add(id);
|
|
640
|
+
}
|
|
641
|
+
if (this.#saved?.cycle?.state === "running" && latest?.cycleId !== this.#saved.cycle.cycleId) {
|
|
642
|
+
const interrupted = {
|
|
643
|
+
cycleId: this.#saved.cycle.cycleId,
|
|
644
|
+
generation: this.#saved.cycle.generation,
|
|
645
|
+
startedAt: this.#saved.cycle.startedAt,
|
|
646
|
+
finishedAt: Date.now(),
|
|
647
|
+
state: "interrupted",
|
|
648
|
+
requestIds: [...this.#saved.cycle.requestIds],
|
|
649
|
+
text: "",
|
|
650
|
+
...this.#saved.cycle.error ? { error: this.#saved.cycle.error } : {}
|
|
651
|
+
};
|
|
652
|
+
this.files.write(this.id, "output.json", interrupted, outputRecord);
|
|
653
|
+
latest = interrupted;
|
|
654
|
+
for (const id of interrupted.requestIds) this.#assigned.add(id);
|
|
510
655
|
}
|
|
511
656
|
for (const requestId of this.#accepted) {
|
|
512
657
|
this.#assigned.add(requestId);
|
|
513
|
-
if (
|
|
658
|
+
if (latest?.generation === this.generation && latest.requestIds.includes(requestId)) continue;
|
|
514
659
|
const interrupted = {
|
|
515
660
|
cycleId: requestId,
|
|
516
661
|
generation: this.generation,
|
|
517
|
-
startedAt: this.files.
|
|
662
|
+
startedAt: this.files.worker(this.id).startedAt,
|
|
518
663
|
finishedAt: Date.now(),
|
|
519
664
|
state: "interrupted",
|
|
520
|
-
leaf: null,
|
|
521
665
|
requestIds: [requestId],
|
|
522
|
-
|
|
666
|
+
text: "",
|
|
523
667
|
error: "\u9886\u53D6\u540E\u6267\u884C\u7ED3\u679C\u4E0D\u660E\uFF1B\u672A\u91CD\u8DD1\u3002"
|
|
524
668
|
};
|
|
525
|
-
this.files.write(this.id, "
|
|
669
|
+
this.files.write(this.id, "output.json", interrupted, outputRecord);
|
|
670
|
+
latest = interrupted;
|
|
526
671
|
}
|
|
527
672
|
}
|
|
528
673
|
};
|
|
@@ -547,13 +692,13 @@ var AcpAnswerBuffer = class {
|
|
|
547
692
|
}
|
|
548
693
|
};
|
|
549
694
|
var AcpAgentRun = class {
|
|
550
|
-
constructor(files,
|
|
695
|
+
constructor(files, descriptor, generation, work, exactAnswer, execution) {
|
|
551
696
|
this.files = files;
|
|
552
|
-
this.descriptor =
|
|
697
|
+
this.descriptor = descriptor;
|
|
553
698
|
this.generation = generation;
|
|
554
699
|
this.work = work;
|
|
555
700
|
this.exactAnswer = exactAnswer;
|
|
556
|
-
this.execution = new AgentRun(files,
|
|
701
|
+
this.execution = execution ?? new AgentRun(files, descriptor.agentId, generation);
|
|
557
702
|
}
|
|
558
703
|
execution;
|
|
559
704
|
#answer = new AcpAnswerBuffer();
|
|
@@ -566,7 +711,7 @@ var AcpAgentRun = class {
|
|
|
566
711
|
return this.descriptor.agentId;
|
|
567
712
|
}
|
|
568
713
|
current() {
|
|
569
|
-
return this.files.
|
|
714
|
+
return this.files.worker(this.id).generation === this.generation;
|
|
570
715
|
}
|
|
571
716
|
update(value) {
|
|
572
717
|
if (!this.execution.current || !this.current()) return;
|
|
@@ -577,46 +722,45 @@ var AcpAgentRun = class {
|
|
|
577
722
|
}
|
|
578
723
|
}
|
|
579
724
|
async permission(description, options, signal) {
|
|
580
|
-
const requestId = randomUUID4()
|
|
581
|
-
this.
|
|
582
|
-
this.files.
|
|
725
|
+
const requestId = randomUUID4();
|
|
726
|
+
const request = { generation: this.generation, requestId, kind: "permission", description, options };
|
|
727
|
+
this.files.ensureSubdirectory(this.id, "interactions");
|
|
728
|
+
this.files.write(this.id, "interactions/" + requestId + ".json", request, acpInteraction, true);
|
|
583
729
|
this.execution.save({ state: "busy", activity: "\u7B49\u5F85\u786E\u8BA4" });
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
730
|
+
try {
|
|
731
|
+
while (!signal.aborted && !this.#stopping && this.current() && !this.files.worker(this.id).stop) {
|
|
732
|
+
const reply = this.files.optional(this.id, "interactions/" + requestId + "-reply.json", acpInteractionReply);
|
|
733
|
+
if (reply?.generation === this.generation && reply.kind === "permission") {
|
|
734
|
+
this.execution.save({ state: this.#stopping ? "stopping" : "busy", activity: reply.optionId ? "\u5DF2\u83B7\u786E\u8BA4" : "\u786E\u8BA4\u88AB\u62D2\u7EDD" });
|
|
735
|
+
return reply.optionId;
|
|
736
|
+
}
|
|
737
|
+
await delay(100);
|
|
589
738
|
}
|
|
590
|
-
|
|
739
|
+
return null;
|
|
740
|
+
} finally {
|
|
741
|
+
this.files.removeInteraction(this.id, requestId);
|
|
591
742
|
}
|
|
592
|
-
if (this.current()) this.files.write(this.id, "permissions/" + requestId + "-reply.json", { generation: this.generation, requestId, optionId: null }, acpPermissionReply, true);
|
|
593
|
-
return null;
|
|
594
743
|
}
|
|
595
744
|
async elicitation(input, signal) {
|
|
596
745
|
const requestId = randomUUID4();
|
|
597
|
-
const request = input.mode === "form" ? { generation: this.generation, requestId,
|
|
598
|
-
this.files.ensureSubdirectory(this.id, "
|
|
599
|
-
this.files.write(this.id, "
|
|
746
|
+
const request = input.mode === "form" ? { generation: this.generation, requestId, kind: "form", message: input.message, schema: input.schema } : { generation: this.generation, requestId, kind: "url", message: input.message, url: input.url };
|
|
747
|
+
this.files.ensureSubdirectory(this.id, "interactions");
|
|
748
|
+
this.files.write(this.id, "interactions/" + requestId + ".json", request, acpInteraction, true);
|
|
600
749
|
this.execution.save({ state: "busy", activity: "\u7B49\u5F85\u56DE\u590D" });
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
750
|
+
try {
|
|
751
|
+
while (!signal.aborted && !this.#stopping && this.current() && !this.files.worker(this.id).stop) {
|
|
752
|
+
const reply = this.files.optional(this.id, "interactions/" + requestId + "-reply.json", acpInteractionReply);
|
|
753
|
+
if (reply?.generation === this.generation && reply.kind !== "permission") {
|
|
754
|
+
const label = reply.action === "accept" ? "\u5DF2\u6536\u5230\u56DE\u590D" : reply.action === "decline" ? "\u56DE\u590D\u5DF2\u62D2\u7EDD" : "\u56DE\u590D\u5DF2\u53D6\u6D88";
|
|
755
|
+
this.execution.save({ state: this.#stopping ? "stopping" : "busy", activity: label });
|
|
756
|
+
return { action: reply.action, ...reply.kind === "form" && reply.content ? { content: reply.content } : {} };
|
|
757
|
+
}
|
|
758
|
+
await delay(100);
|
|
607
759
|
}
|
|
608
|
-
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
this.files.write(
|
|
612
|
-
this.id,
|
|
613
|
-
"elicitations/" + requestId + "-reply.json",
|
|
614
|
-
{ generation: this.generation, requestId, action: "cancel" },
|
|
615
|
-
acpElicitationReply,
|
|
616
|
-
true
|
|
617
|
-
);
|
|
760
|
+
return { action: "cancel" };
|
|
761
|
+
} finally {
|
|
762
|
+
this.files.removeInteraction(this.id, requestId);
|
|
618
763
|
}
|
|
619
|
-
return { action: "cancel" };
|
|
620
764
|
}
|
|
621
765
|
async run() {
|
|
622
766
|
this.execution.recover();
|
|
@@ -624,7 +768,7 @@ var AcpAgentRun = class {
|
|
|
624
768
|
while (!this.#stopping && this.current() && !this.work.signal.aborted) {
|
|
625
769
|
this.files.check();
|
|
626
770
|
if (this.#failure) throw this.#failure;
|
|
627
|
-
if (this.files.
|
|
771
|
+
if (this.files.worker(this.id).stop) {
|
|
628
772
|
await this.stop();
|
|
629
773
|
break;
|
|
630
774
|
}
|
|
@@ -651,13 +795,14 @@ var AcpAgentRun = class {
|
|
|
651
795
|
this.execution.claim(request.requestId);
|
|
652
796
|
this.execution.enter(request.requestId);
|
|
653
797
|
this.execution.begin();
|
|
654
|
-
this.
|
|
798
|
+
this.execution.setActiveRequest(request.requestId);
|
|
655
799
|
let result;
|
|
656
800
|
try {
|
|
657
801
|
const end = await this.work.prompt(request);
|
|
658
802
|
let snapshot;
|
|
659
803
|
if (this.exactAnswer) {
|
|
660
804
|
snapshot = this.files.optional(this.id, "acp-answer.json", acpAnswer);
|
|
805
|
+
this.files.remove(this.id, "acp-answer.json");
|
|
661
806
|
if (snapshot?.generation !== this.generation || snapshot.requestId !== request.requestId) snapshot = void 0;
|
|
662
807
|
}
|
|
663
808
|
const answer = this.exactAnswer ? snapshot?.answer ?? "" : this.#answer.text;
|
|
@@ -671,20 +816,18 @@ var AcpAgentRun = class {
|
|
|
671
816
|
...state === "failed" ? { error: snapshot?.error ?? "ACP \u5DE5\u4F5C\u672A\u4EA7\u751F\u6709\u6548\u6700\u7EC8\u56DE\u7B54\uFF1A" + end.stopReason } : {}
|
|
672
817
|
};
|
|
673
818
|
} catch (error2) {
|
|
819
|
+
if (this.exactAnswer) this.files.remove(this.id, "acp-answer.json");
|
|
674
820
|
result = {
|
|
675
821
|
generation: this.generation,
|
|
676
822
|
requestId: request.requestId,
|
|
677
823
|
answer: this.#answer.text,
|
|
678
|
-
state: this.#stopping || this.files.
|
|
824
|
+
state: this.#stopping || this.files.worker(this.id).stop ? "cancelled" : "failed",
|
|
679
825
|
error: String(error2)
|
|
680
826
|
};
|
|
681
827
|
}
|
|
682
828
|
if (!this.current()) return;
|
|
683
|
-
const cycleId = this.execution.current.cycleId;
|
|
684
|
-
this.files.write(this.id, "reports/" + cycleId + ".json", { generation: this.generation, cycleId, text: result.answer }, acpReport, true);
|
|
685
829
|
this.execution.finish({
|
|
686
830
|
state: this.work.signal.aborted && !this.#stopping ? "interrupted" : result.state,
|
|
687
|
-
position: "acp:" + cycleId,
|
|
688
831
|
answer: result.answer,
|
|
689
832
|
...result.error ? { error: result.error } : {}
|
|
690
833
|
});
|
|
@@ -1176,9 +1319,9 @@ function createTransparentProxy(getter) {
|
|
|
1176
1319
|
target ?? (target = getter());
|
|
1177
1320
|
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
1178
1321
|
},
|
|
1179
|
-
defineProperty(_, prop,
|
|
1322
|
+
defineProperty(_, prop, descriptor) {
|
|
1180
1323
|
target ?? (target = getter());
|
|
1181
|
-
return Reflect.defineProperty(target, prop,
|
|
1324
|
+
return Reflect.defineProperty(target, prop, descriptor);
|
|
1182
1325
|
}
|
|
1183
1326
|
});
|
|
1184
1327
|
}
|
|
@@ -10454,7 +10597,7 @@ var claudeAcpHarness = {
|
|
|
10454
10597
|
},
|
|
10455
10598
|
async prepareLaunch(context) {
|
|
10456
10599
|
const base = defaultPrepareLaunch(context);
|
|
10457
|
-
const claude = await claudeOptions(base.command, context.
|
|
10600
|
+
const claude = await claudeOptions(base.command, context.workspace, context.options.thinking, context.features?.skills !== false);
|
|
10458
10601
|
return {
|
|
10459
10602
|
...base,
|
|
10460
10603
|
...claude.thinking ? { defaultThinking: claude.thinking } : {},
|
|
@@ -11088,8 +11231,8 @@ function config2(value) {
|
|
|
11088
11231
|
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");
|
|
11089
11232
|
}
|
|
11090
11233
|
for (const command of Object.values(value.acp)) {
|
|
11091
|
-
const
|
|
11092
|
-
if (!object(command) || !
|
|
11234
|
+
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")));
|
|
11235
|
+
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))) {
|
|
11093
11236
|
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");
|
|
11094
11237
|
}
|
|
11095
11238
|
}
|
|
@@ -11503,9 +11646,10 @@ async function runWorker(args2) {
|
|
|
11503
11646
|
requireThat(directory && id && generation, "\u7F3A\u5C11 ACP worker \u542F\u52A8\u4FE1\u606F\u3002");
|
|
11504
11647
|
const files = new AgentFiles(dirname4(directory));
|
|
11505
11648
|
requireThat(files.directory(id) === directory, "ACP worker \u76EE\u5F55\u4E0D\u5339\u914D\u3002");
|
|
11506
|
-
const d = files.
|
|
11649
|
+
const d = toDescriptor(files.worker(id)), reference = files.reference(id);
|
|
11507
11650
|
requireThat(d.agentId === id && releaseLine(d.release) === releaseLine(packageVersion), "ACP worker \u8EAB\u4EFD\u6216\u7248\u672C\u4E0D\u5339\u914D\u3002");
|
|
11508
11651
|
const validating = args2.includes("--validate"), lifetime = new AbortController();
|
|
11652
|
+
const agentRun = validating ? void 0 : new AgentRun(files, id, generation);
|
|
11509
11653
|
let execution;
|
|
11510
11654
|
const stop = () => {
|
|
11511
11655
|
void execution?.stop().catch((error2) => lifetime.abort(error2));
|
|
@@ -11514,7 +11658,7 @@ async function runWorker(args2) {
|
|
|
11514
11658
|
process.on("SIGTERM", stop);
|
|
11515
11659
|
process.on("SIGINT", stop);
|
|
11516
11660
|
async function main() {
|
|
11517
|
-
requireThat(files.
|
|
11661
|
+
requireThat(files.worker(id).generation === generation, "ACP worker \u542F\u52A8\u4EE3\u6B21\u5DF2\u5931\u6548\u3002");
|
|
11518
11662
|
const harness = resolveAcpHarness(reference.backend);
|
|
11519
11663
|
const exactAnswer = Boolean(harness.exactAnswer);
|
|
11520
11664
|
const packageRoot2 = resolve6(resourceRoot, "..");
|
|
@@ -11527,7 +11671,7 @@ async function runWorker(args2) {
|
|
|
11527
11671
|
PBOT_SUBAGENT_GENERATION: generation,
|
|
11528
11672
|
...validating ? { PBOT_ACP_VALIDATE: "1" } : {}
|
|
11529
11673
|
};
|
|
11530
|
-
const prepared = harness.prepareLaunch ? await harness.prepareLaunch({ reference,
|
|
11674
|
+
const prepared = harness.prepareLaunch ? await harness.prepareLaunch({ reference, workspace: d.workspace, directory, packageRoot: packageRoot2, options: d.options, env: baseEnv, features }) : { command: { ...reference, args: [...reference.args] }, env: { ...baseEnv, ...reference.env ?? {} } };
|
|
11531
11675
|
let prompt;
|
|
11532
11676
|
if (!exactAnswer) {
|
|
11533
11677
|
const workspaceSkills = features.skills && !harness.nativeWorkspaceSkills && !d.options.noSkills ? await discoverWorkspaceSkills(d.workspace) : [];
|
|
@@ -11551,11 +11695,11 @@ async function runWorker(args2) {
|
|
|
11551
11695
|
}
|
|
11552
11696
|
let configured = false;
|
|
11553
11697
|
const saveSelection = (selection) => {
|
|
11554
|
-
if (validating || !configured) return;
|
|
11555
|
-
const
|
|
11556
|
-
if (
|
|
11698
|
+
if (validating || !configured || !agentRun) return;
|
|
11699
|
+
const w = files.worker(id);
|
|
11700
|
+
if (w.generation === generation && !w.stop) agentRun.setSelection(selection);
|
|
11557
11701
|
};
|
|
11558
|
-
const connection = await openAcp(prepared.command, d.
|
|
11702
|
+
const connection = await openAcp(prepared.command, d.workspace, prepared.env, {
|
|
11559
11703
|
selection: saveSelection,
|
|
11560
11704
|
update(update) {
|
|
11561
11705
|
if (update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") {
|
|
@@ -11609,12 +11753,10 @@ async function runWorker(args2) {
|
|
|
11609
11753
|
return;
|
|
11610
11754
|
}
|
|
11611
11755
|
if (reference.sessionId === null) await connection.configure(d.options);
|
|
11612
|
-
|
|
11613
|
-
|
|
11614
|
-
|
|
11615
|
-
|
|
11616
|
-
capabilities: connection.capabilities
|
|
11617
|
-
}, acpReference);
|
|
11756
|
+
const currentWorker = files.worker(id);
|
|
11757
|
+
requireThat(currentWorker.generation === generation && !currentWorker.stop, "ACP \u542F\u52A8\u5DF2\u53D6\u6D88\u3002");
|
|
11758
|
+
let sessionId = harness.eagerSessionId || reference.sessionId !== null ? connection.sessionId : null;
|
|
11759
|
+
agentRun.setSession(sessionId, connection.capabilities);
|
|
11618
11760
|
configured = true;
|
|
11619
11761
|
saveSelection(connection.selection());
|
|
11620
11762
|
let promptInjected = reference.sessionId !== null || connection.systemPrompt;
|
|
@@ -11624,15 +11766,17 @@ async function runWorker(args2) {
|
|
|
11624
11766
|
const effective = !exactAnswer && prompt && !promptInjected ? { ...request, message: prompt + "\n\n---\n\n" + request.message } : request;
|
|
11625
11767
|
promptInjected = true;
|
|
11626
11768
|
const content = await acpContent(effective, connection.images, connection.signal);
|
|
11627
|
-
const
|
|
11628
|
-
requireThat(
|
|
11769
|
+
const w = files.worker(id);
|
|
11770
|
+
requireThat(w.generation === generation && !w.stop, "ACP \u8F93\u5165\u5DF2\u53D6\u6D88\u6216\u542F\u52A8\u4EE3\u6B21\u53D8\u5316\u3002");
|
|
11629
11771
|
connection.signal.throwIfAborted();
|
|
11630
|
-
|
|
11631
|
-
|
|
11772
|
+
if (sessionId === null) {
|
|
11773
|
+
sessionId = connection.sessionId;
|
|
11774
|
+
agentRun.setSession(sessionId, connection.capabilities);
|
|
11775
|
+
}
|
|
11632
11776
|
return connection.prompt(content);
|
|
11633
11777
|
},
|
|
11634
11778
|
cancel: () => connection.cancel()
|
|
11635
|
-
}, exactAnswer);
|
|
11779
|
+
}, exactAnswer, agentRun);
|
|
11636
11780
|
await execution.run();
|
|
11637
11781
|
} finally {
|
|
11638
11782
|
try {
|
|
@@ -11644,18 +11788,19 @@ async function runWorker(args2) {
|
|
|
11644
11788
|
}
|
|
11645
11789
|
try {
|
|
11646
11790
|
await main();
|
|
11647
|
-
if (!validating && files.
|
|
11648
|
-
|
|
11649
|
-
|
|
11791
|
+
if (!validating && files.worker(id).generation === generation) {
|
|
11792
|
+
agentRun.save({ state: "stopped", activity: "\u5DF2\u505C\u6B62" });
|
|
11793
|
+
files.clearTransient(id);
|
|
11650
11794
|
}
|
|
11651
11795
|
} catch (error2) {
|
|
11652
11796
|
if (validating) {
|
|
11653
11797
|
await sendIpc({ type: "error", error: errorMessage(error2) });
|
|
11654
|
-
} else if (files.
|
|
11655
|
-
const stopped = files.
|
|
11798
|
+
} else if (files.worker(id).generation === generation) {
|
|
11799
|
+
const stopped = files.worker(id).stop;
|
|
11656
11800
|
const patch = { state: stopped ? "stopped" : "error", activity: stopped ? "\u5DF2\u505C\u6B62" : "ACP \u6267\u884C\u5931\u8D25", ...stopped ? {} : { error: errorMessage(error2) } };
|
|
11657
|
-
if (
|
|
11658
|
-
else files.write(id, "
|
|
11801
|
+
if (agentRun) agentRun.save(patch);
|
|
11802
|
+
else files.write(id, "state.json", { generation, ...patch, updatedAt: Date.now() }, status);
|
|
11803
|
+
if (stopped) files.clearTransient(id);
|
|
11659
11804
|
}
|
|
11660
11805
|
process.exitCode = 1;
|
|
11661
11806
|
} finally {
|