@kenz1117/dsh-engram 0.7.14 → 0.7.16

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/lib/index.js CHANGED
@@ -716,8 +716,9 @@ const MODE_LIMITS = {
716
716
  includeAssistant: true
717
717
  }
718
718
  };
719
- /** 摄取输出 token 上限(提取 JSON 数组,短输出足够)。 */
720
- const INGEST_MAX_TOKENS = 600;
719
+ /** 摄取输出 token 上限。completion 预算含 reasoning_tokens:推理模型可能把预算耗在思考上、
720
+ 答案为空(实测 600/2000 都会出现,4000 未复现),上限给足余量而非按答案长度估。 */
721
+ const INGEST_MAX_TOKENS = 4e3;
721
722
  /** op_log 幂等键 op:该 (sessionId, turn) 已完成摄取。 */
722
723
  const INGEST_DONE_OP = "ingest-done";
723
724
  /** op_log pending 键 op:disposed 末轮摄取失败/超时,待下次会话重放补做。 */
@@ -745,6 +746,7 @@ const INGEST_SYSTEM = [
745
746
  "entities 是这条记忆里提到的具体对象(人名/项目名/工具名/概念名),没有就省略该字段;实体名要短(专名本身,不超过 20 字),aliases 列出该实体的其他叫法,没有就省略。",
746
747
  "facts 列出这条记忆中关于具体实体的客观事实(状态/归属/关系/数据),entity 必须取该条 entities 里出现过的实体名,一条一个知识点,没有就省略该字段。",
747
748
  "scope 决定这条记忆进哪座宫殿:只跟当前项目/仓库有关的(技术选型、项目约定、架构决策、该项目自身的事实)用 project;与具体项目无关、跨项目通用的(个人偏好、习惯、用户本人的经历、通用事实)用 user。拿不准用 project。",
749
+ "忠实转述:原文中被否定、拒绝或纠正的内容,记录时必须保持其被否定的语义,不得写成正面断言;不要添加原文没有的关联、判断或结论。",
748
750
  "只提取明确、可复用的信息;寒暄、临时上下文、你自己的回答不要提取。没有值得记的就输出 []。",
749
751
  "不要输出 JSON 以外的任何内容。"
750
752
  ].join("\n");
@@ -1032,14 +1034,26 @@ async function ingestPreviousTurn(deps) {
1032
1034
  maxTokens: INGEST_MAX_TOKENS,
1033
1035
  mode: deps.mode
1034
1036
  });
1035
- const parsed = parseJsonArray(await deps.call({
1037
+ let raw = await deps.call({
1036
1038
  route,
1037
1039
  system: INGEST_SYSTEM,
1038
1040
  userText,
1039
1041
  maxTokens: INGEST_MAX_TOKENS,
1040
1042
  purpose: "engram-ingest",
1041
1043
  signal: deps.signal
1042
- }));
1044
+ });
1045
+ let parsed = parseJsonArray(raw);
1046
+ if (parsed === void 0 && raw.trim() === "") {
1047
+ raw = await deps.call({
1048
+ route,
1049
+ system: INGEST_SYSTEM,
1050
+ userText,
1051
+ maxTokens: INGEST_MAX_TOKENS,
1052
+ purpose: "engram-ingest",
1053
+ signal: deps.signal
1054
+ });
1055
+ parsed = parseJsonArray(raw);
1056
+ }
1043
1057
  if (parsed === void 0) return {
1044
1058
  scannedEvents: slice.length,
1045
1059
  candidates: 0,
@@ -1047,7 +1061,7 @@ async function ingestPreviousTurn(deps) {
1047
1061
  merged: 0,
1048
1062
  deferred: 0,
1049
1063
  dropped: 0,
1050
- skipped: "unparseable-output"
1064
+ skipped: raw.trim() === "" ? "empty-answer" : "unparseable-output"
1051
1065
  };
1052
1066
  const embedder = await deps.embedder;
1053
1067
  const writtenContents = [];
@@ -2963,6 +2977,34 @@ function registerEngramRoutes(ctx, deps) {
2963
2977
  });
2964
2978
  return;
2965
2979
  }
2980
+ if (req.method === "GET" && route === "observations") {
2981
+ const scope = scopeOf$1(url.searchParams.get("scope"), "user");
2982
+ const status = url.searchParams.get("status");
2983
+ const limit = Math.min(200, Math.max(1, Number(url.searchParams.get("limit") ?? 100) || 100));
2984
+ const items = await (await storeFor(scope)).listObservations({
2985
+ ...status !== null && status !== "" && status !== "all" ? { status } : {},
2986
+ limit
2987
+ });
2988
+ json(res, 200, {
2989
+ scope,
2990
+ items,
2991
+ total: items.length
2992
+ });
2993
+ return;
2994
+ }
2995
+ if (req.method === "GET" && route === "observation-evidence") {
2996
+ const scope = scopeOf$1(url.searchParams.get("scope"), "user");
2997
+ const ids = (url.searchParams.get("ids") ?? "").split(",").map((part) => part.trim()).filter((part) => part !== "").slice(0, 50);
2998
+ if (ids.length === 0) {
2999
+ json(res, 400, { error: "ids required" });
3000
+ return;
3001
+ }
3002
+ json(res, 200, {
3003
+ scope,
3004
+ items: await (await storeFor(scope)).getMany(ids)
3005
+ });
3006
+ return;
3007
+ }
2966
3008
  if (req.method === "GET" && route === "entities") {
2967
3009
  const scope = scopeOf$1(url.searchParams.get("scope"), "user");
2968
3010
  const kind = url.searchParams.get("kind");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kenz1117/dsh-engram",
3
3
  "description": "Cross-session long-term memory for DeepSeek Harness (memory palace · AGI Architecture Exploration on dsh-market): dual-scope SQLite memory graph, hybrid retrieval, provenance audit, and a knowledge flywheel.",
4
- "version": "0.7.14",
4
+ "version": "0.7.16",
5
5
  "icon": "icon.svg",
6
6
  "logo": "icon-256.svg",
7
7
  "publishConfig": {
@@ -45,7 +45,7 @@
45
45
  }
46
46
  },
47
47
  "scripts": {
48
- "prepare": "node scripts/link-peers.mjs",
48
+ "prepare": "node scripts/link-peers.mjs && node scripts/ensure-build.mjs",
49
49
  "bundle": "tsdown",
50
50
  "watch": "tsdown --watch",
51
51
  "test": "vitest run",
@@ -91,12 +91,5 @@
91
91
  "tsdown": "^0.22.14",
92
92
  "typescript": "^5.9.3",
93
93
  "vitest": "^4.1.11"
94
- },
95
- "pnpm": {
96
- "onlyBuiltDependencies": [
97
- "onnxruntime-node",
98
- "sharp",
99
- "protobufjs"
100
- ]
101
94
  }
102
95
  }
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * prepare 的构建兜底:lib/ 缺失时现场构建。
4
+ *
5
+ * 场景:从 GitHub 源码快捷安装(dsh plugin add github:...)会以源码形态执行 prepare,
6
+ * 此时没有构建产物,宿主以 "no entry point" 失败而非提示构建——这里补上自动构建。
7
+ * 开发仓(clone + pnpm install)通常已有 lib/ 或随后手动构建,仅在缺失时才付构建成本。
8
+ * 跨平台:经 node 执行 pnpm(Windows 下 pnpm 是 .cmd,shell 默认解析)。
9
+ */
10
+
11
+ import { existsSync } from 'node:fs'
12
+ import { execSync } from 'node:child_process'
13
+ import { fileURLToPath } from 'node:url'
14
+
15
+ const entry = fileURLToPath(new URL('../lib/index.js', import.meta.url))
16
+ if (existsSync(entry)) {
17
+ console.log('[prepare] lib/index.js present, skipping build')
18
+ } else {
19
+ console.log('[prepare] lib/index.js missing — building (pnpm run bundle)...')
20
+ execSync('pnpm run bundle', { stdio: 'inherit', cwd: fileURLToPath(new URL('..', import.meta.url)) })
21
+ if (!existsSync(entry)) {
22
+ console.error('[prepare] build finished but lib/index.js is still missing — check the bundle output above')
23
+ process.exitCode = 1
24
+ }
25
+ }
@@ -59,4 +59,5 @@ for (const [name, rel] of LINKED_PACKAGES) {
59
59
  symlinkSync(target, link, 'dir')
60
60
  created += 1
61
61
  }
62
- console.log(`[link-peers] ok(新建 ${created} 个链接,跳过 ${skipped} 个无源码环境的 peer,共 ${LINKED_PACKAGES.length} 个)`)
62
+ // 英文输出:这份摘要最常被贴进 issue/安装日志(贡献者含英文用户),中文注释留在源码内。
63
+ console.log(`[link-peers] ok: created ${created}, skipped ${skipped} of ${LINKED_PACKAGES.length} peers${skipped === LINKED_PACKAGES.length ? ' (all already provided by the host profile — nothing to link, this is expected)' : ''}`)