@postnesia/db 0.1.6 → 0.1.7
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/core/BOOTSTRAP.md +26 -2
- package/dist/index.js +32 -1
- package/dist/seed.js +4 -2
- package/package.json +1 -1
package/core/BOOTSTRAP.md
CHANGED
|
@@ -25,6 +25,8 @@ If an MCP connection to `postnesia-mcp` is active, use MCP tools directly:
|
|
|
25
25
|
| `memory_stats` | Check database health and distribution. |
|
|
26
26
|
| `memory_consolidate` | Run decay/boost cycle on importance scores. |
|
|
27
27
|
| `memory_relationships` | Explore how a memory connects to others. |
|
|
28
|
+
| `memory_link` | Manually create a typed relationship between two memories. |
|
|
29
|
+
| `memory_unlink` | Remove a relationship by its ID. |
|
|
28
30
|
| `journal_add` | Write a daily journal entry (narrative). |
|
|
29
31
|
| `journal_recent` | Read recent journal entries. |
|
|
30
32
|
| `task_create` | Create a persistent task with an optional `session_id` to group by project/feature. |
|
|
@@ -44,6 +46,8 @@ If no MCP connection is available, use the `postnesia` CLI via Bash. Every MCP t
|
|
|
44
46
|
| `memory_stats` | `postnesia memory stats` |
|
|
45
47
|
| `memory_consolidate` | `postnesia memory consolidate` |
|
|
46
48
|
| `memory_relationships` | `postnesia memory relationships <id>` |
|
|
49
|
+
| `memory_link` | `postnesia memory link <fromId> <toId> --type <type>` |
|
|
50
|
+
| `memory_unlink` | `postnesia memory unlink <relationshipId>` |
|
|
47
51
|
| `journal_add` | `postnesia journal add <YYYY-MM-DD> "<content>" [--learned "..."] [--key-moments "..."] [--mood "..."]` |
|
|
48
52
|
| `journal_recent` | `postnesia journal recent [--days N]` |
|
|
49
53
|
| `task_create` | `postnesia task create "<title>" [-d "<description>"] [-s <session-id>]` |
|
|
@@ -135,11 +139,31 @@ Memories you access frequently stay in L1 forever. Memories not accessed in 14+
|
|
|
135
139
|
|
|
136
140
|
Tag liberally at creation time. Tags improve both keyword filtering and search relevance. Use lowercase, hyphenated: `memory-system`, `rye-preference`, `critical-thinking`.
|
|
137
141
|
|
|
142
|
+
## Relationships
|
|
143
|
+
|
|
144
|
+
Memories form a knowledge graph via typed edges. Relationships are used by `memory_consolidate` to boost the importance of well-connected memories.
|
|
145
|
+
|
|
146
|
+
### Auto-linking (happens automatically on `memory_add`)
|
|
147
|
+
|
|
148
|
+
- **`related`** — inserted for any existing memory within vector distance 0.4 of the new memory
|
|
149
|
+
- **`supersedes`** — inserted when `supersedes_id` is provided
|
|
150
|
+
|
|
151
|
+
### Manual link types
|
|
152
|
+
|
|
153
|
+
| Type | When to use |
|
|
154
|
+
|---|---|
|
|
155
|
+
| `supports` | This memory provides evidence or context for another |
|
|
156
|
+
| `contradicts` | This memory conflicts with or overrides another |
|
|
157
|
+
| `derives_from` | This memory was derived from, inspired by, or builds on another |
|
|
158
|
+
|
|
159
|
+
Use `memory_link` to assert these explicitly. Use `memory_relationships` to inspect the graph before deciding how a new memory relates to existing ones.
|
|
160
|
+
|
|
138
161
|
## Critical Rules
|
|
139
162
|
|
|
140
163
|
1. **Search before assuming.** If you're unsure about a preference, decision, or past event — search for it.
|
|
141
164
|
2. **Store decisions in real time.** Don't wait until end of session. If a user makes a meaningful choice, store it now.
|
|
142
165
|
3. **Never store noise.** Quality over quantity. Every memory costs tokens in L1.
|
|
143
166
|
4. **Supersede, don't duplicate.** If a preference changes, link to the old one.
|
|
144
|
-
5. **
|
|
145
|
-
6. **
|
|
167
|
+
5. **Assert relationships explicitly.** When you know two memories are related, contradictory, or one derives from another — say so with `memory_link`. The graph improves consolidation accuracy.
|
|
168
|
+
6. **L1 is your lifeline.** If it's not in L1 and you didn't search L2, you effectively don't remember it.
|
|
169
|
+
7. **Tasks over files.** Use `task_create`/`task_update` instead of local markdown checklists. Tasks persist across sessions.
|
package/dist/index.js
CHANGED
|
@@ -228,7 +228,7 @@ export const queries = {
|
|
|
228
228
|
ORDER BY date DESC
|
|
229
229
|
`),
|
|
230
230
|
// -------------------------------------------------------------------
|
|
231
|
-
// Relationships
|
|
231
|
+
// Relationships
|
|
232
232
|
// -------------------------------------------------------------------
|
|
233
233
|
getMemoryRelationships: (db) => db.prepare(`
|
|
234
234
|
SELECT
|
|
@@ -240,6 +240,15 @@ export const queries = {
|
|
|
240
240
|
JOIN memory t ON t.id = r.to_id
|
|
241
241
|
WHERE r.from_id = ? OR r.to_id = ?
|
|
242
242
|
`),
|
|
243
|
+
insertRelationship: (db) => db.prepare(`
|
|
244
|
+
INSERT OR IGNORE INTO relationship (from_id, to_id, type)
|
|
245
|
+
VALUES (?, ?, ?)
|
|
246
|
+
`),
|
|
247
|
+
findRelationshipBetween: (db) => db.prepare(`
|
|
248
|
+
SELECT id FROM relationship WHERE from_id = ? AND to_id = ? AND type = ?
|
|
249
|
+
`),
|
|
250
|
+
deleteRelationship: (db) => db.prepare(`DELETE FROM relationship WHERE id = ?
|
|
251
|
+
`),
|
|
243
252
|
// -------------------------------------------------------------------
|
|
244
253
|
// Tasks
|
|
245
254
|
// -------------------------------------------------------------------
|
|
@@ -258,6 +267,8 @@ export const queries = {
|
|
|
258
267
|
`),
|
|
259
268
|
getTaskById: (db) => db.prepare(`SELECT * FROM task WHERE id = ?`),
|
|
260
269
|
};
|
|
270
|
+
// Distance threshold below which two memories are considered "related"
|
|
271
|
+
const AUTO_LINK_THRESHOLD = 0.4;
|
|
261
272
|
// -------------------------------------------------------------------
|
|
262
273
|
// Helper functions
|
|
263
274
|
// -------------------------------------------------------------------
|
|
@@ -294,6 +305,26 @@ export function createMemory(db, memory) {
|
|
|
294
305
|
}
|
|
295
306
|
});
|
|
296
307
|
txn();
|
|
308
|
+
// Auto-link: find semantically similar memories and create 'related' edges.
|
|
309
|
+
// Runs outside the main transaction so vec0 reflects the just-inserted embedding.
|
|
310
|
+
const similar = queries.vectorSearch(db).all(Buffer.from(memory.embedding.buffer), 6 // fetch one extra so we can skip self
|
|
311
|
+
);
|
|
312
|
+
const linkTxn = db.transaction(() => {
|
|
313
|
+
for (const s of similar) {
|
|
314
|
+
if (s.id === memoryId)
|
|
315
|
+
continue;
|
|
316
|
+
if (s.distance > AUTO_LINK_THRESHOLD)
|
|
317
|
+
break; // results are ordered by distance
|
|
318
|
+
const exists = queries.findRelationshipBetween(db).get(memoryId, s.id, 'related');
|
|
319
|
+
if (!exists) {
|
|
320
|
+
queries.insertRelationship(db).run(memoryId, s.id, 'related');
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (memory.supersedes_id) {
|
|
324
|
+
queries.insertRelationship(db).run(memoryId, memory.supersedes_id, 'supersedes');
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
linkTxn();
|
|
297
328
|
return memoryId;
|
|
298
329
|
}
|
|
299
330
|
// Transaction helper
|
package/dist/seed.js
CHANGED
|
@@ -46,13 +46,15 @@ try {
|
|
|
46
46
|
], [
|
|
47
47
|
'CORE: Memory system operational guide.',
|
|
48
48
|
'L1=auto-loaded working memory, L2=vector search, L3=deep storage.',
|
|
49
|
-
'Tools: memory_search, memory_add, memory_update_core, memory_recent, memory_stats, memory_consolidate, journal_add, journal_recent, task_create, task_update, task_list.',
|
|
50
|
-
'NO MCP: use postnesia CLI — postnesia memory search|add|update-core|recent|stats|consolidate|relationships, postnesia journal add|recent, postnesia task create|update|list.',
|
|
49
|
+
'Tools: memory_search, memory_add, memory_update_core, memory_recent, memory_stats, memory_consolidate, memory_relationships, memory_link, memory_unlink, journal_add, journal_recent, task_create, task_update, task_list.',
|
|
50
|
+
'NO MCP: use postnesia CLI — postnesia memory search|add|update-core|recent|stats|consolidate|relationships|link|unlink, postnesia journal add|recent, postnesia task create|update|list.',
|
|
51
51
|
'SESSION START: task_list(status=pending) to resume work + memory_search("lesson").',
|
|
52
52
|
'TASKS: task_create(title,session_id)→in_progress→completed. Tasks persist across sessions.',
|
|
53
53
|
'Core memories: update with memory_update_core, never supersede.',
|
|
54
54
|
'Create memories: decisions(5), preferences(5), person(5), lessons(3-5), technical(3-4), events(1-4).',
|
|
55
55
|
'Supersede regular memories via supersedes_id. Rules: search first, store decisions now, tasks over files.',
|
|
56
|
+
'Relationships: memory_add auto-links related memories (distance<0.4) and inserts supersedes edge. Manual types: supports, contradicts, derives_from. Use memory_link(fromId,toId,type) to assert explicit edges; memory_unlink(id) to remove. memory_relationships(id) to inspect graph.',
|
|
57
|
+
'Consolidation boosts well-connected memories — assert relationships explicitly to improve importance scoring.',
|
|
56
58
|
]);
|
|
57
59
|
await bootstrap('WORKFLOW.md', 'workflow-principles', [
|
|
58
60
|
'workflow',
|