SessionStart injects raw JSON bundle: key list misses the engine's rendered_markdown field

未關閉 適合新手
#8 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
1/5
預估耗時
1 小時以內
新手友好度
88/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
javascript, nodejs
領域
tooling

研究方向

開啟 hooks/zcode-mem-hook.mjs,閱讀 L245-250 附近的 summarizeContextBundle,此處會先檢查 render 鍵清單,然後再回退到 JSON.stringify。透過將 nmem --json context --source-app zcode 的輸出餵給它來重現,並確認輸出顯示的是帶有頂層 rendered_markdown 字串的原始 JSON。將 payload.rendered_markdown 加到查詢清單的最前面,並重新執行該 hook,以確認注入的上下文以 Markdown 渲染開頭,而不是 JSON dump。

由索引模型根據 Issue 內容生成。

描述

Environment
  • nowledge-mem-zcode: 0.2.2 (installed via ZCode plugin marketplace)
  • nmem CLI / engine: 0.10.119
  • OS: macOS (darwin 25.6.0, arm64)
What happens

On SessionStart, the hook's injected additionalContext is the entire context bundle pretty-printed as raw JSON (truncated to MAX_CONTEXT_CHARS = 6000), instead of the human-readable render the engine already provides.

Root cause

summarizeContextBundle (hooks/zcode-mem-hook.mjs, L245-250 in 0.2.2):

const rendered = payload.markdown || payload.content || payload.context || payload.working_memory;
if (typeof rendered === "string" && rendered.trim()) return rendered.trim();
return JSON.stringify(payload, null, 2);

The engine's context bundle (nmem --json context --source-app zcode) carries the human-readable render under a key this list does not cover:

  • top-level keys observed: active_space, agent_profile, authorship, bundle_kind, compiled_hash, generated_at, kfs_roots, owner_profile, rendered_markdown, rule_stack, schema_version, warnings, working_memory
  • rendered_markdown: string, ~11.7k chars — a finished Markdown render (first line # Nowledge Mem Context Bundle)
  • working_memory: object, so it fails the typeof rendered === "string" check

All four lookups miss → the fallback dumps the whole bundle as JSON.

The engine clearly intends this surface to be human-readable: nmem context without --json (help text: "Emit raw JSON instead of human-readable output") outputs the same rendered Markdown, line-identical to rendered_markdown apart from two blank lines.

Suggested fix (one line)

Add the engine's key to the lookup list:

const rendered = payload.rendered_markdown || payload.markdown || payload.content || payload.context;

(working_memory can stay last or be dropped from the string path — it is an object in current engine output.)

Local workaround in place

A companion hook injecting nmem context plain-mode output as session-start additionalContext (coexists with the official hook until this is fixed). Verified on 0.2.2 + nmem 0.10.119: official hook output is the 6000-char JSON dump; plain-mode output is the clean render.

Notes
  • 0.2.2 release notes do not mention SessionStart / rendered_markdown, so this appears unreported.
  • Side observation: the SessionStart matcher (startup|clear|compact) does not cover resume, which the ZCode host also fires for SessionStart hooks.
主要語言
JavaScript
星號
3
分支
1
PR 合併指標
30 天內沒有已合併 PR

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

nowledge-co/zcode-plugin 的其他 Issue

查看 nowledge-co/zcode-plugin 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。