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,6 +1,5 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import {
|
|
3
|
-
import type { HistoryExchange, HistoryHost, HistoryNode, HistoryRecord, HistorySession, HistorySummary, RawHistory } from "../../model/history.js";
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import type { HistoryExchange, HistoryHost, HistorySession, RawHistory } from "../../model/history.js";
|
|
4
3
|
import { requireThat } from "../../common/validation.js";
|
|
5
4
|
|
|
6
5
|
/** Each native entry has one predecessor. A shortened observation can extend a known path, not erase its prefix. */
|
|
@@ -28,9 +27,9 @@ function mergeBranches(previous: string[][], observed: string[][], removed: Set<
|
|
|
28
27
|
return branches;
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
/**
|
|
30
|
+
/** Merge a native session observation into its raw archive without modifying persisted order invariants. */
|
|
32
31
|
export function indexHistory(session: HistorySession, previous?: RawHistory, host: HistoryHost = previous?.host ?? "pi"): RawHistory {
|
|
33
|
-
requireThat(!previous || previous.host === host && previous.sessionId === session.sessionId, "历史会话与归档来源不匹配。");
|
|
32
|
+
requireThat(!previous || (previous.host === host && previous.sessionId === session.sessionId), "历史会话与归档来源不匹配。");
|
|
34
33
|
const id = previous?.id ?? (host === "pi" ? "" : host + "-") + randomUUID();
|
|
35
34
|
const exchanges = new Map(previous?.exchanges.map(item => [item.id, item]));
|
|
36
35
|
const byEnd = new Map(previous?.exchanges.map(item => [item.entryIds.at(-1)!, item.id]));
|
|
@@ -57,69 +56,56 @@ export function indexHistory(session: HistorySession, previous?: RawHistory, hos
|
|
|
57
56
|
removed.add(item.id); exchanges.delete(item.id);
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
|
-
return {
|
|
61
|
-
|
|
59
|
+
return {
|
|
60
|
+
host,
|
|
61
|
+
id,
|
|
62
|
+
sessionId: session.sessionId,
|
|
63
|
+
name: session.name,
|
|
64
|
+
exchanges: [...exchanges.values()],
|
|
65
|
+
branches: mergeBranches(previous?.branches ?? [], branches, removed),
|
|
66
|
+
};
|
|
62
67
|
}
|
|
63
68
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const children = item.children.map(id => inputs.get(id));
|
|
77
|
-
if (!children.length || !children.every(child => child !== undefined)) { changed.add(item.id); continue; }
|
|
78
|
-
let summary = item;
|
|
79
|
-
if (item.children.some(id => changed.has(id))) {
|
|
80
|
-
summary = { ...item, ...span(children), text: "", ready: false }; changed.add(item.id);
|
|
69
|
+
/** Return deduplicated exchanges in conversation order (branch order first, then any unbranched entries by timestamp). */
|
|
70
|
+
export function orderedRawExchanges(raw: RawHistory): (HistoryExchange & { id: string })[] {
|
|
71
|
+
const lookup = new Map(raw.exchanges.map(item => [item.id, item]));
|
|
72
|
+
const seen = new Set<string>();
|
|
73
|
+
const ordered: (HistoryExchange & { id: string })[] = [];
|
|
74
|
+
for (const branch of raw.branches) {
|
|
75
|
+
for (const id of branch) {
|
|
76
|
+
if (seen.has(id)) continue;
|
|
77
|
+
const item = lookup.get(id);
|
|
78
|
+
if (!item) continue;
|
|
79
|
+
seen.add(id);
|
|
80
|
+
ordered.push(item);
|
|
81
81
|
}
|
|
82
|
-
retained.set(item.id, summary); inputs.set(item.id, summary);
|
|
83
82
|
}
|
|
84
|
-
|
|
83
|
+
const rest = raw.exchanges
|
|
84
|
+
.filter(item => !seen.has(item.id))
|
|
85
|
+
.sort((a, b) => a.from.localeCompare(b.from) || a.id.localeCompare(b.id));
|
|
86
|
+
ordered.push(...rest);
|
|
87
|
+
return ordered;
|
|
85
88
|
}
|
|
86
89
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const nodes = new Map<string, HistoryNode>(raw.exchanges.map(value => [value.id,
|
|
90
|
-
{ ...value, kind: "exchange", level: 0, ready: true, children: [], parents: [] }]));
|
|
91
|
-
const stored = new Map(saved?.map(value => [value.id, value]));
|
|
92
|
-
const groups = new Map<string, Pick<HistorySummary, "id" | "level" | "children">>(stored);
|
|
93
|
-
for (const branch of raw.branches) {
|
|
94
|
-
let layer = branch.map(id => ({ id, end: nodes.get(id)!.entryIds.at(-1)! }));
|
|
95
|
-
for (let level = 1; layer.length >= 4; level++) {
|
|
96
|
-
const next: typeof layer = [];
|
|
97
|
-
for (let i = 0; i + 4 <= layer.length; i += 4) {
|
|
98
|
-
const end = layer[i + 3]!.end, id = `${raw.id}:${level}:${end}`;
|
|
99
|
-
groups.set(id, { id, level, children: layer.slice(i, i + 4).map(child => child.id) });
|
|
100
|
-
next.push({ id, end });
|
|
101
|
-
}
|
|
102
|
-
layer = next;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
for (const group of [...groups.values()].sort((a, b) => a.level - b.level)) {
|
|
106
|
-
const children = group.children.map(id => nodes.get(id));
|
|
107
|
-
if (!children.length || !children.every(child => child !== undefined)) continue;
|
|
108
|
-
const old = stored.get(group.id);
|
|
109
|
-
const summary = old && isDeepStrictEqual(old.children, group.children) && (!old.ready || children.every(child => child.ready)) ? old :
|
|
110
|
-
{ ...group, ...span(children), text: "", ready: false };
|
|
111
|
-
nodes.set(group.id, { ...summary, kind: "summary", parents: [] });
|
|
112
|
-
}
|
|
113
|
-
for (const node of nodes.values()) for (const child of node.children) nodes.get(child)!.parents.push(node.id);
|
|
114
|
-
const top = [...nodes.values()].filter(node => !node.parents.length).sort((a, b) => a.from.localeCompare(b.from));
|
|
115
|
-
for (const child of top) child.parents.push(raw.id);
|
|
116
|
-
const dates = raw.exchanges.flatMap(item => [item.from, item.to]).sort();
|
|
117
|
-
const name = raw.name || raw.exchanges[0]?.text.replace(/\s+/g, " ").slice(0, 80) || "";
|
|
118
|
-
nodes.set(raw.id, { id: raw.id, kind: "session", level: -1, entryIds: [], text: name, ready: true,
|
|
119
|
-
completed: raw.exchanges.every(item => item.completed), from: dates[0] ?? "", to: dates.at(-1) ?? "", parents: [], children: top.map(node => node.id) });
|
|
120
|
-
return { host: raw.host, id: raw.id, sessionId: raw.sessionId, name, nodes: [...nodes.values()] };
|
|
90
|
+
export function rawSessionTitle(raw: RawHistory): string {
|
|
91
|
+
return raw.name.trim();
|
|
121
92
|
}
|
|
122
93
|
|
|
123
|
-
export function
|
|
124
|
-
|
|
94
|
+
export function rawSessionSpan(exchanges: readonly HistoryExchange[]): { from: string; to: string; completed: boolean } {
|
|
95
|
+
const dates = exchanges.flatMap(item => [item.from, item.to]).filter(Boolean).sort();
|
|
96
|
+
return {
|
|
97
|
+
from: dates[0] ?? "",
|
|
98
|
+
to: dates.at(-1) ?? "",
|
|
99
|
+
completed: exchanges.every(item => item.completed),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Stable SHA-256 fingerprint over ordered exchange contents for exact deduplication and prefix matching. */
|
|
104
|
+
export function fingerprintExchanges(exchanges: readonly (HistoryExchange & { id: string })[]): string {
|
|
105
|
+
const hash = createHash("sha256");
|
|
106
|
+
for (const item of exchanges) {
|
|
107
|
+
hash.update(JSON.stringify([item.id, item.entryIds, item.text, item.from, item.to, item.completed]));
|
|
108
|
+
hash.update("\n");
|
|
109
|
+
}
|
|
110
|
+
return hash.digest("hex");
|
|
125
111
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { requireThat } from "../../common/validation.js";
|
|
3
|
+
import type { HistoryMigrationConflict, HistoryMigrationItem, HistoryMigrationReport } from "../../model/history.js";
|
|
4
|
+
import { rawHistoryBucket, summaryArtifactBucket } from "../../storage/history-files.js";
|
|
5
|
+
import { workspaceHistoryFiles } from "./workspace-history.js";
|
|
6
|
+
|
|
7
|
+
export interface MigrateHistoryOptions {
|
|
8
|
+
dryRun?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Read-only check for unmigrated flat history files when running under monthly layout. */
|
|
12
|
+
export function checkHistoryMigrationNotice(root: string): string | undefined {
|
|
13
|
+
return workspaceHistoryFiles(root).migrationNotice();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Explicitly migrate flat .pbot/history/raw/*.json and .pbot/history/summaries/<dim>/*.json
|
|
18
|
+
* into UTC YYYY/MM/ (or unknown/) buckets. Moves files directly without keeping duplicates
|
|
19
|
+
* and never modifies .pbot/config.json or overwrites existing destinations.
|
|
20
|
+
*/
|
|
21
|
+
export function migrateWorkspaceHistory(root: string, options: MigrateHistoryOptions = {}): HistoryMigrationReport {
|
|
22
|
+
const files = workspaceHistoryFiles(root);
|
|
23
|
+
const { layout } = files;
|
|
24
|
+
requireThat(
|
|
25
|
+
layout === "monthly",
|
|
26
|
+
'当前工作区配置为平铺布局(history.layout: "flat"),无需迁移到年月目录;如需迁移,请先在 .pbot/config.json 中将 history.layout 设为 "monthly" 或移除该配置项。',
|
|
27
|
+
);
|
|
28
|
+
const dryRun = Boolean(options.dryRun);
|
|
29
|
+
const moved: HistoryMigrationItem[] = [];
|
|
30
|
+
const skipped: HistoryMigrationConflict[] = [];
|
|
31
|
+
const errors: { path: string; error: string }[] = [];
|
|
32
|
+
|
|
33
|
+
function migrateFile(name: string, dimension?: string) {
|
|
34
|
+
const directory = dimension ? `summaries/${dimension}` : "raw";
|
|
35
|
+
const from = `${directory}/${name}`;
|
|
36
|
+
try {
|
|
37
|
+
const record = dimension ? files.readFlatSummaryFile(dimension, name) : files.readFlatRawFile(name);
|
|
38
|
+
const bucket = "dimension" in record ? summaryArtifactBucket(record) : rawHistoryBucket(record);
|
|
39
|
+
const to = `${directory}/${bucket}/${name}`;
|
|
40
|
+
const source = dimension ? { kind: "summary" as const, dimension } : { kind: "raw" as const };
|
|
41
|
+
if (files.moveHistoryFile(from, to, dryRun) === "conflict") {
|
|
42
|
+
skipped.push({ ...source, from, to, reason: "目标路径已存在同名文件。" });
|
|
43
|
+
} else {
|
|
44
|
+
moved.push({ ...source, id: record.id, from, to });
|
|
45
|
+
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
errors.push({ path: join(files.directory, from), error: error instanceof Error ? error.message : String(error) });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const run = () => {
|
|
52
|
+
for (const name of files.listFlatRawFiles()) migrateFile(name);
|
|
53
|
+
for (const dimension of files.listDimensions()) {
|
|
54
|
+
for (const name of files.listFlatSummaryFiles(dimension)) migrateFile(name, dimension);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
if (dryRun) run();
|
|
59
|
+
else files.controlMigration(run);
|
|
60
|
+
|
|
61
|
+
return { layout, dryRun, moved, skipped, errors };
|
|
62
|
+
}
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { requireThat } from "../../common/validation.js";
|
|
2
|
+
import { historyPageLimits } from "../../model/history.js";
|
|
3
|
+
import type { HistoryHost, HistoryQuery, RawHistory, SummaryArtifact } from "../../model/history.js";
|
|
4
|
+
import {
|
|
5
|
+
type HistoryFiles,
|
|
6
|
+
historyBucketFromTimestamp,
|
|
7
|
+
rawHistoryBucket,
|
|
8
|
+
unknownHistoryBucket,
|
|
9
|
+
} from "../../storage/history-files.js";
|
|
10
|
+
import { workspaceHistoryFiles } from "./workspace-history.js";
|
|
11
|
+
import { orderedRawExchanges, rawSessionSpan, rawSessionTitle } from "./history-index.js";
|
|
12
|
+
|
|
13
|
+
const summaryIdPrefix = "summary:";
|
|
14
|
+
|
|
15
|
+
export interface HistoryNodeBrief {
|
|
16
|
+
host: HistoryHost;
|
|
17
|
+
id: string;
|
|
18
|
+
kind: "session" | "exchange" | "summary";
|
|
19
|
+
dimension?: string;
|
|
20
|
+
sessionId: string;
|
|
21
|
+
name: string;
|
|
22
|
+
preview: string;
|
|
23
|
+
from: string;
|
|
24
|
+
to: string;
|
|
25
|
+
ready: boolean;
|
|
26
|
+
completed: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface HistorySearchMatch extends HistoryNodeBrief {
|
|
30
|
+
parents: string[];
|
|
31
|
+
snippet: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface HistorySearchResult {
|
|
35
|
+
matches: HistorySearchMatch[];
|
|
36
|
+
total: number;
|
|
37
|
+
nextOffset: number | null;
|
|
38
|
+
warnings: string[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface HistoryReadNode extends HistoryNodeBrief {
|
|
42
|
+
text: string;
|
|
43
|
+
totalLength: number;
|
|
44
|
+
nextOffset: number | null;
|
|
45
|
+
parents: HistoryNodeBrief[];
|
|
46
|
+
children: HistoryNodeBrief[];
|
|
47
|
+
nextChildrenOffset: number | null;
|
|
48
|
+
source: {
|
|
49
|
+
host: HistoryHost;
|
|
50
|
+
sessionId: string;
|
|
51
|
+
entryIds: string[];
|
|
52
|
+
dimension?: string;
|
|
53
|
+
};
|
|
54
|
+
warnings: string[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const page = <T>(values: readonly T[], offset: number, limit: number) => ({
|
|
58
|
+
values: values.slice(offset, offset + limit),
|
|
59
|
+
nextOffset: offset + limit < values.length ? offset + limit : null,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const previewText = (text: string) => text.replace(/\s+/g, " ").trim().slice(0, 100);
|
|
63
|
+
|
|
64
|
+
export function summaryNodeId(dimension: string, artifactId: string): string {
|
|
65
|
+
return `${summaryIdPrefix}${dimension}:${artifactId}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function parseSummaryNodeId(id: string): { dimension: string; artifactId: string } | undefined {
|
|
69
|
+
if (!id.startsWith(summaryIdPrefix)) return undefined;
|
|
70
|
+
const rest = id.slice(summaryIdPrefix.length);
|
|
71
|
+
const sep = rest.indexOf(":");
|
|
72
|
+
if (sep <= 0 || sep === rest.length - 1) return undefined;
|
|
73
|
+
return { dimension: rest.slice(0, sep), artifactId: rest.slice(sep + 1) };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function parseExchangeNodeId(id: string): { rawId: string } | undefined {
|
|
77
|
+
const index = id.indexOf(":0:");
|
|
78
|
+
if (index <= 0) return undefined;
|
|
79
|
+
return { rawId: id.slice(0, index) };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function sessionBrief(raw: RawHistory, summaryPreview?: string): HistoryNodeBrief {
|
|
83
|
+
const ordered = orderedRawExchanges(raw);
|
|
84
|
+
const span = rawSessionSpan(ordered);
|
|
85
|
+
const name = rawSessionTitle(raw);
|
|
86
|
+
return {
|
|
87
|
+
host: raw.host,
|
|
88
|
+
id: raw.id,
|
|
89
|
+
kind: "session",
|
|
90
|
+
sessionId: raw.sessionId,
|
|
91
|
+
name,
|
|
92
|
+
preview: summaryPreview ? previewText(summaryPreview) : previewText(name || ordered[0]?.text || ""),
|
|
93
|
+
from: span.from,
|
|
94
|
+
to: span.to,
|
|
95
|
+
ready: true,
|
|
96
|
+
completed: span.completed,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function exchangeBrief(raw: RawHistory, exchange: RawHistory["exchanges"][number], title: string): HistoryNodeBrief {
|
|
101
|
+
return {
|
|
102
|
+
host: raw.host,
|
|
103
|
+
id: exchange.id,
|
|
104
|
+
kind: "exchange",
|
|
105
|
+
sessionId: raw.sessionId,
|
|
106
|
+
name: title,
|
|
107
|
+
preview: previewText(exchange.text),
|
|
108
|
+
from: exchange.from,
|
|
109
|
+
to: exchange.to,
|
|
110
|
+
ready: true,
|
|
111
|
+
completed: exchange.completed,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function summaryBrief(artifact: SummaryArtifact): HistoryNodeBrief {
|
|
116
|
+
return {
|
|
117
|
+
host: artifact.host ?? "workspace",
|
|
118
|
+
id: summaryNodeId(artifact.dimension, artifact.id),
|
|
119
|
+
kind: "summary",
|
|
120
|
+
dimension: artifact.dimension,
|
|
121
|
+
sessionId: artifact.sessionId ?? artifact.id,
|
|
122
|
+
name: artifact.title,
|
|
123
|
+
preview: previewText(artifact.text),
|
|
124
|
+
from: artifact.from,
|
|
125
|
+
to: artifact.to,
|
|
126
|
+
ready: true,
|
|
127
|
+
completed: true,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function sliceSnippet(text: string, needle: string): string {
|
|
132
|
+
if (!needle) return text.slice(0, 400);
|
|
133
|
+
const start = Math.max(0, text.toLowerCase().indexOf(needle) - 80);
|
|
134
|
+
return text.slice(start, start + 400);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function inTimeRange(from: string, to: string, after: number, before: number): boolean {
|
|
138
|
+
const fromMs = from ? Date.parse(from) : NaN;
|
|
139
|
+
const toMs = to ? Date.parse(to) : NaN;
|
|
140
|
+
if (after !== -Infinity && !Number.isNaN(toMs) && toMs < after) return false;
|
|
141
|
+
if (before !== Infinity && !Number.isNaN(fromMs) && fromMs > before) return false;
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Isolated, stateless read-only search over .pbot/history/raw/ and .pbot/history/summaries/<dimension>/.
|
|
147
|
+
* Uses ripgrep (with automatic Node fallback) to pre-filter candidate JSON files before parsing.
|
|
148
|
+
*/
|
|
149
|
+
export function searchWorkspaceHistory(root: string, query: HistoryQuery = {}): HistorySearchResult {
|
|
150
|
+
const { host, sessionId, dimension, from, to, offset = 0, limit = historyPageLimits.search.default } = query;
|
|
151
|
+
const needle = (query.query ?? "").trim().toLowerCase();
|
|
152
|
+
const after = from === undefined ? -Infinity : Date.parse(from);
|
|
153
|
+
const before = to === undefined ? Infinity : Date.parse(to);
|
|
154
|
+
requireThat(!Number.isNaN(after) && !Number.isNaN(before) && after <= before, "时间范围无效,请使用 ISO 日期或时间。");
|
|
155
|
+
|
|
156
|
+
const files = workspaceHistoryFiles(root);
|
|
157
|
+
const warnings: string[] = [];
|
|
158
|
+
const flatNotice = files.migrationNotice();
|
|
159
|
+
if (flatNotice) warnings.push(flatNotice);
|
|
160
|
+
const matches: HistorySearchMatch[] = [];
|
|
161
|
+
|
|
162
|
+
function collectSummaries(artifacts: SummaryArtifact[]) {
|
|
163
|
+
warnings.push(...files.warnings);
|
|
164
|
+
for (const artifact of artifacts) {
|
|
165
|
+
if (!inTimeRange(artifact.from, artifact.to, after, before)) continue;
|
|
166
|
+
if (needle && !`${artifact.title}\n${artifact.text}`.toLowerCase().includes(needle)) continue;
|
|
167
|
+
const brief = summaryBrief(artifact);
|
|
168
|
+
if (host && brief.host !== host || sessionId && brief.sessionId !== sessionId) continue;
|
|
169
|
+
matches.push({
|
|
170
|
+
...brief,
|
|
171
|
+
parents: artifact.dimension === "monthly" ? [] : artifact.source.rawIds,
|
|
172
|
+
snippet: sliceSnippet(artifact.text, needle),
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (!needle) {
|
|
178
|
+
// Empty query: list sessions (default / dimension="raw") or list summaries of a specific dimension.
|
|
179
|
+
if (dimension && dimension !== "raw") {
|
|
180
|
+
collectSummaries(files.listSummaries(dimension));
|
|
181
|
+
} else {
|
|
182
|
+
const raws = files.listRaw(host);
|
|
183
|
+
warnings.push(...files.warnings);
|
|
184
|
+
const sessionSummaries = new Map(files.listSummaries("session").map(item => [item.id, item]));
|
|
185
|
+
warnings.push(...files.warnings);
|
|
186
|
+
for (const raw of raws) {
|
|
187
|
+
if (sessionId && raw.sessionId !== sessionId) continue;
|
|
188
|
+
const summary = sessionSummaries.get(raw.id);
|
|
189
|
+
const brief = sessionBrief(raw, summary?.text);
|
|
190
|
+
if (!inTimeRange(brief.from, brief.to, after, before)) continue;
|
|
191
|
+
matches.push({
|
|
192
|
+
...brief,
|
|
193
|
+
parents: [],
|
|
194
|
+
snippet: summary ? sliceSnippet(summary.text, "") : brief.preview,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
// Keyword query: pre-filter candidate files via rg/fallback, then parse and match exact fields.
|
|
200
|
+
const searchRaw = !dimension || dimension === "raw";
|
|
201
|
+
const summaryDimensions = dimension === "raw"
|
|
202
|
+
? []
|
|
203
|
+
: dimension
|
|
204
|
+
? [dimension]
|
|
205
|
+
: files.listDimensions();
|
|
206
|
+
|
|
207
|
+
if (searchRaw) {
|
|
208
|
+
const candidateRaws = files.searchCandidateRaw(needle);
|
|
209
|
+
warnings.push(...files.warnings);
|
|
210
|
+
for (const raw of candidateRaws) {
|
|
211
|
+
if (host && raw.host !== host) continue;
|
|
212
|
+
if (sessionId && raw.sessionId !== sessionId) continue;
|
|
213
|
+
const ordered = orderedRawExchanges(raw);
|
|
214
|
+
const title = rawSessionTitle(raw);
|
|
215
|
+
for (const item of ordered) {
|
|
216
|
+
if (!item.text.toLowerCase().includes(needle)) continue;
|
|
217
|
+
if (!inTimeRange(item.from, item.to, after, before)) continue;
|
|
218
|
+
matches.push({
|
|
219
|
+
...exchangeBrief(raw, item, title),
|
|
220
|
+
parents: [raw.id],
|
|
221
|
+
snippet: sliceSnippet(item.text, needle),
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
for (const dim of summaryDimensions) {
|
|
228
|
+
collectSummaries(files.searchCandidateSummaries(dim, needle));
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
matches.sort((a, b) => b.to.localeCompare(a.to) || a.id.localeCompare(b.id));
|
|
233
|
+
const paged = page(matches, offset, limit);
|
|
234
|
+
return {
|
|
235
|
+
matches: paged.values,
|
|
236
|
+
total: matches.length,
|
|
237
|
+
nextOffset: paged.nextOffset,
|
|
238
|
+
warnings: [...new Set(warnings)],
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function sliceText(text: string, offset: number, limit: number) {
|
|
243
|
+
requireThat(offset <= text.length, "读取位置超出正文。");
|
|
244
|
+
let start = offset;
|
|
245
|
+
if (start && /[\uDC00-\uDFFF]/.test(text[start] ?? "")) start--;
|
|
246
|
+
let end = Math.min(text.length, start + limit);
|
|
247
|
+
if (end < text.length && /[\uD800-\uDBFF]/.test(text[end - 1] ?? "")) end += end - start === 1 ? 1 : -1;
|
|
248
|
+
return {
|
|
249
|
+
text: text.slice(start, end),
|
|
250
|
+
totalLength: text.length,
|
|
251
|
+
nextOffset: end < text.length ? end : null,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function findMonthlyParent(files: HistoryFiles, bucket: string, rawId: string): HistoryNodeBrief | undefined {
|
|
256
|
+
if (files.layout !== "monthly" || bucket === unknownHistoryBucket) return undefined;
|
|
257
|
+
const monthly = files.readSummary("monthly", bucket.replace("/", "-"));
|
|
258
|
+
if (!monthly || !monthly.source.rawIds.includes(rawId)) return undefined;
|
|
259
|
+
return summaryBrief(monthly);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** O(1) read of a session root, summary artifact, or individual raw exchange. */
|
|
263
|
+
export function readWorkspaceHistory(
|
|
264
|
+
root: string,
|
|
265
|
+
id: string,
|
|
266
|
+
offset = 0,
|
|
267
|
+
limit: number = historyPageLimits.read.default,
|
|
268
|
+
childrenOffset = 0,
|
|
269
|
+
host?: HistoryHost,
|
|
270
|
+
): HistoryReadNode {
|
|
271
|
+
const files = workspaceHistoryFiles(root);
|
|
272
|
+
const baseWarnings: string[] = [];
|
|
273
|
+
const flatNotice = files.migrationNotice();
|
|
274
|
+
if (flatNotice) baseWarnings.push(flatNotice);
|
|
275
|
+
|
|
276
|
+
// 1. Summary artifact: summary:<dimension>:<artifactId>
|
|
277
|
+
const parsedSummary = parseSummaryNodeId(id);
|
|
278
|
+
if (parsedSummary) {
|
|
279
|
+
const artifact = files.readSummary(parsedSummary.dimension, parsedSummary.artifactId);
|
|
280
|
+
requireThat(artifact, "历史节点不存在,请重新搜索。");
|
|
281
|
+
const brief = summaryBrief(artifact);
|
|
282
|
+
requireThat(!host || brief.host === host, "历史节点不存在,请重新搜索。");
|
|
283
|
+
const parents: HistoryNodeBrief[] = [];
|
|
284
|
+
const children: HistoryNodeBrief[] = [];
|
|
285
|
+
|
|
286
|
+
if (artifact.dimension === "monthly") {
|
|
287
|
+
// Monthly summary drills down to per-session summaries (falling back to raw session roots).
|
|
288
|
+
for (const rawId of artifact.source.rawIds) {
|
|
289
|
+
const sessionSummary = files.readSummary("session", rawId);
|
|
290
|
+
if (sessionSummary) {
|
|
291
|
+
children.push(summaryBrief(sessionSummary));
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
const raw = files.readRaw(rawId);
|
|
295
|
+
if (raw) children.push(sessionBrief(raw));
|
|
296
|
+
}
|
|
297
|
+
} else {
|
|
298
|
+
const wantedExchanges = new Set(artifact.source.exchangeIds);
|
|
299
|
+
for (const rawId of artifact.source.rawIds) {
|
|
300
|
+
const raw = files.readRaw(rawId);
|
|
301
|
+
if (!raw) continue;
|
|
302
|
+
parents.push(sessionBrief(raw, artifact.dimension === "session" ? artifact.text : undefined));
|
|
303
|
+
const ordered = orderedRawExchanges(raw);
|
|
304
|
+
const title = rawSessionTitle(raw);
|
|
305
|
+
for (const item of ordered) {
|
|
306
|
+
if (!wantedExchanges.size || wantedExchanges.has(item.id)) {
|
|
307
|
+
children.push(exchangeBrief(raw, item, title));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (artifact.dimension === "session") {
|
|
312
|
+
const bucket = historyBucketFromTimestamp(artifact.from || artifact.to);
|
|
313
|
+
const monthlyParent = findMonthlyParent(files, bucket, artifact.id);
|
|
314
|
+
if (monthlyParent) parents.push(monthlyParent);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const pagedChildren = page(children, childrenOffset, 20);
|
|
319
|
+
const sliced = sliceText(artifact.text, offset, limit);
|
|
320
|
+
return {
|
|
321
|
+
...brief,
|
|
322
|
+
...sliced,
|
|
323
|
+
parents,
|
|
324
|
+
children: pagedChildren.values,
|
|
325
|
+
nextChildrenOffset: pagedChildren.nextOffset,
|
|
326
|
+
source: {
|
|
327
|
+
host: brief.host,
|
|
328
|
+
sessionId: brief.sessionId,
|
|
329
|
+
entryIds: artifact.source.exchangeIds,
|
|
330
|
+
dimension: artifact.dimension,
|
|
331
|
+
},
|
|
332
|
+
warnings: [...new Set([...baseWarnings, ...files.warnings])],
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// 2. Raw exchange: <rawId>:0:<end>
|
|
337
|
+
const parsedExchange = parseExchangeNodeId(id);
|
|
338
|
+
if (parsedExchange) {
|
|
339
|
+
const raw = files.readRaw(parsedExchange.rawId);
|
|
340
|
+
requireThat(raw && (!host || raw.host === host), "历史节点不存在,请重新搜索。");
|
|
341
|
+
const exchange = raw.exchanges.find(item => item.id === id);
|
|
342
|
+
requireThat(exchange, "历史节点不存在,请重新搜索。");
|
|
343
|
+
const title = rawSessionTitle(raw);
|
|
344
|
+
const parents: HistoryNodeBrief[] = [sessionBrief(raw)];
|
|
345
|
+
for (const dim of files.listDimensions()) {
|
|
346
|
+
if (dim === "monthly") continue;
|
|
347
|
+
const artifact = files.readSummary(dim, raw.id);
|
|
348
|
+
if (artifact) parents.push(summaryBrief(artifact));
|
|
349
|
+
}
|
|
350
|
+
const sliced = sliceText(exchange.text, offset, limit);
|
|
351
|
+
return {
|
|
352
|
+
...exchangeBrief(raw, exchange, title),
|
|
353
|
+
...sliced,
|
|
354
|
+
parents,
|
|
355
|
+
children: [],
|
|
356
|
+
nextChildrenOffset: null,
|
|
357
|
+
source: {
|
|
358
|
+
host: raw.host,
|
|
359
|
+
sessionId: raw.sessionId,
|
|
360
|
+
entryIds: exchange.entryIds,
|
|
361
|
+
},
|
|
362
|
+
warnings: [...new Set([...baseWarnings, ...files.warnings])],
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// 3. Session root: <rawId>
|
|
367
|
+
const raw = files.readRaw(id);
|
|
368
|
+
requireThat(raw && (!host || raw.host === host), "历史节点不存在,请重新搜索。");
|
|
369
|
+
const ordered = orderedRawExchanges(raw);
|
|
370
|
+
const title = rawSessionTitle(raw);
|
|
371
|
+
const summaryChildren: HistoryNodeBrief[] = [];
|
|
372
|
+
let sessionSummaryText: string | undefined;
|
|
373
|
+
for (const dim of files.listDimensions()) {
|
|
374
|
+
if (dim === "monthly") continue;
|
|
375
|
+
const artifact = files.readSummary(dim, raw.id);
|
|
376
|
+
if (!artifact) continue;
|
|
377
|
+
if (dim === "session") sessionSummaryText = artifact.text;
|
|
378
|
+
summaryChildren.push(summaryBrief(artifact));
|
|
379
|
+
}
|
|
380
|
+
const monthlyParent = findMonthlyParent(files, rawHistoryBucket(raw), raw.id);
|
|
381
|
+
const allChildren: HistoryNodeBrief[] = [
|
|
382
|
+
...summaryChildren,
|
|
383
|
+
...ordered.map(item => exchangeBrief(raw, item, title)),
|
|
384
|
+
];
|
|
385
|
+
const pagedChildren = page(allChildren, childrenOffset, 20);
|
|
386
|
+
const body = sessionSummaryText ? (title ? `${title}\n\n${sessionSummaryText}` : sessionSummaryText) : title;
|
|
387
|
+
const sliced = sliceText(body, offset, limit);
|
|
388
|
+
return {
|
|
389
|
+
...sessionBrief(raw, sessionSummaryText),
|
|
390
|
+
...sliced,
|
|
391
|
+
parents: monthlyParent ? [monthlyParent] : [],
|
|
392
|
+
children: pagedChildren.values,
|
|
393
|
+
nextChildrenOffset: pagedChildren.nextOffset,
|
|
394
|
+
source: {
|
|
395
|
+
host: raw.host,
|
|
396
|
+
sessionId: raw.sessionId,
|
|
397
|
+
entryIds: ordered.flatMap(item => item.entryIds),
|
|
398
|
+
},
|
|
399
|
+
warnings: [...new Set([...baseWarnings, ...files.warnings])],
|
|
400
|
+
};
|
|
401
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { object } from "../../common/json.js";
|
|
2
|
+
import { requireThat } from "../../common/validation.js";
|
|
3
|
+
|
|
4
|
+
export type ParsedHistoryCommand =
|
|
5
|
+
| { kind: "status" }
|
|
6
|
+
| { kind: "list" }
|
|
7
|
+
| { kind: "migrate"; dryRun: boolean }
|
|
8
|
+
| { kind: "summary"; dimensions?: string[]; force: boolean; backend?: string; model?: string; thinking?: string }
|
|
9
|
+
| { kind: "query"; input: Record<string, unknown> };
|
|
10
|
+
|
|
11
|
+
export const historyCommandUsage =
|
|
12
|
+
'用法:/pbot history summary [维度...] [--force] [--backend <acp>] [--model <model>] [--thinking <level>] | migrate [--dry-run] | status | list | {"action":"search"|"read",...}';
|
|
13
|
+
|
|
14
|
+
export function parseHistoryCommand(raw: string | readonly string[]): ParsedHistoryCommand {
|
|
15
|
+
const tokens = typeof raw === "string"
|
|
16
|
+
? raw.trim().startsWith("{") ? [raw.trim()] : raw.trim().split(/\s+/).filter(Boolean)
|
|
17
|
+
: raw;
|
|
18
|
+
const [sub] = tokens;
|
|
19
|
+
if (!sub || sub === "status" && tokens.length === 1) return { kind: "status" };
|
|
20
|
+
if (sub === "list" && tokens.length === 1) return { kind: "list" };
|
|
21
|
+
if (tokens.length === 1 && sub.startsWith("{")) {
|
|
22
|
+
const parsed: unknown = JSON.parse(sub);
|
|
23
|
+
requireThat(object(parsed), "历史查询参数必须是 JSON 对象。");
|
|
24
|
+
return { kind: "query", input: parsed };
|
|
25
|
+
}
|
|
26
|
+
if (sub === "migrate") {
|
|
27
|
+
let dryRun = false;
|
|
28
|
+
for (const token of tokens.slice(1)) {
|
|
29
|
+
if (token === "--dry-run") dryRun = true;
|
|
30
|
+
else throw new Error(`未知参数:${token}\n${historyCommandUsage}`);
|
|
31
|
+
}
|
|
32
|
+
return { kind: "migrate", dryRun };
|
|
33
|
+
}
|
|
34
|
+
if (sub === "summary") {
|
|
35
|
+
let force = false;
|
|
36
|
+
let backend: string | undefined;
|
|
37
|
+
let model: string | undefined;
|
|
38
|
+
let thinking: string | undefined;
|
|
39
|
+
const dimensions: string[] = [];
|
|
40
|
+
const rest = tokens.slice(1);
|
|
41
|
+
for (let i = 0; i < rest.length; i++) {
|
|
42
|
+
const token = rest[i]!;
|
|
43
|
+
if (token === "--force" || token === "-f") {
|
|
44
|
+
force = true;
|
|
45
|
+
} else if (token === "--backend") {
|
|
46
|
+
backend = rest[++i];
|
|
47
|
+
requireThat(backend && !backend.startsWith("-"), "--backend 需要指定 ACP 后端名称(如 pi、dsh、claude)。");
|
|
48
|
+
} else if (token === "--model") {
|
|
49
|
+
model = rest[++i];
|
|
50
|
+
requireThat(model && !model.startsWith("-"), "--model 需要指定模型标识。");
|
|
51
|
+
} else if (token === "--thinking") {
|
|
52
|
+
thinking = rest[++i];
|
|
53
|
+
requireThat(thinking && !thinking.startsWith("-"), "--thinking 需要指定思考深度。");
|
|
54
|
+
} else if (token.startsWith("-")) {
|
|
55
|
+
throw new Error(`未知参数:${token}\n${historyCommandUsage}`);
|
|
56
|
+
} else {
|
|
57
|
+
dimensions.push(token);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
kind: "summary",
|
|
62
|
+
...(dimensions.length ? { dimensions } : {}),
|
|
63
|
+
force,
|
|
64
|
+
...(backend ? { backend } : {}),
|
|
65
|
+
...(model ? { model } : {}),
|
|
66
|
+
...(thinking ? { thinking } : {}),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
throw new Error(historyCommandUsage);
|
|
70
|
+
}
|