@kenz1117/dsh-engram 0.11.1 → 0.11.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/CHANGELOG.md +20 -1
- package/icon-256.svg +38 -38
- package/icon.svg +38 -27
- package/lib/client.js +3 -3
- package/lib/client.js.map +1 -1
- package/lib/index.js +145 -52
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -2306,6 +2306,16 @@ const en = {
|
|
|
2306
2306
|
profileDiffTarget: "Compare version",
|
|
2307
2307
|
profileDiffNone: "The two versions are identical",
|
|
2308
2308
|
profileLoadFailed: "Failed to load profile",
|
|
2309
|
+
aboutDesc: "Local-first cross-session long-term memory palace",
|
|
2310
|
+
aboutAuthor: "Author",
|
|
2311
|
+
aboutRepo: "Repository",
|
|
2312
|
+
aboutNpm: "npm",
|
|
2313
|
+
aboutLicense: "License",
|
|
2314
|
+
moreWorksTitle: "More plugins",
|
|
2315
|
+
adBillingName: "Usage Billing",
|
|
2316
|
+
adBillingDesc: "Real usage · history ledger · peak/valley pricing · subscription quota",
|
|
2317
|
+
adRainbowName: "RainbowSpeak",
|
|
2318
|
+
adRainbowDesc: "A flowing rainbow border + Xiao-Hong the window pet",
|
|
2309
2319
|
tabEpisodes: "Episodes",
|
|
2310
2320
|
episodeSince: "From date",
|
|
2311
2321
|
episodeUntil: "To date",
|
|
@@ -2867,6 +2877,16 @@ const ru = {
|
|
|
2867
2877
|
profileDiffTarget: "Версия для сравнения",
|
|
2868
2878
|
profileDiffNone: "Версии идентичны",
|
|
2869
2879
|
profileLoadFailed: "Не удалось загрузить профиль",
|
|
2880
|
+
aboutDesc: "Локальная межсессионная долговременная память · дворец памяти",
|
|
2881
|
+
aboutAuthor: "Автор",
|
|
2882
|
+
aboutRepo: "Репозиторий",
|
|
2883
|
+
aboutNpm: "npm",
|
|
2884
|
+
aboutLicense: "Лицензия",
|
|
2885
|
+
moreWorksTitle: "Другие плагины",
|
|
2886
|
+
adBillingName: "Usage Billing",
|
|
2887
|
+
adBillingDesc: "Реальное использование · история · тарифы пик/долина · квоты подписки",
|
|
2888
|
+
adRainbowName: "RainbowSpeak",
|
|
2889
|
+
adRainbowDesc: "Переливающаяся радужная рамка + питомец «Сяохун»",
|
|
2870
2890
|
tabEpisodes: "Эпизоды",
|
|
2871
2891
|
episodeSince: "С даты",
|
|
2872
2892
|
episodeUntil: "По дату",
|
|
@@ -3426,6 +3446,16 @@ const zh = {
|
|
|
3426
3446
|
profileDiffTarget: "对比版本",
|
|
3427
3447
|
profileDiffNone: "两个版本内容相同",
|
|
3428
3448
|
profileLoadFailed: "画像加载失败",
|
|
3449
|
+
aboutDesc: "本地优先的跨会话长期记忆 · 记忆宫殿",
|
|
3450
|
+
aboutAuthor: "作者",
|
|
3451
|
+
aboutRepo: "仓库",
|
|
3452
|
+
aboutNpm: "npm",
|
|
3453
|
+
aboutLicense: "许可证",
|
|
3454
|
+
moreWorksTitle: "更多作品",
|
|
3455
|
+
adBillingName: "Usage Billing · 用量账单",
|
|
3456
|
+
adBillingDesc: "真实用量 · 历史账本 · 峰谷计价 · 订阅额度",
|
|
3457
|
+
adRainbowName: "RainbowSpeak · 虹语",
|
|
3458
|
+
adRainbowDesc: "会流动的彩虹边框 + 窗口桌宠「小虹」",
|
|
3429
3459
|
tabEpisodes: "往事",
|
|
3430
3460
|
episodeSince: "开始日期",
|
|
3431
3461
|
episodeUntil: "结束日期",
|
|
@@ -5808,7 +5838,11 @@ function finishError(finish) {
|
|
|
5808
5838
|
error.code = finish.failure.code;
|
|
5809
5839
|
return error;
|
|
5810
5840
|
}
|
|
5811
|
-
case "max-tokens":
|
|
5841
|
+
case "max-tokens": {
|
|
5842
|
+
const error = new Error(message("llm.finishMaxTokens"));
|
|
5843
|
+
error.code = "LLM_MAX_TOKENS";
|
|
5844
|
+
return error;
|
|
5845
|
+
}
|
|
5812
5846
|
case "tool-calls": return new Error(message("llm.finishUnexpectedToolCalls"));
|
|
5813
5847
|
default: return new Error(message("llm.finishUnsupported", { kind: String(finish.kind) }));
|
|
5814
5848
|
}
|
|
@@ -6311,6 +6345,51 @@ const MODE_LIMITS = {
|
|
|
6311
6345
|
/** 摄取输出 token 上限。completion 预算含 reasoning_tokens:推理模型可能把预算耗在思考上、
|
|
6312
6346
|
答案为空(实测 600/2000 都会出现,4000 未复现),上限给足余量而非按答案长度估。 */
|
|
6313
6347
|
const INGEST_MAX_TOKENS = 4e3;
|
|
6348
|
+
/** 提取切块的最小文本粒度(字符):切到低于此长度仍超输出预算的块直接放弃(贡献 0 条候选)。
|
|
6349
|
+
正常文本到这个量级输出预算绰绰有余;触发即说明模型输出退化(复读死循环),再切只是空烧。 */
|
|
6350
|
+
const EXTRACT_MIN_CHUNK = 80;
|
|
6351
|
+
/** max-tokens 终止错误的判别(llm/client.ts 的 finishError 打上 LLM_MAX_TOKENS code)。 */
|
|
6352
|
+
function isMaxTokensError(error) {
|
|
6353
|
+
return error?.code === "LLM_MAX_TOKENS";
|
|
6354
|
+
}
|
|
6355
|
+
/** 单块提取的解析失败(含空答案重试后仍失败)——携带原始输出,交上层按 reason 分类报告。 */
|
|
6356
|
+
var ExtractFailure = class extends Error {
|
|
6357
|
+
raw;
|
|
6358
|
+
constructor(raw) {
|
|
6359
|
+
super("extract-parse-failed");
|
|
6360
|
+
this.raw = raw;
|
|
6361
|
+
this.name = "ExtractFailure";
|
|
6362
|
+
}
|
|
6363
|
+
};
|
|
6364
|
+
/**
|
|
6365
|
+
* 提取候选,输出超预算(max-tokens)时对半切块重试(#42 附带报告:长转写/数百行日志的
|
|
6366
|
+
* 轮次提取输出必然超 4000 输出预算,且同样输入重跑永远失败——回填轮次被永久卡死)。
|
|
6367
|
+
* 切块让这类轮次自愈:多段文本对半分;单段文本按换行边界对半切;切到最小粒度仍超限的
|
|
6368
|
+
* 块放弃(贡献 0 条候选),其余块照常提取,整轮照常收口为 done 而非永久 pending。
|
|
6369
|
+
* 语义边界:只有 max-tokens 触发切块;解析失败(ExtractFailure)与瞬时错误原样上抛,
|
|
6370
|
+
* 轮次保持「可重试」状态,与旧行为一致。
|
|
6371
|
+
*/
|
|
6372
|
+
async function extractChunked(callOnce, texts) {
|
|
6373
|
+
try {
|
|
6374
|
+
return await callOnce(texts);
|
|
6375
|
+
} catch (error) {
|
|
6376
|
+
if (!isMaxTokensError(error)) throw error;
|
|
6377
|
+
if (texts.length > 1) {
|
|
6378
|
+
const mid = Math.ceil(texts.length / 2);
|
|
6379
|
+
const first = await extractChunked(callOnce, texts.slice(0, mid));
|
|
6380
|
+
const second = await extractChunked(callOnce, texts.slice(mid));
|
|
6381
|
+
return [...first, ...second];
|
|
6382
|
+
}
|
|
6383
|
+
const text = texts[0] ?? "";
|
|
6384
|
+
if (text.length < EXTRACT_MIN_CHUNK) return [];
|
|
6385
|
+
const half = Math.floor(text.length / 2);
|
|
6386
|
+
const positions = [text.lastIndexOf("\n", half), text.indexOf("\n", half)].filter((position) => position !== -1);
|
|
6387
|
+
const cut = positions.length === 0 ? half : positions.reduce((best, position) => Math.abs(position - half) < Math.abs(best - half) ? position : best);
|
|
6388
|
+
const first = await extractChunked(callOnce, [text.slice(0, cut)]);
|
|
6389
|
+
const second = await extractChunked(callOnce, [text.slice(cut + 1)]);
|
|
6390
|
+
return [...first, ...second];
|
|
6391
|
+
}
|
|
6392
|
+
}
|
|
6314
6393
|
/** op_log 幂等键 op:该 (sessionId, turn) 已完成摄取。 */
|
|
6315
6394
|
const INGEST_DONE_OP = "ingest-done";
|
|
6316
6395
|
/** op_log pending 键 op:disposed 末轮摄取失败/超时,待下次会话重放补做。 */
|
|
@@ -6676,43 +6755,54 @@ async function ingestPreviousTurn(deps) {
|
|
|
6676
6755
|
};
|
|
6677
6756
|
}
|
|
6678
6757
|
const recallNote = hasRecallToolCalls(scoped) ? message("llm.ingestRecallNote") : "";
|
|
6679
|
-
const
|
|
6680
|
-
|
|
6681
|
-
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
|
|
6685
|
-
|
|
6686
|
-
|
|
6687
|
-
|
|
6688
|
-
|
|
6689
|
-
system: ingestSystemPrompt(),
|
|
6690
|
-
userText,
|
|
6691
|
-
maxTokens: INGEST_MAX_TOKENS,
|
|
6692
|
-
purpose: "engram-ingest",
|
|
6693
|
-
signal: deps.signal
|
|
6694
|
-
});
|
|
6695
|
-
let parsed = parseJsonArray(raw);
|
|
6696
|
-
if (parsed === void 0 && raw.trim() === "") {
|
|
6697
|
-
raw = await deps.call({
|
|
6758
|
+
const callExtract = async (texts) => {
|
|
6759
|
+
const userText = `${message("llm.ingestUserPrompt")}\n${JSON.stringify(texts)}${recallNote === "" ? "" : `\n${recallNote}`}`;
|
|
6760
|
+
deps.logRequest({
|
|
6761
|
+
route,
|
|
6762
|
+
round,
|
|
6763
|
+
userText,
|
|
6764
|
+
maxTokens: INGEST_MAX_TOKENS,
|
|
6765
|
+
mode: deps.mode
|
|
6766
|
+
});
|
|
6767
|
+
const args = {
|
|
6698
6768
|
route,
|
|
6699
6769
|
system: ingestSystemPrompt(),
|
|
6700
6770
|
userText,
|
|
6701
6771
|
maxTokens: INGEST_MAX_TOKENS,
|
|
6702
6772
|
purpose: "engram-ingest",
|
|
6703
6773
|
signal: deps.signal
|
|
6704
|
-
}
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6774
|
+
};
|
|
6775
|
+
let raw = await deps.call(args);
|
|
6776
|
+
let parsed = parseJsonArray(raw);
|
|
6777
|
+
if (parsed === void 0 && raw.trim() === "") {
|
|
6778
|
+
deps.logRequest({
|
|
6779
|
+
route,
|
|
6780
|
+
round,
|
|
6781
|
+
userText,
|
|
6782
|
+
maxTokens: INGEST_MAX_TOKENS,
|
|
6783
|
+
mode: deps.mode
|
|
6784
|
+
});
|
|
6785
|
+
raw = await deps.call(args);
|
|
6786
|
+
parsed = parseJsonArray(raw);
|
|
6787
|
+
}
|
|
6788
|
+
if (parsed === void 0) throw new ExtractFailure(raw);
|
|
6789
|
+
return parsed;
|
|
6715
6790
|
};
|
|
6791
|
+
let parsed;
|
|
6792
|
+
try {
|
|
6793
|
+
parsed = await extractChunked(callExtract, cleaned);
|
|
6794
|
+
} catch (error) {
|
|
6795
|
+
if (!(error instanceof ExtractFailure)) throw error;
|
|
6796
|
+
return {
|
|
6797
|
+
scannedEvents: slice.length,
|
|
6798
|
+
candidates: 0,
|
|
6799
|
+
written: 0,
|
|
6800
|
+
merged: 0,
|
|
6801
|
+
deferred: 0,
|
|
6802
|
+
dropped: 0,
|
|
6803
|
+
skipped: error.raw.trim() === "" ? "empty-answer" : "unparseable-output"
|
|
6804
|
+
};
|
|
6805
|
+
}
|
|
6716
6806
|
const embedder = await deps.embedder;
|
|
6717
6807
|
const judge = deps.resolveJudge?.();
|
|
6718
6808
|
const writtenContents = [];
|
|
@@ -7402,17 +7492,18 @@ async function runConsolidation(store, embedder, opts = {}) {
|
|
|
7402
7492
|
const key = record.content.slice(0, 60);
|
|
7403
7493
|
const existing = seen.get(key);
|
|
7404
7494
|
if (existing === void 0) seen.set(key, record);
|
|
7405
|
-
else if (record.importance > existing.importance) {
|
|
7406
|
-
await store.supersedeMany({
|
|
7495
|
+
else if (record.importance > existing.importance) try {
|
|
7496
|
+
const survivor = await store.supersedeMany({
|
|
7407
7497
|
scope,
|
|
7408
7498
|
kind: record.kind,
|
|
7409
7499
|
content: record.content,
|
|
7410
7500
|
importance: record.importance,
|
|
7411
7501
|
confidence: record.confidence
|
|
7412
|
-
}, [existing.id])
|
|
7413
|
-
skipped += 1;
|
|
7414
|
-
});
|
|
7502
|
+
}, [existing.id, record.id]);
|
|
7415
7503
|
merged += 1;
|
|
7504
|
+
seen.set(key, survivor);
|
|
7505
|
+
} catch {
|
|
7506
|
+
skipped += 1;
|
|
7416
7507
|
seen.set(key, record);
|
|
7417
7508
|
}
|
|
7418
7509
|
}
|
|
@@ -7451,21 +7542,23 @@ async function runConsolidation(store, embedder, opts = {}) {
|
|
|
7451
7542
|
if (bVec === void 0) continue;
|
|
7452
7543
|
if (cosine(vectors.get(a.id), bVec) >= options.mergeThreshold) dupes.push(b);
|
|
7453
7544
|
}
|
|
7454
|
-
if (dupes.length
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
|
|
7458
|
-
|
|
7459
|
-
|
|
7460
|
-
|
|
7461
|
-
|
|
7462
|
-
|
|
7463
|
-
|
|
7464
|
-
|
|
7465
|
-
|
|
7466
|
-
|
|
7467
|
-
|
|
7468
|
-
|
|
7545
|
+
if (dupes.length > 0) {
|
|
7546
|
+
const ids = [...dupes.map((record) => record.id), a.id];
|
|
7547
|
+
const embedding = vectors.get(a.id);
|
|
7548
|
+
try {
|
|
7549
|
+
await store.supersedeMany({
|
|
7550
|
+
scope,
|
|
7551
|
+
kind: a.kind,
|
|
7552
|
+
content: a.content,
|
|
7553
|
+
importance: Math.max(a.importance, ...dupes.map((record) => record.importance)),
|
|
7554
|
+
confidence: a.confidence,
|
|
7555
|
+
...embedding === void 0 ? {} : { embedding }
|
|
7556
|
+
}, ids);
|
|
7557
|
+
for (const id of ids) visited.add(id);
|
|
7558
|
+
merged += 1;
|
|
7559
|
+
} catch {
|
|
7560
|
+
skipped += 1;
|
|
7561
|
+
}
|
|
7469
7562
|
}
|
|
7470
7563
|
}
|
|
7471
7564
|
}
|
|
@@ -17122,7 +17215,7 @@ function estimateTokens(text) {
|
|
|
17122
17215
|
}
|
|
17123
17216
|
//#endregion
|
|
17124
17217
|
//#region package.json
|
|
17125
|
-
var version = "0.11.
|
|
17218
|
+
var version = "0.11.3";
|
|
17126
17219
|
//#endregion
|
|
17127
17220
|
//#region src/index.ts
|
|
17128
17221
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kenz1117/dsh-engram",
|
|
3
3
|
"description": "Local-first cross-session long-term memory for DeepSeek Harness: dual-scope SQLite stores, hybrid FTS5 + local-vector retrieval with RRF, an evidence gate, provenance audit and SM-2 spaced repetition. 23 narrow tools, zero external services, zero API keys.",
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.3",
|
|
5
5
|
"icon": "icon.svg",
|
|
6
6
|
"logo": "icon-256.svg",
|
|
7
7
|
"publishConfig": {
|