noormme 1.1.0 → 1.2.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 +84 -65
- package/dist/cjs/agentic/ActionJournal.js +13 -9
- package/dist/cjs/agentic/CapabilityManager.js +35 -21
- package/dist/cjs/agentic/CognitiveRepository.js +19 -9
- package/dist/cjs/agentic/ContextBuffer.js +24 -12
- package/dist/cjs/agentic/Cortex.js +11 -4
- package/dist/cjs/agentic/EpisodicMemory.js +7 -5
- package/dist/cjs/agentic/PersonaManager.js +16 -8
- package/dist/cjs/agentic/PolicyEnforcer.js +31 -12
- package/dist/cjs/agentic/ResourceMonitor.js +4 -4
- package/dist/cjs/agentic/SessionCompressor.js +22 -14
- package/dist/cjs/agentic/SessionManager.js +36 -18
- package/dist/cjs/agentic/VectorIndexer.js +22 -18
- package/dist/cjs/agentic/improvement/AblationEngine.js +22 -15
- package/dist/cjs/agentic/improvement/ActionRefiner.js +12 -10
- package/dist/cjs/agentic/improvement/ConflictResolver.js +5 -5
- package/dist/cjs/agentic/improvement/CortexJanitor.js +30 -9
- package/dist/cjs/agentic/improvement/CuriosityEngine.js +27 -23
- package/dist/cjs/agentic/improvement/EvolutionRitual.js +4 -4
- package/dist/cjs/agentic/improvement/EvolutionaryPilot.js +16 -6
- package/dist/cjs/agentic/improvement/GoalArchitect.d.ts +2 -2
- package/dist/cjs/agentic/improvement/GoalArchitect.js +20 -18
- package/dist/cjs/agentic/improvement/GovernanceManager.js +19 -11
- package/dist/cjs/agentic/improvement/HiveLink.js +22 -15
- package/dist/cjs/agentic/improvement/KnowledgeDistiller.js +48 -32
- package/dist/cjs/agentic/improvement/RecursiveReasoner.js +40 -17
- package/dist/cjs/agentic/improvement/ReflectionEngine.js +10 -8
- package/dist/cjs/agentic/improvement/RitualOrchestrator.js +28 -22
- package/dist/cjs/agentic/improvement/RuleEngine.js +22 -17
- package/dist/cjs/agentic/improvement/SelfEvolution.js +24 -18
- package/dist/cjs/agentic/improvement/SelfTestRegistry.js +18 -15
- package/dist/cjs/agentic/improvement/SkillSynthesizer.js +42 -27
- package/dist/cjs/agentic/improvement/SovereignMetrics.js +19 -17
- package/dist/cjs/agentic/improvement/StrategicPlanner.js +120 -55
- package/dist/cjs/agentic/telemetry/CognitiveSynthesizer.js +26 -12
- package/dist/cjs/agentic/telemetry/EventHarvester.js +3 -2
- package/dist/cjs/agentic/telemetry/ResearchAlchemist.js +5 -2
- package/dist/cjs/cache/cache-manager.js +7 -4
- package/dist/cjs/cli/commands/analyze.js +5 -4
- package/dist/cjs/cli/commands/generate.js +81 -44
- package/dist/cjs/cli/commands/init.js +7 -3
- package/dist/cjs/cli/commands/inspect.js +139 -36
- package/dist/cjs/cli/commands/migrate.js +5 -4
- package/dist/cjs/cli/commands/optimize.js +4 -4
- package/dist/cjs/cli/commands/status.js +9 -7
- package/dist/cjs/cli/commands/watch.js +7 -6
- package/dist/cjs/cli/index.js +2 -2
- package/dist/cjs/cli/ui/spinner.d.ts +15 -0
- package/dist/cjs/cli/ui/spinner.js +76 -0
- package/dist/cjs/dialect/database-introspector.js +3 -1
- package/dist/cjs/dialect/postgresql/postgresql-driver.js +3 -1
- package/dist/cjs/dialect/postgresql/postgresql-features.js +18 -8
- package/dist/cjs/dialect/postgresql/postgresql-introspector.js +2 -2
- package/dist/cjs/dialect/sqlite/sqlite-auto-indexer.js +47 -33
- package/dist/cjs/dialect/sqlite/sqlite-auto-optimizer.js +8 -7
- package/dist/cjs/dialect/sqlite/sqlite-driver.js +2 -2
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +15 -12
- package/dist/cjs/edge-runtime/edge-config.js +21 -19
- package/dist/cjs/errors/NoormError.js +22 -20
- package/dist/cjs/helpers/agent-schema.js +2 -0
- package/dist/cjs/helpers/postgresql.js +7 -4
- package/dist/cjs/helpers/schema-evolution.js +31 -6
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/logging/logger.js +8 -4
- package/dist/cjs/migration/data_migrator.js +12 -11
- package/dist/cjs/migration/database_migration_manager.js +17 -13
- package/dist/cjs/migration/schema_differ.js +22 -14
- package/dist/cjs/migration/schema_introspector.js +8 -8
- package/dist/cjs/migration/type_mapper.js +68 -67
- package/dist/cjs/noormme.js +52 -37
- package/dist/cjs/performance/index.js +5 -5
- package/dist/cjs/performance/query-optimizer.js +26 -21
- package/dist/cjs/performance/services/cache-service.js +26 -16
- package/dist/cjs/performance/services/connection-factory.js +28 -23
- package/dist/cjs/performance/services/metrics-collector.js +41 -36
- package/dist/cjs/performance/utils/query-parser.js +15 -16
- package/dist/cjs/relationships/relationship-engine.js +10 -8
- package/dist/cjs/repository/repository-factory.js +97 -38
- package/dist/cjs/schema/core/coordinators/schema-discovery.coordinator.js +1 -3
- package/dist/cjs/schema/core/discovery/relationship-discovery.js +16 -16
- package/dist/cjs/schema/core/discovery/table-metadata-discovery.js +9 -9
- package/dist/cjs/schema/core/discovery/view-discovery.js +5 -4
- package/dist/cjs/schema/core/factories/discovery-factory.js +4 -4
- package/dist/cjs/schema/core/utils/name-generator.js +14 -5
- package/dist/cjs/schema/core/utils/type-mapper.js +24 -24
- package/dist/cjs/schema/dialects/postgresql/postgresql-discovery.coordinator.js +8 -7
- package/dist/cjs/schema/dialects/sqlite/discovery/sqlite-constraint-discovery.js +17 -15
- package/dist/cjs/schema/dialects/sqlite/discovery/sqlite-index-discovery.js +8 -8
- package/dist/cjs/schema/dialects/sqlite/introspection/sqlite-schema-introspector.js +6 -11
- package/dist/cjs/schema/dialects/sqlite/sqlite-discovery.coordinator.js +14 -13
- package/dist/cjs/schema/test/basic-schema-test.js +11 -9
- package/dist/cjs/schema/test/dialect-capabilities.test.js +6 -6
- package/dist/cjs/schema/test/discovery-factory.test.js +2 -2
- package/dist/cjs/schema/test/error-handling.test.js +8 -6
- package/dist/cjs/schema/test/integration.test.js +24 -18
- package/dist/cjs/schema/test/schema-discovery-coordinator.test.js +9 -9
- package/dist/cjs/schema/test/simple-schema-test.js +9 -9
- package/dist/cjs/schema/test/sqlite-discovery-coordinator.test.js +64 -48
- package/dist/cjs/schema/test/test-runner.js +3 -3
- package/dist/cjs/sqlite-migration/index.d.ts +2 -2
- package/dist/cjs/sqlite-migration/sqlite-migration-manager.js +21 -17
- package/dist/cjs/sqlite-migration/sqlite-migration-provider.js +38 -34
- package/dist/cjs/testing/test-utils.js +36 -34
- package/dist/cjs/types/index.d.ts +5 -2
- package/dist/cjs/types/index.js +6 -3
- package/dist/cjs/types/type-generator.js +46 -42
- package/dist/cjs/util/safe-sql-helpers.js +1 -1
- package/dist/cjs/util/security-validator.js +20 -9
- package/dist/cjs/utils/errorHelpers.js +20 -10
- package/dist/cjs/watch/schema-watcher.js +22 -23
- package/dist/esm/agentic/ActionJournal.js +13 -9
- package/dist/esm/agentic/CapabilityManager.js +35 -21
- package/dist/esm/agentic/CognitiveRepository.js +19 -9
- package/dist/esm/agentic/ContextBuffer.js +24 -12
- package/dist/esm/agentic/Cortex.js +11 -4
- package/dist/esm/agentic/EpisodicMemory.js +7 -5
- package/dist/esm/agentic/PersonaManager.js +16 -8
- package/dist/esm/agentic/PolicyEnforcer.js +31 -12
- package/dist/esm/agentic/ResourceMonitor.js +4 -4
- package/dist/esm/agentic/SessionCompressor.js +22 -14
- package/dist/esm/agentic/SessionManager.js +36 -18
- package/dist/esm/agentic/VectorIndexer.js +22 -18
- package/dist/esm/agentic/improvement/AblationEngine.js +22 -15
- package/dist/esm/agentic/improvement/ActionRefiner.js +12 -10
- package/dist/esm/agentic/improvement/ConflictResolver.js +5 -5
- package/dist/esm/agentic/improvement/CortexJanitor.js +30 -9
- package/dist/esm/agentic/improvement/CuriosityEngine.js +27 -23
- package/dist/esm/agentic/improvement/EvolutionRitual.js +4 -4
- package/dist/esm/agentic/improvement/EvolutionaryPilot.js +16 -6
- package/dist/esm/agentic/improvement/GoalArchitect.d.ts +2 -2
- package/dist/esm/agentic/improvement/GoalArchitect.js +20 -18
- package/dist/esm/agentic/improvement/GovernanceManager.js +19 -11
- package/dist/esm/agentic/improvement/HiveLink.js +22 -15
- package/dist/esm/agentic/improvement/KnowledgeDistiller.js +48 -32
- package/dist/esm/agentic/improvement/RecursiveReasoner.js +40 -17
- package/dist/esm/agentic/improvement/ReflectionEngine.js +10 -8
- package/dist/esm/agentic/improvement/RitualOrchestrator.js +28 -22
- package/dist/esm/agentic/improvement/RuleEngine.js +22 -17
- package/dist/esm/agentic/improvement/SelfEvolution.js +24 -18
- package/dist/esm/agentic/improvement/SelfTestRegistry.js +18 -15
- package/dist/esm/agentic/improvement/SkillSynthesizer.js +42 -27
- package/dist/esm/agentic/improvement/SovereignMetrics.js +19 -17
- package/dist/esm/agentic/improvement/StrategicPlanner.js +120 -55
- package/dist/esm/agentic/telemetry/CognitiveSynthesizer.js +26 -12
- package/dist/esm/agentic/telemetry/EventHarvester.js +3 -2
- package/dist/esm/agentic/telemetry/ResearchAlchemist.js +5 -2
- package/dist/esm/cache/cache-manager.js +7 -4
- package/dist/esm/cli/commands/analyze.js +5 -4
- package/dist/esm/cli/commands/generate.js +82 -45
- package/dist/esm/cli/commands/init.js +8 -4
- package/dist/esm/cli/commands/inspect.js +140 -37
- package/dist/esm/cli/commands/migrate.js +5 -4
- package/dist/esm/cli/commands/optimize.js +4 -4
- package/dist/esm/cli/commands/status.js +9 -7
- package/dist/esm/cli/commands/watch.js +7 -6
- package/dist/esm/cli/index.js +2 -2
- package/dist/esm/cli/ui/spinner.d.ts +15 -0
- package/dist/esm/cli/ui/spinner.js +70 -0
- package/dist/esm/dialect/database-introspector.js +3 -1
- package/dist/esm/dialect/postgresql/postgresql-driver.js +3 -1
- package/dist/esm/dialect/postgresql/postgresql-features.js +18 -8
- package/dist/esm/dialect/postgresql/postgresql-introspector.js +2 -2
- package/dist/esm/dialect/sqlite/sqlite-auto-indexer.js +47 -33
- package/dist/esm/dialect/sqlite/sqlite-auto-optimizer.js +8 -7
- package/dist/esm/dialect/sqlite/sqlite-driver.js +2 -2
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +15 -12
- package/dist/esm/dynamic/dynamic.js +1 -1
- package/dist/esm/edge-runtime/edge-config.js +21 -19
- package/dist/esm/errors/NoormError.js +22 -20
- package/dist/esm/helpers/agent-schema.js +2 -0
- package/dist/esm/helpers/postgresql.js +7 -4
- package/dist/esm/helpers/schema-evolution.js +31 -6
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +2 -2
- package/dist/esm/logging/logger.js +8 -4
- package/dist/esm/migration/data_migrator.js +12 -11
- package/dist/esm/migration/database_migration_manager.js +18 -14
- package/dist/esm/migration/schema_differ.js +22 -14
- package/dist/esm/migration/schema_introspector.js +8 -8
- package/dist/esm/migration/type_mapper.js +68 -67
- package/dist/esm/noormme.js +52 -37
- package/dist/esm/performance/index.js +5 -5
- package/dist/esm/performance/query-optimizer.js +26 -21
- package/dist/esm/performance/services/cache-service.js +26 -16
- package/dist/esm/performance/services/connection-factory.js +28 -23
- package/dist/esm/performance/services/metrics-collector.js +41 -36
- package/dist/esm/performance/utils/query-parser.js +15 -16
- package/dist/esm/raw-builder/sql.js +1 -1
- package/dist/esm/relationships/relationship-engine.js +10 -8
- package/dist/esm/repository/repository-factory.js +98 -39
- package/dist/esm/schema/builders/alter-table-add-index-builder.js +1 -1
- package/dist/esm/schema/builders/create-index-builder.js +2 -2
- package/dist/esm/schema/core/coordinators/schema-discovery.coordinator.js +1 -3
- package/dist/esm/schema/core/discovery/relationship-discovery.js +16 -16
- package/dist/esm/schema/core/discovery/table-metadata-discovery.js +9 -9
- package/dist/esm/schema/core/discovery/view-discovery.js +5 -4
- package/dist/esm/schema/core/factories/discovery-factory.js +4 -4
- package/dist/esm/schema/core/utils/name-generator.js +14 -5
- package/dist/esm/schema/core/utils/type-mapper.js +24 -24
- package/dist/esm/schema/dialects/postgresql/postgresql-discovery.coordinator.js +8 -7
- package/dist/esm/schema/dialects/sqlite/discovery/sqlite-constraint-discovery.js +17 -15
- package/dist/esm/schema/dialects/sqlite/discovery/sqlite-index-discovery.js +8 -8
- package/dist/esm/schema/dialects/sqlite/introspection/sqlite-schema-introspector.js +6 -11
- package/dist/esm/schema/dialects/sqlite/sqlite-discovery.coordinator.js +14 -13
- package/dist/esm/schema/test/basic-schema-test.js +11 -9
- package/dist/esm/schema/test/dialect-capabilities.test.js +6 -6
- package/dist/esm/schema/test/discovery-factory.test.js +2 -2
- package/dist/esm/schema/test/error-handling.test.js +8 -6
- package/dist/esm/schema/test/integration.test.js +24 -18
- package/dist/esm/schema/test/schema-discovery-coordinator.test.js +9 -9
- package/dist/esm/schema/test/simple-schema-test.js +9 -9
- package/dist/esm/schema/test/sqlite-discovery-coordinator.test.js +64 -48
- package/dist/esm/schema/test/test-runner.js +3 -3
- package/dist/esm/sqlite-migration/index.d.ts +2 -2
- package/dist/esm/sqlite-migration/sqlite-migration-manager.js +21 -17
- package/dist/esm/sqlite-migration/sqlite-migration-provider.js +38 -34
- package/dist/esm/testing/test-utils.js +36 -34
- package/dist/esm/types/index.d.ts +5 -2
- package/dist/esm/types/index.js +6 -3
- package/dist/esm/types/type-generator.js +46 -42
- package/dist/esm/util/safe-sql-helpers.js +1 -1
- package/dist/esm/util/security-validator.js +20 -9
- package/dist/esm/utils/errorHelpers.js +21 -11
- package/dist/esm/watch/schema-watcher.js +22 -23
- package/package.json +40 -44
|
@@ -27,7 +27,7 @@ class SchemaWatcher {
|
|
|
27
27
|
ignoreViews: true,
|
|
28
28
|
ignoredTables: [],
|
|
29
29
|
enabled: options.enabled !== undefined ? options.enabled : defaultEnabled,
|
|
30
|
-
...options
|
|
30
|
+
...options,
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
@@ -57,7 +57,7 @@ class SchemaWatcher {
|
|
|
57
57
|
}
|
|
58
58
|
this.isWatching = true;
|
|
59
59
|
this.intervalId = setInterval(() => {
|
|
60
|
-
this.checkForChanges().catch(error => {
|
|
60
|
+
this.checkForChanges().catch((error) => {
|
|
61
61
|
this.logger.error('Error checking for schema changes:', error);
|
|
62
62
|
});
|
|
63
63
|
}, this.options.pollInterval);
|
|
@@ -141,23 +141,22 @@ class SchemaWatcher {
|
|
|
141
141
|
// Create a deterministic string representation of the schema
|
|
142
142
|
const schemaString = JSON.stringify({
|
|
143
143
|
tables: schema.tables
|
|
144
|
-
.filter(table => !this.options.ignoredTables?.includes(table.name))
|
|
145
|
-
.map(table => ({
|
|
144
|
+
.filter((table) => !this.options.ignoredTables?.includes(table.name))
|
|
145
|
+
.map((table) => ({
|
|
146
146
|
name: table.name,
|
|
147
|
-
columns: table.columns.map(col => ({
|
|
147
|
+
columns: table.columns.map((col) => ({
|
|
148
148
|
name: col.name,
|
|
149
149
|
type: col.type,
|
|
150
150
|
nullable: col.nullable,
|
|
151
151
|
isPrimaryKey: col.isPrimaryKey,
|
|
152
|
-
defaultValue: col.defaultValue
|
|
152
|
+
defaultValue: col.defaultValue,
|
|
153
153
|
})),
|
|
154
154
|
primaryKey: table.primaryKey,
|
|
155
155
|
foreignKeys: table.foreignKeys,
|
|
156
|
-
indexes: table.indexes
|
|
156
|
+
indexes: table.indexes,
|
|
157
157
|
}))
|
|
158
158
|
.sort((a, b) => a.name.localeCompare(b.name)),
|
|
159
|
-
relationships: schema.relationships
|
|
160
|
-
.sort((a, b) => `${a.fromTable}.${a.name}`.localeCompare(`${b.fromTable}.${b.name}`))
|
|
159
|
+
relationships: schema.relationships.sort((a, b) => `${a.fromTable}.${a.name}`.localeCompare(`${b.fromTable}.${b.name}`)),
|
|
161
160
|
});
|
|
162
161
|
return (0, node_crypto_1.createHash)('sha256').update(schemaString).digest('hex');
|
|
163
162
|
}
|
|
@@ -175,20 +174,20 @@ class SchemaWatcher {
|
|
|
175
174
|
changes.push({
|
|
176
175
|
type: 'table_added',
|
|
177
176
|
table: table.name,
|
|
178
|
-
details: { columns: table.columns.length }
|
|
177
|
+
details: { columns: table.columns.length },
|
|
179
178
|
});
|
|
180
179
|
}
|
|
181
180
|
return changes;
|
|
182
181
|
}
|
|
183
|
-
const oldTablesMap = new Map(oldSchema.tables.map(t => [t.name, t]));
|
|
184
|
-
const newTablesMap = new Map(newSchema.tables.map(t => [t.name, t]));
|
|
182
|
+
const oldTablesMap = new Map(oldSchema.tables.map((t) => [t.name, t]));
|
|
183
|
+
const newTablesMap = new Map(newSchema.tables.map((t) => [t.name, t]));
|
|
185
184
|
// Check for added tables
|
|
186
185
|
for (const table of newSchema.tables) {
|
|
187
186
|
if (!oldTablesMap.has(table.name)) {
|
|
188
187
|
changes.push({
|
|
189
188
|
type: 'table_added',
|
|
190
189
|
table: table.name,
|
|
191
|
-
details: { columns: table.columns.length }
|
|
190
|
+
details: { columns: table.columns.length },
|
|
192
191
|
});
|
|
193
192
|
}
|
|
194
193
|
}
|
|
@@ -197,7 +196,7 @@ class SchemaWatcher {
|
|
|
197
196
|
if (!newTablesMap.has(table.name)) {
|
|
198
197
|
changes.push({
|
|
199
198
|
type: 'table_removed',
|
|
200
|
-
table: table.name
|
|
199
|
+
table: table.name,
|
|
201
200
|
});
|
|
202
201
|
}
|
|
203
202
|
}
|
|
@@ -205,8 +204,8 @@ class SchemaWatcher {
|
|
|
205
204
|
for (const newTable of newSchema.tables) {
|
|
206
205
|
const oldTable = oldTablesMap.get(newTable.name);
|
|
207
206
|
if (oldTable) {
|
|
208
|
-
const oldColumnsMap = new Map(oldTable.columns.map(c => [c.name, c]));
|
|
209
|
-
const newColumnsMap = new Map(newTable.columns.map(c => [c.name, c]));
|
|
207
|
+
const oldColumnsMap = new Map(oldTable.columns.map((c) => [c.name, c]));
|
|
208
|
+
const newColumnsMap = new Map(newTable.columns.map((c) => [c.name, c]));
|
|
210
209
|
// Check for added columns
|
|
211
210
|
for (const column of newTable.columns) {
|
|
212
211
|
if (!oldColumnsMap.has(column.name)) {
|
|
@@ -214,7 +213,7 @@ class SchemaWatcher {
|
|
|
214
213
|
type: 'column_added',
|
|
215
214
|
table: newTable.name,
|
|
216
215
|
column: column.name,
|
|
217
|
-
details: { type: column.type }
|
|
216
|
+
details: { type: column.type },
|
|
218
217
|
});
|
|
219
218
|
}
|
|
220
219
|
}
|
|
@@ -224,7 +223,7 @@ class SchemaWatcher {
|
|
|
224
223
|
changes.push({
|
|
225
224
|
type: 'column_removed',
|
|
226
225
|
table: newTable.name,
|
|
227
|
-
column: column.name
|
|
226
|
+
column: column.name,
|
|
228
227
|
});
|
|
229
228
|
}
|
|
230
229
|
else {
|
|
@@ -237,8 +236,8 @@ class SchemaWatcher {
|
|
|
237
236
|
column: column.name,
|
|
238
237
|
details: {
|
|
239
238
|
old: { type: column.type, nullable: column.nullable },
|
|
240
|
-
new: { type: newColumn.type, nullable: newColumn.nullable }
|
|
241
|
-
}
|
|
239
|
+
new: { type: newColumn.type, nullable: newColumn.nullable },
|
|
240
|
+
},
|
|
242
241
|
});
|
|
243
242
|
}
|
|
244
243
|
}
|
|
@@ -248,15 +247,15 @@ class SchemaWatcher {
|
|
|
248
247
|
return changes;
|
|
249
248
|
}
|
|
250
249
|
isColumnModified(oldCol, newCol) {
|
|
251
|
-
return oldCol.type !== newCol.type ||
|
|
250
|
+
return (oldCol.type !== newCol.type ||
|
|
252
251
|
oldCol.nullable !== newCol.nullable ||
|
|
253
|
-
oldCol.isPrimaryKey !== newCol.isPrimaryKey;
|
|
252
|
+
oldCol.isPrimaryKey !== newCol.isPrimaryKey);
|
|
254
253
|
}
|
|
255
254
|
/**
|
|
256
255
|
* Notify all registered callbacks about schema changes
|
|
257
256
|
*/
|
|
258
257
|
notifyCallbacks(changes) {
|
|
259
|
-
this.callbacks.forEach(callback => {
|
|
258
|
+
this.callbacks.forEach((callback) => {
|
|
260
259
|
try {
|
|
261
260
|
callback(changes);
|
|
262
261
|
}
|
|
@@ -29,7 +29,7 @@ export class ActionJournal {
|
|
|
29
29
|
tool_name: toolName,
|
|
30
30
|
arguments: JSON.stringify(args),
|
|
31
31
|
status: 'pending',
|
|
32
|
-
created_at: new Date()
|
|
32
|
+
created_at: new Date(),
|
|
33
33
|
})
|
|
34
34
|
.returningAll()
|
|
35
35
|
.executeTakeFirstOrThrow();
|
|
@@ -50,7 +50,7 @@ export class ActionJournal {
|
|
|
50
50
|
status,
|
|
51
51
|
outcome,
|
|
52
52
|
duration_ms: durationMs || null,
|
|
53
|
-
metadata: metadata ? JSON.stringify(metadata) : null
|
|
53
|
+
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
54
54
|
})
|
|
55
55
|
.where('id', '=', actionId)
|
|
56
56
|
.returningAll()
|
|
@@ -74,7 +74,7 @@ export class ActionJournal {
|
|
|
74
74
|
.where('session_id', '=', sessionId)
|
|
75
75
|
.orderBy('created_at', 'asc')
|
|
76
76
|
.execute();
|
|
77
|
-
return actions.map(a => this.parseAction(a));
|
|
77
|
+
return actions.map((a) => this.parseAction(a));
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* Get actions by tool name across all sessions.
|
|
@@ -87,7 +87,7 @@ export class ActionJournal {
|
|
|
87
87
|
.orderBy('created_at', 'desc')
|
|
88
88
|
.limit(limit)
|
|
89
89
|
.execute();
|
|
90
|
-
return actions.map(a => this.parseAction(a));
|
|
90
|
+
return actions.map((a) => this.parseAction(a));
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
93
93
|
* Generate a report of tool failures.
|
|
@@ -98,7 +98,7 @@ export class ActionJournal {
|
|
|
98
98
|
.select([
|
|
99
99
|
'tool_name',
|
|
100
100
|
(eb) => eb.fn.count('id').as('failureCount'),
|
|
101
|
-
(eb) => eb.fn.max('created_at').as('lastFailure')
|
|
101
|
+
(eb) => eb.fn.max('created_at').as('lastFailure'),
|
|
102
102
|
])
|
|
103
103
|
.where('status', '=', 'failure')
|
|
104
104
|
.groupBy('tool_name')
|
|
@@ -107,7 +107,7 @@ export class ActionJournal {
|
|
|
107
107
|
return results.map((r) => ({
|
|
108
108
|
toolName: r.tool_name,
|
|
109
109
|
failureCount: Number(r.failureCount),
|
|
110
|
-
lastFailure: r.lastFailure
|
|
110
|
+
lastFailure: r.lastFailure,
|
|
111
111
|
}));
|
|
112
112
|
}
|
|
113
113
|
parseAction(action) {
|
|
@@ -116,12 +116,16 @@ export class ActionJournal {
|
|
|
116
116
|
sessionId: action.session_id,
|
|
117
117
|
messageId: action.message_id,
|
|
118
118
|
toolName: action.tool_name,
|
|
119
|
-
arguments: typeof action.arguments === 'string'
|
|
119
|
+
arguments: typeof action.arguments === 'string'
|
|
120
|
+
? JSON.parse(action.arguments)
|
|
121
|
+
: action.arguments || {},
|
|
120
122
|
status: action.status,
|
|
121
123
|
outcome: action.outcome,
|
|
122
124
|
durationMs: action.duration_ms,
|
|
123
|
-
metadata: typeof action.metadata === 'string'
|
|
124
|
-
|
|
125
|
+
metadata: typeof action.metadata === 'string'
|
|
126
|
+
? JSON.parse(action.metadata)
|
|
127
|
+
: action.metadata || {},
|
|
128
|
+
createdAt: new Date(action.created_at),
|
|
125
129
|
};
|
|
126
130
|
}
|
|
127
131
|
}
|
|
@@ -19,7 +19,7 @@ export class CapabilityManager {
|
|
|
19
19
|
rollbackThresholdZ: config.evolution?.rollbackThresholdZ ?? 2.5,
|
|
20
20
|
enableHiveLink: config.evolution?.enableHiveLink ?? true,
|
|
21
21
|
mutationAggressiveness: config.evolution?.mutationAggressiveness ?? 0.5,
|
|
22
|
-
maxSandboxSkills: config.evolution?.maxSandboxSkills ?? 5
|
|
22
|
+
maxSandboxSkills: config.evolution?.maxSandboxSkills ?? 5,
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
get typedDb() {
|
|
@@ -42,8 +42,11 @@ export class CapabilityManager {
|
|
|
42
42
|
.set({
|
|
43
43
|
description: description || existing.description,
|
|
44
44
|
status: existing.status || 'experimental',
|
|
45
|
-
metadata: JSON.stringify({
|
|
46
|
-
|
|
45
|
+
metadata: JSON.stringify({
|
|
46
|
+
...JSON.parse(existing.metadata || '{}'),
|
|
47
|
+
...metadata,
|
|
48
|
+
}),
|
|
49
|
+
updated_at: new Date(),
|
|
47
50
|
})
|
|
48
51
|
.where('id', '=', existing.id)
|
|
49
52
|
.returningAll()
|
|
@@ -58,9 +61,13 @@ export class CapabilityManager {
|
|
|
58
61
|
description: description || null,
|
|
59
62
|
status: metadata.initialStatus || 'experimental',
|
|
60
63
|
reliability: 1.0,
|
|
61
|
-
metadata: JSON.stringify({
|
|
64
|
+
metadata: JSON.stringify({
|
|
65
|
+
...metadata,
|
|
66
|
+
successCount: 0,
|
|
67
|
+
totalCount: 0,
|
|
68
|
+
}),
|
|
62
69
|
created_at: new Date(),
|
|
63
|
-
updated_at: new Date()
|
|
70
|
+
updated_at: new Date(),
|
|
64
71
|
})
|
|
65
72
|
.returningAll()
|
|
66
73
|
.executeTakeFirstOrThrow();
|
|
@@ -81,7 +88,9 @@ export class CapabilityManager {
|
|
|
81
88
|
.executeTakeFirst();
|
|
82
89
|
if (capability) {
|
|
83
90
|
const cap = capability;
|
|
84
|
-
const metadata = typeof cap.metadata === 'string'
|
|
91
|
+
const metadata = typeof cap.metadata === 'string'
|
|
92
|
+
? JSON.parse(cap.metadata)
|
|
93
|
+
: cap.metadata || {};
|
|
85
94
|
const totalCount = (metadata.totalCount || 0) + 1;
|
|
86
95
|
const successCount = (metadata.successCount || 0) + (success ? 1 : 0);
|
|
87
96
|
// Damped moving average: weight recent outcomes more but keep history
|
|
@@ -100,34 +109,39 @@ export class CapabilityManager {
|
|
|
100
109
|
const windowSize = this.evolutionConfig.verificationWindow || 20;
|
|
101
110
|
const minSampleSize = Math.ceil(windowSize * 0.75);
|
|
102
111
|
// Fast-Track Promotion: 5 consecutive successes bypasses sample size
|
|
103
|
-
const isPromotable = (totalCount >= minSampleSize && winRate >= 0.8) ||
|
|
112
|
+
const isPromotable = (totalCount >= minSampleSize && winRate >= 0.8) || streakSuccess >= 5;
|
|
104
113
|
// Early-Exit Rollback: 3 consecutive failures at the start immediately blacklists
|
|
105
114
|
const isCatastrophic = !success && failureStreak >= 3 && totalCount <= 5;
|
|
106
115
|
// Pass 6: Predictive Pre-warming Trigger
|
|
107
116
|
// If a skill is close to promotion, pre-warm its optimized description
|
|
108
117
|
const promoThreshold = Math.ceil(minSampleSize * 0.8);
|
|
109
|
-
const isNearingPromotion = (totalCount >= promoThreshold && winRate >= 0.8) ||
|
|
110
|
-
|
|
118
|
+
const isNearingPromotion = (totalCount >= promoThreshold && winRate >= 0.8) ||
|
|
119
|
+
streakSuccess === 4;
|
|
120
|
+
if (isNearingPromotion &&
|
|
121
|
+
newStatus === 'experimental' &&
|
|
122
|
+
this.cortex.skillSynthesizer) {
|
|
111
123
|
// Trigger async background pre-warming
|
|
112
124
|
this.cortex.skillSynthesizer.preWarmSkill(name).catch(() => { });
|
|
113
125
|
}
|
|
114
126
|
// --- Production Hardening: Dynamic Performance Baselining ---
|
|
115
127
|
const historyAlpha = 0.05; // Slower moving average for baseline
|
|
116
128
|
const baseline = metadata.performanceBaseline ?? winRate;
|
|
117
|
-
const newBaseline =
|
|
129
|
+
const newBaseline = baseline * (1 - historyAlpha) + winRate * historyAlpha;
|
|
118
130
|
// Variance tracking for Z-score calculation
|
|
119
131
|
const variance = metadata.performanceVariance ?? 0.01;
|
|
120
132
|
const diff = winRate - baseline;
|
|
121
|
-
const newVariance =
|
|
133
|
+
const newVariance = variance * (1 - historyAlpha) + Math.pow(diff, 2) * historyAlpha;
|
|
122
134
|
const stdDev = Math.sqrt(newVariance);
|
|
123
135
|
// Z-Score: How many standard deviations is current performance from baseline?
|
|
124
136
|
const zScore = stdDev > 0 ? (winRate - baseline) / stdDev : 0;
|
|
125
137
|
// Promotion/Demotion Logic
|
|
126
|
-
if (isCatastrophic &&
|
|
138
|
+
if (isCatastrophic &&
|
|
139
|
+
(newStatus === 'experimental' || newStatus === 'sandbox')) {
|
|
127
140
|
console.error(`[CapabilityManager] Skill '${name}' FAILED early-exit safety check (Streak: ${failureStreak}). Blacklisting immediately.`);
|
|
128
141
|
newStatus = 'blacklisted';
|
|
129
142
|
}
|
|
130
|
-
else if (isPromotable &&
|
|
143
|
+
else if (isPromotable &&
|
|
144
|
+
(newStatus === 'experimental' || newStatus === 'sandbox')) {
|
|
131
145
|
console.log(`[CapabilityManager] Skill '${name}' PASSED fast-track verification (Streak: ${streakSuccess}, Rate: ${(winRate * 100).toFixed(1)}%). Promoting to Verified.`);
|
|
132
146
|
newStatus = 'verified';
|
|
133
147
|
}
|
|
@@ -158,9 +172,9 @@ export class CapabilityManager {
|
|
|
158
172
|
failureStreak,
|
|
159
173
|
performanceBaseline: newBaseline,
|
|
160
174
|
performanceVariance: newVariance,
|
|
161
|
-
lastOutcomeType: success ? 'success' : 'failure' // Categorization point
|
|
175
|
+
lastOutcomeType: success ? 'success' : 'failure', // Categorization point
|
|
162
176
|
}),
|
|
163
|
-
updated_at: new Date()
|
|
177
|
+
updated_at: new Date(),
|
|
164
178
|
})
|
|
165
179
|
.where('id', '=', cap.id)
|
|
166
180
|
.execute();
|
|
@@ -189,10 +203,8 @@ export class CapabilityManager {
|
|
|
189
203
|
if (status) {
|
|
190
204
|
query = query.where('status', '=', status);
|
|
191
205
|
}
|
|
192
|
-
const list = await query
|
|
193
|
-
|
|
194
|
-
.execute();
|
|
195
|
-
return list.map(c => this.parseCapability(c));
|
|
206
|
+
const list = await query.orderBy('name', 'asc').execute();
|
|
207
|
+
return list.map((c) => this.parseCapability(c));
|
|
196
208
|
}
|
|
197
209
|
parseCapability(cap) {
|
|
198
210
|
return {
|
|
@@ -202,9 +214,11 @@ export class CapabilityManager {
|
|
|
202
214
|
description: cap.description,
|
|
203
215
|
status: cap.status || 'experimental',
|
|
204
216
|
reliability: cap.reliability,
|
|
205
|
-
metadata: typeof cap.metadata === 'string'
|
|
217
|
+
metadata: typeof cap.metadata === 'string'
|
|
218
|
+
? JSON.parse(cap.metadata)
|
|
219
|
+
: cap.metadata || {},
|
|
206
220
|
createdAt: new Date(cap.created_at),
|
|
207
|
-
updatedAt: new Date(cap.updated_at)
|
|
221
|
+
updatedAt: new Date(cap.updated_at),
|
|
208
222
|
};
|
|
209
223
|
}
|
|
210
224
|
}
|
|
@@ -18,16 +18,18 @@ export class CognitiveRepository {
|
|
|
18
18
|
*/
|
|
19
19
|
async triggerRules(operation, data) {
|
|
20
20
|
// Check if rules table exists to avoid errors during initialization
|
|
21
|
-
const rulesTable = this.cortex.config.agentic?.rulesTable ||
|
|
21
|
+
const rulesTable = this.cortex.config.agentic?.rulesTable ||
|
|
22
|
+
this.cortex.config.rulesTable ||
|
|
23
|
+
'agent_rules';
|
|
22
24
|
const tables = await this.cortex.db.introspection.getTables();
|
|
23
|
-
if (!tables.some(t => t.name === rulesTable)) {
|
|
25
|
+
if (!tables.some((t) => t.name === rulesTable)) {
|
|
24
26
|
return data;
|
|
25
27
|
}
|
|
26
28
|
const result = await this.cortex.rules.evaluateRules(this.table.name, operation, data);
|
|
27
29
|
if (result.action === 'deny') {
|
|
28
30
|
throw new NoormError(`Operation ${operation} on ${this.table.name} denied: ${result.reason}`, {
|
|
29
31
|
operation: 'cognitive_rule_enforcement',
|
|
30
|
-
suggestion: 'Check agent rules or adjust policy'
|
|
32
|
+
suggestion: 'Check agent rules or adjust policy',
|
|
31
33
|
});
|
|
32
34
|
}
|
|
33
35
|
if (result.action === 'audit') {
|
|
@@ -35,7 +37,7 @@ export class CognitiveRepository {
|
|
|
35
37
|
}
|
|
36
38
|
if (result.action === 'mask' && result.ruleId) {
|
|
37
39
|
const rules = await this.cortex.rules.getActiveRules(this.table.name, operation);
|
|
38
|
-
const rule = rules.find(r => r.id === result.ruleId);
|
|
40
|
+
const rule = rules.find((r) => r.id === result.ruleId);
|
|
39
41
|
if (rule) {
|
|
40
42
|
return this.cortex.rules.applyMasking(data, rule);
|
|
41
43
|
}
|
|
@@ -55,10 +57,18 @@ export class CognitiveRepository {
|
|
|
55
57
|
return await this.repository.delete(id);
|
|
56
58
|
}
|
|
57
59
|
// Delegate other methods to the internal repository
|
|
58
|
-
async findById(id) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
async
|
|
60
|
+
async findById(id) {
|
|
61
|
+
return this.repository.findById(id);
|
|
62
|
+
}
|
|
63
|
+
async findAll() {
|
|
64
|
+
return this.repository.findAll();
|
|
65
|
+
}
|
|
66
|
+
async count() {
|
|
67
|
+
return this.repository.count();
|
|
68
|
+
}
|
|
69
|
+
async exists(id) {
|
|
70
|
+
return this.repository.exists(id);
|
|
71
|
+
}
|
|
62
72
|
// Dynamic method delegation via Proxy
|
|
63
73
|
static createProxy(repository, table, cortex) {
|
|
64
74
|
const cognitive = new CognitiveRepository(repository, table, cortex);
|
|
@@ -68,7 +78,7 @@ export class CognitiveRepository {
|
|
|
68
78
|
return cognitive[prop];
|
|
69
79
|
}
|
|
70
80
|
return Reflect.get(target, prop, receiver);
|
|
71
|
-
}
|
|
81
|
+
},
|
|
72
82
|
});
|
|
73
83
|
}
|
|
74
84
|
}
|
|
@@ -50,7 +50,7 @@ export class ContextBuffer {
|
|
|
50
50
|
msg: m,
|
|
51
51
|
index,
|
|
52
52
|
isAnchor: !!m.metadata?.anchor,
|
|
53
|
-
tokens: this.estimateTokens(m.content)
|
|
53
|
+
tokens: this.estimateTokens(m.content),
|
|
54
54
|
}));
|
|
55
55
|
const sortedForSelection = [...scored].sort((a, b) => {
|
|
56
56
|
if (a.isAnchor !== b.isAnchor)
|
|
@@ -58,15 +58,18 @@ export class ContextBuffer {
|
|
|
58
58
|
return b.index - a.index; // Recency tie-breaker
|
|
59
59
|
});
|
|
60
60
|
const selected = new Set();
|
|
61
|
-
let currentTokens = systemMessage
|
|
61
|
+
let currentTokens = systemMessage
|
|
62
|
+
? this.estimateTokens(systemMessage.content)
|
|
63
|
+
: 0;
|
|
62
64
|
for (const item of sortedForSelection) {
|
|
63
|
-
if (selected.size < effectiveLimit &&
|
|
65
|
+
if (selected.size < effectiveLimit &&
|
|
66
|
+
currentTokens + item.tokens <= tokenLimit) {
|
|
64
67
|
selected.add(item.msg);
|
|
65
68
|
currentTokens += item.tokens;
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
71
|
// Maintain temporal order
|
|
69
|
-
const result = this.messages.filter(m => m === systemMessage || selected.has(m));
|
|
72
|
+
const result = this.messages.filter((m) => m === systemMessage || selected.has(m));
|
|
70
73
|
return result;
|
|
71
74
|
}
|
|
72
75
|
/**
|
|
@@ -74,14 +77,14 @@ export class ContextBuffer {
|
|
|
74
77
|
*/
|
|
75
78
|
toPromptString(limit) {
|
|
76
79
|
return this.getWindow({ maxMessages: limit })
|
|
77
|
-
.map(m => `[${m.role.toUpperCase()}]: ${m.content}`)
|
|
80
|
+
.map((m) => `[${m.role.toUpperCase()}]: ${m.content}`)
|
|
78
81
|
.join('\n\n');
|
|
79
82
|
}
|
|
80
83
|
/**
|
|
81
84
|
* Helper to identify if the buffer is becoming too large.
|
|
82
85
|
*/
|
|
83
86
|
shouldSummarize(tokenThreshold) {
|
|
84
|
-
const threshold = tokenThreshold ||
|
|
87
|
+
const threshold = tokenThreshold || this.maxTokens * 0.8;
|
|
85
88
|
return this.getTotalTokens() > threshold;
|
|
86
89
|
}
|
|
87
90
|
/**
|
|
@@ -92,7 +95,7 @@ export class ContextBuffer {
|
|
|
92
95
|
messageCount: this.messages.length,
|
|
93
96
|
totalTokens: this.getTotalTokens(),
|
|
94
97
|
maxTokens: this.maxTokens,
|
|
95
|
-
maxMessages: this.maxMessages
|
|
98
|
+
maxMessages: this.maxMessages,
|
|
96
99
|
};
|
|
97
100
|
}
|
|
98
101
|
getTotalTokens() {
|
|
@@ -105,28 +108,37 @@ export class ContextBuffer {
|
|
|
105
108
|
const initialCount = this.messages.length;
|
|
106
109
|
// Importance Trimming: Prefer keeping 'anchor' messages or high-priority messages
|
|
107
110
|
// We sort a copy to determine which ones to keep, then reconstruct in temporal order
|
|
108
|
-
const otherMessages = systemMessage
|
|
111
|
+
const otherMessages = systemMessage
|
|
112
|
+
? this.messages.slice(1)
|
|
113
|
+
: this.messages;
|
|
109
114
|
// Heuristic for importance: anchors > assistant > user (user input is often redundant if reflected/anchored)
|
|
110
115
|
const sortedByImportance = [...otherMessages].sort((a, b) => {
|
|
111
116
|
const aIsAnchor = a.metadata?.anchor ? 1 : 0;
|
|
112
117
|
const bIsAnchor = b.metadata?.anchor ? 1 : 0;
|
|
113
118
|
if (aIsAnchor !== bIsAnchor)
|
|
114
119
|
return bIsAnchor - aIsAnchor;
|
|
115
|
-
const rolePriority = {
|
|
120
|
+
const rolePriority = {
|
|
121
|
+
system: 3,
|
|
122
|
+
assistant: 2,
|
|
123
|
+
user: 1,
|
|
124
|
+
action: 2,
|
|
125
|
+
};
|
|
116
126
|
return (rolePriority[b.role] || 0) - (rolePriority[a.role] || 0);
|
|
117
127
|
});
|
|
118
128
|
const toKeep = new Set(sortedByImportance.slice(0, this.maxMessages));
|
|
119
|
-
this.messages = this.messages.filter(m => m === systemMessage || toKeep.has(m));
|
|
129
|
+
this.messages = this.messages.filter((m) => m === systemMessage || toKeep.has(m));
|
|
120
130
|
console.log(`[ContextBuffer] Importance Trimming: ${initialCount} -> ${this.messages.length} messages. preserved anchors and assistant reasoning.`);
|
|
121
131
|
}
|
|
122
132
|
}
|
|
123
133
|
estimateTokens(content) {
|
|
124
134
|
if (!content)
|
|
125
135
|
return 0;
|
|
126
|
-
// More sophisticated heuristic:
|
|
136
|
+
// More sophisticated heuristic:
|
|
127
137
|
// - JSON/Code tends to have more tokens per character due to symbols.
|
|
128
138
|
// - Natural language is ~4 chars per token.
|
|
129
|
-
const isStructured = content.startsWith('{') ||
|
|
139
|
+
const isStructured = content.startsWith('{') ||
|
|
140
|
+
content.startsWith('[') ||
|
|
141
|
+
content.includes('```');
|
|
130
142
|
const ratio = isStructured ? 3 : 4;
|
|
131
143
|
return Math.ceil(content.length / ratio);
|
|
132
144
|
}
|
|
@@ -82,7 +82,9 @@ export class Cortex {
|
|
|
82
82
|
this.llmPremium = agenticConfig.llmPremium || this.llm;
|
|
83
83
|
this.telemetry = new TelemetryOrchestrator(db, agenticConfig);
|
|
84
84
|
this.sessions = new SessionManager(db, agenticConfig, this.telemetry);
|
|
85
|
-
this.buffer = new ContextBuffer({
|
|
85
|
+
this.buffer = new ContextBuffer({
|
|
86
|
+
maxMessages: agenticConfig.contextWindowSize,
|
|
87
|
+
});
|
|
86
88
|
this.vectors = agenticConfig.vectorConfig
|
|
87
89
|
? new VectorIndexer(db, agenticConfig.vectorConfig, agenticConfig.memoriesTable)
|
|
88
90
|
: null;
|
|
@@ -148,7 +150,9 @@ export class Cortex {
|
|
|
148
150
|
catch (err) {
|
|
149
151
|
console.error('[Cortex] Soul-Searching loop failed:', err);
|
|
150
152
|
// Telemetry: track failure
|
|
151
|
-
await this.telemetry.track('system', 'error', 'Self-iteration failed', {
|
|
153
|
+
await this.telemetry.track('system', 'error', 'Self-iteration failed', {
|
|
154
|
+
error: String(err),
|
|
155
|
+
});
|
|
152
156
|
}
|
|
153
157
|
}
|
|
154
158
|
/**
|
|
@@ -165,8 +169,11 @@ export class Cortex {
|
|
|
165
169
|
async recordInteraction(sessionId, role, content, options = {}) {
|
|
166
170
|
const message = await this.sessions.addMessage(sessionId, role, content);
|
|
167
171
|
// Telemetry: Track prompt and output
|
|
168
|
-
const type = role === 'user' ? 'prompt' :
|
|
169
|
-
await this.telemetry.track(sessionId, type, content, {
|
|
172
|
+
const type = role === 'user' ? 'prompt' : role === 'assistant' ? 'output' : 'action';
|
|
173
|
+
await this.telemetry.track(sessionId, type, content, {
|
|
174
|
+
role,
|
|
175
|
+
messageId: message.id,
|
|
176
|
+
});
|
|
170
177
|
if (options.index && options.embedding && this.vectors) {
|
|
171
178
|
await this.vectors.addMemory(content, options.embedding, sessionId);
|
|
172
179
|
}
|
|
@@ -26,7 +26,7 @@ export class EpisodicMemory {
|
|
|
26
26
|
name,
|
|
27
27
|
status: 'active',
|
|
28
28
|
start_time: new Date(),
|
|
29
|
-
metadata: metadata ? JSON.stringify(metadata) : null
|
|
29
|
+
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
30
30
|
})
|
|
31
31
|
.returningAll()
|
|
32
32
|
.executeTakeFirstOrThrow();
|
|
@@ -52,7 +52,7 @@ export class EpisodicMemory {
|
|
|
52
52
|
status: 'completed',
|
|
53
53
|
summary,
|
|
54
54
|
end_time: new Date(),
|
|
55
|
-
metadata: JSON.stringify(newMeta)
|
|
55
|
+
metadata: JSON.stringify(newMeta),
|
|
56
56
|
})
|
|
57
57
|
.where('id', '=', episodeId)
|
|
58
58
|
.returningAll()
|
|
@@ -70,7 +70,7 @@ export class EpisodicMemory {
|
|
|
70
70
|
.where('session_id', '=', sessionId)
|
|
71
71
|
.orderBy('start_time', 'desc')
|
|
72
72
|
.execute();
|
|
73
|
-
return list.map(e => this.parseEpisode(e));
|
|
73
|
+
return list.map((e) => this.parseEpisode(e));
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
76
|
* Get recently completed episodes across all sessions.
|
|
@@ -83,7 +83,7 @@ export class EpisodicMemory {
|
|
|
83
83
|
.orderBy('end_time', 'desc')
|
|
84
84
|
.limit(limit)
|
|
85
85
|
.execute();
|
|
86
|
-
return list.map(e => this.parseEpisode(e));
|
|
86
|
+
return list.map((e) => this.parseEpisode(e));
|
|
87
87
|
}
|
|
88
88
|
parseEpisode(episode) {
|
|
89
89
|
return {
|
|
@@ -94,7 +94,9 @@ export class EpisodicMemory {
|
|
|
94
94
|
status: episode.status,
|
|
95
95
|
startTime: new Date(episode.start_time),
|
|
96
96
|
endTime: episode.end_time ? new Date(episode.end_time) : undefined,
|
|
97
|
-
metadata: typeof episode.metadata === 'string'
|
|
97
|
+
metadata: typeof episode.metadata === 'string'
|
|
98
|
+
? JSON.parse(episode.metadata)
|
|
99
|
+
: episode.metadata || {},
|
|
98
100
|
};
|
|
99
101
|
}
|
|
100
102
|
}
|
|
@@ -26,10 +26,12 @@ export class PersonaManager {
|
|
|
26
26
|
const values = {
|
|
27
27
|
name,
|
|
28
28
|
role: options.role || null,
|
|
29
|
-
capabilities: options.capabilities
|
|
29
|
+
capabilities: options.capabilities
|
|
30
|
+
? JSON.stringify(options.capabilities)
|
|
31
|
+
: null,
|
|
30
32
|
policies: options.policies ? JSON.stringify(options.policies) : null,
|
|
31
33
|
metadata: options.metadata ? JSON.stringify(options.metadata) : null,
|
|
32
|
-
updated_at: new Date()
|
|
34
|
+
updated_at: new Date(),
|
|
33
35
|
};
|
|
34
36
|
if (existing) {
|
|
35
37
|
const updated = await this.typedDb
|
|
@@ -44,7 +46,7 @@ export class PersonaManager {
|
|
|
44
46
|
.insertInto(this.personasTable)
|
|
45
47
|
.values({
|
|
46
48
|
...values,
|
|
47
|
-
created_at: new Date()
|
|
49
|
+
created_at: new Date(),
|
|
48
50
|
})
|
|
49
51
|
.returningAll()
|
|
50
52
|
.executeTakeFirstOrThrow();
|
|
@@ -80,18 +82,24 @@ export class PersonaManager {
|
|
|
80
82
|
.selectAll()
|
|
81
83
|
.orderBy('name', 'asc')
|
|
82
84
|
.execute();
|
|
83
|
-
return list.map(p => this.parsePersona(p));
|
|
85
|
+
return list.map((p) => this.parsePersona(p));
|
|
84
86
|
}
|
|
85
87
|
parsePersona(p) {
|
|
86
88
|
return {
|
|
87
89
|
id: p.id,
|
|
88
90
|
name: p.name,
|
|
89
91
|
role: p.role || undefined,
|
|
90
|
-
capabilities: typeof p.capabilities === 'string'
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
capabilities: typeof p.capabilities === 'string'
|
|
93
|
+
? JSON.parse(p.capabilities)
|
|
94
|
+
: p.capabilities || [],
|
|
95
|
+
policies: typeof p.policies === 'string'
|
|
96
|
+
? JSON.parse(p.policies)
|
|
97
|
+
: p.policies || [],
|
|
98
|
+
metadata: typeof p.metadata === 'string'
|
|
99
|
+
? JSON.parse(p.metadata)
|
|
100
|
+
: p.metadata || {},
|
|
93
101
|
createdAt: new Date(p.created_at),
|
|
94
|
-
updatedAt: new Date(p.updated_at)
|
|
102
|
+
updatedAt: new Date(p.updated_at),
|
|
95
103
|
};
|
|
96
104
|
}
|
|
97
105
|
}
|