personal-bot 0.2.14 → 0.2.16
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 -2
- package/README.md +10 -11
- package/README.zh-CN.md +10 -11
- package/docs/README.md +2 -2
- package/docs/adr/0001-claude-skill-discovery.md +1 -1
- package/docs/agent-collaboration.md +8 -9
- package/docs/architecture-guidelines.md +1 -1
- package/docs/capability-design.md +2 -2
- package/docs/claude-code-design.md +10 -11
- package/docs/claude-code.md +8 -15
- package/docs/dsh.md +18 -19
- package/docs/file-storage.md +2 -3
- package/docs/installation-design.md +4 -5
- package/docs/interaction-design.md +1 -1
- package/docs/model-context.md +9 -10
- package/docs/release.md +5 -5
- package/docs/technical-design.md +16 -21
- package/docs/workspace-configuration.md +5 -8
- package/hooks/hooks.json +1 -4
- package/lib/client.js +3 -15
- package/lib/common/schema.d.ts +2 -0
- package/lib/common/schema.js +9 -0
- package/lib/extension/acp-member.js +1 -3
- package/lib/extension/acp-worker.js +3 -22
- package/lib/extension/claude-hooks.d.ts +0 -6
- package/lib/extension/claude-hooks.js +5 -31
- package/lib/extension/dsh/acp-member.js +1 -2
- package/lib/extension/dsh/command.js +13 -23
- package/lib/extension/dsh/management.d.ts +1 -1
- package/lib/extension/dsh/management.js +3 -3
- package/lib/extension/dsh/workspace.d.ts +1 -9
- package/lib/extension/dsh/workspace.js +4 -31
- package/lib/extension/setup-cli.js +4 -4
- package/lib/integrations/dsh/dsh-agents.d.ts +1 -2
- package/lib/integrations/dsh/dsh-agents.js +0 -4
- package/lib/integrations/dsh/resources.d.ts +1 -5
- package/lib/integrations/dsh/resources.js +2 -5
- package/lib/integrations/installation/processes.js +0 -15
- package/lib/model/agent.d.ts +0 -1
- package/lib/services/agents/agent-notices.js +1 -1
- package/lib/services/agents/agent-service.js +3 -2
- package/lib/services/agents/start-options.d.ts +4 -0
- package/lib/services/agents/start-options.js +20 -0
- package/lib/tools/agents/actions.d.ts +1 -5
- package/lib/tools/agents/actions.js +12 -1
- package/lib/tools/agents/contract.d.ts +50 -77
- package/lib/tools/agents/contract.js +54 -32
- package/lib/tools/agents/dsh-tool.js +6 -11
- package/lib/tools/history/contract.d.ts +28 -11
- package/lib/tools/history/contract.js +18 -12
- package/lib/tools/input.d.ts +11 -0
- package/lib/tools/input.js +23 -0
- package/lib/tools/teams/actions.d.ts +3 -4
- package/lib/tools/teams/actions.js +7 -5
- package/lib/tools/teams/contract.d.ts +56 -87
- package/lib/tools/teams/contract.js +55 -31
- package/lib/tools/teams/dsh-tool.js +7 -18
- package/lib/ui/dsh/management.js +1 -9
- package/lib/ui/dsh/styles.d.ts +1 -1
- package/lib/ui/dsh/styles.js +2 -2
- package/lib/ui/presentation.js +1 -1
- package/package.json +1 -4
- package/resources/claude/skills/pbot/SKILL.md +2 -3
- package/resources/prompts/native-coordinator.md +1 -1
- package/resources/prompts/workspace.md +1 -1
- package/resources/references/compute.md +6 -8
- package/scripts/README.md +2 -6
- package/src/common/schema.ts +10 -0
- package/src/extension/acp-member.ts +1 -3
- package/src/extension/acp-worker.ts +3 -12
- package/src/extension/agent-events.ts +1 -1
- package/src/extension/claude-hooks.ts +5 -25
- package/src/extension/command.ts +7 -16
- package/src/extension/dsh/acp-member.ts +1 -2
- package/src/extension/dsh/command.ts +14 -23
- package/src/extension/dsh/management.ts +3 -3
- package/src/extension/dsh/workspace.ts +5 -26
- package/src/extension/events.ts +2 -11
- package/src/extension/lifecycle.ts +8 -23
- package/src/extension/setup-cli.ts +4 -4
- package/src/extension/subagent-entry.ts +6 -12
- package/src/integrations/dsh/dsh-agents.ts +1 -4
- package/src/integrations/dsh/resources.ts +2 -5
- package/src/integrations/installation/processes.ts +0 -13
- package/src/integrations/pi/pi-agents.ts +12 -5
- package/src/model/agent.ts +1 -1
- package/src/pbot.ts +1 -2
- package/src/services/agents/agent-notices.ts +1 -1
- package/src/services/agents/agent-service.ts +4 -2
- package/src/services/agents/start-options.ts +19 -0
- package/src/tools/agents/actions.ts +18 -10
- package/src/tools/agents/contract.ts +68 -33
- package/src/tools/agents/dsh-tool.ts +7 -12
- package/src/tools/agents/tool.ts +2 -8
- package/src/tools/history/actions.ts +1 -1
- package/src/tools/history/contract.ts +27 -14
- package/src/tools/input.ts +29 -0
- package/src/tools/teams/actions.ts +10 -14
- package/src/tools/teams/contract.ts +71 -33
- package/src/tools/teams/dsh-tool.ts +7 -18
- package/src/tools/teams/tool.ts +3 -13
- package/src/ui/dsh/management.ts +2 -8
- package/src/ui/dsh/styles.ts +2 -2
- package/src/ui/presentation.ts +1 -1
- package/lib/integrations/process.d.ts +0 -14
- package/lib/integrations/process.js +0 -48
- package/lib/integrations/python-activation.d.ts +0 -2
- package/lib/integrations/python-activation.js +0 -29
- package/lib/services/workspace/python-environment-service.d.ts +0 -21
- package/lib/services/workspace/python-environment-service.js +0 -66
- package/lib/tools/agents/dsh-contract.d.ts +0 -45
- package/lib/tools/agents/dsh-contract.js +0 -19
- package/python/README.md +0 -72
- package/python/requirements.lock +0 -38
- package/scripts/setup-python.py +0 -170
- package/src/integrations/process.ts +0 -40
- package/src/integrations/python-activation.ts +0 -23
- package/src/services/workspace/python-environment-service.ts +0 -61
- package/src/tools/agents/dsh-contract.ts +0 -20
|
@@ -3,11 +3,10 @@ import { object, json } from "../../common/json.js";
|
|
|
3
3
|
import { requireThat } from "../../common/validation.js";
|
|
4
4
|
import { schema } from "../../common/schema.js";
|
|
5
5
|
import { executeAgent } from "../../tools/agents/actions.js";
|
|
6
|
-
import {
|
|
6
|
+
import { agentInput } from "../../tools/agents/contract.js";
|
|
7
7
|
import { executeTeam, executeTeamMessage } from "../../tools/teams/actions.js";
|
|
8
|
-
import {
|
|
8
|
+
import { teamInput, teamMessageInput } from "../../tools/teams/contract.js";
|
|
9
9
|
import { dshWorkspaceStatus } from "./management.js";
|
|
10
|
-
const validAgent = schema(dshAgentActionSchema), validTeam = schema(teamActionSchema), validMessage = schema(teamMessageActionSchema);
|
|
11
10
|
const chatSchema = Type.Object({ agentId: Type.String({ minLength: 1 }), text: Type.Optional(Type.String({ maxLength: 24000 })),
|
|
12
11
|
delivery: Type.Optional(Type.Union([Type.Literal("steer"), Type.Literal("followUp")])),
|
|
13
12
|
files: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 32 })) }, { additionalProperties: false });
|
|
@@ -15,10 +14,10 @@ const validChat = schema(chatSchema);
|
|
|
15
14
|
const approvalSchema = Type.Object({ agentId: Type.String({ minLength: 1 }), requestId: Type.String({ minLength: 1 }),
|
|
16
15
|
optionId: Type.Union([Type.String({ minLength: 1 }), Type.Null()]) }, { additionalProperties: false });
|
|
17
16
|
const validApproval = schema(approvalSchema);
|
|
18
|
-
const usage = '用法:/pbot status | init |
|
|
17
|
+
const usage = '用法:/pbot status | init | agent {"action":…} | chat {"agentId":…,"text":…} | team {"action":…} | messages {"teamId":…} | post {"teamId":…,"text":…} | history {"action":…} | records {"agentId":…}';
|
|
19
18
|
export function registerDshCommand(ctx, workspaces, management) {
|
|
20
19
|
ctx.commands.register({ name: "pbot", description: "Personal Bot 工作区与协作管理", recordInput: false,
|
|
21
|
-
input: { hint: "status | init |
|
|
20
|
+
input: { hint: "status | init | agent/chat/team/messages/post/history/records JSON", attachments: true },
|
|
22
21
|
async handler({ agent, rawInput, signal, attachments, commandId }) {
|
|
23
22
|
signal.throwIfAborted();
|
|
24
23
|
const command = rawInput.trim(), split = command.search(/\s/);
|
|
@@ -38,23 +37,16 @@ export function registerDshCommand(ctx, workspaces, management) {
|
|
|
38
37
|
signal.throwIfAborted();
|
|
39
38
|
const verb = split < 0 ? command : command.slice(0, split);
|
|
40
39
|
requireThat(verb === "chat" || !attachments.length, "输入框附件仅用于 chat 人工对话。");
|
|
41
|
-
if (command === "python setup") {
|
|
42
|
-
const result = await workspaces.preparePython();
|
|
43
|
-
workspace.check();
|
|
44
|
-
return { kind: "success", text: JSON.stringify(result, null, 2) };
|
|
45
|
-
}
|
|
46
40
|
requireThat(split >= 0, usage);
|
|
47
41
|
const input = JSON.parse(command.slice(split));
|
|
48
42
|
requireThat(object(input), "命令参数必须是 JSON 对象。");
|
|
49
43
|
let result;
|
|
50
44
|
switch (verb) {
|
|
51
45
|
case "agent": {
|
|
52
|
-
requireThat(validAgent(input), "dsh 专家参数无效或包含不支持的宿主选项。");
|
|
53
46
|
const selection = agent.model.current();
|
|
54
|
-
const output = await executeAgent(workspace.agents, input, workspace.owner, selection ? {
|
|
47
|
+
const output = await executeAgent(workspace.agents, agentInput(input), workspace.owner, selection ? {
|
|
55
48
|
provider: selection.provider, model: selection.model,
|
|
56
|
-
...(selection.reasoningEffort
|
|
57
|
-
? { thinking: selection.reasoningEffort } : {}),
|
|
49
|
+
...(selection.reasoningEffort ? { thinking: selection.reasoningEffort } : {}),
|
|
58
50
|
} : {});
|
|
59
51
|
result = output.structuredContent;
|
|
60
52
|
break;
|
|
@@ -72,17 +64,15 @@ export function registerDshCommand(ctx, workspaces, management) {
|
|
|
72
64
|
result = { answered: true };
|
|
73
65
|
break;
|
|
74
66
|
}
|
|
75
|
-
case "team":
|
|
76
|
-
|
|
77
|
-
result = executeTeam(workspace.teams, workspace.agents, input, workspace.owner).structuredContent;
|
|
67
|
+
case "team":
|
|
68
|
+
result = executeTeam(workspace.teams, workspace.agents, teamInput(input), workspace.owner).structuredContent;
|
|
78
69
|
break;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
result = executeTeamMessage(workspace.teams,
|
|
70
|
+
case "messages":
|
|
71
|
+
result = executeTeamMessage(workspace.teams, teamMessageInput({ ...input, action: "read" }), { kind: "coordinator", owner: workspace.owner }, commandId).structuredContent;
|
|
72
|
+
break;
|
|
73
|
+
case "post":
|
|
74
|
+
result = executeTeamMessage(workspace.teams, teamMessageInput({ ...input, action: "post" }), { kind: "user", owner: workspace.owner }, commandId).structuredContent;
|
|
84
75
|
break;
|
|
85
|
-
}
|
|
86
76
|
case "history":
|
|
87
77
|
result = await management.history({ parentSessionId: agent.id, input: json(input) }, signal);
|
|
88
78
|
break;
|
|
@@ -3,7 +3,7 @@ import type { Context } from "@deepseek-ai/cordis";
|
|
|
3
3
|
import { TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
4
4
|
import { type Json } from "../../common/json.js";
|
|
5
5
|
import type { DshWorkspaces, DshWorkspace } from "./workspace.js";
|
|
6
|
-
export declare function dshStatus(
|
|
6
|
+
export declare function dshStatus(workspace: DshWorkspace): Json;
|
|
7
7
|
/** Status remains available when this workspace has not opted in. */
|
|
8
8
|
export declare function dshWorkspaceStatus(workspaces: DshWorkspaces, agent: Agent): Promise<Json>;
|
|
9
9
|
/** Native Remote owns transport and access checks. These workspace reads do not admit or cancel execution. */
|
|
@@ -104,11 +104,11 @@ const teamSchema = Type.Object({ teamId: Type.String({ minLength: 1 }), afterSeq
|
|
|
104
104
|
seq: Type.Optional(Type.Integer({ minimum: 1 })), offset: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
105
105
|
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 16000 })) }, { additionalProperties: false });
|
|
106
106
|
const validRequest = schema(requestSchema), validExpert = schema(expertSchema), validTeam = schema(teamSchema);
|
|
107
|
-
export function dshStatus(
|
|
107
|
+
export function dshStatus(workspace) {
|
|
108
108
|
workspace.check();
|
|
109
109
|
const agents = workspace.agents.list(workspace.owner);
|
|
110
110
|
return json({ host: "dsh", release: packageVersion, enabled: true, state: "running", workspaceRoot: workspace.root, sessionId: workspace.agent.id,
|
|
111
|
-
model: workspace.agent.model.current() ?? null,
|
|
111
|
+
model: workspace.agent.model.current() ?? null,
|
|
112
112
|
controlError: workspace.controlError ?? null, history: workspace.history.status,
|
|
113
113
|
agents, permissions: workspace.agents.pendingPermissions(workspace.owner), teams: workspace.teams.list(workspace.owner, agents) });
|
|
114
114
|
}
|
|
@@ -119,7 +119,7 @@ export async function dshWorkspaceStatus(workspaces, agent) {
|
|
|
119
119
|
return json({ host: "dsh", release: packageVersion, enabled: false,
|
|
120
120
|
state: configuration.error ? "error" : "disabled", nextStep: configuration.error ? configuration.error : "/pbot init",
|
|
121
121
|
workspaceRoot: root, sessionId: agent.id, configuration, model: agent.model.current() ?? null, agents: [], teams: [] });
|
|
122
|
-
return json({ ...dshStatus(
|
|
122
|
+
return json({ ...dshStatus(await workspaces.get(agent)), configuration });
|
|
123
123
|
}
|
|
124
124
|
/** Native Remote owns transport and access checks. These workspace reads do not admit or cancel execution. */
|
|
125
125
|
let PbotManagement = (() => {
|
|
@@ -9,7 +9,6 @@ import { TeamService } from "../../services/agents/team-service.js";
|
|
|
9
9
|
import { DshAgentRuntime } from "./agent-runtime.js";
|
|
10
10
|
import { DshHistoryWork } from "./history.js";
|
|
11
11
|
import type { HistoryService } from "../../services/history/history-service.js";
|
|
12
|
-
import { PythonEnvironmentService } from "../../services/workspace/python-environment-service.js";
|
|
13
12
|
import type { WorkspaceConfiguration } from "../../model/workspace-config.js";
|
|
14
13
|
export declare const dshDependencies: string[];
|
|
15
14
|
export declare class DshWorkspace {
|
|
@@ -17,7 +16,6 @@ export declare class DshWorkspace {
|
|
|
17
16
|
readonly ctx: Context;
|
|
18
17
|
readonly root: string;
|
|
19
18
|
readonly agent: Agent;
|
|
20
|
-
readonly python: PythonEnvironmentService;
|
|
21
19
|
readonly component: AbortSignal;
|
|
22
20
|
private readonly historyWork;
|
|
23
21
|
private readonly releaseHistory;
|
|
@@ -27,7 +25,7 @@ export declare class DshWorkspace {
|
|
|
27
25
|
readonly teams: TeamService;
|
|
28
26
|
readonly history: HistoryService;
|
|
29
27
|
readonly owner: AgentOwner;
|
|
30
|
-
constructor(ctx: Context, root: string, agent: Agent,
|
|
28
|
+
constructor(ctx: Context, root: string, agent: Agent, component: AbortSignal, historyWork: DshHistoryWork, releaseHistory: () => Promise<void>, acp?: AcpCommands);
|
|
31
29
|
check: () => void;
|
|
32
30
|
get controlError(): string | undefined;
|
|
33
31
|
open(): Promise<void>;
|
|
@@ -66,11 +64,9 @@ export declare class DshWorkspace {
|
|
|
66
64
|
expert(id: string): DshAgentRuntime;
|
|
67
65
|
close(): Promise<void>;
|
|
68
66
|
}
|
|
69
|
-
/** The execution component owns Python; closing one Session must not undo its activation. */
|
|
70
67
|
export declare class DshWorkspaces {
|
|
71
68
|
#private;
|
|
72
69
|
readonly ctx: Context;
|
|
73
|
-
readonly python: PythonEnvironmentService;
|
|
74
70
|
constructor(ctx: Context);
|
|
75
71
|
private history;
|
|
76
72
|
open(agent: Agent): Promise<DshWorkspace | undefined>;
|
|
@@ -80,9 +76,5 @@ export declare class DshWorkspaces {
|
|
|
80
76
|
configuration: WorkspaceConfiguration;
|
|
81
77
|
}>;
|
|
82
78
|
initialize(agent: Agent): Promise<DshWorkspace>;
|
|
83
|
-
preparePython(): Promise<{
|
|
84
|
-
directory: string;
|
|
85
|
-
python: string;
|
|
86
|
-
}>;
|
|
87
79
|
close(): Promise<void>;
|
|
88
80
|
}
|
|
@@ -12,8 +12,6 @@ import { DshAgentEvents } from "./agent-events.js";
|
|
|
12
12
|
import { registerDshFileEvents } from "./files.js";
|
|
13
13
|
import { DshHistoryWork, registerDshHistoryEvents } from "./history.js";
|
|
14
14
|
import { registerDshHistoryTool } from "../../tools/history/dsh-tool.js";
|
|
15
|
-
import { activatePython } from "../../integrations/python-activation.js";
|
|
16
|
-
import { PythonEnvironmentService } from "../../services/workspace/python-environment-service.js";
|
|
17
15
|
import { requireThat } from "../../common/validation.js";
|
|
18
16
|
import { registerDshSkills } from "../../integrations/dsh/skills.js";
|
|
19
17
|
import { readWorkspaceConfig, workspaceDisabledMessage } from "../../services/workspace/workspace-config.js";
|
|
@@ -23,7 +21,6 @@ export class DshWorkspace {
|
|
|
23
21
|
ctx;
|
|
24
22
|
root;
|
|
25
23
|
agent;
|
|
26
|
-
python;
|
|
27
24
|
component;
|
|
28
25
|
historyWork;
|
|
29
26
|
releaseHistory;
|
|
@@ -37,11 +34,10 @@ export class DshWorkspace {
|
|
|
37
34
|
#scope;
|
|
38
35
|
#events;
|
|
39
36
|
#closing;
|
|
40
|
-
constructor(ctx, root, agent,
|
|
37
|
+
constructor(ctx, root, agent, component, historyWork, releaseHistory, acp) {
|
|
41
38
|
this.ctx = ctx;
|
|
42
39
|
this.root = root;
|
|
43
40
|
this.agent = agent;
|
|
44
|
-
this.python = python;
|
|
45
41
|
this.component = component;
|
|
46
42
|
this.historyWork = historyWork;
|
|
47
43
|
this.releaseHistory = releaseHistory;
|
|
@@ -49,15 +45,13 @@ export class DshWorkspace {
|
|
|
49
45
|
this.owner = { sessionId: agent.id, leaf: null, branch: [] };
|
|
50
46
|
this.host = new DshAgents(ctx, agent, {
|
|
51
47
|
setup: (d, _directory, generation) => async (agentCtx, child) => {
|
|
52
|
-
for (const key of ["noExtensions", "noPromptTemplates", "noContextFiles"])
|
|
53
|
-
requireThat(d.options[key] === undefined, "dsh 不支持宿主选项:" + key);
|
|
54
48
|
await agentCtx.plugin({ name: "pbot-expert", inject: dshDependencies, apply: async (scope) => {
|
|
55
49
|
const runtime = new DshAgentRuntime(scope, child, d, generation, this.agents.files, this.teams, { check: this.check, release: () => this.host.release(d.agentId, generation) });
|
|
56
50
|
this.#experts.set(d.agentId, runtime);
|
|
57
51
|
scope.effect(() => () => { if (this.#experts.get(d.agentId) === runtime)
|
|
58
52
|
this.#experts.delete(d.agentId); });
|
|
59
53
|
registerDshSkills(scope, child);
|
|
60
|
-
await dshResources(scope, child, root, "general-purpose",
|
|
54
|
+
await dshResources(scope, child, root, "general-purpose", runtime.check);
|
|
61
55
|
const teamTool = dshExpertTools(scope, child, d.options);
|
|
62
56
|
if (teamTool)
|
|
63
57
|
registerDshTeamMessageTool(scope, child, this.teams, runtime.actor, runtime.check);
|
|
@@ -84,7 +78,7 @@ export class DshWorkspace {
|
|
|
84
78
|
this.check();
|
|
85
79
|
this.#scope = await this.agent.ctx.plugin({ name: "pbot-coordinator", inject: dshDependencies, apply: async (ctx) => {
|
|
86
80
|
registerDshSkills(ctx, this.agent);
|
|
87
|
-
await dshResources(ctx, this.agent, this.root, "coordinator",
|
|
81
|
+
await dshResources(ctx, this.agent, this.root, "coordinator", this.check);
|
|
88
82
|
registerDshFileEvents(ctx, this.agent, this.root, false, this.check);
|
|
89
83
|
registerDshAgentTool(ctx, this.agent, this.agents, this.owner, this.check);
|
|
90
84
|
registerDshTeamTool(ctx, this.agent, this.teams, this.agents, this.owner, this.check);
|
|
@@ -170,18 +164,14 @@ export class DshWorkspace {
|
|
|
170
164
|
return this.#closing;
|
|
171
165
|
}
|
|
172
166
|
}
|
|
173
|
-
/** The execution component owns Python; closing one Session must not undo its activation. */
|
|
174
167
|
export class DshWorkspaces {
|
|
175
168
|
ctx;
|
|
176
|
-
python = new PythonEnvironmentService(process.cwd());
|
|
177
169
|
#parents = new Map();
|
|
178
170
|
#initializing = new Map();
|
|
179
171
|
#configurations = new Map();
|
|
180
172
|
#parentEffects = new Map();
|
|
181
173
|
#histories = new Map();
|
|
182
174
|
#lifetime = new AbortController();
|
|
183
|
-
#restorePython;
|
|
184
|
-
#preparing;
|
|
185
175
|
#closing;
|
|
186
176
|
constructor(ctx) {
|
|
187
177
|
this.ctx = ctx;
|
|
@@ -244,7 +234,7 @@ export class DshWorkspaces {
|
|
|
244
234
|
const history = await this.history(root);
|
|
245
235
|
let workspace;
|
|
246
236
|
try {
|
|
247
|
-
workspace = new DshWorkspace(this.ctx, root, agent, this
|
|
237
|
+
workspace = new DshWorkspace(this.ctx, root, agent, this.#lifetime.signal, history.work, history.release, configuration.acp);
|
|
248
238
|
const owned = workspace;
|
|
249
239
|
const dispose = agent.ctx.effect(() => async () => {
|
|
250
240
|
this.#parents.delete(agent);
|
|
@@ -255,7 +245,6 @@ export class DshWorkspaces {
|
|
|
255
245
|
this.#parentEffects.set(agent, dispose);
|
|
256
246
|
await workspace.open();
|
|
257
247
|
this.#lifetime.signal.throwIfAborted();
|
|
258
|
-
void this.preparePython().catch(error => this.ctx.logger.warn(String(error)));
|
|
259
248
|
return workspace;
|
|
260
249
|
}
|
|
261
250
|
catch (error) {
|
|
@@ -332,19 +321,6 @@ export class DshWorkspaces {
|
|
|
332
321
|
}
|
|
333
322
|
return this.get(agent);
|
|
334
323
|
}
|
|
335
|
-
preparePython() {
|
|
336
|
-
this.#lifetime.signal.throwIfAborted();
|
|
337
|
-
if (this.#preparing)
|
|
338
|
-
return this.#preparing;
|
|
339
|
-
this.#preparing = (async () => {
|
|
340
|
-
const result = await this.python.setup(this.#lifetime.signal);
|
|
341
|
-
this.#lifetime.signal.throwIfAborted();
|
|
342
|
-
if (!this.#restorePython)
|
|
343
|
-
this.#restorePython = activatePython(result.directory);
|
|
344
|
-
return result;
|
|
345
|
-
})().finally(() => { this.#preparing = undefined; });
|
|
346
|
-
return this.#preparing;
|
|
347
|
-
}
|
|
348
324
|
close() {
|
|
349
325
|
if (this.#closing)
|
|
350
326
|
return this.#closing;
|
|
@@ -356,7 +332,6 @@ export class DshWorkspaces {
|
|
|
356
332
|
const closed = await Promise.allSettled(opened.flatMap(value => value.status === "fulfilled" && value.value ? [value.value.close()] : []));
|
|
357
333
|
const effects = await Promise.allSettled([...this.#parentEffects.values()].map(dispose => dispose()));
|
|
358
334
|
const histories = await Promise.allSettled([...this.#histories.values()].map(value => value.work.close()));
|
|
359
|
-
await this.python.close();
|
|
360
335
|
const errors = [...new Set([...closed, ...effects, ...histories].flatMap(value => value.status === "rejected" ? [value.reason] : []))];
|
|
361
336
|
if (errors.length)
|
|
362
337
|
throw new AggregateError(errors, "部分 dsh 工作区未能完成关闭。");
|
|
@@ -366,8 +341,6 @@ export class DshWorkspaces {
|
|
|
366
341
|
this.#configurations.clear();
|
|
367
342
|
this.#parentEffects.clear();
|
|
368
343
|
this.#histories.clear();
|
|
369
|
-
this.#restorePython?.();
|
|
370
|
-
this.#restorePython = undefined;
|
|
371
344
|
}
|
|
372
345
|
})();
|
|
373
346
|
return this.#closing;
|
|
@@ -26,7 +26,7 @@ export async function main(args) {
|
|
|
26
26
|
if (options.action === "help") {
|
|
27
27
|
console.log("Personal Bot " + manifest.version + "\n\n用法:pbot setup [--workspace <目录>]\n" +
|
|
28
28
|
" npx personal-bot@latest setup\n\nsetup 安装或升级 Pi、pbot 和选中的插件,然后启动 Pi 执行 /pbot init。\n" +
|
|
29
|
-
"支持 Linux/macOS,需要 Node.js 22.19
|
|
29
|
+
"支持 Linux/macOS,需要 Node.js 22.19+ 和 npm。\n--help 显示帮助;--version 显示安装器版本。");
|
|
30
30
|
return 0;
|
|
31
31
|
}
|
|
32
32
|
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
@@ -40,7 +40,7 @@ export async function main(args) {
|
|
|
40
40
|
const ui = new SetupUI(controller), processes = new SetupProcesses(controller.signal);
|
|
41
41
|
try {
|
|
42
42
|
const cwd = process.cwd();
|
|
43
|
-
ui.text("Personal Bot " + manifest.version + " — 安装与升级\n正在检查 Node/npm
|
|
43
|
+
ui.text("Personal Bot " + manifest.version + " — 安装与升级\n正在检查 Node/npm 和 tmux…");
|
|
44
44
|
const system = await inspectSystem(processes, cwd);
|
|
45
45
|
const supplied = options.workspace ?? await ui.ask("工作区目录(当前、已有或新建目录)", cwd);
|
|
46
46
|
const workspace = await resolveWorkspace(supplied, cwd, homedir());
|
|
@@ -104,7 +104,7 @@ export async function main(args) {
|
|
|
104
104
|
const blocking = choices.find(choice => choice.required && choice.error);
|
|
105
105
|
if (blocking)
|
|
106
106
|
throw new Error(blocking.error);
|
|
107
|
-
ui.text("升级前请停止活动 pbot
|
|
107
|
+
ui.text("升级前请停止活动 pbot 子会话。Pi 为当前用户共用,插件只处理此工作区。");
|
|
108
108
|
if (!await ui.confirm("执行以上计划"))
|
|
109
109
|
return 130;
|
|
110
110
|
await mkdir(workspace, { recursive: true });
|
|
@@ -114,7 +114,7 @@ export async function main(args) {
|
|
|
114
114
|
const failed = result.results.some(item => item.state === "failed");
|
|
115
115
|
if (!result.pi)
|
|
116
116
|
return 1;
|
|
117
|
-
ui.text("\n
|
|
117
|
+
ui.text("\n软件安装阶段结束。工作区初始化和外部服务的状态由 Pi/pbot/插件分别报告。");
|
|
118
118
|
if (await ui.confirm(failed ? "部分插件失败,是否仍启动 Pi 并初始化启用工作区" : "启动 Pi 并初始化启用工作区", !failed)) {
|
|
119
119
|
process.stdin.pause();
|
|
120
120
|
await host.start(result.pi, workspace);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Context } from "@deepseek-ai/cordis";
|
|
2
2
|
import type { Agent, AgentSetup } from "@deepseek-ai/dsh-agent";
|
|
3
|
-
import type { AgentDescriptor,
|
|
3
|
+
import type { AgentDescriptor, AgentSessionReference } from "../../model/agent.js";
|
|
4
4
|
import type { AgentHost } from "../../services/agents/agent-service.js";
|
|
5
5
|
/** Native handles belong to the execution component, independently of browser observers. */
|
|
6
6
|
export declare class DshAgents implements AgentHost {
|
|
@@ -19,7 +19,6 @@ export declare class DshAgents implements AgentHost {
|
|
|
19
19
|
ready(agent: Agent, generation: string): void;
|
|
20
20
|
stopping(agent: Agent, generation: string): Promise<void>;
|
|
21
21
|
}, lifetime: AbortSignal);
|
|
22
|
-
validateOptions(options: AgentOptions): void;
|
|
23
22
|
available(): void;
|
|
24
23
|
alive(id: string): boolean;
|
|
25
24
|
private reference;
|
|
@@ -16,10 +16,6 @@ export class DshAgents {
|
|
|
16
16
|
this.composition = composition;
|
|
17
17
|
this.lifetime = lifetime;
|
|
18
18
|
}
|
|
19
|
-
validateOptions(options) {
|
|
20
|
-
for (const key of ["noExtensions", "noPromptTemplates", "noContextFiles"])
|
|
21
|
-
requireThat(options[key] === undefined, "dsh 不支持宿主选项:" + key);
|
|
22
|
-
}
|
|
23
19
|
available() {
|
|
24
20
|
this.lifetime.throwIfAborted();
|
|
25
21
|
requireThat(!this.#closed && this.ctx.agents.get(this.parent.id) === this.parent, "dsh 父会话或执行组件已关闭。");
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import type { Context } from "@deepseek-ai/cordis";
|
|
2
2
|
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
3
|
import type { AgentOptions } from "../../model/agent.js";
|
|
4
|
-
export declare function dshResources(ctx: Context, _agent: Agent, root: string, role: "coordinator" | "general-purpose",
|
|
5
|
-
state: string;
|
|
6
|
-
directory?: string;
|
|
7
|
-
error?: string;
|
|
8
|
-
}, check: () => void): Promise<void>;
|
|
4
|
+
export declare function dshResources(ctx: Context, _agent: Agent, root: string, role: "coordinator" | "general-purpose", check: () => void): Promise<void>;
|
|
9
5
|
/** Map the expert's native loadout; this is not isolation from Bash, CLI, or MCP. */
|
|
10
6
|
export declare function dshExpertTools(ctx: Context, agent: Agent, options: AgentOptions): boolean;
|
|
@@ -3,17 +3,14 @@ import { join } from "node:path";
|
|
|
3
3
|
import { agentText } from "../agent-resources.js";
|
|
4
4
|
import { resourceRoot } from "../../common/paths.js";
|
|
5
5
|
import { requireThat } from "../../common/validation.js";
|
|
6
|
-
export async function dshResources(ctx, _agent, root, role,
|
|
6
|
+
export async function dshResources(ctx, _agent, root, role, check) {
|
|
7
7
|
const read = () => Promise.all([agentText(role, root), readFile(join(resourceRoot, "prompts/workspace.md"), "utf8")]);
|
|
8
8
|
const [text, workspace] = await read();
|
|
9
9
|
check();
|
|
10
10
|
ctx.systemPrompt.section({ name: "pbot:role", order: 1, text, interpolate: false });
|
|
11
11
|
ctx.systemPrompt.section({ name: "pbot:workspace", order: 2, text: workspace, interpolate: false });
|
|
12
12
|
ctx.systemPrompt.context({ name: "pbot:environment", order: 300, required: true, interpolate: false,
|
|
13
|
-
text: ()
|
|
14
|
-
const { state, directory } = python();
|
|
15
|
-
return JSON.stringify({ workspaceRoot: root, resourceRoot, python: { state, ...(directory ? { directory } : {}) } });
|
|
16
|
-
} });
|
|
13
|
+
text: JSON.stringify({ workspaceRoot: root, resourceRoot }) });
|
|
17
14
|
ctx.on("system-prompt/assemble", async (_assembly, _context, next) => {
|
|
18
15
|
check();
|
|
19
16
|
const [roleText, workspaceText] = await read();
|
|
@@ -127,21 +127,6 @@ export async function inspectSystem(processes, cwd) {
|
|
|
127
127
|
const npm = await findExecutable("npm", processes.env);
|
|
128
128
|
if (!npm)
|
|
129
129
|
throw new Error("未找到 npm。请先安装 Node.js/npm。");
|
|
130
|
-
const python = await findExecutable("python3", processes.env) ?? await findExecutable("python", processes.env);
|
|
131
|
-
if (!python)
|
|
132
|
-
throw new Error("需要 Python 3.11+ 和 venv/ensurepip。请先安装后重试。");
|
|
133
|
-
try {
|
|
134
|
-
await processes.run(python, ["-I", "-B", "-c", [
|
|
135
|
-
"import sys, tempfile, venv, ensurepip",
|
|
136
|
-
"assert sys.version_info >= (3, 11), 'Python 3.11+ required'",
|
|
137
|
-
"with tempfile.TemporaryDirectory(prefix='pbot-python-check-') as path:",
|
|
138
|
-
" venv.EnvBuilder(with_pip=True).create(path)",
|
|
139
|
-
].join("\n")], cwd);
|
|
140
|
-
}
|
|
141
|
-
catch (error) {
|
|
142
|
-
processes.signal.throwIfAborted();
|
|
143
|
-
throw new Error("基础 Python 检查失败。需要 Python 3.11+ 和 venv/ensurepip;Debian/Ubuntu 还需 python3-venv。\n" + String(error));
|
|
144
|
-
}
|
|
145
130
|
const tmux = await findExecutable("tmux", processes.env);
|
|
146
131
|
if (tmux) {
|
|
147
132
|
await processes.run(tmux, ["-V"], cwd);
|
package/lib/model/agent.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export function teamNotice(values, known) {
|
|
|
5
5
|
if (!notes.length)
|
|
6
6
|
return;
|
|
7
7
|
return { kind: "teams", keys: notes.map(value => value.key), content: ["# 团队批次状态", "",
|
|
8
|
-
"团队批次状态已变化,用 pbot_team status
|
|
8
|
+
"团队批次状态已变化,用 pbot_team status 与 pbot_team_message read 查看状态和结果。暂停时可能仍有在途工作,重跑前先查看原请求结果。", "",
|
|
9
9
|
notes.map(value => ["## " + value.name, "", "- `teamId`: `" + value.teamId + "`", "- `runId`: `" + value.runId + "`",
|
|
10
10
|
"- 状态:" + value.state, "- 在途工作:" + value.activeCount, ...(value.reason ? ["", "### 原因", "", value.reason] : [])].join("\n")).join("\n\n")].join("\n") };
|
|
11
11
|
}
|
|
@@ -6,6 +6,7 @@ import { requireThat } from "../../common/validation.js";
|
|
|
6
6
|
import { AgentFiles, descriptor, launch, status, cycle } from "../../storage/agent-files.js";
|
|
7
7
|
import { TeamFiles } from "../../storage/team-files.js";
|
|
8
8
|
import { acpModelState, acpPermission, acpPermissionReply, acpReference } from "../../storage/acp-files.js";
|
|
9
|
+
import { applicableStartOptions } from "./start-options.js";
|
|
9
10
|
export class AgentService {
|
|
10
11
|
root;
|
|
11
12
|
host;
|
|
@@ -64,7 +65,7 @@ export class AgentService {
|
|
|
64
65
|
this.check();
|
|
65
66
|
const { backend, ...supplied } = input;
|
|
66
67
|
this.host.available(backend);
|
|
67
|
-
const options = Object.fromEntries(Object.entries(supplied).filter(([, v]) => v !== undefined));
|
|
68
|
+
const options = applicableStartOptions(this.host.kind, backend, Object.fromEntries(Object.entries(supplied).filter(([, v]) => v !== undefined)));
|
|
68
69
|
this.host.validateOptions?.(options, backend);
|
|
69
70
|
requireThat(backend || options.provider && options.model, "请选择可在专家会话使用的模型。");
|
|
70
71
|
const reference = backend ? this.host.prepare?.(backend, options) : undefined;
|
|
@@ -78,7 +79,7 @@ export class AgentService {
|
|
|
78
79
|
parentSessionId: owner.sessionId, parentLeaf: owner.leaf, createdAt: Date.now(), options: { ...options, files, cwd } };
|
|
79
80
|
const run = { generation: randomUUID(), name: options.name ?? agentId.slice(0, 8), sequence: 0, stop: false, startedAt: Date.now() };
|
|
80
81
|
this.files.create(d, run, reference);
|
|
81
|
-
const initial =
|
|
82
|
+
const initial = options.message ?? "";
|
|
82
83
|
const request = initial || files.length ? this.files.enqueue(agentId, initial, "steer", files) : undefined;
|
|
83
84
|
this.#starting.set(agentId, { generation: run.generation, controller: new AbortController(), stage: "launch" });
|
|
84
85
|
return { d, run, request };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AcpBackend } from "../../model/acp.js";
|
|
2
|
+
import type { AgentOptions, NativeAgentHost } from "../../model/agent.js";
|
|
3
|
+
/** Keep only options the effective target can use; declared-but-inapplicable fields are inert. */
|
|
4
|
+
export declare function applicableStartOptions(kind: NativeAgentHost, backend: AcpBackend | undefined, options: AgentOptions): AgentOptions;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const piOnly = ["noExtensions", "noPromptTemplates", "noContextFiles"];
|
|
2
|
+
/** Keep only options the effective target can use; declared-but-inapplicable fields are inert. */
|
|
3
|
+
export function applicableStartOptions(kind, backend, options) {
|
|
4
|
+
const result = { ...options };
|
|
5
|
+
if (backend) {
|
|
6
|
+
if (backend !== "pi") {
|
|
7
|
+
for (const key of piOnly)
|
|
8
|
+
delete result[key];
|
|
9
|
+
delete result.noSkills;
|
|
10
|
+
delete result.tools;
|
|
11
|
+
}
|
|
12
|
+
if (backend === "claude")
|
|
13
|
+
delete result.provider;
|
|
14
|
+
}
|
|
15
|
+
else if (kind !== "pi") {
|
|
16
|
+
for (const key of piOnly)
|
|
17
|
+
delete result[key];
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import type { Static } from "typebox";
|
|
2
1
|
import type { AgentService } from "../../services/agents/agent-service.js";
|
|
3
2
|
import type { AgentOptions, AgentOwner } from "../../model/agent.js";
|
|
4
|
-
import type {
|
|
5
|
-
export type AgentInput = Omit<Static<typeof agentParametersSchema>, "thinking"> & {
|
|
6
|
-
thinking?: string;
|
|
7
|
-
};
|
|
3
|
+
import type { AgentInput } from "./contract.js";
|
|
8
4
|
export declare function executeAgent(service: AgentService, input: AgentInput, owner: AgentOwner, defaults?: AgentOptions): Promise<{
|
|
9
5
|
isError?: boolean;
|
|
10
6
|
content: {
|
|
@@ -17,12 +17,23 @@ function agentOutput(view) {
|
|
|
17
17
|
...(view.nextOffset === undefined ? {} : { nextOffset: view.nextOffset }),
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
+
/** Parent selection is inherited only for a native expert; a chosen model drops the thinking default. */
|
|
21
|
+
function inherited(input, defaults) {
|
|
22
|
+
if (input.action !== "start" || input.backend)
|
|
23
|
+
return {};
|
|
24
|
+
const changed = Boolean(input.provider && defaults.provider && input.provider !== defaults.provider) ||
|
|
25
|
+
Boolean(input.model && defaults.model && input.model !== defaults.model);
|
|
26
|
+
const options = { ...defaults };
|
|
27
|
+
if (changed)
|
|
28
|
+
delete options.thinking;
|
|
29
|
+
return options;
|
|
30
|
+
}
|
|
20
31
|
export async function executeAgent(service, input, owner, defaults = {}) {
|
|
21
32
|
let value;
|
|
22
33
|
switch (input.action) {
|
|
23
34
|
case "start": {
|
|
24
35
|
const { action: _action, ...supplied } = input;
|
|
25
|
-
value = await service.start({ ...(
|
|
36
|
+
value = await service.start({ ...inherited(input, defaults), ...supplied }, owner);
|
|
26
37
|
break;
|
|
27
38
|
}
|
|
28
39
|
case "list": return markdownResult({ agents: service.list(owner).map(agentOutput) }, "子会话列表");
|