memory-eternal 0.10.48 → 0.10.50

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://anthropic.com/claude-code/plugin.schema.json",
3
3
  "name": "memory-eternal",
4
- "version": "0.10.48",
4
+ "version": "0.10.50",
5
5
  "description": "记忆核心(Memory Eternal):对话结束后自动沉淀知识卡到本地记忆库(~/.dsh/memory-vault),支持检索 / 召回 / 审核中心。",
6
6
  "author": {
7
7
  "name": "EternalNight996",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "memory-eternal",
3
- "version": "0.10.48",
3
+ "version": "0.10.50",
4
4
  "description": "记忆核心(Memory Eternal):对话结束后自动沉淀知识卡到本地记忆库(~/.dsh/memory-vault),支持检索 / 召回 / 审核中心。",
5
5
  "author": {
6
6
  "name": "EternalNight996",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "memory-eternal",
3
- "version": "0.10.48",
3
+ "version": "0.10.50",
4
4
  "description": "记忆核心(Memory Eternal):对话结束后自动沉淀知识卡到本地记忆库(~/.dsh/memory-vault),支持检索 / 召回 / 审核中心。",
5
5
  "author": {
6
6
  "name": "EternalNight996",
package/README.en.md CHANGED
@@ -361,14 +361,16 @@ curl http://127.0.0.1:7999/memory-eternal/api/web-info # is the standalone we
361
361
 
362
362
  | Version | Date | Highlights |
363
363
  |---|---|---|
364
- | **v0.10.48** | 2026-10-19 | **A visual gate plus exhaustive state coverage (the option we agreed on)**. ① **New `npm run panel-check`** (scripts/panel-check.mjs, zero dependencies): drives local headless Chrome over CDP, asserts **no horizontal overflow** on each screen and saves screenshots (list / reader / config / feedback modal). On its very first run it caught two real bugs: an unbreakable long run in a card title (`(begin/chunk/probe/complete/abort)`) overflowing by 45px, and the **feedback textarea overflowing by 22px** (width:100% plus padding under content-box) — exactly the layout/scrollbar anomaly reported. ② Fixes: word-breaking on `.mc-cardrow h4` and a shared border-box rule for form controls. ③ **The version-card decision is now a pure function** `src/client/version-state.js`: versionCardState returns {showButton, emphasis, warn, hint} and the component only maps keys to text; a table-driven test **enumerates 324 combinations** and enforces the invariant that the button is shown whenever version info exists — structurally preventing the 0.10.45 regression where a third state made it disappear. npm test now runs **420 checks** |
365
- | **v0.10.47** | 2026-10-19 | **The panel version probe now refreshes itself, and the "resident not running" wording is fixed (user report: the panel kept saying "resident instance: not running" after a restart)**. ① The instance was in fact alive (status showed 7999 listening and serving v0.10.46), but the probe ran only once when the panel mounted, so a run that happened to land inside the restart window was cached as "not running" and stuck. It now **re-checks silently every 60 seconds** (without lighting up the Check-for-updates button) and **immediately when the tab becomes visible** (visibilitychange); a restart already triggers a re-check six seconds later. ② When the resident really is down, the hint used to interpolate an empty "currently v"; it now uses vcRestartStart: "Starts the resident instance on the current disk version v{disk} (no DSH restart needed)". npm test now runs **408 checks** |
364
+ | **v0.10.50** | 2026-10-19 | **Models that ignore JSON no longer burn a call every turn (a follow-up to #47)**. ① "The model replied with prose and produced no JSON object at all" is now separated from the generic UNPARSEABLE_OUTPUT failure and gets its own code **MODEL_NOT_JSON**, with wording that says the model likely does not follow structured output. ② New `lib/model-strikes.js` records which provider/model recently ignored the format (24h window, at most 50 entries) and the host moves those to the end of the candidate list when routing (never removing them; if every candidate was struck the original order is kept, so we never run out), logging a "candidates reordered" line. ③ Effect: models such as stepfun/step-api, which answer distillation prompts conversationally, stop being tried first from the second turn on, saving a pointless call each time. Adds `tests/model-strikes.test.mjs` (prose detection, stable ranking, record window and trimming, wiring guards). npm test now runs **429 checks** |
365
+ | **v0.10.49** | 2026-10-19 | **Fixes "cannot choose the distillation model" in the desktop app (#47): the standalone page now proxies /llm-routes and /llm-test to the host, plus one more state in the matrix**. Root cause: the desktop memory popup is a **standalone page inside an iframe** with no DSH llm service, so /llm-routes always failed and provider/model had to be typed by hand. The standalone page now reads the host heartbeat (the port in <config>.host.json, 127.0.0.1 only, valid for 120s) and forwards those two routes to the host, marking the reply as proxied; when the host is offline the panel shows the concrete reason instead of silently falling back to text inputs. ② The version-card matrix gains restartRepair: when versions already match but nothing keeps the instance alive it says "re-register and keep it alive", no longer the self-contradictory "switch to v0.10.48 (currently v0.10.48)". npm test now runs **425 checks** |
366
366
 
367
367
  <details>
368
- <summary>Older release notes (v0.10.46 and earlier · 73 releases, click to expand)</summary>
368
+ <summary>Older release notes (v0.10.48 and earlier · 75 releases, click to expand)</summary>
369
369
 
370
370
  | Version | Date | Highlights |
371
371
  |---|---|---|
372
+ | **v0.10.48** | 2026-10-19 | **A visual gate plus exhaustive state coverage (the option we agreed on)**. ① **New `npm run panel-check`** (scripts/panel-check.mjs, zero dependencies): drives local headless Chrome over CDP, asserts **no horizontal overflow** on each screen and saves screenshots (list / reader / config / feedback modal). On its very first run it caught two real bugs: an unbreakable long run in a card title (`(begin/chunk/probe/complete/abort)`) overflowing by 45px, and the **feedback textarea overflowing by 22px** (width:100% plus padding under content-box) — exactly the layout/scrollbar anomaly reported. ② Fixes: word-breaking on `.mc-cardrow h4` and a shared border-box rule for form controls. ③ **The version-card decision is now a pure function** `src/client/version-state.js`: versionCardState returns {showButton, emphasis, warn, hint} and the component only maps keys to text; a table-driven test **enumerates 324 combinations** and enforces the invariant that the button is shown whenever version info exists — structurally preventing the 0.10.45 regression where a third state made it disappear. npm test now runs **420 checks** |
373
+ | **v0.10.47** | 2026-10-19 | **The panel version probe now refreshes itself, and the "resident not running" wording is fixed (user report: the panel kept saying "resident instance: not running" after a restart)**. ① The instance was in fact alive (status showed 7999 listening and serving v0.10.46), but the probe ran only once when the panel mounted, so a run that happened to land inside the restart window was cached as "not running" and stuck. It now **re-checks silently every 60 seconds** (without lighting up the Check-for-updates button) and **immediately when the tab becomes visible** (visibilitychange); a restart already triggers a re-check six seconds later. ② When the resident really is down, the hint used to interpolate an empty "currently v"; it now uses vcRestartStart: "Starts the resident instance on the current disk version v{disk} (no DSH restart needed)". npm test now runs **408 checks** |
372
374
  | **v0.10.46** | 2026-10-19 | **The "restart resident instance" button is now always shown, and the "which one is stale" wording is fixed (second user report of the button disappearing)**. The previous build put the button inside the "resident needs restart" branch, while the real state was "the resident is already current, but the process serving this page (the DSH host) is stale", so it fell into the host-hint branch and the button vanished again; worse, the warning claimed clicking restart-resident would fix it even though restarting the resident never changes the host-served page. Now: ① the button depends only on vc existing; ② each of the three states gets an accurate explanation — resident stale (click and it upgrades without restarting DSH) / host stale (restarting the resident does not affect this page, restart DSH) / everything current (force restart if it looks stuck); ③ the warning text is split into vcHostProcessStale, making clear that the page is served by the host process. npm test now runs **406 checks** |
373
375
  | **v0.10.45** | 2026-10-19 | **Fixes the disappearing "restart resident instance" button and the dialog layout / scrollbar anomalies (from user screenshots)**. ① **The button is persistent**: it used to live inside the warning block that only renders when something is wrong, so once versions matched the whole block vanished and the button could not be found (issue #28 complained about the same). The action row now renders independently: it is the repair entry point when something is off, and stays available when everything is fine, with a note that a restart is usually unnecessary but can be forced if the instance looks stuck. ② **Scrollbar anomalies**: the reader can have up to eight header buttons while 0.10.42 made the action group nowrap, so it overflowed horizontally inside a max-width:760px dialog; each button still never shrinks or wraps, but the **group itself may wrap** onto a second row without deforming. ③ **Layout**: .me-dialog and .me-dialog-body use border-box and hide horizontal scrolling in the body (the reader width:100% plus padding no longer breaks out of the container), diagnostic/feedback pre blocks use word-break for long paths, and large-title modals ellipsize their h2. Adds tests/ui-overflow.test.mjs (4 guards). npm test now runs **406 checks** |
374
376
  | **v0.10.44** | 2026-10-19 | **UI experience, batch two: click a tag to filter, plus search hit snippets**. ① **Tag filtering**: tag chips in the list and the reader are now clickable and filter immediately (combining with search, kind and status); the toolbar shows a removable "tag x" chip. The server-side /cards?tag= uses an exact SQL match on the quoted complete tag inside the JSON array (instr), so **ab is never matched by a**, and both the countCards and sort=title branches apply it. ② **Search hit snippets**: when the match is in the body, the list shows a short excerpt around the keyword with highlighting (whitespace collapsed, ellipses at both ends), so it is obvious why a card matched. ③ Adds src/client/snippet.js (pure, unit-testable in Node) and tests/tag-filter.test.mjs (3 checks). npm test now runs **402 checks** |
package/README.md CHANGED
@@ -393,14 +393,16 @@ curl http://127.0.0.1:7999/memory-eternal/api/web-info # 独立 web 是否活
393
393
 
394
394
  | 版本 | 日期 | 关键改动 |
395
395
  |---|---|---|
396
- | **v0.10.48** | 2026-10-19 | **界面验收手段 + 状态穷举(方案一落地)**。① **新增 `npm run panel-check`**(scripts/panel-check.mjs,零依赖):用本机 Chrome headless + CDP 打开面板,逐屏断言**没有横向溢出**并截图(列表 / 阅读器 / 配置 / 反馈弹窗)。它第一次跑就抓到两个真 bug:卡片标题里的无断点长串(`(begin/chunk/probe/complete/abort)`)溢出 45px;**反馈弹窗 textarea 溢出 22px**(width:100% + padding 在 content-box 下)—— 正是用户报的「排版不对 / 滚动条异常」。② 修复:`.mc-cardrow h4` 断词、`.me-overlay input/textarea/select` 统一 border-box。③ **版本卡判定抽成纯函数** `src/client/version-state.js`:`versionCardState(...)` 返回 `{showButton, emphasis, warn, hint}`,组件只做 key→文案;新增表驱动测试**穷举 324 种组合**,并守住不变式「只要拿到版本信息,按钮永远显示」—— 0.10.45「第三种状态导致按钮消失」从结构上不可能再发生。npm test 共 **420 项** |
397
- | **v0.10.47** | 2026-10-19 | **面板版本探针自动复查 + 「常驻未运行」文案修正(用户反馈:重启后面板一直显示「常驻实例 未运行」)**。① 现场其实**是活的**(status 显示 7999 在听、服务 v0.10.46),但版本探针只在面板挂载时跑一次 —— 恰好撞上重启窗口就会被缓存成「未运行」并一直显示。现在**每 60 秒静默复查**(不点亮「检查更新」按钮)+ **切回页面立刻复查**(visibilitychange),重启后 6 秒本来就会复查一次。② 文案:常驻实例真没跑时,原来那句会拼出「当前 v」(空值);现在改走 vcRestartStart:**「点击会用当前磁盘版本 v{disk} 把常驻实例拉起来(不用重启 DSH)」**。npm test 共 **408 项** |
396
+ | **v0.10.50** | 2026-10-19 | **「模型不守 JSON」不再每轮白烧调用(#47 衍生改进)**。① 把「模型回了散文、输出里根本没有 JSON 对象」从笼统的 UNPARSEABLE_OUTPUT 里拆出来,给独立错误码 **MODEL_NOT_JSON**,文案直接说清「该模型可能不遵守结构化输出」。② 新增 `lib/model-strikes.js`:记下「哪个 provider/model 最近不守格式」(24h 窗口、最多 50 条),宿主选路时把它们**排到候选末尾**(不删除;全部命中过则按原顺序兜底,绝不没候选),并留一条「蒸馏候选已调整」日志。③ 效果:像 stepfun/step-api 这种会把蒸馏当聊天回的模型,第二轮起就不再优先尝试,省掉每次的无效调用。新增 `tests/model-strikes.test.mjs`(4 项:散文识别 / 排序稳定性 / 记录窗口与裁剪 / 接线守卫)。npm test 共 **429 项** |
397
+ | **v0.10.49** | 2026-10-19 | **桌面版里「无法选择蒸馏模型」修复(#47):独立页把 /llm-routes 与 /llm-test 代理给宿主 + 文案补一个状态**。根因:桌面版的「记忆」弹窗是 iframe 里的**独立页**,它没有 DSH 的 llm 服务 → /llm-routes 恒失败 → provider/model 只能手填。现在独立页读宿主心跳(<config>.host.json 里的端口,仅 127.0.0.1、心跳 120s 内有效),把这两个路由**转发给宿主**执行并标记 proxied;宿主不在线时给明确原因(面板直接显示,不再静默回退成手填)。② 版本卡状态矩阵补 restartRepair:**版本已对但没人保活**时提示「重新托管并保活」,不再出现「换成 v0.10.48(当前 v0.10.48)」这种自相矛盾的文案(截图实测)。npm test 共 **425 项** |
398
398
 
399
399
  <details>
400
- <summary>更早的更新日志(v0.10.46 及以前 · 共 73 版,点开查看)</summary>
400
+ <summary>更早的更新日志(v0.10.48 及以前 · 共 75 版,点开查看)</summary>
401
401
 
402
402
  | 版本 | 日期 | 关键改动 |
403
403
  |---|---|---|
404
+ | **v0.10.48** | 2026-10-19 | **界面验收手段 + 状态穷举(方案一落地)**。① **新增 `npm run panel-check`**(scripts/panel-check.mjs,零依赖):用本机 Chrome headless + CDP 打开面板,逐屏断言**没有横向溢出**并截图(列表 / 阅读器 / 配置 / 反馈弹窗)。它第一次跑就抓到两个真 bug:卡片标题里的无断点长串(`(begin/chunk/probe/complete/abort)`)溢出 45px;**反馈弹窗 textarea 溢出 22px**(width:100% + padding 在 content-box 下)—— 正是用户报的「排版不对 / 滚动条异常」。② 修复:`.mc-cardrow h4` 断词、`.me-overlay input/textarea/select` 统一 border-box。③ **版本卡判定抽成纯函数** `src/client/version-state.js`:`versionCardState(...)` 返回 `{showButton, emphasis, warn, hint}`,组件只做 key→文案;新增表驱动测试**穷举 324 种组合**,并守住不变式「只要拿到版本信息,按钮永远显示」—— 0.10.45「第三种状态导致按钮消失」从结构上不可能再发生。npm test 共 **420 项** |
405
+ | **v0.10.47** | 2026-10-19 | **面板版本探针自动复查 + 「常驻未运行」文案修正(用户反馈:重启后面板一直显示「常驻实例 未运行」)**。① 现场其实**是活的**(status 显示 7999 在听、服务 v0.10.46),但版本探针只在面板挂载时跑一次 —— 恰好撞上重启窗口就会被缓存成「未运行」并一直显示。现在**每 60 秒静默复查**(不点亮「检查更新」按钮)+ **切回页面立刻复查**(visibilitychange),重启后 6 秒本来就会复查一次。② 文案:常驻实例真没跑时,原来那句会拼出「当前 v」(空值);现在改走 vcRestartStart:**「点击会用当前磁盘版本 v{disk} 把常驻实例拉起来(不用重启 DSH)」**。npm test 共 **408 项** |
404
406
  | **v0.10.46** | 2026-10-19 | **「重启常驻实例」按钮改为**永远显示** + 修正「谁旧」的文案(用户第二次反馈按钮消失)**。上一版把按钮放进「常驻实例需要重启」的分支,而实际状态是**常驻实例已是新版、服务本页的进程(DSH 宿主)还是旧版** → 落进宿主提示分支、按钮又没了;更糟的是警告文案写着「点重启常驻实例即可」,而重启常驻根本不会改变宿主提供给你的本页版本。现在:① 按钮**只依赖 vc 存在**,任何状态都在;② 三种状态各给准确说明 —— 常驻旧(点了就换新版,不用重启 DSH)/ 宿主旧(重启常驻**不影响本页**,请重启 DSH)/ 全部对齐(卡住时可强制重启);③ 警告文案拆出 vcHostProcessStale,明确「服务本页的是宿主进程」。npm test 共 **406 项** |
405
407
  | **v0.10.45** | 2026-10-19 | **修复「重启常驻实例」按钮消失 + 对话框排版/滚动条异常(用户截图反馈)**。① **按钮常驻**:它原来被包在「有异常才渲染」的警告块里 —— 版本一对齐整块消失,用户再也找不到(#28 也抱怨过)。现在操作行**独立渲染**:异常时是修复入口,一切正常时也保留按钮并说明「通常无需重启,卡住时可强制重启」。② **滚动条异常**:阅读器最多 8 个头部按钮,而 0.10.42 给按钮组设的是 nowrap → 在 max-width:760px 的对话框里**横向溢出**;现在按钮自身仍不缩不换行、但**按钮组整体允许换行**(掉到第二行也不变形)。③ **排版**:.me-dialog / .me-dialog-body 改 border-box 并隐藏正文横向滚动(阅读器的 width:100% + padding 不再撑破容器);诊断/反馈的 <pre> 长路径加 word-break(远程 agent 的路径没有断点,以前必横向滚);大标题 modal 的 h2 加省略号。新增 tests/ui-overflow.test.mjs(4 项守卫)。npm test 共 **406 项** |
406
408
  | **v0.10.44** | 2026-10-19 | **界面体验(第二批):标签点击即筛选 + 搜索命中片段**。① **标签筛选**:列表/阅读器里的标签芯片现在可点,点了立即按该标签筛(与搜索 / 类型 / 状态**可叠加**);工具栏出现可清除的「🏷 标签 ✕」。服务端 /cards?tag= 走 SQL 精确匹配 —— 按「JSON 数组里带引号的完整标签」用 instr 匹配,**不会把 ab 命中成 a**;countCards 与 sort=title 两条分支同步生效。② **搜索命中片段**:命中正文时,列表多显示一段**关键词附近的片段并高亮**(折叠空白、两端省略),一眼看出「为什么命中」。③ 新增 src/client/snippet.js(纯函数,Node 可单测)+ tests/tag-filter.test.mjs(3 项)。npm test 共 **402 项** |
package/index.js CHANGED
@@ -712,7 +712,18 @@ export function apply(ctx, config) {
712
712
  }
713
713
  } catch { /* 探测失败一律回退配置 */ }
714
714
  }
715
- const routes = await routeCandidates(llm, routeOpts)
715
+ let routes = await routeCandidates(llm, routeOpts)
716
+ // issue #47:近期「不守 JSON」的模型排到后面(不删除,全部命中过则原顺序兜底)
717
+ try {
718
+ const st = await import('./lib/model-strikes.js')
719
+ const strikes = st.recentModelStrikes(process.env)
720
+ if (Object.keys(strikes).length) {
721
+ const before = routes.map((r) => r.provider + '/' + r.model).join(' → ')
722
+ routes = st.rankRoutesByStrikes(routes, strikes)
723
+ const after = routes.map((r) => r.provider + '/' + r.model).join(' → ')
724
+ if (after !== before) logCapture(sessionId, 'boot', `蒸馏候选已调整(近期不守 JSON 的模型排后):${before} → ${after}`)
725
+ }
726
+ } catch { /* 记录读不到就按原顺序 */ }
716
727
  if (!routes.length) { logCapture(sessionId, 'fail', '取不到模型路由(llm.listProviders 为空)'); return }
717
728
  // 语义去重近邻:把已有卡片索引喂给模型,让模型决定新建 vs 追加。
718
729
  // 成本控制:dedupByLLM=false 时跳过喂 LLM 的近邻采样(纯词法去重兜底)。
@@ -739,6 +750,10 @@ export function apply(ctx, config) {
739
750
  if (detailed.card !== undefined) { result = detailed.card; failure = null; break }
740
751
  if (detailed.failure) {
741
752
  const f = { ...detailed.failure, provider: route.provider, model: route.model }
753
+ // 「模型回了散文」要记住:下次选路把它排到最后,别每轮都先白烧一次(issue #47)
754
+ if (f.code === 'MODEL_NOT_JSON') {
755
+ try { const st = await import('./lib/model-strikes.js'); st.recordModelStrike(process.env, route, f.code) } catch { /* 记不下来不影响主流程 */ }
756
+ }
742
757
  failures.push(f)
743
758
  // 只保留第一个:旧实现每轮覆盖,最终上报的是**最后一个兜底候选**的错误,
744
759
  // 真正有信息量的主因被彻底丢弃(#18 根因 2)。
package/lib/api.js CHANGED
@@ -144,6 +144,36 @@ export function createApi(deps = {}) {
144
144
  const getCaptureHealth = deps.getCaptureHealth ?? (() => null)
145
145
  // 矛盾扫描(issue #36)要用模型:宿主把 ctx.get('llm') 传进来;独立 web 进程拿不到就如实报错
146
146
  const getLlm = deps.getLlm ?? (() => null)
147
+ // ── 宿主代理(issue #47):桌面版的「记忆」弹窗其实是 iframe 里的**独立页**,
148
+ // 它没有 DSH 的 llm 服务 → /llm-routes 恒为「拿不到 llm」→ 用户只能手填 provider/model,
149
+ // 「无法选择蒸馏模型」就是这么来的。宿主每 15s 会把 web 端口写进 <config>.host.json,
150
+ // 独立页据此把只读查询/试调用的请求**转发给宿主**(仅限 127.0.0.1、只转发这两个路由)。
151
+ const hostBase = async () => {
152
+ try {
153
+ const { readHostMarker } = await import('./host-heartbeat.js')
154
+ const marker = readHostMarker(process.env)
155
+ if (!marker || !marker.port) return ''
156
+ if (Date.now() - marker.at > 120000) return '' // 心跳过期(宿主可能已退出)
157
+ return 'http://127.0.0.1:' + marker.port
158
+ } catch { return '' }
159
+ }
160
+ const proxyHost = deps.proxyHost
161
+ ? ((route, init) => deps.proxyHost(route, init))
162
+ : (async (route, init = {}) => {
163
+ const base = await hostBase()
164
+ if (!base) return { ok: false, error: '宿主不在线(或心跳过期):请从 DSH 面板打开设置,或直接手填 provider/model' }
165
+ try {
166
+ const ctl = new AbortController()
167
+ const timer = setTimeout(() => ctl.abort(), 8000)
168
+ const r = await fetch(base + route, { ...init, signal: ctl.signal })
169
+ clearTimeout(timer)
170
+ const data = await r.json().catch(() => null)
171
+ if (!data) return { ok: false, error: '宿主返回了非 JSON 响应(HTTP ' + r.status + ')' }
172
+ return { ...data, proxied: true }
173
+ } catch (e) {
174
+ return { ok: false, error: '代理到宿主失败:' + String((e && e.message) || e) }
175
+ }
176
+ })
147
177
  // 锁读取可注入:单测不能依赖开发者本机真实的看门狗锁(#30 复测期间就因此翻过车)
148
178
  const readLock = deps.readWatchdogLock ?? ((env) => readWatchdogLock(env))
149
179
  // 「重启常驻实例」的实现(宿主与独立 web 共用 lib/watchdog.js 的那一份;注入仅为单测)
@@ -693,7 +723,8 @@ export function createApi(deps = {}) {
693
723
  case '/llm-routes': {
694
724
  // issue #42 需求 1:把可选的 provider / model 动态列出来(面板用它渲染下拉,不再手填编号)。
695
725
  const llm = getLlm()
696
- if (!llm) { json(res, 200, { ok: false, error: '当前进程拿不到 llm 服务(独立页请在 DSH 面板里操作)' }); return }
726
+ // 独立页没有 llm 服务 → 代理给宿主(宿主心跳里有它的端口)
727
+ if (!llm) { json(res, 200, await proxyHost('/memory-eternal/api/llm-routes')); return }
697
728
  const providers = []
698
729
  try {
699
730
  for (const p of (llm.listProviders() || [])) {
@@ -710,10 +741,17 @@ export function createApi(deps = {}) {
710
741
  case '/llm-test': {
711
742
  // issue #42 需求 3:用当前配置真打一次,把 provider/model/耗时/错误码原样回显(也是 ①② 的验证手段)。
712
743
  if (req.method !== 'POST') { json(res, 405, { ok: false, error: '需 POST' }); return }
744
+ // 先读 body:本地调用与代理都要用
745
+ let rawBody = ''
746
+ try { for await (const chunk of req) rawBody += chunk } catch { rawBody = '' }
713
747
  const llm = getLlm()
714
- if (!llm) { json(res, 200, { ok: false, error: '当前进程拿不到 llm 服务' }); return }
748
+ if (!llm) {
749
+ // 独立页(桌面版弹窗 iframe)没有 llm:转给宿主真打一次,返回同样的结构
750
+ json(res, 200, await proxyHost('/memory-eternal/api/llm-test', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: rawBody || '{}' }))
751
+ return
752
+ }
715
753
  let opts = {}
716
- try { let raw = ''; for await (const chunk of req) raw += chunk; opts = JSON.parse(raw || '{}') } catch { opts = {} }
754
+ try { opts = JSON.parse(rawBody || '{}') } catch { opts = {} }
717
755
  const cfgT = getSettings() || {}
718
756
  const { routeCandidates: rc, callLlmJson: call } = await import('./capture.js')
719
757
  const routes = await rc(llm, { provider: opts.provider || cfgT.captureProvider, model: opts.model || cfgT.captureModel, firstOnly: opts.firstOnly === true || cfgT.captureFirstOnly === true })
package/lib/capture.js CHANGED
@@ -370,6 +370,10 @@ export async function summarizeTurnDetailed(llm, route, conversation, opts = {})
370
370
  const out = activeAssembler.blocks().filter((b) => b.type === 'text').map((b) => b.text).join('').trim()
371
371
  const parsed = parseCaptureJsonDetailed(out)
372
372
  if (!parsed.card) {
373
+ // 模型回了散文(完全没有 JSON 对象):给独立错误码,调用方据此**记住该模型不守格式**
374
+ if (parsed.noJson && out) {
375
+ return { failure: { code: 'MODEL_NOT_JSON', message: '模型没有按 JSON 格式输出(纯文本回复,未发现任何 JSON 对象)—— 多半是模型不遵守结构化输出;建议换一个 provider/model,或开启「仅试首选」避免反复轮换:' + describeOutputExcerpt(out) } }
376
+ }
373
377
  const why = out ? '模型输出无法解析为 JSON' : '模型返回空文本'
374
378
  // 括号没闭合 = 截断的强特征:即便宿主没给 max-tokens finish,也把方向指对(#18 建议 1)
375
379
  const hint = out && looksTruncatedJson(out) ? '(JSON 括号未闭合,疑似输出被截断)' : ''
@@ -604,7 +608,7 @@ function cardFromParsedJson(parsed) {
604
608
  * parsed=true → JSON 解析成功;card=null 表示内容不合格 / 不值得保存
605
609
  */
606
610
  export function parseCaptureJsonDetailed(text) {
607
- if (!text) return { card: null, parsed: false, error: '空输出', repaired: false }
611
+ if (!text) return { card: null, parsed: false, error: '空输出', repaired: false, noJson: true }
608
612
  // 去掉可能的 ```json 围栏
609
613
  const cleaned = String(text).replace(/^```(?:json)?\s*/i, '').replace(/```\s*$/, '').trim()
610
614
  const bases = [cleaned]
@@ -634,7 +638,9 @@ export function parseCaptureJsonDetailed(text) {
634
638
  }
635
639
  return { card: cardFromParsedJson(parsed), parsed: true, error: '', repaired: candidate.repaired }
636
640
  }
637
- return { card: null, parsed: false, error: lastError || '输出不是合法 JSON', repaired: false }
641
+ // noJson=true = 输出里**根本没有 JSON 对象**(纯散文):这不是「格式写坏了」,是模型不守格式。
642
+ // 两者要分开报/分开处理 —— 前者换模型才有用,后者重试可能成功(issue #47 的日志就是前者)。
643
+ return { card: null, parsed: false, error: lastError || '输出不是合法 JSON', repaired: false, noJson: !cleaned.includes('{') }
638
644
  }
639
645
 
640
646
  /** 兼容旧签名:解析成卡片;解析失败 / 内容不合格返回 null。 */