personal-bot 0.3.1 → 0.3.2
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 +1 -1
- package/README.zh-CN.md +1 -1
- package/bin/pbot-pi-acp.mjs +27 -11
- package/bin/pbot.mjs +1 -1
- package/docs/README.md +1 -1
- package/docs/architecture/design.md +23 -10
- package/docs/architecture/extensibility.md +20 -18
- package/docs/architecture/model-context.md +2 -2
- package/docs/architecture/principles.md +4 -3
- package/docs/guides/capabilities.md +3 -3
- package/docs/guides/history.md +50 -16
- package/docs/guides/workspace-configuration.md +31 -6
- package/docs/hosts/antigravity.md +2 -0
- package/docs/hosts/claude-code.md +1 -1
- package/docs/hosts/dsh.md +1 -1
- package/docs/hosts/pi.md +1 -1
- package/hooks/hooks.json +3 -0
- package/lib/antigravity-plugin/hooks.json +7 -0
- package/lib/antigravity-plugin/lib/claude.js +2 -2
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +156 -11
- package/lib/antigravity-plugin/lib/extension/{plugin-runtime.d.ts → hosts/plugin-runtime.d.ts} +2 -2
- package/lib/antigravity-plugin/lib/extension/{plugin-runtime.js → hosts/plugin-runtime.js} +34 -8
- package/lib/antigravity-plugin/lib/extension/mcp.js +1113 -78
- package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +1 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +5 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.js +171 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/{claude.js → claude/adapter.js} +32 -4
- package/lib/antigravity-plugin/lib/integrations/hosts/{registry.js → plugin-registry.js} +2 -2
- package/lib/antigravity-plugin/lib/model/history.d.ts +169 -0
- package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +26 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +25 -0
- package/lib/antigravity-plugin/lib/plugin.js +2 -2
- package/lib/antigravity-plugin/lib/services/history/history-capture.d.ts +4 -0
- package/lib/antigravity-plugin/lib/services/history/history-capture.js +86 -0
- package/lib/antigravity-plugin/lib/services/history/history-index.d.ts +17 -0
- package/lib/antigravity-plugin/lib/services/history/history-index.js +112 -0
- package/lib/antigravity-plugin/lib/services/history/history-migrate.d.ts +12 -0
- package/lib/antigravity-plugin/lib/services/history/history-migrate.js +88 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.js +121 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.d.ts +7 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.js +124 -0
- package/lib/antigravity-plugin/lib/services/history/summary-registry.d.ts +7 -0
- package/lib/antigravity-plugin/lib/services/history/summary-registry.js +36 -0
- package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +37 -0
- package/lib/antigravity-plugin/lib/services/history/summary-runner.js +301 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.d.ts +5 -1
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +73 -4
- package/lib/antigravity-plugin/lib/storage/file-access.d.ts +2 -0
- package/lib/antigravity-plugin/lib/storage/file-access.js +26 -0
- package/lib/antigravity-plugin/lib/storage/history-files.d.ts +54 -0
- package/lib/antigravity-plugin/lib/storage/history-files.js +467 -0
- package/lib/antigravity-plugin/lib/storage/history-format.d.ts +6 -0
- package/lib/antigravity-plugin/lib/storage/history-format.js +62 -0
- package/lib/antigravity-plugin/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +1 -1
- package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +22 -12
- package/lib/claude.js +2 -2
- package/lib/client.js +21 -11
- package/lib/dsh.js +4 -4
- package/lib/extension/{acp-member.d.ts → acp/member.d.ts} +5 -5
- package/lib/extension/{acp-member.js → acp/member.js} +6 -6
- package/lib/extension/acp/worker.d.ts +1 -0
- package/lib/extension/acp/worker.js +384 -0
- package/lib/extension/acp-worker.js +156 -11
- package/lib/extension/{dsh → hosts/dsh}/acp-member.js +8 -8
- package/lib/extension/hosts/dsh/command.js +92 -0
- package/lib/extension/{dsh → hosts/dsh}/files.js +3 -3
- package/lib/extension/hosts/dsh/history.d.ts +4 -0
- package/lib/extension/hosts/dsh/history.js +62 -0
- package/lib/extension/{dsh → hosts/dsh}/management.d.ts +1 -1
- package/lib/extension/{dsh → hosts/dsh}/management.js +12 -10
- package/lib/extension/{dsh → hosts/dsh}/workspace.d.ts +3 -9
- package/lib/extension/{dsh → hosts/dsh}/workspace.js +32 -70
- package/lib/extension/{plugin-runtime.d.ts → hosts/plugin-runtime.d.ts} +2 -2
- package/lib/extension/{plugin-runtime.js → hosts/plugin-runtime.js} +34 -8
- package/lib/extension/{mcp-bridge.d.ts → mcp/bridge.d.ts} +1 -1
- package/lib/extension/{mcp-bridge.js → mcp/bridge.js} +4 -4
- package/lib/extension/{mcp-workers.d.ts → mcp/workers.d.ts} +222 -2
- package/lib/extension/{mcp-workers.js → mcp/workers.js} +229 -63
- package/lib/extension/mcp.js +1113 -78
- package/lib/extension/{setup-cli.js → setup/cli.js} +9 -9
- package/lib/integrations/acp/connection.d.ts +11 -10
- package/lib/integrations/acp/connection.js +6 -0
- package/lib/integrations/acp/harnesses/claude.js +1 -1
- package/lib/integrations/acp/harnesses/dsh.js +1 -1
- package/lib/integrations/acp/history-summary.d.ts +17 -0
- package/lib/integrations/acp/history-summary.js +100 -0
- package/lib/integrations/agent-resources.d.ts +1 -0
- package/lib/integrations/agent-resources.js +5 -1
- package/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
- package/lib/integrations/hosts/antigravity/adapter.js +171 -0
- package/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
- package/lib/integrations/hosts/{claude.js → claude/adapter.js} +32 -4
- package/lib/integrations/{dsh → hosts/dsh}/mcp.d.ts +1 -1
- package/lib/integrations/{dsh → hosts/dsh}/resources.d.ts +1 -1
- package/lib/integrations/{dsh → hosts/dsh}/resources.js +4 -4
- package/lib/integrations/{dsh → hosts/dsh}/schema.js +1 -1
- package/lib/integrations/{dsh → hosts/dsh}/skills.js +1 -1
- package/lib/integrations/hosts/{registry.js → plugin-registry.js} +2 -2
- package/lib/integrations/installation/pi-setup.js +1 -1
- package/lib/model/history.d.ts +133 -34
- package/lib/model/plugin-host.d.ts +26 -0
- package/lib/model/workspace-config.d.ts +25 -0
- package/lib/plugin.js +2 -2
- package/lib/services/agents/agent-run.d.ts +1 -1
- package/lib/services/history/history-capture.d.ts +4 -0
- package/lib/services/history/history-capture.js +86 -0
- package/lib/services/history/history-index.d.ts +16 -7
- package/lib/services/history/history-index.js +48 -70
- package/lib/services/history/history-migrate.d.ts +12 -0
- package/lib/services/history/history-migrate.js +88 -0
- package/lib/services/history/history-query.d.ts +51 -0
- package/lib/services/history/history-query.js +371 -0
- package/lib/services/history/summary-command.d.ts +20 -0
- package/lib/services/history/summary-command.js +68 -0
- package/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
- package/lib/services/history/summary-dimensions/monthly.js +121 -0
- package/lib/services/history/summary-dimensions/session.d.ts +7 -0
- package/lib/services/history/summary-dimensions/session.js +124 -0
- package/lib/services/history/summary-registry.d.ts +7 -0
- package/lib/services/history/summary-registry.js +36 -0
- package/lib/services/history/summary-runner.d.ts +37 -0
- package/lib/services/history/summary-runner.js +301 -0
- package/lib/services/workspace/workspace-config.d.ts +5 -1
- package/lib/services/workspace/workspace-config.js +73 -4
- package/lib/storage/history-files.d.ts +45 -9
- package/lib/storage/history-files.js +373 -247
- package/lib/storage/history-format.d.ts +3 -12
- package/lib/storage/history-format.js +26 -50
- package/lib/tools/history/actions.d.ts +3 -68
- package/lib/tools/history/actions.js +7 -5
- package/lib/tools/history/contract.d.ts +14 -7
- package/lib/tools/history/contract.js +58 -18
- package/lib/tools/history/dsh-tool.d.ts +1 -2
- package/lib/tools/history/dsh-tool.js +11 -5
- package/lib/ui/dsh/management.js +18 -5
- package/package.json +1 -1
- package/resources/prompts/history-coordinator.md +1 -1
- package/resources/prompts/history-monthly-summary.md +13 -0
- package/resources/prompts/history-summary.md +10 -4
- package/resources/skills/provider-connections/SKILL.md +22 -12
- package/src/claude.ts +2 -2
- package/src/dsh.ts +4 -4
- package/src/extension/{acp-member.ts → acp/member.ts} +7 -7
- package/src/extension/{acp-worker.ts → acp/worker.ts} +131 -17
- package/src/extension/{dsh → hosts/dsh}/acp-member.ts +9 -9
- package/src/extension/hosts/dsh/command.ts +92 -0
- package/src/extension/{dsh → hosts/dsh}/files.ts +3 -3
- package/src/extension/hosts/dsh/history.ts +67 -0
- package/src/extension/{dsh → hosts/dsh}/management.ts +11 -9
- package/src/extension/{dsh → hosts/dsh}/workspace.ts +31 -50
- package/src/extension/{pi-acp-member.ts → hosts/pi/acp-member.ts} +9 -9
- package/src/extension/hosts/pi/command.ts +158 -0
- package/src/extension/{events.ts → hosts/pi/events.ts} +14 -4
- package/src/extension/hosts/pi/history.ts +45 -0
- package/src/extension/{lifecycle.ts → hosts/pi/lifecycle.ts} +7 -11
- package/src/extension/{plugin-runtime.ts → hosts/plugin-runtime.ts} +29 -9
- package/src/extension/{mcp-bridge.ts → mcp/bridge.ts} +5 -5
- package/src/extension/{mcp-workers.ts → mcp/workers.ts} +237 -64
- package/src/extension/{setup-cli.ts → setup/cli.ts} +11 -11
- package/src/integrations/acp/connection.ts +6 -0
- package/src/integrations/acp/harnesses/claude.ts +1 -1
- package/src/integrations/acp/harnesses/dsh.ts +1 -1
- package/src/integrations/acp/history-summary.ts +108 -0
- package/src/integrations/agent-resources.ts +6 -0
- package/src/integrations/hosts/antigravity/adapter.ts +161 -0
- package/src/integrations/hosts/{claude.ts → claude/adapter.ts} +28 -5
- package/src/integrations/{dsh → hosts/dsh}/mcp.ts +1 -1
- package/src/integrations/{dsh → hosts/dsh}/resources.ts +5 -5
- package/src/integrations/{dsh → hosts/dsh}/schema.ts +1 -1
- package/src/integrations/{dsh → hosts/dsh}/session.ts +2 -2
- package/src/integrations/{dsh → hosts/dsh}/skills.ts +1 -1
- package/src/integrations/{pi → hosts/pi}/mcp.ts +1 -1
- package/src/integrations/{pi → hosts/pi}/skills.ts +1 -1
- package/src/integrations/hosts/{registry.ts → plugin-registry.ts} +2 -2
- package/src/integrations/installation/pi-setup.ts +1 -1
- package/src/mcp.ts +1 -1
- package/src/model/history.ts +151 -26
- package/src/model/plugin-host.ts +26 -2
- package/src/model/workspace-config.ts +30 -0
- package/src/pbot.ts +13 -22
- package/src/plugin.ts +2 -2
- package/src/services/history/history-capture.ts +83 -0
- package/src/services/history/history-index.ts +48 -62
- package/src/services/history/history-migrate.ts +89 -0
- package/src/services/history/history-query.ts +415 -0
- package/src/services/history/summary-command.ts +69 -0
- package/src/services/history/summary-dimensions/monthly.ts +139 -0
- package/src/services/history/summary-dimensions/session.ts +149 -0
- package/src/services/history/summary-registry.ts +44 -0
- package/src/services/history/summary-runner.ts +352 -0
- package/src/services/workspace/workspace-config.ts +91 -5
- package/src/storage/history-files.ts +408 -188
- package/src/storage/history-format.ts +46 -60
- package/src/tools/history/actions.ts +8 -6
- package/src/tools/history/contract.ts +65 -20
- package/src/tools/history/dsh-tool.ts +17 -8
- package/src/tools/history/pi-tool.ts +21 -0
- package/src/tools/register.ts +3 -4
- package/src/ui/dsh/management.ts +27 -11
- package/src/ui/{confirmation.ts → pi/confirmation.ts} +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.d.ts +0 -4
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.js +0 -79
- package/lib/extension/dsh/command.js +0 -50
- package/lib/extension/dsh/history.d.ts +0 -15
- package/lib/extension/dsh/history.js +0 -87
- package/lib/integrations/dsh/history-summary.d.ts +0 -11
- package/lib/integrations/dsh/history-summary.js +0 -36
- package/lib/integrations/dsh/history.d.ts +0 -16
- package/lib/integrations/dsh/history.js +0 -167
- package/lib/integrations/history-summary.d.ts +0 -4
- package/lib/integrations/history-summary.js +0 -32
- package/lib/integrations/hosts/antigravity.d.ts +0 -4
- package/lib/integrations/hosts/antigravity.js +0 -79
- package/lib/services/history/history-service.d.ts +0 -106
- package/lib/services/history/history-service.js +0 -242
- package/lib/storage/acp-history.d.ts +0 -10
- package/lib/storage/acp-history.js +0 -57
- package/src/extension/command.ts +0 -76
- package/src/extension/dsh/command.ts +0 -54
- package/src/extension/dsh/history.ts +0 -74
- package/src/extension/history.ts +0 -26
- package/src/integrations/dsh/history-summary.ts +0 -39
- package/src/integrations/dsh/history.ts +0 -84
- package/src/integrations/history-summary.ts +0 -30
- package/src/integrations/hosts/antigravity.ts +0 -83
- package/src/integrations/pi/history.ts +0 -99
- package/src/services/history/history-service.ts +0 -195
- package/src/storage/acp-history.ts +0 -49
- package/src/tools/history/tool.ts +0 -19
- /package/lib/antigravity-plugin/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +0 -0
- /package/lib/{extension/acp-worker.d.ts → antigravity-plugin/lib/model/history.js} +0 -0
- /package/lib/extension/{dsh → hosts/dsh}/acp-member.d.ts +0 -0
- /package/lib/extension/{dsh → hosts/dsh}/command.d.ts +0 -0
- /package/lib/extension/{dsh → hosts/dsh}/files.d.ts +0 -0
- /package/lib/extension/{setup-guard.js → setup/guard.js} +0 -0
- /package/lib/integrations/acp/{claude.d.ts → claude-settings.d.ts} +0 -0
- /package/lib/integrations/acp/{claude.js → claude-settings.js} +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/mcp.js +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/messages.d.ts +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/messages.js +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/root-agents.d.ts +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/root-agents.js +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/schema.d.ts +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/skills.d.ts +0 -0
- /package/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +0 -0
- /package/src/extension/{setup-guard.ts → setup/guard.ts} +0 -0
- /package/src/integrations/acp/{claude.ts → claude-settings.ts} +0 -0
- /package/src/integrations/{dsh → hosts/dsh}/messages.ts +0 -0
- /package/src/integrations/{dsh → hosts/dsh}/root-agents.ts +0 -0
- /package/src/integrations/{pi → hosts/pi}/agent-tools.ts +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { dirname } from "node:path";
|
|
2
2
|
import { realpathSync } from "node:fs";
|
|
3
|
-
import { AgentFiles, descriptor, launch } from "
|
|
4
|
-
import { acpInput, acpAnswer } from "
|
|
5
|
-
import type { AcpInput, AcpAnswer } from "
|
|
6
|
-
import { requireThat } from "
|
|
7
|
-
import { packageVersion, releaseLine } from "
|
|
8
|
-
import { loadWorkspaceContext } from "
|
|
9
|
-
import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "
|
|
3
|
+
import { AgentFiles, descriptor, launch } from "../../storage/agent-files.js";
|
|
4
|
+
import { acpInput, acpAnswer } from "../../storage/acp-files.js";
|
|
5
|
+
import type { AcpInput, AcpAnswer } from "../../model/acp.js";
|
|
6
|
+
import { requireThat } from "../../common/validation.js";
|
|
7
|
+
import { packageVersion, releaseLine } from "../../common/version.js";
|
|
8
|
+
import { loadWorkspaceContext } from "../../integrations/agent-resources.js";
|
|
9
|
+
import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../services/workspace/workspace-config.js";
|
|
10
10
|
|
|
11
11
|
export async function acpMember() {
|
|
12
12
|
const id = process.env.PBOT_SUBAGENT_RUN_ID, directory = process.env.PBOT_SUBAGENT_DIR, generation = process.env.PBOT_SUBAGENT_GENERATION;
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
2
3
|
import type { RequestPermissionRequest } from "@agentclientprotocol/sdk";
|
|
3
|
-
import { AgentFiles, descriptor, launch, status } from "
|
|
4
|
-
import { acpModelState, acpReference } from "
|
|
5
|
-
import type { AcpModelSelection, AcpSessionReference } from "
|
|
6
|
-
import { AcpAgentRun } from "
|
|
7
|
-
import { openAcp } from "
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
4
|
+
import { AgentFiles, descriptor, launch, status } from "../../storage/agent-files.js";
|
|
5
|
+
import { acpModelState, acpReference } from "../../storage/acp-files.js";
|
|
6
|
+
import type { AcpModelSelection, AcpSessionReference } from "../../model/acp.js";
|
|
7
|
+
import { AcpAgentRun } from "../../services/agents/acp-run.js";
|
|
8
|
+
import { openAcp } from "../../integrations/acp/connection.js";
|
|
9
|
+
import { acpExecutable } from "../../integrations/acp/executable.js";
|
|
10
|
+
import { acpContent } from "../../integrations/acp/input.js";
|
|
11
|
+
import { toAcpMcpServers } from "../../integrations/acp/mcp.js";
|
|
12
|
+
import { resolveAcpHarness } from "../../integrations/acp/registry.js";
|
|
13
|
+
import { loadWorkspaceContext } from "../../integrations/agent-resources.js";
|
|
14
|
+
import { readWorkspaceConfig, workspaceFeatures } from "../../services/workspace/workspace-config.js";
|
|
15
|
+
import { readWorkspaceMcpConfig, resolveWorkspaceMcpServers } from "../../services/workspace/workspace-mcp.js";
|
|
16
|
+
import { discoverWorkspaceSkills } from "../../services/workspace/workspace-skills.js";
|
|
17
|
+
import { object } from "../../common/json.js";
|
|
18
|
+
import { resourceRoot } from "../../common/paths.js";
|
|
19
|
+
import { requireThat } from "../../common/validation.js";
|
|
20
|
+
import { packageVersion, releaseLine } from "../../common/version.js";
|
|
19
21
|
|
|
20
22
|
const errorMessage = (error: unknown) => error instanceof Error ? error.message : String(error);
|
|
21
23
|
|
|
@@ -252,6 +254,118 @@ async function runWorker(args: string[]) {
|
|
|
252
254
|
}
|
|
253
255
|
}
|
|
254
256
|
|
|
257
|
+
async function runOneShotPrompt() {
|
|
258
|
+
const lifetime = new AbortController();
|
|
259
|
+
const stop = () => lifetime.abort(new Error("ACP 摘要任务已取消。"));
|
|
260
|
+
process.on("SIGTERM", stop);
|
|
261
|
+
process.on("SIGINT", stop);
|
|
262
|
+
try {
|
|
263
|
+
const payload = await new Promise<{
|
|
264
|
+
reference: AcpSessionReference;
|
|
265
|
+
cwd: string;
|
|
266
|
+
system: string;
|
|
267
|
+
prompt: string;
|
|
268
|
+
model?: string;
|
|
269
|
+
thinking?: string;
|
|
270
|
+
}>((resolvePayload, rejectPayload) => {
|
|
271
|
+
const timer = setTimeout(() => rejectPayload(new Error("缺少 ACP 摘要任务参数。")), 5000);
|
|
272
|
+
process.once("message", (value: unknown) => {
|
|
273
|
+
clearTimeout(timer);
|
|
274
|
+
if (!object(value)) { rejectPayload(new Error("ACP 摘要任务参数必须是对象。")); return; }
|
|
275
|
+
resolvePayload(value as {
|
|
276
|
+
reference: AcpSessionReference;
|
|
277
|
+
cwd: string;
|
|
278
|
+
system: string;
|
|
279
|
+
prompt: string;
|
|
280
|
+
model?: string;
|
|
281
|
+
thinking?: string;
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
process.once("disconnect", () => { clearTimeout(timer); rejectPayload(new Error("ACP 摘要任务通道已断开。")); });
|
|
285
|
+
});
|
|
286
|
+
const reference = acpReference(payload.reference);
|
|
287
|
+
requireThat(typeof payload.cwd === "string" && payload.cwd.length > 0, "缺少 ACP 摘要工作目录。");
|
|
288
|
+
requireThat(typeof payload.prompt === "string" && payload.prompt.trim().length > 0, "缺少 ACP 摘要输入内容。");
|
|
289
|
+
const harness = resolveAcpHarness(reference.backend);
|
|
290
|
+
const packageRoot = resolve(resourceRoot, "..");
|
|
291
|
+
// Mark as managed subagent so no host (Pi, dsh, Claude, Antigravity) ever records raw history for summary runs.
|
|
292
|
+
const env: NodeJS.ProcessEnv = {
|
|
293
|
+
...process.env,
|
|
294
|
+
...(reference.env ?? {}),
|
|
295
|
+
PBOT_SUBAGENT_RUN_ID: "pbot-summary-" + randomUUID(),
|
|
296
|
+
...(reference.backend === "pi" ? {
|
|
297
|
+
PBOT_SUMMARY_WORKER: "1",
|
|
298
|
+
PI_OFFLINE: "1",
|
|
299
|
+
PBOT_ACP_PI_COMMAND: process.env.PI_ACP_PI_COMMAND ?? acpExecutable("pi", "pi"),
|
|
300
|
+
PI_ACP_PI_COMMAND: join(packageRoot, "bin/pbot-pi-acp.mjs"),
|
|
301
|
+
} : {}),
|
|
302
|
+
};
|
|
303
|
+
let collecting = false;
|
|
304
|
+
let text = "";
|
|
305
|
+
const connection = await openAcp(
|
|
306
|
+
reference,
|
|
307
|
+
payload.cwd,
|
|
308
|
+
env,
|
|
309
|
+
{
|
|
310
|
+
update(update) {
|
|
311
|
+
if (collecting && update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") {
|
|
312
|
+
text += update.content.text;
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
async permission() {
|
|
316
|
+
return { outcome: { outcome: "cancelled" } };
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
lifetime.signal,
|
|
320
|
+
{
|
|
321
|
+
harness,
|
|
322
|
+
...(payload.system ? { systemPrompt: payload.system } : {}),
|
|
323
|
+
},
|
|
324
|
+
);
|
|
325
|
+
try {
|
|
326
|
+
if (payload.model || payload.thinking) {
|
|
327
|
+
const parsedModel = payload.model
|
|
328
|
+
? (harness.parseModelValue ? harness.parseModelValue(payload.model) : { model: payload.model })
|
|
329
|
+
: undefined;
|
|
330
|
+
await connection.configure({
|
|
331
|
+
...(parsedModel?.provider ? { provider: parsedModel.provider } : {}),
|
|
332
|
+
...(parsedModel?.model ? { model: parsedModel.model } : {}),
|
|
333
|
+
...(payload.thinking ? { thinking: payload.thinking } : {}),
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
const promptText = !connection.systemPrompt && payload.system
|
|
337
|
+
? `${payload.system}\n\n---\n\n${payload.prompt}`
|
|
338
|
+
: payload.prompt;
|
|
339
|
+
collecting = true;
|
|
340
|
+
await connection.prompt([{ type: "text", text: promptText }]);
|
|
341
|
+
let cleaned = text;
|
|
342
|
+
if (connection.startupInfo) {
|
|
343
|
+
if (cleaned.startsWith(connection.startupInfo)) {
|
|
344
|
+
cleaned = cleaned.slice(connection.startupInfo.length);
|
|
345
|
+
} else {
|
|
346
|
+
const trimmedInfo = connection.startupInfo.trim();
|
|
347
|
+
const trimmedText = cleaned.trimStart();
|
|
348
|
+
if (trimmedInfo && trimmedText.startsWith(trimmedInfo)) {
|
|
349
|
+
cleaned = trimmedText.slice(trimmedInfo.length);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
const answer = cleaned.trim();
|
|
354
|
+
requireThat(answer.length > 0, "ACP 摘要返回为空。");
|
|
355
|
+
await sendIpc({ type: "answer", text: answer });
|
|
356
|
+
} finally {
|
|
357
|
+
await connection.close();
|
|
358
|
+
}
|
|
359
|
+
} catch (error) {
|
|
360
|
+
await sendIpc({ type: "error", error: errorMessage(error) });
|
|
361
|
+
process.exitCode = 1;
|
|
362
|
+
} finally {
|
|
363
|
+
lifetime.abort();
|
|
364
|
+
if (process.connected) process.disconnect();
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
255
368
|
const args = process.argv.slice(2);
|
|
256
369
|
if (args.includes("--probe")) await runProbe();
|
|
370
|
+
else if (args.includes("--prompt")) await runOneShotPrompt();
|
|
257
371
|
else await runWorker(args);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { Context } from "@deepseek-ai/cordis";
|
|
2
2
|
import * as McpClient from "@deepseek-ai/dsh-mcp-client";
|
|
3
|
-
import type { AcpInput } from "
|
|
4
|
-
import { acpMember } from "
|
|
5
|
-
import { rootAgents } from "
|
|
6
|
-
import { dshResources, dshExpertTools } from "
|
|
7
|
-
import { registerDshSkills } from "
|
|
8
|
-
import { toDshMcpConfig } from "
|
|
9
|
-
import { finalDshAnswer } from "
|
|
10
|
-
import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "
|
|
3
|
+
import type { AcpInput } from "../../../model/acp.js";
|
|
4
|
+
import { acpMember } from "../../acp/member.js";
|
|
5
|
+
import { rootAgents } from "../../../integrations/hosts/dsh/root-agents.js";
|
|
6
|
+
import { dshResources, dshExpertTools } from "../../../integrations/hosts/dsh/resources.js";
|
|
7
|
+
import { registerDshSkills } from "../../../integrations/hosts/dsh/skills.js";
|
|
8
|
+
import { toDshMcpConfig } from "../../../integrations/hosts/dsh/mcp.js";
|
|
9
|
+
import { finalDshAnswer } from "../../../integrations/hosts/dsh/messages.js";
|
|
10
|
+
import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../../../services/workspace/workspace-mcp.js";
|
|
11
11
|
import { registerDshFileEvents } from "./files.js";
|
|
12
|
-
import { requireThat } from "
|
|
12
|
+
import { requireThat } from "../../../common/validation.js";
|
|
13
13
|
|
|
14
14
|
export const name = "pbot-acp-member";
|
|
15
15
|
export const inject = ["agents", "sessions", "llm", "tools", "systemPrompt", "skills", "fs", "workingDirectory", "approval"];
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type {} from "@deepseek-ai/dsh-commands";
|
|
3
|
+
import { json } from "../../../common/json.js";
|
|
4
|
+
import { requireThat } from "../../../common/validation.js";
|
|
5
|
+
import { createAcpHistorySummarizer } from "../../../integrations/acp/history-summary.js";
|
|
6
|
+
import { migrateWorkspaceHistory } from "../../../services/history/history-migrate.js";
|
|
7
|
+
import { parseHistoryCommand } from "../../../services/history/summary-command.js";
|
|
8
|
+
import { listSummaryDimensions } from "../../../services/history/summary-registry.js";
|
|
9
|
+
import { inspectWorkspaceSummaries, runWorkspaceSummaries } from "../../../services/history/summary-runner.js";
|
|
10
|
+
import { readWorkspaceConfig, readWorkspaceHistoryLayoutSync, workspaceDisabledMessage, workspaceSummaryConfig } from "../../../services/workspace/workspace-config.js";
|
|
11
|
+
import { dshWorkspaceStatus, type PbotManagement } from "./management.js";
|
|
12
|
+
import type { DshWorkspaces } from "./workspace.js";
|
|
13
|
+
import { parseWorkerCommand } from "../../mcp/workers.js";
|
|
14
|
+
|
|
15
|
+
const usage = '用法:/pbot status | init | history [summary [维度] [--force] [--backend <acp>] [--model <model>] | migrate [--dry-run] | status | list | {"action":…}] | worker [overview|status|backends|models|create|request|response|output|close] [JSON]';
|
|
16
|
+
|
|
17
|
+
export function registerDshCommand(ctx: Context, workspaces: DshWorkspaces, management: PbotManagement) {
|
|
18
|
+
ctx.commands.register({
|
|
19
|
+
name: "pbot",
|
|
20
|
+
description: "Personal Bot 工作区、历史摘要与跨 Harness worker 管理",
|
|
21
|
+
recordInput: false,
|
|
22
|
+
input: { hint: "status | init | history ... | worker ...", attachments: false },
|
|
23
|
+
async handler({ agent, rawInput, signal }) {
|
|
24
|
+
signal.throwIfAborted();
|
|
25
|
+
const command = rawInput.trim(), split = command.search(/\s/);
|
|
26
|
+
if (!command || command === "status") {
|
|
27
|
+
const status = await dshWorkspaceStatus(workspaces, agent);
|
|
28
|
+
signal.throwIfAborted(); return { kind: "success", text: JSON.stringify(status, null, 2) };
|
|
29
|
+
}
|
|
30
|
+
if (command === "init") {
|
|
31
|
+
await workspaces.initialize(agent);
|
|
32
|
+
signal.throwIfAborted();
|
|
33
|
+
return { kind: "success", text: JSON.stringify(await dshWorkspaceStatus(workspaces, agent), null, 2) };
|
|
34
|
+
}
|
|
35
|
+
const workspace = await workspaces.get(agent);
|
|
36
|
+
signal.throwIfAborted();
|
|
37
|
+
const verb = split < 0 ? command : command.slice(0, split);
|
|
38
|
+
const rest = split < 0 ? "" : command.slice(split).trim();
|
|
39
|
+
let result: unknown;
|
|
40
|
+
switch (verb) {
|
|
41
|
+
case "worker": {
|
|
42
|
+
const { tool, args } = parseWorkerCommand(rest);
|
|
43
|
+
result = await workspace.workers.callTool(tool, { workspace: workspace.root, ...args });
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
case "history": {
|
|
47
|
+
requireThat(workspace.features.history, "当前工作区已停用历史功能(features.history: false)。");
|
|
48
|
+
const parsed = parseHistoryCommand(rest);
|
|
49
|
+
if (parsed.kind === "status") {
|
|
50
|
+
result = inspectWorkspaceSummaries(workspace.root);
|
|
51
|
+
} else if (parsed.kind === "list") {
|
|
52
|
+
const layout = readWorkspaceHistoryLayoutSync(workspace.root);
|
|
53
|
+
result = { layout, dimensions: listSummaryDimensions(layout).map(({ id, title, description }) => ({ id, title, description })) };
|
|
54
|
+
} else if (parsed.kind === "migrate") {
|
|
55
|
+
result = migrateWorkspaceHistory(workspace.root, { dryRun: parsed.dryRun });
|
|
56
|
+
} else if (parsed.kind === "query") {
|
|
57
|
+
result = await management.history({ parentSessionId: agent.id, input: json(parsed.input) }, signal);
|
|
58
|
+
} else {
|
|
59
|
+
const active = AbortSignal.any([signal, workspace.lifetime.signal]);
|
|
60
|
+
const config = await readWorkspaceConfig(workspace.root);
|
|
61
|
+
requireThat(config.enabled && !config.error, workspaceDisabledMessage(config));
|
|
62
|
+
const summaryCfg = workspaceSummaryConfig(config);
|
|
63
|
+
const backend = parsed.backend ?? summaryCfg.backend;
|
|
64
|
+
const model = parsed.model ?? summaryCfg.model;
|
|
65
|
+
const thinking = parsed.thinking ?? summaryCfg.thinking;
|
|
66
|
+
const summarizer = createAcpHistorySummarizer({
|
|
67
|
+
cwd: workspace.root,
|
|
68
|
+
backend,
|
|
69
|
+
...(config.acp ? { commands: config.acp } : {}),
|
|
70
|
+
...(model ? { model } : {}),
|
|
71
|
+
...(thinking ? { thinking } : {}),
|
|
72
|
+
});
|
|
73
|
+
const report = await runWorkspaceSummaries({
|
|
74
|
+
root: workspace.root,
|
|
75
|
+
summarizer,
|
|
76
|
+
...(parsed.dimensions ? { dimensions: parsed.dimensions } : {}),
|
|
77
|
+
force: parsed.force,
|
|
78
|
+
...(summaryCfg.concurrency !== undefined ? { concurrency: summaryCfg.concurrency } : {}),
|
|
79
|
+
signal: active,
|
|
80
|
+
});
|
|
81
|
+
result = { backend, ...(model ? { model } : {}), ...report };
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
default:
|
|
86
|
+
throw new Error(usage);
|
|
87
|
+
}
|
|
88
|
+
workspace.check();
|
|
89
|
+
return { kind: "success", text: JSON.stringify(result, null, 2) };
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
@@ -4,9 +4,9 @@ import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
|
4
4
|
import type { ToolExecution, ToolExecutionToken } from "@deepseek-ai/dsh-tools";
|
|
5
5
|
import { parsePatch } from "@deepseek-ai/dsh-fs-patch";
|
|
6
6
|
import type {} from "@deepseek-ai/dsh-user-approval";
|
|
7
|
-
import { object } from "
|
|
8
|
-
import { requireThat } from "
|
|
9
|
-
import { mutationScope } from "
|
|
7
|
+
import { object } from "../../../common/json.js";
|
|
8
|
+
import { requireThat } from "../../../common/validation.js";
|
|
9
|
+
import { mutationScope } from "../../../services/workspace/workspace-files.js";
|
|
10
10
|
|
|
11
11
|
/** Native filesystem mutations share the original workspace's confirmation rule.
|
|
12
12
|
* This does not confine Bash, Python, MCP, or other extensions. */
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
+
import type { SessionEvent } from "@deepseek-ai/dsh-session";
|
|
4
|
+
import { recordHistoryCapture } from "../../../services/history/history-capture.js";
|
|
5
|
+
import { finalDshAnswer } from "../../../integrations/hosts/dsh/messages.js";
|
|
6
|
+
|
|
7
|
+
type Question = Extract<SessionEvent, { type: "user/message" }>;
|
|
8
|
+
|
|
9
|
+
function userMessageText(content: Question["data"]["content"]): string {
|
|
10
|
+
return content.flatMap(block => block.type === "text" ? [block.text] :
|
|
11
|
+
block.type === "image" ? ["[图片 " + (block.attachment.name ?? block.attachment.attachmentId) + "]"] :
|
|
12
|
+
block.type === "file" ? ["[附件 " + (block.attachment.name ?? block.attachment.attachmentId) + "]"] : []).join("\n");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Capture root-session raw Q&A exchanges into .pbot/history/raw/. Summaries run on explicit trigger. */
|
|
16
|
+
export function registerDshHistoryEvents(ctx: Context, agent: Agent, root: string) {
|
|
17
|
+
let final = false;
|
|
18
|
+
let lastAnswer = "";
|
|
19
|
+
let lastAnswerTime: string | undefined;
|
|
20
|
+
|
|
21
|
+
ctx.on("session/event", (session, event) => {
|
|
22
|
+
if (session !== agent.session) return;
|
|
23
|
+
if (event.type === "turn/start") {
|
|
24
|
+
final = false;
|
|
25
|
+
lastAnswer = "";
|
|
26
|
+
lastAnswerTime = undefined;
|
|
27
|
+
}
|
|
28
|
+
if (event.type === "user/message" && event.data.source.kind === "user") {
|
|
29
|
+
const text = userMessageText(event.data.content).trim();
|
|
30
|
+
if (text) {
|
|
31
|
+
try {
|
|
32
|
+
recordHistoryCapture(root, "dsh", {
|
|
33
|
+
kind: "input",
|
|
34
|
+
sessionId: agent.id,
|
|
35
|
+
text,
|
|
36
|
+
timestamp: new Date(event.time).toISOString(),
|
|
37
|
+
});
|
|
38
|
+
} catch { /* Never block a user turn if history persistence fails. */ }
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (event.type === "assistant/message") {
|
|
42
|
+
const completeText = finalDshAnswer(event).trim();
|
|
43
|
+
final = Boolean(completeText);
|
|
44
|
+
const body = completeText || event.data.message.content.filter(block => block.type === "text").map(block => block.text).join("\n").trim();
|
|
45
|
+
if (body) {
|
|
46
|
+
lastAnswer = body;
|
|
47
|
+
lastAnswerTime = new Date(event.time).toISOString();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (event.type === "turn/end") {
|
|
51
|
+
const completed = event.data.reason.kind === "completed" && final;
|
|
52
|
+
if (lastAnswer) {
|
|
53
|
+
try {
|
|
54
|
+
recordHistoryCapture(root, "dsh", {
|
|
55
|
+
kind: "answer",
|
|
56
|
+
sessionId: agent.id,
|
|
57
|
+
assistantText: lastAnswer,
|
|
58
|
+
completed,
|
|
59
|
+
...(lastAnswerTime ? { timestamp: lastAnswerTime } : {}),
|
|
60
|
+
});
|
|
61
|
+
} catch { /* Never block turn completion if history persistence fails. */ }
|
|
62
|
+
}
|
|
63
|
+
lastAnswer = "";
|
|
64
|
+
lastAnswerTime = undefined;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
@@ -4,13 +4,14 @@ import { Remote, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
|
4
4
|
import type {} from "@deepseek-ai/dsh-typert-registry";
|
|
5
5
|
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
6
6
|
import { Type, type Static } from "typebox";
|
|
7
|
-
import { json, type Json } from "
|
|
8
|
-
import { requireThat } from "
|
|
9
|
-
import { schema } from "
|
|
10
|
-
import { packageVersion } from "
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
7
|
+
import { json, type Json } from "../../../common/json.js";
|
|
8
|
+
import { requireThat } from "../../../common/validation.js";
|
|
9
|
+
import { schema } from "../../../common/schema.js";
|
|
10
|
+
import { packageVersion } from "../../../common/version.js";
|
|
11
|
+
import { inspectWorkspaceSummaries } from "../../../services/history/summary-runner.js";
|
|
12
|
+
import { historyInput } from "../../../tools/history/contract.js";
|
|
13
|
+
import { executeHistory } from "../../../tools/history/actions.js";
|
|
14
|
+
import { pbotReadRemote } from "../../../ui/dsh/remote.js";
|
|
14
15
|
import type { DshWorkspaces, DshWorkspace } from "./workspace.js";
|
|
15
16
|
|
|
16
17
|
const requestSchema = Type.Object({ parentSessionId: Type.String({ minLength: 1 }), input: Type.Optional(Type.Unknown()) }, { additionalProperties: false });
|
|
@@ -26,7 +27,7 @@ export function dshStatus(workspace: DshWorkspace): Json {
|
|
|
26
27
|
workspaceRoot: workspace.root,
|
|
27
28
|
sessionId: workspace.agent.id,
|
|
28
29
|
model: workspace.agent.model.current() ?? null,
|
|
29
|
-
history: workspace.history.
|
|
30
|
+
history: workspace.features.history ? inspectWorkspaceSummaries(workspace.root) : null,
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
33
|
|
|
@@ -79,7 +80,8 @@ export class PbotManagement extends TypertRemoteService {
|
|
|
79
80
|
@Remote
|
|
80
81
|
async history(request: Json, signal: AbortSignal): Promise<Json> {
|
|
81
82
|
const current = await this.workspace(request, signal), { workspace, input } = current;
|
|
82
|
-
|
|
83
|
+
requireThat(workspace.features.history, "当前工作区已停用历史功能(features.history: false)。");
|
|
84
|
+
const result = executeHistory(workspace.root, historyInput(input), current.signal);
|
|
83
85
|
workspace.check(); current.signal.throwIfAborted(); return json(result);
|
|
84
86
|
}
|
|
85
87
|
}
|
|
@@ -4,27 +4,27 @@ import { resolve } from "node:path";
|
|
|
4
4
|
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
5
5
|
import type { Context } from "@deepseek-ai/cordis";
|
|
6
6
|
import * as McpClient from "@deepseek-ai/dsh-mcp-client";
|
|
7
|
-
import { rootAgents } from "
|
|
8
|
-
import { dshResources } from "
|
|
7
|
+
import { rootAgents } from "../../../integrations/hosts/dsh/root-agents.js";
|
|
8
|
+
import { dshResources } from "../../../integrations/hosts/dsh/resources.js";
|
|
9
9
|
import { registerDshFileEvents } from "./files.js";
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
10
|
+
import { registerDshHistoryEvents } from "./history.js";
|
|
11
|
+
import { registerDshHistoryTool } from "../../../tools/history/dsh-tool.js";
|
|
12
|
+
import { resourceRoot } from "../../../common/paths.js";
|
|
13
|
+
import { requireThat } from "../../../common/validation.js";
|
|
14
|
+
import { toDshMcpConfig } from "../../../integrations/hosts/dsh/mcp.js";
|
|
15
|
+
import { registerDshSkills } from "../../../integrations/hosts/dsh/skills.js";
|
|
16
|
+
import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../../services/workspace/workspace-config.js";
|
|
17
|
+
import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../../../services/workspace/workspace-mcp.js";
|
|
18
|
+
import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration } from "../../../model/workspace-config.js";
|
|
19
|
+
import { initializeWorkspace } from "../../../services/workspace/workspace-preparation.js";
|
|
20
|
+
import { checkHistoryMigrationNotice } from "../../../services/history/history-migrate.js";
|
|
21
|
+
import { checkHistorySummaryReminder } from "../../../services/history/summary-runner.js";
|
|
22
|
+
import { McpWorkerRuntime, defaultWorkerDirectory } from "../../mcp/workers.js";
|
|
22
23
|
|
|
23
24
|
export const dshDependencies = ["agents", "sessions", "sessionPersistence", "sessionQuery", "llm", "tools", "systemPrompt", "skills", "fs", "workingDirectory", "approval"];
|
|
24
25
|
|
|
25
26
|
export class DshWorkspace {
|
|
26
27
|
readonly lifetime = new AbortController();
|
|
27
|
-
readonly history: HistoryService;
|
|
28
28
|
readonly workers: McpWorkerRuntime;
|
|
29
29
|
#scope: { dispose(): Promise<void> } | undefined;
|
|
30
30
|
#closing: Promise<void> | undefined;
|
|
@@ -34,11 +34,8 @@ export class DshWorkspace {
|
|
|
34
34
|
readonly root: string,
|
|
35
35
|
readonly agent: Agent,
|
|
36
36
|
readonly component: AbortSignal,
|
|
37
|
-
private readonly historyWork: DshHistoryWork,
|
|
38
|
-
private readonly releaseHistory: () => Promise<void>,
|
|
39
37
|
readonly features: ResolvedWorkspaceFeatures = workspaceFeatures(),
|
|
40
38
|
) {
|
|
41
|
-
this.history = historyWork.service;
|
|
42
39
|
this.workers = new McpWorkerRuntime(defaultWorkerDirectory(), agent.id, "dsh");
|
|
43
40
|
}
|
|
44
41
|
|
|
@@ -55,8 +52,16 @@ export class DshWorkspace {
|
|
|
55
52
|
if (this.features.skills) registerDshSkills(ctx, this.agent, { workspaceRoot: this.root });
|
|
56
53
|
if (this.features.prompts) await dshResources(ctx, this.agent, this.root, "coordinator", this.check, "history-coordinator.md");
|
|
57
54
|
registerDshFileEvents(ctx, this.agent, this.root, false, this.check);
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
if (this.features.history) {
|
|
56
|
+
registerDshHistoryTool(ctx, this.agent, this.root, this.lifetime.signal, this.check);
|
|
57
|
+
registerDshHistoryEvents(ctx, this.agent, this.root);
|
|
58
|
+
try {
|
|
59
|
+
const migrationNotice = checkHistoryMigrationNotice(this.root);
|
|
60
|
+
if (migrationNotice) this.ctx.logger.info(migrationNotice);
|
|
61
|
+
const reminder = checkHistorySummaryReminder(this.root);
|
|
62
|
+
if (reminder) this.ctx.logger.info(reminder.message);
|
|
63
|
+
} catch { /* Never block workspace startup if history reminder probe fails. */ }
|
|
64
|
+
}
|
|
60
65
|
if (existsSync(mcpEntry)) {
|
|
61
66
|
await ctx.plugin(McpClient, McpClient.Config({
|
|
62
67
|
transport: "stdio",
|
|
@@ -71,6 +76,8 @@ export class DshWorkspace {
|
|
|
71
76
|
PBOT_WORKSPACE_ROOT: this.root,
|
|
72
77
|
PBOT_MCP_AGENT_DIR: workerDir,
|
|
73
78
|
PBOT_MCP_SESSION_ID: this.agent.id,
|
|
79
|
+
PBOT_NATIVE_WORKSPACE_MCP: "1",
|
|
80
|
+
PBOT_NATIVE_HISTORY: "1",
|
|
74
81
|
},
|
|
75
82
|
cwd: this.root,
|
|
76
83
|
toolCallTimeoutMs: 600_000,
|
|
@@ -106,7 +113,6 @@ export class DshWorkspace {
|
|
|
106
113
|
const errors: unknown[] = [];
|
|
107
114
|
try { await this.workers.close(); } catch (error) { errors.push(error); }
|
|
108
115
|
try { await this.#scope?.dispose(); } catch (error) { errors.push(error); }
|
|
109
|
-
try { await this.releaseHistory(); } catch (error) { errors.push(error); }
|
|
110
116
|
if (errors.length) throw new AggregateError(errors, "dsh 工作区关闭失败;请核对执行资源。");
|
|
111
117
|
})();
|
|
112
118
|
return this.#closing;
|
|
@@ -118,33 +124,10 @@ export class DshWorkspaces {
|
|
|
118
124
|
readonly #initializing = new Map<string, Promise<void>>();
|
|
119
125
|
readonly #configurations = new Map<Agent, { root: string; configuration: WorkspaceConfiguration }>();
|
|
120
126
|
readonly #parentEffects = new Map<Agent, () => Promise<void>>();
|
|
121
|
-
readonly #histories = new Map<string, { work: DshHistoryWork; users: number }>();
|
|
122
127
|
readonly #lifetime = new AbortController();
|
|
123
128
|
#closing: Promise<void> | undefined;
|
|
124
129
|
constructor(readonly ctx: Context) {}
|
|
125
130
|
|
|
126
|
-
private async history(root: string): Promise<{ work: DshHistoryWork; release(): Promise<void> }> {
|
|
127
|
-
this.#lifetime.signal.throwIfAborted();
|
|
128
|
-
let entry = this.#histories.get(root);
|
|
129
|
-
if (entry && entry.users === 0) {
|
|
130
|
-
await entry.work.close(); this.#lifetime.signal.throwIfAborted();
|
|
131
|
-
if (this.#histories.get(root) === entry) this.#histories.delete(root);
|
|
132
|
-
return this.history(root);
|
|
133
|
-
}
|
|
134
|
-
if (!entry) { entry = { work: new DshHistoryWork(this.ctx, root), users: 0 }; this.#histories.set(root, entry); }
|
|
135
|
-
const owned = entry; owned.users++;
|
|
136
|
-
let released = false;
|
|
137
|
-
return {
|
|
138
|
-
work: owned.work,
|
|
139
|
-
release: async () => {
|
|
140
|
-
if (released) return; released = true;
|
|
141
|
-
if (--owned.users === 0) {
|
|
142
|
-
try { await owned.work.close(); } finally { if (this.#histories.get(root) === owned) this.#histories.delete(root); }
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
|
|
148
131
|
async open(agent: Agent) {
|
|
149
132
|
this.#lifetime.signal.throwIfAborted();
|
|
150
133
|
requireThat(rootAgents(this.ctx.agents).includes(agent), "子会话不拥有协调者管理入口。");
|
|
@@ -164,10 +147,9 @@ export class DshWorkspaces {
|
|
|
164
147
|
this.#parentEffects.set(agent, dispose);
|
|
165
148
|
return undefined;
|
|
166
149
|
}
|
|
167
|
-
const history = await this.history(root);
|
|
168
150
|
let workspace: DshWorkspace | undefined;
|
|
169
151
|
try {
|
|
170
|
-
workspace = new DshWorkspace(this.ctx, root, agent, this.#lifetime.signal,
|
|
152
|
+
workspace = new DshWorkspace(this.ctx, root, agent, this.#lifetime.signal, workspaceFeatures(configuration));
|
|
171
153
|
const owned = workspace;
|
|
172
154
|
const dispose = agent.ctx.effect(() => async () => {
|
|
173
155
|
this.#parents.delete(agent); this.#configurations.delete(agent); this.#parentEffects.delete(agent); await owned.close();
|
|
@@ -178,7 +160,7 @@ export class DshWorkspaces {
|
|
|
178
160
|
} catch (error) {
|
|
179
161
|
try {
|
|
180
162
|
const dispose = this.#parentEffects.get(agent);
|
|
181
|
-
if (dispose) await dispose(); else if (workspace) await workspace.close();
|
|
163
|
+
if (dispose) await dispose(); else if (workspace) await workspace.close();
|
|
182
164
|
} catch (cleanup) { throw new AggregateError([error, cleanup], "dsh 工作区装配与清理均未完成。"); }
|
|
183
165
|
throw error;
|
|
184
166
|
}
|
|
@@ -240,10 +222,9 @@ export class DshWorkspaces {
|
|
|
240
222
|
const opened = await Promise.allSettled(this.#parents.values());
|
|
241
223
|
const closed = await Promise.allSettled(opened.flatMap(value => value.status === "fulfilled" && value.value ? [value.value.close()] : []));
|
|
242
224
|
const effects = await Promise.allSettled([...this.#parentEffects.values()].map(dispose => dispose()));
|
|
243
|
-
const
|
|
244
|
-
const errors = [...new Set([...closed, ...effects, ...histories].flatMap(value => value.status === "rejected" ? [value.reason] : []))];
|
|
225
|
+
const errors = [...new Set([...closed, ...effects].flatMap(value => value.status === "rejected" ? [value.reason] : []))];
|
|
245
226
|
if (errors.length) throw new AggregateError(errors, "部分 dsh 工作区未能完成关闭。");
|
|
246
|
-
} finally { this.#parents.clear(); this.#configurations.clear(); this.#parentEffects.clear();
|
|
227
|
+
} finally { this.#parents.clear(); this.#configurations.clear(); this.#parentEffects.clear(); }
|
|
247
228
|
})();
|
|
248
229
|
return this.#closing;
|
|
249
230
|
}
|
|
@@ -2,15 +2,15 @@ import { stat } from "node:fs/promises";
|
|
|
2
2
|
import { realpathSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
5
|
-
import { isMcpWorkerTool, type AcpInput } from "
|
|
6
|
-
import { acpMember } from "
|
|
7
|
-
import { agentFileTools } from "
|
|
8
|
-
import { toPiMcpConfig } from "
|
|
9
|
-
import { authorizeMutation } from "
|
|
10
|
-
import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "
|
|
11
|
-
import { resourceRoot } from "
|
|
12
|
-
import { launch } from "
|
|
13
|
-
import { requireThat } from "
|
|
5
|
+
import { isMcpWorkerTool, type AcpInput } from "../../../model/acp.js";
|
|
6
|
+
import { acpMember } from "../../acp/member.js";
|
|
7
|
+
import { agentFileTools } from "../../../integrations/hosts/pi/agent-tools.js";
|
|
8
|
+
import { toPiMcpConfig } from "../../../integrations/hosts/pi/mcp.js";
|
|
9
|
+
import { authorizeMutation } from "../../../services/workspace/workspace-files.js";
|
|
10
|
+
import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../../../services/workspace/workspace-mcp.js";
|
|
11
|
+
import { resourceRoot } from "../../../common/paths.js";
|
|
12
|
+
import { launch } from "../../../storage/agent-files.js";
|
|
13
|
+
import { requireThat } from "../../../common/validation.js";
|
|
14
14
|
|
|
15
15
|
const isBlockedTool = (name: string) => name === "pbot_history" || isMcpWorkerTool(name);
|
|
16
16
|
|