synapse-causal-memory 0.0.0-stage → 0.2.3

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.
@@ -0,0 +1,273 @@
1
+ /**
2
+ * 인과율 트리거 규격
3
+ */
4
+ export interface CausalTrigger {
5
+ readonly files?: readonly string[];
6
+ readonly keywords?: readonly string[];
7
+ readonly commands?: readonly string[];
8
+ readonly alwaysActive?: boolean;
9
+ }
10
+ /**
11
+ * 인과율 간선(Relation) 규격
12
+ */
13
+ export interface CausalRelation {
14
+ readonly from: string;
15
+ readonly to: string;
16
+ readonly relationType: string;
17
+ }
18
+ /**
19
+ * 인과율 규칙(Node) 규격
20
+ */
21
+ export interface CausalRule {
22
+ readonly id: string;
23
+ readonly domain: string;
24
+ readonly title: string;
25
+ readonly entityType?: string;
26
+ readonly triggers: CausalTrigger;
27
+ readonly invariants: readonly string[];
28
+ readonly actions: readonly string[];
29
+ readonly context: readonly string[];
30
+ readonly lastVerified?: string;
31
+ }
32
+ /**
33
+ * 인과율 메모리 데이터베이스 규격
34
+ */
35
+ export interface CausalMemoryDatabase {
36
+ readonly version: string;
37
+ readonly updatedAt: string;
38
+ readonly totalRules: number;
39
+ readonly totalRelations: number;
40
+ readonly rules: readonly CausalRule[];
41
+ readonly relations: readonly CausalRelation[];
42
+ }
43
+ /**
44
+ * 공명 쿼리 입력 규격
45
+ */
46
+ export interface CausalQueryOptions {
47
+ readonly files?: readonly string[];
48
+ readonly keywords?: readonly string[];
49
+ readonly command?: string;
50
+ readonly domain?: string;
51
+ readonly propagateRelations?: boolean;
52
+ readonly maxHops?: number;
53
+ }
54
+ /**
55
+ * 공명 쿼리 결과 규격
56
+ */
57
+ export interface CausalResonanceResult {
58
+ readonly queryDurationMs: number;
59
+ readonly matchedCount: number;
60
+ readonly totalDatabaseRules: number;
61
+ readonly resonanceRules: readonly CausalRule[];
62
+ readonly activeRelations: readonly CausalRelation[];
63
+ readonly tokenDietSavingsRatio: string;
64
+ }
65
+ /**
66
+ * 구형 memory MCP 호환 엔티티 규격
67
+ */
68
+ export interface LegacyEntityInput {
69
+ readonly name: string;
70
+ readonly entityType: string;
71
+ readonly observations: readonly string[];
72
+ }
73
+ /**
74
+ * 인과율 메모리 저장소 및 O(1) 역인덱스 공명 엔진 클래스 (SRP 및 OCP 준수)
75
+ */
76
+ export declare class CausalMemoryStore {
77
+ private readonly dbPath;
78
+ private database;
79
+ private lastMtimeMs;
80
+ private alwaysActiveRules;
81
+ private domainIndex;
82
+ private commandIndex;
83
+ private exactKeywordIndex;
84
+ private exactFileIndex;
85
+ private prefixFileRules;
86
+ private compiledSearchRules;
87
+ private titleToRuleMap;
88
+ private idToRuleMap;
89
+ private relationAdjacency;
90
+ constructor(customPath?: string, initialDatabase?: CausalMemoryDatabase);
91
+ /**
92
+ * 디스크 파일 변경(mtimeMs)이 감지된 경우에만 스마트 리로드 수행 (Zero-Copy Cache)
93
+ */
94
+ reloadIfNeeded(): boolean;
95
+ /**
96
+ * 강제 디스크 리로드
97
+ */
98
+ reload(): void;
99
+ /**
100
+ * 인메모리 데이터베이스 직접 주입 (벤치마크 및 인메모리 시뮬레이션용)
101
+ */
102
+ loadFromMemory(db: CausalMemoryDatabase): void;
103
+ /**
104
+ * O(1) 역인덱스(Inverted Index) 및 인접 리스트 그래프(Adjacency List) 재구축
105
+ */
106
+ private rebuildIndices;
107
+ /**
108
+ * 동일 제목(title) 규칙 중복 시 도메인 우선순위 점수 산출
109
+ */
110
+ private static getRuleDomainPriority;
111
+ /**
112
+ * 규칙 배열에서 동일 제목(title) 중복 제거 및 정규화
113
+ */
114
+ private static deduplicateRulesByTitle;
115
+ /**
116
+ * 데이터베이스 로드
117
+ */
118
+ private loadDatabase;
119
+ /**
120
+ * 데이터베이스 디스크 동기화
121
+ */
122
+ private saveDatabase;
123
+ getAllRules(): readonly CausalRule[];
124
+ getAllRelations(): readonly CausalRelation[];
125
+ getStatus(): {
126
+ version: string;
127
+ updatedAt: string;
128
+ totalRules: number;
129
+ totalRelations: number;
130
+ dbPath: string;
131
+ domains: string[];
132
+ domainCounts: Record<string, number>;
133
+ };
134
+ /**
135
+ * 부분 문자열 폴백 검색을 위한 지연 컴파일러 (Lazy Compilation)
136
+ */
137
+ private getCompiledSearchRules;
138
+ /**
139
+ * 초고속 O(1) 역인덱스 및 다중 홉(Multi-Hop) 그래프 전파 공명 쿼리 엔진
140
+ */
141
+ queryResonance(options: CausalQueryOptions): CausalResonanceResult;
142
+ /**
143
+ * 신규 규칙 등록 또는 기존 규칙 갱신
144
+ */
145
+ assertRule(rule: CausalRule, persistToDisk?: boolean): void;
146
+ /**
147
+ * 구형 memory MCP 호환: read_graph 대체 (초경량 인과 공명 요약 반환)
148
+ */
149
+ readSmartGraph(files?: readonly string[]): {
150
+ causalMemoryEngine: string;
151
+ tokenDietSavings: string;
152
+ queryDurationMs: number;
153
+ activeEntitiesCount: number;
154
+ totalIndexedRules: number;
155
+ totalIndexedRelations: number;
156
+ availableDomains: Record<string, number>;
157
+ hint: string;
158
+ entities: {
159
+ name: string;
160
+ entityType: string;
161
+ domain: string;
162
+ invariants: readonly string[];
163
+ actions: readonly string[];
164
+ observations: string[];
165
+ }[];
166
+ relations: readonly CausalRelation[];
167
+ };
168
+ /**
169
+ * 구형 memory MCP 호환: search_nodes
170
+ */
171
+ searchNodes(query: string): {
172
+ causalMemoryEngine: string;
173
+ tokenDietSavings: string;
174
+ queryDurationMs: number;
175
+ activeEntitiesCount: number;
176
+ totalIndexedRules: number;
177
+ totalIndexedRelations: number;
178
+ availableDomains: Record<string, number>;
179
+ hint: string;
180
+ entities: {
181
+ name: string;
182
+ entityType: string;
183
+ domain: string;
184
+ invariants: readonly string[];
185
+ actions: readonly string[];
186
+ observations: string[];
187
+ }[];
188
+ relations: readonly CausalRelation[];
189
+ } | {
190
+ entities: {
191
+ name: string;
192
+ entityType: string;
193
+ observations: string[];
194
+ }[];
195
+ relations: CausalRelation[];
196
+ };
197
+ /**
198
+ * 구형 memory MCP 호환: open_nodes
199
+ */
200
+ openNodes(names: readonly string[]): {
201
+ entities: {
202
+ name: string;
203
+ entityType: string;
204
+ observations: string[];
205
+ }[];
206
+ relations: CausalRelation[];
207
+ };
208
+ /**
209
+ * 구형 memory MCP 호환: create_entities
210
+ */
211
+ createEntities(entities: readonly LegacyEntityInput[], persistToDisk?: boolean): LegacyEntityInput[];
212
+ /**
213
+ * 구형 memory MCP 호환: add_observations
214
+ */
215
+ addObservations(observations: readonly {
216
+ readonly entityName: string;
217
+ readonly contents: readonly string[];
218
+ }[], persistToDisk?: boolean): {
219
+ entityName: string;
220
+ addedObservations: string[];
221
+ }[];
222
+ /**
223
+ * 구형 memory MCP 호환: create_relations
224
+ */
225
+ createRelations(relations: readonly CausalRelation[], persistToDisk?: boolean): CausalRelation[];
226
+ /**
227
+ * 단일 인과 규칙 삭제 (연결된 고아 인과 간선 동시 정리)
228
+ */
229
+ deleteRule(ruleId: string, persistToDisk?: boolean): boolean;
230
+ /**
231
+ * 구형 memory MCP 호환: delete_entities
232
+ */
233
+ deleteEntities(entityNames: readonly string[], persistToDisk?: boolean): void;
234
+ /**
235
+ * 구형 memory MCP 호환: delete_observations
236
+ */
237
+ deleteObservations(deletions: readonly {
238
+ readonly entityName: string;
239
+ readonly observations: readonly string[];
240
+ }[], persistToDisk?: boolean): void;
241
+ /**
242
+ * 구형 memory MCP 호환: delete_relations
243
+ */
244
+ deleteRelations(relations: readonly CausalRelation[], persistToDisk?: boolean): void;
245
+ /**
246
+ * 엔티티 입력으로부터 도메인 및 인과율 규칙 자동 추론
247
+ */
248
+ static inferRuleFromEntity(ent: LegacyEntityInput, today: string): CausalRule;
249
+ /**
250
+ * 메모리 무결성 감사 (Audit)
251
+ */
252
+ audit(): {
253
+ ok: boolean;
254
+ totalRules: number;
255
+ totalRelations: number;
256
+ alwaysActiveCount: number;
257
+ issues: string[];
258
+ };
259
+ /**
260
+ * 원시 데이터베이스 객체 반환 (백업 및 피어 동기화용)
261
+ */
262
+ getRawDatabase(): CausalMemoryDatabase;
263
+ /**
264
+ * 원격 피어 데이터베이스와 로컬 데이터베이스 양방향 무손실 병합 (Sync)
265
+ */
266
+ mergeDatabase(incomingRules: readonly CausalRule[], incomingRelations?: readonly CausalRelation[]): {
267
+ addedRules: number;
268
+ updatedRules: number;
269
+ addedRelations: number;
270
+ totalRules: number;
271
+ totalRelations: number;
272
+ };
273
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env bun
2
+ export interface MemoryCliOptions {
3
+ lang?: string;
4
+ compact?: boolean;
5
+ agent?: boolean;
6
+ agentMode?: boolean;
7
+ force?: boolean;
8
+ [key: string]: unknown;
9
+ }
10
+ /**
11
+ * synapse memory CLI 명령어 핸들러
12
+ */
13
+ export declare function handleMemoryCommand(args: readonly string[], options?: MemoryCliOptions): Promise<number>;