@modusensus/dsh-mneme 0.11.0 → 0.13.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/README.md +54 -21
- package/docs/CONFIGURATION.md +45 -4
- package/docs/DIRECTORIES.md +114 -0
- package/docs/DISTILL.md +64 -0
- package/docs/DSH-GO.md +97 -0
- package/docs/ENTITIES.md +5 -3
- package/docs/FORGET.md +77 -0
- package/docs/KB.md +110 -0
- package/docs/SLEEP.md +28 -3
- package/docs/STORAGE.md +23 -0
- package/lib/api-standalone.js +4 -1
- package/lib/api.js +744 -26
- package/lib/attachment-text.js +122 -0
- package/lib/choro-command.js +9 -2
- package/lib/client.js +3752 -819
- package/lib/config.js +171 -2
- package/lib/continuity.js +7 -6
- package/lib/diary/auto.js +190 -0
- package/lib/diary/compose.js +440 -0
- package/lib/diary/dir.js +59 -0
- package/lib/diary/export.js +97 -0
- package/lib/diary/index.js +26 -0
- package/lib/diary/library.js +189 -0
- package/lib/diary/qq-inbox.js +142 -0
- package/lib/diary/rollover.js +61 -0
- package/lib/diary/session-provider.js +122 -0
- package/lib/document.js +9 -3
- package/lib/dream/clustering.js +6 -1
- package/lib/dream/decisions.js +56 -5
- package/lib/dream/sleep.js +616 -15
- package/lib/dream.js +45 -13
- package/lib/dsh-go/host.js +162 -0
- package/lib/dsh-go/panel.js +2091 -0
- package/lib/dsh-go/text.js +342 -0
- package/lib/dsh-go/views/common.js +68 -0
- package/lib/dsh-go/views/entity.js +48 -0
- package/lib/dsh-go/views/memory.js +198 -0
- package/lib/dsh-go/views/root.js +30 -0
- package/lib/dsh-go/views/settings.js +398 -0
- package/lib/dsh-go/views/status.js +51 -0
- package/lib/embedding.js +42 -8
- package/lib/entities/extractor.js +36 -7
- package/lib/hot-memory.js +8 -9
- package/lib/index.js +131 -5
- package/lib/inject.js +192 -19
- package/lib/kb/index.js +309 -0
- package/lib/kb/routes.js +220 -0
- package/lib/kb/tools.js +148 -0
- package/lib/lang.js +115 -4
- package/lib/peak-hours.js +57 -2
- package/lib/profile-facts.js +356 -0
- package/lib/semantic.js +347 -60
- package/lib/service.js +302 -70
- package/lib/settings.js +117 -14
- package/lib/store.js +830 -55
- package/lib/summarize.js +38 -11
- package/lib/tools.js +173 -25
- package/lib/user-settings.js +175 -23
- package/lib/vector-index.js +76 -6
- package/lib/wiki/cli-hint.js +90 -0
- package/lib/wiki/queries.js +264 -10
- package/lib/wiki/t1-jobs.js +232 -0
- package/lib/wiki/t1.js +7 -1
- package/package.json +25 -1
- package/scripts/sync-test-badge.mjs +1 -1
- package/scripts/test-count-sync.mjs +9 -5
- package/src/api-standalone.js +4 -1
- package/src/api.js +744 -26
- package/src/attachment-text.js +122 -0
- package/src/choro-command.js +9 -2
- package/src/config.js +171 -2
- package/src/continuity.js +7 -6
- package/src/diary/auto.js +190 -0
- package/src/diary/compose.js +440 -0
- package/src/diary/dir.js +59 -0
- package/src/diary/export.js +97 -0
- package/src/diary/index.js +26 -0
- package/src/diary/library.js +189 -0
- package/src/diary/qq-inbox.js +142 -0
- package/src/diary/rollover.js +61 -0
- package/src/diary/session-provider.js +122 -0
- package/src/document.js +9 -3
- package/src/dream/clustering.js +6 -1
- package/src/dream/decisions.js +56 -5
- package/src/dream/sleep.js +616 -15
- package/src/dream.js +45 -13
- package/src/dsh-go/host.js +162 -0
- package/src/dsh-go/panel.js +2091 -0
- package/src/dsh-go/text.js +342 -0
- package/src/dsh-go/views/common.js +68 -0
- package/src/dsh-go/views/entity.js +48 -0
- package/src/dsh-go/views/memory.js +198 -0
- package/src/dsh-go/views/root.js +30 -0
- package/src/dsh-go/views/settings.js +398 -0
- package/src/dsh-go/views/status.js +51 -0
- package/src/embedding.js +42 -8
- package/src/entities/extractor.js +36 -7
- package/src/hot-memory.js +8 -9
- package/src/index.js +131 -5
- package/src/inject.js +192 -19
- package/src/kb/index.js +309 -0
- package/src/kb/routes.js +220 -0
- package/src/kb/tools.js +148 -0
- package/src/lang.js +115 -4
- package/src/peak-hours.js +57 -2
- package/src/profile-facts.js +356 -0
- package/src/semantic.js +347 -60
- package/src/service.js +302 -70
- package/src/settings.js +117 -14
- package/src/store.js +830 -55
- package/src/summarize.js +38 -11
- package/src/tools.js +173 -25
- package/src/user-settings.js +175 -23
- package/src/vector-index.js +76 -6
- package/src/wiki/cli-hint.js +90 -0
- package/src/wiki/queries.js +264 -10
- package/src/wiki/t1-jobs.js +232 -0
- package/src/wiki/t1.js +7 -1
- package/test/api-routes-gaps.test.js +63 -0
- package/test/api.test.js +377 -4
- package/test/attachment-text.test.js +140 -0
- package/test/bm25-corpus-cache.test.js +145 -0
- package/test/capacity-warning.test.js +262 -0
- package/test/client.test.js +908 -138
- package/test/config.test.js +79 -0
- package/test/conflict-freeze.test.js +45 -1
- package/test/continuity.test.js +8 -1
- package/test/diary-library.test.js +187 -0
- package/test/diary.test.js +576 -0
- package/test/document.test.js +32 -0
- package/test/dream-maxtokens-fallback.test.js +3 -3
- package/test/dream.test.js +62 -1
- package/test/dsh-go-host.test.js +134 -0
- package/test/dsh-go-panel-actions.test.js +854 -0
- package/test/dsh-go-panel.test.js +251 -0
- package/test/embedding-cache-f32.test.js +276 -0
- package/test/embedding-ready.test.js +33 -3
- package/test/entities.test.js +73 -0
- package/test/forget-corrections.test.js +70 -0
- package/test/image-memory.test.js +171 -0
- package/test/inject-pin-explicit.test.js +300 -0
- package/test/inject-pin-vector-crowd.test.js +225 -0
- package/test/issue-617-step1-query-and-fusion.test.js +361 -0
- package/test/kb-api-wiring.test.js +128 -0
- package/test/kb-collections.test.js +272 -0
- package/test/kb-routes.test.js +379 -0
- package/test/mint-source.test.js +26 -0
- package/test/peak-hours-observability.test.js +70 -0
- package/test/persona-api.test.js +3 -3
- package/test/persona-by-session.test.js +568 -0
- package/test/persona-settings.test.js +38 -7
- package/test/profile-facts.test.js +492 -0
- package/test/reflection-update-gate.test.js +129 -0
- package/test/reindex-backfill.test.js +334 -0
- package/test/reindex-scheduler.test.js +369 -0
- package/test/scope-candidates.test.js +249 -0
- package/test/session-gate.test.js +1 -1
- package/test/sleep-action-set.test.js +14 -0
- package/test/sleep-heat.test.js +49 -0
- package/test/sleep.test.js +598 -0
- package/test/standalone-api.test.js +24 -0
- package/test/store.test.js +20 -0
- package/test/summarize.test.js +26 -0
- package/test/test-count-sync.test.js +14 -3
- package/test/tool-state-ignore.test.js +65 -0
- package/test/tools-dto-schema-matrix.test.js +23 -2
- package/test/tools.test.js +144 -7
- package/test/user-settings-segments.test.js +528 -0
- package/test/vector-index.test.js +120 -6
- package/test/wiki-api.test.js +476 -1
- package/test/wiki-cli-hint.test.js +118 -0
- package/test/wiki-queries.test.js +91 -1
- package/test/wiki-t1-jobs.test.js +125 -0
- package/test/wiki-tools.test.js +131 -76
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// 图块抽取:会话消息里的 `type:"image"` 块到纯文本占位(Issue #611)。
|
|
2
|
+
//
|
|
3
|
+
// 为什么单独一个模块:在本次改动之前,`textOf` 的实现在 summarize / continuity /
|
|
4
|
+
// hot-memory 三处各有一份副本(各写一份的理由不同,注释里都写了)。三份都是
|
|
5
|
+
// `p?.type && p.type !== "text"` → 空串,于是图片一律被丢。给三份各加一遍 image
|
|
6
|
+
// 分支,等于给同一件事写三份实现——而这三份本来就该同一个口径。所以为 image
|
|
7
|
+
// 单独抽一个**只做一件事**的模块:给定一个 content 块,回答它的可读文本。
|
|
8
|
+
//
|
|
9
|
+
// 口径(维护者 2026-11-08 定,先只做 off 档):
|
|
10
|
+
// - 不调 vision、不读字节、不落原图。宿主有 `attachments.readImage()`,但记忆库
|
|
11
|
+
// 已 273MB,原图档明确不做。
|
|
12
|
+
// - 占位形如 `[图: 屏幕截图 2026-10-19.png]`,带文件名与宽高,够人回看时定位;
|
|
13
|
+
// 拿不到名字时退化成 `[图: image/png]`、再退化成 `[图]`,**绝不返回空串**——
|
|
14
|
+
// 返回空串正是本次要修的那个 bug(图-only 消息整条被丢,静默)。
|
|
15
|
+
// - 这里只回答「这一块读出什么文本」,不回答「这个模型能不能看图」。后者要看
|
|
16
|
+
// `llm.resolveModelInfo(...).inputModalities`,属于描述档的准入判断,本批不做。
|
|
17
|
+
|
|
18
|
+
/** 图片块的占位前缀:审计与测试都按它计数。 */
|
|
19
|
+
export const IMAGE_PLACEHOLDER_PREFIX = "[图";
|
|
20
|
+
|
|
21
|
+
/** 标签里单段元数据的长度上限。文件名可以任意长,但占位不该被一个长名字撑开。 */
|
|
22
|
+
const LABEL_PART_MAX = 80;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 把一段外部可写的元数据(文件名 / mediaType)压成占位符里安全的一段。
|
|
26
|
+
*
|
|
27
|
+
* 为什么必须做:占位形如 `[图: <name>]`,而 `name` 是**外部可写的字符串**(附件的
|
|
28
|
+
* 原始文件名,用户可以随便起)。名字里出现 `]` 就能提前闭合占位,后面的内容随
|
|
29
|
+
* 即冒充占位符之外的正文——那是把元数据升格成转录文本的一条路,和 `#493` 的
|
|
30
|
+
* 围栏断链是同一类问题。换行同理:一段元数据不该能凭空造出一行「用户:…」。
|
|
31
|
+
* 所以 `[`、`]`、控制字符、连续空白一律折成单个空格,再按长度截断。
|
|
32
|
+
*
|
|
33
|
+
* @param {unknown} value
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/
|
|
36
|
+
function sanitizeLabelPart(value) {
|
|
37
|
+
if (typeof value !== "string") return "";
|
|
38
|
+
// eslint-disable-next-line no-control-regex
|
|
39
|
+
const flattened = value.replace(/[\u0000-\u001f\u007f[\]\\]/g, " ").replace(/\s+/g, " ").trim();
|
|
40
|
+
if (flattened.length <= LABEL_PART_MAX) return flattened;
|
|
41
|
+
// 按 UTF-16 长度切会切在代理对中间(emoji 占两个单元),留下一个孤立的高位代理——
|
|
42
|
+
// 那一半写进 SQLite 就是 `�`,落盘后原文再也拼不回来(CodeRabbit 2026-11-08 指出)。
|
|
43
|
+
// 所以先切到上限,再回头检查末位是不是高位代理:是就再退一格。
|
|
44
|
+
let cut = flattened.slice(0, LABEL_PART_MAX - 1);
|
|
45
|
+
const last = cut.charCodeAt(cut.length - 1);
|
|
46
|
+
if (last >= 0xd800 && last <= 0xdbff) cut = cut.slice(0, -1);
|
|
47
|
+
return `${cut}…`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 一个图片块读出的人类可读标签(不含方括号)。什么元数据都没有时返回空串。 */
|
|
51
|
+
export function imageLabel(block) {
|
|
52
|
+
const attachment = block?.attachment ?? {};
|
|
53
|
+
const name = sanitizeLabelPart(attachment.name);
|
|
54
|
+
const mediaType = sanitizeLabelPart(attachment.mediaType);
|
|
55
|
+
const width = Number.isFinite(attachment.width) ? attachment.width : undefined;
|
|
56
|
+
const height = Number.isFinite(attachment.height) ? attachment.height : undefined;
|
|
57
|
+
const size = width !== undefined && height !== undefined ? `${width}x${height}` : "";
|
|
58
|
+
// 没有名字也没有 mediaType 时返回空串,由调用方退化成裸 `[图]`——宁可写「有一张图」,
|
|
59
|
+
// 也不要写「[图: image]」这种把类型名当名字的假标签。
|
|
60
|
+
const head = name || mediaType;
|
|
61
|
+
if (!head) return "";
|
|
62
|
+
const tail = [mediaType && name ? mediaType : "", size].filter(Boolean).join(" ");
|
|
63
|
+
return tail ? `${head} ${tail}` : head;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 把一个 content 块读成文本。
|
|
68
|
+
*
|
|
69
|
+
* @param {unknown} block content 数组里的一项
|
|
70
|
+
* @param {object} [options]
|
|
71
|
+
* @param {boolean} [options.imagePlaceholder=true] false 时图片块返回空串(旧行为,
|
|
72
|
+
* 留给需要严格「只要文字」的调用方,例如把同一批内容喂给不支持图的模型)。
|
|
73
|
+
* @returns {string}
|
|
74
|
+
*/
|
|
75
|
+
export function blockToText(block, options = {}) {
|
|
76
|
+
if (typeof block === "string") return block;
|
|
77
|
+
if (!block || typeof block !== "object") return "";
|
|
78
|
+
if (block.type === "image") {
|
|
79
|
+
if (options.imagePlaceholder === false) return "";
|
|
80
|
+
const label = imageLabel(block);
|
|
81
|
+
return label ? `${IMAGE_PLACEHOLDER_PREFIX}: ${label}]` : `${IMAGE_PLACEHOLDER_PREFIX}]`;
|
|
82
|
+
}
|
|
83
|
+
if (block.type === undefined || block.type === "text") {
|
|
84
|
+
return typeof block.text === "string" ? block.text : "";
|
|
85
|
+
}
|
|
86
|
+
// reasoning 等私有块:刻意不采集(各调用方的注释都写了理由,这里不重复)。
|
|
87
|
+
return "";
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 把一个 content 数组读成多行文本。字符串数组(宽松形状)与严格块数组都认。
|
|
92
|
+
*
|
|
93
|
+
* @param {unknown} content
|
|
94
|
+
* @param {object} [options] 透传给 blockToText
|
|
95
|
+
* @returns {string}
|
|
96
|
+
*/
|
|
97
|
+
export function contentToText(content, options = {}) {
|
|
98
|
+
if (typeof content === "string") return content;
|
|
99
|
+
if (!Array.isArray(content)) return "";
|
|
100
|
+
return content
|
|
101
|
+
.map((block) => blockToText(block, options))
|
|
102
|
+
.filter((s) => s)
|
|
103
|
+
.join("\n");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 数一段 content 里有几个图片块(审计用)。
|
|
108
|
+
*
|
|
109
|
+
* 为什么单独一个函数而不是在 contentToText 里顺带返回:调用方要的是「这一窗有多少
|
|
110
|
+
* 张图」这个数,而 contentToText 的返回值是字符串,签名不想为一个计量改成对象。
|
|
111
|
+
*
|
|
112
|
+
* @param {unknown} content
|
|
113
|
+
* @returns {number}
|
|
114
|
+
*/
|
|
115
|
+
export function countImages(content) {
|
|
116
|
+
if (!Array.isArray(content)) return 0;
|
|
117
|
+
let n = 0;
|
|
118
|
+
for (const block of content) {
|
|
119
|
+
if (block && typeof block === "object" && block.type === "image") n += 1;
|
|
120
|
+
}
|
|
121
|
+
return n;
|
|
122
|
+
}
|
package/lib/choro-command.js
CHANGED
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
import { gitHead } from "./wiki/t0.js";
|
|
8
8
|
import { renderChoroBlock } from "./wiki/inject.js";
|
|
9
9
|
import { STR } from "./lang.js";
|
|
10
|
+
// #607:提示里的 CLI 命令必须给绝对路径入口(profile 装的插件没有全局 shim),
|
|
11
|
+
// 光写 `dsh-mneme-choro` 让用户照抄只会 command not found。推导不出入口时
|
|
12
|
+
// 返回 null,文案退回通用说法——宁可少说,也不给一条跑不起来的命令。
|
|
13
|
+
import { choroCliCommandFrom } from "./wiki/cli-hint.js";
|
|
10
14
|
|
|
11
15
|
export const CHORO_COMMAND = "choro";
|
|
12
16
|
|
|
@@ -46,6 +50,9 @@ function staleness(repo) {
|
|
|
46
50
|
* @param {() => string} [opts.language]
|
|
47
51
|
*/
|
|
48
52
|
export function createChoroHandler({ choro, config, language = () => "zh" } = {}) {
|
|
53
|
+
// 本文件在 `src/` 与 `lib/` 的同一层(bin/ 的父级),推导一次就够,不必每次
|
|
54
|
+
// 报错都去碰文件系统。
|
|
55
|
+
const cli = choroCliCommandFrom(import.meta.url, language() === "en" ? "<repo path>" : "<仓库路径>");
|
|
49
56
|
return (invocation) => {
|
|
50
57
|
const lang = language() === "en" ? "en" : "zh";
|
|
51
58
|
const S = STR.choroCommandUsage[lang];
|
|
@@ -58,7 +65,7 @@ export function createChoroHandler({ choro, config, language = () => "zh" } = {}
|
|
|
58
65
|
const cwd = typeof raw === "string" ? raw.trim() : "";
|
|
59
66
|
if (!cwd) return { kind: "error", text: S.noCwd };
|
|
60
67
|
const repo = choro ? choro.repoByCwd(cwd) : null;
|
|
61
|
-
if (!repo) return { kind: "error", text: S.noRepo(cwd) };
|
|
68
|
+
if (!repo) return { kind: "error", text: S.noRepo(cwd, cli) };
|
|
62
69
|
const outline = choro.outline(repo.id);
|
|
63
70
|
if (!outline || outline.modules.length === 0) {
|
|
64
71
|
return { kind: "success", text: S.title(repo.name, 0, dateOnly(repo.updated_at)) + "\n" + S.empty };
|
|
@@ -76,7 +83,7 @@ export function createChoroHandler({ choro, config, language = () => "zh" } = {}
|
|
|
76
83
|
if (rest > 0) lines.push(S.truncated(rest));
|
|
77
84
|
const head = staleness(repo);
|
|
78
85
|
if (head.state === "fresh") lines.push(S.fresh(shortSha(head.head)));
|
|
79
|
-
else if (head.state === "stale") lines.push(S.stale(shortSha(head.baseline), shortSha(head.head)));
|
|
86
|
+
else if (head.state === "stale") lines.push(S.stale(shortSha(head.baseline), shortSha(head.head), cli));
|
|
80
87
|
else lines.push(S.noGit);
|
|
81
88
|
lines.push(S.hint);
|
|
82
89
|
return { kind: "success", text: lines.filter(Boolean).join("\n") };
|