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