From 0ed4b7bbed1aaf20b607c1dba5bb4c7767c0664f Mon Sep 17 00:00:00 2001 From: Eva Date: Fri, 10 Apr 2026 01:23:20 +0700 Subject: [PATCH 1/5] feat(cortex): log when relevant-memories injection is truncated by maxInjectionChars\n\nRefs #5 --- dist/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dist/index.js b/dist/index.js index c718d2d..a9a9f6c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -764,6 +764,7 @@ function formatMemoryContext(items, maxChars, maxCount = 8, minScore = 0.25) { return ""; const lines = [""]; let charCount = 0; + let injectedCount = 0; for (const item of relevant) { const tag = item.source === "cornerstone" ? " [cornerstone]" : ""; // Build metadata prefix: [id] [date] [salience/category] @@ -781,9 +782,14 @@ function formatMemoryContext(items, maxChars, maxCount = 8, minScore = 0.25) { break; lines.push(line); charCount += line.length; + injectedCount++; } if (lines.length === 1) return ""; // Only header, no items fit + if (items.length > injectedCount) { + console.info(`[cortex] memories-injected=${injectedCount}/${items.length} chars=${charCount}/${maxChars}`); + lines.push(`[${injectedCount} of ${items.length} memories shown — use cortex_search for more]`); + } lines.push(""); return lines.join("\n"); } From f700dc04033da31fd1fae37f9ea1f71e8332a6c9 Mon Sep 17 00:00:00 2001 From: Eva Date: Fri, 10 Apr 2026 01:36:12 +0700 Subject: [PATCH 2/5] fix(charcap-logging): track explicit capHit flag instead of items.length > injectedCount --- dist/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index a9a9f6c..56f0d0a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -765,6 +765,7 @@ function formatMemoryContext(items, maxChars, maxCount = 8, minScore = 0.25) { const lines = [""]; let charCount = 0; let injectedCount = 0; + let capHit = false; for (const item of relevant) { const tag = item.source === "cornerstone" ? " [cornerstone]" : ""; // Build metadata prefix: [id] [date] [salience/category] @@ -778,17 +779,19 @@ function formatMemoryContext(items, maxChars, maxCount = 8, minScore = 0.25) { const line = prefix ? `- ${prefix} ${item.content}${tag}` : `- ${item.content}${tag}`; - if (charCount + line.length > maxChars) + if (charCount + line.length > maxChars) { + capHit = true; break; + } lines.push(line); charCount += line.length; injectedCount++; } if (lines.length === 1) return ""; // Only header, no items fit - if (items.length > injectedCount) { - console.info(`[cortex] memories-injected=${injectedCount}/${items.length} chars=${charCount}/${maxChars}`); - lines.push(`[${injectedCount} of ${items.length} memories shown — use cortex_search for more]`); + if (capHit) { + console.info(`[cortex] memories-injected=${injectedCount}/${relevant.length} chars=${charCount}/${maxChars}`); + lines.push(`[${injectedCount} of ${relevant.length} memories shown — use cortex_search for more]`); } lines.push(""); return lines.join("\n"); From 226fbe23223d367d5bcf4182d86424abe0f1967c Mon Sep 17 00:00:00 2001 From: Eva Date: Fri, 10 Apr 2026 01:36:17 +0700 Subject: [PATCH 3/5] fix(charcap-logging): use api.logger instead of console.info --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 56f0d0a..b4edf4e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -790,7 +790,7 @@ function formatMemoryContext(items, maxChars, maxCount = 8, minScore = 0.25) { if (lines.length === 1) return ""; // Only header, no items fit if (capHit) { - console.info(`[cortex] memories-injected=${injectedCount}/${relevant.length} chars=${charCount}/${maxChars}`); + api.logger.info(`[cortex] memories-injected=${injectedCount}/${relevant.length} chars=${charCount}/${maxChars}`); lines.push(`[${injectedCount} of ${relevant.length} memories shown — use cortex_search for more]`); } lines.push(""); From eb0a3710de91c44734b4ec92c3bffc20605c6342 Mon Sep 17 00:00:00 2001 From: Eva Date: Fri, 10 Apr 2026 01:36:23 +0700 Subject: [PATCH 4/5] fix(charcap-logging): log zero-memories-fit edge case on early return --- dist/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index b4edf4e..3b8da64 100644 --- a/dist/index.js +++ b/dist/index.js @@ -787,8 +787,11 @@ function formatMemoryContext(items, maxChars, maxCount = 8, minScore = 0.25) { charCount += line.length; injectedCount++; } - if (lines.length === 1) + if (lines.length === 1) { + if (capHit) + api.logger.info(`[cortex] memories-injected=0/${relevant.length} chars=${charCount}/${maxChars}`); return ""; // Only header, no items fit + } if (capHit) { api.logger.info(`[cortex] memories-injected=${injectedCount}/${relevant.length} chars=${charCount}/${maxChars}`); lines.push(`[${injectedCount} of ${relevant.length} memories shown — use cortex_search for more]`); From e5213cff8f225a1b07aab5e298e832d69111c7c7 Mon Sep 17 00:00:00 2001 From: Eva Date: Fri, 10 Apr 2026 01:36:33 +0700 Subject: [PATCH 5/5] fix(charcap-logging): log final serialized block length, not loop counter --- dist/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dist/index.js b/dist/index.js index 3b8da64..28d90fe 100644 --- a/dist/index.js +++ b/dist/index.js @@ -788,13 +788,16 @@ function formatMemoryContext(items, maxChars, maxCount = 8, minScore = 0.25) { injectedCount++; } if (lines.length === 1) { - if (capHit) - api.logger.info(`[cortex] memories-injected=0/${relevant.length} chars=${charCount}/${maxChars}`); + if (capHit) { + const serializedLength = lines.join("\n").length; + api.logger.info(`[cortex] memories-injected=0/${relevant.length} chars=${serializedLength}/${maxChars}`); + } return ""; // Only header, no items fit } if (capHit) { - api.logger.info(`[cortex] memories-injected=${injectedCount}/${relevant.length} chars=${charCount}/${maxChars}`); lines.push(`[${injectedCount} of ${relevant.length} memories shown — use cortex_search for more]`); + const serializedLength = lines.join("\n").length; + api.logger.info(`[cortex] memories-injected=${injectedCount}/${relevant.length} chars=${serializedLength}/${maxChars}`); } lines.push(""); return lines.join("\n");