personal-bot 0.3.2 → 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 +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 +8 -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 +7 -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 +31 -23
- 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 +20127 -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 +3 -0
- package/lib/antigravity-plugin/lib/services/workspace/plugin-releases.js +78 -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 +31 -23
- 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 +3 -0
- package/lib/extension/workspace-cli.js +20127 -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/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/workspace/plugin-releases.d.ts +3 -0
- package/lib/services/workspace/plugin-releases.js +78 -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 +32 -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 +4 -1
- package/src/extension/setup/workspace-cli.ts +159 -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 +116 -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/model/acp.ts +11 -3
- package/src/model/agent.ts +20 -4
- package/src/model/history.ts +5 -0
- package/src/model/installation.ts +41 -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 +2 -41
- package/src/services/workspace/plugin-releases.ts +68 -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
|
@@ -5,12 +5,11 @@ export interface WorkspaceFeatures {
|
|
|
5
5
|
mcp?: boolean;
|
|
6
6
|
history?: boolean;
|
|
7
7
|
}
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
readonly
|
|
11
|
-
readonly
|
|
12
|
-
|
|
13
|
-
}
|
|
8
|
+
export type ResolvedWorkspaceFeatures = Readonly<Required<WorkspaceFeatures>>;
|
|
9
|
+
export declare const summaryConcurrency: {
|
|
10
|
+
readonly default: 3;
|
|
11
|
+
readonly max: 8;
|
|
12
|
+
};
|
|
14
13
|
export interface WorkspaceSummaryConfig {
|
|
15
14
|
backend?: string;
|
|
16
15
|
model?: string;
|
|
@@ -23,7 +22,8 @@ export interface ResolvedWorkspaceSummaryConfig {
|
|
|
23
22
|
readonly thinking?: string;
|
|
24
23
|
readonly concurrency: number;
|
|
25
24
|
}
|
|
26
|
-
export
|
|
25
|
+
export declare const historyLayouts: readonly ["monthly", "flat"];
|
|
26
|
+
export type HistoryLayout = typeof historyLayouts[number];
|
|
27
27
|
export interface WorkspaceHistoryConfig {
|
|
28
28
|
layout?: HistoryLayout;
|
|
29
29
|
}
|
|
@@ -37,13 +37,9 @@ export interface WorkspaceConfig {
|
|
|
37
37
|
summary?: WorkspaceSummaryConfig;
|
|
38
38
|
history?: WorkspaceHistoryConfig;
|
|
39
39
|
}
|
|
40
|
-
export interface WorkspaceConfiguration {
|
|
40
|
+
export interface WorkspaceConfiguration extends WorkspaceConfig {
|
|
41
41
|
path: string;
|
|
42
42
|
present: boolean;
|
|
43
43
|
enabled: boolean;
|
|
44
44
|
error?: string;
|
|
45
|
-
features?: WorkspaceFeatures;
|
|
46
|
-
acp?: AcpCommands;
|
|
47
|
-
summary?: WorkspaceSummaryConfig;
|
|
48
|
-
history?: WorkspaceHistoryConfig;
|
|
49
45
|
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export const summaryConcurrency = { default: 3, max: 8 };
|
|
2
|
+
export const historyLayouts = ["monthly", "flat"];
|
package/lib/plugin.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { type ReplayPluginHook } from "./extension/hosts/plugin-runtime.js";
|
|
2
|
+
export declare function main(args: readonly string[], replayHook?: ReplayPluginHook): Promise<void>;
|
package/lib/plugin.js
CHANGED
|
@@ -3,11 +3,11 @@ import { pathToFileURL } from "node:url";
|
|
|
3
3
|
import { requireThat } from "./common/validation.js";
|
|
4
4
|
import { runPluginHost } from "./extension/hosts/plugin-runtime.js";
|
|
5
5
|
import { listPluginHosts, pluginHosts } from "./integrations/hosts/plugin-registry.js";
|
|
6
|
-
export async function main(args) {
|
|
6
|
+
export async function main(args, replayHook) {
|
|
7
7
|
const [host, ...rest] = args;
|
|
8
8
|
const adapter = host ? pluginHosts.get(host) : undefined;
|
|
9
9
|
requireThat(adapter, `用法:node <插件目录>/lib/plugin.js <${listPluginHosts().join("|")}> hook|init|status`);
|
|
10
|
-
await runPluginHost(adapter, rest);
|
|
10
|
+
await runPluginHost(adapter, rest, replayHook);
|
|
11
11
|
}
|
|
12
12
|
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
|
|
13
13
|
void main(process.argv.slice(2)).catch(error => {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mcpServers": {
|
|
3
|
+
"pbot": {
|
|
4
|
+
"command": "sh",
|
|
5
|
+
"args": [
|
|
6
|
+
"-c",
|
|
7
|
+
"if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.3 \"$@\"",
|
|
8
|
+
"pbot",
|
|
9
|
+
"mcp"
|
|
10
|
+
],
|
|
11
|
+
"env": {
|
|
12
|
+
"PBOT_HOST": "qoder",
|
|
13
|
+
"PBOT_PLUGIN_VERSION": "0.3.3"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Disclaimer / 免责声明
|
|
2
|
+
|
|
3
|
+
## English
|
|
4
|
+
|
|
5
|
+
AI models can produce incorrect answers, commands, and code. Verify information before relying on it. Review proposed changes before applying them to important files or systems.
|
|
6
|
+
|
|
7
|
+
Workers and MCP tools may read or change files, run commands, or send workspace data to services you configure. Check which data and credentials a worker or service can access when granting permissions. Third-party providers may charge for requests and process data under their own terms and privacy policies.
|
|
8
|
+
|
|
9
|
+
Personal Bot is provided “as is”. Its warranty disclaimer and limitation of liability are set out in the project license. Third-party software is subject to its own licenses. [MIT License](LICENSE)
|
|
10
|
+
|
|
11
|
+
## 中文
|
|
12
|
+
|
|
13
|
+
AI 模型生成的回答、命令和代码可能有误。请在据此作出决定前核实关键信息,在将更改应用到重要文件或系统前审查具体内容。
|
|
14
|
+
|
|
15
|
+
Worker 和 MCP 工具可能读取或修改文件、执行命令,或将工作区数据发送给你配置的服务。授予权限时,请确认对方能够访问哪些数据和凭据。第三方服务可能按请求收费,并按各自的条款和隐私政策处理数据。
|
|
16
|
+
|
|
17
|
+
Personal Bot 按现状提供,担保免责和责任限制条款见项目许可证。第三方软件适用其各自的许可证。[MIT 许可证全文](LICENSE)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Personal Bot contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"SessionStart": [
|
|
4
|
+
{
|
|
5
|
+
"hooks": [
|
|
6
|
+
{
|
|
7
|
+
"type": "command",
|
|
8
|
+
"command": "PBOT_PLUGIN_VERSION=0.3.3 PBOT_PLUGIN_MANIFEST=\"${QODER_PLUGIN_ROOT:+$QODER_PLUGIN_ROOT/.qoder-plugin/plugin.json}\" sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.3 \"$@\"' pbot plugin qoder hook",
|
|
9
|
+
"timeout": 120
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"UserPromptSubmit": [
|
|
15
|
+
{
|
|
16
|
+
"hooks": [
|
|
17
|
+
{
|
|
18
|
+
"type": "command",
|
|
19
|
+
"command": "PBOT_PLUGIN_VERSION=0.3.3 PBOT_PLUGIN_MANIFEST=\"${QODER_PLUGIN_ROOT:+$QODER_PLUGIN_ROOT/.qoder-plugin/plugin.json}\" sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.3 \"$@\"' pbot plugin qoder hook",
|
|
20
|
+
"timeout": 120
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"Stop": [
|
|
26
|
+
{
|
|
27
|
+
"hooks": [
|
|
28
|
+
{
|
|
29
|
+
"type": "command",
|
|
30
|
+
"command": "PBOT_PLUGIN_VERSION=0.3.3 PBOT_PLUGIN_MANIFEST=\"${QODER_PLUGIN_ROOT:+$QODER_PLUGIN_ROOT/.qoder-plugin/plugin.json}\" sh -c 'if pbot --at-least 0.3.3 </dev/null >/dev/null 2>&1; then exec pbot \"$@\"; fi\nexec npx --yes --ignore-scripts --prefer-offline personal-bot@0.3.3 \"$@\"' pbot plugin qoder hook",
|
|
31
|
+
"timeout": 120
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pbot
|
|
3
|
+
description: 初始化 Personal Bot 工作区、查看状态、搜索归档或生成历史摘要。
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
使用当前会话的 `workspaceRoot` 作为 `--workspace`。省略子命令时使用 `status`。可执行 `init`、`status`、`history status|list|summary|migrate|search|read`。保留用户指定的维度、模型和筛选参数。
|
|
8
|
+
|
|
9
|
+
运行 `npx --yes personal-bot@0.3.3 <子命令> --workspace "<workspaceRoot>"`。如果 `pbot --at-least 0.3.3` 返回 0,也可以用 `pbot` 执行同一条命令。返回实际结果。
|
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import type { AcpBackend, AcpSessionReference } from "../../model/acp.js";
|
|
4
|
-
export interface AgentHost {
|
|
5
|
-
available(backend: AcpBackend): void;
|
|
6
|
-
filterOptions?(backend: AcpBackend, options: AgentOptions): AgentOptions;
|
|
7
|
-
prepare(backend: AcpBackend, options: AgentOptions): AcpSessionReference;
|
|
8
|
-
alive(id: string): boolean;
|
|
9
|
-
validateSession(value: AgentDescriptor, reference: AgentSessionReference): void | Promise<void>;
|
|
10
|
-
launch(value: AgentDescriptor, directory: string, generation: string, reference: AgentSessionReference, resume: boolean, signal: AbortSignal): void | Promise<void>;
|
|
11
|
-
release(id: string, generation: string): void | Promise<void>;
|
|
12
|
-
report(value: AgentDescriptor, reference: AgentSessionReference, leaf: string): string | Promise<string>;
|
|
13
|
-
}
|
|
1
|
+
import type { AgentOwner, AgentOptions, AgentMessage, AgentPendingRequest, AgentResponseInput, AgentStartOptions, AgentCycle, AgentHost, AgentView } from "../../model/agent.js";
|
|
2
|
+
export type { AgentHost } from "../../model/agent.js";
|
|
14
3
|
/** Host-neutral lifecycle manager for cross-harness ACP workers. */
|
|
15
4
|
export declare class AgentService {
|
|
16
5
|
#private;
|
|
17
6
|
readonly root: string;
|
|
18
7
|
readonly host: AgentHost;
|
|
19
|
-
readonly files
|
|
8
|
+
private readonly files;
|
|
20
9
|
constructor(root: string, directory: string, host: AgentHost);
|
|
21
10
|
private alive;
|
|
22
11
|
private check;
|
|
@@ -35,7 +24,7 @@ export declare class AgentService {
|
|
|
35
24
|
state: import("../../model/agent.js").AgentStatus["state"];
|
|
36
25
|
activity: string;
|
|
37
26
|
alive: boolean;
|
|
38
|
-
backend: AcpBackend;
|
|
27
|
+
backend: import("../../model/acp.js").AcpBackend;
|
|
39
28
|
transport: "acp";
|
|
40
29
|
selection?: import("../../model/acp.js").AcpModelSelection;
|
|
41
30
|
capabilities: {
|
|
@@ -57,7 +46,7 @@ export declare class AgentService {
|
|
|
57
46
|
options: AgentOptions;
|
|
58
47
|
}>;
|
|
59
48
|
private launch;
|
|
60
|
-
send(id: string, text: string, delivery: "
|
|
49
|
+
send(id: string, text: string, delivery: AgentMessage["delivery"], owner: AgentOwner, attachments?: readonly string[]): {
|
|
61
50
|
requestId: string;
|
|
62
51
|
messageStatus: "queued";
|
|
63
52
|
name: string;
|
|
@@ -65,7 +54,7 @@ export declare class AgentService {
|
|
|
65
54
|
state: import("../../model/agent.js").AgentStatus["state"];
|
|
66
55
|
activity: string;
|
|
67
56
|
alive: boolean;
|
|
68
|
-
backend: AcpBackend;
|
|
57
|
+
backend: import("../../model/acp.js").AcpBackend;
|
|
69
58
|
transport: "acp";
|
|
70
59
|
selection?: import("../../model/acp.js").AcpModelSelection;
|
|
71
60
|
capabilities: {
|
|
@@ -98,7 +87,7 @@ export declare class AgentService {
|
|
|
98
87
|
state: import("../../model/agent.js").AgentStatus["state"];
|
|
99
88
|
activity: string;
|
|
100
89
|
alive: boolean;
|
|
101
|
-
backend: AcpBackend;
|
|
90
|
+
backend: import("../../model/acp.js").AcpBackend;
|
|
102
91
|
transport: "acp";
|
|
103
92
|
selection?: import("../../model/acp.js").AcpModelSelection;
|
|
104
93
|
capabilities: {
|
|
@@ -121,32 +110,13 @@ export declare class AgentService {
|
|
|
121
110
|
}>;
|
|
122
111
|
private restart;
|
|
123
112
|
cycles(id: string, owner: AgentOwner): AgentCycle[];
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
backend: AcpBackend;
|
|
132
|
-
transport: "acp";
|
|
133
|
-
selection?: import("../../model/acp.js").AcpModelSelection;
|
|
134
|
-
capabilities: {
|
|
135
|
-
steer: boolean;
|
|
136
|
-
resume: boolean;
|
|
137
|
-
transcript: boolean;
|
|
138
|
-
};
|
|
139
|
-
error?: string;
|
|
140
|
-
owned: boolean;
|
|
141
|
-
pendingRequests?: AgentPendingRequest[];
|
|
142
|
-
agentId: string;
|
|
143
|
-
release: string;
|
|
144
|
-
workspace: string;
|
|
145
|
-
cwd: string;
|
|
146
|
-
parentSessionId: string;
|
|
147
|
-
parentLeaf: string | null;
|
|
148
|
-
createdAt: number;
|
|
149
|
-
options: AgentOptions;
|
|
113
|
+
private cyclesFor;
|
|
114
|
+
private snapshot;
|
|
115
|
+
status(id: string, owner: AgentOwner): AgentView;
|
|
116
|
+
outputStatus(id: string, owner: AgentOwner, requestId?: string): {
|
|
117
|
+
current: AgentView;
|
|
118
|
+
cycle: AgentCycle | undefined;
|
|
119
|
+
terminal: boolean;
|
|
150
120
|
};
|
|
151
121
|
read(id: string, owner: AgentOwner, cycleId?: string, offset?: number, limit?: number): Promise<{
|
|
152
122
|
cycles: {
|
|
@@ -162,7 +132,7 @@ export declare class AgentService {
|
|
|
162
132
|
state: import("../../model/agent.js").AgentStatus["state"];
|
|
163
133
|
activity: string;
|
|
164
134
|
alive: boolean;
|
|
165
|
-
backend: AcpBackend;
|
|
135
|
+
backend: import("../../model/acp.js").AcpBackend;
|
|
166
136
|
transport: "acp";
|
|
167
137
|
selection?: import("../../model/acp.js").AcpModelSelection;
|
|
168
138
|
capabilities: {
|
|
@@ -298,7 +298,11 @@ export class AgentService {
|
|
|
298
298
|
}
|
|
299
299
|
}
|
|
300
300
|
cycles(id, owner) {
|
|
301
|
-
|
|
301
|
+
return this.cyclesFor(this.view(this.get(id, owner), owner));
|
|
302
|
+
}
|
|
303
|
+
cyclesFor(view) {
|
|
304
|
+
const id = view.agentId;
|
|
305
|
+
const values = this.files.completions(id);
|
|
302
306
|
if (view.cycle && !values.some(c => c.cycleId === view.cycle.cycleId)) {
|
|
303
307
|
values.push(view.state === "stopped" || view.state === "error" ? { ...view.cycle, state: "interrupted", finishedAt: view.cycle.finishedAt ?? Date.now() } : view.cycle);
|
|
304
308
|
}
|
|
@@ -321,9 +325,24 @@ export class AgentService {
|
|
|
321
325
|
}
|
|
322
326
|
return values;
|
|
323
327
|
}
|
|
328
|
+
snapshot(id, owner) {
|
|
329
|
+
const view = this.view(this.get(id, owner), owner);
|
|
330
|
+
const cycles = this.cyclesFor(view);
|
|
331
|
+
const latest = cycles.at(-1);
|
|
332
|
+
return { current: latest ? { ...view, cycle: latest } : view, cycles };
|
|
333
|
+
}
|
|
324
334
|
status(id, owner) {
|
|
325
|
-
|
|
326
|
-
|
|
335
|
+
return this.snapshot(id, owner).current;
|
|
336
|
+
}
|
|
337
|
+
outputStatus(id, owner, requestId) {
|
|
338
|
+
const { current, cycles } = this.snapshot(id, owner);
|
|
339
|
+
const request = requestId ?? this.files.messages(id).findLast(item => item.generation === current.generation)?.requestId;
|
|
340
|
+
const cycle = request
|
|
341
|
+
? cycles.find(item => item.generation === current.generation && item.requestIds.includes(request))
|
|
342
|
+
: current.cycle;
|
|
343
|
+
const stopped = current.state === "stopped" || current.state === "error";
|
|
344
|
+
const terminal = request ? stopped && !cycle : stopped || (current.state === "idle" && !cycle);
|
|
345
|
+
return { current, cycle, terminal };
|
|
327
346
|
}
|
|
328
347
|
async read(id, owner, cycleId, offset = 0, limit = 16000) {
|
|
329
348
|
const d = this.get(id, owner), cycles = this.cycles(id, owner);
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { join } from "node:path";
|
|
3
2
|
import { isDeepStrictEqual } from "node:util";
|
|
4
|
-
import {
|
|
5
|
-
import { readWorkspaceHistoryLayoutSync } from "../workspace/workspace-config.js";
|
|
3
|
+
import { workspaceHistoryFiles } from "./workspace-history.js";
|
|
6
4
|
import { indexHistory, orderedRawExchanges } from "./history-index.js";
|
|
7
5
|
function orderedExchanges(raw) {
|
|
8
6
|
if (!raw)
|
|
@@ -17,10 +15,15 @@ function orderedExchanges(raw) {
|
|
|
17
15
|
}
|
|
18
16
|
function replaceAssistantSuffix(text, assistantText) {
|
|
19
17
|
const marker = "\n\n助手:\n";
|
|
18
|
+
const section = `助手:\n${assistantText}`;
|
|
19
|
+
if (text === section || text.endsWith("\n\n" + section))
|
|
20
|
+
return text;
|
|
21
|
+
if (!text || text.startsWith("助手:\n"))
|
|
22
|
+
return section;
|
|
20
23
|
const index = text.lastIndexOf(marker);
|
|
21
24
|
if (index >= 0)
|
|
22
25
|
return text.slice(0, index) + marker + assistantText;
|
|
23
|
-
return text
|
|
26
|
+
return text + marker + assistantText;
|
|
24
27
|
}
|
|
25
28
|
function buildSession(host, capture, previous) {
|
|
26
29
|
if (capture.kind === "session") {
|
|
@@ -28,34 +31,44 @@ function buildSession(host, capture, previous) {
|
|
|
28
31
|
}
|
|
29
32
|
const timestamp = capture.timestamp ?? new Date().toISOString();
|
|
30
33
|
const branch = orderedExchanges(previous);
|
|
34
|
+
// entryIds already identify native observations on disk. A turn keeps its ID
|
|
35
|
+
// across steering, attachment-only inputs and Stop hooks arriving out of order.
|
|
36
|
+
const turnEntry = capture.turnId ? `${host}:turn:${capture.turnId}` : undefined;
|
|
37
|
+
const turn = turnEntry ? branch.find(item => item.entryIds.includes(turnEntry)) : undefined;
|
|
38
|
+
const entryId = () => turnEntry ?? `${host}:${Date.now()}:${randomUUID().slice(0, 8)}`;
|
|
31
39
|
if (capture.kind === "input") {
|
|
32
40
|
const text = capture.text.trim();
|
|
33
|
-
if (!text)
|
|
41
|
+
if (!text && !turnEntry)
|
|
34
42
|
return undefined;
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
const input = "用户:\n" + (text || "(无文本输入)");
|
|
44
|
+
if (turn) {
|
|
45
|
+
turn.text += "\n\n" + input;
|
|
46
|
+
turn.to = timestamp;
|
|
47
|
+
turn.completed = false;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
branch.push({ entryIds: [entryId()], text: input, from: timestamp, to: timestamp, completed: false });
|
|
51
|
+
}
|
|
43
52
|
return { sessionId: capture.sessionId, name: previous?.name ?? "", branches: [branch] };
|
|
44
53
|
}
|
|
45
54
|
const assistantText = capture.assistantText.trim();
|
|
46
55
|
if (!assistantText)
|
|
47
56
|
return undefined;
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
57
|
+
const target = turnEntry ? turn : branch.at(-1);
|
|
58
|
+
if (target && (turnEntry || !target.completed || capture.isContinuation)) {
|
|
59
|
+
const updated = turnEntry && !target.completed
|
|
60
|
+
? target.text + "\n\n助手:\n" + assistantText
|
|
61
|
+
: replaceAssistantSuffix(target.text, assistantText);
|
|
62
|
+
if (target.text === updated && target.completed === capture.completed)
|
|
63
|
+
return undefined;
|
|
64
|
+
target.text = updated;
|
|
65
|
+
target.to = timestamp;
|
|
66
|
+
target.completed = capture.completed;
|
|
53
67
|
}
|
|
54
68
|
else {
|
|
55
|
-
const entryId = `${host}:${Date.now()}:${randomUUID().slice(0, 8)}`;
|
|
56
69
|
const userText = capture.userText?.trim();
|
|
57
70
|
branch.push({
|
|
58
|
-
entryIds: [entryId],
|
|
71
|
+
entryIds: [entryId()],
|
|
59
72
|
text: userText ? `用户:\n${userText}\n\n助手:\n${assistantText}` : `助手:\n${assistantText}`,
|
|
60
73
|
from: timestamp,
|
|
61
74
|
to: timestamp,
|
|
@@ -69,8 +82,7 @@ export function recordHistoryCapture(root, host, capture) {
|
|
|
69
82
|
const sessionId = capture.kind === "session" ? capture.session.sessionId : capture.sessionId;
|
|
70
83
|
if (!sessionId)
|
|
71
84
|
return;
|
|
72
|
-
const
|
|
73
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), host, layout);
|
|
85
|
+
const files = workspaceHistoryFiles(root, host);
|
|
74
86
|
files.control(() => {
|
|
75
87
|
const previous = files.listRaw(host).find(raw => raw.sessionId === sessionId);
|
|
76
88
|
if (!previous && files.rawWarnings.length)
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import { lstatSync } from "node:fs";
|
|
2
1
|
import { join } from "node:path";
|
|
3
2
|
import { requireThat } from "../../common/validation.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { rawHistoryBucket, summaryArtifactBucket } from "../../storage/history-files.js";
|
|
4
|
+
import { workspaceHistoryFiles } from "./workspace-history.js";
|
|
6
5
|
/** Read-only check for unmigrated flat history files when running under monthly layout. */
|
|
7
6
|
export function checkHistoryMigrationNotice(root) {
|
|
8
|
-
|
|
9
|
-
if (layout !== "monthly")
|
|
10
|
-
return undefined;
|
|
11
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", layout);
|
|
12
|
-
return files.detectFlatFiles().message;
|
|
7
|
+
return workspaceHistoryFiles(root).migrationNotice();
|
|
13
8
|
}
|
|
14
9
|
/**
|
|
15
10
|
* Explicitly migrate flat .pbot/history/raw/*.json and .pbot/history/summaries/<dim>/*.json
|
|
@@ -17,67 +12,38 @@ export function checkHistoryMigrationNotice(root) {
|
|
|
17
12
|
* and never modifies .pbot/config.json or overwrites existing destinations.
|
|
18
13
|
*/
|
|
19
14
|
export function migrateWorkspaceHistory(root, options = {}) {
|
|
20
|
-
const
|
|
15
|
+
const files = workspaceHistoryFiles(root);
|
|
16
|
+
const { layout } = files;
|
|
21
17
|
requireThat(layout === "monthly", '当前工作区配置为平铺布局(history.layout: "flat"),无需迁移到年月目录;如需迁移,请先在 .pbot/config.json 中将 history.layout 设为 "monthly" 或移除该配置项。');
|
|
22
18
|
const dryRun = Boolean(options.dryRun);
|
|
23
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", "monthly");
|
|
24
19
|
const moved = [];
|
|
25
20
|
const skipped = [];
|
|
26
21
|
const errors = [];
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
moved.push({ kind: "raw", id: raw.id, from, to });
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
const outcome = files.moveHistoryFile(from, to);
|
|
44
|
-
if (outcome === "moved")
|
|
45
|
-
moved.push({ kind: "raw", id: raw.id, from, to });
|
|
46
|
-
else
|
|
47
|
-
skipped.push({ kind: "raw", from, to, reason: "目标路径已存在同名文件。" });
|
|
48
|
-
}
|
|
22
|
+
function migrateFile(name, dimension) {
|
|
23
|
+
const directory = dimension ? `summaries/${dimension}` : "raw";
|
|
24
|
+
const from = `${directory}/${name}`;
|
|
25
|
+
try {
|
|
26
|
+
const record = dimension ? files.readFlatSummaryFile(dimension, name) : files.readFlatRawFile(name);
|
|
27
|
+
const bucket = "dimension" in record ? summaryArtifactBucket(record) : rawHistoryBucket(record);
|
|
28
|
+
const to = `${directory}/${bucket}/${name}`;
|
|
29
|
+
const source = dimension ? { kind: "summary", dimension } : { kind: "raw" };
|
|
30
|
+
if (files.moveHistoryFile(from, to, dryRun) === "conflict") {
|
|
31
|
+
skipped.push({ ...source, from, to, reason: "目标路径已存在同名文件。" });
|
|
49
32
|
}
|
|
50
|
-
|
|
51
|
-
|
|
33
|
+
else {
|
|
34
|
+
moved.push({ ...source, id: record.id, from, to });
|
|
52
35
|
}
|
|
53
36
|
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
errors.push({ path: join(files.directory, from), error: error instanceof Error ? error.message : String(error) });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const run = () => {
|
|
42
|
+
for (const name of files.listFlatRawFiles())
|
|
43
|
+
migrateFile(name);
|
|
54
44
|
for (const dimension of files.listDimensions()) {
|
|
55
|
-
for (const name of files.listFlatSummaryFiles(dimension))
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
const artifact = files.readFlatSummaryFile(dimension, name);
|
|
59
|
-
const bucket = summaryArtifactBucket(artifact);
|
|
60
|
-
const to = `summaries/${dimension}/${bucket}/${name}`;
|
|
61
|
-
if (dryRun) {
|
|
62
|
-
if (lstatSync(join(files.directory, to), { throwIfNoEntry: false })) {
|
|
63
|
-
skipped.push({ kind: "summary", dimension, from, to, reason: "目标路径已存在同名文件。" });
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
moved.push({ kind: "summary", dimension, id: artifact.id, from, to });
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
const outcome = files.moveHistoryFile(from, to);
|
|
71
|
-
if (outcome === "moved")
|
|
72
|
-
moved.push({ kind: "summary", dimension, id: artifact.id, from, to });
|
|
73
|
-
else
|
|
74
|
-
skipped.push({ kind: "summary", dimension, from, to, reason: "目标路径已存在同名文件。" });
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
errors.push({ path: join(files.directory, from), error: error instanceof Error ? error.message : String(error) });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
45
|
+
for (const name of files.listFlatSummaryFiles(dimension))
|
|
46
|
+
migrateFile(name, dimension);
|
|
81
47
|
}
|
|
82
48
|
};
|
|
83
49
|
if (dryRun)
|