@generacy-ai/knowledge-store 0.0.0-preview-20260304013206

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 (90) hide show
  1. package/LICENSE +191 -0
  2. package/dist/index.d.ts +47 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +50 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/manager/ContextManager.d.ts +54 -0
  7. package/dist/manager/ContextManager.d.ts.map +1 -0
  8. package/dist/manager/ContextManager.js +124 -0
  9. package/dist/manager/ContextManager.js.map +1 -0
  10. package/dist/manager/KnowledgeStoreManager.d.ts +128 -0
  11. package/dist/manager/KnowledgeStoreManager.d.ts.map +1 -0
  12. package/dist/manager/KnowledgeStoreManager.js +332 -0
  13. package/dist/manager/KnowledgeStoreManager.js.map +1 -0
  14. package/dist/manager/PatternManager.d.ts +72 -0
  15. package/dist/manager/PatternManager.d.ts.map +1 -0
  16. package/dist/manager/PatternManager.js +187 -0
  17. package/dist/manager/PatternManager.js.map +1 -0
  18. package/dist/manager/PhilosophyManager.d.ts +37 -0
  19. package/dist/manager/PhilosophyManager.d.ts.map +1 -0
  20. package/dist/manager/PhilosophyManager.js +82 -0
  21. package/dist/manager/PhilosophyManager.js.map +1 -0
  22. package/dist/manager/PrincipleManager.d.ts +74 -0
  23. package/dist/manager/PrincipleManager.d.ts.map +1 -0
  24. package/dist/manager/PrincipleManager.js +159 -0
  25. package/dist/manager/PrincipleManager.js.map +1 -0
  26. package/dist/portability/Exporter.d.ts +14 -0
  27. package/dist/portability/Exporter.d.ts.map +1 -0
  28. package/dist/portability/Exporter.js +48 -0
  29. package/dist/portability/Exporter.js.map +1 -0
  30. package/dist/portability/Importer.d.ts +18 -0
  31. package/dist/portability/Importer.d.ts.map +1 -0
  32. package/dist/portability/Importer.js +192 -0
  33. package/dist/portability/Importer.js.map +1 -0
  34. package/dist/portability/redaction.d.ts +22 -0
  35. package/dist/portability/redaction.d.ts.map +1 -0
  36. package/dist/portability/redaction.js +128 -0
  37. package/dist/portability/redaction.js.map +1 -0
  38. package/dist/storage/AuditableStorage.d.ts +44 -0
  39. package/dist/storage/AuditableStorage.d.ts.map +1 -0
  40. package/dist/storage/AuditableStorage.js +109 -0
  41. package/dist/storage/AuditableStorage.js.map +1 -0
  42. package/dist/storage/LocalFileStorage.d.ts +63 -0
  43. package/dist/storage/LocalFileStorage.d.ts.map +1 -0
  44. package/dist/storage/LocalFileStorage.js +219 -0
  45. package/dist/storage/LocalFileStorage.js.map +1 -0
  46. package/dist/storage/StorageProvider.d.ts +28 -0
  47. package/dist/storage/StorageProvider.d.ts.map +1 -0
  48. package/dist/storage/StorageProvider.js +38 -0
  49. package/dist/storage/StorageProvider.js.map +1 -0
  50. package/dist/storage/VersionedStorage.d.ts +61 -0
  51. package/dist/storage/VersionedStorage.d.ts.map +1 -0
  52. package/dist/storage/VersionedStorage.js +102 -0
  53. package/dist/storage/VersionedStorage.js.map +1 -0
  54. package/dist/types/index.d.ts +7 -0
  55. package/dist/types/index.d.ts.map +1 -0
  56. package/dist/types/index.js +5 -0
  57. package/dist/types/index.js.map +1 -0
  58. package/dist/types/knowledge.d.ts +149 -0
  59. package/dist/types/knowledge.d.ts.map +1 -0
  60. package/dist/types/knowledge.js +6 -0
  61. package/dist/types/knowledge.js.map +1 -0
  62. package/dist/types/portability.d.ts +85 -0
  63. package/dist/types/portability.d.ts.map +1 -0
  64. package/dist/types/portability.js +6 -0
  65. package/dist/types/portability.js.map +1 -0
  66. package/dist/types/storage.d.ts +58 -0
  67. package/dist/types/storage.d.ts.map +1 -0
  68. package/dist/types/storage.js +6 -0
  69. package/dist/types/storage.js.map +1 -0
  70. package/dist/utils/id.d.ts +6 -0
  71. package/dist/utils/id.d.ts.map +1 -0
  72. package/dist/utils/id.js +9 -0
  73. package/dist/utils/id.js.map +1 -0
  74. package/dist/utils/index.d.ts +3 -0
  75. package/dist/utils/index.d.ts.map +1 -0
  76. package/dist/utils/index.js +3 -0
  77. package/dist/utils/index.js.map +1 -0
  78. package/dist/utils/timestamps.d.ts +6 -0
  79. package/dist/utils/timestamps.d.ts.map +1 -0
  80. package/dist/utils/timestamps.js +8 -0
  81. package/dist/utils/timestamps.js.map +1 -0
  82. package/dist/validation/schemas.d.ts +917 -0
  83. package/dist/validation/schemas.d.ts.map +1 -0
  84. package/dist/validation/schemas.js +143 -0
  85. package/dist/validation/schemas.js.map +1 -0
  86. package/dist/validation/validator.d.ts +29 -0
  87. package/dist/validation/validator.d.ts.map +1 -0
  88. package/dist/validation/validator.js +54 -0
  89. package/dist/validation/validator.js.map +1 -0
  90. package/package.json +49 -0
@@ -0,0 +1,332 @@
1
+ /**
2
+ * KnowledgeStoreManager - Facade for all knowledge operations
3
+ */
4
+ import { LocalFileStorage } from '../storage/LocalFileStorage.js';
5
+ import { VersionedStorage } from '../storage/VersionedStorage.js';
6
+ import { exportKnowledge as exportKnowledgeFn } from '../portability/Exporter.js';
7
+ import { importKnowledge as importKnowledgeFn, applyImport } from '../portability/Importer.js';
8
+ import { PhilosophyManager } from './PhilosophyManager.js';
9
+ import { PrincipleManager } from './PrincipleManager.js';
10
+ import { PatternManager } from './PatternManager.js';
11
+ import { ContextManager } from './ContextManager.js';
12
+ import { now } from '../utils/timestamps.js';
13
+ /**
14
+ * Default configuration
15
+ */
16
+ const DEFAULT_CONFIG = {
17
+ baseDir: '.generacy/knowledge',
18
+ maxVersions: 50,
19
+ enableAudit: true,
20
+ };
21
+ /**
22
+ * Main facade for all knowledge store operations
23
+ */
24
+ export class KnowledgeStoreManager {
25
+ config;
26
+ storage;
27
+ philosophyManager;
28
+ principleManager;
29
+ patternManager;
30
+ contextManager;
31
+ constructor(config = {}) {
32
+ this.config = { ...DEFAULT_CONFIG, ...config };
33
+ const baseStorage = new LocalFileStorage(this.config.baseDir);
34
+ this.storage = new VersionedStorage(baseStorage, {
35
+ maxVersions: this.config.maxVersions,
36
+ });
37
+ this.philosophyManager = new PhilosophyManager(this.storage);
38
+ this.principleManager = new PrincipleManager(this.storage);
39
+ this.patternManager = new PatternManager(this.storage);
40
+ this.contextManager = new ContextManager(this.storage);
41
+ // Wire up pattern manager to principle manager for promotion
42
+ this.patternManager.setPrincipleManager(this.principleManager);
43
+ }
44
+ // ==================== Aggregation ====================
45
+ /**
46
+ * Get complete knowledge for a user
47
+ */
48
+ async getKnowledge(userId) {
49
+ const [philosophy, principles, patterns, context] = await Promise.all([
50
+ this.philosophyManager.get(userId),
51
+ this.principleManager.get(userId),
52
+ this.patternManager.get(userId),
53
+ this.contextManager.get(userId),
54
+ ]);
55
+ return {
56
+ userId,
57
+ philosophy,
58
+ principles,
59
+ patterns,
60
+ context,
61
+ metadata: {
62
+ createdAt: now(),
63
+ updatedAt: now(),
64
+ version: 1,
65
+ },
66
+ };
67
+ }
68
+ // ==================== Philosophy Operations ====================
69
+ /**
70
+ * Get a user's philosophy
71
+ */
72
+ async getPhilosophy(userId) {
73
+ return this.philosophyManager.get(userId);
74
+ }
75
+ /**
76
+ * Update a user's philosophy
77
+ */
78
+ async updatePhilosophy(userId, update) {
79
+ return this.philosophyManager.update(userId, update);
80
+ }
81
+ // ==================== Principle Operations ====================
82
+ /**
83
+ * Get principles for a user, optionally filtered by domains
84
+ */
85
+ async getPrinciples(userId, domains) {
86
+ return this.principleManager.get(userId, domains);
87
+ }
88
+ /**
89
+ * Add a new principle
90
+ */
91
+ async addPrinciple(userId, principle) {
92
+ return this.principleManager.add(userId, principle);
93
+ }
94
+ /**
95
+ * Update a principle
96
+ */
97
+ async updatePrinciple(userId, principleId, update) {
98
+ return this.principleManager.update(userId, principleId, update);
99
+ }
100
+ /**
101
+ * Deprecate a principle
102
+ */
103
+ async deprecatePrinciple(userId, principleId, reason) {
104
+ return this.principleManager.deprecate(userId, principleId, reason);
105
+ }
106
+ // ==================== Pattern Operations ====================
107
+ /**
108
+ * Get patterns for a user, optionally filtered by status
109
+ */
110
+ async getPatterns(userId, status) {
111
+ return this.patternManager.get(userId, status);
112
+ }
113
+ /**
114
+ * Add a new pattern
115
+ */
116
+ async addPattern(userId, pattern) {
117
+ return this.patternManager.add(userId, pattern);
118
+ }
119
+ /**
120
+ * Promote a pattern to a principle
121
+ */
122
+ async promoteToAnciple(userId, patternId) {
123
+ return this.patternManager.promoteToAnciple(userId, patternId);
124
+ }
125
+ // ==================== Context Operations ====================
126
+ /**
127
+ * Get a user's context
128
+ */
129
+ async getContext(userId) {
130
+ return this.contextManager.get(userId);
131
+ }
132
+ /**
133
+ * Update a user's context
134
+ */
135
+ async updateContext(userId, update) {
136
+ return this.contextManager.update(userId, update);
137
+ }
138
+ // ==================== Versioning ====================
139
+ /**
140
+ * Get version history for all stores
141
+ */
142
+ async getHistory(userId, store) {
143
+ if (store === 'philosophy') {
144
+ return this.philosophyManager.getHistory(userId);
145
+ }
146
+ if (store === 'principles') {
147
+ return this.principleManager.getHistory(userId);
148
+ }
149
+ if (store === 'patterns') {
150
+ // Patterns don't have versioning by default, return empty
151
+ return [];
152
+ }
153
+ // Return all histories
154
+ const [philosophy, principles] = await Promise.all([
155
+ this.philosophyManager.getHistory(userId),
156
+ this.principleManager.getHistory(userId),
157
+ ]);
158
+ return {
159
+ philosophy,
160
+ principles,
161
+ patterns: [],
162
+ };
163
+ }
164
+ /**
165
+ * Revert a store to a specific version
166
+ */
167
+ async revertTo(userId, store, version) {
168
+ if (store === 'philosophy') {
169
+ return this.philosophyManager.revertTo(userId, version);
170
+ }
171
+ throw new Error(`Revert not supported for store: ${store}`);
172
+ }
173
+ // ==================== Portability ====================
174
+ /**
175
+ * Export knowledge at specified portability level
176
+ */
177
+ async exportKnowledge(userId, level) {
178
+ const [philosophy, principles, patterns, context] = await Promise.all([
179
+ this.philosophyManager.get(userId),
180
+ this.principleManager.get(userId),
181
+ this.patternManager.get(userId),
182
+ this.contextManager.get(userId),
183
+ ]);
184
+ return exportKnowledgeFn(philosophy, principles, patterns, context, level);
185
+ }
186
+ /**
187
+ * Import knowledge with merge strategy
188
+ */
189
+ async importKnowledge(userId, data) {
190
+ const [existingPrinciples, existingPatterns, existingPhilosophy] = await Promise.all([
191
+ this.principleManager.get(userId),
192
+ this.patternManager.get(userId),
193
+ this.philosophyManager.get(userId),
194
+ ]);
195
+ const result = importKnowledgeFn(existingPrinciples, existingPatterns, existingPhilosophy, data);
196
+ // If import was successful or has only auto-resolved conflicts, apply changes
197
+ if (result.success || result.conflicts.every((c) => c.autoResolved)) {
198
+ const { principles, patterns } = applyImport(data, result);
199
+ // Add new principles
200
+ for (const principle of principles) {
201
+ // Use internal storage to avoid validation (already validated during export)
202
+ const key = `${userId}/principles`;
203
+ const existing = await this.principleManager.get(userId);
204
+ existing.push(principle);
205
+ await this.storage.set(key, existing);
206
+ }
207
+ // Add new patterns
208
+ for (const pattern of patterns) {
209
+ const key = `${userId}/patterns`;
210
+ const existing = await this.patternManager.get(userId);
211
+ existing.push(pattern);
212
+ await this.storage.set(key, existing);
213
+ }
214
+ // Import philosophy if indicated
215
+ if (result.imported.philosophy && data.philosophy) {
216
+ await this.philosophyManager.update(userId, data.philosophy);
217
+ }
218
+ }
219
+ return result;
220
+ }
221
+ // ==================== Integrity ====================
222
+ /**
223
+ * Validate integrity of a user's knowledge store
224
+ */
225
+ async validateIntegrity(userId) {
226
+ const issues = [];
227
+ const [philosophy, principles, patterns] = await Promise.all([
228
+ this.philosophyManager.get(userId),
229
+ this.principleManager.get(userId),
230
+ this.patternManager.get(userId),
231
+ ]);
232
+ // Check for duplicate principle IDs
233
+ const principleIds = new Set();
234
+ for (const p of principles) {
235
+ if (principleIds.has(p.id)) {
236
+ issues.push(`Duplicate principle ID: ${p.id}`);
237
+ }
238
+ principleIds.add(p.id);
239
+ }
240
+ // Check for duplicate pattern IDs
241
+ const patternIds = new Set();
242
+ for (const p of patterns) {
243
+ if (patternIds.has(p.id)) {
244
+ issues.push(`Duplicate pattern ID: ${p.id}`);
245
+ }
246
+ patternIds.add(p.id);
247
+ }
248
+ // Check promoted patterns reference valid principles
249
+ for (const pattern of patterns) {
250
+ if (pattern.status === 'promoted' && pattern.promotedTo) {
251
+ if (!principleIds.has(pattern.promotedTo)) {
252
+ issues.push(`Pattern ${pattern.id} references non-existent principle ${pattern.promotedTo}`);
253
+ }
254
+ }
255
+ }
256
+ // Check value priorities are unique
257
+ const priorities = new Set();
258
+ for (const value of philosophy.values) {
259
+ if (priorities.has(value.priority)) {
260
+ issues.push(`Duplicate value priority: ${value.priority}`);
261
+ }
262
+ priorities.add(value.priority);
263
+ }
264
+ return {
265
+ valid: issues.length === 0,
266
+ issues,
267
+ };
268
+ }
269
+ /**
270
+ * Detect circular or conflicting principles
271
+ */
272
+ async detectCircularConflicts(userId) {
273
+ const principles = await this.principleManager.get(userId);
274
+ const conflicts = [];
275
+ // Simple heuristic: principles with opposite keywords
276
+ const oppositePatterns = [
277
+ ['always', 'never'],
278
+ ['all', 'none'],
279
+ ['must', 'must not'],
280
+ ['should', 'should not'],
281
+ ];
282
+ for (let i = 0; i < principles.length; i++) {
283
+ const p1 = principles[i];
284
+ for (let j = i + 1; j < principles.length; j++) {
285
+ const p2 = principles[j];
286
+ // Check if they share domains
287
+ const sharedDomains = p1.domain.filter((d) => p2.domain.includes(d));
288
+ if (sharedDomains.length === 0)
289
+ continue;
290
+ // Check for opposite patterns
291
+ const content1 = p1.content.toLowerCase();
292
+ const content2 = p2.content.toLowerCase();
293
+ for (const pair of oppositePatterns) {
294
+ const word1 = pair[0];
295
+ const word2 = pair[1];
296
+ if ((content1.includes(word1) && content2.includes(word2)) ||
297
+ (content1.includes(word2) && content2.includes(word1))) {
298
+ conflicts.push({
299
+ principle1: p1.id,
300
+ principle2: p2.id,
301
+ reason: `Potentially conflicting guidance in domain: ${sharedDomains.join(', ')}`,
302
+ });
303
+ break;
304
+ }
305
+ }
306
+ }
307
+ }
308
+ return {
309
+ hasConflicts: conflicts.length > 0,
310
+ conflicts,
311
+ };
312
+ }
313
+ // ==================== Internal Access ====================
314
+ /**
315
+ * Get the underlying storage provider (for testing)
316
+ */
317
+ getStorage() {
318
+ return this.storage;
319
+ }
320
+ /**
321
+ * Get individual managers (for advanced usage)
322
+ */
323
+ getManagers() {
324
+ return {
325
+ philosophy: this.philosophyManager,
326
+ principles: this.principleManager,
327
+ patterns: this.patternManager,
328
+ context: this.contextManager,
329
+ };
330
+ }
331
+ }
332
+ //# sourceMappingURL=KnowledgeStoreManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KnowledgeStoreManager.js","sourceRoot":"","sources":["../../src/manager/KnowledgeStoreManager.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,eAAe,IAAI,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAClF,OAAO,EAAE,eAAe,IAAI,iBAAiB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC/F,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAA8C,MAAM,uBAAuB,CAAC;AACrG,OAAO,EAAE,cAAc,EAAsB,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAE7C;;GAEG;AACH,MAAM,cAAc,GAAmC;IACrD,OAAO,EAAE,qBAAqB;IAC9B,WAAW,EAAE,EAAE;IACf,WAAW,EAAE,IAAI;CAClB,CAAC;AAWF;;GAEG;AACH,MAAM,OAAO,qBAAqB;IACf,MAAM,CAAiC;IACvC,OAAO,CAAmB;IAC1B,iBAAiB,CAAoB;IACrC,gBAAgB,CAAmB;IACnC,cAAc,CAAiB;IAC/B,cAAc,CAAiB;IAEhD,YAAY,SAA+B,EAAE;QAC3C,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,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AS;SACV,CAAC;IACJ,CAAC;IAED,4DAA4D;IAE5D;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,iBAAiB;YAClC,UAAU,EAAE,IAAI,CAAC,gBAAgB;YACjC,QAAQ,EAAE,IAAI,CAAC,cAAc;YAC7B,OAAO,EAAE,IAAI,CAAC,cAAc;SAC7B,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * PatternManager - Manages pattern CRUD operations with status filtering and promotion
3
+ */
4
+ import type { Pattern, PatternStatus, PatternOccurrence } from '../types/knowledge.js';
5
+ import type { StorageProvider } from '../types/storage.js';
6
+ import type { PrincipleManager } from './PrincipleManager.js';
7
+ /**
8
+ * Input for creating a new pattern
9
+ */
10
+ export interface CreatePatternInput {
11
+ description: string;
12
+ domain: string[];
13
+ occurrences?: PatternOccurrence[];
14
+ }
15
+ /**
16
+ * Input for updating a pattern
17
+ */
18
+ export interface UpdatePatternInput {
19
+ description?: string;
20
+ domain?: string[];
21
+ status?: PatternStatus;
22
+ }
23
+ /**
24
+ * Manages patterns storage and retrieval with filtering and promotion
25
+ */
26
+ export declare class PatternManager {
27
+ private readonly storage;
28
+ private principleManager?;
29
+ constructor(storage: StorageProvider);
30
+ /**
31
+ * Set the principle manager for pattern promotion
32
+ */
33
+ setPrincipleManager(manager: PrincipleManager): void;
34
+ /**
35
+ * Get the storage key for a user's patterns
36
+ */
37
+ private getKey;
38
+ /**
39
+ * Get all patterns for a user, optionally filtered by status
40
+ */
41
+ get(userId: string, status?: PatternStatus): Promise<Pattern[]>;
42
+ /**
43
+ * Get a specific pattern by ID
44
+ */
45
+ getById(userId: string, patternId: string): Promise<Pattern | null>;
46
+ /**
47
+ * Add a new pattern
48
+ */
49
+ add(userId: string, input: CreatePatternInput): Promise<string>;
50
+ /**
51
+ * Update an existing pattern
52
+ */
53
+ update(userId: string, patternId: string, update: UpdatePatternInput): Promise<void>;
54
+ /**
55
+ * Add an occurrence to a pattern
56
+ */
57
+ addOccurrence(userId: string, patternId: string, occurrence: Omit<PatternOccurrence, 'timestamp'>): Promise<void>;
58
+ /**
59
+ * Promote a pattern to a principle
60
+ * Returns the new principle ID
61
+ */
62
+ promoteToAnciple(userId: string, patternId: string): Promise<string>;
63
+ /**
64
+ * Reject a pattern
65
+ */
66
+ reject(userId: string, patternId: string): Promise<void>;
67
+ /**
68
+ * Delete a pattern (hard delete)
69
+ */
70
+ delete(userId: string, patternId: string): Promise<void>;
71
+ }
72
+ //# sourceMappingURL=PatternManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PatternManager.d.ts","sourceRoot":"","sources":["../../src/manager/PatternManager.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACvF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAI3D,OAAO,KAAK,EAAE,gBAAgB,EAAwB,MAAM,uBAAuB,CAAC;AAEpF;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,CAAC,EAAE,iBAAiB,EAAE,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,OAAO,CAAC,gBAAgB,CAAC,CAAmB;gBAEhC,OAAO,EAAE,eAAe;IAIpC;;OAEG;IACH,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAIpD;;OAEG;IACH,OAAO,CAAC,MAAM;IAId;;OAEG;IACG,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAerE;;OAEG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAKzE;;OAEG;IACG,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IA0BrE;;OAEG;IACG,MAAM,CACV,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,IAAI,CAAC;IA2BhB;;OAEG;IACG,aAAa,CACjB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,IAAI,CAAC,iBAAiB,EAAE,WAAW,CAAC,GAC/C,OAAO,CAAC,IAAI,CAAC;IA6BhB;;;OAGG;IACG,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAgD1E;;OAEG;IACG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9D;;OAEG;IACG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAW/D"}
@@ -0,0 +1,187 @@
1
+ /**
2
+ * PatternManager - Manages pattern CRUD operations with status filtering and promotion
3
+ */
4
+ import { validatePattern } from '../validation/validator.js';
5
+ import { generateId } from '../utils/id.js';
6
+ import { now } from '../utils/timestamps.js';
7
+ /**
8
+ * Manages patterns storage and retrieval with filtering and promotion
9
+ */
10
+ export class PatternManager {
11
+ storage;
12
+ principleManager;
13
+ constructor(storage) {
14
+ this.storage = storage;
15
+ }
16
+ /**
17
+ * Set the principle manager for pattern promotion
18
+ */
19
+ setPrincipleManager(manager) {
20
+ this.principleManager = manager;
21
+ }
22
+ /**
23
+ * Get the storage key for a user's patterns
24
+ */
25
+ getKey(userId) {
26
+ return `${userId}/patterns`;
27
+ }
28
+ /**
29
+ * Get all patterns for a user, optionally filtered by status
30
+ */
31
+ async get(userId, status) {
32
+ const key = this.getKey(userId);
33
+ const patterns = await this.storage.get(key);
34
+ if (!patterns) {
35
+ return [];
36
+ }
37
+ if (!status) {
38
+ return patterns;
39
+ }
40
+ return patterns.filter((p) => p.status === status);
41
+ }
42
+ /**
43
+ * Get a specific pattern by ID
44
+ */
45
+ async getById(userId, patternId) {
46
+ const patterns = await this.get(userId);
47
+ return patterns.find((p) => p.id === patternId) ?? null;
48
+ }
49
+ /**
50
+ * Add a new pattern
51
+ */
52
+ async add(userId, input) {
53
+ const key = this.getKey(userId);
54
+ const patterns = await this.get(userId);
55
+ const timestamp = now();
56
+ const pattern = {
57
+ id: generateId(),
58
+ description: input.description,
59
+ occurrences: input.occurrences ?? [],
60
+ status: 'emerging',
61
+ domain: input.domain,
62
+ firstSeen: timestamp,
63
+ lastSeen: timestamp,
64
+ };
65
+ const validation = validatePattern(pattern);
66
+ if (!validation.success) {
67
+ throw new Error(`Invalid pattern: ${validation.errors?.join(', ')}`);
68
+ }
69
+ patterns.push(pattern);
70
+ await this.storage.set(key, patterns);
71
+ return pattern.id;
72
+ }
73
+ /**
74
+ * Update an existing pattern
75
+ */
76
+ async update(userId, patternId, update) {
77
+ const key = this.getKey(userId);
78
+ const patterns = await this.get(userId);
79
+ const index = patterns.findIndex((p) => p.id === patternId);
80
+ if (index === -1) {
81
+ throw new Error(`Pattern not found: ${patternId}`);
82
+ }
83
+ const current = patterns[index];
84
+ const updated = {
85
+ ...current,
86
+ description: update.description ?? current.description,
87
+ domain: update.domain ?? current.domain,
88
+ status: update.status ?? current.status,
89
+ lastSeen: now(),
90
+ };
91
+ const validation = validatePattern(updated);
92
+ if (!validation.success) {
93
+ throw new Error(`Invalid pattern: ${validation.errors?.join(', ')}`);
94
+ }
95
+ patterns[index] = updated;
96
+ await this.storage.set(key, patterns);
97
+ }
98
+ /**
99
+ * Add an occurrence to a pattern
100
+ */
101
+ async addOccurrence(userId, patternId, occurrence) {
102
+ const key = this.getKey(userId);
103
+ const patterns = await this.get(userId);
104
+ const index = patterns.findIndex((p) => p.id === patternId);
105
+ if (index === -1) {
106
+ throw new Error(`Pattern not found: ${patternId}`);
107
+ }
108
+ const current = patterns[index];
109
+ const timestamp = now();
110
+ patterns[index] = {
111
+ ...current,
112
+ occurrences: [
113
+ ...current.occurrences,
114
+ { ...occurrence, timestamp },
115
+ ],
116
+ lastSeen: timestamp,
117
+ // Auto-promote to established if enough occurrences
118
+ status: current.status === 'emerging' && current.occurrences.length >= 2
119
+ ? 'established'
120
+ : current.status,
121
+ };
122
+ await this.storage.set(key, patterns);
123
+ }
124
+ /**
125
+ * Promote a pattern to a principle
126
+ * Returns the new principle ID
127
+ */
128
+ async promoteToAnciple(userId, patternId) {
129
+ if (!this.principleManager) {
130
+ throw new Error('PrincipleManager not set. Call setPrincipleManager first.');
131
+ }
132
+ const pattern = await this.getById(userId, patternId);
133
+ if (!pattern) {
134
+ throw new Error(`Pattern not found: ${patternId}`);
135
+ }
136
+ if (pattern.status === 'promoted') {
137
+ throw new Error(`Pattern already promoted: ${patternId}`);
138
+ }
139
+ // Create principle from pattern
140
+ const principleInput = {
141
+ content: pattern.description,
142
+ domain: pattern.domain,
143
+ weight: 0.6, // Start with moderate weight
144
+ evidence: pattern.occurrences.map((o) => ({
145
+ decision: o.decision,
146
+ context: o.context,
147
+ timestamp: o.timestamp,
148
+ })),
149
+ status: 'draft',
150
+ source: `Promoted from pattern ${patternId}`,
151
+ };
152
+ const principleId = await this.principleManager.add(userId, principleInput);
153
+ // Update pattern status
154
+ const key = this.getKey(userId);
155
+ const patterns = await this.get(userId);
156
+ const index = patterns.findIndex((p) => p.id === patternId);
157
+ if (index !== -1) {
158
+ patterns[index] = {
159
+ ...patterns[index],
160
+ status: 'promoted',
161
+ promotedTo: principleId,
162
+ lastSeen: now(),
163
+ };
164
+ await this.storage.set(key, patterns);
165
+ }
166
+ return principleId;
167
+ }
168
+ /**
169
+ * Reject a pattern
170
+ */
171
+ async reject(userId, patternId) {
172
+ await this.update(userId, patternId, { status: 'rejected' });
173
+ }
174
+ /**
175
+ * Delete a pattern (hard delete)
176
+ */
177
+ async delete(userId, patternId) {
178
+ const key = this.getKey(userId);
179
+ const patterns = await this.get(userId);
180
+ const filtered = patterns.filter((p) => p.id !== patternId);
181
+ if (filtered.length === patterns.length) {
182
+ throw new Error(`Pattern not found: ${patternId}`);
183
+ }
184
+ await this.storage.set(key, filtered);
185
+ }
186
+ }
187
+ //# sourceMappingURL=PatternManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PatternManager.js","sourceRoot":"","sources":["../../src/manager/PatternManager.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAqB7C;;GAEG;AACH,MAAM,OAAO,cAAc;IACR,OAAO,CAAkB;IAClC,gBAAgB,CAAoB;IAE5C,YAAY,OAAwB;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,mBAAmB,CAAC,OAAyB;QAC3C,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC;IAClC,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,MAAc;QAC3B,OAAO,GAAG,MAAM,WAAW,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CAAC,MAAc,EAAE,MAAsB;QAC9C,MAAM,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2
+ * PhilosophyManager - Manages philosophy operations with versioning
3
+ */
4
+ import type { Philosophy } from '../types/knowledge.js';
5
+ import type { StorageProvider, VersionInfo } from '../types/storage.js';
6
+ /**
7
+ * Manages philosophy storage and retrieval with versioning support
8
+ */
9
+ export declare class PhilosophyManager {
10
+ private readonly storage;
11
+ constructor(storage: StorageProvider);
12
+ /**
13
+ * Get the storage key for a user's philosophy
14
+ */
15
+ private getKey;
16
+ /**
17
+ * Get a user's philosophy
18
+ */
19
+ get(userId: string): Promise<Philosophy>;
20
+ /**
21
+ * Update a user's philosophy (partial update supported)
22
+ */
23
+ update(userId: string, update: Partial<Philosophy>): Promise<void>;
24
+ /**
25
+ * Get philosophy history (versions)
26
+ */
27
+ getHistory(userId: string): Promise<VersionInfo[]>;
28
+ /**
29
+ * Get a specific version of philosophy
30
+ */
31
+ getVersion(userId: string, version: number): Promise<Philosophy | null>;
32
+ /**
33
+ * Revert philosophy to a specific version
34
+ */
35
+ revertTo(userId: string, version: number): Promise<void>;
36
+ }
37
+ //# sourceMappingURL=PhilosophyManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PhilosophyManager.d.ts","sourceRoot":"","sources":["../../src/manager/PhilosophyManager.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAcxE;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;gBAE9B,OAAO,EAAE,eAAe;IAIpC;;OAEG;IACH,OAAO,CAAC,MAAM;IAId;;OAEG;IACG,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAM9C;;OAEG;IACG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBxE;;OAEG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAKxD;;OAEG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAK7E;;OAEG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAU/D"}