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.
Files changed (81) hide show
  1. package/.githooks/post-commit +22 -0
  2. package/AGENTS.md +328 -0
  3. package/CHANGELOG.md +198 -0
  4. package/LICENSE +21 -0
  5. package/README.md +488 -0
  6. package/bin/humemory.js +19 -0
  7. package/dist/agent/claude-hook.d.ts +15 -0
  8. package/dist/agent/claude-hook.js +38 -0
  9. package/dist/agent/commit-closer.d.ts +60 -0
  10. package/dist/agent/commit-closer.js +125 -0
  11. package/dist/agent/learning-extractor.d.ts +10 -0
  12. package/dist/agent/learning-extractor.js +75 -0
  13. package/dist/agent/session-context.d.ts +63 -0
  14. package/dist/agent/session-context.js +216 -0
  15. package/dist/agent/session-parser.d.ts +12 -0
  16. package/dist/agent/session-parser.js +85 -0
  17. package/dist/api/dream-routes.d.ts +7 -0
  18. package/dist/api/dream-routes.js +40 -0
  19. package/dist/api/intentions-routes.d.ts +23 -0
  20. package/dist/api/intentions-routes.js +252 -0
  21. package/dist/api/memory-routes.d.ts +10 -0
  22. package/dist/api/memory-routes.js +277 -0
  23. package/dist/api/scripts-routes.d.ts +13 -0
  24. package/dist/api/scripts-routes.js +129 -0
  25. package/dist/api/server.d.ts +33 -0
  26. package/dist/api/server.js +157 -0
  27. package/dist/cli/index.d.ts +2 -0
  28. package/dist/cli/index.js +798 -0
  29. package/dist/core/clock.d.ts +38 -0
  30. package/dist/core/clock.js +52 -0
  31. package/dist/core/cue-arg.d.ts +19 -0
  32. package/dist/core/cue-arg.js +72 -0
  33. package/dist/core/cues.d.ts +138 -0
  34. package/dist/core/cues.js +372 -0
  35. package/dist/core/decay.d.ts +49 -0
  36. package/dist/core/decay.js +157 -0
  37. package/dist/core/dreamer.d.ts +114 -0
  38. package/dist/core/dreamer.js +427 -0
  39. package/dist/core/embeddings.d.ts +79 -0
  40. package/dist/core/embeddings.js +133 -0
  41. package/dist/core/event-bus.d.ts +71 -0
  42. package/dist/core/event-bus.js +67 -0
  43. package/dist/core/hybrid.d.ts +33 -0
  44. package/dist/core/hybrid.js +63 -0
  45. package/dist/core/llm-generator.d.ts +18 -0
  46. package/dist/core/llm-generator.js +69 -0
  47. package/dist/core/sanitize.d.ts +57 -0
  48. package/dist/core/sanitize.js +87 -0
  49. package/dist/core/scripts.d.ts +55 -0
  50. package/dist/core/scripts.js +96 -0
  51. package/dist/core/search.d.ts +42 -0
  52. package/dist/core/search.js +173 -0
  53. package/dist/core/trust.d.ts +48 -0
  54. package/dist/core/trust.js +57 -0
  55. package/dist/core/types.d.ts +333 -0
  56. package/dist/core/types.js +1 -0
  57. package/dist/core/vector-clusterer.d.ts +53 -0
  58. package/dist/core/vector-clusterer.js +113 -0
  59. package/dist/index.d.ts +28 -0
  60. package/dist/index.js +18 -0
  61. package/dist/mcp/server.d.ts +22 -0
  62. package/dist/mcp/server.js +158 -0
  63. package/dist/store/sqlite.d.ts +240 -0
  64. package/dist/store/sqlite.js +1653 -0
  65. package/docs/TESTING.md +244 -0
  66. package/package.json +95 -0
  67. package/public/app/galaxy-f42190mq.js +10 -0
  68. package/public/app/index-2cf31xxn.css +1 -0
  69. package/public/app/index-epqg22cp.js +1 -0
  70. package/public/app/index-f9h80bzq.js +12 -0
  71. package/public/app/index-gbfwa9vq.js +2 -0
  72. package/public/app/index-kvhc17mz.js +2 -0
  73. package/public/app/index-pbd5t4dj.js +2 -0
  74. package/public/app/index.html +12 -0
  75. package/public/app/promenade-cnzzpm73.js +4111 -0
  76. package/public/app/river-tyawhh8w.js +13 -0
  77. package/public/session.html +659 -0
  78. package/scripts/consolidate.js +46 -0
  79. package/scripts/hook-post-commit.ts +80 -0
  80. package/scripts/hook-session-start.ts +92 -0
  81. 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
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};