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
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { isDeepStrictEqual } from "node:util";
|
|
4
|
-
import { resourceRoot } from "../../common/paths.js";
|
|
5
|
-
import { requireThat } from "../../common/validation.js";
|
|
6
|
-
import { historySummaries, historyView, indexHistory, retainHistorySummaries } from "./history-index.js";
|
|
7
|
-
const page = (values, offset, limit) => ({ values: values.slice(offset, offset + limit),
|
|
8
|
-
nextOffset: offset + limit < values.length ? offset + limit : null });
|
|
9
|
-
const brief = ({ host, record }, node) => ({ host, id: node.id, kind: node.kind, sessionId: record.sessionId,
|
|
10
|
-
name: record.name, preview: node.text.replace(/\s+/g, " ").slice(0, 100), from: node.from, to: node.to, ready: node.ready, completed: node.completed });
|
|
11
|
-
const view = ({ raw, summaries }) => ({ host: raw.host, record: historyView(raw, summaries) });
|
|
12
|
-
const summarySource = (node) => [node.id, node.kind, node.level, node.entryIds, node.children, node.text, node.from, node.to, node.completed, node.ready];
|
|
13
|
-
function nextSummary(archives) {
|
|
14
|
-
for (const { raw, summaries } of archives) {
|
|
15
|
-
if (summaries === null)
|
|
16
|
-
continue;
|
|
17
|
-
const record = historyView(raw, summaries), lookup = new Map(record.nodes.map(node => [node.id, node]));
|
|
18
|
-
const node = record.nodes.find(node => node.kind === "summary" && !node.ready && node.children.every(id => lookup.get(id).ready));
|
|
19
|
-
if (node)
|
|
20
|
-
return { record, node, children: node.children.map(id => lookup.get(id)) };
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
/** Validate the exact target and ordered inputs under the source lock. Only publish the derived file. */
|
|
24
|
-
export function commitHistorySummary(files, identity, expected, children, text, signal) {
|
|
25
|
-
return files.control(() => {
|
|
26
|
-
signal?.throwIfAborted();
|
|
27
|
-
const current = files.list().find(({ raw }) => raw.host === identity.host && raw.id === identity.id && raw.sessionId === identity.sessionId);
|
|
28
|
-
if (!current || current.summaries === null)
|
|
29
|
-
return;
|
|
30
|
-
const record = historyView(current.raw, current.summaries), lookup = new Map(record.nodes.map(node => [node.id, node]));
|
|
31
|
-
const node = lookup.get(expected.id);
|
|
32
|
-
if (!node || node.kind !== "summary" || node.ready || !isDeepStrictEqual(summarySource(node), summarySource(expected)) ||
|
|
33
|
-
!isDeepStrictEqual(node.children, children.map(child => child.id)))
|
|
34
|
-
return;
|
|
35
|
-
for (const child of children) {
|
|
36
|
-
const input = lookup.get(child.id);
|
|
37
|
-
if (!input?.ready || !isDeepStrictEqual(summarySource(input), summarySource(child)))
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
requireThat(text.trim(), "历史摘要为空。");
|
|
41
|
-
node.text = text.trim();
|
|
42
|
-
node.ready = true;
|
|
43
|
-
files.saveSummaries(current.raw, historySummaries(record));
|
|
44
|
-
return record;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
export class HistoryService {
|
|
48
|
-
root;
|
|
49
|
-
files;
|
|
50
|
-
source;
|
|
51
|
-
otherFiles;
|
|
52
|
-
acpSessions;
|
|
53
|
-
#records = [];
|
|
54
|
-
#closed = false;
|
|
55
|
-
#loaded = false;
|
|
56
|
-
#refresh;
|
|
57
|
-
#work;
|
|
58
|
-
#controller = new AbortController();
|
|
59
|
-
#sourceWarnings = [];
|
|
60
|
-
#summaryError;
|
|
61
|
-
constructor(root, files, source, otherFiles = [], acpSessions) {
|
|
62
|
-
this.root = root;
|
|
63
|
-
this.files = files;
|
|
64
|
-
this.source = source;
|
|
65
|
-
this.otherFiles = otherFiles;
|
|
66
|
-
this.acpSessions = acpSessions;
|
|
67
|
-
requireThat((source.host === "pi" || source.host === "dsh") && source.host === files.host &&
|
|
68
|
-
new Set([files.host, ...otherFiles.map(value => value.host)]).size === otherFiles.length + 1, "历史来源与归档目录不匹配。");
|
|
69
|
-
}
|
|
70
|
-
check() { requireThat(!this.#closed, "历史服务已关闭。"); }
|
|
71
|
-
get warnings() {
|
|
72
|
-
return [...new Set([...this.#sourceWarnings, ...this.files.warnings, ...this.otherFiles.flatMap(value => value.warnings),
|
|
73
|
-
...(this.#summaryError ? [this.files.host + " 摘要:" + this.#summaryError] : [])])];
|
|
74
|
-
}
|
|
75
|
-
get status() {
|
|
76
|
-
return { loaded: this.#loaded, organizing: Boolean(this.#work), pending: this.#loaded ? this.#records.filter(value => value.host === this.files.host)
|
|
77
|
-
.reduce((total, value) => total + value.record.nodes.filter(node => node.kind === "summary" && !node.ready).length, 0) : null, warnings: this.warnings };
|
|
78
|
-
}
|
|
79
|
-
refresh(location, signal) {
|
|
80
|
-
this.check();
|
|
81
|
-
requireThat(location.host === this.source.host, "历史位置与来源不匹配。");
|
|
82
|
-
// Each caller keeps its own cancellation. A closed page cannot cancel a server-owned refresh.
|
|
83
|
-
const work = (this.#refresh ?? Promise.resolve()).catch(() => { }).then(() => this.load(location, signal));
|
|
84
|
-
this.#refresh = work;
|
|
85
|
-
return work.finally(() => { if (this.#refresh === work)
|
|
86
|
-
this.#refresh = undefined; });
|
|
87
|
-
}
|
|
88
|
-
async load(location, signal) {
|
|
89
|
-
this.check();
|
|
90
|
-
signal?.throwIfAborted();
|
|
91
|
-
const warnings = [], records = [];
|
|
92
|
-
const warning = (host, error) => { this.check(); signal?.throwIfAborted(); warnings.push(host + ": " + String(error)); };
|
|
93
|
-
let known = [], sessions = [];
|
|
94
|
-
try {
|
|
95
|
-
try {
|
|
96
|
-
this.files.migrate(this.root);
|
|
97
|
-
}
|
|
98
|
-
finally {
|
|
99
|
-
known = this.files.list(this.root);
|
|
100
|
-
}
|
|
101
|
-
const scanned = await this.source.scan(location, signal, this.acpSessions?.().ids[this.files.host]);
|
|
102
|
-
sessions = scanned.sessions;
|
|
103
|
-
warnings.push(...scanned.warnings.map(value => this.files.host + ": " + value));
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
warning(this.files.host, error);
|
|
107
|
-
}
|
|
108
|
-
this.check();
|
|
109
|
-
signal?.throwIfAborted();
|
|
110
|
-
// The worker binds the actual backend ID before delivery, possibly during the native scan.
|
|
111
|
-
const excluded = this.acpSessions?.();
|
|
112
|
-
if (excluded) {
|
|
113
|
-
warnings.push(...excluded.warnings);
|
|
114
|
-
sessions = sessions.filter(session => !excluded.ids[this.files.host].has(session.sessionId));
|
|
115
|
-
}
|
|
116
|
-
const visible = ({ raw }) => !excluded?.ids[raw.host].has(raw.sessionId);
|
|
117
|
-
try {
|
|
118
|
-
if (sessions.length) {
|
|
119
|
-
const before = new Map(known.map(({ raw }) => [raw.sessionId, raw]));
|
|
120
|
-
known = this.files.control(() => {
|
|
121
|
-
this.check();
|
|
122
|
-
signal?.throwIfAborted();
|
|
123
|
-
const current = new Map(this.files.list().map(archive => [archive.raw.sessionId, archive]));
|
|
124
|
-
for (const session of sessions) {
|
|
125
|
-
const previous = current.get(session.sessionId);
|
|
126
|
-
// A damaged raw file may own this session; a damaged summary cannot own a root ID.
|
|
127
|
-
if (!previous && this.files.rawWarnings.length)
|
|
128
|
-
continue;
|
|
129
|
-
if (!isDeepStrictEqual(before.get(session.sessionId), previous?.raw))
|
|
130
|
-
continue;
|
|
131
|
-
const raw = indexHistory(session, previous?.raw, this.files.host);
|
|
132
|
-
if (isDeepStrictEqual(raw, previous?.raw))
|
|
133
|
-
continue;
|
|
134
|
-
let summaries = previous ? previous.summaries : [];
|
|
135
|
-
if (previous && summaries?.length) {
|
|
136
|
-
const retained = retainHistorySummaries(previous.raw, raw, summaries);
|
|
137
|
-
// Invalidate first: even an interrupted two-file update cannot attach old text to a corrected exchange.
|
|
138
|
-
if (!isDeepStrictEqual(summaries, retained))
|
|
139
|
-
this.files.saveSummaries(previous.raw, retained);
|
|
140
|
-
summaries = retained;
|
|
141
|
-
}
|
|
142
|
-
this.files.saveRaw(raw);
|
|
143
|
-
current.set(session.sessionId, { raw, summaries });
|
|
144
|
-
}
|
|
145
|
-
return [...current.values()];
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
catch (error) {
|
|
150
|
-
warning(this.files.host, error);
|
|
151
|
-
}
|
|
152
|
-
records.push(...known.filter(visible).map(view));
|
|
153
|
-
for (const files of this.otherFiles) {
|
|
154
|
-
try {
|
|
155
|
-
records.push(...files.list(this.root).filter(visible).map(view));
|
|
156
|
-
}
|
|
157
|
-
catch (error) {
|
|
158
|
-
warning(files.host, error);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
this.check();
|
|
162
|
-
signal?.throwIfAborted();
|
|
163
|
-
this.#records = records;
|
|
164
|
-
this.#sourceWarnings = warnings;
|
|
165
|
-
this.#loaded = true;
|
|
166
|
-
}
|
|
167
|
-
search({ host, query = "", sessionId, from, to, offset = 0, limit = 20 } = {}) {
|
|
168
|
-
this.check();
|
|
169
|
-
const needle = query.trim().toLowerCase(), after = from === undefined ? -Infinity : Date.parse(from), before = to === undefined ? Infinity : Date.parse(to);
|
|
170
|
-
requireThat(!Number.isNaN(after) && !Number.isNaN(before) && after <= before, "时间范围无效,请使用 ISO 日期或时间。");
|
|
171
|
-
const matches = this.#records.filter(value => (!host || value.host === host) && (!sessionId || value.record.sessionId === sessionId)).flatMap(value => value.record.nodes
|
|
172
|
-
.filter(node => (needle ? node.kind !== "session" && node.ready && node.text.toLowerCase().includes(needle) : node.kind === "session") &&
|
|
173
|
-
Date.parse(node.to) >= after && Date.parse(node.from) <= before)
|
|
174
|
-
.map(node => {
|
|
175
|
-
const start = Math.max(0, node.text.toLowerCase().indexOf(needle) - 80);
|
|
176
|
-
return { ...brief(value, node), parents: node.parents, snippet: node.text.slice(start, start + 400) };
|
|
177
|
-
})).sort((a, b) => b.to.localeCompare(a.to) || a.id.localeCompare(b.id));
|
|
178
|
-
const result = page(matches, offset, limit);
|
|
179
|
-
return { matches: result.values, total: matches.length, nextOffset: result.nextOffset, warnings: this.warnings };
|
|
180
|
-
}
|
|
181
|
-
find(id, host) {
|
|
182
|
-
const values = this.#records.filter(value => (!host || value.host === host) && value.record.nodes.some(node => node.id === id));
|
|
183
|
-
requireThat(values.length, "历史节点不存在,请重新搜索。");
|
|
184
|
-
requireThat(values.length === 1, "历史节点来源不明确,请指定 host。");
|
|
185
|
-
const value = values[0], node = value.record.nodes.find(node => node.id === id);
|
|
186
|
-
return { value, node };
|
|
187
|
-
}
|
|
188
|
-
read(id, offset = 0, limit = 12000, childrenOffset = 0, host) {
|
|
189
|
-
this.check();
|
|
190
|
-
const { value, node } = this.find(id, host), lookup = new Map(value.record.nodes.map(node => [node.id, node]));
|
|
191
|
-
requireThat(offset <= node.text.length, "读取位置超出正文。");
|
|
192
|
-
if (offset && /[\uDC00-\uDFFF]/.test(node.text[offset] ?? ""))
|
|
193
|
-
offset--;
|
|
194
|
-
let end = Math.min(node.text.length, offset + limit);
|
|
195
|
-
if (end < node.text.length && /[\uD800-\uDBFF]/.test(node.text[end - 1] ?? ""))
|
|
196
|
-
end += end - offset === 1 ? 1 : -1;
|
|
197
|
-
const children = page(node.children, childrenOffset, 20);
|
|
198
|
-
return { ...brief(value, node), text: node.text.slice(offset, end), totalLength: node.text.length,
|
|
199
|
-
nextOffset: end < node.text.length ? end : null,
|
|
200
|
-
parents: node.parents.map(id => brief(value, lookup.get(id))), children: children.values.map(id => brief(value, lookup.get(id))),
|
|
201
|
-
nextChildrenOffset: children.nextOffset, source: { host: value.host, sessionId: value.record.sessionId, entryIds: node.entryIds }, warnings: this.warnings };
|
|
202
|
-
}
|
|
203
|
-
/** Retain exact inputs only for this call; model work never holds the source write lock. */
|
|
204
|
-
organize(summarize, signal) {
|
|
205
|
-
this.check();
|
|
206
|
-
const active = AbortSignal.any([signal, this.#controller.signal]);
|
|
207
|
-
const run = async () => {
|
|
208
|
-
for (;;) {
|
|
209
|
-
this.check();
|
|
210
|
-
active.throwIfAborted();
|
|
211
|
-
const archives = this.files.list(), excluded = this.acpSessions?.().ids[this.files.host];
|
|
212
|
-
const pending = nextSummary(archives.filter(({ raw }) => !excluded?.has(raw.sessionId)));
|
|
213
|
-
if (!pending)
|
|
214
|
-
return;
|
|
215
|
-
const { record, node, children } = pending;
|
|
216
|
-
const text = await summarize({ system: readFileSync(join(resourceRoot, "prompts/history-summary.md"), "utf8"), maxTokens: 2048,
|
|
217
|
-
prompt: children.map(child => `[${child.from} — ${child.to}${child.completed ? "" : ";未完成"}]\n${child.text}`).join("\n\n") }, active);
|
|
218
|
-
this.check();
|
|
219
|
-
active.throwIfAborted();
|
|
220
|
-
const committed = commitHistorySummary(this.files, record, node, children, text, active);
|
|
221
|
-
if (!committed)
|
|
222
|
-
return;
|
|
223
|
-
this.#records = this.#records.map(value => value.host === this.files.host && value.record.id === committed.id ? { host: value.host, record: committed } : value);
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
const work = (this.#work ?? Promise.resolve()).catch(() => { }).then(run).then(() => { this.#summaryError = undefined; }).catch(error => {
|
|
227
|
-
if (!active.aborted && !this.#closed)
|
|
228
|
-
this.#summaryError = String(error);
|
|
229
|
-
throw error;
|
|
230
|
-
});
|
|
231
|
-
this.#work = work;
|
|
232
|
-
return work.finally(() => { if (this.#work === work)
|
|
233
|
-
this.#work = undefined; });
|
|
234
|
-
}
|
|
235
|
-
async close() {
|
|
236
|
-
this.#closed = true;
|
|
237
|
-
this.#controller.abort();
|
|
238
|
-
await Promise.allSettled([this.#work, this.#refresh]);
|
|
239
|
-
this.#records = [];
|
|
240
|
-
this.#loaded = false;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { HistoryHost } from "../model/history.js";
|
|
2
|
-
/** Exclude ACP worker sessions owned by MCP or legacy Pi/dsh control directories from native history. */
|
|
3
|
-
export declare function acpHistorySessions(directories?: {
|
|
4
|
-
pi?: string;
|
|
5
|
-
dsh?: string;
|
|
6
|
-
mcp?: string;
|
|
7
|
-
}): {
|
|
8
|
-
ids: Record<HistoryHost, Set<string>>;
|
|
9
|
-
warnings: string[];
|
|
10
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { readdirSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { readJsonFile } from "./atomic-json.js";
|
|
6
|
-
import { acpReference } from "./acp-files.js";
|
|
7
|
-
import { isHistoryHost } from "./history-format.js";
|
|
8
|
-
function memberDirectory(home, host) {
|
|
9
|
-
if (host === "pi" && home.startsWith("file://"))
|
|
10
|
-
return join(fileURLToPath(home), "pbot/subagents");
|
|
11
|
-
const tilde = home === "~" || home.startsWith("~/") || ((host === "dsh" || process.platform === "win32") && home.startsWith("~\\"));
|
|
12
|
-
return join(tilde ? join(homedir(), home.slice(2)) : home, "pbot/subagents");
|
|
13
|
-
}
|
|
14
|
-
function defaultMcpWorkerDirectories() {
|
|
15
|
-
const dirs = [join(homedir(), ".pbot/subagents")];
|
|
16
|
-
if (process.env.PBOT_MCP_AGENT_DIR)
|
|
17
|
-
dirs.push(process.env.PBOT_MCP_AGENT_DIR);
|
|
18
|
-
if (process.env.PLUGIN_DATA)
|
|
19
|
-
dirs.push(join(process.env.PLUGIN_DATA, "subagents"));
|
|
20
|
-
return dirs;
|
|
21
|
-
}
|
|
22
|
-
/** Exclude ACP worker sessions owned by MCP or legacy Pi/dsh control directories from native history. */
|
|
23
|
-
export function acpHistorySessions(directories = {}) {
|
|
24
|
-
const ids = { pi: new Set(), dsh: new Set(), claude: new Set() };
|
|
25
|
-
const warnings = [];
|
|
26
|
-
const warn = (path, error) => {
|
|
27
|
-
if (error.code !== "ENOENT")
|
|
28
|
-
warnings.push(path + ": " + String(error));
|
|
29
|
-
};
|
|
30
|
-
const homes = { pi: process.env.PI_CODING_AGENT_DIR || "~/.pi/agent", dsh: process.env.DSH_HOME?.trim() ? process.env.DSH_HOME : "~/.dsh" };
|
|
31
|
-
const scanDirs = new Set([
|
|
32
|
-
directories.pi ?? memberDirectory(homes.pi, "pi"),
|
|
33
|
-
directories.dsh ?? memberDirectory(homes.dsh, "dsh"),
|
|
34
|
-
...(directories.mcp ? [directories.mcp] : defaultMcpWorkerDirectories()),
|
|
35
|
-
]);
|
|
36
|
-
for (const directory of scanDirs) {
|
|
37
|
-
try {
|
|
38
|
-
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
39
|
-
if (!entry.isDirectory() || entry.name.startsWith("."))
|
|
40
|
-
continue;
|
|
41
|
-
const path = join(directory, entry.name);
|
|
42
|
-
try {
|
|
43
|
-
const ref = readJsonFile(path, "acp-session.json", acpReference);
|
|
44
|
-
if (ref.sessionId !== null && isHistoryHost(ref.backend))
|
|
45
|
-
ids[ref.backend].add(ref.sessionId);
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
warn(path, error);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
warn(directory, error);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return { ids, warnings };
|
|
57
|
-
}
|
package/lib/ui/presentation.d.ts
DELETED
package/lib/ui/presentation.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const states = {
|
|
2
|
-
starting: "启动中", busy: "执行中", idle: "待命", stopping: "停止中", stopped: "已停止", error: "需要处理",
|
|
3
|
-
running: "进行中", paused: "已暂停", finished: "已结束", completed: "已完成", failed: "失败",
|
|
4
|
-
cancelled: "已取消", interrupted: "已中断",
|
|
5
|
-
open: "待安排", closed: "已关闭",
|
|
6
|
-
};
|
|
7
|
-
export const stateLabel = (state) => states[String(state)] ?? String(state ?? "未知");
|
|
8
|
-
export const oneLine = (value) => value.replace(/\s+/g, " ").trim();
|
|
9
|
-
export function duration(milliseconds) {
|
|
10
|
-
const seconds = Math.max(0, Math.floor(milliseconds / 1000));
|
|
11
|
-
return seconds < 60 ? `${seconds} 秒` : seconds < 3600 ? `${Math.floor(seconds / 60)} 分钟` : `${Math.floor(seconds / 3600)} 小时 ${Math.floor(seconds % 3600 / 60)} 分钟`;
|
|
12
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import type { Context } from "@deepseek-ai/cordis";
|
|
3
|
-
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
4
|
-
import { acpHistorySessions } from "../../storage/acp-history.js";
|
|
5
|
-
import { HistoryFiles } from "../../storage/history-files.js";
|
|
6
|
-
import { HistoryService } from "../../services/history/history-service.js";
|
|
7
|
-
import { DshHistory } from "../../integrations/dsh/history.js";
|
|
8
|
-
import { dshHistorySummarizer } from "../../integrations/dsh/history-summary.js";
|
|
9
|
-
import { finalDshAnswer } from "../../integrations/dsh/messages.js";
|
|
10
|
-
import { defaultWorkerDirectory } from "../mcp-workers.js";
|
|
11
|
-
|
|
12
|
-
/** One server-owned organizer per workspace, shared by its parent Sessions. */
|
|
13
|
-
export class DshHistoryWork {
|
|
14
|
-
readonly service: HistoryService;
|
|
15
|
-
readonly #parents = new Set<Agent>();
|
|
16
|
-
#controller: AbortController | undefined;
|
|
17
|
-
#work: Promise<void> | undefined;
|
|
18
|
-
#closing: Promise<void> | undefined;
|
|
19
|
-
|
|
20
|
-
constructor(private readonly ctx: Context, root: string) {
|
|
21
|
-
this.service = new HistoryService(
|
|
22
|
-
root,
|
|
23
|
-
new HistoryFiles(join(root, ".pbot/history"), "dsh"),
|
|
24
|
-
new DshHistory(ctx, root),
|
|
25
|
-
[new HistoryFiles(join(root, ".pbot/history"), "pi"), new HistoryFiles(join(root, ".pbot/history"), "claude")],
|
|
26
|
-
() => acpHistorySessions({ mcp: defaultWorkerDirectory() }),
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
attach(agent: Agent) { this.#parents.add(agent); return () => { this.#parents.delete(agent); }; }
|
|
31
|
-
cancel() { this.#controller?.abort(); }
|
|
32
|
-
schedule(agent: Agent) {
|
|
33
|
-
if (this.#closing || [...this.#parents].some(parent => parent.status !== "idle" || parent.inbox.nextTurn.length || parent.inbox.nextStep.length)) return;
|
|
34
|
-
this.cancel();
|
|
35
|
-
const controller = new AbortController(), selection = agent.model.current(), sessionId = agent.id;
|
|
36
|
-
this.#controller = controller;
|
|
37
|
-
const signal = controller.signal;
|
|
38
|
-
const work = (this.#work ?? Promise.resolve()).catch(() => {}).then(async () => {
|
|
39
|
-
signal.throwIfAborted();
|
|
40
|
-
await this.service.refresh({ host: "dsh", sessionId }, signal);
|
|
41
|
-
signal.throwIfAborted();
|
|
42
|
-
await this.service.organize(dshHistorySummarizer(this.ctx, selection, sessionId), signal);
|
|
43
|
-
}).catch(error => { if (!signal.aborted) this.ctx.logger.warn("pbot 历史整理未完成:" + String(error)); });
|
|
44
|
-
this.#work = work;
|
|
45
|
-
void work.finally(() => { if (this.#work === work) { this.#work = undefined; this.#controller = undefined; } });
|
|
46
|
-
}
|
|
47
|
-
close() {
|
|
48
|
-
if (this.#closing) return this.#closing;
|
|
49
|
-
this.cancel();
|
|
50
|
-
this.#closing = (async () => { await this.#work; await this.service.close(); this.#parents.clear(); })();
|
|
51
|
-
return this.#closing;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function registerDshHistoryEvents(ctx: Context, agent: Agent, work: DshHistoryWork, check: () => void) {
|
|
56
|
-
let normal = false, final = false;
|
|
57
|
-
ctx.effect(() => work.attach(agent));
|
|
58
|
-
ctx.on("session/event", (session, event) => {
|
|
59
|
-
if (session !== agent.session) return;
|
|
60
|
-
if (event.type === "turn/start") { normal = false; final = false; }
|
|
61
|
-
if (event.type === "assistant/message") final = Boolean(finalDshAnswer(event).trim());
|
|
62
|
-
if (event.type === "agent/inbox/spliced" && event.data.inserted.some(message => message.source.kind === "user")) { normal = false; work.cancel(); }
|
|
63
|
-
if (event.type === "turn/end") normal = event.data.reason.kind === "completed" && final;
|
|
64
|
-
});
|
|
65
|
-
ctx.on("agent/pre-step", async (_payload, next) => { work.cancel(); check(); return next(); });
|
|
66
|
-
ctx.on("agent/status", ({ agent: changed, status }) => {
|
|
67
|
-
if (changed !== agent || status !== "idle" || !normal) return;
|
|
68
|
-
normal = false;
|
|
69
|
-
if (!agent.inbox.nextTurn.length && !agent.inbox.nextStep.length) {
|
|
70
|
-
try { check(); } catch (error) { if ((error as Error).name === "AbortError") return; throw error; }
|
|
71
|
-
work.schedule(agent);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
package/src/extension/history.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { historyLocation, historySummarizer } from "../integrations/pi/history.js";
|
|
3
|
-
import type { Lifecycle } from "./lifecycle.js";
|
|
4
|
-
|
|
5
|
-
export function registerHistoryEvents(pi: ExtensionAPI, lifecycle: Lifecycle) {
|
|
6
|
-
pi.on("session_start", async (_event, ctx) => {
|
|
7
|
-
const instance = lifecycle.active;
|
|
8
|
-
if (!instance) return;
|
|
9
|
-
try { await instance.history.refresh(historyLocation(ctx), instance.signal()); }
|
|
10
|
-
catch (error) { ctx.ui.notify("历史索引:" + String(error), "warning"); }
|
|
11
|
-
});
|
|
12
|
-
pi.on("agent_settled", (event, ctx) => {
|
|
13
|
-
const instance = lifecycle.active;
|
|
14
|
-
if (!instance || event.aborted) return;
|
|
15
|
-
const signal = instance.signal();
|
|
16
|
-
void (async () => {
|
|
17
|
-
await instance.history.refresh(historyLocation(ctx), signal);
|
|
18
|
-
signal.throwIfAborted();
|
|
19
|
-
const summarize = await historySummarizer(ctx);
|
|
20
|
-
ctx.ui.setStatus("pbot-history", "历史整理中");
|
|
21
|
-
await instance.history.organize(summarize, signal);
|
|
22
|
-
})().catch(error => {
|
|
23
|
-
if (!signal.aborted) ctx.ui.notify("历史摘要暂未完成,下次交互结束后重试:" + String(error), "warning");
|
|
24
|
-
}).finally(() => { if (lifecycle.active === instance) ctx.ui.setStatus("pbot-history", undefined); });
|
|
25
|
-
});
|
|
26
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { resourceRoot } from "../common/paths.js";
|
|
2
|
-
import { packageVersion } from "../common/version.js";
|
|
3
|
-
import { requireThat } from "../common/validation.js";
|
|
4
|
-
import { loadWorkspaceContext } from "../integrations/agent-resources.js";
|
|
5
|
-
import type { PluginHostAdapter } from "../model/plugin-host.js";
|
|
6
|
-
import { readWorkspaceConfig, workspaceFeatures } from "../services/workspace/workspace-config.js";
|
|
7
|
-
import { initializeWorkspace } from "../services/workspace/workspace-preparation.js";
|
|
8
|
-
import { discoverWorkspaceSkills } from "../services/workspace/workspace-skills.js";
|
|
9
|
-
|
|
10
|
-
function disabledMessage(adapter: PluginHostAdapter, configuration: Awaited<ReturnType<typeof readWorkspaceConfig>>) {
|
|
11
|
-
return configuration.error ?? `Personal Bot 未在此工作区启用。运行 ${adapter.initCommandHint};配置文件:${configuration.path}`;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function pluginCommand(adapter: PluginHostAdapter, args: readonly string[], cwd: string) {
|
|
15
|
-
const root = await adapter.resolveRoot(cwd);
|
|
16
|
-
const action = args.join(" ");
|
|
17
|
-
requireThat(["init", "status"].includes(action), adapter.usage);
|
|
18
|
-
if (action === "init") await initializeWorkspace(root);
|
|
19
|
-
const configuration = await readWorkspaceConfig(root);
|
|
20
|
-
return { version: packageVersion, workspaceRoot: root, resourceRoot, configuration };
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function runPluginHost(adapter: PluginHostAdapter, args: readonly string[]): Promise<void> {
|
|
24
|
-
if (args[0] === "hook") {
|
|
25
|
-
let input = "";
|
|
26
|
-
process.stdin.setEncoding("utf8");
|
|
27
|
-
for await (const chunk of process.stdin) input += String(chunk);
|
|
28
|
-
process.stdout.write(JSON.stringify(await pluginHook(adapter, JSON.parse(input))) + "\n");
|
|
29
|
-
} else {
|
|
30
|
-
process.stdout.write(JSON.stringify(await pluginCommand(adapter, args, process.cwd()), null, 2) + "\n");
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Shared hook execution engine; host-specific protocols stay in PluginHostAdapter implementations. */
|
|
35
|
-
export async function pluginHook(adapter: PluginHostAdapter, payload: unknown): Promise<Record<string, unknown>> {
|
|
36
|
-
if (process.env.PBOT_SUBAGENT_RUN_ID) return adapter.formatPass(payload);
|
|
37
|
-
const event = adapter.parseEvent(payload);
|
|
38
|
-
if (event.kind === "ignore") return adapter.formatPass(payload);
|
|
39
|
-
const root = await adapter.resolveRoot(event.cwd, event.raw);
|
|
40
|
-
const configuration = await readWorkspaceConfig(root);
|
|
41
|
-
const features = workspaceFeatures(configuration);
|
|
42
|
-
if (event.kind === "check-skill") {
|
|
43
|
-
if (!configuration.enabled) return adapter.formatDeny(event, disabledMessage(adapter, configuration));
|
|
44
|
-
if (!features.skills) return adapter.formatDeny(event, `Personal Bot 工作区技能已在 ${configuration.path} 中停用(features.skills: false)。`);
|
|
45
|
-
return adapter.formatPass(payload);
|
|
46
|
-
}
|
|
47
|
-
if (!configuration.enabled) return adapter.formatPass(payload);
|
|
48
|
-
const workspaceSkills = features.skills && !adapter.nativeWorkspaceSkills
|
|
49
|
-
? await discoverWorkspaceSkills(root)
|
|
50
|
-
: [];
|
|
51
|
-
if (!features.prompts && !workspaceSkills.length) return adapter.formatPass(payload);
|
|
52
|
-
const context = await loadWorkspaceContext({
|
|
53
|
-
host: adapter.host,
|
|
54
|
-
root,
|
|
55
|
-
role: event.role,
|
|
56
|
-
...(adapter.coordinatorPrompt ? { coordinatorPrompt: adapter.coordinatorPrompt } : {}),
|
|
57
|
-
includePrompts: features.prompts,
|
|
58
|
-
includeRootAgents: features.prompts && !adapter.nativeRootAgents,
|
|
59
|
-
...(event.localRoleOnly ? { localRoleOnly: true } : {}),
|
|
60
|
-
workspaceSkills,
|
|
61
|
-
});
|
|
62
|
-
return adapter.formatContext(event, context);
|
|
63
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
-
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
-
import type { SessionId } from "@deepseek-ai/dsh-session";
|
|
4
|
-
import { BlockAssembler, type PreparedLlmCall } from "@deepseek-ai/dsh-llm";
|
|
5
|
-
import type { HistorySummarizer } from "../../model/history.js";
|
|
6
|
-
import { requireThat } from "../../common/validation.js";
|
|
7
|
-
import { reduceHistorySummary } from "../history-summary.js";
|
|
8
|
-
|
|
9
|
-
declare module "@deepseek-ai/dsh-llm" {
|
|
10
|
-
interface LlmRequestPurposeMap { "pbot-history": true }
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** Independent text calls through the host's routing and authentication; no Agent or Session messages. */
|
|
14
|
-
export function dshHistorySummarizer(ctx: Context, selection: ReturnType<Agent["model"]["current"]>, sessionId: SessionId): HistorySummarizer {
|
|
15
|
-
return async (request, signal) => {
|
|
16
|
-
requireThat(selection, "请先选择 dsh 模型。"); signal.throwIfAborted();
|
|
17
|
-
const prepare = () => ctx.llm.prepareCall({ provider: selection.provider, model: selection.model, maxTokens: request.maxTokens }, signal,
|
|
18
|
-
(controls, model) => ({ ...controls, ...(model.reasoning?.efforts[0] ? { reasoningEffort: model.reasoning.efforts[0].id } : {}) }));
|
|
19
|
-
let first: PreparedLlmCall | undefined = await prepare();
|
|
20
|
-
const budget = Math.max(2000, Math.min(24000, Math.floor((first.context?.contextWindow ?? 12000) / 2)));
|
|
21
|
-
const ask: HistorySummarizer = async ({ system, prompt }, signal) => {
|
|
22
|
-
signal.throwIfAborted();
|
|
23
|
-
const prepared = first ?? await prepare(); first = undefined;
|
|
24
|
-
const assembler = new BlockAssembler(); let finished = false;
|
|
25
|
-
for await (const chunk of prepared.stream({ ...prepared.config, system, sessionId, purpose: "pbot-history", signal, tools: [],
|
|
26
|
-
messages: [{ role: "user", content: [{ type: "text", text: prompt }] }] })) {
|
|
27
|
-
signal.throwIfAborted(); assembler.push(chunk); if (chunk.type === "finish") finished = true;
|
|
28
|
-
}
|
|
29
|
-
signal.throwIfAborted();
|
|
30
|
-
const reason = assembler.finish;
|
|
31
|
-
requireThat(finished && reason.kind === "stop", reason.kind === "error" || reason.kind === "aborted" ? reason.failure.message : "历史摘要未正常结束:" + reason.kind);
|
|
32
|
-
const blocks = assembler.blocks();
|
|
33
|
-
requireThat(!blocks.some(block => block.type === "tool-call"), "历史摘要不能执行工具。");
|
|
34
|
-
const answer = blocks.filter(block => block.type === "text").map(block => block.text).join("\n").trim();
|
|
35
|
-
requireThat(answer, "历史摘要为空。"); return answer;
|
|
36
|
-
};
|
|
37
|
-
return reduceHistorySummary(budget, ask)(request, signal);
|
|
38
|
-
};
|
|
39
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { realpath } from "node:fs/promises";
|
|
2
|
-
import type { Context } from "@deepseek-ai/cordis";
|
|
3
|
-
import type { SessionEvent, SessionHeader } from "@deepseek-ai/dsh-session";
|
|
4
|
-
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
5
|
-
import type {} from "@deepseek-ai/dsh-session-query";
|
|
6
|
-
import type { HistoryExchange, HistoryLocation, HistorySession, HistorySource } from "../../model/history.js";
|
|
7
|
-
import { requireThat } from "../../common/validation.js";
|
|
8
|
-
import { finalDshAnswer } from "./messages.js";
|
|
9
|
-
|
|
10
|
-
type Question = Extract<SessionEvent, { type: "user/message" }>;
|
|
11
|
-
type Answer = Extract<SessionEvent, { type: "assistant/message" }>;
|
|
12
|
-
const text = (content: Question["data"]["content"]) => content.flatMap(block => block.type === "text" ? [block.text] :
|
|
13
|
-
block.type === "image" ? ["[图片 " + (block.attachment.name ?? block.attachment.attachmentId) + "]"] :
|
|
14
|
-
block.type === "file" ? ["[附件 " + (block.attachment.name ?? block.attachment.attachmentId) + "]"] : []).join("\n");
|
|
15
|
-
|
|
16
|
-
/** Archive questions and the final/partial answer; raw tool records stay in the native log. */
|
|
17
|
-
export function projectDshHistory(header: SessionHeader, events: readonly SessionEvent[], name = ""): HistorySession {
|
|
18
|
-
const exchanges: HistoryExchange[] = [], supersededEntryIds: string[] = [];
|
|
19
|
-
let users: Question[] = [], answer: Answer | undefined, observed: string[] = [];
|
|
20
|
-
const finish = (completed = false) => {
|
|
21
|
-
if (users.length) {
|
|
22
|
-
const entries = [...users, ...(answer ? [answer] : [])];
|
|
23
|
-
const body = answer ? answer.data.message.content.filter(block => block.type === "text").map(block => block.text).join("\n") : "";
|
|
24
|
-
exchanges.push({ entryIds: entries.map(event => "dsh:" + event.seq), from: new Date(users[0]!.time).toISOString(),
|
|
25
|
-
to: new Date(entries.at(-1)!.time).toISOString(),
|
|
26
|
-
completed: completed && Boolean(answer && finalDshAnswer(answer).trim()),
|
|
27
|
-
text: users.map(event => (event.data.source.kind === "user" ? "用户:\n" : "协调者要求:\n") + text(event.data.content)).join("\n\n") +
|
|
28
|
-
(body ? "\n\n助手:\n" + body : "") });
|
|
29
|
-
}
|
|
30
|
-
const last = (answer ?? users.at(-1))?.seq;
|
|
31
|
-
supersededEntryIds.push(...observed.filter(id => id !== "dsh:" + last));
|
|
32
|
-
users = []; answer = undefined; observed = [];
|
|
33
|
-
};
|
|
34
|
-
for (const event of events) {
|
|
35
|
-
if (event.type === "turn/start") finish();
|
|
36
|
-
else if (event.type === "user/message" && ["user", "pbot-input"].includes(event.data.source.kind)) {
|
|
37
|
-
if (!answer) observed.push("dsh:" + event.seq);
|
|
38
|
-
users.push(event);
|
|
39
|
-
} else if (event.type === "assistant/message" && users.length) {
|
|
40
|
-
answer = event; observed.push("dsh:" + event.seq);
|
|
41
|
-
}
|
|
42
|
-
else if (event.type === "turn/end") finish(event.data.reason.kind === "completed");
|
|
43
|
-
}
|
|
44
|
-
finish();
|
|
45
|
-
return { sessionId: header.id, name, branches: exchanges.length ? [exchanges] : [], supersededEntryIds };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export class DshHistory implements HistorySource {
|
|
49
|
-
readonly host = "dsh";
|
|
50
|
-
constructor(private readonly ctx: Context, private readonly root: string, private readonly relatedSessions: () => string[] = () => []) {}
|
|
51
|
-
async scan(location: HistoryLocation, signal?: AbortSignal, excluded?: ReadonlySet<string>) {
|
|
52
|
-
requireThat(location.host === "dsh", "dsh 历史只读取 dsh 原生会话。");
|
|
53
|
-
signal?.throwIfAborted();
|
|
54
|
-
const records = (await this.ctx.sessionQuery.listSessions(signal)).filter(record => !excluded?.has(record.header.id));
|
|
55
|
-
const selected = new Set<string>(), warnings: string[] = [];
|
|
56
|
-
// Expert records also name ACP members and sessions that dsh no longer stores; only real dsh sessions are readable.
|
|
57
|
-
const stored = new Set<string>(records.map(record => record.header.id));
|
|
58
|
-
try { for (const id of this.relatedSessions()) if (stored.has(id)) selected.add(id); } catch (error) { warnings.push("专家引用:" + String(error)); }
|
|
59
|
-
if (location.sessionId && !excluded?.has(location.sessionId)) selected.add(location.sessionId);
|
|
60
|
-
for (const record of records) {
|
|
61
|
-
signal?.throwIfAborted();
|
|
62
|
-
if ((record.header.origin !== "subagent" || !record.header.parentSession) && record.header.cwd &&
|
|
63
|
-
await realpath(record.header.cwd).catch(() => record.header.cwd) === this.root) selected.add(record.header.id);
|
|
64
|
-
}
|
|
65
|
-
// Native subagents may use a different cwd while still belonging to a workspace's parent.
|
|
66
|
-
for (let changed = true; changed;) {
|
|
67
|
-
changed = false;
|
|
68
|
-
for (const record of records) if (record.header.origin === "subagent" && record.header.parentSession && selected.has(record.header.parentSession) && !selected.has(record.header.id)) {
|
|
69
|
-
selected.add(record.header.id); changed = true;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const sessions: HistorySession[] = [];
|
|
73
|
-
for (const id of selected) {
|
|
74
|
-
signal?.throwIfAborted();
|
|
75
|
-
try {
|
|
76
|
-
using observation = await this.ctx.sessionQuery.observeSession(SessionId(id), { ...(signal ? { signal } : {}), projectionMode: "none" });
|
|
77
|
-
const title = await this.ctx.sessionQuery.readTitle(SessionId(id), signal);
|
|
78
|
-
const session = projectDshHistory(observation.header, observation.events, title?.title);
|
|
79
|
-
if (session.branches.length) sessions.push(session);
|
|
80
|
-
} catch (error) { signal?.throwIfAborted(); warnings.push(id + ": " + String(error)); }
|
|
81
|
-
}
|
|
82
|
-
return { sessions, warnings };
|
|
83
|
-
}
|
|
84
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { HistorySummarizer } from "../model/history.js";
|
|
2
|
-
|
|
3
|
-
/** Split Pi/dsh summary inputs within the model's character budget. */
|
|
4
|
-
export function splitHistorySummary(text: string, budget: number): string[] {
|
|
5
|
-
if (!Number.isInteger(budget) || budget < 2) throw new Error("历史摘要分段预算无效。");
|
|
6
|
-
const parts: string[] = [];
|
|
7
|
-
for (let offset = 0; offset < text.length;) {
|
|
8
|
-
let end = Math.min(text.length, offset + budget);
|
|
9
|
-
if (end < text.length && /[\uD800-\uDBFF]/.test(text[end - 1]!)) end--;
|
|
10
|
-
parts.push(text.slice(offset, end)); offset = end;
|
|
11
|
-
}
|
|
12
|
-
return parts;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function reduceHistorySummary(budget: number, ask: HistorySummarizer): HistorySummarizer {
|
|
16
|
-
return async (request, signal) => {
|
|
17
|
-
let text = request.prompt;
|
|
18
|
-
while (text.length > budget) {
|
|
19
|
-
const parts: string[] = [];
|
|
20
|
-
for (const prompt of splitHistorySummary(text, budget)) {
|
|
21
|
-
signal.throwIfAborted();
|
|
22
|
-
parts.push(await ask({ ...request, prompt }, signal));
|
|
23
|
-
}
|
|
24
|
-
const smaller = parts.join("\n\n");
|
|
25
|
-
if (smaller.length >= text.length) throw new Error("历史摘要未缩短,稍后重试。");
|
|
26
|
-
text = smaller;
|
|
27
|
-
}
|
|
28
|
-
signal.throwIfAborted(); return ask({ ...request, prompt: text }, signal);
|
|
29
|
-
};
|
|
30
|
-
}
|