Skip to content

Commit 3e28417

Browse files
author
Tehan
committed
fix(skill-memory): gate ctx_memory cross-ref in skill guidance when memory off
Rebase-onto-v0.29.0 resolution completion. Upstream ab4f01c added a memory.enabled gate that drops ALL ctx_memory mentions from the system prompt when memory is off (ctx_memory is then unregistered). The skill-memory guidance carried a 'those belong in ctx_memory' cross-reference that violated the new contract (buildMagicContextSection memory-gating tests). Parameterized ctxSkillMemoryGuidance(memoryEnabled) so the cross-ref drops when memory is off; skill-memory itself stays ungated (independent store).
1 parent 7618eb8 commit 3e28417

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

packages/plugin/src/agents/magic-context-prompt.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,20 @@ function memoryGuidanceBlock(memoryEnabled: boolean): string {
7070
// `ctx_skill_recall` rehydrates accumulated notes for a skill without re-loading it.
7171
// Distinct from `ctx_memory`, which captures general project knowledge (not tied
7272
// to a specific skill). NOT gated on memory.enabled — skill-memory is an
73-
// independent store (its own table + tool-result-tail injection).
74-
const CTX_SKILL_MEMORY_GUIDANCE = `Use \`ctx_skill_note\` after using a skill when you hit a non-obvious issue, found a better approach, or fixed a skill-specific error. Skip routine successes — only record gotchas, discoveries, fixes, and workflow steps that would save time on the next use.
73+
// independent store (its own table + tool-result-tail injection) — BUT the
74+
// `ctx_memory` cross-reference is dropped when memory is off, since ctx_memory is
75+
// then unregistered and pointing at it would be misleading (mirrors MEMORY_GUIDANCE).
76+
function ctxSkillMemoryGuidance(memoryEnabled: boolean): string {
77+
const generalObservationsLine = memoryEnabled
78+
? "Do NOT use `ctx_skill_note` for general project observations — those belong in `ctx_memory`."
79+
: "Do NOT use `ctx_skill_note` for general project observations.";
80+
return `Use \`ctx_skill_note\` after using a skill when you hit a non-obvious issue, found a better approach, or fixed a skill-specific error. Skip routine successes — only record gotchas, discoveries, fixes, and workflow steps that would save time on the next use.
7581
Example: \`ctx_skill_note({skill: 'trilium', intent: 'bulk-retag a subtree', kind: 'gotcha', delta: 'ETAPI note PUT needs Content-Type: text/plain even for HTML content'})\`
7682
Example: \`ctx_skill_note({skill: 'test-driven-development', intent: 'fix flaky auth test', kind: 'fix', delta: 'Always mock Date.now() in auth tests — real timers cause intermittent failures'})\`
77-
Do NOT use \`ctx_skill_note\` for general project observations — those belong in \`ctx_memory\`.
83+
${generalObservationsLine}
7884
7985
Use \`ctx_skill_recall\` to explicitly query accumulated notes for a skill without re-loading it. Call it when you want to recall gotchas/discoveries for a skill you have already loaded this session, or when you need notes without triggering a full skill load. Returns the \`<skill-memory>\` block directly as a tool result. Example: \`ctx_skill_recall({skill: 'trilium', intent: 'bulk-retag a subtree'})\`.`;
86+
}
8087

8188
const BASE_INTRO = (
8289
protectedTags: number,
@@ -85,7 +92,7 @@ const BASE_INTRO = (
8592
Use \`ctx_reduce\` to mark spent tagged content as discardable and reclaim space. Marking is NOT an immediate delete — it queues the content, which stays fully visible until space is actually needed (as soon as the next turn if you're already under pressure, much later if not), so mark a tool output as soon as you're done with it rather than hoarding the call for the end of the turn. The last ${protectedTags} tags are protected (marking one just queues it until it ages out). Syntax: "3-5", "1,2,9", or "1-5,8,12-15".
8693
Do not announce or narrate \`ctx_reduce\` drops — just call the tool silently. Saying "I'll drop these outputs" wastes tokens the user does not care about.
8794
${CTX_NOTE_GUIDANCE}
88-
${memoryGuidanceBlock(memoryEnabled)}${CTX_SKILL_MEMORY_GUIDANCE}
95+
${memoryGuidanceBlock(memoryEnabled)}${ctxSkillMemoryGuidance(memoryEnabled)}
8996
Use \`ctx_search\` to search across project memories, indexed git commits, and this session's full conversation history (including compacted parts) from one query.
9097
Use \`ctx_expand\` to recover the raw conversation behind a \`<compartment>\` summary in \`<session-history>\` — pass its \`start\`/\`end\` attributes when the summary is not enough (exact wording, values, error text).
9198
**Search before asking the user**: If you can't remember or don't know something that might have been discussed before or stored in project memory, use \`ctx_search\` before asking the user. Examples:
@@ -107,7 +114,7 @@ Before your turn finishes, consider using \`ctx_reduce\` to drop large tool outp
107114
* a tagging system they can't observe just wastes tokens and (empirically) primes
108115
* some models to emit malformed `§N">§` tokens at the start of their own text. */
109116
const BASE_INTRO_NO_REDUCE = (memoryEnabled: boolean): string => `${CTX_NOTE_GUIDANCE}
110-
${memoryGuidanceBlock(memoryEnabled)}${CTX_SKILL_MEMORY_GUIDANCE}
117+
${memoryGuidanceBlock(memoryEnabled)}${ctxSkillMemoryGuidance(memoryEnabled)}
111118
Use \`ctx_search\` to search across project memories, indexed git commits, and this session's full conversation history (including compacted parts) from one query.
112119
Use \`ctx_expand\` to recover the raw conversation behind a \`<compartment>\` summary in \`<session-history>\` — pass its \`start\`/\`end\` attributes when the summary is not enough (exact wording, values, error text).
113120
**Search before asking the user**: If you can't remember or don't know something that might have been discussed before or stored in project memory, use \`ctx_search\` before asking the user. Examples:

0 commit comments

Comments
 (0)