@plur-ai/core 0.2.9 → 0.3.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 (3) hide show
  1. package/dist/index.d.ts +815 -0
  2. package/dist/index.js +176 -161
  3. package/package.json +3 -4
@@ -0,0 +1,815 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const KnowledgeAnchorSchema: z.ZodObject<{
4
+ path: z.ZodString;
5
+ relevance: z.ZodDefault<z.ZodEnum<["primary", "supporting", "example"]>>;
6
+ snippet: z.ZodOptional<z.ZodString>;
7
+ snippet_extracted_at: z.ZodOptional<z.ZodString>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ path: string;
10
+ relevance: "primary" | "supporting" | "example";
11
+ snippet?: string | undefined;
12
+ snippet_extracted_at?: string | undefined;
13
+ }, {
14
+ path: string;
15
+ relevance?: "primary" | "supporting" | "example" | undefined;
16
+ snippet?: string | undefined;
17
+ snippet_extracted_at?: string | undefined;
18
+ }>;
19
+ declare const AssociationSchema: z.ZodObject<{
20
+ target_type: z.ZodEnum<["engram", "document"]>;
21
+ target: z.ZodString;
22
+ strength: z.ZodNumber;
23
+ type: z.ZodEnum<["semantic", "temporal", "causal", "co_accessed"]>;
24
+ updated_at: z.ZodOptional<z.ZodString>;
25
+ }, "strip", z.ZodTypeAny, {
26
+ type: "semantic" | "temporal" | "causal" | "co_accessed";
27
+ target_type: "engram" | "document";
28
+ target: string;
29
+ strength: number;
30
+ updated_at?: string | undefined;
31
+ }, {
32
+ type: "semantic" | "temporal" | "causal" | "co_accessed";
33
+ target_type: "engram" | "document";
34
+ target: string;
35
+ strength: number;
36
+ updated_at?: string | undefined;
37
+ }>;
38
+ declare const EngramSchema: z.ZodObject<{
39
+ id: z.ZodString;
40
+ version: z.ZodDefault<z.ZodNumber>;
41
+ status: z.ZodEnum<["active", "dormant", "retired", "candidate"]>;
42
+ consolidated: z.ZodDefault<z.ZodBoolean>;
43
+ type: z.ZodEnum<["behavioral", "terminological", "procedural", "architectural"]>;
44
+ scope: z.ZodString;
45
+ visibility: z.ZodDefault<z.ZodEnum<["private", "public", "template"]>>;
46
+ statement: z.ZodString;
47
+ rationale: z.ZodOptional<z.ZodString>;
48
+ contraindications: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
49
+ source: z.ZodOptional<z.ZodString>;
50
+ source_patterns: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
51
+ derivation_count: z.ZodDefault<z.ZodNumber>;
52
+ pack: z.ZodDefault<z.ZodNullable<z.ZodString>>;
53
+ abstract: z.ZodDefault<z.ZodNullable<z.ZodString>>;
54
+ derived_from: z.ZodDefault<z.ZodNullable<z.ZodString>>;
55
+ knowledge_type: z.ZodOptional<z.ZodObject<{
56
+ memory_class: z.ZodEnum<["semantic", "episodic", "procedural", "metacognitive"]>;
57
+ cognitive_level: z.ZodEnum<["remember", "understand", "apply", "analyze", "evaluate", "create"]>;
58
+ }, "strip", z.ZodTypeAny, {
59
+ memory_class: "procedural" | "semantic" | "episodic" | "metacognitive";
60
+ cognitive_level: "remember" | "understand" | "apply" | "analyze" | "evaluate" | "create";
61
+ }, {
62
+ memory_class: "procedural" | "semantic" | "episodic" | "metacognitive";
63
+ cognitive_level: "remember" | "understand" | "apply" | "analyze" | "evaluate" | "create";
64
+ }>>;
65
+ domain: z.ZodOptional<z.ZodString>;
66
+ tags: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
67
+ activation: z.ZodDefault<z.ZodObject<{
68
+ retrieval_strength: z.ZodNumber;
69
+ storage_strength: z.ZodNumber;
70
+ frequency: z.ZodNumber;
71
+ last_accessed: z.ZodString;
72
+ }, "strip", z.ZodTypeAny, {
73
+ retrieval_strength: number;
74
+ storage_strength: number;
75
+ frequency: number;
76
+ last_accessed: string;
77
+ }, {
78
+ retrieval_strength: number;
79
+ storage_strength: number;
80
+ frequency: number;
81
+ last_accessed: string;
82
+ }>>;
83
+ relations: z.ZodOptional<z.ZodObject<{
84
+ broader: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
85
+ narrower: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
86
+ related: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
87
+ conflicts: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
88
+ }, "strip", z.ZodTypeAny, {
89
+ broader: string[];
90
+ narrower: string[];
91
+ related: string[];
92
+ conflicts: string[];
93
+ }, {
94
+ broader?: string[] | undefined;
95
+ narrower?: string[] | undefined;
96
+ related?: string[] | undefined;
97
+ conflicts?: string[] | undefined;
98
+ }>>;
99
+ associations: z.ZodDefault<z.ZodArray<z.ZodObject<{
100
+ target_type: z.ZodEnum<["engram", "document"]>;
101
+ target: z.ZodString;
102
+ strength: z.ZodNumber;
103
+ type: z.ZodEnum<["semantic", "temporal", "causal", "co_accessed"]>;
104
+ updated_at: z.ZodOptional<z.ZodString>;
105
+ }, "strip", z.ZodTypeAny, {
106
+ type: "semantic" | "temporal" | "causal" | "co_accessed";
107
+ target_type: "engram" | "document";
108
+ target: string;
109
+ strength: number;
110
+ updated_at?: string | undefined;
111
+ }, {
112
+ type: "semantic" | "temporal" | "causal" | "co_accessed";
113
+ target_type: "engram" | "document";
114
+ target: string;
115
+ strength: number;
116
+ updated_at?: string | undefined;
117
+ }>, "many">>;
118
+ knowledge_anchors: z.ZodDefault<z.ZodArray<z.ZodObject<{
119
+ path: z.ZodString;
120
+ relevance: z.ZodDefault<z.ZodEnum<["primary", "supporting", "example"]>>;
121
+ snippet: z.ZodOptional<z.ZodString>;
122
+ snippet_extracted_at: z.ZodOptional<z.ZodString>;
123
+ }, "strip", z.ZodTypeAny, {
124
+ path: string;
125
+ relevance: "primary" | "supporting" | "example";
126
+ snippet?: string | undefined;
127
+ snippet_extracted_at?: string | undefined;
128
+ }, {
129
+ path: string;
130
+ relevance?: "primary" | "supporting" | "example" | undefined;
131
+ snippet?: string | undefined;
132
+ snippet_extracted_at?: string | undefined;
133
+ }>, "many">>;
134
+ dual_coding: z.ZodOptional<z.ZodEffects<z.ZodObject<{
135
+ example: z.ZodOptional<z.ZodString>;
136
+ analogy: z.ZodOptional<z.ZodString>;
137
+ }, "strip", z.ZodTypeAny, {
138
+ example?: string | undefined;
139
+ analogy?: string | undefined;
140
+ }, {
141
+ example?: string | undefined;
142
+ analogy?: string | undefined;
143
+ }>, {
144
+ example?: string | undefined;
145
+ analogy?: string | undefined;
146
+ }, {
147
+ example?: string | undefined;
148
+ analogy?: string | undefined;
149
+ }>>;
150
+ provenance: z.ZodOptional<z.ZodObject<{
151
+ origin: z.ZodString;
152
+ chain: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
153
+ signature: z.ZodDefault<z.ZodNullable<z.ZodString>>;
154
+ license: z.ZodDefault<z.ZodString>;
155
+ }, "strip", z.ZodTypeAny, {
156
+ origin: string;
157
+ chain: string[];
158
+ signature: string | null;
159
+ license: string;
160
+ }, {
161
+ origin: string;
162
+ chain?: string[] | undefined;
163
+ signature?: string | null | undefined;
164
+ license?: string | undefined;
165
+ }>>;
166
+ feedback_signals: z.ZodDefault<z.ZodObject<{
167
+ positive: z.ZodDefault<z.ZodNumber>;
168
+ negative: z.ZodDefault<z.ZodNumber>;
169
+ neutral: z.ZodDefault<z.ZodNumber>;
170
+ }, "strip", z.ZodTypeAny, {
171
+ positive: number;
172
+ negative: number;
173
+ neutral: number;
174
+ }, {
175
+ positive?: number | undefined;
176
+ negative?: number | undefined;
177
+ neutral?: number | undefined;
178
+ }>>;
179
+ /** Typed entity references extracted from statement. Enables graph queries. */
180
+ entities: z.ZodOptional<z.ZodArray<z.ZodObject<{
181
+ name: z.ZodString;
182
+ type: z.ZodEnum<["person", "organization", "technology", "concept", "project", "tool", "place", "event", "standard", "other"]>;
183
+ uri: z.ZodOptional<z.ZodString>;
184
+ }, "strip", z.ZodTypeAny, {
185
+ type: "person" | "organization" | "technology" | "concept" | "project" | "tool" | "place" | "event" | "standard" | "other";
186
+ name: string;
187
+ uri?: string | undefined;
188
+ }, {
189
+ type: "person" | "organization" | "technology" | "concept" | "project" | "tool" | "place" | "event" | "standard" | "other";
190
+ name: string;
191
+ uri?: string | undefined;
192
+ }>, "many">>;
193
+ /** Temporal validity window. When is this knowledge true? */
194
+ temporal: z.ZodOptional<z.ZodObject<{
195
+ learned_at: z.ZodString;
196
+ valid_from: z.ZodOptional<z.ZodString>;
197
+ valid_until: z.ZodOptional<z.ZodString>;
198
+ ingested_at: z.ZodOptional<z.ZodString>;
199
+ }, "strip", z.ZodTypeAny, {
200
+ learned_at: string;
201
+ valid_from?: string | undefined;
202
+ valid_until?: string | undefined;
203
+ ingested_at?: string | undefined;
204
+ }, {
205
+ learned_at: string;
206
+ valid_from?: string | undefined;
207
+ valid_until?: string | undefined;
208
+ ingested_at?: string | undefined;
209
+ }>>;
210
+ /** Automatic usage tracking. Injections, hits, misses. */
211
+ usage: z.ZodOptional<z.ZodObject<{
212
+ injections: z.ZodDefault<z.ZodNumber>;
213
+ hits: z.ZodDefault<z.ZodNumber>;
214
+ misses: z.ZodDefault<z.ZodNumber>;
215
+ last_hit_at: z.ZodOptional<z.ZodString>;
216
+ }, "strip", z.ZodTypeAny, {
217
+ injections: number;
218
+ hits: number;
219
+ misses: number;
220
+ last_hit_at?: string | undefined;
221
+ }, {
222
+ injections?: number | undefined;
223
+ hits?: number | undefined;
224
+ misses?: number | undefined;
225
+ last_hit_at?: string | undefined;
226
+ }>>;
227
+ /** Episodic context: emotional weight, confidence, trigger. */
228
+ episodic: z.ZodOptional<z.ZodObject<{
229
+ emotional_weight: z.ZodDefault<z.ZodNumber>;
230
+ confidence: z.ZodDefault<z.ZodNumber>;
231
+ trigger_context: z.ZodOptional<z.ZodString>;
232
+ journal_ref: z.ZodOptional<z.ZodString>;
233
+ }, "strip", z.ZodTypeAny, {
234
+ emotional_weight: number;
235
+ confidence: number;
236
+ trigger_context?: string | undefined;
237
+ journal_ref?: string | undefined;
238
+ }, {
239
+ emotional_weight?: number | undefined;
240
+ confidence?: number | undefined;
241
+ trigger_context?: string | undefined;
242
+ journal_ref?: string | undefined;
243
+ }>>;
244
+ /** Exchange marketplace metadata: fitness, adoption, diversity. */
245
+ exchange: z.ZodOptional<z.ZodObject<{
246
+ fitness_score: z.ZodOptional<z.ZodNumber>;
247
+ environmental_diversity: z.ZodDefault<z.ZodNumber>;
248
+ adoption_count: z.ZodDefault<z.ZodNumber>;
249
+ contradiction_rate: z.ZodDefault<z.ZodNumber>;
250
+ }, "strip", z.ZodTypeAny, {
251
+ environmental_diversity: number;
252
+ adoption_count: number;
253
+ contradiction_rate: number;
254
+ fitness_score?: number | undefined;
255
+ }, {
256
+ fitness_score?: number | undefined;
257
+ environmental_diversity?: number | undefined;
258
+ adoption_count?: number | undefined;
259
+ contradiction_rate?: number | undefined;
260
+ }>>;
261
+ /** Extensible key-value data for domain-specific fields. */
262
+ structured_data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
263
+ }, "strip", z.ZodTypeAny, {
264
+ type: "behavioral" | "architectural" | "procedural" | "terminological";
265
+ status: "active" | "dormant" | "retired" | "candidate";
266
+ id: string;
267
+ version: number;
268
+ consolidated: boolean;
269
+ scope: string;
270
+ visibility: "private" | "public" | "template";
271
+ statement: string;
272
+ derivation_count: number;
273
+ pack: string | null;
274
+ abstract: string | null;
275
+ derived_from: string | null;
276
+ tags: string[];
277
+ activation: {
278
+ retrieval_strength: number;
279
+ storage_strength: number;
280
+ frequency: number;
281
+ last_accessed: string;
282
+ };
283
+ associations: {
284
+ type: "semantic" | "temporal" | "causal" | "co_accessed";
285
+ target_type: "engram" | "document";
286
+ target: string;
287
+ strength: number;
288
+ updated_at?: string | undefined;
289
+ }[];
290
+ knowledge_anchors: {
291
+ path: string;
292
+ relevance: "primary" | "supporting" | "example";
293
+ snippet?: string | undefined;
294
+ snippet_extracted_at?: string | undefined;
295
+ }[];
296
+ feedback_signals: {
297
+ positive: number;
298
+ negative: number;
299
+ neutral: number;
300
+ };
301
+ rationale?: string | undefined;
302
+ contraindications?: string[] | undefined;
303
+ source?: string | undefined;
304
+ source_patterns?: string[] | undefined;
305
+ episodic?: {
306
+ emotional_weight: number;
307
+ confidence: number;
308
+ trigger_context?: string | undefined;
309
+ journal_ref?: string | undefined;
310
+ } | undefined;
311
+ knowledge_type?: {
312
+ memory_class: "procedural" | "semantic" | "episodic" | "metacognitive";
313
+ cognitive_level: "remember" | "understand" | "apply" | "analyze" | "evaluate" | "create";
314
+ } | undefined;
315
+ domain?: string | undefined;
316
+ relations?: {
317
+ broader: string[];
318
+ narrower: string[];
319
+ related: string[];
320
+ conflicts: string[];
321
+ } | undefined;
322
+ temporal?: {
323
+ learned_at: string;
324
+ valid_from?: string | undefined;
325
+ valid_until?: string | undefined;
326
+ ingested_at?: string | undefined;
327
+ } | undefined;
328
+ dual_coding?: {
329
+ example?: string | undefined;
330
+ analogy?: string | undefined;
331
+ } | undefined;
332
+ provenance?: {
333
+ origin: string;
334
+ chain: string[];
335
+ signature: string | null;
336
+ license: string;
337
+ } | undefined;
338
+ entities?: {
339
+ type: "person" | "organization" | "technology" | "concept" | "project" | "tool" | "place" | "event" | "standard" | "other";
340
+ name: string;
341
+ uri?: string | undefined;
342
+ }[] | undefined;
343
+ usage?: {
344
+ injections: number;
345
+ hits: number;
346
+ misses: number;
347
+ last_hit_at?: string | undefined;
348
+ } | undefined;
349
+ exchange?: {
350
+ environmental_diversity: number;
351
+ adoption_count: number;
352
+ contradiction_rate: number;
353
+ fitness_score?: number | undefined;
354
+ } | undefined;
355
+ structured_data?: Record<string, unknown> | undefined;
356
+ }, {
357
+ type: "behavioral" | "architectural" | "procedural" | "terminological";
358
+ status: "active" | "dormant" | "retired" | "candidate";
359
+ id: string;
360
+ scope: string;
361
+ statement: string;
362
+ version?: number | undefined;
363
+ consolidated?: boolean | undefined;
364
+ visibility?: "private" | "public" | "template" | undefined;
365
+ rationale?: string | undefined;
366
+ contraindications?: string[] | undefined;
367
+ source?: string | undefined;
368
+ source_patterns?: string[] | undefined;
369
+ derivation_count?: number | undefined;
370
+ pack?: string | null | undefined;
371
+ abstract?: string | null | undefined;
372
+ derived_from?: string | null | undefined;
373
+ episodic?: {
374
+ emotional_weight?: number | undefined;
375
+ confidence?: number | undefined;
376
+ trigger_context?: string | undefined;
377
+ journal_ref?: string | undefined;
378
+ } | undefined;
379
+ knowledge_type?: {
380
+ memory_class: "procedural" | "semantic" | "episodic" | "metacognitive";
381
+ cognitive_level: "remember" | "understand" | "apply" | "analyze" | "evaluate" | "create";
382
+ } | undefined;
383
+ domain?: string | undefined;
384
+ tags?: string[] | undefined;
385
+ activation?: {
386
+ retrieval_strength: number;
387
+ storage_strength: number;
388
+ frequency: number;
389
+ last_accessed: string;
390
+ } | undefined;
391
+ relations?: {
392
+ broader?: string[] | undefined;
393
+ narrower?: string[] | undefined;
394
+ related?: string[] | undefined;
395
+ conflicts?: string[] | undefined;
396
+ } | undefined;
397
+ temporal?: {
398
+ learned_at: string;
399
+ valid_from?: string | undefined;
400
+ valid_until?: string | undefined;
401
+ ingested_at?: string | undefined;
402
+ } | undefined;
403
+ associations?: {
404
+ type: "semantic" | "temporal" | "causal" | "co_accessed";
405
+ target_type: "engram" | "document";
406
+ target: string;
407
+ strength: number;
408
+ updated_at?: string | undefined;
409
+ }[] | undefined;
410
+ knowledge_anchors?: {
411
+ path: string;
412
+ relevance?: "primary" | "supporting" | "example" | undefined;
413
+ snippet?: string | undefined;
414
+ snippet_extracted_at?: string | undefined;
415
+ }[] | undefined;
416
+ dual_coding?: {
417
+ example?: string | undefined;
418
+ analogy?: string | undefined;
419
+ } | undefined;
420
+ provenance?: {
421
+ origin: string;
422
+ chain?: string[] | undefined;
423
+ signature?: string | null | undefined;
424
+ license?: string | undefined;
425
+ } | undefined;
426
+ feedback_signals?: {
427
+ positive?: number | undefined;
428
+ negative?: number | undefined;
429
+ neutral?: number | undefined;
430
+ } | undefined;
431
+ entities?: {
432
+ type: "person" | "organization" | "technology" | "concept" | "project" | "tool" | "place" | "event" | "standard" | "other";
433
+ name: string;
434
+ uri?: string | undefined;
435
+ }[] | undefined;
436
+ usage?: {
437
+ injections?: number | undefined;
438
+ hits?: number | undefined;
439
+ misses?: number | undefined;
440
+ last_hit_at?: string | undefined;
441
+ } | undefined;
442
+ exchange?: {
443
+ fitness_score?: number | undefined;
444
+ environmental_diversity?: number | undefined;
445
+ adoption_count?: number | undefined;
446
+ contradiction_rate?: number | undefined;
447
+ } | undefined;
448
+ structured_data?: Record<string, unknown> | undefined;
449
+ }>;
450
+ type Engram = z.infer<typeof EngramSchema>;
451
+ type KnowledgeAnchor = z.infer<typeof KnowledgeAnchorSchema>;
452
+ type Association = z.infer<typeof AssociationSchema>;
453
+
454
+ declare const PackManifestSchema: z.ZodObject<{
455
+ name: z.ZodString;
456
+ version: z.ZodString;
457
+ description: z.ZodOptional<z.ZodString>;
458
+ creator: z.ZodOptional<z.ZodString>;
459
+ license: z.ZodDefault<z.ZodString>;
460
+ tags: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
461
+ metadata: z.ZodOptional<z.ZodObject<{
462
+ id: z.ZodOptional<z.ZodString>;
463
+ injection_policy: z.ZodDefault<z.ZodEnum<["on_match", "on_request", "always"]>>;
464
+ match_terms: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
465
+ domain: z.ZodOptional<z.ZodString>;
466
+ engram_count: z.ZodOptional<z.ZodNumber>;
467
+ }, "strip", z.ZodTypeAny, {
468
+ injection_policy: "on_match" | "on_request" | "always";
469
+ match_terms: string[];
470
+ id?: string | undefined;
471
+ domain?: string | undefined;
472
+ engram_count?: number | undefined;
473
+ }, {
474
+ id?: string | undefined;
475
+ domain?: string | undefined;
476
+ injection_policy?: "on_match" | "on_request" | "always" | undefined;
477
+ match_terms?: string[] | undefined;
478
+ engram_count?: number | undefined;
479
+ }>>;
480
+ 'x-datacore': z.ZodOptional<z.ZodObject<{
481
+ id: z.ZodString;
482
+ injection_policy: z.ZodEnum<["on_match", "on_request"]>;
483
+ match_terms: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
484
+ domain: z.ZodOptional<z.ZodString>;
485
+ engram_count: z.ZodNumber;
486
+ }, "strip", z.ZodTypeAny, {
487
+ id: string;
488
+ injection_policy: "on_match" | "on_request";
489
+ match_terms: string[];
490
+ engram_count: number;
491
+ domain?: string | undefined;
492
+ }, {
493
+ id: string;
494
+ injection_policy: "on_match" | "on_request";
495
+ engram_count: number;
496
+ domain?: string | undefined;
497
+ match_terms?: string[] | undefined;
498
+ }>>;
499
+ }, "strip", z.ZodTypeAny, {
500
+ version: string;
501
+ tags: string[];
502
+ license: string;
503
+ name: string;
504
+ description?: string | undefined;
505
+ creator?: string | undefined;
506
+ metadata?: {
507
+ injection_policy: "on_match" | "on_request" | "always";
508
+ match_terms: string[];
509
+ id?: string | undefined;
510
+ domain?: string | undefined;
511
+ engram_count?: number | undefined;
512
+ } | undefined;
513
+ 'x-datacore'?: {
514
+ id: string;
515
+ injection_policy: "on_match" | "on_request";
516
+ match_terms: string[];
517
+ engram_count: number;
518
+ domain?: string | undefined;
519
+ } | undefined;
520
+ }, {
521
+ version: string;
522
+ name: string;
523
+ tags?: string[] | undefined;
524
+ license?: string | undefined;
525
+ description?: string | undefined;
526
+ creator?: string | undefined;
527
+ metadata?: {
528
+ id?: string | undefined;
529
+ domain?: string | undefined;
530
+ injection_policy?: "on_match" | "on_request" | "always" | undefined;
531
+ match_terms?: string[] | undefined;
532
+ engram_count?: number | undefined;
533
+ } | undefined;
534
+ 'x-datacore'?: {
535
+ id: string;
536
+ injection_policy: "on_match" | "on_request";
537
+ engram_count: number;
538
+ domain?: string | undefined;
539
+ match_terms?: string[] | undefined;
540
+ } | undefined;
541
+ }>;
542
+ type PackManifest = z.infer<typeof PackManifestSchema>;
543
+
544
+ interface PackInfo {
545
+ name: string;
546
+ path: string;
547
+ engram_count: number;
548
+ manifest?: PackManifest;
549
+ }
550
+ declare function listPacks(packsDir: string): PackInfo[];
551
+
552
+ interface SyncStatus {
553
+ initialized: boolean;
554
+ remote: string | null;
555
+ dirty: boolean;
556
+ branch: string | null;
557
+ ahead: number;
558
+ behind: number;
559
+ }
560
+ interface SyncResult {
561
+ action: 'initialized' | 'committed' | 'synced' | 'up-to-date';
562
+ message: string;
563
+ remote: string | null;
564
+ files_changed: number;
565
+ }
566
+
567
+ declare const EpisodeSchema: z.ZodObject<{
568
+ id: z.ZodString;
569
+ summary: z.ZodString;
570
+ agent: z.ZodOptional<z.ZodString>;
571
+ channel: z.ZodOptional<z.ZodString>;
572
+ session_id: z.ZodOptional<z.ZodString>;
573
+ tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
574
+ timestamp: z.ZodString;
575
+ }, "strip", z.ZodTypeAny, {
576
+ id: string;
577
+ summary: string;
578
+ timestamp: string;
579
+ tags?: string[] | undefined;
580
+ agent?: string | undefined;
581
+ channel?: string | undefined;
582
+ session_id?: string | undefined;
583
+ }, {
584
+ id: string;
585
+ summary: string;
586
+ timestamp: string;
587
+ tags?: string[] | undefined;
588
+ agent?: string | undefined;
589
+ channel?: string | undefined;
590
+ session_id?: string | undefined;
591
+ }>;
592
+ type Episode = z.infer<typeof EpisodeSchema>;
593
+
594
+ declare const PlurConfigSchema: z.ZodObject<{
595
+ auto_learn: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
596
+ auto_capture: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
597
+ injection_budget: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
598
+ decay_enabled: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
599
+ decay_threshold: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
600
+ packs: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
601
+ injection: z.ZodOptional<z.ZodDefault<z.ZodObject<{
602
+ spread_cap: z.ZodDefault<z.ZodNumber>;
603
+ spread_budget: z.ZodDefault<z.ZodNumber>;
604
+ co_access: z.ZodDefault<z.ZodBoolean>;
605
+ }, "strip", z.ZodTypeAny, {
606
+ spread_cap: number;
607
+ spread_budget: number;
608
+ co_access: boolean;
609
+ }, {
610
+ spread_cap?: number | undefined;
611
+ spread_budget?: number | undefined;
612
+ co_access?: boolean | undefined;
613
+ }>>>;
614
+ }, "strip", z.ZodTypeAny, {
615
+ auto_learn?: boolean | undefined;
616
+ auto_capture?: boolean | undefined;
617
+ injection_budget?: number | undefined;
618
+ decay_enabled?: boolean | undefined;
619
+ decay_threshold?: number | undefined;
620
+ packs?: string[] | undefined;
621
+ injection?: {
622
+ spread_cap: number;
623
+ spread_budget: number;
624
+ co_access: boolean;
625
+ } | undefined;
626
+ }, {
627
+ auto_learn?: boolean | undefined;
628
+ auto_capture?: boolean | undefined;
629
+ injection_budget?: number | undefined;
630
+ decay_enabled?: boolean | undefined;
631
+ decay_threshold?: number | undefined;
632
+ packs?: string[] | undefined;
633
+ injection?: {
634
+ spread_cap?: number | undefined;
635
+ spread_budget?: number | undefined;
636
+ co_access?: boolean | undefined;
637
+ } | undefined;
638
+ }>;
639
+ type PlurConfig = z.infer<typeof PlurConfigSchema>;
640
+
641
+ interface LearnContext {
642
+ type?: 'behavioral' | 'terminological' | 'procedural' | 'architectural';
643
+ scope?: string;
644
+ domain?: string;
645
+ source?: string;
646
+ }
647
+ /**
648
+ * Function that calls an LLM. Model-agnostic — consumer provides this.
649
+ * Takes a prompt, returns the LLM's text response.
650
+ */
651
+ type LlmFunction = (prompt: string) => Promise<string>;
652
+ interface RecallOptions {
653
+ scope?: string;
654
+ domain?: string;
655
+ limit?: number;
656
+ min_strength?: number;
657
+ /** Search mode: 'fast' (BM25, default) or 'agentic' (LLM-assisted semantic search) */
658
+ mode?: 'fast' | 'agentic';
659
+ /** LLM function for agentic mode. Required when mode='agentic'. */
660
+ llm?: LlmFunction;
661
+ }
662
+ interface InjectOptions {
663
+ budget?: number;
664
+ scope?: string;
665
+ boost_recent?: boolean;
666
+ }
667
+ interface InjectionResult {
668
+ directives: string;
669
+ consider: string;
670
+ count: number;
671
+ tokens_used: number;
672
+ }
673
+ interface CaptureContext {
674
+ agent?: string;
675
+ channel?: string;
676
+ session_id?: string;
677
+ tags?: string[];
678
+ }
679
+ interface TimelineQuery {
680
+ since?: Date;
681
+ until?: Date;
682
+ agent?: string;
683
+ channel?: string;
684
+ search?: string;
685
+ }
686
+
687
+ /** Build searchable text from all engram fields */
688
+ declare function engramSearchText(engram: Engram): string;
689
+
690
+ interface PlurPaths {
691
+ root: string;
692
+ engrams: string;
693
+ episodes: string;
694
+ candidates: string;
695
+ packs: string;
696
+ exchange: string;
697
+ config: string;
698
+ }
699
+ declare function detectPlurStorage(explicitPath?: string): PlurPaths;
700
+
701
+ /**
702
+ * Non-blocking version check against npm registry.
703
+ * Caches result in memory — one fetch per process lifetime.
704
+ * Never throws or blocks startup.
705
+ */
706
+ interface VersionCheckResult {
707
+ current: string;
708
+ latest: string | null;
709
+ updateAvailable: boolean;
710
+ checkedAt: number | null;
711
+ }
712
+ /**
713
+ * Check npm for a newer version. Fetches once, caches forever (process lifetime).
714
+ * Fire-and-forget: call at startup, read later via getCachedUpdateCheck().
715
+ */
716
+ declare function checkForUpdate(packageName: string, currentVersion: string, onResult?: (result: VersionCheckResult) => void): Promise<VersionCheckResult>;
717
+ /**
718
+ * Read the cached version check result. Returns null if checkForUpdate() hasn't
719
+ * completed yet. This is the zero-cost read path for assemblers.
720
+ */
721
+ declare function getCachedUpdateCheck(packageName: string): VersionCheckResult | null;
722
+ /** Clear cache (for testing). */
723
+ declare function clearVersionCache(): void;
724
+
725
+ interface IngestOptions {
726
+ source?: string;
727
+ extract_only?: boolean;
728
+ scope?: string;
729
+ domain?: string;
730
+ }
731
+ interface IngestCandidate {
732
+ statement: string;
733
+ type: 'behavioral' | 'architectural' | 'procedural';
734
+ source?: string;
735
+ }
736
+ interface StatusResult {
737
+ engram_count: number;
738
+ episode_count: number;
739
+ pack_count: number;
740
+ storage_root: string;
741
+ config: PlurConfig;
742
+ }
743
+ declare class Plur {
744
+ private paths;
745
+ private config;
746
+ constructor(options?: {
747
+ path?: string;
748
+ });
749
+ /** Create engram, detect conflicts, save. Returns the created engram. */
750
+ learn(statement: string, context?: LearnContext): Engram;
751
+ /**
752
+ * Search engrams, filter by scope/domain/strength, reactivate accessed.
753
+ * Supports two modes:
754
+ * - 'fast' (default): BM25 keyword search, instant, no API calls
755
+ * - 'agentic': LLM-assisted semantic search, higher accuracy, requires llm function
756
+ */
757
+ /** Search engrams using fast BM25 keyword matching. Sync, no API calls. */
758
+ recall(query: string, options?: Omit<RecallOptions, 'mode' | 'llm'>): Engram[];
759
+ /** Search engrams using LLM-assisted semantic filtering. Async, requires llm function. */
760
+ recallAsync(query: string, options: RecallOptions & {
761
+ llm: LlmFunction;
762
+ }): Promise<Engram[]>;
763
+ /** Search engrams using local embeddings (transformers.js). Async, no API calls. */
764
+ recallSemantic(query: string, options?: Omit<RecallOptions, 'mode' | 'llm'>): Promise<Engram[]>;
765
+ /** Hybrid search: BM25 + embeddings merged via Reciprocal Rank Fusion. Async, no API calls. */
766
+ recallHybrid(query: string, options?: Omit<RecallOptions, 'mode' | 'llm'>): Promise<Engram[]>;
767
+ /** Expanded search: LLM query expansion + hybrid search + RRF merge. Opt-in, requires LLM function. */
768
+ recallExpanded(query: string, options: RecallOptions & {
769
+ llm: LlmFunction;
770
+ }): Promise<Engram[]>;
771
+ /** Filter engrams by scope/domain/strength (shared by both modes) */
772
+ private _filterEngrams;
773
+ /** Reactivate accessed engrams (bump retrieval strength, frequency, last_accessed) */
774
+ private _reactivateResults;
775
+ /** Scored injection within token budget (BM25 only). Returns formatted strings. */
776
+ inject(task: string, options?: InjectOptions): InjectionResult;
777
+ /** Scored injection with embedding boost when available. Falls back to BM25 if embeddings not installed. */
778
+ injectHybrid(task: string, options?: InjectOptions): Promise<InjectionResult>;
779
+ private _formatInjection;
780
+ /** Update feedback_signals and adjust retrieval_strength. */
781
+ feedback(id: string, signal: 'positive' | 'negative' | 'neutral'): void;
782
+ /** Set engram status to 'retired'. */
783
+ forget(id: string, reason?: string): void;
784
+ /** Capture an episodic memory. */
785
+ capture(summary: string, context?: CaptureContext): Episode;
786
+ /** Query the episode timeline. */
787
+ timeline(query?: TimelineQuery): Episode[];
788
+ /** Rule-based extraction of engram candidates from content. */
789
+ ingest(content: string, options?: IngestOptions): IngestCandidate[];
790
+ /** Install a pack from a source path. */
791
+ installPack(source: string): {
792
+ installed: number;
793
+ name: string;
794
+ };
795
+ /** Export engrams as a shareable pack. */
796
+ exportPack(engrams: Engram[], outputDir: string, manifest: {
797
+ name: string;
798
+ version: string;
799
+ description?: string;
800
+ creator?: string;
801
+ }): {
802
+ path: string;
803
+ engram_count: number;
804
+ };
805
+ /** List all installed packs. */
806
+ listPacks(): ReturnType<typeof listPacks>;
807
+ /** Sync engrams to git. Initializes repo on first call, commits + push/pull on subsequent calls. */
808
+ sync(remote?: string): SyncResult;
809
+ /** Get git sync status without making changes. */
810
+ syncStatus(): SyncStatus;
811
+ /** Return system health info. */
812
+ status(): StatusResult;
813
+ }
814
+
815
+ export { type Association, type CaptureContext, type Engram, type Episode, type IngestCandidate, type IngestOptions, type InjectOptions, type InjectionResult, type KnowledgeAnchor, type LearnContext, type LlmFunction, type PackManifest, Plur, type PlurConfig, type PlurPaths, type RecallOptions, type StatusResult, type SyncResult, type SyncStatus, type TimelineQuery, type VersionCheckResult, checkForUpdate, clearVersionCache, detectPlurStorage, engramSearchText, getCachedUpdateCheck };
package/dist/index.js CHANGED
@@ -158,6 +158,7 @@ var EngramSchema = z2.object({
158
158
  rationale: z2.string().optional(),
159
159
  contraindications: z2.array(z2.string()).optional(),
160
160
  // Lineage
161
+ source: z2.string().optional(),
161
162
  source_patterns: z2.array(z2.string()).optional(),
162
163
  derivation_count: z2.number().int().min(0).default(1),
163
164
  pack: z2.string().nullable().default(null),
@@ -242,6 +243,168 @@ var logger = {
242
243
  }
243
244
  };
244
245
 
246
+ // src/sync.ts
247
+ import { execFileSync } from "child_process";
248
+ import { existsSync as existsSync3, writeFileSync, renameSync, mkdirSync as mkdirSync2 } from "fs";
249
+ import { join as join2, dirname } from "path";
250
+ var GITIGNORE = `# PLUR \u2014 derived/cache files (regenerated automatically)
251
+ embeddings/
252
+ .embeddings-cache.json
253
+ *.db
254
+ *.sqlite
255
+ exchange/
256
+ `;
257
+ function git(args, cwd) {
258
+ return execFileSync("git", args, { cwd, encoding: "utf8", timeout: 3e4 }).trim();
259
+ }
260
+ function gitSafe(args, cwd) {
261
+ try {
262
+ return git(args, cwd);
263
+ } catch {
264
+ return null;
265
+ }
266
+ }
267
+ function isGitRepo(root) {
268
+ return existsSync3(join2(root, ".git"));
269
+ }
270
+ function hasGitCli() {
271
+ try {
272
+ execFileSync("git", ["--version"], { encoding: "utf8", timeout: 5e3 });
273
+ return true;
274
+ } catch {
275
+ return false;
276
+ }
277
+ }
278
+ function getRemote(root) {
279
+ return gitSafe(["remote", "get-url", "origin"], root);
280
+ }
281
+ function isDirty(root) {
282
+ const status = gitSafe(["status", "--porcelain"], root);
283
+ return status !== null && status.length > 0;
284
+ }
285
+ function countDiff(root, direction) {
286
+ const tracking = gitSafe(["rev-parse", "--abbrev-ref", "@{u}"], root);
287
+ if (!tracking) return 0;
288
+ const flag = direction === "ahead" ? "--left-only" : "--right-only";
289
+ const count = gitSafe(["rev-list", flag, "--count", "HEAD...@{u}"], root);
290
+ return count ? parseInt(count, 10) : 0;
291
+ }
292
+ function getSyncStatus(root) {
293
+ if (!isGitRepo(root)) {
294
+ return { initialized: false, remote: null, dirty: false, branch: null, ahead: 0, behind: 0 };
295
+ }
296
+ const branch = gitSafe(["rev-parse", "--abbrev-ref", "HEAD"], root);
297
+ const remote = getRemote(root);
298
+ if (remote) gitSafe(["fetch", "origin", "--quiet"], root);
299
+ return {
300
+ initialized: true,
301
+ remote,
302
+ dirty: isDirty(root),
303
+ branch,
304
+ ahead: countDiff(root, "ahead"),
305
+ behind: countDiff(root, "behind")
306
+ };
307
+ }
308
+ function initRepo(root) {
309
+ git(["init"], root);
310
+ atomicWrite(join2(root, ".gitignore"), GITIGNORE);
311
+ git(["add", "-A"], root);
312
+ git(["commit", "-m", "Initial PLUR engram store"], root);
313
+ }
314
+ function commitChanges(root) {
315
+ if (!isDirty(root)) return 0;
316
+ git(["add", "-A"], root);
317
+ const diff = gitSafe(["diff", "--cached", "--stat", "--shortstat"], root);
318
+ const now = (/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace("T", " ");
319
+ git(["commit", "-m", `plur sync ${now}`], root);
320
+ const match = diff?.match(/(\d+) file/);
321
+ return match ? parseInt(match[1], 10) : 1;
322
+ }
323
+ function hasConflictMarkers(root) {
324
+ const result = gitSafe(["grep", "-l", "<<<<<<<"], root);
325
+ return result !== null && result.length > 0;
326
+ }
327
+ function pullRebase(root) {
328
+ const result = gitSafe(["pull", "--rebase", "origin", "main"], root);
329
+ if (result !== null) return true;
330
+ gitSafe(["rebase", "--abort"], root);
331
+ const mergeResult = gitSafe(["pull", "origin", "main", "--no-edit"], root);
332
+ if (mergeResult !== null) return true;
333
+ if (hasConflictMarkers(root)) {
334
+ gitSafe(["merge", "--abort"], root);
335
+ throw new Error("Sync conflict: YAML files have merge conflicts that require manual resolution. Your local changes are preserved.");
336
+ }
337
+ git(["add", "-A"], root);
338
+ gitSafe(["commit", "-m", "plur sync: merge conflict resolved (kept both)"], root);
339
+ return true;
340
+ }
341
+ function sync(root, remote) {
342
+ if (!hasGitCli()) {
343
+ throw new Error("git is not installed. Install git to enable sync.");
344
+ }
345
+ if (!isGitRepo(root)) {
346
+ initRepo(root);
347
+ if (remote) {
348
+ git(["remote", "add", "origin", remote], root);
349
+ const branch = git(["rev-parse", "--abbrev-ref", "HEAD"], root);
350
+ git(["push", "-u", "origin", branch], root);
351
+ return { action: "initialized", message: `Initialized and pushed to ${remote}`, remote, files_changed: 0 };
352
+ }
353
+ return {
354
+ action: "initialized",
355
+ message: "Initialized local git repo. Call plur.sync with remote to enable cross-device sync.",
356
+ remote: null,
357
+ files_changed: 0
358
+ };
359
+ }
360
+ const existingRemote = getRemote(root);
361
+ if (remote && !existingRemote) {
362
+ git(["remote", "add", "origin", remote], root);
363
+ const filesChanged2 = commitChanges(root);
364
+ const branch = git(["rev-parse", "--abbrev-ref", "HEAD"], root);
365
+ git(["push", "-u", "origin", branch], root);
366
+ return { action: "synced", message: `Remote added and pushed to ${remote}`, remote, files_changed: filesChanged2 };
367
+ }
368
+ if (!existingRemote) {
369
+ const filesChanged2 = commitChanges(root);
370
+ if (filesChanged2 === 0) {
371
+ return { action: "up-to-date", message: 'No changes to commit. Add a remote with plur.sync({ remote: "..." }) to enable cross-device sync.', remote: null, files_changed: 0 };
372
+ }
373
+ return { action: "committed", message: `Committed ${filesChanged2} file(s) locally.`, remote: null, files_changed: filesChanged2 };
374
+ }
375
+ const filesChanged = commitChanges(root);
376
+ gitSafe(["fetch", "origin", "--quiet"], root);
377
+ const behind = countDiff(root, "behind");
378
+ const aheadBefore = countDiff(root, "ahead");
379
+ if (behind > 0) {
380
+ pullRebase(root);
381
+ }
382
+ const aheadAfter = countDiff(root, "ahead");
383
+ if (aheadAfter > 0) {
384
+ gitSafe(["push", "origin"], root);
385
+ }
386
+ if (filesChanged === 0 && behind === 0 && aheadBefore === 0) {
387
+ return { action: "up-to-date", message: "Already in sync.", remote: existingRemote, files_changed: 0 };
388
+ }
389
+ const parts = [];
390
+ if (filesChanged > 0) parts.push(`${filesChanged} file(s) committed`);
391
+ if (behind > 0) parts.push(`pulled ${behind} remote commit(s)`);
392
+ if (aheadAfter === 0 && aheadBefore > 0) parts.push("pushed");
393
+ return {
394
+ action: "synced",
395
+ message: `Synced. ${parts.join(", ")}.`,
396
+ remote: existingRemote,
397
+ files_changed: filesChanged
398
+ };
399
+ }
400
+ function atomicWrite(filePath, content) {
401
+ const dir = dirname(filePath);
402
+ if (!existsSync3(dir)) mkdirSync2(dir, { recursive: true });
403
+ const tmp = filePath + ".tmp";
404
+ writeFileSync(tmp, content);
405
+ renameSync(tmp, filePath);
406
+ }
407
+
245
408
  // src/engrams.ts
246
409
  function loadEngrams(filePath) {
247
410
  if (!fs.existsSync(filePath)) return [];
@@ -264,7 +427,7 @@ function loadEngrams(filePath) {
264
427
  }
265
428
  function saveEngrams(filePath, engrams) {
266
429
  const content = yaml2.dump({ engrams }, { lineWidth: 120, noRefs: true, quotingType: '"' });
267
- fs.writeFileSync(filePath, content);
430
+ atomicWrite(filePath, content);
268
431
  }
269
432
  function parseSkillMdFrontmatter(filePath) {
270
433
  const content = fs.readFileSync(filePath, "utf8");
@@ -635,7 +798,7 @@ function selectAndSpread(ctx, personalEngrams, packs, config, embeddingBoosts) {
635
798
  }
636
799
 
637
800
  // src/episodes.ts
638
- import { existsSync as existsSync4, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
801
+ import { existsSync as existsSync5, readFileSync as readFileSync3 } from "fs";
639
802
  import yaml3 from "js-yaml";
640
803
  function generateEpisodeId() {
641
804
  const ts = Date.now();
@@ -654,7 +817,7 @@ function captureEpisode(path2, summary, context) {
654
817
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
655
818
  };
656
819
  episodes.push(episode);
657
- writeFileSync2(path2, yaml3.dump(episodes, { lineWidth: 120, noRefs: true }), "utf8");
820
+ atomicWrite(path2, yaml3.dump(episodes, { lineWidth: 120, noRefs: true }));
658
821
  return episode;
659
822
  }
660
823
  function queryTimeline(path2, query) {
@@ -670,7 +833,7 @@ function queryTimeline(path2, query) {
670
833
  return episodes;
671
834
  }
672
835
  function loadEpisodes(path2) {
673
- if (!existsSync4(path2)) return [];
836
+ if (!existsSync5(path2)) return [];
674
837
  try {
675
838
  const raw = yaml3.load(readFileSync3(path2, "utf8"));
676
839
  return Array.isArray(raw) ? raw : [];
@@ -743,8 +906,9 @@ Rules:
743
906
  }
744
907
 
745
908
  // src/embeddings.ts
746
- import { existsSync as existsSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync3, mkdirSync as mkdirSync2 } from "fs";
747
- import { join as join2 } from "path";
909
+ import { existsSync as existsSync6, readFileSync as readFileSync4, mkdirSync as mkdirSync3 } from "fs";
910
+ import { join as join3 } from "path";
911
+ import { createHash } from "crypto";
748
912
  var embedPipeline = null;
749
913
  var transformersUnavailable = false;
750
914
  async function getEmbedder() {
@@ -774,7 +938,7 @@ function cosineSimilarity(a, b) {
774
938
  return dot;
775
939
  }
776
940
  function loadCache(cachePath) {
777
- if (!existsSync5(cachePath)) return {};
941
+ if (!existsSync6(cachePath)) return {};
778
942
  try {
779
943
  return JSON.parse(readFileSync4(cachePath, "utf8"));
780
944
  } catch {
@@ -783,19 +947,15 @@ function loadCache(cachePath) {
783
947
  }
784
948
  function saveCache(cachePath, cache2) {
785
949
  const dir = cachePath.substring(0, cachePath.lastIndexOf("/"));
786
- if (!existsSync5(dir)) mkdirSync2(dir, { recursive: true });
787
- writeFileSync3(cachePath, JSON.stringify(cache2));
950
+ if (!existsSync6(dir)) mkdirSync3(dir, { recursive: true });
951
+ atomicWrite(cachePath, JSON.stringify(cache2));
788
952
  }
789
953
  function hashStatement(statement) {
790
- let hash = 0;
791
- for (let i = 0; i < statement.length; i++) {
792
- hash = (hash << 5) - hash + statement.charCodeAt(i) | 0;
793
- }
794
- return hash.toString(36);
954
+ return createHash("sha256").update(statement).digest("hex").slice(0, 16);
795
955
  }
796
956
  async function embeddingSearch(engrams, query, limit, storagePath) {
797
957
  if (engrams.length === 0) return [];
798
- const cachePath = storagePath ? join2(storagePath, ".embeddings-cache.json") : ".embeddings-cache.json";
958
+ const cachePath = storagePath ? join3(storagePath, ".embeddings-cache.json") : ".embeddings-cache.json";
799
959
  const cache2 = loadCache(cachePath);
800
960
  const queryEmbedding = await embed(query);
801
961
  if (!queryEmbedding) {
@@ -1023,152 +1183,6 @@ ${manifest.description || ""}
1023
1183
  return { path: outputDir, engram_count: engrams.length };
1024
1184
  }
1025
1185
 
1026
- // src/sync.ts
1027
- import { execSync } from "child_process";
1028
- import { existsSync as existsSync7, writeFileSync as writeFileSync5 } from "fs";
1029
- import { join as join4 } from "path";
1030
- var GITIGNORE = `# PLUR \u2014 derived/cache files (regenerated automatically)
1031
- embeddings/
1032
- *.db
1033
- *.sqlite
1034
- exchange/
1035
- `;
1036
- function git(args, cwd) {
1037
- return execSync(`git ${args}`, { cwd, encoding: "utf8", timeout: 3e4 }).trim();
1038
- }
1039
- function gitSafe(args, cwd) {
1040
- try {
1041
- return git(args, cwd);
1042
- } catch {
1043
- return null;
1044
- }
1045
- }
1046
- function isGitRepo(root) {
1047
- return existsSync7(join4(root, ".git"));
1048
- }
1049
- function hasGitCli() {
1050
- try {
1051
- execSync("git --version", { encoding: "utf8", timeout: 5e3 });
1052
- return true;
1053
- } catch {
1054
- return false;
1055
- }
1056
- }
1057
- function getRemote(root) {
1058
- return gitSafe("remote get-url origin", root);
1059
- }
1060
- function isDirty(root) {
1061
- const status = gitSafe("status --porcelain", root);
1062
- return status !== null && status.length > 0;
1063
- }
1064
- function countDiff(root, direction) {
1065
- const tracking = gitSafe("rev-parse --abbrev-ref @{u}", root);
1066
- if (!tracking) return 0;
1067
- const flag = direction === "ahead" ? "left" : "right";
1068
- const count = gitSafe(`rev-list --${flag}-only --count HEAD...@{u}`, root);
1069
- return count ? parseInt(count, 10) : 0;
1070
- }
1071
- function getSyncStatus(root) {
1072
- if (!isGitRepo(root)) {
1073
- return { initialized: false, remote: null, dirty: false, branch: null, ahead: 0, behind: 0 };
1074
- }
1075
- const branch = gitSafe("rev-parse --abbrev-ref HEAD", root);
1076
- const remote = getRemote(root);
1077
- if (remote) gitSafe("fetch origin --quiet", root);
1078
- return {
1079
- initialized: true,
1080
- remote,
1081
- dirty: isDirty(root),
1082
- branch,
1083
- ahead: countDiff(root, "ahead"),
1084
- behind: countDiff(root, "behind")
1085
- };
1086
- }
1087
- function initRepo(root) {
1088
- git("init", root);
1089
- writeFileSync5(join4(root, ".gitignore"), GITIGNORE);
1090
- git("add -A", root);
1091
- git('commit -m "Initial PLUR engram store"', root);
1092
- }
1093
- function commitChanges(root) {
1094
- if (!isDirty(root)) return 0;
1095
- git("add -A", root);
1096
- const diff = gitSafe("diff --cached --stat --shortstat", root);
1097
- const now = (/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace("T", " ");
1098
- git(`commit -m "plur sync ${now}"`, root);
1099
- const match = diff?.match(/(\d+) file/);
1100
- return match ? parseInt(match[1], 10) : 1;
1101
- }
1102
- function pullRebase(root) {
1103
- const result = gitSafe("pull --rebase origin main", root);
1104
- if (result !== null) return true;
1105
- gitSafe("rebase --abort", root);
1106
- const mergeResult = gitSafe("pull origin main --no-edit", root);
1107
- if (mergeResult !== null) return true;
1108
- git("add -A", root);
1109
- gitSafe('commit -m "plur sync: merge conflict resolved (kept both)"', root);
1110
- return true;
1111
- }
1112
- function sync(root, remote) {
1113
- if (!hasGitCli()) {
1114
- throw new Error("git is not installed. Install git to enable sync.");
1115
- }
1116
- if (!isGitRepo(root)) {
1117
- initRepo(root);
1118
- if (remote) {
1119
- git(`remote add origin ${remote}`, root);
1120
- const branch = git("rev-parse --abbrev-ref HEAD", root);
1121
- git(`push -u origin ${branch}`, root);
1122
- return { action: "initialized", message: `Initialized and pushed to ${remote}`, remote, files_changed: 0 };
1123
- }
1124
- return {
1125
- action: "initialized",
1126
- message: "Initialized local git repo. Call plur.sync with remote to enable cross-device sync.",
1127
- remote: null,
1128
- files_changed: 0
1129
- };
1130
- }
1131
- const existingRemote = getRemote(root);
1132
- if (remote && !existingRemote) {
1133
- git(`remote add origin ${remote}`, root);
1134
- const filesChanged2 = commitChanges(root);
1135
- const branch = git("rev-parse --abbrev-ref HEAD", root);
1136
- git(`push -u origin ${branch}`, root);
1137
- return { action: "synced", message: `Remote added and pushed to ${remote}`, remote, files_changed: filesChanged2 };
1138
- }
1139
- if (!existingRemote) {
1140
- const filesChanged2 = commitChanges(root);
1141
- if (filesChanged2 === 0) {
1142
- return { action: "up-to-date", message: 'No changes to commit. Add a remote with plur.sync({ remote: "..." }) to enable cross-device sync.', remote: null, files_changed: 0 };
1143
- }
1144
- return { action: "committed", message: `Committed ${filesChanged2} file(s) locally.`, remote: null, files_changed: filesChanged2 };
1145
- }
1146
- const filesChanged = commitChanges(root);
1147
- gitSafe("fetch origin --quiet", root);
1148
- const behind = countDiff(root, "behind");
1149
- const aheadBefore = countDiff(root, "ahead");
1150
- if (behind > 0) {
1151
- pullRebase(root);
1152
- }
1153
- const aheadAfter = countDiff(root, "ahead");
1154
- if (aheadAfter > 0) {
1155
- gitSafe("push origin", root);
1156
- }
1157
- if (filesChanged === 0 && behind === 0 && aheadBefore === 0) {
1158
- return { action: "up-to-date", message: "Already in sync.", remote: existingRemote, files_changed: 0 };
1159
- }
1160
- const parts = [];
1161
- if (filesChanged > 0) parts.push(`${filesChanged} file(s) committed`);
1162
- if (behind > 0) parts.push(`pulled ${behind} remote commit(s)`);
1163
- if (aheadAfter === 0 && aheadBefore > 0) parts.push("pushed");
1164
- return {
1165
- action: "synced",
1166
- message: `Synced. ${parts.join(", ")}.`,
1167
- remote: existingRemote,
1168
- files_changed: filesChanged
1169
- };
1170
- }
1171
-
1172
1186
  // src/version-check.ts
1173
1187
  var cache = /* @__PURE__ */ new Map();
1174
1188
  async function checkForUpdate(packageName, currentVersion, onResult) {
@@ -1252,6 +1266,7 @@ var Plur = class {
1252
1266
  scope,
1253
1267
  visibility: "private",
1254
1268
  statement,
1269
+ source: context?.source,
1255
1270
  domain: context?.domain,
1256
1271
  activation: {
1257
1272
  retrieval_strength: 0.7,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plur-ai/core",
3
- "version": "0.2.9",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -38,9 +38,8 @@
38
38
  "author": "PLUR <info@plur.ai>",
39
39
  "exports": {
40
40
  ".": {
41
- "import": "./dist/index.js",
42
- "require": "./dist/index.js",
43
- "types": "./dist/index.d.ts"
41
+ "types": "./dist/index.d.ts",
42
+ "import": "./dist/index.js"
44
43
  }
45
44
  },
46
45
  "scripts": {