humemory 0.2.1
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/.githooks/post-commit +22 -0
- package/AGENTS.md +328 -0
- package/CHANGELOG.md +198 -0
- package/LICENSE +21 -0
- package/README.md +488 -0
- package/bin/humemory.js +19 -0
- package/dist/agent/claude-hook.d.ts +15 -0
- package/dist/agent/claude-hook.js +38 -0
- package/dist/agent/commit-closer.d.ts +60 -0
- package/dist/agent/commit-closer.js +125 -0
- package/dist/agent/learning-extractor.d.ts +10 -0
- package/dist/agent/learning-extractor.js +75 -0
- package/dist/agent/session-context.d.ts +63 -0
- package/dist/agent/session-context.js +216 -0
- package/dist/agent/session-parser.d.ts +12 -0
- package/dist/agent/session-parser.js +85 -0
- package/dist/api/dream-routes.d.ts +7 -0
- package/dist/api/dream-routes.js +40 -0
- package/dist/api/intentions-routes.d.ts +23 -0
- package/dist/api/intentions-routes.js +252 -0
- package/dist/api/memory-routes.d.ts +10 -0
- package/dist/api/memory-routes.js +277 -0
- package/dist/api/scripts-routes.d.ts +13 -0
- package/dist/api/scripts-routes.js +129 -0
- package/dist/api/server.d.ts +33 -0
- package/dist/api/server.js +157 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +798 -0
- package/dist/core/clock.d.ts +38 -0
- package/dist/core/clock.js +52 -0
- package/dist/core/cue-arg.d.ts +19 -0
- package/dist/core/cue-arg.js +72 -0
- package/dist/core/cues.d.ts +138 -0
- package/dist/core/cues.js +372 -0
- package/dist/core/decay.d.ts +49 -0
- package/dist/core/decay.js +157 -0
- package/dist/core/dreamer.d.ts +114 -0
- package/dist/core/dreamer.js +427 -0
- package/dist/core/embeddings.d.ts +79 -0
- package/dist/core/embeddings.js +133 -0
- package/dist/core/event-bus.d.ts +71 -0
- package/dist/core/event-bus.js +67 -0
- package/dist/core/hybrid.d.ts +33 -0
- package/dist/core/hybrid.js +63 -0
- package/dist/core/llm-generator.d.ts +18 -0
- package/dist/core/llm-generator.js +69 -0
- package/dist/core/sanitize.d.ts +57 -0
- package/dist/core/sanitize.js +87 -0
- package/dist/core/scripts.d.ts +55 -0
- package/dist/core/scripts.js +96 -0
- package/dist/core/search.d.ts +42 -0
- package/dist/core/search.js +173 -0
- package/dist/core/trust.d.ts +48 -0
- package/dist/core/trust.js +57 -0
- package/dist/core/types.d.ts +333 -0
- package/dist/core/types.js +1 -0
- package/dist/core/vector-clusterer.d.ts +53 -0
- package/dist/core/vector-clusterer.js +113 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +18 -0
- package/dist/mcp/server.d.ts +22 -0
- package/dist/mcp/server.js +158 -0
- package/dist/store/sqlite.d.ts +240 -0
- package/dist/store/sqlite.js +1653 -0
- package/docs/TESTING.md +244 -0
- package/package.json +95 -0
- package/public/app/galaxy-f42190mq.js +10 -0
- package/public/app/index-2cf31xxn.css +1 -0
- package/public/app/index-epqg22cp.js +1 -0
- package/public/app/index-f9h80bzq.js +12 -0
- package/public/app/index-gbfwa9vq.js +2 -0
- package/public/app/index-kvhc17mz.js +2 -0
- package/public/app/index-pbd5t4dj.js +2 -0
- package/public/app/index.html +12 -0
- package/public/app/promenade-cnzzpm73.js +4111 -0
- package/public/app/river-tyawhh8w.js +13 -0
- package/public/session.html +659 -0
- package/scripts/consolidate.js +46 -0
- package/scripts/hook-post-commit.ts +80 -0
- package/scripts/hook-session-start.ts +92 -0
- package/scripts/hook-session.ts +60 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API HTTP pour humemory
|
|
3
|
+
*
|
|
4
|
+
* Endpoints:
|
|
5
|
+
* POST /memories - Add a memory
|
|
6
|
+
* GET /memories - List memories
|
|
7
|
+
* GET /memories/:id - Fetch one memory
|
|
8
|
+
* POST /memories/:id/recall - Recall a memory
|
|
9
|
+
* DELETE /memories/:id - Delete a memory
|
|
10
|
+
* GET /search - Search
|
|
11
|
+
* POST /decay - Run the decay sweep
|
|
12
|
+
* GET /status - Memory state
|
|
13
|
+
*
|
|
14
|
+
* Fronts :
|
|
15
|
+
* GET / - React app (explicit 503 when the bundle is missing)
|
|
16
|
+
* GET /app - Same app, historical URL
|
|
17
|
+
* GET /session - Mnemonic context composer (standalone page)
|
|
18
|
+
*
|
|
19
|
+
* Prospective memory (src/api/intentions-routes.ts):
|
|
20
|
+
* POST /intentions - Arm a loop (and its cues)
|
|
21
|
+
* GET /intentions - List (status, directory filters)
|
|
22
|
+
* GET /intentions/:id - Detail plus cues
|
|
23
|
+
* POST /intentions/:id/close - Close (cancels remaining cues)
|
|
24
|
+
* POST /intentions/:id/fire - Force-fire (debug/dashboard)
|
|
25
|
+
* DELETE /intentions/:id - Delete (cues cascade)
|
|
26
|
+
* POST /cues - Attach a cue
|
|
27
|
+
* GET /cues - List (intentionId, status, kind filters)
|
|
28
|
+
* POST /events - Push an event, waking the loops that match
|
|
29
|
+
* POST /cues/resolve - Sweep: expire overdue loops, fire due deadlines
|
|
30
|
+
*/
|
|
31
|
+
import { Hono } from 'hono';
|
|
32
|
+
declare const app: Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
|
|
33
|
+
export { app };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API HTTP pour humemory
|
|
3
|
+
*
|
|
4
|
+
* Endpoints:
|
|
5
|
+
* POST /memories - Add a memory
|
|
6
|
+
* GET /memories - List memories
|
|
7
|
+
* GET /memories/:id - Fetch one memory
|
|
8
|
+
* POST /memories/:id/recall - Recall a memory
|
|
9
|
+
* DELETE /memories/:id - Delete a memory
|
|
10
|
+
* GET /search - Search
|
|
11
|
+
* POST /decay - Run the decay sweep
|
|
12
|
+
* GET /status - Memory state
|
|
13
|
+
*
|
|
14
|
+
* Fronts :
|
|
15
|
+
* GET / - React app (explicit 503 when the bundle is missing)
|
|
16
|
+
* GET /app - Same app, historical URL
|
|
17
|
+
* GET /session - Mnemonic context composer (standalone page)
|
|
18
|
+
*
|
|
19
|
+
* Prospective memory (src/api/intentions-routes.ts):
|
|
20
|
+
* POST /intentions - Arm a loop (and its cues)
|
|
21
|
+
* GET /intentions - List (status, directory filters)
|
|
22
|
+
* GET /intentions/:id - Detail plus cues
|
|
23
|
+
* POST /intentions/:id/close - Close (cancels remaining cues)
|
|
24
|
+
* POST /intentions/:id/fire - Force-fire (debug/dashboard)
|
|
25
|
+
* DELETE /intentions/:id - Delete (cues cascade)
|
|
26
|
+
* POST /cues - Attach a cue
|
|
27
|
+
* GET /cues - List (intentionId, status, kind filters)
|
|
28
|
+
* POST /events - Push an event, waking the loops that match
|
|
29
|
+
* POST /cues/resolve - Sweep: expire overdue loops, fire due deadlines
|
|
30
|
+
*/
|
|
31
|
+
import { Hono } from 'hono';
|
|
32
|
+
import { cors } from 'hono/cors';
|
|
33
|
+
import { serve } from '@hono/node-server';
|
|
34
|
+
import { SQLiteStore } from '../store/sqlite.js';
|
|
35
|
+
import { createIntentionRoutes } from './intentions-routes.js';
|
|
36
|
+
import { createMemoryRoutes } from './memory-routes.js';
|
|
37
|
+
import { createDreamRoutes } from './dream-routes.js';
|
|
38
|
+
import { createScriptRoutes } from './scripts-routes.js';
|
|
39
|
+
import { join, dirname, resolve, sep } from 'path';
|
|
40
|
+
import { fileURLToPath } from 'url';
|
|
41
|
+
import { readFileSync } from 'fs';
|
|
42
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
43
|
+
const __dirname = dirname(__filename);
|
|
44
|
+
/**
|
|
45
|
+
* Resolve a request-supplied path under a trusted base dir, refusing any
|
|
46
|
+
* result that escapes the base (path traversal / CWE-22). Returns null if
|
|
47
|
+
* the path would leave baseDir.
|
|
48
|
+
*/
|
|
49
|
+
function safeJoin(baseDir, ...segments) {
|
|
50
|
+
const base = resolve(baseDir);
|
|
51
|
+
const full = resolve(base, ...segments);
|
|
52
|
+
if (full !== base && !full.startsWith(base + sep))
|
|
53
|
+
return null;
|
|
54
|
+
return full;
|
|
55
|
+
}
|
|
56
|
+
// HUMEMORY_DB: same convention as the CLI and the hooks. Without it, the API
|
|
57
|
+
// cannot be pointed at a demo database without writing to production.
|
|
58
|
+
const DB_PATH = process.env.HUMEMORY_DB ?? join(__dirname, '../../data/humemory.db');
|
|
59
|
+
const store = new SQLiteStore(DB_PATH);
|
|
60
|
+
const PUBLIC_DIR = join(__dirname, '../../public');
|
|
61
|
+
// Configure CORS securely (allow localhost for development, restrict in production)
|
|
62
|
+
const allowedOrigins = process.env.NODE_ENV === 'production'
|
|
63
|
+
? (process.env.CORS_ORIGINS || 'http://localhost:3456').split(',')
|
|
64
|
+
: ['http://localhost:3456', 'http://localhost:3000', 'http://127.0.0.1:3456'];
|
|
65
|
+
const app = new Hono();
|
|
66
|
+
app.use('*', cors({
|
|
67
|
+
origin: (origin) => {
|
|
68
|
+
if (!origin)
|
|
69
|
+
return '*'; // Allow requests without origin (like mobile apps, curl, etc)
|
|
70
|
+
return allowedOrigins.some(allowed => origin.includes(allowed.trim())) ? origin : undefined;
|
|
71
|
+
},
|
|
72
|
+
credentials: true,
|
|
73
|
+
maxAge: 600,
|
|
74
|
+
}));
|
|
75
|
+
// Static files (dashboard)
|
|
76
|
+
const APP_DIR = join(PUBLIC_DIR, 'app');
|
|
77
|
+
/**
|
|
78
|
+
* The React app page, served at `/` as well as `/app`.
|
|
79
|
+
*
|
|
80
|
+
* bun emits relative references (`./index-abc.js`). Served anywhere other than
|
|
81
|
+
* `/app/`, the browser resolves them against the root and finds nothing — so they
|
|
82
|
+
* are absolutised to `/app/`.
|
|
83
|
+
*/
|
|
84
|
+
function reactAppHtml() {
|
|
85
|
+
const html = readFileSync(join(APP_DIR, 'index.html'), 'utf-8');
|
|
86
|
+
return html.replace(/(src|href)="\.\//g, '$1="/app/');
|
|
87
|
+
}
|
|
88
|
+
app.get('/', (c) => {
|
|
89
|
+
try {
|
|
90
|
+
return c.html(reactAppHtml());
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// Missing bundle: say what to run rather than serve a dead page.
|
|
94
|
+
return c.text('Front non construit. Lance `pnpm build:web`.', 503);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
app.get('/session', (c) => {
|
|
98
|
+
const html = readFileSync(join(PUBLIC_DIR, 'session.html'), 'utf-8');
|
|
99
|
+
return c.html(html);
|
|
100
|
+
});
|
|
101
|
+
// React front end (web/ → public/app/ through `pnpm build:web`), served at / and /app.
|
|
102
|
+
const APP_MIME = {
|
|
103
|
+
js: 'application/javascript',
|
|
104
|
+
css: 'text/css',
|
|
105
|
+
html: 'text/html',
|
|
106
|
+
json: 'application/json',
|
|
107
|
+
svg: 'image/svg+xml',
|
|
108
|
+
png: 'image/png',
|
|
109
|
+
woff2: 'font/woff2',
|
|
110
|
+
};
|
|
111
|
+
app.get('/app', (c) => {
|
|
112
|
+
try {
|
|
113
|
+
return c.html(reactAppHtml());
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// Missing bundle: say what to run rather than a silent 404.
|
|
117
|
+
return c.text('Front non construit. Lance `pnpm build:web`.', 503);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
app.get('/app/*', (c) => {
|
|
121
|
+
const filePath = c.req.path.replace('/app/', '');
|
|
122
|
+
const fullPath = safeJoin(APP_DIR, filePath);
|
|
123
|
+
if (!fullPath)
|
|
124
|
+
return c.notFound();
|
|
125
|
+
try {
|
|
126
|
+
const ext = filePath.split('.').pop() ?? '';
|
|
127
|
+
const content = readFileSync(fullPath);
|
|
128
|
+
return c.body(content, 200, { 'Content-Type': APP_MIME[ext] ?? 'application/octet-stream' });
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return c.notFound();
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
// === RETROSPECTIVE MEMORY ===
|
|
135
|
+
// Testable sub-router (src/api/memory-routes.ts), mounted here.
|
|
136
|
+
app.route('/', createMemoryRoutes(store));
|
|
137
|
+
// === PROSPECTIVE MEMORY (Phase 5.4) ===
|
|
138
|
+
// Isolated sub-router: it takes the store as a parameter, so it is testable
|
|
139
|
+
// without opening the production database (see tests/api-intentions.test.ts).
|
|
140
|
+
app.route('/', createIntentionRoutes(store));
|
|
141
|
+
// === DREAMING (Phase 6.1) ===
|
|
142
|
+
app.route('/', createDreamRoutes(store));
|
|
143
|
+
// === COGNITIVE SCRIPTS (Phase 8.3) ===
|
|
144
|
+
app.route('/', createScriptRoutes(store));
|
|
145
|
+
// === HEALTH ===
|
|
146
|
+
app.get('/health', (c) => {
|
|
147
|
+
return c.json({ status: 'ok', timestamp: new Date().toISOString() });
|
|
148
|
+
});
|
|
149
|
+
export { app };
|
|
150
|
+
// Only starts when run directly: importing this module (a test, a tool) must not
|
|
151
|
+
// raise a server or seize the port.
|
|
152
|
+
if (import.meta.main) {
|
|
153
|
+
const port = parseInt(process.env.PORT || '3456');
|
|
154
|
+
console.log(`🧠 humemory API running on http://localhost:${port}`);
|
|
155
|
+
console.log(`📊 Dashboard: http://localhost:${port}/`);
|
|
156
|
+
serve({ fetch: app.fetch, port });
|
|
157
|
+
}
|