pi-web-ui 0.110.0 → 0.111.0
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/bin/frp-manager.mjs +85 -7
- package/dist/server/agent-formatters.js +10 -6
- package/dist/server/agent-service-daemon.js +27 -9
- package/dist/server/agent-service.js +140 -24
- package/dist/server/attachments.js +114 -31
- package/dist/server/canvas/canvas-agent-tool.js +587 -0
- package/dist/server/canvas/canvas-cards.js +144 -0
- package/dist/server/canvas/canvas-dispatch.js +155 -0
- package/dist/server/canvas/canvas-orchestrator.js +1027 -0
- package/dist/server/canvas/canvas-store.js +260 -0
- package/dist/server/client-id-utils.js +2 -2
- package/dist/server/client-state.js +24 -0
- package/dist/server/context-budget.js +6 -3
- package/dist/server/dsh/dsh-agent-service.js +115 -9
- package/dist/server/dsh/dsh-client.js +10 -1
- package/dist/server/dsh/runtime/goal-rpc.mjs +128 -3
- package/dist/server/dsh/runtime/launcher.mjs +59 -5
- package/dist/server/dsh/runtime/runtime-root.mjs +353 -40
- package/dist/server/durable/durable-agent-service.js +3 -0
- package/dist/server/file-transfer-routes.js +8 -2
- package/dist/server/files-service.js +10 -2
- package/dist/server/index.js +137 -4
- package/dist/server/marker-service.js +3 -1
- package/dist/server/markers/marker.js +45 -4
- package/dist/server/markers/registry.js +31 -0
- package/dist/server/message-window.js +6 -3
- package/dist/server/office-parse.js +394 -7
- package/dist/server/plugin-api-catalog.js +6 -0
- package/dist/server/plugins.js +97 -20
- package/dist/server/preset-fields.js +35 -1
- package/dist/server/preset-share.js +3 -0
- package/dist/server/prompt-assembler.js +7 -1
- package/dist/server/prompt-composer.js +66 -36
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/remote-ssh-service.js +16 -4
- package/dist/server/settings-service.js +19 -3
- package/dist/server/tool-manager.js +30 -0
- package/dist/server/univer-service.js +448 -0
- package/dist/server/universal/drivers/claude-code.js +19 -2
- package/dist/server/universal/universal-attachments.js +5 -0
- package/dist/server/universal/universal-service.js +5 -0
- package/dist/server/universal/universal-session.js +28 -12
- package/dist/server/update-check.js +90 -5
- package/dist/server/workspace-snapshot.js +33 -2
- package/docs/dsh-engine.md +497 -0
- package/package.json +5 -4
- package/plugin-sdk/index.d.ts +17 -0
- package/plugin-sdk/index.mjs +5 -0
- package/plugins/catalog.json +22 -0
- package/themes/aetheris.css +114 -0
- package/themes/bases/obsidian-base.css +216 -0
- package/themes/md-preview.css +113 -0
- package/themes/wallpaper-flow.css +182 -0
- package/web/dist/assets/{TerminalPanel-BHjM6pzY.js → TerminalPanel-BiUNySMA.js} +2 -2
- package/web/dist/assets/index-B0ajS__T.js +697 -0
- package/web/dist/assets/index-BHik5WGG.css +1 -0
- package/web/dist/assets/{markdown-DXwnfD9T.js → markdown-BJZlfvdP.js} +24 -24
- package/web/dist/assets/markdown-DSNUiDzp.css +1 -0
- package/web/dist/index.html +4 -4
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/es-DIDZppIF.js +0 -2
- package/web/dist/assets/index-DwInT7-a.css +0 -1
- package/web/dist/assets/index-GfVFIgIL.js +0 -693
- package/web/dist/assets/markdown-CCeVCbci.css +0 -1
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* canvas-store.ts — 画布协作工程持久化与模板管理器。
|
|
3
|
+
*
|
|
4
|
+
* 画布工程存放在 <dataDir>/canvas/<graphId>.json 中。
|
|
5
|
+
* 提供画布的增删改查、列表摘要、以及内置开箱即用模板。
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, unlinkSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { writeJsonAtomicSync } from "../atomic-file.js";
|
|
10
|
+
/** 创建系统出厂默认画布(全栈多引擎敏捷协同工程) */
|
|
11
|
+
export function createDefaultCanvasGraph(id = "default") {
|
|
12
|
+
const now = Date.now();
|
|
13
|
+
return {
|
|
14
|
+
id,
|
|
15
|
+
name: "全栈多引擎协同流水线",
|
|
16
|
+
viewport: { x: 50, y: 50, zoom: 1 },
|
|
17
|
+
status: "idle",
|
|
18
|
+
createdAt: now,
|
|
19
|
+
updatedAt: now,
|
|
20
|
+
nodes: [
|
|
21
|
+
{
|
|
22
|
+
id: "node_architect",
|
|
23
|
+
title: "架构总指挥 (Lead)",
|
|
24
|
+
role: "architect",
|
|
25
|
+
x: 80,
|
|
26
|
+
y: 180,
|
|
27
|
+
width: 300,
|
|
28
|
+
engine: "pi",
|
|
29
|
+
model: "anthropic/claude-3-7-sonnet",
|
|
30
|
+
cwd: ".",
|
|
31
|
+
useWorktree: false,
|
|
32
|
+
systemPromptOverride: "你是团队首席架构师。负责拆解需求、明确模块边界与接口契约,向前后端开发派发清晰的任务卡。",
|
|
33
|
+
instruction: "把业务需求拆解为前后端清晰的技术规约与数据契约,可用 {{上游摘要}} 引用输入,派发任务卡给下游。",
|
|
34
|
+
status: "idle",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: "node_fe",
|
|
38
|
+
title: "前端界面工程师",
|
|
39
|
+
role: "coder",
|
|
40
|
+
x: 480,
|
|
41
|
+
y: 60,
|
|
42
|
+
width: 300,
|
|
43
|
+
engine: "dsh",
|
|
44
|
+
model: "deepseek/deepseek-chat",
|
|
45
|
+
cwd: "web",
|
|
46
|
+
useWorktree: true,
|
|
47
|
+
systemPromptOverride: "你是前端专家。使用 DSH 极速 Hashline 补丁引擎,根据契约编写 React/Vite 界面与交互。",
|
|
48
|
+
instruction: "基于上游契约 {{上游摘要}} 快速编写组件与交互,保持最小改动。",
|
|
49
|
+
status: "idle",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "node_be",
|
|
53
|
+
title: "后端与核心引擎",
|
|
54
|
+
role: "coder",
|
|
55
|
+
x: 480,
|
|
56
|
+
y: 320,
|
|
57
|
+
width: 300,
|
|
58
|
+
engine: "claude",
|
|
59
|
+
model: "deepseek/deepseek-chat",
|
|
60
|
+
cwd: "server",
|
|
61
|
+
useWorktree: true,
|
|
62
|
+
systemPromptOverride: "你是后端服务专家。使用 Claude Code 引擎负责 Node/Express/WS 路由实现、数据持久化与核心逻辑处理。",
|
|
63
|
+
instruction: "按上游数据契约 {{上游摘要}} 实现后端路由与核心逻辑,保证可运行。",
|
|
64
|
+
status: "idle",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: "node_qa",
|
|
68
|
+
title: "测试与自愈运维",
|
|
69
|
+
role: "tester",
|
|
70
|
+
x: 880,
|
|
71
|
+
y: 180,
|
|
72
|
+
width: 300,
|
|
73
|
+
engine: "durable",
|
|
74
|
+
model: "anthropic/claude-3-5-haiku",
|
|
75
|
+
cwd: ".",
|
|
76
|
+
useWorktree: false,
|
|
77
|
+
systemPromptOverride: "你是测试与自愈运维专家。使用 Durable 引擎持久化运行单元测试、类型检查与端到端验证,发现 Bug 即时自愈纠错。",
|
|
78
|
+
instruction: "运行测试套件并自动修复失败项,把验证结论交接归档。",
|
|
79
|
+
status: "idle",
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
edges: [
|
|
83
|
+
{
|
|
84
|
+
id: "edge_arch_to_fe",
|
|
85
|
+
sourceNodeId: "node_architect",
|
|
86
|
+
targetNodeId: "node_fe",
|
|
87
|
+
type: "handoff",
|
|
88
|
+
label: "派发前端需求与 UI 契约",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: "edge_arch_to_be",
|
|
92
|
+
sourceNodeId: "node_architect",
|
|
93
|
+
targetNodeId: "node_be",
|
|
94
|
+
type: "handoff",
|
|
95
|
+
label: "派发后端路由与数据契约",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: "edge_fe_to_qa",
|
|
99
|
+
sourceNodeId: "node_fe",
|
|
100
|
+
targetNodeId: "node_qa",
|
|
101
|
+
type: "handoff",
|
|
102
|
+
label: "前端产物提交验证",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
id: "edge_be_to_qa",
|
|
106
|
+
sourceNodeId: "node_be",
|
|
107
|
+
targetNodeId: "node_qa",
|
|
108
|
+
type: "handoff",
|
|
109
|
+
label: "后端接口提交测试",
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/** 画布图/节点 id 白名单:抵挡路径穿越(../)与 git 分支参数注入载体。
|
|
115
|
+
* 限制字符集与长度,杜绝 join 拼接逃逸、worktree 目录逃逸、git 分支名注入。 */
|
|
116
|
+
const SAFE_ID_RE = /^[A-Za-z0-9._-]{1,64}$/;
|
|
117
|
+
/** id 是否可安全用作文件名片段 / worktree 目录名 / git 分支名。 */
|
|
118
|
+
export function isSafeGraphId(id) {
|
|
119
|
+
return typeof id === "string" && SAFE_ID_RE.test(id);
|
|
120
|
+
}
|
|
121
|
+
function assertSafeGraphId(id) {
|
|
122
|
+
if (!isSafeGraphId(id))
|
|
123
|
+
throw new Error(`Invalid canvas graph id: ${JSON.stringify(id)}`);
|
|
124
|
+
}
|
|
125
|
+
/** 确保画布存储目录存在 */
|
|
126
|
+
function ensureCanvasDir(dataDir) {
|
|
127
|
+
const dir = join(dataDir, "canvas");
|
|
128
|
+
if (!existsSync(dir)) {
|
|
129
|
+
mkdirSync(dir, { recursive: true });
|
|
130
|
+
}
|
|
131
|
+
return dir;
|
|
132
|
+
}
|
|
133
|
+
/** 列出所有已保存的画布工程摘要 */
|
|
134
|
+
export function listCanvasGraphs(dataDir) {
|
|
135
|
+
const dir = ensureCanvasDir(dataDir);
|
|
136
|
+
const files = readdirSync(dir).filter((f) => f.endsWith(".json"));
|
|
137
|
+
if (files.length === 0) {
|
|
138
|
+
// 初始化默认画布
|
|
139
|
+
const def = createDefaultCanvasGraph();
|
|
140
|
+
saveCanvasGraph(dataDir, def);
|
|
141
|
+
return [
|
|
142
|
+
{
|
|
143
|
+
id: def.id,
|
|
144
|
+
name: def.name,
|
|
145
|
+
nodeCount: def.nodes.length,
|
|
146
|
+
edgeCount: def.edges.length,
|
|
147
|
+
updatedAt: def.updatedAt,
|
|
148
|
+
},
|
|
149
|
+
];
|
|
150
|
+
}
|
|
151
|
+
const list = [];
|
|
152
|
+
for (const f of files) {
|
|
153
|
+
try {
|
|
154
|
+
const full = join(dir, f);
|
|
155
|
+
const content = JSON.parse(readFileSync(full, "utf8"));
|
|
156
|
+
if (content && content.id) {
|
|
157
|
+
list.push({
|
|
158
|
+
id: content.id,
|
|
159
|
+
name: content.name || content.id,
|
|
160
|
+
nodeCount: content.nodes?.length ?? 0,
|
|
161
|
+
edgeCount: content.edges?.length ?? 0,
|
|
162
|
+
updatedAt: content.updatedAt ?? Date.now(),
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
// 跳过损坏的文件
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return list.sort((a, b) => b.updatedAt - a.updatedAt);
|
|
171
|
+
}
|
|
172
|
+
/** 读取指定画布工程 */
|
|
173
|
+
export function loadCanvasGraph(dataDir, id) {
|
|
174
|
+
assertSafeGraphId(id);
|
|
175
|
+
const dir = ensureCanvasDir(dataDir);
|
|
176
|
+
const path = join(dir, `${id}.json`);
|
|
177
|
+
if (!existsSync(path)) {
|
|
178
|
+
if (id === "default") {
|
|
179
|
+
const def = createDefaultCanvasGraph(id);
|
|
180
|
+
saveCanvasGraph(dataDir, def);
|
|
181
|
+
return def;
|
|
182
|
+
}
|
|
183
|
+
throw new Error(`Canvas graph not found: ${id}`);
|
|
184
|
+
}
|
|
185
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
186
|
+
}
|
|
187
|
+
/** 保存或更新画布工程(全量拓扑写:rev +1) */
|
|
188
|
+
export function saveCanvasGraph(dataDir, graph, opts) {
|
|
189
|
+
assertSafeGraphId(graph.id);
|
|
190
|
+
const dir = ensureCanvasDir(dataDir);
|
|
191
|
+
const path = join(dir, `${graph.id}.json`);
|
|
192
|
+
let diskRev = 0;
|
|
193
|
+
if (existsSync(path)) {
|
|
194
|
+
try {
|
|
195
|
+
diskRev = JSON.parse(readFileSync(path, "utf8")).rev ?? 0;
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
diskRev = 0;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (opts?.expectedRev !== undefined && opts.expectedRev !== diskRev) {
|
|
202
|
+
return { conflict: true, graph: JSON.parse(readFileSync(path, "utf8")) };
|
|
203
|
+
}
|
|
204
|
+
graph.rev = diskRev + 1;
|
|
205
|
+
graph.updatedAt = Date.now();
|
|
206
|
+
writeJsonAtomicSync(path, graph);
|
|
207
|
+
return { conflict: false, graph };
|
|
208
|
+
}
|
|
209
|
+
const RUNTIME_FIELDS = [
|
|
210
|
+
"status",
|
|
211
|
+
"currentAction",
|
|
212
|
+
"lastOutputSummary",
|
|
213
|
+
"lastError",
|
|
214
|
+
"loopCount",
|
|
215
|
+
"needsReview",
|
|
216
|
+
"reviewDecision",
|
|
217
|
+
];
|
|
218
|
+
/** 运行态落盘:只合并运行字段,拓扑(nodes 增删/edges/坐标/指令)以磁盘版为准,防 stale 回滚(F1)。不推进 rev。 */
|
|
219
|
+
export function saveCanvasRuntimeState(dataDir, runtime) {
|
|
220
|
+
assertSafeGraphId(runtime.id);
|
|
221
|
+
const dir = ensureCanvasDir(dataDir);
|
|
222
|
+
const path = join(dir, `${runtime.id}.json`);
|
|
223
|
+
if (!existsSync(path)) {
|
|
224
|
+
runtime.rev = runtime.rev ?? 1;
|
|
225
|
+
runtime.updatedAt = Date.now();
|
|
226
|
+
writeJsonAtomicSync(path, runtime);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
let disk;
|
|
230
|
+
try {
|
|
231
|
+
disk = JSON.parse(readFileSync(path, "utf8"));
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const rt = new Map(runtime.nodes.map((n) => [n.id, n]));
|
|
237
|
+
for (const n of disk.nodes) {
|
|
238
|
+
const r = rt.get(n.id);
|
|
239
|
+
if (!r)
|
|
240
|
+
continue;
|
|
241
|
+
for (const f of RUNTIME_FIELDS)
|
|
242
|
+
n[f] = r[f];
|
|
243
|
+
}
|
|
244
|
+
disk.status = runtime.status;
|
|
245
|
+
disk.updatedAt = Date.now();
|
|
246
|
+
writeJsonAtomicSync(path, disk);
|
|
247
|
+
// 回填调用方,使广播带上最新 rev/拓扑
|
|
248
|
+
runtime.rev = disk.rev;
|
|
249
|
+
}
|
|
250
|
+
/** 删除画布工程 */
|
|
251
|
+
export function deleteCanvasGraph(dataDir, id) {
|
|
252
|
+
assertSafeGraphId(id);
|
|
253
|
+
const dir = ensureCanvasDir(dataDir);
|
|
254
|
+
const path = join(dir, `${id}.json`);
|
|
255
|
+
if (existsSync(path)) {
|
|
256
|
+
unlinkSync(path);
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
@@ -45,7 +45,7 @@ export function checkPluginCwd(cwd) {
|
|
|
45
45
|
}
|
|
46
46
|
return { ok: true, abs };
|
|
47
47
|
}
|
|
48
|
-
/**
|
|
48
|
+
/** 插件/调度/Canvas伪客户端:sink 常驻或后台辅助专用通道,不参与聊天会话认领与感知。 */
|
|
49
49
|
export function isPseudoClientId(id) {
|
|
50
|
-
return id.startsWith("plugin:") || id.startsWith("scheduler:");
|
|
50
|
+
return (id.startsWith("plugin:") || id.startsWith("scheduler:") || id.startsWith("canvas:") || id.startsWith("canvas-"));
|
|
51
51
|
}
|
|
@@ -250,6 +250,22 @@ export function normalizeUiLayout(v) {
|
|
|
250
250
|
export function normalizeSkillList(v) {
|
|
251
251
|
return Array.isArray(v) ? v.filter((x) => typeof x === "string") : [];
|
|
252
252
|
}
|
|
253
|
+
export const DEFAULT_SKILLS_CATALOG_MAX_DESC = 250;
|
|
254
|
+
export const DEFAULT_SKILLS_CATALOG_BUDGET = 20000;
|
|
255
|
+
/** 归一化技能名录单描述字符数截断:>=0 整数,非法/未设置回退 250。0 为不截断。 */
|
|
256
|
+
export function normalizeSkillsCatalogMaxDesc(v) {
|
|
257
|
+
if (typeof v === "number" && Number.isFinite(v) && v >= 0) {
|
|
258
|
+
return Math.floor(v);
|
|
259
|
+
}
|
|
260
|
+
return DEFAULT_SKILLS_CATALOG_MAX_DESC;
|
|
261
|
+
}
|
|
262
|
+
/** 归一化技能名录总字符预算:>=0 整数,非法/未设置回退 20000。0 为不设限。 */
|
|
263
|
+
export function normalizeSkillsCatalogBudget(v) {
|
|
264
|
+
if (typeof v === "number" && Number.isFinite(v) && v >= 0) {
|
|
265
|
+
return Math.floor(v);
|
|
266
|
+
}
|
|
267
|
+
return DEFAULT_SKILLS_CATALOG_BUDGET;
|
|
268
|
+
}
|
|
253
269
|
/** 工具延迟加载的**出厂默认**(默认关:模型忘记加载会先吃一次 `Tool <name> not found`,
|
|
254
270
|
* 开箱即用优先——见 #652;`PI_WEB_TOOL_LAZY_LOADING=1/true/on/yes` 部署级打开,给
|
|
255
271
|
* 「想省上下文、愿意让模型多一步 load_tools」的实例一个开关;用户在设置面板的选择优先于此)。 */
|
|
@@ -852,6 +868,9 @@ export class ClientStateStore {
|
|
|
852
868
|
retainFinishedConversations: stored?.retainFinishedConversations ?? false,
|
|
853
869
|
openRecentSessionOnProjectSwitch: stored?.openRecentSessionOnProjectSwitch ?? true,
|
|
854
870
|
skillsFullText: normalizeSkillList(stored?.skillsFullText),
|
|
871
|
+
skillsCatalogMaxDesc: normalizeSkillsCatalogMaxDesc(stored?.skillsCatalogMaxDesc),
|
|
872
|
+
skillsCatalogShowLocation: Boolean(stored?.skillsCatalogShowLocation ?? false),
|
|
873
|
+
skillsCatalogBudget: normalizeSkillsCatalogBudget(stored?.skillsCatalogBudget),
|
|
855
874
|
visionBridgeEnabled: stored?.visionBridgeEnabled ?? true,
|
|
856
875
|
visionBridgeModel: stored?.visionBridgeModel ?? null,
|
|
857
876
|
visionBridgePromptMode: stored?.visionBridgePromptMode === "replace" ? "replace" : "append",
|
|
@@ -921,6 +940,11 @@ export class ClientStateStore {
|
|
|
921
940
|
retainFinishedConversations: settings.retainFinishedConversations ?? cur.retainFinishedConversations ?? false,
|
|
922
941
|
openRecentSessionOnProjectSwitch: settings.openRecentSessionOnProjectSwitch ?? cur.openRecentSessionOnProjectSwitch ?? true,
|
|
923
942
|
skillsFullText: normalizeSkillList(settings.skillsFullText ?? cur.skillsFullText),
|
|
943
|
+
skillsCatalogMaxDesc: normalizeSkillsCatalogMaxDesc(settings.skillsCatalogMaxDesc ?? cur.skillsCatalogMaxDesc ?? DEFAULT_SKILLS_CATALOG_MAX_DESC),
|
|
944
|
+
skillsCatalogShowLocation: settings.skillsCatalogShowLocation !== undefined
|
|
945
|
+
? Boolean(settings.skillsCatalogShowLocation)
|
|
946
|
+
: (cur.skillsCatalogShowLocation ?? false),
|
|
947
|
+
skillsCatalogBudget: normalizeSkillsCatalogBudget(settings.skillsCatalogBudget ?? cur.skillsCatalogBudget ?? DEFAULT_SKILLS_CATALOG_BUDGET),
|
|
924
948
|
visionBridgeEnabled: settings.visionBridgeEnabled ?? cur.visionBridgeEnabled ?? true,
|
|
925
949
|
// 按键存在性合并:null 是合法值(清除语义),`null ?? cur` 会把旧值
|
|
926
950
|
// 复活到磁盘(设置面板清空后重启又回来)。settings-service 持久化
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* 纯模块:纯函数与纯逻辑,无外部 I/O 副作用,易于单测与多端复用。
|
|
14
14
|
*/
|
|
15
|
+
import { SOFT_CAP_MIN_HEADROOM } from "./soft-cap.js";
|
|
15
16
|
/** 默认第一级触发预警水位(70%)。 */
|
|
16
17
|
export const DEFAULT_PRUNE_WATERMARK = 0.7;
|
|
17
18
|
/** 默认第二级触发预警水位(85%)。 */
|
|
@@ -265,9 +266,11 @@ export function foldCompletedStepLogs(messages, options = {}) {
|
|
|
265
266
|
export function pruneContextHierarchically(messages, options) {
|
|
266
267
|
const contextWindow = options.contextWindow > 0 ? options.contextWindow : 128_000;
|
|
267
268
|
const reserveTokens = options.reserveTokens > 0 ? options.reserveTokens : 16_384;
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
269
|
+
const room = contextWindow - reserveTokens;
|
|
270
|
+
// reserve 若是按更大窗口换算的(例如 1M - 256K = 744K),room 会变成负数,
|
|
271
|
+
// 70% 水位跟着变成负数,任意长度都会裁。只在 room 不为正时改按当前窗口收口。
|
|
272
|
+
const physicalCap = room > 0 ? room : Math.max(1, contextWindow - SOFT_CAP_MIN_HEADROOM);
|
|
273
|
+
const effectiveCap = options.softCap && options.softCap > 0 ? Math.min(options.softCap, physicalCap) : physicalCap;
|
|
271
274
|
const tier1Watermark = options.tier1Watermark ?? DEFAULT_PRUNE_WATERMARK;
|
|
272
275
|
const tier2Watermark = options.tier2Watermark ?? DEFAULT_STAGE2_WATERMARK;
|
|
273
276
|
const tier1Threshold = Math.floor(effectiveCap * tier1Watermark);
|
|
@@ -33,6 +33,7 @@ import { BG_CLEANUP_FALLBACK_MIN, BgServerTracker } from "../bg-servers.js";
|
|
|
33
33
|
import { ClientStateStore, DEFAULT_RETRY_MAX_ATTEMPTS, normalizeBgCleanupMinutes, normalizePathKey, normalizeToolWatchdogTimeoutMs, settingsPresetToUi, } from "../client-state.js";
|
|
34
34
|
import { normalizeUiLayout, normalizeKeepRecentMessages, DEFAULT_KEEP_RECENT_MESSAGES } from "../client-state.js";
|
|
35
35
|
import { PLAN_MODE_SYSTEM_PROMPT } from "../plan-mode.js";
|
|
36
|
+
import { buildToolsSchemaText } from "../prompt-composer.js";
|
|
36
37
|
import { FilesService, workspacePath, desktopDirWire } from "../files-service.js";
|
|
37
38
|
import { SandboxManager, isSameOrSubpath } from "../sandbox-service.js";
|
|
38
39
|
import { QuiesceRejectedError } from "../agent-service.js";
|
|
@@ -229,6 +230,11 @@ export class DshClientSession {
|
|
|
229
230
|
permissionOptions = [];
|
|
230
231
|
/** clone 出来的预设 id(roster 名录校验用;空 = 未生成,走 legacy)。 */
|
|
231
232
|
presetCloneIds = [];
|
|
233
|
+
/** 系统提示词缓存(从运行时 inspectPrompt 异步拉取;未就绪时兜底)。 */
|
|
234
|
+
cachedEffectiveSystemPrompt = "";
|
|
235
|
+
cachedToolsSchema = "";
|
|
236
|
+
cachedPromptSections = [];
|
|
237
|
+
cachedPromptSourceDefaults = {};
|
|
232
238
|
files;
|
|
233
239
|
bg;
|
|
234
240
|
sandboxes;
|
|
@@ -405,6 +411,7 @@ export class DshClientSession {
|
|
|
405
411
|
void cs.refreshAgentPresets();
|
|
406
412
|
void cs.refreshPermissionOptions().catch(() => { });
|
|
407
413
|
void cs.refreshActivePermission().catch(() => { });
|
|
414
|
+
void cs.refreshPromptInfo().catch(() => { });
|
|
408
415
|
};
|
|
409
416
|
// P0-1 watchdog:意外退出(非 kill/close 主动触发)→ 限频自动重启,保持可用。
|
|
410
417
|
cs.runtime.onExit = (code, signal, intentional) => {
|
|
@@ -415,11 +422,19 @@ export class DshClientSession {
|
|
|
415
422
|
// P0-5 启动重试:1s/3s/9s 指数退避,最终失败才发 notice。
|
|
416
423
|
void cs.startWithRetry().catch((err) => {
|
|
417
424
|
console.error(`[dsh] runtime.start 失败 (client=${clientId}): ${err.message}`);
|
|
425
|
+
const errMsg = err.message || "";
|
|
426
|
+
const isDepOrRuntimeIssue = /找不到 DSH 运行时树|版本族不匹配|version mismatch|dsh-base|typert|codec|launcher|spawn|node_modules|not found|exit.*code/i.test(errMsg);
|
|
427
|
+
const hintZh = isDepOrRuntimeIssue
|
|
428
|
+
? "请检查 @deepseek-ai/dsh 依赖安装与版本匹配(详见 docs/dsh-engine.md)。"
|
|
429
|
+
: "请检查 DeepSeek API key(~/.pi/agent/auth.json)与 dsh 依赖安装。";
|
|
430
|
+
const hintEn = isDepOrRuntimeIssue
|
|
431
|
+
? "Check @deepseek-ai/dsh installation and version compatibility (see docs/dsh-engine.md)."
|
|
432
|
+
: "Check the DeepSeek API key (~/.pi/agent/auth.json) and dsh dependencies.";
|
|
418
433
|
cs.pendingNotices.push({
|
|
419
434
|
type: "notice",
|
|
420
435
|
level: "error",
|
|
421
|
-
text: `DSH 运行时启动失败:${
|
|
422
|
-
textEn: `DSH runtime failed to start: ${
|
|
436
|
+
text: `DSH 运行时启动失败:${errMsg}。${hintZh}`,
|
|
437
|
+
textEn: `DSH runtime failed to start: ${errMsg}. ${hintEn}`,
|
|
423
438
|
});
|
|
424
439
|
});
|
|
425
440
|
// P0-3 convs 内存回收定时器(unref:不阻止进程退出)。
|
|
@@ -472,11 +487,19 @@ export class DshClientSession {
|
|
|
472
487
|
this.runtimeRestart.count += 1;
|
|
473
488
|
if (this.runtimeRestart.count > DshClientSession.RUNTIME_MAX_RESTARTS) {
|
|
474
489
|
console.error(`[dsh] runtime 反复崩溃 (code=${code} signal=${signal}),停止自动重启`);
|
|
490
|
+
const tail = this.runtime.getStderrTail();
|
|
491
|
+
const isDepOrRuntimeIssue = /找不到 DSH 运行时树|版本族不匹配|version mismatch|dsh-base|typert|codec/i.test(tail);
|
|
492
|
+
const hintZh = isDepOrRuntimeIssue
|
|
493
|
+
? "DSH 运行时反复崩溃,已停止自动重启。请检查 dsh 运行时依赖安装与版本匹配(详见 docs/dsh-engine.md)。"
|
|
494
|
+
: "DSH 运行时反复崩溃,已停止自动重启。请检查 DeepSeek API key 与 dsh 依赖安装。";
|
|
495
|
+
const hintEn = isDepOrRuntimeIssue
|
|
496
|
+
? "DSH runtime keeps crashing; auto-restart stopped. Check dsh runtime dependencies and version compatibility (see docs/dsh-engine.md)."
|
|
497
|
+
: "DSH runtime keeps crashing; auto-restart stopped. Check the DeepSeek API key and dsh dependencies.";
|
|
475
498
|
this.emit({
|
|
476
499
|
type: "notice",
|
|
477
500
|
level: "error",
|
|
478
|
-
text:
|
|
479
|
-
textEn:
|
|
501
|
+
text: hintZh,
|
|
502
|
+
textEn: hintEn,
|
|
480
503
|
});
|
|
481
504
|
this.flushSnapshot();
|
|
482
505
|
return;
|
|
@@ -3529,7 +3552,50 @@ export class DshClientSession {
|
|
|
3529
3552
|
// -----------------------------------------------------------------------
|
|
3530
3553
|
// 设置 / 系统提示词
|
|
3531
3554
|
// -----------------------------------------------------------------------
|
|
3555
|
+
buildFallbackPromptSections() {
|
|
3556
|
+
const identity = "You are an AI agent powered by DeepSeek Harness.";
|
|
3557
|
+
const custom = this.settings.customSystemPrompt.trim();
|
|
3558
|
+
const markerGuidance = this.markerSvc.buildGuidance().trim();
|
|
3559
|
+
const effectiveCustom = [custom, markerGuidance].filter(Boolean).join("\n\n");
|
|
3560
|
+
const sections = [
|
|
3561
|
+
{ name: "harness:identity", text: identity, chars: identity.length },
|
|
3562
|
+
];
|
|
3563
|
+
if (this.settings.promptMode === "replace") {
|
|
3564
|
+
const persona = effectiveCustom ||
|
|
3565
|
+
`You are a coding agent powered by the ${this.model} model. Your working directory is ${this.cwd}.`;
|
|
3566
|
+
sections.push({ name: "deployment:persona-prefix", text: persona, chars: persona.length });
|
|
3567
|
+
}
|
|
3568
|
+
else {
|
|
3569
|
+
const persona = `You are a coding agent powered by the ${this.model} model. Your working directory is ${this.cwd}.`;
|
|
3570
|
+
sections.push({ name: "deployment:persona-prefix", text: persona, chars: persona.length });
|
|
3571
|
+
if (effectiveCustom) {
|
|
3572
|
+
sections.push({ name: "pi-webui:custom-prompt", text: effectiveCustom, chars: effectiveCustom.length });
|
|
3573
|
+
}
|
|
3574
|
+
}
|
|
3575
|
+
return sections;
|
|
3576
|
+
}
|
|
3577
|
+
buildFallbackSystemPrompt() {
|
|
3578
|
+
return this.buildFallbackPromptSections()
|
|
3579
|
+
.map((s) => s.text)
|
|
3580
|
+
.filter(Boolean)
|
|
3581
|
+
.join("\n\n");
|
|
3582
|
+
}
|
|
3583
|
+
buildFallbackPromptSourceDefaults() {
|
|
3584
|
+
const defs = {};
|
|
3585
|
+
for (const s of this.buildFallbackPromptSections()) {
|
|
3586
|
+
defs[s.name] = s.text;
|
|
3587
|
+
}
|
|
3588
|
+
return defs;
|
|
3589
|
+
}
|
|
3532
3590
|
pushSettings() {
|
|
3591
|
+
if (this.runtime?.alive && !this.cachedEffectiveSystemPrompt) {
|
|
3592
|
+
void this.refreshPromptInfo().catch(() => { });
|
|
3593
|
+
}
|
|
3594
|
+
const effectiveSystemPrompt = this.cachedEffectiveSystemPrompt || this.buildFallbackSystemPrompt();
|
|
3595
|
+
const promptSourceDefaults = Object.keys(this.cachedPromptSourceDefaults).length > 0
|
|
3596
|
+
? this.cachedPromptSourceDefaults
|
|
3597
|
+
: this.buildFallbackPromptSourceDefaults();
|
|
3598
|
+
const promptSections = this.cachedPromptSections.length > 0 ? this.cachedPromptSections : this.buildFallbackPromptSections();
|
|
3533
3599
|
const settings = {
|
|
3534
3600
|
promptMode: this.settings.promptMode,
|
|
3535
3601
|
customSystemPrompt: this.settings.customSystemPrompt,
|
|
@@ -3573,6 +3639,9 @@ export class DshClientSession {
|
|
|
3573
3639
|
openRecentSessionOnProjectSwitch: this.settings.openRecentSessionOnProjectSwitch ?? true,
|
|
3574
3640
|
// DSH 无 skill 全文注入概念,给空保协议完整。
|
|
3575
3641
|
skillsFullText: [],
|
|
3642
|
+
skillsCatalogMaxDesc: 250,
|
|
3643
|
+
skillsCatalogShowLocation: false,
|
|
3644
|
+
skillsCatalogBudget: 20000,
|
|
3576
3645
|
visionBridgeEnabled: false,
|
|
3577
3646
|
visionBridgeModel: null,
|
|
3578
3647
|
visionBridgePromptMode: "append",
|
|
@@ -3592,10 +3661,11 @@ export class DshClientSession {
|
|
|
3592
3661
|
promptOverrides: this.settings.promptOverrides ?? {},
|
|
3593
3662
|
// DSH 无 pi 工具注册表面,逐工具文案覆盖不适用;保协议完整。
|
|
3594
3663
|
toolPromptOverrides: {},
|
|
3595
|
-
effectiveSystemPrompt
|
|
3596
|
-
promptSourceDefaults
|
|
3597
|
-
|
|
3598
|
-
|
|
3664
|
+
effectiveSystemPrompt,
|
|
3665
|
+
promptSourceDefaults,
|
|
3666
|
+
promptSections,
|
|
3667
|
+
// DSH 运行时真实的工具 schema 文本(发给模型的工具列表 JSON Schema 格式化文本)。
|
|
3668
|
+
toolsSchema: this.cachedToolsSchema,
|
|
3599
3669
|
visionBridgeDefaultPrompt: "",
|
|
3600
3670
|
scmCommitMsgDefaultPrompt: "",
|
|
3601
3671
|
visionModels: [],
|
|
@@ -3735,8 +3805,10 @@ export class DshClientSession {
|
|
|
3735
3805
|
// 仅系统提示词或内联标记指引变化才重启运行时(DSH_PERSONA 由 launcher env 注入);
|
|
3736
3806
|
// 其他设置(开关/隐藏插件等)只存不回写运行时。
|
|
3737
3807
|
const personaChanged = partial.promptMode !== undefined || partial.customSystemPrompt !== undefined || markerGuidanceChanged;
|
|
3738
|
-
if (personaChanged)
|
|
3808
|
+
if (personaChanged) {
|
|
3739
3809
|
await this.applyPersona();
|
|
3810
|
+
void this.refreshPromptInfo().catch(() => { });
|
|
3811
|
+
}
|
|
3740
3812
|
// 技能启停(#18):禁用集变化 → 同步运行时(晚 pre-step 钩子过滤目录)并刷新技能列表。
|
|
3741
3813
|
if (partial.disabledSkills !== undefined) {
|
|
3742
3814
|
void this.pushDisabledSkillsToRuntime();
|
|
@@ -3768,6 +3840,35 @@ export class DshClientSession {
|
|
|
3768
3840
|
}
|
|
3769
3841
|
return Promise.resolve();
|
|
3770
3842
|
}
|
|
3843
|
+
/** 从运行时异步拉取真实组装的系统提示词、sections 与工具 schema。 */
|
|
3844
|
+
async refreshPromptInfo() {
|
|
3845
|
+
try {
|
|
3846
|
+
if (!this.runtime.alive)
|
|
3847
|
+
return;
|
|
3848
|
+
const res = await this.runtime.inspectPrompt();
|
|
3849
|
+
if (res && !res.error) {
|
|
3850
|
+
if (typeof res.prompt === "string" && res.prompt) {
|
|
3851
|
+
this.cachedEffectiveSystemPrompt = res.prompt;
|
|
3852
|
+
}
|
|
3853
|
+
if (Array.isArray(res.sections)) {
|
|
3854
|
+
this.cachedPromptSections = res.sections;
|
|
3855
|
+
const defaults = {};
|
|
3856
|
+
for (const s of res.sections) {
|
|
3857
|
+
if (s.name)
|
|
3858
|
+
defaults[s.name] = s.text ?? "";
|
|
3859
|
+
}
|
|
3860
|
+
this.cachedPromptSourceDefaults = defaults;
|
|
3861
|
+
}
|
|
3862
|
+
if (Array.isArray(res.tools) && res.tools.length > 0) {
|
|
3863
|
+
this.cachedToolsSchema = buildToolsSchemaText(res.tools);
|
|
3864
|
+
}
|
|
3865
|
+
this.pushSettings();
|
|
3866
|
+
}
|
|
3867
|
+
}
|
|
3868
|
+
catch {
|
|
3869
|
+
/* 忽略拉取失败,保持上一次缓存或兜底 */
|
|
3870
|
+
}
|
|
3871
|
+
}
|
|
3771
3872
|
async reloadExtensions() {
|
|
3772
3873
|
// DSH 引擎无 pi 扩展体系。
|
|
3773
3874
|
this.emit({
|
|
@@ -3886,6 +3987,7 @@ export class DshClientSession {
|
|
|
3886
3987
|
conv.agentPreset = res.preset ?? target;
|
|
3887
3988
|
this.emitConversations();
|
|
3888
3989
|
this.pushSettings();
|
|
3990
|
+
void this.refreshPromptInfo().catch(() => { });
|
|
3889
3991
|
this.flushSnapshot();
|
|
3890
3992
|
}
|
|
3891
3993
|
catch (err) {
|
|
@@ -5413,6 +5515,10 @@ export class DshAgentService {
|
|
|
5413
5515
|
for (const cs of this.clients.values())
|
|
5414
5516
|
void cs.pushSlashCommands();
|
|
5415
5517
|
}
|
|
5518
|
+
applyPluginMarkers() {
|
|
5519
|
+
for (const cs of this.clients.values())
|
|
5520
|
+
cs.pushSettings();
|
|
5521
|
+
}
|
|
5416
5522
|
refreshBackgroundServers() {
|
|
5417
5523
|
for (const cs of this.clients.values())
|
|
5418
5524
|
cs.refreshBgTasks();
|
|
@@ -164,6 +164,9 @@ export class DshRuntime {
|
|
|
164
164
|
env.PI_WEB_DSH_JSONRPC_ENTRY = this.jsonrpcEntry;
|
|
165
165
|
return { env, activeProvider, bareModelId };
|
|
166
166
|
}
|
|
167
|
+
getStderrTail() {
|
|
168
|
+
return this.stderrTail;
|
|
169
|
+
}
|
|
167
170
|
/** 启动子进程 + initialize 握手(幂等;并发调用共享同一个启动任务)。 */
|
|
168
171
|
start() {
|
|
169
172
|
if (this.disposed) {
|
|
@@ -217,7 +220,8 @@ export class DshRuntime {
|
|
|
217
220
|
return;
|
|
218
221
|
const intentional = this.closed;
|
|
219
222
|
this.debug("exit", { code, signal, intentional });
|
|
220
|
-
const
|
|
223
|
+
const stderrSnippet = this.stderrTail.trim().slice(-2000);
|
|
224
|
+
const err = new DshTransportError(bilingual(`DSH runtime exited (code=${code} signal=${signal}) stderr: ${stderrSnippet}`, `DSH runtime 已退出 (code=${code} signal=${signal}) stderr: ${stderrSnippet}`));
|
|
221
225
|
this.failPending(err);
|
|
222
226
|
this.initialized = false;
|
|
223
227
|
this.onExit?.(code, signal, intentional);
|
|
@@ -396,6 +400,11 @@ export class DshRuntime {
|
|
|
396
400
|
await this.start();
|
|
397
401
|
return this._request("tools/list", {});
|
|
398
402
|
}
|
|
403
|
+
/** 检查并获取运行时当前的组装系统提示词、sections 明细和工具 schemas。 */
|
|
404
|
+
async inspectPrompt(sessionId) {
|
|
405
|
+
await this.start();
|
|
406
|
+
return this._request("prompt/inspect", sessionId ? { sessionId } : {});
|
|
407
|
+
}
|
|
399
408
|
/** 回传一个桥接工具的执行结果(isError=true 时 result 为错误信息)。 */
|
|
400
409
|
async toolsCallResult(id, result, isError) {
|
|
401
410
|
await this.start();
|