dsh-trivium 0.4.2 → 0.4.3
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/README.md +6 -3
- package/lib/client.js +123 -10
- package/lib/episode.js +42 -0
- package/lib/server.js +18 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ dsh plugin --profile web add dsh-trivium
|
|
|
54
54
|
|
|
55
55
|
- **跨会话** — 会话 A 记下「鉴权走 header X」,会话 B 调用 `ctx_find("鉴权")` 命中,并带上它连着谁(`about` / `decided` / `broke` / `fixed`)。
|
|
56
56
|
- **默认安静** — 新会话只注入一张短地图(≤400 token)。模型要用再调工具,不会每一步灌满。
|
|
57
|
-
- **会话图** — compaction
|
|
57
|
+
- **会话图** — compaction 切一段就收成一个方框;旧会话可点「更新检查点」补上已经发生过的压缩 / 分叉;勾选的记忆芯片从当前这段的下一轮注入。
|
|
58
58
|
- **人能改错** — 会话图芯片条可新增、归档、删除;设置页管搜、改名 / 正文、合并、全局开关。
|
|
59
59
|
- **抽取偏严** — 闲聊、一次性改文件、密钥**不会从对话自动入库**。芯片「新增」按你写的存(点一次整段一条)。
|
|
60
60
|
- **可选 embedding** — 默认关。官方 DeepSeek 对话接口没有 embeddings;可填 OpenAI 兼容地址。
|
|
@@ -80,6 +80,7 @@ dsh plugin --profile web add dsh-trivium
|
|
|
80
80
|
|
|
81
81
|
- 没压过上下文:只有一个「后续」方框。
|
|
82
82
|
- 一次成功的 compaction 之后:左边历史检查点(摘要来自 DSH),右边仍是「后续」。
|
|
83
|
+
- 装插件之前已经压过 / 分过叉的旧会话:点「更新检查点」,从当前对话里的压缩标记和侧边栏分叉补方框(可重复点,不会双写)。没压过就仍只有「后续」——会话长、工具多不等于 DSH 已经压缩(默认约窗口 80% 才自动压)。
|
|
83
84
|
- 方框自己不压缩。质量来自 DSH 已经做的摘要替换;fork 时不会再总结一遍。
|
|
84
85
|
- 「改名」只改方框标题,不动 DSH 摘要。点方框可跳回对话里对应的检查点,或打开轨迹。
|
|
85
86
|
|
|
@@ -146,7 +147,7 @@ dsh plugin --profile web add dsh-trivium
|
|
|
146
147
|
- 抽取会漏;脏数据可在芯片条归档 / 删除,或到设置里改、合并。
|
|
147
148
|
- 同一个 `.tdb` 不要两个 Node 进程同时打开(正常只开一个 `dsh web` 即可)。
|
|
148
149
|
- Markdown 导出是给人看的,不能再解析回去。WorkBuddy 导入是一次性,不是双向同步。
|
|
149
|
-
- 会话图只投影 compaction 与 fork
|
|
150
|
+
- 会话图只投影 compaction 与 fork,不会按消息条数自己切方框。窗口没到 DSH 压缩线时,「更新检查点」也补不出历史方框。
|
|
150
151
|
- 改插件设置后需要重启 `dsh web`。
|
|
151
152
|
- 宿主升到 rc.8 后,DSH 自己的旧会话库可能打不开(官方 SQLite 格式不兼容)。工作区里的 `.tdb` 图记忆还在;对不上号的旧会话图方框可以当情节残留,不影响 `ctx_find`。
|
|
152
153
|
|
|
@@ -154,6 +155,8 @@ dsh plugin --profile web add dsh-trivium
|
|
|
154
155
|
|
|
155
156
|
## 更新说明
|
|
156
157
|
|
|
158
|
+
**0.4.3** — 会话图「更新检查点」:把当前对话里 DSH 已有的压缩标记和侧边栏 fork 补进图,给装插件之前的旧会话用。没压过的会话仍然只有「后续」。
|
|
159
|
+
|
|
157
160
|
**0.4.2** — 会话图芯片条可新增(整段粘贴一条)、批量归档 / 删除。自动抽取仍偏严;芯片新增按你写的入库。
|
|
158
161
|
|
|
159
162
|
**0.4.1** — 宿主钉到 `@deepseek-ai/dsh@0.1.0-rc.8`。功能与 0.4.0 相同。已在 rc.8 上确认:设置「Trivium 记忆」、新会话短地图、跨会话 `ctx_find`、会话图标签。
|
|
@@ -165,6 +168,6 @@ dsh plugin --profile web add dsh-trivium
|
|
|
165
168
|
## 发布信息
|
|
166
169
|
|
|
167
170
|
- GitHub: https://github.com/QWQcool/dsh-trivium
|
|
168
|
-
- npm: [`dsh-trivium@0.4.
|
|
171
|
+
- npm: [`dsh-trivium@0.4.3`](https://www.npmjs.com/package/dsh-trivium)
|
|
169
172
|
- 测试宿主:`@deepseek-ai/dsh@0.1.0-rc.8`
|
|
170
173
|
- License: MIT(依赖 [TriviumDB](https://github.com/TriviumDB/triviumdb) 为 Apache-2.0)
|
package/lib/client.js
CHANGED
|
@@ -980,6 +980,67 @@ window.__ModuleLoader__.load({
|
|
|
980
980
|
return best;
|
|
981
981
|
}
|
|
982
982
|
|
|
983
|
+
function collectChatCompactions(chat) {
|
|
984
|
+
const nodes = chat?.nodes;
|
|
985
|
+
if (!nodes || typeof nodes.values !== "function") return [];
|
|
986
|
+
const rows = [];
|
|
987
|
+
const seen = new Set();
|
|
988
|
+
for (const n of nodes.values()) {
|
|
989
|
+
const kind = n.kind;
|
|
990
|
+
const data = n.data || {};
|
|
991
|
+
let seq;
|
|
992
|
+
let summary = "";
|
|
993
|
+
let compactionId = "";
|
|
994
|
+
if (kind === "compaction") {
|
|
995
|
+
seq = Number(n.anchorSeq ?? data.seq);
|
|
996
|
+
summary = String(data.summary || "");
|
|
997
|
+
compactionId = String(data.compactionId || data.id || "");
|
|
998
|
+
} else if (kind === "manual-compaction") {
|
|
999
|
+
const landed = data.compaction;
|
|
1000
|
+
if (!landed) continue;
|
|
1001
|
+
seq = Number(landed.seq ?? n.anchorSeq ?? data.command?.seq);
|
|
1002
|
+
summary = String(landed.summary || "");
|
|
1003
|
+
compactionId = String(landed.compactionId || data.command?.commandId || "");
|
|
1004
|
+
} else continue;
|
|
1005
|
+
if (!Number.isFinite(seq) || seen.has(seq)) continue;
|
|
1006
|
+
seen.add(seq);
|
|
1007
|
+
rows.push({ atSeq: seq, compactionId, summary });
|
|
1008
|
+
}
|
|
1009
|
+
return rows.sort((a, b) => a.atSeq - b.atSeq);
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
function parentIdOf(row) {
|
|
1013
|
+
return String(row?.parentSessionId || row?.parentId || "");
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
function collectSessionForks(sessionId, byId, seedLengthOf) {
|
|
1017
|
+
const forks = [];
|
|
1018
|
+
const seen = new Set();
|
|
1019
|
+
const add = (childId, parentId) => {
|
|
1020
|
+
const child = String(childId || "");
|
|
1021
|
+
const parent = String(parentId || "");
|
|
1022
|
+
if (!child || !parent || seen.has(child + ":" + parent)) return;
|
|
1023
|
+
const row = byId[child];
|
|
1024
|
+
if (row?.origin === "subagent") return;
|
|
1025
|
+
seen.add(child + ":" + parent);
|
|
1026
|
+
const seed = typeof seedLengthOf === "function" ? seedLengthOf(child) : null;
|
|
1027
|
+
const n = Number(seed);
|
|
1028
|
+
forks.push({
|
|
1029
|
+
childSessionId: child,
|
|
1030
|
+
parentSessionId: parent,
|
|
1031
|
+
atSeq: Number.isFinite(n) && n > 0 ? n - 1 : undefined,
|
|
1032
|
+
});
|
|
1033
|
+
};
|
|
1034
|
+
const mine = String(sessionId || "");
|
|
1035
|
+
const rows = byId || {};
|
|
1036
|
+
add(mine, parentIdOf(rows[mine]));
|
|
1037
|
+
for (const id of Object.keys(rows)) {
|
|
1038
|
+
const parent = parentIdOf(rows[id]);
|
|
1039
|
+
if (parent && (parent === mine || id === mine)) add(id, parent);
|
|
1040
|
+
}
|
|
1041
|
+
return forks;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
983
1044
|
function scrollConversation({ key, bottom }) {
|
|
984
1045
|
let n = 0;
|
|
985
1046
|
const tick = () => {
|
|
@@ -1669,7 +1730,7 @@ window.__ModuleLoader__.load({
|
|
|
1669
1730
|
|
|
1670
1731
|
let pendingSessionNav = null;
|
|
1671
1732
|
|
|
1672
|
-
function SessionMapView({ sessionId, useSessions, useSession, fork, open, renameSession, actions }) {
|
|
1733
|
+
function SessionMapView({ sessionId, useSessions, useSession, fork, open, renameSession, actions, seedLengthOf }) {
|
|
1673
1734
|
const canSetView = typeof actions?.setView === "function";
|
|
1674
1735
|
const chat = useSession((s) => s.chat);
|
|
1675
1736
|
const cwd = useSessions((s) => (sessionId == null ? "" : s.byId[sessionId]?.cwd || ""));
|
|
@@ -1701,6 +1762,7 @@ window.__ModuleLoader__.load({
|
|
|
1701
1762
|
const [draftOpen, setDraftOpen] = react.useState(false);
|
|
1702
1763
|
const [draftText, setDraftText] = react.useState("");
|
|
1703
1764
|
const [forkDraft, setForkDraft] = react.useState(null);
|
|
1765
|
+
const [backfillNote, setBackfillNote] = react.useState("");
|
|
1704
1766
|
const canvasRef = react.useRef(null);
|
|
1705
1767
|
const dragRef = react.useRef(null);
|
|
1706
1768
|
const userMovedRef = react.useRef(false);
|
|
@@ -1759,6 +1821,34 @@ window.__ModuleLoader__.load({
|
|
|
1759
1821
|
}
|
|
1760
1822
|
}, [qs, sessionId]);
|
|
1761
1823
|
|
|
1824
|
+
const syncCheckpoints = async () => {
|
|
1825
|
+
if (!sessionId || busy) return;
|
|
1826
|
+
setBusy(true);
|
|
1827
|
+
setError("");
|
|
1828
|
+
try {
|
|
1829
|
+
const compactations = collectChatCompactions(chat);
|
|
1830
|
+
const forks = collectSessionForks(sessionId, sessionById, seedLengthOf);
|
|
1831
|
+
const resp = await api("/api/dsh-trivium/map/backfill" + qs, {
|
|
1832
|
+
method: "POST",
|
|
1833
|
+
headers: { "content-type": "application/json" },
|
|
1834
|
+
body: JSON.stringify({ sessionId, compactations, forks }),
|
|
1835
|
+
});
|
|
1836
|
+
setNodes(resp.nodes || []);
|
|
1837
|
+
setEdges(resp.edges || []);
|
|
1838
|
+
const checks = Number(resp.checkpoints) || 0;
|
|
1839
|
+
const forkN = Number(resp.forks) || 0;
|
|
1840
|
+
if (!checks && !forkN) {
|
|
1841
|
+
setBackfillNote("没有发现压缩标记或分叉。没压过的会话本来就只有「后续」。");
|
|
1842
|
+
} else {
|
|
1843
|
+
setBackfillNote("已同步 " + checks + " 个检查点、" + forkN + " 条分叉。");
|
|
1844
|
+
}
|
|
1845
|
+
} catch (err) {
|
|
1846
|
+
setError(String(err.message || err));
|
|
1847
|
+
} finally {
|
|
1848
|
+
setBusy(false);
|
|
1849
|
+
}
|
|
1850
|
+
};
|
|
1851
|
+
|
|
1762
1852
|
react.useEffect(() => {
|
|
1763
1853
|
load();
|
|
1764
1854
|
}, [load, lineageKey]);
|
|
@@ -2055,17 +2145,31 @@ window.__ModuleLoader__.load({
|
|
|
2055
2145
|
jsx("div", {
|
|
2056
2146
|
style: mapUi.hint,
|
|
2057
2147
|
children:
|
|
2148
|
+
backfillNote ||
|
|
2058
2149
|
"共 " +
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2150
|
+
chips.length +
|
|
2151
|
+
" 条,已钉 " +
|
|
2152
|
+
pinIds.length +
|
|
2153
|
+
"。默认不勾选:不钉就不会按芯片白名单注入,但仍可能被开场短地图点名带上,模型也能 find 到。",
|
|
2063
2154
|
}),
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2155
|
+
jsxs("div", {
|
|
2156
|
+
style: mapUi.chipsActions,
|
|
2157
|
+
children: [
|
|
2158
|
+
jsx("button", {
|
|
2159
|
+
type: "button",
|
|
2160
|
+
style: mapUi.actionBtn,
|
|
2161
|
+
disabled: busy,
|
|
2162
|
+
title: "读取当前对话里 DSH 已有的压缩标记和侧边栏分叉,生成检查点方框。给插件装上之前的旧会话用。",
|
|
2163
|
+
onClick: syncCheckpoints,
|
|
2164
|
+
children: busy ? "更新中…" : "更新检查点",
|
|
2165
|
+
}),
|
|
2166
|
+
jsx("button", {
|
|
2167
|
+
type: "button",
|
|
2168
|
+
style: mapUi.actionBtn,
|
|
2169
|
+
onClick: () => setChipsOpen((v) => !v),
|
|
2170
|
+
children: chipsOpen ? "收起" : "展开勾选",
|
|
2171
|
+
}),
|
|
2172
|
+
],
|
|
2069
2173
|
}),
|
|
2070
2174
|
],
|
|
2071
2175
|
}),
|
|
@@ -2406,6 +2510,15 @@ window.__ModuleLoader__.load({
|
|
|
2406
2510
|
inject: () => ({
|
|
2407
2511
|
fork: (opts) => sessions.fork(opts),
|
|
2408
2512
|
open: (id) => sessions.open(id),
|
|
2513
|
+
seedLengthOf: (id) => {
|
|
2514
|
+
try {
|
|
2515
|
+
const seed = sessions.binding?.(id)?.session?.header?.seedLength;
|
|
2516
|
+
const n = Number(seed);
|
|
2517
|
+
return Number.isFinite(n) && n > 0 ? n : null;
|
|
2518
|
+
} catch {
|
|
2519
|
+
return null;
|
|
2520
|
+
}
|
|
2521
|
+
},
|
|
2409
2522
|
renameSession: async (id, title) => {
|
|
2410
2523
|
const face = sessions.binding?.(id)?.session;
|
|
2411
2524
|
if (!face || typeof face.rename !== "function") {
|
package/lib/episode.js
CHANGED
|
@@ -203,6 +203,48 @@ export function syncForkLineage(db, { childSessionId, parentSessionId, atSeq } =
|
|
|
203
203
|
return { cutId, childTail };
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
+
/**
|
|
207
|
+
* Project DSH's already-landed compactations and fork list onto episode boxes.
|
|
208
|
+
* Idempotent: same atSeq / child reuses the existing node.
|
|
209
|
+
*/
|
|
210
|
+
export function backfillSessionMap(db, { sessionId, compactations = [], forks = [] } = {}) {
|
|
211
|
+
const sid = String(sessionId || "");
|
|
212
|
+
let checkpoints = 0;
|
|
213
|
+
const seenSeq = new Set();
|
|
214
|
+
for (const raw of compactations || []) {
|
|
215
|
+
const atSeq = Number(raw.atSeq);
|
|
216
|
+
if (!sid || !Number.isFinite(atSeq) || seenSeq.has(atSeq)) continue;
|
|
217
|
+
seenSeq.add(atSeq);
|
|
218
|
+
const id = recordCheckpoint(db, {
|
|
219
|
+
sessionId: sid,
|
|
220
|
+
atSeq,
|
|
221
|
+
compactionId: raw.compactionId,
|
|
222
|
+
summary: raw.summary,
|
|
223
|
+
});
|
|
224
|
+
if (id != null) checkpoints += 1;
|
|
225
|
+
}
|
|
226
|
+
if (sid) ensureTail(db, sid);
|
|
227
|
+
let forkLinks = 0;
|
|
228
|
+
for (const raw of forks || []) {
|
|
229
|
+
const child = String(raw.childSessionId || "");
|
|
230
|
+
const parent = String(raw.parentSessionId || "");
|
|
231
|
+
if (!child || !parent) continue;
|
|
232
|
+
const atSeq = Number.isFinite(Number(raw.atSeq)) ? Number(raw.atSeq) : undefined;
|
|
233
|
+
const result = syncForkLineage(db, {
|
|
234
|
+
childSessionId: child,
|
|
235
|
+
parentSessionId: parent,
|
|
236
|
+
atSeq,
|
|
237
|
+
});
|
|
238
|
+
if (result?.childTail != null) forkLinks += 1;
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
ok: true,
|
|
242
|
+
checkpoints,
|
|
243
|
+
forks: forkLinks,
|
|
244
|
+
...sessionMapSnapshot(db, sid),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
206
248
|
export function sessionMapSnapshot(db, sessionId) {
|
|
207
249
|
const sid = String(sessionId || "");
|
|
208
250
|
const all = listEpisodeRecords(db);
|
package/lib/server.js
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
import { embeddingPublicStatus } from "./embed.js";
|
|
18
18
|
import { recallModeOf, writeUiSettings } from "./settings.js";
|
|
19
19
|
import { discoverWorkbuddyFiles, exportMarkdown, importWorkbuddy } from "./markdown.js";
|
|
20
|
-
import { renameEpisode, sessionMapSnapshot } from "./episode.js";
|
|
20
|
+
import { backfillSessionMap, renameEpisode, sessionMapSnapshot } from "./episode.js";
|
|
21
21
|
import { applyPinsUpdate, addChipsFromText, batchChipAction, listChips, readSessionPins } from "./pins.js";
|
|
22
22
|
|
|
23
23
|
export { readUiSettings, writeUiSettings } from "./settings.js";
|
|
@@ -272,6 +272,23 @@ async function handle(req, res, { liveOptions, status }) {
|
|
|
272
272
|
return;
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
+
if (path === "/api/dsh-trivium/map/backfill" && method === "POST") {
|
|
276
|
+
const { cwd, db } = await dbForRequest(url);
|
|
277
|
+
if (!db) {
|
|
278
|
+
sendJson(res, 400, { ok: false, message: "no workspace" });
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const body = JSON.parse((await readBody(req)) || "{}");
|
|
282
|
+
const sessionId = body.sessionId || url.searchParams.get("sessionId") || "";
|
|
283
|
+
const result = backfillSessionMap(db, {
|
|
284
|
+
sessionId,
|
|
285
|
+
compactations: body.compactations,
|
|
286
|
+
forks: body.forks,
|
|
287
|
+
});
|
|
288
|
+
sendJson(res, 200, { ok: true, cwd, sessionId, ...result });
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
|
|
275
292
|
if (path === "/api/dsh-trivium/chips" && method === "GET") {
|
|
276
293
|
const { cwd, db } = await dbForRequest(url);
|
|
277
294
|
const q = url.searchParams.get("q") || "";
|