pi-web-ui 0.105.1 → 0.107.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/CHANGELOG.md +84 -2
- package/README.md +193 -797
- package/README.zh-CN.md +186 -625
- package/README.zh-TW.md +781 -0
- package/bin/frp-manager.mjs +1488 -0
- package/bin/pi-web-ui.mjs +27 -0
- package/deploy/nginx-subpath.conf +16 -1
- package/dist/server/agent-service-daemon.js +34 -0
- package/dist/server/agent-service.js +259 -60
- package/dist/server/claim-files-tool.js +8 -1
- package/dist/server/client-state.js +136 -30
- package/dist/server/conversation-read-tool.js +12 -4
- package/dist/server/delegate-task.js +9 -1
- package/dist/server/dispatch-domain-handlers.js +15 -0
- package/dist/server/dsh/dsh-agent-service.js +848 -246
- package/dist/server/dsh/dsh-client.js +59 -18
- package/dist/server/dsh/dsh-market-service.js +233 -0
- package/dist/server/dsh/dsh-serialize.js +11 -3
- package/dist/server/dsh/dsh-sessions.js +64 -2
- package/dist/server/dsh/preset-clones.js +12 -1
- package/dist/server/dsh/runtime/goal-rpc.mjs +183 -45
- package/dist/server/durable/durable-agent-service.js +153 -0
- package/dist/server/durable/durable-capabilities.js +11 -0
- package/dist/server/durable/durable-driver.js +481 -0
- package/dist/server/durable/durable-loader.js +38 -0
- package/dist/server/durable/durable-models.js +283 -0
- package/dist/server/durable/durable-storage.js +42 -0
- package/dist/server/durable/durable-tools.js +45 -0
- package/dist/server/durable/index.js +8 -0
- package/dist/server/engine-capabilities.js +91 -0
- package/dist/server/engine-probe.js +391 -0
- package/dist/server/global-loader.js +335 -0
- package/dist/server/goal-service.js +23 -12
- package/dist/server/i18n.js +20 -1
- package/dist/server/index.js +286 -71
- package/dist/server/locales.js +1 -0
- package/dist/server/managed.js +2 -0
- package/dist/server/marker-service.js +5 -19
- package/dist/server/markers/index.js +1 -3
- package/dist/server/mcp-agent-tool.js +10 -7
- package/dist/server/mcp-bridge.js +428 -24
- package/dist/server/model-admin.js +172 -74
- package/dist/server/model-resolver.js +309 -0
- package/dist/server/plugin-installer.js +4 -2
- package/dist/server/plugins.js +89 -12
- package/dist/server/present-files-tool.js +10 -2
- package/dist/server/preset-fields.js +14 -0
- package/dist/server/preset-share.js +2 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/schedule-agent-tool.js +2 -1
- package/dist/server/scm-commitmsg.js +3 -2
- package/dist/server/sdk-origin.js +2 -2
- package/dist/server/serialize.js +1 -1
- package/dist/server/settings-service.js +10 -2
- package/dist/server/skill-discovery.js +161 -0
- package/dist/server/skill-tool.js +2 -1
- package/dist/server/slash-commands.js +154 -73
- package/dist/server/subagent-templates-hant.js +215 -0
- package/dist/server/subagent-templates.js +49 -2
- package/dist/server/subagents.js +22 -12
- package/dist/server/terminals.js +2 -2
- package/dist/server/tool-manager.js +6 -19
- package/dist/server/universal/driver-base.js +60 -0
- package/dist/server/universal/drivers/claude-code.js +463 -0
- package/dist/server/universal/drivers/dsh-driver.js +376 -0
- package/dist/server/universal/drivers/mock-driver.js +103 -0
- package/dist/server/universal/index.js +10 -0
- package/dist/server/universal/session-store.js +100 -0
- package/dist/server/universal/universal-attachments.js +175 -0
- package/dist/server/universal/universal-service.js +166 -0
- package/dist/server/universal/universal-session.js +2664 -0
- package/dist/server/universal/universal-types.js +4 -0
- package/dist/server/update-check.js +24 -9
- package/dist/server/worktree-service.js +1 -1
- package/dist/server/worktree-tool.js +9 -7
- package/package.json +3 -2
- package/plugin-sdk/index.d.ts +12 -2
- package/plugins/catalog.json +50 -5
- package/themes/dark-teal.css +20 -24
- package/themes/flow-light.css +1085 -0
- package/themes/flow.css +1094 -0
- package/themes/md-preview.css +1 -2
- package/themes/wallpaper-flow.css +1158 -0
- package/themes/wallpaper-obsidian.css +743 -0
- package/themes/zhujian-dark.css +0 -7
- package/themes/zhujian.css +0 -7
- package/themes/zhupi-dark.css +0 -7
- package/themes/zhupi.css +0 -7
- package/web/dist/assets/{TerminalPanel-Mk4laCAL.js → TerminalPanel-BnViyTlx.js} +2 -2
- package/web/dist/assets/index-cCRCYMwT.css +1 -0
- package/web/dist/assets/index-fH5vhkAE.js +690 -0
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-BDLVjBeK.js +0 -690
- package/web/dist/assets/index-BQC6lADz.css +0 -1
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* universal-attachments.ts — 通用底座附件构建、@ 提及扫描与技能提示注入。
|
|
3
|
+
*
|
|
4
|
+
* 职责:
|
|
5
|
+
* 1. 扫描用户提问中的 `@path`(文件引用)与 `@skill:name`(技能引用);
|
|
6
|
+
* 2. 生成符合 Web UI 标准的 custom "file" 卡片(UiMessage),供渲染折叠文件卡片、
|
|
7
|
+
* 图片预览并支持编辑重问(question-attachments.ts);
|
|
8
|
+
* 3. 格式化最终投递给各底层驱动(Claude Code、DSH 等)的 Prompt 上下文与附件列表。
|
|
9
|
+
*/
|
|
10
|
+
import { randomUUID } from "node:crypto";
|
|
11
|
+
import { existsSync, statSync } from "node:fs";
|
|
12
|
+
import { basename, isAbsolute, relative, resolve } from "node:path";
|
|
13
|
+
import { readSkillInstruction } from "../skill-discovery.js";
|
|
14
|
+
/**
|
|
15
|
+
* 扫描用户提问文本中的 `@` 词元:
|
|
16
|
+
* - `@skill:foo` 或匹配已知技能名的 `@foo`
|
|
17
|
+
* - `@path/to/file` 在当前工作区存在的相对路径
|
|
18
|
+
*/
|
|
19
|
+
export function scanAtMentions(text, cwd, availableSkills = [], existingAttachments = []) {
|
|
20
|
+
const detectedAttachments = [];
|
|
21
|
+
const detectedSkills = [];
|
|
22
|
+
const existingPaths = new Set(existingAttachments.map((a) => a.path).filter(Boolean));
|
|
23
|
+
// 1. 扫描 @skill:xxx 引用
|
|
24
|
+
const skillRegex = /@skill:([A-Za-z0-9_-]+)/g;
|
|
25
|
+
let sm;
|
|
26
|
+
const matchedSkillNames = new Set();
|
|
27
|
+
while ((sm = skillRegex.exec(text)) !== null) {
|
|
28
|
+
matchedSkillNames.add(sm[1].toLowerCase());
|
|
29
|
+
}
|
|
30
|
+
for (const sk of availableSkills) {
|
|
31
|
+
const bareName = sk.name.startsWith("skill:") ? sk.name.slice(6) : sk.name;
|
|
32
|
+
if (matchedSkillNames.has(bareName.toLowerCase()) || matchedSkillNames.has(sk.name.toLowerCase())) {
|
|
33
|
+
detectedSkills.push(sk);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// 2. 扫描 @path/to/file 引用(避开邮箱格式,例如 a@b.com)
|
|
37
|
+
const pathRegex = /(?:^|\s)@([^\s@:"'<>|?*]+)/g;
|
|
38
|
+
let pm;
|
|
39
|
+
const root = resolve(cwd);
|
|
40
|
+
while ((pm = pathRegex.exec(text)) !== null) {
|
|
41
|
+
const rawCandidate = pm[1].trim();
|
|
42
|
+
if (!rawCandidate || rawCandidate.startsWith("skill:"))
|
|
43
|
+
continue;
|
|
44
|
+
// 规范化相对路径
|
|
45
|
+
const candidate = rawCandidate.replace(/^[/\\]+/, "");
|
|
46
|
+
const absPath = isAbsolute(rawCandidate) ? rawCandidate : resolve(root, candidate);
|
|
47
|
+
// 防止跳出项目根目录或不存在的文件
|
|
48
|
+
if (existsSync(absPath)) {
|
|
49
|
+
try {
|
|
50
|
+
const rel = relative(root, absPath).replace(/\\/g, "/");
|
|
51
|
+
if (!existingPaths.has(rel) && !existingPaths.has(rawCandidate)) {
|
|
52
|
+
existingPaths.add(rel);
|
|
53
|
+
detectedAttachments.push({
|
|
54
|
+
path: rel,
|
|
55
|
+
name: basename(absPath),
|
|
56
|
+
mode: "reference",
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
/* ignore fs error */
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return { detectedAttachments, detectedSkills };
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 将用户携带的附件列表转为 UiMessage 卡片消息(以便持久化及前端渲染与复原)。
|
|
69
|
+
*/
|
|
70
|
+
export function createAttachmentUiMessages(attachments, timestamp = Date.now()) {
|
|
71
|
+
const out = [];
|
|
72
|
+
for (const att of attachments) {
|
|
73
|
+
const cardId = `u-att-${timestamp}-${randomUUID().slice(0, 6)}`;
|
|
74
|
+
// 1. 图片附件
|
|
75
|
+
if (att.imageData) {
|
|
76
|
+
const dataUrl = att.imageData.startsWith("data:")
|
|
77
|
+
? att.imageData
|
|
78
|
+
: `data:${att.mimeType || "image/png"};base64,${att.imageData}`;
|
|
79
|
+
out.push({
|
|
80
|
+
id: cardId,
|
|
81
|
+
role: "custom",
|
|
82
|
+
customType: "file",
|
|
83
|
+
timestamp,
|
|
84
|
+
content: [{ type: "image", dataUrl }],
|
|
85
|
+
details: {
|
|
86
|
+
name: att.name || "image.png",
|
|
87
|
+
mode: "reference",
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
// 2. 引述文本
|
|
93
|
+
if (att.mode === "quote" && att.quote) {
|
|
94
|
+
out.push({
|
|
95
|
+
id: cardId,
|
|
96
|
+
role: "custom",
|
|
97
|
+
customType: "file",
|
|
98
|
+
timestamp,
|
|
99
|
+
content: [{ type: "text", text: att.quote.text }],
|
|
100
|
+
details: {
|
|
101
|
+
mode: "quote",
|
|
102
|
+
quote: att.quote,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
// 3. 授权网页
|
|
108
|
+
if (att.mode === "page") {
|
|
109
|
+
out.push({
|
|
110
|
+
id: cardId,
|
|
111
|
+
role: "custom",
|
|
112
|
+
customType: "file",
|
|
113
|
+
timestamp,
|
|
114
|
+
content: [{ type: "text", text: `<browser-page url="${att.path}" title="${att.name || att.path}" />` }],
|
|
115
|
+
details: {
|
|
116
|
+
name: att.name || att.path,
|
|
117
|
+
path: att.path,
|
|
118
|
+
mode: "page",
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
// 4. 工作区文件/目录/行范围
|
|
124
|
+
if (att.path) {
|
|
125
|
+
const isLines = att.mode === "lines" && att.lines;
|
|
126
|
+
let isDir = false;
|
|
127
|
+
try {
|
|
128
|
+
if (existsSync(att.path)) {
|
|
129
|
+
isDir = statSync(att.path).isDirectory();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
/* ignore */
|
|
134
|
+
}
|
|
135
|
+
const text = isLines
|
|
136
|
+
? `<file path="${att.path}" lines="${att.lines.start}-${att.lines.end}" />`
|
|
137
|
+
: isDir
|
|
138
|
+
? `<folder path="${att.path}" />`
|
|
139
|
+
: `<file path="${att.path}" />`;
|
|
140
|
+
out.push({
|
|
141
|
+
id: cardId,
|
|
142
|
+
role: "custom",
|
|
143
|
+
customType: "file",
|
|
144
|
+
timestamp,
|
|
145
|
+
content: [{ type: "text", text }],
|
|
146
|
+
details: {
|
|
147
|
+
name: att.name || basename(att.path),
|
|
148
|
+
path: att.path,
|
|
149
|
+
mode: isLines ? "lines" : "reference",
|
|
150
|
+
isDir,
|
|
151
|
+
...(isLines ? { startLine: att.lines.start, endLine: att.lines.end } : {}),
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return out;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* 组装最终送入底座驱动的 Prompt 上下文与综合附件。
|
|
160
|
+
*/
|
|
161
|
+
export function formatPromptWithSkills(rawPrompt, skills) {
|
|
162
|
+
if (!skills || skills.length === 0)
|
|
163
|
+
return rawPrompt;
|
|
164
|
+
const skillSnippets = [];
|
|
165
|
+
for (const sk of skills) {
|
|
166
|
+
const body = readSkillInstruction(sk.filePath);
|
|
167
|
+
if (body) {
|
|
168
|
+
const title = sk.name.startsWith("skill:") ? sk.name.slice(6) : sk.name;
|
|
169
|
+
skillSnippets.push(`[Skill: ${title}]\n${body}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (skillSnippets.length === 0)
|
|
173
|
+
return rawPrompt;
|
|
174
|
+
return `${skillSnippets.join("\n\n")}\n\n[User Prompt]\n${rawPrompt}`;
|
|
175
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* universal-service.ts — 通用 Agent 引擎服务(实现 EngineService)。
|
|
3
|
+
*
|
|
4
|
+
* 职责:
|
|
5
|
+
* 1. 接入 index.ts 的全局引擎分发层;
|
|
6
|
+
* 2. 管理各浏览器客户端(clientId)的 UniversalSession 实例;
|
|
7
|
+
* 3. 负责安静停机(quiesce)、状态汇总(serviceStatus)与生命周期销毁。
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync } from "node:fs";
|
|
10
|
+
import { UniversalSessionStore } from "./session-store.js";
|
|
11
|
+
import { UniversalSession } from "./universal-session.js";
|
|
12
|
+
import { MockAgentDriver } from "./drivers/mock-driver.js";
|
|
13
|
+
import { DEFAULT_UNIVERSAL_CAPABILITIES } from "../engine-capabilities.js";
|
|
14
|
+
import { getAppVersion } from "../pkg-info.js";
|
|
15
|
+
export class UniversalAgentService {
|
|
16
|
+
cwd;
|
|
17
|
+
dataDir;
|
|
18
|
+
store;
|
|
19
|
+
stateStore;
|
|
20
|
+
driverFactory;
|
|
21
|
+
sessions = new Map();
|
|
22
|
+
agentDir;
|
|
23
|
+
engine;
|
|
24
|
+
quiesced = false;
|
|
25
|
+
quiescedSince;
|
|
26
|
+
socketCount = 0;
|
|
27
|
+
pluginCommandsProvider;
|
|
28
|
+
onQuit;
|
|
29
|
+
constructor(opts) {
|
|
30
|
+
this.cwd = opts.cwd;
|
|
31
|
+
this.dataDir = opts.dataDir;
|
|
32
|
+
this.agentDir = opts.agentDir;
|
|
33
|
+
this.engine = opts.engine ?? "claude";
|
|
34
|
+
this.store = new UniversalSessionStore(opts.dataDir);
|
|
35
|
+
this.stateStore = opts.stateStore;
|
|
36
|
+
// 默认使用 MockDriver;接入 Claude Code 时可替换
|
|
37
|
+
this.driverFactory = opts.driverFactory ?? ((cwd) => new MockAgentDriver(cwd));
|
|
38
|
+
}
|
|
39
|
+
async attach(clientId, send) {
|
|
40
|
+
let session = this.sessions.get(clientId);
|
|
41
|
+
if (!session) {
|
|
42
|
+
let effectiveCwd = this.cwd;
|
|
43
|
+
const saved = this.stateStore?.get(clientId);
|
|
44
|
+
if (saved?.lastCwd && saved.lastCwd !== this.cwd) {
|
|
45
|
+
try {
|
|
46
|
+
if (existsSync(saved.lastCwd)) {
|
|
47
|
+
effectiveCwd = saved.lastCwd;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
/* fallback */
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (typeof this.stateStore?.remember === "function") {
|
|
55
|
+
this.stateStore.remember(clientId, effectiveCwd);
|
|
56
|
+
}
|
|
57
|
+
const driver = this.driverFactory(effectiveCwd);
|
|
58
|
+
session = new UniversalSession({
|
|
59
|
+
clientId,
|
|
60
|
+
cwd: effectiveCwd,
|
|
61
|
+
dataDir: this.dataDir,
|
|
62
|
+
agentDir: this.agentDir,
|
|
63
|
+
send,
|
|
64
|
+
store: this.store,
|
|
65
|
+
stateStore: this.stateStore,
|
|
66
|
+
driver,
|
|
67
|
+
driverFactory: this.driverFactory,
|
|
68
|
+
engine: this.engine,
|
|
69
|
+
pluginCommandsProvider: () => this.pluginCommandsProvider?.() ?? [],
|
|
70
|
+
onQuit: () => this.onQuit?.() ?? false,
|
|
71
|
+
});
|
|
72
|
+
this.sessions.set(clientId, session);
|
|
73
|
+
session.attachSink(send);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
session.attachSink(send);
|
|
77
|
+
}
|
|
78
|
+
return session;
|
|
79
|
+
}
|
|
80
|
+
detach(clientId, send) {
|
|
81
|
+
const session = this.sessions.get(clientId);
|
|
82
|
+
if (session) {
|
|
83
|
+
if (send) {
|
|
84
|
+
session.detachSink(send);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
session.dispose();
|
|
88
|
+
this.sessions.delete(clientId);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
get(clientId) {
|
|
93
|
+
return this.sessions.get(clientId);
|
|
94
|
+
}
|
|
95
|
+
async disposeAll() {
|
|
96
|
+
for (const session of this.sessions.values()) {
|
|
97
|
+
session.dispose();
|
|
98
|
+
}
|
|
99
|
+
this.sessions.clear();
|
|
100
|
+
}
|
|
101
|
+
recordInterruptedRuns() {
|
|
102
|
+
/* 通用底座基于线性落盘,重启后直接回放 JSON */
|
|
103
|
+
}
|
|
104
|
+
noteSocketOpen() {
|
|
105
|
+
this.socketCount++;
|
|
106
|
+
}
|
|
107
|
+
noteSocketClose() {
|
|
108
|
+
this.socketCount = Math.max(0, this.socketCount - 1);
|
|
109
|
+
}
|
|
110
|
+
isQuiesced() {
|
|
111
|
+
return this.quiesced;
|
|
112
|
+
}
|
|
113
|
+
quiesce() {
|
|
114
|
+
this.quiesced = true;
|
|
115
|
+
this.quiescedSince = Date.now();
|
|
116
|
+
}
|
|
117
|
+
unquiesce() {
|
|
118
|
+
this.quiesced = false;
|
|
119
|
+
this.quiescedSince = undefined;
|
|
120
|
+
}
|
|
121
|
+
quiesceInfo() {
|
|
122
|
+
return { quiesced: this.quiesced, quiescedSince: this.quiescedSince };
|
|
123
|
+
}
|
|
124
|
+
serviceStatus() {
|
|
125
|
+
return {
|
|
126
|
+
pid: process.pid,
|
|
127
|
+
version: getAppVersion(),
|
|
128
|
+
cwd: this.cwd,
|
|
129
|
+
quiesced: this.quiesced,
|
|
130
|
+
quiescedSince: this.quiescedSince,
|
|
131
|
+
connectedClients: this.socketCount,
|
|
132
|
+
activeConversations: this.activeConversations(),
|
|
133
|
+
pendingMessages: this.pendingMessages(),
|
|
134
|
+
service: null,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
activeConversations() {
|
|
138
|
+
let count = 0;
|
|
139
|
+
for (const s of this.sessions.values()) {
|
|
140
|
+
count += s.activeConversations();
|
|
141
|
+
}
|
|
142
|
+
return count;
|
|
143
|
+
}
|
|
144
|
+
pendingMessages() {
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
147
|
+
applyPluginAgentTools() {
|
|
148
|
+
/* no-op */
|
|
149
|
+
}
|
|
150
|
+
applyPluginCommandCatalog() {
|
|
151
|
+
/* no-op */
|
|
152
|
+
}
|
|
153
|
+
refreshBackgroundServers() {
|
|
154
|
+
/* no-op */
|
|
155
|
+
}
|
|
156
|
+
async setLocale(clientId, locale) {
|
|
157
|
+
const session = this.sessions.get(clientId);
|
|
158
|
+
if (session) {
|
|
159
|
+
await session.setLocale(locale);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
getCapabilities() {
|
|
163
|
+
const first = this.sessions.values().next().value;
|
|
164
|
+
return first ? first.getCapabilities() : DEFAULT_UNIVERSAL_CAPABILITIES;
|
|
165
|
+
}
|
|
166
|
+
}
|