personal-bot 0.3.2 → 0.3.4
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 +2 -1
- package/DISCLAIMER.md +17 -0
- package/LICENSE +21 -0
- package/README.md +15 -5
- package/README.zh-CN.md +15 -5
- package/bin/pbot-pi-acp.mjs +1 -1
- package/bin/pbot.mjs +22 -2
- package/docs/README.md +2 -0
- package/docs/architecture/design.md +16 -16
- package/docs/architecture/extensibility.md +29 -2
- package/docs/architecture/model-context.md +3 -2
- package/docs/architecture/principles.md +2 -2
- package/docs/guides/capabilities.md +1 -1
- package/docs/guides/cross-harness-workers.md +3 -1
- package/docs/guides/history.md +30 -7
- package/docs/guides/workspace-configuration.md +20 -3
- package/docs/hosts/antigravity.md +1 -1
- package/docs/hosts/claude-code.md +1 -1
- package/docs/hosts/codex-qoder.md +63 -0
- package/docs/maintainers/architecture-governance.md +78 -0
- package/lib/antigravity-plugin/DISCLAIMER.md +17 -0
- package/lib/antigravity-plugin/LICENSE +21 -0
- package/lib/antigravity-plugin/bin/pbot-pi-acp.mjs +36 -0
- package/lib/antigravity-plugin/lib/common/files.d.ts +2 -0
- package/lib/antigravity-plugin/lib/common/files.js +44 -0
- package/lib/antigravity-plugin/lib/common/validation.d.ts +4 -0
- package/lib/antigravity-plugin/lib/common/validation.js +8 -0
- package/lib/antigravity-plugin/lib/extension/acp/member.d.ts +18 -0
- package/lib/antigravity-plugin/lib/extension/acp/member.js +44 -0
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +71 -45
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.js +22 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.d.ts +4 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.js +58 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.d.ts +5 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.js +67 -0
- package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.d.ts +3 -0
- package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.js +100 -0
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.d.ts +3 -1
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +37 -22
- package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.d.ts +6 -0
- package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.js +21 -0
- package/lib/antigravity-plugin/lib/extension/mcp.js +2577 -2255
- package/lib/antigravity-plugin/lib/extension/workspace-cli.js +20171 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/claude/adapter.js +7 -59
- package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.d.ts +2 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.js +14 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/mcp.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/mcp.js +28 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.d.ts +36 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.js +11 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.d.ts +6 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.js +47 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.js +3 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.d.ts +8 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.js +31 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.js +32 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.js +23 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/plugin-registry.d.ts +1 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/plugin-registry.js +8 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.js +76 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.js +16 -0
- package/lib/antigravity-plugin/lib/model/acp.d.ts +7 -3
- package/lib/antigravity-plugin/lib/model/acp.js +8 -0
- package/lib/antigravity-plugin/lib/model/agent.d.ts +121 -0
- package/lib/antigravity-plugin/lib/model/agent.js +4 -0
- package/lib/antigravity-plugin/lib/model/history.d.ts +10 -0
- package/lib/antigravity-plugin/lib/model/history.js +4 -1
- package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +5 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +8 -12
- package/lib/antigravity-plugin/lib/model/workspace-config.js +2 -1
- package/lib/antigravity-plugin/lib/plugin.d.ts +2 -1
- package/lib/antigravity-plugin/lib/plugin.js +2 -2
- package/lib/antigravity-plugin/lib/services/history/history-capture.js +34 -22
- package/lib/antigravity-plugin/lib/services/history/summary-registry.js +2 -3
- package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +2 -5
- package/lib/antigravity-plugin/lib/services/history/summary-runner.js +72 -74
- package/lib/antigravity-plugin/lib/services/history/workspace-history.d.ts +3 -0
- package/lib/antigravity-plugin/lib/services/history/workspace-history.js +6 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +15 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +126 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +9 -8
- package/lib/antigravity-plugin/lib/services/workspace/workspace-files.d.ts +2 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-files.js +17 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.d.ts +14 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.js +193 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.d.ts +1 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.js +4 -2
- package/lib/antigravity-plugin/lib/storage/acp-files.d.ts +11 -0
- package/lib/antigravity-plugin/lib/storage/acp-files.js +75 -0
- package/lib/antigravity-plugin/lib/storage/agent-files.d.ts +31 -0
- package/lib/antigravity-plugin/lib/storage/agent-files.js +159 -0
- package/lib/antigravity-plugin/lib/storage/atomic-json.d.ts +3 -1
- package/lib/antigravity-plugin/lib/storage/atomic-json.js +43 -3
- package/lib/antigravity-plugin/lib/storage/history-files.d.ts +2 -1
- package/lib/antigravity-plugin/lib/storage/history-files.js +21 -15
- package/lib/antigravity-plugin/lib/storage/history-format.d.ts +2 -3
- package/lib/antigravity-plugin/lib/storage/history-format.js +5 -7
- package/lib/antigravity-plugin/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +1 -1
- package/lib/antigravity-plugin/resources/prompts/history-monthly-summary.md +13 -0
- package/lib/antigravity-plugin/resources/prompts/history-summary.md +13 -0
- package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -0
- package/lib/antigravity-plugin/resources/skills/.claude-plugin/plugin.json +4 -0
- package/lib/antigravity-plugin/resources/skills/project-maintenance/SKILL.md +35 -0
- package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +52 -0
- package/lib/antigravity-plugin/skills/pbot/SKILL.md +11 -1
- package/lib/client.js +22 -50
- package/lib/codex-marketplace/.agents/plugins/marketplace.json +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +7 -0
- package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/DISCLAIMER.md +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/LICENSE +21 -0
- package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +37 -0
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +9 -0
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/agents/openai.yaml +2 -0
- package/lib/common/validation.d.ts +4 -0
- package/lib/common/validation.js +8 -0
- package/lib/dsh.js +2 -2
- package/lib/extension/acp/member.d.ts +1 -1
- package/lib/extension/acp-worker.js +71 -45
- package/lib/extension/history/command.d.ts +37 -0
- package/lib/extension/history/command.js +57 -0
- package/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
- package/lib/extension/hosts/dsh/acp-entry.js +22 -0
- package/lib/extension/hosts/dsh/acp-member.js +4 -18
- package/lib/extension/hosts/dsh/command.d.ts +1 -2
- package/lib/extension/hosts/dsh/command.js +5 -49
- package/lib/extension/hosts/dsh/workspace.js +13 -44
- package/lib/extension/hosts/pi/acp-member.d.ts +3 -0
- package/lib/extension/hosts/pi/acp-member.js +100 -0
- package/lib/extension/hosts/plugin-runtime.d.ts +3 -1
- package/lib/extension/hosts/plugin-runtime.js +37 -22
- package/lib/extension/hosts/workspace-mcp.d.ts +6 -0
- package/lib/extension/hosts/workspace-mcp.js +21 -0
- package/lib/extension/mcp/bridge.d.ts +6 -8
- package/lib/extension/mcp/bridge.js +66 -84
- package/lib/extension/mcp/tool-contract.d.ts +735 -0
- package/lib/extension/mcp/tool-contract.js +441 -0
- package/lib/extension/mcp/workers.d.ts +29 -742
- package/lib/extension/mcp/workers.js +75 -525
- package/lib/extension/mcp.js +2577 -2255
- package/lib/extension/setup/cli.js +15 -0
- package/lib/extension/setup/upgrade.js +153 -0
- package/lib/extension/workspace-cli.js +20171 -0
- package/lib/integrations/acp/agents.d.ts +2 -3
- package/lib/integrations/acp/harnesses/dsh.js +1 -1
- package/lib/integrations/acp/harnesses/presets.js +8 -0
- package/lib/integrations/acp/history-summary.js +2 -1
- package/lib/integrations/acp/launch.d.ts +2 -2
- package/lib/integrations/agent-resources.js +1 -1
- package/lib/integrations/hosts/claude/adapter.js +7 -59
- package/lib/integrations/hosts/codex/adapter.d.ts +2 -0
- package/lib/integrations/hosts/codex/adapter.js +14 -0
- package/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
- package/lib/integrations/hosts/pi/agent-tools.js +32 -0
- package/lib/integrations/hosts/pi/mcp.d.ts +4 -0
- package/lib/integrations/hosts/pi/mcp.js +23 -0
- package/lib/integrations/hosts/plugin-registry.d.ts +1 -0
- package/lib/integrations/hosts/plugin-registry.js +8 -1
- package/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
- package/lib/integrations/hosts/prompt-hooks.js +76 -0
- package/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
- package/lib/integrations/hosts/qoder/adapter.js +16 -0
- package/lib/integrations/installation/cli-update.js +146 -0
- package/lib/integrations/installation/upgraders/antigravity.js +67 -0
- package/lib/integrations/installation/upgraders/claude.js +123 -0
- package/lib/integrations/installation/upgraders/codex.js +73 -0
- package/lib/integrations/installation/upgraders/dsh.js +62 -0
- package/lib/integrations/installation/upgraders/pi.js +90 -0
- package/lib/integrations/installation/upgraders/qoder.js +67 -0
- package/lib/integrations/installation/upgraders/registry.js +40 -0
- package/lib/model/acp.d.ts +7 -3
- package/lib/model/acp.js +8 -0
- package/lib/model/agent.d.ts +18 -4
- package/lib/model/agent.js +4 -1
- package/lib/model/history.d.ts +10 -0
- package/lib/model/history.js +4 -1
- package/lib/model/installation.js +1 -0
- package/lib/model/plugin-host.d.ts +5 -0
- package/lib/model/workspace-config.d.ts +8 -12
- package/lib/model/workspace-config.js +2 -1
- package/lib/plugin.d.ts +2 -1
- package/lib/plugin.js +2 -2
- package/lib/qoder-plugin/.mcp.json +17 -0
- package/lib/qoder-plugin/.qoder-plugin/plugin.json +7 -0
- package/lib/qoder-plugin/DISCLAIMER.md +17 -0
- package/lib/qoder-plugin/LICENSE +21 -0
- package/lib/qoder-plugin/hooks/hooks.json +37 -0
- package/lib/qoder-plugin/skills/pbot/SKILL.md +9 -0
- package/lib/services/agents/agent-service.d.ts +15 -45
- package/lib/services/agents/agent-service.js +22 -3
- package/lib/services/history/history-capture.js +34 -22
- package/lib/services/history/history-migrate.js +26 -60
- package/lib/services/history/history-query.js +38 -57
- package/lib/services/history/summary-command.d.ts +1 -1
- package/lib/services/history/summary-command.js +8 -7
- package/lib/services/history/summary-registry.js +2 -3
- package/lib/services/history/summary-runner.d.ts +2 -5
- package/lib/services/history/summary-runner.js +72 -74
- package/lib/services/history/workspace-history.d.ts +3 -0
- package/lib/services/history/workspace-history.js +6 -0
- package/lib/services/installation/setup-service.js +4 -1
- package/lib/services/installation/upgrade-service.js +95 -0
- package/lib/services/workspace/plugin-releases.d.ts +15 -0
- package/lib/services/workspace/plugin-releases.js +126 -0
- package/lib/services/workspace/workspace-config.js +9 -8
- package/lib/services/workspace/workspace-mcp.js +22 -29
- package/lib/services/workspace/workspace-skills.d.ts +1 -0
- package/lib/services/workspace/workspace-skills.js +4 -2
- package/lib/storage/acp-files.js +7 -12
- package/lib/storage/agent-files.js +6 -5
- package/lib/storage/atomic-json.d.ts +3 -1
- package/lib/storage/atomic-json.js +43 -3
- package/lib/storage/history-files.d.ts +2 -1
- package/lib/storage/history-files.js +21 -15
- package/lib/storage/history-format.d.ts +2 -3
- package/lib/storage/history-format.js +5 -7
- package/lib/tools/history/contract.d.ts +3 -11
- package/lib/tools/history/contract.js +8 -7
- package/lib/ui/dsh/elements.d.ts +2 -5
- package/lib/ui/dsh/elements.js +3 -16
- package/lib/ui/dsh/management.js +9 -9
- package/lib/ui/dsh/styles.d.ts +1 -1
- package/lib/ui/dsh/styles.js +5 -33
- package/package.json +4 -1
- package/resources/antigravity/skills/pbot/SKILL.md +11 -1
- package/resources/claude/skills/pbot/SKILL.md +11 -1
- package/resources/plugin/skills/pbot/SKILL.md +9 -0
- package/resources/prompts/history-coordinator.md +1 -0
- package/resources/prompts/plugin-coordinator.md +1 -0
- package/scripts/README.md +3 -2
- package/src/common/validation.ts +10 -0
- package/src/dsh.ts +2 -2
- package/src/extension/history/command.ts +68 -0
- package/src/extension/hosts/dsh/acp-entry.ts +21 -0
- package/src/extension/hosts/dsh/acp-member.ts +4 -15
- package/src/extension/hosts/dsh/command.ts +6 -46
- package/src/extension/hosts/dsh/workspace.ts +12 -38
- package/src/extension/hosts/pi/acp-member.ts +4 -10
- package/src/extension/hosts/pi/command.ts +14 -63
- package/src/extension/hosts/pi/events.ts +2 -8
- package/src/extension/hosts/pi/lifecycle.ts +3 -2
- package/src/extension/hosts/plugin-runtime.ts +39 -19
- package/src/extension/hosts/workspace-mcp.ts +25 -0
- package/src/extension/mcp/bridge.ts +80 -80
- package/src/extension/mcp/tool-contract.ts +462 -0
- package/src/extension/mcp/workers.ts +81 -551
- package/src/extension/setup/cli.ts +11 -1
- package/src/extension/setup/upgrade.ts +158 -0
- package/src/extension/setup/workspace-cli.ts +167 -0
- package/src/integrations/acp/agents.ts +2 -3
- package/src/integrations/acp/harnesses/dsh.ts +1 -1
- package/src/integrations/acp/harnesses/presets.ts +8 -0
- package/src/integrations/acp/history-summary.ts +2 -1
- package/src/integrations/agent-resources.ts +1 -1
- package/src/integrations/hosts/claude/adapter.ts +7 -53
- package/src/integrations/hosts/codex/adapter.ts +16 -0
- package/src/integrations/hosts/plugin-registry.ts +9 -1
- package/src/integrations/hosts/prompt-hooks.ts +72 -0
- package/src/integrations/hosts/qoder/adapter.ts +19 -0
- package/src/integrations/installation/cli-update.ts +144 -0
- package/src/integrations/installation/pi-bridge.ts +1 -1
- package/src/integrations/installation/pi-setup.ts +1 -1
- package/src/integrations/installation/processes.ts +1 -1
- package/src/integrations/installation/upgraders/antigravity.ts +68 -0
- package/src/integrations/installation/upgraders/claude.ts +123 -0
- package/src/integrations/installation/upgraders/codex.ts +73 -0
- package/src/integrations/installation/upgraders/dsh.ts +63 -0
- package/src/integrations/installation/upgraders/pi.ts +87 -0
- package/src/integrations/installation/upgraders/qoder.ts +68 -0
- package/src/integrations/installation/upgraders/registry.ts +48 -0
- package/src/model/acp.ts +11 -3
- package/src/model/agent.ts +20 -4
- package/src/model/history.ts +5 -0
- package/src/model/installation.ts +86 -0
- package/src/model/plugin-host.ts +5 -1
- package/src/model/workspace-config.ts +6 -12
- package/src/pbot.ts +13 -32
- package/src/plugin.ts +3 -3
- package/src/services/agents/agent-service.ts +29 -17
- package/src/services/history/history-capture.ts +30 -22
- package/src/services/history/history-migrate.ts +23 -50
- package/src/services/history/history-query.ts +34 -48
- package/src/services/history/summary-command.ts +9 -8
- package/src/services/history/summary-registry.ts +2 -3
- package/src/services/history/summary-runner.ts +72 -81
- package/src/services/history/workspace-history.ts +8 -0
- package/src/services/installation/setup-service.ts +9 -43
- package/src/services/installation/upgrade-service.ts +127 -0
- package/src/services/workspace/plugin-releases.ts +121 -0
- package/src/services/workspace/workspace-config.ts +9 -8
- package/src/services/workspace/workspace-mcp.ts +23 -28
- package/src/services/workspace/workspace-skills.ts +5 -2
- package/src/storage/acp-files.ts +7 -12
- package/src/storage/agent-files.ts +6 -5
- package/src/storage/atomic-json.ts +31 -4
- package/src/storage/history-files.ts +22 -15
- package/src/storage/history-format.ts +6 -8
- package/src/tools/history/contract.ts +9 -9
- package/src/tools/history/pi-tool.ts +6 -4
- package/src/ui/dsh/elements.ts +5 -12
- package/src/ui/dsh/management.ts +10 -10
- package/src/ui/dsh/styles.ts +5 -33
- package/lib/antigravity-plugin/lib/services/history/history-migrate.d.ts +0 -12
- package/lib/antigravity-plugin/lib/services/history/history-migrate.js +0 -88
- package/lib/ui/presentation.d.ts +0 -3
- package/lib/ui/presentation.js +0 -12
- package/src/tools/access.ts +0 -7
- package/src/tools/register.ts +0 -21
- package/src/ui/presentation.ts +0 -12
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
1
2
|
import { resourceRoot } from "../../common/paths.js";
|
|
2
3
|
import { packageVersion } from "../../common/version.js";
|
|
3
4
|
import { requireThat } from "../../common/validation.js";
|
|
4
5
|
import { loadWorkspaceContext } from "../../integrations/agent-resources.js";
|
|
5
6
|
import type { PluginHostAdapter } from "../../model/plugin-host.js";
|
|
6
7
|
import { recordHistoryCapture } from "../../services/history/history-capture.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
8
|
+
import { historyStartupNotices } from "../../services/history/summary-runner.js";
|
|
9
|
+
import { bindWorkspacePlugin, workspacePluginDrift, workspacePluginReleases } from "../../services/workspace/plugin-releases.js";
|
|
9
10
|
import { readWorkspaceConfig, workspaceFeatures } from "../../services/workspace/workspace-config.js";
|
|
10
11
|
import { initializeWorkspace } from "../../services/workspace/workspace-preparation.js";
|
|
11
|
-
import { discoverWorkspaceSkills } from "../../services/workspace/workspace-skills.js";
|
|
12
|
+
import { discoverSkills, discoverWorkspaceSkills } from "../../services/workspace/workspace-skills.js";
|
|
12
13
|
|
|
13
14
|
function disabledMessage(adapter: PluginHostAdapter, configuration: Awaited<ReturnType<typeof readWorkspaceConfig>>) {
|
|
14
15
|
return configuration.error ?? `Personal Bot 未在此工作区启用。运行 ${adapter.initCommandHint};配置文件:${configuration.path}`;
|
|
@@ -18,29 +19,42 @@ export async function pluginCommand(adapter: PluginHostAdapter, args: readonly s
|
|
|
18
19
|
const root = await adapter.resolveRoot(cwd);
|
|
19
20
|
const action = args.join(" ");
|
|
20
21
|
requireThat(["init", "status"].includes(action), adapter.usage);
|
|
21
|
-
if (action === "init")
|
|
22
|
+
if (action === "init") {
|
|
23
|
+
await initializeWorkspace(root);
|
|
24
|
+
bindWorkspacePlugin(root, adapter.host, process.env.PBOT_PLUGIN_MANIFEST || process.env.PBOT_PLUGIN_VERSION);
|
|
25
|
+
}
|
|
22
26
|
const configuration = await readWorkspaceConfig(root);
|
|
23
27
|
return { version: packageVersion, workspaceRoot: root, resourceRoot, configuration };
|
|
24
28
|
}
|
|
25
29
|
|
|
26
|
-
export
|
|
30
|
+
export type ReplayPluginHook = (root: string, input: string) => Promise<number | undefined>;
|
|
31
|
+
|
|
32
|
+
export async function runPluginHost(adapter: PluginHostAdapter, args: readonly string[], replay?: ReplayPluginHook): Promise<void> {
|
|
27
33
|
if (args[0] === "hook") {
|
|
28
34
|
let input = "";
|
|
29
35
|
process.stdin.setEncoding("utf8");
|
|
30
36
|
for await (const chunk of process.stdin) input += String(chunk);
|
|
31
|
-
|
|
37
|
+
const result = await pluginHook(adapter, JSON.parse(input), replay && (root => replay(root, input)));
|
|
38
|
+
if (typeof result === "number") process.exitCode = result;
|
|
39
|
+
else process.stdout.write(JSON.stringify(result) + "\n");
|
|
32
40
|
} else {
|
|
33
41
|
process.stdout.write(JSON.stringify(await pluginCommand(adapter, args, process.cwd()), null, 2) + "\n");
|
|
34
42
|
}
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
/** Shared hook execution engine; host-specific protocols stay in PluginHostAdapter implementations. */
|
|
38
|
-
export
|
|
46
|
+
export function pluginHook(adapter: PluginHostAdapter, payload: unknown): Promise<Record<string, unknown>>;
|
|
47
|
+
export function pluginHook(adapter: PluginHostAdapter, payload: unknown, replay: ((root: string) => Promise<number | undefined>) | undefined): Promise<Record<string, unknown> | number>;
|
|
48
|
+
export async function pluginHook(adapter: PluginHostAdapter, payload: unknown, replay?: (root: string) => Promise<number | undefined>) {
|
|
39
49
|
if (process.env.PBOT_SUBAGENT_RUN_ID) return adapter.formatPass(payload);
|
|
40
50
|
const event = adapter.parseEvent(payload);
|
|
41
51
|
if (event.kind === "ignore") return adapter.formatPass(payload);
|
|
42
52
|
const root = await adapter.resolveRoot(event.cwd, event.raw);
|
|
43
53
|
const configuration = await readWorkspaceConfig(root);
|
|
54
|
+
if (configuration.enabled && replay) {
|
|
55
|
+
const code = await replay(root);
|
|
56
|
+
if (code !== undefined) return code;
|
|
57
|
+
}
|
|
44
58
|
const features = workspaceFeatures(configuration);
|
|
45
59
|
if (event.kind === "check-skill") {
|
|
46
60
|
if (!configuration.enabled) return adapter.formatDeny(event, disabledMessage(adapter, configuration));
|
|
@@ -48,6 +62,7 @@ export async function pluginHook(adapter: PluginHostAdapter, payload: unknown):
|
|
|
48
62
|
return adapter.formatPass(payload);
|
|
49
63
|
}
|
|
50
64
|
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);
|
|
51
66
|
if (features.history && adapter.extractHistory) {
|
|
52
67
|
try {
|
|
53
68
|
const capture = await adapter.extractHistory(event);
|
|
@@ -55,26 +70,31 @@ export async function pluginHook(adapter: PluginHostAdapter, payload: unknown):
|
|
|
55
70
|
} catch { /* Never block a host turn if history persistence encounters a transient error or busy lock. */ }
|
|
56
71
|
}
|
|
57
72
|
if (event.kind === "record-history") return adapter.formatPass(payload);
|
|
58
|
-
const
|
|
73
|
+
const includePrompts = features.prompts && !event.noticesOnly;
|
|
74
|
+
const includeSkills = features.skills && !event.noticesOnly;
|
|
75
|
+
const workspaceSkills = includeSkills && !adapter.nativeWorkspaceSkills
|
|
59
76
|
? await discoverWorkspaceSkills(root)
|
|
60
77
|
: [];
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
78
|
+
if (includeSkills && adapter.indexBundledSkills) {
|
|
79
|
+
const directory = join(resourceRoot, "skills");
|
|
80
|
+
workspaceSkills.push(...await discoverSkills(directory, directory));
|
|
81
|
+
}
|
|
82
|
+
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
|
+
}
|
|
69
89
|
}
|
|
70
|
-
if (!
|
|
90
|
+
if (!includePrompts && !workspaceSkills.length && !notices.length) return adapter.formatPass(payload);
|
|
71
91
|
const context = await loadWorkspaceContext({
|
|
72
92
|
host: adapter.host,
|
|
73
93
|
root,
|
|
74
94
|
role: event.role,
|
|
75
95
|
...(adapter.coordinatorPrompt ? { coordinatorPrompt: adapter.coordinatorPrompt } : {}),
|
|
76
|
-
includePrompts
|
|
77
|
-
includeRootAgents:
|
|
96
|
+
includePrompts,
|
|
97
|
+
includeRootAgents: includePrompts && !adapter.nativeRootAgents,
|
|
78
98
|
...(event.localRoleOnly ? { localRoleOnly: true } : {}),
|
|
79
99
|
workspaceSkills,
|
|
80
100
|
notices,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ResolvedWorkspaceMcpServer } from "../../model/workspace-mcp.js";
|
|
2
|
+
import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../../services/workspace/workspace-mcp.js";
|
|
3
|
+
|
|
4
|
+
/** A native host can keep its other tools when one workspace server cannot be mounted. */
|
|
5
|
+
export async function loadNativeWorkspaceServers(
|
|
6
|
+
root: string,
|
|
7
|
+
mount: (server: ResolvedWorkspaceMcpServer) => void | Promise<void>,
|
|
8
|
+
options: { check?: () => void; warn?: (message: string) => void } = {},
|
|
9
|
+
) {
|
|
10
|
+
const config = await readWorkspaceMcpConfig(root);
|
|
11
|
+
options.check?.();
|
|
12
|
+
if (config.error) {
|
|
13
|
+
options.warn?.(config.error);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
for (const [name, server] of Object.entries(config.servers)) {
|
|
17
|
+
if (server.enabled === false) continue;
|
|
18
|
+
options.check?.();
|
|
19
|
+
try {
|
|
20
|
+
await mount(resolveWorkspaceMcpServer(root, name, server));
|
|
21
|
+
} catch (error) {
|
|
22
|
+
options.warn?.(error instanceof Error ? error.message : String(error));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -4,6 +4,7 @@ import { object } from "../../common/json.js";
|
|
|
4
4
|
import { requireThat } from "../../common/validation.js";
|
|
5
5
|
import { packageVersion } from "../../common/version.js";
|
|
6
6
|
import type {
|
|
7
|
+
WorkspaceMcpConfiguration,
|
|
7
8
|
ResolvedWorkspaceMcpHttpServer,
|
|
8
9
|
ResolvedWorkspaceMcpServer,
|
|
9
10
|
ResolvedWorkspaceMcpStdioServer,
|
|
@@ -263,65 +264,76 @@ class HttpMcpClient implements DownstreamClient {
|
|
|
263
264
|
}
|
|
264
265
|
}
|
|
265
266
|
|
|
267
|
+
function configuredServer(root: string, configuration: WorkspaceMcpConfiguration, serverName: string) {
|
|
268
|
+
const raw = Object.hasOwn(configuration.servers, serverName) ? configuration.servers[serverName] : undefined;
|
|
269
|
+
requireThat(raw, `工作区未注册名为 "${serverName}" 的 MCP 服务(已注册:${Object.keys(configuration.servers).join(", ") || "无"})。`);
|
|
270
|
+
requireThat(raw.enabled !== false, `工作区 MCP 服务 "${serverName}" 当前已停用(enabled: false)。`);
|
|
271
|
+
return resolveWorkspaceMcpServer(root, serverName, raw);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
interface Connection {
|
|
275
|
+
key: string;
|
|
276
|
+
client: DownstreamClient;
|
|
277
|
+
ready: Promise<void>;
|
|
278
|
+
users: number;
|
|
279
|
+
retired: boolean;
|
|
280
|
+
closing?: Promise<void>;
|
|
281
|
+
}
|
|
282
|
+
|
|
266
283
|
export class WorkspaceMcpBridge {
|
|
267
|
-
readonly #
|
|
268
|
-
|
|
269
|
-
|
|
284
|
+
readonly #connections = new Set<Connection>();
|
|
285
|
+
#closing: Promise<void> | undefined;
|
|
286
|
+
|
|
287
|
+
#close(connection: Connection): Promise<void> {
|
|
288
|
+
return connection.closing ??= connection.ready.catch(() => {}).then(() => connection.client.close())
|
|
289
|
+
.finally(() => this.#connections.delete(connection));
|
|
290
|
+
}
|
|
270
291
|
|
|
271
|
-
#
|
|
272
|
-
|
|
292
|
+
#retire(connection: Connection): Promise<void> | undefined {
|
|
293
|
+
connection.retired = true;
|
|
294
|
+
if (!connection.users) return this.#close(connection);
|
|
273
295
|
}
|
|
274
296
|
|
|
275
|
-
async #
|
|
276
|
-
|
|
277
|
-
|
|
297
|
+
async #withClient<T>(
|
|
298
|
+
root: string, server: ResolvedWorkspaceMcpServer, operation: (client: DownstreamClient) => Promise<T>,
|
|
299
|
+
): Promise<T> {
|
|
300
|
+
requireThat(!this.#closing, "Workspace MCP 桥接已关闭。");
|
|
301
|
+
const key = `${root}\0${server.name}`;
|
|
278
302
|
const fingerprint = JSON.stringify(server);
|
|
279
|
-
|
|
280
|
-
if (
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
await existing.close().catch(() => {});
|
|
303
|
+
let connection = [...this.#connections].find(entry => entry.key === key && !entry.retired);
|
|
304
|
+
if (connection && (!connection.client.alive || connection.client.fingerprint !== fingerprint)) {
|
|
305
|
+
void this.#retire(connection)?.catch(() => {});
|
|
306
|
+
connection = undefined;
|
|
284
307
|
}
|
|
285
|
-
|
|
286
|
-
if (inflight) return inflight;
|
|
287
|
-
const creating = (async () => {
|
|
308
|
+
if (!connection) {
|
|
288
309
|
const client = server.transport === "http"
|
|
289
310
|
? new HttpMcpClient(server, fingerprint)
|
|
290
311
|
: new StdioMcpClient(server, fingerprint);
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
try { return await creating; }
|
|
306
|
-
finally { if (this.#connecting.get(key) === creating) this.#connecting.delete(key); }
|
|
312
|
+
connection = { key, client, ready: client.initialize(), users: 0, retired: false };
|
|
313
|
+
this.#connections.add(connection);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
connection.users++;
|
|
317
|
+
try {
|
|
318
|
+
try { await connection.ready; }
|
|
319
|
+
catch (error) { connection.retired = true; throw error; }
|
|
320
|
+
requireThat(!this.#closing, "Workspace MCP 桥接已关闭。");
|
|
321
|
+
return await operation(connection.client);
|
|
322
|
+
} finally {
|
|
323
|
+
connection.users--;
|
|
324
|
+
if (connection.retired && !connection.users) await this.#close(connection).catch(() => {});
|
|
325
|
+
}
|
|
307
326
|
}
|
|
308
327
|
|
|
309
328
|
async #pruneRemoved(root: string, activeNames: ReadonlySet<string>): Promise<void> {
|
|
310
329
|
const prefix = `${root}\0`;
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
const name = key.slice(prefix.length);
|
|
315
|
-
if (!activeNames.has(name)) {
|
|
316
|
-
this.#clients.delete(key);
|
|
317
|
-
stale.push(client);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
await Promise.allSettled(stale.map(client => client.close()));
|
|
330
|
+
await Promise.allSettled([...this.#connections]
|
|
331
|
+
.filter(entry => entry.key.startsWith(prefix) && !activeNames.has(entry.key.slice(prefix.length)))
|
|
332
|
+
.map(entry => this.#retire(entry)));
|
|
321
333
|
}
|
|
322
334
|
|
|
323
335
|
async discover(root: string, serverName?: string) {
|
|
324
|
-
requireThat(!this.#
|
|
336
|
+
requireThat(!this.#closing, "Workspace MCP 桥接已关闭。");
|
|
325
337
|
const configuration = await readWorkspaceMcpConfig(root);
|
|
326
338
|
if (configuration.error) throw new Error(configuration.error);
|
|
327
339
|
const enabledNames = new Set(
|
|
@@ -347,39 +359,34 @@ export class WorkspaceMcpBridge {
|
|
|
347
359
|
};
|
|
348
360
|
}
|
|
349
361
|
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
tools,
|
|
370
|
-
};
|
|
362
|
+
const resolved = configuredServer(root, configuration, serverName);
|
|
363
|
+
return this.#withClient(root, resolved, async client => {
|
|
364
|
+
const tools: unknown[] = [];
|
|
365
|
+
let cursor: string | undefined;
|
|
366
|
+
for (;;) {
|
|
367
|
+
const page = await client.request("tools/list", cursor ? { cursor } : {});
|
|
368
|
+
if (object(page) && Array.isArray(page.tools)) tools.push(...page.tools);
|
|
369
|
+
const next = object(page) && typeof page.nextCursor === "string" && page.nextCursor ? page.nextCursor : undefined;
|
|
370
|
+
if (!next) break;
|
|
371
|
+
cursor = next;
|
|
372
|
+
}
|
|
373
|
+
return {
|
|
374
|
+
workspace: root,
|
|
375
|
+
server: resolved.name,
|
|
376
|
+
transport: resolved.transport,
|
|
377
|
+
...(resolved.description ? { description: resolved.description } : {}),
|
|
378
|
+
tools,
|
|
379
|
+
};
|
|
380
|
+
});
|
|
371
381
|
}
|
|
372
382
|
|
|
373
383
|
async call(root: string, serverName: string, toolName: string, args: Record<string, unknown> = {}) {
|
|
374
|
-
requireThat(!this.#
|
|
384
|
+
requireThat(!this.#closing, "Workspace MCP 桥接已关闭。");
|
|
375
385
|
const configuration = await readWorkspaceMcpConfig(root);
|
|
376
386
|
if (configuration.error) throw new Error(configuration.error);
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
const resolved = resolveWorkspaceMcpServer(root, serverName, raw);
|
|
381
|
-
const client = await this.#connect(root, resolved);
|
|
382
|
-
const result = await client.request("tools/call", { name: toolName, arguments: args });
|
|
387
|
+
const resolved = configuredServer(root, configuration, serverName);
|
|
388
|
+
const result = await this.#withClient(root, resolved, client =>
|
|
389
|
+
client.request("tools/call", { name: toolName, arguments: args }));
|
|
383
390
|
if (object(result)) {
|
|
384
391
|
return {
|
|
385
392
|
server: resolved.name,
|
|
@@ -397,15 +404,8 @@ export class WorkspaceMcpBridge {
|
|
|
397
404
|
};
|
|
398
405
|
}
|
|
399
406
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
this.#closed = true;
|
|
403
|
-
const inflight = [...this.#connecting.values()];
|
|
404
|
-
this.#connecting.clear();
|
|
405
|
-
await Promise.allSettled(inflight);
|
|
406
|
-
const clients = [...this.#clients.values()];
|
|
407
|
-
this.#clients.clear();
|
|
408
|
-
await Promise.allSettled(clients.map(client => client.close()));
|
|
407
|
+
close(): Promise<void> {
|
|
408
|
+
return this.#closing ??= Promise.allSettled([...this.#connections].map(entry => this.#close(entry))).then(() => {});
|
|
409
409
|
}
|
|
410
410
|
}
|
|
411
411
|
|