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