personal-bot 0.2.13 → 0.2.15
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 +3 -3
- 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 +7 -8
- 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 +6 -6
- package/docs/technical-design.md +18 -23
- 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 +10 -0
- package/lib/common/validation.d.ts +0 -2
- package/lib/common/validation.js +0 -10
- 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 +4 -8
- package/lib/extension/dsh/management.d.ts +1 -1
- package/lib/extension/dsh/management.js +5 -4
- package/lib/extension/dsh/workspace.d.ts +1 -9
- package/lib/extension/dsh/workspace.js +4 -29
- package/lib/extension/setup-cli.js +4 -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/tools/agents/dsh-tool.js +2 -1
- package/lib/tools/history/contract.js +2 -1
- package/lib/tools/history/dsh-tool.js +2 -1
- package/lib/tools/teams/dsh-tool.js +2 -1
- 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 -5
- package/resources/claude/skills/pbot/SKILL.md +2 -3
- package/resources/prompts/workspace.md +1 -1
- package/resources/references/compute.md +6 -8
- package/scripts/README.md +5 -9
- package/src/common/schema.ts +11 -0
- package/src/common/validation.ts +0 -11
- package/src/extension/acp-member.ts +1 -3
- package/src/extension/acp-worker.ts +3 -12
- 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 +4 -7
- package/src/extension/dsh/management.ts +5 -4
- package/src/extension/dsh/workspace.ts +5 -25
- 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/resources.ts +2 -5
- package/src/integrations/installation/processes.ts +0 -13
- package/src/integrations/pi/pi-agents.ts +12 -5
- package/src/pbot.ts +1 -2
- package/src/tools/agents/dsh-tool.ts +2 -1
- package/src/tools/agents/tool.ts +2 -1
- package/src/tools/history/contract.ts +2 -1
- package/src/tools/history/dsh-tool.ts +2 -1
- package/src/tools/teams/dsh-tool.ts +2 -1
- package/src/tools/teams/tool.ts +2 -1
- 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/npm-shrinkwrap.json +0 -13544
- 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
|
@@ -26,9 +26,7 @@ export async function acpMember() {
|
|
|
26
26
|
};
|
|
27
27
|
const context = async () => {
|
|
28
28
|
const [workspace, role] = await Promise.all([readFile(join(resourceRoot, "prompts/workspace.md"), "utf8"), agentText("general-purpose", d.workspace)]);
|
|
29
|
-
|
|
30
|
-
const python = state === "ready" && process.env.VIRTUAL_ENV ? { state, directory: process.env.VIRTUAL_ENV } : { state };
|
|
31
|
-
return { workspace, role, environment: JSON.stringify({ workspaceRoot: d.workspace, resourceRoot, python }) };
|
|
29
|
+
return { workspace, role, environment: JSON.stringify({ workspaceRoot: d.workspace, resourceRoot }) };
|
|
32
30
|
};
|
|
33
31
|
return { files, d, id, generation, check, context,
|
|
34
32
|
input() {
|
|
@@ -9,8 +9,6 @@ import { acpExecutable } from "../integrations/acp/launch.js";
|
|
|
9
9
|
import { claudeOptions } from "../integrations/acp/claude.js";
|
|
10
10
|
import { acpContent } from "../integrations/acp/input.js";
|
|
11
11
|
import { agentText } from "../integrations/agent-resources.js";
|
|
12
|
-
import { activatePython } from "../integrations/python-activation.js";
|
|
13
|
-
import { PythonEnvironmentService } from "../services/workspace/python-environment-service.js";
|
|
14
12
|
import { resourceRoot } from "../common/paths.js";
|
|
15
13
|
import { requireThat } from "../common/validation.js";
|
|
16
14
|
import { packageVersion, releaseLine } from "../common/version.js";
|
|
@@ -25,18 +23,13 @@ requireThat(files.directory(id) === directory, "ACP worker 目录不匹配。");
|
|
|
25
23
|
const d = files.read(id, "descriptor.json", descriptor), reference = files.read(id, "acp-session.json", acpReference);
|
|
26
24
|
requireThat(d.agentId === id && releaseLine(d.release) === releaseLine(packageVersion), "ACP worker 身份或版本不匹配。");
|
|
27
25
|
const validating = args.includes("--validate"), lifetime = new AbortController();
|
|
28
|
-
let execution: AcpAgentRun | undefined
|
|
29
|
-
const python = new PythonEnvironmentService(d.workspace);
|
|
26
|
+
let execution: AcpAgentRun | undefined;
|
|
30
27
|
const stop = () => { void execution?.stop().catch(error => lifetime.abort(error)); if (!execution) lifetime.abort(); };
|
|
31
28
|
process.on("SIGTERM", stop); process.on("SIGINT", stop);
|
|
32
29
|
|
|
33
30
|
async function main() {
|
|
34
31
|
requireThat(files.read(id!, "launch.json", launch).generation === generation, "ACP worker 启动代次已失效。");
|
|
35
|
-
|
|
36
|
-
try { const prepared = await python.setup(lifetime.signal); restorePython = activatePython(prepared.directory); }
|
|
37
|
-
catch { lifetime.signal.throwIfAborted(); }
|
|
38
|
-
}
|
|
39
|
-
const env = { ...process.env, PBOT_ACP_PYTHON_STATE: validating ? "unavailable" : python.status.state, PBOT_SUBAGENT_RUN_ID: id!, PBOT_SUBAGENT_DIR: directory!, PBOT_SUBAGENT_GENERATION: generation!,
|
|
32
|
+
const env = { ...process.env, PBOT_SUBAGENT_RUN_ID: id!, PBOT_SUBAGENT_DIR: directory!, PBOT_SUBAGENT_GENERATION: generation!,
|
|
40
33
|
...(validating ? { PBOT_ACP_VALIDATE: "1" } : {}) };
|
|
41
34
|
const command = { ...reference, args: [...reference.args] };
|
|
42
35
|
const packageRoot = resolve(resourceRoot, "..");
|
|
@@ -52,8 +45,7 @@ async function main() {
|
|
|
52
45
|
let prompt: string | undefined;
|
|
53
46
|
if (reference.backend === "claude") {
|
|
54
47
|
prompt = [await readFile(join(resourceRoot, "prompts/workspace.md"), "utf8"), await agentText("general-purpose", d.workspace),
|
|
55
|
-
JSON.stringify({ workspaceRoot: d.workspace, resourceRoot
|
|
56
|
-
? { state: "ready", directory: process.env.VIRTUAL_ENV } : { state: python.status.state } })].join("\n\n");
|
|
48
|
+
JSON.stringify({ workspaceRoot: d.workspace, resourceRoot })].join("\n\n");
|
|
57
49
|
}
|
|
58
50
|
const saveSelection = (selection: AcpModelSelection) => {
|
|
59
51
|
if (validating) return;
|
|
@@ -118,7 +110,6 @@ try {
|
|
|
118
110
|
process.exitCode = 1;
|
|
119
111
|
} finally {
|
|
120
112
|
lifetime.abort();
|
|
121
|
-
try { await python.close(); } finally { restorePython?.(); }
|
|
122
113
|
if (process.connected) process.disconnect();
|
|
123
114
|
// Keep child processes in this worker's process group so forced release covers descendants.
|
|
124
115
|
}
|
|
@@ -5,7 +5,6 @@ import { resourceRoot } from "../common/paths.js";
|
|
|
5
5
|
import { packageVersion } from "../common/version.js";
|
|
6
6
|
import { requireThat } from "../common/validation.js";
|
|
7
7
|
import { agentText } from "../integrations/agent-resources.js";
|
|
8
|
-
import { PythonEnvironmentService } from "../services/workspace/python-environment-service.js";
|
|
9
8
|
import { readWorkspaceConfig } from "../services/workspace/workspace-config.js";
|
|
10
9
|
import { initializeWorkspace } from "../services/workspace/workspace-preparation.js";
|
|
11
10
|
|
|
@@ -17,20 +16,6 @@ export async function claudeWorkspaceRoot(cwd: string, projectDirectory = proces
|
|
|
17
16
|
return root;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
async function pythonStatus(root: string, prepare: boolean, force = false) {
|
|
21
|
-
const python = new PythonEnvironmentService(root);
|
|
22
|
-
try {
|
|
23
|
-
if (force) await python.setup();
|
|
24
|
-
else {
|
|
25
|
-
const current = await python.inspect();
|
|
26
|
-
if (prepare && current.state === "unprepared") await python.setup();
|
|
27
|
-
}
|
|
28
|
-
} catch { /* The service retains the preparation or inspection error for status. */ }
|
|
29
|
-
finally { await python.close(); }
|
|
30
|
-
const status = python.status;
|
|
31
|
-
return { ...status, ...(status.state === "ready" ? { executable: join(status.directory!, "bin/python") } : {}) };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
19
|
function disabled(configuration: Awaited<ReturnType<typeof readWorkspaceConfig>>) {
|
|
35
20
|
return configuration.error ?? "Personal Bot 未在此工作区启用。运行 /personal-bot:pbot init;配置文件:" + configuration.path;
|
|
36
21
|
}
|
|
@@ -38,12 +23,10 @@ function disabled(configuration: Awaited<ReturnType<typeof readWorkspaceConfig>>
|
|
|
38
23
|
export async function claudeCommand(args: readonly string[], cwd: string) {
|
|
39
24
|
const root = await claudeWorkspaceRoot(cwd);
|
|
40
25
|
const action = args.join(" ");
|
|
41
|
-
requireThat(["init", "status"
|
|
26
|
+
requireThat(["init", "status"].includes(action), "用法:node <插件目录>/lib/claude.js init|status");
|
|
42
27
|
if (action === "init") await initializeWorkspace(root);
|
|
43
28
|
const configuration = await readWorkspaceConfig(root);
|
|
44
|
-
|
|
45
|
-
return { version: packageVersion, workspaceRoot: root, resourceRoot, configuration,
|
|
46
|
-
python: configuration.enabled ? await pythonStatus(root, action !== "status", action === "python setup") : { state: "unprepared" as const } };
|
|
29
|
+
return { version: packageVersion, workspaceRoot: root, resourceRoot, configuration };
|
|
47
30
|
}
|
|
48
31
|
|
|
49
32
|
/** Standard command hooks consume documented stdin fields; native sessions remain entirely host-owned. */
|
|
@@ -51,7 +34,7 @@ export async function claudeHook(value: unknown): Promise<Record<string, unknown
|
|
|
51
34
|
requireThat(object(value) && typeof value.hook_event_name === "string", "Claude hook 输入无效。");
|
|
52
35
|
if (process.env.PBOT_SUBAGENT_RUN_ID) return {};
|
|
53
36
|
const event = value.hook_event_name;
|
|
54
|
-
requireThat(["
|
|
37
|
+
requireThat(["UserPromptSubmit", "SubagentStart", "PreToolUse", "UserPromptExpansion"].includes(event), "Claude hook 事件未支持。");
|
|
55
38
|
const skillCheck = event === "PreToolUse" || event === "UserPromptExpansion";
|
|
56
39
|
if (skillCheck) {
|
|
57
40
|
const skill = event === "UserPromptExpansion"
|
|
@@ -72,8 +55,6 @@ export async function claudeHook(value: unknown): Promise<Record<string, unknown
|
|
|
72
55
|
hookSpecificOutput: { hookEventName: event, additionalContext: disabled(configuration) },
|
|
73
56
|
};
|
|
74
57
|
if (event === "SubagentStart" && value.agent_type !== "personal-bot:general-purpose") return {};
|
|
75
|
-
const python = await pythonStatus(root, event === "SessionStart" || event === "UserPromptSubmit");
|
|
76
|
-
if (event === "SessionStart") return python.state === "error" ? { systemMessage: python.error } : {};
|
|
77
58
|
const member = event === "SubagentStart" || typeof value.agent_id === "string";
|
|
78
59
|
const role = event === "SubagentStart" ? readFile(join(root, "agents/general-purpose.md"), "utf8").catch(error => {
|
|
79
60
|
if ((error as NodeJS.ErrnoException).code === "ENOENT") return "";
|
|
@@ -87,8 +68,7 @@ export async function claudeHook(value: unknown): Promise<Record<string, unknown
|
|
|
87
68
|
throw error;
|
|
88
69
|
}),
|
|
89
70
|
]);
|
|
90
|
-
return {
|
|
91
|
-
|
|
92
|
-
workspace, duties, agents, JSON.stringify({ workspaceRoot: root, resourceRoot, python }),
|
|
71
|
+
return { hookSpecificOutput: { hookEventName: event, additionalContext: [
|
|
72
|
+
workspace, duties, agents, JSON.stringify({ workspaceRoot: root, resourceRoot }),
|
|
93
73
|
].filter(Boolean).join("\n\n") } };
|
|
94
74
|
}
|
package/src/extension/command.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { initializeWorkspace } from "../services/workspace/workspace-preparation
|
|
|
4
4
|
import type { Confirmations } from "../ui/confirmation.js";
|
|
5
5
|
import { readPage } from "../ui/pi/reader.js";
|
|
6
6
|
import { choose } from "../ui/pi/menu.js";
|
|
7
|
-
import { stateLabel } from "../ui/presentation.js";
|
|
8
7
|
import { agentOwner } from "../integrations/pi/agent-context.js";
|
|
9
8
|
import type { Lifecycle } from "./lifecycle.js";
|
|
10
9
|
import { showAgents } from "./agents-command.js";
|
|
@@ -17,7 +16,7 @@ export function registerCommand(pi: ExtensionAPI, lifecycle: Lifecycle, confirma
|
|
|
17
16
|
description: "工作区、专家、团队与历史",
|
|
18
17
|
getArgumentCompletions: prefix => {
|
|
19
18
|
if (/\s/.test(prefix)) return null;
|
|
20
|
-
return ["init", "status", "history", "agents", "teams"
|
|
19
|
+
return ["init", "status", "history", "agents", "teams"]
|
|
21
20
|
.filter(command => command.startsWith(prefix)).map(command => ({ value: command, label: command }));
|
|
22
21
|
},
|
|
23
22
|
handler: async (args, ctx) => {
|
|
@@ -43,38 +42,30 @@ export function registerCommand(pi: ExtensionAPI, lifecycle: Lifecycle, confirma
|
|
|
43
42
|
async function execute(command: string | undefined, argument: string) {
|
|
44
43
|
const instance = lifecycle.get();
|
|
45
44
|
if (command === "status" && !argument) {
|
|
46
|
-
|
|
47
|
-
if (ctx.mode !== "tui") { ctx.ui.notify(JSON.stringify({ workspaceRoot: instance.root, release: packageVersion, enabled: true, state: "running", configuration: lifecycle.configuration, python }, null, 2), "info"); return; }
|
|
45
|
+
if (ctx.mode !== "tui") { ctx.ui.notify(JSON.stringify({ workspaceRoot: instance.root, release: packageVersion, enabled: true, state: "running", configuration: lifecycle.configuration }, null, 2), "info"); return; }
|
|
48
46
|
const agents = instance.agents.list(agentOwner(ctx)), history = instance.history.status;
|
|
49
47
|
await readPage(ctx, "工作区", [instance.root, "", "状态 已启动", `配置 ${lifecycle.configuration?.path ?? ""}`, `版本 ${packageVersion}`,
|
|
50
48
|
`模型 ${ctx.model && !(ctx.model.provider === "unknown" && ctx.model.id === "unknown") ? ctx.model.provider + "/" + ctx.model.id : "未选择"}`,
|
|
51
49
|
`专家 ${agents.length} 位 · ${agents.filter(value => value.alive).length} 位存活`,
|
|
52
|
-
`Python ${stateLabel(python.state)}`, ...(python.directory ? [python.directory] : []), ...(python.error ? ["", python.error] : []),
|
|
53
50
|
"", `历史 ${history.organizing ? "整理中" : history.pending === null ? "查询时更新索引" : history.pending + " 项待整理"}`,
|
|
54
51
|
...history.warnings].join("\n")); return;
|
|
55
52
|
}
|
|
56
53
|
if (command === "history") { await showHistory(instance, ctx, argument); return; }
|
|
57
54
|
if (command === "agents") { await showAgents(pi, instance, ctx, confirmations); return; }
|
|
58
55
|
if (command === "teams") { await showTeams(pi, instance, ctx, confirmations); return; }
|
|
59
|
-
|
|
60
|
-
const cancel = instance.signal(ctx.signal); await ctx.waitForIdle();
|
|
61
|
-
ctx.ui.notify("正在准备 Python…", "info");
|
|
62
|
-
const result = await instance.preparePython(cancel);
|
|
63
|
-
ctx.ui.notify(ctx.mode === "tui" ? "Python 已就绪。" : JSON.stringify(result, null, 2), "info"); return;
|
|
64
|
-
}
|
|
65
|
-
ctx.ui.notify("/pbot init | status | history [关键词] | agents | teams | python setup", "info");
|
|
56
|
+
ctx.ui.notify("/pbot init | status | history [关键词] | agents | teams", "info");
|
|
66
57
|
}
|
|
67
58
|
if (command || ctx.mode !== "tui") { await execute(command, argument); return; }
|
|
68
59
|
if (confirmations.presenting) { ctx.ui.notify("请先处理待确认操作。", "info"); return; }
|
|
69
60
|
for (;;) {
|
|
70
61
|
const instance = lifecycle.get(), agents = instance.agents.list(agentOwner(ctx));
|
|
71
|
-
const choices = ["专家 · " + agents.length, "团队", "历史", "工作区状态", "准备资料目录"
|
|
72
|
-
const choice = await choose(ctx,
|
|
62
|
+
const choices = ["专家 · " + agents.length, "团队", "历史", "工作区状态", "准备资料目录"];
|
|
63
|
+
const choice = await choose(ctx, "Personal Bot", choices);
|
|
73
64
|
if (!choice) return;
|
|
74
|
-
const command = ["agents", "teams", "history", "status", "init"
|
|
65
|
+
const command = ["agents", "teams", "history", "status", "init"][choices.indexOf(choice)]!;
|
|
75
66
|
try {
|
|
76
67
|
if (command === "init") { await ctx.waitForIdle(); instance.check(); await initializeWorkspace(instance.root); ctx.ui.notify("资料目录已准备。", "info"); }
|
|
77
|
-
else await execute(command,
|
|
68
|
+
else await execute(command, "");
|
|
78
69
|
}
|
|
79
70
|
catch (error) { ctx.ui.notify(error instanceof Error ? error.message : String(error), "error"); }
|
|
80
71
|
}
|
|
@@ -25,8 +25,7 @@ export async function apply(ctx: Context) {
|
|
|
25
25
|
await agent.ctx.plugin({ name: "pbot-acp-expert", inject, apply: async scope => {
|
|
26
26
|
registerDshSkills(scope, agent);
|
|
27
27
|
dshExpertTools(scope, agent, member.d.options);
|
|
28
|
-
await dshResources(scope, agent, member.d.workspace, "general-purpose",
|
|
29
|
-
? { state: "ready", directory: process.env.VIRTUAL_ENV } : { state: process.env.PBOT_ACP_PYTHON_STATE ?? "unavailable" }, member.check);
|
|
28
|
+
await dshResources(scope, agent, member.d.workspace, "general-purpose", member.check);
|
|
30
29
|
registerDshFileEvents(scope, agent, member.d.workspace, true, member.check);
|
|
31
30
|
let input: AcpInput | undefined, answer = "";
|
|
32
31
|
scope.on("session/event", (session, event) => {
|
|
@@ -2,7 +2,8 @@ import type { Context } from "@deepseek-ai/cordis";
|
|
|
2
2
|
import type {} from "@deepseek-ai/dsh-commands";
|
|
3
3
|
import { Type, type Static } from "typebox";
|
|
4
4
|
import { object, json } from "../../common/json.js";
|
|
5
|
-
import { requireThat
|
|
5
|
+
import { requireThat } from "../../common/validation.js";
|
|
6
|
+
import { schema } from "../../common/schema.js";
|
|
6
7
|
import { executeAgent, type AgentInput } from "../../tools/agents/actions.js";
|
|
7
8
|
import { dshAgentActionSchema } from "../../tools/agents/dsh-contract.js";
|
|
8
9
|
import { executeTeam, executeTeamMessage } from "../../tools/teams/actions.js";
|
|
@@ -18,11 +19,11 @@ const validChat = schema(chatSchema);
|
|
|
18
19
|
const approvalSchema = Type.Object({ agentId: Type.String({ minLength: 1 }), requestId: Type.String({ minLength: 1 }),
|
|
19
20
|
optionId: Type.Union([Type.String({ minLength: 1 }), Type.Null()]) }, { additionalProperties: false });
|
|
20
21
|
const validApproval = schema(approvalSchema);
|
|
21
|
-
const usage = '用法:/pbot status | init |
|
|
22
|
+
const usage = '用法:/pbot status | init | agent {"action":…} | chat {"agentId":…,"text":…} | team {"action":…} | post {"teamId":…,"text":…} | history {"action":…} | records {"agentId":…}';
|
|
22
23
|
|
|
23
24
|
export function registerDshCommand(ctx: Context, workspaces: DshWorkspaces, management: PbotManagement) {
|
|
24
25
|
ctx.commands.register({ name: "pbot", description: "Personal Bot 工作区与协作管理", recordInput: false,
|
|
25
|
-
input: { hint: "status | init |
|
|
26
|
+
input: { hint: "status | init | agent/chat/team/post/history/records JSON", attachments: true },
|
|
26
27
|
async handler({ agent, rawInput, signal, attachments, commandId }) {
|
|
27
28
|
signal.throwIfAborted();
|
|
28
29
|
const command = rawInput.trim(), split = command.search(/\s/);
|
|
@@ -41,10 +42,6 @@ export function registerDshCommand(ctx: Context, workspaces: DshWorkspaces, mana
|
|
|
41
42
|
signal.throwIfAborted();
|
|
42
43
|
const verb = split < 0 ? command : command.slice(0, split);
|
|
43
44
|
requireThat(verb === "chat" || !attachments.length, "输入框附件仅用于 chat 人工对话。");
|
|
44
|
-
if (command === "python setup") {
|
|
45
|
-
const result = await workspaces.preparePython(); workspace.check();
|
|
46
|
-
return { kind: "success", text: JSON.stringify(result, null, 2) };
|
|
47
|
-
}
|
|
48
45
|
requireThat(split >= 0, usage);
|
|
49
46
|
const input: unknown = JSON.parse(command.slice(split));
|
|
50
47
|
requireThat(object(input), "命令参数必须是 JSON 对象。");
|
|
@@ -6,7 +6,8 @@ import { SessionId } from "@deepseek-ai/dsh-session";
|
|
|
6
6
|
import { extractSessionEventText } from "@deepseek-ai/dsh-session-query";
|
|
7
7
|
import { Type, type Static } from "typebox";
|
|
8
8
|
import { json, type Json } from "../../common/json.js";
|
|
9
|
-
import { requireThat
|
|
9
|
+
import { requireThat } from "../../common/validation.js";
|
|
10
|
+
import { schema } from "../../common/schema.js";
|
|
10
11
|
import { packageVersion } from "../../common/version.js";
|
|
11
12
|
import { historyInput } from "../../tools/history/contract.js";
|
|
12
13
|
import { executeHistory } from "../../tools/history/actions.js";
|
|
@@ -23,11 +24,11 @@ const teamSchema = Type.Object({ teamId: Type.String({ minLength: 1 }), afterSeq
|
|
|
23
24
|
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 16000 })) }, { additionalProperties: false });
|
|
24
25
|
const validRequest = schema(requestSchema), validExpert = schema(expertSchema), validTeam = schema(teamSchema);
|
|
25
26
|
|
|
26
|
-
export function dshStatus(
|
|
27
|
+
export function dshStatus(workspace: DshWorkspace): Json {
|
|
27
28
|
workspace.check();
|
|
28
29
|
const agents = workspace.agents.list(workspace.owner);
|
|
29
30
|
return json({ host: "dsh", release: packageVersion, enabled: true, state: "running", workspaceRoot: workspace.root, sessionId: workspace.agent.id,
|
|
30
|
-
model: workspace.agent.model.current() ?? null,
|
|
31
|
+
model: workspace.agent.model.current() ?? null,
|
|
31
32
|
controlError: workspace.controlError ?? null, history: workspace.history.status,
|
|
32
33
|
agents, permissions: workspace.agents.pendingPermissions(workspace.owner), teams: workspace.teams.list(workspace.owner, agents) });
|
|
33
34
|
}
|
|
@@ -38,7 +39,7 @@ export async function dshWorkspaceStatus(workspaces: DshWorkspaces, agent: Agent
|
|
|
38
39
|
if (!configuration.enabled) return json({ host: "dsh", release: packageVersion, enabled: false,
|
|
39
40
|
state: configuration.error ? "error" : "disabled", nextStep: configuration.error ? configuration.error : "/pbot init",
|
|
40
41
|
workspaceRoot: root, sessionId: agent.id, configuration, model: agent.model.current() ?? null, agents: [], teams: [] });
|
|
41
|
-
return json({ ...dshStatus(
|
|
42
|
+
return json({ ...dshStatus(await workspaces.get(agent)) as Record<string, Json>, configuration });
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
/** Native Remote owns transport and access checks. These workspace reads do not admit or cancel execution. */
|
|
@@ -18,8 +18,6 @@ import { registerDshFileEvents } from "./files.js";
|
|
|
18
18
|
import { DshHistoryWork, registerDshHistoryEvents } from "./history.js";
|
|
19
19
|
import type { HistoryService } from "../../services/history/history-service.js";
|
|
20
20
|
import { registerDshHistoryTool } from "../../tools/history/dsh-tool.js";
|
|
21
|
-
import { activatePython } from "../../integrations/python-activation.js";
|
|
22
|
-
import { PythonEnvironmentService } from "../../services/workspace/python-environment-service.js";
|
|
23
21
|
import { requireThat } from "../../common/validation.js";
|
|
24
22
|
import { registerDshSkills } from "../../integrations/dsh/skills.js";
|
|
25
23
|
import { readWorkspaceConfig, workspaceDisabledMessage } from "../../services/workspace/workspace-config.js";
|
|
@@ -40,7 +38,7 @@ export class DshWorkspace {
|
|
|
40
38
|
#events: DshAgentEvents | undefined;
|
|
41
39
|
#closing: Promise<void> | undefined;
|
|
42
40
|
constructor(readonly ctx: Context, readonly root: string, readonly agent: Agent,
|
|
43
|
-
readonly
|
|
41
|
+
readonly component: AbortSignal,
|
|
44
42
|
private readonly historyWork: DshHistoryWork, private readonly releaseHistory: () => Promise<void>, acp?: AcpCommands) {
|
|
45
43
|
this.history = historyWork.service;
|
|
46
44
|
this.owner = { sessionId: agent.id, leaf: null, branch: [] };
|
|
@@ -53,7 +51,7 @@ export class DshWorkspace {
|
|
|
53
51
|
this.#experts.set(d.agentId, runtime);
|
|
54
52
|
scope.effect(() => () => { if (this.#experts.get(d.agentId) === runtime) this.#experts.delete(d.agentId); });
|
|
55
53
|
registerDshSkills(scope, child);
|
|
56
|
-
await dshResources(scope, child, root, "general-purpose",
|
|
54
|
+
await dshResources(scope, child, root, "general-purpose", runtime.check);
|
|
57
55
|
const teamTool = dshExpertTools(scope, child, d.options);
|
|
58
56
|
if (teamTool) registerDshTeamMessageTool(scope, child, this.teams, runtime.actor, runtime.check);
|
|
59
57
|
registerDshFileEvents(scope, child, root, true, runtime.check);
|
|
@@ -77,7 +75,7 @@ export class DshWorkspace {
|
|
|
77
75
|
this.check();
|
|
78
76
|
this.#scope = await this.agent.ctx.plugin({ name: "pbot-coordinator", inject: dshDependencies, apply: async ctx => {
|
|
79
77
|
registerDshSkills(ctx, this.agent);
|
|
80
|
-
await dshResources(ctx, this.agent, this.root, "coordinator",
|
|
78
|
+
await dshResources(ctx, this.agent, this.root, "coordinator", this.check);
|
|
81
79
|
registerDshFileEvents(ctx, this.agent, this.root, false, this.check);
|
|
82
80
|
registerDshAgentTool(ctx, this.agent, this.agents, this.owner, this.check);
|
|
83
81
|
registerDshTeamTool(ctx, this.agent, this.teams, this.agents, this.owner, this.check);
|
|
@@ -129,17 +127,13 @@ export class DshWorkspace {
|
|
|
129
127
|
}
|
|
130
128
|
}
|
|
131
129
|
|
|
132
|
-
/** The execution component owns Python; closing one Session must not undo its activation. */
|
|
133
130
|
export class DshWorkspaces {
|
|
134
|
-
readonly python = new PythonEnvironmentService(process.cwd());
|
|
135
131
|
readonly #parents = new Map<Agent, Promise<DshWorkspace | undefined>>();
|
|
136
132
|
readonly #initializing = new Map<string, Promise<void>>();
|
|
137
133
|
readonly #configurations = new Map<Agent, { root: string; configuration: WorkspaceConfiguration }>();
|
|
138
134
|
readonly #parentEffects = new Map<Agent, () => Promise<void>>();
|
|
139
135
|
readonly #histories = new Map<string, { work: DshHistoryWork; users: number }>();
|
|
140
136
|
readonly #lifetime = new AbortController();
|
|
141
|
-
#restorePython: (() => void) | undefined;
|
|
142
|
-
#preparing: Promise<{ directory: string; python: string }> | undefined;
|
|
143
137
|
#closing: Promise<void> | undefined;
|
|
144
138
|
constructor(readonly ctx: Context) {}
|
|
145
139
|
|
|
@@ -184,14 +178,13 @@ export class DshWorkspaces {
|
|
|
184
178
|
const history = await this.history(root);
|
|
185
179
|
let workspace: DshWorkspace | undefined;
|
|
186
180
|
try {
|
|
187
|
-
workspace = new DshWorkspace(this.ctx, root, agent, this
|
|
181
|
+
workspace = new DshWorkspace(this.ctx, root, agent, this.#lifetime.signal, history.work, history.release, configuration.acp);
|
|
188
182
|
const owned = workspace;
|
|
189
183
|
const dispose = agent.ctx.effect(() => async () => {
|
|
190
184
|
this.#parents.delete(agent); this.#configurations.delete(agent); this.#parentEffects.delete(agent); await owned.close();
|
|
191
185
|
});
|
|
192
186
|
this.#parentEffects.set(agent, dispose);
|
|
193
187
|
await workspace.open(); this.#lifetime.signal.throwIfAborted();
|
|
194
|
-
void this.preparePython().catch(error => this.ctx.logger.warn(String(error)));
|
|
195
188
|
return workspace;
|
|
196
189
|
} catch (error) {
|
|
197
190
|
try {
|
|
@@ -249,18 +242,6 @@ export class DshWorkspaces {
|
|
|
249
242
|
return this.get(agent);
|
|
250
243
|
}
|
|
251
244
|
|
|
252
|
-
preparePython() {
|
|
253
|
-
this.#lifetime.signal.throwIfAborted();
|
|
254
|
-
if (this.#preparing) return this.#preparing;
|
|
255
|
-
this.#preparing = (async () => {
|
|
256
|
-
const result = await this.python.setup(this.#lifetime.signal);
|
|
257
|
-
this.#lifetime.signal.throwIfAborted();
|
|
258
|
-
if (!this.#restorePython) this.#restorePython = activatePython(result.directory);
|
|
259
|
-
return result;
|
|
260
|
-
})().finally(() => { this.#preparing = undefined; });
|
|
261
|
-
return this.#preparing;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
245
|
close() {
|
|
265
246
|
if (this.#closing) return this.#closing;
|
|
266
247
|
this.#lifetime.abort();
|
|
@@ -271,10 +252,9 @@ export class DshWorkspaces {
|
|
|
271
252
|
const closed = await Promise.allSettled(opened.flatMap(value => value.status === "fulfilled" && value.value ? [value.value.close()] : []));
|
|
272
253
|
const effects = await Promise.allSettled([...this.#parentEffects.values()].map(dispose => dispose()));
|
|
273
254
|
const histories = await Promise.allSettled([...this.#histories.values()].map(value => value.work.close()));
|
|
274
|
-
await this.python.close();
|
|
275
255
|
const errors = [...new Set([...closed, ...effects, ...histories].flatMap(value => value.status === "rejected" ? [value.reason] : []))];
|
|
276
256
|
if (errors.length) throw new AggregateError(errors, "部分 dsh 工作区未能完成关闭。");
|
|
277
|
-
} finally { this.#parents.clear(); this.#configurations.clear(); this.#parentEffects.clear(); this.#histories.clear();
|
|
257
|
+
} finally { this.#parents.clear(); this.#configurations.clear(); this.#parentEffects.clear(); this.#histories.clear(); }
|
|
278
258
|
})();
|
|
279
259
|
return this.#closing;
|
|
280
260
|
}
|
package/src/extension/events.ts
CHANGED
|
@@ -20,14 +20,6 @@ export function registerEvents(pi: ExtensionAPI, lifecycle: Lifecycle, confirmat
|
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
22
|
ctx.ui.setStatus("pbot", "PBot 已启动");
|
|
23
|
-
if (ctx.mode === "tui") ctx.ui.setStatus("pbot-python", "Python 准备中");
|
|
24
|
-
else ctx.ui.notify("正在准备共享 Python 环境;首次安装可能需要数分钟。", "info");
|
|
25
|
-
try { await lifecycle.get().preparePython(); }
|
|
26
|
-
catch (error) {
|
|
27
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
28
|
-
if (ctx.mode === "tui") ctx.ui.notify("Python 未就绪;/pbot status 查看详情。", "warning");
|
|
29
|
-
else if (ctx.hasUI) ctx.ui.notify(message, "warning"); else console.error(message);
|
|
30
|
-
} finally { if (ctx.mode === "tui") ctx.ui.setStatus("pbot-python", undefined); }
|
|
31
23
|
} catch (error) {
|
|
32
24
|
ctx.ui.setStatus("pbot", "PBot 启动失败");
|
|
33
25
|
if (ctx.hasUI) ctx.ui.notify(error instanceof Error ? error.message : "pbot 启动失败。", "error");
|
|
@@ -46,10 +38,9 @@ export function registerEvents(pi: ExtensionAPI, lifecycle: Lifecycle, confirmat
|
|
|
46
38
|
const role = await agentText("coordinator", instance.root);
|
|
47
39
|
const workspace = await readFile(join(resourceRoot, "prompts/workspace.md"), "utf8");
|
|
48
40
|
instance.check();
|
|
49
|
-
const { state, directory } = instance.pythonEnvironment.status;
|
|
50
41
|
Object.assign(event.systemPromptOptions.sections, {
|
|
51
42
|
pbot_workspace: workspace,
|
|
52
|
-
pbot_environment: JSON.stringify({ workspaceRoot: instance.root, resourceRoot
|
|
43
|
+
pbot_environment: JSON.stringify({ workspaceRoot: instance.root, resourceRoot }),
|
|
53
44
|
pbot: role,
|
|
54
45
|
});
|
|
55
46
|
} catch (error) {
|
|
@@ -65,7 +56,7 @@ export function registerEvents(pi: ExtensionAPI, lifecycle: Lifecycle, confirmat
|
|
|
65
56
|
pi.on("session_shutdown", async (event, ctx) => {
|
|
66
57
|
const preserve = event.reason === "reload" && lifecycle.root && (await readWorkspaceConfig(lifecycle.root)).enabled;
|
|
67
58
|
try { await lifecycle.close(Boolean(preserve)); }
|
|
68
|
-
finally { ctx.ui.setStatus("pbot", undefined);
|
|
59
|
+
finally { ctx.ui.setStatus("pbot", undefined); }
|
|
69
60
|
});
|
|
70
61
|
pi.on("tool_call", async (event, ctx) => {
|
|
71
62
|
const instance = lifecycle.active;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { realpath } from "node:fs/promises";
|
|
2
|
-
import { activatePython } from "../integrations/python-activation.js";
|
|
3
2
|
import { requireThat } from "../common/validation.js";
|
|
4
3
|
import { authorizeMutation } from "../services/workspace/workspace-files.js";
|
|
5
4
|
import type { AgentOwner } from "../model/agent.js";
|
|
6
|
-
import type { PythonEnvironmentService } from "../services/workspace/python-environment-service.js";
|
|
7
5
|
import type { AgentService } from "../services/agents/agent-service.js";
|
|
8
6
|
import type { TeamService } from "../services/agents/team-service.js";
|
|
9
7
|
import type { CallAccess } from "../tools/access.js";
|
|
@@ -15,18 +13,7 @@ export class WorkspaceInstance implements CallAccess {
|
|
|
15
13
|
readonly #controller = new AbortController();
|
|
16
14
|
#work = new AbortController();
|
|
17
15
|
#closing: Promise<void> | undefined;
|
|
18
|
-
|
|
19
|
-
constructor(readonly root: string, readonly pythonEnvironment: PythonEnvironmentService, readonly agents: AgentService,
|
|
20
|
-
readonly teams: TeamService, readonly history: HistoryService) {}
|
|
21
|
-
async preparePython(signal?: AbortSignal) {
|
|
22
|
-
this.check();
|
|
23
|
-
this.#restorePython?.();
|
|
24
|
-
this.#restorePython = undefined;
|
|
25
|
-
const result = await this.pythonEnvironment.setup(signal);
|
|
26
|
-
this.check();
|
|
27
|
-
this.#restorePython ??= activatePython(result.directory);
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
16
|
+
constructor(readonly root: string, readonly agents: AgentService, readonly teams: TeamService, readonly history: HistoryService) {}
|
|
30
17
|
check() {
|
|
31
18
|
requireThat(!this.#controller.signal.aborted, "pbot 工作区实例已关闭。");
|
|
32
19
|
}
|
|
@@ -49,15 +36,13 @@ export class WorkspaceInstance implements CallAccess {
|
|
|
49
36
|
this.#controller.abort();
|
|
50
37
|
this.#work.abort();
|
|
51
38
|
this.#closing = (async () => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (errors.length) throw new AggregateError(errors, "工作区关闭失败。");
|
|
60
|
-
} finally { this.#restorePython?.(); this.#restorePython = undefined; }
|
|
39
|
+
const errors: unknown[] = [];
|
|
40
|
+
try { if (this.agentOwner) this.teams.pauseAll(this.agentOwner, "主会话关闭或重新载入"); }
|
|
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));
|
|
45
|
+
if (errors.length) throw new AggregateError(errors, "工作区关闭失败。");
|
|
61
46
|
})();
|
|
62
47
|
return this.#closing;
|
|
63
48
|
}
|
|
@@ -21,7 +21,7 @@ export async function main(args: string[]): Promise<number> {
|
|
|
21
21
|
if (options.action === "help") {
|
|
22
22
|
console.log("Personal Bot " + manifest.version + "\n\n用法:pbot setup [--workspace <目录>]\n" +
|
|
23
23
|
" npx personal-bot@latest setup\n\nsetup 安装或升级 Pi、pbot 和选中的插件,然后启动 Pi 执行 /pbot init。\n" +
|
|
24
|
-
"支持 Linux/macOS,需要 Node.js 22.19
|
|
24
|
+
"支持 Linux/macOS,需要 Node.js 22.19+ 和 npm。\n--help 显示帮助;--version 显示安装器版本。");
|
|
25
25
|
return 0;
|
|
26
26
|
}
|
|
27
27
|
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
@@ -33,7 +33,7 @@ export async function main(args: string[]): Promise<number> {
|
|
|
33
33
|
const ui = new SetupUI(controller), processes = new SetupProcesses(controller.signal);
|
|
34
34
|
try {
|
|
35
35
|
const cwd = process.cwd();
|
|
36
|
-
ui.text("Personal Bot " + manifest.version + " — 安装与升级\n正在检查 Node/npm
|
|
36
|
+
ui.text("Personal Bot " + manifest.version + " — 安装与升级\n正在检查 Node/npm 和 tmux…");
|
|
37
37
|
const system = await inspectSystem(processes, cwd);
|
|
38
38
|
const supplied = options.workspace ?? await ui.ask("工作区目录(当前、已有或新建目录)", cwd);
|
|
39
39
|
const workspace = await resolveWorkspace(supplied, cwd, homedir());
|
|
@@ -84,14 +84,14 @@ export async function main(args: string[]): Promise<number> {
|
|
|
84
84
|
}
|
|
85
85
|
const blocking = choices.find(choice => choice.required && choice.error);
|
|
86
86
|
if (blocking) throw new Error(blocking.error);
|
|
87
|
-
ui.text("升级前请停止活动 pbot
|
|
87
|
+
ui.text("升级前请停止活动 pbot 子会话。Pi 为当前用户共用,插件只处理此工作区。");
|
|
88
88
|
if (!await ui.confirm("执行以上计划")) return 130;
|
|
89
89
|
await mkdir(workspace, { recursive: true });
|
|
90
90
|
if (await realpath(workspace) !== workspace) throw new Error("工作区路径已发生变化,请重新运行 setup。");
|
|
91
91
|
const result = await executeSetup(plan, host, item => ui.text("[" + item.state + "] " + item.name + ": " + item.detail), controller.signal);
|
|
92
92
|
const failed = result.results.some(item => item.state === "failed");
|
|
93
93
|
if (!result.pi) return 1;
|
|
94
|
-
ui.text("\n
|
|
94
|
+
ui.text("\n软件安装阶段结束。工作区初始化和外部服务的状态由 Pi/pbot/插件分别报告。");
|
|
95
95
|
if (await ui.confirm(failed ? "部分插件失败,是否仍启动 Pi 并初始化启用工作区" : "启动 Pi 并初始化启用工作区", !failed)) {
|
|
96
96
|
process.stdin.pause();
|
|
97
97
|
await host.start(result.pi, workspace);
|
|
@@ -11,8 +11,6 @@ import { teamContext } from "../integrations/pi/team-context.js";
|
|
|
11
11
|
import { teamBrief } from "../integrations/team-context.js";
|
|
12
12
|
import { readAgentSession } from "../integrations/pi/pi-agents.js";
|
|
13
13
|
import type { TeamLink } from "../model/team.js";
|
|
14
|
-
import { PythonEnvironmentService } from "../services/workspace/python-environment-service.js";
|
|
15
|
-
import { activatePython } from "../integrations/python-activation.js";
|
|
16
14
|
import { authorizeMutation } from "../services/workspace/workspace-files.js";
|
|
17
15
|
import { agentText } from "../integrations/agent-resources.js";
|
|
18
16
|
import { agentInput } from "../integrations/pi/agent-input.js";
|
|
@@ -38,7 +36,7 @@ export default async function subagent(pi: ExtensionAPI) {
|
|
|
38
36
|
let activeTeam: TeamLink | undefined, pendingPause: string | undefined;
|
|
39
37
|
let ready = false, disposed = false;
|
|
40
38
|
let ctx: ExtensionContext | undefined, timer: ReturnType<typeof setInterval> | undefined;
|
|
41
|
-
let
|
|
39
|
+
let initialized = false;
|
|
42
40
|
let processing = false, closing = false, startLeaf: string | null = null;
|
|
43
41
|
const execution = new AgentRun(files, id, generation);
|
|
44
42
|
let lastActivity = 0;
|
|
@@ -47,7 +45,7 @@ export default async function subagent(pi: ExtensionAPI) {
|
|
|
47
45
|
lifetime.signal.throwIfAborted(); files.check();
|
|
48
46
|
const run = files.read(id, "launch.json", launch);
|
|
49
47
|
requireThat(run.generation === generation && !run.stop, "子会话已停止或启动代次变化。");
|
|
50
|
-
requireThat(
|
|
48
|
+
requireThat(initialized, "子会话尚未就绪。");
|
|
51
49
|
};
|
|
52
50
|
const bindSession = () => {
|
|
53
51
|
const file = ctx?.sessionManager.getSessionFile();
|
|
@@ -79,7 +77,7 @@ export default async function subagent(pi: ExtensionAPI) {
|
|
|
79
77
|
teams.files.setReady(id, generation, false); ready = false;
|
|
80
78
|
pauseTeam("成员停止");
|
|
81
79
|
save({ state: "stopping", activity: "停止" });
|
|
82
|
-
} finally {
|
|
80
|
+
} finally { ctx?.shutdown(); }
|
|
83
81
|
};
|
|
84
82
|
const pump = async () => {
|
|
85
83
|
if (processing || !ctx || closing) return;
|
|
@@ -175,9 +173,7 @@ export default async function subagent(pi: ExtensionAPI) {
|
|
|
175
173
|
})) pi.registerTool(tool);
|
|
176
174
|
// Keep the native CLI loadout, including MCP exposure and explicit --tools choices.
|
|
177
175
|
pi.setActiveTools(active);
|
|
178
|
-
|
|
179
|
-
try { const result = await python.setup(lifetime.signal); restorePython = activatePython(result.directory); }
|
|
180
|
-
catch (error) { ctx.ui.notify(String(error), "warning"); }
|
|
176
|
+
initialized = true;
|
|
181
177
|
save({ state: "idle", activity: "空闲" });
|
|
182
178
|
ready = !pendingPause && pi.getActiveTools().includes("pbot_team_message");
|
|
183
179
|
teams.files.setReady(id, generation, ready);
|
|
@@ -195,7 +191,6 @@ export default async function subagent(pi: ExtensionAPI) {
|
|
|
195
191
|
ctx = context;
|
|
196
192
|
try {
|
|
197
193
|
ensure(); bindSession();
|
|
198
|
-
requireThat(python, "子会话计算环境状态不可用。");
|
|
199
194
|
const workspace = await readFile(join(resourceRoot, "prompts/workspace.md"), "utf8");
|
|
200
195
|
const role = await agentText("general-purpose", d.workspace);
|
|
201
196
|
let brief: string | undefined, message;
|
|
@@ -205,9 +200,8 @@ export default async function subagent(pi: ExtensionAPI) {
|
|
|
205
200
|
brief = teamBrief(link);
|
|
206
201
|
message = teamContext(link, context, link.request.throughSeq);
|
|
207
202
|
}
|
|
208
|
-
const { state, directory } = python.status;
|
|
209
203
|
Object.assign(event.systemPromptOptions.sections, {
|
|
210
|
-
pbot_environment: JSON.stringify({ workspaceRoot: d.workspace, resourceRoot
|
|
204
|
+
pbot_environment: JSON.stringify({ workspaceRoot: d.workspace, resourceRoot }),
|
|
211
205
|
pbot_workspace: workspace, pbot_child: role,
|
|
212
206
|
});
|
|
213
207
|
if (brief) event.systemPromptOptions.sections.pbot_team = brief;
|
|
@@ -270,7 +264,7 @@ export default async function subagent(pi: ExtensionAPI) {
|
|
|
270
264
|
if (execution.current) finish(true);
|
|
271
265
|
if (event.reason !== "reload" && execution.state !== "error") save({ state: "stopped", activity: "已停止" });
|
|
272
266
|
} finally {
|
|
273
|
-
|
|
267
|
+
initialized = false; teams.dispose(); ctx = undefined;
|
|
274
268
|
}
|
|
275
269
|
});
|
|
276
270
|
}
|
|
@@ -11,17 +11,14 @@ import { requireThat } from "../../common/validation.js";
|
|
|
11
11
|
import type { AgentOptions } from "../../model/agent.js";
|
|
12
12
|
|
|
13
13
|
export async function dshResources(ctx: Context, _agent: Agent, root: string,
|
|
14
|
-
role: "coordinator" | "general-purpose",
|
|
14
|
+
role: "coordinator" | "general-purpose", check: () => void) {
|
|
15
15
|
const read = () => Promise.all([agentText(role, root), readFile(join(resourceRoot, "prompts/workspace.md"), "utf8")]);
|
|
16
16
|
const [text, workspace] = await read();
|
|
17
17
|
check();
|
|
18
18
|
ctx.systemPrompt.section({ name: "pbot:role", order: 1, text, interpolate: false });
|
|
19
19
|
ctx.systemPrompt.section({ name: "pbot:workspace", order: 2, text: workspace, interpolate: false });
|
|
20
20
|
ctx.systemPrompt.context({ name: "pbot:environment", order: 300, required: true, interpolate: false,
|
|
21
|
-
text: ()
|
|
22
|
-
const { state, directory } = python();
|
|
23
|
-
return JSON.stringify({ workspaceRoot: root, resourceRoot, python: { state, ...(directory ? { directory } : {}) } });
|
|
24
|
-
} });
|
|
21
|
+
text: JSON.stringify({ workspaceRoot: root, resourceRoot }) });
|
|
25
22
|
ctx.on("system-prompt/assemble", async (_assembly, _context, next) => {
|
|
26
23
|
check();
|
|
27
24
|
const [roleText, workspaceText] = await read();
|
|
@@ -100,19 +100,6 @@ export async function inspectSystem(processes: SetupProcesses, cwd: string): Pro
|
|
|
100
100
|
if (major < 22 || major === 22 && minor < 19) throw new Error("需要 Node.js 22.19 或更高版本。");
|
|
101
101
|
const npm = await findExecutable("npm", processes.env);
|
|
102
102
|
if (!npm) throw new Error("未找到 npm。请先安装 Node.js/npm。");
|
|
103
|
-
const python = await findExecutable("python3", processes.env) ?? await findExecutable("python", processes.env);
|
|
104
|
-
if (!python) throw new Error("需要 Python 3.11+ 和 venv/ensurepip。请先安装后重试。");
|
|
105
|
-
try {
|
|
106
|
-
await processes.run(python, ["-I", "-B", "-c", [
|
|
107
|
-
"import sys, tempfile, venv, ensurepip",
|
|
108
|
-
"assert sys.version_info >= (3, 11), 'Python 3.11+ required'",
|
|
109
|
-
"with tempfile.TemporaryDirectory(prefix='pbot-python-check-') as path:",
|
|
110
|
-
" venv.EnvBuilder(with_pip=True).create(path)",
|
|
111
|
-
].join("\n")], cwd);
|
|
112
|
-
} catch (error) {
|
|
113
|
-
processes.signal.throwIfAborted();
|
|
114
|
-
throw new Error("基础 Python 检查失败。需要 Python 3.11+ 和 venv/ensurepip;Debian/Ubuntu 还需 python3-venv。\n" + String(error));
|
|
115
|
-
}
|
|
116
103
|
const tmux = await findExecutable("tmux", processes.env);
|
|
117
104
|
if (tmux) { await processes.run(tmux, ["-V"], cwd); return { npm }; }
|
|
118
105
|
const names = process.platform === "darwin" ? ["brew"] : ["apt-get", "dnf", "pacman", "zypper", "apk", "sudo"];
|