personal-bot 0.3.0 → 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 +75 -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 +75 -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 +93 -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
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { packageVersion } from "../../../common/version.js";
|
|
3
|
+
import { requireThat } from "../../../common/validation.js";
|
|
4
|
+
import { createAcpHistorySummarizer } from "../../../integrations/acp/history-summary.js";
|
|
5
|
+
import { migrateWorkspaceHistory } from "../../../services/history/history-migrate.js";
|
|
6
|
+
import { parseHistoryCommand } from "../../../services/history/summary-command.js";
|
|
7
|
+
import { listSummaryDimensions } from "../../../services/history/summary-registry.js";
|
|
8
|
+
import { inspectWorkspaceSummaries, runWorkspaceSummaries } from "../../../services/history/summary-runner.js";
|
|
9
|
+
import { initializeWorkspace } from "../../../services/workspace/workspace-preparation.js";
|
|
10
|
+
import { readWorkspaceConfig, readWorkspaceHistoryLayoutSync, workspaceDisabledMessage, workspaceSummaryConfig } from "../../../services/workspace/workspace-config.js";
|
|
11
|
+
import { executeHistory } from "../../../tools/history/actions.js";
|
|
12
|
+
import { historyInput } from "../../../tools/history/contract.js";
|
|
13
|
+
import type { Confirmations } from "../../../ui/pi/confirmation.js";
|
|
14
|
+
import type { Lifecycle } from "./lifecycle.js";
|
|
15
|
+
import { parseWorkerCommand } from "../../mcp/workers.js";
|
|
16
|
+
|
|
17
|
+
function formatHistoryStatusLine(root: string): string[] {
|
|
18
|
+
const status = inspectWorkspaceSummaries(root);
|
|
19
|
+
const parts = status.dimensions.map(dim => {
|
|
20
|
+
const pending = dim.pendingCreate + dim.pendingIncremental + dim.pendingRebuild;
|
|
21
|
+
return `${dim.dimension} ${dim.ready}/${dim.total}` + (pending ? `(待处理 ${pending})` : "");
|
|
22
|
+
});
|
|
23
|
+
return [
|
|
24
|
+
`历史 原始会话 ${status.rawCount}` + (parts.length ? ` · ${parts.join(",")}` : ""),
|
|
25
|
+
...(status.reminder ? [`提示 ${status.reminder.message}`] : []),
|
|
26
|
+
...status.warnings,
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function registerCommand(pi: ExtensionAPI, lifecycle: Lifecycle, confirmations: Confirmations) {
|
|
31
|
+
pi.registerCommand("pbot", {
|
|
32
|
+
description: "工作区初始化、状态、历史摘要与跨 Harness worker 管理",
|
|
33
|
+
getArgumentCompletions: prefix => {
|
|
34
|
+
if (/\s/.test(prefix)) return null;
|
|
35
|
+
return ["init", "status", "history", "worker"]
|
|
36
|
+
.filter(command => command.startsWith(prefix)).map(command => ({ value: command, label: command }));
|
|
37
|
+
},
|
|
38
|
+
handler: async (args, ctx) => {
|
|
39
|
+
const [, command, argument = ""] = args.trim().match(/^(\S+)(?:\s+([\s\S]*))?$/) ?? [];
|
|
40
|
+
confirmations.resume();
|
|
41
|
+
if (command === "init" && !argument) {
|
|
42
|
+
await ctx.waitForIdle();
|
|
43
|
+
const start = !lifecycle.active;
|
|
44
|
+
await initializeWorkspace(lifecycle.root ?? ctx.cwd);
|
|
45
|
+
ctx.ui.notify(start ? "工作区已初始化并启用,正在加载 Personal Bot。" : "资料目录已准备;新建的 AGENTS.md 经 /reload 加载。", "info");
|
|
46
|
+
if (start) await ctx.reload();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!lifecycle.active) {
|
|
50
|
+
const configuration = lifecycle.configuration;
|
|
51
|
+
const status = {
|
|
52
|
+
workspaceRoot: lifecycle.root ?? ctx.cwd,
|
|
53
|
+
release: packageVersion,
|
|
54
|
+
enabled: false,
|
|
55
|
+
state: configuration?.error || configuration?.enabled ? "error" : "disabled",
|
|
56
|
+
nextStep: configuration?.error ?? "/pbot init",
|
|
57
|
+
configuration,
|
|
58
|
+
};
|
|
59
|
+
ctx.ui.notify(command === "status" ? JSON.stringify(status, null, 2)
|
|
60
|
+
: configuration ? workspaceDisabledMessage(configuration) : "pbot 工作区实例不可用。", configuration?.error ? "error" : "info");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const instance = lifecycle.get();
|
|
64
|
+
if (command === "status" && !argument) {
|
|
65
|
+
if (ctx.mode !== "tui") {
|
|
66
|
+
ctx.ui.notify(JSON.stringify({
|
|
67
|
+
workspaceRoot: instance.root,
|
|
68
|
+
release: packageVersion,
|
|
69
|
+
enabled: true,
|
|
70
|
+
state: "running",
|
|
71
|
+
configuration: lifecycle.configuration,
|
|
72
|
+
...(instance.features.history ? { history: inspectWorkspaceSummaries(instance.root) } : {}),
|
|
73
|
+
}, null, 2), "info");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
ctx.ui.notify([
|
|
77
|
+
`工作区 ${instance.root}`,
|
|
78
|
+
`状态 已启动 · 版本 ${packageVersion}`,
|
|
79
|
+
...(instance.features.history ? formatHistoryStatusLine(instance.root) : ["历史 已停用"]),
|
|
80
|
+
].join("\n"), "info");
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (command === "history") {
|
|
84
|
+
try {
|
|
85
|
+
requireThat(instance.features.history, "当前工作区已停用历史功能(features.history: false)。");
|
|
86
|
+
const parsed = parseHistoryCommand(argument);
|
|
87
|
+
if (parsed.kind === "status") {
|
|
88
|
+
ctx.ui.notify(JSON.stringify(inspectWorkspaceSummaries(instance.root), null, 2), "info");
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (parsed.kind === "list") {
|
|
92
|
+
const layout = readWorkspaceHistoryLayoutSync(instance.root);
|
|
93
|
+
const dims = listSummaryDimensions(layout).map(({ id, title, description }) => ({ id, title, description }));
|
|
94
|
+
ctx.ui.notify(JSON.stringify({ layout, dimensions: dims }, null, 2), "info");
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (parsed.kind === "migrate") {
|
|
98
|
+
const report = migrateWorkspaceHistory(instance.root, { dryRun: parsed.dryRun });
|
|
99
|
+
ctx.ui.notify(JSON.stringify(report, null, 2), "info");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (parsed.kind === "query") {
|
|
103
|
+
const result = executeHistory(instance.root, historyInput(parsed.input), instance.signal());
|
|
104
|
+
ctx.ui.notify(JSON.stringify(result, null, 2), "info");
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const signal = instance.signal();
|
|
108
|
+
const config = await readWorkspaceConfig(instance.root);
|
|
109
|
+
requireThat(config.enabled && !config.error, workspaceDisabledMessage(config));
|
|
110
|
+
const summaryCfg = workspaceSummaryConfig(config);
|
|
111
|
+
const backend = parsed.backend ?? summaryCfg.backend;
|
|
112
|
+
const model = parsed.model ?? summaryCfg.model;
|
|
113
|
+
const thinking = parsed.thinking ?? summaryCfg.thinking;
|
|
114
|
+
const summarizer = createAcpHistorySummarizer({
|
|
115
|
+
cwd: instance.root,
|
|
116
|
+
backend,
|
|
117
|
+
...(config.acp ? { commands: config.acp } : {}),
|
|
118
|
+
...(model ? { model } : {}),
|
|
119
|
+
...(thinking ? { thinking } : {}),
|
|
120
|
+
});
|
|
121
|
+
ctx.ui.setStatus("pbot-history", `历史摘要生成中 (${backend})`);
|
|
122
|
+
try {
|
|
123
|
+
const report = await runWorkspaceSummaries({
|
|
124
|
+
root: instance.root,
|
|
125
|
+
summarizer,
|
|
126
|
+
...(parsed.dimensions ? { dimensions: parsed.dimensions } : {}),
|
|
127
|
+
force: parsed.force,
|
|
128
|
+
...(summaryCfg.concurrency !== undefined ? { concurrency: summaryCfg.concurrency } : {}),
|
|
129
|
+
signal,
|
|
130
|
+
onProgress: progress => {
|
|
131
|
+
if (lifecycle.active === instance) {
|
|
132
|
+
ctx.ui.setStatus("pbot-history", `历史摘要 ${progress.dimension} (${progress.completed}/${progress.total})`);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
ctx.ui.notify(JSON.stringify({ backend, ...(model ? { model } : {}), ...report }, null, 2), "info");
|
|
137
|
+
} finally {
|
|
138
|
+
if (lifecycle.active === instance) ctx.ui.setStatus("pbot-history", undefined);
|
|
139
|
+
}
|
|
140
|
+
} catch (error) {
|
|
141
|
+
ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
|
|
142
|
+
}
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (command === "worker") {
|
|
146
|
+
try {
|
|
147
|
+
const { tool, args: payload } = parseWorkerCommand(argument);
|
|
148
|
+
const result = await instance.workers.callTool(tool, { workspace: instance.root, ...payload });
|
|
149
|
+
ctx.ui.notify(JSON.stringify(result, null, 2), "info");
|
|
150
|
+
} catch (error) {
|
|
151
|
+
ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
|
|
152
|
+
}
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
ctx.ui.notify('/pbot init | status | history [summary [维度] [--force] [--backend <acp>] [--model <model>]|migrate [--dry-run]|status|list|JSON] | worker [overview|status|backends|models|create|request|response|output|close] [JSON]', "info");
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
}
|
|
@@ -2,11 +2,13 @@ import { join, resolve } from "node:path";
|
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
5
|
-
import { loadWorkspaceContext } from "
|
|
6
|
-
import type { Confirmations } from "
|
|
5
|
+
import { loadWorkspaceContext } from "../../../integrations/agent-resources.js";
|
|
6
|
+
import type { Confirmations } from "../../../ui/pi/confirmation.js";
|
|
7
7
|
import type { Lifecycle } from "./lifecycle.js";
|
|
8
|
-
import { readWorkspaceConfig, workspaceDisabledMessage } from "
|
|
9
|
-
import {
|
|
8
|
+
import { readWorkspaceConfig, workspaceDisabledMessage } from "../../../services/workspace/workspace-config.js";
|
|
9
|
+
import { checkHistoryMigrationNotice } from "../../../services/history/history-migrate.js";
|
|
10
|
+
import { checkHistorySummaryReminder } from "../../../services/history/summary-runner.js";
|
|
11
|
+
import { workspaceSkillPaths } from "../../../integrations/hosts/pi/skills.js";
|
|
10
12
|
|
|
11
13
|
export function registerEvents(pi: ExtensionAPI, lifecycle: Lifecycle, confirmations: Confirmations) {
|
|
12
14
|
pi.on("session_start", async (_event, ctx) => {
|
|
@@ -18,6 +20,14 @@ export function registerEvents(pi: ExtensionAPI, lifecycle: Lifecycle, confirmat
|
|
|
18
20
|
return;
|
|
19
21
|
}
|
|
20
22
|
ctx.ui.setStatus("pbot", "PBot 已启动");
|
|
23
|
+
if (lifecycle.active.features.history && ctx.hasUI) {
|
|
24
|
+
try {
|
|
25
|
+
const migrationNotice = checkHistoryMigrationNotice(lifecycle.active.root);
|
|
26
|
+
if (migrationNotice) ctx.ui.notify(migrationNotice, "info");
|
|
27
|
+
const reminder = checkHistorySummaryReminder(lifecycle.active.root);
|
|
28
|
+
if (reminder) ctx.ui.notify(reminder.message, "info");
|
|
29
|
+
} catch { /* Never block session startup if history reminder probe fails. */ }
|
|
30
|
+
}
|
|
21
31
|
} catch (error) {
|
|
22
32
|
ctx.ui.setStatus("pbot", "PBot 启动失败");
|
|
23
33
|
if (ctx.hasUI) ctx.ui.notify(error instanceof Error ? error.message : "pbot 启动失败。", "error");
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { recordHistoryCapture } from "../../../services/history/history-capture.js";
|
|
3
|
+
import type { Lifecycle } from "./lifecycle.js";
|
|
4
|
+
|
|
5
|
+
function messageText(content: unknown): string {
|
|
6
|
+
if (typeof content === "string") return content;
|
|
7
|
+
if (!Array.isArray(content)) return "";
|
|
8
|
+
return content.flatMap(block => block?.type === "text" ? [String(block.text)] : block?.type === "image" ? ["[图片]"] : []).join("\n");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Capture main-session raw Q&A exchanges into .pbot/history/raw/. Summaries run on explicit trigger. */
|
|
12
|
+
export function registerHistoryEvents(pi: ExtensionAPI, lifecycle: Lifecycle) {
|
|
13
|
+
pi.on("before_agent_start", (event, ctx) => {
|
|
14
|
+
const instance = lifecycle.active;
|
|
15
|
+
if (!instance || !instance.features.history || event.messageType !== "user") return;
|
|
16
|
+
const text = event.prompt.trim();
|
|
17
|
+
if (!text) return;
|
|
18
|
+
try {
|
|
19
|
+
recordHistoryCapture(instance.root, "pi", {
|
|
20
|
+
kind: "input",
|
|
21
|
+
sessionId: ctx.sessionManager.getSessionId(),
|
|
22
|
+
text,
|
|
23
|
+
});
|
|
24
|
+
} catch { /* Never block a user turn if history persistence fails. */ }
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
pi.on("agent_end", (event, ctx) => {
|
|
28
|
+
const instance = lifecycle.active;
|
|
29
|
+
if (!instance || !instance.features.history) return;
|
|
30
|
+
const assistant = [...event.messages].reverse().find(message => message.role === "assistant");
|
|
31
|
+
if (!assistant || !("content" in assistant)) return;
|
|
32
|
+
const text = messageText(assistant.content).trim();
|
|
33
|
+
if (!text) return;
|
|
34
|
+
const completed = "stopReason" in assistant && assistant.stopReason === "stop" &&
|
|
35
|
+
!(Array.isArray(assistant.content) && assistant.content.some(block => block.type === "toolCall"));
|
|
36
|
+
try {
|
|
37
|
+
recordHistoryCapture(instance.root, "pi", {
|
|
38
|
+
kind: "answer",
|
|
39
|
+
sessionId: ctx.sessionManager.getSessionId(),
|
|
40
|
+
assistantText: text,
|
|
41
|
+
completed,
|
|
42
|
+
});
|
|
43
|
+
} catch { /* Never block turn completion if history persistence fails. */ }
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { realpath } from "node:fs/promises";
|
|
2
|
-
import { requireThat } from "
|
|
3
|
-
import { authorizeMutation } from "
|
|
4
|
-
import type { CallAccess } from "
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import type {
|
|
8
|
-
import type { McpWorkerRuntime } from "./mcp-workers.js";
|
|
2
|
+
import { requireThat } from "../../../common/validation.js";
|
|
3
|
+
import { authorizeMutation } from "../../../services/workspace/workspace-files.js";
|
|
4
|
+
import type { CallAccess } from "../../../tools/access.js";
|
|
5
|
+
import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../../services/workspace/workspace-config.js";
|
|
6
|
+
import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration } from "../../../model/workspace-config.js";
|
|
7
|
+
import type { McpWorkerRuntime } from "../../mcp/workers.js";
|
|
9
8
|
|
|
10
9
|
export class WorkspaceInstance implements CallAccess {
|
|
11
10
|
readonly #controller = new AbortController();
|
|
@@ -15,7 +14,6 @@ export class WorkspaceInstance implements CallAccess {
|
|
|
15
14
|
constructor(
|
|
16
15
|
readonly root: string,
|
|
17
16
|
readonly sessionId: string,
|
|
18
|
-
readonly history: HistoryService,
|
|
19
17
|
readonly workers: McpWorkerRuntime,
|
|
20
18
|
readonly features: ResolvedWorkspaceFeatures = workspaceFeatures(),
|
|
21
19
|
) {}
|
|
@@ -45,9 +43,7 @@ export class WorkspaceInstance implements CallAccess {
|
|
|
45
43
|
this.#controller.abort();
|
|
46
44
|
this.#work.abort();
|
|
47
45
|
this.#closing = (async () => {
|
|
48
|
-
|
|
49
|
-
const errors = results.filter(result => result.status === "rejected").map(result => result.reason);
|
|
50
|
-
if (errors.length) throw new AggregateError(errors, "工作区关闭失败。");
|
|
46
|
+
await this.workers.close(preserveWorkers);
|
|
51
47
|
})();
|
|
52
48
|
return this.#closing;
|
|
53
49
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { resourceRoot } from "
|
|
2
|
-
import { packageVersion } from "
|
|
3
|
-
import { requireThat } from "
|
|
4
|
-
import { loadWorkspaceContext } from "
|
|
5
|
-
import type { PluginHostAdapter } from "
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
import { resourceRoot } from "../../common/paths.js";
|
|
2
|
+
import { packageVersion } from "../../common/version.js";
|
|
3
|
+
import { requireThat } from "../../common/validation.js";
|
|
4
|
+
import { loadWorkspaceContext } from "../../integrations/agent-resources.js";
|
|
5
|
+
import type { PluginHostAdapter } from "../../model/plugin-host.js";
|
|
6
|
+
import { recordHistoryCapture } from "../../services/history/history-capture.js";
|
|
7
|
+
import { checkHistoryMigrationNotice } from "../../services/history/history-migrate.js";
|
|
8
|
+
import { checkHistorySummaryReminder } from "../../services/history/summary-runner.js";
|
|
9
|
+
import { readWorkspaceConfig, workspaceFeatures } from "../../services/workspace/workspace-config.js";
|
|
10
|
+
import { initializeWorkspace } from "../../services/workspace/workspace-preparation.js";
|
|
11
|
+
import { discoverWorkspaceSkills } from "../../services/workspace/workspace-skills.js";
|
|
9
12
|
|
|
10
13
|
function disabledMessage(adapter: PluginHostAdapter, configuration: Awaited<ReturnType<typeof readWorkspaceConfig>>) {
|
|
11
14
|
return configuration.error ?? `Personal Bot 未在此工作区启用。运行 ${adapter.initCommandHint};配置文件:${configuration.path}`;
|
|
@@ -45,10 +48,26 @@ export async function pluginHook(adapter: PluginHostAdapter, payload: unknown):
|
|
|
45
48
|
return adapter.formatPass(payload);
|
|
46
49
|
}
|
|
47
50
|
if (!configuration.enabled) return adapter.formatPass(payload);
|
|
51
|
+
if (features.history && adapter.extractHistory) {
|
|
52
|
+
try {
|
|
53
|
+
const capture = await adapter.extractHistory(event);
|
|
54
|
+
if (capture) recordHistoryCapture(root, adapter.host, capture);
|
|
55
|
+
} catch { /* Never block a host turn if history persistence encounters a transient error or busy lock. */ }
|
|
56
|
+
}
|
|
57
|
+
if (event.kind === "record-history") return adapter.formatPass(payload);
|
|
48
58
|
const workspaceSkills = features.skills && !adapter.nativeWorkspaceSkills
|
|
49
59
|
? await discoverWorkspaceSkills(root)
|
|
50
60
|
: [];
|
|
51
|
-
|
|
61
|
+
const notices: string[] = [];
|
|
62
|
+
if (event.isSessionStart && features.history) {
|
|
63
|
+
try {
|
|
64
|
+
const migrationNotice = checkHistoryMigrationNotice(root);
|
|
65
|
+
if (migrationNotice) notices.push(migrationNotice);
|
|
66
|
+
const reminder = checkHistorySummaryReminder(root);
|
|
67
|
+
if (reminder) notices.push(reminder.message);
|
|
68
|
+
} catch { /* Never block session start if history reminder probe fails. */ }
|
|
69
|
+
}
|
|
70
|
+
if (!features.prompts && !workspaceSkills.length && !notices.length) return adapter.formatPass(payload);
|
|
52
71
|
const context = await loadWorkspaceContext({
|
|
53
72
|
host: adapter.host,
|
|
54
73
|
root,
|
|
@@ -58,6 +77,7 @@ export async function pluginHook(adapter: PluginHostAdapter, payload: unknown):
|
|
|
58
77
|
includeRootAgents: features.prompts && !adapter.nativeRootAgents,
|
|
59
78
|
...(event.localRoleOnly ? { localRoleOnly: true } : {}),
|
|
60
79
|
workspaceSkills,
|
|
80
|
+
notices,
|
|
61
81
|
});
|
|
62
82
|
return adapter.formatContext(event, context);
|
|
63
83
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
|
|
2
2
|
import { setTimeout as delay } from "node:timers/promises";
|
|
3
|
-
import { object } from "
|
|
4
|
-
import { requireThat } from "
|
|
5
|
-
import { packageVersion } from "
|
|
3
|
+
import { object } from "../../common/json.js";
|
|
4
|
+
import { requireThat } from "../../common/validation.js";
|
|
5
|
+
import { packageVersion } from "../../common/version.js";
|
|
6
6
|
import type {
|
|
7
7
|
ResolvedWorkspaceMcpHttpServer,
|
|
8
8
|
ResolvedWorkspaceMcpServer,
|
|
9
9
|
ResolvedWorkspaceMcpStdioServer,
|
|
10
|
-
} from "
|
|
10
|
+
} from "../../model/workspace-mcp.js";
|
|
11
11
|
import {
|
|
12
12
|
readWorkspaceMcpConfig,
|
|
13
13
|
resolveWorkspaceMcpServer,
|
|
14
14
|
resolveWorkspaceMcpServers,
|
|
15
|
-
} from "
|
|
15
|
+
} from "../../services/workspace/workspace-mcp.js";
|
|
16
16
|
|
|
17
17
|
const protocolVersion = "2025-03-26";
|
|
18
18
|
const maxStderrBytes = 4096;
|