personal-bot 0.3.2 → 0.3.4
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 +1 -1
- package/bin/pbot.mjs +22 -2
- package/docs/README.md +2 -0
- package/docs/architecture/design.md +16 -16
- package/docs/architecture/extensibility.md +29 -2
- package/docs/architecture/model-context.md +3 -2
- package/docs/architecture/principles.md +2 -2
- package/docs/guides/capabilities.md +1 -1
- package/docs/guides/cross-harness-workers.md +3 -1
- package/docs/guides/history.md +30 -7
- package/docs/guides/workspace-configuration.md +20 -3
- package/docs/hosts/antigravity.md +1 -1
- package/docs/hosts/claude-code.md +1 -1
- package/docs/hosts/codex-qoder.md +63 -0
- package/docs/maintainers/architecture-governance.md +78 -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/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/antigravity-plugin/lib/extension/acp/member.d.ts +18 -0
- package/lib/antigravity-plugin/lib/extension/acp/member.js +44 -0
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +71 -45
- 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/antigravity-plugin/lib/extension/hosts/dsh/acp-member.d.ts +4 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/acp-member.js +58 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.d.ts +5 -0
- package/lib/antigravity-plugin/lib/extension/hosts/dsh/files.js +67 -0
- 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 +3 -1
- package/lib/antigravity-plugin/lib/extension/hosts/plugin-runtime.js +37 -22
- 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 +2577 -2255
- package/lib/antigravity-plugin/lib/extension/workspace-cli.js +20171 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +1 -1
- package/lib/antigravity-plugin/lib/integrations/hosts/claude/adapter.js +7 -59
- 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/antigravity-plugin/lib/integrations/hosts/dsh/mcp.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/mcp.js +28 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.d.ts +36 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/messages.js +11 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.d.ts +6 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/resources.js +47 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/root-agents.js +3 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.d.ts +8 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/dsh/skills.js +31 -0
- 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/plugin-registry.d.ts +1 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/plugin-registry.js +8 -1
- 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 +10 -0
- package/lib/antigravity-plugin/lib/model/history.js +4 -1
- package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +5 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +8 -12
- 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 +2 -2
- package/lib/antigravity-plugin/lib/services/history/history-capture.js +34 -22
- package/lib/antigravity-plugin/lib/services/history/summary-registry.js +2 -3
- package/lib/antigravity-plugin/lib/services/history/summary-runner.d.ts +2 -5
- package/lib/antigravity-plugin/lib/services/history/summary-runner.js +72 -74
- 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 +15 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +126 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +9 -8
- 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/history-files.d.ts +2 -1
- package/lib/antigravity-plugin/lib/storage/history-files.js +21 -15
- package/lib/antigravity-plugin/lib/storage/history-format.d.ts +2 -3
- package/lib/antigravity-plugin/lib/storage/history-format.js +5 -7
- 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/client.js +22 -50
- 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 +2 -2
- package/lib/extension/acp/member.d.ts +1 -1
- package/lib/extension/acp-worker.js +71 -45
- 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.js +4 -18
- package/lib/extension/hosts/dsh/command.d.ts +1 -2
- package/lib/extension/hosts/dsh/command.js +5 -49
- package/lib/extension/hosts/dsh/workspace.js +13 -44
- 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 +3 -1
- package/lib/extension/hosts/plugin-runtime.js +37 -22
- 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 +6 -8
- package/lib/extension/mcp/bridge.js +66 -84
- package/lib/extension/mcp/tool-contract.d.ts +735 -0
- package/lib/extension/mcp/tool-contract.js +441 -0
- package/lib/extension/mcp/workers.d.ts +29 -742
- package/lib/extension/mcp/workers.js +75 -525
- package/lib/extension/mcp.js +2577 -2255
- package/lib/extension/setup/cli.js +15 -0
- package/lib/extension/setup/upgrade.js +153 -0
- package/lib/extension/workspace-cli.js +20171 -0
- package/lib/integrations/acp/agents.d.ts +2 -3
- package/lib/integrations/acp/harnesses/dsh.js +1 -1
- package/lib/integrations/acp/harnesses/presets.js +8 -0
- package/lib/integrations/acp/history-summary.js +2 -1
- package/lib/integrations/acp/launch.d.ts +2 -2
- package/lib/integrations/agent-resources.js +1 -1
- package/lib/integrations/hosts/claude/adapter.js +7 -59
- package/lib/integrations/hosts/codex/adapter.d.ts +2 -0
- package/lib/integrations/hosts/codex/adapter.js +14 -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/plugin-registry.d.ts +1 -0
- package/lib/integrations/hosts/plugin-registry.js +8 -1
- 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/cli-update.js +146 -0
- package/lib/integrations/installation/upgraders/antigravity.js +67 -0
- package/lib/integrations/installation/upgraders/claude.js +123 -0
- package/lib/integrations/installation/upgraders/codex.js +73 -0
- package/lib/integrations/installation/upgraders/dsh.js +62 -0
- package/lib/integrations/installation/upgraders/pi.js +90 -0
- package/lib/integrations/installation/upgraders/qoder.js +67 -0
- package/lib/integrations/installation/upgraders/registry.js +40 -0
- 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 +10 -0
- package/lib/model/history.js +4 -1
- package/lib/model/installation.js +1 -0
- package/lib/model/plugin-host.d.ts +5 -0
- package/lib/model/workspace-config.d.ts +8 -12
- package/lib/model/workspace-config.js +2 -1
- package/lib/plugin.d.ts +2 -1
- package/lib/plugin.js +2 -2
- 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-service.d.ts +15 -45
- package/lib/services/agents/agent-service.js +22 -3
- package/lib/services/history/history-capture.js +34 -22
- package/lib/services/history/history-migrate.js +26 -60
- package/lib/services/history/history-query.js +38 -57
- package/lib/services/history/summary-command.d.ts +1 -1
- package/lib/services/history/summary-command.js +8 -7
- package/lib/services/history/summary-registry.js +2 -3
- package/lib/services/history/summary-runner.d.ts +2 -5
- package/lib/services/history/summary-runner.js +72 -74
- package/lib/services/history/workspace-history.d.ts +3 -0
- package/lib/services/history/workspace-history.js +6 -0
- package/lib/services/installation/setup-service.js +4 -1
- package/lib/services/installation/upgrade-service.js +95 -0
- package/lib/services/workspace/plugin-releases.d.ts +15 -0
- package/lib/services/workspace/plugin-releases.js +126 -0
- package/lib/services/workspace/workspace-config.js +9 -8
- 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 +2 -1
- package/lib/storage/history-files.js +21 -15
- package/lib/storage/history-format.d.ts +2 -3
- package/lib/storage/history-format.js +5 -7
- package/lib/tools/history/contract.d.ts +3 -11
- package/lib/tools/history/contract.js +8 -7
- package/lib/ui/dsh/elements.d.ts +2 -5
- package/lib/ui/dsh/elements.js +3 -16
- package/lib/ui/dsh/management.js +9 -9
- 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 +1 -0
- package/resources/prompts/plugin-coordinator.md +1 -0
- package/scripts/README.md +3 -2
- package/src/common/validation.ts +10 -0
- package/src/dsh.ts +2 -2
- package/src/extension/history/command.ts +68 -0
- package/src/extension/hosts/dsh/acp-entry.ts +21 -0
- package/src/extension/hosts/dsh/acp-member.ts +4 -15
- package/src/extension/hosts/dsh/command.ts +6 -46
- package/src/extension/hosts/dsh/workspace.ts +12 -38
- package/src/extension/hosts/pi/acp-member.ts +4 -10
- package/src/extension/hosts/pi/command.ts +14 -63
- package/src/extension/hosts/pi/events.ts +2 -8
- package/src/extension/hosts/pi/lifecycle.ts +3 -2
- package/src/extension/hosts/plugin-runtime.ts +39 -19
- package/src/extension/hosts/workspace-mcp.ts +25 -0
- package/src/extension/mcp/bridge.ts +80 -80
- package/src/extension/mcp/tool-contract.ts +462 -0
- package/src/extension/mcp/workers.ts +81 -551
- package/src/extension/setup/cli.ts +11 -1
- package/src/extension/setup/upgrade.ts +158 -0
- package/src/extension/setup/workspace-cli.ts +167 -0
- package/src/integrations/acp/agents.ts +2 -3
- 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 +2 -1
- package/src/integrations/agent-resources.ts +1 -1
- package/src/integrations/hosts/claude/adapter.ts +7 -53
- package/src/integrations/hosts/codex/adapter.ts +16 -0
- package/src/integrations/hosts/plugin-registry.ts +9 -1
- 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 +144 -0
- package/src/integrations/installation/pi-bridge.ts +1 -1
- package/src/integrations/installation/pi-setup.ts +1 -1
- package/src/integrations/installation/processes.ts +1 -1
- package/src/integrations/installation/upgraders/antigravity.ts +68 -0
- package/src/integrations/installation/upgraders/claude.ts +123 -0
- package/src/integrations/installation/upgraders/codex.ts +73 -0
- package/src/integrations/installation/upgraders/dsh.ts +63 -0
- package/src/integrations/installation/upgraders/pi.ts +87 -0
- package/src/integrations/installation/upgraders/qoder.ts +68 -0
- package/src/integrations/installation/upgraders/registry.ts +48 -0
- package/src/model/acp.ts +11 -3
- package/src/model/agent.ts +20 -4
- package/src/model/history.ts +5 -0
- package/src/model/installation.ts +86 -0
- package/src/model/plugin-host.ts +5 -1
- package/src/model/workspace-config.ts +6 -12
- package/src/pbot.ts +13 -32
- package/src/plugin.ts +3 -3
- package/src/services/agents/agent-service.ts +29 -17
- package/src/services/history/history-capture.ts +30 -22
- package/src/services/history/history-migrate.ts +23 -50
- package/src/services/history/history-query.ts +34 -48
- package/src/services/history/summary-command.ts +9 -8
- package/src/services/history/summary-registry.ts +2 -3
- package/src/services/history/summary-runner.ts +72 -81
- package/src/services/history/workspace-history.ts +8 -0
- package/src/services/installation/setup-service.ts +9 -43
- package/src/services/installation/upgrade-service.ts +127 -0
- package/src/services/workspace/plugin-releases.ts +121 -0
- package/src/services/workspace/workspace-config.ts +9 -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 +22 -15
- package/src/storage/history-format.ts +6 -8
- package/src/tools/history/contract.ts +9 -9
- package/src/tools/history/pi-tool.ts +6 -4
- package/src/ui/dsh/elements.ts +5 -12
- package/src/ui/dsh/management.ts +10 -10
- package/src/ui/dsh/styles.ts +5 -33
- package/lib/antigravity-plugin/lib/services/history/history-migrate.d.ts +0 -12
- package/lib/antigravity-plugin/lib/services/history/history-migrate.js +0 -88
- package/lib/ui/presentation.d.ts +0 -3
- package/lib/ui/presentation.js +0 -12
- package/src/tools/access.ts +0 -7
- package/src/tools/register.ts +0 -21
- package/src/ui/presentation.ts +0 -12
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
1
|
import { requireThat } from "../../common/validation.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { historyPageLimits } from "../../model/history.js";
|
|
3
|
+
import { historyBucketFromTimestamp, rawHistoryBucket, unknownHistoryBucket, } from "../../storage/history-files.js";
|
|
4
|
+
import { workspaceHistoryFiles } from "./workspace-history.js";
|
|
5
5
|
import { orderedRawExchanges, rawSessionSpan, rawSessionTitle } from "./history-index.js";
|
|
6
6
|
const summaryIdPrefix = "summary:";
|
|
7
7
|
const page = (values, offset, limit) => ({
|
|
@@ -93,39 +93,38 @@ function inTimeRange(from, to, after, before) {
|
|
|
93
93
|
* Uses ripgrep (with automatic Node fallback) to pre-filter candidate JSON files before parsing.
|
|
94
94
|
*/
|
|
95
95
|
export function searchWorkspaceHistory(root, query = {}) {
|
|
96
|
-
const { host, sessionId, dimension, from, to, offset = 0, limit =
|
|
96
|
+
const { host, sessionId, dimension, from, to, offset = 0, limit = historyPageLimits.search.default } = query;
|
|
97
97
|
const needle = (query.query ?? "").trim().toLowerCase();
|
|
98
98
|
const after = from === undefined ? -Infinity : Date.parse(from);
|
|
99
99
|
const before = to === undefined ? Infinity : Date.parse(to);
|
|
100
100
|
requireThat(!Number.isNaN(after) && !Number.isNaN(before) && after <= before, "时间范围无效,请使用 ISO 日期或时间。");
|
|
101
|
-
const
|
|
102
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", layout);
|
|
101
|
+
const files = workspaceHistoryFiles(root);
|
|
103
102
|
const warnings = [];
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
warnings.push(flatNotice);
|
|
108
|
-
}
|
|
103
|
+
const flatNotice = files.migrationNotice();
|
|
104
|
+
if (flatNotice)
|
|
105
|
+
warnings.push(flatNotice);
|
|
109
106
|
const matches = [];
|
|
107
|
+
function collectSummaries(artifacts) {
|
|
108
|
+
warnings.push(...files.warnings);
|
|
109
|
+
for (const artifact of artifacts) {
|
|
110
|
+
if (!inTimeRange(artifact.from, artifact.to, after, before))
|
|
111
|
+
continue;
|
|
112
|
+
if (needle && !`${artifact.title}\n${artifact.text}`.toLowerCase().includes(needle))
|
|
113
|
+
continue;
|
|
114
|
+
const brief = summaryBrief(artifact);
|
|
115
|
+
if (host && brief.host !== host || sessionId && brief.sessionId !== sessionId)
|
|
116
|
+
continue;
|
|
117
|
+
matches.push({
|
|
118
|
+
...brief,
|
|
119
|
+
parents: artifact.dimension === "monthly" ? [] : artifact.source.rawIds,
|
|
120
|
+
snippet: sliceSnippet(artifact.text, needle),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
110
124
|
if (!needle) {
|
|
111
125
|
// Empty query: list sessions (default / dimension="raw") or list summaries of a specific dimension.
|
|
112
126
|
if (dimension && dimension !== "raw") {
|
|
113
|
-
|
|
114
|
-
warnings.push(...files.warnings);
|
|
115
|
-
for (const artifact of summaries) {
|
|
116
|
-
if (host && artifact.host !== host)
|
|
117
|
-
continue;
|
|
118
|
-
if (sessionId && artifact.sessionId !== sessionId)
|
|
119
|
-
continue;
|
|
120
|
-
if (!inTimeRange(artifact.from, artifact.to, after, before))
|
|
121
|
-
continue;
|
|
122
|
-
const brief = summaryBrief(artifact);
|
|
123
|
-
matches.push({
|
|
124
|
-
...brief,
|
|
125
|
-
parents: artifact.dimension === "monthly" ? [] : artifact.source.rawIds,
|
|
126
|
-
snippet: sliceSnippet(artifact.text, ""),
|
|
127
|
-
});
|
|
128
|
-
}
|
|
127
|
+
collectSummaries(files.listSummaries(dimension));
|
|
129
128
|
}
|
|
130
129
|
else {
|
|
131
130
|
const raws = files.listRaw(host);
|
|
@@ -179,24 +178,7 @@ export function searchWorkspaceHistory(root, query = {}) {
|
|
|
179
178
|
}
|
|
180
179
|
}
|
|
181
180
|
for (const dim of summaryDimensions) {
|
|
182
|
-
|
|
183
|
-
warnings.push(...files.warnings);
|
|
184
|
-
for (const artifact of candidateSummaries) {
|
|
185
|
-
if (host && artifact.host !== host)
|
|
186
|
-
continue;
|
|
187
|
-
if (sessionId && artifact.sessionId !== sessionId)
|
|
188
|
-
continue;
|
|
189
|
-
const searchable = `${artifact.title}\n${artifact.text}`;
|
|
190
|
-
if (!searchable.toLowerCase().includes(needle))
|
|
191
|
-
continue;
|
|
192
|
-
if (!inTimeRange(artifact.from, artifact.to, after, before))
|
|
193
|
-
continue;
|
|
194
|
-
matches.push({
|
|
195
|
-
...summaryBrief(artifact),
|
|
196
|
-
parents: artifact.dimension === "monthly" ? [] : artifact.source.rawIds,
|
|
197
|
-
snippet: sliceSnippet(artifact.text, needle),
|
|
198
|
-
});
|
|
199
|
-
}
|
|
181
|
+
collectSummaries(files.searchCandidateSummaries(dim, needle));
|
|
200
182
|
}
|
|
201
183
|
}
|
|
202
184
|
matches.sort((a, b) => b.to.localeCompare(a.to) || a.id.localeCompare(b.id));
|
|
@@ -231,20 +213,19 @@ function findMonthlyParent(files, bucket, rawId) {
|
|
|
231
213
|
return summaryBrief(monthly);
|
|
232
214
|
}
|
|
233
215
|
/** O(1) read of a session root, summary artifact, or individual raw exchange. */
|
|
234
|
-
export function readWorkspaceHistory(root, id, offset = 0, limit =
|
|
235
|
-
const
|
|
236
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", layout);
|
|
216
|
+
export function readWorkspaceHistory(root, id, offset = 0, limit = historyPageLimits.read.default, childrenOffset = 0, host) {
|
|
217
|
+
const files = workspaceHistoryFiles(root);
|
|
237
218
|
const baseWarnings = [];
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
baseWarnings.push(flatNotice);
|
|
242
|
-
}
|
|
219
|
+
const flatNotice = files.migrationNotice();
|
|
220
|
+
if (flatNotice)
|
|
221
|
+
baseWarnings.push(flatNotice);
|
|
243
222
|
// 1. Summary artifact: summary:<dimension>:<artifactId>
|
|
244
223
|
const parsedSummary = parseSummaryNodeId(id);
|
|
245
224
|
if (parsedSummary) {
|
|
246
225
|
const artifact = files.readSummary(parsedSummary.dimension, parsedSummary.artifactId);
|
|
247
|
-
requireThat(artifact
|
|
226
|
+
requireThat(artifact, "历史节点不存在,请重新搜索。");
|
|
227
|
+
const brief = summaryBrief(artifact);
|
|
228
|
+
requireThat(!host || brief.host === host, "历史节点不存在,请重新搜索。");
|
|
248
229
|
const parents = [];
|
|
249
230
|
const children = [];
|
|
250
231
|
if (artifact.dimension === "monthly") {
|
|
@@ -285,14 +266,14 @@ export function readWorkspaceHistory(root, id, offset = 0, limit = 12000, childr
|
|
|
285
266
|
const pagedChildren = page(children, childrenOffset, 20);
|
|
286
267
|
const sliced = sliceText(artifact.text, offset, limit);
|
|
287
268
|
return {
|
|
288
|
-
...
|
|
269
|
+
...brief,
|
|
289
270
|
...sliced,
|
|
290
271
|
parents,
|
|
291
272
|
children: pagedChildren.values,
|
|
292
273
|
nextChildrenOffset: pagedChildren.nextOffset,
|
|
293
274
|
source: {
|
|
294
|
-
host:
|
|
295
|
-
sessionId:
|
|
275
|
+
host: brief.host,
|
|
276
|
+
sessionId: brief.sessionId,
|
|
296
277
|
entryIds: artifact.source.exchangeIds,
|
|
297
278
|
dimension: artifact.dimension,
|
|
298
279
|
},
|
|
@@ -17,4 +17,4 @@ export type ParsedHistoryCommand = {
|
|
|
17
17
|
input: Record<string, unknown>;
|
|
18
18
|
};
|
|
19
19
|
export declare const historyCommandUsage = "\u7528\u6CD5\uFF1A/pbot history summary [\u7EF4\u5EA6...] [--force] [--backend <acp>] [--model <model>] [--thinking <level>] | migrate [--dry-run] | status | list | {\"action\":\"search\"|\"read\",...}";
|
|
20
|
-
export declare function parseHistoryCommand(raw: string): ParsedHistoryCommand;
|
|
20
|
+
export declare function parseHistoryCommand(raw: string | readonly string[]): ParsedHistoryCommand;
|
|
@@ -2,18 +2,19 @@ import { object } from "../../common/json.js";
|
|
|
2
2
|
import { requireThat } from "../../common/validation.js";
|
|
3
3
|
export const historyCommandUsage = '用法:/pbot history summary [维度...] [--force] [--backend <acp>] [--model <model>] [--thinking <level>] | migrate [--dry-run] | status | list | {"action":"search"|"read",...}';
|
|
4
4
|
export function parseHistoryCommand(raw) {
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const tokens = typeof raw === "string"
|
|
6
|
+
? raw.trim().startsWith("{") ? [raw.trim()] : raw.trim().split(/\s+/).filter(Boolean)
|
|
7
|
+
: raw;
|
|
8
|
+
const [sub] = tokens;
|
|
9
|
+
if (!sub || sub === "status" && tokens.length === 1)
|
|
7
10
|
return { kind: "status" };
|
|
8
|
-
if (
|
|
11
|
+
if (sub === "list" && tokens.length === 1)
|
|
9
12
|
return { kind: "list" };
|
|
10
|
-
if (
|
|
11
|
-
const parsed = JSON.parse(
|
|
13
|
+
if (tokens.length === 1 && sub.startsWith("{")) {
|
|
14
|
+
const parsed = JSON.parse(sub);
|
|
12
15
|
requireThat(object(parsed), "历史查询参数必须是 JSON 对象。");
|
|
13
16
|
return { kind: "query", input: parsed };
|
|
14
17
|
}
|
|
15
|
-
const tokens = trimmed.split(/\s+/);
|
|
16
|
-
const sub = tokens[0];
|
|
17
18
|
if (sub === "migrate") {
|
|
18
19
|
let dryRun = false;
|
|
19
20
|
for (const token of tokens.slice(1)) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { requireThat } from "../../common/validation.js";
|
|
2
|
-
import { isSummaryDimension } from "../../storage/history-format.js";
|
|
1
|
+
import { isHistoryIdentifier, requireThat } from "../../common/validation.js";
|
|
3
2
|
import { monthlySummaryDimension } from "./summary-dimensions/monthly.js";
|
|
4
3
|
import { sessionSummaryDimension } from "./summary-dimensions/session.js";
|
|
5
4
|
const registry = new Map([
|
|
@@ -8,7 +7,7 @@ const registry = new Map([
|
|
|
8
7
|
]);
|
|
9
8
|
/** Register a custom summary dimension (e.g. daily, decisions, topics). */
|
|
10
9
|
export function registerSummaryDimension(dimension) {
|
|
11
|
-
requireThat(
|
|
10
|
+
requireThat(isHistoryIdentifier(dimension.id), "摘要维度 ID 无效:" + dimension.id);
|
|
12
11
|
registry.set(dimension.id, dimension);
|
|
13
12
|
}
|
|
14
13
|
export function unregisterSummaryDimension(id) {
|
|
@@ -5,13 +5,10 @@ export interface InspectSummaryOptions {
|
|
|
5
5
|
thresholdDays?: number;
|
|
6
6
|
now?: Date;
|
|
7
7
|
}
|
|
8
|
-
export
|
|
9
|
-
dimensions?: readonly string[];
|
|
10
|
-
thresholdDays?: number;
|
|
11
|
-
now?: Date;
|
|
12
|
-
}
|
|
8
|
+
export type CheckSummaryReminderOptions = InspectSummaryOptions;
|
|
13
9
|
/** Read-only startup probe: reminds when raw history has existed >= thresholdDays and no summary ran within thresholdDays. */
|
|
14
10
|
export declare function checkHistorySummaryReminder(root: string, options?: CheckSummaryReminderOptions): HistorySummaryReminder | undefined;
|
|
11
|
+
export declare function historyStartupNotices(root: string): string[];
|
|
15
12
|
/** Read-only inspection of raw archives vs derived summaries across requested dimensions. */
|
|
16
13
|
export declare function inspectWorkspaceSummaries(root: string, options?: InspectSummaryOptions): {
|
|
17
14
|
layout: HistoryLayout;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
2
|
import { setTimeout as delay } from "node:timers/promises";
|
|
3
3
|
import { requireThat } from "../../common/validation.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { summaryConcurrency } from "../../model/workspace-config.js";
|
|
5
|
+
import { workspaceHistoryFiles } from "./workspace-history.js";
|
|
6
6
|
import { rawSessionSpan } from "./history-index.js";
|
|
7
7
|
import { resolveSummaryDimensions } from "./summary-registry.js";
|
|
8
|
-
const defaultConcurrency = 3;
|
|
9
|
-
const maxConcurrency = 8;
|
|
10
8
|
const lockRetryAttempts = 5;
|
|
11
9
|
const lockRetryDelayMs = 40;
|
|
12
10
|
export const defaultSummaryReminderDays = 7;
|
|
@@ -70,8 +68,8 @@ function evaluateSummaryReminder(raws, allSummaries, pendingCount, options = {})
|
|
|
70
68
|
const rawAgeDays = Math.floor((nowMs - oldestRawMs) / dayMs);
|
|
71
69
|
const daysSinceLastSummary = latestSummaryMs === undefined ? undefined : Math.floor((nowMs - latestSummaryMs) / dayMs);
|
|
72
70
|
const message = daysSinceLastSummary === undefined
|
|
73
|
-
? `历史原文已累计 ${rawAgeDays} 天(待摘要 ${pendingCount}
|
|
74
|
-
: `历史原文已累计 ${rawAgeDays} 天,且已 ${daysSinceLastSummary} 天未触发摘要整理(待摘要 ${pendingCount}
|
|
71
|
+
? `历史原文已累计 ${rawAgeDays} 天(待摘要 ${pendingCount} 项),尚未触发过摘要整理;可在终端运行 pbot history summary 生成摘要(Pi/dsh 可用 /pbot history summary)。`
|
|
72
|
+
: `历史原文已累计 ${rawAgeDays} 天,且已 ${daysSinceLastSummary} 天未触发摘要整理(待摘要 ${pendingCount} 项);可在终端运行 pbot history summary 更新摘要(Pi/dsh 可用 /pbot history summary)。`;
|
|
75
73
|
return {
|
|
76
74
|
rawCount: raws.length,
|
|
77
75
|
pendingCount,
|
|
@@ -85,8 +83,23 @@ function evaluateSummaryReminder(raws, allSummaries, pendingCount, options = {})
|
|
|
85
83
|
}
|
|
86
84
|
/** Read-only startup probe: reminds when raw history has existed >= thresholdDays and no summary ran within thresholdDays. */
|
|
87
85
|
export function checkHistorySummaryReminder(root, options = {}) {
|
|
88
|
-
|
|
89
|
-
|
|
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) {
|
|
90
103
|
const raws = files.listRaw();
|
|
91
104
|
if (!raws.length)
|
|
92
105
|
return undefined;
|
|
@@ -96,48 +109,11 @@ export function checkHistorySummaryReminder(root, options = {}) {
|
|
|
96
109
|
const oldestRawMs = oldestRawTimestamp(raws);
|
|
97
110
|
if (oldestRawMs === undefined || nowMs - oldestRawMs < thresholdDays * dayMs)
|
|
98
111
|
return undefined;
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
const summariesByDimension = new Map();
|
|
102
|
-
const allSummaries = [];
|
|
103
|
-
let pendingCount = 0;
|
|
104
|
-
const loadDimension = (dimId) => {
|
|
105
|
-
const cached = summariesByDimension.get(dimId);
|
|
106
|
-
if (cached)
|
|
107
|
-
return cached;
|
|
108
|
-
const list = files.listSummaries(dimId);
|
|
109
|
-
const map = new Map(list.map(item => [item.id, item]));
|
|
110
|
-
summariesByDimension.set(dimId, map);
|
|
111
|
-
return map;
|
|
112
|
-
};
|
|
113
|
-
for (const dimension of dimensions) {
|
|
114
|
-
seenDimensions.add(dimension.id);
|
|
115
|
-
if (dimension.id !== "session")
|
|
116
|
-
loadDimension("session");
|
|
117
|
-
const existing = loadDimension(dimension.id);
|
|
118
|
-
allSummaries.push(...existing.values());
|
|
119
|
-
const plan = dimension.plan(raws, existing, { force: false, summariesByDimension });
|
|
120
|
-
pendingCount += plan.tasks.length;
|
|
121
|
-
}
|
|
122
|
-
for (const dim of files.listDimensions()) {
|
|
123
|
-
if (seenDimensions.has(dim))
|
|
124
|
-
continue;
|
|
125
|
-
allSummaries.push(...loadDimension(dim).values());
|
|
126
|
-
}
|
|
127
|
-
return evaluateSummaryReminder(raws, allSummaries, pendingCount, options);
|
|
112
|
+
const { totalPending, allSummaries } = inspectDimensions(files, raws, options, []);
|
|
113
|
+
return evaluateSummaryReminder(raws, allSummaries, totalPending, options);
|
|
128
114
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const layout = readWorkspaceHistoryLayoutSync(root);
|
|
132
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", layout);
|
|
133
|
-
const raws = files.listRaw();
|
|
134
|
-
const warnings = [...files.warnings];
|
|
135
|
-
if (layout === "monthly") {
|
|
136
|
-
const flatNotice = files.detectFlatFiles().message;
|
|
137
|
-
if (flatNotice)
|
|
138
|
-
warnings.push(flatNotice);
|
|
139
|
-
}
|
|
140
|
-
const dimensions = resolveSummaryDimensions(options.dimensions, layout);
|
|
115
|
+
function inspectDimensions(files, raws, options, warnings) {
|
|
116
|
+
const dimensions = resolveSummaryDimensions(options.dimensions, files.layout);
|
|
141
117
|
const statuses = [];
|
|
142
118
|
const seenDimensions = new Set();
|
|
143
119
|
const summariesByDimension = new Map();
|
|
@@ -188,9 +164,20 @@ export function inspectWorkspaceSummaries(root, options = {}) {
|
|
|
188
164
|
continue;
|
|
189
165
|
allSummaries.push(...loadDimension(dim).values());
|
|
190
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);
|
|
191
178
|
const reminder = evaluateSummaryReminder(raws, allSummaries, totalPending, options);
|
|
192
179
|
return {
|
|
193
|
-
layout,
|
|
180
|
+
layout: files.layout,
|
|
194
181
|
rawCount: raws.length,
|
|
195
182
|
dimensions: statuses,
|
|
196
183
|
warnings: [...new Set(warnings)],
|
|
@@ -206,29 +193,28 @@ export async function runWorkspaceSummaries(options) {
|
|
|
206
193
|
const startedAt = Date.now();
|
|
207
194
|
const signal = options.signal ?? new AbortController().signal;
|
|
208
195
|
signal.throwIfAborted();
|
|
209
|
-
const concurrency = Math.max(1, Math.min(
|
|
210
|
-
const
|
|
211
|
-
const dimensions = resolveSummaryDimensions(options.dimensions, layout);
|
|
212
|
-
const
|
|
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) }));
|
|
213
207
|
const raws = files.listRaw();
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
warnings.push(flatNotice);
|
|
219
|
-
}
|
|
208
|
+
warnings.push(...files.warnings);
|
|
209
|
+
const flatNotice = files.migrationNotice();
|
|
210
|
+
if (flatNotice)
|
|
211
|
+
warnings.push(flatNotice);
|
|
220
212
|
const summariesByDimension = new Map();
|
|
221
213
|
const reports = [];
|
|
222
|
-
for (const dimension of
|
|
214
|
+
for (const { dimension, existing } of plannedDimensions) {
|
|
223
215
|
signal.throwIfAborted();
|
|
224
|
-
if (dimension.id !== "session"
|
|
225
|
-
|
|
226
|
-
warnings.push(...files.warnings);
|
|
227
|
-
summariesByDimension.set("session", new Map(sessionList.map(item => [item.id, item])));
|
|
228
|
-
}
|
|
229
|
-
const existingList = files.listSummaries(dimension.id);
|
|
230
|
-
warnings.push(...files.warnings);
|
|
231
|
-
const existing = new Map(existingList.map(item => [item.id, item]));
|
|
216
|
+
if (dimension.id !== "session")
|
|
217
|
+
summariesByDimension.set("session", loadSummaries("session"));
|
|
232
218
|
summariesByDimension.set(dimension.id, existing);
|
|
233
219
|
const plan = dimension.plan(raws, existing, { force: Boolean(options.force), summariesByDimension });
|
|
234
220
|
const report = {
|
|
@@ -256,12 +242,24 @@ export async function runWorkspaceSummaries(options) {
|
|
|
256
242
|
const output = await options.summarizer(request, signal);
|
|
257
243
|
signal.throwIfAborted();
|
|
258
244
|
const artifact = dimension.finalize(task, output, new Date().toISOString());
|
|
259
|
-
await withSummaryLockRetry(files, dimension.id, () => {
|
|
245
|
+
const published = await withSummaryLockRetry(files, dimension.id, () => {
|
|
260
246
|
signal.throwIfAborted();
|
|
261
|
-
files.
|
|
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;
|
|
262
258
|
}, signal);
|
|
263
|
-
existing.set(artifact.id,
|
|
264
|
-
if (
|
|
259
|
+
existing.set(artifact.id, published);
|
|
260
|
+
if (published !== artifact)
|
|
261
|
+
report.skipped++;
|
|
262
|
+
else if (task.mode === "create")
|
|
265
263
|
report.created++;
|
|
266
264
|
else if (task.mode === "incremental")
|
|
267
265
|
report.incremental++;
|
|
@@ -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
|
+
}
|
|
@@ -45,6 +45,9 @@ export function parseSetupArgs(args) {
|
|
|
45
45
|
return { action: "help" };
|
|
46
46
|
if (args.length === 1 && ["--version", "-v"].includes(args[0]))
|
|
47
47
|
return { action: "version" };
|
|
48
|
+
if (args[0] === "upgrade" || args[0] === "update") {
|
|
49
|
+
return { action: "upgrade", upgradeArgs: args.slice(1), upgradeVerb: args[0] };
|
|
50
|
+
}
|
|
48
51
|
if (args[0] === "install-antigravity") {
|
|
49
52
|
if (args.length === 1)
|
|
50
53
|
return { action: "install-antigravity" };
|
|
@@ -62,7 +65,7 @@ export function parseSetupArgs(args) {
|
|
|
62
65
|
throw new Error("用法:pbot mcp [list|add|remove ...]");
|
|
63
66
|
}
|
|
64
67
|
if (args[0] !== "setup")
|
|
65
|
-
throw new Error("用法:pbot setup [--workspace <目录>] | pbot install-antigravity | pbot mcp [list|add|remove ...]");
|
|
68
|
+
throw new Error("用法:pbot setup [--workspace <目录>] | pbot upgrade|update [--workspace <目录>] | pbot install-antigravity | pbot mcp [list|add|remove ...]");
|
|
66
69
|
let workspace;
|
|
67
70
|
for (let index = 1; index < args.length; index++) {
|
|
68
71
|
const arg = args[index];
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { valid } from "semver";
|
|
2
|
+
import { requireThat } from "../../common/validation.js";
|
|
3
|
+
export const upgradeUsage = "用法:pbot upgrade|update [--workspace <目录>] [--version <MAJOR.MINOR.PATCH>] [--hosts <h1,h2>] [--dsh-profile <名称>] [--json]\n" +
|
|
4
|
+
"将全局 CLI 与当前工作区已绑定的各宿主插件统一升级到 npm 最新稳定版(或指定版本)。";
|
|
5
|
+
export function parseUpgradeArgs(args) {
|
|
6
|
+
let workspace;
|
|
7
|
+
let version;
|
|
8
|
+
let hosts;
|
|
9
|
+
let dshProfile;
|
|
10
|
+
let json = false;
|
|
11
|
+
for (let index = 0; index < args.length; index++) {
|
|
12
|
+
const token = args[index];
|
|
13
|
+
if (token === "--help" || token === "-h")
|
|
14
|
+
return { help: true, json: false };
|
|
15
|
+
if (token === "--json") {
|
|
16
|
+
json = true;
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (token === "--workspace" || token.startsWith("--workspace=")) {
|
|
20
|
+
requireThat(workspace === undefined, "--workspace 只能指定一次。");
|
|
21
|
+
workspace = token === "--workspace" ? args[++index] : token.slice("--workspace=".length);
|
|
22
|
+
requireThat(workspace && !workspace.startsWith("-"), "--workspace 需要目录。");
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (token === "--version" || token.startsWith("--version=")) {
|
|
26
|
+
requireThat(version === undefined, "--version 只能指定一次。");
|
|
27
|
+
version = token === "--version" ? args[++index] : token.slice("--version=".length);
|
|
28
|
+
requireThat(version && valid(version) && /^[0-9]/.test(version) && version === version.trim(), "--version 需要合法的 MAJOR.MINOR.PATCH 版本号。");
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (token === "--hosts" || token.startsWith("--hosts=")) {
|
|
32
|
+
requireThat(hosts === undefined, "--hosts 只能指定一次。");
|
|
33
|
+
const raw = token === "--hosts" ? args[++index] : token.slice("--hosts=".length);
|
|
34
|
+
requireThat(raw && !raw.startsWith("-"), "--hosts 需要逗号分隔的宿主名称。");
|
|
35
|
+
hosts = [...new Set(raw.split(",").map(item => item.trim()).filter(Boolean))];
|
|
36
|
+
requireThat(hosts.length > 0, "--hosts 不能为空。");
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (token === "--dsh-profile" || token.startsWith("--dsh-profile=")) {
|
|
40
|
+
requireThat(dshProfile === undefined, "--dsh-profile 只能指定一次。");
|
|
41
|
+
dshProfile = token === "--dsh-profile" ? args[++index] : token.slice("--dsh-profile=".length);
|
|
42
|
+
requireThat(dshProfile && !dshProfile.startsWith("-"), "--dsh-profile 需要 profile 名称。");
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
throw new Error(`不支持的参数:${token}\n${upgradeUsage}`);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
help: false,
|
|
49
|
+
...(workspace !== undefined ? { workspace } : {}),
|
|
50
|
+
...(version !== undefined ? { version } : {}),
|
|
51
|
+
...(hosts !== undefined ? { hosts } : {}),
|
|
52
|
+
...(dshProfile !== undefined ? { dshProfile } : {}),
|
|
53
|
+
json,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export async function executeWorkspaceUpgrade(input) {
|
|
57
|
+
const results = [];
|
|
58
|
+
for (const target of input.targets) {
|
|
59
|
+
input.signal.throwIfAborted();
|
|
60
|
+
const upgrader = input.resolveUpgrader(target.host);
|
|
61
|
+
let result;
|
|
62
|
+
if (!upgrader) {
|
|
63
|
+
result = {
|
|
64
|
+
host: target.host,
|
|
65
|
+
state: "skipped",
|
|
66
|
+
...(target.currentVersion ? { previousVersion: target.currentVersion } : {}),
|
|
67
|
+
detail: "未注册该宿主的自动升级适配器,已跳过。",
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
try {
|
|
72
|
+
result = await upgrader.upgrade(input.createContext(target));
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
input.signal.throwIfAborted();
|
|
76
|
+
result = {
|
|
77
|
+
host: target.host,
|
|
78
|
+
state: "failed",
|
|
79
|
+
...(target.currentVersion ? { previousVersion: target.currentVersion } : {}),
|
|
80
|
+
detail: error instanceof Error ? error.message : String(error),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
results.push(result);
|
|
85
|
+
input.onResult?.(result);
|
|
86
|
+
}
|
|
87
|
+
const ok = input.cli.state !== "failed" && !results.some(item => item.state === "failed");
|
|
88
|
+
return {
|
|
89
|
+
workspaceRoot: input.workspaceRoot,
|
|
90
|
+
targetVersion: input.targetVersion,
|
|
91
|
+
cli: input.cli,
|
|
92
|
+
results,
|
|
93
|
+
ok,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 interface WorkspacePluginBinding {
|
|
4
|
+
version: string;
|
|
5
|
+
bindingPath?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface WorkspacePluginDrift {
|
|
8
|
+
outOfSync: boolean;
|
|
9
|
+
highest?: string;
|
|
10
|
+
lowest?: string;
|
|
11
|
+
versions: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
export declare function workspacePluginBindings(root: string): Record<string, WorkspacePluginBinding>;
|
|
14
|
+
export declare function workspacePluginReleases(root: string): Record<string, string>;
|
|
15
|
+
export declare function workspacePluginDrift(releases: Record<string, string>): WorkspacePluginDrift;
|