personal-bot 0.3.1 → 0.3.3
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 +27 -11
- package/bin/pbot.mjs +22 -2
- package/docs/README.md +3 -1
- package/docs/architecture/design.md +37 -24
- package/docs/architecture/extensibility.md +27 -19
- package/docs/architecture/model-context.md +4 -3
- package/docs/architecture/principles.md +5 -4
- package/docs/guides/capabilities.md +4 -4
- package/docs/guides/cross-harness-workers.md +3 -1
- package/docs/guides/history.md +73 -16
- package/docs/guides/workspace-configuration.md +35 -6
- package/docs/hosts/antigravity.md +2 -0
- package/docs/hosts/claude-code.md +1 -1
- package/docs/hosts/codex-qoder.md +63 -0
- package/docs/hosts/dsh.md +1 -1
- package/docs/hosts/pi.md +1 -1
- package/docs/maintainers/architecture-governance.md +78 -0
- package/hooks/hooks.json +3 -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/hooks.json +7 -0
- package/lib/antigravity-plugin/lib/claude.js +2 -2
- 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/{extension/acp-member.d.ts → antigravity-plugin/lib/extension/acp/member.d.ts} +5 -5
- package/lib/{extension/acp-member.js → antigravity-plugin/lib/extension/acp/member.js} +6 -6
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +222 -51
- 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/{extension → antigravity-plugin/lib/extension/hosts}/dsh/acp-member.js +11 -25
- package/lib/{extension → antigravity-plugin/lib/extension/hosts}/dsh/files.js +3 -3
- 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 +12 -0
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +101 -0
- 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 +2705 -1348
- package/lib/antigravity-plugin/lib/extension/workspace-cli.js +20127 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +1 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +6 -2
- 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/adapter.js +36 -0
- 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/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/mcp.d.ts +1 -1
- package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/resources.d.ts +1 -1
- package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/resources.js +4 -4
- package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/skills.js +1 -1
- 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/{registry.d.ts → plugin-registry.d.ts} +1 -0
- package/lib/{integrations/hosts/registry.js → antigravity-plugin/lib/integrations/hosts/plugin-registry.js} +10 -3
- 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 +179 -0
- package/lib/antigravity-plugin/lib/model/history.js +4 -0
- package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +31 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +28 -7
- 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 +4 -4
- package/lib/antigravity-plugin/lib/services/history/history-capture.d.ts +4 -0
- package/lib/antigravity-plugin/lib/services/history/history-capture.js +98 -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/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 +35 -0
- package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +34 -0
- package/lib/antigravity-plugin/lib/services/history/summary-runner.js +299 -0
- 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 +3 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +78 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.d.ts +5 -1
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +77 -7
- 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/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 +55 -0
- package/lib/antigravity-plugin/lib/storage/history-files.js +473 -0
- package/lib/antigravity-plugin/lib/storage/history-format.d.ts +5 -0
- package/lib/antigravity-plugin/lib/storage/history-format.js +60 -0
- 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/antigravity-plugin/skills/provider-connections/SKILL.md +22 -12
- package/lib/claude.js +2 -2
- package/lib/client.js +42 -60
- 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 +6 -6
- package/lib/extension/acp/member.d.ts +18 -0
- package/lib/extension/acp/member.js +44 -0
- package/lib/extension/acp/worker.js +384 -0
- package/lib/extension/acp-worker.js +222 -51
- 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.d.ts +4 -0
- package/lib/extension/hosts/dsh/acp-member.js +58 -0
- package/lib/extension/{dsh → hosts/dsh}/command.d.ts +1 -2
- package/lib/extension/{dsh → hosts/dsh}/command.js +9 -11
- package/lib/extension/hosts/dsh/files.d.ts +5 -0
- package/lib/extension/hosts/dsh/files.js +67 -0
- 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 +30 -99
- 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 +12 -0
- package/lib/extension/hosts/plugin-runtime.js +101 -0
- 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 → mcp/bridge.d.ts} +7 -9
- package/lib/extension/{mcp-bridge.js → mcp/bridge.js} +70 -88
- package/lib/extension/{mcp-workers.d.ts → mcp/tool-contract.d.ts} +129 -374
- package/lib/extension/mcp/tool-contract.js +441 -0
- package/lib/extension/mcp/workers.d.ts +487 -0
- package/lib/extension/mcp/workers.js +598 -0
- package/lib/extension/mcp.js +2705 -1348
- package/lib/extension/{setup-cli.js → setup/cli.js} +12 -9
- package/lib/extension/workspace-cli.js +20127 -0
- package/lib/integrations/acp/agents.d.ts +2 -3
- 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/harnesses/presets.js +8 -0
- package/lib/integrations/acp/history-summary.d.ts +17 -0
- package/lib/integrations/acp/history-summary.js +101 -0
- package/lib/integrations/acp/launch.d.ts +2 -2
- package/lib/integrations/agent-resources.d.ts +1 -0
- package/lib/integrations/agent-resources.js +6 -2
- 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/adapter.js +36 -0
- package/lib/integrations/hosts/codex/adapter.d.ts +2 -0
- package/lib/integrations/hosts/codex/adapter.js +14 -0
- package/lib/integrations/hosts/dsh/mcp.d.ts +4 -0
- package/lib/integrations/hosts/dsh/mcp.js +28 -0
- package/lib/integrations/hosts/dsh/messages.d.ts +36 -0
- package/lib/integrations/hosts/dsh/messages.js +11 -0
- package/lib/integrations/hosts/dsh/resources.d.ts +6 -0
- package/lib/integrations/hosts/dsh/resources.js +47 -0
- package/lib/integrations/hosts/dsh/root-agents.d.ts +4 -0
- package/lib/integrations/hosts/dsh/root-agents.js +3 -0
- package/lib/integrations/{dsh → hosts/dsh}/schema.js +1 -1
- package/lib/integrations/hosts/dsh/skills.d.ts +8 -0
- package/lib/integrations/hosts/dsh/skills.js +31 -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/{registry.d.ts → plugin-registry.d.ts} +1 -0
- package/lib/{antigravity-plugin/lib/integrations/hosts/registry.js → integrations/hosts/plugin-registry.js} +10 -3
- 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/pi-setup.js +1 -1
- 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 +143 -34
- package/lib/model/history.js +4 -1
- package/lib/model/installation.js +1 -0
- package/lib/model/plugin-host.d.ts +31 -0
- package/lib/model/workspace-config.d.ts +28 -7
- package/lib/model/workspace-config.js +2 -1
- package/lib/plugin.d.ts +2 -1
- package/lib/plugin.js +4 -4
- 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-run.d.ts +1 -1
- 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.d.ts +4 -0
- package/lib/services/history/history-capture.js +98 -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 +54 -0
- package/lib/services/history/history-query.d.ts +51 -0
- package/lib/services/history/history-query.js +352 -0
- package/lib/services/history/summary-command.d.ts +20 -0
- package/lib/services/history/summary-command.js +69 -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 +35 -0
- package/lib/services/history/summary-runner.d.ts +34 -0
- package/lib/services/history/summary-runner.js +299 -0
- package/lib/services/history/workspace-history.d.ts +3 -0
- package/lib/services/history/workspace-history.js +6 -0
- package/lib/services/workspace/plugin-releases.d.ts +3 -0
- package/lib/services/workspace/plugin-releases.js +78 -0
- package/lib/services/workspace/workspace-config.d.ts +5 -1
- package/lib/services/workspace/workspace-config.js +77 -7
- 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 +46 -9
- package/lib/storage/history-files.js +382 -250
- package/lib/storage/history-format.d.ts +3 -13
- package/lib/storage/history-format.js +26 -52
- package/lib/tools/history/actions.d.ts +3 -68
- package/lib/tools/history/actions.js +7 -5
- package/lib/tools/history/contract.d.ts +16 -17
- package/lib/tools/history/contract.js +63 -22
- package/lib/tools/history/dsh-tool.d.ts +1 -2
- package/lib/tools/history/dsh-tool.js +11 -5
- package/lib/ui/dsh/elements.d.ts +2 -5
- package/lib/ui/dsh/elements.js +3 -16
- package/lib/ui/dsh/management.js +26 -13
- 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 +2 -1
- package/resources/prompts/history-monthly-summary.md +13 -0
- package/resources/prompts/history-summary.md +10 -4
- package/resources/prompts/plugin-coordinator.md +1 -0
- package/resources/skills/provider-connections/SKILL.md +22 -12
- package/scripts/README.md +3 -2
- package/src/claude.ts +2 -2
- package/src/common/validation.ts +10 -0
- package/src/dsh.ts +6 -6
- 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/history/command.ts +68 -0
- package/src/extension/hosts/dsh/acp-entry.ts +21 -0
- package/src/extension/{dsh → hosts/dsh}/acp-member.ts +12 -23
- package/src/extension/{dsh → hosts/dsh}/command.ts +10 -12
- 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 -76
- package/src/extension/{pi-acp-member.ts → hosts/pi/acp-member.ts} +12 -18
- package/src/extension/{command.ts → hosts/pi/command.ts} +44 -11
- package/src/extension/{events.ts → hosts/pi/events.ts} +8 -4
- package/src/extension/hosts/pi/history.ts +45 -0
- package/src/extension/{lifecycle.ts → hosts/pi/lifecycle.ts} +9 -12
- package/src/extension/hosts/plugin-runtime.ts +96 -0
- package/src/extension/hosts/workspace-mcp.ts +25 -0
- package/src/extension/{mcp-bridge.ts → mcp/bridge.ts} +85 -85
- package/src/extension/mcp/tool-contract.ts +462 -0
- package/src/extension/{mcp-workers.ts → mcp/workers.ts} +151 -448
- package/src/extension/{setup-cli.ts → setup/cli.ts} +14 -11
- package/src/extension/setup/workspace-cli.ts +159 -0
- package/src/integrations/acp/agents.ts +2 -3
- 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/harnesses/presets.ts +8 -0
- package/src/integrations/acp/history-summary.ts +109 -0
- package/src/integrations/agent-resources.ts +7 -1
- package/src/integrations/hosts/antigravity/adapter.ts +161 -0
- package/src/integrations/hosts/claude/adapter.ts +39 -0
- package/src/integrations/hosts/codex/adapter.ts +16 -0
- 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} +11 -3
- 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 +116 -0
- package/src/integrations/installation/pi-bridge.ts +1 -1
- package/src/integrations/installation/pi-setup.ts +2 -2
- package/src/integrations/installation/processes.ts +1 -1
- package/src/mcp.ts +1 -1
- package/src/model/acp.ts +11 -3
- package/src/model/agent.ts +20 -4
- package/src/model/history.ts +156 -26
- package/src/model/installation.ts +41 -0
- package/src/model/plugin-host.ts +30 -2
- package/src/model/workspace-config.ts +31 -7
- package/src/pbot.ts +22 -50
- package/src/plugin.ts +4 -4
- package/src/services/agents/agent-service.ts +29 -17
- package/src/services/history/history-capture.ts +91 -0
- package/src/services/history/history-index.ts +48 -62
- package/src/services/history/history-migrate.ts +62 -0
- package/src/services/history/history-query.ts +401 -0
- package/src/services/history/summary-command.ts +70 -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 +43 -0
- package/src/services/history/summary-runner.ts +343 -0
- package/src/services/history/workspace-history.ts +8 -0
- package/src/services/installation/setup-service.ts +2 -41
- package/src/services/workspace/plugin-releases.ts +68 -0
- package/src/services/workspace/workspace-config.ts +95 -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 +416 -189
- package/src/storage/history-format.ts +45 -61
- package/src/tools/history/actions.ts +8 -6
- package/src/tools/history/contract.ts +70 -25
- package/src/tools/history/dsh-tool.ts +17 -8
- package/src/tools/history/pi-tool.ts +23 -0
- package/src/ui/dsh/elements.ts +5 -12
- package/src/ui/dsh/management.ts +36 -20
- package/src/ui/dsh/styles.ts +5 -33
- package/src/ui/{confirmation.ts → pi/confirmation.ts} +1 -1
- package/lib/antigravity-plugin/lib/extension/plugin-runtime.d.ts +0 -10
- package/lib/antigravity-plugin/lib/extension/plugin-runtime.js +0 -67
- 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/antigravity-plugin/lib/integrations/hosts/claude.js +0 -60
- package/lib/extension/dsh/history.d.ts +0 -15
- package/lib/extension/dsh/history.js +0 -87
- package/lib/extension/mcp-workers.js +0 -882
- package/lib/extension/plugin-runtime.d.ts +0 -10
- package/lib/extension/plugin-runtime.js +0 -67
- 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/integrations/hosts/claude.js +0 -60
- 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/lib/ui/presentation.d.ts +0 -3
- package/lib/ui/presentation.js +0 -12
- package/src/extension/dsh/history.ts +0 -74
- package/src/extension/history.ts +0 -26
- package/src/extension/plugin-runtime.ts +0 -63
- 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/hosts/claude.ts +0 -62
- 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/access.ts +0 -7
- package/src/tools/history/tool.ts +0 -19
- package/src/tools/register.ts +0 -22
- package/src/ui/presentation.ts +0 -12
- /package/lib/{extension → antigravity-plugin/lib/extension/hosts}/dsh/acp-member.d.ts +0 -0
- /package/lib/{extension → antigravity-plugin/lib/extension/hosts}/dsh/files.d.ts +0 -0
- /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/mcp.js +0 -0
- /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/messages.d.ts +0 -0
- /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/messages.js +0 -0
- /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/root-agents.d.ts +0 -0
- /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/root-agents.js +0 -0
- /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/skills.d.ts +0 -0
- /package/lib/extension/{acp-worker.d.ts → acp/worker.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}/schema.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,598 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { realpath, stat } from "node:fs/promises";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { isAbsolute, join } from "node:path";
|
|
6
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
7
|
+
import { object } from "../../common/json.js";
|
|
8
|
+
import { isAcpBackend, isHistoryIdentifier, isOneOf, requireThat } from "../../common/validation.js";
|
|
9
|
+
import { resourceRoot } from "../../common/paths.js";
|
|
10
|
+
import { packageVersion } from "../../common/version.js";
|
|
11
|
+
import { AcpWorkerHost } from "../../integrations/acp/agents.js";
|
|
12
|
+
import { canonicalAcpBackend, inspectAcpBackends, knownAcpBackends } from "../../integrations/acp/launch.js";
|
|
13
|
+
import { pluginMcpWorkspaceRoot } from "../../integrations/hosts/plugin-registry.js";
|
|
14
|
+
import { mcpWorkerToolNames, acpElicitationActions, isAcpElicitationValue, } from "../../model/acp.js";
|
|
15
|
+
import { buildHistoryMcpTools, buildPbotWorkerTools, buildWorkspaceMcpTools, defaultWaitMs, discoverTargets, maxWaitMs, parseMcpToolCall, } from "./tool-contract.js";
|
|
16
|
+
import { historyPageLimits } from "../../model/history.js";
|
|
17
|
+
import { AgentService } from "../../services/agents/agent-service.js";
|
|
18
|
+
import { readWorkspaceHistory, searchWorkspaceHistory } from "../../services/history/history-query.js";
|
|
19
|
+
import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../services/workspace/workspace-config.js";
|
|
20
|
+
import { WorkspaceMcpBridge } from "./bridge.js";
|
|
21
|
+
export { buildHistoryMcpTools, buildPbotWorkerTools, buildWorkspaceMcpTools, pbotWorkerTools } from "./tool-contract.js";
|
|
22
|
+
const protocolVersion = "2025-03-26";
|
|
23
|
+
const readyTimeoutMs = 45_000;
|
|
24
|
+
const reportPageSize = 16_000;
|
|
25
|
+
const progressIntervalMs = 5_000;
|
|
26
|
+
export const mcpWorkerOnlyInstructions = "提供跨助手协作能力(worker_*):可启动并调度其他外部 AI 助手在当前工作区中独立执行任务,适用于用户指定其他助手、需要特定模型或思考深度、获取独立审查/第二意见,或并行处理子任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。\n" +
|
|
27
|
+
"使用流程:用 worker_create 启动目标助手(或用 worker_discover 复用已有会话)→ 用 worker_request 派发任务或继续追问 → 任务完成后可用 worker_close 结束会话。后台等待、超时续等(timedOut)或长结果翻页(nextOffset)用 worker_output;助手请求授权或提问(needsResponse)时,先向用户确认,再用 worker_response 回复。";
|
|
28
|
+
export const mcpInstructions = "提供三类能力:\n" +
|
|
29
|
+
"1. 跨助手协作(worker_*):启动并调度其他外部 AI 助手在当前工作区中独立执行任务,适用于用户指定其他助手、需要特定模型或思考深度、获取独立审查/第二意见,或并行处理子任务。不需要借助其他助手时,优先自行完成或使用当前内置子代理。使用流程:worker_create 启动助手(或 worker_discover 复用已有会话)→ worker_request 派发任务或追问 → 完成后 worker_close 结束;后台等待、超时续等(timedOut)或长结果翻页(nextOffset)用 worker_output;返回 needsResponse 时先向用户确认,再用 worker_response 回复。\n" +
|
|
30
|
+
"2. 工作区共享外部工具(workspace_mcp_*):发现并调用当前工作区接入的外部工具服务与数据源(可与当前环境原生工具同时使用)。先用 workspace_mcp_discover 查看可用服务与工具说明,再用 workspace_mcp_call 调用。\n" +
|
|
31
|
+
"3. 跨宿主历史查询(history_search / history_read):只读检索当前工作区在 Pi、dsh、Claude Code、Antigravity 等宿主中记录的历史问答与摘要归档。";
|
|
32
|
+
export function defaultWorkerDirectory() {
|
|
33
|
+
if (process.env.PBOT_MCP_AGENT_DIR)
|
|
34
|
+
return process.env.PBOT_MCP_AGENT_DIR;
|
|
35
|
+
if (process.env.PLUGIN_DATA)
|
|
36
|
+
return join(process.env.PLUGIN_DATA, "subagents");
|
|
37
|
+
return join(homedir(), ".pbot/subagents");
|
|
38
|
+
}
|
|
39
|
+
function workerCommandTool(name) {
|
|
40
|
+
const full = name.startsWith("worker_") ? name : `worker_${name}`;
|
|
41
|
+
return isOneOf(full, mcpWorkerToolNames) ? full : undefined;
|
|
42
|
+
}
|
|
43
|
+
/** Parse Pi/dsh `/pbot worker ...` CLI arguments into a canonical MCP tool call. */
|
|
44
|
+
export function parseWorkerCommand(raw) {
|
|
45
|
+
const trimmed = raw.trim();
|
|
46
|
+
if (!trimmed || trimmed === "overview")
|
|
47
|
+
return { tool: "worker_discover", args: { target: "overview" } };
|
|
48
|
+
if (trimmed === "status" || trimmed === "list" || trimmed === "workers") {
|
|
49
|
+
return { tool: "worker_discover", args: { target: "workers" } };
|
|
50
|
+
}
|
|
51
|
+
if (trimmed.startsWith("status ") || trimmed.startsWith("workers ")) {
|
|
52
|
+
const workerId = trimmed.slice(trimmed.indexOf(" ") + 1).trim();
|
|
53
|
+
requireThat(workerId.length > 0, "请提供 workerId。");
|
|
54
|
+
return { tool: "worker_discover", args: { target: "workers", workerId } };
|
|
55
|
+
}
|
|
56
|
+
if (trimmed === "backends")
|
|
57
|
+
return { tool: "worker_discover", args: { target: "backends" } };
|
|
58
|
+
if (trimmed === "models")
|
|
59
|
+
return { tool: "worker_discover", args: { target: "models" } };
|
|
60
|
+
if (trimmed.startsWith("models ")) {
|
|
61
|
+
const backend = trimmed.slice(7).trim();
|
|
62
|
+
requireThat(backend.length > 0, "请提供 backend 名称。");
|
|
63
|
+
return { tool: "worker_discover", args: { target: "models", backend } };
|
|
64
|
+
}
|
|
65
|
+
if (trimmed.startsWith("close ")) {
|
|
66
|
+
const rest = trimmed.slice(6).trim();
|
|
67
|
+
if (!rest.startsWith("{")) {
|
|
68
|
+
requireThat(rest.length > 0, "请提供要关闭的 workerId。");
|
|
69
|
+
return { tool: "worker_close", args: { workerId: rest } };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (trimmed.startsWith("{")) {
|
|
73
|
+
const parsed = JSON.parse(trimmed);
|
|
74
|
+
requireThat(object(parsed), 'worker 参数必须是 JSON 对象,例如:/pbot worker create {"backend":"codex"}');
|
|
75
|
+
const resolved = typeof parsed.tool === "string" ? workerCommandTool(parsed.tool) : undefined;
|
|
76
|
+
requireThat(resolved, `JSON 形式需包含有效 tool 字段(${mcpWorkerToolNames.join(", ")}),或使用 /pbot worker <工具名> <JSON>。`);
|
|
77
|
+
const rest = Object.fromEntries(Object.entries(parsed).filter(([key]) => key !== "tool"));
|
|
78
|
+
return { tool: resolved, args: rest };
|
|
79
|
+
}
|
|
80
|
+
const match = trimmed.match(/^(\S+)(?:\s+([\s\S]*))?$/);
|
|
81
|
+
const verb = match?.[1] ?? "";
|
|
82
|
+
const rest = (match?.[2] ?? "").trim();
|
|
83
|
+
const tool = workerCommandTool(verb);
|
|
84
|
+
requireThat(tool, `未知 worker 命令:${verb}(支持:overview | status | backends | models | ${mcpWorkerToolNames.map(name => name.slice("worker_".length)).join(" | ")})。`);
|
|
85
|
+
if (!rest)
|
|
86
|
+
return { tool, args: {} };
|
|
87
|
+
const parsed = JSON.parse(rest);
|
|
88
|
+
requireThat(object(parsed), `${tool} 的参数必须是 JSON 对象。`);
|
|
89
|
+
return { tool, args: parsed };
|
|
90
|
+
}
|
|
91
|
+
function asString(args, key, required = false) {
|
|
92
|
+
const value = args[key];
|
|
93
|
+
if (value === undefined || value === null) {
|
|
94
|
+
requireThat(!required, `缺少必填参数:${key}`);
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
requireThat(typeof value === "string" && value.length > 0, `参数 ${key} 必须是非空字符串。`);
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
function asInt(args, key, min, max) {
|
|
101
|
+
const value = args[key];
|
|
102
|
+
if (value === undefined || value === null)
|
|
103
|
+
return undefined;
|
|
104
|
+
requireThat(typeof value === "number" && Number.isInteger(value) && value >= min && value <= max, `参数 ${key} 必须是 ${min}–${max} 的整数。`);
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
function asContent(args, key) {
|
|
108
|
+
const value = args[key];
|
|
109
|
+
if (value === undefined || value === null)
|
|
110
|
+
return undefined;
|
|
111
|
+
requireThat(object(value), `参数 ${key} 必须是 JSON 对象。`);
|
|
112
|
+
for (const [field, entry] of Object.entries(value)) {
|
|
113
|
+
requireThat(isAcpElicitationValue(entry), `参数 ${key}.${field} 必须是字符串、数字、布尔值或字符串数组。`);
|
|
114
|
+
}
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
function presentCycle(cycle) {
|
|
118
|
+
return {
|
|
119
|
+
state: cycle.state,
|
|
120
|
+
...(cycle.error ? { error: cycle.error } : {}),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function presentSelection(selection) {
|
|
124
|
+
if (!selection)
|
|
125
|
+
return undefined;
|
|
126
|
+
const entries = Object.entries(selection).filter(([, value]) => value !== undefined);
|
|
127
|
+
return entries.length ? Object.fromEntries(entries) : undefined;
|
|
128
|
+
}
|
|
129
|
+
function presentWorker(value) {
|
|
130
|
+
const selection = presentSelection(value.selection);
|
|
131
|
+
const truncated = value.nextOffset !== undefined && value.nextOffset !== null;
|
|
132
|
+
return {
|
|
133
|
+
workerId: value.agentId,
|
|
134
|
+
backend: value.backend,
|
|
135
|
+
state: value.state,
|
|
136
|
+
activity: value.activity,
|
|
137
|
+
alive: value.alive,
|
|
138
|
+
...(selection ? { selection } : {}),
|
|
139
|
+
...(value.pendingRequests?.length ? { pendingRequests: value.pendingRequests } : {}),
|
|
140
|
+
...(value.cycle ? { cycle: presentCycle(value.cycle) } : {}),
|
|
141
|
+
...(value.report !== undefined ? { report: value.report } : {}),
|
|
142
|
+
...(truncated ? { totalLength: value.totalLength, nextOffset: value.nextOffset } : {}),
|
|
143
|
+
...(value.error ? { error: value.error } : {}),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
export class McpWorkerRuntime {
|
|
147
|
+
#services = new Map();
|
|
148
|
+
#bridge = new WorkspaceMcpBridge();
|
|
149
|
+
#sessionId;
|
|
150
|
+
#directory;
|
|
151
|
+
#defaultBackend;
|
|
152
|
+
#nativeWorkspaceMcp;
|
|
153
|
+
#nativeHistory;
|
|
154
|
+
#closing;
|
|
155
|
+
constructor(directory = defaultWorkerDirectory(), sessionId = process.env.PBOT_MCP_SESSION_ID || ("mcp-" + randomUUID()), defaultBackend = process.env.PBOT_HOST || undefined, nativeWorkspaceMcp = /^(1|true)$/i.test(process.env.PBOT_NATIVE_WORKSPACE_MCP ?? ""), nativeHistory = /^(1|true)$/i.test(process.env.PBOT_NATIVE_HISTORY ?? "")) {
|
|
156
|
+
this.#directory = directory;
|
|
157
|
+
this.#sessionId = sessionId;
|
|
158
|
+
this.#defaultBackend = defaultBackend?.trim() || undefined;
|
|
159
|
+
this.#nativeWorkspaceMcp = nativeWorkspaceMcp;
|
|
160
|
+
this.#nativeHistory = nativeHistory;
|
|
161
|
+
}
|
|
162
|
+
/** Mount the stdio sibling with the same worker ownership as the native host command. */
|
|
163
|
+
nativeServer(root) {
|
|
164
|
+
const entry = join(resourceRoot, "../lib/extension/mcp.js");
|
|
165
|
+
if (!existsSync(entry))
|
|
166
|
+
return undefined;
|
|
167
|
+
requireThat(this.#defaultBackend, "原生 MCP 挂载需要宿主名称。");
|
|
168
|
+
return {
|
|
169
|
+
command: process.execPath,
|
|
170
|
+
args: [entry],
|
|
171
|
+
env: {
|
|
172
|
+
PBOT_HOST: this.#defaultBackend,
|
|
173
|
+
PBOT_WORKSPACE_ROOT: root,
|
|
174
|
+
PBOT_MCP_AGENT_DIR: this.#directory,
|
|
175
|
+
PBOT_MCP_SESSION_ID: this.#sessionId,
|
|
176
|
+
PBOT_NATIVE_WORKSPACE_MCP: "1",
|
|
177
|
+
PBOT_NATIVE_HISTORY: "1",
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
get nativeWorkspaceMcp() {
|
|
182
|
+
return this.#nativeWorkspaceMcp;
|
|
183
|
+
}
|
|
184
|
+
get nativeHistory() {
|
|
185
|
+
return this.#nativeHistory;
|
|
186
|
+
}
|
|
187
|
+
resolveBackend(rawArgs, commands, allowDefault) {
|
|
188
|
+
const raw = asString(rawArgs, "backend") ?? (allowDefault ? this.#defaultBackend : undefined);
|
|
189
|
+
requireThat(raw, `缺少必填参数:backend(请指定目标程序:${knownAcpBackends(commands).join(", ")})。`);
|
|
190
|
+
const backend = canonicalAcpBackend(raw, commands);
|
|
191
|
+
requireThat(isAcpBackend(backend), "无效的 backend 名称:" + raw);
|
|
192
|
+
return backend;
|
|
193
|
+
}
|
|
194
|
+
async resolveWorkspace(supplied) {
|
|
195
|
+
const target = supplied || pluginMcpWorkspaceRoot() || process.cwd();
|
|
196
|
+
requireThat(isAbsolute(target), "工作区需要绝对路径。");
|
|
197
|
+
const root = await realpath(target);
|
|
198
|
+
requireThat((await stat(root)).isDirectory(), "工作区路径不是目录。");
|
|
199
|
+
return root;
|
|
200
|
+
}
|
|
201
|
+
workerService(root, commands = {}) {
|
|
202
|
+
let entry = this.#services.get(root);
|
|
203
|
+
if (!entry) {
|
|
204
|
+
const host = new AcpWorkerHost(this.#directory, commands);
|
|
205
|
+
entry = {
|
|
206
|
+
host,
|
|
207
|
+
service: new AgentService(root, this.#directory, host),
|
|
208
|
+
owner: { sessionId: this.#sessionId, leaf: null, branch: [] },
|
|
209
|
+
};
|
|
210
|
+
this.#services.set(root, entry);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
entry.host.commands = commands;
|
|
214
|
+
}
|
|
215
|
+
return entry;
|
|
216
|
+
}
|
|
217
|
+
async toolDefinitions() {
|
|
218
|
+
let commands;
|
|
219
|
+
let includeWorkspaceMcp = !this.#nativeWorkspaceMcp;
|
|
220
|
+
let includeHistory = !this.#nativeHistory;
|
|
221
|
+
try {
|
|
222
|
+
const root = await this.resolveWorkspace();
|
|
223
|
+
const configuration = await readWorkspaceConfig(root);
|
|
224
|
+
if (configuration.enabled) {
|
|
225
|
+
commands = configuration.acp;
|
|
226
|
+
const features = workspaceFeatures(configuration);
|
|
227
|
+
includeWorkspaceMcp = !this.#nativeWorkspaceMcp && features.mcp;
|
|
228
|
+
includeHistory = !this.#nativeHistory && features.history;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
catch { /* Fall back to registered built-in harnesses when cwd is outside an enabled workspace. */ }
|
|
232
|
+
const defaultBackend = this.#defaultBackend ? canonicalAcpBackend(this.#defaultBackend, commands) : undefined;
|
|
233
|
+
const workspaceBound = Boolean(pluginMcpWorkspaceRoot());
|
|
234
|
+
return [
|
|
235
|
+
...buildPbotWorkerTools(commands, defaultBackend, workspaceBound),
|
|
236
|
+
...(includeWorkspaceMcp ? buildWorkspaceMcpTools(workspaceBound) : []),
|
|
237
|
+
...(includeHistory ? buildHistoryMcpTools(workspaceBound) : []),
|
|
238
|
+
];
|
|
239
|
+
}
|
|
240
|
+
/** Wait until ACP handshake and model/thinking configuration finish so invalid options fail synchronously on create/resume. */
|
|
241
|
+
async waitReady(service, owner, workerId, timeoutMs, progress) {
|
|
242
|
+
const deadline = Date.now() + timeoutMs;
|
|
243
|
+
let lastProgressAt = 0;
|
|
244
|
+
let lastMarker = "";
|
|
245
|
+
for (;;) {
|
|
246
|
+
requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
|
|
247
|
+
const current = service.status(workerId, owner);
|
|
248
|
+
if (current.state === "error" || current.state === "stopped") {
|
|
249
|
+
throw new Error(current.error || "worker 启动失败。");
|
|
250
|
+
}
|
|
251
|
+
if (current.state === "idle" || current.state === "busy")
|
|
252
|
+
return current;
|
|
253
|
+
if (Date.now() >= deadline)
|
|
254
|
+
return current;
|
|
255
|
+
if (progress) {
|
|
256
|
+
const marker = `${current.state}:${current.activity}`;
|
|
257
|
+
const now = Date.now();
|
|
258
|
+
if (marker !== lastMarker || now - lastProgressAt >= progressIntervalMs) {
|
|
259
|
+
lastMarker = marker;
|
|
260
|
+
lastProgressAt = now;
|
|
261
|
+
progress(`${current.backend}: ${current.activity}`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
await delay(50);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
async waitFor(service, owner, workerId, requestId, timeoutMs, offset = 0, progress) {
|
|
268
|
+
const deadline = Date.now() + timeoutMs;
|
|
269
|
+
let lastProgressAt = 0;
|
|
270
|
+
let lastMarker = "";
|
|
271
|
+
for (;;) {
|
|
272
|
+
requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
|
|
273
|
+
const { current, cycle, terminal } = service.outputStatus(workerId, owner, requestId);
|
|
274
|
+
if (cycle && cycle.state !== "running") {
|
|
275
|
+
const page = await service.read(workerId, owner, cycle.cycleId, offset, reportPageSize);
|
|
276
|
+
return { settled: true, ...presentWorker(page) };
|
|
277
|
+
}
|
|
278
|
+
if (terminal) {
|
|
279
|
+
if (offset > 0)
|
|
280
|
+
await service.read(workerId, owner, undefined, offset, reportPageSize);
|
|
281
|
+
return { settled: true, ...presentWorker(current) };
|
|
282
|
+
}
|
|
283
|
+
if (current.pendingRequests?.length) {
|
|
284
|
+
return {
|
|
285
|
+
settled: false,
|
|
286
|
+
needsResponse: true,
|
|
287
|
+
...presentWorker(current),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
if (Date.now() >= deadline) {
|
|
291
|
+
return { settled: false, timedOut: true, ...presentWorker(current) };
|
|
292
|
+
}
|
|
293
|
+
if (progress) {
|
|
294
|
+
const marker = `${current.state}:${current.activity}`;
|
|
295
|
+
const now = Date.now();
|
|
296
|
+
if (marker !== lastMarker || now - lastProgressAt >= progressIntervalMs) {
|
|
297
|
+
lastMarker = marker;
|
|
298
|
+
lastProgressAt = now;
|
|
299
|
+
progress(`${current.backend}: ${current.activity}`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
await delay(100);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
async callTool(toolName, input, progress) {
|
|
306
|
+
const { name, args: rawArgs } = parseMcpToolCall(toolName, input);
|
|
307
|
+
requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
|
|
308
|
+
const root = await this.resolveWorkspace(asString(rawArgs, "workspace"));
|
|
309
|
+
const configuration = await readWorkspaceConfig(root);
|
|
310
|
+
requireThat(!this.#closing, "Personal Bot MCP 服务已关闭。");
|
|
311
|
+
requireThat(configuration.enabled, workspaceDisabledMessage(configuration));
|
|
312
|
+
switch (name) {
|
|
313
|
+
case "workspace_mcp_discover":
|
|
314
|
+
case "workspace_mcp_call": {
|
|
315
|
+
requireThat(!this.#nativeWorkspaceMcp, "当前宿主已原生挂载工作区 .pbot/mcp.json 服务,请直接调用对应原生 MCP 工具,勿重复经由 workspace_mcp_* 桥接。");
|
|
316
|
+
requireThat(workspaceFeatures(configuration).mcp, `工作区统一 MCP 功能已在 ${configuration.path} 中停用(features.mcp: false)。`);
|
|
317
|
+
if (name === "workspace_mcp_discover")
|
|
318
|
+
return this.#bridge.discover(root, asString(rawArgs, "server"));
|
|
319
|
+
const server = asString(rawArgs, "server", true);
|
|
320
|
+
const tool = asString(rawArgs, "tool", true);
|
|
321
|
+
const toolArgs = rawArgs.arguments === undefined ? {} : rawArgs.arguments;
|
|
322
|
+
requireThat(object(toolArgs), "参数 arguments 必须是 JSON 对象。");
|
|
323
|
+
return this.#bridge.call(root, server, tool, toolArgs);
|
|
324
|
+
}
|
|
325
|
+
case "history_search": {
|
|
326
|
+
requireThat(!this.#nativeHistory, "当前宿主已提供原生 pbot_history 工具,请直接调用 pbot_history。");
|
|
327
|
+
requireThat(workspaceFeatures(configuration).history, `工作区历史功能已在 ${configuration.path} 中停用(features.history: false)。`);
|
|
328
|
+
const hostFilter = asString(rawArgs, "host");
|
|
329
|
+
if (hostFilter !== undefined)
|
|
330
|
+
requireThat(isHistoryIdentifier(hostFilter), "无效的 host 来源:" + hostFilter);
|
|
331
|
+
const dimension = asString(rawArgs, "dimension");
|
|
332
|
+
if (dimension !== undefined)
|
|
333
|
+
requireThat(isHistoryIdentifier(dimension), "无效的 dimension:" + dimension);
|
|
334
|
+
const query = asString(rawArgs, "query");
|
|
335
|
+
const sessionId = asString(rawArgs, "sessionId");
|
|
336
|
+
const from = asString(rawArgs, "from");
|
|
337
|
+
const to = asString(rawArgs, "to");
|
|
338
|
+
const offset = asInt(rawArgs, "offset", 0, 10_000_000) ?? 0;
|
|
339
|
+
const limit = asInt(rawArgs, "limit", 1, historyPageLimits.search.max) ?? historyPageLimits.search.default;
|
|
340
|
+
return searchWorkspaceHistory(root, {
|
|
341
|
+
...(hostFilter ? { host: hostFilter } : {}),
|
|
342
|
+
...(dimension ? { dimension } : {}),
|
|
343
|
+
...(query ? { query } : {}),
|
|
344
|
+
...(sessionId ? { sessionId } : {}),
|
|
345
|
+
...(from ? { from } : {}),
|
|
346
|
+
...(to ? { to } : {}),
|
|
347
|
+
offset,
|
|
348
|
+
limit,
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
case "history_read": {
|
|
352
|
+
requireThat(!this.#nativeHistory, "当前宿主已提供原生 pbot_history 工具,请直接调用 pbot_history。");
|
|
353
|
+
requireThat(workspaceFeatures(configuration).history, `工作区历史功能已在 ${configuration.path} 中停用(features.history: false)。`);
|
|
354
|
+
const id = asString(rawArgs, "id", true);
|
|
355
|
+
const hostFilter = asString(rawArgs, "host");
|
|
356
|
+
if (hostFilter !== undefined)
|
|
357
|
+
requireThat(isHistoryIdentifier(hostFilter), "无效的 host 来源:" + hostFilter);
|
|
358
|
+
const offset = asInt(rawArgs, "offset", 0, 10_000_000) ?? 0;
|
|
359
|
+
const limit = asInt(rawArgs, "limit", 1, historyPageLimits.read.max) ?? historyPageLimits.read.default;
|
|
360
|
+
const childrenOffset = asInt(rawArgs, "childrenOffset", 0, 10_000_000) ?? 0;
|
|
361
|
+
return { node: readWorkspaceHistory(root, id, offset, limit, childrenOffset, hostFilter) };
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
const { host, service, owner } = this.workerService(root, configuration.acp);
|
|
365
|
+
switch (name) {
|
|
366
|
+
case "worker_create": {
|
|
367
|
+
const backend = this.resolveBackend(rawArgs, configuration.acp, false);
|
|
368
|
+
const model = asString(rawArgs, "model");
|
|
369
|
+
const thinking = asString(rawArgs, "thinking");
|
|
370
|
+
const cwd = asString(rawArgs, "cwd");
|
|
371
|
+
const created = await service.start({
|
|
372
|
+
backend,
|
|
373
|
+
...(model ? { model } : {}),
|
|
374
|
+
...(thinking ? { thinking } : {}),
|
|
375
|
+
...(cwd ? { cwd } : {}),
|
|
376
|
+
}, owner);
|
|
377
|
+
const ready = await this.waitReady(service, owner, created.agentId, readyTimeoutMs, progress);
|
|
378
|
+
return {
|
|
379
|
+
...presentWorker(ready),
|
|
380
|
+
capabilities: { resume: ready.capabilities.resume },
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
case "worker_close":
|
|
384
|
+
return presentWorker(service.stop(asString(rawArgs, "workerId", true), owner));
|
|
385
|
+
case "worker_request": {
|
|
386
|
+
const workerId = asString(rawArgs, "workerId", true);
|
|
387
|
+
const message = asString(rawArgs, "message", true);
|
|
388
|
+
const waitMs = asInt(rawArgs, "waitMs", 0, maxWaitMs) ?? defaultWaitMs;
|
|
389
|
+
const current = service.status(workerId, owner);
|
|
390
|
+
requireThat(current.state !== "stopping", "worker 正在停止,请稍后重试。");
|
|
391
|
+
if (current.alive) {
|
|
392
|
+
const sent = service.send(workerId, message, "followUp", owner);
|
|
393
|
+
if (waitMs > 0)
|
|
394
|
+
return this.waitFor(service, owner, workerId, sent.requestId, waitMs, 0, progress);
|
|
395
|
+
return presentWorker(sent);
|
|
396
|
+
}
|
|
397
|
+
const startedAt = Date.now();
|
|
398
|
+
const resumed = await service.resume(workerId, message, owner);
|
|
399
|
+
const ready = await this.waitReady(service, owner, workerId, waitMs > 0 ? Math.min(waitMs, readyTimeoutMs) : readyTimeoutMs, progress);
|
|
400
|
+
if (waitMs > 0 && resumed.requestId) {
|
|
401
|
+
const remaining = Math.max(0, waitMs - (Date.now() - startedAt));
|
|
402
|
+
return this.waitFor(service, owner, workerId, resumed.requestId, remaining, 0, progress);
|
|
403
|
+
}
|
|
404
|
+
return {
|
|
405
|
+
...presentWorker(ready),
|
|
406
|
+
...(ready.pendingRequests?.length ? { settled: false, needsResponse: true } : {}),
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
case "worker_response": {
|
|
410
|
+
const workerId = asString(rawArgs, "workerId", true);
|
|
411
|
+
const action = asString(rawArgs, "action", true);
|
|
412
|
+
requireThat(isOneOf(action, acpElicitationActions), `参数 action 无效:${action}(可用:${acpElicitationActions.join(", ")})。`);
|
|
413
|
+
const requestId = asString(rawArgs, "requestId");
|
|
414
|
+
const optionId = asString(rawArgs, "optionId");
|
|
415
|
+
const content = asContent(rawArgs, "content");
|
|
416
|
+
const waitMs = asInt(rawArgs, "waitMs", 0, maxWaitMs) ?? defaultWaitMs;
|
|
417
|
+
const updated = service.respond(workerId, {
|
|
418
|
+
action,
|
|
419
|
+
...(requestId ? { requestId } : {}),
|
|
420
|
+
...(optionId ? { optionId } : {}),
|
|
421
|
+
...(content !== undefined ? { content } : {}),
|
|
422
|
+
}, owner);
|
|
423
|
+
if (waitMs > 0)
|
|
424
|
+
return this.waitFor(service, owner, workerId, undefined, waitMs, 0, progress);
|
|
425
|
+
return presentWorker(updated);
|
|
426
|
+
}
|
|
427
|
+
case "worker_output": {
|
|
428
|
+
const workerId = asString(rawArgs, "workerId", true);
|
|
429
|
+
const offset = asInt(rawArgs, "offset", 0, 10_000_000) ?? 0;
|
|
430
|
+
const waitMs = asInt(rawArgs, "waitMs", 0, maxWaitMs) ?? defaultWaitMs;
|
|
431
|
+
return this.waitFor(service, owner, workerId, undefined, waitMs, offset, progress);
|
|
432
|
+
}
|
|
433
|
+
case "worker_discover": {
|
|
434
|
+
const rawTarget = asString(rawArgs, "target") ?? "overview";
|
|
435
|
+
requireThat(isOneOf(rawTarget, discoverTargets), `参数 target 无效:${rawTarget}(可用:${discoverTargets.join(", ")})。`);
|
|
436
|
+
const target = rawTarget;
|
|
437
|
+
const workerId = asString(rawArgs, "workerId");
|
|
438
|
+
const backendRaw = asString(rawArgs, "backend");
|
|
439
|
+
const model = asString(rawArgs, "model");
|
|
440
|
+
if (target !== "workers") {
|
|
441
|
+
requireThat(workerId === undefined, '参数 workerId 仅在 target="workers" 时可用。');
|
|
442
|
+
}
|
|
443
|
+
if (target !== "models") {
|
|
444
|
+
requireThat(backendRaw === undefined && model === undefined, '参数 backend / model 仅在 target="models" 时可用。');
|
|
445
|
+
}
|
|
446
|
+
if (target === "overview") {
|
|
447
|
+
return {
|
|
448
|
+
target,
|
|
449
|
+
backends: inspectAcpBackends(configuration.acp),
|
|
450
|
+
workers: service.list(owner).map(presentWorker),
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
if (target === "backends") {
|
|
454
|
+
return { target, backends: inspectAcpBackends(configuration.acp) };
|
|
455
|
+
}
|
|
456
|
+
if (target === "workers") {
|
|
457
|
+
return {
|
|
458
|
+
target,
|
|
459
|
+
workers: workerId
|
|
460
|
+
? [presentWorker(service.status(workerId, owner))]
|
|
461
|
+
: service.list(owner).map(presentWorker),
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
const backend = this.resolveBackend(rawArgs, configuration.acp, true);
|
|
465
|
+
return {
|
|
466
|
+
target,
|
|
467
|
+
...(await host.inspectModels(backend, root, { ...(model ? { model } : {}) })),
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
throw new Error(`未知工具:${name}`);
|
|
472
|
+
}
|
|
473
|
+
close(preserve = false) {
|
|
474
|
+
if (this.#closing)
|
|
475
|
+
return this.#closing;
|
|
476
|
+
const entries = [...this.#services.values()];
|
|
477
|
+
this.#services.clear();
|
|
478
|
+
this.#closing = Promise.allSettled([
|
|
479
|
+
this.#bridge.close(),
|
|
480
|
+
...entries.map(({ service, owner }) => service.close(owner, preserve)),
|
|
481
|
+
]).then(() => { });
|
|
482
|
+
return this.#closing;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
export async function handleMcpRequest(runtime, message, notify) {
|
|
486
|
+
if (!object(message) || message.jsonrpc !== "2.0" || typeof message.method !== "string") {
|
|
487
|
+
return { jsonrpc: "2.0", id: null, error: { code: -32600, message: "Invalid JSON-RPC request" } };
|
|
488
|
+
}
|
|
489
|
+
const hasId = Object.hasOwn(message, "id") && message.id !== undefined;
|
|
490
|
+
const id = hasId ? message.id : null;
|
|
491
|
+
if (!hasId)
|
|
492
|
+
return null; // Notifications expect no response.
|
|
493
|
+
try {
|
|
494
|
+
if (message.method === "initialize") {
|
|
495
|
+
const requested = object(message.params) && typeof message.params.protocolVersion === "string"
|
|
496
|
+
? message.params.protocolVersion
|
|
497
|
+
: protocolVersion;
|
|
498
|
+
return {
|
|
499
|
+
jsonrpc: "2.0",
|
|
500
|
+
id,
|
|
501
|
+
result: {
|
|
502
|
+
protocolVersion: requested || protocolVersion,
|
|
503
|
+
capabilities: { tools: {} },
|
|
504
|
+
serverInfo: { name: "personal-bot", version: packageVersion },
|
|
505
|
+
instructions: runtime.nativeWorkspaceMcp ? mcpWorkerOnlyInstructions : mcpInstructions,
|
|
506
|
+
},
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
if (message.method === "ping")
|
|
510
|
+
return { jsonrpc: "2.0", id, result: {} };
|
|
511
|
+
if (message.method === "tools/list") {
|
|
512
|
+
return { jsonrpc: "2.0", id, result: { tools: await runtime.toolDefinitions() } };
|
|
513
|
+
}
|
|
514
|
+
if (message.method === "tools/call") {
|
|
515
|
+
requireThat(object(message.params) && typeof message.params.name === "string", "tools/call 缺少 name。");
|
|
516
|
+
const meta = object(message.params._meta) ? message.params._meta : undefined;
|
|
517
|
+
const progressToken = meta && (typeof meta.progressToken === "string" || typeof meta.progressToken === "number")
|
|
518
|
+
? meta.progressToken
|
|
519
|
+
: undefined;
|
|
520
|
+
let progressStep = 0;
|
|
521
|
+
const progress = progressToken !== undefined && notify
|
|
522
|
+
? (statusMessage) => {
|
|
523
|
+
progressStep++;
|
|
524
|
+
notify({
|
|
525
|
+
jsonrpc: "2.0",
|
|
526
|
+
method: "notifications/progress",
|
|
527
|
+
params: { progressToken, progress: progressStep, message: statusMessage },
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
: undefined;
|
|
531
|
+
try {
|
|
532
|
+
const result = await runtime.callTool(message.params.name, message.params.arguments ?? {}, progress);
|
|
533
|
+
return {
|
|
534
|
+
jsonrpc: "2.0",
|
|
535
|
+
id,
|
|
536
|
+
result: {
|
|
537
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
538
|
+
},
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
catch (error) {
|
|
542
|
+
return {
|
|
543
|
+
jsonrpc: "2.0",
|
|
544
|
+
id,
|
|
545
|
+
result: {
|
|
546
|
+
isError: true,
|
|
547
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
548
|
+
},
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return { jsonrpc: "2.0", id, error: { code: -32601, message: "Method not found: " + message.method } };
|
|
553
|
+
}
|
|
554
|
+
catch (error) {
|
|
555
|
+
return { jsonrpc: "2.0", id, error: { code: -32603, message: error instanceof Error ? error.message : String(error) } };
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
export async function serveMcpStdio(runtime = new McpWorkerRuntime()) {
|
|
559
|
+
const shutdown = () => { void runtime.close().finally(() => process.exit(0)); };
|
|
560
|
+
process.on("SIGTERM", shutdown);
|
|
561
|
+
process.on("SIGINT", shutdown);
|
|
562
|
+
let buffer = "";
|
|
563
|
+
const pending = new Set();
|
|
564
|
+
const write = (value) => { process.stdout.write(JSON.stringify(value) + "\n"); };
|
|
565
|
+
process.stdin.setEncoding("utf8");
|
|
566
|
+
for await (const chunk of process.stdin) {
|
|
567
|
+
buffer += String(chunk);
|
|
568
|
+
for (;;) {
|
|
569
|
+
const nl = buffer.indexOf("\n");
|
|
570
|
+
if (nl < 0)
|
|
571
|
+
break;
|
|
572
|
+
const line = buffer.slice(0, nl).trim();
|
|
573
|
+
buffer = buffer.slice(nl + 1);
|
|
574
|
+
if (!line)
|
|
575
|
+
continue;
|
|
576
|
+
let parsed;
|
|
577
|
+
try {
|
|
578
|
+
parsed = JSON.parse(line);
|
|
579
|
+
}
|
|
580
|
+
catch {
|
|
581
|
+
write({ jsonrpc: "2.0", id: null, error: { code: -32700, message: "Parse error" } });
|
|
582
|
+
continue;
|
|
583
|
+
}
|
|
584
|
+
const task = handleMcpRequest(runtime, parsed, write)
|
|
585
|
+
.then(reply => { if (reply)
|
|
586
|
+
write(reply); })
|
|
587
|
+
.catch(error => {
|
|
588
|
+
const id = object(parsed) && Object.hasOwn(parsed, "id") && parsed.id !== undefined ? parsed.id : null;
|
|
589
|
+
if (id !== null)
|
|
590
|
+
write({ jsonrpc: "2.0", id, error: { code: -32603, message: error instanceof Error ? error.message : String(error) } });
|
|
591
|
+
})
|
|
592
|
+
.finally(() => { pending.delete(task); });
|
|
593
|
+
pending.add(task);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
await Promise.allSettled(pending);
|
|
597
|
+
await runtime.close();
|
|
598
|
+
}
|