personal-bot 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +2 -1
- package/DISCLAIMER.md +17 -0
- package/LICENSE +21 -0
- package/README.md +15 -5
- package/README.zh-CN.md +15 -5
- package/bin/pbot-pi-acp.mjs +27 -11
- package/bin/pbot.mjs +22 -2
- package/docs/README.md +3 -1
- package/docs/architecture/design.md +37 -24
- package/docs/architecture/extensibility.md +27 -19
- package/docs/architecture/model-context.md +4 -3
- package/docs/architecture/principles.md +5 -4
- package/docs/guides/capabilities.md +4 -4
- package/docs/guides/cross-harness-workers.md +3 -1
- package/docs/guides/history.md +73 -16
- package/docs/guides/workspace-configuration.md +35 -6
- package/docs/hosts/antigravity.md +2 -0
- package/docs/hosts/claude-code.md +1 -1
- package/docs/hosts/codex-qoder.md +63 -0
- package/docs/hosts/dsh.md +1 -1
- package/docs/hosts/pi.md +1 -1
- package/docs/maintainers/architecture-governance.md +78 -0
- package/hooks/hooks.json +3 -0
- package/lib/antigravity-plugin/DISCLAIMER.md +17 -0
- package/lib/antigravity-plugin/LICENSE +21 -0
- package/lib/antigravity-plugin/bin/pbot-pi-acp.mjs +36 -0
- package/lib/antigravity-plugin/hooks.json +7 -0
- package/lib/antigravity-plugin/lib/claude.js +2 -2
- package/lib/antigravity-plugin/lib/common/files.d.ts +2 -0
- package/lib/antigravity-plugin/lib/common/files.js +44 -0
- package/lib/antigravity-plugin/lib/common/validation.d.ts +4 -0
- package/lib/antigravity-plugin/lib/common/validation.js +8 -0
- package/lib/{extension/acp-member.d.ts → antigravity-plugin/lib/extension/acp/member.d.ts} +5 -5
- package/lib/{extension/acp-member.js → antigravity-plugin/lib/extension/acp/member.js} +6 -6
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +222 -51
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-entry.js +22 -0
- package/lib/{extension → antigravity-plugin/lib/extension/hosts}/dsh/acp-member.js +11 -25
- package/lib/{extension → antigravity-plugin/lib/extension/hosts}/dsh/files.js +3 -3
- package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.d.ts +3 -0
- package/lib/antigravity-plugin/lib/extension/hosts/pi/acp-member.js +100 -0
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.d.ts +12 -0
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +101 -0
- package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.d.ts +6 -0
- package/lib/antigravity-plugin/lib/extension/hosts/workspace-mcp.js +21 -0
- package/lib/antigravity-plugin/lib/extension/mcp.js +2705 -1348
- package/lib/antigravity-plugin/lib/extension/workspace-cli.js +20127 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +1 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +6 -2
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity/adapter.js +171 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/claude/adapter.js +36 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.d.ts +2 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/codex/adapter.js +14 -0
- package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/mcp.d.ts +1 -1
- package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/resources.d.ts +1 -1
- package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/resources.js +4 -4
- package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/skills.js +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/agent-tools.js +32 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/pi/mcp.js +23 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +1 -0
- package/lib/{integrations/hosts/registry.js → antigravity-plugin/lib/integrations/hosts/plugin-registry.js} +10 -3
- package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/prompt-hooks.js +76 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/qoder/adapter.js +16 -0
- package/lib/antigravity-plugin/lib/model/acp.d.ts +7 -3
- package/lib/antigravity-plugin/lib/model/acp.js +8 -0
- package/lib/antigravity-plugin/lib/model/agent.d.ts +121 -0
- package/lib/antigravity-plugin/lib/model/agent.js +4 -0
- package/lib/antigravity-plugin/lib/model/history.d.ts +179 -0
- package/lib/antigravity-plugin/lib/model/history.js +4 -0
- package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +31 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +28 -7
- package/lib/antigravity-plugin/lib/model/workspace-config.js +2 -1
- package/lib/antigravity-plugin/lib/plugin.d.ts +2 -1
- package/lib/antigravity-plugin/lib/plugin.js +4 -4
- package/lib/antigravity-plugin/lib/services/history/history-capture.d.ts +4 -0
- package/lib/antigravity-plugin/lib/services/history/history-capture.js +98 -0
- package/lib/antigravity-plugin/lib/services/history/history-index.d.ts +17 -0
- package/lib/antigravity-plugin/lib/services/history/history-index.js +112 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/monthly.js +121 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.d.ts +7 -0
- package/lib/antigravity-plugin/lib/services/history/summary-dimensions/session.js +124 -0
- package/lib/antigravity-plugin/lib/services/history/summary-registry.d.ts +7 -0
- package/lib/antigravity-plugin/lib/services/history/summary-registry.js +35 -0
- package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +34 -0
- package/lib/antigravity-plugin/lib/services/history/summary-runner.js +299 -0
- package/lib/antigravity-plugin/lib/services/history/workspace-history.d.ts +3 -0
- package/lib/antigravity-plugin/lib/services/history/workspace-history.js +6 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.d.ts +3 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +78 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.d.ts +5 -1
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +77 -7
- package/lib/antigravity-plugin/lib/services/workspace/workspace-files.d.ts +2 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-files.js +17 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.d.ts +14 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-mcp.js +193 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.d.ts +1 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.js +4 -2
- package/lib/antigravity-plugin/lib/storage/acp-files.d.ts +11 -0
- package/lib/antigravity-plugin/lib/storage/acp-files.js +75 -0
- package/lib/antigravity-plugin/lib/storage/agent-files.d.ts +31 -0
- package/lib/antigravity-plugin/lib/storage/agent-files.js +159 -0
- package/lib/antigravity-plugin/lib/storage/atomic-json.d.ts +3 -1
- package/lib/antigravity-plugin/lib/storage/atomic-json.js +43 -3
- package/lib/antigravity-plugin/lib/storage/file-access.d.ts +2 -0
- package/lib/antigravity-plugin/lib/storage/file-access.js +26 -0
- package/lib/antigravity-plugin/lib/storage/history-files.d.ts +55 -0
- package/lib/antigravity-plugin/lib/storage/history-files.js +473 -0
- package/lib/antigravity-plugin/lib/storage/history-format.d.ts +5 -0
- package/lib/antigravity-plugin/lib/storage/history-format.js +60 -0
- package/lib/antigravity-plugin/package.json +1 -1
- package/lib/antigravity-plugin/plugin.json +1 -1
- package/lib/antigravity-plugin/resources/prompts/history-monthly-summary.md +13 -0
- package/lib/antigravity-plugin/resources/prompts/history-summary.md +13 -0
- package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -0
- package/lib/antigravity-plugin/resources/skills/.claude-plugin/plugin.json +4 -0
- package/lib/antigravity-plugin/resources/skills/project-maintenance/SKILL.md +35 -0
- package/lib/antigravity-plugin/resources/skills/provider-connections/SKILL.md +52 -0
- package/lib/antigravity-plugin/skills/pbot/SKILL.md +11 -1
- package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +22 -12
- package/lib/claude.js +2 -2
- package/lib/client.js +42 -60
- package/lib/codex-marketplace/.agents/plugins/marketplace.json +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/.codex-plugin/plugin.json +7 -0
- package/lib/codex-marketplace/plugins/personal-bot/.mcp.json +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/DISCLAIMER.md +17 -0
- package/lib/codex-marketplace/plugins/personal-bot/LICENSE +21 -0
- package/lib/codex-marketplace/plugins/personal-bot/hooks/hooks.json +37 -0
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/SKILL.md +9 -0
- package/lib/codex-marketplace/plugins/personal-bot/skills/pbot/agents/openai.yaml +2 -0
- package/lib/common/validation.d.ts +4 -0
- package/lib/common/validation.js +8 -0
- package/lib/dsh.js +6 -6
- package/lib/extension/acp/member.d.ts +18 -0
- package/lib/extension/acp/member.js +44 -0
- package/lib/extension/acp/worker.js +384 -0
- package/lib/extension/acp-worker.js +222 -51
- package/lib/extension/history/command.d.ts +37 -0
- package/lib/extension/history/command.js +57 -0
- package/lib/extension/hosts/dsh/acp-entry.d.ts +1 -0
- package/lib/extension/hosts/dsh/acp-entry.js +22 -0
- package/lib/extension/hosts/dsh/acp-member.d.ts +4 -0
- package/lib/extension/hosts/dsh/acp-member.js +58 -0
- package/lib/extension/{dsh → hosts/dsh}/command.d.ts +1 -2
- package/lib/extension/{dsh → hosts/dsh}/command.js +9 -11
- package/lib/extension/hosts/dsh/files.d.ts +5 -0
- package/lib/extension/hosts/dsh/files.js +67 -0
- package/lib/extension/hosts/dsh/history.d.ts +4 -0
- package/lib/extension/hosts/dsh/history.js +62 -0
- package/lib/extension/{dsh → hosts/dsh}/management.d.ts +1 -1
- package/lib/extension/{dsh → hosts/dsh}/management.js +12 -10
- package/lib/extension/{dsh → hosts/dsh}/workspace.d.ts +3 -9
- package/lib/extension/{dsh → hosts/dsh}/workspace.js +30 -99
- package/lib/extension/hosts/pi/acp-member.d.ts +3 -0
- package/lib/extension/hosts/pi/acp-member.js +100 -0
- package/lib/extension/hosts/plugin-runtime.d.ts +12 -0
- package/lib/extension/hosts/plugin-runtime.js +101 -0
- package/lib/extension/hosts/workspace-mcp.d.ts +6 -0
- package/lib/extension/hosts/workspace-mcp.js +21 -0
- package/lib/extension/{mcp-bridge.d.ts → mcp/bridge.d.ts} +7 -9
- package/lib/extension/{mcp-bridge.js → mcp/bridge.js} +70 -88
- package/lib/extension/{mcp-workers.d.ts → mcp/tool-contract.d.ts} +129 -374
- package/lib/extension/mcp/tool-contract.js +441 -0
- package/lib/extension/mcp/workers.d.ts +487 -0
- package/lib/extension/mcp/workers.js +598 -0
- package/lib/extension/mcp.js +2705 -1348
- package/lib/extension/{setup-cli.js → setup/cli.js} +12 -9
- package/lib/extension/workspace-cli.js +20127 -0
- package/lib/integrations/acp/agents.d.ts +2 -3
- package/lib/integrations/acp/connection.d.ts +11 -10
- package/lib/integrations/acp/connection.js +6 -0
- package/lib/integrations/acp/harnesses/claude.js +1 -1
- package/lib/integrations/acp/harnesses/dsh.js +1 -1
- package/lib/integrations/acp/harnesses/presets.js +8 -0
- package/lib/integrations/acp/history-summary.d.ts +17 -0
- package/lib/integrations/acp/history-summary.js +101 -0
- package/lib/integrations/acp/launch.d.ts +2 -2
- package/lib/integrations/agent-resources.d.ts +1 -0
- package/lib/integrations/agent-resources.js +6 -2
- package/lib/integrations/hosts/antigravity/adapter.d.ts +6 -0
- package/lib/integrations/hosts/antigravity/adapter.js +171 -0
- package/lib/integrations/hosts/{claude.d.ts → claude/adapter.d.ts} +1 -1
- package/lib/integrations/hosts/claude/adapter.js +36 -0
- package/lib/integrations/hosts/codex/adapter.d.ts +2 -0
- package/lib/integrations/hosts/codex/adapter.js +14 -0
- package/lib/integrations/hosts/dsh/mcp.d.ts +4 -0
- package/lib/integrations/hosts/dsh/mcp.js +28 -0
- package/lib/integrations/hosts/dsh/messages.d.ts +36 -0
- package/lib/integrations/hosts/dsh/messages.js +11 -0
- package/lib/integrations/hosts/dsh/resources.d.ts +6 -0
- package/lib/integrations/hosts/dsh/resources.js +47 -0
- package/lib/integrations/hosts/dsh/root-agents.d.ts +4 -0
- package/lib/integrations/hosts/dsh/root-agents.js +3 -0
- package/lib/integrations/{dsh → hosts/dsh}/schema.js +1 -1
- package/lib/integrations/hosts/dsh/skills.d.ts +8 -0
- package/lib/integrations/hosts/dsh/skills.js +31 -0
- package/lib/integrations/hosts/pi/agent-tools.d.ts +3 -0
- package/lib/integrations/hosts/pi/agent-tools.js +32 -0
- package/lib/integrations/hosts/pi/mcp.d.ts +4 -0
- package/lib/integrations/hosts/pi/mcp.js +23 -0
- package/lib/integrations/hosts/{registry.d.ts → plugin-registry.d.ts} +1 -0
- package/lib/{antigravity-plugin/lib/integrations/hosts/registry.js → integrations/hosts/plugin-registry.js} +10 -3
- package/lib/integrations/hosts/prompt-hooks.d.ts +76 -0
- package/lib/integrations/hosts/prompt-hooks.js +76 -0
- package/lib/integrations/hosts/qoder/adapter.d.ts +2 -0
- package/lib/integrations/hosts/qoder/adapter.js +16 -0
- package/lib/integrations/installation/pi-setup.js +1 -1
- package/lib/model/acp.d.ts +7 -3
- package/lib/model/acp.js +8 -0
- package/lib/model/agent.d.ts +18 -4
- package/lib/model/agent.js +4 -1
- package/lib/model/history.d.ts +143 -34
- package/lib/model/history.js +4 -1
- package/lib/model/installation.js +1 -0
- package/lib/model/plugin-host.d.ts +31 -0
- package/lib/model/workspace-config.d.ts +28 -7
- package/lib/model/workspace-config.js +2 -1
- package/lib/plugin.d.ts +2 -1
- package/lib/plugin.js +4 -4
- package/lib/qoder-plugin/.mcp.json +17 -0
- package/lib/qoder-plugin/.qoder-plugin/plugin.json +7 -0
- package/lib/qoder-plugin/DISCLAIMER.md +17 -0
- package/lib/qoder-plugin/LICENSE +21 -0
- package/lib/qoder-plugin/hooks/hooks.json +37 -0
- package/lib/qoder-plugin/skills/pbot/SKILL.md +9 -0
- package/lib/services/agents/agent-run.d.ts +1 -1
- package/lib/services/agents/agent-service.d.ts +15 -45
- package/lib/services/agents/agent-service.js +22 -3
- package/lib/services/history/history-capture.d.ts +4 -0
- package/lib/services/history/history-capture.js +98 -0
- package/lib/services/history/history-index.d.ts +16 -7
- package/lib/services/history/history-index.js +48 -70
- package/lib/services/history/history-migrate.d.ts +12 -0
- package/lib/services/history/history-migrate.js +54 -0
- package/lib/services/history/history-query.d.ts +51 -0
- package/lib/services/history/history-query.js +352 -0
- package/lib/services/history/summary-command.d.ts +20 -0
- package/lib/services/history/summary-command.js +69 -0
- package/lib/services/history/summary-dimensions/monthly.d.ts +7 -0
- package/lib/services/history/summary-dimensions/monthly.js +121 -0
- package/lib/services/history/summary-dimensions/session.d.ts +7 -0
- package/lib/services/history/summary-dimensions/session.js +124 -0
- package/lib/services/history/summary-registry.d.ts +7 -0
- package/lib/services/history/summary-registry.js +35 -0
- package/lib/services/history/summary-runner.d.ts +34 -0
- package/lib/services/history/summary-runner.js +299 -0
- package/lib/services/history/workspace-history.d.ts +3 -0
- package/lib/services/history/workspace-history.js +6 -0
- package/lib/services/workspace/plugin-releases.d.ts +3 -0
- package/lib/services/workspace/plugin-releases.js +78 -0
- package/lib/services/workspace/workspace-config.d.ts +5 -1
- package/lib/services/workspace/workspace-config.js +77 -7
- package/lib/services/workspace/workspace-mcp.js +22 -29
- package/lib/services/workspace/workspace-skills.d.ts +1 -0
- package/lib/services/workspace/workspace-skills.js +4 -2
- package/lib/storage/acp-files.js +7 -12
- package/lib/storage/agent-files.js +6 -5
- package/lib/storage/atomic-json.d.ts +3 -1
- package/lib/storage/atomic-json.js +43 -3
- package/lib/storage/history-files.d.ts +46 -9
- package/lib/storage/history-files.js +382 -250
- package/lib/storage/history-format.d.ts +3 -13
- package/lib/storage/history-format.js +26 -52
- package/lib/tools/history/actions.d.ts +3 -68
- package/lib/tools/history/actions.js +7 -5
- package/lib/tools/history/contract.d.ts +16 -17
- package/lib/tools/history/contract.js +63 -22
- package/lib/tools/history/dsh-tool.d.ts +1 -2
- package/lib/tools/history/dsh-tool.js +11 -5
- package/lib/ui/dsh/elements.d.ts +2 -5
- package/lib/ui/dsh/elements.js +3 -16
- package/lib/ui/dsh/management.js +26 -13
- package/lib/ui/dsh/styles.d.ts +1 -1
- package/lib/ui/dsh/styles.js +5 -33
- package/package.json +4 -1
- package/resources/antigravity/skills/pbot/SKILL.md +11 -1
- package/resources/claude/skills/pbot/SKILL.md +11 -1
- package/resources/plugin/skills/pbot/SKILL.md +9 -0
- package/resources/prompts/history-coordinator.md +2 -1
- package/resources/prompts/history-monthly-summary.md +13 -0
- package/resources/prompts/history-summary.md +10 -4
- package/resources/prompts/plugin-coordinator.md +1 -0
- package/resources/skills/provider-connections/SKILL.md +22 -12
- package/scripts/README.md +3 -2
- package/src/claude.ts +2 -2
- package/src/common/validation.ts +10 -0
- package/src/dsh.ts +6 -6
- package/src/extension/{acp-member.ts → acp/member.ts} +7 -7
- package/src/extension/{acp-worker.ts → acp/worker.ts} +131 -17
- package/src/extension/history/command.ts +68 -0
- package/src/extension/hosts/dsh/acp-entry.ts +21 -0
- package/src/extension/{dsh → hosts/dsh}/acp-member.ts +12 -23
- package/src/extension/{dsh → hosts/dsh}/command.ts +10 -12
- package/src/extension/{dsh → hosts/dsh}/files.ts +3 -3
- package/src/extension/hosts/dsh/history.ts +67 -0
- package/src/extension/{dsh → hosts/dsh}/management.ts +11 -9
- package/src/extension/{dsh → hosts/dsh}/workspace.ts +31 -76
- package/src/extension/{pi-acp-member.ts → hosts/pi/acp-member.ts} +12 -18
- package/src/extension/{command.ts → hosts/pi/command.ts} +44 -11
- package/src/extension/{events.ts → hosts/pi/events.ts} +8 -4
- package/src/extension/hosts/pi/history.ts +45 -0
- package/src/extension/{lifecycle.ts → hosts/pi/lifecycle.ts} +9 -12
- package/src/extension/hosts/plugin-runtime.ts +96 -0
- package/src/extension/hosts/workspace-mcp.ts +25 -0
- package/src/extension/{mcp-bridge.ts → mcp/bridge.ts} +85 -85
- package/src/extension/mcp/tool-contract.ts +462 -0
- package/src/extension/{mcp-workers.ts → mcp/workers.ts} +151 -448
- package/src/extension/{setup-cli.ts → setup/cli.ts} +14 -11
- package/src/extension/setup/workspace-cli.ts +159 -0
- package/src/integrations/acp/agents.ts +2 -3
- package/src/integrations/acp/connection.ts +6 -0
- package/src/integrations/acp/harnesses/claude.ts +1 -1
- package/src/integrations/acp/harnesses/dsh.ts +1 -1
- package/src/integrations/acp/harnesses/presets.ts +8 -0
- package/src/integrations/acp/history-summary.ts +109 -0
- package/src/integrations/agent-resources.ts +7 -1
- package/src/integrations/hosts/antigravity/adapter.ts +161 -0
- package/src/integrations/hosts/claude/adapter.ts +39 -0
- package/src/integrations/hosts/codex/adapter.ts +16 -0
- package/src/integrations/{dsh → hosts/dsh}/mcp.ts +1 -1
- package/src/integrations/{dsh → hosts/dsh}/resources.ts +5 -5
- package/src/integrations/{dsh → hosts/dsh}/schema.ts +1 -1
- package/src/integrations/{dsh → hosts/dsh}/session.ts +2 -2
- package/src/integrations/{dsh → hosts/dsh}/skills.ts +1 -1
- package/src/integrations/{pi → hosts/pi}/mcp.ts +1 -1
- package/src/integrations/{pi → hosts/pi}/skills.ts +1 -1
- package/src/integrations/hosts/{registry.ts → plugin-registry.ts} +11 -3
- package/src/integrations/hosts/prompt-hooks.ts +72 -0
- package/src/integrations/hosts/qoder/adapter.ts +19 -0
- package/src/integrations/installation/cli-update.ts +116 -0
- package/src/integrations/installation/pi-bridge.ts +1 -1
- package/src/integrations/installation/pi-setup.ts +2 -2
- package/src/integrations/installation/processes.ts +1 -1
- package/src/mcp.ts +1 -1
- package/src/model/acp.ts +11 -3
- package/src/model/agent.ts +20 -4
- package/src/model/history.ts +156 -26
- package/src/model/installation.ts +41 -0
- package/src/model/plugin-host.ts +30 -2
- package/src/model/workspace-config.ts +31 -7
- package/src/pbot.ts +22 -50
- package/src/plugin.ts +4 -4
- package/src/services/agents/agent-service.ts +29 -17
- package/src/services/history/history-capture.ts +91 -0
- package/src/services/history/history-index.ts +48 -62
- package/src/services/history/history-migrate.ts +62 -0
- package/src/services/history/history-query.ts +401 -0
- package/src/services/history/summary-command.ts +70 -0
- package/src/services/history/summary-dimensions/monthly.ts +139 -0
- package/src/services/history/summary-dimensions/session.ts +149 -0
- package/src/services/history/summary-registry.ts +43 -0
- package/src/services/history/summary-runner.ts +343 -0
- package/src/services/history/workspace-history.ts +8 -0
- package/src/services/installation/setup-service.ts +2 -41
- package/src/services/workspace/plugin-releases.ts +68 -0
- package/src/services/workspace/workspace-config.ts +95 -8
- package/src/services/workspace/workspace-mcp.ts +23 -28
- package/src/services/workspace/workspace-skills.ts +5 -2
- package/src/storage/acp-files.ts +7 -12
- package/src/storage/agent-files.ts +6 -5
- package/src/storage/atomic-json.ts +31 -4
- package/src/storage/history-files.ts +416 -189
- package/src/storage/history-format.ts +45 -61
- package/src/tools/history/actions.ts +8 -6
- package/src/tools/history/contract.ts +70 -25
- package/src/tools/history/dsh-tool.ts +17 -8
- package/src/tools/history/pi-tool.ts +23 -0
- package/src/ui/dsh/elements.ts +5 -12
- package/src/ui/dsh/management.ts +36 -20
- package/src/ui/dsh/styles.ts +5 -33
- package/src/ui/{confirmation.ts → pi/confirmation.ts} +1 -1
- package/lib/antigravity-plugin/lib/extension/plugin-runtime.d.ts +0 -10
- package/lib/antigravity-plugin/lib/extension/plugin-runtime.js +0 -67
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.d.ts +0 -4
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.js +0 -79
- package/lib/antigravity-plugin/lib/integrations/hosts/claude.js +0 -60
- package/lib/extension/dsh/history.d.ts +0 -15
- package/lib/extension/dsh/history.js +0 -87
- package/lib/extension/mcp-workers.js +0 -882
- package/lib/extension/plugin-runtime.d.ts +0 -10
- package/lib/extension/plugin-runtime.js +0 -67
- package/lib/integrations/dsh/history-summary.d.ts +0 -11
- package/lib/integrations/dsh/history-summary.js +0 -36
- package/lib/integrations/dsh/history.d.ts +0 -16
- package/lib/integrations/dsh/history.js +0 -167
- package/lib/integrations/history-summary.d.ts +0 -4
- package/lib/integrations/history-summary.js +0 -32
- package/lib/integrations/hosts/antigravity.d.ts +0 -4
- package/lib/integrations/hosts/antigravity.js +0 -79
- package/lib/integrations/hosts/claude.js +0 -60
- package/lib/services/history/history-service.d.ts +0 -106
- package/lib/services/history/history-service.js +0 -242
- package/lib/storage/acp-history.d.ts +0 -10
- package/lib/storage/acp-history.js +0 -57
- package/lib/ui/presentation.d.ts +0 -3
- package/lib/ui/presentation.js +0 -12
- package/src/extension/dsh/history.ts +0 -74
- package/src/extension/history.ts +0 -26
- package/src/extension/plugin-runtime.ts +0 -63
- package/src/integrations/dsh/history-summary.ts +0 -39
- package/src/integrations/dsh/history.ts +0 -84
- package/src/integrations/history-summary.ts +0 -30
- package/src/integrations/hosts/antigravity.ts +0 -83
- package/src/integrations/hosts/claude.ts +0 -62
- package/src/integrations/pi/history.ts +0 -99
- package/src/services/history/history-service.ts +0 -195
- package/src/storage/acp-history.ts +0 -49
- package/src/tools/access.ts +0 -7
- package/src/tools/history/tool.ts +0 -19
- package/src/tools/register.ts +0 -22
- package/src/ui/presentation.ts +0 -12
- /package/lib/{extension → antigravity-plugin/lib/extension/hosts}/dsh/acp-member.d.ts +0 -0
- /package/lib/{extension → antigravity-plugin/lib/extension/hosts}/dsh/files.d.ts +0 -0
- /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/mcp.js +0 -0
- /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/messages.d.ts +0 -0
- /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/messages.js +0 -0
- /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/root-agents.d.ts +0 -0
- /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/root-agents.js +0 -0
- /package/lib/{integrations → antigravity-plugin/lib/integrations/hosts}/dsh/skills.d.ts +0 -0
- /package/lib/extension/{acp-worker.d.ts → acp/worker.d.ts} +0 -0
- /package/lib/extension/{setup-guard.js → setup/guard.js} +0 -0
- /package/lib/integrations/acp/{claude.d.ts → claude-settings.d.ts} +0 -0
- /package/lib/integrations/acp/{claude.js → claude-settings.js} +0 -0
- /package/lib/integrations/{dsh → hosts/dsh}/schema.d.ts +0 -0
- /package/src/extension/{setup-guard.ts → setup/guard.ts} +0 -0
- /package/src/integrations/acp/{claude.ts → claude-settings.ts} +0 -0
- /package/src/integrations/{dsh → hosts/dsh}/messages.ts +0 -0
- /package/src/integrations/{dsh → hosts/dsh}/root-agents.ts +0 -0
- /package/src/integrations/{pi → hosts/pi}/agent-tools.ts +0 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { resourceRoot } from "../../../common/paths.js";
|
|
4
|
+
import { requireThat } from "../../../common/validation.js";
|
|
5
|
+
import { fingerprintExchanges, orderedRawExchanges, rawSessionSpan, rawSessionTitle } from "../history-index.js";
|
|
6
|
+
let cachedPrompt;
|
|
7
|
+
function systemPrompt() {
|
|
8
|
+
cachedPrompt ??= readFileSync(join(resourceRoot, "prompts/history-summary.md"), "utf8");
|
|
9
|
+
return cachedPrompt;
|
|
10
|
+
}
|
|
11
|
+
function formatExchanges(exchanges) {
|
|
12
|
+
return exchanges
|
|
13
|
+
.map(item => `[${item.from} — ${item.to}${item.completed ? "" : ";未完成"}]\n${item.text}`)
|
|
14
|
+
.join("\n\n");
|
|
15
|
+
}
|
|
16
|
+
function isStrictUnchangedPrefix(existing, ordered) {
|
|
17
|
+
const prevIds = existing.source.exchangeIds;
|
|
18
|
+
if (prevIds.length === 0 || prevIds.length >= ordered.length)
|
|
19
|
+
return false;
|
|
20
|
+
for (let i = 0; i < prevIds.length; i++) {
|
|
21
|
+
if (ordered[i].id !== prevIds[i])
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const prefixFingerprint = fingerprintExchanges(ordered.slice(0, prevIds.length));
|
|
25
|
+
return prefixFingerprint === existing.source.fingerprint;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Default per-session task summary dimension.
|
|
29
|
+
* Produces one concise summary per raw session archive, supporting exact deduplication
|
|
30
|
+
* (0 tokens on unchanged sessions) and rolling incremental updates when new turns are appended.
|
|
31
|
+
*/
|
|
32
|
+
export const sessionSummaryDimension = {
|
|
33
|
+
id: "session",
|
|
34
|
+
title: "会话任务摘要",
|
|
35
|
+
description: "按单个会话提炼任务目标、关键决定、结果与未决事项,支持去重跳过与增量滚动更新。",
|
|
36
|
+
plan(raws, existing, options = {}) {
|
|
37
|
+
const force = Boolean(options.force);
|
|
38
|
+
const tasks = [];
|
|
39
|
+
let skipped = 0;
|
|
40
|
+
for (const raw of raws) {
|
|
41
|
+
const ordered = orderedRawExchanges(raw);
|
|
42
|
+
if (!ordered.length)
|
|
43
|
+
continue;
|
|
44
|
+
const exchangeIds = ordered.map(item => item.id);
|
|
45
|
+
const fingerprint = fingerprintExchanges(ordered);
|
|
46
|
+
const prev = existing.get(raw.id);
|
|
47
|
+
if (!force && prev && prev.source.fingerprint === fingerprint) {
|
|
48
|
+
skipped++;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const span = rawSessionSpan(ordered);
|
|
52
|
+
const title = rawSessionTitle(raw);
|
|
53
|
+
const source = { rawIds: [raw.id], exchangeIds, fingerprint };
|
|
54
|
+
if (!force && prev && isStrictUnchangedPrefix(prev, ordered)) {
|
|
55
|
+
tasks.push({
|
|
56
|
+
id: raw.id,
|
|
57
|
+
dimension: this.id,
|
|
58
|
+
mode: "incremental",
|
|
59
|
+
title,
|
|
60
|
+
host: raw.host,
|
|
61
|
+
sessionId: raw.sessionId,
|
|
62
|
+
from: span.from,
|
|
63
|
+
to: span.to,
|
|
64
|
+
source,
|
|
65
|
+
exchanges: ordered,
|
|
66
|
+
existing: prev,
|
|
67
|
+
addedExchanges: ordered.slice(prev.source.exchangeIds.length),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
tasks.push({
|
|
72
|
+
id: raw.id,
|
|
73
|
+
dimension: this.id,
|
|
74
|
+
mode: prev ? "rebuild" : "create",
|
|
75
|
+
title,
|
|
76
|
+
host: raw.host,
|
|
77
|
+
sessionId: raw.sessionId,
|
|
78
|
+
from: span.from,
|
|
79
|
+
to: span.to,
|
|
80
|
+
source,
|
|
81
|
+
exchanges: ordered,
|
|
82
|
+
...(prev ? { existing: prev } : {}),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Process most recently active sessions first.
|
|
87
|
+
tasks.sort((a, b) => b.to.localeCompare(a.to) || a.id.localeCompare(b.id));
|
|
88
|
+
return { tasks, skipped };
|
|
89
|
+
},
|
|
90
|
+
buildRequest(task) {
|
|
91
|
+
const system = systemPrompt();
|
|
92
|
+
const heading = task.title ? [`会话标题:${task.title}`] : [];
|
|
93
|
+
if (task.mode === "incremental" && task.existing && task.addedExchanges?.length) {
|
|
94
|
+
const prompt = [
|
|
95
|
+
...heading,
|
|
96
|
+
`【已有摘要(${task.existing.from} — ${task.existing.to})】\n${task.existing.text}`,
|
|
97
|
+
`【新增对话】\n${formatExchanges(task.addedExchanges)}`,
|
|
98
|
+
"在已有摘要基础上合并新增对话,输出更新后的完整摘要:保留仍有效的事实,用新决定覆盖旧决定,去重并保持简洁。",
|
|
99
|
+
].join("\n\n");
|
|
100
|
+
return { system, prompt, maxTokens: 2048 };
|
|
101
|
+
}
|
|
102
|
+
const prompt = [
|
|
103
|
+
...heading,
|
|
104
|
+
formatExchanges(task.exchanges),
|
|
105
|
+
].join("\n\n");
|
|
106
|
+
return { system, prompt, maxTokens: 2048 };
|
|
107
|
+
},
|
|
108
|
+
finalize(task, output, now) {
|
|
109
|
+
const text = output.trim();
|
|
110
|
+
requireThat(text.length > 0, "历史摘要为空。");
|
|
111
|
+
return {
|
|
112
|
+
id: task.id,
|
|
113
|
+
dimension: this.id,
|
|
114
|
+
...(task.host ? { host: task.host } : {}),
|
|
115
|
+
...(task.sessionId ? { sessionId: task.sessionId } : {}),
|
|
116
|
+
title: task.title,
|
|
117
|
+
text,
|
|
118
|
+
from: task.from,
|
|
119
|
+
to: task.to,
|
|
120
|
+
updatedAt: now,
|
|
121
|
+
source: task.source,
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HistoryLayout, SummaryDimension } from "../../model/history.js";
|
|
2
|
+
/** Register a custom summary dimension (e.g. daily, decisions, topics). */
|
|
3
|
+
export declare function registerSummaryDimension(dimension: SummaryDimension): void;
|
|
4
|
+
export declare function unregisterSummaryDimension(id: string): boolean;
|
|
5
|
+
export declare function getSummaryDimension(id: string): SummaryDimension | undefined;
|
|
6
|
+
export declare function listSummaryDimensions(layout?: HistoryLayout): SummaryDimension[];
|
|
7
|
+
export declare function resolveSummaryDimensions(ids?: readonly string[], layout?: HistoryLayout): SummaryDimension[];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isHistoryIdentifier, requireThat } from "../../common/validation.js";
|
|
2
|
+
import { monthlySummaryDimension } from "./summary-dimensions/monthly.js";
|
|
3
|
+
import { sessionSummaryDimension } from "./summary-dimensions/session.js";
|
|
4
|
+
const registry = new Map([
|
|
5
|
+
[sessionSummaryDimension.id, sessionSummaryDimension],
|
|
6
|
+
[monthlySummaryDimension.id, monthlySummaryDimension],
|
|
7
|
+
]);
|
|
8
|
+
/** Register a custom summary dimension (e.g. daily, decisions, topics). */
|
|
9
|
+
export function registerSummaryDimension(dimension) {
|
|
10
|
+
requireThat(isHistoryIdentifier(dimension.id), "摘要维度 ID 无效:" + dimension.id);
|
|
11
|
+
registry.set(dimension.id, dimension);
|
|
12
|
+
}
|
|
13
|
+
export function unregisterSummaryDimension(id) {
|
|
14
|
+
return registry.delete(id);
|
|
15
|
+
}
|
|
16
|
+
export function getSummaryDimension(id) {
|
|
17
|
+
return registry.get(id);
|
|
18
|
+
}
|
|
19
|
+
export function listSummaryDimensions(layout) {
|
|
20
|
+
const all = [...registry.values()];
|
|
21
|
+
if (layout === "flat")
|
|
22
|
+
return all.filter(dim => !dim.requiresMonthlyLayout);
|
|
23
|
+
return all;
|
|
24
|
+
}
|
|
25
|
+
export function resolveSummaryDimensions(ids, layout = "monthly") {
|
|
26
|
+
if (!ids || ids.length === 0)
|
|
27
|
+
return listSummaryDimensions(layout);
|
|
28
|
+
const unique = [...new Set(ids)];
|
|
29
|
+
return unique.map(id => {
|
|
30
|
+
const found = registry.get(id);
|
|
31
|
+
requireThat(found, `未知的摘要维度:${id}(可用:${[...registry.keys()].join(", ")})。`);
|
|
32
|
+
requireThat(!found.requiresMonthlyLayout || layout === "monthly", `摘要维度 ${id} 仅在年月目录布局(history.layout: "monthly")下启用。`);
|
|
33
|
+
return found;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { HistoryLayout, HistorySummarizer, HistorySummaryReminder, SummaryDimensionStatus, SummaryRunProgress, SummaryRunReport } from "../../model/history.js";
|
|
2
|
+
export declare const defaultSummaryReminderDays = 7;
|
|
3
|
+
export interface InspectSummaryOptions {
|
|
4
|
+
dimensions?: readonly string[];
|
|
5
|
+
thresholdDays?: number;
|
|
6
|
+
now?: Date;
|
|
7
|
+
}
|
|
8
|
+
export type CheckSummaryReminderOptions = InspectSummaryOptions;
|
|
9
|
+
/** Read-only startup probe: reminds when raw history has existed >= thresholdDays and no summary ran within thresholdDays. */
|
|
10
|
+
export declare function checkHistorySummaryReminder(root: string, options?: CheckSummaryReminderOptions): HistorySummaryReminder | undefined;
|
|
11
|
+
export declare function historyStartupNotices(root: string): string[];
|
|
12
|
+
/** Read-only inspection of raw archives vs derived summaries across requested dimensions. */
|
|
13
|
+
export declare function inspectWorkspaceSummaries(root: string, options?: InspectSummaryOptions): {
|
|
14
|
+
layout: HistoryLayout;
|
|
15
|
+
rawCount: number;
|
|
16
|
+
dimensions: SummaryDimensionStatus[];
|
|
17
|
+
warnings: string[];
|
|
18
|
+
reminder?: HistorySummaryReminder;
|
|
19
|
+
};
|
|
20
|
+
export interface RunSummaryOptions {
|
|
21
|
+
root: string;
|
|
22
|
+
summarizer: HistorySummarizer;
|
|
23
|
+
dimensions?: readonly string[];
|
|
24
|
+
force?: boolean;
|
|
25
|
+
concurrency?: number;
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
onProgress?: (progress: SummaryRunProgress) => void;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Trigger-agnostic summary execution engine.
|
|
31
|
+
* Reads raw archives once, plans deduplicated incremental/full tasks per dimension,
|
|
32
|
+
* executes LLM calls with bounded concurrency, and persists each artifact atomically.
|
|
33
|
+
*/
|
|
34
|
+
export declare function runWorkspaceSummaries(options: RunSummaryOptions): Promise<SummaryRunReport>;
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
3
|
+
import { requireThat } from "../../common/validation.js";
|
|
4
|
+
import { summaryConcurrency } from "../../model/workspace-config.js";
|
|
5
|
+
import { workspaceHistoryFiles } from "./workspace-history.js";
|
|
6
|
+
import { rawSessionSpan } from "./history-index.js";
|
|
7
|
+
import { resolveSummaryDimensions } from "./summary-registry.js";
|
|
8
|
+
const lockRetryAttempts = 5;
|
|
9
|
+
const lockRetryDelayMs = 40;
|
|
10
|
+
export const defaultSummaryReminderDays = 7;
|
|
11
|
+
const dayMs = 24 * 60 * 60 * 1000;
|
|
12
|
+
async function withSummaryLockRetry(files, dimension, operation, signal) {
|
|
13
|
+
for (let attempt = 0;; attempt++) {
|
|
14
|
+
signal?.throwIfAborted();
|
|
15
|
+
try {
|
|
16
|
+
return files.controlSummary(dimension, operation);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
const code = error.code;
|
|
20
|
+
if (code === "PBOT_HISTORY_BUSY" && attempt < lockRetryAttempts - 1) {
|
|
21
|
+
await delay(lockRetryDelayMs * (attempt + 1), undefined, { signal });
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function oldestRawTimestamp(raws) {
|
|
29
|
+
let oldest;
|
|
30
|
+
for (const raw of raws) {
|
|
31
|
+
if (!raw.exchanges.length)
|
|
32
|
+
continue;
|
|
33
|
+
const { from } = rawSessionSpan(raw.exchanges);
|
|
34
|
+
if (!from)
|
|
35
|
+
continue;
|
|
36
|
+
const parsed = Date.parse(from);
|
|
37
|
+
if (Number.isNaN(parsed))
|
|
38
|
+
continue;
|
|
39
|
+
if (oldest === undefined || parsed < oldest)
|
|
40
|
+
oldest = parsed;
|
|
41
|
+
}
|
|
42
|
+
return oldest;
|
|
43
|
+
}
|
|
44
|
+
function latestSummaryTimestamp(artifacts) {
|
|
45
|
+
let latest;
|
|
46
|
+
for (const artifact of artifacts) {
|
|
47
|
+
const parsed = Date.parse(artifact.updatedAt);
|
|
48
|
+
if (Number.isNaN(parsed))
|
|
49
|
+
continue;
|
|
50
|
+
if (latest === undefined || parsed > latest)
|
|
51
|
+
latest = parsed;
|
|
52
|
+
}
|
|
53
|
+
return latest;
|
|
54
|
+
}
|
|
55
|
+
function evaluateSummaryReminder(raws, allSummaries, pendingCount, options = {}) {
|
|
56
|
+
if (!raws.length || pendingCount <= 0)
|
|
57
|
+
return undefined;
|
|
58
|
+
const thresholdDays = options.thresholdDays ?? defaultSummaryReminderDays;
|
|
59
|
+
requireThat(Number.isFinite(thresholdDays) && thresholdDays > 0, "历史摘要提醒天数必须大于 0。");
|
|
60
|
+
const thresholdMs = thresholdDays * dayMs;
|
|
61
|
+
const nowMs = (options.now ?? new Date()).getTime();
|
|
62
|
+
const oldestRawMs = oldestRawTimestamp(raws);
|
|
63
|
+
if (oldestRawMs === undefined || nowMs - oldestRawMs < thresholdMs)
|
|
64
|
+
return undefined;
|
|
65
|
+
const latestSummaryMs = latestSummaryTimestamp(allSummaries);
|
|
66
|
+
if (latestSummaryMs !== undefined && nowMs - latestSummaryMs < thresholdMs)
|
|
67
|
+
return undefined;
|
|
68
|
+
const rawAgeDays = Math.floor((nowMs - oldestRawMs) / dayMs);
|
|
69
|
+
const daysSinceLastSummary = latestSummaryMs === undefined ? undefined : Math.floor((nowMs - latestSummaryMs) / dayMs);
|
|
70
|
+
const message = daysSinceLastSummary === undefined
|
|
71
|
+
? `历史原文已累计 ${rawAgeDays} 天(待摘要 ${pendingCount} 项),尚未触发过摘要整理;可在终端运行 pbot history summary 生成摘要(Pi/dsh 可用 /pbot history summary)。`
|
|
72
|
+
: `历史原文已累计 ${rawAgeDays} 天,且已 ${daysSinceLastSummary} 天未触发摘要整理(待摘要 ${pendingCount} 项);可在终端运行 pbot history summary 更新摘要(Pi/dsh 可用 /pbot history summary)。`;
|
|
73
|
+
return {
|
|
74
|
+
rawCount: raws.length,
|
|
75
|
+
pendingCount,
|
|
76
|
+
oldestRawAt: new Date(oldestRawMs).toISOString(),
|
|
77
|
+
...(latestSummaryMs !== undefined ? { latestSummaryAt: new Date(latestSummaryMs).toISOString() } : {}),
|
|
78
|
+
rawAgeDays,
|
|
79
|
+
...(daysSinceLastSummary !== undefined ? { daysSinceLastSummary } : {}),
|
|
80
|
+
thresholdDays,
|
|
81
|
+
message,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** Read-only startup probe: reminds when raw history has existed >= thresholdDays and no summary ran within thresholdDays. */
|
|
85
|
+
export function checkHistorySummaryReminder(root, options = {}) {
|
|
86
|
+
return summaryReminder(workspaceHistoryFiles(root), options);
|
|
87
|
+
}
|
|
88
|
+
export function historyStartupNotices(root) {
|
|
89
|
+
const notices = [];
|
|
90
|
+
try {
|
|
91
|
+
const files = workspaceHistoryFiles(root);
|
|
92
|
+
const migration = files.migrationNotice();
|
|
93
|
+
if (migration)
|
|
94
|
+
notices.push(migration);
|
|
95
|
+
const reminder = summaryReminder(files, {});
|
|
96
|
+
if (reminder)
|
|
97
|
+
notices.push(reminder.message);
|
|
98
|
+
}
|
|
99
|
+
catch { /* History diagnostics are best effort during host startup. */ }
|
|
100
|
+
return notices;
|
|
101
|
+
}
|
|
102
|
+
function summaryReminder(files, options) {
|
|
103
|
+
const raws = files.listRaw();
|
|
104
|
+
if (!raws.length)
|
|
105
|
+
return undefined;
|
|
106
|
+
const thresholdDays = options.thresholdDays ?? defaultSummaryReminderDays;
|
|
107
|
+
requireThat(Number.isFinite(thresholdDays) && thresholdDays > 0, "历史摘要提醒天数必须大于 0。");
|
|
108
|
+
const nowMs = (options.now ?? new Date()).getTime();
|
|
109
|
+
const oldestRawMs = oldestRawTimestamp(raws);
|
|
110
|
+
if (oldestRawMs === undefined || nowMs - oldestRawMs < thresholdDays * dayMs)
|
|
111
|
+
return undefined;
|
|
112
|
+
const { totalPending, allSummaries } = inspectDimensions(files, raws, options, []);
|
|
113
|
+
return evaluateSummaryReminder(raws, allSummaries, totalPending, options);
|
|
114
|
+
}
|
|
115
|
+
function inspectDimensions(files, raws, options, warnings) {
|
|
116
|
+
const dimensions = resolveSummaryDimensions(options.dimensions, files.layout);
|
|
117
|
+
const statuses = [];
|
|
118
|
+
const seenDimensions = new Set();
|
|
119
|
+
const summariesByDimension = new Map();
|
|
120
|
+
const allSummaries = [];
|
|
121
|
+
let totalPending = 0;
|
|
122
|
+
const loadDimension = (dimId) => {
|
|
123
|
+
const cached = summariesByDimension.get(dimId);
|
|
124
|
+
if (cached)
|
|
125
|
+
return cached;
|
|
126
|
+
const list = files.listSummaries(dimId);
|
|
127
|
+
warnings.push(...files.warnings);
|
|
128
|
+
const map = new Map(list.map(item => [item.id, item]));
|
|
129
|
+
summariesByDimension.set(dimId, map);
|
|
130
|
+
return map;
|
|
131
|
+
};
|
|
132
|
+
for (const dimension of dimensions) {
|
|
133
|
+
seenDimensions.add(dimension.id);
|
|
134
|
+
if (dimension.id !== "session")
|
|
135
|
+
loadDimension("session");
|
|
136
|
+
const existing = loadDimension(dimension.id);
|
|
137
|
+
allSummaries.push(...existing.values());
|
|
138
|
+
const plan = dimension.plan(raws, existing, { force: false, summariesByDimension });
|
|
139
|
+
totalPending += plan.tasks.length;
|
|
140
|
+
let pendingCreate = 0;
|
|
141
|
+
let pendingIncremental = 0;
|
|
142
|
+
let pendingRebuild = 0;
|
|
143
|
+
for (const task of plan.tasks) {
|
|
144
|
+
if (task.mode === "create")
|
|
145
|
+
pendingCreate++;
|
|
146
|
+
else if (task.mode === "incremental")
|
|
147
|
+
pendingIncremental++;
|
|
148
|
+
else
|
|
149
|
+
pendingRebuild++;
|
|
150
|
+
}
|
|
151
|
+
statuses.push({
|
|
152
|
+
dimension: dimension.id,
|
|
153
|
+
title: dimension.title,
|
|
154
|
+
description: dimension.description,
|
|
155
|
+
total: plan.skipped + plan.tasks.length,
|
|
156
|
+
ready: plan.skipped,
|
|
157
|
+
pendingCreate,
|
|
158
|
+
pendingIncremental,
|
|
159
|
+
pendingRebuild,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
for (const dim of files.listDimensions()) {
|
|
163
|
+
if (seenDimensions.has(dim))
|
|
164
|
+
continue;
|
|
165
|
+
allSummaries.push(...loadDimension(dim).values());
|
|
166
|
+
}
|
|
167
|
+
return { statuses, totalPending, allSummaries };
|
|
168
|
+
}
|
|
169
|
+
/** Read-only inspection of raw archives vs derived summaries across requested dimensions. */
|
|
170
|
+
export function inspectWorkspaceSummaries(root, options = {}) {
|
|
171
|
+
const files = workspaceHistoryFiles(root);
|
|
172
|
+
const raws = files.listRaw();
|
|
173
|
+
const warnings = [...files.warnings];
|
|
174
|
+
const flatNotice = files.migrationNotice();
|
|
175
|
+
if (flatNotice)
|
|
176
|
+
warnings.push(flatNotice);
|
|
177
|
+
const { statuses, totalPending, allSummaries } = inspectDimensions(files, raws, options, warnings);
|
|
178
|
+
const reminder = evaluateSummaryReminder(raws, allSummaries, totalPending, options);
|
|
179
|
+
return {
|
|
180
|
+
layout: files.layout,
|
|
181
|
+
rawCount: raws.length,
|
|
182
|
+
dimensions: statuses,
|
|
183
|
+
warnings: [...new Set(warnings)],
|
|
184
|
+
...(reminder ? { reminder } : {}),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Trigger-agnostic summary execution engine.
|
|
189
|
+
* Reads raw archives once, plans deduplicated incremental/full tasks per dimension,
|
|
190
|
+
* executes LLM calls with bounded concurrency, and persists each artifact atomically.
|
|
191
|
+
*/
|
|
192
|
+
export async function runWorkspaceSummaries(options) {
|
|
193
|
+
const startedAt = Date.now();
|
|
194
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
195
|
+
signal.throwIfAborted();
|
|
196
|
+
const concurrency = Math.max(1, Math.min(summaryConcurrency.max, Math.floor(options.concurrency ?? summaryConcurrency.default)));
|
|
197
|
+
const files = workspaceHistoryFiles(options.root);
|
|
198
|
+
const dimensions = resolveSummaryDimensions(options.dimensions, files.layout);
|
|
199
|
+
const warnings = [];
|
|
200
|
+
const loadSummaries = (id) => {
|
|
201
|
+
const items = files.listSummaries(id);
|
|
202
|
+
warnings.push(...files.warnings);
|
|
203
|
+
return new Map(items.map(item => [item.id, item]));
|
|
204
|
+
};
|
|
205
|
+
// Capture each publication baseline before reading the input it will summarize.
|
|
206
|
+
const plannedDimensions = dimensions.map(dimension => ({ dimension, existing: loadSummaries(dimension.id) }));
|
|
207
|
+
const raws = files.listRaw();
|
|
208
|
+
warnings.push(...files.warnings);
|
|
209
|
+
const flatNotice = files.migrationNotice();
|
|
210
|
+
if (flatNotice)
|
|
211
|
+
warnings.push(flatNotice);
|
|
212
|
+
const summariesByDimension = new Map();
|
|
213
|
+
const reports = [];
|
|
214
|
+
for (const { dimension, existing } of plannedDimensions) {
|
|
215
|
+
signal.throwIfAborted();
|
|
216
|
+
if (dimension.id !== "session")
|
|
217
|
+
summariesByDimension.set("session", loadSummaries("session"));
|
|
218
|
+
summariesByDimension.set(dimension.id, existing);
|
|
219
|
+
const plan = dimension.plan(raws, existing, { force: Boolean(options.force), summariesByDimension });
|
|
220
|
+
const report = {
|
|
221
|
+
dimension: dimension.id,
|
|
222
|
+
scanned: dimension.id === "monthly" ? (summariesByDimension.get("session")?.size ?? 0) : raws.length,
|
|
223
|
+
skipped: plan.skipped,
|
|
224
|
+
created: 0,
|
|
225
|
+
incremental: 0,
|
|
226
|
+
rebuilt: 0,
|
|
227
|
+
failed: [],
|
|
228
|
+
};
|
|
229
|
+
if (plan.tasks.length > 0) {
|
|
230
|
+
let nextIndex = 0;
|
|
231
|
+
let completed = 0;
|
|
232
|
+
const total = plan.tasks.length;
|
|
233
|
+
const worker = async () => {
|
|
234
|
+
for (;;) {
|
|
235
|
+
signal.throwIfAborted();
|
|
236
|
+
const index = nextIndex++;
|
|
237
|
+
if (index >= total)
|
|
238
|
+
return;
|
|
239
|
+
const task = plan.tasks[index];
|
|
240
|
+
try {
|
|
241
|
+
const request = dimension.buildRequest(task);
|
|
242
|
+
const output = await options.summarizer(request, signal);
|
|
243
|
+
signal.throwIfAborted();
|
|
244
|
+
const artifact = dimension.finalize(task, output, new Date().toISOString());
|
|
245
|
+
const published = await withSummaryLockRetry(files, dimension.id, () => {
|
|
246
|
+
signal.throwIfAborted();
|
|
247
|
+
const current = files.readSummary(dimension.id, artifact.id);
|
|
248
|
+
if (isDeepStrictEqual(current, existing.get(artifact.id))) {
|
|
249
|
+
files.saveSummary(artifact);
|
|
250
|
+
return artifact;
|
|
251
|
+
}
|
|
252
|
+
if (current)
|
|
253
|
+
existing.set(artifact.id, current);
|
|
254
|
+
else
|
|
255
|
+
existing.delete(artifact.id);
|
|
256
|
+
requireThat(current && isDeepStrictEqual(current.source, artifact.source), "摘要在生成期间已变更,请重新运行摘要。");
|
|
257
|
+
return current;
|
|
258
|
+
}, signal);
|
|
259
|
+
existing.set(artifact.id, published);
|
|
260
|
+
if (published !== artifact)
|
|
261
|
+
report.skipped++;
|
|
262
|
+
else if (task.mode === "create")
|
|
263
|
+
report.created++;
|
|
264
|
+
else if (task.mode === "incremental")
|
|
265
|
+
report.incremental++;
|
|
266
|
+
else
|
|
267
|
+
report.rebuilt++;
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
if (signal.aborted)
|
|
271
|
+
throw error;
|
|
272
|
+
report.failed.push({ id: task.id, error: error instanceof Error ? error.message : String(error) });
|
|
273
|
+
}
|
|
274
|
+
finally {
|
|
275
|
+
completed++;
|
|
276
|
+
if (!signal.aborted) {
|
|
277
|
+
options.onProgress?.({
|
|
278
|
+
dimension: dimension.id,
|
|
279
|
+
completed,
|
|
280
|
+
total,
|
|
281
|
+
currentId: task.id,
|
|
282
|
+
mode: task.mode,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
const workerCount = Math.min(concurrency, total);
|
|
289
|
+
await Promise.all(Array.from({ length: workerCount }, () => worker()));
|
|
290
|
+
}
|
|
291
|
+
reports.push(report);
|
|
292
|
+
}
|
|
293
|
+
requireThat(!signal.aborted, "历史摘要已取消。");
|
|
294
|
+
return {
|
|
295
|
+
dimensions: reports,
|
|
296
|
+
durationMs: Date.now() - startedAt,
|
|
297
|
+
warnings: [...new Set(warnings)],
|
|
298
|
+
};
|
|
299
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { HistoryFiles } from "../../storage/history-files.js";
|
|
3
|
+
import { readWorkspaceHistoryLayoutSync } from "../workspace/workspace-config.js";
|
|
4
|
+
export function workspaceHistoryFiles(root, host) {
|
|
5
|
+
return new HistoryFiles(join(root, ".pbot/history"), host, readWorkspaceHistoryLayoutSync(root));
|
|
6
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Each host owns its file, including when two hosts activate the same canonical workspace concurrently. */
|
|
2
|
+
export declare function bindWorkspacePlugin(root: string, host: string, binding?: string): void;
|
|
3
|
+
export declare function workspacePluginReleases(root: string): Record<string, string>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdirSync, readdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
5
|
+
import { object } from "../../common/json.js";
|
|
6
|
+
import { resourceRoot } from "../../common/paths.js";
|
|
7
|
+
import { requireThat } from "../../common/validation.js";
|
|
8
|
+
import { releaseLine } from "../../common/version.js";
|
|
9
|
+
import { readJsonFile, writeJsonFile } from "../../storage/atomic-json.js";
|
|
10
|
+
function bindingDirectory(root) {
|
|
11
|
+
const key = createHash("sha256").update(root).digest("hex");
|
|
12
|
+
return join(homedir(), ".pbot", "workspaces", key);
|
|
13
|
+
}
|
|
14
|
+
// Full plugins own a local manifest. Thin clients can supply the release stamped into their cached hooks.
|
|
15
|
+
function pluginBinding(value) {
|
|
16
|
+
requireThat(typeof value === "string", "无效的插件安装记录。");
|
|
17
|
+
if (!isAbsolute(value))
|
|
18
|
+
releaseLine(value);
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
function permissionDenied(error) {
|
|
22
|
+
return ["EACCES", "EPERM", "EROFS"].includes(error.code ?? "");
|
|
23
|
+
}
|
|
24
|
+
/** Each host owns its file, including when two hosts activate the same canonical workspace concurrently. */
|
|
25
|
+
export function bindWorkspacePlugin(root, host, binding = resolve(resourceRoot, "../package.json")) {
|
|
26
|
+
const directory = bindingDirectory(root);
|
|
27
|
+
const file = encodeURIComponent(host) + ".json";
|
|
28
|
+
try {
|
|
29
|
+
if (readJsonFile(directory, file, pluginBinding) === binding)
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (permissionDenied(error))
|
|
34
|
+
return;
|
|
35
|
+
if (error.code !== "ENOENT")
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
40
|
+
writeJsonFile(directory, file, binding, pluginBinding);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (!permissionDenied(error))
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function workspacePluginReleases(root) {
|
|
48
|
+
const directory = bindingDirectory(root);
|
|
49
|
+
let files;
|
|
50
|
+
try {
|
|
51
|
+
files = readdirSync(directory);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (error.code === "ENOENT" || permissionDenied(error))
|
|
55
|
+
return {};
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
const releases = Object.create(null);
|
|
59
|
+
for (const file of files.filter(name => name.endsWith(".json"))) {
|
|
60
|
+
const host = decodeURIComponent(file.slice(0, -5));
|
|
61
|
+
try {
|
|
62
|
+
const binding = readJsonFile(directory, file, pluginBinding);
|
|
63
|
+
if (!isAbsolute(binding)) {
|
|
64
|
+
releases[host] = binding;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const manifest = JSON.parse(readFileSync(binding, "utf8"));
|
|
68
|
+
requireThat(object(manifest) && typeof manifest.version === "string", "无效的插件安装清单:" + binding);
|
|
69
|
+
releaseLine(manifest.version);
|
|
70
|
+
releases[host] = manifest.version;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (error.code !== "ENOENT" && !permissionDenied(error))
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return releases;
|
|
78
|
+
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration, WorkspaceFeatures } from "../../model/workspace-config.js";
|
|
1
|
+
import type { HistoryLayout, ResolvedWorkspaceFeatures, ResolvedWorkspaceHistoryConfig, ResolvedWorkspaceSummaryConfig, WorkspaceConfiguration, WorkspaceFeatures, WorkspaceHistoryConfig, WorkspaceSummaryConfig } from "../../model/workspace-config.js";
|
|
2
2
|
export declare function workspaceFeatures(configuration?: Pick<WorkspaceConfiguration, "features"> | WorkspaceFeatures): ResolvedWorkspaceFeatures;
|
|
3
|
+
export declare function workspaceSummaryConfig(configuration?: Pick<WorkspaceConfiguration, "summary"> | WorkspaceSummaryConfig): ResolvedWorkspaceSummaryConfig;
|
|
4
|
+
export declare function workspaceHistoryConfig(configuration?: Pick<WorkspaceConfiguration, "history"> | WorkspaceHistoryConfig): ResolvedWorkspaceHistoryConfig;
|
|
3
5
|
export declare function workspaceConfigPath(root: string): string;
|
|
6
|
+
/** Synchronous read of history.layout for storage and query callers; defaults to "monthly". */
|
|
7
|
+
export declare function readWorkspaceHistoryLayoutSync(root: string): HistoryLayout;
|
|
4
8
|
/** Read only this workspace's configuration; parent directories never grant activation. */
|
|
5
9
|
export declare function readWorkspaceConfig(root: string): Promise<WorkspaceConfiguration>;
|
|
6
10
|
/** Explicit init opts in this workspace while preserving its other configuration fields. */
|