pi-web-ui 0.105.1 → 0.106.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.
Files changed (74) hide show
  1. package/CHANGELOG.md +43 -1
  2. package/README.md +193 -797
  3. package/README.zh-CN.md +186 -625
  4. package/README.zh-TW.md +781 -0
  5. package/bin/frp-manager.mjs +1488 -0
  6. package/bin/pi-web-ui.mjs +27 -0
  7. package/deploy/nginx-subpath.conf +16 -1
  8. package/dist/server/agent-service-daemon.js +34 -0
  9. package/dist/server/agent-service.js +227 -44
  10. package/dist/server/claim-files-tool.js +8 -1
  11. package/dist/server/client-state.js +136 -30
  12. package/dist/server/conversation-read-tool.js +12 -4
  13. package/dist/server/delegate-task.js +9 -1
  14. package/dist/server/dispatch-domain-handlers.js +15 -0
  15. package/dist/server/dsh/dsh-agent-service.js +838 -241
  16. package/dist/server/dsh/dsh-client.js +59 -18
  17. package/dist/server/dsh/dsh-market-service.js +233 -0
  18. package/dist/server/dsh/dsh-serialize.js +11 -3
  19. package/dist/server/dsh/dsh-sessions.js +64 -2
  20. package/dist/server/dsh/preset-clones.js +12 -1
  21. package/dist/server/dsh/runtime/goal-rpc.mjs +183 -45
  22. package/dist/server/engine-capabilities.js +72 -0
  23. package/dist/server/engine-probe.js +243 -0
  24. package/dist/server/goal-service.js +23 -12
  25. package/dist/server/i18n.js +20 -1
  26. package/dist/server/index.js +171 -66
  27. package/dist/server/locales.js +1 -0
  28. package/dist/server/mcp-agent-tool.js +10 -7
  29. package/dist/server/mcp-bridge.js +428 -24
  30. package/dist/server/model-admin.js +172 -74
  31. package/dist/server/model-resolver.js +221 -0
  32. package/dist/server/plugin-installer.js +4 -2
  33. package/dist/server/plugins.js +71 -11
  34. package/dist/server/present-files-tool.js +10 -2
  35. package/dist/server/preset-fields.js +14 -0
  36. package/dist/server/preset-share.js +2 -0
  37. package/dist/server/protocol-version.js +1 -1
  38. package/dist/server/schedule-agent-tool.js +2 -1
  39. package/dist/server/scm-commitmsg.js +3 -2
  40. package/dist/server/settings-service.js +10 -2
  41. package/dist/server/skill-discovery.js +161 -0
  42. package/dist/server/skill-tool.js +2 -1
  43. package/dist/server/slash-commands.js +154 -73
  44. package/dist/server/subagent-templates-hant.js +215 -0
  45. package/dist/server/subagent-templates.js +49 -2
  46. package/dist/server/subagents.js +22 -12
  47. package/dist/server/terminals.js +2 -2
  48. package/dist/server/tool-manager.js +3 -0
  49. package/dist/server/universal/driver-base.js +56 -0
  50. package/dist/server/universal/drivers/claude-code.js +462 -0
  51. package/dist/server/universal/drivers/dsh-driver.js +376 -0
  52. package/dist/server/universal/drivers/mock-driver.js +103 -0
  53. package/dist/server/universal/index.js +10 -0
  54. package/dist/server/universal/session-store.js +100 -0
  55. package/dist/server/universal/universal-attachments.js +175 -0
  56. package/dist/server/universal/universal-service.js +149 -0
  57. package/dist/server/universal/universal-session.js +2610 -0
  58. package/dist/server/universal/universal-types.js +4 -0
  59. package/dist/server/update-check.js +4 -1
  60. package/dist/server/worktree-service.js +1 -1
  61. package/dist/server/worktree-tool.js +9 -7
  62. package/package.json +3 -2
  63. package/plugin-sdk/index.d.ts +12 -2
  64. package/plugins/catalog.json +39 -5
  65. package/themes/dark-teal.css +20 -23
  66. package/themes/md-preview.css +1 -2
  67. package/themes/wallpaper-obsidian.css +693 -0
  68. package/web/dist/assets/{TerminalPanel-Mk4laCAL.js → TerminalPanel-CfxKLDW9.js} +2 -2
  69. package/web/dist/assets/index-BtcP6BDk.css +1 -0
  70. package/web/dist/assets/index-XVtCzcHR.js +690 -0
  71. package/web/dist/index.html +2 -2
  72. package/web/dist/sw.js +1 -1
  73. package/web/dist/assets/index-BDLVjBeK.js +0 -690
  74. package/web/dist/assets/index-BQC6lADz.css +0 -1
@@ -23,6 +23,7 @@ import { homedir } from "node:os";
23
23
  import { dirname, join, resolve } from "node:path";
24
24
  import { fileURLToPath } from "node:url";
25
25
  import { bilingual } from "../i18n.js";
26
+ import { resolveProviderCredential } from "../model-resolver.js";
26
27
  /** 项目依赖解析(tsc 编译后 dist/server/dsh/ 里向上找 node_modules)。 */
27
28
  const require = createRequire(import.meta.url);
28
29
  export class DshRpcError extends Error {
@@ -62,6 +63,7 @@ export class DshRuntime {
62
63
  cwd;
63
64
  provider;
64
65
  model;
66
+ modelProvider;
65
67
  maxTokens;
66
68
  sessionRoot;
67
69
  dataDir;
@@ -96,6 +98,9 @@ export class DshRuntime {
96
98
  this.cwd = resolve(opts.cwd);
97
99
  this.provider = opts.provider ?? "deepseek-official";
98
100
  this.model = opts.model ?? "deepseek-v4-flash";
101
+ this.modelProvider =
102
+ opts.modelProvider ??
103
+ (opts.model && opts.model.includes("/") ? opts.model.slice(0, opts.model.indexOf("/")) : undefined);
99
104
  this.maxTokens = opts.maxTokens;
100
105
  this.sessionRoot = opts.sessionRoot;
101
106
  this.dataDir = opts.dataDir;
@@ -121,6 +126,44 @@ export class DshRuntime {
121
126
  get running() {
122
127
  return this.alive;
123
128
  }
129
+ /** 解析当前激活模型对应的运行环境(BaseURL、API Key、CWD 等)与 bare model ID。 */
130
+ resolveRuntimeConfig() {
131
+ let activeProvider = this.modelProvider;
132
+ let bareModelId = this.model;
133
+ if (this.model.includes("/")) {
134
+ const slashIdx = this.model.indexOf("/");
135
+ if (!activeProvider) {
136
+ activeProvider = this.model.slice(0, slashIdx);
137
+ }
138
+ bareModelId = this.model.slice(slashIdx + 1);
139
+ }
140
+ if (!activeProvider) {
141
+ activeProvider = "deepseek";
142
+ }
143
+ // 根据当前激活模型所属的 Provider(通过 resolveProviderCredential)
144
+ // 将对应的 BaseURL 注入到 DEEPSEEK_BASE_URL,将 API Key 注入到 DEEPSEEK_API_KEY
145
+ const cred = resolveProviderCredential(this.agentDir, activeProvider);
146
+ const deepseekKey = loadDeepSeekKey(this.agentDir);
147
+ const resolvedKey = cred.apiKey || (activeProvider === "deepseek" ? deepseekKey : undefined);
148
+ const resolvedBaseUrl = cred.baseUrl;
149
+ const env = {
150
+ ...process.env,
151
+ DSH_CWD: this.cwd,
152
+ ...this.env,
153
+ };
154
+ if (this.sessionRoot)
155
+ env.DSH_SESSION_ROOT = this.sessionRoot;
156
+ if (this.dataDir)
157
+ env.PI_WEB_DSH_DATA_DIR = this.dataDir;
158
+ if (resolvedKey && !this.env.DEEPSEEK_API_KEY && !env.DEEPSEEK_API_KEY) {
159
+ env.DEEPSEEK_API_KEY = resolvedKey;
160
+ }
161
+ if (resolvedBaseUrl && !this.env.DEEPSEEK_BASE_URL && !env.DEEPSEEK_BASE_URL) {
162
+ env.DEEPSEEK_BASE_URL = resolvedBaseUrl;
163
+ }
164
+ env.PI_WEB_DSH_JSONRPC_ENTRY = this.jsonrpcEntry;
165
+ return { env, activeProvider, bareModelId };
166
+ }
124
167
  /** 启动子进程 + initialize 握手(幂等;并发调用共享同一个启动任务)。 */
125
168
  start() {
126
169
  if (this.disposed) {
@@ -144,19 +187,7 @@ export class DshRuntime {
144
187
  // 「版本族」),写死的提示迟早骗人。报当前实际解析到的路径即可。
145
188
  throw new DshTransportError(bilingual(`dsh-sdk-jsonrpc-server is not installed (missing ${this.jsonrpcEntry}). Run npm i (see docs/dsh-engine.md for the pinned version family) first`, `dsh-sdk-jsonrpc-server 未安装(缺 ${this.jsonrpcEntry})。请先 npm i(版本族见 docs/dsh-engine.md)`));
146
189
  }
147
- const key = loadDeepSeekKey(this.agentDir);
148
- const env = {
149
- ...process.env,
150
- DSH_CWD: this.cwd,
151
- ...this.env,
152
- };
153
- if (this.sessionRoot)
154
- env.DSH_SESSION_ROOT = this.sessionRoot;
155
- if (this.dataDir)
156
- env.PI_WEB_DSH_DATA_DIR = this.dataDir;
157
- if (key && !this.env.DEEPSEEK_API_KEY)
158
- env.DEEPSEEK_API_KEY = key;
159
- env.PI_WEB_DSH_JSONRPC_ENTRY = this.jsonrpcEntry;
190
+ const { env, bareModelId } = this.resolveRuntimeConfig();
160
191
  this.closed = false;
161
192
  this.buffer = "";
162
193
  this.pending.clear();
@@ -195,12 +226,12 @@ export class DshRuntime {
195
226
  await this._request("initialize", {
196
227
  cwd: this.cwd,
197
228
  provider: this.provider,
198
- model: this.model,
229
+ model: bareModelId,
199
230
  ...(this.maxTokens ? { maxTokens: this.maxTokens } : {}),
200
231
  });
201
232
  }
202
233
  catch (err) {
203
- console.error(`[dsh] initialize 失败 (model=${this.model} cwd=${this.cwd}): ${err.message}` +
234
+ console.error(`[dsh] initialize 失败 (model=${bareModelId} cwd=${this.cwd}): ${err.message}` +
204
235
  (this.stderrTail ? `\n launcher stderr: ${this.stderrTail.slice(-600)}` : ""));
205
236
  // initialize 失败:确认子进程已被清理,避免半死进程占着 stdin。
206
237
  void this.kill();
@@ -568,10 +599,20 @@ export class DshRuntime {
568
599
  // 等旧进程真正退出(避免 pid 复用竞态)。
569
600
  await new Promise((r) => setTimeout(r, 150));
570
601
  }
571
- if (newModel)
602
+ if (newModel) {
572
603
  this.model = newModel;
573
- if (newProvider)
574
- this.provider = newProvider;
604
+ if (newModel.includes("/")) {
605
+ this.modelProvider = newModel.slice(0, newModel.indexOf("/"));
606
+ }
607
+ }
608
+ if (newProvider) {
609
+ if (newProvider === "deepseek-official") {
610
+ this.provider = newProvider;
611
+ }
612
+ else {
613
+ this.modelProvider = newProvider;
614
+ }
615
+ }
575
616
  this.initialized = false;
576
617
  if (wasAlive)
577
618
  await this.start();
@@ -0,0 +1,233 @@
1
+ /**
2
+ * DSH 插件市场数据服务(对接 awesome-dsh-plugin / dsh-market 数据源)。
3
+ *
4
+ * 数据源:https://awesome-dsh-plugin.com/plugins.json
5
+ * 缓存:<dataDir>/dsh-market-cache.json(默认 12 小时有效)
6
+ * 离线兜底:内置热门精选插件列表,避免断网或首屏拉取受阻时白屏。
7
+ */
8
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
9
+ import { join } from "node:path";
10
+ const DSH_MARKET_URL = "https://awesome-dsh-plugin.com/plugins.json";
11
+ const CACHE_TTL_MS = 12 * 60 * 60 * 1000; // 12 小时
12
+ /** 内置精选种子插件列表(离线/首屏保底用)。 */
13
+ const SEED_CATEGORIES = {
14
+ model: { en: "Models & Providers", zh: "模型与账号接入" },
15
+ ui: { en: "UI Enhancements", zh: "UI 增强" },
16
+ memory: { en: "Memory", zh: "记忆" },
17
+ workflow: { en: "Workflow & Automation", zh: "工作流与自动化" },
18
+ skills: { en: "Skills", zh: "技能" },
19
+ tools: { en: "Tools & Capabilities", zh: "工具与能力" },
20
+ market: { en: "Plugin Markets & Managers", zh: "插件市场与管理器" },
21
+ };
22
+ const SEED_PLUGINS = [
23
+ {
24
+ name: "dsh-our-free-model",
25
+ owner: "Ebony-Vinyl",
26
+ url: "https://github.com/Ebony-Vinyl/dsh-our-free-model",
27
+ category: "model",
28
+ description: {
29
+ zh: "无需登录或 API Key,聚合 DeepSeek V4.1 Flash、Kimi K3 及 13 个主流渠道账号池,完全免费。",
30
+ en: "Frontier models without login or API key: DeepSeek V4.1 Flash, Kimi K3, and 13 channel pools. Completely free.",
31
+ },
32
+ npm: "dsh-our-free-model",
33
+ version: "2.1.0",
34
+ stars: 3820,
35
+ downloads: 185000,
36
+ capabilities: ["net", "env"],
37
+ },
38
+ {
39
+ name: "dshmarket",
40
+ owner: "dsh-market",
41
+ url: "https://github.com/dsh-market/dsh-market",
42
+ category: "market",
43
+ description: {
44
+ zh: "DSH 可视化插件市场:逛一逛,点一下,装好。4500+ 社区插件一键发现与管理。",
45
+ en: "Visual plugin market inside DeepSeek Harness: browse, search, and one-click install 4500+ community plugins.",
46
+ },
47
+ npm: "dshmarket",
48
+ version: "1.66.20",
49
+ stars: 4950,
50
+ downloads: 320000,
51
+ capabilities: ["fs-write", "net"],
52
+ },
53
+ {
54
+ name: "dsh-better-sidebar",
55
+ owner: "omdsh-dev",
56
+ url: "https://github.com/omdsh-dev/dsh-better-sidebar",
57
+ category: "ui",
58
+ description: {
59
+ zh: "侧边栏工作台增强,集成文件渲染、代码编辑、终端、Git 与子代理多标签管理。",
60
+ en: "Full sidebar workbench with file rendering, editing, terminal, Git, and subagents tab management.",
61
+ },
62
+ npm: "@omdsh/dsh-better-sidebar",
63
+ version: "0.21.1",
64
+ stars: 3710,
65
+ downloads: 265800,
66
+ capabilities: ["ui", "fs-read"],
67
+ },
68
+ {
69
+ name: "dsh-project-memory",
70
+ owner: "00080000",
71
+ url: "https://github.com/00080000/dsh-project-memory",
72
+ category: "memory",
73
+ description: {
74
+ zh: "持久化项目级记忆系统:任务清单与阅读文件自动沉淀为跨会话记忆,开发工作流可切换续接。",
75
+ en: "Project memory for dsh: session todos and file reads auto-condense into cross-session task records.",
76
+ },
77
+ npm: "@00080000/dsh-project-memory",
78
+ version: "0.4.0",
79
+ stars: 2150,
80
+ downloads: 142000,
81
+ capabilities: ["fs-write", "fs-read"],
82
+ },
83
+ {
84
+ name: "dsh-task-board",
85
+ owner: "zhu1090093659",
86
+ url: "https://github.com/zhu1090093659/dsh-task-board",
87
+ category: "workflow",
88
+ description: {
89
+ zh: "侧边栏多列看板与定时任务,在后台实时执行并支持 Cron 周期计划调度。",
90
+ en: "Task board for dsh web GUI: multi-column kanban and cron expression execution.",
91
+ },
92
+ npm: "dsh-task-board",
93
+ version: "0.4.1",
94
+ stars: 1840,
95
+ downloads: 177400,
96
+ capabilities: ["fs-write", "timer"],
97
+ },
98
+ {
99
+ name: "dsh-skill-explorer",
100
+ owner: "zhu1090093659",
101
+ url: "https://github.com/zhu1090093659/dsh-skill-explorer",
102
+ category: "skills",
103
+ description: {
104
+ zh: "技能中心:浏览所有已加载技能,按来源分组管理,支持启用/停用与模型调用权限控制。",
105
+ en: "Skill center for dsh web GUI: browse and manage all loaded skills grouped by source.",
106
+ },
107
+ npm: "dsh-skill-explorer",
108
+ version: "0.4.1",
109
+ stars: 1980,
110
+ downloads: 178500,
111
+ capabilities: ["fs-read"],
112
+ },
113
+ {
114
+ name: "dsh-answer-reviewer",
115
+ owner: "bycall",
116
+ url: "https://github.com/bycall/dsh-answer-reviewer",
117
+ category: "workflow",
118
+ description: {
119
+ zh: "智能体答案复审器:独立大模型对助手最终回复打分并提供纠错反馈,低于阈值自动返工。",
120
+ en: "Agentic answer reviewer for DeepSeek Harness: scores turns 1-100 and steers agent with feedback.",
121
+ },
122
+ npm: "dsh-answer-reviewer",
123
+ version: "0.3.5",
124
+ stars: 1250,
125
+ downloads: 98000,
126
+ capabilities: ["llm"],
127
+ },
128
+ ];
129
+ /** 读取或拉取 DSH 市场插件清单。 */
130
+ export async function loadDshMarketData(dataDir, force = false) {
131
+ const cachePath = join(dataDir, "dsh-market-cache.json");
132
+ // 1. 若无需强制刷新,尝试读取有效本地缓存
133
+ if (!force && existsSync(cachePath)) {
134
+ try {
135
+ const raw = readFileSync(cachePath, "utf8");
136
+ const cached = JSON.parse(raw);
137
+ if (cached.savedAt && Date.now() - cached.savedAt < CACHE_TTL_MS && Array.isArray(cached.plugins)) {
138
+ return {
139
+ count: cached.count ?? cached.plugins.length,
140
+ updated: cached.updated ?? "",
141
+ categories: cached.categories ?? SEED_CATEGORIES,
142
+ plugins: cached.plugins,
143
+ };
144
+ }
145
+ }
146
+ catch {
147
+ /* 缓存损坏,继续走网络拉取 */
148
+ }
149
+ }
150
+ // 2. 尝试从远程 awesome-dsh-plugin 获取
151
+ try {
152
+ const controller = new AbortController();
153
+ const timeoutId = setTimeout(() => controller.abort(), 10000);
154
+ const resp = await fetch(DSH_MARKET_URL, {
155
+ signal: controller.signal,
156
+ headers: { "User-Agent": "pi-web-ui/dsh-market" },
157
+ });
158
+ clearTimeout(timeoutId);
159
+ if (resp.ok) {
160
+ const json = (await resp.json());
161
+ const categories = json.categories && typeof json.categories === "object" ? json.categories : SEED_CATEGORIES;
162
+ const pluginList = [];
163
+ if (json.plugins) {
164
+ const entries = Array.isArray(json.plugins) ? json.plugins : Object.values(json.plugins);
165
+ for (const p of entries) {
166
+ if (!p || typeof p !== "object" || !p.name)
167
+ continue;
168
+ pluginList.push({
169
+ name: String(p.name),
170
+ owner: p.owner ? String(p.owner) : undefined,
171
+ url: p.url ? String(p.url) : undefined,
172
+ category: p.category ? String(p.category) : undefined,
173
+ description: typeof p.description === "object" && p.description
174
+ ? {
175
+ zh: p.description.zh ? String(p.description.zh) : undefined,
176
+ en: p.description.en ? String(p.description.en) : undefined,
177
+ }
178
+ : undefined,
179
+ npm: p.npm ? String(p.npm) : undefined,
180
+ version: p.version ? String(p.version) : undefined,
181
+ stars: typeof p.stars === "number" ? p.stars : 0,
182
+ downloads: typeof p.downloads === "number" ? p.downloads : 0,
183
+ capabilities: Array.isArray(p.capabilities) ? p.capabilities.map(String) : [],
184
+ install: p.install ? String(p.install) : undefined,
185
+ });
186
+ }
187
+ }
188
+ // 默认按热度降序排序:综合 Star 与下载量
189
+ pluginList.sort((a, b) => (b.downloads ?? 0) + (b.stars ?? 0) * 10 - ((a.downloads ?? 0) + (a.stars ?? 0) * 10));
190
+ const result = {
191
+ count: pluginList.length,
192
+ updated: json.updated ?? new Date().toISOString().slice(0, 10),
193
+ categories,
194
+ plugins: pluginList,
195
+ };
196
+ // 写入缓存
197
+ try {
198
+ writeFileSync(cachePath, JSON.stringify({ ...result, savedAt: Date.now() }), "utf8");
199
+ }
200
+ catch {
201
+ /* ignore write failure */
202
+ }
203
+ return result;
204
+ }
205
+ }
206
+ catch (err) {
207
+ console.warn(`[dsh-market] 拉取远程市场失败: ${err.message},使用缓存或种子数据`);
208
+ }
209
+ // 3. 远程拉取失败时:使用过期缓存
210
+ if (existsSync(cachePath)) {
211
+ try {
212
+ const cached = JSON.parse(readFileSync(cachePath, "utf8"));
213
+ if (Array.isArray(cached.plugins)) {
214
+ return {
215
+ count: cached.count ?? cached.plugins.length,
216
+ updated: cached.updated ?? "",
217
+ categories: cached.categories ?? SEED_CATEGORIES,
218
+ plugins: cached.plugins,
219
+ };
220
+ }
221
+ }
222
+ catch {
223
+ /* ignore */
224
+ }
225
+ }
226
+ // 4. 终极回退:使用内置种子数据
227
+ return {
228
+ count: SEED_PLUGINS.length,
229
+ updated: new Date().toISOString().slice(0, 10),
230
+ categories: SEED_CATEGORIES,
231
+ plugins: SEED_PLUGINS,
232
+ };
233
+ }
@@ -39,13 +39,14 @@ export function serializeUserBlocks(blocks) {
39
39
  return { type: "text", text: String(b?.text ?? "") };
40
40
  });
41
41
  }
42
- /** 提取 DSH assistant 事件中的原始未剥离文本(供 MarkerService 解析内联标记)。 */
42
+ /** 提取 DSH assistant 事件中的原始未剥离文本(供 MarkerService 解析内联标记)。
43
+ * 同时包含正文 (text) 与思考链 (reasoning),确保模型在思考开头输出的 marker 也被捕获执行。 */
43
44
  export function extractDshAssistantRawText(data) {
44
45
  const blocks = data.message?.content;
45
46
  if (!Array.isArray(blocks))
46
47
  return "";
47
48
  return blocks
48
- .filter((b) => b?.type === "text" && typeof b.text === "string")
49
+ .filter((b) => (b?.type === "text" || b?.type === "reasoning") && typeof b.text === "string")
49
50
  .map((b) => b.text)
50
51
  .join("\n");
51
52
  }
@@ -61,7 +62,8 @@ export function serializeAssistantBlocks(blocks) {
61
62
  return { type: "text", text, truncated };
62
63
  }
63
64
  case "reasoning": {
64
- return { type: "thinking", thinking: b.text ?? "" };
65
+ const cleaned = stripMarkers(b.text ?? "");
66
+ return { type: "thinking", thinking: cleaned };
65
67
  }
66
68
  case "tool-call": {
67
69
  const args = typeof b.arguments === "string" ? b.arguments : "";
@@ -251,6 +253,12 @@ export class DshStreamAccumulator {
251
253
  else if (b.type === "text") {
252
254
  out.push({ ...b, text: stripMarkers(String(b.text ?? ""), { stripTrailingIncomplete: true }) });
253
255
  }
256
+ else if (b.type === "thinking") {
257
+ out.push({
258
+ ...b,
259
+ thinking: stripMarkers(String(b.thinking ?? ""), { stripTrailingIncomplete: true }),
260
+ });
261
+ }
254
262
  else {
255
263
  out.push(b);
256
264
  }
@@ -208,16 +208,57 @@ export function findSessionFilesForCwd(sessionRoot, cwd) {
208
208
  out.push(...findSessionFiles(d));
209
209
  return out.sort(sessionFileNewest);
210
210
  }
211
+ /**
212
+ * 判断 DSH user/message 事件是否为系统内部注入消息(不进 UI、不进标题)。
213
+ *
214
+ * 官方 DSH 核心契约(E:\deepseek-harness 官方事实源):
215
+ * 真实人类用户提问在 MessageSourceMap 中有且仅有 `source: { kind: 'user' }`!
216
+ * 其余所有 kind(runtime-context, time-context, agent-instructions, goal,
217
+ * subagent-settled, repeat-tool-reminder, session-reference, plan-mode,
218
+ * user-question-reply, user-approval-reply, system-prompt, plugin 等)
219
+ * 100% 全是系统内部注入上下文,绝对不该进入 UI 聊天气泡。
220
+ */
221
+ export function isDshInternalUserMessage(data) {
222
+ if (!data)
223
+ return false;
224
+ const src = (data.source ?? data.message?.source);
225
+ // 1. 白名单铁律:只要有 source.kind 且不是 "user",一律直接判定为系统内部注入!
226
+ if (src && typeof src.kind === "string") {
227
+ return src.kind !== "user";
228
+ }
229
+ // 2. 文本特征容错兜底(未带 source 的旧版本或外部模拟事件)
230
+ const content = (data.content ?? data.message?.content);
231
+ if (Array.isArray(content)) {
232
+ for (const b of content) {
233
+ const text = b?.text;
234
+ if (typeof text === "string" &&
235
+ (text.includes("<system-reminder>") ||
236
+ text.includes("<goal_round") ||
237
+ text.includes("<available_skills>") ||
238
+ text.includes("Current runtime context.") ||
239
+ text.includes("Current DSH file policy:") ||
240
+ text.startsWith("Current runtime context"))) {
241
+ return true;
242
+ }
243
+ }
244
+ }
245
+ return false;
246
+ }
211
247
  /** 第一个用户文本(会话标题素材)。无用户文本时回退默认标题(issue #91:lang 缺省英文)。 */
212
248
  export function firstUserText(events, lang = "en") {
213
249
  for (const ev of events) {
214
- if (ev.type === "user/message") {
250
+ if (ev.type === "user/message" && !isDshInternalUserMessage(ev.data)) {
215
251
  const blocks = ev.data?.content;
216
252
  if (Array.isArray(blocks)) {
217
253
  for (const b of blocks) {
218
254
  const bb = b;
219
255
  if (bb?.type === "text" && typeof bb.text === "string" && bb.text.trim()) {
220
- const t = bb.text.trim().replace(/\s+/g, " ");
256
+ // 过滤尾部由系统追加的文件引用/附件标记,使首条消息作为标题时纯净展示真实提问
257
+ const clean = bb.text
258
+ .replace(/\n\[(?:文件引用|File reference|上传文件|Uploaded file|图片附件|Image attachment):[\s\S]*$/u, "")
259
+ .trim()
260
+ .replace(/\s+/g, " ");
261
+ const t = clean || bb.text.trim().replace(/\s+/g, " ");
221
262
  return t.length > 30 ? `${t.slice(0, 30)}…` : t;
222
263
  }
223
264
  }
@@ -226,6 +267,25 @@ export function firstUserText(events, lang = "en") {
226
267
  }
227
268
  return pick(lang, "新对话", "New chat", "dsh.sessions.untitled");
228
269
  }
270
+ /** 从会话日志中提取显式标题(session/title 事件),若无则返回 undefined。 */
271
+ export function sessionLogTitle(events) {
272
+ for (let i = events.length - 1; i >= 0; i--) {
273
+ const ev = events[i];
274
+ if (ev.type === "session/title") {
275
+ const t = ev.data?.title;
276
+ if (typeof t === "string" &&
277
+ t.trim() &&
278
+ !t.startsWith("chat-") &&
279
+ !t.startsWith("web-") &&
280
+ !t.startsWith("fork-") &&
281
+ t !== "新对话" &&
282
+ t !== "New chat") {
283
+ return t.trim();
284
+ }
285
+ }
286
+ }
287
+ return undefined;
288
+ }
229
289
  import { assistantMessageEventToUiMessage, toolResultEventToUiMessage, userMessageEventToUiMessage, } from "./dsh-serialize.js";
230
290
  export function replayEventsToMessages(events) {
231
291
  const messages = [];
@@ -233,6 +293,8 @@ export function replayEventsToMessages(events) {
233
293
  for (const ev of events) {
234
294
  let msg = null;
235
295
  if (ev.type === "user/message") {
296
+ if (isDshInternalUserMessage(ev.data))
297
+ continue;
236
298
  msg = userMessageEventToUiMessage(ev.data);
237
299
  }
238
300
  else if (ev.type === "assistant/message") {
@@ -33,7 +33,18 @@ export function runtimeBaseCandidates() {
33
33
  const explicit = process.env.PI_WEB_DSH_RUNTIME;
34
34
  if (explicit)
35
35
  out.push(resolve(explicit));
36
- out.push(resolve(join(dirname(fileURLToPath(import.meta.url)), "..", "..", "node_modules")));
36
+ let dir = dirname(fileURLToPath(import.meta.url));
37
+ for (let i = 0; i < 5; i++) {
38
+ const nm = join(dir, "node_modules");
39
+ if (existsSync(nm)) {
40
+ out.push(resolve(nm));
41
+ break;
42
+ }
43
+ const parent = dirname(dir);
44
+ if (parent === dir)
45
+ break;
46
+ dir = parent;
47
+ }
37
48
  out.push(join(dirname(process.execPath), "node_modules"));
38
49
  try {
39
50
  const prefixes = [