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,46 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * humemory automatic consolidation script.
4
+ * Meant to run from cron, nightly.
5
+ */
6
+
7
+ import { execSync } from 'child_process';
8
+ import { fileURLToPath } from 'url';
9
+ import { dirname, join } from 'path';
10
+
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = dirname(__filename);
13
+ const HUMEMORY_DIR = join(__dirname, '..');
14
+
15
+ console.log('humemory - automatic consolidation');
16
+ console.log('='.repeat(50));
17
+ console.log(`Date: ${new Date().toISOString()}`);
18
+ console.log(`Directory: ${HUMEMORY_DIR}`);
19
+ console.log();
20
+
21
+ try {
22
+ // Run the decay sweep
23
+ console.log('Updating consolidation...');
24
+ const decayOutput = execSync('pnpm cli decay', {
25
+ cwd: HUMEMORY_DIR,
26
+ encoding: 'utf-8',
27
+ });
28
+ console.log(decayOutput);
29
+
30
+ // State of the memory palace
31
+ console.log('humemory state:');
32
+ const statusOutput = execSync('pnpm cli status', {
33
+ cwd: HUMEMORY_DIR,
34
+ encoding: 'utf-8',
35
+ });
36
+ console.log(statusOutput);
37
+
38
+ console.log('Consolidation finished successfully');
39
+ process.exit(0);
40
+ } catch (error) {
41
+ console.error('Consolidation failed:');
42
+ console.error(error.message);
43
+ if (error.stdout) console.error(error.stdout.toString());
44
+ if (error.stderr) console.error(error.stderr.toString());
45
+ process.exit(1);
46
+ }
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Git post-commit hook — closes the loops this commit purged.
4
+ *
5
+ * Install with:
6
+ * git config core.hooksPath .githooks
7
+ *
8
+ * `.githooks/post-commit` calls this script. It only closes loops named
9
+ * explicitly (`Closes loop-a1b2c3d4`); everything else is suggested, never
10
+ * applied.
11
+ *
12
+ * Environment variables:
13
+ * HUMEMORY_DB — database path (default: data/humemory.db, relative to this script)
14
+ * HUMEMORY_DIR — mental place (default: the git repository root)
15
+ */
16
+
17
+ import { join, dirname } from 'path';
18
+ import { fileURLToPath } from 'url';
19
+ import { SQLiteStore } from '../src/store/sqlite.js';
20
+ import { applyCommitToLoops, renderCommitReport, type CommitInfo } from '../src/agent/commit-closer.js';
21
+
22
+ const __filename = fileURLToPath(import.meta.url);
23
+ const __dirname = dirname(__filename);
24
+
25
+ const DB_PATH = process.env.HUMEMORY_DB ?? join(__dirname, '../data/humemory.db');
26
+
27
+ /** Runs a git command, returning stdout or null when it fails. */
28
+ async function git(args: string[]): Promise<string | null> {
29
+ try {
30
+ const proc = Bun.spawn(['git', ...args], { stdout: 'pipe', stderr: 'ignore' });
31
+ const out = await new Response(proc.stdout).text();
32
+ return (await proc.exited) === 0 ? out.trim() : null;
33
+ } catch {
34
+ return null;
35
+ }
36
+ }
37
+
38
+ /** Describes the commit just created. Null when not inside a repository. */
39
+ async function lastCommit(): Promise<CommitInfo | null> {
40
+ const sha = await git(['rev-parse', 'HEAD']);
41
+ if (!sha) return null;
42
+
43
+ const message = (await git(['log', '-1', '--pretty=%B'])) ?? '';
44
+ const root = (await git(['rev-parse', '--show-toplevel'])) ?? process.cwd();
45
+
46
+ // Files in the commit. An initial commit has no parent; this form covers it.
47
+ const raw = await git(['show', '--name-only', '--pretty=format:', '--no-renames', sha]);
48
+ const files = (raw ?? '').split('\n').map((f) => f.trim()).filter(Boolean);
49
+
50
+ return {
51
+ sha,
52
+ message,
53
+ files,
54
+ directory: process.env.HUMEMORY_DIR ?? root,
55
+ };
56
+ }
57
+
58
+ async function main() {
59
+ let store: SQLiteStore | undefined;
60
+
61
+ try {
62
+ const commit = await lastCommit();
63
+ if (!commit) return; // not a git repository: nothing to do
64
+
65
+ store = new SQLiteStore(DB_PATH);
66
+ const result = await applyCommitToLoops(store, commit);
67
+
68
+ const report = renderCommitReport(result);
69
+ if (report) process.stdout.write(`\n${report}`);
70
+ } catch (err) {
71
+ // A git hook must never fail a commit that is already written.
72
+ console.error(`[humemory] post-commit hook error: ${err}`);
73
+ } finally {
74
+ store?.close();
75
+ }
76
+
77
+ process.exit(0);
78
+ }
79
+
80
+ main();
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Claude Code SessionStart hook — writes the mnemonic context to stdout.
4
+ *
5
+ * Whatever Claude Code reads on stdout is injected into the session context: the
6
+ * agent starts out knowing which loops it left open on this project, instead of
7
+ * having to go looking for them.
8
+ *
9
+ * Usage dans Claude Code settings.json:
10
+ * {
11
+ * "hooks": {
12
+ * "SessionStart": [{ "matcher": "", "hooks": [{ "type": "command", "command": "bun /path/to/humemory/scripts/hook-session-start.ts" }] }]
13
+ * }
14
+ * }
15
+ *
16
+ * Environment variables:
17
+ * HUMEMORY_DB — database path (default: data/humemory.db, relative to this script)
18
+ * HUMEMORY_DIR — project directory (default: cwd)
19
+ * HUMEMORY_SESSION_BUDGET — max items per section (default: 10)
20
+ * HUMEMORY_SAILLANCE_MIN — salience floor for recalled traces (default: 60)
21
+ * HUMEMORY_VERBOSE — '1' to log on stderr
22
+ */
23
+
24
+ import { join, dirname } from 'path';
25
+ import { fileURLToPath } from 'url';
26
+ import { SQLiteStore } from '../src/store/sqlite.js';
27
+ import { SqliteCueResolver } from '../src/core/cues.js';
28
+ import { buildSessionContext, DEFAULT_SESSION_BUDGET, DEFAULT_SAILLANCE_THRESHOLD } from '../src/agent/session-context.js';
29
+
30
+ const __filename = fileURLToPath(import.meta.url);
31
+ const __dirname = dirname(__filename);
32
+
33
+ const DB_PATH = process.env.HUMEMORY_DB ?? join(__dirname, '../data/humemory.db');
34
+ const DIRECTORY = process.env.HUMEMORY_DIR ?? process.cwd();
35
+ const VERBOSE = process.env.HUMEMORY_VERBOSE === '1';
36
+
37
+ function positiveInt(raw: string | undefined, fallback: number): number {
38
+ const n = Number(raw);
39
+ return Number.isInteger(n) && n > 0 ? n : fallback;
40
+ }
41
+
42
+ /** Current git branch, or undefined outside a repository — never an exception. */
43
+ async function currentBranch(cwd: string): Promise<string | undefined> {
44
+ try {
45
+ const proc = Bun.spawn(['git', 'branch', '--show-current'], {
46
+ cwd,
47
+ stdout: 'pipe',
48
+ stderr: 'ignore',
49
+ });
50
+ const out = (await new Response(proc.stdout).text()).trim();
51
+ return (await proc.exited) === 0 && out ? out : undefined;
52
+ } catch {
53
+ return undefined;
54
+ }
55
+ }
56
+
57
+ async function main() {
58
+ let store: SQLiteStore | undefined;
59
+
60
+ try {
61
+ store = new SQLiteStore(DB_PATH);
62
+ const resolver = new SqliteCueResolver(store);
63
+
64
+ const context = await buildSessionContext({
65
+ store,
66
+ resolver,
67
+ directory: DIRECTORY,
68
+ branch: await currentBranch(DIRECTORY),
69
+ budget: positiveInt(process.env.HUMEMORY_SESSION_BUDGET, DEFAULT_SESSION_BUDGET),
70
+ saillanceThreshold: positiveInt(process.env.HUMEMORY_SAILLANCE_MIN, DEFAULT_SAILLANCE_THRESHOLD),
71
+ });
72
+
73
+ // Nothing relevant: write nothing rather than pollute the context.
74
+ if (context.markdown) process.stdout.write(context.markdown);
75
+
76
+ if (VERBOSE) {
77
+ console.error(
78
+ `[humemory] ${context.openLoops.length} open loop(s), ` +
79
+ `${context.traces.length} trace(s), ${context.firedNow.length} deadline(s) reached`
80
+ );
81
+ }
82
+ } catch (err) {
83
+ // A hook must never block a session: log it and exit cleanly.
84
+ console.error(`[humemory] session-start hook error: ${err}`);
85
+ } finally {
86
+ store?.close();
87
+ }
88
+
89
+ process.exit(0);
90
+ }
91
+
92
+ main();
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Claude Code Stop hook — reads the transcript from stdin and stores the learnings.
4
+ *
5
+ * Usage dans Claude Code settings.json:
6
+ * {
7
+ * "hooks": {
8
+ * "Stop": [{ "matcher": "", "hooks": [{ "type": "command", "command": "bun /path/to/humemory/scripts/hook-session.ts" }] }]
9
+ * }
10
+ * }
11
+ *
12
+ * Environment variables:
13
+ * HUMEMORY_DB — database path (default: data/humemory.db, relative to this script)
14
+ * HUMEMORY_DIR — project directory (default: cwd)
15
+ * HUMEMORY_MAX — max learnings per session (default: 5)
16
+ */
17
+
18
+ import { join, dirname } from 'path';
19
+ import { fileURLToPath } from 'url';
20
+ import { processSession } from '../src/agent/claude-hook.js';
21
+
22
+ const __filename = fileURLToPath(import.meta.url);
23
+ const __dirname = dirname(__filename);
24
+
25
+ const DB_PATH = process.env.HUMEMORY_DB ?? join(__dirname, '../data/humemory.db');
26
+ const DIRECTORY = process.env.HUMEMORY_DIR ?? process.cwd();
27
+ const MAX_LEARNINGS = parseInt(process.env.HUMEMORY_MAX ?? '5');
28
+
29
+ async function main() {
30
+ let rawInput = '';
31
+
32
+ // Read from stdin (Claude Code hook passes transcript via stdin)
33
+ for await (const chunk of Bun.stdin.stream()) {
34
+ rawInput += new TextDecoder().decode(chunk);
35
+ }
36
+
37
+ if (!rawInput.trim()) {
38
+ process.exit(0);
39
+ }
40
+
41
+ try {
42
+ const result = await processSession(rawInput, {
43
+ dbPath: DB_PATH,
44
+ directory: DIRECTORY,
45
+ maxLearnings: MAX_LEARNINGS,
46
+ verbose: process.env.HUMEMORY_VERBOSE === '1',
47
+ });
48
+
49
+ if (result.memoriesStored > 0) {
50
+ console.error(`[humemory] ${result.memoriesStored} learning(s) stored — session ${result.sessionId}`);
51
+ }
52
+ } catch (err) {
53
+ // Never block Claude Code — log to stderr only
54
+ console.error(`[humemory] hook error: ${err}`);
55
+ }
56
+
57
+ process.exit(0);
58
+ }
59
+
60
+ main();