fix(cypher): interpolateString single-ref array/object pass-through (P0 #11)
mira_feed_watcher 第一輪 cron tick 跑 264ms 完成但 0 raw 處理 — 挖到 root cause:
interpolateString 看到模板就 string.replace,非 string 值(如 kbdb_get 回的
blocks 陣列)一律 JSON.stringify。所以 `items: "{{list_raws.blocks}}"` 把
陣列轉成字串給 filter 零件,filter 收到字串 != array → items 被忽略 →
FOREACH 跑 0 次 → watcher 看似成功實則空跑。
修:interpolateString 加 single-ref pass-through —— 若整個值是純單一 `{{x}}`
引用,回 raw value(保留 array / object 型別)。多 ref / 混合文字仍 stringify。
對應 SDD: arcrun.md 三-A P0 #11。
下一輪 cron tick 應該真正處理 raws,加 wiki-processed tag。
This commit is contained in:
@@ -526,8 +526,18 @@ function propagateCtx(
|
||||
* 支援 array index:{{paragraphs.0.entity}} → ctx.paragraphs[0].entity
|
||||
* 非 string 值(object/array)遞迴展開內部 string;undefined / null / number / bool 保留原值
|
||||
* 2026-05-13 加遞迴:原本只跑 top-level,set 零件 values 嵌套 / kbdb_create_block content 內含 {{x.y}} 用不了。
|
||||
* 2026-05-14 加 single-ref pass-through:若整個 string 是 `{{x}}` 且 x 是 array / object,
|
||||
* 回 raw value 不 stringify(讓 filter `items: "{{list.blocks}}"` 能拿到真陣列)。
|
||||
* 多 ref 或混合文字仍 stringify 為字串。
|
||||
*/
|
||||
function interpolateString(s: string, ctx: Record<string, unknown>): string {
|
||||
function interpolateString(s: string, ctx: Record<string, unknown>): unknown {
|
||||
// 整個值是單一 {{x}} 引用 → 回 raw value(保留 array / object 型別)
|
||||
const single = s.match(/^\s*\{\{([\w.]+)\}\}\s*$/);
|
||||
if (single) {
|
||||
const val = getNestedValue(ctx, single[1]);
|
||||
return val === undefined ? s : val;
|
||||
}
|
||||
// 多 ref / 混合文字 → 一律拼成 string
|
||||
return s.replace(/\{\{([\w.]+)\}\}/g, (_, key: string) => {
|
||||
const val = getNestedValue(ctx, key);
|
||||
if (val === undefined) return `{{${key}}}`;
|
||||
|
||||
Reference in New Issue
Block a user