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
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AgentCycle, AgentDescriptor, AgentMessage, AgentOutput, AgentSessionReference, AgentStatus, AgentWorkerRecord } from "../model/agent.js";
|
|
2
2
|
import type { AcpSessionReference } from "../model/acp.js";
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function launch(v: unknown): AgentLaunch;
|
|
3
|
+
export declare function workerRecord(v: unknown): AgentWorkerRecord;
|
|
5
4
|
export declare function message(v: unknown): AgentMessage;
|
|
6
5
|
export declare function cycle(v: unknown): AgentCycle;
|
|
7
6
|
export declare function status(v: unknown): AgentStatus;
|
|
7
|
+
export declare function outputRecord(v: unknown): AgentOutput;
|
|
8
|
+
export declare function toDescriptor(record: AgentWorkerRecord): AgentDescriptor;
|
|
8
9
|
export declare class AgentFiles {
|
|
9
10
|
#private;
|
|
10
11
|
readonly root: string;
|
|
@@ -15,14 +16,22 @@ export declare class AgentFiles {
|
|
|
15
16
|
read<T>(id: string, path: string, parse: (v: unknown) => T): T;
|
|
16
17
|
optional<T>(id: string, path: string, parse: (v: unknown) => T): T | undefined;
|
|
17
18
|
write<T>(id: string, path: string, value: T, parse: (v: unknown) => T, create?: boolean): void;
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
remove(id: string, path: string): void;
|
|
20
|
+
create(value: AgentDescriptor, run: {
|
|
21
|
+
generation: string;
|
|
22
|
+
sequence: number;
|
|
23
|
+
stop: boolean;
|
|
24
|
+
startedAt: number;
|
|
25
|
+
}, acp: AcpSessionReference): void;
|
|
26
|
+
worker(id: string): AgentWorkerRecord;
|
|
27
|
+
list(): AgentWorkerRecord[];
|
|
20
28
|
messages(id: string): AgentMessage[];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
removeMessage(id: string, requestId: string): void;
|
|
30
|
+
output(id: string): AgentOutput | undefined;
|
|
31
|
+
pendingInteractions(id: string, generation: string): import("../model/acp.js").AcpInteraction[];
|
|
32
|
+
removeInteraction(id: string, requestId: string): void;
|
|
33
|
+
clearTransient(id: string): void;
|
|
34
|
+
removeWorker(id: string): void;
|
|
26
35
|
ensureSubdirectory(id: string, name: string): void;
|
|
27
36
|
reference(id: string): AgentSessionReference;
|
|
28
37
|
/** Short controller edits are serialized; an abandoned lock fails closed. */
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, rmdirSync, rmSync, unlinkSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { canonical, object } from "../common/json.js";
|
|
5
5
|
import { isOneOf, requireThat } from "../common/validation.js";
|
|
6
6
|
import { readJsonFile, writeJsonFile } from "./atomic-json.js";
|
|
7
7
|
import { fileId, privateDirectory } from "./file-access.js";
|
|
8
|
-
import { agentStates,
|
|
9
|
-
import {
|
|
8
|
+
import { agentStates, cycleStates, messageDeliveries } from "../model/agent.js";
|
|
9
|
+
import { acpConfig, acpInteraction, acpReference } from "./acp-files.js";
|
|
10
10
|
const text = (v) => typeof v === "string" && v.length > 0;
|
|
11
11
|
const number = (v) => typeof v === "number" && Number.isFinite(v);
|
|
12
|
-
export function
|
|
13
|
-
requireThat(object(v) && text(v.agentId) && text(v.release) && text(v.workspace) && text(v.
|
|
14
|
-
(v.
|
|
12
|
+
export function workerRecord(v) {
|
|
13
|
+
requireThat(object(v) && text(v.agentId) && text(v.release) && text(v.workspace) && text(v.parentSessionId) &&
|
|
14
|
+
text(v.generation) && Number.isSafeInteger(v.sequence) && typeof v.stop === "boolean" && number(v.startedAt) &&
|
|
15
|
+
(v.pid === undefined || (Number.isSafeInteger(v.pid) && Number(v.pid) > 1)) &&
|
|
16
|
+
(v.options === undefined || object(v.options)), "worker 控制记录无效。");
|
|
15
17
|
fileId(v.agentId);
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
export function launch(v) {
|
|
19
|
-
requireThat(object(v) && text(v.generation) && text(v.name) && Number.isSafeInteger(v.sequence) && typeof v.stop === "boolean" && number(v.startedAt), "子会话启动状态无效。");
|
|
18
|
+
acpConfig(v.acp);
|
|
20
19
|
return v;
|
|
21
20
|
}
|
|
22
21
|
export function message(v) {
|
|
@@ -26,18 +25,72 @@ export function message(v) {
|
|
|
26
25
|
}
|
|
27
26
|
export function cycle(v) {
|
|
28
27
|
requireThat(object(v) && text(v.cycleId) && text(v.generation) && number(v.startedAt) &&
|
|
29
|
-
isOneOf(v.state, cycleStates) &&
|
|
30
|
-
(v.
|
|
31
|
-
|
|
28
|
+
isOneOf(v.state, cycleStates) && Array.isArray(v.requestIds) && v.requestIds.every(text) &&
|
|
29
|
+
(v.finishedAt === undefined || number(v.finishedAt)) &&
|
|
30
|
+
(v.error === undefined || typeof v.error === "string"), "子会话周期无效。");
|
|
32
31
|
return v;
|
|
33
32
|
}
|
|
34
33
|
export function status(v) {
|
|
35
34
|
requireThat(object(v) && text(v.generation) && isOneOf(v.state, agentStates) &&
|
|
36
35
|
typeof v.activity === "string" && number(v.updatedAt), "子会话状态无效。");
|
|
37
|
-
if (v.
|
|
36
|
+
if (v.sessionId !== undefined)
|
|
37
|
+
requireThat(v.sessionId === null || text(v.sessionId), "ACP 会话 ID 无效。");
|
|
38
|
+
if (v.capabilities !== undefined) {
|
|
39
|
+
requireThat(object(v.capabilities) &&
|
|
40
|
+
["resume", "load", "close"].every(key => typeof v.capabilities[key] === "boolean"), "ACP 会话能力无效。");
|
|
41
|
+
}
|
|
42
|
+
if (v.selection !== undefined) {
|
|
43
|
+
requireThat(object(v.selection) &&
|
|
44
|
+
["provider", "model", "resolvedModel", "thinking"].every(key => v.selection[key] === undefined || text(v.selection[key])), "ACP 模型选择无效。");
|
|
45
|
+
}
|
|
46
|
+
if (v.activeRequestId !== undefined) {
|
|
47
|
+
requireThat(text(v.activeRequestId), "ACP 输入关联无效。");
|
|
48
|
+
fileId(v.activeRequestId);
|
|
49
|
+
}
|
|
50
|
+
if (v.accepted !== undefined)
|
|
51
|
+
requireThat(Array.isArray(v.accepted) && v.accepted.every(text), "已领取请求列表无效。");
|
|
52
|
+
if (v.cycle !== undefined)
|
|
38
53
|
cycle(v.cycle);
|
|
54
|
+
if (v.error !== undefined)
|
|
55
|
+
requireThat(typeof v.error === "string", "子会话错误信息无效。");
|
|
56
|
+
return v;
|
|
57
|
+
}
|
|
58
|
+
export function outputRecord(v) {
|
|
59
|
+
requireThat(object(v) && text(v.cycleId) && text(v.generation) && number(v.startedAt) && number(v.finishedAt) &&
|
|
60
|
+
isOneOf(v.state, ["completed", "failed", "cancelled", "interrupted"]) &&
|
|
61
|
+
Array.isArray(v.requestIds) && v.requestIds.every(text) &&
|
|
62
|
+
typeof v.text === "string" && (v.error === undefined || typeof v.error === "string"), "子会话输出记录无效。");
|
|
63
|
+
fileId(v.cycleId);
|
|
39
64
|
return v;
|
|
40
65
|
}
|
|
66
|
+
export function toDescriptor(record) {
|
|
67
|
+
return {
|
|
68
|
+
agentId: record.agentId,
|
|
69
|
+
release: record.release,
|
|
70
|
+
workspace: record.workspace,
|
|
71
|
+
parentSessionId: record.parentSessionId,
|
|
72
|
+
options: record.options ?? {},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function tryUnlink(path) {
|
|
76
|
+
try {
|
|
77
|
+
unlinkSync(path);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (error.code !== "ENOENT")
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function tryRmdir(path) {
|
|
85
|
+
try {
|
|
86
|
+
rmdirSync(path);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
const code = error.code;
|
|
90
|
+
if (code !== "ENOENT" && code !== "ENOTEMPTY" && code !== "EEXIST")
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
41
94
|
export class AgentFiles {
|
|
42
95
|
root;
|
|
43
96
|
#failure;
|
|
@@ -72,56 +125,105 @@ export class AgentFiles {
|
|
|
72
125
|
}
|
|
73
126
|
requireThat(published, "子会话文件已存在。");
|
|
74
127
|
}
|
|
128
|
+
remove(id, path) {
|
|
129
|
+
tryUnlink(join(this.directory(id), path));
|
|
130
|
+
}
|
|
75
131
|
create(value, run, acp) {
|
|
76
132
|
this.check();
|
|
77
133
|
acpReference(acp);
|
|
78
134
|
mkdirSync(this.root, { recursive: true, mode: 0o700 });
|
|
79
135
|
mkdirSync(this.directory(value.agentId), { mode: 0o700 });
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
136
|
+
const hasOptions = Object.keys(value.options).length > 0;
|
|
137
|
+
const record = {
|
|
138
|
+
agentId: value.agentId,
|
|
139
|
+
release: value.release,
|
|
140
|
+
workspace: value.workspace,
|
|
141
|
+
parentSessionId: value.parentSessionId,
|
|
142
|
+
generation: run.generation,
|
|
143
|
+
sequence: run.sequence,
|
|
144
|
+
stop: run.stop,
|
|
145
|
+
startedAt: run.startedAt,
|
|
146
|
+
acp: {
|
|
147
|
+
backend: acp.backend,
|
|
148
|
+
command: acp.command,
|
|
149
|
+
args: acp.args,
|
|
150
|
+
...(acp.env ? { env: acp.env } : {}),
|
|
151
|
+
...(acp.permission ? { permission: acp.permission } : {}),
|
|
152
|
+
},
|
|
153
|
+
...(hasOptions ? { options: value.options } : {}),
|
|
154
|
+
};
|
|
155
|
+
this.write(value.agentId, "worker.json", record, workerRecord, true);
|
|
156
|
+
}
|
|
157
|
+
worker(id) {
|
|
158
|
+
return this.read(id, "worker.json", workerRecord);
|
|
85
159
|
}
|
|
86
160
|
list() {
|
|
87
161
|
if (!existsSync(this.root))
|
|
88
162
|
return [];
|
|
89
163
|
return readdirSync(this.root, { withFileTypes: true }).filter(e => e.isDirectory() && !e.name.startsWith(".")).flatMap(e => {
|
|
90
|
-
const
|
|
91
|
-
return
|
|
164
|
+
const record = this.optional(e.name, "worker.json", workerRecord);
|
|
165
|
+
return record ? [record] : [];
|
|
92
166
|
});
|
|
93
167
|
}
|
|
94
168
|
messages(id) {
|
|
95
|
-
|
|
169
|
+
const dir = join(this.directory(id), "inbox");
|
|
170
|
+
if (!existsSync(dir))
|
|
171
|
+
return [];
|
|
172
|
+
return readdirSync(dir).filter(n => n.endsWith(".json"))
|
|
96
173
|
.map(n => this.read(id, "inbox/" + n, message)).sort((a, b) => a.sequence - b.sequence);
|
|
97
174
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
175
|
+
removeMessage(id, requestId) {
|
|
176
|
+
fileId(requestId);
|
|
177
|
+
const dir = join(this.directory(id), "inbox");
|
|
178
|
+
tryUnlink(join(dir, requestId + ".json"));
|
|
179
|
+
tryRmdir(dir);
|
|
101
180
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const dir = join(this.directory(id), "permissions");
|
|
105
|
-
if (!existsSync(dir))
|
|
106
|
-
return [];
|
|
107
|
-
const names = readdirSync(dir);
|
|
108
|
-
return names.filter(n => n.endsWith(".json") && !n.endsWith("-reply.json") && !names.includes(n.slice(0, -5) + "-reply.json"))
|
|
109
|
-
.map(n => this.read(id, "permissions/" + n, acpPermission)).filter(item => item.generation === generation);
|
|
181
|
+
output(id) {
|
|
182
|
+
return this.optional(id, "output.json", outputRecord);
|
|
110
183
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const dir = join(this.directory(id), "elicitations");
|
|
184
|
+
pendingInteractions(id, generation) {
|
|
185
|
+
const dir = join(this.directory(id), "interactions");
|
|
114
186
|
if (!existsSync(dir))
|
|
115
187
|
return [];
|
|
116
188
|
const names = readdirSync(dir);
|
|
117
189
|
return names.filter(n => n.endsWith(".json") && !n.endsWith("-reply.json") && !names.includes(n.slice(0, -5) + "-reply.json"))
|
|
118
|
-
.map(n => this.read(id, "
|
|
190
|
+
.map(n => this.read(id, "interactions/" + n, acpInteraction)).filter(item => item.generation === generation);
|
|
191
|
+
}
|
|
192
|
+
removeInteraction(id, requestId) {
|
|
193
|
+
fileId(requestId);
|
|
194
|
+
const dir = join(this.directory(id), "interactions");
|
|
195
|
+
tryUnlink(join(dir, requestId + ".json"));
|
|
196
|
+
tryUnlink(join(dir, requestId + "-reply.json"));
|
|
197
|
+
tryRmdir(dir);
|
|
198
|
+
}
|
|
199
|
+
clearTransient(id) {
|
|
200
|
+
const base = this.directory(id);
|
|
201
|
+
if (!existsSync(base))
|
|
202
|
+
return;
|
|
203
|
+
rmSync(join(base, "inbox"), { recursive: true, force: true });
|
|
204
|
+
rmSync(join(base, "interactions"), { recursive: true, force: true });
|
|
205
|
+
tryUnlink(join(base, "acp-answer.json"));
|
|
206
|
+
}
|
|
207
|
+
removeWorker(id) {
|
|
208
|
+
rmSync(this.directory(id), { recursive: true, force: true });
|
|
209
|
+
tryRmdir(this.root);
|
|
119
210
|
}
|
|
120
211
|
ensureSubdirectory(id, name) {
|
|
121
212
|
privateDirectory(this.directory(id), name);
|
|
122
213
|
}
|
|
123
214
|
reference(id) {
|
|
124
|
-
|
|
215
|
+
const w = this.worker(id);
|
|
216
|
+
const saved = this.optional(id, "state.json", status);
|
|
217
|
+
return {
|
|
218
|
+
host: "acp",
|
|
219
|
+
backend: w.acp.backend,
|
|
220
|
+
command: w.acp.command,
|
|
221
|
+
args: w.acp.args,
|
|
222
|
+
...(w.acp.env ? { env: w.acp.env } : {}),
|
|
223
|
+
...(w.acp.permission ? { permission: w.acp.permission } : {}),
|
|
224
|
+
sessionId: saved?.sessionId ?? null,
|
|
225
|
+
...(saved?.capabilities ? { capabilities: saved.capabilities } : {}),
|
|
226
|
+
};
|
|
125
227
|
}
|
|
126
228
|
/** Short controller edits are serialized; an abandoned lock fails closed. */
|
|
127
229
|
control(work) {
|
|
@@ -145,14 +247,16 @@ export class AgentFiles {
|
|
|
145
247
|
}
|
|
146
248
|
enqueue(id, text, delivery, files = [], requestId = randomUUID()) {
|
|
147
249
|
fileId(requestId);
|
|
148
|
-
const
|
|
250
|
+
const w = this.worker(id);
|
|
251
|
+
const previous = this.optional(id, "inbox/" + requestId + ".json", message);
|
|
149
252
|
if (previous) {
|
|
150
|
-
requireThat(previous.generation ===
|
|
253
|
+
requireThat(previous.generation === w.generation && previous.message === text && previous.delivery === delivery && canonical(previous.files) === canonical(files), "请求 ID 已被不同输入使用。");
|
|
151
254
|
return previous;
|
|
152
255
|
}
|
|
153
|
-
|
|
154
|
-
this.write(id, "
|
|
155
|
-
|
|
256
|
+
w.sequence++;
|
|
257
|
+
this.write(id, "worker.json", w, workerRecord);
|
|
258
|
+
this.ensureSubdirectory(id, "inbox");
|
|
259
|
+
const value = { requestId, generation: w.generation, sequence: w.sequence, message: text, delivery, files };
|
|
156
260
|
this.write(id, "inbox/" + value.requestId + ".json", value, message, true);
|
|
157
261
|
return value;
|
|
158
262
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { dirname } from "node:path";
|
|
2
2
|
import { realpathSync } from "node:fs";
|
|
3
|
-
import { AgentFiles,
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
3
|
+
import { AgentFiles, status, toDescriptor } from "../../storage/agent-files.js";
|
|
4
|
+
import { acpAnswer } from "../../storage/acp-files.js";
|
|
5
|
+
import type { AcpAnswer, AcpInput } from "../../model/acp.js";
|
|
6
6
|
import { requireThat } from "../../common/validation.js";
|
|
7
7
|
import { packageVersion, releaseLine } from "../../common/version.js";
|
|
8
8
|
import { loadWorkspaceContext } from "../../integrations/agent-resources.js";
|
|
@@ -13,15 +13,15 @@ export async function acpMember() {
|
|
|
13
13
|
requireThat(id && directory && generation, "缺少 ACP 成员启动身份。");
|
|
14
14
|
const files = new AgentFiles(dirname(realpathSync(directory)));
|
|
15
15
|
requireThat(files.directory(id) === realpathSync(directory), "ACP 成员目录不匹配。");
|
|
16
|
-
const d = files.
|
|
16
|
+
const d = toDescriptor(files.worker(id));
|
|
17
17
|
requireThat(d.agentId === id && releaseLine(d.release) === releaseLine(packageVersion), "ACP 成员身份或版本无效。");
|
|
18
18
|
const configuration = await readWorkspaceConfig(d.workspace);
|
|
19
19
|
requireThat(configuration.enabled, workspaceDisabledMessage(configuration));
|
|
20
20
|
const features = workspaceFeatures(configuration);
|
|
21
21
|
const check = () => {
|
|
22
22
|
files.check();
|
|
23
|
-
const
|
|
24
|
-
requireThat(
|
|
23
|
+
const w = files.worker(id);
|
|
24
|
+
requireThat(w.generation === generation && (!w.stop || process.env.PBOT_ACP_VALIDATE === "1"), "ACP 成员已停止或启动代次变化。");
|
|
25
25
|
};
|
|
26
26
|
const context = async () => {
|
|
27
27
|
const reference = files.reference(id);
|
|
@@ -29,14 +29,17 @@ export async function acpMember() {
|
|
|
29
29
|
const loaded = await loadWorkspaceContext({ host, root: d.workspace, role: "general-purpose" });
|
|
30
30
|
return { workspace: loaded.workspace, role: loaded.role, environment: JSON.stringify(loaded.environment) };
|
|
31
31
|
};
|
|
32
|
-
return {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
return {
|
|
33
|
+
files, d, id, generation, configuration, features, check, context,
|
|
34
|
+
input(): AcpInput {
|
|
35
|
+
check();
|
|
36
|
+
const saved = files.read(id, "state.json", status);
|
|
37
|
+
requireThat(saved.generation === generation && typeof saved.activeRequestId === "string" && saved.activeRequestId.length > 0, "ACP 输入代次无效。");
|
|
38
|
+
return { generation, requestId: saved.activeRequestId! };
|
|
36
39
|
},
|
|
37
40
|
answer(input: AcpInput, state: AcpAnswer["state"], answer: string, error?: string) {
|
|
38
41
|
// A stop can race the native terminal event. The current generation may still seal its result.
|
|
39
|
-
if (files.
|
|
42
|
+
if (files.worker(id).generation !== generation) return;
|
|
40
43
|
files.write(id, "acp-answer.json", { ...input, state, answer, ...(error ? { error } : {}) }, acpAnswer);
|
|
41
44
|
},
|
|
42
45
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { dirname, join, resolve } from "node:path";
|
|
3
3
|
import type { RequestPermissionRequest } from "@agentclientprotocol/sdk";
|
|
4
|
-
import { AgentFiles,
|
|
5
|
-
import {
|
|
4
|
+
import { AgentFiles, status, toDescriptor } from "../../storage/agent-files.js";
|
|
5
|
+
import { acpReference } from "../../storage/acp-files.js";
|
|
6
6
|
import type { AcpModelSelection, AcpSessionReference } from "../../model/acp.js";
|
|
7
7
|
import { AcpAgentRun } from "../../services/agents/acp-run.js";
|
|
8
|
+
import { AgentRun } from "../../services/agents/agent-run.js";
|
|
8
9
|
import { openAcp } from "../../integrations/acp/connection.js";
|
|
9
10
|
import { acpExecutable } from "../../integrations/acp/executable.js";
|
|
10
11
|
import { acpContent } from "../../integrations/acp/input.js";
|
|
@@ -90,15 +91,16 @@ async function runWorker(args: string[]) {
|
|
|
90
91
|
requireThat(directory && id && generation, "缺少 ACP worker 启动信息。");
|
|
91
92
|
const files = new AgentFiles(dirname(directory));
|
|
92
93
|
requireThat(files.directory(id) === directory, "ACP worker 目录不匹配。");
|
|
93
|
-
const d = files.
|
|
94
|
+
const d = toDescriptor(files.worker(id)), reference = files.reference(id);
|
|
94
95
|
requireThat(d.agentId === id && releaseLine(d.release) === releaseLine(packageVersion), "ACP worker 身份或版本不匹配。");
|
|
95
96
|
const validating = args.includes("--validate"), lifetime = new AbortController();
|
|
97
|
+
const agentRun = validating ? undefined : new AgentRun(files, id, generation);
|
|
96
98
|
let execution: AcpAgentRun | undefined;
|
|
97
99
|
const stop = () => { void execution?.stop().catch(error => lifetime.abort(error)); if (!execution) lifetime.abort(); };
|
|
98
100
|
process.on("SIGTERM", stop); process.on("SIGINT", stop);
|
|
99
101
|
|
|
100
102
|
async function main() {
|
|
101
|
-
requireThat(files.
|
|
103
|
+
requireThat(files.worker(id!).generation === generation, "ACP worker 启动代次已失效。");
|
|
102
104
|
const harness = resolveAcpHarness(reference.backend);
|
|
103
105
|
const exactAnswer = Boolean(harness.exactAnswer);
|
|
104
106
|
const packageRoot = resolve(resourceRoot, "..");
|
|
@@ -112,7 +114,7 @@ async function runWorker(args: string[]) {
|
|
|
112
114
|
...(validating ? { PBOT_ACP_VALIDATE: "1" } : {}),
|
|
113
115
|
};
|
|
114
116
|
const prepared = harness.prepareLaunch
|
|
115
|
-
? await harness.prepareLaunch({ reference,
|
|
117
|
+
? await harness.prepareLaunch({ reference, workspace: d.workspace, directory: directory!, packageRoot, options: d.options, env: baseEnv, features })
|
|
116
118
|
: { command: { ...reference, args: [...reference.args] }, env: { ...baseEnv, ...(reference.env ?? {}) } };
|
|
117
119
|
|
|
118
120
|
let prompt: string | undefined;
|
|
@@ -140,15 +142,15 @@ async function runWorker(args: string[]) {
|
|
|
140
142
|
}
|
|
141
143
|
}
|
|
142
144
|
|
|
143
|
-
// Only publish
|
|
145
|
+
// Only publish selection after requested model/thinking options are applied so callers can detect startup readiness.
|
|
144
146
|
let configured = false;
|
|
145
147
|
const saveSelection = (selection: AcpModelSelection) => {
|
|
146
|
-
if (validating || !configured) return;
|
|
147
|
-
const
|
|
148
|
-
if (
|
|
148
|
+
if (validating || !configured || !agentRun) return;
|
|
149
|
+
const w = files.worker(id!);
|
|
150
|
+
if (w.generation === generation && !w.stop) agentRun.setSelection(selection);
|
|
149
151
|
};
|
|
150
152
|
|
|
151
|
-
const connection = await openAcp(prepared.command, d.
|
|
153
|
+
const connection = await openAcp(prepared.command, d.workspace, prepared.env, {
|
|
152
154
|
selection: saveSelection,
|
|
153
155
|
update(update) {
|
|
154
156
|
if (update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") {
|
|
@@ -200,12 +202,10 @@ async function runWorker(args: string[]) {
|
|
|
200
202
|
`${reference.backend} ACP 后端需要支持 systemPrompt,以加载专家职责与工作区资料。`);
|
|
201
203
|
if (validating) { await sendIpc({ type: "validated" }); return; }
|
|
202
204
|
if (reference.sessionId === null) await connection.configure(d.options);
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
capabilities: connection.capabilities,
|
|
208
|
-
}, acpReference);
|
|
205
|
+
const currentWorker = files.worker(id!);
|
|
206
|
+
requireThat(currentWorker.generation === generation && !currentWorker.stop, "ACP 启动已取消。");
|
|
207
|
+
let sessionId = harness.eagerSessionId || reference.sessionId !== null ? connection.sessionId : null;
|
|
208
|
+
agentRun!.setSession(sessionId, connection.capabilities);
|
|
209
209
|
configured = true;
|
|
210
210
|
saveSelection(connection.selection());
|
|
211
211
|
let promptInjected = reference.sessionId !== null || connection.systemPrompt;
|
|
@@ -217,15 +217,17 @@ async function runWorker(args: string[]) {
|
|
|
217
217
|
: request;
|
|
218
218
|
promptInjected = true;
|
|
219
219
|
const content = await acpContent(effective, connection.images, connection.signal);
|
|
220
|
-
const
|
|
221
|
-
requireThat(
|
|
220
|
+
const w = files.worker(id!);
|
|
221
|
+
requireThat(w.generation === generation && !w.stop, "ACP 输入已取消或启动代次变化。");
|
|
222
222
|
connection.signal.throwIfAborted();
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
if (sessionId === null) {
|
|
224
|
+
sessionId = connection.sessionId;
|
|
225
|
+
agentRun!.setSession(sessionId, connection.capabilities);
|
|
226
|
+
}
|
|
225
227
|
return connection.prompt(content);
|
|
226
228
|
},
|
|
227
229
|
cancel: () => connection.cancel(),
|
|
228
|
-
}, exactAnswer);
|
|
230
|
+
}, exactAnswer, agentRun);
|
|
229
231
|
await execution.run();
|
|
230
232
|
} finally {
|
|
231
233
|
try { await connection.close(); } finally { await execution?.settled(); }
|
|
@@ -234,17 +236,18 @@ async function runWorker(args: string[]) {
|
|
|
234
236
|
|
|
235
237
|
try {
|
|
236
238
|
await main();
|
|
237
|
-
if (!validating && files.
|
|
238
|
-
|
|
239
|
-
|
|
239
|
+
if (!validating && files.worker(id).generation === generation) {
|
|
240
|
+
agentRun!.save({ state: "stopped", activity: "已停止" });
|
|
241
|
+
files.clearTransient(id);
|
|
240
242
|
}
|
|
241
243
|
} catch (error) {
|
|
242
244
|
if (validating) { await sendIpc({ type: "error", error: errorMessage(error) }); }
|
|
243
|
-
else if (files.
|
|
244
|
-
const stopped = files.
|
|
245
|
+
else if (files.worker(id).generation === generation) {
|
|
246
|
+
const stopped = files.worker(id).stop;
|
|
245
247
|
const patch = { state: stopped ? "stopped" as const : "error" as const, activity: stopped ? "已停止" : "ACP 执行失败", ...(stopped ? {} : { error: errorMessage(error) }) };
|
|
246
|
-
if (
|
|
247
|
-
else files.write(id, "
|
|
248
|
+
if (agentRun) agentRun.save(patch);
|
|
249
|
+
else files.write(id, "state.json", { generation, ...patch, updatedAt: Date.now() }, status);
|
|
250
|
+
if (stopped) files.clearTransient(id);
|
|
248
251
|
}
|
|
249
252
|
process.exitCode = 1;
|
|
250
253
|
} finally {
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
1
|
import { join } from "node:path";
|
|
3
|
-
import { valid } from "semver";
|
|
4
|
-
import { object } from "../../../common/json.js";
|
|
5
2
|
import { checkStableVersion } from "../../../common/package-source.js";
|
|
6
3
|
import { packageRoot } from "../../../common/paths.js";
|
|
7
4
|
import { packageVersion } from "../../../common/version.js";
|
|
8
5
|
import { execCliEntry, upgradeManagedGlobalCli } from "../../../integrations/installation/cli-update.js";
|
|
9
6
|
import { findExecutable, SetupProcesses } from "../../../integrations/installation/processes.js";
|
|
10
|
-
import { getHostUpgrader } from "../../../integrations/installation/upgraders/registry.js";
|
|
7
|
+
import { getHostUpgrader, listHostUpgraders } from "../../../integrations/installation/upgraders/registry.js";
|
|
11
8
|
import type { CliUpgradeSummary, HostUpgradeResult, WorkspaceUpgradeSummary } from "../../../model/installation.js";
|
|
12
9
|
import {
|
|
13
10
|
executeWorkspaceUpgrade,
|
|
@@ -15,7 +12,6 @@ import {
|
|
|
15
12
|
upgradeUsage,
|
|
16
13
|
type WorkspaceUpgradeTarget,
|
|
17
14
|
} from "../../../services/installation/upgrade-service.js";
|
|
18
|
-
import { workspacePluginBindings } from "../../../services/workspace/plugin-releases.js";
|
|
19
15
|
import { CliError, resolveCliWorkspace, withSignals } from "../args.js";
|
|
20
16
|
import type { CliCommand } from "../types.js";
|
|
21
17
|
|
|
@@ -29,31 +25,9 @@ async function latestStableVersion(processes: SetupProcesses, cwd: string): Prom
|
|
|
29
25
|
return checkStableVersion(value.version, value.engines?.node);
|
|
30
26
|
}
|
|
31
27
|
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
for (const [host, entry] of Object.entries(bindings)) {
|
|
36
|
-
byHost.set(host, {
|
|
37
|
-
host,
|
|
38
|
-
currentVersion: entry.version,
|
|
39
|
-
...(entry.bindingPath ? { bindingPath: entry.bindingPath } : {}),
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
if (!byHost.has("pi")) {
|
|
43
|
-
const localPiManifest = join(workspace, ".pi", "npm", "node_modules", "personal-bot", "package.json");
|
|
44
|
-
try {
|
|
45
|
-
const manifest: unknown = JSON.parse(await readFile(localPiManifest, "utf8"));
|
|
46
|
-
if (object(manifest) && manifest.name === "personal-bot" && typeof manifest.version === "string" && valid(manifest.version)) {
|
|
47
|
-
byHost.set("pi", { host: "pi", currentVersion: manifest.version, bindingPath: localPiManifest });
|
|
48
|
-
}
|
|
49
|
-
} catch (error) {
|
|
50
|
-
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (requestedHosts) {
|
|
54
|
-
return requestedHosts.map(host => byHost.get(host) ?? { host });
|
|
55
|
-
}
|
|
56
|
-
return [...byHost.values()].sort((a, b) => a.host.localeCompare(b.host));
|
|
28
|
+
function resolveUpgradeTargets(requestedHosts?: readonly string[]): WorkspaceUpgradeTarget[] {
|
|
29
|
+
const hosts = requestedHosts ?? listHostUpgraders();
|
|
30
|
+
return hosts.map(host => ({ host }));
|
|
57
31
|
}
|
|
58
32
|
|
|
59
33
|
function formatLine(result: HostUpgradeResult): string {
|
|
@@ -70,7 +44,7 @@ function printHumanSummary(summary: WorkspaceUpgradeSummary): void {
|
|
|
70
44
|
console.log(`目标版本:${summary.targetVersion}`);
|
|
71
45
|
console.log(`[${summary.cli.state}] cli ${summary.cli.previousVersion} → ${summary.cli.version}: ${summary.cli.detail}`);
|
|
72
46
|
if (!summary.results.length) {
|
|
73
|
-
console.log("
|
|
47
|
+
console.log("未注册任何宿主升级适配器。");
|
|
74
48
|
return;
|
|
75
49
|
}
|
|
76
50
|
for (const result of summary.results) console.log(formatLine(result));
|
|
@@ -79,7 +53,7 @@ function printHumanSummary(summary: WorkspaceUpgradeSummary): void {
|
|
|
79
53
|
export const upgradeCommand: CliCommand = {
|
|
80
54
|
name: "upgrade",
|
|
81
55
|
aliases: ["update"],
|
|
82
|
-
summary: "统一升级全局 CLI
|
|
56
|
+
summary: "统一升级全局 CLI 与本机/当前工作区已安装的各宿主插件",
|
|
83
57
|
usage: upgradeUsage,
|
|
84
58
|
updatePolicy: "none",
|
|
85
59
|
supportsWorkspaceFlag: true,
|
|
@@ -125,19 +99,17 @@ export const upgradeCommand: CliCommand = {
|
|
|
125
99
|
};
|
|
126
100
|
}
|
|
127
101
|
|
|
128
|
-
const targets =
|
|
102
|
+
const targets = resolveUpgradeTargets(parsed.hosts);
|
|
129
103
|
const summary = await executeWorkspaceUpgrade({
|
|
130
104
|
workspaceRoot: workspace,
|
|
131
105
|
targetVersion,
|
|
132
106
|
cli,
|
|
133
107
|
targets,
|
|
134
108
|
resolveUpgrader: getHostUpgrader,
|
|
135
|
-
createContext:
|
|
109
|
+
createContext: () => ({
|
|
136
110
|
workspace,
|
|
137
111
|
targetVersion,
|
|
138
|
-
...(target.currentVersion ? { currentVersion: target.currentVersion } : {}),
|
|
139
112
|
packageRoot,
|
|
140
|
-
...(target.bindingPath ? { bindingPath: target.bindingPath } : {}),
|
|
141
113
|
env: process.env,
|
|
142
114
|
signal: controller.signal,
|
|
143
115
|
options: { dshProfile: parsed.dshProfile },
|
|
@@ -2,26 +2,21 @@ import { mkdir, stat } from "node:fs/promises";
|
|
|
2
2
|
import { requireThat } from "../../../common/validation.js";
|
|
3
3
|
import { packageVersion } from "../../../common/version.js";
|
|
4
4
|
import { minimumCliRelease } from "../../../integrations/installation/cli-update.js";
|
|
5
|
-
import { workspacePluginDrift, workspacePluginReleases } from "../../../services/workspace/plugin-releases.js";
|
|
6
5
|
import { readWorkspaceConfig } from "../../../services/workspace/workspace-config.js";
|
|
7
6
|
import { initializeWorkspace } from "../../../services/workspace/workspace-preparation.js";
|
|
8
7
|
import { printJson, requireNoExtraArgs, resolveCliWorkspace } from "../args.js";
|
|
9
8
|
import type { CliCommand } from "../types.js";
|
|
10
9
|
|
|
11
10
|
const initUsage = "用法:pbot init [--workspace <目录>] [--json]\n初始化共享工作区资料并启用 Personal Bot。";
|
|
12
|
-
const statusUsage = "用法:pbot status [--workspace <目录>] [--json]\n查看工作区根目录、CLI
|
|
11
|
+
const statusUsage = "用法:pbot status [--workspace <目录>] [--json]\n查看工作区根目录、CLI 版本与配置。";
|
|
13
12
|
|
|
14
13
|
async function reportWorkspaceStatus(root: string, compact: boolean, checkRelease: boolean): Promise<number> {
|
|
15
14
|
const configuration = await readWorkspaceConfig(root);
|
|
16
15
|
const active = checkRelease || configuration.enabled;
|
|
17
|
-
const
|
|
18
|
-
const required = active ? await minimumCliRelease(root, plugins) : undefined;
|
|
19
|
-
const drift = workspacePluginDrift(plugins);
|
|
16
|
+
const required = active ? await minimumCliRelease(root) : undefined;
|
|
20
17
|
printJson({
|
|
21
18
|
workspaceRoot: root,
|
|
22
19
|
version: packageVersion,
|
|
23
|
-
plugins,
|
|
24
|
-
outOfSync: drift.outOfSync,
|
|
25
20
|
minimumCliVersion: required ?? null,
|
|
26
21
|
configuration,
|
|
27
22
|
}, compact);
|
|
@@ -54,7 +49,7 @@ export const initCommand: CliCommand = {
|
|
|
54
49
|
|
|
55
50
|
export const statusCommand: CliCommand = {
|
|
56
51
|
name: "status",
|
|
57
|
-
summary: "
|
|
52
|
+
summary: "查看工作区状态、CLI 版本与配置",
|
|
58
53
|
usage: statusUsage,
|
|
59
54
|
updatePolicy: "workspace",
|
|
60
55
|
supportsWorkspaceFlag: true,
|