@justfortytwo/memory 0.1.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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +183 -0
  3. package/dist/contract.d.ts +19 -0
  4. package/dist/contract.js +41 -0
  5. package/dist/contract.js.map +1 -0
  6. package/dist/db.d.ts +11 -0
  7. package/dist/db.js +33 -0
  8. package/dist/db.js.map +1 -0
  9. package/dist/dispatch.d.ts +3 -0
  10. package/dist/dispatch.js +43 -0
  11. package/dist/dispatch.js.map +1 -0
  12. package/dist/embedder.d.ts +18 -0
  13. package/dist/embedder.js +44 -0
  14. package/dist/embedder.js.map +1 -0
  15. package/dist/enrichment.d.ts +58 -0
  16. package/dist/enrichment.js +109 -0
  17. package/dist/enrichment.js.map +1 -0
  18. package/dist/gate-approval-store.d.ts +17 -0
  19. package/dist/gate-approval-store.js +114 -0
  20. package/dist/gate-approval-store.js.map +1 -0
  21. package/dist/index.d.ts +16 -0
  22. package/dist/index.js +72 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/memory.d.ts +74 -0
  25. package/dist/memory.js +179 -0
  26. package/dist/memory.js.map +1 -0
  27. package/dist/migrate.d.ts +2 -0
  28. package/dist/migrate.js +40 -0
  29. package/dist/migrate.js.map +1 -0
  30. package/dist/migrations/001_init.d.ts +3 -0
  31. package/dist/migrations/001_init.js +40 -0
  32. package/dist/migrations/001_init.js.map +1 -0
  33. package/dist/migrations/002_fts.d.ts +3 -0
  34. package/dist/migrations/002_fts.js +26 -0
  35. package/dist/migrations/002_fts.js.map +1 -0
  36. package/dist/migrations/003_approvals.d.ts +3 -0
  37. package/dist/migrations/003_approvals.js +37 -0
  38. package/dist/migrations/003_approvals.js.map +1 -0
  39. package/dist/tools.d.ts +2 -0
  40. package/dist/tools.js +66 -0
  41. package/dist/tools.js.map +1 -0
  42. package/package.json +68 -0
@@ -0,0 +1,37 @@
1
+ // Durable backing for gate's ApprovalStore + AuditLogger seam (see
2
+ // gate-approval-store.ts). `approvals` holds staged one-shot approvals keyed by
3
+ // tool_use_id; `audit_log` is an append-only trail. Both live on memory's db so a
4
+ // host can give the gate a transactional store instead of its JSONL default.
5
+ export async function up(k) {
6
+ await k.schema
7
+ .createTable('approvals', (t) => {
8
+ t.string('id').primary(); // pa_<uuid>
9
+ t.string('tool').notNullable();
10
+ t.string('target').notNullable();
11
+ t.text('payload').notNullable().defaultTo('{}');
12
+ t.string('tier').notNullable();
13
+ t.string('tool_use_id').notNullable();
14
+ t.string('session_id').nullable();
15
+ t.string('status').notNullable().defaultTo('pending'); // pending|approved|denied|executed|expired
16
+ t.string('decided_by').nullable(); // who approved/denied (audit attribution)
17
+ t.string('created_at').notNullable();
18
+ t.string('updated_at').notNullable();
19
+ // One staged row per tool_use_id (gate's "most-recent-wins" contract);
20
+ // addPending upserts, so a re-request replaces the prior row deterministically.
21
+ t.unique(['tool_use_id']);
22
+ t.index(['status']);
23
+ })
24
+ .createTable('audit_log', (t) => {
25
+ t.increments('id').primary();
26
+ t.datetime('ts', { useTz: false }).notNullable().defaultTo(k.fn.now());
27
+ t.string('actor').notNullable();
28
+ t.string('kind').notNullable();
29
+ t.text('content').notNullable();
30
+ t.string('approval_status').nullable();
31
+ t.text('meta').notNullable().defaultTo('{}');
32
+ });
33
+ }
34
+ export async function down(k) {
35
+ await k.schema.dropTableIfExists('audit_log').dropTableIfExists('approvals');
36
+ }
37
+ //# sourceMappingURL=003_approvals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"003_approvals.js","sourceRoot":"","sources":["../../src/migrations/003_approvals.ts"],"names":[],"mappings":"AAEA,mEAAmE;AACnE,gFAAgF;AAChF,kFAAkF;AAClF,6EAA6E;AAC7E,MAAM,CAAC,KAAK,UAAU,EAAE,CAAC,CAAO;IAC9B,MAAM,CAAC,CAAC,MAAM;SACX,WAAW,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE;QAC9B,CAAC,CAAC,M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AC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;QACvE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;QAChC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAC/B,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;QAChC,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,QAAQ,EAAE,CAAC;QACvC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACP,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,CAAO;IAChC,MAAM,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { Tool } from '@modelcontextprotocol/sdk/types.js';
2
+ export declare function toolDefinitions(): Tool[];
package/dist/tools.js ADDED
@@ -0,0 +1,66 @@
1
+ // Wire schema for the generic memory tool surface. Keep in sync with
2
+ // contract.ts (memoryToolContract) — that file is the version-tracked
3
+ // human contract; this file is what the MCP ListTools handler returns.
4
+ export function toolDefinitions() {
5
+ return [
6
+ {
7
+ name: 'store',
8
+ description: 'Store a memory (content + free-form provenance) and embed it for recall. Set `supersedes` to replace a prior memory (history is kept; never a silent overwrite).',
9
+ inputSchema: {
10
+ type: 'object',
11
+ properties: {
12
+ content: { type: 'string' },
13
+ source: { type: 'string', description: 'Free-form provenance, e.g. owner, web, tool:foo.' },
14
+ observed: { type: 'string', description: 'Free-form, e.g. stated, inferred, imported.' },
15
+ date: { type: 'string', description: 'ISO date the memory pertains to. Defaults to today (UTC).' },
16
+ tags: { type: 'array', items: { type: 'string' } },
17
+ meta: { type: 'object', description: 'Arbitrary structured provenance.' },
18
+ supersedes: { type: 'number', description: 'Id of a memory this one replaces.' },
19
+ },
20
+ required: ['content'],
21
+ },
22
+ },
23
+ {
24
+ name: 'query',
25
+ description: 'Structured query over the memory store (source/observed/tag/time). Returns live rows only unless live_only=false.',
26
+ inputSchema: {
27
+ type: 'object',
28
+ properties: {
29
+ source: { type: 'string' }, observed: { type: 'string' }, tag: { type: 'string' },
30
+ since: { type: 'string' }, until: { type: 'string' },
31
+ live_only: { type: 'boolean' }, limit: { type: 'number' },
32
+ },
33
+ },
34
+ },
35
+ {
36
+ name: 'recall',
37
+ description: 'Semantic top-k recall over the memory store by meaning.',
38
+ inputSchema: { type: 'object', properties: { text: { type: 'string' }, k: { type: 'number' } }, required: ['text'] },
39
+ },
40
+ {
41
+ name: 'recall_docs',
42
+ description: 'Semantic top-k recall over reindexed markdown documents (the doc_vec index built by reindex).',
43
+ inputSchema: { type: 'object', properties: { text: { type: 'string' }, k: { type: 'number' } }, required: ['text'] },
44
+ },
45
+ {
46
+ name: 'lexical',
47
+ description: 'Full-text keyword search over the memory store (FTS5).',
48
+ inputSchema: { type: 'object', properties: { text: { type: 'string' }, k: { type: 'number' } }, required: ['text'] },
49
+ },
50
+ {
51
+ name: 'reindex',
52
+ description: 'Self-heal the doc recall index from a directory of markdown files. Pass the directory in `root`.',
53
+ inputSchema: { type: 'object', properties: { root: { type: 'string' } }, required: ['root'] },
54
+ },
55
+ {
56
+ name: 'export_range',
57
+ description: 'Render a date range of memories to markdown (for debugging/export).',
58
+ inputSchema: {
59
+ type: 'object',
60
+ properties: { since: { type: 'string' }, until: { type: 'string' } },
61
+ required: ['since', 'until'],
62
+ },
63
+ },
64
+ ];
65
+ }
66
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAEA,qEAAqE;AACrE,sEAAsE;AACtE,uEAAuE;AACvE,MAAM,UAAU,eAAe;IAC7B,OAAO;QACL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O,EAAE,OAAO,CAAC;aAC7B;SACF;KACF,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@justfortytwo/memory",
3
+ "version": "0.1.0",
4
+ "description": "Standalone semantic-memory MCP server (SQLite + sqlite-vec + Ollama embedder). persona-agnostic.",
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "Enrico Deleo",
8
+ "url": "https://enricodeleo.com"
9
+ },
10
+ "homepage": "https://forty-two.it",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/justfortytwo/memory.git"
14
+ },
15
+ "type": "module",
16
+ "engines": {
17
+ "node": ">=18"
18
+ },
19
+ "bin": {
20
+ "fortytwo-memory": "dist/index.js"
21
+ },
22
+ "main": "dist/index.js",
23
+ "types": "dist/index.d.ts",
24
+ "exports": {
25
+ ".": "./dist/index.js",
26
+ "./contract": "./dist/contract.js"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md",
31
+ "LICENSE"
32
+ ],
33
+ "scripts": {
34
+ "build": "tsc",
35
+ "start": "node dist/index.js",
36
+ "test": "vitest run",
37
+ "test:watch": "vitest",
38
+ "migrate": "node dist/migrate.js",
39
+ "prepublishOnly": "npm run build"
40
+ },
41
+ "dependencies": {
42
+ "@modelcontextprotocol/sdk": "^1.0.0",
43
+ "better-sqlite3": "^11.0.0",
44
+ "knex": "^3.1.0",
45
+ "sqlite-vec": "^0.1.6"
46
+ },
47
+ "peerDependencies": {
48
+ "@justfortytwo/gate": "^0.1.0",
49
+ "@justfortytwo/salience": "^0.1.0"
50
+ },
51
+ "peerDependenciesMeta": {
52
+ "@justfortytwo/gate": {
53
+ "optional": true
54
+ },
55
+ "@justfortytwo/salience": {
56
+ "optional": true
57
+ }
58
+ },
59
+ "devDependencies": {
60
+ "@types/better-sqlite3": "^7.6.0",
61
+ "@types/node": "^20.0.0",
62
+ "typescript": "^5.4.0",
63
+ "vitest": "^1.6.0"
64
+ },
65
+ "publishConfig": {
66
+ "access": "public"
67
+ }
68
+ }