@pinkpixel/memi 0.0.0-stage → 1.0.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/LICENSE +202 -0
- package/README.md +298 -2
- package/dist/cli/commands/config.js +38 -0
- package/dist/cli/commands/doctor.js +53 -0
- package/dist/cli/commands/memories.js +146 -0
- package/dist/cli/commands/reindex.js +34 -0
- package/dist/cli/commands/serve.js +9 -0
- package/dist/cli/commands/ui.js +26 -0
- package/dist/cli/index.js +20 -0
- package/dist/cli/util.js +46 -0
- package/dist/core/config.js +89 -0
- package/dist/core/db.js +21 -0
- package/dist/core/format.js +16 -0
- package/dist/core/memories.js +192 -0
- package/dist/core/project.js +53 -0
- package/dist/core/rows.js +38 -0
- package/dist/core/runtime.js +10 -0
- package/dist/core/schema.js +60 -0
- package/dist/core/search.js +86 -0
- package/dist/core/types.js +12 -0
- package/dist/core/vectors.js +102 -0
- package/dist/embed/http.js +20 -0
- package/dist/embed/index.js +9 -0
- package/dist/embed/ollama.js +24 -0
- package/dist/embed/openai.js +22 -0
- package/dist/embed/types.js +2 -0
- package/dist/lib/app-info.js +5 -0
- package/dist/mcp/server.js +24 -0
- package/dist/mcp/tools.js +152 -0
- package/dist/ui/assets.js +38 -0
- package/dist/ui/routes.js +91 -0
- package/dist/ui/security.js +47 -0
- package/dist/ui/server.js +33 -0
- package/package.json +63 -4
- package/skills/memi-curate/SKILL.md +89 -0
- package/skills/memi-memory/SKILL.md +141 -0
- package/skills/memi-memory/references/examples.md +50 -0
- package/skills/memi-memory/references/rubrics.md +44 -0
- package/skills/memi-setup/SKILL.md +159 -0
- package/ui/css/controls.css +274 -0
- package/ui/css/dialogs.css +145 -0
- package/ui/css/layout.css +237 -0
- package/ui/css/memories.css +168 -0
- package/ui/css/tokens.css +125 -0
- package/ui/favicon.svg +1 -0
- package/ui/fonts/OFL.txt +192 -0
- package/ui/fonts/geist-latin-wght-normal.woff2 +0 -0
- package/ui/fonts/geist-mono-latin-wght-normal.woff2 +0 -0
- package/ui/index.html +75 -0
- package/ui/js/api.js +30 -0
- package/ui/js/confirm.js +29 -0
- package/ui/js/dom.js +49 -0
- package/ui/js/editor.js +133 -0
- package/ui/js/icons.js +29 -0
- package/ui/js/list.js +66 -0
- package/ui/js/main.js +244 -0
- package/ui/js/sidebar.js +85 -0
- package/ui/js/state.js +61 -0
- package/ui/js/toast.js +10 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { MemiError } from "../core/types.js";
|
|
4
|
+
import { EmbedError } from "../embed/types.js";
|
|
5
|
+
const Scope = z.enum(["both", "project", "global", "all"]);
|
|
6
|
+
const Tags = z.array(z.string()).max(10);
|
|
7
|
+
const ListQuery = z.object({
|
|
8
|
+
q: z.string().trim().optional(),
|
|
9
|
+
scope: Scope.default("all"),
|
|
10
|
+
project: z.string().optional(),
|
|
11
|
+
category: z.string().optional(),
|
|
12
|
+
minImportance: z.coerce.number().int().min(1).max(5).optional(),
|
|
13
|
+
pinned: z.enum(["true", "false"]).optional(),
|
|
14
|
+
order: z.enum(["recent", "oldest", "importance"]).default("recent"),
|
|
15
|
+
mode: z.enum(["hybrid", "semantic", "text"]).default("hybrid"),
|
|
16
|
+
limit: z.coerce.number().int().min(1).max(200).default(50),
|
|
17
|
+
offset: z.coerce.number().int().min(0).default(0),
|
|
18
|
+
});
|
|
19
|
+
const NewBody = z.object({
|
|
20
|
+
content: z.string(),
|
|
21
|
+
scope: z.enum(["project", "global"]).optional(),
|
|
22
|
+
project: z.string().nullable().optional(),
|
|
23
|
+
category: z.string().optional(),
|
|
24
|
+
importance: z.number().int().optional(),
|
|
25
|
+
tags: Tags.optional(),
|
|
26
|
+
pinned: z.boolean().optional(),
|
|
27
|
+
});
|
|
28
|
+
const PatchBody = z.object({
|
|
29
|
+
content: z.string().optional(),
|
|
30
|
+
scope: z.enum(["project", "global"]).optional(),
|
|
31
|
+
project: z.string().nullable().optional(),
|
|
32
|
+
category: z.string().optional(),
|
|
33
|
+
importance: z.number().int().optional(),
|
|
34
|
+
tags: Tags.optional(),
|
|
35
|
+
pinned: z.boolean().optional(),
|
|
36
|
+
});
|
|
37
|
+
const Id = z.coerce.number().int().positive();
|
|
38
|
+
export function createApi({ store, currentProject }) {
|
|
39
|
+
const api = new Hono();
|
|
40
|
+
api.onError((err, c) => {
|
|
41
|
+
if (err instanceof z.ZodError)
|
|
42
|
+
return c.json({ error: err.issues.map((i) => `${i.path.join(".") || "request"}: ${i.message}`).join("; ") }, 400);
|
|
43
|
+
if (err instanceof SyntaxError)
|
|
44
|
+
return c.json({ error: "Body is not valid JSON." }, 400);
|
|
45
|
+
if (err instanceof MemiError || err instanceof EmbedError)
|
|
46
|
+
return c.json({ error: err.message }, 400);
|
|
47
|
+
console.error(err);
|
|
48
|
+
return c.json({ error: "Something went wrong. Check the terminal running memi ui." }, 500);
|
|
49
|
+
});
|
|
50
|
+
api.get("/status", (c) => c.json({
|
|
51
|
+
...store.status(),
|
|
52
|
+
currentProject,
|
|
53
|
+
projects: store.projects(),
|
|
54
|
+
categories: store.categories(),
|
|
55
|
+
}));
|
|
56
|
+
api.get("/memories", async (c) => {
|
|
57
|
+
const q = ListQuery.parse(c.req.query());
|
|
58
|
+
const filters = {
|
|
59
|
+
scope: q.scope,
|
|
60
|
+
project: q.project ?? null,
|
|
61
|
+
category: q.category,
|
|
62
|
+
minImportance: q.minImportance,
|
|
63
|
+
pinned: q.pinned === undefined ? undefined : q.pinned === "true",
|
|
64
|
+
};
|
|
65
|
+
if (q.q) {
|
|
66
|
+
const r = await store.search({ ...filters, query: q.q, mode: q.mode, limit: Math.min(q.limit, 50) });
|
|
67
|
+
return c.json({
|
|
68
|
+
items: r.hits.map((h) => h.memory),
|
|
69
|
+
total: r.hits.length,
|
|
70
|
+
scores: Object.fromEntries(r.hits.map((h) => [h.memory.id, h.score])),
|
|
71
|
+
modeUsed: r.modeUsed,
|
|
72
|
+
note: r.note ?? null,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return c.json({ ...store.list({ ...filters, order: q.order, limit: q.limit, offset: q.offset }), scores: null, modeUsed: null, note: null });
|
|
76
|
+
});
|
|
77
|
+
api.post("/memories", async (c) => {
|
|
78
|
+
const body = NewBody.parse(await c.req.json());
|
|
79
|
+
return c.json(await store.add({ ...body, agent: "memi-ui" }), 201);
|
|
80
|
+
});
|
|
81
|
+
api.patch("/memories/:id", async (c) => {
|
|
82
|
+
const id = Id.parse(c.req.param("id"));
|
|
83
|
+
const result = await store.update(id, PatchBody.parse(await c.req.json()));
|
|
84
|
+
return result ? c.json(result) : c.json({ error: `No memory with id ${id}.` }, 404);
|
|
85
|
+
});
|
|
86
|
+
api.delete("/memories/:id", (c) => {
|
|
87
|
+
const id = Id.parse(c.req.param("id"));
|
|
88
|
+
return store.remove(id) ? c.body(null, 204) : c.json({ error: `No memory with id ${id}.` }, 404);
|
|
89
|
+
});
|
|
90
|
+
return api;
|
|
91
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const LOCAL_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
2
|
+
// Memory text is untrusted (an agent can save anything), so the page may only load its own files.
|
|
3
|
+
const CSP = [
|
|
4
|
+
"default-src 'none'",
|
|
5
|
+
"script-src 'self'",
|
|
6
|
+
"style-src 'self'",
|
|
7
|
+
"font-src 'self'",
|
|
8
|
+
"img-src 'self' data:",
|
|
9
|
+
"connect-src 'self'",
|
|
10
|
+
"base-uri 'none'",
|
|
11
|
+
"form-action 'none'",
|
|
12
|
+
"frame-ancestors 'none'",
|
|
13
|
+
].join("; ");
|
|
14
|
+
const forbidden = (message, status) => Response.json({ error: message }, { status });
|
|
15
|
+
/**
|
|
16
|
+
* The UI can delete memories, so a web page you happen to have open must not be able to drive it.
|
|
17
|
+
* - Host check: stops DNS rebinding, where evil.example resolves to 127.0.0.1.
|
|
18
|
+
* - Origin check and JSON-only bodies: stops cross-site writes. A cross-origin JSON request needs a
|
|
19
|
+
* CORS preflight, and this server never answers one.
|
|
20
|
+
*/
|
|
21
|
+
export const guard = async (c, next) => {
|
|
22
|
+
const url = new URL(c.req.url);
|
|
23
|
+
if (!LOCAL_HOSTS.has(url.hostname))
|
|
24
|
+
return forbidden("Forbidden host.", 403);
|
|
25
|
+
if (c.req.method !== "GET" && c.req.method !== "HEAD") {
|
|
26
|
+
const origin = c.req.header("origin");
|
|
27
|
+
if (origin) {
|
|
28
|
+
let originHost = null;
|
|
29
|
+
try {
|
|
30
|
+
originHost = new URL(origin).host;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// "null" and other unparseable origins are rejected below.
|
|
34
|
+
}
|
|
35
|
+
if (originHost !== url.host)
|
|
36
|
+
return forbidden("Forbidden origin.", 403);
|
|
37
|
+
}
|
|
38
|
+
if (c.req.method !== "DELETE" && !c.req.header("content-type")?.toLowerCase().startsWith("application/json")) {
|
|
39
|
+
return forbidden("Send JSON.", 415);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
await next();
|
|
43
|
+
c.header("Content-Security-Policy", CSP);
|
|
44
|
+
c.header("X-Content-Type-Options", "nosniff");
|
|
45
|
+
c.header("Referrer-Policy", "no-referrer");
|
|
46
|
+
c.header("X-Frame-Options", "DENY");
|
|
47
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { serve } from "@hono/node-server";
|
|
2
|
+
import { Hono } from "hono";
|
|
3
|
+
import { resolveProject } from "../core/project.js";
|
|
4
|
+
import { MemiError } from "../core/types.js";
|
|
5
|
+
import { readAsset } from "./assets.js";
|
|
6
|
+
import { createApi } from "./routes.js";
|
|
7
|
+
import { guard } from "./security.js";
|
|
8
|
+
export function createApp(rt, cwd = process.cwd()) {
|
|
9
|
+
const app = new Hono();
|
|
10
|
+
app.use("*", guard);
|
|
11
|
+
app.route("/api", createApi({ store: rt.store, currentProject: resolveProject({ agent: rt.agent, cwd })?.project ?? null }));
|
|
12
|
+
app.get("*", async (c) => {
|
|
13
|
+
const asset = await readAsset(new URL(c.req.url).pathname);
|
|
14
|
+
if (!asset)
|
|
15
|
+
return c.text("Not found", 404);
|
|
16
|
+
return c.body(new Uint8Array(asset.body), 200, { "Content-Type": asset.type, "Cache-Control": asset.cache });
|
|
17
|
+
});
|
|
18
|
+
return app;
|
|
19
|
+
}
|
|
20
|
+
/** Starts the UI on 127.0.0.1 only. Pass port 0 to let the system pick one. */
|
|
21
|
+
export function startUi(rt, opts) {
|
|
22
|
+
const app = createApp(rt, opts.cwd);
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
// Without a createServer option, serve() returns a plain HTTP/1 server.
|
|
25
|
+
const server = serve({ fetch: app.fetch, port: opts.port, hostname: "127.0.0.1" }, (info) => {
|
|
26
|
+
resolve({
|
|
27
|
+
url: `http://localhost:${info.port}`,
|
|
28
|
+
close: () => new Promise((done) => (server.close(() => done()), server.closeAllConnections())),
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
server.once("error", (err) => reject(err.code === "EADDRINUSE" ? new MemiError(`Port ${opts.port} is already in use. Pick another with --port.`) : err));
|
|
32
|
+
});
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pinkpixel/memi",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Local-first memory for AI agents. SQLite, hybrid search, MCP server, and a small local UI.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": "Pink Pixel <admin@pinkpixel.dev> (https://pinkpixel.dev)",
|
|
8
|
+
"homepage": "https://pinkpixel.dev",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/pinkpixel-dev/memi.git"
|
|
12
|
+
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"memi": "dist/cli/index.js"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"ui",
|
|
19
|
+
"skills",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc -p tsconfig.build.json",
|
|
28
|
+
"prepublishOnly": "npm run typecheck && npm run build",
|
|
29
|
+
"dev": "tsx src/cli/index.ts",
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"test": "vitest run"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"mcp",
|
|
35
|
+
"memory",
|
|
36
|
+
"agents",
|
|
37
|
+
"sqlite",
|
|
38
|
+
"embeddings",
|
|
39
|
+
"ollama",
|
|
40
|
+
"openai"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@hono/node-server": "^2.1.3",
|
|
44
|
+
"@modelcontextprotocol/sdk": "^1.32.0",
|
|
45
|
+
"better-sqlite3": "^13.0.3",
|
|
46
|
+
"commander": "^15.0.0",
|
|
47
|
+
"hono": "^4.13.13",
|
|
48
|
+
"sqlite-vec": "^0.1.9",
|
|
49
|
+
"zod": "^4.6.5"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/better-sqlite3": "^9.6.0",
|
|
53
|
+
"@types/node": "^26.6.4",
|
|
54
|
+
"happy-dom": "^20.14.5",
|
|
55
|
+
"tsx": "^4.23.15",
|
|
56
|
+
"typescript": "^7.0.2",
|
|
57
|
+
"vitest": "^5.0.3"
|
|
58
|
+
},
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public"
|
|
61
|
+
},
|
|
62
|
+
"bugs": {
|
|
63
|
+
"url": "https://github.com/pinkpixel-dev/memi/issues"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: memi-curate
|
|
3
|
+
version: 1.0.0
|
|
4
|
+
description: |
|
|
5
|
+
Review and clean up memories stored in memi: find duplicates, contradictions,
|
|
6
|
+
stale or vague entries, wrong scope or category, inflated importance, and
|
|
7
|
+
accidentally saved secrets, then fix them with the user's approval. Use when
|
|
8
|
+
the user asks to "clean up", "review", "organize", or "audit" memories, when
|
|
9
|
+
recall keeps returning noise or contradictory results, or when list_memories
|
|
10
|
+
shows a large pile of low-value entries.
|
|
11
|
+
license: Apache-2.0
|
|
12
|
+
compatibility: claude-code cursor codex gemini-cli opencode
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
# Curating memi memories
|
|
16
|
+
|
|
17
|
+
Memories pile up. Over time a store collects near-duplicates, decisions that were later reversed, vague notes nobody can interpret, and categories that drifted. A messy store makes `recall` worse, because contradictory or noisy results waste attention and can lead the next session wrong.
|
|
18
|
+
|
|
19
|
+
This skill is a careful review. The rule that matters most: **deleting is permanent, so you propose first and the user approves.**
|
|
20
|
+
|
|
21
|
+
If the user would rather look through memories themselves, `memi ui` opens a browser view where they can search, edit, and delete.
|
|
22
|
+
|
|
23
|
+
## 1. Survey
|
|
24
|
+
|
|
25
|
+
1. `list_categories` for the shape of the store.
|
|
26
|
+
2. `list_memories` with `scope: "all"` and `limit: 50`, paging with `offset` until `total` is covered. Use `order: "importance"` to see what is loaded at session start first, then `order: "oldest"` for the stale tail.
|
|
27
|
+
3. If the user only cares about one project, use `scope: "project"` with that `project`. Include `scope: "global"` separately.
|
|
28
|
+
|
|
29
|
+
Read everything before you judge anything. A "duplicate" is easy to misjudge from one memory.
|
|
30
|
+
|
|
31
|
+
## 2. Look for these problems
|
|
32
|
+
|
|
33
|
+
| Problem | How to spot it | Fix |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| **Duplicate** | Two memories say the same thing | Keep the clearer one (`update_memory` to merge in any detail from the other), `forget` the rest |
|
|
36
|
+
| **Contradiction** | Two memories disagree | Decide which is current. Check the repo or ask the user if unsure. Update or keep that one, `forget` the other |
|
|
37
|
+
| **Stale** | Names a file, flag, host, or version that may no longer exist | Verify against the repo. If it changed, `update_memory`. If it is gone, `forget` |
|
|
38
|
+
| **Vague** | Cannot be understood without the original conversation ("use the second approach") | Rewrite so it stands alone if you can tell what it meant. Otherwise `forget` |
|
|
39
|
+
| **Wrong category** | Lots of `context` that is really a decision, preference, or fact | `update_memory` with the right `category` |
|
|
40
|
+
| **Wrong scope** | A project memory that is really a global preference, or the reverse | `update_memory` with `scope` (and `project` if moving to a project) |
|
|
41
|
+
| **Inflated importance** | A pile of 4s and 5s, or more than about five pinned memories per scope | Lower importance, unpin the rest |
|
|
42
|
+
| **Category sprawl** | Near-identical custom names (`ci`, `cicd`, `ci-cd`) | Move the memories into one category |
|
|
43
|
+
| **Secret** | An API key, token, password, or private key | Tell the user straight away, `forget` it, and tell them the secret should be rotated since it was stored |
|
|
44
|
+
|
|
45
|
+
Do not fix what is not broken. A short, plain memory that is correct is fine.
|
|
46
|
+
|
|
47
|
+
## 3. Propose before you change anything
|
|
48
|
+
|
|
49
|
+
Present a list the user can approve in one pass. Group by action, and give the id, the reason, and the new wording when you rewrite:
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
Delete (3)
|
|
53
|
+
#14 duplicate of #9
|
|
54
|
+
#31 vague: "use the second approach"
|
|
55
|
+
#40 stale: refers to scripts/old-deploy.sh, which no longer exists
|
|
56
|
+
|
|
57
|
+
Update (2)
|
|
58
|
+
#22 fact -> decision; reword: "Auth uses signed cookies, not JWTs, because sessions must be revocable."
|
|
59
|
+
#27 scope project -> global (it is a tooling preference)
|
|
60
|
+
|
|
61
|
+
Lower importance (1)
|
|
62
|
+
#8 5 -> 3
|
|
63
|
+
|
|
64
|
+
Secrets (0)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Then wait. Apply only what the user approves. If they approve some items, do those and leave the rest.
|
|
68
|
+
|
|
69
|
+
A secret is the one case where you should say so immediately and not wait for the end of the review. You still need approval before deleting.
|
|
70
|
+
|
|
71
|
+
## 4. Apply
|
|
72
|
+
|
|
73
|
+
- `update_memory` for rewording, recategorizing, rescoping, importance, tags, pinning. Changing `content` or scope re-embeds the memory.
|
|
74
|
+
- `forget` for deletions, one id at a time.
|
|
75
|
+
- Merging: update the best memory with the combined content, then `forget` the others.
|
|
76
|
+
|
|
77
|
+
Note that `update_memory` with `tags` **replaces** the existing tags. Pass the full list you want.
|
|
78
|
+
|
|
79
|
+
## 5. Report
|
|
80
|
+
|
|
81
|
+
End with plain counts: how many deleted, updated, left alone, and anything you were unsure about and skipped. If you could not check something against the repo, say so.
|
|
82
|
+
|
|
83
|
+
## Rules
|
|
84
|
+
|
|
85
|
+
- Never delete without approval.
|
|
86
|
+
- Never change the meaning of a memory while rewording it. If you are not sure what it meant, ask or leave it.
|
|
87
|
+
- Verify stale-looking details against the repo before calling them stale.
|
|
88
|
+
- Keep the user's own words where they are clear. Do not polish for the sake of it.
|
|
89
|
+
- If a warning like `Saved without a vector` appears while updating, mention it once and carry on.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: memi-memory
|
|
3
|
+
version: 1.0.0
|
|
4
|
+
description: |
|
|
5
|
+
Use memi, a local long-term memory for AI agents, so knowledge survives between
|
|
6
|
+
sessions. Use whenever the memi MCP tools (get_context, recall, remember,
|
|
7
|
+
update_memory, forget, list_memories, list_categories) are available: at the
|
|
8
|
+
start of a session, before making a decision that earlier sessions may have
|
|
9
|
+
settled, when the user says "remember", "save this", "do you remember", "what
|
|
10
|
+
did we decide", "last time", "forget that", or "don't do that again", and after
|
|
11
|
+
you learn something durable such as a decision, a preference, a fact, or a
|
|
12
|
+
mistake worth avoiding.
|
|
13
|
+
license: Apache-2.0
|
|
14
|
+
compatibility: claude-code cursor codex gemini-cli opencode
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# Using memi memory
|
|
18
|
+
|
|
19
|
+
memi stores memories in a local SQLite file and finds them by meaning and by keyword. Memories last across sessions, and the same store is shared by every agent on this machine. That makes you responsible for what goes in. A good memory saves the next session real time. A bad one is noise that someone will have to find and delete.
|
|
20
|
+
|
|
21
|
+
Seven tools do all the work: `get_context`, `recall`, `remember`, `update_memory`, `forget`, `list_memories`, `list_categories`.
|
|
22
|
+
|
|
23
|
+
## The loop
|
|
24
|
+
|
|
25
|
+
1. **Start of a session:** call `get_context` once. It returns the pinned and high-importance (4 or 5) memories for this project plus global ones. Treat them as background. Do not read them back to the user.
|
|
26
|
+
2. **While working:** call `recall` when earlier knowledge might change what you do (see below).
|
|
27
|
+
3. **After you learn something durable:** call `remember`.
|
|
28
|
+
4. **When a memory turns out to be wrong:** call `update_memory` or `forget`. Do not leave known-wrong memories behind.
|
|
29
|
+
|
|
30
|
+
## Recall
|
|
31
|
+
|
|
32
|
+
Recall before you:
|
|
33
|
+
|
|
34
|
+
- choose a library, pattern, or architecture
|
|
35
|
+
- answer a question about how this user or project does things
|
|
36
|
+
- start debugging something that might have been hit before
|
|
37
|
+
- act on something the user refers to from the past ("like we did before", "as I said")
|
|
38
|
+
|
|
39
|
+
Recall tips:
|
|
40
|
+
|
|
41
|
+
- Describe what you want in plain language: `how does the user want commit messages written`. Searching by meaning works, so you do not need to guess exact words.
|
|
42
|
+
- The default scope `both` covers global memories plus the current project. Use `scope: "all"` only when the user asks about another project.
|
|
43
|
+
- Add `min_importance: 4` when you only want what matters most. Add `category` to narrow down.
|
|
44
|
+
- One or two searches per task is normal. Do not search on every message.
|
|
45
|
+
|
|
46
|
+
Reading results: each memory starts with `#id | category | importance N | scope | ...`. The score is only useful for comparing results within one search.
|
|
47
|
+
|
|
48
|
+
**Memories can be stale.** Specific details such as file paths, flags, function names, and versions may have changed since the memory was written. Check against the current code before you act on one. If it is wrong, fix it with `update_memory` or remove it with `forget`.
|
|
49
|
+
|
|
50
|
+
If a result ends with `Note:`, read it. It usually means search fell back to keywords only. See "Warnings" below.
|
|
51
|
+
|
|
52
|
+
## Remember
|
|
53
|
+
|
|
54
|
+
### What belongs
|
|
55
|
+
|
|
56
|
+
- **Decisions and the reason for them.** "Use SQLite, not Postgres, because the app is local-first and the data is small."
|
|
57
|
+
- **User preferences and corrections.** "Prefers tabs. Wants short answers without a summary at the end."
|
|
58
|
+
- **Durable facts that are not obvious from the code.** "Staging deploys need the VPN."
|
|
59
|
+
- **Mistakes worth not repeating, with the fix.** "Running migrations before the seed script fails. Seed first."
|
|
60
|
+
- **Work the user explicitly deferred.** "Add rate limiting to the upload route later."
|
|
61
|
+
|
|
62
|
+
### What does not belong
|
|
63
|
+
|
|
64
|
+
- **Secrets of any kind:** API keys, tokens, passwords, private keys. Never.
|
|
65
|
+
- Anything you can read from the code, the git history, or the docs.
|
|
66
|
+
- Task progress that only matters in this session.
|
|
67
|
+
- Guesses. Save what you verified, or what the user said.
|
|
68
|
+
- Long dumps. One memory is one idea in a few sentences. The hard limit is 8000 characters, and you should rarely come close.
|
|
69
|
+
|
|
70
|
+
### Write it so it stands alone
|
|
71
|
+
|
|
72
|
+
A future session will see the memory without this conversation. So:
|
|
73
|
+
|
|
74
|
+
- Lead with the fact, then the reason.
|
|
75
|
+
- Name things exactly (file, tool, command).
|
|
76
|
+
- Use absolute dates, not "yesterday" or "last week".
|
|
77
|
+
- No pronouns that point back at the conversation ("it", "that approach").
|
|
78
|
+
|
|
79
|
+
Before: `We decided to go with the second option.`
|
|
80
|
+
After: `Auth uses signed cookies, not JWTs, because sessions must be revocable. Decided 2026-10-04.`
|
|
81
|
+
|
|
82
|
+
More examples are in `references/examples.md`.
|
|
83
|
+
|
|
84
|
+
### Choose the fields
|
|
85
|
+
|
|
86
|
+
| Field | How to choose |
|
|
87
|
+
|---|---|
|
|
88
|
+
| `scope` | `project` for things about this codebase. `global` for things about the user or how they work everywhere. If unsure, project. |
|
|
89
|
+
| `category` | `decision`, `preference`, `fact`, `error`, `todo`, or `context`. Run `list_categories` before inventing a new one. |
|
|
90
|
+
| `importance` | 1 to 5, default 3. See `references/rubrics.md`. Most memories are 2 or 3. |
|
|
91
|
+
| `pinned` | Loaded at the start of every session. Use rarely, for rules where forgetting would cost real time or trust. |
|
|
92
|
+
| `tags` | A few keywords you would search for. Optional. |
|
|
93
|
+
|
|
94
|
+
`project` is worked out for you. Do not pass it unless the user is talking about a different project by name.
|
|
95
|
+
|
|
96
|
+
### Handle duplicates
|
|
97
|
+
|
|
98
|
+
`remember` checks for close matches in the same scope. If the result says `Similar memories already exist`:
|
|
99
|
+
|
|
100
|
+
- **Same fact:** keep the better one. Call `update_memory` on the older memory with the improved wording, then `forget` the new id you just created.
|
|
101
|
+
- **Related but different** (a new detail, a changed decision): keep both, or update the old one if the new one replaces it.
|
|
102
|
+
|
|
103
|
+
For anything you suspect is already saved, a quick `recall` first is cheaper than cleaning up later.
|
|
104
|
+
|
|
105
|
+
### Tell the user, briefly
|
|
106
|
+
|
|
107
|
+
When you save a preference or a decision on your own initiative, say so in one short line ("Saved a note that you prefer tabs.") so they can correct you. Do not announce routine facts.
|
|
108
|
+
|
|
109
|
+
## When the user asks directly
|
|
110
|
+
|
|
111
|
+
- **"Remember X"**: save it right away, then confirm with the id.
|
|
112
|
+
- **"Forget X"**: `recall` to find it. If more than one memory matches, show them and ask which. Then `forget`. Deleting is permanent.
|
|
113
|
+
- **"What do you remember about X"**: `recall`, then summarize in your own words.
|
|
114
|
+
|
|
115
|
+
## Projects and scope
|
|
116
|
+
|
|
117
|
+
memi works out the project automatically: the folder name of the git repo you are in. With no git repo, it uses the agent name (`MEMI_AGENT`), stored as `agent:<name>`. With neither, saving a project memory fails with an error that says what to set.
|
|
118
|
+
|
|
119
|
+
If you hit that error, either save the memory as `global` (if it truly is global) or ask the user for a project name or tell them to set `MEMI_AGENT`. Do not make up a project name.
|
|
120
|
+
|
|
121
|
+
## Warnings
|
|
122
|
+
|
|
123
|
+
| You see | What it means | What to do |
|
|
124
|
+
|---|---|---|
|
|
125
|
+
| `Saved without a vector` | Saved, but the embedder was unreachable. It can only be found by keyword for now. | Mention it once. The user can run `memi reindex --missing` when Ollama is back. |
|
|
126
|
+
| `The embedder changed from ...` | The configured embedder no longer matches the stored vectors, so semantic search is off. Keyword search still works. | Tell the user to run `memi reindex`. It asks for confirmation, rebuilds the vectors, and keeps all memories. Do not run it yourself unless asked, because it re-embeds everything. |
|
|
127
|
+
| `No embedder configured` / `No vectors yet` | Keyword search only. | Nothing needed. |
|
|
128
|
+
| Tool error | Bad arguments or a bad id. | Read the message, fix the arguments, retry once. |
|
|
129
|
+
|
|
130
|
+
## If the memi tools are not available
|
|
131
|
+
|
|
132
|
+
If the MCP server is not connected but the `memi` command exists, use it from the shell: `memi search "query"`, `memi add "text" -c fact`, `memi list`. If neither is available, say so. Do not claim to remember something you cannot save.
|
|
133
|
+
|
|
134
|
+
## Quick rules
|
|
135
|
+
|
|
136
|
+
- `get_context` at the start. `recall` before deciding. `remember` after learning.
|
|
137
|
+
- Never save secrets.
|
|
138
|
+
- Write memories that make sense with no context.
|
|
139
|
+
- Update or forget what is wrong. Do not stack contradictions.
|
|
140
|
+
- Verify stale details before acting on them.
|
|
141
|
+
- When unsure whether something is worth saving, ask: would the next session be worse off without it?
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
## Rewriting vague memories
|
|
4
|
+
|
|
5
|
+
| Before | After | What changed |
|
|
6
|
+
|---|---|---|
|
|
7
|
+
| `Use the new approach.` | `Search runs FTS5 and vector KNN, merged with reciprocal rank fusion, because either alone missed too much.` | Named the approach and gave the reason. |
|
|
8
|
+
| `User likes it short.` | `Prefers short answers with no closing summary. Said so on 2026-10-04.` | Said what "it" is, added a date. |
|
|
9
|
+
| `Fixed the bug with the thing.` | `Uploads over 10MB failed because the proxy limit is 10MB. Raised it in nginx.conf to 50MB.` | Named the symptom, the cause, and the fix. |
|
|
10
|
+
| `Don't forget to test on mobile.` | `Every UI change must be checked at 375px width. The app is used mostly on phones.` | Made the rule concrete. |
|
|
11
|
+
|
|
12
|
+
## What not to save
|
|
13
|
+
|
|
14
|
+
| Candidate | Why not |
|
|
15
|
+
|---|---|
|
|
16
|
+
| `The project uses TypeScript.` | Visible from the repo. |
|
|
17
|
+
| `Currently refactoring the auth module.` | Session progress. It will be wrong tomorrow. |
|
|
18
|
+
| `The API key is sk-...` | A secret. Never. |
|
|
19
|
+
| `Maybe we should use Redis?` | A guess, not a decision. |
|
|
20
|
+
| A pasted 300-line stack trace | Too long. Save the cause and the fix in two sentences. |
|
|
21
|
+
|
|
22
|
+
## A duplicate, handled
|
|
23
|
+
|
|
24
|
+
You call `remember` with `The user prefers tabs over spaces`. The result says:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
Saved memory #14 (global, preference, importance 3).
|
|
28
|
+
|
|
29
|
+
Similar memories already exist. If one covers this, call update_memory on it and forget #14:
|
|
30
|
+
#9 | preference | importance 4 | global | 2026-09-12
|
|
31
|
+
The user prefers tabs over spaces for indentation
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Memory #9 already says it, and with more detail. So delete the new one:
|
|
35
|
+
|
|
36
|
+
1. `forget` with `{ "id": 14 }`
|
|
37
|
+
|
|
38
|
+
If the new wording were better, you would first call `update_memory` on #9 with the improved `content`, then forget #14.
|
|
39
|
+
|
|
40
|
+
## Session start
|
|
41
|
+
|
|
42
|
+
1. Call `get_context`. It returns, say, four memories: two pinned rules, two important decisions.
|
|
43
|
+
2. Use them silently. If the user asks to change something a decision covers, mention the decision and why it was made.
|
|
44
|
+
3. Later the user says "let's add caching". Call `recall` with `caching decisions and constraints` before proposing anything.
|
|
45
|
+
|
|
46
|
+
## A memory that turned out wrong
|
|
47
|
+
|
|
48
|
+
`recall` returns `#22 | fact | ... | The staging database is at db-staging-1.` While working you find the host is now `db-staging-2`.
|
|
49
|
+
|
|
50
|
+
Call `update_memory` with `{ "id": 22, "content": "The staging database is at db-staging-2 (moved from db-staging-1 on 2026-10-04)." }`. Do not save a second memory next to it.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Rubrics for memi memories
|
|
2
|
+
|
|
3
|
+
Use these when the choice of importance, category, scope, or pinning is not obvious.
|
|
4
|
+
|
|
5
|
+
## Importance
|
|
6
|
+
|
|
7
|
+
| Level | Meaning | Examples |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| 1 | Minor. Nice to know, harmless to forget. | "The old build script is in `scripts/legacy/`." |
|
|
10
|
+
| 2 | Useful detail. | "Dev server runs on port 5174 because 5173 is taken." |
|
|
11
|
+
| 3 | Normal. Default. Worth having next session. | "API errors use the `{ error, code }` shape." |
|
|
12
|
+
| 4 | Important. Getting it wrong costs real time. Loaded by `get_context`. | "Never run migrations on the shared staging database without asking." |
|
|
13
|
+
| 5 | Critical. A rule or fact that must never be missed. Loaded by `get_context`. | "Production deploys are manual. Never trigger one from a script." |
|
|
14
|
+
|
|
15
|
+
Most memories should be 2 or 3. If everything is a 4 or 5, `get_context` stops being useful. Search results are also nudged by importance, so inflating it distorts ranking.
|
|
16
|
+
|
|
17
|
+
## Pinning
|
|
18
|
+
|
|
19
|
+
Pinned memories load at the start of every session whatever their importance. Pin only what would hurt if a session started without it. A reasonable ceiling is about five pinned memories per scope. If you want to pin a sixth, unpin or merge one first.
|
|
20
|
+
|
|
21
|
+
Pinning and importance 4 or 5 do the same job for `get_context`. Use importance for "this matters" and pinning for "this must always be loaded". In practice you rarely need both.
|
|
22
|
+
|
|
23
|
+
## Categories
|
|
24
|
+
|
|
25
|
+
| Category | Use for | Not for |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| `decision` | A choice that was made, with the reason, and ideally what was rejected | Preferences with no trade-off |
|
|
28
|
+
| `preference` | How the user likes things done | Facts about the system |
|
|
29
|
+
| `fact` | Durable truth about the project, system, or user | Anything that will be false next week |
|
|
30
|
+
| `error` | Something that failed, what caused it, and the fix | Bugs that are already fixed and will not recur |
|
|
31
|
+
| `todo` | Work explicitly deferred | Your own in-session task list |
|
|
32
|
+
| `context` | Background that helps orient a future session (the default) | Anything that fits a more specific category |
|
|
33
|
+
|
|
34
|
+
Custom categories are created the first time you use a name. Keep them short and lowercase (letters, numbers, dashes, underscores, up to 32 characters). Run `list_categories` first, because `ci` and `cicd` splitting the same topic helps nobody. Prefer a built-in category unless a custom one will hold several memories.
|
|
35
|
+
|
|
36
|
+
## Scope
|
|
37
|
+
|
|
38
|
+
| Question | If yes |
|
|
39
|
+
|---|---|
|
|
40
|
+
| Is it about the user, how they work, or their tools across projects? | `global` |
|
|
41
|
+
| Would it be wrong or confusing in a different project? | `project` |
|
|
42
|
+
| Is it a coding convention for one repo? | `project` |
|
|
43
|
+
| Is it a personal preference that applies to every repo (tabs, tone, tools)? | `global` |
|
|
44
|
+
| Not sure? | `project`. It is easier to promote later (`update_memory` with `scope: "global"`) than to find a stray global memory. |
|