@oh-my-pi/pi-mnemosyne 15.6.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.
- package/README.md +107 -0
- package/dist/types/cli.d.ts +35 -0
- package/dist/types/config.d.ts +77 -0
- package/dist/types/core/aaak.d.ts +55 -0
- package/dist/types/core/annotations.d.ts +75 -0
- package/dist/types/core/banks.d.ts +33 -0
- package/dist/types/core/beam/consolidate.d.ts +32 -0
- package/dist/types/core/beam/helpers.d.ts +59 -0
- package/dist/types/core/beam/index.d.ts +59 -0
- package/dist/types/core/beam/recall.d.ts +32 -0
- package/dist/types/core/beam/schema.d.ts +2 -0
- package/dist/types/core/beam/store.d.ts +35 -0
- package/dist/types/core/beam/types.d.ts +233 -0
- package/dist/types/core/binary-vectors.d.ts +54 -0
- package/dist/types/core/chat-normalize.d.ts +13 -0
- package/dist/types/core/content-sanitizer.d.ts +18 -0
- package/dist/types/core/cost-log.d.ts +13 -0
- package/dist/types/core/embeddings.d.ts +35 -0
- package/dist/types/core/entities.d.ts +7 -0
- package/dist/types/core/episodic-graph.d.ts +89 -0
- package/dist/types/core/extraction/client.d.ts +31 -0
- package/dist/types/core/extraction/diagnostics.d.ts +51 -0
- package/dist/types/core/extraction/prompts.d.ts +2 -0
- package/dist/types/core/extraction.d.ts +6 -0
- package/dist/types/core/index.d.ts +4 -0
- package/dist/types/core/llm-backends.d.ts +21 -0
- package/dist/types/core/local-llm.d.ts +15 -0
- package/dist/types/core/memory.d.ts +160 -0
- package/dist/types/core/migrations/e6-triplestore-split.d.ts +17 -0
- package/dist/types/core/migrations/index.d.ts +1 -0
- package/dist/types/core/mmr.d.ts +8 -0
- package/dist/types/core/orchestrator.d.ts +20 -0
- package/dist/types/core/patterns.d.ts +61 -0
- package/dist/types/core/plugins.d.ts +109 -0
- package/dist/types/core/polyphonic-recall.d.ts +66 -0
- package/dist/types/core/query-cache.d.ts +47 -0
- package/dist/types/core/query-intent.d.ts +20 -0
- package/dist/types/core/recall-diagnostics.d.ts +48 -0
- package/dist/types/core/runtime-options.d.ts +61 -0
- package/dist/types/core/shmr.d.ts +56 -0
- package/dist/types/core/streaming.d.ts +136 -0
- package/dist/types/core/synonyms.d.ts +46 -0
- package/dist/types/core/temporal-parser.d.ts +16 -0
- package/dist/types/core/token-counter.d.ts +8 -0
- package/dist/types/core/triples.d.ts +63 -0
- package/dist/types/core/typed-memory.d.ts +39 -0
- package/dist/types/core/veracity-consolidation.d.ts +60 -0
- package/dist/types/core/weibull.d.ts +96 -0
- package/dist/types/db.d.ts +16 -0
- package/dist/types/diagnose.d.ts +24 -0
- package/dist/types/dr/index.d.ts +1 -0
- package/dist/types/dr/recovery.d.ts +68 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/mcp-server.d.ts +40 -0
- package/dist/types/mcp-tools.d.ts +484 -0
- package/dist/types/migrations/e6-triplestore-split.d.ts +1 -0
- package/dist/types/migrations/index.d.ts +1 -0
- package/dist/types/types.d.ts +145 -0
- package/dist/types/util/datetime.d.ts +8 -0
- package/dist/types/util/env.d.ts +10 -0
- package/dist/types/util/ids.d.ts +3 -0
- package/dist/types/util/lru.d.ts +12 -0
- package/dist/types/util/regex.d.ts +10 -0
- package/package.json +82 -0
- package/src/cli.ts +390 -0
- package/src/config.ts +326 -0
- package/src/core/aaak.ts +142 -0
- package/src/core/annotations.ts +457 -0
- package/src/core/banks.ts +133 -0
- package/src/core/beam/consolidate.ts +963 -0
- package/src/core/beam/helpers.ts +920 -0
- package/src/core/beam/index.ts +353 -0
- package/src/core/beam/recall.ts +1091 -0
- package/src/core/beam/schema.ts +423 -0
- package/src/core/beam/store.ts +818 -0
- package/src/core/beam/types.ts +268 -0
- package/src/core/binary-vectors.ts +336 -0
- package/src/core/chat-normalize.ts +160 -0
- package/src/core/content-sanitizer.ts +136 -0
- package/src/core/cost-log.ts +103 -0
- package/src/core/embeddings.ts +490 -0
- package/src/core/entities.ts +259 -0
- package/src/core/episodic-graph.ts +708 -0
- package/src/core/extraction/client.ts +162 -0
- package/src/core/extraction/diagnostics.ts +193 -0
- package/src/core/extraction/prompts.ts +31 -0
- package/src/core/extraction.ts +335 -0
- package/src/core/index.ts +30 -0
- package/src/core/llm-backends.ts +51 -0
- package/src/core/local-llm.ts +436 -0
- package/src/core/memory.ts +617 -0
- package/src/core/migrations/e6-triplestore-split.ts +211 -0
- package/src/core/migrations/index.ts +1 -0
- package/src/core/mmr.ts +71 -0
- package/src/core/orchestrator.ts +53 -0
- package/src/core/patterns.ts +484 -0
- package/src/core/plugins.ts +375 -0
- package/src/core/polyphonic-recall.ts +563 -0
- package/src/core/query-cache.ts +370 -0
- package/src/core/query-intent.ts +139 -0
- package/src/core/recall-diagnostics.ts +157 -0
- package/src/core/runtime-options.ts +108 -0
- package/src/core/shmr.ts +471 -0
- package/src/core/streaming.ts +419 -0
- package/src/core/synonyms.ts +197 -0
- package/src/core/temporal-parser.ts +363 -0
- package/src/core/token-counter.ts +30 -0
- package/src/core/triples.ts +452 -0
- package/src/core/typed-memory.ts +407 -0
- package/src/core/veracity-consolidation.ts +477 -0
- package/src/core/weibull.ts +124 -0
- package/src/db.ts +128 -0
- package/src/diagnose.ts +174 -0
- package/src/dr/index.ts +1 -0
- package/src/dr/recovery.ts +405 -0
- package/src/index.ts +32 -0
- package/src/mcp-server.ts +155 -0
- package/src/mcp-tools.ts +961 -0
- package/src/migrations/e6-triplestore-split.ts +1 -0
- package/src/migrations/index.ts +1 -0
- package/src/types.ts +157 -0
- package/src/util/datetime.ts +69 -0
- package/src/util/env.ts +65 -0
- package/src/util/ids.ts +19 -0
- package/src/util/lru.ts +48 -0
- package/src/util/regex.ts +165 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
export declare const SHMR_BATCH_SIZE: number;
|
|
3
|
+
export declare const SHMR_MAX_ITERATIONS: number;
|
|
4
|
+
export declare const SHMR_SIMILARITY_THRESHOLD: number;
|
|
5
|
+
export declare const SHMR_HARMONY_THRESHOLD: number;
|
|
6
|
+
export declare const SHMR_MIN_CLUSTER_SIZE: number;
|
|
7
|
+
export declare const EMBEDDING_DIM = 384;
|
|
8
|
+
export type Vector = Float32Array;
|
|
9
|
+
export interface ShmrItem {
|
|
10
|
+
readonly fact_id?: string;
|
|
11
|
+
readonly subject?: string;
|
|
12
|
+
readonly predicate?: string;
|
|
13
|
+
readonly object?: string;
|
|
14
|
+
readonly content?: string;
|
|
15
|
+
readonly confidence?: number;
|
|
16
|
+
readonly timestamp?: string;
|
|
17
|
+
readonly source?: string;
|
|
18
|
+
readonly embedding?: Vector;
|
|
19
|
+
}
|
|
20
|
+
export interface Belief {
|
|
21
|
+
readonly subject: string;
|
|
22
|
+
readonly predicate: string;
|
|
23
|
+
readonly object: string;
|
|
24
|
+
readonly confidence: number;
|
|
25
|
+
readonly action?: "create" | "update" | "dampen";
|
|
26
|
+
readonly target_fact_id?: string | null;
|
|
27
|
+
readonly rationale?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface HarmonizeStats {
|
|
30
|
+
readonly clusters_found: number;
|
|
31
|
+
readonly beliefs_generated: number;
|
|
32
|
+
readonly contradictions_resolved: number;
|
|
33
|
+
readonly harmony_score_avg: number;
|
|
34
|
+
readonly duration_ms: number;
|
|
35
|
+
readonly status: "insufficient_candidates" | "harmonized" | "no_convergence";
|
|
36
|
+
}
|
|
37
|
+
type BeamLike = {
|
|
38
|
+
readonly conn?: Database;
|
|
39
|
+
readonly db?: Database;
|
|
40
|
+
readonly session_id?: string;
|
|
41
|
+
readonly sessionId?: string;
|
|
42
|
+
};
|
|
43
|
+
export declare const FACTS_SCHEMA_SQL = "\nCREATE TABLE IF NOT EXISTS harmonic_beliefs (\n\tbelief_id TEXT PRIMARY KEY,\n\tsubject TEXT,\n\tpredicate TEXT,\n\tobject TEXT NOT NULL,\n\tconfidence REAL DEFAULT 0.5,\n\tprovenance TEXT,\n\tcluster_id TEXT,\n\titeration INTEGER DEFAULT 0,\n\tcreated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n\tupdated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n);\nCREATE TABLE IF NOT EXISTS memory_resonance_log (\n\tid INTEGER PRIMARY KEY AUTOINCREMENT,\n\tsession_id TEXT,\n\tcluster_count INTEGER,\n\tbeliefs_generated INTEGER,\n\tcontradictions_resolved INTEGER,\n\tharmony_score_avg REAL,\n\tduration_ms INTEGER,\n\tcreated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n);\nCREATE INDEX IF NOT EXISTS idx_beliefs_subject ON harmonic_beliefs(subject);\nCREATE INDEX IF NOT EXISTS idx_beliefs_predicate ON harmonic_beliefs(predicate);\nCREATE INDEX IF NOT EXISTS idx_beliefs_confidence ON harmonic_beliefs(confidence);\n";
|
|
44
|
+
export declare function initSchema(db: Database): void;
|
|
45
|
+
export declare function embed(text: string): Vector;
|
|
46
|
+
export declare function cosineSimilarity(a: ArrayLike<number>, b: ArrayLike<number>): number;
|
|
47
|
+
export declare function clusterBySimilarity(items: readonly ShmrItem[], threshold: number): ShmrItem[][];
|
|
48
|
+
export declare function formatClusterForLlm(cluster: readonly ShmrItem[]): string;
|
|
49
|
+
export declare function extractJsonFromLlmOutput(text: string): Belief[];
|
|
50
|
+
export declare function computeHarmonyScore(beliefs: readonly Belief[], cluster: readonly ShmrItem[]): number;
|
|
51
|
+
export declare function applyBeliefs(db: Database, beliefs: readonly Belief[], cluster: readonly ShmrItem[], clusterId: string): void;
|
|
52
|
+
export declare function harmonize(beam: BeamLike, batchSize?: number, maxIterations?: number, similarityThreshold?: number): HarmonizeStats;
|
|
53
|
+
export declare function recallBeliefs(beam: BeamLike, query: string, topK?: number): Array<Record<string, unknown>>;
|
|
54
|
+
export declare function reflect(_beam: BeamLike | null, _question: string, facts?: Array<Record<string, unknown>> | null, topK?: number): string | null;
|
|
55
|
+
export declare function getResonanceLog(beam: BeamLike, limit?: number): Array<Record<string, unknown>>;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
export declare const ALLOWED_DELTA_TABLES: Set<"episodic_memory" | "working_memory">;
|
|
3
|
+
export type DeltaTable = "working_memory" | "episodic_memory";
|
|
4
|
+
export declare enum EventType {
|
|
5
|
+
MEMORY_ADDED = "MEMORY_ADDED",
|
|
6
|
+
MEMORY_RECALLED = "MEMORY_RECALLED",
|
|
7
|
+
MEMORY_INVALIDATED = "MEMORY_INVALIDATED",
|
|
8
|
+
MEMORY_CONSOLIDATED = "MEMORY_CONSOLIDATED",
|
|
9
|
+
MEMORY_UPDATED = "MEMORY_UPDATED"
|
|
10
|
+
}
|
|
11
|
+
export interface MemoryEventInit {
|
|
12
|
+
readonly eventType?: string;
|
|
13
|
+
readonly event_type?: string;
|
|
14
|
+
readonly memoryId?: string;
|
|
15
|
+
readonly memory_id?: string;
|
|
16
|
+
readonly timestamp?: string;
|
|
17
|
+
readonly sessionId?: string | null;
|
|
18
|
+
readonly session_id?: string | null;
|
|
19
|
+
readonly content?: string | null;
|
|
20
|
+
readonly source?: string | null;
|
|
21
|
+
readonly importance?: number | null;
|
|
22
|
+
readonly metadata?: Record<string, unknown> | null;
|
|
23
|
+
readonly delta?: Record<string, unknown> | null;
|
|
24
|
+
}
|
|
25
|
+
export type MemoryEventDict = {
|
|
26
|
+
event_type: string;
|
|
27
|
+
memory_id: string;
|
|
28
|
+
timestamp: string;
|
|
29
|
+
session_id?: string | null;
|
|
30
|
+
content?: string | null;
|
|
31
|
+
source?: string | null;
|
|
32
|
+
importance?: number | null;
|
|
33
|
+
metadata?: Record<string, unknown> | null;
|
|
34
|
+
delta?: Record<string, unknown> | null;
|
|
35
|
+
};
|
|
36
|
+
export declare class MemoryEvent {
|
|
37
|
+
readonly eventType: EventType;
|
|
38
|
+
readonly memoryId: string;
|
|
39
|
+
readonly timestamp: string;
|
|
40
|
+
readonly sessionId: string | null;
|
|
41
|
+
readonly content: string | null;
|
|
42
|
+
readonly source: string | null;
|
|
43
|
+
readonly importance: number | null;
|
|
44
|
+
readonly metadata: Record<string, unknown> | null;
|
|
45
|
+
readonly delta: Record<string, unknown> | null;
|
|
46
|
+
constructor(init: MemoryEventInit);
|
|
47
|
+
toDict(): MemoryEventDict;
|
|
48
|
+
toJSON(): string;
|
|
49
|
+
static fromDict(data: MemoryEventDict | MemoryEventInit): MemoryEvent;
|
|
50
|
+
}
|
|
51
|
+
export type MemoryEventHandler = (event: MemoryEvent) => void;
|
|
52
|
+
export declare class StreamIterator implements AsyncIterable<MemoryEvent>, AsyncIterator<MemoryEvent> {
|
|
53
|
+
private readonly stream;
|
|
54
|
+
private readonly eventTypes;
|
|
55
|
+
private readonly queue;
|
|
56
|
+
private readonly waiters;
|
|
57
|
+
private closed;
|
|
58
|
+
constructor(stream: MemoryStream, eventTypes?: readonly EventType[] | null);
|
|
59
|
+
push(event: MemoryEvent): void;
|
|
60
|
+
next(): Promise<IteratorResult<MemoryEvent>>;
|
|
61
|
+
return(): Promise<IteratorResult<MemoryEvent>>;
|
|
62
|
+
[Symbol.asyncIterator](): AsyncIterator<MemoryEvent>;
|
|
63
|
+
}
|
|
64
|
+
export declare class MemoryStream {
|
|
65
|
+
private readonly maxBuffer;
|
|
66
|
+
private readonly callbacks;
|
|
67
|
+
private readonly anyCallbacks;
|
|
68
|
+
private readonly buffer;
|
|
69
|
+
private readonly iterators;
|
|
70
|
+
constructor(maxBuffer?: number);
|
|
71
|
+
on(eventType: EventType, callback: MemoryEventHandler): void;
|
|
72
|
+
onAny(callback: MemoryEventHandler): void;
|
|
73
|
+
off(eventType: EventType, callback: MemoryEventHandler): void;
|
|
74
|
+
offAny(callback: MemoryEventHandler): void;
|
|
75
|
+
emit(event: MemoryEvent): void;
|
|
76
|
+
listen(eventTypes?: readonly EventType[] | null): StreamIterator;
|
|
77
|
+
removeIterator(iterator: StreamIterator): void;
|
|
78
|
+
getBuffer(eventTypes?: readonly EventType[] | null, since?: string | null): MemoryEvent[];
|
|
79
|
+
clearBuffer(): void;
|
|
80
|
+
}
|
|
81
|
+
export interface SyncCheckpointInit {
|
|
82
|
+
readonly peerId?: string;
|
|
83
|
+
readonly peer_id?: string;
|
|
84
|
+
readonly lastSyncAt?: string;
|
|
85
|
+
readonly last_sync_at?: string;
|
|
86
|
+
readonly lastRowid?: number;
|
|
87
|
+
readonly last_rowid?: number;
|
|
88
|
+
readonly checksum?: string;
|
|
89
|
+
}
|
|
90
|
+
export declare class SyncCheckpoint {
|
|
91
|
+
readonly peerId: string;
|
|
92
|
+
readonly lastSyncAt: string;
|
|
93
|
+
readonly lastRowid: number;
|
|
94
|
+
readonly checksum: string | null;
|
|
95
|
+
constructor(init: SyncCheckpointInit);
|
|
96
|
+
toDict(): Record<string, unknown>;
|
|
97
|
+
toJson(): string;
|
|
98
|
+
static fromJSON(text: string): SyncCheckpoint;
|
|
99
|
+
}
|
|
100
|
+
type MemoryHost = {
|
|
101
|
+
readonly conn?: Database;
|
|
102
|
+
readonly db?: Database;
|
|
103
|
+
readonly dbPath?: string;
|
|
104
|
+
readonly db_path?: string;
|
|
105
|
+
};
|
|
106
|
+
export declare class DeltaSync {
|
|
107
|
+
readonly mnemosyne: MemoryHost;
|
|
108
|
+
readonly checkpointDir: string;
|
|
109
|
+
private readonly db;
|
|
110
|
+
constructor(mnemosyne: MemoryHost, checkpointDir?: string);
|
|
111
|
+
private checkpointPath;
|
|
112
|
+
private legacyCheckpointPath;
|
|
113
|
+
getCheckpoint(peerId: string, table?: DeltaTable): SyncCheckpoint | null;
|
|
114
|
+
saveCheckpoint(checkpoint: SyncCheckpoint, table?: DeltaTable): void;
|
|
115
|
+
setCheckpoint(peerId: string, checkpoint: SyncCheckpoint, table?: DeltaTable): void;
|
|
116
|
+
computeDelta(peerId: string, table?: DeltaTable): Record<string, unknown>[];
|
|
117
|
+
applyDelta(peerId: string, delta: readonly Record<string, unknown>[], table?: DeltaTable): {
|
|
118
|
+
inserted: number;
|
|
119
|
+
updated: number;
|
|
120
|
+
skipped: number;
|
|
121
|
+
filtered_keys: number;
|
|
122
|
+
};
|
|
123
|
+
syncTo(peerId: string, table?: DeltaTable): {
|
|
124
|
+
delta: Record<string, unknown>[];
|
|
125
|
+
count: number;
|
|
126
|
+
};
|
|
127
|
+
syncFrom(peerId: string, delta: readonly Record<string, unknown>[], table?: DeltaTable): {
|
|
128
|
+
stats: {
|
|
129
|
+
inserted: number;
|
|
130
|
+
updated: number;
|
|
131
|
+
skipped: number;
|
|
132
|
+
filtered_keys: number;
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare const SYNONYM_GROUPS: {
|
|
2
|
+
readonly database: readonly ["db", "datastore", "data_store"];
|
|
3
|
+
readonly password: readonly ["pass", "pwd", "passwd", "credential", "secret", "token"];
|
|
4
|
+
readonly config: readonly ["configuration", "settings", "cfg", "setup"];
|
|
5
|
+
readonly error: readonly ["bug", "issue", "fault", "failure", "crash", "exception", "traceback"];
|
|
6
|
+
readonly fix: readonly ["repair", "resolve", "solve", "patch", "correct", "address"];
|
|
7
|
+
readonly deploy: readonly ["deployment", "release", "ship", "push", "rollout"];
|
|
8
|
+
readonly server: readonly ["host", "machine", "vm", "instance", "node", "vps"];
|
|
9
|
+
readonly api: readonly ["endpoint", "interface", "service"];
|
|
10
|
+
readonly key: readonly ["token", "credential", "secret", "api_key"];
|
|
11
|
+
readonly user: readonly ["account", "profile", "identity", "person"];
|
|
12
|
+
readonly model: readonly ["llm", "ai", "provider", "gpt", "claude", "gemini"];
|
|
13
|
+
readonly speed: readonly ["fast", "quick", "performance", "latency", "throughput"];
|
|
14
|
+
readonly memory: readonly ["recall", "remember", "storage", "retention"];
|
|
15
|
+
readonly search: readonly ["find", "lookup", "query", "retrieve", "locate"];
|
|
16
|
+
readonly file: readonly ["document", "doc", "text", "note"];
|
|
17
|
+
readonly code: readonly ["script", "program", "source", "implementation"];
|
|
18
|
+
readonly test: readonly ["verify", "check", "validate", "probe", "examine"];
|
|
19
|
+
readonly backup: readonly ["snapshot", "copy", "save", "archive"];
|
|
20
|
+
readonly install: readonly ["setup", "configure", "bootstrap", "init"];
|
|
21
|
+
readonly update: readonly ["upgrade", "refresh", "renew", "sync"];
|
|
22
|
+
readonly delete: readonly ["remove", "destroy", "purge", "clean", "wipe", "erase"];
|
|
23
|
+
readonly list: readonly ["show", "display", "enumerate", "catalog"];
|
|
24
|
+
readonly time: readonly ["date", "when", "timestamp", "schedule"];
|
|
25
|
+
readonly url: readonly ["link", "address", "uri", "path"];
|
|
26
|
+
readonly health: readonly ["status", "check", "pulse", "alive", "up"];
|
|
27
|
+
readonly service: readonly ["daemon", "process", "systemd", "worker"];
|
|
28
|
+
readonly port: readonly ["socket", "bind", "listen"];
|
|
29
|
+
readonly network: readonly ["internet", "connection", "connectivity", "dns"];
|
|
30
|
+
readonly ssh: readonly ["terminal", "shell", "remote", "connect"];
|
|
31
|
+
readonly git: readonly ["commit", "push", "pull", "repo", "repository", "branch"];
|
|
32
|
+
readonly log: readonly ["output", "stdout", "stderr", "trace", "debug"];
|
|
33
|
+
readonly cron: readonly ["schedule", "job", "task", "timer", "periodic"];
|
|
34
|
+
readonly email: readonly ["mail", "message", "inbox", "smtp"];
|
|
35
|
+
readonly image: readonly ["picture", "photo", "screenshot", "graphic"];
|
|
36
|
+
readonly browser: readonly ["web", "page", "site", "navigate", "chrome"];
|
|
37
|
+
readonly monitor: readonly ["watch", "observe", "track", "survey"];
|
|
38
|
+
readonly alert: readonly ["notify", "notification", "warning", "ping"];
|
|
39
|
+
readonly migrate: readonly ["transfer", "move", "relocate", "port"];
|
|
40
|
+
readonly compare: readonly ["diff", "versus", "vs", "contrast"];
|
|
41
|
+
readonly save: readonly ["store", "persist", "preserve", "keep"];
|
|
42
|
+
};
|
|
43
|
+
export declare const STOP_WORDS: Set<string>;
|
|
44
|
+
export declare function normalizeQuery(query: string): string;
|
|
45
|
+
export declare function expandQuery(query: string): string;
|
|
46
|
+
export declare function getSynonyms(word: string): string[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type QueryTime } from "../util/datetime";
|
|
2
|
+
export type DatePrecision = "day" | "week" | "month" | "year" | "relative" | "unknown";
|
|
3
|
+
export type ParsedNaturalDate = [eventDate: Date, precision: Exclude<DatePrecision, "unknown">, temporalTags: string[]];
|
|
4
|
+
export interface TemporalInfo {
|
|
5
|
+
event_date: string | null;
|
|
6
|
+
event_date_precision: DatePrecision;
|
|
7
|
+
temporal_tags: string[];
|
|
8
|
+
primary_signal: string | null;
|
|
9
|
+
}
|
|
10
|
+
export declare const DAY_MAP: Readonly<Record<string, number>>;
|
|
11
|
+
export declare const MONTH_MAP: Readonly<Record<string, number>>;
|
|
12
|
+
export declare const NAMED_TIMES: Readonly<Record<string, readonly [startHour: number, endHour: number]>>;
|
|
13
|
+
export declare function resolveRelativeDay(reference: Date, dayNameText: string, qualifier?: string): Date;
|
|
14
|
+
export declare function parseNlDate(text: string, reference?: QueryTime): ParsedNaturalDate | null;
|
|
15
|
+
export declare function extractTemporal(text: string, reference?: QueryTime): TemporalInfo;
|
|
16
|
+
export declare function extractDateFromText(text: string, reference?: QueryTime): string | null;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface CostEstimate {
|
|
2
|
+
tokens: number;
|
|
3
|
+
model: string;
|
|
4
|
+
cost_usd: number;
|
|
5
|
+
rate_per_1m: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function estimateTokens(text: string, _model?: string): number;
|
|
8
|
+
export declare function estimateCost(tokens: number, model?: string): CostEstimate;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Database } from "bun:sqlite";
|
|
2
|
+
import { type DatabasePath } from "../db";
|
|
3
|
+
export interface TripleRow {
|
|
4
|
+
id: number;
|
|
5
|
+
subject: string;
|
|
6
|
+
predicate: string;
|
|
7
|
+
object: string;
|
|
8
|
+
valid_from: string;
|
|
9
|
+
valid_until: string | null;
|
|
10
|
+
source: string | null;
|
|
11
|
+
confidence: number | null;
|
|
12
|
+
created_at: string | null;
|
|
13
|
+
}
|
|
14
|
+
export interface TripleWriteOptions {
|
|
15
|
+
readonly validFrom?: string | null;
|
|
16
|
+
readonly valid_from?: string | null;
|
|
17
|
+
readonly source?: string | null;
|
|
18
|
+
readonly confidence?: number | null;
|
|
19
|
+
}
|
|
20
|
+
export interface TripleQueryOptions {
|
|
21
|
+
readonly subject?: string | null;
|
|
22
|
+
readonly predicate?: string | null;
|
|
23
|
+
readonly object?: string | null;
|
|
24
|
+
readonly asOf?: string | null;
|
|
25
|
+
readonly as_of?: string | null;
|
|
26
|
+
}
|
|
27
|
+
export interface TripleImportStats {
|
|
28
|
+
inserted: number;
|
|
29
|
+
skipped: number;
|
|
30
|
+
overwritten: number;
|
|
31
|
+
imported_renumbered: number;
|
|
32
|
+
}
|
|
33
|
+
export type TripleImportRow = Partial<Omit<TripleRow, "id">> & {
|
|
34
|
+
readonly id?: number | null;
|
|
35
|
+
};
|
|
36
|
+
type ProcessEnv = Record<string, string | undefined>;
|
|
37
|
+
export declare function legacyDataDir(env?: ProcessEnv): string;
|
|
38
|
+
export declare function defaultDataDir(env?: ProcessEnv): string;
|
|
39
|
+
export declare function defaultTripleDbPath(env?: ProcessEnv): string;
|
|
40
|
+
export declare function legacyTripleDbPath(env?: ProcessEnv): string;
|
|
41
|
+
export declare function resolveDefaultTripleDb(env?: ProcessEnv): string;
|
|
42
|
+
export declare function initTriples(dbOrPath?: Database | DatabasePath | null): void;
|
|
43
|
+
export declare class TripleStore {
|
|
44
|
+
#private;
|
|
45
|
+
readonly dbPath: DatabasePath;
|
|
46
|
+
readonly conn: Database;
|
|
47
|
+
constructor(dbPath?: DatabasePath | Database | null);
|
|
48
|
+
close(): void;
|
|
49
|
+
add(subject: string, predicate: string, object: string, options?: TripleWriteOptions | string | null): number;
|
|
50
|
+
query(options?: TripleQueryOptions): TripleRow[];
|
|
51
|
+
query(subject?: string | null, predicate?: string | null, object?: string | null, asOf?: string | null): TripleRow[];
|
|
52
|
+
queryByPredicate(predicate: string, object?: string | null, subject?: string | null): TripleRow[];
|
|
53
|
+
getDistinctObjects(predicate: string): string[];
|
|
54
|
+
exportAll(): TripleRow[];
|
|
55
|
+
importAll(triples: readonly TripleImportRow[], force?: boolean): TripleImportStats;
|
|
56
|
+
}
|
|
57
|
+
export declare function addTriple(subject: string, predicate: string, object: string, options?: TripleWriteOptions & {
|
|
58
|
+
readonly dbPath?: DatabasePath | null;
|
|
59
|
+
}): number;
|
|
60
|
+
export declare function queryTriples(options?: TripleQueryOptions & {
|
|
61
|
+
readonly dbPath?: DatabasePath | null;
|
|
62
|
+
}): TripleRow[];
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const MemoryType: {
|
|
2
|
+
readonly FACT: "fact";
|
|
3
|
+
readonly PREFERENCE: "preference";
|
|
4
|
+
readonly DECISION: "decision";
|
|
5
|
+
readonly COMMITMENT: "commitment";
|
|
6
|
+
readonly GOAL: "goal";
|
|
7
|
+
readonly EVENT: "event";
|
|
8
|
+
readonly INSTRUCTION: "instruction";
|
|
9
|
+
readonly RELATIONSHIP: "relationship";
|
|
10
|
+
readonly CONTEXT: "context";
|
|
11
|
+
readonly LEARNING: "learning";
|
|
12
|
+
readonly OBSERVATION: "observation";
|
|
13
|
+
readonly ERROR: "error";
|
|
14
|
+
readonly ARTIFACT: "artifact";
|
|
15
|
+
readonly UNKNOWN: "unknown";
|
|
16
|
+
};
|
|
17
|
+
export type MemoryType = (typeof MemoryType)[keyof typeof MemoryType];
|
|
18
|
+
export type TypePriority = "stable" | "moderate" | "high" | "time_critical" | "decaying" | "accumulating" | "evolving" | "persistent" | "reference";
|
|
19
|
+
export interface TypeMatch {
|
|
20
|
+
memory_type: MemoryType;
|
|
21
|
+
memoryType: MemoryType;
|
|
22
|
+
confidence: number;
|
|
23
|
+
matched_pattern: string;
|
|
24
|
+
matchedPattern: string;
|
|
25
|
+
priority: TypePriority;
|
|
26
|
+
}
|
|
27
|
+
export type TypePattern = readonly [
|
|
28
|
+
pattern: string,
|
|
29
|
+
memoryType: MemoryType,
|
|
30
|
+
baseConfidence: number,
|
|
31
|
+
priority: TypePriority
|
|
32
|
+
];
|
|
33
|
+
export declare const TYPE_PATTERNS: readonly TypePattern[];
|
|
34
|
+
export declare const CONFIDENCE_BOOSTERS: Readonly<Record<MemoryType, readonly string[]>>;
|
|
35
|
+
export declare function classifyMemory(content: string): TypeMatch;
|
|
36
|
+
export declare function classifyBatch(contents: readonly string[]): TypeMatch[];
|
|
37
|
+
export declare function getTypePriority(memoryType: MemoryType | string): number;
|
|
38
|
+
export declare function shouldConsolidate(memoryType: MemoryType | string): boolean;
|
|
39
|
+
export declare function getDecayRate(memoryType: MemoryType | string): number;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
import { type DatabasePath } from "../db";
|
|
3
|
+
export declare const VERACITY_WEIGHTS: Readonly<{
|
|
4
|
+
stated: 1;
|
|
5
|
+
inferred: 0.7;
|
|
6
|
+
tool: 0.5;
|
|
7
|
+
imported: 0.6;
|
|
8
|
+
unknown: 0.8;
|
|
9
|
+
}>;
|
|
10
|
+
export type Veracity = keyof typeof VERACITY_WEIGHTS;
|
|
11
|
+
export declare const VERACITY_ALLOWED: Record<Veracity, true>;
|
|
12
|
+
export interface ConsolidatedFact {
|
|
13
|
+
readonly subject: string;
|
|
14
|
+
readonly predicate: string;
|
|
15
|
+
readonly object: string;
|
|
16
|
+
readonly confidence: number;
|
|
17
|
+
readonly mention_count: number;
|
|
18
|
+
readonly first_seen: string | null;
|
|
19
|
+
readonly last_seen: string | null;
|
|
20
|
+
readonly sources: string[];
|
|
21
|
+
readonly veracity: string;
|
|
22
|
+
readonly superseded: boolean;
|
|
23
|
+
readonly id: string | null;
|
|
24
|
+
}
|
|
25
|
+
export interface Conflict {
|
|
26
|
+
readonly id: number;
|
|
27
|
+
readonly fact_a_id: string;
|
|
28
|
+
readonly fact_b_id: string;
|
|
29
|
+
readonly type: string | null;
|
|
30
|
+
readonly created_at: string | null;
|
|
31
|
+
}
|
|
32
|
+
export interface ConsolidationStats {
|
|
33
|
+
readonly active_facts: number;
|
|
34
|
+
readonly superseded_facts: number;
|
|
35
|
+
readonly unresolved_conflicts: number;
|
|
36
|
+
readonly avg_confidence: number;
|
|
37
|
+
readonly avg_mentions: number;
|
|
38
|
+
}
|
|
39
|
+
export declare function computeFactId(subject: string, predicate: string, object: string): string;
|
|
40
|
+
export declare function clampVeracity(raw: unknown, context?: string): Veracity;
|
|
41
|
+
export declare function aggregateVeracity(sourceVeracities: readonly string[] | null | undefined): Veracity;
|
|
42
|
+
export declare class VeracityConsolidator {
|
|
43
|
+
readonly conn: Database;
|
|
44
|
+
readonly dbPath: DatabasePath;
|
|
45
|
+
readonly ownsConnection: boolean;
|
|
46
|
+
constructor(dbPath?: DatabasePath, conn?: Database);
|
|
47
|
+
initTables(): void;
|
|
48
|
+
serializedWrite<T>(body: () => T): T;
|
|
49
|
+
bayesianUpdate(currentConfidence: number, veracity: string): number;
|
|
50
|
+
consolidateFact(subject: string, predicate: string, object: string, veracity?: string, source?: string | null): ConsolidatedFact;
|
|
51
|
+
recordConflict(factAId: string, factBId: string, conflictType: string, commit?: boolean): void;
|
|
52
|
+
resolveConflict(conflictId: number, winningFactId: string): void;
|
|
53
|
+
getConflicts(): Conflict[];
|
|
54
|
+
getConsolidatedFacts(subject?: string | null, minConfidence?: number): ConsolidatedFact[];
|
|
55
|
+
getHighConfidenceSummary(subject: string, threshold?: number): string;
|
|
56
|
+
runConsolidationPass(): void;
|
|
57
|
+
resolveConflictByFacts(winningId: string, losingId: string): void;
|
|
58
|
+
getStats(): ConsolidationStats;
|
|
59
|
+
close(): void;
|
|
60
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
export type MemoryType = keyof typeof WEIBULL_PARAMS;
|
|
2
|
+
export interface WeibullParams {
|
|
3
|
+
readonly k: number;
|
|
4
|
+
readonly eta: number;
|
|
5
|
+
}
|
|
6
|
+
export declare const WEIBULL_PARAMS: {
|
|
7
|
+
readonly profile: {
|
|
8
|
+
readonly k: 0.3;
|
|
9
|
+
readonly eta: 8760;
|
|
10
|
+
};
|
|
11
|
+
readonly preference: {
|
|
12
|
+
readonly k: 0.4;
|
|
13
|
+
readonly eta: 4380;
|
|
14
|
+
};
|
|
15
|
+
readonly relationship: {
|
|
16
|
+
readonly k: 0.35;
|
|
17
|
+
readonly eta: 8760;
|
|
18
|
+
};
|
|
19
|
+
readonly learning: {
|
|
20
|
+
readonly k: 0.7;
|
|
21
|
+
readonly eta: 1440;
|
|
22
|
+
};
|
|
23
|
+
readonly fact: {
|
|
24
|
+
readonly k: 0.8;
|
|
25
|
+
readonly eta: 720;
|
|
26
|
+
};
|
|
27
|
+
readonly entity: {
|
|
28
|
+
readonly k: 0.5;
|
|
29
|
+
readonly eta: 4380;
|
|
30
|
+
};
|
|
31
|
+
readonly setup: {
|
|
32
|
+
readonly k: 0.6;
|
|
33
|
+
readonly eta: 2160;
|
|
34
|
+
};
|
|
35
|
+
readonly pattern: {
|
|
36
|
+
readonly k: 0.6;
|
|
37
|
+
readonly eta: 1680;
|
|
38
|
+
};
|
|
39
|
+
readonly context: {
|
|
40
|
+
readonly k: 0.85;
|
|
41
|
+
readonly eta: 360;
|
|
42
|
+
};
|
|
43
|
+
readonly observation: {
|
|
44
|
+
readonly k: 0.9;
|
|
45
|
+
readonly eta: 480;
|
|
46
|
+
};
|
|
47
|
+
readonly artifact: {
|
|
48
|
+
readonly k: 0.75;
|
|
49
|
+
readonly eta: 2160;
|
|
50
|
+
};
|
|
51
|
+
readonly project: {
|
|
52
|
+
readonly k: 0.85;
|
|
53
|
+
readonly eta: 1080;
|
|
54
|
+
};
|
|
55
|
+
readonly goal: {
|
|
56
|
+
readonly k: 0.9;
|
|
57
|
+
readonly eta: 720;
|
|
58
|
+
};
|
|
59
|
+
readonly decision: {
|
|
60
|
+
readonly k: 1;
|
|
61
|
+
readonly eta: 336;
|
|
62
|
+
};
|
|
63
|
+
readonly commitment: {
|
|
64
|
+
readonly k: 1;
|
|
65
|
+
readonly eta: 240;
|
|
66
|
+
};
|
|
67
|
+
readonly event: {
|
|
68
|
+
readonly k: 1.2;
|
|
69
|
+
readonly eta: 168;
|
|
70
|
+
};
|
|
71
|
+
readonly instruction: {
|
|
72
|
+
readonly k: 0.9;
|
|
73
|
+
readonly eta: 480;
|
|
74
|
+
};
|
|
75
|
+
readonly error: {
|
|
76
|
+
readonly k: 1.1;
|
|
77
|
+
readonly eta: 336;
|
|
78
|
+
};
|
|
79
|
+
readonly issue: {
|
|
80
|
+
readonly k: 1.1;
|
|
81
|
+
readonly eta: 336;
|
|
82
|
+
};
|
|
83
|
+
readonly request: {
|
|
84
|
+
readonly k: 1.5;
|
|
85
|
+
readonly eta: 72;
|
|
86
|
+
};
|
|
87
|
+
readonly general: {
|
|
88
|
+
readonly k: 1;
|
|
89
|
+
readonly eta: 168;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
export declare const DEFAULT_HALFLIFE_HOURS = 168;
|
|
93
|
+
type TimestampInput = string | Date | null | undefined;
|
|
94
|
+
export declare function weibullBoost(timestamp: TimestampInput, queryTime?: Date | null, memoryType?: string, halflifeHours?: number | null): number;
|
|
95
|
+
export declare function weibullDecayFactor(ageHours: number, memoryType?: string): number;
|
|
96
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Database } from "bun:sqlite";
|
|
2
|
+
export type DatabasePath = string | ":memory:";
|
|
3
|
+
export interface OpenDatabaseOptions {
|
|
4
|
+
readonly create?: boolean;
|
|
5
|
+
readonly readwrite?: boolean;
|
|
6
|
+
readonly strict?: boolean;
|
|
7
|
+
readonly loadExtension?: string | readonly string[];
|
|
8
|
+
readonly pragmas?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function openDatabase(path?: DatabasePath, options?: OpenDatabaseOptions): Database;
|
|
11
|
+
export declare function enablePragmas(db: Database, path?: DatabasePath): void;
|
|
12
|
+
export declare function loadExtensions(db: Database, extensions: string | readonly string[]): void;
|
|
13
|
+
export declare function transaction<T>(db: Database, fn: () => T): T;
|
|
14
|
+
export declare const deferredTransaction: typeof transaction;
|
|
15
|
+
export declare function transactionAsync<T>(db: Database, fn: () => Promise<T>): Promise<T>;
|
|
16
|
+
export declare function closeQuietly(db: Database | undefined | null): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
export interface DiagnosticEntry {
|
|
3
|
+
readonly ts: string;
|
|
4
|
+
readonly category: string;
|
|
5
|
+
readonly check: string;
|
|
6
|
+
readonly status: string;
|
|
7
|
+
readonly detail?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface DiagnosticSummary {
|
|
10
|
+
readonly checks_total: number;
|
|
11
|
+
readonly checks_passed: number;
|
|
12
|
+
readonly checks_failed: number;
|
|
13
|
+
readonly key_findings: string[];
|
|
14
|
+
readonly entries: DiagnosticEntry[];
|
|
15
|
+
readonly database: string;
|
|
16
|
+
}
|
|
17
|
+
export interface DiagnosticOptions {
|
|
18
|
+
readonly db?: Database;
|
|
19
|
+
readonly dbPath?: string;
|
|
20
|
+
readonly dataDir?: string;
|
|
21
|
+
readonly initialize?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare function inspectDatabase(options?: DiagnosticOptions): DiagnosticSummary;
|
|
24
|
+
export declare function runDiagnostics(options?: DiagnosticOptions): DiagnosticSummary;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./recovery";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type Env } from "../config";
|
|
2
|
+
export interface RecoveryPaths {
|
|
3
|
+
readonly dataDir: string;
|
|
4
|
+
readonly backupDir: string;
|
|
5
|
+
readonly dbPath: string;
|
|
6
|
+
}
|
|
7
|
+
export interface BackupMetadata {
|
|
8
|
+
readonly timestamp: string;
|
|
9
|
+
readonly original_size: number;
|
|
10
|
+
readonly backup_size: number;
|
|
11
|
+
readonly db_checksum: string;
|
|
12
|
+
readonly backup_checksum: string;
|
|
13
|
+
readonly compressed: true;
|
|
14
|
+
}
|
|
15
|
+
export interface BackupResult extends BackupMetadata {
|
|
16
|
+
readonly backup_path: string;
|
|
17
|
+
readonly metadata_path: string;
|
|
18
|
+
}
|
|
19
|
+
export interface RestoreResult {
|
|
20
|
+
readonly restored: true;
|
|
21
|
+
readonly backup_used: string;
|
|
22
|
+
readonly database_path: string;
|
|
23
|
+
readonly integrity_check: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface EmergencyRestoreResult {
|
|
26
|
+
readonly restored: true;
|
|
27
|
+
readonly backup_used: string;
|
|
28
|
+
readonly attempts: number;
|
|
29
|
+
}
|
|
30
|
+
export interface BackupInfo {
|
|
31
|
+
readonly file: string;
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly size: number;
|
|
34
|
+
readonly modified: string;
|
|
35
|
+
readonly metadata?: BackupMetadata;
|
|
36
|
+
}
|
|
37
|
+
export interface RotateBackupsResult {
|
|
38
|
+
readonly total_backups: number;
|
|
39
|
+
readonly kept: number;
|
|
40
|
+
readonly deleted: number;
|
|
41
|
+
readonly deleted_files: string[];
|
|
42
|
+
}
|
|
43
|
+
export interface HealthCheckResult {
|
|
44
|
+
readonly database: {
|
|
45
|
+
readonly exists: boolean;
|
|
46
|
+
readonly valid: boolean;
|
|
47
|
+
readonly path: string;
|
|
48
|
+
readonly message: string;
|
|
49
|
+
};
|
|
50
|
+
readonly backups: {
|
|
51
|
+
readonly total: number;
|
|
52
|
+
readonly latest: string | null;
|
|
53
|
+
readonly directory: string;
|
|
54
|
+
};
|
|
55
|
+
readonly status: "healthy" | "unhealthy";
|
|
56
|
+
}
|
|
57
|
+
export declare function getDefaultPaths(env?: Env): RecoveryPaths;
|
|
58
|
+
export declare function createBackup(dbPath?: string | null, backupDir?: string | null): BackupResult;
|
|
59
|
+
export declare function restoreBackup(backupPath: string, dbPath?: string | null): RestoreResult;
|
|
60
|
+
export declare function emergencyRestore(backupDir?: string | null, dbPath?: string | null): EmergencyRestoreResult;
|
|
61
|
+
export declare function verifyIntegrity(dbPath?: string | null): boolean;
|
|
62
|
+
export declare function listBackups(backupDir?: string | null): BackupInfo[];
|
|
63
|
+
export declare function rotateBackups(backupDir?: string | null, keep?: number): RotateBackupsResult;
|
|
64
|
+
export declare function healthCheck(): HealthCheckResult;
|
|
65
|
+
export declare class FileNotFoundError extends Error {
|
|
66
|
+
constructor(message: string);
|
|
67
|
+
}
|
|
68
|
+
export declare function resetRecoveryForTests(): void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export * from "./core/beam/index";
|
|
2
|
+
export * from "./core/embeddings";
|
|
3
|
+
export * from "./core/llm-backends";
|
|
4
|
+
export * from "./core/memory";
|
|
5
|
+
export { addMemory, flushExtractions, forget, get, getBank, getContext, getDefaultInstance, getStats, Mnemosyne, query, recall, recallEnhanced, remember, resetDefaultInstanceForTests, resetMemoryForTests, resetModuleStateForTests, saveMemory, scratchpadClear, scratchpadRead, scratchpadWrite, search, setBank, sleep, sleepAllSessions, storeMemory, update, } from "./core/memory";
|