You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve memory quality: utility-based injection reranking and smarter dreamer archival
- Rerank memory injection by utility tier (retrieved > constraint-keyword > other)
instead of seen_count alone, with shorter-content tiebreak to fit more in budget
- Overhaul dreamer archive-stale prompt with structured archive/keep criteria,
category-specific protection (CONSTRAINTS nearly untouchable, KNOWN_ISSUES never
archived), and 'because'/'to prevent' keyword preservation for ARCHITECTURE_DECISIONS
- Pass active user memories into archive-stale as Global User Profile context so
dreamer can identify project memories redundant with globally-injected user profile
### Global User Profile (already injected into ALL sessions across ALL projects)
117
+
These user memories are ALREADY available to the agent globally. Project memories that merely restate the same preference/rule are redundant and should be archived — but ONLY if the project memory adds ZERO project-specific detail beyond what the global memory already says.
Find and archive memories that reference removed features, discontinued tools, old paths, obsolete workflows, or completed one-time instructions.
128
+
Find and archive memories that waste the limited injection budget (~6000 tokens, fits ~150 memories).
129
+
${userProfileBlock}
130
+
### Archive criteria (archive IF any apply)
131
+
132
+
1. **Code restatement without rationale** — merely describes what code does without explaining WHY or what would break if changed.
133
+
- Archive: "Tag assignment uses one DB transaction" (obvious from code)
134
+
- Keep: "Tag assignment uses one DB transaction because tags rows and session_meta.counter must stay in sync" (explains the constraint)
135
+
136
+
2. **Redundant with other memories** — same information expressed differently. Keep the better-worded one.
137
+
138
+
3. **Stale implementation detail** — references specific functions, line numbers, or internal structures that change frequently and are better found by reading code.
139
+
- Archive: "Function X is called at line 289 of file Y"
140
+
- Keep: "Feature X requires Y to be initialized before Z" (design constraint)
141
+
142
+
4. **Low retrieval signal** — seen_count=1, retrieval_count=0, and no constraint language. These were promoted once but never needed again.
143
+
144
+
5. **Redundant with global user profile** — ONLY if the project memory adds ZERO project-specific detail beyond what the global memory already says. A project memory that applies a global principle to a specific context (e.g., "cache awareness is highest priority" applies a general principle to THIS project's north star) is NOT redundant — it narrows the global principle.
145
+
146
+
6. **Bare config defaults** — single-line values like \`enabled=true\` or \`experimental.X=false\` with no surrounding explanation or rationale.
147
+
148
+
7. **Completed one-time instructions** — imperative USER_DIRECTIVES like "Add X", "Create Y", "Publish as Z" where the action has clearly been done.
149
+
150
+
### Keep criteria (keep IF ANY apply — these OVERRIDE archive criteria)
151
+
152
+
1. **Contains constraint/rule** — uses "must", "never", "always", "cannot", "should not". CONSTRAINTS category gets extra protection: only archive if the EXACT same constraint exists word-for-word in another memory.
153
+
2. **Captures non-obvious design reasoning** — explains WHY, not just WHAT. Look for "because", "so that", "to prevent", "to avoid".
154
+
3. **Project-specific behavioral rule** — even if it sounds generic, if it's in USER_DIRECTIVES it was explicitly stated by the user for this project. Only archive if: (a) the action is clearly completed, or (b) it is 100% identical in scope to a global user memory.
155
+
4. **Post-failure learning** — memories that encode lessons learned from real bugs, regressions, or user corrections. These prevent re-encountering the same problem.
156
+
5. **Environment/path information** — saves agent from hunting for locations.
157
+
6. **Config defaults with context** — prevents wrong assumptions. Archive ONLY bare values with no surrounding explanation.
8. **High retrieval signal** — retrieval_count > 0 means the agent actually searched for this.
160
+
9. **Priority/philosophy statements** — "X is the highest priority" or "north star" type directives that shape all decisions.
116
161
117
162
### Process
118
163
119
164
1. **List all active memories** with \`ctx_memory(action="list")\`.
120
-
2. **Scan for staleness signals:**
121
-
- References to tools that no longer exist (grep the tool registry)
122
-
- References to files or directories that were deleted or renamed
123
-
- References to old repository names, branches, or workflows
124
-
- References to features explicitly described as "removed" or "replaced"
125
-
- References to config keys that no longer appear in the schema
126
-
- Session-local context that has no ongoing value ("in this session", "earlier today")
127
-
- **Completed one-time instructions** in USER_DIRECTIVES — imperative directives like "Add X", "Create Y", "License as MIT", "Publish as Z" where the action has clearly been done (check the codebase to confirm completion)
128
-
- **Low-value implementation minutiae** in ARCHITECTURE_DECISIONS — single-line statements that merely restate what code does without explaining WHY or capturing a non-obvious constraint. Example: "Tag assignment uses one DB transaction" just restates code behavior — this belongs in source comments, not project memory. Keep memories that explain *why* a design choice was made, *what constraint* drove it, or *what would break* if it changed.
165
+
2. **Apply the archive and keep criteria above to each memory.**
129
166
3. **Verify each candidate** against the codebase before archiving:
130
167
- Check if the file/tool/path actually exists
131
-
- Check if the feature is mentioned in current code
132
-
- For USER_DIRECTIVES: verify the instructed action was completed (e.g., "License as MIT" → check LICENSE file exists)
168
+
- For USER_DIRECTIVES: verify the instructed action was completed
133
169
- If the reference is ambiguous, leave it alone
134
170
4. **Archive** with \`ctx_memory(action="archive", id=N, reason="...")\`. Always include a specific reason.
135
171
136
-
### Common staleness patterns
137
-
- Old plugin paths (e.g., \`oh-my-opencode\` references when the plugin is now \`magic-context\`)
138
-
- Removed tools (e.g., \`ctx_recall\` was merged into \`ctx_memory\`)
- Completed setup/publishing/licensing instructions that are done and won't recur
143
-
- Implementation details that simply restate code behavior without adding design rationale
144
-
145
-
### USER_DIRECTIVES handling
146
-
- **Archive** completed one-time instructions: "License as MIT", "Publish as @cortexkit/...", "Add changelog to releases", "For the README animation, emphasize X"
147
-
- **Keep** ongoing preferences and behavioral rules: "Ask before changing behavior when audit finding is ambiguous", "Cache awareness is the highest-priority feature"
148
-
- **Keep** workflow preferences that apply to future work: "Always use scripts/release.sh for releases"
149
-
- Rule of thumb: if the directive uses imperative "do this" language and the action is done, archive it. If it describes how to behave going forward, keep it.
150
-
151
-
### ARCHITECTURE_DECISIONS pruning
152
-
- **Archive** memories that only restate what code does: "Function X calls Y", "Module A imports B"
153
-
- **Keep** memories that explain constraints, tradeoffs, or non-obvious design reasoning: "X uses Y because Z would cause cache busts"
154
-
- **Keep** memories that warn about gotchas: "Don't use cwd fallback because it causes cross-project contamination"
155
-
- Rule of thumb: if removing the memory would cause someone to make a wrong design decision, keep it. If it's just restating navigable code structure, archive it — ARCHITECTURE.md covers that.
172
+
### Category-specific rules
173
+
- **CONSTRAINTS**: archive ONLY when provably redundant with another specific constraint (not just thematically similar). Each constraint typically guards against a specific bug — losing it means the bug can return.
174
+
- **USER_DIRECTIVES**: archive ONLY completed one-time tasks or exact duplicates of global user profile entries. Keep ongoing behavioral rules even if they have low retrieval.
175
+
- **KNOWN_ISSUES**: NEVER archive — these prevent re-encountering bugs.
0 commit comments