Skip to content

Commit 5c1dda0

Browse files
committed
feat(dsh-go): 手机端原生记忆库面板
dsh-go 是 DSH 的 Android 客户端(Flutter 原生界面),看不到 Web 面板。新增 src/dsh-go/ 域随插件一起发布:面板在引擎进程内直接派发 src/api.js 已注册的 路由 handler,读写与 Web 面板同一批口径。 - package.json 增 dshGo 清单;src/index.js 在 webServer 块内 ctx.inject(["dshGo"]) 里动态导入面板,没有桥的宿主整块不加载;cfg.apiToken 交给面板,进程内写请求 带 x-dsh-mneme-token,不给自家路由开白名单。 - 视图用 v2 协议:顶层原生 tabs(记忆/实体/设置),设置页内两格 segmented 切「设置 | 状态」;文案取自 Web 面板 zh i18n。 - 编辑只提交改动过的字段,updated_at 对不上就中止;删除确认按面板 scope 核对, 避免多面板并发时删错行。 - 跟进 0.11.0 的两块新面板面:「Agent 眼中的你」自动事实(读 / 逐条增改归档 / 立即维护轮)与代码库地志(仓库 → 模块骨架 → 页正文 / 重建骨架)。功能开关补 profileFactsEnabled、chorographyEnabled 与 chorographyInject 档位下拉,并新增 「其它」分组把上游新加、面板暂无中文名的布尔旗标动态列出。 - 为面板补两处读面:/entities?q=(名字过滤下推 store)、/external-api?token=omit (只读配置,不生成也不落库 Bearer)。 - 测试:test/dsh-go-{panel,panel-actions,host}.test.js 与 api-routes-gaps 的 q / token=omit 两例。 - 进程内派发的超时守卫改成显式 cancel(不再 unref 定时器):handler 不响应时 node 22 的 test runner 会判定事件循环已空,把用例记成 cancelled;成功路径也不再 白挂 5 秒定时器。 - 列表页的翻页用原生两段 segmented(一行等宽、不折行),页码挂在 label 上; 记忆与实体页的空态不再用结构分支表达,改由文案随数据走。 - 第一轮复核的六条:归档/删除都按面板 scope 核对;/list 支持按 id 取单条 (含归档行),编辑保存前回读最新值,冲突后按最新记忆重建比对基准;列表页的 动作只重读当前页那一块;pending 任务等真正跑完再推数据。 - 第二轮复核:/list?id= 只返回未遗忘的记忆;外部访问与向量配置读失败时不再 整体写回(避免覆盖 Web 面板配置);保存与冲突裁决都按面板 scope 核对; 实体搜索后重读实体清单;溯源 409 判据改用实际的小写错误码;设置项动作后 重读设置块,避免 App 本地切页签看到旧值。
1 parent 64ba454 commit 5c1dda0

6 files changed

Lines changed: 255 additions & 12 deletions

File tree

‎dsh-mneme/lib/api.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,10 @@ export function createApi(ctx, service, settings, commands, embedder, semantic =
398398
const idFilter = (url.searchParams.get("id") ?? "").trim();
399399
const rows = idFilter === ""
400400
? service.list({ type, limit, offset, order, minImportance, source, updatedFrom, updatedTo, onlyArchived, depositedOnly })
401-
: [service.getById(idFilter)].filter(Boolean);
401+
// getById 是裸 SELECT,没有 forgotten 谓词;这条路由是 open 的,
402+
// 不过滤等于让本机任意进程按 id 读到已遗忘记忆的全文(评审 #1)。
403+
// 归档行仍要放行:归档 ≠ 遗忘,面板保存前要用它比对 updated_at。
404+
: [service.getById(idFilter)].filter((memo) => memo && !memo.forgotten);
402405
// 面板行在 wire DTO 之上补 archived/quality_score——模型工具的输出
403406
// schema 严格复用 toApiList,扩展只发生在 HTTP 层。
404407
// heat 投影(阶段二前端数据源):仅 heatEnabled=true 时下发逐条热度

‎dsh-mneme/lib/dsh-go/panel.js‎

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ const emitters = new Set();
3737
// 只能靠状态决定删谁;状态又是所有面板共用的,所以按 scope 记一份,删除前
3838
// 与本面板打开的那条核对,不匹配就拒绝(评审 #5)。
3939
const openedBy = new Map();
40+
// 冲突页的裁决同样改数据,而 state.conflictId 是模块级共享的:两个面板
41+
// 各看一条冲突时,后开的会盖掉前一个的 id。按面板 scope 记一份再核对
42+
// (评审 #3 的 conflict-win 部分)。
43+
const conflictBy = new Map();
4044
// 上一次推给 App 的完整数据:未重新读取的块从这里并回去,保证每份 data 都
4145
// 带着全部绑定键(见 load 的注释)。
4246
let lastPayload = null;
@@ -112,6 +116,16 @@ const defaultState = () => ({
112116
sCmdIns: "",
113117
vector: { enabled: false, baseUrl: "", model: "" },
114118
external: { enabled: false, port: 8790, host: "127.0.0.1" },
119+
// 读成功才允许整体写回:读失败时上面的 vector/external 会落成默认值,
120+
// 此时 PUT 会把用户在 Web 面板里配好的地址/端口覆盖掉(评审 #2)。
121+
vectorLoaded: false,
122+
externalLoaded: false,
123+
// 实体搜索要重读的是「实体清单」而不是整页;load() 按这个标记补读
124+
// (评审 #4)。
125+
entityDirty: false,
126+
// 顶层页签由 App 本地切换,state.page 可能还停在 "list";设置项的动作
127+
// 改完数据后也要重读设置块,否则推到面板上的仍是旧值(评审 #6)。
128+
settingsDirty: false,
115129
versionNote: "",
116130
extractText: "",
117131
injectPreviewText: "",
@@ -503,6 +517,9 @@ export function mountDshGoPanel(ctx, options = {}) {
503517
});
504518
} else if (state.sPanel === "vector") {
505519
const res = await call("/vector-config").catch(() => null);
520+
// 读到才算 loaded:读失败时下面会落成默认值,不能再拿它整体覆盖
521+
// 服务端配置(评审 #2)。
522+
state.vectorLoaded = res !== null && typeof res === "object" && res.config !== null && typeof res.config === "object";
506523
const config = res?.config ?? {};
507524
state.vector = {
508525
enabled: config.enabled === true,
@@ -531,6 +548,7 @@ export function mountDshGoPanel(ctx, options = {}) {
531548
// 把用户已经在 Web 面板里配好的端口/地址覆盖掉(评审 #6)。
532549
// 必须带 token=omit:不带的话这条 GET 会顺手生成并落库一个 Bearer。
533550
const res = await call("/external-api?token=omit").catch(() => null);
551+
state.externalLoaded = res !== null && typeof res === "object" && res.config !== null && typeof res.config === "object";
534552
const config = res?.config ?? {};
535553
state.external = {
536554
enabled: config.enabled === true,
@@ -819,11 +837,16 @@ export function mountDshGoPanel(ctx, options = {}) {
819837
const memory = page === "detail" ? loadDetail() : page === "editor" ? loadEditor() : loadMemory();
820838
merge(Promise.resolve(memory));
821839
}
822-
if (full || page === "entity") merge(page === "entity" ? loadEntityDetail() : loadEntity());
823-
if (full || page === "settings" || page === "profile") {
840+
const entityPage = page === "entity";
841+
// 实体搜索要重读实体清单;但搜索后 state.page 仍是 "list"(视图里实体
842+
// 区就是列表),旧条件只看页面,于是搜索完推的仍是搜索前那份(评审 #4)。
843+
if (full || entityPage || state.entityDirty) merge(entityPage ? loadEntityDetail() : loadEntity());
844+
state.entityDirty = false;
845+
if (full || page === "settings" || page === "profile" || state.settingsDirty) {
824846
merge(loadSettings());
825847
merge(loadStatus());
826848
}
849+
state.settingsDirty = false;
827850
if (full || (memoryPage && page === "conflict")) merge(loadConflict());
828851
if (full || page === "profile") merge(loadProfile());
829852
const settled = await Promise.allSettled(jobs);
@@ -1046,7 +1069,7 @@ export function mountDshGoPanel(ctx, options = {}) {
10461069
);
10471070
}
10481071
} catch (error) {
1049-
state.provenanceText = errorText(error).includes("DISTILL_RECORDS_DISABLED")
1072+
state.provenanceText = errorText(error).includes("distill-records-disabled")
10501073
? "mneme 没开「保留蒸馏原文」,所以这条记忆没有可查的来源窗口。"
10511074
: errorText(error);
10521075
}
@@ -1131,6 +1154,8 @@ export function mountDshGoPanel(ctx, options = {}) {
11311154
resetNotice();
11321155
state.entityQuery = String(valueOf(event, ["entityQuery", "query", "q"], "") ?? "").trim();
11331156
state.page = "list";
1157+
// 让下一次 load() 补读实体清单(页面仍是列表,见 load 里的注释)。
1158+
state.entityDirty = true;
11341159
return {};
11351160
},
11361161

@@ -1141,10 +1166,12 @@ export function mountDshGoPanel(ctx, options = {}) {
11411166
return {};
11421167
},
11431168

1144-
edit() {
1169+
edit(scope) {
11451170
resetNotice();
11461171
const memo = state.current;
11471172
if (memo === null) return { toast: "先选一条记忆" };
1173+
// 记下本面板打开的那条:save 也要按它核对(评审 #3)。
1174+
openedBy.set(scopeKey(scope), memo.id);
11481175
state.form = {
11491176
id: memo.id,
11501177
title: memo.title ?? "",
@@ -1206,6 +1233,15 @@ export function mountDshGoPanel(ctx, options = {}) {
12061233
const tags = splitTags(String(source.tags ?? ""));
12071234
if (title === "" || content === "") return { toast: "标题和正文都不能空" };
12081235
const id = state.form.id === "" || state.form.id === undefined ? undefined : String(state.form.id);
1236+
// 编辑既有条目也要核对面板 scope:state.form 是模块级共享的,两个面板
1237+
// 各开一条时,A 面板点保存会把内容写进 B 刚打开的那条(评审 #3)。
1238+
// 新建(id 为空)不涉及已有行,不核对。
1239+
if (id !== undefined) {
1240+
const mine = openedBy.get(scopeKey(scope));
1241+
if (mine === undefined || mine !== id) {
1242+
return { toast: "这条不是当前打开的记忆,已取消" };
1243+
}
1244+
}
12091245

12101246
if (id === undefined) {
12111247
try {
@@ -1473,6 +1509,7 @@ export function mountDshGoPanel(ctx, options = {}) {
14731509
"conflict-pick-row"(scope, event) {
14741510
resetNotice();
14751511
state.conflictId = String(valueOf(event, ["id"], "") ?? "");
1512+
conflictBy.set(scopeKey(scope), state.conflictId);
14761513
state.conflictPick = "";
14771514
state.page = "conflict";
14781515
return {};
@@ -1491,9 +1528,14 @@ export function mountDshGoPanel(ctx, options = {}) {
14911528
if (valueOf(event, ["confirmed"], false) !== true) return {};
14921529
const id = state.conflictId;
14931530
if (id === "") return { toast: "先选一条冲突" };
1531+
// 冲突 id 也是共享状态:只裁决本面板自己选中的那条(评审 #3)。
1532+
if (conflictBy.get(scopeKey(scope)) !== id) {
1533+
return { toast: "这条不是当前打开的冲突,已取消" };
1534+
}
14941535
const winner = state.conflictPick === "a" ? "a" : state.conflictPick === "b" ? "b" : null;
14951536
try {
14961537
await call("/conflicts/resolve", { method: "POST", body: { id, winner, apply: true } });
1538+
conflictBy.delete(scopeKey(scope));
14971539
state.conflictId = "";
14981540
state.conflictPick = "";
14991541
notice("已按裁决合并。");
@@ -1566,6 +1608,8 @@ export function mountDshGoPanel(ctx, options = {}) {
15661608

15671609
"vector-toggle"(scope, event) {
15681610
resetNotice();
1611+
// 没读到真实配置时 state.vector 只是默认值,整体 PUT 会覆盖服务端(评审 #2)。
1612+
if (!state.vectorLoaded) return { toast: "还没读到向量配置,请刷新后再改" };
15691613
const value = event?.value;
15701614
state.vector.enabled = typeof value === "boolean" ? value : !state.vector.enabled;
15711615
return call("/vector-config", {
@@ -1585,6 +1629,7 @@ export function mountDshGoPanel(ctx, options = {}) {
15851629

15861630
"vector-save"(scope, event) {
15871631
resetNotice();
1632+
if (!state.vectorLoaded) return { toast: "还没读到向量配置,请刷新后再改" };
15881633
const value = event?.value;
15891634
const source = value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
15901635
const baseUrl = String(source.sVecUrl ?? state.vector.baseUrl ?? "").trim();
@@ -1626,6 +1671,7 @@ export function mountDshGoPanel(ctx, options = {}) {
16261671

16271672
"external-toggle"(scope, event) {
16281673
resetNotice();
1674+
if (!state.externalLoaded) return { toast: "还没读到外部访问配置,请刷新后再改" };
16291675
const value = event?.value;
16301676
state.external.enabled = typeof value === "boolean" ? value : !state.external.enabled;
16311677
return call("/external-api", {
@@ -1645,6 +1691,7 @@ export function mountDshGoPanel(ctx, options = {}) {
16451691

16461692
"external-save"(scope, event) {
16471693
resetNotice();
1694+
if (!state.externalLoaded) return { toast: "还没读到外部访问配置,请刷新后再改" };
16481695
const value = event?.value;
16491696
const source = value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
16501697
const port = Math.round(num(source.sExtPort ?? state.external.port, 8790));
@@ -1712,6 +1759,7 @@ export function mountDshGoPanel(ctx, options = {}) {
17121759
state.flagOverrides = features?.overrides ?? {};
17131760
state.pendingRestart = Array.isArray(features?.pendingRestart) ? features.pendingRestart : [];
17141761
state.flags = features?.effective ?? state.flags;
1762+
state.settingsDirty = true;
17151763
notice(
17161764
`${FLAG_LABELS.get(key) ?? key}:${
17171765
typeof next === "string" ? next : next ? "已开启" : "已关闭"
@@ -1920,6 +1968,7 @@ export function mountDshGoPanel(ctx, options = {}) {
19201968
state.flagOverrides = features?.overrides ?? {};
19211969
state.pendingRestart = Array.isArray(features?.pendingRestart) ? features.pendingRestart : [];
19221970
state.flags = features?.effective ?? state.flags;
1971+
state.settingsDirty = true;
19231972
notice(`${key}:${next ? "已开启" : "已关闭"}`);
19241973
} catch (error) {
19251974
state.err = errorText(error);
@@ -2022,6 +2071,7 @@ export function resetPanelState() {
20222071
cache.clear();
20232072
emitters.clear();
20242073
openedBy.clear();
2074+
conflictBy.clear();
20252075
lastPayload = null;
20262076
Object.assign(state, defaultState());
20272077
}

‎dsh-mneme/src/api.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,10 @@ export function createApi(ctx, service, settings, commands, embedder, semantic =
398398
const idFilter = (url.searchParams.get("id") ?? "").trim();
399399
const rows = idFilter === ""
400400
? service.list({ type, limit, offset, order, minImportance, source, updatedFrom, updatedTo, onlyArchived, depositedOnly })
401-
: [service.getById(idFilter)].filter(Boolean);
401+
// getById 是裸 SELECT,没有 forgotten 谓词;这条路由是 open 的,
402+
// 不过滤等于让本机任意进程按 id 读到已遗忘记忆的全文(评审 #1)。
403+
// 归档行仍要放行:归档 ≠ 遗忘,面板保存前要用它比对 updated_at。
404+
: [service.getById(idFilter)].filter((memo) => memo && !memo.forgotten);
402405
// 面板行在 wire DTO 之上补 archived/quality_score——模型工具的输出
403406
// schema 严格复用 toApiList,扩展只发生在 HTTP 层。
404407
// heat 投影(阶段二前端数据源):仅 heatEnabled=true 时下发逐条热度

0 commit comments

Comments
 (0)