personal-bot 0.2.9 → 0.2.11
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/README.md +22 -11
- package/README.zh-CN.md +20 -9
- package/docs/README.md +3 -2
- package/docs/agent-collaboration.md +1 -1
- package/docs/dsh.md +4 -6
- package/docs/file-storage.md +7 -4
- package/docs/history.md +2 -9
- package/docs/installation-design.md +4 -1
- package/docs/model-context.md +4 -4
- package/docs/technical-design.md +12 -10
- package/docs/workspace-configuration.md +55 -0
- package/lib/client.js +28 -3
- package/lib/dsh.js +0 -5
- package/lib/extension/dsh/command.js +14 -10
- package/lib/extension/dsh/history.js +1 -1
- package/lib/extension/dsh/management.d.ts +4 -0
- package/lib/extension/dsh/management.js +20 -5
- package/lib/extension/dsh/workspace.d.ts +7 -1
- package/lib/extension/dsh/workspace.js +68 -1
- package/lib/extension/setup-cli.js +1 -1
- package/lib/integrations/dsh/skills.d.ts +4 -0
- package/lib/integrations/dsh/skills.js +27 -0
- package/lib/model/history.d.ts +1 -0
- package/lib/model/workspace-config.d.ts +9 -0
- package/lib/model/workspace-config.js +1 -0
- package/lib/services/history/history-service.d.ts +1 -2
- package/lib/services/history/history-service.js +27 -40
- package/lib/services/workspace/workspace-config.d.ts +7 -0
- package/lib/services/workspace/workspace-config.js +50 -0
- package/lib/services/workspace/workspace-preparation.d.ts +1 -0
- package/lib/services/workspace/workspace-preparation.js +8 -0
- package/lib/storage/history-files.d.ts +5 -1
- package/lib/storage/history-files.js +68 -15
- package/lib/ui/dsh/management.js +27 -3
- package/npm-shrinkwrap.json +7 -3
- package/package.json +7 -4
- package/python/README.md +5 -5
- package/scripts/setup-python.py +33 -7
- package/src/dsh.ts +0 -5
- package/src/extension/command.ts +25 -8
- package/src/extension/dsh/command.ts +13 -8
- package/src/extension/dsh/history.ts +2 -2
- package/src/extension/dsh/management.ts +21 -5
- package/src/extension/dsh/workspace.ts +62 -5
- package/src/extension/events.ts +18 -1
- package/src/extension/lifecycle.ts +9 -2
- package/src/extension/setup-cli.ts +1 -1
- package/src/extension/subagent-entry.ts +4 -1
- package/src/integrations/dsh/skills.ts +30 -0
- package/src/integrations/pi/skills.ts +52 -0
- package/src/model/history.ts +1 -0
- package/src/model/workspace-config.ts +10 -0
- package/src/pbot.ts +2 -3
- package/src/services/history/history-service.ts +15 -25
- package/src/services/workspace/workspace-config.ts +49 -0
- package/src/services/workspace/workspace-preparation.ts +8 -0
- package/src/storage/history-files.ts +53 -15
- package/src/ui/dsh/management.ts +20 -3
- package/docs/dsh.en.md +0 -339
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readdirSync, rmdirSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { object } from "../common/json.js";
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, rmdirSync, unlinkSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { canonical, object } from "../common/json.js";
|
|
4
4
|
import { requireThat } from "../common/validation.js";
|
|
5
|
-
import { readJsonFile, writeJsonFile } from "./atomic-json.js";
|
|
5
|
+
import { internalPath, readJsonFile, syncDirectory, writeJsonFile } from "./atomic-json.js";
|
|
6
6
|
import { fileId } from "./file-access.js";
|
|
7
7
|
const strings = (value) => Array.isArray(value) && value.every(item => typeof item === "string");
|
|
8
8
|
function record(value) {
|
|
9
|
-
requireThat(object(value) &&
|
|
9
|
+
requireThat(object(value) && (value.host === "pi" || value.host === "dsh") &&
|
|
10
|
+
typeof value.id === "string" && typeof value.sessionId === "string" &&
|
|
10
11
|
typeof value.name === "string" && Array.isArray(value.nodes), "历史索引无效。");
|
|
11
12
|
for (const node of value.nodes)
|
|
12
13
|
requireThat(object(node) && typeof node.id === "string" &&
|
|
@@ -21,25 +22,77 @@ function record(value) {
|
|
|
21
22
|
export class HistoryFiles {
|
|
22
23
|
directory;
|
|
23
24
|
host;
|
|
25
|
+
#warnings = [];
|
|
24
26
|
constructor(directory, host = "pi") {
|
|
25
27
|
this.directory = directory;
|
|
26
28
|
this.host = host;
|
|
27
29
|
}
|
|
28
|
-
|
|
30
|
+
get warnings() { return this.#warnings; }
|
|
31
|
+
list() {
|
|
32
|
+
this.#warnings = [];
|
|
29
33
|
if (!existsSync(this.directory))
|
|
30
34
|
return [];
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
const records = [];
|
|
36
|
+
for (const name of readdirSync(this.directory).filter(name => name.endsWith(".json"))) {
|
|
37
|
+
try {
|
|
38
|
+
const value = readJsonFile(this.directory, name, record);
|
|
39
|
+
requireThat(name === fileId(value.id) + ".json", "历史文件名与根 ID 不匹配。");
|
|
40
|
+
if (value.host === this.host)
|
|
41
|
+
records.push(value);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
this.#warnings.push(join(this.directory, name) + ": " + String(error));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return records;
|
|
48
|
+
}
|
|
49
|
+
/** Publish each legacy archive with its directory's host before removing the old copy. */
|
|
50
|
+
migrate(root) {
|
|
51
|
+
const directory = join(root, "." + this.host, "pbot/history");
|
|
52
|
+
if (!existsSync(directory))
|
|
53
|
+
return;
|
|
54
|
+
this.control(() => {
|
|
55
|
+
if (!existsSync(directory))
|
|
56
|
+
return;
|
|
57
|
+
const legacyLock = join(directory, ".write");
|
|
58
|
+
mkdirSync(legacyLock, { mode: 0o700 });
|
|
59
|
+
try {
|
|
60
|
+
for (const name of readdirSync(directory).filter(name => name.endsWith(".json"))) {
|
|
61
|
+
const source = internalPath(directory, name), target = internalPath(this.directory, name);
|
|
62
|
+
requireThat(source !== target, "新旧历史目录指向同一位置。");
|
|
63
|
+
const value = readJsonFile(directory, name, value => {
|
|
64
|
+
requireThat(object(value) && (value.host === undefined || value.host === this.host), "旧历史归档与来源目录不匹配。");
|
|
65
|
+
return record({ ...value, host: this.host });
|
|
66
|
+
});
|
|
67
|
+
requireThat(name === fileId(value.id) + ".json", "历史文件名与根 ID 不匹配。");
|
|
68
|
+
if (!writeJsonFile(this.directory, name, value, record, true)) {
|
|
69
|
+
requireThat(canonical(readJsonFile(this.directory, name, record)) === canonical(value), "历史归档迁移冲突,请核对新旧文件:" + name);
|
|
70
|
+
}
|
|
71
|
+
syncDirectory(this.directory);
|
|
72
|
+
unlinkSync(source);
|
|
73
|
+
syncDirectory(directory);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
rmdirSync(legacyLock);
|
|
78
|
+
}
|
|
79
|
+
rmdirSync(directory);
|
|
80
|
+
const parent = dirname(directory);
|
|
81
|
+
syncDirectory(parent);
|
|
82
|
+
try {
|
|
83
|
+
rmdirSync(parent);
|
|
84
|
+
syncDirectory(dirname(parent));
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (!["ENOTEMPTY", "EEXIST"].includes(error.code ?? ""))
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
38
91
|
}
|
|
39
92
|
/** The callback is synchronous: no SDK reads or model work can hold this source's write lock. */
|
|
40
93
|
control(operation) {
|
|
41
94
|
mkdirSync(this.directory, { recursive: true, mode: 0o700 });
|
|
42
|
-
const lock = join(this.directory, ".write");
|
|
95
|
+
const lock = join(this.directory, ".write-" + this.host);
|
|
43
96
|
try {
|
|
44
97
|
mkdirSync(lock, { mode: 0o700 });
|
|
45
98
|
}
|
|
@@ -56,7 +109,7 @@ export class HistoryFiles {
|
|
|
56
109
|
}
|
|
57
110
|
}
|
|
58
111
|
save(value) {
|
|
59
|
-
requireThat(
|
|
112
|
+
requireThat(value.host === this.host, "历史归档与来源不匹配。");
|
|
60
113
|
mkdirSync(this.directory, { recursive: true, mode: 0o700 });
|
|
61
114
|
writeJsonFile(this.directory, fileId(value.id) + ".json", value, record);
|
|
62
115
|
}
|
package/lib/ui/dsh/management.js
CHANGED
|
@@ -78,6 +78,8 @@ export function showManagement(ctx, parentSessionId) {
|
|
|
78
78
|
}
|
|
79
79
|
function form(parent) { const node = element("form"); parent.append(node); return node; }
|
|
80
80
|
function activate(id) {
|
|
81
|
+
if (snapshot?.enabled === false && id !== "status")
|
|
82
|
+
return;
|
|
81
83
|
tab = id;
|
|
82
84
|
for (const [key, section] of sections)
|
|
83
85
|
section.hidden = key !== id;
|
|
@@ -157,7 +159,7 @@ export function showManagement(ctx, parentSessionId) {
|
|
|
157
159
|
counts.classList.add("pbot-counts");
|
|
158
160
|
const materials = group(status, "pbot-setting");
|
|
159
161
|
materials.append(element("h3", "资料目录"));
|
|
160
|
-
button(materials, "准备目录", async () => { await command("init", undefined, "
|
|
162
|
+
const initializeButton = button(materials, "准备目录", async () => { await command("init", undefined, "工作区已初始化并启用。"); });
|
|
161
163
|
const pythonCard = group(status, "pbot-setting"), pythonInfo = group(pythonCard);
|
|
162
164
|
const pythonButton = button(pythonCard, "准备 Python", async () => { await command("python setup", undefined, "Python 准备完成。"); });
|
|
163
165
|
const diagnostic = details(status, "环境详情"), statusBody = block("");
|
|
@@ -625,13 +627,35 @@ export function showManagement(ctx, parentSessionId) {
|
|
|
625
627
|
return;
|
|
626
628
|
location.textContent = text(snapshot.workspaceRoot).split(/[\\/]/).filter(Boolean).at(-1) ?? "";
|
|
627
629
|
location.title = text(snapshot.workspaceRoot);
|
|
630
|
+
if (snapshot.enabled === false) {
|
|
631
|
+
const configuration = record(snapshot.configuration);
|
|
632
|
+
counts.textContent = configuration.error ? "Personal Bot 配置错误" : "Personal Bot 未启用";
|
|
633
|
+
workspaceInfo.replaceChildren(facts([["状态", configuration.error ? "配置错误" : "未启用"], ["工作区", snapshot.workspaceRoot], ["配置文件", configuration.path]]), note(configuration.error ? "修复配置文件后执行 /pbot init。" : "执行 /pbot init,或点击下方按钮初始化并启用。"));
|
|
634
|
+
pythonInfo.replaceChildren(note("启用工作区后自动准备共享 Python 环境。"));
|
|
635
|
+
materials.hidden = false;
|
|
636
|
+
initializeButton.textContent = "初始化并启用";
|
|
637
|
+
enabled(initializeButton, !configuration.error);
|
|
638
|
+
for (const [id, control] of tabs)
|
|
639
|
+
enabled(control, id === "status");
|
|
640
|
+
enabled(pythonButton, false);
|
|
641
|
+
activate("status");
|
|
642
|
+
statusBody.textContent = JSON.stringify(snapshot, null, 2);
|
|
643
|
+
if (configuration.error)
|
|
644
|
+
inform(text(configuration.error), "error");
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
for (const control of tabs.values())
|
|
648
|
+
enabled(control, true);
|
|
649
|
+
materials.hidden = false;
|
|
650
|
+
initializeButton.textContent = "准备目录";
|
|
651
|
+
enabled(initializeButton, true);
|
|
628
652
|
const agents = rows(snapshot.agents), teams = rows(snapshot.teams), python = record(snapshot.python), history = record(snapshot.history);
|
|
629
653
|
tabCounts.get("experts").textContent = text(agents.length);
|
|
630
654
|
tabCounts.get("teams").textContent = text(teams.length);
|
|
631
655
|
const active = agents.filter(agent => ["starting", "busy", "stopping"].includes(text(agent.state))).length;
|
|
632
|
-
counts.textContent =
|
|
656
|
+
counts.textContent = `Personal Bot 已启动 · 专家 ${agents.length} · 执行中 ${active} · 团队 ${teams.length}`;
|
|
633
657
|
const model = object(snapshot.model) ? snapshot.model : {};
|
|
634
|
-
workspaceInfo.replaceChildren(facts([["工作区", snapshot.workspaceRoot], ["模型", model.model || "尚未选择"], ["Provider", model.provider || "—"],
|
|
658
|
+
workspaceInfo.replaceChildren(facts([["状态", "已启动"], ["工作区", snapshot.workspaceRoot], ["配置文件", record(snapshot.configuration).path], ["模型", model.model || "尚未选择"], ["Provider", model.provider || "—"],
|
|
635
659
|
["历史", history.organizing ? "整理中" : history.pending === null ? "查询时更新索引" : `${history.pending} 项待整理`]]));
|
|
636
660
|
pythonInfo.replaceChildren(element("h3", "Python"), badge(python.state));
|
|
637
661
|
if (python.error)
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "personal-bot",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "personal-bot",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.11",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"ajv": "8.17.1",
|
|
12
12
|
"ajv-formats": "3.0.1",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"@deepseek-ai/dsh-fs-patch": "0.2.2-rc.1",
|
|
30
30
|
"@deepseek-ai/dsh-home-paths": "0.2.2-rc.1",
|
|
31
31
|
"@deepseek-ai/dsh-llm": "0.2.2-rc.1",
|
|
32
|
+
"@deepseek-ai/dsh-scope": "0.2.2-rc.1",
|
|
32
33
|
"@deepseek-ai/dsh-session": "0.2.2-rc.1",
|
|
33
34
|
"@deepseek-ai/dsh-session-persistence": "0.2.2-rc.1",
|
|
34
35
|
"@deepseek-ai/dsh-session-query": "0.2.2-rc.1",
|
|
@@ -68,6 +69,7 @@
|
|
|
68
69
|
"@deepseek-ai/dsh-fs-patch": "*",
|
|
69
70
|
"@deepseek-ai/dsh-home-paths": "*",
|
|
70
71
|
"@deepseek-ai/dsh-llm": "*",
|
|
72
|
+
"@deepseek-ai/dsh-scope": "*",
|
|
71
73
|
"@deepseek-ai/dsh-session": "*",
|
|
72
74
|
"@deepseek-ai/dsh-session-persistence": "*",
|
|
73
75
|
"@deepseek-ai/dsh-session-query": "*",
|
|
@@ -122,6 +124,9 @@
|
|
|
122
124
|
"@deepseek-ai/dsh-llm": {
|
|
123
125
|
"optional": true
|
|
124
126
|
},
|
|
127
|
+
"@deepseek-ai/dsh-scope": {
|
|
128
|
+
"optional": true
|
|
129
|
+
},
|
|
125
130
|
"@deepseek-ai/dsh-session": {
|
|
126
131
|
"optional": true
|
|
127
132
|
},
|
|
@@ -4687,7 +4692,6 @@
|
|
|
4687
4692
|
"integrity": "sha512-FOJbXYvrskIcrb/4eVMMQfp0kaReTSBtIry2KsGNURb0OJfelqeSKaB1MsQQq/sOxbt3nPJIN9HY00SwmrTk3Q==",
|
|
4688
4693
|
"dev": true,
|
|
4689
4694
|
"license": "MIT",
|
|
4690
|
-
"peer": true,
|
|
4691
4695
|
"peerDependencies": {
|
|
4692
4696
|
"@deepseek-ai/cordis": "~4.1.0"
|
|
4693
4697
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "personal-bot",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/realqiyan/personal-bot.git"
|
|
@@ -22,9 +22,7 @@
|
|
|
22
22
|
"extensions": [
|
|
23
23
|
"./src/pbot.ts"
|
|
24
24
|
],
|
|
25
|
-
"skills": [
|
|
26
|
-
"./resources/skills"
|
|
27
|
-
],
|
|
25
|
+
"skills": [],
|
|
28
26
|
"prompts": [],
|
|
29
27
|
"themes": []
|
|
30
28
|
},
|
|
@@ -101,6 +99,7 @@
|
|
|
101
99
|
"@deepseek-ai/dsh-tools": "*",
|
|
102
100
|
"@deepseek-ai/dsh-home-paths": "*",
|
|
103
101
|
"@deepseek-ai/dsh-system-prompt": "*",
|
|
102
|
+
"@deepseek-ai/dsh-scope": "*",
|
|
104
103
|
"@deepseek-ai/dsh-skill": "*",
|
|
105
104
|
"@deepseek-ai/dsh-skill-filesystem": "*",
|
|
106
105
|
"@deepseek-ai/dsh-working-directory": "*",
|
|
@@ -159,6 +158,9 @@
|
|
|
159
158
|
"@deepseek-ai/dsh-system-prompt": {
|
|
160
159
|
"optional": true
|
|
161
160
|
},
|
|
161
|
+
"@deepseek-ai/dsh-scope": {
|
|
162
|
+
"optional": true
|
|
163
|
+
},
|
|
162
164
|
"@deepseek-ai/dsh-skill": {
|
|
163
165
|
"optional": true
|
|
164
166
|
},
|
|
@@ -223,6 +225,7 @@
|
|
|
223
225
|
"@deepseek-ai/dsh-tools": "0.2.2-rc.1",
|
|
224
226
|
"@deepseek-ai/dsh-home-paths": "0.2.2-rc.1",
|
|
225
227
|
"@deepseek-ai/dsh-system-prompt": "0.2.2-rc.1",
|
|
228
|
+
"@deepseek-ai/dsh-scope": "0.2.2-rc.1",
|
|
226
229
|
"@deepseek-ai/dsh-skill": "0.2.2-rc.1",
|
|
227
230
|
"@deepseek-ai/dsh-skill-filesystem": "0.2.2-rc.1",
|
|
228
231
|
"@deepseek-ai/dsh-working-directory": "0.2.2-rc.1",
|
package/python/README.md
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
## 自动准备与激活
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
工作区的 `.pbot/config.json` 设置 `enabled: true` 后,Pi 加载或原生 `/reload` 时自动执行 setup;dsh 在首个已启用工作区加载时准备环境。无需另行确认或指定 Python 路径。同一系统用户的两种宿主共用该环境:
|
|
8
8
|
|
|
9
|
-
1. 共享 venv 不存在时创建,不使用系统 site-packages
|
|
9
|
+
1. 共享 venv 不存在时创建,不使用系统 site-packages;解释器无法启动时重新创建。
|
|
10
10
|
2. 按 `requirements.lock` 补齐或对齐依赖,允许升级或降级;已匹配时不重新安装。
|
|
11
11
|
3. 检查依赖关系、全部预装库导入和简单 TA-Lib 计算。
|
|
12
12
|
4. 成功后将 venv 的 `bin` 放到当前宿主进程 PATH 前端,设置 `VIRTUAL_ENV`,移除 `PYTHONHOME`、`PYTHONPATH` 并禁用用户 site-packages。主会话与专家的原生 Bash 继承该环境。
|
|
@@ -16,9 +16,9 @@ Pi 加载 Personal Bot、原生 `/reload`,或 dsh 加载 pbot Host 组件时
|
|
|
16
16
|
| Linux | `${XDG_DATA_HOME:-~/.local/share}/pbot/python/.venv`;仅使用绝对 XDG_DATA_HOME |
|
|
17
17
|
| macOS | `~/Library/Application Support/pbot/python/.venv` |
|
|
18
18
|
|
|
19
|
-
首次准备从当前 PATH 选择 python3,无该命令时使用 python;需要 Python 3.11+ 和 venv/ensurepip。系统 Python 只用于创建独立 venv
|
|
19
|
+
首次准备从当前 PATH 选择 python3,无该命令时使用 python;需要 Python 3.11+ 和 venv/ensurepip。系统 Python 只用于创建独立 venv,不在系统环境中安装依赖。已有 venv 按锁文件对齐,保留额外安装的包。基础解释器被移除或升级、导致共享 venv 的解释器无法启动时,setup 用当前 Python 3.11+ 重建该 venv,原有包随之移除;非 venv 数据、符号链接和其他 Python 环境不会被覆盖或删除。
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
首次安装可能需要数分钟和网络。`/pbot init` 创建共用启用配置并启动环境准备;手工设置 enabled 为 true 后重载也会准备环境。不需要 Personal Bot 的工作区可保留配置缺失或设置 enabled 为 false,再重载或重启宿主;也可通过宿主原生配置取消加载整个插件。`/pbot status` 显示环境状态。所属激活生命周期关闭时恢复本扩展修改的进程环境变量;dsh 按整个 pbot 组件共享激活,不随某个浏览器页面或单个工作区关闭而恢复,不覆盖期间其他代码对变量的新修改。外部终端和 shell 配置不变。
|
|
22
22
|
|
|
23
23
|
## 失败与手工重试
|
|
24
24
|
|
|
@@ -30,7 +30,7 @@ Pi 加载 Personal Bot、原生 `/reload`,或 dsh 加载 pbot Host 组件时
|
|
|
30
30
|
/pbot python setup
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
无需路径和额外确认,执行同一准备逻辑,成功后激活。也可重启 pbot。安装限时 15
|
|
33
|
+
无需路径和额外确认,执行同一准备逻辑,成功后激活。也可重启 pbot。安装限时 15 分钟,超时或关闭会取消准备;不会自动回滚或循环重试。失败留下的环境保留,下次 setup 继续按锁文件补齐。共享 venv 解释器无法启动时自动重建;其他损坏不自动删除环境,可自行删除该目录后重试。缺少 pip 时仅尝试该 venv 的 ensurepip。
|
|
34
34
|
|
|
35
35
|
安装只接受 wheel,不编译 C 库、不安装系统软件,不绕过系统 Python 的安装保护。没有匹配 wheel、网络不可用、权限不足或环境损坏时停止。TA-Lib wheel 包含底层库,但并非所有系统和架构都有匹配 wheel。pip 安装配置被忽略,避免包被重定向到其他目标。
|
|
36
36
|
|
package/scripts/setup-python.py
CHANGED
|
@@ -6,6 +6,7 @@ import json
|
|
|
6
6
|
import os
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
import re
|
|
9
|
+
import shutil
|
|
9
10
|
import stat
|
|
10
11
|
import subprocess
|
|
11
12
|
import sys
|
|
@@ -54,6 +55,7 @@ def locked_packages():
|
|
|
54
55
|
|
|
55
56
|
|
|
56
57
|
def inspect_environment(target):
|
|
58
|
+
"""Return the shared venv description; None means it must be created or rebuilt."""
|
|
57
59
|
if target.is_symlink():
|
|
58
60
|
raise ValueError("共享环境目录不能是符号链接。")
|
|
59
61
|
if not target.exists():
|
|
@@ -63,7 +65,16 @@ def inspect_environment(target):
|
|
|
63
65
|
raise ValueError("共享环境位置已被非 venv 数据占用;不会覆盖或删除。")
|
|
64
66
|
if re.search(r"include-system-site-packages\s*=\s*true", config.read_text(), re.I):
|
|
65
67
|
raise ValueError("共享 venv 不能继承系统 site-packages。")
|
|
66
|
-
|
|
68
|
+
try:
|
|
69
|
+
probe = subprocess.run([str(target / "bin/python"), "-I", "-B", "-c", INSPECT],
|
|
70
|
+
capture_output=True, text=True)
|
|
71
|
+
except OSError:
|
|
72
|
+
# The base interpreter was removed, so the environment cannot run.
|
|
73
|
+
return None
|
|
74
|
+
if probe.returncode != 0:
|
|
75
|
+
# The base interpreter was upgraded, or the copied executable is damaged.
|
|
76
|
+
return None
|
|
77
|
+
info = json.loads(probe.stdout)
|
|
67
78
|
if Path(info["prefix"]).resolve() != target.resolve() or info["prefix"] == info["basePrefix"]:
|
|
68
79
|
raise ValueError("解释器不属于共享 venv;不会修改其他 Python 环境。")
|
|
69
80
|
if info["version"][:2] < [3, 11]:
|
|
@@ -76,11 +87,15 @@ def plan(target):
|
|
|
76
87
|
required = locked_packages()
|
|
77
88
|
current = inspect_environment(target)
|
|
78
89
|
installed = (current or {}).get("packages", {})
|
|
90
|
+
changes = [{"package": name, "from": installed.get(name), "to": version}
|
|
91
|
+
for name, version in required.items() if installed.get(name) != version]
|
|
92
|
+
if current is None:
|
|
93
|
+
action = "rebuild" if target.exists() else "create"
|
|
94
|
+
else:
|
|
95
|
+
action = "update" if changes else "verify"
|
|
79
96
|
return {
|
|
80
|
-
"directory": str(target), "python": str(target / "bin/python"),
|
|
81
|
-
"current": current, "required": required,
|
|
82
|
-
"changes": [{"package": name, "from": installed.get(name), "to": version}
|
|
83
|
-
for name, version in required.items() if installed.get(name) != version],
|
|
97
|
+
"action": action, "directory": str(target), "python": str(target / "bin/python"),
|
|
98
|
+
"current": current, "required": required, "changes": changes,
|
|
84
99
|
}
|
|
85
100
|
|
|
86
101
|
|
|
@@ -94,7 +109,10 @@ def setup(target):
|
|
|
94
109
|
# Concurrent startups wait, then inspect again rather than apply stale plans.
|
|
95
110
|
fcntl.flock(fd, fcntl.LOCK_EX)
|
|
96
111
|
actual = plan(target)
|
|
97
|
-
if actual["
|
|
112
|
+
if actual["action"] == "rebuild":
|
|
113
|
+
print("共享 venv 的解释器无法运行,重建共享环境。", file=sys.stderr)
|
|
114
|
+
shutil.rmtree(target)
|
|
115
|
+
if actual["action"] in ("create", "rebuild"):
|
|
98
116
|
venv.EnvBuilder(with_pip=True).create(target)
|
|
99
117
|
python = str(target / "bin/python")
|
|
100
118
|
|
|
@@ -126,6 +144,11 @@ def setup(target):
|
|
|
126
144
|
|
|
127
145
|
|
|
128
146
|
def main():
|
|
147
|
+
# venv records the invoking path as its home; resolve first so a symlinked launcher
|
|
148
|
+
# (for example a relocatable CPython managed by another tool) yields a usable base.
|
|
149
|
+
real = os.path.realpath(sys.executable) if sys.executable else ""
|
|
150
|
+
if real and real != sys.executable:
|
|
151
|
+
os.execv(real, [real, "-I", "-B", os.path.abspath(__file__), *sys.argv[1:]])
|
|
129
152
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
130
153
|
parser.add_argument("--check", action="store_true", help="只检查共享环境,不创建或安装")
|
|
131
154
|
args = parser.parse_args()
|
|
@@ -139,6 +162,9 @@ if __name__ == "__main__":
|
|
|
139
162
|
try:
|
|
140
163
|
main()
|
|
141
164
|
except (Exception, KeyboardInterrupt) as error:
|
|
165
|
+
if isinstance(error, subprocess.CalledProcessError) and error.output:
|
|
166
|
+
print(error.output if isinstance(error.output, str) else error.output.decode(errors="replace"),
|
|
167
|
+
file=sys.stderr, end="")
|
|
142
168
|
print(str(error), file=sys.stderr)
|
|
143
|
-
print("共享 Python 环境未就绪。请检查 Python 3.11+、venv/ensurepip、网络、安装权限和 wheel;修复后执行 /pbot python setup
|
|
169
|
+
print("共享 Python 环境未就绪。请检查 Python 3.11+、venv/ensurepip、网络、安装权限和 wheel;修复后执行 /pbot python setup 或重启。不改用系统环境安装或编译 C 库;共享 venv 解释器无法运行时会重建,其他数据不删除。", file=sys.stderr)
|
|
144
170
|
sys.exit(1)
|
package/src/dsh.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
1
|
import type { Context } from "@deepseek-ai/cordis";
|
|
3
|
-
import * as SkillFilesystem from "@deepseek-ai/dsh-skill-filesystem";
|
|
4
|
-
import { resourceRoot } from "./common/paths.js";
|
|
5
2
|
import { registerDshCommand } from "./extension/dsh/command.js";
|
|
6
3
|
import { registerDshManagement } from "./extension/dsh/management.js";
|
|
7
4
|
import { DshWorkspaces, dshDependencies } from "./extension/dsh/workspace.js";
|
|
@@ -13,7 +10,6 @@ export const inject = ["commands", "typert", ...dshDependencies];
|
|
|
13
10
|
export async function apply(ctx: Context) {
|
|
14
11
|
const [major, minor] = process.versions.node.split(".").map(Number);
|
|
15
12
|
requireThat(major! > 24 || (major === 24 && minor! >= 9), "dsh 接入需要 Node.js 24.9.0 或更新版本。");
|
|
16
|
-
await ctx.plugin(SkillFilesystem, { providerName: "pbot", includeDefaultRoots: false, bundledSkillDir: join(resourceRoot, "skills") });
|
|
17
13
|
const workspaces = new DshWorkspaces(ctx);
|
|
18
14
|
ctx.effect(() => () => workspaces.close());
|
|
19
15
|
const management = registerDshManagement(ctx, workspaces);
|
|
@@ -22,5 +18,4 @@ export async function apply(ctx: Context) {
|
|
|
22
18
|
if (ctx.agents.roots().includes(agent) && agent.session.header.origin !== "subagent") await workspaces.open(agent);
|
|
23
19
|
});
|
|
24
20
|
for (const agent of ctx.agents.roots()) if (agent.session.header.origin !== "subagent") await workspaces.open(agent);
|
|
25
|
-
void workspaces.preparePython().catch(error => ctx.logger.warn(String(error)));
|
|
26
21
|
}
|
package/src/extension/command.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { packageVersion } from "../common/version.js";
|
|
3
|
-
import {
|
|
3
|
+
import { initializeWorkspace } from "../services/workspace/workspace-preparation.js";
|
|
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";
|
|
@@ -10,6 +10,7 @@ import type { Lifecycle } from "./lifecycle.js";
|
|
|
10
10
|
import { showAgents } from "./agents-command.js";
|
|
11
11
|
import { showTeams } from "./teams-command.js";
|
|
12
12
|
import { showHistory } from "./history.js";
|
|
13
|
+
import { workspaceDisabledMessage } from "../services/workspace/workspace-config.js";
|
|
13
14
|
|
|
14
15
|
export function registerCommand(pi: ExtensionAPI, lifecycle: Lifecycle, confirmations: Confirmations) {
|
|
15
16
|
pi.registerCommand("pbot", {
|
|
@@ -22,17 +23,30 @@ export function registerCommand(pi: ExtensionAPI, lifecycle: Lifecycle, confirma
|
|
|
22
23
|
handler: async (args, ctx) => {
|
|
23
24
|
const [, command, argument = ""] = args.trim().match(/^(\S+)(?:\s+([\s\S]*))?$/) ?? [];
|
|
24
25
|
confirmations.resume();
|
|
26
|
+
if (command === "init" && !argument) {
|
|
27
|
+
await ctx.waitForIdle();
|
|
28
|
+
const start = !lifecycle.active;
|
|
29
|
+
await initializeWorkspace(lifecycle.root ?? ctx.cwd);
|
|
30
|
+
ctx.ui.notify(start ? "工作区已初始化并启用,正在加载 Personal Bot。" : "资料目录已准备;新建的 AGENTS.md 经 /reload 加载。", "info");
|
|
31
|
+
if (start) await ctx.reload();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (!lifecycle.active) {
|
|
35
|
+
const configuration = lifecycle.configuration;
|
|
36
|
+
const status = { workspaceRoot: lifecycle.root ?? ctx.cwd, release: packageVersion, enabled: false,
|
|
37
|
+
state: configuration?.error || configuration?.enabled ? "error" : "disabled",
|
|
38
|
+
nextStep: configuration?.error ?? "/pbot init", configuration };
|
|
39
|
+
ctx.ui.notify(command === "status" ? JSON.stringify(status, null, 2)
|
|
40
|
+
: configuration ? workspaceDisabledMessage(configuration) : "pbot 工作区实例不可用。", configuration?.error ? "error" : "info");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
25
43
|
async function execute(command: string | undefined, argument: string) {
|
|
26
44
|
const instance = lifecycle.get();
|
|
27
|
-
if (command === "init" && !argument) {
|
|
28
|
-
await ctx.waitForIdle(); instance.check(); await prepareWorkspace(instance.root);
|
|
29
|
-
ctx.ui.notify("资料目录已准备。新建的 AGENTS.md 在 /reload 或下次启动后由 Pi 加载。", "info"); return;
|
|
30
|
-
}
|
|
31
45
|
if (command === "status" && !argument) {
|
|
32
46
|
const python = instance.pythonEnvironment.status;
|
|
33
|
-
if (ctx.mode !== "tui") { ctx.ui.notify(JSON.stringify({ workspaceRoot: instance.root, release: packageVersion, python }, null, 2), "info"); return; }
|
|
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; }
|
|
34
48
|
const agents = instance.agents.list(agentOwner(ctx)), history = instance.history.status;
|
|
35
|
-
await readPage(ctx, "工作区", [instance.root, "", `版本 ${packageVersion}`,
|
|
49
|
+
await readPage(ctx, "工作区", [instance.root, "", "状态 已启动", `配置 ${lifecycle.configuration?.path ?? ""}`, `版本 ${packageVersion}`,
|
|
36
50
|
`模型 ${ctx.model && !(ctx.model.provider === "unknown" && ctx.model.id === "unknown") ? ctx.model.provider + "/" + ctx.model.id : "未选择"}`,
|
|
37
51
|
`专家 ${agents.length} 位 · ${agents.filter(value => value.alive).length} 位存活`,
|
|
38
52
|
`Python ${stateLabel(python.state)}`, ...(python.directory ? [python.directory] : []), ...(python.error ? ["", python.error] : []),
|
|
@@ -58,7 +72,10 @@ export function registerCommand(pi: ExtensionAPI, lifecycle: Lifecycle, confirma
|
|
|
58
72
|
const choice = await choose(ctx, `Personal Bot · Python ${stateLabel(instance.pythonEnvironment.status.state)}`, choices);
|
|
59
73
|
if (!choice) return;
|
|
60
74
|
const command = ["agents", "teams", "history", "status", "init", "python"][choices.indexOf(choice)]!;
|
|
61
|
-
try {
|
|
75
|
+
try {
|
|
76
|
+
if (command === "init") { await ctx.waitForIdle(); instance.check(); await initializeWorkspace(instance.root); ctx.ui.notify("资料目录已准备。", "info"); }
|
|
77
|
+
else await execute(command, command === "python" ? "setup" : "");
|
|
78
|
+
}
|
|
62
79
|
catch (error) { ctx.ui.notify(error instanceof Error ? error.message : String(error), "error"); }
|
|
63
80
|
}
|
|
64
81
|
},
|
|
@@ -3,12 +3,11 @@ 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
5
|
import { requireThat, schema } from "../../common/validation.js";
|
|
6
|
-
import { prepareWorkspace } from "../../services/workspace/workspace-preparation.js";
|
|
7
6
|
import { executeAgent, type AgentInput } from "../../tools/agents/actions.js";
|
|
8
7
|
import { dshAgentActionSchema } from "../../tools/agents/dsh-contract.js";
|
|
9
8
|
import { executeTeam, executeTeamMessage } from "../../tools/teams/actions.js";
|
|
10
9
|
import { teamActionSchema, teamParametersSchema, teamMessageActionSchema, teamMessageParametersSchema } from "../../tools/teams/contract.js";
|
|
11
|
-
import {
|
|
10
|
+
import { dshWorkspaceStatus, type PbotManagement } from "./management.js";
|
|
12
11
|
import type { DshWorkspaces } from "./workspace.js";
|
|
13
12
|
|
|
14
13
|
const validAgent = schema(dshAgentActionSchema), validTeam = schema(teamActionSchema), validMessage = schema(teamMessageActionSchema);
|
|
@@ -23,20 +22,26 @@ export function registerDshCommand(ctx: Context, workspaces: DshWorkspaces, mana
|
|
|
23
22
|
input: { hint: "status | init | python setup | agent/chat/team/post/history/records JSON", attachments: true },
|
|
24
23
|
async handler({ agent, rawInput, signal, attachments, commandId }) {
|
|
25
24
|
signal.throwIfAborted();
|
|
25
|
+
const command = rawInput.trim(), split = command.search(/\s/);
|
|
26
|
+
if (!command || command === "status") {
|
|
27
|
+
requireThat(!attachments.length, "状态查询不接受附件。");
|
|
28
|
+
const status = await dshWorkspaceStatus(workspaces, agent);
|
|
29
|
+
signal.throwIfAborted(); return { kind: "success", text: JSON.stringify(status, null, 2) };
|
|
30
|
+
}
|
|
31
|
+
if (command === "init") {
|
|
32
|
+
requireThat(!attachments.length, "初始化不接受附件。");
|
|
33
|
+
await workspaces.initialize(agent);
|
|
34
|
+
signal.throwIfAborted();
|
|
35
|
+
return { kind: "success", text: JSON.stringify(await dshWorkspaceStatus(workspaces, agent), null, 2) };
|
|
36
|
+
}
|
|
26
37
|
const workspace = await workspaces.get(agent);
|
|
27
38
|
signal.throwIfAborted();
|
|
28
|
-
const command = rawInput.trim(), split = command.search(/\s/);
|
|
29
39
|
const verb = split < 0 ? command : command.slice(0, split);
|
|
30
40
|
requireThat(verb === "chat" || !attachments.length, "输入框附件仅用于 chat 人工对话。");
|
|
31
|
-
if (command === "init") {
|
|
32
|
-
await prepareWorkspace(workspace.root); workspace.check();
|
|
33
|
-
return { kind: "success", text: "资料目录已准备;已有文件保留。" };
|
|
34
|
-
}
|
|
35
41
|
if (command === "python setup") {
|
|
36
42
|
const result = await workspaces.preparePython(); workspace.check();
|
|
37
43
|
return { kind: "success", text: JSON.stringify(result, null, 2) };
|
|
38
44
|
}
|
|
39
|
-
if (!command || command === "status") return { kind: "success", text: JSON.stringify(dshStatus(workspaces, workspace), null, 2) };
|
|
40
45
|
requireThat(split >= 0, usage);
|
|
41
46
|
const input: unknown = JSON.parse(command.slice(split));
|
|
42
47
|
requireThat(object(input), "命令参数必须是 JSON 对象。");
|
|
@@ -18,9 +18,9 @@ export class DshHistoryWork {
|
|
|
18
18
|
#closing: Promise<void> | undefined;
|
|
19
19
|
constructor(private readonly ctx: Context, root: string) {
|
|
20
20
|
const agents = new AgentFiles(dshHomePath("pbot", "subagents"), "dsh");
|
|
21
|
-
this.service = new HistoryService(root, new HistoryFiles(join(root, ".
|
|
21
|
+
this.service = new HistoryService(root, new HistoryFiles(join(root, ".pbot/history"), "dsh"),
|
|
22
22
|
new DshHistory(ctx, root, () => agents.list().filter(value => value.workspace === root).map(value => value.agentId)),
|
|
23
|
-
|
|
23
|
+
new HistoryFiles(join(root, ".pbot/history")));
|
|
24
24
|
}
|
|
25
25
|
attach(agent: Agent) { this.#parents.add(agent); return () => { this.#parents.delete(agent); }; }
|
|
26
26
|
cancel() { this.#controller?.abort(); }
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
1
2
|
import type { Context } from "@deepseek-ai/cordis";
|
|
2
3
|
import { Remote, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
3
4
|
import type {} from "@deepseek-ai/dsh-typert-registry";
|
|
@@ -25,31 +26,46 @@ const validRequest = schema(requestSchema), validExpert = schema(expertSchema),
|
|
|
25
26
|
export function dshStatus(workspaces: DshWorkspaces, workspace: DshWorkspace): Json {
|
|
26
27
|
workspace.check();
|
|
27
28
|
const agents = workspace.agents.list(workspace.owner);
|
|
28
|
-
return json({ host: "dsh", release: packageVersion, workspaceRoot: workspace.root, sessionId: workspace.agent.id,
|
|
29
|
+
return json({ host: "dsh", release: packageVersion, enabled: true, state: "running", workspaceRoot: workspace.root, sessionId: workspace.agent.id,
|
|
29
30
|
model: workspace.agent.model.current() ?? null, python: workspaces.python.status,
|
|
30
31
|
controlError: workspace.controlError ?? null, history: workspace.history.status,
|
|
31
32
|
agents, teams: workspace.teams.list(workspace.owner, agents) });
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
/** Status remains available when this workspace has not opted in. */
|
|
36
|
+
export async function dshWorkspaceStatus(workspaces: DshWorkspaces, agent: Agent): Promise<Json> {
|
|
37
|
+
const { root, configuration } = await workspaces.configuration(agent);
|
|
38
|
+
if (!configuration.enabled) return json({ host: "dsh", release: packageVersion, enabled: false,
|
|
39
|
+
state: configuration.error ? "error" : "disabled", nextStep: configuration.error ? configuration.error : "/pbot init",
|
|
40
|
+
workspaceRoot: root, sessionId: agent.id, configuration, model: agent.model.current() ?? null, agents: [], teams: [] });
|
|
41
|
+
return json({ ...dshStatus(workspaces, await workspaces.get(agent)) as Record<string, Json>, configuration });
|
|
42
|
+
}
|
|
43
|
+
|
|
34
44
|
/** Native Remote owns transport and access checks. These workspace reads do not admit or cancel execution. */
|
|
35
45
|
export class PbotManagement extends TypertRemoteService {
|
|
36
46
|
constructor(ctx: Context, private readonly workspaces: DshWorkspaces) { super(ctx, "pbotManagement", { namespace: "pbot" }); }
|
|
37
47
|
|
|
38
|
-
private
|
|
48
|
+
private parent(request: Json, signal: AbortSignal) {
|
|
39
49
|
signal.throwIfAborted(); requireThat(validRequest(request), "管理查询参数无效。");
|
|
40
50
|
const args = request as Static<typeof requestSchema>;
|
|
41
51
|
const agent = this.ctx.agents.get(SessionId(args.parentSessionId));
|
|
42
52
|
requireThat(agent, "父会话未加载或已关闭,请在原生会话页面重新打开。");
|
|
53
|
+
return { agent, input: args.input };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private async workspace(request: Json, signal: AbortSignal) {
|
|
57
|
+
const { agent, input } = this.parent(request, signal);
|
|
43
58
|
const workspace = await this.workspaces.get(agent);
|
|
44
59
|
signal.throwIfAborted(); workspace.check();
|
|
45
|
-
return { workspace, input
|
|
60
|
+
return { workspace, input, signal: AbortSignal.any([signal, workspace.lifetime.signal]) };
|
|
46
61
|
}
|
|
47
62
|
|
|
48
63
|
@Remote
|
|
49
64
|
async snapshot(request: Json, signal: AbortSignal): Promise<Json> {
|
|
50
|
-
const {
|
|
65
|
+
const { agent, input } = this.parent(request, signal);
|
|
51
66
|
requireThat(input === undefined, "工作区状态查询不接受额外参数。");
|
|
52
|
-
|
|
67
|
+
const status = await dshWorkspaceStatus(this.workspaces, agent);
|
|
68
|
+
signal.throwIfAborted(); return status;
|
|
53
69
|
}
|
|
54
70
|
|
|
55
71
|
@Remote
|