@psiclawops/hypermem 0.1.0 → 0.5.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 (93) hide show
  1. package/ARCHITECTURE.md +4 -3
  2. package/README.md +457 -174
  3. package/package.json +15 -5
  4. package/dist/background-indexer.d.ts +0 -117
  5. package/dist/background-indexer.d.ts.map +0 -1
  6. package/dist/background-indexer.js +0 -732
  7. package/dist/compaction-fence.d.ts +0 -89
  8. package/dist/compaction-fence.d.ts.map +0 -1
  9. package/dist/compaction-fence.js +0 -153
  10. package/dist/compositor.d.ts +0 -139
  11. package/dist/compositor.d.ts.map +0 -1
  12. package/dist/compositor.js +0 -1109
  13. package/dist/cross-agent.d.ts +0 -57
  14. package/dist/cross-agent.d.ts.map +0 -1
  15. package/dist/cross-agent.js +0 -254
  16. package/dist/db.d.ts +0 -131
  17. package/dist/db.d.ts.map +0 -1
  18. package/dist/db.js +0 -398
  19. package/dist/desired-state-store.d.ts +0 -100
  20. package/dist/desired-state-store.d.ts.map +0 -1
  21. package/dist/desired-state-store.js +0 -212
  22. package/dist/doc-chunk-store.d.ts +0 -115
  23. package/dist/doc-chunk-store.d.ts.map +0 -1
  24. package/dist/doc-chunk-store.js +0 -278
  25. package/dist/doc-chunker.d.ts +0 -99
  26. package/dist/doc-chunker.d.ts.map +0 -1
  27. package/dist/doc-chunker.js +0 -324
  28. package/dist/episode-store.d.ts +0 -48
  29. package/dist/episode-store.d.ts.map +0 -1
  30. package/dist/episode-store.js +0 -135
  31. package/dist/fact-store.d.ts +0 -57
  32. package/dist/fact-store.d.ts.map +0 -1
  33. package/dist/fact-store.js +0 -175
  34. package/dist/fleet-store.d.ts +0 -144
  35. package/dist/fleet-store.d.ts.map +0 -1
  36. package/dist/fleet-store.js +0 -276
  37. package/dist/hybrid-retrieval.d.ts +0 -60
  38. package/dist/hybrid-retrieval.d.ts.map +0 -1
  39. package/dist/hybrid-retrieval.js +0 -340
  40. package/dist/index.d.ts +0 -611
  41. package/dist/index.d.ts.map +0 -1
  42. package/dist/index.js +0 -1042
  43. package/dist/knowledge-graph.d.ts +0 -110
  44. package/dist/knowledge-graph.d.ts.map +0 -1
  45. package/dist/knowledge-graph.js +0 -305
  46. package/dist/knowledge-store.d.ts +0 -72
  47. package/dist/knowledge-store.d.ts.map +0 -1
  48. package/dist/knowledge-store.js +0 -241
  49. package/dist/library-schema.d.ts +0 -22
  50. package/dist/library-schema.d.ts.map +0 -1
  51. package/dist/library-schema.js +0 -717
  52. package/dist/message-store.d.ts +0 -76
  53. package/dist/message-store.d.ts.map +0 -1
  54. package/dist/message-store.js +0 -273
  55. package/dist/preference-store.d.ts +0 -54
  56. package/dist/preference-store.d.ts.map +0 -1
  57. package/dist/preference-store.js +0 -109
  58. package/dist/preservation-gate.d.ts +0 -82
  59. package/dist/preservation-gate.d.ts.map +0 -1
  60. package/dist/preservation-gate.js +0 -150
  61. package/dist/provider-translator.d.ts +0 -40
  62. package/dist/provider-translator.d.ts.map +0 -1
  63. package/dist/provider-translator.js +0 -349
  64. package/dist/rate-limiter.d.ts +0 -76
  65. package/dist/rate-limiter.d.ts.map +0 -1
  66. package/dist/rate-limiter.js +0 -179
  67. package/dist/redis.d.ts +0 -188
  68. package/dist/redis.d.ts.map +0 -1
  69. package/dist/redis.js +0 -534
  70. package/dist/schema.d.ts +0 -15
  71. package/dist/schema.d.ts.map +0 -1
  72. package/dist/schema.js +0 -203
  73. package/dist/secret-scanner.d.ts +0 -51
  74. package/dist/secret-scanner.d.ts.map +0 -1
  75. package/dist/secret-scanner.js +0 -248
  76. package/dist/seed.d.ts +0 -108
  77. package/dist/seed.d.ts.map +0 -1
  78. package/dist/seed.js +0 -177
  79. package/dist/system-store.d.ts +0 -73
  80. package/dist/system-store.d.ts.map +0 -1
  81. package/dist/system-store.js +0 -182
  82. package/dist/topic-store.d.ts +0 -45
  83. package/dist/topic-store.d.ts.map +0 -1
  84. package/dist/topic-store.js +0 -136
  85. package/dist/types.d.ts +0 -329
  86. package/dist/types.d.ts.map +0 -1
  87. package/dist/types.js +0 -9
  88. package/dist/vector-store.d.ts +0 -132
  89. package/dist/vector-store.d.ts.map +0 -1
  90. package/dist/vector-store.js +0 -498
  91. package/dist/work-store.d.ts +0 -112
  92. package/dist/work-store.d.ts.map +0 -1
  93. package/dist/work-store.js +0 -273
package/package.json CHANGED
@@ -1,22 +1,32 @@
1
1
  {
2
2
  "name": "@psiclawops/hypermem",
3
- "version": "0.1.0",
3
+ "version": "0.5.0",
4
4
  "description": "Agent-centric memory and context composition engine for OpenClaw",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ },
13
+ "./image-eviction": {
14
+ "import": "./dist/image-eviction.js",
15
+ "types": "./dist/image-eviction.d.ts"
16
+ }
17
+ },
8
18
  "scripts": {
9
19
  "build": "tsc",
10
20
  "dev": "tsc --watch",
11
21
  "typecheck": "tsc --noEmit",
12
- "test": "node test/smoke.mjs && node test/redis-integration.mjs && node test/cross-agent.mjs && node test/vector-search.mjs && node test/library.mjs && node test/compositor.mjs && node test/fleet-cache.mjs && node test/rotation.mjs && node test/knowledge-graph.mjs && node test/rate-limiter.mjs && node test/doc-chunker.mjs && node test/compaction-fence-gate.mjs && node test/hybrid-retrieval.mjs && node test/live-org-registry.mjs && node test/multi-turn-session.mjs && node test/secret-scanner.mjs",
22
+ "test": "node test/smoke.mjs && node test/cross-agent.mjs && node test/vector-search.mjs && node test/library.mjs && node test/compositor.mjs && node test/fleet-cache.mjs && node test/rotation.mjs && node test/knowledge-graph.mjs && node test/rate-limiter.mjs && node test/doc-chunker.mjs && node test/compaction-fence-gate.mjs && node test/hybrid-retrieval.mjs && node test/live-org-registry.mjs && node test/multi-turn-session.mjs && node test/secret-scanner.mjs && node --test test/content-type-classifier.mjs && node test/keystone-history.mjs && node test/cross-topic-keystone.mjs && node test/proactive-pass.mjs && node test/topic-synthesis.mjs && node test/session-topic-map.mjs && node test/virtual-sessions.mjs && node test/budget-downshift.mjs && node --test test/image-eviction.mjs && node test/fos-mod.mjs",
13
23
  "test:quick": "node test/smoke.mjs && node test/library.mjs && node test/compositor.mjs",
14
24
  "validate:plugin-pipeline": "npm --prefix plugin run build && node test/plugin-pipeline.mjs",
15
25
  "test:multi-turn": "node test/multi-turn-session.mjs",
16
- "test:ci": "npm test && npm --prefix plugin run typecheck"
26
+ "test:ci": "npm test && npm --prefix plugin run typecheck",
27
+ "smoke": "node scripts/smoke-test.mjs"
17
28
  },
18
29
  "dependencies": {
19
- "ioredis": "^5.4.1",
20
30
  "sqlite-vec": "^0.1.9"
21
31
  },
22
32
  "devDependencies": {
@@ -38,7 +48,7 @@
38
48
  "license": "Apache-2.0",
39
49
  "repository": {
40
50
  "type": "git",
41
- "url": "https://github.com/PsiClawOps/hypermem-internal.git"
51
+ "url": "https://github.com/PsiClawOps/hypermem.git"
42
52
  },
43
53
  "publishConfig": {
44
54
  "access": "public",
@@ -1,117 +0,0 @@
1
- /**
2
- * HyperMem Background Indexer
3
- *
4
- * Processes message history to extract structured knowledge:
5
- * - Facts: atomic pieces of learned information
6
- * - Episodes: significant events worth remembering
7
- * - Topics: conversation threads and their lifecycle
8
- * - Knowledge: durable structured entries (domain + key)
9
- *
10
- * Runs as a periodic background task, processing unindexed messages
11
- * in batches. Each batch is scored, classified, and stored in L4 (library.db).
12
- *
13
- * Design principles:
14
- * - No LLM dependency: extraction uses pattern matching + heuristics
15
- * - Idempotent: tracks watermarks per agent to avoid reprocessing
16
- * - Bounded: processes N messages per tick to avoid blocking
17
- * - Observable: logs extraction stats for monitoring
18
- */
19
- import type { DatabaseSync } from 'node:sqlite';
20
- import type { IndexerConfig, SessionCursor } from './types.js';
21
- import type { VectorStore } from './vector-store.js';
22
- export interface IndexerStats {
23
- agentId: string;
24
- messagesProcessed: number;
25
- factsExtracted: number;
26
- episodesRecorded: number;
27
- topicsUpdated: number;
28
- knowledgeUpserted: number;
29
- elapsedMs: number;
30
- /** Number of messages that were post-cursor (unseen by model, high-signal priority). */
31
- postCursorMessages: number;
32
- }
33
- /**
34
- * Optional callback to fetch the session cursor for an agent+session.
35
- * When provided, the indexer uses the cursor to prioritize unseen messages.
36
- * The cursor boundary separates "model has seen this" from "new since last compose".
37
- */
38
- export type CursorFetcher = (agentId: string, sessionKey: string) => Promise<SessionCursor | null>;
39
- export interface WatermarkState {
40
- agentId: string;
41
- lastMessageId: number;
42
- lastRunAt: string;
43
- }
44
- export declare class BackgroundIndexer {
45
- private getMessageDb?;
46
- private getLibraryDb?;
47
- private listAgents?;
48
- private getCursor?;
49
- private readonly config;
50
- private intervalHandle;
51
- private running;
52
- private vectorStore;
53
- constructor(config?: Partial<IndexerConfig>, getMessageDb?: ((agentId: string) => DatabaseSync) | undefined, getLibraryDb?: (() => DatabaseSync) | undefined, listAgents?: (() => string[]) | undefined, getCursor?: CursorFetcher | undefined);
54
- /**
55
- * Set the vector store for embedding new facts/episodes at index time.
56
- * Optional — if not set, indexer runs without embedding (FTS5-only mode).
57
- */
58
- setVectorStore(vs: VectorStore): void;
59
- /**
60
- * Start periodic indexing.
61
- */
62
- start(): void;
63
- /**
64
- * Stop periodic indexing.
65
- */
66
- stop(): void;
67
- /**
68
- * Run one indexing pass across all agents.
69
- */
70
- tick(): Promise<IndexerStats[]>;
71
- /**
72
- * Process a single agent's unindexed messages.
73
- *
74
- * When a cursor fetcher is available, messages are split into two tiers:
75
- * - Post-cursor (id > cursor.lastSentId): "unseen" by the model, high-signal priority
76
- * - Pre-cursor (id <= cursor.lastSentId): already in the model's context window, lower priority
77
- * Post-cursor messages are processed first. This ensures the indexer prioritizes
78
- * content the model hasn't seen yet — decisions, incidents, and discoveries that
79
- * happened between context windows.
80
- */
81
- private processAgent;
82
- /**
83
- * Fetch unindexed messages for an agent.
84
- */
85
- private getUnindexedMessages;
86
- /**
87
- * Get the session key for a conversation ID.
88
- */
89
- private getSessionKeyForMessage;
90
- /**
91
- * Get the indexing watermark for an agent.
92
- */
93
- private getWatermark;
94
- /**
95
- * Set the indexing watermark for an agent.
96
- */
97
- private setWatermark;
98
- /**
99
- * Apply time-based decay to facts.
100
- * Increases decay_score for older facts, making them less relevant.
101
- */
102
- private applyDecay;
103
- /**
104
- * Parse a duration string like "24h", "7d" into seconds.
105
- */
106
- private parseDuration;
107
- /**
108
- * Get current watermarks for all agents.
109
- */
110
- getWatermarks(libraryDb: DatabaseSync): WatermarkState[];
111
- }
112
- /**
113
- * Create and start a background indexer connected to HyperMem databases.
114
- * Used by the hook or a standalone daemon.
115
- */
116
- export declare function createIndexer(getMessageDb: (agentId: string) => DatabaseSync, getLibraryDb: () => DatabaseSync, listAgents: () => string[], config?: Partial<IndexerConfig>, getCursor?: CursorFetcher, vectorStore?: VectorStore): BackgroundIndexer;
117
- //# sourceMappingURL=background-indexer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"background-indexer.d.ts","sourceRoot":"","sources":["../src/background-indexer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAiB,aAAa,EAAe,aAAa,EAAE,MAAM,YAAY,CAAC;AAO3F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,wFAAwF;IACxF,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,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