@michengai/dsh-codex-ui 2.0.5 → 2.0.6
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 +10 -0
- package/CHANGELOG.zh-CN.md +10 -0
- package/lib/client.js +1817 -28
- package/lib/composer-plugin.mjs +1 -2
- package/lib/index.mjs +166 -2
- package/lib/profile-resolver-D81fBy52.mjs +84 -0
- package/lib/session-title-plugin.mjs +24 -0
- package/lib/settings-skin-plugin.mjs +1 -2
- package/lib/sidebar-plugin.mjs +1 -2
- package/lib/theme-plugin.mjs +1 -2
- package/package.json +1 -1
package/lib/composer-plugin.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as isSubPluginDisabledOnDisk$1 } from "./profile-resolver-9ws-Evm5.mjs";
|
|
1
|
+
import { r as CODEX_UI_API_ENDPOINTS, t as isSubPluginDisabledOnDisk$1 } from "./profile-resolver-D81fBy52.mjs";
|
|
3
2
|
//#region src/composer-plugin.ts
|
|
4
3
|
const name = "codex-ui-composer";
|
|
5
4
|
const inject = ["webServer"];
|
package/lib/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as resolveCurrentProfile, r as CODEX_UI_API_ENDPOINTS } from "./profile-resolver-D81fBy52.mjs";
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { readFile, rm, unlink, writeFile } from "node:fs/promises";
|
|
5
5
|
import { homedir } from "node:os";
|
|
6
6
|
import { basename, delimiter, dirname, isAbsolute, join, resolve, sep } from "node:path";
|
|
@@ -1028,6 +1028,108 @@ function hostServices(ctx) {
|
|
|
1028
1028
|
return { webServer: requireService(ctx, "webServer", "register") };
|
|
1029
1029
|
}
|
|
1030
1030
|
//#endregion
|
|
1031
|
+
//#region src/sections-store.ts
|
|
1032
|
+
/**
|
|
1033
|
+
* 工作区分区的宿主侧存储。
|
|
1034
|
+
*
|
|
1035
|
+
* 对齐 Codex 的分层:分区结构与成员归属属于**用户数据**,由宿主落盘
|
|
1036
|
+
* (Codex 是 `~/.codex/state_5.sqlite` 里的 `thread_sections` + `threads.thread_section_id`),
|
|
1037
|
+
* 浏览器只负责折叠、展开这类视图偏好。
|
|
1038
|
+
*
|
|
1039
|
+
* 这里把文档写到当前 DSH profile 的 `plugin-data/<app>/` 下:换浏览器、清缓存都不会丢,
|
|
1040
|
+
* 也不会和宿主自己的配置混在一起。写入走「临时文件 + rename」,避免进程中断留下半截 JSON。
|
|
1041
|
+
*/
|
|
1042
|
+
/** 单个分区文档的体积上限:这是结构数据,超过就说明客户端出了问题。 */
|
|
1043
|
+
const SECTIONS_STORE_MAX_BYTES = 65536;
|
|
1044
|
+
/** 单个分区内成员上限。 */
|
|
1045
|
+
const SECTIONS_STORE_MAX_MEMBERS = 2e3;
|
|
1046
|
+
/** 非法文档:调用方据此回 400,且绝不覆盖已存在的合法文件。 */
|
|
1047
|
+
var SectionsDocumentError = class extends Error {};
|
|
1048
|
+
/**
|
|
1049
|
+
* 解析分区文档的落盘路径。
|
|
1050
|
+
*
|
|
1051
|
+
* @param ctx - 宿主 Context,可从中读到当前 profile。
|
|
1052
|
+
* @returns 绝对路径:`<profileDir>/plugin-data/michengai.dsh-codex-ui/workspace-sections.json`。
|
|
1053
|
+
*/
|
|
1054
|
+
function resolveSectionsStorePath(ctx) {
|
|
1055
|
+
const { profileDir, homeDir } = resolveCurrentProfile(ctx);
|
|
1056
|
+
return join(profileDir !== "" ? profileDir : homeDir, "plugin-data", "michengai.dsh-codex-ui", "workspace-sections.json");
|
|
1057
|
+
}
|
|
1058
|
+
/** 校验并规范化分区文档;不合法时抛 {@link SectionsDocumentError}。 */
|
|
1059
|
+
function validateSectionsDocument(value) {
|
|
1060
|
+
if (typeof value !== "object" || value === null) throw new SectionsDocumentError("分区数据必须是对象。");
|
|
1061
|
+
const raw = value;
|
|
1062
|
+
if (!Array.isArray(raw.sections)) throw new SectionsDocumentError("分区数据缺少 sections 数组。");
|
|
1063
|
+
if (raw.sections.length > 100) throw new SectionsDocumentError(`分区数量超过上限 100。`);
|
|
1064
|
+
const seenSections = /* @__PURE__ */ new Set();
|
|
1065
|
+
const seenWorkspaces = /* @__PURE__ */ new Set();
|
|
1066
|
+
const sections = raw.sections.map((item, index) => {
|
|
1067
|
+
if (typeof item !== "object" || item === null) throw new SectionsDocumentError(`第 ${index + 1} 个分区不是对象。`);
|
|
1068
|
+
const section = item;
|
|
1069
|
+
if (typeof section.id !== "string" || section.id.trim() === "" || section.id.length > 64) throw new SectionsDocumentError(`第 ${index + 1} 个分区的 id 不合法。`);
|
|
1070
|
+
if (seenSections.has(section.id)) throw new SectionsDocumentError(`分区 id 重复:${section.id}。`);
|
|
1071
|
+
seenSections.add(section.id);
|
|
1072
|
+
const name = typeof section.name === "string" ? section.name.trim() : "";
|
|
1073
|
+
if (name === "" || name.length > 64) throw new SectionsDocumentError(`分区「${section.id}」的名称不合法。`);
|
|
1074
|
+
if (!Array.isArray(section.ids)) throw new SectionsDocumentError(`分区「${section.id}」缺少 ids 数组。`);
|
|
1075
|
+
if (section.ids.length > 2e3) throw new SectionsDocumentError(`分区「${section.id}」成员数量超过上限 ${SECTIONS_STORE_MAX_MEMBERS}。`);
|
|
1076
|
+
const ids = section.ids.map((member) => {
|
|
1077
|
+
if (typeof member !== "string" || member === "" || member.length > 128) throw new SectionsDocumentError(`分区「${section.id}」存在不合法的成员 id。`);
|
|
1078
|
+
if (seenWorkspaces.has(member)) throw new SectionsDocumentError(`同一个工作区出现在多个分区:${member}。`);
|
|
1079
|
+
seenWorkspaces.add(member);
|
|
1080
|
+
return member;
|
|
1081
|
+
});
|
|
1082
|
+
return {
|
|
1083
|
+
id: section.id,
|
|
1084
|
+
name,
|
|
1085
|
+
ids
|
|
1086
|
+
};
|
|
1087
|
+
});
|
|
1088
|
+
return {
|
|
1089
|
+
version: typeof raw.version === "number" && Number.isFinite(raw.version) ? Math.trunc(raw.version) : 1,
|
|
1090
|
+
sections
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* 读取分区文档。
|
|
1095
|
+
*
|
|
1096
|
+
* @param ctx - 宿主 Context。
|
|
1097
|
+
* @returns 文档;文件不存在或内容损坏时返回 `undefined`(损坏内容不会被删除,便于排查)。
|
|
1098
|
+
*/
|
|
1099
|
+
function readSectionsDocument(ctx) {
|
|
1100
|
+
const path = resolveSectionsStorePath(ctx);
|
|
1101
|
+
if (!existsSync(path)) return void 0;
|
|
1102
|
+
try {
|
|
1103
|
+
const text = readFileSync(path, "utf8");
|
|
1104
|
+
if (text.length > 65536) return void 0;
|
|
1105
|
+
return validateSectionsDocument(JSON.parse(text));
|
|
1106
|
+
} catch {
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* 原子写入分区文档。
|
|
1112
|
+
*
|
|
1113
|
+
* @param ctx - 宿主 Context。
|
|
1114
|
+
* @param document - 已校验的文档。
|
|
1115
|
+
*/
|
|
1116
|
+
function writeSectionsDocument(ctx, document) {
|
|
1117
|
+
const path = resolveSectionsStorePath(ctx);
|
|
1118
|
+
const payload = JSON.stringify(validateSectionsDocument(document), null, 2);
|
|
1119
|
+
if (Buffer.byteLength(payload, "utf8") > 65536) throw new SectionsDocumentError("分区数据过大。");
|
|
1120
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
1121
|
+
const temporary = `${path}.${process.pid}.tmp`;
|
|
1122
|
+
try {
|
|
1123
|
+
writeFileSync(temporary, payload, "utf8");
|
|
1124
|
+
renameSync(temporary, path);
|
|
1125
|
+
} catch (error) {
|
|
1126
|
+
try {
|
|
1127
|
+
if (existsSync(temporary)) unlinkSync(temporary);
|
|
1128
|
+
} catch {}
|
|
1129
|
+
throw error;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
//#endregion
|
|
1031
1133
|
//#region src/index.ts
|
|
1032
1134
|
const dependenciesEndpoint = CODEX_UI_API_ENDPOINTS.dependencies;
|
|
1033
1135
|
function headerValue(headers, name) {
|
|
@@ -1169,9 +1271,71 @@ function apply(ctx) {
|
|
|
1169
1271
|
}
|
|
1170
1272
|
}
|
|
1171
1273
|
});
|
|
1274
|
+
/**
|
|
1275
|
+
* 工作区分区:结构与归属由宿主落盘(当前 profile 的 plugin-data 下),浏览器只留折叠这类视图偏好。
|
|
1276
|
+
* 对齐 Codex:`thread_sections` + `threads.thread_section_id` 在宿主,折叠状态在客户端。
|
|
1277
|
+
*/
|
|
1278
|
+
const disposeSections = host.webServer.register({
|
|
1279
|
+
kind: "exact",
|
|
1280
|
+
path: CODEX_UI_API_ENDPOINTS.sections,
|
|
1281
|
+
handler: async (request, response) => {
|
|
1282
|
+
if (!authenticateBusinessRequest(ctx, request, response)) return;
|
|
1283
|
+
const json = (status, body) => {
|
|
1284
|
+
response.writeHead(status, {
|
|
1285
|
+
"content-type": "application/json; charset=utf-8",
|
|
1286
|
+
"cache-control": "no-store"
|
|
1287
|
+
});
|
|
1288
|
+
response.end(JSON.stringify(body));
|
|
1289
|
+
};
|
|
1290
|
+
try {
|
|
1291
|
+
if (request.method === "GET") {
|
|
1292
|
+
json(200, readSectionsDocument(ctx) ?? {
|
|
1293
|
+
version: 1,
|
|
1294
|
+
sections: []
|
|
1295
|
+
});
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
if (request.method !== "POST" && request.method !== "PUT") {
|
|
1299
|
+
response.writeHead(405);
|
|
1300
|
+
response.end();
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
const body = await readRequestBody(request, SECTIONS_STORE_MAX_BYTES);
|
|
1304
|
+
if (body.trim() === "") {
|
|
1305
|
+
json(400, { error: "缺少分区数据。" });
|
|
1306
|
+
return;
|
|
1307
|
+
}
|
|
1308
|
+
let parsed;
|
|
1309
|
+
try {
|
|
1310
|
+
parsed = JSON.parse(body);
|
|
1311
|
+
} catch {
|
|
1312
|
+
json(400, { error: "分区数据不是合法 JSON。" });
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
const document = validateSectionsDocument(parsed);
|
|
1316
|
+
writeSectionsDocument(ctx, document);
|
|
1317
|
+
json(200, {
|
|
1318
|
+
ok: true,
|
|
1319
|
+
sections: document.sections.length
|
|
1320
|
+
});
|
|
1321
|
+
} catch (error) {
|
|
1322
|
+
if (error instanceof SectionsDocumentError) {
|
|
1323
|
+
json(400, { error: error.message });
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
if (error instanceof RequestBodyTooLargeError) {
|
|
1327
|
+
json(413, { error: "分区数据过大。" });
|
|
1328
|
+
return;
|
|
1329
|
+
}
|
|
1330
|
+
ctx.logger.warn("sections endpoint failed: %s", error);
|
|
1331
|
+
json(503, { error: "分区存储暂不可用。" });
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1172
1335
|
return () => {
|
|
1173
1336
|
disposeDependencyInstaller();
|
|
1174
1337
|
disposeDependencies();
|
|
1338
|
+
disposeSections?.();
|
|
1175
1339
|
};
|
|
1176
1340
|
}, "michengai-codex-ui: catalogs");
|
|
1177
1341
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { basename, isAbsolute, join, resolve } from "node:path";
|
|
4
|
+
//#region src/business-api.ts
|
|
5
|
+
const CODEX_UI_API_BASE = "/api/michengai/dsh-codex-ui";
|
|
6
|
+
const CODEX_UI_API_ENDPOINTS = Object.freeze({
|
|
7
|
+
dependencies: `${CODEX_UI_API_BASE}/dependencies`,
|
|
8
|
+
settingsSkin: `${CODEX_UI_API_BASE}/settings-skin`,
|
|
9
|
+
composer: `${CODEX_UI_API_BASE}/composer`,
|
|
10
|
+
sidebar: `${CODEX_UI_API_BASE}/sidebar`,
|
|
11
|
+
sections: `${CODEX_UI_API_BASE}/sections`,
|
|
12
|
+
theme: `${CODEX_UI_API_BASE}/theme`
|
|
13
|
+
});
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/profile-resolver.ts
|
|
16
|
+
/**
|
|
17
|
+
* 健壮解析当前 DSH 实例的 Profile 信息:
|
|
18
|
+
* 优先级:
|
|
19
|
+
* 1. Cordis 服务 profileContext(官方运行时注入,最权威)
|
|
20
|
+
* 2. 环境变量 DSH_PROFILE_DIR
|
|
21
|
+
* 3. 命令行参数 --profile <name>
|
|
22
|
+
* 4. 环境变量 DSH_PROFILE
|
|
23
|
+
* 5. 兜底默认值 'web'
|
|
24
|
+
*/
|
|
25
|
+
function resolveCurrentProfile(ctx, customHomeDir) {
|
|
26
|
+
const homeDir = customHomeDir ?? process.env.DSH_HOME ?? join(homedir(), ".dsh");
|
|
27
|
+
let profileName;
|
|
28
|
+
let profileDir;
|
|
29
|
+
try {
|
|
30
|
+
const launched = ctx?.get?.("profileContext");
|
|
31
|
+
if (typeof launched?.name === "string" && launched.name.trim()) profileName = launched.name.trim();
|
|
32
|
+
if (typeof launched?.dir === "string" && isAbsolute(launched.dir)) profileDir = resolve(launched.dir);
|
|
33
|
+
} catch {}
|
|
34
|
+
if (!profileDir && process.env.DSH_PROFILE_DIR) try {
|
|
35
|
+
profileDir = resolve(process.env.DSH_PROFILE_DIR);
|
|
36
|
+
if (!profileName) profileName = basename(profileDir);
|
|
37
|
+
} catch {}
|
|
38
|
+
if (!profileName && typeof process !== "undefined" && Array.isArray(process.argv)) {
|
|
39
|
+
const argv = process.argv;
|
|
40
|
+
for (let i = 0; i < argv.length; i++) {
|
|
41
|
+
const arg = argv[i];
|
|
42
|
+
if (arg === "--profile" && argv[i + 1]) {
|
|
43
|
+
profileName = argv[i + 1].trim();
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
if (typeof arg === "string" && arg.startsWith("--profile=")) {
|
|
47
|
+
profileName = arg.slice(10).trim();
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (!profileName && process.env.DSH_PROFILE) profileName = process.env.DSH_PROFILE.trim();
|
|
53
|
+
if (!profileName) profileName = "web";
|
|
54
|
+
if (!profileDir) profileDir = join(homeDir, "profiles", profileName);
|
|
55
|
+
return {
|
|
56
|
+
profileName,
|
|
57
|
+
profileDir,
|
|
58
|
+
homeDir
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 严格基于当前 Profile 检查 cordis.patch.yml 中是否显式配置了 disabled: true。
|
|
63
|
+
* 杜绝跨 Profile 串读(绝不扫描非当前 Profile 的目录)。
|
|
64
|
+
*/
|
|
65
|
+
function isSubPluginDisabledOnDisk(id, homeDir, ctx) {
|
|
66
|
+
try {
|
|
67
|
+
const { profileDir } = resolveCurrentProfile(ctx, homeDir);
|
|
68
|
+
const patchPath = join(profileDir, "cordis.patch.yml");
|
|
69
|
+
if (existsSync(patchPath)) {
|
|
70
|
+
const itemBlocks = readFileSync(patchPath, "utf8").split(/(?:\r?\n)(?=-\s+)/);
|
|
71
|
+
for (let i = itemBlocks.length - 1; i >= 0; i--) {
|
|
72
|
+
const block = itemBlocks[i];
|
|
73
|
+
if (new RegExp(`(?:^|\\s)id:\\s*['"]?${id}['"]?(?:\\s|$)`, "m").test(block)) {
|
|
74
|
+
if (/(?:^|\s)disabled:\s*true(?:\s|$)/m.test(block)) return true;
|
|
75
|
+
if (/(?:^|\s)disabled:\s*false(?:\\s|$)/m.test(block)) return false;
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
} catch {}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
export { resolveCurrentProfile as n, CODEX_UI_API_ENDPOINTS as r, isSubPluginDisabledOnDisk as t };
|
|
@@ -34,6 +34,18 @@ const zh = {
|
|
|
34
34
|
"settings.noResults": "没有匹配的设置分类",
|
|
35
35
|
"input.historyHint": "↑↓ 翻历史",
|
|
36
36
|
"about.nav": "Codex UI",
|
|
37
|
+
"sections.pinned": "置顶",
|
|
38
|
+
"sections.default": "项目",
|
|
39
|
+
"sections.menu": "分区",
|
|
40
|
+
"sections.pin": "置顶",
|
|
41
|
+
"sections.unpin": "取消置顶",
|
|
42
|
+
"sections.rename": "重命名",
|
|
43
|
+
"sections.remove": "移除分区",
|
|
44
|
+
"sections.writePending": "工作区移动尚未完成,后续操作正在等待宿主响应。",
|
|
45
|
+
"sections.writeAborted": "工作区移动未完成,已自动撤销。",
|
|
46
|
+
"sections.new": "新建分区",
|
|
47
|
+
"sections.newName": "新分区名称",
|
|
48
|
+
"sections.settings": "分区设置",
|
|
37
49
|
"about.title": "Codex UI",
|
|
38
50
|
"about.viewProject": "GitHub",
|
|
39
51
|
"about.feedback": "问题反馈",
|
|
@@ -189,6 +201,18 @@ const en = {
|
|
|
189
201
|
"settings.noResults": "No matching settings categories",
|
|
190
202
|
"input.historyHint": "↑↓ History",
|
|
191
203
|
"about.nav": "Codex UI",
|
|
204
|
+
"sections.pinned": "Pinned",
|
|
205
|
+
"sections.default": "Projects",
|
|
206
|
+
"sections.menu": "Section",
|
|
207
|
+
"sections.pin": "Pin",
|
|
208
|
+
"sections.unpin": "Unpin",
|
|
209
|
+
"sections.rename": "Rename",
|
|
210
|
+
"sections.remove": "Remove section",
|
|
211
|
+
"sections.writePending": "Workspace move is still pending host response.",
|
|
212
|
+
"sections.writeAborted": "Workspace move was not completed and was aborted.",
|
|
213
|
+
"sections.new": "New section",
|
|
214
|
+
"sections.newName": "Section name",
|
|
215
|
+
"sections.settings": "Section settings",
|
|
192
216
|
"about.title": "Codex UI",
|
|
193
217
|
"about.viewProject": "GitHub",
|
|
194
218
|
"about.feedback": "Issues",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as isSubPluginDisabledOnDisk } from "./profile-resolver-9ws-Evm5.mjs";
|
|
1
|
+
import { r as CODEX_UI_API_ENDPOINTS, t as isSubPluginDisabledOnDisk } from "./profile-resolver-D81fBy52.mjs";
|
|
3
2
|
//#region src/settings-skin-plugin.ts
|
|
4
3
|
const name = "codex-ui-settings-skin";
|
|
5
4
|
const inject = ["webServer"];
|
package/lib/sidebar-plugin.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as isSubPluginDisabledOnDisk$1 } from "./profile-resolver-9ws-Evm5.mjs";
|
|
1
|
+
import { r as CODEX_UI_API_ENDPOINTS, t as isSubPluginDisabledOnDisk$1 } from "./profile-resolver-D81fBy52.mjs";
|
|
3
2
|
//#region src/sidebar-plugin.ts
|
|
4
3
|
const name = "codex-ui-sidebar";
|
|
5
4
|
const inject = ["webServer"];
|
package/lib/theme-plugin.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as isSubPluginDisabledOnDisk$1 } from "./profile-resolver-9ws-Evm5.mjs";
|
|
1
|
+
import { r as CODEX_UI_API_ENDPOINTS, t as isSubPluginDisabledOnDisk$1 } from "./profile-resolver-D81fBy52.mjs";
|
|
3
2
|
//#region src/theme-plugin.ts
|
|
4
3
|
const name = "codex-ui-theme";
|
|
5
4
|
const inject = ["webServer"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@michengai/dsh-codex-ui",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "DSH Codex UI — 为 DeepSeek Harness 提供极速历史召回、全屏设置皮肤、原生物理毛玻璃换肤与模块化侧栏 · Input enhancement, settings skin, native glass theme, and modular sidebar for DSH",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"publishConfig": {
|