toon-memory 3.4.0 ā 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.de.md +9 -4
- package/README.es.md +9 -4
- package/README.fr.md +9 -4
- package/README.ja.md +9 -4
- package/README.ko.md +9 -4
- package/README.md +9 -8
- package/README.pt-br.md +9 -4
- package/README.zh.md +9 -4
- package/dist/cli/setup.js +1 -1
- package/mcp/server.js +206 -49
- package/package.json +2 -2
- package/skills/toon-memory.md +20 -0
- package/src/lib/graph.ts +24 -15
- package/src/lib/quality.ts +30 -15
- package/src/lib/sessions.ts +8 -0
- package/src/mcp/tools.ts +172 -15
package/src/lib/quality.ts
CHANGED
|
@@ -139,9 +139,14 @@ export function mergeEntries(existingLine: string, newLine: string): string {
|
|
|
139
139
|
const newLastAccessed = np.length > 12 ? np[12] || "" : ""
|
|
140
140
|
const lastAccessed = newLastAccessed > existingLastAccessed ? newLastAccessed : existingLastAccessed
|
|
141
141
|
|
|
142
|
+
// Take max priority (field 13)
|
|
143
|
+
const existingPriority = ep.length > 13 ? parseInt(ep[13]) || 0 : 0
|
|
144
|
+
const newPriority = np.length > 13 ? parseInt(np[13]) || 0 : 0
|
|
145
|
+
const priority = Math.max(existingPriority, newPriority)
|
|
146
|
+
|
|
142
147
|
const quality = qualityScore(mergedTags, mergedLinks, content, date, accessed, lastAccessed)
|
|
143
148
|
|
|
144
|
-
return `${id}|${category}|${key}|${content}|${file}|${mergedTags}|${date}|${ttl}|${accessed}|${mergedLinks}|${quality.toFixed(2)}|${confidence}|${lastAccessed}`
|
|
149
|
+
return `${id}|${category}|${key}|${content}|${file}|${mergedTags}|${date}|${ttl}|${accessed}|${mergedLinks}|${quality.toFixed(2)}|${confidence}|${lastAccessed}|${priority}`
|
|
145
150
|
}
|
|
146
151
|
|
|
147
152
|
/**
|
|
@@ -151,7 +156,7 @@ export function mergeEntries(existingLine: string, newLine: string): string {
|
|
|
151
156
|
export function generateSmartRecall(
|
|
152
157
|
data: string,
|
|
153
158
|
intent: string,
|
|
154
|
-
opts: { limit?: number; category?: string; bumpAccess?: (ids: string[]) => void; fileMtimes?: Map<string, string
|
|
159
|
+
opts: { limit?: number; category?: string; bumpAccess?: (ids: string[]) => void; fileMtimes?: Map<string, string>; sessionFiles?: string[] } = {}
|
|
155
160
|
): string {
|
|
156
161
|
const entries = parseEntries(data)
|
|
157
162
|
if (entries.length === 0) return "Empty memory."
|
|
@@ -190,32 +195,42 @@ export function generateSmartRecall(
|
|
|
190
195
|
const fileDate = mtimes.get(filePath)
|
|
191
196
|
if (fileDate && e.date && fileDate > e.date) drift = 0.3
|
|
192
197
|
}
|
|
198
|
+
// Session bias: boost entries matching current session files
|
|
199
|
+
let sessionBias = 0
|
|
200
|
+
if (opts.sessionFiles && opts.sessionFiles.length > 0 && e.file) {
|
|
201
|
+
const entryFile = e.file.split(":")[0]
|
|
202
|
+
if (opts.sessionFiles.some((f) => f === entryFile)) {
|
|
203
|
+
sessionBias = 0.15
|
|
204
|
+
}
|
|
205
|
+
}
|
|
193
206
|
const combined =
|
|
194
|
-
bm25Score + 0.3 * centScore + 0.3 * impScore + (matchesQuery ? 0.5 : 0) - drift
|
|
195
|
-
return { entry: e, score: combined, matchesQuery,
|
|
207
|
+
bm25Score + 0.3 * centScore + 0.3 * impScore + (matchesQuery ? 0.5 : 0) - drift + sessionBias
|
|
208
|
+
return { entry: e, score: combined, matchesQuery, priority: e.priority }
|
|
196
209
|
})
|
|
197
210
|
.filter((x) => x.score > 0 || x.matchesQuery)
|
|
198
211
|
.sort((a, b) => {
|
|
199
|
-
if (a.
|
|
212
|
+
if (a.priority !== b.priority) return b.priority - a.priority
|
|
200
213
|
return b.score - a.score
|
|
201
214
|
})
|
|
202
215
|
.slice(0, limit)
|
|
203
216
|
|
|
204
|
-
// Inject pinned entries not already in the result set.
|
|
205
|
-
const pinnedKeys = new Set(entries.filter((e) => e.
|
|
217
|
+
// Inject pinned entries not already in the result set, sorted by priority desc.
|
|
218
|
+
const pinnedKeys = new Set(entries.filter((e) => e.priority > 0).map((e) => e.key))
|
|
206
219
|
const inResult = new Set(scored.map((x) => x.entry.key))
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
220
|
+
const toInject = [...pinnedKeys]
|
|
221
|
+
.filter((k) => !inResult.has(k))
|
|
222
|
+
.map((k) => entries.find((en) => en.key === k)!)
|
|
223
|
+
.filter(Boolean)
|
|
224
|
+
.sort((a, b) => b.priority - a.priority)
|
|
225
|
+
for (const e of toInject) {
|
|
226
|
+
scored.unshift({ entry: e, score: 999, matchesQuery: false, priority: e.priority })
|
|
212
227
|
}
|
|
213
228
|
|
|
214
229
|
if (scored.length === 0) {
|
|
215
230
|
const top = entries
|
|
216
231
|
.filter((e) => !category || e.category === category)
|
|
217
232
|
.sort((a, b) => {
|
|
218
|
-
if (a.
|
|
233
|
+
if (a.priority !== b.priority) return b.priority - a.priority
|
|
219
234
|
return importance(b) - importance(a)
|
|
220
235
|
})
|
|
221
236
|
.slice(0, limit)
|
|
@@ -252,7 +267,7 @@ export function generateSystemPrimer(data: string): string {
|
|
|
252
267
|
const top = [...entries]
|
|
253
268
|
.filter((e) => !isPrivate(e))
|
|
254
269
|
.sort((a, b) => {
|
|
255
|
-
if (a.
|
|
270
|
+
if (a.priority !== b.priority) return b.priority - a.priority
|
|
256
271
|
return importance(b) - importance(a)
|
|
257
272
|
})
|
|
258
273
|
.slice(0, 5)
|
|
@@ -267,7 +282,7 @@ export function generateSystemPrimer(data: string): string {
|
|
|
267
282
|
e.lastAccessed
|
|
268
283
|
)
|
|
269
284
|
const conf = quality >= 0.5 ? "high" : quality >= 0.3 ? "medium" : "low"
|
|
270
|
-
const pin = e.
|
|
285
|
+
const pin = e.priority > 0 ? (e.priority > 1 ? ` š${e.priority}` : " š") : ""
|
|
271
286
|
lines.push(
|
|
272
287
|
` [${e.category}] ${e.key}${pin} ā ${e.content.slice(0, 80)} (quality: ${conf})`
|
|
273
288
|
)
|
package/src/lib/sessions.ts
CHANGED
|
@@ -226,6 +226,14 @@ export function detectConflicts(active: ActiveSessionView[] = listSessions().fil
|
|
|
226
226
|
return conflicts
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
+
/** Get files touched by the current session. Returns empty array if no heartbeat record. */
|
|
230
|
+
export function getCurrentSessionFiles(): string[] {
|
|
231
|
+
const id = resolveSessionId({})
|
|
232
|
+
const all = listSessions()
|
|
233
|
+
const mine = all.find((s) => s.id === id)
|
|
234
|
+
return mine ? Object.keys(mine.files) : []
|
|
235
|
+
}
|
|
236
|
+
|
|
229
237
|
/** Convenience: list active sessions + conflicts in one call. */
|
|
230
238
|
export function coordinationView(selfId?: string) {
|
|
231
239
|
const all = listSessions()
|
package/src/mcp/tools.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { encrypt, decrypt } from "./crypto"
|
|
|
15
15
|
import { graphRecallDetailed, renderCompact, parseEntries, buildGraph } from "../lib/graph"
|
|
16
16
|
import { qualityScore, mergeEntries, generateSmartRecall } from "../lib/quality"
|
|
17
17
|
import { generateContextBrief, generateContextGenerate, generateContextDiff, generateContextFocus, generateContextHealth, generateContextExport } from "../lib/context"
|
|
18
|
-
import { coordinationView, resolveSessionId, currentBranch, SESSION_TTL_MS } from "../lib/sessions"
|
|
18
|
+
import { coordinationView, resolveSessionId, currentBranch, SESSION_TTL_MS, getCurrentSessionFiles } from "../lib/sessions"
|
|
19
19
|
import { fileMtimes } from "../lib/git"
|
|
20
20
|
import { normalize, isExpiredLocal, tokenize, importance } from "../lib/utils"
|
|
21
21
|
import { expandSynonyms } from "../lib/synonyms"
|
|
@@ -142,14 +142,16 @@ server.registerTool(
|
|
|
142
142
|
mode: z.enum(["flat", "graph"]).optional().default("flat").describe("'flat' = keyword search (default). 'graph' = graph-based recall: expands the related-entry subgraph from matches (more precise, fewer tokens)."),
|
|
143
143
|
hops: z.number().optional().default(1).describe("Graph depth in 'graph' mode (1 or 2). Default 1."),
|
|
144
144
|
compact: z.boolean().optional().default(false).describe("Token-efficient output: numeric indices (1, 2), omits id/date/file (keeps tags), edges as '->2', truncates graph neighbors to a snippet. Does not mutate .toon file."),
|
|
145
|
+
bias: z.enum(["none", "session"]).optional().default("none").describe("'session': boost entries whose file matches current session files. 'none': no bias (default)."),
|
|
145
146
|
},
|
|
146
147
|
},
|
|
147
|
-
async ({ query, category, from_date, to_date, mode, hops, compact }) => {
|
|
148
|
+
async ({ query, category, from_date, to_date, mode, hops, compact, bias }) => {
|
|
148
149
|
const data = readMemory()
|
|
149
150
|
|
|
150
151
|
// Delegate to graphRecallDetailed for both flat and graph modes
|
|
151
152
|
// This avoids duplicating BM25 + ranking logic
|
|
152
|
-
const
|
|
153
|
+
const sessionFiles = bias === "session" ? getCurrentSessionFiles() : undefined
|
|
154
|
+
const detail = graphRecallDetailed(data, query, { category, from_date, to_date, hops, sessionFiles })
|
|
153
155
|
if (detail.entries.length === 0) {
|
|
154
156
|
return { content: [{ type: "text" as const, text: `No results found for "${query}"` }] }
|
|
155
157
|
}
|
|
@@ -165,7 +167,8 @@ server.registerTool(
|
|
|
165
167
|
const formatted = detail.entries
|
|
166
168
|
.map((r) => {
|
|
167
169
|
const links = r.links.length ? `\n links: ${r.links.join(", ")}` : ""
|
|
168
|
-
|
|
170
|
+
const pin = r.priority > 0 ? (r.priority > 1 ? ` š${r.priority}` : " š") : ""
|
|
171
|
+
return `[${r.category}] ${r.key}${pin} (${r.id})\n ${r.content}\n File: ${r.file} | Tags: ${r.tags.join(";")} | Date: ${r.date}${links}`
|
|
169
172
|
})
|
|
170
173
|
.join("\n\n")
|
|
171
174
|
return { content: [{ type: "text" as const, text: formatted }] }
|
|
@@ -280,6 +283,44 @@ server.registerTool(
|
|
|
280
283
|
.map((e) => ` ${e.key}: ${e.accessed}x (Q: ${e.quality})`),
|
|
281
284
|
]
|
|
282
285
|
|
|
286
|
+
// Cold memories: high quality but rarely accessed
|
|
287
|
+
const coldEntries = lines
|
|
288
|
+
.filter((l) => l.startsWith(" ") && l.includes("|") && !l.startsWith(" summaries:"))
|
|
289
|
+
.map((l) => {
|
|
290
|
+
const p = l.trim().split("|")
|
|
291
|
+
return {
|
|
292
|
+
key: p[2],
|
|
293
|
+
cat: p[1],
|
|
294
|
+
quality: parseFloat(p[10]) || 0,
|
|
295
|
+
accessed: p.length > 8 ? parseInt(p[8]) || 0 : 0,
|
|
296
|
+
lastAccessed: p.length > 12 ? p[12] || "" : "",
|
|
297
|
+
date: p[6] || "",
|
|
298
|
+
}
|
|
299
|
+
})
|
|
300
|
+
.filter((e) => {
|
|
301
|
+
if (e.accessed >= 2) return false
|
|
302
|
+
if (e.quality < 0.7) return false
|
|
303
|
+
const lastDate = e.lastAccessed || e.date
|
|
304
|
+
if (!lastDate) return false
|
|
305
|
+
const daysSinceLastAccess = (Date.now() - new Date(lastDate).getTime()) / 86400000
|
|
306
|
+
return daysSinceLastAccess > 30
|
|
307
|
+
})
|
|
308
|
+
.sort((a, b) => b.quality - a.quality)
|
|
309
|
+
|
|
310
|
+
if (coldEntries.length > 0) {
|
|
311
|
+
stats.push(
|
|
312
|
+
"",
|
|
313
|
+
`Cold memories (${coldEntries.length}):`,
|
|
314
|
+
...coldEntries.slice(0, 5).map((e) => {
|
|
315
|
+
const lastDate = e.lastAccessed || e.date
|
|
316
|
+
const daysSince = Math.round((Date.now() - new Date(lastDate).getTime()) / 86400000)
|
|
317
|
+
return ` ${e.key} (Q: ${e.quality.toFixed(2)}) ā ${daysSince}d since last access`
|
|
318
|
+
}),
|
|
319
|
+
"",
|
|
320
|
+
"š” Run memory_archive() to archive cold entries."
|
|
321
|
+
)
|
|
322
|
+
}
|
|
323
|
+
|
|
283
324
|
return { content: [{ type: "text" as const, text: stats.join("\n") }] }
|
|
284
325
|
}
|
|
285
326
|
)
|
|
@@ -382,12 +423,14 @@ server.registerTool(
|
|
|
382
423
|
intent: z.string().describe("Describe what you need to know (e.g. 'database schema for backend')"),
|
|
383
424
|
limit: z.number().optional().default(8).describe("Maximum entries to return"),
|
|
384
425
|
category: z.string().optional().default("").describe("Filter by category (empty = all)"),
|
|
426
|
+
bias: z.enum(["none", "session"]).optional().default("none").describe("'session': boost entries whose file matches current session files. 'none': no bias (default)."),
|
|
385
427
|
},
|
|
386
428
|
},
|
|
387
|
-
async ({ intent, limit, category }) => {
|
|
429
|
+
async ({ intent, limit, category, bias }) => {
|
|
388
430
|
const data = readMemory()
|
|
389
431
|
const mtimes = fileMtimes()
|
|
390
|
-
const
|
|
432
|
+
const sessionFiles = bias === "session" ? getCurrentSessionFiles() : undefined
|
|
433
|
+
const result = generateSmartRecall(data, intent, { limit, category, fileMtimes: mtimes, sessionFiles })
|
|
391
434
|
return { content: [{ type: "text" as const, text: result }] }
|
|
392
435
|
}
|
|
393
436
|
)
|
|
@@ -1450,10 +1493,31 @@ server.registerTool(
|
|
|
1450
1493
|
}
|
|
1451
1494
|
|
|
1452
1495
|
if (dryRun) {
|
|
1496
|
+
// Detailed preview: show what each merge produces
|
|
1497
|
+
const previewLines: string[] = [
|
|
1498
|
+
`š Dry run ā ${mergePairs.length} merge candidate(s) found:`,
|
|
1499
|
+
"",
|
|
1500
|
+
]
|
|
1501
|
+
for (const pair of mergePairs) {
|
|
1502
|
+
const a = parsed[pair.a], b = parsed[pair.b]
|
|
1503
|
+
const mergedTags = [...new Set([...a.tags.split(";"), ...b.tags.split(";")])].filter(Boolean).join(";")
|
|
1504
|
+
const longer = a.content.length >= b.content.length ? a : b
|
|
1505
|
+
const shorter = a.content.length < b.content.length ? a : b
|
|
1506
|
+
previewLines.push(` āā Pair: [${a.cat}] ${a.key} ā [${b.cat}] ${b.key}`)
|
|
1507
|
+
previewLines.push(` Similarity: ${(pair.similarity * 100).toFixed(0)}%`)
|
|
1508
|
+
previewLines.push(` A tags: ${a.tags || "(none)"}`)
|
|
1509
|
+
previewLines.push(` B tags: ${b.tags || "(none)"}`)
|
|
1510
|
+
previewLines.push(` ā Merged tags: ${mergedTags || "(none)"}`)
|
|
1511
|
+
previewLines.push(` ā Content winner: "${longer.key}" (${longer.content.length} chars vs ${shorter.content.length})`)
|
|
1512
|
+
previewLines.push(` ā Result content: ${longer.content.slice(0, 120)}${longer.content.length > 120 ? "ā¦" : ""}`)
|
|
1513
|
+
previewLines.push("")
|
|
1514
|
+
}
|
|
1515
|
+
previewLines.push(`Would merge ${merged.size} entries into ${entries.length - merged.size} entries.`)
|
|
1516
|
+
previewLines.push("Run with dryRun: false to apply.")
|
|
1453
1517
|
return {
|
|
1454
1518
|
content: [{
|
|
1455
1519
|
type: "text" as const,
|
|
1456
|
-
text:
|
|
1520
|
+
text: previewLines.join("\n"),
|
|
1457
1521
|
}],
|
|
1458
1522
|
}
|
|
1459
1523
|
}
|
|
@@ -1551,18 +1615,107 @@ server.registerTool(
|
|
|
1551
1615
|
}
|
|
1552
1616
|
)
|
|
1553
1617
|
|
|
1618
|
+
// āā memory_checkpoint āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
1619
|
+
|
|
1620
|
+
server.registerTool(
|
|
1621
|
+
"memory_checkpoint",
|
|
1622
|
+
{
|
|
1623
|
+
title: "Session Checkpoint",
|
|
1624
|
+
description: "Save or update a session checkpoint with 7-day TTL. Creates a knowledge entry snapshot of the current session state. Same session = upsert (single checkpoint per session). Auto-expires.",
|
|
1625
|
+
inputSchema: {
|
|
1626
|
+
note: z.string().optional().default("").describe("Optional summary of what was accomplished in this session."),
|
|
1627
|
+
},
|
|
1628
|
+
},
|
|
1629
|
+
async ({ note }) => {
|
|
1630
|
+
const data = readMemory()
|
|
1631
|
+
const lines = data.split("\n")
|
|
1632
|
+
|
|
1633
|
+
let headerIdx = lines.findIndex((l) => l.startsWith("entries[") || /^\[\d+\|]/.test(l))
|
|
1634
|
+
if (headerIdx === -1) {
|
|
1635
|
+
lines.push(`[0|]`)
|
|
1636
|
+
headerIdx = lines.length - 1
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
const sessionId = resolveSessionId({})
|
|
1640
|
+
const shortId = sessionId.replace(/^proc-/, "").slice(0, 8)
|
|
1641
|
+
const key = `checkpoint-${shortId}`
|
|
1642
|
+
const now = new Date()
|
|
1643
|
+
const date = now.toISOString().split("T")[0]
|
|
1644
|
+
const ttl7d = new Date(now.getTime() + 7 * 86400000).toISOString().split("T")[0]
|
|
1645
|
+
|
|
1646
|
+
// Gather session context: branch, files touched, agent
|
|
1647
|
+
const sessions = await import("../lib/sessions")
|
|
1648
|
+
const allSessions = sessions.listSessions()
|
|
1649
|
+
const mySession = allSessions.find((s) => s.id === sessionId)
|
|
1650
|
+
const branch = mySession?.branch || currentBranch()
|
|
1651
|
+
const files = mySession ? Object.keys(mySession.files) : []
|
|
1652
|
+
const fileList = files.length > 0 ? `\nFiles touched: ${files.slice(0, 10).join(", ")}${files.length > 10 ? ` (+${files.length - 10} more)` : ""}` : ""
|
|
1653
|
+
|
|
1654
|
+
const content = `Session checkpoint (${date})${note ? `\nNote: ${note}` : ""}\nBranch: ${branch}${fileList}`
|
|
1655
|
+
|
|
1656
|
+
// Check for existing checkpoint with same key
|
|
1657
|
+
let existingIdx = -1
|
|
1658
|
+
let existingId = ""
|
|
1659
|
+
for (let i = headerIdx + 1; i < lines.length; i++) {
|
|
1660
|
+
const line = lines[i]
|
|
1661
|
+
if (!line.startsWith(" ") || !line.includes("|")) continue
|
|
1662
|
+
if (line.startsWith(" summaries:")) break
|
|
1663
|
+
const parts = line.trim().split("|")
|
|
1664
|
+
if (parts[2] === key) {
|
|
1665
|
+
existingIdx = i
|
|
1666
|
+
existingId = parts[0]
|
|
1667
|
+
break
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
if (existingIdx !== -1) {
|
|
1672
|
+
// Update existing checkpoint
|
|
1673
|
+
const parts = lines[existingIdx].trim().split("|")
|
|
1674
|
+
parts[3] = content
|
|
1675
|
+
parts[6] = date
|
|
1676
|
+
parts[7] = ttl7d
|
|
1677
|
+
while (parts.length < 14) parts.push("")
|
|
1678
|
+
parts[13] = "0"
|
|
1679
|
+
lines[existingIdx] = ` ${parts.join("|")}`
|
|
1680
|
+
writeMemory(lines.join("\n"))
|
|
1681
|
+
return {
|
|
1682
|
+
content: [{ type: "text" as const, text: `š Checkpoint updated: ${key}\nā° TTL: ${ttl7d} (7d)\n${note ? `\n${note}` : ""}` }],
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
// Create new checkpoint entry
|
|
1687
|
+
const newId = `cp-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`
|
|
1688
|
+
const quality = qualityScore("checkpoint", "", content, date)
|
|
1689
|
+
const newEntry = `${newId}|knowledge|${key}|${content}||checkpoint|${date}|${ttl7d}|0||${quality.toFixed(2)}|1|${now.toISOString()}|0`
|
|
1690
|
+
|
|
1691
|
+
const match = lines[headerIdx].match(/\[(\d+)\|/)
|
|
1692
|
+
const count = match ? parseInt(match[1]) : 0
|
|
1693
|
+
lines.splice(headerIdx + 1, 0, ` ${newEntry}`)
|
|
1694
|
+
lines[headerIdx] = lines[headerIdx].replace(/\[\d+\|/, `[${count + 1}|`)
|
|
1695
|
+
writeMemory(lines.join("\n"))
|
|
1696
|
+
|
|
1697
|
+
return {
|
|
1698
|
+
content: [{
|
|
1699
|
+
type: "text" as const,
|
|
1700
|
+
text: `š Checkpoint saved: ${key} (${newId})\nā° TTL: ${ttl7d} (7d)${note ? `\n\n${note}` : ""}`,
|
|
1701
|
+
}],
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
)
|
|
1705
|
+
|
|
1554
1706
|
// āā memory_pin āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
1555
1707
|
|
|
1556
1708
|
server.registerTool(
|
|
1557
1709
|
"memory_pin",
|
|
1558
1710
|
{
|
|
1559
1711
|
title: "Pin Entry",
|
|
1560
|
-
description: "Pin a memory entry
|
|
1712
|
+
description: "Pin a memory entry with priority level (1-5). Higher priority entries appear first in recalls. Default: 1. Useful for critical decisions, project rules, or frequently-needed context.",
|
|
1561
1713
|
inputSchema: {
|
|
1562
1714
|
key: z.string().describe("Key or id of the entry to pin"),
|
|
1715
|
+
priority: z.number().optional().default(1).describe("Priority level 1-5 (5 = highest). Default: 1."),
|
|
1563
1716
|
},
|
|
1564
1717
|
},
|
|
1565
|
-
async ({ key }) => {
|
|
1718
|
+
async ({ key, priority }) => {
|
|
1566
1719
|
const data = readMemory()
|
|
1567
1720
|
const lines = data.split("\n")
|
|
1568
1721
|
const headerIdx = lines.findIndex((l) => l.startsWith("entries[") || /^\[\d+\|]/.test(l))
|
|
@@ -1571,6 +1724,8 @@ server.registerTool(
|
|
|
1571
1724
|
return { content: [{ type: "text" as const, text: "No entries in memory" }] }
|
|
1572
1725
|
}
|
|
1573
1726
|
|
|
1727
|
+
const clampedPriority = Math.max(1, Math.min(5, Math.round(priority)))
|
|
1728
|
+
|
|
1574
1729
|
let found = false
|
|
1575
1730
|
for (let i = headerIdx + 1; i < lines.length; i++) {
|
|
1576
1731
|
const line = lines[i]
|
|
@@ -1578,9 +1733,8 @@ server.registerTool(
|
|
|
1578
1733
|
if (line.startsWith(" summaries:")) break
|
|
1579
1734
|
const parts = line.trim().split("|")
|
|
1580
1735
|
if (parts[0] === key || parts[2] === key) {
|
|
1581
|
-
// Set pinned field at position 13
|
|
1582
1736
|
while (parts.length < 14) parts.push("")
|
|
1583
|
-
parts[13] =
|
|
1737
|
+
parts[13] = String(clampedPriority)
|
|
1584
1738
|
lines[i] = ` ${parts.join("|")}`
|
|
1585
1739
|
found = true
|
|
1586
1740
|
break
|
|
@@ -1592,7 +1746,7 @@ server.registerTool(
|
|
|
1592
1746
|
}
|
|
1593
1747
|
|
|
1594
1748
|
writeMemory(lines.join("\n"))
|
|
1595
|
-
return { content: [{ type: "text" as const, text:
|
|
1749
|
+
return { content: [{ type: "text" as const, text: `š${clampedPriority > 1 ? clampedPriority : ""} Pinned "${key}" at priority ${clampedPriority}. It will now appear first in recalls.` }] }
|
|
1596
1750
|
}
|
|
1597
1751
|
)
|
|
1598
1752
|
|
|
@@ -1637,7 +1791,7 @@ server.registerTool(
|
|
|
1637
1791
|
}
|
|
1638
1792
|
|
|
1639
1793
|
writeMemory(lines.join("\n"))
|
|
1640
|
-
return { content: [{ type: "text" as const, text:
|
|
1794
|
+
return { content: [{ type: "text" as const, text: `Unpinned "${key}". It will now use normal ranking.` }] }
|
|
1641
1795
|
}
|
|
1642
1796
|
)
|
|
1643
1797
|
|
|
@@ -1658,12 +1812,14 @@ server.registerTool(
|
|
|
1658
1812
|
mode: z.enum(["flat", "graph"]).optional().default("flat").describe("'flat' = keyword search (default). 'graph' = graph-based recall."),
|
|
1659
1813
|
hops: z.number().optional().default(1).describe("Graph depth in 'graph' mode (1 or 2). Default 1."),
|
|
1660
1814
|
compact: z.boolean().optional().default(false).describe("Token-efficient output"),
|
|
1815
|
+
bias: z.enum(["none", "session"]).optional().default("none").describe("'session': boost entries whose file matches current session files. 'none': no bias (default)."),
|
|
1661
1816
|
},
|
|
1662
1817
|
},
|
|
1663
|
-
async ({ query, category, tags, from_date, to_date, limit, mode, hops, compact }) => {
|
|
1818
|
+
async ({ query, category, tags, from_date, to_date, limit, mode, hops, compact, bias }) => {
|
|
1664
1819
|
const data = readMemory()
|
|
1665
1820
|
|
|
1666
1821
|
const resolvedFrom = from_date ? parseRelativeDate(from_date) : ""
|
|
1822
|
+
const sessionFiles = bias === "session" ? getCurrentSessionFiles() : undefined
|
|
1667
1823
|
const detail = graphRecallDetailed(data, query, {
|
|
1668
1824
|
category: category || undefined,
|
|
1669
1825
|
tags: tags || undefined,
|
|
@@ -1671,6 +1827,7 @@ server.registerTool(
|
|
|
1671
1827
|
to_date: to_date || undefined,
|
|
1672
1828
|
hops,
|
|
1673
1829
|
limit,
|
|
1830
|
+
sessionFiles,
|
|
1674
1831
|
})
|
|
1675
1832
|
|
|
1676
1833
|
if (detail.entries.length === 0) {
|
|
@@ -1691,7 +1848,7 @@ server.registerTool(
|
|
|
1691
1848
|
const formatted = detail.entries
|
|
1692
1849
|
.map((r) => {
|
|
1693
1850
|
const links = r.links.length ? `\n links: ${r.links.join(", ")}` : ""
|
|
1694
|
-
const pin = r.
|
|
1851
|
+
const pin = r.priority > 0 ? (r.priority > 1 ? ` š${r.priority}` : " š") : ""
|
|
1695
1852
|
return `[${r.category}] ${r.key}${pin} (${r.id})\n ${r.content}\n File: ${r.file} | Tags: ${r.tags.join(";")} | Date: ${r.date}${links}`
|
|
1696
1853
|
})
|
|
1697
1854
|
.join("\n\n")
|