pi-web-ui 0.109.0 → 0.110.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 +31 -0
- package/README.md +21 -1
- package/README.zh-CN.md +21 -1
- package/README.zh-TW.md +201 -677
- package/dist/server/agent-service-daemon.js +2 -2
- package/dist/server/agent-service.js +20 -30
- package/dist/server/attachments.js +26 -6
- package/dist/server/dispatch-domain-handlers.js +2 -0
- package/dist/server/dispatch-plugin-handlers.js +1 -0
- package/dist/server/durable/durable-driver.js +1 -1
- package/dist/server/durable/durable-tools.js +4 -1
- package/dist/server/files-service.js +23 -4
- package/dist/server/goal-service.js +12 -3
- package/dist/server/index.js +39 -10
- package/dist/server/locales.js +33 -0
- package/dist/server/marker-service.js +7 -13
- package/dist/server/markers/builtins/action.js +5 -6
- package/dist/server/markers/builtins/notify.js +2 -2
- package/dist/server/markers/builtins/rename.js +2 -2
- package/dist/server/markers/registry.js +5 -1
- package/dist/server/message-window.js +190 -0
- package/dist/server/model-admin.js +0 -4
- package/dist/server/plugin-catalog-sync.js +10 -2
- package/dist/server/plugin-catalog.js +63 -10
- package/dist/server/plugins.js +47 -6
- package/dist/server/preset-share.js +2 -3
- package/dist/server/process-utils.js +58 -24
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/settings-service.js +5 -0
- package/dist/server/slash-commands.js +16 -4
- package/dist/server/text-sniff.js +10 -7
- package/dist/server/themes.js +36 -1
- package/dist/server/universal/drivers/dsh-driver.js +1 -1
- package/dist/server/universal/universal-session.js +10 -3
- package/dist/server/worktree-service.js +1 -1
- package/package.json +7 -2
- package/plugin-sdk/index.d.ts +20 -0
- package/plugin-sdk/index.mjs +14 -0
- package/plugins/catalog.json +22 -2
- package/themes/aetheris.css +149 -118
- package/themes/bases/flow-base.css +1363 -0
- package/themes/bases/obsidian-base.css +679 -0
- package/themes/bases/zhujian-base.css +687 -0
- package/themes/bases/zhupi-base.css +659 -0
- package/themes/flow-light.css +2 -925
- package/themes/flow.css +1 -936
- package/themes/wallpaper-flow.css +71 -1031
- package/themes/wallpaper-obsidian.css +1 -673
- package/themes/zhujian-dark.css +1 -605
- package/themes/zhujian.css +1 -654
- package/themes/zhupi-dark.css +1 -576
- package/themes/zhupi.css +1 -626
- package/web/dist/assets/{TerminalPanel-BD3a9o-a.js → TerminalPanel-BHjM6pzY.js} +1 -1
- package/web/dist/assets/index-DwInT7-a.css +1 -0
- package/web/dist/assets/index-GfVFIgIL.js +693 -0
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-AccytlpP.css +0 -1
- package/web/dist/assets/index-B3dar1BK.js +0 -690
|
@@ -14,9 +14,13 @@ export function allMarkers() {
|
|
|
14
14
|
export function collectGuidance(disabled = new Set(), lang = "en") {
|
|
15
15
|
const out = [];
|
|
16
16
|
for (const m of allMarkers()) {
|
|
17
|
+
if (m.isAlias)
|
|
18
|
+
continue;
|
|
17
19
|
if (disabled.has(m.name))
|
|
18
20
|
continue;
|
|
19
|
-
|
|
21
|
+
const lines = m.getGuidance?.(lang) ?? m.guidance;
|
|
22
|
+
if (lines && lines.length > 0)
|
|
23
|
+
out.push(...lines);
|
|
20
24
|
}
|
|
21
25
|
return out;
|
|
22
26
|
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/** 尾部窗口条数(缺省 300 条)。 */
|
|
2
|
+
export const DEFAULT_HISTORY_WINDOW = 300;
|
|
3
|
+
/** 尾部窗口字符预算(缺省 150 万字符 ≈ 3MB JSON)。
|
|
4
|
+
*
|
|
5
|
+
* 只按条数裁不够用:一条巨型 tool 输出就能把几十条普通消息顶下去——实测一份
|
|
6
|
+
* 287 条、17MB 的转录序列化后仍有 4MB,按条数(300)根本裁不动。所以从尾部
|
|
7
|
+
* 往前累加**字符长度**(只读每个字符串的 `.length`,O(block 数),不展开内容),超预算即停。
|
|
8
|
+
*/
|
|
9
|
+
export const DEFAULT_HISTORY_CHARS = 1_500_000;
|
|
10
|
+
/** 「加载更早」单页条数。 */
|
|
11
|
+
export const DEFAULT_HISTORY_PAGE = 30;
|
|
12
|
+
/** 单次翻页上限,防止一条消息把几千条历史一次拉下来。 */
|
|
13
|
+
const MAX_PAGE = 2000;
|
|
14
|
+
/** 最多为几个对话保留全量缓存(LRU)—— 引用的是引擎已序列化好的对象,只有指针开销。 */
|
|
15
|
+
const MAX_CACHED_CONVERSATIONS = 4;
|
|
16
|
+
const OFF_CONFIG = { windowSize: 0, charBudget: 0, pageSize: DEFAULT_HISTORY_PAGE };
|
|
17
|
+
const DEFAULT_CONFIG = {
|
|
18
|
+
windowSize: DEFAULT_HISTORY_WINDOW,
|
|
19
|
+
charBudget: DEFAULT_HISTORY_CHARS,
|
|
20
|
+
pageSize: DEFAULT_HISTORY_PAGE,
|
|
21
|
+
};
|
|
22
|
+
/** 从环境变量读窗口配置:`PI_WEB_HISTORY_WINDOW`(条数;0/off/false/no = 关闭)。 */
|
|
23
|
+
export function readMessageWindowConfig(env) {
|
|
24
|
+
const raw = (env.PI_WEB_HISTORY_WINDOW ?? "").trim().toLowerCase();
|
|
25
|
+
if (raw === "0" || raw === "off" || raw === "false" || raw === "no")
|
|
26
|
+
return OFF_CONFIG;
|
|
27
|
+
if (raw === "")
|
|
28
|
+
return DEFAULT_CONFIG;
|
|
29
|
+
const n = Number(raw);
|
|
30
|
+
if (!Number.isFinite(n) || n <= 0)
|
|
31
|
+
return DEFAULT_CONFIG;
|
|
32
|
+
return { ...DEFAULT_CONFIG, windowSize: Math.floor(n) };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 本轮窗口起点(纯函数,便于单测)。
|
|
36
|
+
*
|
|
37
|
+
* `prevStart` 是上一次下发的起点(新对话传 -1)。起点只允许**单调不增**:
|
|
38
|
+
* 客户端可能已经往前翻过几页,若某次全量快照把起点推回去(比如先 200 后 400),
|
|
39
|
+
* 客户端会凭空丢掉已经看过的历史。消息总数变少(压缩重写)时以尾部窗口为准。
|
|
40
|
+
*/
|
|
41
|
+
export function computeWindowStart(prevStart, total, windowSize) {
|
|
42
|
+
if (windowSize <= 0)
|
|
43
|
+
return 0;
|
|
44
|
+
const tail = Math.max(0, total - windowSize);
|
|
45
|
+
if (prevStart < 0)
|
|
46
|
+
return tail;
|
|
47
|
+
return Math.min(prevStart, tail);
|
|
48
|
+
}
|
|
49
|
+
/** 单条消息的字符量估算:只累加各文本字段的 `.length`(每条 O(block 数),不展开内容)。 */
|
|
50
|
+
export function estimateMessageChars(m) {
|
|
51
|
+
let n = 0;
|
|
52
|
+
const content = m.content;
|
|
53
|
+
if (Array.isArray(content)) {
|
|
54
|
+
for (const b of content) {
|
|
55
|
+
// dataUrl:截图类 toolResult 是真正的重量级(实测一份长会话的 4MB JSON 里
|
|
56
|
+
// 3.4MB 全来自三张整页截图),漏掉它字符预算就形同虚设。
|
|
57
|
+
for (const k of ["text", "thinking", "argumentsText", "output", "command", "dataUrl", "summary"]) {
|
|
58
|
+
const v = b[k];
|
|
59
|
+
if (typeof v === "string")
|
|
60
|
+
n += v.length;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const summary = m.summary;
|
|
65
|
+
if (typeof summary === "string")
|
|
66
|
+
n += summary.length;
|
|
67
|
+
return n;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 首次计算窗口起点:条数上限与字符预算取**更严**的那个,且至少保留最后一条消息。
|
|
71
|
+
* `windowSize <= 0` 时返回 0(窗口化关闭)。
|
|
72
|
+
*/
|
|
73
|
+
export function pickWindowStart(messages, cfg) {
|
|
74
|
+
const total = messages.length;
|
|
75
|
+
if (cfg.windowSize <= 0)
|
|
76
|
+
return 0;
|
|
77
|
+
const byCount = Math.max(0, total - cfg.windowSize);
|
|
78
|
+
if (cfg.charBudget <= 0)
|
|
79
|
+
return byCount;
|
|
80
|
+
let chars = 0;
|
|
81
|
+
let i = total - 1;
|
|
82
|
+
for (; i >= byCount; i--) {
|
|
83
|
+
chars += estimateMessageChars(messages[i]);
|
|
84
|
+
if (chars > cfg.charBudget)
|
|
85
|
+
return Math.min(total - 1, i + 1);
|
|
86
|
+
}
|
|
87
|
+
return byCount;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 连接级历史窗口。每个 socket(= 每个标签页)一份,`accept()` 包在 send 之前,
|
|
91
|
+
* `loadEarlier()` 由 WS 分发层直接调用。
|
|
92
|
+
*/
|
|
93
|
+
export class MessageWindowTap {
|
|
94
|
+
send;
|
|
95
|
+
cfg;
|
|
96
|
+
convs = new Map();
|
|
97
|
+
/** 最近一次快照所属的对话 —— `load_earlier_messages` 不带 id,按「当前对话」服务。 */
|
|
98
|
+
lastConversationId = "";
|
|
99
|
+
constructor(send, cfg) {
|
|
100
|
+
this.send = send;
|
|
101
|
+
this.cfg = cfg;
|
|
102
|
+
}
|
|
103
|
+
get enabled() {
|
|
104
|
+
return this.cfg.windowSize > 0;
|
|
105
|
+
}
|
|
106
|
+
/** 引擎消息入口:窗口化 snapshot/delta,其余原样透传。 */
|
|
107
|
+
accept(msg) {
|
|
108
|
+
if (!this.enabled) {
|
|
109
|
+
this.send(msg);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (msg.type === "snapshot") {
|
|
113
|
+
const state = msg.state;
|
|
114
|
+
const full = state.messages;
|
|
115
|
+
const entry = this.entry(state.conversationId);
|
|
116
|
+
entry.full = full;
|
|
117
|
+
// 首次按「条数 + 字符预算」算;之后只允许单调不增(已翻过的页不能被全量快照推回去)。
|
|
118
|
+
entry.start =
|
|
119
|
+
entry.start < 0
|
|
120
|
+
? pickWindowStart(full, this.cfg)
|
|
121
|
+
: computeWindowStart(entry.start, full.length, this.cfg.windowSize);
|
|
122
|
+
this.lastConversationId = state.conversationId;
|
|
123
|
+
this.send({
|
|
124
|
+
...msg,
|
|
125
|
+
state: {
|
|
126
|
+
...state,
|
|
127
|
+
messages: entry.start > 0 ? full.slice(entry.start) : full,
|
|
128
|
+
historyStart: entry.start,
|
|
129
|
+
historyTotal: full.length,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (msg.type === "snapshot_delta") {
|
|
135
|
+
const entry = this.convs.get(msg.conversationId);
|
|
136
|
+
if (!entry) {
|
|
137
|
+
// 没见过完整基线(重连后先来增量):原样透传,客户端会凭 rev 缺口自愈。
|
|
138
|
+
this.send(msg);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (msg.appended.length > 0) {
|
|
142
|
+
entry.full = entry.full.concat(msg.appended);
|
|
143
|
+
}
|
|
144
|
+
this.lastConversationId = msg.conversationId;
|
|
145
|
+
this.send({
|
|
146
|
+
...msg,
|
|
147
|
+
state: { ...msg.state, historyStart: entry.start, historyTotal: entry.full.length },
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
this.send(msg);
|
|
152
|
+
}
|
|
153
|
+
/** 客户端往上翻页:把窗口起点往前扩 `count` 条(`all` = 一路拉到最早)。 */
|
|
154
|
+
loadEarlier(count, all) {
|
|
155
|
+
const convId = this.lastConversationId;
|
|
156
|
+
const entry = convId ? this.convs.get(convId) : undefined;
|
|
157
|
+
if (!entry || !convId)
|
|
158
|
+
return;
|
|
159
|
+
const total = entry.full.length;
|
|
160
|
+
const page = all ? entry.start : Math.min(MAX_PAGE, Math.max(1, Math.floor(count ?? this.cfg.pageSize) || 1));
|
|
161
|
+
const start = all ? 0 : Math.max(0, entry.start - page);
|
|
162
|
+
const messages = start < entry.start ? entry.full.slice(start, entry.start) : [];
|
|
163
|
+
entry.start = start;
|
|
164
|
+
this.send({
|
|
165
|
+
type: "earlier_messages",
|
|
166
|
+
conversationId: convId,
|
|
167
|
+
messages,
|
|
168
|
+
historyStart: start,
|
|
169
|
+
historyTotal: total,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/** 取(或建)对话窗口;LRU 超限时淘汰最久未用的那个。 */
|
|
173
|
+
entry(convId) {
|
|
174
|
+
const hit = this.convs.get(convId);
|
|
175
|
+
if (hit) {
|
|
176
|
+
this.convs.delete(convId);
|
|
177
|
+
this.convs.set(convId, hit);
|
|
178
|
+
return hit;
|
|
179
|
+
}
|
|
180
|
+
const created = { full: [], start: -1 };
|
|
181
|
+
this.convs.set(convId, created);
|
|
182
|
+
while (this.convs.size > MAX_CACHED_CONVERSATIONS) {
|
|
183
|
+
const oldest = this.convs.keys().next();
|
|
184
|
+
if (oldest.done)
|
|
185
|
+
break;
|
|
186
|
+
this.convs.delete(oldest.value);
|
|
187
|
+
}
|
|
188
|
+
return created;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -66,10 +66,6 @@ export function graduateOverlayModels(providers, official) {
|
|
|
66
66
|
}
|
|
67
67
|
return graduated;
|
|
68
68
|
}
|
|
69
|
-
/** 原子写 JSON(tmp + rename):进程崩溃不留半截文件。 */
|
|
70
|
-
function atomicWriteJson(path, data) {
|
|
71
|
-
writeJsonAtomicSync(path, data);
|
|
72
|
-
}
|
|
73
69
|
/** 原子写凭据 JSON 并修权限 0600(port from fork 50e723f,保留上游原子写语义)。
|
|
74
70
|
* chmod 覆盖已存在文件(mode 选项只对新建有效)。Windows 下尽力而为。 */
|
|
75
71
|
function atomicWriteCredentialJson(path, data) {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import { existsSync, readFileSync } from "node:fs";
|
|
20
20
|
import { join } from "node:path";
|
|
21
21
|
import { pick } from "./i18n.js";
|
|
22
|
-
import { normalizeSyncPayload, writeCustomCatalog } from "./plugin-catalog.js";
|
|
22
|
+
import { normalizeSyncPayload, writeCustomCatalog, writeCommunityCatalog } from "./plugin-catalog.js";
|
|
23
23
|
import { workspacePath } from "./files-service.js";
|
|
24
24
|
/**
|
|
25
25
|
* 读同步文档:`http(s)://` 走网络,其余当本地文件路径 —— **只允许工作区内的路径**
|
|
@@ -110,7 +110,15 @@ export async function syncPluginCatalog(source, opts, deps) {
|
|
|
110
110
|
if ("error" in payload)
|
|
111
111
|
return { ok: false, error: payload.error };
|
|
112
112
|
// 到这里才动磁盘:校验失败的文档绝不覆盖一份有效目录。
|
|
113
|
-
|
|
113
|
+
const isCommunity = opts.target === "community" ||
|
|
114
|
+
(Boolean(deps.communityCatalogPath) &&
|
|
115
|
+
(source.includes("pi-web-ui-plugins/catalog.json") || source.endsWith("/community-catalog.json")));
|
|
116
|
+
if (isCommunity && deps.communityCatalogPath) {
|
|
117
|
+
writeCommunityCatalog(deps.communityCatalogPath, payload.entries);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
writeCustomCatalog(deps.customCatalogPath, payload.entries, opts.replace === true);
|
|
121
|
+
}
|
|
114
122
|
await deps.afterWrite();
|
|
115
123
|
let installed;
|
|
116
124
|
if (opts.install === true && payload.entries.length) {
|
|
@@ -64,7 +64,9 @@ function atomicWrite(path, data) {
|
|
|
64
64
|
writeJsonAtomicSync(path, data);
|
|
65
65
|
}
|
|
66
66
|
/** 把任意对象规范化为合法条目;非法则返回 null。 */
|
|
67
|
-
function toEntry(raw,
|
|
67
|
+
function toEntry(raw, originOrBuiltin) {
|
|
68
|
+
const origin = typeof originOrBuiltin === "boolean" ? (originOrBuiltin ? "builtin" : "custom") : originOrBuiltin;
|
|
69
|
+
const builtin = origin === "builtin";
|
|
68
70
|
const source = typeof raw.source === "string" ? raw.source.trim() : "";
|
|
69
71
|
if (!isValidSource(source))
|
|
70
72
|
return null;
|
|
@@ -83,6 +85,7 @@ function toEntry(raw, builtin) {
|
|
|
83
85
|
name,
|
|
84
86
|
source,
|
|
85
87
|
builtin,
|
|
88
|
+
origin,
|
|
86
89
|
...(nameEn ? { nameEn } : {}),
|
|
87
90
|
...(description ? { description } : {}),
|
|
88
91
|
...(descriptionEn ? { descriptionEn } : {}),
|
|
@@ -91,38 +94,70 @@ function toEntry(raw, builtin) {
|
|
|
91
94
|
...(homepage ? { homepage } : {}),
|
|
92
95
|
};
|
|
93
96
|
}
|
|
94
|
-
/** 读合并后的目录:
|
|
97
|
+
/** 读合并后的目录:
|
|
98
|
+
* 1. builtin : 项目随包内置核心插件(不可移除);
|
|
99
|
+
* 2. community : 官方社区生态清单(pi-web-ui-plugins 自动化审核构建,不可移除);
|
|
100
|
+
* 3. custom : 用户在设置面板手动填写的自定义条目(同 id 可覆盖 builtin/community,支持单独移除)。
|
|
95
101
|
* custom 覆盖 builtin 时强制打 `overridesBuiltin: true` 标记(builtin 同时为
|
|
96
|
-
* false
|
|
97
|
-
|
|
98
|
-
* 不允许伪装成官方来源。 */
|
|
99
|
-
export function readCatalog(builtinPath, customPath) {
|
|
102
|
+
* false):显示字段来自用户可写来源,前端据此把它标识为「自定义覆盖」。 */
|
|
103
|
+
export function readCatalog(builtinPath, customPath, communityPath) {
|
|
100
104
|
const out = [];
|
|
105
|
+
const seenBuiltin = new Set();
|
|
101
106
|
const seen = new Set();
|
|
107
|
+
// 1. 内置核心插件
|
|
102
108
|
if (existsSync(builtinPath)) {
|
|
103
109
|
const raw = readJsonSafe(builtinPath, []);
|
|
104
110
|
if (Array.isArray(raw)) {
|
|
105
111
|
for (const it of raw) {
|
|
106
|
-
const e = it && typeof it === "object" ? toEntry(it,
|
|
112
|
+
const e = it && typeof it === "object" ? toEntry(it, "builtin") : null;
|
|
107
113
|
if (e && !seen.has(e.id)) {
|
|
114
|
+
seenBuiltin.add(e.id);
|
|
108
115
|
seen.add(e.id);
|
|
109
116
|
out.push(e);
|
|
110
117
|
}
|
|
111
118
|
}
|
|
112
119
|
}
|
|
113
120
|
}
|
|
121
|
+
// 2. 官方社区生态插件(若存在)
|
|
122
|
+
if (communityPath && existsSync(communityPath)) {
|
|
123
|
+
const rawCommunity = readJsonSafe(communityPath, []);
|
|
124
|
+
const list = Array.isArray(rawCommunity)
|
|
125
|
+
? rawCommunity
|
|
126
|
+
: rawCommunity &&
|
|
127
|
+
typeof rawCommunity === "object" &&
|
|
128
|
+
Array.isArray(rawCommunity.entries)
|
|
129
|
+
? rawCommunity.entries
|
|
130
|
+
: [];
|
|
131
|
+
for (const it of list) {
|
|
132
|
+
const e = it && typeof it === "object" ? toEntry(it, "community") : null;
|
|
133
|
+
if (!e)
|
|
134
|
+
continue;
|
|
135
|
+
// 内置插件绝对优先,不被社区同名条目替换
|
|
136
|
+
if (seenBuiltin.has(e.id))
|
|
137
|
+
continue;
|
|
138
|
+
const idx = out.findIndex((x) => x.id === e.id);
|
|
139
|
+
if (idx >= 0) {
|
|
140
|
+
out[idx] = e;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
out.push(e);
|
|
144
|
+
}
|
|
145
|
+
seen.add(e.id);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// 3. 用户在设置面板手动添加的自定义条目
|
|
114
149
|
const rawCustom = readJsonSafe(customPath, {});
|
|
115
150
|
const list = rawCustom && typeof rawCustom === "object" && Array.isArray(rawCustom.entries)
|
|
116
151
|
? rawCustom.entries
|
|
117
152
|
: [];
|
|
118
153
|
for (const it of list) {
|
|
119
|
-
const e = it && typeof it === "object" ? toEntry(it,
|
|
154
|
+
const e = it && typeof it === "object" ? toEntry(it, "custom") : null;
|
|
120
155
|
if (!e)
|
|
121
156
|
continue;
|
|
122
157
|
const idx = out.findIndex((x) => x.id === e.id);
|
|
123
158
|
if (idx >= 0) {
|
|
124
|
-
// 覆盖了同名 builtin 条目:强制带标识(不信任 custom 文件里的任何自标字段)。
|
|
125
|
-
out[idx] = { ...e, builtin: false, overridesBuiltin:
|
|
159
|
+
// 覆盖了同名 builtin/community 条目:强制带标识(不信任 custom 文件里的任何自标字段)。
|
|
160
|
+
out[idx] = { ...e, builtin: false, origin: "custom", overridesBuiltin: seenBuiltin.has(e.id) };
|
|
126
161
|
}
|
|
127
162
|
else {
|
|
128
163
|
out.push(e);
|
|
@@ -240,3 +275,21 @@ export function writeCustomCatalog(customPath, incoming, replace) {
|
|
|
240
275
|
atomicWrite(customPath, { entries });
|
|
241
276
|
return entries.length;
|
|
242
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* 原子写入官方社区生态清单(由远端构建的 catalog.json 同步而来,全量替换)。
|
|
280
|
+
*/
|
|
281
|
+
export function writeCommunityCatalog(communityPath, incoming) {
|
|
282
|
+
const entries = incoming.map((e) => ({
|
|
283
|
+
id: e.id,
|
|
284
|
+
source: e.source,
|
|
285
|
+
name: e.name,
|
|
286
|
+
...(e.nameEn ? { nameEn: e.nameEn } : {}),
|
|
287
|
+
...(e.description ? { description: e.description } : {}),
|
|
288
|
+
...(e.descriptionEn ? { descriptionEn: e.descriptionEn } : {}),
|
|
289
|
+
...(e.icon ? { icon: e.icon } : {}),
|
|
290
|
+
...(e.iconSvg ? { iconSvg: e.iconSvg } : {}),
|
|
291
|
+
...(e.homepage ? { homepage: e.homepage } : {}),
|
|
292
|
+
}));
|
|
293
|
+
atomicWrite(communityPath, { entries });
|
|
294
|
+
return entries.length;
|
|
295
|
+
}
|
package/dist/server/plugins.js
CHANGED
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
* - activate 抛错只标记 error 字段并记日志,绝不影响主进程。
|
|
18
18
|
*/
|
|
19
19
|
import { mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
20
|
-
import { cpSync, existsSync, readFileSync, readdirSync, renameSync, watch as fsWatch, writeFileSync } from "node:fs";
|
|
20
|
+
import { cpSync, existsSync, lstatSync, readFileSync, readdirSync, renameSync, watch as fsWatch, writeFileSync, } from "node:fs";
|
|
21
21
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
22
|
-
import { pathToFileURL
|
|
22
|
+
import { pathToFileURL } from "node:url";
|
|
23
23
|
import {} from "./protocol.js";
|
|
24
24
|
import { UI_SLOTS } from "./plugin-ui-slots.js";
|
|
25
25
|
import { LeftPanelRunningStore } from "./left-panel-running.js";
|
|
@@ -1174,9 +1174,15 @@ export class PluginManager {
|
|
|
1174
1174
|
get customCatalogPath() {
|
|
1175
1175
|
return join(this.dataDir, "plugin-catalog.json");
|
|
1176
1176
|
}
|
|
1177
|
-
/**
|
|
1177
|
+
/** 官方社区生态插件清单文件(<dataDir>/community-catalog.json)。 */
|
|
1178
|
+
get communityCatalogPath() {
|
|
1179
|
+
return join(this.dataDir, "community-catalog.json");
|
|
1180
|
+
}
|
|
1181
|
+
/** 合并后的插件市场列表(builtin + community + 用户自定义,同 id 用户覆盖)。 */
|
|
1178
1182
|
catalog() {
|
|
1179
|
-
return this.builtinCatalogPath
|
|
1183
|
+
return this.builtinCatalogPath
|
|
1184
|
+
? readCatalog(this.builtinCatalogPath, this.customCatalogPath, this.communityCatalogPath)
|
|
1185
|
+
: [];
|
|
1180
1186
|
}
|
|
1181
1187
|
/** 插件市场列表纪元(随 plugin_catalog 消息下发)。 */
|
|
1182
1188
|
get catalogEpochValue() {
|
|
@@ -1203,14 +1209,14 @@ export class PluginManager {
|
|
|
1203
1209
|
return { error: err.message };
|
|
1204
1210
|
}
|
|
1205
1211
|
}
|
|
1206
|
-
/** 移除一条用户自定义条目(builtin
|
|
1212
|
+
/** 移除一条用户自定义条目(builtin / 社区条目不可经此删除);返回错误信息或 null。 */
|
|
1207
1213
|
removeCatalogEntry(id, lang) {
|
|
1208
1214
|
const l = lang?.() ?? "en";
|
|
1209
1215
|
try {
|
|
1210
1216
|
const ok = removeCustomEntry(this.customCatalogPath, id);
|
|
1211
1217
|
if (!ok)
|
|
1212
1218
|
return {
|
|
1213
|
-
error: pick(l, "
|
|
1219
|
+
error: pick(l, "未找到该条目,或它是内置/社区条目(不可移除)", "Entry not found, or it is a built-in/community entry (cannot be removed)", "plugins.catalog.entry.cannot.remove"),
|
|
1214
1220
|
};
|
|
1215
1221
|
this.catalogEpoch += 1;
|
|
1216
1222
|
void this.pushCatalog();
|
|
@@ -2188,6 +2194,19 @@ export class PluginManager {
|
|
|
2188
2194
|
if (pluginIds.has(this.proxyRoutes.get(prefix).pluginId))
|
|
2189
2195
|
this.proxyRoutes.delete(prefix);
|
|
2190
2196
|
}
|
|
2197
|
+
if (this.panelPushTimer) {
|
|
2198
|
+
clearTimeout(this.panelPushTimer);
|
|
2199
|
+
this.panelPushTimer = null;
|
|
2200
|
+
}
|
|
2201
|
+
if (this.panelSweepTimer) {
|
|
2202
|
+
clearInterval(this.panelSweepTimer);
|
|
2203
|
+
this.panelSweepTimer = null;
|
|
2204
|
+
}
|
|
2205
|
+
this.agentTools.clear();
|
|
2206
|
+
this.pluginCommands.clear();
|
|
2207
|
+
this.uiRuntime.clear();
|
|
2208
|
+
this.uiBase.clear();
|
|
2209
|
+
this.proxyRoutes.clear();
|
|
2191
2210
|
this.pluginBgTasks.clear();
|
|
2192
2211
|
this.loaded.clear();
|
|
2193
2212
|
this.messageHandlers.clear();
|
|
@@ -2227,6 +2246,15 @@ export class PluginManager {
|
|
|
2227
2246
|
continue;
|
|
2228
2247
|
const targetDir = join(this.pluginsDir, name);
|
|
2229
2248
|
const sourceDir = join(builtinDir, name);
|
|
2249
|
+
try {
|
|
2250
|
+
if (lstatSync(targetDir).isSymbolicLink()) {
|
|
2251
|
+
// 处于源码开发软链接模式(如 npm run plugins:link),直接使用源码,跳过随包文件覆盖
|
|
2252
|
+
continue;
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
catch {
|
|
2256
|
+
/* lstat 失败走普通流程 */
|
|
2257
|
+
}
|
|
2230
2258
|
const targetManifest = join(targetDir, "manifest.json");
|
|
2231
2259
|
const sourceManifest = join(sourceDir, "manifest.json");
|
|
2232
2260
|
if (!existsSync(sourceDir) || !existsSync(sourceManifest) || !existsSync(targetManifest)) {
|
|
@@ -3182,6 +3210,19 @@ export class PluginManager {
|
|
|
3182
3210
|
const off = this.registerCommand(info.id, cmd);
|
|
3183
3211
|
return effects.add(`command:/${String(cmd?.name ?? "?").replace(/^\/+/, "")}`, off);
|
|
3184
3212
|
},
|
|
3213
|
+
execCommand: async (name, args, context) => {
|
|
3214
|
+
const hit = this.findCommand(name);
|
|
3215
|
+
if (!hit)
|
|
3216
|
+
return { ok: false, error: `未找到命令 /${name}` };
|
|
3217
|
+
try {
|
|
3218
|
+
const res = await hit.def.run(args, context ?? { clientId: `plugin:${info.id}` });
|
|
3219
|
+
return { ok: true, result: typeof res === "string" ? res : "" };
|
|
3220
|
+
}
|
|
3221
|
+
catch (err) {
|
|
3222
|
+
return { ok: false, error: err.message };
|
|
3223
|
+
}
|
|
3224
|
+
},
|
|
3225
|
+
getPluginCommands: () => this.listCommands(),
|
|
3185
3226
|
storage,
|
|
3186
3227
|
secrets,
|
|
3187
3228
|
ensureDeps: (specs, opts) => ensurePluginDeps(dir, specs ?? [], opts?.onProgress),
|
|
@@ -21,10 +21,9 @@
|
|
|
21
21
|
* 与副作用(createPresetIssue / fetchPresetCatalog)分开,便于单测。
|
|
22
22
|
*/
|
|
23
23
|
import { execFile } from "node:child_process";
|
|
24
|
-
import { mkdtempSync,
|
|
24
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
25
25
|
import { tmpdir } from "node:os";
|
|
26
|
-
import {
|
|
27
|
-
import { fileURLToPath } from "node:url";
|
|
26
|
+
import { join } from "node:path";
|
|
28
27
|
import { promisify } from "node:util";
|
|
29
28
|
import { getAppVersion } from "./pkg-info.js";
|
|
30
29
|
import { normalizeDisabledPluginTools, normalizeRetryMaxAttempts, normalizeSkillList, normalizeUiLayout, } from "./client-state.js";
|
|
@@ -4,6 +4,61 @@ import { resolve } from "node:path";
|
|
|
4
4
|
* 后台任务面板(bgServers)用它们检测/停止 agent 在后台拉起的服务。
|
|
5
5
|
* 从 agent-service.ts 抽出,行为保持不变。全平台 best-effort:失败静默。
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* 解析 Windows `netstat -ano -p tcp` 输出 → 端口→pid。纯函数,单测覆盖。
|
|
9
|
+
* 行形状:`TCP 0.0.0.0:5173 0.0.0.0:0 LISTENING 12345`。
|
|
10
|
+
*/
|
|
11
|
+
export function parseNetstatListening(stdout) {
|
|
12
|
+
const m = new Map();
|
|
13
|
+
for (const line of stdout.split(/\r?\n/)) {
|
|
14
|
+
const p = line.trim().split(/\s+/);
|
|
15
|
+
if (p.length >= 5 && p[0] === "TCP" && p[3] === "LISTENING") {
|
|
16
|
+
// 本地地址可能是 0.0.0.0:5173 / [::1]:5173 —— 取最后一段就是端口。
|
|
17
|
+
const port = Number(p[1].split(":").pop());
|
|
18
|
+
const pid = Number(p[4]);
|
|
19
|
+
if (Number.isFinite(port) && Number.isFinite(pid))
|
|
20
|
+
m.set(port, pid);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return m;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 解析 POSIX `lsof -iTCP -sTCP:LISTEN -P -n` 输出 → 端口→pid。纯函数,单测覆盖。
|
|
27
|
+
*
|
|
28
|
+
* NAME 列形如 `*:5173` / `127.0.0.1:5173` / `[::1]:5173`。监听态 `(LISTEN)`
|
|
29
|
+
* 在不同发行版上**要么贴在 NAME 里、要么自成最后一列**,所以“取最后一列”的
|
|
30
|
+
* 写法(旧实现)在后者上拿到的是 `(LISTEN)` 而不是地址 —— 整条 posix 端口探测
|
|
31
|
+
* 静默失效(后台任务面板就看不到 AI 拉起的服务)。这里改成扫列:第一个
|
|
32
|
+
* “以冒号+数字收尾”的列就是地址(FD/TYPE/DEVICE/SIZE-OFF/NODE 都不带这种形状)。
|
|
33
|
+
*/
|
|
34
|
+
export function parseLsofListening(stdout) {
|
|
35
|
+
const m = new Map();
|
|
36
|
+
for (const line of stdout.split(/\r?\n/)) {
|
|
37
|
+
const p = line.trim().split(/\s+/);
|
|
38
|
+
if (p.length < 5)
|
|
39
|
+
continue;
|
|
40
|
+
const pid = Number(p[1]);
|
|
41
|
+
if (!Number.isFinite(pid) || pid <= 0)
|
|
42
|
+
continue; // 表头 / 脏行
|
|
43
|
+
const port = findListenPort(p.slice(3));
|
|
44
|
+
if (port === null)
|
|
45
|
+
continue;
|
|
46
|
+
m.set(port, pid);
|
|
47
|
+
}
|
|
48
|
+
return m;
|
|
49
|
+
}
|
|
50
|
+
/** 从 lsof 行尾列里找出监听端口(第一个 `:数字` 收尾的列)。 */
|
|
51
|
+
function findListenPort(cols) {
|
|
52
|
+
for (const col of cols) {
|
|
53
|
+
const mm = col.match(/:(\d{1,5})$/);
|
|
54
|
+
if (!mm)
|
|
55
|
+
continue;
|
|
56
|
+
const port = Number(mm[1]);
|
|
57
|
+
if (port > 0 && port <= 65535)
|
|
58
|
+
return port;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
7
62
|
/**
|
|
8
63
|
* Snapshot currently LISTENING TCP ports → owning pid. Windows: netstat;
|
|
9
64
|
* POSIX: lsof. Used to detect servers the agent started in the background
|
|
@@ -15,31 +70,10 @@ export async function snapshotListeningPorts() {
|
|
|
15
70
|
const { execFile } = await import("node:child_process");
|
|
16
71
|
if (process.platform === "win32") {
|
|
17
72
|
const out = await new Promise((resolve, reject) => execFile("netstat", ["-ano", "-p", "tcp"], { windowsHide: true, timeout: 8000 }, (err, stdout) => err ? reject(err) : resolve(stdout)));
|
|
18
|
-
|
|
19
|
-
const p = line.trim().split(/\s+/);
|
|
20
|
-
// TCP 0.0.0.0:5173 0.0.0.0:0 LISTENING 12345
|
|
21
|
-
if (p.length >= 5 && p[0] === "TCP" && p[3] === "LISTENING") {
|
|
22
|
-
const port = Number(p[1].split(":").pop());
|
|
23
|
-
const pid = Number(p[4]);
|
|
24
|
-
if (Number.isFinite(port) && Number.isFinite(pid))
|
|
25
|
-
m.set(port, pid);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
const out = await new Promise((resolve, reject) => execFile("lsof", ["-iTCP", "-sTCP:LISTEN", "-P", "-n"], { timeout: 8000 }, (err, stdout) => err ? reject(err) : resolve(stdout)));
|
|
31
|
-
for (const line of out.split(/\r?\n/).slice(1)) {
|
|
32
|
-
const p = line.trim().split(/\s+/);
|
|
33
|
-
if (p.length >= 9) {
|
|
34
|
-
// NAME column tail: "*:5173 (LISTEN)" or "[::1]:5173 (LISTEN)"
|
|
35
|
-
const mm = (p[p.length - 1] ?? "").match(/(\d+)\)?\s*$/);
|
|
36
|
-
const port = mm ? Number(mm[1]) : NaN;
|
|
37
|
-
const pid = Number(p[1]);
|
|
38
|
-
if (Number.isFinite(port) && Number.isFinite(pid))
|
|
39
|
-
m.set(port, pid);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
73
|
+
return parseNetstatListening(out);
|
|
42
74
|
}
|
|
75
|
+
const out = await new Promise((resolve, reject) => execFile("lsof", ["-iTCP", "-sTCP:LISTEN", "-P", "-n"], { timeout: 8000 }, (err, stdout) => err ? reject(err) : resolve(stdout)));
|
|
76
|
+
return parseLsofListening(out);
|
|
43
77
|
}
|
|
44
78
|
catch {
|
|
45
79
|
// best effort — snapshot failure just means no tracking this round
|
|
@@ -323,6 +323,7 @@ export class SettingsService {
|
|
|
323
323
|
toolsWrap: this.settings.toolsWrap,
|
|
324
324
|
toolImagesEnabled: this.settings.toolImagesEnabled ?? true,
|
|
325
325
|
keepRecentMessages: normalizeKeepRecentMessages(this.settings.keepRecentMessages),
|
|
326
|
+
reversePagination: this.settings.reversePagination ?? false,
|
|
326
327
|
showForkedParentSessions: this.settings.showForkedParentSessions ?? false,
|
|
327
328
|
retainFinishedConversations: this.settings.retainFinishedConversations ?? false,
|
|
328
329
|
openRecentSessionOnProjectSwitch: this.settings.openRecentSessionOnProjectSwitch ?? true,
|
|
@@ -577,6 +578,10 @@ export class SettingsService {
|
|
|
577
578
|
if (partial.keepRecentMessages !== undefined) {
|
|
578
579
|
this.settings.keepRecentMessages = normalizeKeepRecentMessages(partial.keepRecentMessages);
|
|
579
580
|
}
|
|
581
|
+
// 向上分页加载:前端 MessageList 实时读它(纯渲染策略),无需 reload runtime。
|
|
582
|
+
if (partial.reversePagination !== undefined) {
|
|
583
|
+
this.settings.reversePagination = Boolean(partial.reversePagination);
|
|
584
|
+
}
|
|
580
585
|
if (partial.retainFinishedConversations !== undefined) {
|
|
581
586
|
this.settings.retainFinishedConversations = Boolean(partial.retainFinishedConversations);
|
|
582
587
|
}
|
|
@@ -63,10 +63,10 @@ export function parseSlash(text) {
|
|
|
63
63
|
const trimmed = text.trim();
|
|
64
64
|
if (!trimmed.startsWith("/"))
|
|
65
65
|
return null;
|
|
66
|
-
const m = trimmed.match(/^\/([^\s]
|
|
67
|
-
if (!m
|
|
66
|
+
const m = trimmed.match(/^\/([^\s]*)\s*([\s\S]*)$/);
|
|
67
|
+
if (!m)
|
|
68
68
|
return null;
|
|
69
|
-
return { name: m[1], args: m[2].trim() };
|
|
69
|
+
return { name: m[1] ?? "", args: (m[2] ?? "").trim() };
|
|
70
70
|
}
|
|
71
71
|
export class SlashCommandsService {
|
|
72
72
|
host;
|
|
@@ -418,7 +418,19 @@ export class SlashCommandsService {
|
|
|
418
418
|
}, 300);
|
|
419
419
|
return true;
|
|
420
420
|
}
|
|
421
|
-
case "
|
|
421
|
+
case "":
|
|
422
|
+
case "?":
|
|
423
|
+
case "help": {
|
|
424
|
+
void this.push();
|
|
425
|
+
const cmdList = NATIVE_COMMANDS.map((c) => `/${c.name} : ${c.description}`).join("\n");
|
|
426
|
+
this.host.emit({
|
|
427
|
+
type: "notice",
|
|
428
|
+
level: "info",
|
|
429
|
+
text: `可用斜杠指令:\n${cmdList}`,
|
|
430
|
+
textEn: `Available slash commands:\n${cmdList}`,
|
|
431
|
+
});
|
|
432
|
+
return true;
|
|
433
|
+
}
|
|
422
434
|
case "copy":
|
|
423
435
|
// Client-side UI actions — the client handles them before sending;
|
|
424
436
|
// swallow here so the SDK never sees them as plain prompt text.
|