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
package/README.md
CHANGED
|
@@ -1,74 +1,83 @@
|
|
|
1
|
-
|
|
1
|
+
# NOORMME: The Sovereign Agentic Data Engine
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**NOORMME** is a sovereign persistence layer and cognitive operating system purpose-built for **Autonomous AI Agents**. It transcends legacy ORM patterns by providing a self-healing, evolutionary data infrastructure that functions as a high-fidelity extension of an agent's internal reasoning loop.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[](./docs/ultra-scale-orchestration.md)
|
|
5
|
+
[](https://www.npmjs.com/package/noormme)
|
|
6
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
7
|
+
[](./docs/postgresql/POSTGRESQL_SUPPORT.md)
|
|
8
|
+
[](./docs/agentic-intelligence.md)
|
|
9
|
+
[](./docs/ultra-scale-orchestration.md)
|
|
11
10
|
|
|
12
11
|
---
|
|
13
12
|
|
|
14
|
-
##
|
|
15
|
-
|
|
16
|
-
NOORMME implements a closed-loop system where data is not merely "stored" but continuously distilled, questioned, and evolved. It turns your database into a living world model.
|
|
17
|
-
|
|
18
|
-
```mermaid
|
|
19
|
-
graph LR
|
|
20
|
-
A[Raw Ingestion] --> B{Distillation}
|
|
21
|
-
B --> C[Knowledge Base]
|
|
22
|
-
C --> D[Reasoning Engine]
|
|
23
|
-
D --> E[Action / Outcome]
|
|
24
|
-
E --> F{Reflection}
|
|
25
|
-
F -->|Success| G[Goal Reinforcement]
|
|
26
|
-
F -->|Failure| H[Strategic Mutation]
|
|
27
|
-
H --> B
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### ✨ Advanced Orchestration
|
|
31
|
-
- **🎭 Tiered Model Routing**: Optimize cost/performance by routing batch discovery to **Fast LLMs** and mutation logic to **Premium LLMs**.
|
|
32
|
-
- **🔥 Predictive Pre-warming**: Background AI optimization of skills nearing promotion to eliminate cold-start latency.
|
|
33
|
-
- **🌐 Goal Cross-Pollination**: Breakthroughs in individual persona mutations are automatically distilled into global **Systemic Best-Practices**.
|
|
34
|
-
- **🌸 Bloom Filter Heuristics**: Ultra-scale knowledge de-duplication at 100x speed vs traditional DB hits.
|
|
13
|
+
## 🏛️ The Sovereign Triad
|
|
35
14
|
|
|
36
|
-
|
|
15
|
+
NOORMME is built on three architectural pillars that enable agents to move beyond simple storage into true cognitive autonomy.
|
|
37
16
|
|
|
38
|
-
|
|
17
|
+
### 1. 🧠 Cognitive Governance
|
|
18
|
+
Turn your passive database into a living world model. NOORMME implements a closed-loop system where data is distilled, questioned, and evolved.
|
|
19
|
+
- **Semantic Similarity**: Bigram engine for conflict detection.
|
|
20
|
+
- **Curiosity Engine**: Bridges factual gaps and identifies anomalies.
|
|
21
|
+
- **HiveLink**: Promotes local insights to global system wisdom.
|
|
39
22
|
|
|
40
|
-
|
|
23
|
+
### 2. 🧬 Evolutionary DNA
|
|
24
|
+
Allow agents to autonomously mutate their own structural DNA while maintaining 100% safety.
|
|
25
|
+
- **DNA Inversion**: Automatically generates inverse SQL for all autonomous DDL changes.
|
|
26
|
+
- **Self-Healing Indexing**: Proactively optimizes schema based on observed query contexts.
|
|
27
|
+
- **Strategic Mutation**: Sequential evolution loops with autonomous safety rollbacks.
|
|
41
28
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
- **
|
|
29
|
+
### 3. 🚀 Ultra-Scale Orchestration
|
|
30
|
+
Handle massive agentic workloads with high-throughput intelligence.
|
|
31
|
+
- **Tiered Model Routing**: Route batch tasks to Fast LLMs and reasoning to Premium LLMs.
|
|
32
|
+
- **Predictive Pre-warming**: Eliminates latency by optimizing skills in the background.
|
|
33
|
+
- **Bloom Heuristics**: 100x faster fact de-duplication at the ingestion layer.
|
|
45
34
|
|
|
46
35
|
---
|
|
47
36
|
|
|
48
|
-
##
|
|
37
|
+
## 🧠 The Cognitive Loop
|
|
49
38
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
39
|
+
```mermaid
|
|
40
|
+
graph TD
|
|
41
|
+
subgraph "Ingestion & Distillation"
|
|
42
|
+
A[Raw Ingestion] --> B{Bigram Distiller}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
subgraph "Internal Reasoning"
|
|
46
|
+
B --> C[Knowledge Base]
|
|
47
|
+
C --> D[Reasoning Engine]
|
|
48
|
+
D --> E[Action / Outcome]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
subgraph "Evolutionary Feedback"
|
|
52
|
+
E --> F{Cognitive Reflection}
|
|
53
|
+
F -->|Success| G[Goal Reinforcement]
|
|
54
|
+
F -->|Failure| H[DNA Inversion Reset]
|
|
55
|
+
H --> B
|
|
56
|
+
G --> I[HiveLink Promotion]
|
|
57
|
+
I --> B
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
style B fill:#f9f,stroke:#333,stroke-width:2px
|
|
61
|
+
style D fill:#bbf,stroke:#333,stroke-width:2px
|
|
62
|
+
style F fill:#bfb,stroke:#333,stroke-width:2px
|
|
63
|
+
```
|
|
54
64
|
|
|
55
65
|
---
|
|
56
66
|
|
|
57
|
-
##
|
|
67
|
+
## ⚡ Quick Start
|
|
58
68
|
|
|
59
69
|
### 1. Provision the Mind
|
|
60
|
-
Initialize
|
|
70
|
+
Initialize a self-healing database in seconds. Supports SQLite (Local Cortex) and PostgreSQL (Neural Storage).
|
|
61
71
|
|
|
62
72
|
```typescript
|
|
63
73
|
import { NOORMME } from 'noormme';
|
|
64
74
|
|
|
65
75
|
const db = new NOORMME({
|
|
66
|
-
dialect: 'sqlite',
|
|
76
|
+
dialect: 'sqlite', // or 'postgresql'
|
|
67
77
|
connection: { database: './mind.sqlite' },
|
|
68
78
|
agentic: {
|
|
69
79
|
llm: primaryModel,
|
|
70
|
-
llmFast: gpt4oMini,
|
|
71
|
-
llmPremium: claude35, // For complex mutations
|
|
80
|
+
llmFast: gpt4oMini,
|
|
72
81
|
enableSelfEvolution: true
|
|
73
82
|
}
|
|
74
83
|
});
|
|
@@ -76,7 +85,25 @@ const db = new NOORMME({
|
|
|
76
85
|
await db.initialize();
|
|
77
86
|
```
|
|
78
87
|
|
|
79
|
-
### 2.
|
|
88
|
+
### 2. High-Fidelity Data Interaction
|
|
89
|
+
Use the Django-style `objects` manager for sovereign data sifting.
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
// Access a repository
|
|
93
|
+
const agentRepo = db.getRepository('agents');
|
|
94
|
+
|
|
95
|
+
// Chainable query logic
|
|
96
|
+
const activeAgents = await agentRepo.objects
|
|
97
|
+
.filter({ status: 'active', is_verified: true })
|
|
98
|
+
.exclude({ type: 'temporary' })
|
|
99
|
+
.order_by('-last_active')
|
|
100
|
+
.limit(10)
|
|
101
|
+
.all();
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 3. Autonomous Evolution
|
|
105
|
+
Challenge the system with new evidence and let it evolve.
|
|
106
|
+
|
|
80
107
|
```typescript
|
|
81
108
|
const cortex = db.agent.cortex;
|
|
82
109
|
|
|
@@ -89,30 +116,22 @@ await cortex.knowledge.challengeKnowledge('SystemArch', 'New audit results.', 0.
|
|
|
89
116
|
|
|
90
117
|
---
|
|
91
118
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
| Feature | SQLite (Edge) | PostgreSQL (Enterprise) |
|
|
95
|
-
| :--- | :--- | :--- |
|
|
96
|
-
| **Search** | `sqlite-vss` / Fallback | `pgvector` / FTS |
|
|
97
|
-
| **Logic** | In-Process Atomicity | Multi-Tenant Governance |
|
|
98
|
-
| **Evolution** | Sequential Snapshotting | Clustered Mutation |
|
|
99
|
-
| **Throughput** | Sequential Direct | Bloom-Heuristic Parallel |
|
|
100
|
-
|
|
101
|
-
---
|
|
119
|
+

|
|
102
120
|
|
|
103
|
-
## 📚
|
|
104
|
-
|
|
121
|
+
## 📚 Deep Dive Documentation
|
|
122
|
+
Explore our comprehensive guides to unlock the full potential of your agents:
|
|
105
123
|
|
|
106
|
-
- [**
|
|
107
|
-
- [**
|
|
108
|
-
- [**
|
|
109
|
-
- [**
|
|
110
|
-
- [**
|
|
124
|
+
- [**Full Documentation Index**](./docs/README.md) – Start here for the complete guide.
|
|
125
|
+
- [**Agentic Intelligence**](./docs/agentic-intelligence.md) – Cognitive rules and governance.
|
|
126
|
+
- [**PostgreSQL Neural Storage**](./docs/postgresql/POSTGRESQL_SUPPORT.md) – Enterprise-grade scaling and `pgvector`.
|
|
127
|
+
- [**Ultra-Scale Orchestration**](./docs/ultra-scale-orchestration.md) – Massive scale patterns.
|
|
128
|
+
- [**Strategic Evolution**](./docs/strategic-evolution.md) – DNA inversion and mutation.
|
|
129
|
+
- [**Skill Lifecycle**](./docs/skill-lifecycle.md) – How agents learn and grow.
|
|
111
130
|
|
|
112
131
|
---
|
|
113
132
|
|
|
114
|
-
## 🤝 Community
|
|
115
|
-
NOORMME is an Apache 2.0 open-source project. We invite
|
|
133
|
+
## 🤝 Community
|
|
134
|
+
NOORMME is an Apache 2.0 open-source project. We invite researchers to contribute to the future of autonomous persistence.
|
|
116
135
|
|
|
117
136
|
[Contribution Guide](CONTRIBUTING.md) | [Security Audit](SECURITY.md)
|
|
118
137
|
|
|
@@ -31,7 +31,7 @@ class ActionJournal {
|
|
|
31
31
|
tool_name: toolName,
|
|
32
32
|
arguments: JSON.stringify(args),
|
|
33
33
|
status: 'pending',
|
|
34
|
-
created_at: new Date()
|
|
34
|
+
created_at: new Date(),
|
|
35
35
|
})
|
|
36
36
|
.returningAll()
|
|
37
37
|
.executeTakeFirstOrThrow();
|
|
@@ -52,7 +52,7 @@ class ActionJournal {
|
|
|
52
52
|
status,
|
|
53
53
|
outcome,
|
|
54
54
|
duration_ms: durationMs || null,
|
|
55
|
-
metadata: metadata ? JSON.stringify(metadata) : null
|
|
55
|
+
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
56
56
|
})
|
|
57
57
|
.where('id', '=', actionId)
|
|
58
58
|
.returningAll()
|
|
@@ -76,7 +76,7 @@ class ActionJournal {
|
|
|
76
76
|
.where('session_id', '=', sessionId)
|
|
77
77
|
.orderBy('created_at', 'asc')
|
|
78
78
|
.execute();
|
|
79
|
-
return actions.map(a => this.parseAction(a));
|
|
79
|
+
return actions.map((a) => this.parseAction(a));
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
82
|
* Get actions by tool name across all sessions.
|
|
@@ -89,7 +89,7 @@ class ActionJournal {
|
|
|
89
89
|
.orderBy('created_at', 'desc')
|
|
90
90
|
.limit(limit)
|
|
91
91
|
.execute();
|
|
92
|
-
return actions.map(a => this.parseAction(a));
|
|
92
|
+
return actions.map((a) => this.parseAction(a));
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* Generate a report of tool failures.
|
|
@@ -100,7 +100,7 @@ class ActionJournal {
|
|
|
100
100
|
.select([
|
|
101
101
|
'tool_name',
|
|
102
102
|
(eb) => eb.fn.count('id').as('failureCount'),
|
|
103
|
-
(eb) => eb.fn.max('created_at').as('lastFailure')
|
|
103
|
+
(eb) => eb.fn.max('created_at').as('lastFailure'),
|
|
104
104
|
])
|
|
105
105
|
.where('status', '=', 'failure')
|
|
106
106
|
.groupBy('tool_name')
|
|
@@ -109,7 +109,7 @@ class ActionJournal {
|
|
|
109
109
|
return results.map((r) => ({
|
|
110
110
|
toolName: r.tool_name,
|
|
111
111
|
failureCount: Number(r.failureCount),
|
|
112
|
-
lastFailure: r.lastFailure
|
|
112
|
+
lastFailure: r.lastFailure,
|
|
113
113
|
}));
|
|
114
114
|
}
|
|
115
115
|
parseAction(action) {
|
|
@@ -118,12 +118,16 @@ class ActionJournal {
|
|
|
118
118
|
sessionId: action.session_id,
|
|
119
119
|
messageId: action.message_id,
|
|
120
120
|
toolName: action.tool_name,
|
|
121
|
-
arguments: typeof action.arguments === 'string'
|
|
121
|
+
arguments: typeof action.arguments === 'string'
|
|
122
|
+
? JSON.parse(action.arguments)
|
|
123
|
+
: action.arguments || {},
|
|
122
124
|
status: action.status,
|
|
123
125
|
outcome: action.outcome,
|
|
124
126
|
durationMs: action.duration_ms,
|
|
125
|
-
metadata: typeof action.metadata === 'string'
|
|
126
|
-
|
|
127
|
+
metadata: typeof action.metadata === 'string'
|
|
128
|
+
? JSON.parse(action.metadata)
|
|
129
|
+
: action.metadata || {},
|
|
130
|
+
createdAt: new Date(action.created_at),
|
|
127
131
|
};
|
|
128
132
|
}
|
|
129
133
|
}
|
|
@@ -21,7 +21,7 @@ class CapabilityManager {
|
|
|
21
21
|
rollbackThresholdZ: config.evolution?.rollbackThresholdZ ?? 2.5,
|
|
22
22
|
enableHiveLink: config.evolution?.enableHiveLink ?? true,
|
|
23
23
|
mutationAggressiveness: config.evolution?.mutationAggressiveness ?? 0.5,
|
|
24
|
-
maxSandboxSkills: config.evolution?.maxSandboxSkills ?? 5
|
|
24
|
+
maxSandboxSkills: config.evolution?.maxSandboxSkills ?? 5,
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
get typedDb() {
|
|
@@ -44,8 +44,11 @@ class CapabilityManager {
|
|
|
44
44
|
.set({
|
|
45
45
|
description: description || existing.description,
|
|
46
46
|
status: existing.status || 'experimental',
|
|
47
|
-
metadata: JSON.stringify({
|
|
48
|
-
|
|
47
|
+
metadata: JSON.stringify({
|
|
48
|
+
...JSON.parse(existing.metadata || '{}'),
|
|
49
|
+
...metadata,
|
|
50
|
+
}),
|
|
51
|
+
updated_at: new Date(),
|
|
49
52
|
})
|
|
50
53
|
.where('id', '=', existing.id)
|
|
51
54
|
.returningAll()
|
|
@@ -60,9 +63,13 @@ class CapabilityManager {
|
|
|
60
63
|
description: description || null,
|
|
61
64
|
status: metadata.initialStatus || 'experimental',
|
|
62
65
|
reliability: 1.0,
|
|
63
|
-
metadata: JSON.stringify({
|
|
66
|
+
metadata: JSON.stringify({
|
|
67
|
+
...metadata,
|
|
68
|
+
successCount: 0,
|
|
69
|
+
totalCount: 0,
|
|
70
|
+
}),
|
|
64
71
|
created_at: new Date(),
|
|
65
|
-
updated_at: new Date()
|
|
72
|
+
updated_at: new Date(),
|
|
66
73
|
})
|
|
67
74
|
.returningAll()
|
|
68
75
|
.executeTakeFirstOrThrow();
|
|
@@ -83,7 +90,9 @@ class CapabilityManager {
|
|
|
83
90
|
.executeTakeFirst();
|
|
84
91
|
if (capability) {
|
|
85
92
|
const cap = capability;
|
|
86
|
-
const metadata = typeof cap.metadata === 'string'
|
|
93
|
+
const metadata = typeof cap.metadata === 'string'
|
|
94
|
+
? JSON.parse(cap.metadata)
|
|
95
|
+
: cap.metadata || {};
|
|
87
96
|
const totalCount = (metadata.totalCount || 0) + 1;
|
|
88
97
|
const successCount = (metadata.successCount || 0) + (success ? 1 : 0);
|
|
89
98
|
// Damped moving average: weight recent outcomes more but keep history
|
|
@@ -102,34 +111,39 @@ class CapabilityManager {
|
|
|
102
111
|
const windowSize = this.evolutionConfig.verificationWindow || 20;
|
|
103
112
|
const minSampleSize = Math.ceil(windowSize * 0.75);
|
|
104
113
|
// Fast-Track Promotion: 5 consecutive successes bypasses sample size
|
|
105
|
-
const isPromotable = (totalCount >= minSampleSize && winRate >= 0.8) ||
|
|
114
|
+
const isPromotable = (totalCount >= minSampleSize && winRate >= 0.8) || streakSuccess >= 5;
|
|
106
115
|
// Early-Exit Rollback: 3 consecutive failures at the start immediately blacklists
|
|
107
116
|
const isCatastrophic = !success && failureStreak >= 3 && totalCount <= 5;
|
|
108
117
|
// Pass 6: Predictive Pre-warming Trigger
|
|
109
118
|
// If a skill is close to promotion, pre-warm its optimized description
|
|
110
119
|
const promoThreshold = Math.ceil(minSampleSize * 0.8);
|
|
111
|
-
const isNearingPromotion = (totalCount >= promoThreshold && winRate >= 0.8) ||
|
|
112
|
-
|
|
120
|
+
const isNearingPromotion = (totalCount >= promoThreshold && winRate >= 0.8) ||
|
|
121
|
+
streakSuccess === 4;
|
|
122
|
+
if (isNearingPromotion &&
|
|
123
|
+
newStatus === 'experimental' &&
|
|
124
|
+
this.cortex.skillSynthesizer) {
|
|
113
125
|
// Trigger async background pre-warming
|
|
114
126
|
this.cortex.skillSynthesizer.preWarmSkill(name).catch(() => { });
|
|
115
127
|
}
|
|
116
128
|
// --- Production Hardening: Dynamic Performance Baselining ---
|
|
117
129
|
const historyAlpha = 0.05; // Slower moving average for baseline
|
|
118
130
|
const baseline = metadata.performanceBaseline ?? winRate;
|
|
119
|
-
const newBaseline =
|
|
131
|
+
const newBaseline = baseline * (1 - historyAlpha) + winRate * historyAlpha;
|
|
120
132
|
// Variance tracking for Z-score calculation
|
|
121
133
|
const variance = metadata.performanceVariance ?? 0.01;
|
|
122
134
|
const diff = winRate - baseline;
|
|
123
|
-
const newVariance =
|
|
135
|
+
const newVariance = variance * (1 - historyAlpha) + Math.pow(diff, 2) * historyAlpha;
|
|
124
136
|
const stdDev = Math.sqrt(newVariance);
|
|
125
137
|
// Z-Score: How many standard deviations is current performance from baseline?
|
|
126
138
|
const zScore = stdDev > 0 ? (winRate - baseline) / stdDev : 0;
|
|
127
139
|
// Promotion/Demotion Logic
|
|
128
|
-
if (isCatastrophic &&
|
|
140
|
+
if (isCatastrophic &&
|
|
141
|
+
(newStatus === 'experimental' || newStatus === 'sandbox')) {
|
|
129
142
|
console.error(`[CapabilityManager] Skill '${name}' FAILED early-exit safety check (Streak: ${failureStreak}). Blacklisting immediately.`);
|
|
130
143
|
newStatus = 'blacklisted';
|
|
131
144
|
}
|
|
132
|
-
else if (isPromotable &&
|
|
145
|
+
else if (isPromotable &&
|
|
146
|
+
(newStatus === 'experimental' || newStatus === 'sandbox')) {
|
|
133
147
|
console.log(`[CapabilityManager] Skill '${name}' PASSED fast-track verification (Streak: ${streakSuccess}, Rate: ${(winRate * 100).toFixed(1)}%). Promoting to Verified.`);
|
|
134
148
|
newStatus = 'verified';
|
|
135
149
|
}
|
|
@@ -160,9 +174,9 @@ class CapabilityManager {
|
|
|
160
174
|
failureStreak,
|
|
161
175
|
performanceBaseline: newBaseline,
|
|
162
176
|
performanceVariance: newVariance,
|
|
163
|
-
lastOutcomeType: success ? 'success' : 'failure' // Categorization point
|
|
177
|
+
lastOutcomeType: success ? 'success' : 'failure', // Categorization point
|
|
164
178
|
}),
|
|
165
|
-
updated_at: new Date()
|
|
179
|
+
updated_at: new Date(),
|
|
166
180
|
})
|
|
167
181
|
.where('id', '=', cap.id)
|
|
168
182
|
.execute();
|
|
@@ -191,10 +205,8 @@ class CapabilityManager {
|
|
|
191
205
|
if (status) {
|
|
192
206
|
query = query.where('status', '=', status);
|
|
193
207
|
}
|
|
194
|
-
const list = await query
|
|
195
|
-
|
|
196
|
-
.execute();
|
|
197
|
-
return list.map(c => this.parseCapability(c));
|
|
208
|
+
const list = await query.orderBy('name', 'asc').execute();
|
|
209
|
+
return list.map((c) => this.parseCapability(c));
|
|
198
210
|
}
|
|
199
211
|
parseCapability(cap) {
|
|
200
212
|
return {
|
|
@@ -204,9 +216,11 @@ class CapabilityManager {
|
|
|
204
216
|
description: cap.description,
|
|
205
217
|
status: cap.status || 'experimental',
|
|
206
218
|
reliability: cap.reliability,
|
|
207
|
-
metadata: typeof cap.metadata === 'string'
|
|
219
|
+
metadata: typeof cap.metadata === 'string'
|
|
220
|
+
? JSON.parse(cap.metadata)
|
|
221
|
+
: cap.metadata || {},
|
|
208
222
|
createdAt: new Date(cap.created_at),
|
|
209
|
-
updatedAt: new Date(cap.updated_at)
|
|
223
|
+
updatedAt: new Date(cap.updated_at),
|
|
210
224
|
};
|
|
211
225
|
}
|
|
212
226
|
}
|
|
@@ -20,16 +20,18 @@ class CognitiveRepository {
|
|
|
20
20
|
*/
|
|
21
21
|
async triggerRules(operation, data) {
|
|
22
22
|
// Check if rules table exists to avoid errors during initialization
|
|
23
|
-
const rulesTable = this.cortex.config.agentic?.rulesTable ||
|
|
23
|
+
const rulesTable = this.cortex.config.agentic?.rulesTable ||
|
|
24
|
+
this.cortex.config.rulesTable ||
|
|
25
|
+
'agent_rules';
|
|
24
26
|
const tables = await this.cortex.db.introspection.getTables();
|
|
25
|
-
if (!tables.some(t => t.name === rulesTable)) {
|
|
27
|
+
if (!tables.some((t) => t.name === rulesTable)) {
|
|
26
28
|
return data;
|
|
27
29
|
}
|
|
28
30
|
const result = await this.cortex.rules.evaluateRules(this.table.name, operation, data);
|
|
29
31
|
if (result.action === 'deny') {
|
|
30
32
|
throw new NoormError_js_1.NoormError(`Operation ${operation} on ${this.table.name} denied: ${result.reason}`, {
|
|
31
33
|
operation: 'cognitive_rule_enforcement',
|
|
32
|
-
suggestion: 'Check agent rules or adjust policy'
|
|
34
|
+
suggestion: 'Check agent rules or adjust policy',
|
|
33
35
|
});
|
|
34
36
|
}
|
|
35
37
|
if (result.action === 'audit') {
|
|
@@ -37,7 +39,7 @@ class CognitiveRepository {
|
|
|
37
39
|
}
|
|
38
40
|
if (result.action === 'mask' && result.ruleId) {
|
|
39
41
|
const rules = await this.cortex.rules.getActiveRules(this.table.name, operation);
|
|
40
|
-
const rule = rules.find(r => r.id === result.ruleId);
|
|
42
|
+
const rule = rules.find((r) => r.id === result.ruleId);
|
|
41
43
|
if (rule) {
|
|
42
44
|
return this.cortex.rules.applyMasking(data, rule);
|
|
43
45
|
}
|
|
@@ -57,10 +59,18 @@ class CognitiveRepository {
|
|
|
57
59
|
return await this.repository.delete(id);
|
|
58
60
|
}
|
|
59
61
|
// Delegate other methods to the internal repository
|
|
60
|
-
async findById(id) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
async
|
|
62
|
+
async findById(id) {
|
|
63
|
+
return this.repository.findById(id);
|
|
64
|
+
}
|
|
65
|
+
async findAll() {
|
|
66
|
+
return this.repository.findAll();
|
|
67
|
+
}
|
|
68
|
+
async count() {
|
|
69
|
+
return this.repository.count();
|
|
70
|
+
}
|
|
71
|
+
async exists(id) {
|
|
72
|
+
return this.repository.exists(id);
|
|
73
|
+
}
|
|
64
74
|
// Dynamic method delegation via Proxy
|
|
65
75
|
static createProxy(repository, table, cortex) {
|
|
66
76
|
const cognitive = new CognitiveRepository(repository, table, cortex);
|
|
@@ -70,7 +80,7 @@ class CognitiveRepository {
|
|
|
70
80
|
return cognitive[prop];
|
|
71
81
|
}
|
|
72
82
|
return Reflect.get(target, prop, receiver);
|
|
73
|
-
}
|
|
83
|
+
},
|
|
74
84
|
});
|
|
75
85
|
}
|
|
76
86
|
}
|
|
@@ -52,7 +52,7 @@ class ContextBuffer {
|
|
|
52
52
|
msg: m,
|
|
53
53
|
index,
|
|
54
54
|
isAnchor: !!m.metadata?.anchor,
|
|
55
|
-
tokens: this.estimateTokens(m.content)
|
|
55
|
+
tokens: this.estimateTokens(m.content),
|
|
56
56
|
}));
|
|
57
57
|
const sortedForSelection = [...scored].sort((a, b) => {
|
|
58
58
|
if (a.isAnchor !== b.isAnchor)
|
|
@@ -60,15 +60,18 @@ class ContextBuffer {
|
|
|
60
60
|
return b.index - a.index; // Recency tie-breaker
|
|
61
61
|
});
|
|
62
62
|
const selected = new Set();
|
|
63
|
-
let currentTokens = systemMessage
|
|
63
|
+
let currentTokens = systemMessage
|
|
64
|
+
? this.estimateTokens(systemMessage.content)
|
|
65
|
+
: 0;
|
|
64
66
|
for (const item of sortedForSelection) {
|
|
65
|
-
if (selected.size < effectiveLimit &&
|
|
67
|
+
if (selected.size < effectiveLimit &&
|
|
68
|
+
currentTokens + item.tokens <= tokenLimit) {
|
|
66
69
|
selected.add(item.msg);
|
|
67
70
|
currentTokens += item.tokens;
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
73
|
// Maintain temporal order
|
|
71
|
-
const result = this.messages.filter(m => m === systemMessage || selected.has(m));
|
|
74
|
+
const result = this.messages.filter((m) => m === systemMessage || selected.has(m));
|
|
72
75
|
return result;
|
|
73
76
|
}
|
|
74
77
|
/**
|
|
@@ -76,14 +79,14 @@ class ContextBuffer {
|
|
|
76
79
|
*/
|
|
77
80
|
toPromptString(limit) {
|
|
78
81
|
return this.getWindow({ maxMessages: limit })
|
|
79
|
-
.map(m => `[${m.role.toUpperCase()}]: ${m.content}`)
|
|
82
|
+
.map((m) => `[${m.role.toUpperCase()}]: ${m.content}`)
|
|
80
83
|
.join('\n\n');
|
|
81
84
|
}
|
|
82
85
|
/**
|
|
83
86
|
* Helper to identify if the buffer is becoming too large.
|
|
84
87
|
*/
|
|
85
88
|
shouldSummarize(tokenThreshold) {
|
|
86
|
-
const threshold = tokenThreshold ||
|
|
89
|
+
const threshold = tokenThreshold || this.maxTokens * 0.8;
|
|
87
90
|
return this.getTotalTokens() > threshold;
|
|
88
91
|
}
|
|
89
92
|
/**
|
|
@@ -94,7 +97,7 @@ class ContextBuffer {
|
|
|
94
97
|
messageCount: this.messages.length,
|
|
95
98
|
totalTokens: this.getTotalTokens(),
|
|
96
99
|
maxTokens: this.maxTokens,
|
|
97
|
-
maxMessages: this.maxMessages
|
|
100
|
+
maxMessages: this.maxMessages,
|
|
98
101
|
};
|
|
99
102
|
}
|
|
100
103
|
getTotalTokens() {
|
|
@@ -107,28 +110,37 @@ class ContextBuffer {
|
|
|
107
110
|
const initialCount = this.messages.length;
|
|
108
111
|
// Importance Trimming: Prefer keeping 'anchor' messages or high-priority messages
|
|
109
112
|
// We sort a copy to determine which ones to keep, then reconstruct in temporal order
|
|
110
|
-
const otherMessages = systemMessage
|
|
113
|
+
const otherMessages = systemMessage
|
|
114
|
+
? this.messages.slice(1)
|
|
115
|
+
: this.messages;
|
|
111
116
|
// Heuristic for importance: anchors > assistant > user (user input is often redundant if reflected/anchored)
|
|
112
117
|
const sortedByImportance = [...otherMessages].sort((a, b) => {
|
|
113
118
|
const aIsAnchor = a.metadata?.anchor ? 1 : 0;
|
|
114
119
|
const bIsAnchor = b.metadata?.anchor ? 1 : 0;
|
|
115
120
|
if (aIsAnchor !== bIsAnchor)
|
|
116
121
|
return bIsAnchor - aIsAnchor;
|
|
117
|
-
const rolePriority = {
|
|
122
|
+
const rolePriority = {
|
|
123
|
+
system: 3,
|
|
124
|
+
assistant: 2,
|
|
125
|
+
user: 1,
|
|
126
|
+
action: 2,
|
|
127
|
+
};
|
|
118
128
|
return (rolePriority[b.role] || 0) - (rolePriority[a.role] || 0);
|
|
119
129
|
});
|
|
120
130
|
const toKeep = new Set(sortedByImportance.slice(0, this.maxMessages));
|
|
121
|
-
this.messages = this.messages.filter(m => m === systemMessage || toKeep.has(m));
|
|
131
|
+
this.messages = this.messages.filter((m) => m === systemMessage || toKeep.has(m));
|
|
122
132
|
console.log(`[ContextBuffer] Importance Trimming: ${initialCount} -> ${this.messages.length} messages. preserved anchors and assistant reasoning.`);
|
|
123
133
|
}
|
|
124
134
|
}
|
|
125
135
|
estimateTokens(content) {
|
|
126
136
|
if (!content)
|
|
127
137
|
return 0;
|
|
128
|
-
// More sophisticated heuristic:
|
|
138
|
+
// More sophisticated heuristic:
|
|
129
139
|
// - JSON/Code tends to have more tokens per character due to symbols.
|
|
130
140
|
// - Natural language is ~4 chars per token.
|
|
131
|
-
const isStructured = content.startsWith('{') ||
|
|
141
|
+
const isStructured = content.startsWith('{') ||
|
|
142
|
+
content.startsWith('[') ||
|
|
143
|
+
content.includes('```');
|
|
132
144
|
const ratio = isStructured ? 3 : 4;
|
|
133
145
|
return Math.ceil(content.length / ratio);
|
|
134
146
|
}
|
|
@@ -84,7 +84,9 @@ class Cortex {
|
|
|
84
84
|
this.llmPremium = agenticConfig.llmPremium || this.llm;
|
|
85
85
|
this.telemetry = new TelemetryOrchestrator_js_1.TelemetryOrchestrator(db, agenticConfig);
|
|
86
86
|
this.sessions = new SessionManager_js_1.SessionManager(db, agenticConfig, this.telemetry);
|
|
87
|
-
this.buffer = new ContextBuffer_js_1.ContextBuffer({
|
|
87
|
+
this.buffer = new ContextBuffer_js_1.ContextBuffer({
|
|
88
|
+
maxMessages: agenticConfig.contextWindowSize,
|
|
89
|
+
});
|
|
88
90
|
this.vectors = agenticConfig.vectorConfig
|
|
89
91
|
? new VectorIndexer_js_1.VectorIndexer(db, agenticConfig.vectorConfig, agenticConfig.memoriesTable)
|
|
90
92
|
: null;
|
|
@@ -150,7 +152,9 @@ class Cortex {
|
|
|
150
152
|
catch (err) {
|
|
151
153
|
console.error('[Cortex] Soul-Searching loop failed:', err);
|
|
152
154
|
// Telemetry: track failure
|
|
153
|
-
await this.telemetry.track('system', 'error', 'Self-iteration failed', {
|
|
155
|
+
await this.telemetry.track('system', 'error', 'Self-iteration failed', {
|
|
156
|
+
error: String(err),
|
|
157
|
+
});
|
|
154
158
|
}
|
|
155
159
|
}
|
|
156
160
|
/**
|
|
@@ -167,8 +171,11 @@ class Cortex {
|
|
|
167
171
|
async recordInteraction(sessionId, role, content, options = {}) {
|
|
168
172
|
const message = await this.sessions.addMessage(sessionId, role, content);
|
|
169
173
|
// Telemetry: Track prompt and output
|
|
170
|
-
const type = role === 'user' ? 'prompt' :
|
|
171
|
-
await this.telemetry.track(sessionId, type, content, {
|
|
174
|
+
const type = role === 'user' ? 'prompt' : role === 'assistant' ? 'output' : 'action';
|
|
175
|
+
await this.telemetry.track(sessionId, type, content, {
|
|
176
|
+
role,
|
|
177
|
+
messageId: message.id,
|
|
178
|
+
});
|
|
172
179
|
if (options.index && options.embedding && this.vectors) {
|
|
173
180
|
await this.vectors.addMemory(content, options.embedding, sessionId);
|
|
174
181
|
}
|
|
@@ -28,7 +28,7 @@ class EpisodicMemory {
|
|
|
28
28
|
name,
|
|
29
29
|
status: 'active',
|
|
30
30
|
start_time: new Date(),
|
|
31
|
-
metadata: metadata ? JSON.stringify(metadata) : null
|
|
31
|
+
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
32
32
|
})
|
|
33
33
|
.returningAll()
|
|
34
34
|
.executeTakeFirstOrThrow();
|
|
@@ -54,7 +54,7 @@ class EpisodicMemory {
|
|
|
54
54
|
status: 'completed',
|
|
55
55
|
summary,
|
|
56
56
|
end_time: new Date(),
|
|
57
|
-
metadata: JSON.stringify(newMeta)
|
|
57
|
+
metadata: JSON.stringify(newMeta),
|
|
58
58
|
})
|
|
59
59
|
.where('id', '=', episodeId)
|
|
60
60
|
.returningAll()
|
|
@@ -72,7 +72,7 @@ class EpisodicMemory {
|
|
|
72
72
|
.where('session_id', '=', sessionId)
|
|
73
73
|
.orderBy('start_time', 'desc')
|
|
74
74
|
.execute();
|
|
75
|
-
return list.map(e => this.parseEpisode(e));
|
|
75
|
+
return list.map((e) => this.parseEpisode(e));
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* Get recently completed episodes across all sessions.
|
|
@@ -85,7 +85,7 @@ class EpisodicMemory {
|
|
|
85
85
|
.orderBy('end_time', 'desc')
|
|
86
86
|
.limit(limit)
|
|
87
87
|
.execute();
|
|
88
|
-
return list.map(e => this.parseEpisode(e));
|
|
88
|
+
return list.map((e) => this.parseEpisode(e));
|
|
89
89
|
}
|
|
90
90
|
parseEpisode(episode) {
|
|
91
91
|
return {
|
|
@@ -96,7 +96,9 @@ class EpisodicMemory {
|
|
|
96
96
|
status: episode.status,
|
|
97
97
|
startTime: new Date(episode.start_time),
|
|
98
98
|
endTime: episode.end_time ? new Date(episode.end_time) : undefined,
|
|
99
|
-
metadata: typeof episode.metadata === 'string'
|
|
99
|
+
metadata: typeof episode.metadata === 'string'
|
|
100
|
+
? JSON.parse(episode.metadata)
|
|
101
|
+
: episode.metadata || {},
|
|
100
102
|
};
|
|
101
103
|
}
|
|
102
104
|
}
|