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
package/src/model/acp.ts
CHANGED
|
@@ -19,7 +19,8 @@ export interface AcpCommand {
|
|
|
19
19
|
env?: Record<string, string>;
|
|
20
20
|
}
|
|
21
21
|
/** ask: forward target permission requests to the parent session; allow/deny: answer them automatically. */
|
|
22
|
-
export
|
|
22
|
+
export const acpPermissionPolicies = ["ask", "allow", "deny"] as const;
|
|
23
|
+
export type AcpPermissionPolicy = typeof acpPermissionPolicies[number];
|
|
23
24
|
/** Workspace `acp.<name>` entry; omitting `command` keeps a registered harness's default command. */
|
|
24
25
|
export interface AcpHarnessConfig {
|
|
25
26
|
command?: string;
|
|
@@ -48,9 +49,10 @@ export interface AcpModelsResult {
|
|
|
48
49
|
export interface AcpModelState extends AcpModelSelection { generation: string }
|
|
49
50
|
export interface AcpProcess { generation: string; pid: number; startedAt: number }
|
|
50
51
|
export interface AcpInput { generation: string; requestId: string }
|
|
52
|
+
export const acpAnswerStates = ["completed", "failed", "cancelled"] as const;
|
|
51
53
|
export interface AcpAnswer extends AcpInput {
|
|
52
54
|
answer: string;
|
|
53
|
-
state:
|
|
55
|
+
state: typeof acpAnswerStates[number];
|
|
54
56
|
error?: string;
|
|
55
57
|
}
|
|
56
58
|
export interface AcpReport { generation: string; cycleId: string; text: string }
|
|
@@ -61,8 +63,14 @@ export interface AcpPermission {
|
|
|
61
63
|
options: { optionId: string; name: string; kind: string }[];
|
|
62
64
|
}
|
|
63
65
|
export interface AcpPermissionReply { generation: string; requestId: string; optionId: string | null }
|
|
64
|
-
export
|
|
66
|
+
export const acpElicitationActions = ["accept", "decline", "cancel"] as const;
|
|
67
|
+
export type AcpElicitationAction = typeof acpElicitationActions[number];
|
|
65
68
|
export type AcpElicitationValue = string | number | boolean | string[];
|
|
69
|
+
export function isAcpElicitationValue(value: unknown): value is AcpElicitationValue {
|
|
70
|
+
return typeof value === "string" || typeof value === "boolean" || (typeof value === "number" && Number.isFinite(value))
|
|
71
|
+
|| (Array.isArray(value) && value.every(item => typeof item === "string"));
|
|
72
|
+
}
|
|
73
|
+
|
|
66
74
|
export type AcpElicitationContent = Record<string, AcpElicitationValue>;
|
|
67
75
|
export interface AcpElicitation {
|
|
68
76
|
generation: string;
|
package/src/model/agent.ts
CHANGED
|
@@ -9,15 +9,20 @@ export interface AgentDescriptor {
|
|
|
9
9
|
}
|
|
10
10
|
export type AgentSessionReference = AcpSessionReference;
|
|
11
11
|
export interface AgentLaunch { generation: string; name: string; sequence: number; stop: boolean; startedAt: number }
|
|
12
|
-
export
|
|
12
|
+
export const messageDeliveries = ["steer", "followUp"] as const;
|
|
13
|
+
export const cycleStates = ["running", "completed", "failed", "cancelled", "interrupted"] as const;
|
|
14
|
+
export const cycleSources = ["parent", "interactive", "mixed"] as const;
|
|
15
|
+
export const agentStates = ["starting", "busy", "idle", "stopping", "stopped", "error"] as const;
|
|
16
|
+
|
|
17
|
+
export interface AgentMessage { requestId: string; generation: string; sequence: number; message: string; delivery: typeof messageDeliveries[number]; files: string[] }
|
|
13
18
|
export interface AgentCycle {
|
|
14
19
|
cycleId: string; generation: string; startedAt: number; finishedAt?: number;
|
|
15
|
-
state:
|
|
16
|
-
leaf: string | null; requestIds: string[]; source:
|
|
20
|
+
state: typeof cycleStates[number];
|
|
21
|
+
leaf: string | null; requestIds: string[]; source: typeof cycleSources[number];
|
|
17
22
|
error?: string;
|
|
18
23
|
}
|
|
19
24
|
export interface AgentStatus {
|
|
20
|
-
generation: string; state:
|
|
25
|
+
generation: string; state: typeof agentStates[number];
|
|
21
26
|
activity: string; updatedAt: number; accepted?: string[]; cycle?: AgentCycle; error?: string;
|
|
22
27
|
}
|
|
23
28
|
export interface AgentView extends AgentDescriptor {
|
|
@@ -39,3 +44,14 @@ export interface AgentResponseInput {
|
|
|
39
44
|
content?: AcpElicitationContent;
|
|
40
45
|
}
|
|
41
46
|
export interface AgentCompletion { agentId: string; name: string; cycle: AgentCycle; report: string }
|
|
47
|
+
|
|
48
|
+
export interface AgentHost {
|
|
49
|
+
available(backend: AcpBackend): void;
|
|
50
|
+
filterOptions?(backend: AcpBackend, options: AgentOptions): AgentOptions;
|
|
51
|
+
prepare(backend: AcpBackend, options: AgentOptions): AcpSessionReference;
|
|
52
|
+
alive(id: string): boolean;
|
|
53
|
+
validateSession(value: AgentDescriptor, reference: AgentSessionReference): void | Promise<void>;
|
|
54
|
+
launch(value: AgentDescriptor, directory: string, generation: string, reference: AgentSessionReference, resume: boolean, signal: AbortSignal): void | Promise<void>;
|
|
55
|
+
release(id: string, generation: string): void | Promise<void>;
|
|
56
|
+
report(value: AgentDescriptor, reference: AgentSessionReference, leaf: string): string | Promise<string>;
|
|
57
|
+
}
|
package/src/model/history.ts
CHANGED
|
@@ -172,6 +172,11 @@ export interface SummaryRunReport {
|
|
|
172
172
|
warnings: string[];
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
export const historyPageLimits = {
|
|
176
|
+
search: { default: 20, max: 50 },
|
|
177
|
+
read: { default: 12_000, max: 24_000 },
|
|
178
|
+
} as const;
|
|
179
|
+
|
|
175
180
|
export interface HistoryQuery {
|
|
176
181
|
host?: HistoryHost;
|
|
177
182
|
query?: string;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface PluginSpec {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
description: string;
|
|
5
|
+
source: string;
|
|
6
|
+
defaultSelected: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface InstalledPackage {
|
|
9
|
+
source: string;
|
|
10
|
+
scope: "user" | "project";
|
|
11
|
+
name?: string;
|
|
12
|
+
version?: string;
|
|
13
|
+
installedPath?: string;
|
|
14
|
+
filtered: boolean;
|
|
15
|
+
entry: unknown;
|
|
16
|
+
}
|
|
17
|
+
export interface PackageChoice {
|
|
18
|
+
plugin: PluginSpec;
|
|
19
|
+
required: boolean;
|
|
20
|
+
existing: InstalledPackage[];
|
|
21
|
+
selected: boolean;
|
|
22
|
+
keep: boolean;
|
|
23
|
+
target?: string;
|
|
24
|
+
error?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface PiInstallation { command: string; root: string; version: string }
|
|
27
|
+
export interface SystemCommand { command: string; args: string[] }
|
|
28
|
+
export interface SetupPlan {
|
|
29
|
+
workspace: string;
|
|
30
|
+
pi?: PiInstallation;
|
|
31
|
+
piVersion: string;
|
|
32
|
+
tmux?: SystemCommand;
|
|
33
|
+
packages: PackageChoice[];
|
|
34
|
+
}
|
|
35
|
+
export interface SetupResult { name: string; state: "done" | "kept" | "skipped" | "failed"; detail: string }
|
|
36
|
+
export interface SetupOperations {
|
|
37
|
+
installTmux(command: SystemCommand): Promise<void>;
|
|
38
|
+
ensurePi(existing: PiInstallation | undefined, version: string): Promise<PiInstallation>;
|
|
39
|
+
installPackage(pi: PiInstallation, workspace: string, choice: PackageChoice): Promise<string>;
|
|
40
|
+
verifyKeptPackage(pi: PiInstallation, workspace: string, choice: PackageChoice): Promise<string>;
|
|
41
|
+
}
|
package/src/model/plugin-host.ts
CHANGED
|
@@ -24,12 +24,14 @@ export type HistoryCapture =
|
|
|
24
24
|
| {
|
|
25
25
|
kind: "input";
|
|
26
26
|
sessionId: string;
|
|
27
|
+
turnId?: string;
|
|
27
28
|
text: string;
|
|
28
29
|
timestamp?: string;
|
|
29
30
|
}
|
|
30
31
|
| {
|
|
31
32
|
kind: "answer";
|
|
32
33
|
sessionId: string;
|
|
34
|
+
turnId?: string;
|
|
33
35
|
userText?: string;
|
|
34
36
|
assistantText: string;
|
|
35
37
|
completed: boolean;
|
|
@@ -43,17 +45,19 @@ export type HistoryCapture =
|
|
|
43
45
|
|
|
44
46
|
export type HostEvent =
|
|
45
47
|
| { kind: "ignore" }
|
|
46
|
-
| { kind: "inject-context"; role: WorkspaceRole; localRoleOnly?: boolean; isSessionStart?: boolean; cwd: string; raw: unknown }
|
|
48
|
+
| { kind: "inject-context"; role: WorkspaceRole; localRoleOnly?: boolean; isSessionStart?: boolean; noticesOnly?: boolean; cwd: string; raw: unknown }
|
|
47
49
|
| { kind: "check-skill"; skill: string; cwd: string; raw: unknown }
|
|
48
50
|
| { kind: "record-history"; cwd: string; raw: unknown };
|
|
49
51
|
|
|
50
52
|
export interface PluginHostAdapter {
|
|
51
53
|
readonly host: PluginHostId;
|
|
52
54
|
readonly nativeRootAgents: boolean;
|
|
55
|
+
readonly indexBundledSkills?: boolean;
|
|
53
56
|
readonly nativeWorkspaceSkills?: boolean;
|
|
54
57
|
readonly coordinatorPrompt?: string;
|
|
55
58
|
readonly initCommandHint: string;
|
|
56
59
|
readonly usage: string;
|
|
60
|
+
boundWorkspaceRoot?(): string | undefined;
|
|
57
61
|
resolveRoot(cwd: string, rawPayload?: unknown): Promise<string>;
|
|
58
62
|
parseEvent(payload: unknown): HostEvent;
|
|
59
63
|
extractHistory?(event: Extract<HostEvent, { kind: "inject-context" | "record-history" }>): Promise<HistoryCapture | undefined>;
|
|
@@ -7,12 +7,9 @@ export interface WorkspaceFeatures {
|
|
|
7
7
|
history?: boolean;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
readonly mcp: boolean;
|
|
14
|
-
readonly history: boolean;
|
|
15
|
-
}
|
|
10
|
+
export type ResolvedWorkspaceFeatures = Readonly<Required<WorkspaceFeatures>>;
|
|
11
|
+
|
|
12
|
+
export const summaryConcurrency = { default: 3, max: 8 } as const;
|
|
16
13
|
|
|
17
14
|
export interface WorkspaceSummaryConfig {
|
|
18
15
|
backend?: string;
|
|
@@ -28,7 +25,8 @@ export interface ResolvedWorkspaceSummaryConfig {
|
|
|
28
25
|
readonly concurrency: number;
|
|
29
26
|
}
|
|
30
27
|
|
|
31
|
-
export
|
|
28
|
+
export const historyLayouts = ["monthly", "flat"] as const;
|
|
29
|
+
export type HistoryLayout = typeof historyLayouts[number];
|
|
32
30
|
|
|
33
31
|
export interface WorkspaceHistoryConfig {
|
|
34
32
|
layout?: HistoryLayout;
|
|
@@ -46,13 +44,9 @@ export interface WorkspaceConfig {
|
|
|
46
44
|
history?: WorkspaceHistoryConfig;
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
export interface WorkspaceConfiguration {
|
|
47
|
+
export interface WorkspaceConfiguration extends WorkspaceConfig {
|
|
50
48
|
path: string;
|
|
51
49
|
present: boolean;
|
|
52
50
|
enabled: boolean;
|
|
53
51
|
error?: string;
|
|
54
|
-
features?: WorkspaceFeatures;
|
|
55
|
-
acp?: AcpCommands;
|
|
56
|
-
summary?: WorkspaceSummaryConfig;
|
|
57
|
-
history?: WorkspaceHistoryConfig;
|
|
58
52
|
}
|
package/src/pbot.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import { resolve } from "node:path";
|
|
3
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
4
|
-
import { resourceRoot } from "./common/paths.js";
|
|
5
2
|
import { Confirmations } from "./ui/pi/confirmation.js";
|
|
6
|
-
import {
|
|
3
|
+
import { registerPiHistoryTool } from "./tools/history/pi-tool.js";
|
|
7
4
|
import { Lifecycle, WorkspaceInstance } from "./extension/hosts/pi/lifecycle.js";
|
|
8
5
|
import { registerCommand } from "./extension/hosts/pi/command.js";
|
|
9
6
|
import { registerEvents } from "./extension/hosts/pi/events.js";
|
|
10
7
|
import { registerHistoryEvents } from "./extension/hosts/pi/history.js";
|
|
11
8
|
import { McpWorkerRuntime, defaultWorkerDirectory } from "./extension/mcp/workers.js";
|
|
12
9
|
import { workspaceFeatures } from "./services/workspace/workspace-config.js";
|
|
13
|
-
import {
|
|
10
|
+
import { loadNativeWorkspaceServers } from "./extension/hosts/workspace-mcp.js";
|
|
14
11
|
import { toPiMcpConfig } from "./integrations/hosts/pi/mcp.js";
|
|
15
12
|
|
|
16
13
|
const mcpServerName = "pbot";
|
|
@@ -19,8 +16,7 @@ export default function pbot(pi: ExtensionAPI) {
|
|
|
19
16
|
// The explicitly loaded child entry owns the child; normal discovery never grants main privileges.
|
|
20
17
|
if (process.env.PBOT_SUBAGENT_RUN_ID) return;
|
|
21
18
|
const confirmations = new Confirmations();
|
|
22
|
-
|
|
23
|
-
const mcpEntry = resolve(resourceRoot, "../lib/extension/mcp.js");
|
|
19
|
+
let hideHistory: (() => void) | undefined;
|
|
24
20
|
const registeredMcpServers: string[] = [];
|
|
25
21
|
|
|
26
22
|
const lifecycle = new Lifecycle(
|
|
@@ -30,20 +26,12 @@ export default function pbot(pi: ExtensionAPI) {
|
|
|
30
26
|
return new WorkspaceInstance(root, sessionId, workers, workspaceFeatures(configuration));
|
|
31
27
|
},
|
|
32
28
|
async instance => {
|
|
33
|
-
if (instance.features.history)
|
|
34
|
-
|
|
29
|
+
if (instance.features.history) hideHistory = registerPiHistoryTool(pi, instance.root, instance);
|
|
30
|
+
const server = instance.workers.nativeServer(instance.root);
|
|
31
|
+
if (server) {
|
|
35
32
|
pi.registerMcpServer(mcpServerName, {
|
|
36
33
|
type: "stdio",
|
|
37
|
-
|
|
38
|
-
args: [mcpEntry],
|
|
39
|
-
env: {
|
|
40
|
-
PBOT_HOST: "pi",
|
|
41
|
-
PBOT_WORKSPACE_ROOT: instance.root,
|
|
42
|
-
PBOT_MCP_AGENT_DIR: defaultWorkerDirectory(),
|
|
43
|
-
PBOT_MCP_SESSION_ID: instance.sessionId,
|
|
44
|
-
PBOT_NATIVE_WORKSPACE_MCP: "1",
|
|
45
|
-
PBOT_NATIVE_HISTORY: "1",
|
|
46
|
-
},
|
|
34
|
+
...server,
|
|
47
35
|
exposure: "direct",
|
|
48
36
|
timeout: 600,
|
|
49
37
|
description: "跨代理程序委派(worker_*)",
|
|
@@ -51,22 +39,15 @@ export default function pbot(pi: ExtensionAPI) {
|
|
|
51
39
|
registeredMcpServers.push(mcpServerName);
|
|
52
40
|
}
|
|
53
41
|
if (instance.features.mcp) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (server.enabled === false) continue;
|
|
59
|
-
try {
|
|
60
|
-
const resolved = resolveWorkspaceMcpServer(instance.root, name, server);
|
|
61
|
-
pi.registerMcpServer(resolved.name, toPiMcpConfig(resolved));
|
|
62
|
-
registeredMcpServers.push(resolved.name);
|
|
63
|
-
} catch { /* Keep the workspace active even if one external MCP env var is unset. */ }
|
|
64
|
-
}
|
|
65
|
-
}
|
|
42
|
+
await loadNativeWorkspaceServers(instance.root, server => {
|
|
43
|
+
pi.registerMcpServer(server.name, toPiMcpConfig(server));
|
|
44
|
+
registeredMcpServers.push(server.name);
|
|
45
|
+
}, { check: () => instance.check() });
|
|
66
46
|
}
|
|
67
47
|
},
|
|
68
48
|
() => {
|
|
69
|
-
|
|
49
|
+
hideHistory?.();
|
|
50
|
+
hideHistory = undefined;
|
|
70
51
|
for (const name of registeredMcpServers.splice(0)) {
|
|
71
52
|
pi.unregisterMcpServer(name);
|
|
72
53
|
}
|
package/src/plugin.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { realpathSync } from "node:fs";
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
3
|
import { requireThat } from "./common/validation.js";
|
|
4
|
-
import { runPluginHost } from "./extension/hosts/plugin-runtime.js";
|
|
4
|
+
import { runPluginHost, type ReplayPluginHook } from "./extension/hosts/plugin-runtime.js";
|
|
5
5
|
import { listPluginHosts, pluginHosts } from "./integrations/hosts/plugin-registry.js";
|
|
6
6
|
|
|
7
|
-
export async function main(args: readonly string[]): Promise<void> {
|
|
7
|
+
export async function main(args: readonly string[], replayHook?: ReplayPluginHook): Promise<void> {
|
|
8
8
|
const [host, ...rest] = args;
|
|
9
9
|
const adapter = host ? pluginHosts.get(host) : undefined;
|
|
10
10
|
requireThat(adapter, `用法:node <插件目录>/lib/plugin.js <${listPluginHosts().join("|")}> hook|init|status`);
|
|
11
|
-
await runPluginHost(adapter, rest);
|
|
11
|
+
await runPluginHost(adapter, rest, replayHook);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
|
|
@@ -5,24 +5,14 @@ import { object } from "../../common/json.js";
|
|
|
5
5
|
import { packageVersion, releaseLine } from "../../common/version.js";
|
|
6
6
|
import { requireThat } from "../../common/validation.js";
|
|
7
7
|
import { AgentFiles, descriptor, launch, status, cycle } from "../../storage/agent-files.js";
|
|
8
|
-
import type { AgentOwner, AgentOptions, AgentPendingRequest, AgentResponseInput, AgentStartOptions, AgentDescriptor, AgentCycle,
|
|
9
|
-
import type { AcpBackend, AcpSessionReference } from "../../model/acp.js";
|
|
8
|
+
import type { AgentOwner, AgentOptions, AgentMessage, AgentPendingRequest, AgentResponseInput, AgentStartOptions, AgentDescriptor, AgentCycle, AgentHost, AgentView } from "../../model/agent.js";
|
|
10
9
|
import { acpElicitationReply, acpModelState, acpPermissionReply, acpReference } from "../../storage/acp-files.js";
|
|
11
10
|
|
|
12
|
-
export
|
|
13
|
-
available(backend: AcpBackend): void;
|
|
14
|
-
filterOptions?(backend: AcpBackend, options: AgentOptions): AgentOptions;
|
|
15
|
-
prepare(backend: AcpBackend, options: AgentOptions): AcpSessionReference;
|
|
16
|
-
alive(id: string): boolean;
|
|
17
|
-
validateSession(value: AgentDescriptor, reference: AgentSessionReference): void | Promise<void>;
|
|
18
|
-
launch(value: AgentDescriptor, directory: string, generation: string, reference: AgentSessionReference, resume: boolean, signal: AbortSignal): void | Promise<void>;
|
|
19
|
-
release(id: string, generation: string): void | Promise<void>;
|
|
20
|
-
report(value: AgentDescriptor, reference: AgentSessionReference, leaf: string): string | Promise<string>;
|
|
21
|
-
}
|
|
11
|
+
export type { AgentHost } from "../../model/agent.js";
|
|
22
12
|
|
|
23
13
|
/** Host-neutral lifecycle manager for cross-harness ACP workers. */
|
|
24
14
|
export class AgentService {
|
|
25
|
-
readonly files: AgentFiles;
|
|
15
|
+
private readonly files: AgentFiles;
|
|
26
16
|
#closed = false;
|
|
27
17
|
#preserve = false;
|
|
28
18
|
readonly #starting = new Map<string, { generation: string; controller: AbortController; stage: "validate" | "launch" }>();
|
|
@@ -218,7 +208,7 @@ export class AgentService {
|
|
|
218
208
|
try { await operation; } finally { this.#launches.delete(operation); }
|
|
219
209
|
}
|
|
220
210
|
|
|
221
|
-
send(id: string, text: string, delivery: "
|
|
211
|
+
send(id: string, text: string, delivery: AgentMessage["delivery"], owner: AgentOwner, attachments: readonly string[] = []) {
|
|
222
212
|
const d = this.get(id, owner);
|
|
223
213
|
return this.files.control(() => {
|
|
224
214
|
requireThat(this.alive(id) && this.#starting.get(id)?.stage !== "validate" && !this.files.read(id, "launch.json", launch).stop, "worker 已停止或仍在恢复校验,请等待显式恢复完成。");
|
|
@@ -298,7 +288,12 @@ export class AgentService {
|
|
|
298
288
|
}
|
|
299
289
|
|
|
300
290
|
cycles(id: string, owner: AgentOwner): AgentCycle[] {
|
|
301
|
-
|
|
291
|
+
return this.cyclesFor(this.view(this.get(id, owner), owner));
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
private cyclesFor(view: AgentView): AgentCycle[] {
|
|
295
|
+
const id = view.agentId;
|
|
296
|
+
const values = this.files.completions(id);
|
|
302
297
|
if (view.cycle && !values.some(c => c.cycleId === view.cycle!.cycleId)) {
|
|
303
298
|
values.push(view.state === "stopped" || view.state === "error" ? { ...view.cycle, state: "interrupted", finishedAt: view.cycle.finishedAt ?? Date.now() } : view.cycle);
|
|
304
299
|
}
|
|
@@ -321,9 +316,26 @@ export class AgentService {
|
|
|
321
316
|
return values;
|
|
322
317
|
}
|
|
323
318
|
|
|
319
|
+
private snapshot(id: string, owner: AgentOwner) {
|
|
320
|
+
const view = this.view(this.get(id, owner), owner);
|
|
321
|
+
const cycles = this.cyclesFor(view);
|
|
322
|
+
const latest = cycles.at(-1);
|
|
323
|
+
return { current: latest ? { ...view, cycle: latest } : view, cycles };
|
|
324
|
+
}
|
|
325
|
+
|
|
324
326
|
status(id: string, owner: AgentOwner) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
+
return this.snapshot(id, owner).current;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
outputStatus(id: string, owner: AgentOwner, requestId?: string) {
|
|
331
|
+
const { current, cycles } = this.snapshot(id, owner);
|
|
332
|
+
const request = requestId ?? this.files.messages(id).findLast(item => item.generation === current.generation)?.requestId;
|
|
333
|
+
const cycle = request
|
|
334
|
+
? cycles.find(item => item.generation === current.generation && item.requestIds.includes(request))
|
|
335
|
+
: current.cycle;
|
|
336
|
+
const stopped = current.state === "stopped" || current.state === "error";
|
|
337
|
+
const terminal = request ? stopped && !cycle : stopped || (current.state === "idle" && !cycle);
|
|
338
|
+
return { current, cycle, terminal };
|
|
327
339
|
}
|
|
328
340
|
|
|
329
341
|
async read(id: string, owner: AgentOwner, cycleId?: string, offset = 0, limit = 16000) {
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { join } from "node:path";
|
|
3
2
|
import { isDeepStrictEqual } from "node:util";
|
|
4
3
|
import type { HistoryExchange, HistoryHost, HistorySession, RawHistory } from "../../model/history.js";
|
|
5
4
|
import type { HistoryCapture } from "../../model/plugin-host.js";
|
|
6
|
-
import {
|
|
7
|
-
import { readWorkspaceHistoryLayoutSync } from "../workspace/workspace-config.js";
|
|
5
|
+
import { workspaceHistoryFiles } from "./workspace-history.js";
|
|
8
6
|
import { indexHistory, orderedRawExchanges } from "./history-index.js";
|
|
9
7
|
|
|
10
8
|
function orderedExchanges(raw?: RawHistory): HistoryExchange[] {
|
|
@@ -20,9 +18,12 @@ function orderedExchanges(raw?: RawHistory): HistoryExchange[] {
|
|
|
20
18
|
|
|
21
19
|
function replaceAssistantSuffix(text: string, assistantText: string): string {
|
|
22
20
|
const marker = "\n\n助手:\n";
|
|
21
|
+
const section = `助手:\n${assistantText}`;
|
|
22
|
+
if (text === section || text.endsWith("\n\n" + section)) return text;
|
|
23
|
+
if (!text || text.startsWith("助手:\n")) return section;
|
|
23
24
|
const index = text.lastIndexOf(marker);
|
|
24
25
|
if (index >= 0) return text.slice(0, index) + marker + assistantText;
|
|
25
|
-
return text
|
|
26
|
+
return text + marker + assistantText;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
function buildSession(host: HistoryHost, capture: HistoryCapture, previous?: RawHistory): HistorySession | undefined {
|
|
@@ -31,31 +32,39 @@ function buildSession(host: HistoryHost, capture: HistoryCapture, previous?: Raw
|
|
|
31
32
|
}
|
|
32
33
|
const timestamp = capture.timestamp ?? new Date().toISOString();
|
|
33
34
|
const branch = orderedExchanges(previous);
|
|
35
|
+
// entryIds already identify native observations on disk. A turn keeps its ID
|
|
36
|
+
// across steering, attachment-only inputs and Stop hooks arriving out of order.
|
|
37
|
+
const turnEntry = capture.turnId ? `${host}:turn:${capture.turnId}` : undefined;
|
|
38
|
+
const turn = turnEntry ? branch.find(item => item.entryIds.includes(turnEntry)) : undefined;
|
|
39
|
+
const entryId = () => turnEntry ?? `${host}:${Date.now()}:${randomUUID().slice(0, 8)}`;
|
|
34
40
|
if (capture.kind === "input") {
|
|
35
41
|
const text = capture.text.trim();
|
|
36
|
-
if (!text) return undefined;
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
completed: false
|
|
44
|
-
}
|
|
42
|
+
if (!text && !turnEntry) return undefined;
|
|
43
|
+
const input = "用户:\n" + (text || "(无文本输入)");
|
|
44
|
+
if (turn) {
|
|
45
|
+
turn.text += "\n\n" + input;
|
|
46
|
+
turn.to = timestamp;
|
|
47
|
+
turn.completed = false;
|
|
48
|
+
} else {
|
|
49
|
+
branch.push({ entryIds: [entryId()], text: input, from: timestamp, to: timestamp, completed: false });
|
|
50
|
+
}
|
|
45
51
|
return { sessionId: capture.sessionId, name: previous?.name ?? "", branches: [branch] };
|
|
46
52
|
}
|
|
47
53
|
const assistantText = capture.assistantText.trim();
|
|
48
54
|
if (!assistantText) return undefined;
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
const target = turnEntry ? turn : branch.at(-1);
|
|
56
|
+
if (target && (turnEntry || !target.completed || capture.isContinuation)) {
|
|
57
|
+
const updated = turnEntry && !target.completed
|
|
58
|
+
? target.text + "\n\n助手:\n" + assistantText
|
|
59
|
+
: replaceAssistantSuffix(target.text, assistantText);
|
|
60
|
+
if (target.text === updated && target.completed === capture.completed) return undefined;
|
|
61
|
+
target.text = updated;
|
|
62
|
+
target.to = timestamp;
|
|
63
|
+
target.completed = capture.completed;
|
|
54
64
|
} else {
|
|
55
|
-
const entryId = `${host}:${Date.now()}:${randomUUID().slice(0, 8)}`;
|
|
56
65
|
const userText = capture.userText?.trim();
|
|
57
66
|
branch.push({
|
|
58
|
-
entryIds: [entryId],
|
|
67
|
+
entryIds: [entryId()],
|
|
59
68
|
text: userText ? `用户:\n${userText}\n\n助手:\n${assistantText}` : `助手:\n${assistantText}`,
|
|
60
69
|
from: timestamp,
|
|
61
70
|
to: timestamp,
|
|
@@ -69,8 +78,7 @@ function buildSession(host: HistoryHost, capture: HistoryCapture, previous?: Raw
|
|
|
69
78
|
export function recordHistoryCapture(root: string, host: HistoryHost, capture: HistoryCapture): void {
|
|
70
79
|
const sessionId = capture.kind === "session" ? capture.session.sessionId : capture.sessionId;
|
|
71
80
|
if (!sessionId) return;
|
|
72
|
-
const
|
|
73
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), host, layout);
|
|
81
|
+
const files = workspaceHistoryFiles(root, host);
|
|
74
82
|
files.control(() => {
|
|
75
83
|
const previous = files.listRaw(host).find(raw => raw.sessionId === sessionId);
|
|
76
84
|
if (!previous && files.rawWarnings.length) return;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { lstatSync } from "node:fs";
|
|
2
1
|
import { join } from "node:path";
|
|
3
2
|
import { requireThat } from "../../common/validation.js";
|
|
4
3
|
import type { HistoryMigrationConflict, HistoryMigrationItem, HistoryMigrationReport } from "../../model/history.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { rawHistoryBucket, summaryArtifactBucket } from "../../storage/history-files.js";
|
|
5
|
+
import { workspaceHistoryFiles } from "./workspace-history.js";
|
|
7
6
|
|
|
8
7
|
export interface MigrateHistoryOptions {
|
|
9
8
|
dryRun?: boolean;
|
|
@@ -11,10 +10,7 @@ export interface MigrateHistoryOptions {
|
|
|
11
10
|
|
|
12
11
|
/** Read-only check for unmigrated flat history files when running under monthly layout. */
|
|
13
12
|
export function checkHistoryMigrationNotice(root: string): string | undefined {
|
|
14
|
-
|
|
15
|
-
if (layout !== "monthly") return undefined;
|
|
16
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", layout);
|
|
17
|
-
return files.detectFlatFiles().message;
|
|
13
|
+
return workspaceHistoryFiles(root).migrationNotice();
|
|
18
14
|
}
|
|
19
15
|
|
|
20
16
|
/**
|
|
@@ -23,62 +19,39 @@ export function checkHistoryMigrationNotice(root: string): string | undefined {
|
|
|
23
19
|
* and never modifies .pbot/config.json or overwrites existing destinations.
|
|
24
20
|
*/
|
|
25
21
|
export function migrateWorkspaceHistory(root: string, options: MigrateHistoryOptions = {}): HistoryMigrationReport {
|
|
26
|
-
const
|
|
22
|
+
const files = workspaceHistoryFiles(root);
|
|
23
|
+
const { layout } = files;
|
|
27
24
|
requireThat(
|
|
28
25
|
layout === "monthly",
|
|
29
26
|
'当前工作区配置为平铺布局(history.layout: "flat"),无需迁移到年月目录;如需迁移,请先在 .pbot/config.json 中将 history.layout 设为 "monthly" 或移除该配置项。',
|
|
30
27
|
);
|
|
31
28
|
const dryRun = Boolean(options.dryRun);
|
|
32
|
-
const files = new HistoryFiles(join(root, ".pbot/history"), "pi", "monthly");
|
|
33
29
|
const moved: HistoryMigrationItem[] = [];
|
|
34
30
|
const skipped: HistoryMigrationConflict[] = [];
|
|
35
31
|
const errors: { path: string; error: string }[] = [];
|
|
36
32
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
const outcome = files.moveHistoryFile(from, to);
|
|
52
|
-
if (outcome === "moved") moved.push({ kind: "raw", id: raw.id, from, to });
|
|
53
|
-
else skipped.push({ kind: "raw", from, to, reason: "目标路径已存在同名文件。" });
|
|
54
|
-
}
|
|
55
|
-
} catch (error) {
|
|
56
|
-
errors.push({ path: join(files.directory, from), error: error instanceof Error ? error.message : String(error) });
|
|
33
|
+
function migrateFile(name: string, dimension?: string) {
|
|
34
|
+
const directory = dimension ? `summaries/${dimension}` : "raw";
|
|
35
|
+
const from = `${directory}/${name}`;
|
|
36
|
+
try {
|
|
37
|
+
const record = dimension ? files.readFlatSummaryFile(dimension, name) : files.readFlatRawFile(name);
|
|
38
|
+
const bucket = "dimension" in record ? summaryArtifactBucket(record) : rawHistoryBucket(record);
|
|
39
|
+
const to = `${directory}/${bucket}/${name}`;
|
|
40
|
+
const source = dimension ? { kind: "summary" as const, dimension } : { kind: "raw" as const };
|
|
41
|
+
if (files.moveHistoryFile(from, to, dryRun) === "conflict") {
|
|
42
|
+
skipped.push({ ...source, from, to, reason: "目标路径已存在同名文件。" });
|
|
43
|
+
} else {
|
|
44
|
+
moved.push({ ...source, id: record.id, from, to });
|
|
57
45
|
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
errors.push({ path: join(files.directory, from), error: error instanceof Error ? error.message : String(error) });
|
|
58
48
|
}
|
|
49
|
+
}
|
|
59
50
|
|
|
51
|
+
const run = () => {
|
|
52
|
+
for (const name of files.listFlatRawFiles()) migrateFile(name);
|
|
60
53
|
for (const dimension of files.listDimensions()) {
|
|
61
|
-
for (const name of files.listFlatSummaryFiles(dimension))
|
|
62
|
-
const from = `summaries/${dimension}/${name}`;
|
|
63
|
-
try {
|
|
64
|
-
const artifact = files.readFlatSummaryFile(dimension, name);
|
|
65
|
-
const bucket = summaryArtifactBucket(artifact);
|
|
66
|
-
const to = `summaries/${dimension}/${bucket}/${name}`;
|
|
67
|
-
if (dryRun) {
|
|
68
|
-
if (lstatSync(join(files.directory, to), { throwIfNoEntry: false })) {
|
|
69
|
-
skipped.push({ kind: "summary", dimension, from, to, reason: "目标路径已存在同名文件。" });
|
|
70
|
-
} else {
|
|
71
|
-
moved.push({ kind: "summary", dimension, id: artifact.id, from, to });
|
|
72
|
-
}
|
|
73
|
-
} else {
|
|
74
|
-
const outcome = files.moveHistoryFile(from, to);
|
|
75
|
-
if (outcome === "moved") moved.push({ kind: "summary", dimension, id: artifact.id, from, to });
|
|
76
|
-
else skipped.push({ kind: "summary", dimension, from, to, reason: "目标路径已存在同名文件。" });
|
|
77
|
-
}
|
|
78
|
-
} catch (error) {
|
|
79
|
-
errors.push({ path: join(files.directory, from), error: error instanceof Error ? error.message : String(error) });
|
|
80
|
-
}
|
|
81
|
-
}
|
|
54
|
+
for (const name of files.listFlatSummaryFiles(dimension)) migrateFile(name, dimension);
|
|
82
55
|
}
|
|
83
56
|
};
|
|
84
57
|
|