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
|
@@ -4,8 +4,8 @@ import { resolve } from "node:path";
|
|
|
4
4
|
import { object } from "../../common/json.js";
|
|
5
5
|
import { packageVersion, releaseLine } from "../../common/version.js";
|
|
6
6
|
import { requireThat } from "../../common/validation.js";
|
|
7
|
-
import { AgentFiles,
|
|
8
|
-
import {
|
|
7
|
+
import { AgentFiles, outputRecord, status, toDescriptor, workerRecord } from "../../storage/agent-files.js";
|
|
8
|
+
import { acpInteractionReply } from "../../storage/acp-files.js";
|
|
9
9
|
/** Host-neutral lifecycle manager for cross-harness ACP workers. */
|
|
10
10
|
export class AgentService {
|
|
11
11
|
root;
|
|
@@ -24,59 +24,56 @@ export class AgentService {
|
|
|
24
24
|
}
|
|
25
25
|
alive(id) { return this.#starting.has(id) || this.#releasing.has(id) || this.host.alive(id); }
|
|
26
26
|
check() { requireThat(!this.#closed, "worker 服务已关闭。"); }
|
|
27
|
-
owned(
|
|
28
|
-
return
|
|
27
|
+
owned(w, owner) {
|
|
28
|
+
return w.workspace === this.root && w.parentSessionId === owner.sessionId;
|
|
29
29
|
}
|
|
30
30
|
get(id, owner) {
|
|
31
31
|
this.check();
|
|
32
|
-
const
|
|
33
|
-
requireThat(this.owned(
|
|
34
|
-
requireThat(releaseLine(
|
|
35
|
-
return
|
|
32
|
+
const w = this.files.worker(id);
|
|
33
|
+
requireThat(this.owned(w, owner), "worker 不属于当前会话。");
|
|
34
|
+
requireThat(releaseLine(w.release) === releaseLine(packageVersion), "worker 版本不兼容;请停止后使用匹配版本。");
|
|
35
|
+
return w;
|
|
36
36
|
}
|
|
37
37
|
records(owner) {
|
|
38
38
|
this.check();
|
|
39
|
-
return this.files.list().filter(
|
|
40
|
-
releaseLine(
|
|
39
|
+
return this.files.list().filter(w => w.workspace === this.root && w.parentSessionId === owner.sessionId &&
|
|
40
|
+
releaseLine(w.release) === releaseLine(packageVersion));
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
has(id, owner) {
|
|
43
|
+
if (this.#closed)
|
|
44
|
+
return false;
|
|
45
|
+
const w = this.files.optional(id, "worker.json", workerRecord);
|
|
46
|
+
return Boolean(w && this.owned(w, owner) && releaseLine(w.release) === releaseLine(packageVersion));
|
|
47
|
+
}
|
|
48
|
+
list(owner) { return this.records(owner).map(w => this.view(w, owner)); }
|
|
49
|
+
view(w, owner) {
|
|
50
|
+
const saved = this.files.optional(w.agentId, "state.json", status);
|
|
51
|
+
const current = saved?.generation === w.generation ? saved : undefined;
|
|
52
|
+
const alive = this.alive(w.agentId), pending = this.#starting.get(w.agentId);
|
|
48
53
|
const starting = pending && !pending.controller.signal.aborted;
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
...this.files.pendingPermissions(d.agentId, run.generation)
|
|
59
|
-
.map(item => ({ requestId: item.requestId, kind: "permission", description: item.description, options: item.options })),
|
|
60
|
-
...this.files.pendingElicitations(d.agentId, run.generation)
|
|
61
|
-
.map(item => (item.mode === "form"
|
|
62
|
-
? { requestId: item.requestId, kind: "form", message: item.message, schema: item.schema ?? { type: "object", properties: {} } }
|
|
63
|
-
: { requestId: item.requestId, kind: "url", message: item.message, url: item.url ?? "" })),
|
|
64
|
-
] : [];
|
|
54
|
+
const selection = current?.selection && Object.keys(current.selection).length ? current.selection : undefined;
|
|
55
|
+
const pendingRequests = alive
|
|
56
|
+
? this.files.pendingInteractions(w.agentId, w.generation).map(item => (item.kind === "permission"
|
|
57
|
+
? { requestId: item.requestId, kind: "permission", description: item.description, options: item.options }
|
|
58
|
+
: item.kind === "form"
|
|
59
|
+
? { requestId: item.requestId, kind: "form", message: item.message, schema: item.schema }
|
|
60
|
+
: { requestId: item.requestId, kind: "url", message: item.message, url: item.url }))
|
|
61
|
+
: [];
|
|
62
|
+
const capabilities = saved?.capabilities;
|
|
65
63
|
return {
|
|
66
|
-
...
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
owned: this.owned(d, owner),
|
|
64
|
+
...toDescriptor(w),
|
|
65
|
+
generation: w.generation,
|
|
66
|
+
owned: this.owned(w, owner),
|
|
70
67
|
alive,
|
|
71
|
-
backend:
|
|
68
|
+
backend: w.acp.backend,
|
|
72
69
|
transport: "acp",
|
|
73
70
|
capabilities: {
|
|
74
71
|
steer: false,
|
|
75
|
-
resume: Boolean(
|
|
72
|
+
resume: Boolean(capabilities?.resume || capabilities?.load),
|
|
76
73
|
transcript: false,
|
|
77
74
|
},
|
|
78
75
|
...(selection ? { selection } : {}),
|
|
79
|
-
state: alive ? starting ? "starting" :
|
|
76
|
+
state: alive ? starting ? "starting" : w.stop || pending?.controller.signal.aborted ? "stopping" : current?.state ?? "starting" : current?.state === "error" ? "error" : "stopped",
|
|
80
77
|
activity: starting ? "启动" : alive ? current?.activity ?? "启动" : current?.error ?? "已停止",
|
|
81
78
|
...(current?.cycle ? { cycle: current.cycle } : {}),
|
|
82
79
|
...(current?.error ? { error: current.error } : {}),
|
|
@@ -85,17 +82,18 @@ export class AgentService {
|
|
|
85
82
|
}
|
|
86
83
|
/** Answer a pending permission or elicitation request forwarded by the worker. */
|
|
87
84
|
respond(id, input, owner) {
|
|
88
|
-
const
|
|
89
|
-
const pending = this.view(
|
|
85
|
+
const w = this.get(id, owner);
|
|
86
|
+
const pending = this.view(w, owner).pendingRequests ?? [];
|
|
90
87
|
if (!input.requestId && pending.length > 1) {
|
|
91
88
|
throw new Error("存在多条待回复请求,请指定 requestId:" + pending.map(item => item.requestId).join(", "));
|
|
92
89
|
}
|
|
93
90
|
const target = input.requestId ? pending.find(item => item.requestId === input.requestId) : pending[0];
|
|
94
91
|
requireThat(target, input.requestId
|
|
95
|
-
?
|
|
92
|
+
? `没有待回复的请求 ${input.requestId}。用 worker_discover 查询 target="workers"、workerId="${id}" 的当前请求。`
|
|
96
93
|
: "当前没有待回复的请求。");
|
|
94
|
+
this.files.ensureSubdirectory(id, "interactions");
|
|
97
95
|
if (target.kind === "permission") {
|
|
98
|
-
requireThat(input.content === undefined, "
|
|
96
|
+
requireThat(input.content === undefined, "请移除 content。权限请求用 action 回复,选择具体权限范围时加上 optionId。");
|
|
99
97
|
let resolved = null;
|
|
100
98
|
if (input.action === "cancel") {
|
|
101
99
|
requireThat(input.optionId === undefined, "action 为 cancel 时不能同时指定 optionId。");
|
|
@@ -125,9 +123,8 @@ export class AgentService {
|
|
|
125
123
|
resolved = pick("reject_once", "reject_always") ?? null;
|
|
126
124
|
}
|
|
127
125
|
}
|
|
128
|
-
this.files.
|
|
129
|
-
this.
|
|
130
|
-
return this.view(d, owner);
|
|
126
|
+
this.files.write(id, "interactions/" + target.requestId + "-reply.json", { generation: w.generation, requestId: target.requestId, kind: "permission", optionId: resolved }, acpInteractionReply, true);
|
|
127
|
+
return this.view(w, owner);
|
|
131
128
|
}
|
|
132
129
|
if (target.kind === "form") {
|
|
133
130
|
requireThat(input.optionId === undefined, "问答/表单请求不使用 optionId;请将答案填入 content。");
|
|
@@ -137,28 +134,28 @@ export class AgentService {
|
|
|
137
134
|
else {
|
|
138
135
|
requireThat(input.content === undefined || object(input.content), "问答/表单答复的 content 必须是对象。");
|
|
139
136
|
}
|
|
140
|
-
this.files.
|
|
141
|
-
|
|
142
|
-
generation: run.generation,
|
|
137
|
+
this.files.write(id, "interactions/" + target.requestId + "-reply.json", {
|
|
138
|
+
generation: w.generation,
|
|
143
139
|
requestId: target.requestId,
|
|
140
|
+
kind: "form",
|
|
144
141
|
action: input.action,
|
|
145
142
|
...(input.action === "accept" ? { content: input.content ?? {} } : {}),
|
|
146
|
-
},
|
|
147
|
-
return this.view(
|
|
143
|
+
}, acpInteractionReply, true);
|
|
144
|
+
return this.view(w, owner);
|
|
148
145
|
}
|
|
149
146
|
requireThat(input.optionId === undefined, "URL 确认请求不使用 optionId。");
|
|
150
147
|
requireThat(input.content === undefined, "URL 确认请求不使用 content。");
|
|
151
|
-
this.files.
|
|
152
|
-
|
|
153
|
-
generation: run.generation,
|
|
148
|
+
this.files.write(id, "interactions/" + target.requestId + "-reply.json", {
|
|
149
|
+
generation: w.generation,
|
|
154
150
|
requestId: target.requestId,
|
|
151
|
+
kind: "url",
|
|
155
152
|
action: input.action,
|
|
156
|
-
},
|
|
157
|
-
return this.view(
|
|
153
|
+
}, acpInteractionReply, true);
|
|
154
|
+
return this.view(w, owner);
|
|
158
155
|
}
|
|
159
156
|
async start(input, owner) {
|
|
160
157
|
this.check();
|
|
161
|
-
const { backend, ...supplied } = input;
|
|
158
|
+
const { backend, message: initialMessage, files: initialFiles, ...supplied } = input;
|
|
162
159
|
this.host.available(backend);
|
|
163
160
|
const clean = Object.fromEntries(Object.entries(supplied).filter(([, v]) => v !== undefined));
|
|
164
161
|
const options = this.host.filterOptions ? this.host.filterOptions(backend, clean) : clean;
|
|
@@ -166,21 +163,26 @@ export class AgentService {
|
|
|
166
163
|
const prepared = this.files.control(() => {
|
|
167
164
|
requireThat(this.list(owner).filter(v => v.alive).length < 50, "最多 50 个存活或启动中 worker;请先停止一个空闲会话。");
|
|
168
165
|
const agentId = randomUUID();
|
|
169
|
-
const
|
|
170
|
-
const files = (options.files ?? []).map(p => realpathSync(resolve(this.root, p)));
|
|
166
|
+
const files = (initialFiles ?? []).map(p => realpathSync(resolve(this.root, p)));
|
|
171
167
|
const d = {
|
|
172
|
-
agentId,
|
|
173
|
-
|
|
168
|
+
agentId,
|
|
169
|
+
release: packageVersion,
|
|
170
|
+
workspace: this.root,
|
|
171
|
+
parentSessionId: owner.sessionId,
|
|
172
|
+
options,
|
|
174
173
|
};
|
|
175
|
-
const run = { generation: randomUUID(),
|
|
174
|
+
const run = { generation: randomUUID(), sequence: 0, stop: false, startedAt: Date.now() };
|
|
176
175
|
this.files.create(d, run, reference);
|
|
177
|
-
const initial =
|
|
176
|
+
const initial = initialMessage ?? "";
|
|
178
177
|
const request = initial || files.length ? this.files.enqueue(agentId, initial, "steer", files) : undefined;
|
|
179
178
|
this.#starting.set(agentId, { generation: run.generation, controller: new AbortController(), stage: "launch" });
|
|
180
179
|
return { d, run, request };
|
|
181
180
|
});
|
|
182
181
|
await this.launch(prepared.d, prepared.run.generation);
|
|
183
|
-
return {
|
|
182
|
+
return {
|
|
183
|
+
...this.view(this.files.worker(prepared.d.agentId), owner),
|
|
184
|
+
...(prepared.request ? { requestId: prepared.request.requestId, messageStatus: "queued" } : {}),
|
|
185
|
+
};
|
|
184
186
|
}
|
|
185
187
|
async launch(d, generation, resume = false) {
|
|
186
188
|
const pending = this.#starting.get(d.agentId);
|
|
@@ -190,17 +192,23 @@ export class AgentService {
|
|
|
190
192
|
await this.host.launch(d, this.files.directory(d.agentId), generation, this.files.reference(d.agentId), resume, pending.controller.signal);
|
|
191
193
|
requireThat(!this.#closed || this.#preserve, "worker 服务已关闭。");
|
|
192
194
|
pending.controller.signal.throwIfAborted();
|
|
193
|
-
const
|
|
194
|
-
requireThat(
|
|
195
|
+
const w = this.files.worker(d.agentId);
|
|
196
|
+
requireThat(w.generation === generation && !w.stop, "worker 启动已取消或代次变化。");
|
|
195
197
|
}
|
|
196
198
|
catch (error) {
|
|
197
|
-
const
|
|
198
|
-
if (
|
|
199
|
+
const w = this.files.worker(d.agentId);
|
|
200
|
+
if (w.generation === generation) {
|
|
199
201
|
if (this.host.alive(d.agentId))
|
|
200
202
|
await this.release(d.agentId);
|
|
201
|
-
this.files.
|
|
202
|
-
|
|
203
|
-
|
|
203
|
+
const existing = this.files.optional(d.agentId, "state.json", status);
|
|
204
|
+
this.files.write(d.agentId, "state.json", {
|
|
205
|
+
generation,
|
|
206
|
+
state: w.stop ? "stopped" : "error",
|
|
207
|
+
activity: w.stop ? "已停止" : "启动失败",
|
|
208
|
+
updatedAt: Date.now(),
|
|
209
|
+
...(existing?.sessionId !== undefined ? { sessionId: existing.sessionId } : {}),
|
|
210
|
+
...(existing?.capabilities ? { capabilities: existing.capabilities } : {}),
|
|
211
|
+
...(w.stop ? {} : { error: String(error) }),
|
|
204
212
|
}, status);
|
|
205
213
|
}
|
|
206
214
|
throw error;
|
|
@@ -219,49 +227,40 @@ export class AgentService {
|
|
|
219
227
|
}
|
|
220
228
|
}
|
|
221
229
|
send(id, text, delivery, owner, attachments = []) {
|
|
222
|
-
const
|
|
230
|
+
const w = this.get(id, owner);
|
|
223
231
|
return this.files.control(() => {
|
|
224
|
-
|
|
225
|
-
|
|
232
|
+
const latest = this.files.worker(id);
|
|
233
|
+
requireThat(this.alive(id) && this.#starting.get(id)?.stage !== "validate" && !latest.stop, "worker 已停止或仍在恢复校验,请等待显式恢复完成。");
|
|
234
|
+
const view = this.view(latest, owner);
|
|
226
235
|
requireThat(!(delivery === "steer" && view.state !== "idle"), "该 ACP worker 运行中不支持 steer;请用 delivery: followUp 排队。");
|
|
227
236
|
const files = attachments.map(path => realpathSync(resolve(this.root, path)));
|
|
228
237
|
const request = this.files.enqueue(id, text, delivery, files);
|
|
229
|
-
return { ...this.view(
|
|
238
|
+
return { ...this.view(this.files.worker(w.agentId), owner), requestId: request.requestId, messageStatus: "queued" };
|
|
230
239
|
});
|
|
231
240
|
}
|
|
232
|
-
rename(id, name, owner) {
|
|
233
|
-
requireThat(name.trim().length > 0 && name.length <= 64 && !/[\x00-\x1f]/.test(name), "名称必须是 1 到 64 字符的单行文本。");
|
|
234
|
-
const d = this.get(id, owner);
|
|
235
|
-
this.files.control(() => { const run = this.files.read(id, "launch.json", launch); run.name = name; this.files.write(id, "launch.json", run, launch); });
|
|
236
|
-
return this.view(d, owner);
|
|
237
|
-
}
|
|
238
241
|
stop(id, owner) {
|
|
239
|
-
|
|
242
|
+
this.get(id, owner);
|
|
240
243
|
this.requestStop(id);
|
|
241
|
-
return this.view(
|
|
244
|
+
return this.view(this.files.worker(id), owner);
|
|
242
245
|
}
|
|
243
246
|
requestStop(id) {
|
|
244
|
-
this.files.control(() => {
|
|
247
|
+
this.files.control(() => {
|
|
248
|
+
const w = this.files.worker(id);
|
|
249
|
+
w.stop = true;
|
|
250
|
+
this.files.write(id, "worker.json", w, workerRecord);
|
|
251
|
+
});
|
|
245
252
|
this.#starting.get(id)?.controller.abort();
|
|
246
253
|
}
|
|
247
|
-
async enter(id, owner) {
|
|
248
|
-
const d = this.get(id, owner);
|
|
249
|
-
if (this.alive(id)) {
|
|
250
|
-
requireThat(!this.files.read(id, "launch.json", launch).stop, "worker 正在停止,请稍后操作。");
|
|
251
|
-
return this.view(d, owner);
|
|
252
|
-
}
|
|
253
|
-
return this.restart(id, owner);
|
|
254
|
-
}
|
|
255
254
|
resume(id, text, owner) {
|
|
256
255
|
return this.restart(id, owner, text);
|
|
257
256
|
}
|
|
258
257
|
async restart(id, owner, text) {
|
|
259
|
-
const
|
|
258
|
+
const w = this.get(id, owner), d = toDescriptor(w), reference = this.files.reference(id);
|
|
260
259
|
this.host.available(reference.backend);
|
|
261
260
|
const reserved = this.files.control(() => {
|
|
262
261
|
requireThat(!this.alive(id), "worker 仍在运行。");
|
|
263
262
|
requireThat(this.list(owner).filter(v => v.alive).length < 50, "最多 50 个存活或启动中 worker。");
|
|
264
|
-
const previous = this.files.
|
|
263
|
+
const previous = this.files.worker(id), interrupted = this.cycles(id, owner);
|
|
265
264
|
const pending = { generation: previous.generation, controller: new AbortController(), stage: "validate" };
|
|
266
265
|
this.#starting.set(id, pending);
|
|
267
266
|
return { previous, interrupted, pending };
|
|
@@ -271,21 +270,41 @@ export class AgentService {
|
|
|
271
270
|
requireThat(!this.#closed || this.#preserve, "worker 服务已关闭。");
|
|
272
271
|
reserved.pending.controller.signal.throwIfAborted();
|
|
273
272
|
const prepared = this.files.control(() => {
|
|
274
|
-
requireThat(!this.host.alive(id) && this.files.
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
273
|
+
requireThat(!this.host.alive(id) && this.files.worker(id).generation === reserved.previous.generation, "worker 已由其他操作恢复。");
|
|
274
|
+
const existingOutput = this.files.output(id);
|
|
275
|
+
const lastInterrupted = reserved.interrupted.findLast(ended => ended.generation === reserved.previous.generation && existingOutput?.cycleId !== ended.cycleId);
|
|
276
|
+
if (lastInterrupted && lastInterrupted.state !== "running") {
|
|
277
|
+
this.files.write(id, "output.json", {
|
|
278
|
+
cycleId: lastInterrupted.cycleId,
|
|
279
|
+
generation: lastInterrupted.generation,
|
|
280
|
+
startedAt: lastInterrupted.startedAt,
|
|
281
|
+
finishedAt: lastInterrupted.finishedAt ?? Date.now(),
|
|
282
|
+
state: lastInterrupted.state,
|
|
283
|
+
requestIds: lastInterrupted.requestIds,
|
|
284
|
+
text: "",
|
|
285
|
+
...(lastInterrupted.error ? { error: lastInterrupted.error } : {}),
|
|
286
|
+
}, outputRecord);
|
|
279
287
|
}
|
|
280
|
-
|
|
281
|
-
|
|
288
|
+
this.files.clearTransient(id);
|
|
289
|
+
const next = {
|
|
290
|
+
...reserved.previous,
|
|
291
|
+
generation: randomUUID(),
|
|
292
|
+
sequence: 0,
|
|
293
|
+
stop: false,
|
|
294
|
+
startedAt: Date.now(),
|
|
295
|
+
};
|
|
296
|
+
delete next.pid;
|
|
297
|
+
this.files.write(id, "worker.json", next, workerRecord);
|
|
282
298
|
const request = text === undefined ? undefined : this.files.enqueue(id, text, "steer");
|
|
283
|
-
reserved.pending.generation =
|
|
299
|
+
reserved.pending.generation = next.generation;
|
|
284
300
|
reserved.pending.stage = "launch";
|
|
285
|
-
return { run, request };
|
|
301
|
+
return { run: next, request };
|
|
286
302
|
});
|
|
287
303
|
await this.launch(d, prepared.run.generation, true);
|
|
288
|
-
return {
|
|
304
|
+
return {
|
|
305
|
+
...this.view(this.files.worker(id), owner),
|
|
306
|
+
...(prepared.request ? { requestId: prepared.request.requestId, messageStatus: "queued" } : {}),
|
|
307
|
+
};
|
|
289
308
|
})();
|
|
290
309
|
this.#launches.add(operation);
|
|
291
310
|
try {
|
|
@@ -302,24 +321,48 @@ export class AgentService {
|
|
|
302
321
|
}
|
|
303
322
|
cyclesFor(view) {
|
|
304
323
|
const id = view.agentId;
|
|
305
|
-
const values =
|
|
324
|
+
const values = [];
|
|
325
|
+
const output = this.files.output(id);
|
|
326
|
+
if (output) {
|
|
327
|
+
values.push({
|
|
328
|
+
cycleId: output.cycleId,
|
|
329
|
+
generation: output.generation,
|
|
330
|
+
startedAt: output.startedAt,
|
|
331
|
+
finishedAt: output.finishedAt,
|
|
332
|
+
state: output.state,
|
|
333
|
+
requestIds: output.requestIds,
|
|
334
|
+
...(output.error ? { error: output.error } : {}),
|
|
335
|
+
});
|
|
336
|
+
}
|
|
306
337
|
if (view.cycle && !values.some(c => c.cycleId === view.cycle.cycleId)) {
|
|
307
|
-
values.push(view.state === "stopped" || view.state === "error"
|
|
338
|
+
values.push(view.state === "stopped" || view.state === "error"
|
|
339
|
+
? { ...view.cycle, state: "interrupted", finishedAt: view.cycle.finishedAt ?? Date.now() }
|
|
340
|
+
: view.cycle);
|
|
308
341
|
}
|
|
309
342
|
if (["stopped", "error"].includes(view.state)) {
|
|
310
|
-
const
|
|
311
|
-
for (const requestId of saved?.generation ===
|
|
312
|
-
if (values.some(c => c.generation ===
|
|
343
|
+
const w = this.files.worker(id), saved = this.files.optional(id, "state.json", status);
|
|
344
|
+
for (const requestId of saved?.generation === w.generation ? saved.accepted ?? [] : []) {
|
|
345
|
+
if (values.some(c => c.generation === w.generation && c.requestIds.includes(requestId)))
|
|
313
346
|
continue;
|
|
314
347
|
values.push({
|
|
315
|
-
cycleId: requestId,
|
|
316
|
-
|
|
348
|
+
cycleId: requestId,
|
|
349
|
+
generation: w.generation,
|
|
350
|
+
startedAt: w.startedAt,
|
|
351
|
+
finishedAt: Date.now(),
|
|
352
|
+
state: "interrupted",
|
|
353
|
+
requestIds: [requestId],
|
|
354
|
+
error: "领取后执行结果不明;未重跑。",
|
|
317
355
|
});
|
|
318
356
|
}
|
|
319
|
-
if (
|
|
357
|
+
if (w.sequence > 0 && !values.some(c => c.generation === view.generation)) {
|
|
320
358
|
values.push({
|
|
321
|
-
cycleId:
|
|
322
|
-
|
|
359
|
+
cycleId: w.generation,
|
|
360
|
+
generation: w.generation,
|
|
361
|
+
startedAt: w.startedAt,
|
|
362
|
+
finishedAt: w.startedAt,
|
|
363
|
+
state: "interrupted",
|
|
364
|
+
requestIds: [],
|
|
365
|
+
error: view.error ?? "子进程在交付前退出。",
|
|
323
366
|
});
|
|
324
367
|
}
|
|
325
368
|
}
|
|
@@ -345,14 +388,15 @@ export class AgentService {
|
|
|
345
388
|
return { current, cycle, terminal };
|
|
346
389
|
}
|
|
347
390
|
async read(id, owner, cycleId, offset = 0, limit = 16000) {
|
|
348
|
-
const
|
|
391
|
+
const w = this.get(id, owner), cycles = this.cycles(id, owner);
|
|
349
392
|
const c = cycleId ? cycles.find(v => v.cycleId === cycleId) : cycles.at(-1);
|
|
350
393
|
requireThat(!cycleId || c, "周期不存在。");
|
|
351
|
-
const
|
|
394
|
+
const output = this.files.output(id);
|
|
395
|
+
const report = c && output?.cycleId === c.cycleId ? output.text : "";
|
|
352
396
|
this.check();
|
|
353
397
|
requireThat(offset <= report.length, "分页位置超出报告。");
|
|
354
398
|
return {
|
|
355
|
-
...this.view(
|
|
399
|
+
...this.view(w, owner),
|
|
356
400
|
...(c ? { cycle: c } : {}),
|
|
357
401
|
cycles: cycles.map(v => ({ cycleId: v.cycleId, state: v.state })),
|
|
358
402
|
report: report.slice(offset, offset + limit),
|
|
@@ -360,18 +404,15 @@ export class AgentService {
|
|
|
360
404
|
nextOffset: offset + limit < report.length ? offset + limit : null,
|
|
361
405
|
};
|
|
362
406
|
}
|
|
363
|
-
report(d, c) {
|
|
364
|
-
if (c.leaf === null)
|
|
365
|
-
return "";
|
|
366
|
-
return this.host.report(d, this.files.reference(d.agentId), c.leaf);
|
|
367
|
-
}
|
|
368
407
|
release(id) {
|
|
369
408
|
let pending = this.#releasing.get(id);
|
|
370
409
|
if (!pending) {
|
|
371
|
-
const generation = this.files.
|
|
410
|
+
const generation = this.files.worker(id).generation;
|
|
372
411
|
pending = Promise.resolve().then(async () => {
|
|
373
|
-
if (this.files.
|
|
412
|
+
if (this.files.worker(id).generation === generation) {
|
|
374
413
|
await this.host.release(id, generation);
|
|
414
|
+
this.files.clearTransient(id);
|
|
415
|
+
}
|
|
375
416
|
}).finally(() => this.#releasing.delete(id));
|
|
376
417
|
this.#releasing.set(id, pending);
|
|
377
418
|
}
|
|
@@ -383,11 +424,12 @@ export class AgentService {
|
|
|
383
424
|
async dispose(owner, preserve = false) {
|
|
384
425
|
if (this.#closed)
|
|
385
426
|
return;
|
|
386
|
-
const
|
|
427
|
+
const ownedRecords = !preserve && owner ? this.records(owner) : [];
|
|
428
|
+
const aliveIds = ownedRecords.filter(w => this.alive(w.agentId)).map(w => w.agentId);
|
|
387
429
|
this.#closed = true;
|
|
388
430
|
this.#preserve = preserve;
|
|
389
431
|
const errors = [];
|
|
390
|
-
for (const id of
|
|
432
|
+
for (const id of aliveIds) {
|
|
391
433
|
try {
|
|
392
434
|
this.requestStop(id);
|
|
393
435
|
}
|
|
@@ -399,13 +441,25 @@ export class AgentService {
|
|
|
399
441
|
for (const pending of this.#starting.values())
|
|
400
442
|
pending.controller.abort();
|
|
401
443
|
const deadline = Date.now() + 5000;
|
|
402
|
-
while (
|
|
444
|
+
while (aliveIds.some(id => this.alive(id)) && Date.now() < deadline)
|
|
403
445
|
await new Promise(r => setTimeout(r, 100));
|
|
404
|
-
const released = await Promise.allSettled(
|
|
446
|
+
const released = await Promise.allSettled(aliveIds.filter(id => this.host.alive(id)).map(id => this.release(id)));
|
|
405
447
|
for (const value of released)
|
|
406
448
|
if (value.status === "rejected")
|
|
407
449
|
errors.push(value.reason);
|
|
408
450
|
await Promise.allSettled([...this.#launches]);
|
|
451
|
+
if (!preserve && owner) {
|
|
452
|
+
for (const w of ownedRecords) {
|
|
453
|
+
if (!this.host.alive(w.agentId)) {
|
|
454
|
+
try {
|
|
455
|
+
this.files.removeWorker(w.agentId);
|
|
456
|
+
}
|
|
457
|
+
catch (error) {
|
|
458
|
+
errors.push(error);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
409
463
|
if (errors.length)
|
|
410
464
|
throw new AggregateError(errors, "停止或释放 worker 失败;请核对仍存活的执行资源。");
|
|
411
465
|
}
|
|
@@ -45,7 +45,7 @@ function formatSessionSummaries(summaries) {
|
|
|
45
45
|
export const monthlySummaryDimension = {
|
|
46
46
|
id: "monthly",
|
|
47
47
|
title: "月度历史汇总",
|
|
48
|
-
description: "
|
|
48
|
+
description: "按会话开始的 UTC 月份汇总会话摘要,可从月度结果查回各会话。",
|
|
49
49
|
requiresMonthlyLayout: true,
|
|
50
50
|
plan(_raws, existing, options = {}) {
|
|
51
51
|
const force = Boolean(options.force);
|
|
@@ -32,7 +32,7 @@ function isStrictUnchangedPrefix(existing, ordered) {
|
|
|
32
32
|
export const sessionSummaryDimension = {
|
|
33
33
|
id: "session",
|
|
34
34
|
title: "会话任务摘要",
|
|
35
|
-
description: "
|
|
35
|
+
description: "汇总单次会话的目标、决定、结果和未决事项。",
|
|
36
36
|
plan(raws, existing, options = {}) {
|
|
37
37
|
const force = Boolean(options.force);
|
|
38
38
|
const tasks = [];
|
|
@@ -95,9 +95,12 @@ export const sessionSummaryDimension = {
|
|
|
95
95
|
...heading,
|
|
96
96
|
`【已有摘要(${task.existing.from} — ${task.existing.to})】\n${task.existing.text}`,
|
|
97
97
|
`【新增对话】\n${formatExchanges(task.addedExchanges)}`,
|
|
98
|
-
"在已有摘要基础上合并新增对话,输出更新后的完整摘要:保留仍有效的事实,用新决定覆盖旧决定,去重并保持简洁。",
|
|
99
98
|
].join("\n\n");
|
|
100
|
-
return {
|
|
99
|
+
return {
|
|
100
|
+
system: system + "\n合并已有摘要与新增对话,输出完整摘要。保留仍有效的事实,用后续明确的决定更新相应结论。",
|
|
101
|
+
prompt,
|
|
102
|
+
maxTokens: 2048,
|
|
103
|
+
};
|
|
101
104
|
}
|
|
102
105
|
const prompt = [
|
|
103
106
|
...heading,
|
|
@@ -67,9 +67,9 @@ function evaluateSummaryReminder(raws, allSummaries, pendingCount, options = {})
|
|
|
67
67
|
return undefined;
|
|
68
68
|
const rawAgeDays = Math.floor((nowMs - oldestRawMs) / dayMs);
|
|
69
69
|
const daysSinceLastSummary = latestSummaryMs === undefined ? undefined : Math.floor((nowMs - latestSummaryMs) / dayMs);
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
const lastUpdate = daysSinceLastSummary === undefined ? "尚无摘要" : `上次更新摘要在 ${daysSinceLastSummary} 天前`;
|
|
71
|
+
const message = `工作区已积累 ${rawAgeDays} 天的历史,${lastUpdate},${pendingCount} 项待摘要。` +
|
|
72
|
+
"可在工作区根目录运行 pbot history summary,或在 Pi、dsh 会话中输入 /pbot history summary。";
|
|
73
73
|
return {
|
|
74
74
|
rawCount: raws.length,
|
|
75
75
|
pendingCount,
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import type { AcpAnswer,
|
|
1
|
+
import type { AcpAnswer, AcpInput, AcpInteraction, AcpInteractionReply, AcpSessionReference } from "../model/acp.js";
|
|
2
|
+
import type { AgentAcpConfig } from "../model/agent.js";
|
|
3
|
+
export declare function acpConfig(value: unknown): AgentAcpConfig;
|
|
2
4
|
export declare function acpReference(value: unknown): AcpSessionReference;
|
|
3
|
-
export declare function acpModelState(value: unknown): AcpModelState;
|
|
4
|
-
export declare function acpProcess(value: unknown): AcpProcess;
|
|
5
5
|
export declare function acpInput(value: unknown): AcpInput;
|
|
6
6
|
export declare function acpAnswer(value: unknown): AcpAnswer;
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function acpPermissionReply(value: unknown): AcpPermissionReply;
|
|
10
|
-
export declare function acpElicitation(value: unknown): AcpElicitation;
|
|
11
|
-
export declare function acpElicitationReply(value: unknown): AcpElicitationReply;
|
|
7
|
+
export declare function acpInteraction(value: unknown): AcpInteraction;
|
|
8
|
+
export declare function acpInteractionReply(value: unknown): AcpInteractionReply;
|