diff --git a/.agents/specs/arcrun/arcrun.md b/.agents/specs/arcrun/arcrun.md index cd3964f..56a91a2 100644 --- a/.agents/specs/arcrun/arcrun.md +++ b/.agents/specs/arcrun/arcrun.md @@ -233,6 +233,18 @@ acr push 就會自動建立 cron-idx 並開始定時觸發。 --- +#### P0 #11(2026-05-14 已解決):interpolateString stringify array 撐爆下游 + +**現象**:mira_feed_watcher 用 `items: "{{list_raws.blocks}}"` 把 kbdb_get 拿到的 blocks 陣列傳給 filter 零件。watcher 跑 264ms 完成、0 raw 處理。 + +**根因**:`interpolateString` 看到模板就用 `String.replace`,非 string 值(陣列)一律 `JSON.stringify`。filter 零件收到字串 `"[{...},{...}]"` 不是 array,items 被忽略 → 0 matches → FOREACH 跑 0 次。 + +**修法**:`interpolateString` 加 single-ref pass-through 規則:若整個值是純單一 `{{x}}` 引用,回 raw value(保留 array / object 型別)。多 ref / 混合文字仍 stringify 拼接字串。 + +**測試**:mira_feed_watcher 推到 prod 後下一個 cron tick 觀察 wiki-processed tag 是否在 raws 上出現。 + +--- + ### 三-B、新零件加入紀錄 | 日期 | 零件 | 動機 | 對應 SDD | diff --git a/cypher-executor/src/graph-executor.ts b/cypher-executor/src/graph-executor.ts index 7ffc66e..0f6c51c 100644 --- a/cypher-executor/src/graph-executor.ts +++ b/cypher-executor/src/graph-executor.ts @@ -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 { +function interpolateString(s: string, ctx: Record): 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}}}`;