personal-bot 0.3.6 → 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/README.md +1 -1
- package/docs/architecture/design.md +2 -2
- package/docs/architecture/extensibility.md +1 -1
- package/docs/architecture/model-context.md +1 -2
- package/docs/guides/capabilities.md +4 -8
- 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 +348 -203
- package/lib/antigravity-plugin/lib/extension/cli.js +574 -549
- 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 +462 -326
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +2 -2
- 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/antigravity-plugin/resources/agents/coordinator.md +3 -7
- package/lib/antigravity-plugin/resources/agents/general-purpose.md +3 -3
- package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -2
- package/lib/antigravity-plugin/resources/prompts/workspace.md +12 -16
- package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +7 -6
- package/lib/antigravity-plugin/resources/templates/workspace-agents.md +0 -4
- package/lib/antigravity-plugin/skills/pbot/SKILL.md +14 -6
- package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +7 -6
- 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 +2 -2
- 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 +348 -203
- package/lib/extension/cli.js +574 -549
- 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 +48 -62
- package/lib/extension/mcp/workers.d.ts +13 -27
- package/lib/extension/mcp/workers.js +60 -25
- package/lib/extension/mcp.js +462 -326
- 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.js +2 -2
- 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 +2 -2
- 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/lib/tools/history/contract.js +12 -12
- package/package.json +1 -1
- package/resources/agents/coordinator.md +3 -7
- package/resources/agents/general-purpose.md +3 -3
- package/resources/antigravity/skills/pbot/SKILL.md +14 -6
- package/resources/claude/skills/pbot/SKILL.md +14 -6
- package/resources/plugin/skills/pbot/SKILL.md +2 -2
- package/resources/prompts/history-coordinator.md +1 -2
- package/resources/prompts/plugin-coordinator.md +1 -2
- package/resources/prompts/workspace.md +12 -16
- package/resources/skills/provider-connections/SKILL.md +7 -6
- package/resources/templates/workspace-agents.md +0 -4
- 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 +48 -62
- package/src/extension/mcp/workers.ts +66 -27
- package/src/integrations/acp/agents.ts +28 -27
- package/src/integrations/acp/harnesses/claude.ts +1 -1
- package/src/integrations/agent-resources.ts +2 -2
- 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 +2 -2
- 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/src/tools/history/contract.ts +12 -12
- 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/antigravity-plugin/resources/references/compute-finance.md +0 -22
- package/lib/antigravity-plugin/resources/references/compute.md +0 -16
- package/lib/antigravity-plugin/resources/references/task-conductor.md +0 -25
- package/lib/services/workspace/plugin-releases.d.ts +0 -15
- package/lib/services/workspace/plugin-releases.js +0 -126
- package/resources/references/compute-finance.md +0 -22
- package/resources/references/compute.md +0 -16
- package/resources/references/task-conductor.md +0 -25
- package/src/services/workspace/plugin-releases.ts +0 -121
|
@@ -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,
|
|
@@ -3,7 +3,6 @@ import { pathToFileURL } from "node:url";
|
|
|
3
3
|
import { gte, valid } from "semver";
|
|
4
4
|
import { packageVersion } from "../../common/version.js";
|
|
5
5
|
import { minimumCliRelease, runUpdatedCli } from "../../integrations/installation/cli-update.js";
|
|
6
|
-
import { workspacePluginReleases } from "../../services/workspace/plugin-releases.js";
|
|
7
6
|
import { readWorkspaceConfig } from "../../services/workspace/workspace-config.js";
|
|
8
7
|
import { CliError, extractCommonFlags, resolveCliWorkspace } from "./args.js";
|
|
9
8
|
import { historyCommand } from "./commands/history.js";
|
|
@@ -63,7 +62,7 @@ export function formatRootHelp(): string {
|
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
export async function updateForWorkspace(root: string, args: readonly string[], input?: string): Promise<number | undefined> {
|
|
66
|
-
return runUpdatedCli(await minimumCliRelease(root
|
|
65
|
+
return runUpdatedCli(await minimumCliRelease(root), args, input);
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
export async function updateForCommand(args: readonly string[]): Promise<number | undefined> {
|
|
@@ -24,7 +24,7 @@ export async function apply(ctx: Context) {
|
|
|
24
24
|
if (!rootAgents(ctx.agents).includes(agent)) return;
|
|
25
25
|
if (source === "resume") agent.inbox.clear();
|
|
26
26
|
const reference = member.files.reference(member.id);
|
|
27
|
-
requireThat(reference.host === "acp" && reference.backend === "dsh" && agent.session.header.cwd === member.d.
|
|
27
|
+
requireThat(reference.host === "acp" && reference.backend === "dsh" && agent.session.header.cwd === member.d.workspace &&
|
|
28
28
|
(reference.sessionId === null || reference.sessionId === agent.id), "dsh ACP 会话身份或工作目录不匹配。");
|
|
29
29
|
await agent.ctx.plugin({ name: "pbot-acp-expert", inject, apply: async scope => {
|
|
30
30
|
if (member.features.skills) registerDshSkills(scope, agent, { workspaceRoot: member.d.workspace });
|
|
@@ -33,7 +33,7 @@ export function registerDshCommand(ctx: Context, workspaces: DshWorkspaces) {
|
|
|
33
33
|
switch (verb) {
|
|
34
34
|
case "worker": {
|
|
35
35
|
const { tool, args } = parseWorkerCommand(rest);
|
|
36
|
-
result = await workspace.workers.callTool(tool,
|
|
36
|
+
result = await workspace.workers.callTool(tool, args, undefined, workspace.root);
|
|
37
37
|
break;
|
|
38
38
|
}
|
|
39
39
|
case "history": {
|
|
@@ -10,7 +10,6 @@ import { registerDshHistoryTool } from "../../../tools/history/dsh-tool.js";
|
|
|
10
10
|
import { requireThat } from "../../../common/validation.js";
|
|
11
11
|
import { toDshMcpConfig } from "../../../integrations/hosts/dsh/mcp.js";
|
|
12
12
|
import { registerDshSkills } from "../../../integrations/hosts/dsh/skills.js";
|
|
13
|
-
import { bindWorkspacePlugin } from "../../../services/workspace/plugin-releases.js";
|
|
14
13
|
import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../../services/workspace/workspace-config.js";
|
|
15
14
|
import { loadNativeWorkspaceServers } from "../workspace-mcp.js";
|
|
16
15
|
import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration } from "../../../model/workspace-config.js";
|
|
@@ -33,7 +32,7 @@ export class DshWorkspace {
|
|
|
33
32
|
readonly component: AbortSignal,
|
|
34
33
|
readonly features: ResolvedWorkspaceFeatures = workspaceFeatures(),
|
|
35
34
|
) {
|
|
36
|
-
this.workers = new McpWorkerRuntime(defaultWorkerDirectory(), agent.id, "dsh");
|
|
35
|
+
this.workers = new McpWorkerRuntime(defaultWorkerDirectory(root), agent.id, "dsh");
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
check = () => { this.component.throwIfAborted(); this.lifetime.signal.throwIfAborted(); };
|
|
@@ -122,7 +121,6 @@ export class DshWorkspaces {
|
|
|
122
121
|
}
|
|
123
122
|
let workspace: DshWorkspace | undefined;
|
|
124
123
|
try {
|
|
125
|
-
bindWorkspacePlugin(root, "dsh");
|
|
126
124
|
workspace = new DshWorkspace(this.ctx, root, agent, this.#lifetime.signal, workspaceFeatures(configuration));
|
|
127
125
|
const owned = workspace;
|
|
128
126
|
const dispose = agent.ctx.effect(() => async () => {
|
|
@@ -10,7 +10,6 @@ import { toPiMcpConfig } from "../../../integrations/hosts/pi/mcp.js";
|
|
|
10
10
|
import { authorizeMutation } from "../../../services/workspace/workspace-files.js";
|
|
11
11
|
import { loadNativeWorkspaceServers } from "../workspace-mcp.js";
|
|
12
12
|
import { resourceRoot } from "../../../common/paths.js";
|
|
13
|
-
import { launch } from "../../../storage/agent-files.js";
|
|
14
13
|
import { requireThat } from "../../../common/validation.js";
|
|
15
14
|
|
|
16
15
|
const isBlockedTool = (name: string) => name === "pbot_history" || isMcpWorkerTool(name);
|
|
@@ -22,7 +21,7 @@ export default async function piAcpMember(pi: ExtensionAPI) {
|
|
|
22
21
|
let input: AcpInput | undefined, startLeaf: string | null = null;
|
|
23
22
|
const checkSession = (ctx: ExtensionContext) => {
|
|
24
23
|
const reference = member.files.reference(member.id);
|
|
25
|
-
requireThat(reference.host === "acp" && reference.backend === "pi" && realpathSync(ctx.cwd) === member.d.
|
|
24
|
+
requireThat(reference.host === "acp" && reference.backend === "pi" && realpathSync(ctx.cwd) === member.d.workspace &&
|
|
26
25
|
(reference.sessionId === null || reference.sessionId === ctx.sessionManager.getSessionId()), "Pi ACP 会话身份或工作目录不匹配。");
|
|
27
26
|
};
|
|
28
27
|
const workspaceMcpServers: ResolvedWorkspaceMcpServer[] = [];
|
|
@@ -39,7 +38,7 @@ export default async function piAcpMember(pi: ExtensionAPI) {
|
|
|
39
38
|
pi.on("session_start", (_event, ctx) => {
|
|
40
39
|
checkSession(ctx);
|
|
41
40
|
const active = pi.getActiveTools();
|
|
42
|
-
for (const tool of agentFileTools(member.d.
|
|
41
|
+
for (const tool of agentFileTools(member.d.workspace, lifetime.signal, async (path, change, signal) => {
|
|
43
42
|
member.check(); await authorizeMutation(member.d.workspace, path, change, async () => false, signal); member.check();
|
|
44
43
|
})) pi.registerTool(tool);
|
|
45
44
|
for (const server of workspaceMcpServers) {
|
|
@@ -47,7 +46,7 @@ export default async function piAcpMember(pi: ExtensionAPI) {
|
|
|
47
46
|
registeredMcp.push(server.name);
|
|
48
47
|
}
|
|
49
48
|
pi.setActiveTools(active.filter(name => !isBlockedTool(name)));
|
|
50
|
-
pi.setSessionName(member.
|
|
49
|
+
pi.setSessionName(member.id.slice(0, 8));
|
|
51
50
|
startLeaf = ctx.sessionManager.getLeafId();
|
|
52
51
|
});
|
|
53
52
|
pi.on("before_agent_start", async (event, ctx) => {
|
|
@@ -96,7 +96,7 @@ export function registerCommand(pi: ExtensionAPI, lifecycle: Lifecycle, confirma
|
|
|
96
96
|
if (command === "worker") {
|
|
97
97
|
try {
|
|
98
98
|
const { tool, args: payload } = parseWorkerCommand(argument);
|
|
99
|
-
const result = await instance.workers.callTool(tool,
|
|
99
|
+
const result = await instance.workers.callTool(tool, payload, undefined, instance.root);
|
|
100
100
|
ctx.ui.notify(JSON.stringify(result, null, 2), "info");
|
|
101
101
|
} catch (error) {
|
|
102
102
|
ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { realpath } from "node:fs/promises";
|
|
2
2
|
import { requireThat } from "../../../common/validation.js";
|
|
3
|
-
import { bindWorkspacePlugin } from "../../../services/workspace/plugin-releases.js";
|
|
4
3
|
import { authorizeMutation } from "../../../services/workspace/workspace-files.js";
|
|
5
4
|
import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../../services/workspace/workspace-config.js";
|
|
6
5
|
import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration } from "../../../model/workspace-config.js";
|
|
@@ -73,7 +72,6 @@ export class Lifecycle {
|
|
|
73
72
|
this.root = await realpath(root);
|
|
74
73
|
this.configuration = await readWorkspaceConfig(this.root);
|
|
75
74
|
if (!this.configuration.enabled) return;
|
|
76
|
-
bindWorkspacePlugin(this.root, "pi");
|
|
77
75
|
const instance = this.create(this.root, sessionId, this.configuration);
|
|
78
76
|
this.#active = instance;
|
|
79
77
|
try { await this.register(instance); }
|
|
@@ -6,7 +6,6 @@ import { loadWorkspaceContext } from "../../integrations/agent-resources.js";
|
|
|
6
6
|
import type { PluginHostAdapter } from "../../model/plugin-host.js";
|
|
7
7
|
import { recordHistoryCapture } from "../../services/history/history-capture.js";
|
|
8
8
|
import { historyStartupNotices } from "../../services/history/summary-runner.js";
|
|
9
|
-
import { bindWorkspacePlugin, workspacePluginDrift, workspacePluginReleases } from "../../services/workspace/plugin-releases.js";
|
|
10
9
|
import { readWorkspaceConfig, workspaceFeatures } from "../../services/workspace/workspace-config.js";
|
|
11
10
|
import { initializeWorkspace } from "../../services/workspace/workspace-preparation.js";
|
|
12
11
|
import { discoverSkills, discoverWorkspaceSkills } from "../../services/workspace/workspace-skills.js";
|
|
@@ -21,7 +20,6 @@ export async function pluginCommand(adapter: PluginHostAdapter, args: readonly s
|
|
|
21
20
|
requireThat(["init", "status"].includes(action), adapter.usage);
|
|
22
21
|
if (action === "init") {
|
|
23
22
|
await initializeWorkspace(root);
|
|
24
|
-
bindWorkspacePlugin(root, adapter.host, process.env.PBOT_PLUGIN_MANIFEST || process.env.PBOT_PLUGIN_VERSION);
|
|
25
23
|
}
|
|
26
24
|
const configuration = await readWorkspaceConfig(root);
|
|
27
25
|
return { version: packageVersion, workspaceRoot: root, resourceRoot, configuration };
|
|
@@ -62,7 +60,6 @@ export async function pluginHook(adapter: PluginHostAdapter, payload: unknown, r
|
|
|
62
60
|
return adapter.formatPass(payload);
|
|
63
61
|
}
|
|
64
62
|
if (!configuration.enabled) return adapter.formatPass(payload);
|
|
65
|
-
if (event.kind === "inject-context") bindWorkspacePlugin(root, adapter.host, process.env.PBOT_PLUGIN_MANIFEST || process.env.PBOT_PLUGIN_VERSION);
|
|
66
63
|
if (features.history && adapter.extractHistory) {
|
|
67
64
|
try {
|
|
68
65
|
const capture = await adapter.extractHistory(event);
|
|
@@ -80,13 +77,6 @@ export async function pluginHook(adapter: PluginHostAdapter, payload: unknown, r
|
|
|
80
77
|
workspaceSkills.push(...await discoverSkills(directory, directory));
|
|
81
78
|
}
|
|
82
79
|
const notices = event.isSessionStart && features.history ? [...historyStartupNotices(root)] : [];
|
|
83
|
-
if (event.isSessionStart) {
|
|
84
|
-
const drift = workspacePluginDrift(workspacePluginReleases(root));
|
|
85
|
-
if (drift.outOfSync) {
|
|
86
|
-
const summary = Object.entries(drift.versions).map(([host, version]) => `${host}=${version}`).join(", ");
|
|
87
|
-
notices.push(`检测到当前工作区各宿主 Personal Bot 插件版本不一致(${summary}),可在终端运行 pbot upgrade 统一升级。`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
80
|
if (!includePrompts && !workspaceSkills.length && !notices.length) return adapter.formatPass(payload);
|
|
91
81
|
const context = await loadWorkspaceContext({
|
|
92
82
|
host: adapter.host,
|