personal-bot 0.2.20 → 0.3.1
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 +3 -3
- package/.claude-plugin/plugin.json +2 -5
- package/.mcp.json +11 -0
- package/CONTEXT.md +17 -73
- package/README.md +41 -120
- package/README.zh-CN.md +41 -120
- package/docs/README.md +31 -23
- package/docs/architecture/design.md +74 -0
- package/docs/architecture/extensibility.md +78 -0
- package/docs/architecture/model-context.md +31 -0
- package/docs/architecture/model-instruction-guidelines.md +34 -0
- package/docs/architecture/principles.md +33 -0
- package/docs/guides/capabilities.md +36 -0
- package/docs/guides/cross-harness-workers.md +83 -0
- package/docs/guides/history.md +25 -0
- package/docs/guides/workspace-configuration.md +102 -0
- package/docs/hosts/antigravity.md +52 -0
- package/docs/hosts/claude-code.md +47 -0
- package/docs/hosts/dsh.md +67 -0
- package/docs/hosts/pi.md +49 -0
- package/docs/maintainers/release.md +59 -0
- package/hooks/hooks.json +0 -3
- package/lib/antigravity-plugin/hooks.json +23 -0
- package/lib/antigravity-plugin/lib/claude.d.ts +1 -0
- package/lib/antigravity-plugin/lib/claude.js +13 -0
- package/lib/antigravity-plugin/lib/common/json.d.ts +6 -0
- package/lib/antigravity-plugin/lib/common/json.js +16 -0
- package/lib/antigravity-plugin/lib/common/paths.d.ts +1 -0
- package/lib/antigravity-plugin/lib/common/paths.js +2 -0
- package/lib/antigravity-plugin/lib/common/validation.d.ts +3 -0
- package/lib/antigravity-plugin/lib/common/validation.js +8 -0
- package/lib/antigravity-plugin/lib/common/version.d.ts +3 -0
- package/lib/antigravity-plugin/lib/common/version.js +13 -0
- package/lib/antigravity-plugin/lib/extension/acp-worker.js +11597 -0
- package/lib/antigravity-plugin/lib/extension/mcp.js +2715 -0
- package/lib/antigravity-plugin/lib/extension/plugin-runtime.d.ts +10 -0
- package/lib/antigravity-plugin/lib/extension/plugin-runtime.js +67 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.d.ts +16 -0
- package/lib/antigravity-plugin/lib/integrations/agent-resources.js +56 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.d.ts +4 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/antigravity.js +79 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/claude.d.ts +3 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/claude.js +60 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/registry.d.ts +15 -0
- package/lib/antigravity-plugin/lib/integrations/hosts/registry.js +34 -0
- package/lib/antigravity-plugin/lib/model/acp.d.ts +164 -0
- package/lib/antigravity-plugin/lib/model/acp.js +12 -0
- package/lib/antigravity-plugin/lib/model/plugin-host.d.ts +48 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.d.ts +24 -0
- package/lib/antigravity-plugin/lib/model/workspace-config.js +1 -0
- package/lib/antigravity-plugin/lib/model/workspace-mcp.d.ts +51 -0
- package/lib/antigravity-plugin/lib/model/workspace-mcp.js +4 -0
- package/lib/antigravity-plugin/lib/plugin.d.ts +1 -0
- package/lib/antigravity-plugin/lib/plugin.js +17 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.d.ts +8 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-config.js +95 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-preparation.d.ts +3 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-preparation.js +26 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.d.ts +8 -0
- package/lib/antigravity-plugin/lib/services/workspace/workspace-skills.js +91 -0
- package/lib/antigravity-plugin/lib/storage/atomic-json.d.ts +11 -0
- package/lib/antigravity-plugin/lib/storage/atomic-json.js +101 -0
- package/lib/antigravity-plugin/mcp_config.json +13 -0
- package/lib/antigravity-plugin/package.json +6 -0
- package/lib/antigravity-plugin/plugin.json +7 -0
- package/lib/antigravity-plugin/resources/agents/coordinator.md +11 -0
- package/{resources/claude → lib/antigravity-plugin/resources}/agents/general-purpose.md +0 -5
- package/lib/antigravity-plugin/resources/prompts/plugin-coordinator.md +1 -0
- package/lib/antigravity-plugin/resources/prompts/workspace.md +31 -0
- package/lib/antigravity-plugin/resources/references/compute-finance.md +22 -0
- package/lib/antigravity-plugin/resources/references/compute.md +16 -0
- package/lib/antigravity-plugin/resources/references/task-conductor.md +25 -0
- package/lib/antigravity-plugin/resources/templates/workspace-agents.md +21 -0
- package/lib/antigravity-plugin/skills/pbot/SKILL.md +16 -0
- package/lib/antigravity-plugin/skills/project-maintenance/SKILL.md +35 -0
- package/lib/antigravity-plugin/skills/provider-connections/SKILL.md +42 -0
- package/lib/claude.js +4 -11
- package/lib/client.js +14 -531
- package/lib/common/markdown.js +2 -3
- package/lib/common/validation.d.ts +2 -0
- package/lib/common/validation.js +4 -0
- package/lib/extension/acp-member.d.ts +2 -0
- package/lib/extension/acp-member.js +9 -8
- package/lib/extension/acp-worker.js +11578 -121
- package/lib/extension/dsh/acp-member.js +26 -2
- package/lib/extension/dsh/command.js +19 -57
- package/lib/extension/dsh/history.js +2 -4
- package/lib/extension/dsh/management.d.ts +0 -2
- package/lib/extension/dsh/management.js +27 -126
- package/lib/extension/dsh/workspace.d.ts +5 -47
- package/lib/extension/dsh/workspace.js +76 -108
- package/lib/extension/mcp-bridge.d.ts +41 -0
- package/lib/extension/mcp-bridge.js +412 -0
- package/lib/extension/mcp-workers.d.ts +980 -0
- package/lib/extension/mcp-workers.js +882 -0
- package/lib/extension/mcp.js +2715 -0
- package/lib/extension/plugin-runtime.d.ts +10 -0
- package/lib/extension/plugin-runtime.js +67 -0
- package/lib/extension/setup-cli.js +215 -2
- package/lib/integrations/acp/agents.d.ts +10 -11
- package/lib/integrations/acp/agents.js +65 -33
- package/lib/integrations/acp/claude.d.ts +2 -2
- package/lib/integrations/acp/claude.js +5 -3
- package/lib/integrations/acp/connection.d.ts +17 -4
- package/lib/integrations/acp/connection.js +53 -27
- package/lib/integrations/acp/executable.d.ts +3 -0
- package/lib/integrations/acp/executable.js +42 -0
- package/lib/integrations/acp/harnesses/claude.d.ts +2 -0
- package/lib/integrations/acp/harnesses/claude.js +49 -0
- package/lib/integrations/acp/harnesses/dsh.d.ts +2 -0
- package/lib/integrations/acp/harnesses/dsh.js +35 -0
- package/lib/integrations/acp/harnesses/generic.d.ts +13 -0
- package/lib/integrations/acp/harnesses/generic.js +37 -0
- package/lib/integrations/acp/harnesses/pi.d.ts +2 -0
- package/lib/integrations/acp/harnesses/pi.js +34 -0
- package/lib/integrations/acp/harnesses/presets.d.ts +3 -0
- package/lib/integrations/acp/harnesses/presets.js +20 -0
- package/lib/integrations/acp/launch.d.ts +33 -4
- package/lib/integrations/acp/launch.js +60 -48
- package/lib/integrations/acp/mcp.d.ts +6 -0
- package/lib/integrations/acp/mcp.js +40 -0
- package/lib/integrations/acp/model-selection.d.ts +9 -2
- package/lib/integrations/acp/model-selection.js +73 -27
- package/lib/integrations/acp/registry.d.ts +18 -0
- package/lib/integrations/acp/registry.js +50 -0
- package/lib/integrations/agent-resources.d.ts +16 -1
- package/lib/integrations/agent-resources.js +45 -9
- package/lib/integrations/dsh/mcp.d.ts +4 -0
- package/lib/integrations/dsh/mcp.js +28 -0
- package/lib/integrations/dsh/resources.d.ts +3 -3
- package/lib/integrations/dsh/resources.js +21 -12
- package/lib/integrations/dsh/skills.d.ts +5 -1
- package/lib/integrations/dsh/skills.js +10 -6
- package/lib/integrations/hosts/antigravity.d.ts +4 -0
- package/lib/integrations/hosts/antigravity.js +79 -0
- package/lib/integrations/hosts/claude.d.ts +3 -0
- package/lib/integrations/hosts/claude.js +60 -0
- package/lib/integrations/hosts/registry.d.ts +15 -0
- package/lib/integrations/hosts/registry.js +34 -0
- package/lib/model/acp.d.ts +107 -2
- package/lib/model/acp.js +12 -1
- package/lib/model/agent.d.ts +35 -33
- package/lib/model/plugin-host.d.ts +48 -0
- package/lib/model/plugin-host.js +1 -0
- package/lib/model/workspace-config.d.ts +12 -0
- package/lib/model/workspace-mcp.d.ts +51 -0
- package/lib/model/workspace-mcp.js +4 -0
- package/lib/plugin.d.ts +1 -0
- package/lib/plugin.js +17 -0
- package/lib/services/agents/acp-run.d.ts +13 -1
- package/lib/services/agents/acp-run.js +30 -2
- package/lib/services/agents/agent-service.d.ts +35 -120
- package/lib/services/agents/agent-service.js +156 -160
- package/lib/services/installation/setup-service.js +17 -1
- package/lib/services/workspace/workspace-config.d.ts +2 -1
- package/lib/services/workspace/workspace-config.js +43 -9
- package/lib/services/workspace/workspace-mcp.d.ts +14 -0
- package/lib/services/workspace/workspace-mcp.js +200 -0
- package/lib/services/workspace/workspace-skills.d.ts +8 -0
- package/lib/services/workspace/workspace-skills.js +91 -0
- package/lib/storage/acp-files.d.ts +3 -1
- package/lib/storage/acp-files.js +32 -2
- package/lib/storage/acp-history.d.ts +3 -2
- package/lib/storage/acp-history.js +19 -7
- package/lib/storage/agent-files.d.ts +8 -8
- package/lib/storage/agent-files.js +27 -47
- package/lib/tools/history/contract.d.ts +1 -1
- package/lib/tools/history/contract.js +17 -11
- package/lib/ui/dsh/index.js +8 -3
- package/lib/ui/dsh/management.d.ts +1 -1
- package/lib/ui/dsh/management.js +24 -456
- package/lib/ui/dsh/remote.d.ts +0 -2
- package/lib/ui/dsh/remote.js +1 -1
- package/package.json +12 -7
- package/resources/agents/coordinator.md +2 -2
- package/resources/antigravity/skills/pbot/SKILL.md +16 -0
- package/resources/claude/skills/pbot/SKILL.md +1 -1
- package/resources/prompts/history-coordinator.md +1 -0
- package/resources/prompts/plugin-coordinator.md +1 -0
- package/resources/prompts/workspace.md +9 -8
- package/resources/references/compute.md +9 -11
- package/resources/references/task-conductor.md +12 -26
- package/resources/skills/project-maintenance/SKILL.md +16 -21
- package/resources/skills/provider-connections/SKILL.md +24 -40
- package/resources/templates/workspace-agents.md +4 -0
- package/scripts/README.md +17 -34
- package/src/claude.ts +4 -8
- package/src/common/markdown.ts +2 -3
- package/src/common/validation.ts +6 -0
- package/src/extension/acp-member.ts +9 -8
- package/src/extension/acp-worker.ts +239 -97
- package/src/extension/command.ts +38 -36
- package/src/extension/dsh/acp-member.ts +21 -2
- package/src/extension/dsh/command.ts +21 -51
- package/src/extension/dsh/files.ts +1 -0
- package/src/extension/dsh/history.ts +9 -6
- package/src/extension/dsh/management.ts +27 -58
- package/src/extension/dsh/workspace.ts +88 -99
- package/src/extension/events.ts +13 -10
- package/src/extension/history.ts +2 -50
- package/src/extension/lifecycle.ts +37 -22
- package/src/extension/mcp-bridge.ts +412 -0
- package/src/extension/mcp-workers.ts +941 -0
- package/src/extension/pi-acp-member.ts +29 -5
- package/src/extension/plugin-runtime.ts +63 -0
- package/src/extension/setup-cli.ts +186 -2
- package/src/integrations/acp/agents.ts +70 -24
- package/src/integrations/acp/claude.ts +11 -4
- package/src/integrations/acp/connection.ts +63 -25
- package/src/integrations/acp/executable.ts +41 -0
- package/src/integrations/acp/harnesses/claude.ts +50 -0
- package/src/integrations/acp/harnesses/dsh.ts +40 -0
- package/src/integrations/acp/harnesses/generic.ts +52 -0
- package/src/integrations/acp/harnesses/pi.ts +35 -0
- package/src/integrations/acp/harnesses/presets.ts +22 -0
- package/src/integrations/acp/launch.ts +69 -47
- package/src/integrations/acp/mcp.ts +43 -0
- package/src/integrations/acp/model-selection.ts +68 -25
- package/src/integrations/acp/registry.ts +60 -0
- package/src/integrations/agent-resources.ts +70 -6
- package/src/integrations/dsh/mcp.ts +30 -0
- package/src/integrations/dsh/resources.ts +28 -13
- package/src/integrations/dsh/skills.ts +16 -6
- package/src/integrations/hosts/antigravity.ts +83 -0
- package/src/integrations/hosts/claude.ts +62 -0
- package/src/integrations/hosts/registry.ts +42 -0
- package/src/integrations/pi/mcp.ts +26 -0
- package/src/mcp.ts +14 -0
- package/src/model/acp.ts +113 -3
- package/src/model/agent.ts +18 -14
- package/src/model/plugin-host.ts +39 -0
- package/src/model/workspace-config.ts +14 -0
- package/src/model/workspace-mcp.ts +64 -0
- package/src/pbot.ts +69 -20
- package/src/plugin.ts +19 -0
- package/src/services/agents/acp-run.ts +35 -3
- package/src/services/agents/agent-service.ts +180 -160
- package/src/services/installation/setup-service.ts +17 -2
- package/src/services/workspace/workspace-config.ts +46 -8
- package/src/services/workspace/workspace-mcp.ts +242 -0
- package/src/services/workspace/workspace-skills.ts +78 -0
- package/src/storage/acp-files.ts +32 -3
- package/src/storage/acp-history.ts +18 -7
- package/src/storage/agent-files.ts +27 -41
- package/src/tools/history/contract.ts +17 -11
- package/src/tools/register.ts +4 -8
- package/src/ui/dsh/index.ts +8 -3
- package/src/ui/dsh/management.ts +40 -282
- package/src/ui/dsh/remote.ts +2 -2
- package/docs/adr/0001-claude-skill-discovery.md +0 -3
- package/docs/adr/0002-claude-native-collaboration.md +0 -3
- package/docs/agent-collaboration.md +0 -190
- package/docs/architecture-guidelines.md +0 -37
- package/docs/capability-design.md +0 -55
- package/docs/claude-code-design.md +0 -44
- package/docs/claude-code.md +0 -57
- package/docs/dsh.md +0 -337
- package/docs/file-storage.md +0 -97
- package/docs/history.md +0 -54
- package/docs/installation-design.md +0 -86
- package/docs/interaction-design.md +0 -21
- package/docs/model-context.md +0 -76
- package/docs/model-instruction-guidelines.md +0 -51
- package/docs/release.md +0 -108
- package/docs/technical-design.md +0 -163
- package/docs/workspace-configuration.md +0 -79
- package/lib/extension/claude-hooks.d.ts +0 -9
- package/lib/extension/claude-hooks.js +0 -78
- package/lib/extension/dsh/agent-events.d.ts +0 -24
- package/lib/extension/dsh/agent-events.js +0 -242
- package/lib/extension/dsh/agent-runtime.d.ts +0 -49
- package/lib/extension/dsh/agent-runtime.js +0 -351
- package/lib/integrations/dsh/dsh-agents.d.ts +0 -30
- package/lib/integrations/dsh/dsh-agents.js +0 -104
- package/lib/integrations/dsh/input.d.ts +0 -21
- package/lib/integrations/dsh/input.js +0 -62
- package/lib/integrations/dsh/notifications.d.ts +0 -8
- package/lib/integrations/dsh/notifications.js +0 -55
- package/lib/integrations/dsh/session.d.ts +0 -14
- package/lib/integrations/dsh/session.js +0 -60
- package/lib/integrations/team-context.d.ts +0 -18
- package/lib/integrations/team-context.js +0 -61
- package/lib/model/team.d.ts +0 -85
- package/lib/services/agents/agent-notices.d.ts +0 -13
- package/lib/services/agents/agent-notices.js +0 -25
- package/lib/services/agents/start-options.d.ts +0 -4
- package/lib/services/agents/start-options.js +0 -20
- package/lib/services/agents/team-service.d.ts +0 -168
- package/lib/services/agents/team-service.js +0 -345
- package/lib/storage/team-files.d.ts +0 -16
- package/lib/storage/team-files.js +0 -111
- package/lib/tools/agents/actions.d.ts +0 -62
- package/lib/tools/agents/actions.js +0 -62
- package/lib/tools/agents/contract.d.ts +0 -181
- package/lib/tools/agents/contract.js +0 -84
- package/lib/tools/agents/dsh-tool.d.ts +0 -5
- package/lib/tools/agents/dsh-tool.js +0 -34
- package/lib/tools/result.d.ts +0 -18
- package/lib/tools/result.js +0 -10
- package/lib/tools/teams/actions.d.ts +0 -23
- package/lib/tools/teams/actions.js +0 -40
- package/lib/tools/teams/contract.d.ts +0 -201
- package/lib/tools/teams/contract.js +0 -91
- package/lib/tools/teams/dsh-tool.d.ts +0 -8
- package/lib/tools/teams/dsh-tool.js +0 -39
- package/lib/ui/dsh/attachments.d.ts +0 -5
- package/lib/ui/dsh/attachments.js +0 -39
- package/resources/prompts/claude-coordinator.md +0 -1
- package/resources/prompts/native-coordinator.md +0 -1
- package/resources/prompts/team-member.md +0 -7
- package/src/extension/agent-events.ts +0 -210
- package/src/extension/agents-command.ts +0 -89
- package/src/extension/claude-hooks.ts +0 -74
- package/src/extension/dsh/agent-events.ts +0 -148
- package/src/extension/dsh/agent-runtime.ts +0 -252
- package/src/extension/subagent-entry.ts +0 -270
- package/src/extension/teams-command.ts +0 -67
- package/src/integrations/dsh/dsh-agents.ts +0 -97
- package/src/integrations/dsh/input.ts +0 -66
- package/src/integrations/dsh/notifications.ts +0 -46
- package/src/integrations/pi/agent-context.ts +0 -18
- package/src/integrations/pi/agent-input.ts +0 -19
- package/src/integrations/pi/pi-agents.ts +0 -84
- package/src/integrations/pi/team-context.ts +0 -26
- package/src/integrations/team-context.ts +0 -64
- package/src/model/team.ts +0 -29
- package/src/services/agents/agent-notices.ts +0 -28
- package/src/services/agents/start-options.ts +0 -19
- package/src/services/agents/team-service.ts +0 -275
- package/src/storage/team-files.ts +0 -93
- package/src/tools/agents/actions.ts +0 -57
- package/src/tools/agents/contract.ts +0 -101
- package/src/tools/agents/dsh-tool.ts +0 -37
- package/src/tools/agents/tool.ts +0 -20
- package/src/tools/teams/actions.ts +0 -34
- package/src/tools/teams/contract.ts +0 -109
- package/src/tools/teams/dsh-tool.ts +0 -45
- package/src/tools/teams/tool.ts +0 -29
- package/src/ui/agent-display.ts +0 -14
- package/src/ui/dsh/attachments.ts +0 -42
- package/src/ui/pi/menu.ts +0 -37
- package/src/ui/pi/reader.ts +0 -46
- /package/lib/{model/team.js → antigravity-plugin/lib/model/plugin-host.js} +0 -0
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import type { Context } from "@deepseek-ai/cordis";
|
|
3
3
|
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
4
|
-
import { dshHomePath } from "@deepseek-ai/dsh-home-paths";
|
|
5
|
-
import { AgentFiles } from "../../storage/agent-files.js";
|
|
6
4
|
import { acpHistorySessions } from "../../storage/acp-history.js";
|
|
7
5
|
import { HistoryFiles } from "../../storage/history-files.js";
|
|
8
6
|
import { HistoryService } from "../../services/history/history-service.js";
|
|
9
7
|
import { DshHistory } from "../../integrations/dsh/history.js";
|
|
10
8
|
import { dshHistorySummarizer } from "../../integrations/dsh/history-summary.js";
|
|
11
9
|
import { finalDshAnswer } from "../../integrations/dsh/messages.js";
|
|
10
|
+
import { defaultWorkerDirectory } from "../mcp-workers.js";
|
|
12
11
|
|
|
13
12
|
/** One server-owned organizer per workspace, shared by its parent Sessions. */
|
|
14
13
|
export class DshHistoryWork {
|
|
@@ -17,13 +16,17 @@ export class DshHistoryWork {
|
|
|
17
16
|
#controller: AbortController | undefined;
|
|
18
17
|
#work: Promise<void> | undefined;
|
|
19
18
|
#closing: Promise<void> | undefined;
|
|
19
|
+
|
|
20
20
|
constructor(private readonly ctx: Context, root: string) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
new
|
|
21
|
+
this.service = new HistoryService(
|
|
22
|
+
root,
|
|
23
|
+
new HistoryFiles(join(root, ".pbot/history"), "dsh"),
|
|
24
|
+
new DshHistory(ctx, root),
|
|
24
25
|
[new HistoryFiles(join(root, ".pbot/history"), "pi"), new HistoryFiles(join(root, ".pbot/history"), "claude")],
|
|
25
|
-
() => acpHistorySessions({
|
|
26
|
+
() => acpHistorySessions({ mcp: defaultWorkerDirectory() }),
|
|
27
|
+
);
|
|
26
28
|
}
|
|
29
|
+
|
|
27
30
|
attach(agent: Agent) { this.#parents.add(agent); return () => { this.#parents.delete(agent); }; }
|
|
28
31
|
cancel() { this.#controller?.abort(); }
|
|
29
32
|
schedule(agent: Agent) {
|
|
@@ -3,7 +3,6 @@ import type { Context } from "@deepseek-ai/cordis";
|
|
|
3
3
|
import { Remote, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
4
4
|
import type {} from "@deepseek-ai/dsh-typert-registry";
|
|
5
5
|
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
6
|
-
import { extractSessionEventText } from "@deepseek-ai/dsh-session-query";
|
|
7
6
|
import { Type, type Static } from "typebox";
|
|
8
7
|
import { json, type Json } from "../../common/json.js";
|
|
9
8
|
import { requireThat } from "../../common/validation.js";
|
|
@@ -15,30 +14,38 @@ import { pbotReadRemote } from "../../ui/dsh/remote.js";
|
|
|
15
14
|
import type { DshWorkspaces, DshWorkspace } from "./workspace.js";
|
|
16
15
|
|
|
17
16
|
const requestSchema = Type.Object({ parentSessionId: Type.String({ minLength: 1 }), input: Type.Optional(Type.Unknown()) }, { additionalProperties: false });
|
|
18
|
-
const
|
|
19
|
-
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 100 })), seq: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
20
|
-
textOffset: Type.Optional(Type.Integer({ minimum: 0 })), textLimit: Type.Optional(Type.Integer({ minimum: 2, maximum: 24000 })),
|
|
21
|
-
format: Type.Optional(Type.Union([Type.Literal("text"), Type.Literal("json")])) }, { additionalProperties: false });
|
|
22
|
-
const teamSchema = Type.Object({ teamId: Type.String({ minLength: 1 }), afterSeq: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
23
|
-
seq: Type.Optional(Type.Integer({ minimum: 1 })), offset: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
24
|
-
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 16000 })) }, { additionalProperties: false });
|
|
25
|
-
const validRequest = schema(requestSchema), validExpert = schema(expertSchema), validTeam = schema(teamSchema);
|
|
17
|
+
const validRequest = schema(requestSchema);
|
|
26
18
|
|
|
27
19
|
export function dshStatus(workspace: DshWorkspace): Json {
|
|
28
20
|
workspace.check();
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
return json({
|
|
22
|
+
host: "dsh",
|
|
23
|
+
release: packageVersion,
|
|
24
|
+
enabled: true,
|
|
25
|
+
state: "running",
|
|
26
|
+
workspaceRoot: workspace.root,
|
|
27
|
+
sessionId: workspace.agent.id,
|
|
31
28
|
model: workspace.agent.model.current() ?? null,
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
history: workspace.history.status,
|
|
30
|
+
});
|
|
34
31
|
}
|
|
35
32
|
|
|
36
33
|
/** Status remains available when this workspace has not opted in. */
|
|
37
34
|
export async function dshWorkspaceStatus(workspaces: DshWorkspaces, agent: Agent): Promise<Json> {
|
|
38
35
|
const { root, configuration } = await workspaces.configuration(agent);
|
|
39
|
-
if (!configuration.enabled)
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
if (!configuration.enabled) {
|
|
37
|
+
return json({
|
|
38
|
+
host: "dsh",
|
|
39
|
+
release: packageVersion,
|
|
40
|
+
enabled: false,
|
|
41
|
+
state: configuration.error ? "error" : "disabled",
|
|
42
|
+
nextStep: configuration.error ? configuration.error : "/pbot init",
|
|
43
|
+
workspaceRoot: root,
|
|
44
|
+
sessionId: agent.id,
|
|
45
|
+
configuration,
|
|
46
|
+
model: agent.model.current() ?? null,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
42
49
|
return json({ ...dshStatus(await workspaces.get(agent)) as Record<string, Json>, configuration });
|
|
43
50
|
}
|
|
44
51
|
|
|
@@ -69,46 +76,6 @@ export class PbotManagement extends TypertRemoteService {
|
|
|
69
76
|
signal.throwIfAborted(); return status;
|
|
70
77
|
}
|
|
71
78
|
|
|
72
|
-
@Remote
|
|
73
|
-
async expert(request: Json, signal: AbortSignal): Promise<Json> {
|
|
74
|
-
const current = await this.workspace(request, signal), { workspace, input } = current;
|
|
75
|
-
requireThat(validExpert(input), "专家记录查询参数无效。");
|
|
76
|
-
const args = input as Static<typeof expertSchema>;
|
|
77
|
-
const view = workspace.agents.status(args.agentId, workspace.owner);
|
|
78
|
-
if (view.transport === "acp") return json(await workspace.agents.recordPage(args.agentId, workspace.owner, args));
|
|
79
|
-
using observation = await this.ctx.sessionQuery.observeSession(SessionId(view.agentId), { projectionMode: "none", signal: current.signal });
|
|
80
|
-
workspace.check(); current.signal.throwIfAborted();
|
|
81
|
-
const header = observation.header;
|
|
82
|
-
requireThat(header.id === view.agentId && header.cwd === view.cwd && header.parentSession === workspace.agent.id &&
|
|
83
|
-
header.origin === "subagent" && !header.isSeeded, "原生专家记录的身份或归属不匹配。");
|
|
84
|
-
const events = observation.events;
|
|
85
|
-
if (args.seq !== undefined) {
|
|
86
|
-
const event = events.find(value => value.seq === args.seq);
|
|
87
|
-
requireThat(event, "原生记录位置不存在。");
|
|
88
|
-
const text = (args.format === "text" ? extractSessionEventText(event) : "") || JSON.stringify(event, null, 2), offset = args.textOffset ?? 0;
|
|
89
|
-
requireThat(offset <= text.length, "原生记录分页位置超出范围。");
|
|
90
|
-
let end = Math.min(text.length, offset + (args.textLimit ?? 12000));
|
|
91
|
-
if (end < text.length && /[\uD800-\uDBFF]/.test(text[end - 1]!)) end--;
|
|
92
|
-
return json({ agent: view, cursor: observation.cursor, seq: event.seq, offset, text: text.slice(offset, end),
|
|
93
|
-
totalLength: text.length, nextOffset: end < text.length ? end : null });
|
|
94
|
-
}
|
|
95
|
-
const limit = args.limit ?? 30, offset = args.offset ?? Math.max(0, events.length - limit);
|
|
96
|
-
requireThat(offset <= events.length, "原生记录分页位置超出范围。");
|
|
97
|
-
return json({ agent: view, header, cursor: observation.cursor, total: events.length, offset,
|
|
98
|
-
nextOffset: offset + limit < events.length ? offset + limit : null,
|
|
99
|
-
events: events.slice(offset, offset + limit).map(event => ({ seq: event.seq, type: event.type, time: event.time,
|
|
100
|
-
...(event.type === "user/message" ? { source: event.data.source.kind } : {}), preview: extractSessionEventText(event).slice(0, 800) })) });
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
@Remote
|
|
104
|
-
async team(request: Json, signal: AbortSignal): Promise<Json> {
|
|
105
|
-
const { workspace, input } = await this.workspace(request, signal);
|
|
106
|
-
requireThat(validTeam(input), "团队记录查询参数无效。");
|
|
107
|
-
const args = input as Static<typeof teamSchema>;
|
|
108
|
-
return json({ team: workspace.teams.status(args.teamId, workspace.owner, workspace.agents.list(workspace.owner)),
|
|
109
|
-
page: workspace.teams.read(args.teamId, { kind: "user", owner: workspace.owner }, args) });
|
|
110
|
-
}
|
|
111
|
-
|
|
112
79
|
@Remote
|
|
113
80
|
async history(request: Json, signal: AbortSignal): Promise<Json> {
|
|
114
81
|
const current = await this.workspace(request, signal), { workspace, input } = current;
|
|
@@ -120,7 +87,9 @@ export class PbotManagement extends TypertRemoteService {
|
|
|
120
87
|
declare module "@deepseek-ai/cordis" { interface Context { pbotManagement: PbotManagement } }
|
|
121
88
|
|
|
122
89
|
export function registerDshManagement(ctx: Context, workspaces: DshWorkspaces) {
|
|
123
|
-
ctx.typert.register({
|
|
124
|
-
|
|
90
|
+
ctx.typert.register({
|
|
91
|
+
package: pbotReadRemote.package, face: "host", schemas: [],
|
|
92
|
+
model: { services: [], events: [], objects: [] }, invocations: pbotReadRemote.descriptors,
|
|
93
|
+
});
|
|
125
94
|
return new PbotManagement(ctx, workspaces);
|
|
126
95
|
}
|
|
@@ -1,127 +1,113 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
1
2
|
import { realpath } from "node:fs/promises";
|
|
2
|
-
import {
|
|
3
|
+
import { resolve } from "node:path";
|
|
3
4
|
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
4
5
|
import type { Context } from "@deepseek-ai/cordis";
|
|
5
|
-
import
|
|
6
|
-
import { AgentBackends } from "../../integrations/acp/agents.js";
|
|
7
|
-
import type { AcpCommands } from "../../model/acp.js";
|
|
8
|
-
import type { AgentOwner } from "../../model/agent.js";
|
|
6
|
+
import * as McpClient from "@deepseek-ai/dsh-mcp-client";
|
|
9
7
|
import { rootAgents } from "../../integrations/dsh/root-agents.js";
|
|
10
|
-
import {
|
|
11
|
-
import { dshResources, dshExpertTools } from "../../integrations/dsh/resources.js";
|
|
12
|
-
import { AgentService } from "../../services/agents/agent-service.js";
|
|
13
|
-
import { TeamService } from "../../services/agents/team-service.js";
|
|
14
|
-
import { registerDshAgentTool } from "../../tools/agents/dsh-tool.js";
|
|
15
|
-
import { registerDshTeamTool, registerDshTeamMessageTool } from "../../tools/teams/dsh-tool.js";
|
|
16
|
-
import { DshAgentRuntime } from "./agent-runtime.js";
|
|
17
|
-
import { DshAgentEvents } from "./agent-events.js";
|
|
8
|
+
import { dshResources } from "../../integrations/dsh/resources.js";
|
|
18
9
|
import { registerDshFileEvents } from "./files.js";
|
|
19
10
|
import { DshHistoryWork, registerDshHistoryEvents } from "./history.js";
|
|
20
11
|
import type { HistoryService } from "../../services/history/history-service.js";
|
|
21
12
|
import { registerDshHistoryTool } from "../../tools/history/dsh-tool.js";
|
|
13
|
+
import { resourceRoot } from "../../common/paths.js";
|
|
22
14
|
import { requireThat } from "../../common/validation.js";
|
|
15
|
+
import { toDshMcpConfig } from "../../integrations/dsh/mcp.js";
|
|
23
16
|
import { registerDshSkills } from "../../integrations/dsh/skills.js";
|
|
24
|
-
import { readWorkspaceConfig, workspaceDisabledMessage } from "../../services/workspace/workspace-config.js";
|
|
25
|
-
import
|
|
17
|
+
import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../../services/workspace/workspace-config.js";
|
|
18
|
+
import { readWorkspaceMcpConfig, resolveWorkspaceMcpServer } from "../../services/workspace/workspace-mcp.js";
|
|
19
|
+
import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration } from "../../model/workspace-config.js";
|
|
26
20
|
import { initializeWorkspace } from "../../services/workspace/workspace-preparation.js";
|
|
21
|
+
import { McpWorkerRuntime, defaultWorkerDirectory } from "../mcp-workers.js";
|
|
27
22
|
|
|
28
|
-
export const dshDependencies = ["agents", "sessions", "sessionPersistence", "sessionQuery", "llm", "tools", "systemPrompt", "skills", "fs", "
|
|
23
|
+
export const dshDependencies = ["agents", "sessions", "sessionPersistence", "sessionQuery", "llm", "tools", "systemPrompt", "skills", "fs", "workingDirectory", "approval"];
|
|
29
24
|
|
|
30
25
|
export class DshWorkspace {
|
|
31
26
|
readonly lifetime = new AbortController();
|
|
32
|
-
readonly host: DshAgents;
|
|
33
|
-
readonly agents: AgentService;
|
|
34
|
-
readonly teams: TeamService;
|
|
35
27
|
readonly history: HistoryService;
|
|
36
|
-
readonly
|
|
37
|
-
readonly #experts = new Map<string, DshAgentRuntime>();
|
|
28
|
+
readonly workers: McpWorkerRuntime;
|
|
38
29
|
#scope: { dispose(): Promise<void> } | undefined;
|
|
39
|
-
#events: DshAgentEvents | undefined;
|
|
40
30
|
#closing: Promise<void> | undefined;
|
|
41
|
-
|
|
31
|
+
|
|
32
|
+
constructor(
|
|
33
|
+
readonly ctx: Context,
|
|
34
|
+
readonly root: string,
|
|
35
|
+
readonly agent: Agent,
|
|
42
36
|
readonly component: AbortSignal,
|
|
43
|
-
private readonly historyWork: DshHistoryWork,
|
|
37
|
+
private readonly historyWork: DshHistoryWork,
|
|
38
|
+
private readonly releaseHistory: () => Promise<void>,
|
|
39
|
+
readonly features: ResolvedWorkspaceFeatures = workspaceFeatures(),
|
|
40
|
+
) {
|
|
44
41
|
this.history = historyWork.service;
|
|
45
|
-
this.
|
|
46
|
-
this.host = new DshAgents(ctx, agent, {
|
|
47
|
-
setup: (d, _directory, generation) => async (agentCtx, child) => {
|
|
48
|
-
await agentCtx.plugin({ name: "pbot-expert", inject: dshDependencies, apply: async scope => {
|
|
49
|
-
const runtime = new DshAgentRuntime(scope, child, d, generation, this.agents.files, this.teams,
|
|
50
|
-
{ check: this.check, release: () => this.host.release(d.agentId, generation) });
|
|
51
|
-
this.#experts.set(d.agentId, runtime);
|
|
52
|
-
scope.effect(() => () => { if (this.#experts.get(d.agentId) === runtime) this.#experts.delete(d.agentId); });
|
|
53
|
-
registerDshSkills(scope, child);
|
|
54
|
-
await dshResources(scope, child, root, "general-purpose", runtime.check);
|
|
55
|
-
const teamTool = dshExpertTools(scope, child, d.options);
|
|
56
|
-
if (teamTool) registerDshTeamMessageTool(scope, child, this.teams, runtime.actor, runtime.check);
|
|
57
|
-
registerDshFileEvents(scope, child, root, true, runtime.check);
|
|
58
|
-
runtime.initialize(teamTool);
|
|
59
|
-
} });
|
|
60
|
-
return { commit: this.check };
|
|
61
|
-
},
|
|
62
|
-
ready: (child, generation) => {
|
|
63
|
-
const runtime = this.#experts.get(child.id);
|
|
64
|
-
requireThat(runtime?.generation === generation, "专家执行组件未就绪。"); runtime.start();
|
|
65
|
-
},
|
|
66
|
-
stopping: async (child, generation) => { const runtime = this.#experts.get(child.id); if (runtime?.generation === generation) await runtime.stop(); },
|
|
67
|
-
}, this.lifetime.signal);
|
|
68
|
-
const directory = dshHomePath("pbot", "subagents");
|
|
69
|
-
this.agents = new AgentService(root, directory, new AgentBackends(this.host, directory, acp));
|
|
70
|
-
this.teams = new TeamService(root, this.agents.files, this.agents.teamFiles);
|
|
42
|
+
this.workers = new McpWorkerRuntime(defaultWorkerDirectory(), agent.id, "dsh");
|
|
71
43
|
}
|
|
44
|
+
|
|
72
45
|
check = () => { this.component.throwIfAborted(); this.lifetime.signal.throwIfAborted(); };
|
|
73
|
-
|
|
46
|
+
|
|
74
47
|
async open() {
|
|
75
48
|
this.check();
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
49
|
+
const mcpEntry = resolve(resourceRoot, "../lib/extension/mcp.js");
|
|
50
|
+
const workerDir = defaultWorkerDirectory();
|
|
51
|
+
this.#scope = await this.agent.ctx.plugin({
|
|
52
|
+
name: "pbot-coordinator",
|
|
53
|
+
inject: dshDependencies,
|
|
54
|
+
apply: async ctx => {
|
|
55
|
+
if (this.features.skills) registerDshSkills(ctx, this.agent, { workspaceRoot: this.root });
|
|
56
|
+
if (this.features.prompts) await dshResources(ctx, this.agent, this.root, "coordinator", this.check, "history-coordinator.md");
|
|
57
|
+
registerDshFileEvents(ctx, this.agent, this.root, false, this.check);
|
|
58
|
+
registerDshHistoryTool(ctx, this.agent, this.history, this.lifetime.signal, this.check);
|
|
59
|
+
registerDshHistoryEvents(ctx, this.agent, this.historyWork, this.check);
|
|
60
|
+
if (existsSync(mcpEntry)) {
|
|
61
|
+
await ctx.plugin(McpClient, McpClient.Config({
|
|
62
|
+
transport: "stdio",
|
|
63
|
+
serverName: "pbot",
|
|
64
|
+
command: process.execPath,
|
|
65
|
+
args: [mcpEntry],
|
|
66
|
+
env: {
|
|
67
|
+
...(process.env.PATH ? { PATH: process.env.PATH } : {}),
|
|
68
|
+
...(process.env.HOME ? { HOME: process.env.HOME } : {}),
|
|
69
|
+
...(process.env.DSH_HOME ? { DSH_HOME: process.env.DSH_HOME } : {}),
|
|
70
|
+
PBOT_HOST: "dsh",
|
|
71
|
+
PBOT_WORKSPACE_ROOT: this.root,
|
|
72
|
+
PBOT_MCP_AGENT_DIR: workerDir,
|
|
73
|
+
PBOT_MCP_SESSION_ID: this.agent.id,
|
|
74
|
+
},
|
|
75
|
+
cwd: this.root,
|
|
76
|
+
toolCallTimeoutMs: 600_000,
|
|
77
|
+
failOnStartupError: false,
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
if (this.features.mcp) {
|
|
81
|
+
const mcpConfig = await readWorkspaceMcpConfig(this.root);
|
|
82
|
+
this.check();
|
|
83
|
+
if (mcpConfig.error) {
|
|
84
|
+
this.ctx.logger.warn(mcpConfig.error);
|
|
85
|
+
} else {
|
|
86
|
+
for (const [serverName, server] of Object.entries(mcpConfig.servers)) {
|
|
87
|
+
if (server.enabled === false) continue;
|
|
88
|
+
try {
|
|
89
|
+
const resolved = resolveWorkspaceMcpServer(this.root, serverName, server);
|
|
90
|
+
await ctx.plugin(McpClient, toDshMcpConfig(resolved));
|
|
91
|
+
} catch (error) {
|
|
92
|
+
this.ctx.logger.warn(error instanceof Error ? error.message : String(error));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
});
|
|
88
99
|
this.check();
|
|
89
100
|
}
|
|
90
|
-
|
|
91
|
-
attachments: readonly (ImageBlock | FileBlock)[] = [], signal: AbortSignal) {
|
|
92
|
-
const view = this.agents.status(id, this.owner);
|
|
93
|
-
if (view.transport !== "acp") return this.expert(id).interact(text, delivery, files, attachments, signal);
|
|
94
|
-
this.check(); signal.throwIfAborted();
|
|
95
|
-
requireThat(text.length <= 24000 && files.length + attachments.length <= 32 && (!files.length || !attachments.length), "人工消息或附件参数无效。");
|
|
96
|
-
const paths = [...files, ...attachments.map(attachment => {
|
|
97
|
-
const path = attachment.type === "image" ? this.ctx.attachments.imageHostPath(attachment.attachment) : this.ctx.attachments.fileHostPath(attachment.attachment);
|
|
98
|
-
requireThat(path, "该原生附件存储不提供 ACP 子进程可读取的文件路径。"); return path;
|
|
99
|
-
})];
|
|
100
|
-
requireThat(text.trim() || paths.length, "请输入消息或附加文件。");
|
|
101
|
-
this.teams.pauseMember(id, "成员由人工接管");
|
|
102
|
-
return this.agents.send(id, text || "请处理所附文件。", delivery ?? "followUp", this.owner, paths);
|
|
103
|
-
}
|
|
104
|
-
expert(id: string) {
|
|
105
|
-
this.check(); const view = this.agents.status(id, this.owner), runtime = this.#experts.get(id);
|
|
106
|
-
requireThat(view.owned, "专家不属于当前父会话。");
|
|
107
|
-
requireThat(view.alive, "专家已停止;需要明确恢复后才能对话。");
|
|
108
|
-
requireThat(view.state !== "starting", "专家尚未就绪,请等待启动或恢复完成。");
|
|
109
|
-
requireThat(runtime?.generation === view.generation, "原生专家由其他执行实例持有;当前组件不能接管对话。");
|
|
110
|
-
return runtime;
|
|
111
|
-
}
|
|
101
|
+
|
|
112
102
|
close() {
|
|
113
103
|
if (this.#closing) return this.#closing;
|
|
114
104
|
this.lifetime.abort();
|
|
115
105
|
this.#closing = (async () => {
|
|
116
106
|
const errors: unknown[] = [];
|
|
117
|
-
try { await this
|
|
118
|
-
try { this.teams.pauseAll(this.owner, "父会话或执行组件关闭"); } catch (error) { errors.push(error); }
|
|
119
|
-
try { await this.agents.close(this.owner); } catch (error) { errors.push(error); }
|
|
120
|
-
try { await this.host.close(); } catch (error) { errors.push(error); }
|
|
121
|
-
this.teams.dispose();
|
|
107
|
+
try { await this.workers.close(); } catch (error) { errors.push(error); }
|
|
122
108
|
try { await this.#scope?.dispose(); } catch (error) { errors.push(error); }
|
|
123
109
|
try { await this.releaseHistory(); } catch (error) { errors.push(error); }
|
|
124
|
-
if (errors.length) throw new AggregateError(errors, "dsh
|
|
110
|
+
if (errors.length) throw new AggregateError(errors, "dsh 工作区关闭失败;请核对执行资源。");
|
|
125
111
|
})();
|
|
126
112
|
return this.#closing;
|
|
127
113
|
}
|
|
@@ -148,17 +134,20 @@ export class DshWorkspaces {
|
|
|
148
134
|
if (!entry) { entry = { work: new DshHistoryWork(this.ctx, root), users: 0 }; this.#histories.set(root, entry); }
|
|
149
135
|
const owned = entry; owned.users++;
|
|
150
136
|
let released = false;
|
|
151
|
-
return {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
137
|
+
return {
|
|
138
|
+
work: owned.work,
|
|
139
|
+
release: async () => {
|
|
140
|
+
if (released) return; released = true;
|
|
141
|
+
if (--owned.users === 0) {
|
|
142
|
+
try { await owned.work.close(); } finally { if (this.#histories.get(root) === owned) this.#histories.delete(root); }
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
};
|
|
157
146
|
}
|
|
158
147
|
|
|
159
148
|
async open(agent: Agent) {
|
|
160
149
|
this.#lifetime.signal.throwIfAborted();
|
|
161
|
-
requireThat(rootAgents(this.ctx.agents).includes(agent), "
|
|
150
|
+
requireThat(rootAgents(this.ctx.agents).includes(agent), "子会话不拥有协调者管理入口。");
|
|
162
151
|
const current = this.#parents.get(agent);
|
|
163
152
|
if (current) return current;
|
|
164
153
|
const opening = (async () => {
|
|
@@ -178,7 +167,7 @@ export class DshWorkspaces {
|
|
|
178
167
|
const history = await this.history(root);
|
|
179
168
|
let workspace: DshWorkspace | undefined;
|
|
180
169
|
try {
|
|
181
|
-
workspace = new DshWorkspace(this.ctx, root, agent, this.#lifetime.signal, history.work, history.release, configuration
|
|
170
|
+
workspace = new DshWorkspace(this.ctx, root, agent, this.#lifetime.signal, history.work, history.release, workspaceFeatures(configuration));
|
|
182
171
|
const owned = workspace;
|
|
183
172
|
const dispose = agent.ctx.effect(() => async () => {
|
|
184
173
|
this.#parents.delete(agent); this.#configurations.delete(agent); this.#parentEffects.delete(agent); await owned.close();
|
package/src/extension/events.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
1
|
import { join, resolve } from "node:path";
|
|
3
2
|
import { homedir } from "node:os";
|
|
4
3
|
import { fileURLToPath } from "node:url";
|
|
5
4
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
6
|
-
import {
|
|
7
|
-
import { agentText } from "../integrations/agent-resources.js";
|
|
5
|
+
import { loadWorkspaceContext } from "../integrations/agent-resources.js";
|
|
8
6
|
import type { Confirmations } from "../ui/confirmation.js";
|
|
9
7
|
import type { Lifecycle } from "./lifecycle.js";
|
|
10
8
|
import { readWorkspaceConfig, workspaceDisabledMessage } from "../services/workspace/workspace-config.js";
|
|
@@ -13,7 +11,7 @@ import { workspaceSkillPaths } from "../integrations/pi/skills.js";
|
|
|
13
11
|
export function registerEvents(pi: ExtensionAPI, lifecycle: Lifecycle, confirmations: Confirmations) {
|
|
14
12
|
pi.on("session_start", async (_event, ctx) => {
|
|
15
13
|
try {
|
|
16
|
-
await lifecycle.open(ctx.cwd);
|
|
14
|
+
await lifecycle.open(ctx.cwd, ctx.sessionManager.getSessionId());
|
|
17
15
|
if (!lifecycle.active) {
|
|
18
16
|
ctx.ui.setStatus("pbot", lifecycle.configuration?.error ? "PBot 配置错误" : "PBot 未启用 · /pbot init");
|
|
19
17
|
if (ctx.hasUI && lifecycle.configuration) ctx.ui.notify(workspaceDisabledMessage(lifecycle.configuration), lifecycle.configuration.error ? "error" : "info");
|
|
@@ -27,21 +25,26 @@ export function registerEvents(pi: ExtensionAPI, lifecycle: Lifecycle, confirmat
|
|
|
27
25
|
}
|
|
28
26
|
});
|
|
29
27
|
pi.on("resources_discover", (_event, ctx) => {
|
|
30
|
-
if (!lifecycle.active) return;
|
|
28
|
+
if (!lifecycle.active || !lifecycle.active.features.skills) return;
|
|
31
29
|
return { skillPaths: workspaceSkillPaths(pi, ctx.cwd) };
|
|
32
30
|
});
|
|
33
31
|
pi.on("before_agent_start", async (event, ctx) => {
|
|
34
32
|
const instance = lifecycle.active;
|
|
35
33
|
if (!instance) return;
|
|
36
34
|
instance.cancelWork();
|
|
35
|
+
if (!instance.features.prompts) return;
|
|
37
36
|
try {
|
|
38
|
-
const
|
|
39
|
-
|
|
37
|
+
const context = await loadWorkspaceContext({
|
|
38
|
+
host: "pi",
|
|
39
|
+
root: instance.root,
|
|
40
|
+
role: "coordinator",
|
|
41
|
+
coordinatorPrompt: "history-coordinator.md",
|
|
42
|
+
});
|
|
40
43
|
instance.check();
|
|
41
44
|
Object.assign(event.systemPromptOptions.sections, {
|
|
42
|
-
pbot_workspace: workspace,
|
|
43
|
-
pbot_environment: JSON.stringify(
|
|
44
|
-
pbot: role,
|
|
45
|
+
pbot_workspace: context.workspace,
|
|
46
|
+
pbot_environment: JSON.stringify(context.environment),
|
|
47
|
+
pbot: context.role,
|
|
45
48
|
});
|
|
46
49
|
} catch (error) {
|
|
47
50
|
// Pi reports hook errors but continues preparation unless the run is explicitly aborted.
|
package/src/extension/history.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import type { ExtensionAPI
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { historyLocation, historySummarizer } from "../integrations/pi/history.js";
|
|
3
|
-
import type { Lifecycle
|
|
4
|
-
import { readPage } from "../ui/pi/reader.js";
|
|
5
|
-
import { choose } from "../ui/pi/menu.js";
|
|
3
|
+
import type { Lifecycle } from "./lifecycle.js";
|
|
6
4
|
|
|
7
5
|
export function registerHistoryEvents(pi: ExtensionAPI, lifecycle: Lifecycle) {
|
|
8
6
|
pi.on("session_start", async (_event, ctx) => {
|
|
@@ -26,49 +24,3 @@ export function registerHistoryEvents(pi: ExtensionAPI, lifecycle: Lifecycle) {
|
|
|
26
24
|
}).finally(() => { if (lifecycle.active === instance) ctx.ui.setStatus("pbot-history", undefined); });
|
|
27
25
|
});
|
|
28
26
|
}
|
|
29
|
-
|
|
30
|
-
const label = (node: { host: string; kind: string; from: string; ready: boolean; preview: string }) =>
|
|
31
|
-
`${node.host} · ${node.from.slice(0, 10)} · ${node.kind === "session" ? "会话" : node.kind === "summary" ? "摘要" : "问答"}${node.ready ? "" : "(待整理)"} · ${node.preview.replace(/\s+/g, " ").slice(0, 48)}`;
|
|
32
|
-
|
|
33
|
-
export async function showHistory(instance: WorkspaceInstance, ctx: ExtensionCommandContext, query: string) {
|
|
34
|
-
await instance.history.refresh(historyLocation(ctx), instance.signal(ctx.signal));
|
|
35
|
-
const service = instance.history;
|
|
36
|
-
if (ctx.mode !== "tui") { ctx.ui.notify(JSON.stringify(service.search({ query })), "info"); return; }
|
|
37
|
-
for (const warning of service.warnings) ctx.ui.notify(warning, "warning");
|
|
38
|
-
let offset = 0;
|
|
39
|
-
for (;;) {
|
|
40
|
-
instance.check();
|
|
41
|
-
const result = service.search({ query, offset });
|
|
42
|
-
const choices = result.matches.map((node, index) => `${index + 1}. ${label(node)}`);
|
|
43
|
-
const more = "下一页", previous = "上一页", search = "搜索", back = "返回";
|
|
44
|
-
const selected = await choose(ctx, `历史 · ${query || "最近会话"} · ${result.total} 项`, [...choices, ...(offset ? [previous] : []), ...(result.nextOffset === null ? [] : [more]), search, back]);
|
|
45
|
-
if (!selected || selected === back) return;
|
|
46
|
-
if (selected === more) { offset = result.nextOffset!; continue; }
|
|
47
|
-
if (selected === previous) { offset = Math.max(0, offset - 20); continue; }
|
|
48
|
-
if (selected === search) {
|
|
49
|
-
const value = await ctx.ui.input("全文搜索(留空列出会话)", query);
|
|
50
|
-
if (value !== undefined) { query = value; offset = 0; }
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
let current = result.matches[choices.indexOf(selected)]!, id = current.id, source = current.host, textOffset = 0, childrenOffset = 0;
|
|
54
|
-
for (;;) {
|
|
55
|
-
instance.check();
|
|
56
|
-
const node = service.read(id, textOffset, 12000, childrenOffset, source);
|
|
57
|
-
const body = "正文", nextText = "后续正文", nextChildren = "更多下级", first = "回到开头";
|
|
58
|
-
const links = [...node.parents.map(parent => ({ ...parent, direction: "↑" })), ...node.children.map(child => ({ ...child, direction: "↓" }))];
|
|
59
|
-
const names = links.map((value, index) => `${index + 1}. ${value.direction} ${label(value)}`);
|
|
60
|
-
const action = await choose(ctx, label(node), [body, ...names, ...(node.nextOffset === null ? [] : [nextText]),
|
|
61
|
-
...(node.nextChildrenOffset === null ? [] : [nextChildren]), ...(textOffset || childrenOffset ? [first] : []), back]);
|
|
62
|
-
if (!action || action === back) break;
|
|
63
|
-
if (action === body || action === nextText) {
|
|
64
|
-
if (action === nextText) textOffset = node.nextOffset!;
|
|
65
|
-
const page = service.read(id, textOffset, 12000, childrenOffset, source);
|
|
66
|
-
await readPage(ctx, `历史正文 · ${textOffset + 1}–${textOffset + page.text.length}/${page.totalLength}`, page.text || "摘要待整理,请展开下级记录。");
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
if (action === nextChildren) { childrenOffset = node.nextChildrenOffset!; continue; }
|
|
70
|
-
if (action === first) { textOffset = 0; childrenOffset = 0; continue; }
|
|
71
|
-
const link = links[names.indexOf(action)]!; id = link.id; source = link.host; textOffset = 0; childrenOffset = 0;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
@@ -1,76 +1,91 @@
|
|
|
1
1
|
import { realpath } from "node:fs/promises";
|
|
2
2
|
import { requireThat } from "../common/validation.js";
|
|
3
3
|
import { authorizeMutation } from "../services/workspace/workspace-files.js";
|
|
4
|
-
import type { AgentOwner } from "../model/agent.js";
|
|
5
|
-
import type { AgentService } from "../services/agents/agent-service.js";
|
|
6
|
-
import type { TeamService } from "../services/agents/team-service.js";
|
|
7
4
|
import type { CallAccess } from "../tools/access.js";
|
|
8
5
|
import type { HistoryService } from "../services/history/history-service.js";
|
|
9
|
-
import { readWorkspaceConfig, workspaceDisabledMessage } from "../services/workspace/workspace-config.js";
|
|
10
|
-
import type { WorkspaceConfiguration } from "../model/workspace-config.js";
|
|
6
|
+
import { readWorkspaceConfig, workspaceDisabledMessage, workspaceFeatures } from "../services/workspace/workspace-config.js";
|
|
7
|
+
import type { ResolvedWorkspaceFeatures, WorkspaceConfiguration } from "../model/workspace-config.js";
|
|
8
|
+
import type { McpWorkerRuntime } from "./mcp-workers.js";
|
|
11
9
|
|
|
12
10
|
export class WorkspaceInstance implements CallAccess {
|
|
13
11
|
readonly #controller = new AbortController();
|
|
14
12
|
#work = new AbortController();
|
|
15
13
|
#closing: Promise<void> | undefined;
|
|
16
|
-
|
|
14
|
+
|
|
15
|
+
constructor(
|
|
16
|
+
readonly root: string,
|
|
17
|
+
readonly sessionId: string,
|
|
18
|
+
readonly history: HistoryService,
|
|
19
|
+
readonly workers: McpWorkerRuntime,
|
|
20
|
+
readonly features: ResolvedWorkspaceFeatures = workspaceFeatures(),
|
|
21
|
+
) {}
|
|
22
|
+
|
|
17
23
|
check() {
|
|
18
24
|
requireThat(!this.#controller.signal.aborted, "pbot 工作区实例已关闭。");
|
|
19
25
|
}
|
|
26
|
+
|
|
20
27
|
signal(signal?: AbortSignal) {
|
|
21
28
|
this.check();
|
|
22
29
|
return AbortSignal.any([this.#controller.signal, this.#work.signal, ...(signal ? [signal] : [])]);
|
|
23
30
|
}
|
|
31
|
+
|
|
24
32
|
async authorizeFile(path: string, change: unknown, confirm: (value: unknown) => Promise<boolean>, signal: AbortSignal) {
|
|
25
33
|
this.check();
|
|
26
34
|
await authorizeMutation(this.root, path, change, confirm, signal);
|
|
27
35
|
this.check();
|
|
28
36
|
}
|
|
29
|
-
|
|
37
|
+
|
|
30
38
|
cancelWork() {
|
|
31
39
|
this.#work.abort();
|
|
32
40
|
this.#work = new AbortController();
|
|
33
41
|
}
|
|
34
|
-
|
|
42
|
+
|
|
43
|
+
close(preserveWorkers = false): Promise<void> {
|
|
35
44
|
if (this.#closing) return this.#closing;
|
|
36
45
|
this.#controller.abort();
|
|
37
46
|
this.#work.abort();
|
|
38
47
|
this.#closing = (async () => {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
catch (error) { errors.push(error); }
|
|
42
|
-
this.teams.dispose();
|
|
43
|
-
const results = await Promise.allSettled([this.agents.close(this.agentOwner, preserveAgents), this.history.close()]);
|
|
44
|
-
errors.push(...results.filter(result => result.status === "rejected").map(result => result.reason));
|
|
48
|
+
const results = await Promise.allSettled([this.workers.close(preserveWorkers), this.history.close()]);
|
|
49
|
+
const errors = results.filter(result => result.status === "rejected").map(result => result.reason);
|
|
45
50
|
if (errors.length) throw new AggregateError(errors, "工作区关闭失败。");
|
|
46
51
|
})();
|
|
47
52
|
return this.#closing;
|
|
48
53
|
}
|
|
49
54
|
}
|
|
55
|
+
|
|
50
56
|
export class Lifecycle {
|
|
51
57
|
#active: WorkspaceInstance | undefined;
|
|
52
58
|
configuration: WorkspaceConfiguration | undefined;
|
|
53
59
|
root: string | undefined;
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
|
|
61
|
+
constructor(
|
|
62
|
+
private readonly create: (root: string, sessionId: string, configuration: WorkspaceConfiguration) => WorkspaceInstance,
|
|
63
|
+
private readonly register: (instance: WorkspaceInstance) => void | Promise<void>,
|
|
64
|
+
private readonly hide: () => void,
|
|
65
|
+
) {}
|
|
66
|
+
|
|
56
67
|
get active() { return this.#active; }
|
|
68
|
+
|
|
57
69
|
get() {
|
|
58
70
|
requireThat(this.#active, this.configuration ? workspaceDisabledMessage(this.configuration) : "pbot 工作区实例不可用。");
|
|
59
|
-
this.#active.check();
|
|
71
|
+
this.#active.check();
|
|
72
|
+
return this.#active;
|
|
60
73
|
}
|
|
61
|
-
|
|
74
|
+
|
|
75
|
+
async open(root: string, sessionId: string) {
|
|
62
76
|
await this.close();
|
|
63
77
|
this.root = await realpath(root);
|
|
64
78
|
this.configuration = await readWorkspaceConfig(this.root);
|
|
65
79
|
if (!this.configuration.enabled) return;
|
|
66
|
-
const instance = this.create(this.root, this.configuration);
|
|
80
|
+
const instance = this.create(this.root, sessionId, this.configuration);
|
|
67
81
|
this.#active = instance;
|
|
68
|
-
try { this.register(instance); }
|
|
82
|
+
try { await this.register(instance); }
|
|
69
83
|
catch (error) { await this.close(); throw error; }
|
|
70
84
|
}
|
|
71
|
-
|
|
85
|
+
|
|
86
|
+
async close(preserveWorkers = false) {
|
|
72
87
|
const old = this.#active;
|
|
73
88
|
this.#active = undefined;
|
|
74
|
-
try { await old?.close(
|
|
89
|
+
try { await old?.close(preserveWorkers); } finally { this.hide(); }
|
|
75
90
|
}
|
|
76
91
|
}
|