Add exact KV memory with persona overlays and param priority.

Canonical defaults live in exact.json (UI fills empties without an LLM call); chat session overrides beat file defaults until clear/persona change.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Leonid Pershin
2026-08-21 23:04:34 +03:00
co-authored by Cursor
parent fe4d8d3a3a
commit 1b9cc1ad78
15 changed files with 418 additions and 121 deletions
+35 -2
View File
@@ -1347,6 +1347,16 @@ public class SwarmAssistentExtension : Extension
}
}
JObject exact = Config.LoadExact(pid);
if (exact is not null && exact.Count > 0)
{
system.AppendLine();
system.AppendLine("## Exact memory (canonical KV — always trust over RAG guesses)");
system.AppendLine("```json");
system.AppendLine(exact.ToString(Newtonsoft.Json.Formatting.None));
system.AppendLine("```");
}
foreach (string skillId in skillIds ?? Config.ResolveEnabledSkills(pid, null))
{
string skillText = Config.LoadSkillPrompt(pid, skillId);
@@ -1564,7 +1574,7 @@ public class SwarmAssistentExtension : Extension
Logs.Debug($"Assistent memory retrieve: {ex.Message}");
}
string enrichedContext = InjectMemoryHits(contextJson, hits);
string enrichedContext = InjectMemoryHits(contextJson, hits, Config.LoadExact(pid));
List<JObject> messages = BuildOllamaMessages(packName, includeBase, enrichedContext, userMessages, personaId: pid, skillIds: skills);
JArray civitaiResults = [];
string reply = "";
@@ -1659,7 +1669,7 @@ public class SwarmAssistentExtension : Extension
return string.IsNullOrWhiteSpace(q) ? "krea2 prompting" : q;
}
static string InjectMemoryHits(string contextJson, JArray hits)
static string InjectMemoryHits(string contextJson, JArray hits, JObject exact = null)
{
JObject ctx;
try
@@ -1671,6 +1681,29 @@ public class SwarmAssistentExtension : Extension
ctx = new JObject { ["_raw_context"] = contextJson };
}
ctx["memory_hits"] = hits ?? new JArray();
if (exact is not null && exact.Count > 0 && ctx["exact"] is null)
{
ctx["exact"] = exact;
}
if (ctx["session_exact"] is null)
{
ctx["session_exact"] = new JObject();
}
if (ctx["recommended_params"] is null && exact?["generation"] is JObject gen)
{
JObject rec = new();
foreach (string key in new[] { "steps", "cfg", "sigma_shift", "aspect", "images" })
{
if (gen[key] is not null)
{
rec[key] = gen[key].DeepClone();
}
}
if (rec.Count > 0)
{
ctx["recommended_params"] = rec;
}
}
// Slim inventory for LLM: keep enabled + current, drop full dump if present
if (ctx["available_loras"] is JArray allLoras && allLoras.Count > 24)
{