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,18 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { linkSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmdirSync, unlinkSync } from "node:fs";
|
|
3
|
+
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
3
4
|
import { isDeepStrictEqual } from "node:util";
|
|
4
|
-
import {
|
|
5
|
-
import { requireThat } from "../common/validation.js";
|
|
5
|
+
import { isHistoryIdentifier, requireThat } from "../common/validation.js";
|
|
6
6
|
import { internalPath, readJsonFile, syncDirectory, writeJsonFile } from "./atomic-json.js";
|
|
7
7
|
import { fileId, privateDirectory } from "./file-access.js";
|
|
8
|
-
import {
|
|
8
|
+
import { matchIdentity, rawHistory, summaryArtifact } from "./history-format.js";
|
|
9
|
+
const yearPattern = /^\d{4}$/;
|
|
10
|
+
const monthPattern = /^(?:0[1-9]|1[0-2])$/;
|
|
11
|
+
const monthlyIdPattern = /^(\d{4})-(0[1-9]|1[0-2])$/;
|
|
12
|
+
const monthlyRelativeJsonPattern = /^(?:\d{4}\/(?:0[1-9]|1[0-2])|unknown)\/[^/]+\.json$/;
|
|
13
|
+
const yearlyRelativeJsonPattern = /^(?:\d{4}|unknown)\/[^/]+\.json$/;
|
|
14
|
+
export const unknownHistoryBucket = "unknown";
|
|
9
15
|
function ordinaryDirectory(path) {
|
|
10
16
|
const stat = lstatSync(path, { throwIfNoEntry: false });
|
|
11
17
|
if (!stat)
|
|
12
18
|
return false;
|
|
13
|
-
requireThat(stat.isDirectory(), "历史目录必须使用普通目录:" + path);
|
|
19
|
+
requireThat(stat.isDirectory() && !stat.isSymbolicLink(), "历史目录必须使用普通目录:" + path);
|
|
14
20
|
return true;
|
|
15
21
|
}
|
|
22
|
+
function ordinaryFile(path) {
|
|
23
|
+
const stat = lstatSync(path, { throwIfNoEntry: false });
|
|
24
|
+
return Boolean(stat && stat.isFile() && !stat.isSymbolicLink());
|
|
25
|
+
}
|
|
16
26
|
function sharedDirectory(path) {
|
|
17
27
|
const parent = dirname(path);
|
|
18
28
|
return (basename(parent) !== ".pbot" || ordinaryDirectory(parent)) && ordinaryDirectory(path);
|
|
@@ -29,21 +39,107 @@ function ensureDirectory(path) {
|
|
|
29
39
|
}
|
|
30
40
|
}
|
|
31
41
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
export function earliestTimestamp(values) {
|
|
43
|
+
let bestMs;
|
|
44
|
+
let bestValue;
|
|
45
|
+
for (const value of values) {
|
|
46
|
+
if (!value)
|
|
47
|
+
continue;
|
|
48
|
+
const ms = Date.parse(value);
|
|
49
|
+
if (Number.isNaN(ms))
|
|
50
|
+
continue;
|
|
51
|
+
if (bestMs === undefined || ms < bestMs) {
|
|
52
|
+
bestMs = ms;
|
|
53
|
+
bestValue = value;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return bestValue;
|
|
35
57
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
58
|
+
/** Resolve UTC YYYY/MM bucket from an ISO timestamp, falling back to "unknown". */
|
|
59
|
+
export function historyBucketFromTimestamp(timestamp) {
|
|
60
|
+
if (!timestamp)
|
|
61
|
+
return unknownHistoryBucket;
|
|
62
|
+
const ms = Date.parse(timestamp);
|
|
63
|
+
if (Number.isNaN(ms))
|
|
64
|
+
return unknownHistoryBucket;
|
|
65
|
+
const date = new Date(ms);
|
|
66
|
+
const year = String(date.getUTCFullYear()).padStart(4, "0");
|
|
67
|
+
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
|
|
68
|
+
return `${year}/${month}`;
|
|
69
|
+
}
|
|
70
|
+
export function rawHistoryBucket(raw) {
|
|
71
|
+
const earliest = earliestTimestamp(raw.exchanges.map(item => item.from))
|
|
72
|
+
?? earliestTimestamp(raw.exchanges.map(item => item.to));
|
|
73
|
+
return historyBucketFromTimestamp(earliest);
|
|
74
|
+
}
|
|
75
|
+
export function summaryArtifactBucket(artifact) {
|
|
76
|
+
if (artifact.dimension === "monthly") {
|
|
77
|
+
const match = monthlyIdPattern.exec(artifact.id);
|
|
78
|
+
if (match)
|
|
79
|
+
return match[1];
|
|
80
|
+
const bucket = historyBucketFromTimestamp(artifact.from || artifact.to);
|
|
81
|
+
return bucket === unknownHistoryBucket ? unknownHistoryBucket : bucket.slice(0, 4);
|
|
40
82
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
83
|
+
return historyBucketFromTimestamp(artifact.from || artifact.to);
|
|
84
|
+
}
|
|
85
|
+
const topLevelJsonNames = (directory) => readdirSync(directory, { withFileTypes: true })
|
|
86
|
+
.filter(entry => entry.isFile() && !entry.isSymbolicLink() && entry.name.endsWith(".json"))
|
|
87
|
+
.map(entry => entry.name)
|
|
88
|
+
.sort();
|
|
89
|
+
function bucketDirs(directory, depth) {
|
|
90
|
+
if (!ordinaryDirectory(directory))
|
|
91
|
+
return [];
|
|
92
|
+
const buckets = [];
|
|
93
|
+
const entries = readdirSync(directory, { withFileTypes: true });
|
|
94
|
+
const years = entries
|
|
95
|
+
.filter(entry => entry.isDirectory() && !entry.isSymbolicLink() && yearPattern.test(entry.name))
|
|
96
|
+
.map(entry => entry.name)
|
|
97
|
+
.sort((a, b) => b.localeCompare(a));
|
|
98
|
+
if (depth === "year") {
|
|
99
|
+
buckets.push(...years);
|
|
44
100
|
}
|
|
101
|
+
else {
|
|
102
|
+
for (const year of years) {
|
|
103
|
+
const yearDir = join(directory, year);
|
|
104
|
+
const months = readdirSync(yearDir, { withFileTypes: true })
|
|
105
|
+
.filter(entry => entry.isDirectory() && !entry.isSymbolicLink() && monthPattern.test(entry.name))
|
|
106
|
+
.map(entry => entry.name)
|
|
107
|
+
.sort((a, b) => b.localeCompare(a));
|
|
108
|
+
for (const month of months)
|
|
109
|
+
buckets.push(`${year}/${month}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (entries.some(entry => entry.isDirectory() && !entry.isSymbolicLink() && entry.name === unknownHistoryBucket)) {
|
|
113
|
+
buckets.push(unknownHistoryBucket);
|
|
114
|
+
}
|
|
115
|
+
return buckets;
|
|
116
|
+
}
|
|
117
|
+
function listLayoutJsonFiles(directory, layout, depth = "month") {
|
|
118
|
+
if (!ordinaryDirectory(directory))
|
|
119
|
+
return [];
|
|
120
|
+
if (layout === "flat")
|
|
121
|
+
return topLevelJsonNames(directory);
|
|
122
|
+
const results = [];
|
|
123
|
+
for (const bucket of bucketDirs(directory, depth)) {
|
|
124
|
+
const dir = join(directory, bucket);
|
|
125
|
+
for (const name of topLevelJsonNames(dir)) {
|
|
126
|
+
results.push(`${bucket}/${name}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return results;
|
|
130
|
+
}
|
|
131
|
+
function locateLayoutFile(directory, name, layout, depth = "month") {
|
|
132
|
+
if (!ordinaryDirectory(directory))
|
|
133
|
+
return undefined;
|
|
134
|
+
if (layout === "flat") {
|
|
135
|
+
return ordinaryFile(join(directory, name)) ? name : undefined;
|
|
136
|
+
}
|
|
137
|
+
for (const bucket of bucketDirs(directory, depth)) {
|
|
138
|
+
if (ordinaryFile(join(directory, bucket, name)))
|
|
139
|
+
return `${bucket}/${name}`;
|
|
140
|
+
}
|
|
141
|
+
return undefined;
|
|
45
142
|
}
|
|
46
|
-
const names = (directory) => readdirSync(directory).filter(name => name.endsWith(".json"));
|
|
47
143
|
const filename = (id) => fileId(id) + ".json";
|
|
48
144
|
const diagnostic = (path, error) => path + ": " + String(error);
|
|
49
145
|
function optional(read) {
|
|
@@ -55,138 +151,108 @@ function optional(read) {
|
|
|
55
151
|
throw error;
|
|
56
152
|
}
|
|
57
153
|
}
|
|
58
|
-
function namedRaw(value,
|
|
154
|
+
function namedRaw(value, relPath) {
|
|
59
155
|
const raw = rawHistory(value);
|
|
60
|
-
requireThat(
|
|
156
|
+
requireThat(basename(relPath) === filename(raw.id), "历史文件名与根 ID 不匹配。");
|
|
61
157
|
return raw;
|
|
62
158
|
}
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return { raw: namedRaw(value, name) };
|
|
68
|
-
const mixed = legacyHistory(value, privateHost);
|
|
69
|
-
requireThat(name === filename(mixed.id), "历史文件名与根 ID 不匹配。");
|
|
70
|
-
return { ...splitLegacy(mixed), mixed };
|
|
159
|
+
function namedSummary(value, relPath, dimension) {
|
|
160
|
+
const artifact = summaryArtifact(value, dimension);
|
|
161
|
+
requireThat(basename(relPath) === filename(artifact.id), "历史摘要文件名与 ID 不匹配。");
|
|
162
|
+
return artifact;
|
|
71
163
|
}
|
|
72
|
-
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Use ripgrep when available to pre-filter candidate JSON files containing a literal query.
|
|
166
|
+
* Queries containing JSON-escaped characters fall back to direct Node reading to avoid false negatives.
|
|
167
|
+
*/
|
|
168
|
+
function canPrefilterWithRg(query) {
|
|
169
|
+
return query.length > 0 && !/["\\\n\r\t]/.test(query);
|
|
170
|
+
}
|
|
171
|
+
export function findCandidateJsonFiles(directory, query, layout = "monthly", depth = "month") {
|
|
172
|
+
if (!ordinaryDirectory(directory))
|
|
173
|
+
return [];
|
|
174
|
+
const trimmed = query.trim();
|
|
175
|
+
if (!trimmed)
|
|
176
|
+
return listLayoutJsonFiles(directory, layout, depth);
|
|
177
|
+
const relativePattern = depth === "year" ? yearlyRelativeJsonPattern : monthlyRelativeJsonPattern;
|
|
178
|
+
if (canPrefilterWithRg(trimmed)) {
|
|
179
|
+
const args = [
|
|
180
|
+
"--ignore-case",
|
|
181
|
+
"--fixed-strings",
|
|
182
|
+
"--files-with-matches",
|
|
183
|
+
"--glob", "*.json",
|
|
184
|
+
"--no-ignore",
|
|
185
|
+
"--hidden",
|
|
186
|
+
...(layout === "flat" ? ["--max-depth", "1"] : []),
|
|
187
|
+
"--",
|
|
188
|
+
trimmed,
|
|
189
|
+
directory,
|
|
190
|
+
];
|
|
191
|
+
const result = spawnSync("rg", args, { encoding: "utf8", maxBuffer: 8 * 1024 * 1024 });
|
|
192
|
+
if (!result.error && (result.status === 0 || result.status === 1)) {
|
|
193
|
+
if (result.status === 1)
|
|
194
|
+
return [];
|
|
195
|
+
const base = realpathSync(directory);
|
|
196
|
+
const matched = [];
|
|
197
|
+
for (const line of result.stdout.split(/\r?\n/)) {
|
|
198
|
+
const trimmedLine = line.trim();
|
|
199
|
+
if (!trimmedLine)
|
|
200
|
+
continue;
|
|
201
|
+
const rel = relative(base, resolve(trimmedLine)).replaceAll("\\", "/");
|
|
202
|
+
if (layout === "flat") {
|
|
203
|
+
if (!rel.includes("/") && rel.endsWith(".json"))
|
|
204
|
+
matched.push(rel);
|
|
205
|
+
}
|
|
206
|
+
else if (relativePattern.test(rel)) {
|
|
207
|
+
matched.push(rel);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return matched;
|
|
211
|
+
}
|
|
77
212
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
213
|
+
// Fallback: direct case-insensitive file scan via Node built-ins.
|
|
214
|
+
const needle = trimmed.toLowerCase();
|
|
215
|
+
const matched = [];
|
|
216
|
+
for (const rel of listLayoutJsonFiles(directory, layout, depth)) {
|
|
217
|
+
try {
|
|
218
|
+
const content = readFileSync(join(directory, rel), "utf8");
|
|
219
|
+
if (content.toLowerCase().includes(needle))
|
|
220
|
+
matched.push(rel);
|
|
221
|
+
}
|
|
222
|
+
catch { /* Individual unreadable files are reported during JSON parse if needed. */ }
|
|
82
223
|
}
|
|
83
|
-
|
|
84
|
-
return true;
|
|
85
|
-
}
|
|
86
|
-
function retire(directory, relative) {
|
|
87
|
-
const path = internalPath(directory, relative);
|
|
88
|
-
unlinkSync(path);
|
|
89
|
-
syncDirectory(dirname(path));
|
|
224
|
+
return matched;
|
|
90
225
|
}
|
|
91
226
|
export class HistoryFiles {
|
|
92
227
|
directory;
|
|
93
228
|
host;
|
|
229
|
+
layout;
|
|
94
230
|
#warnings = [];
|
|
95
231
|
#rawWarnings = [];
|
|
96
|
-
constructor(directory, host = "pi") {
|
|
232
|
+
constructor(directory, host = "pi", layout = "monthly") {
|
|
97
233
|
this.directory = directory;
|
|
98
234
|
this.host = host;
|
|
99
|
-
|
|
235
|
+
this.layout = layout;
|
|
236
|
+
requireThat(isHistoryIdentifier(host), "历史来源无效。");
|
|
100
237
|
}
|
|
101
238
|
get warnings() { return this.#warnings; }
|
|
102
239
|
get rawWarnings() { return this.#rawWarnings; }
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const message = diagnostic(path, error);
|
|
109
|
-
this.#warnings.push(message);
|
|
110
|
-
this.#rawWarnings.push(message);
|
|
111
|
-
};
|
|
112
|
-
const scan = (directory, layout) => {
|
|
113
|
-
for (const name of names(directory)) {
|
|
114
|
-
const path = join(directory, name);
|
|
115
|
-
try {
|
|
116
|
-
for (;;) {
|
|
117
|
-
const before = lstatSync(path, { bigint: true });
|
|
118
|
-
const file = readJsonFile(directory, name, (value) => {
|
|
119
|
-
if (layout !== "private" && object(value) && isHistoryHost(value.host) && value.host !== this.host)
|
|
120
|
-
return undefined;
|
|
121
|
-
return layout === "raw" ? { raw: namedRaw(value, name) } : oldFile(value, name, layout === "private" ? this.host : undefined);
|
|
122
|
-
});
|
|
123
|
-
if (!file)
|
|
124
|
-
break;
|
|
125
|
-
const { raw } = file;
|
|
126
|
-
if (file.summaries) {
|
|
127
|
-
archives.set(raw.id, { raw, summaries: file.summaries });
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
const layer = layout === "raw" ? "summary" : "hierarchical";
|
|
131
|
-
let summaries, warning;
|
|
132
|
-
try {
|
|
133
|
-
summaries = readSummaries(this.directory, layer, raw)?.summaries ?? [];
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
warning = diagnostic(join(this.directory, layer, name), error);
|
|
137
|
-
summaries = null;
|
|
138
|
-
}
|
|
139
|
-
// Peers take no lock. Retry if a native update replaced the raw file between reads.
|
|
140
|
-
const after = lstatSync(path, { bigint: true });
|
|
141
|
-
if (before.ino !== after.ino || before.ctimeNs !== after.ctimeNs)
|
|
142
|
-
continue;
|
|
143
|
-
if (warning)
|
|
144
|
-
this.#warnings.push(warning);
|
|
145
|
-
archives.set(raw.id, { raw, summaries });
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
catch (error) {
|
|
150
|
-
if (error.code !== "ENOENT")
|
|
151
|
-
rawWarning(path, error);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
// Read the destinations last: a concurrent migration publishes both files before retiring its source.
|
|
156
|
-
if (legacyRoot && this.host !== "claude") {
|
|
157
|
-
try {
|
|
158
|
-
const directory = legacyDirectory(legacyRoot, this.host);
|
|
159
|
-
if (directory)
|
|
160
|
-
scan(directory, "private");
|
|
161
|
-
}
|
|
162
|
-
catch (error) {
|
|
163
|
-
rawWarning(join(legacyRoot, "." + this.host, "pbot/history"), error);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
try {
|
|
167
|
-
if (sharedDirectory(this.directory)) {
|
|
168
|
-
scan(this.directory, "shared");
|
|
169
|
-
const directory = join(this.directory, "raw");
|
|
170
|
-
if (ordinaryDirectory(directory))
|
|
171
|
-
scan(directory, "raw");
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
rawWarning(this.directory, error);
|
|
176
|
-
}
|
|
177
|
-
return [...archives.values()];
|
|
240
|
+
get rawDirectory() { return join(this.directory, "raw"); }
|
|
241
|
+
get summariesDirectory() { return join(this.directory, "summaries"); }
|
|
242
|
+
summaryDirectory(dimension) {
|
|
243
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
244
|
+
return join(this.summariesDirectory, dimension);
|
|
178
245
|
}
|
|
179
|
-
|
|
180
|
-
control(operation) {
|
|
181
|
-
requireThat(this.host !== "claude", "Claude 历史归档只读。");
|
|
246
|
+
withLock(lockName, label, operation) {
|
|
182
247
|
ensureDirectory(this.directory);
|
|
183
|
-
const lock = join(this.directory,
|
|
248
|
+
const lock = join(this.directory, lockName);
|
|
184
249
|
try {
|
|
185
250
|
mkdirSync(lock, { mode: 0o700 });
|
|
186
251
|
}
|
|
187
252
|
catch (error) {
|
|
188
|
-
if (error.code === "EEXIST")
|
|
189
|
-
throw Object.assign(new Error("
|
|
253
|
+
if (error.code === "EEXIST") {
|
|
254
|
+
throw Object.assign(new Error("历史写锁被占用:" + label), { code: "PBOT_HISTORY_BUSY" });
|
|
255
|
+
}
|
|
190
256
|
throw error;
|
|
191
257
|
}
|
|
192
258
|
try {
|
|
@@ -196,146 +262,212 @@ export class HistoryFiles {
|
|
|
196
262
|
rmdirSync(lock);
|
|
197
263
|
}
|
|
198
264
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
265
|
+
/** Synchronous host write lock for raw history files. */
|
|
266
|
+
control(operation) {
|
|
267
|
+
return this.withLock(".write-" + this.host, this.host, operation);
|
|
268
|
+
}
|
|
269
|
+
/** Synchronous dimension write lock for derived summary files. */
|
|
270
|
+
controlSummary(dimension, operation) {
|
|
271
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
272
|
+
return this.withLock(".write-summary-" + dimension, "summary:" + dimension, operation);
|
|
273
|
+
}
|
|
274
|
+
/** Synchronous migration lock for explicit layout migration. */
|
|
275
|
+
controlMigration(operation) {
|
|
276
|
+
return this.withLock(".write-migrate", "migrate", operation);
|
|
277
|
+
}
|
|
278
|
+
migrationNotice() {
|
|
279
|
+
return this.layout === "monthly" ? this.detectFlatFiles().message : undefined;
|
|
280
|
+
}
|
|
281
|
+
/** Detect unmigrated top-level flat JSON files when running under monthly layout. */
|
|
282
|
+
detectFlatFiles() {
|
|
283
|
+
if (!sharedDirectory(this.directory))
|
|
284
|
+
return { rawCount: 0, summaryCount: 0, total: 0 };
|
|
285
|
+
const rawCount = ordinaryDirectory(this.rawDirectory) ? topLevelJsonNames(this.rawDirectory).length : 0;
|
|
286
|
+
let summaryCount = 0;
|
|
287
|
+
for (const dim of this.listDimensions()) {
|
|
288
|
+
const dir = this.summaryDirectory(dim);
|
|
289
|
+
if (ordinaryDirectory(dir))
|
|
290
|
+
summaryCount += topLevelJsonNames(dir).length;
|
|
291
|
+
}
|
|
292
|
+
const total = rawCount + summaryCount;
|
|
293
|
+
if (total === 0)
|
|
294
|
+
return { rawCount: 0, summaryCount: 0, total: 0 };
|
|
295
|
+
return {
|
|
296
|
+
rawCount,
|
|
297
|
+
summaryCount,
|
|
298
|
+
total,
|
|
299
|
+
message: `检测到 ${total} 个未迁移的平铺历史文件(raw ${rawCount},summaries ${summaryCount});当前为年月目录布局(history.layout: monthly),未迁移文件不会被读取。` +
|
|
300
|
+
`请在终端运行 pbot history migrate 整理到 YYYY/MM/ 目录(Pi/dsh 可用 /pbot history migrate),或在 .pbot/config.json 中设置 "history": { "layout": "flat" } 切回平铺布局。`,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
listFlatRawFiles() {
|
|
304
|
+
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.rawDirectory))
|
|
305
|
+
return [];
|
|
306
|
+
return topLevelJsonNames(this.rawDirectory);
|
|
307
|
+
}
|
|
308
|
+
listFlatSummaryFiles(dimension) {
|
|
309
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
310
|
+
const dir = this.summaryDirectory(dimension);
|
|
311
|
+
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory) || !ordinaryDirectory(dir))
|
|
312
|
+
return [];
|
|
313
|
+
return topLevelJsonNames(dir);
|
|
314
|
+
}
|
|
315
|
+
readFlatRawFile(name) {
|
|
316
|
+
return readJsonFile(this.directory, "raw/" + name, value => namedRaw(value, name));
|
|
317
|
+
}
|
|
318
|
+
readFlatSummaryFile(dimension, name) {
|
|
319
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
320
|
+
return readJsonFile(this.directory, `summaries/${dimension}/${name}`, value => namedSummary(value, name, dimension));
|
|
321
|
+
}
|
|
322
|
+
/** Atomically move a file within .pbot/history/ without ever overwriting an existing destination. */
|
|
323
|
+
moveHistoryFile(fromRelative, toRelative, dryRun = false) {
|
|
324
|
+
const src = internalPath(this.directory, fromRelative);
|
|
325
|
+
if (dryRun) {
|
|
326
|
+
const target = internalPath(this.directory, toRelative, true);
|
|
327
|
+
return ordinaryFile(target) ? "conflict" : "moved";
|
|
328
|
+
}
|
|
329
|
+
const dstParentRel = dirname(toRelative);
|
|
330
|
+
if (dstParentRel && dstParentRel !== ".") {
|
|
331
|
+
privateDirectory(this.directory, dstParentRel);
|
|
332
|
+
}
|
|
333
|
+
const dst = internalPath(this.directory, toRelative);
|
|
334
|
+
try {
|
|
335
|
+
linkSync(src, dst);
|
|
336
|
+
}
|
|
337
|
+
catch (error) {
|
|
338
|
+
if (error.code === "EEXIST")
|
|
339
|
+
return "conflict";
|
|
340
|
+
throw error;
|
|
341
|
+
}
|
|
342
|
+
syncDirectory(dirname(dst));
|
|
343
|
+
unlinkSync(src);
|
|
344
|
+
syncDirectory(dirname(src));
|
|
345
|
+
return "moved";
|
|
346
|
+
}
|
|
347
|
+
listRaw(filterHost, onlyFiles) {
|
|
348
|
+
this.#warnings = [];
|
|
349
|
+
this.#rawWarnings = [];
|
|
350
|
+
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.rawDirectory))
|
|
351
|
+
return [];
|
|
352
|
+
const files = onlyFiles ?? listLayoutJsonFiles(this.rawDirectory, this.layout);
|
|
353
|
+
const results = [];
|
|
354
|
+
for (const rel of files) {
|
|
355
|
+
const path = join(this.rawDirectory, rel);
|
|
356
|
+
try {
|
|
357
|
+
const raw = readJsonFile(this.directory, "raw/" + rel, value => namedRaw(value, rel));
|
|
358
|
+
if (filterHost !== undefined && raw.host !== filterHost)
|
|
359
|
+
continue;
|
|
360
|
+
results.push(raw);
|
|
361
|
+
}
|
|
362
|
+
catch (error) {
|
|
363
|
+
if (error.code !== "ENOENT") {
|
|
364
|
+
const message = diagnostic(path, error);
|
|
365
|
+
this.#warnings.push(message);
|
|
366
|
+
this.#rawWarnings.push(message);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return results;
|
|
371
|
+
}
|
|
372
|
+
readRaw(id) {
|
|
373
|
+
const name = filename(id);
|
|
374
|
+
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.rawDirectory))
|
|
375
|
+
return undefined;
|
|
376
|
+
const rel = locateLayoutFile(this.rawDirectory, name, this.layout);
|
|
377
|
+
if (!rel)
|
|
378
|
+
return undefined;
|
|
379
|
+
return optional(() => readJsonFile(this.directory, "raw/" + rel, value => namedRaw(value, rel)));
|
|
204
380
|
}
|
|
205
381
|
saveRaw(raw) {
|
|
206
|
-
|
|
382
|
+
requireThat(isHistoryIdentifier(raw.host) && raw.host === this.host, "历史归档只允许所属来源写入。");
|
|
207
383
|
rawHistory(raw);
|
|
208
384
|
ensureDirectory(this.directory);
|
|
209
|
-
const
|
|
385
|
+
const name = filename(raw.id);
|
|
386
|
+
const existingRel = ordinaryDirectory(this.rawDirectory)
|
|
387
|
+
? locateLayoutFile(this.rawDirectory, name, this.layout)
|
|
388
|
+
: undefined;
|
|
389
|
+
const bucket = this.layout === "monthly" ? rawHistoryBucket(raw) : undefined;
|
|
390
|
+
const rel = existingRel ?? (bucket ? `${bucket}/${name}` : name);
|
|
391
|
+
const current = optional(() => readJsonFile(this.directory, "raw/" + rel, value => namedRaw(value, rel)));
|
|
210
392
|
if (current) {
|
|
211
393
|
matchIdentity(current, raw);
|
|
212
394
|
if (isDeepStrictEqual(current, raw))
|
|
213
395
|
return;
|
|
214
396
|
}
|
|
215
397
|
else {
|
|
216
|
-
|
|
217
|
-
const directory = join(this.directory, layer);
|
|
218
|
-
if (lstatSync(directory, { throwIfNoEntry: false })?.isDirectory()) {
|
|
219
|
-
requireThat(!lstatSync(join(directory, name), { throwIfNoEntry: false }), "历史根 ID 已有关联的摘要文件:" + name);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
privateDirectory(this.directory, "raw");
|
|
398
|
+
privateDirectory(this.directory, bucket ? `raw/${bucket}` : "raw");
|
|
223
399
|
}
|
|
224
|
-
requireThat(writeJsonFile(this.directory, "raw/" +
|
|
225
|
-
}
|
|
226
|
-
saveSummaries(identity, summaries) {
|
|
227
|
-
const name = this.writable(identity);
|
|
228
|
-
requireThat(sharedDirectory(this.directory), "历史原文目录不存在:" + this.directory);
|
|
229
|
-
const raw = readRaw(this.directory, name);
|
|
230
|
-
matchIdentity(raw, identity);
|
|
231
|
-
this.publishSummaries(raw, summaries);
|
|
232
|
-
}
|
|
233
|
-
publishSummaries(raw, summaries, source) {
|
|
234
|
-
const { host, id, sessionId } = raw, path = "summary/" + filename(id);
|
|
235
|
-
const validate = (data) => hierarchicalHistory(data, raw);
|
|
236
|
-
const value = validate({ host, id, sessionId, summaries: summaries.map(summaryData) });
|
|
237
|
-
const previous = readSummaries(this.directory, "summary", raw);
|
|
238
|
-
if (previous) {
|
|
239
|
-
if (isDeepStrictEqual(previous, value)) {
|
|
240
|
-
if (source)
|
|
241
|
-
syncDirectory(join(this.directory, "summary"));
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
requireThat(!source, "历史摘要迁移冲突,请核对已有文件:" + path);
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
privateDirectory(this.directory, "summary");
|
|
248
|
-
if (source === "hierarchical" && linkArchive(this.directory, "hierarchical/" + filename(id), path))
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
requireThat(writeJsonFile(this.directory, path, value, validate, !previous), "历史摘要文件已被占用:" + path);
|
|
400
|
+
requireThat(writeJsonFile(this.directory, "raw/" + rel, raw, rawHistory, !current), "历史根 ID 已被占用:" + rel);
|
|
252
401
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return;
|
|
262
|
-
if (shared && local)
|
|
263
|
-
requireThat(isDeepStrictEqual(shared.raw, local.raw) && (!shared.mixed || isDeepStrictEqual(shared.mixed, local.mixed)), "历史归档迁移冲突,请核对新旧文件:" + name);
|
|
264
|
-
const target = optional(() => readRaw(this.directory, name));
|
|
265
|
-
requireThat(!target || isDeepStrictEqual(target, raw), "历史原文迁移冲突,请核对已有文件:" + name);
|
|
266
|
-
const oldLayer = readSummaries(this.directory, "hierarchical", raw), embedded = source.summaries ?? local?.summaries;
|
|
267
|
-
requireThat(!oldLayer || !embedded || isDeepStrictEqual(oldLayer.summaries, embedded), "旧历史摘要不一致:" + name);
|
|
268
|
-
const summaries = embedded ?? oldLayer?.summaries;
|
|
269
|
-
// The raw file makes this pair discoverable. Publish summaries first; never overwrite a migration conflict.
|
|
270
|
-
if (summaries)
|
|
271
|
-
this.publishSummaries(raw, summaries, oldLayer ? "hierarchical" : "mixed");
|
|
272
|
-
else
|
|
273
|
-
requireThat(!readSummaries(this.directory, "summary", raw) || target, "历史摘要迁移冲突:" + name);
|
|
274
|
-
if (!target) {
|
|
275
|
-
privateDirectory(this.directory, "raw");
|
|
276
|
-
const path = "raw/" + name;
|
|
277
|
-
if (!shared || shared.mixed || !linkArchive(this.directory, name, path)) {
|
|
278
|
-
requireThat(writeJsonFile(this.directory, path, raw, rawHistory, true), "历史原文迁移冲突:" + name);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
else
|
|
282
|
-
syncDirectory(join(this.directory, "raw"));
|
|
283
|
-
syncDirectory(this.directory);
|
|
284
|
-
if (oldLayer) {
|
|
285
|
-
retire(this.directory, "hierarchical/" + name);
|
|
286
|
-
removeEmptyDirectory(join(this.directory, "hierarchical"));
|
|
287
|
-
}
|
|
288
|
-
if (shared)
|
|
289
|
-
retire(this.directory, name);
|
|
290
|
-
if (privateDir)
|
|
291
|
-
retire(privateDir, name);
|
|
402
|
+
listDimensions() {
|
|
403
|
+
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory))
|
|
404
|
+
return [];
|
|
405
|
+
const entries = readdirSync(this.summariesDirectory, { withFileTypes: true });
|
|
406
|
+
return entries
|
|
407
|
+
.filter(entry => entry.isDirectory() && !entry.isSymbolicLink() && isHistoryIdentifier(entry.name))
|
|
408
|
+
.map(entry => entry.name)
|
|
409
|
+
.sort();
|
|
292
410
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
411
|
+
summaryBucketDepth(dimension) {
|
|
412
|
+
return dimension === "monthly" ? "year" : "month";
|
|
413
|
+
}
|
|
414
|
+
listSummaries(dimension, onlyFiles) {
|
|
415
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
416
|
+
const dir = this.summaryDirectory(dimension);
|
|
417
|
+
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory) || !ordinaryDirectory(dir))
|
|
418
|
+
return [];
|
|
419
|
+
const files = onlyFiles ?? listLayoutJsonFiles(dir, this.layout, this.summaryBucketDepth(dimension));
|
|
420
|
+
const results = [];
|
|
421
|
+
for (const rel of files) {
|
|
422
|
+
const path = join(dir, rel);
|
|
298
423
|
try {
|
|
299
|
-
|
|
424
|
+
results.push(readJsonFile(this.directory, `summaries/${dimension}/${rel}`, value => namedSummary(value, rel, dimension)));
|
|
300
425
|
}
|
|
301
|
-
catch {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}) : [];
|
|
305
|
-
if (!legacy && !shared.length)
|
|
306
|
-
return;
|
|
307
|
-
this.control(() => {
|
|
308
|
-
const directory = legacy && legacyDirectory(root, this.host), errors = [];
|
|
309
|
-
const migrateFiles = (local) => {
|
|
310
|
-
const privateNames = new Set(local);
|
|
311
|
-
for (const name of new Set([...local, ...shared])) {
|
|
312
|
-
try {
|
|
313
|
-
this.migrateFile(name, privateNames.has(name) ? directory : undefined);
|
|
314
|
-
}
|
|
315
|
-
catch (error) {
|
|
316
|
-
if (error.code)
|
|
317
|
-
throw error;
|
|
318
|
-
errors.push(diagnostic(name, error));
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
if (directory) {
|
|
323
|
-
requireThat(realpathSync(directory) !== realpathSync(this.directory), "新旧历史目录指向同一位置。");
|
|
324
|
-
const lock = join(directory, ".write");
|
|
325
|
-
mkdirSync(lock, { mode: 0o700 });
|
|
326
|
-
try {
|
|
327
|
-
migrateFiles(names(directory));
|
|
328
|
-
}
|
|
329
|
-
finally {
|
|
330
|
-
rmdirSync(lock);
|
|
426
|
+
catch (error) {
|
|
427
|
+
if (error.code !== "ENOENT") {
|
|
428
|
+
this.#warnings.push(diagnostic(path, error));
|
|
331
429
|
}
|
|
332
|
-
removeEmptyDirectory(directory);
|
|
333
|
-
removeEmptyDirectory(dirname(directory));
|
|
334
430
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
431
|
+
}
|
|
432
|
+
return results;
|
|
433
|
+
}
|
|
434
|
+
readSummary(dimension, id) {
|
|
435
|
+
requireThat(isHistoryIdentifier(dimension), "历史摘要维度无效:" + dimension);
|
|
436
|
+
const dir = this.summaryDirectory(dimension);
|
|
437
|
+
if (!sharedDirectory(this.directory) || !ordinaryDirectory(this.summariesDirectory) || !ordinaryDirectory(dir))
|
|
438
|
+
return undefined;
|
|
439
|
+
const name = filename(id);
|
|
440
|
+
const rel = locateLayoutFile(dir, name, this.layout, this.summaryBucketDepth(dimension));
|
|
441
|
+
if (!rel)
|
|
442
|
+
return undefined;
|
|
443
|
+
return optional(() => readJsonFile(this.directory, `summaries/${dimension}/${rel}`, value => namedSummary(value, rel, dimension)));
|
|
444
|
+
}
|
|
445
|
+
saveSummary(artifact) {
|
|
446
|
+
summaryArtifact(artifact);
|
|
447
|
+
ensureDirectory(this.directory);
|
|
448
|
+
const name = filename(artifact.id);
|
|
449
|
+
const dir = this.summaryDirectory(artifact.dimension);
|
|
450
|
+
const depth = this.summaryBucketDepth(artifact.dimension);
|
|
451
|
+
const existingRel = ordinaryDirectory(this.summariesDirectory) && ordinaryDirectory(dir)
|
|
452
|
+
? locateLayoutFile(dir, name, this.layout, depth)
|
|
453
|
+
: undefined;
|
|
454
|
+
const bucket = this.layout === "monthly" ? summaryArtifactBucket(artifact) : undefined;
|
|
455
|
+
const rel = existingRel ?? (bucket ? `${bucket}/${name}` : name);
|
|
456
|
+
const relativePath = `summaries/${artifact.dimension}/${rel}`;
|
|
457
|
+
privateDirectory(this.directory, dirname(relativePath));
|
|
458
|
+
const current = optional(() => readJsonFile(this.directory, relativePath, value => namedSummary(value, rel, artifact.dimension)));
|
|
459
|
+
if (current && isDeepStrictEqual(current, artifact))
|
|
460
|
+
return;
|
|
461
|
+
requireThat(writeJsonFile(this.directory, relativePath, artifact, value => summaryArtifact(value, artifact.dimension), !current), "历史摘要文件已被占用:" + relativePath);
|
|
462
|
+
}
|
|
463
|
+
/** Isolated read-only candidate search across raw/ and summaries/<dimension>/. */
|
|
464
|
+
searchCandidateRaw(query) {
|
|
465
|
+
const names = findCandidateJsonFiles(this.rawDirectory, query, this.layout, "month");
|
|
466
|
+
return this.listRaw(undefined, names);
|
|
467
|
+
}
|
|
468
|
+
searchCandidateSummaries(dimension, query) {
|
|
469
|
+
const dir = this.summaryDirectory(dimension);
|
|
470
|
+
const names = findCandidateJsonFiles(dir, query, this.layout, this.summaryBucketDepth(dimension));
|
|
471
|
+
return this.listSummaries(dimension, names);
|
|
340
472
|
}
|
|
341
473
|
}
|