@aleph-ai/tinyaleph 1.7.2 → 1.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -486,6 +486,35 @@ class BioinformaticsBackend extends Backend {
486
486
  }
487
487
  }
488
488
 
489
+ // Re-export encoding named exports
490
+ export {
491
+ NUCLEOTIDE_PRIMES,
492
+ AMINO_ACID_PRIMES,
493
+ encodeDNA,
494
+ decodeDNA,
495
+ encodeRNA,
496
+ decodeRNA,
497
+ encodeProtein,
498
+ decodeProtein,
499
+ } from './encoding.js';
500
+
501
+ // Named exports for classes and DNA computing
502
+ const { BindingAffinityCalculator } = binding;
503
+ const { DNAStrand, ANDGate, ORGate, NOTGate, DNACircuit } = dnaComputing;
504
+
505
+ export {
506
+ BioinformaticsBackend,
507
+ TranscriptionOperator,
508
+ TranslationOperator,
509
+ FoldingTransform,
510
+ BindingAffinityCalculator,
511
+ DNAStrand,
512
+ ANDGate,
513
+ ORGate,
514
+ NOTGate,
515
+ DNACircuit,
516
+ };
517
+
489
518
  // Export everything
490
519
  export default {
491
520
  // Main backend
package/backends/index.js CHANGED
@@ -4,8 +4,8 @@
4
4
 
5
5
  import { Backend } from './interface.js';
6
6
  import SemanticBackend from './semantic/index.js';
7
- import CryptographicBackend from './cryptographic/index.js';
8
- import ScientificBackend from './scientific/index.js';
7
+ import { CryptographicBackend } from './cryptographic/index.js';
8
+ import { ScientificBackend } from './scientific/index.js';
9
9
 
10
10
  import bioinformatics from './bioinformatics/index.js';
11
11
 
@@ -0,0 +1,141 @@
1
+ /**
2
+ * E8 Root System
3
+ *
4
+ * 240 roots in 8D Euclidean space.
5
+ * Uses scaled coordinates (x2) to avoid floating point issues.
6
+ * - Integer roots: coordinates are ±2 or 0.
7
+ * - Half-integer roots: coordinates are ±1.
8
+ *
9
+ * All roots have squared norm 8 (in scaled units), which corresponds to 2 in standard units.
10
+ */
11
+ export class E8RootSystem {
12
+ constructor() {
13
+ this.roots = []; // Array<Int8Array(8)>
14
+ this.rootIndex = new Map(); // Map<string, number>
15
+ this.negationTable = [];
16
+
17
+ this._initialize();
18
+ }
19
+
20
+ _initialize() {
21
+ this.roots = this._generateAllRoots();
22
+ this.rootIndex = new Map(this.roots.map((r, i) => [r.join(','), i]));
23
+ this.negationTable = this._computeNegationTable();
24
+ this._verifyInvariants();
25
+ }
26
+
27
+ _generateAllRoots() {
28
+ const roots = [];
29
+
30
+ // Type I: Integer roots (±e_i ±e_j) -> Scaled: ±2 at two positions
31
+ // C(8, 2) * 4 = 28 * 4 = 112
32
+ for (let i = 0; i < 8; i++) {
33
+ for (let j = i + 1; j < 8; j++) {
34
+ for (const si of [2, -2]) {
35
+ for (const sj of [2, -2]) {
36
+ const v = new Int8Array(8);
37
+ v[i] = si;
38
+ v[j] = sj;
39
+ roots.push(v);
40
+ }
41
+ }
42
+ }
43
+ }
44
+
45
+ // Type II: Half-integer roots (±1/2) -> Scaled: ±1 everywhere
46
+ // Must have even number of negative signs.
47
+ // 2^8 = 256 combinations. Half are even -> 128.
48
+ for (let i = 0; i < 256; i++) {
49
+ const v = new Int8Array(8);
50
+ let negCount = 0;
51
+ for (let bit = 0; bit < 8; bit++) {
52
+ if ((i >> bit) & 1) {
53
+ v[bit] = -1;
54
+ negCount++;
55
+ } else {
56
+ v[bit] = 1;
57
+ }
58
+ }
59
+ if (negCount % 2 === 0) {
60
+ roots.push(v);
61
+ }
62
+ }
63
+
64
+ return roots;
65
+ }
66
+
67
+ _computeNegationTable() {
68
+ return this.roots.map(r => {
69
+ const neg = r.map(x => -x);
70
+ const key = neg.join(',');
71
+ if (!this.rootIndex.has(key)) {
72
+ throw new Error(`Negation of root ${r} not found`);
73
+ }
74
+ return this.rootIndex.get(key);
75
+ });
76
+ }
77
+
78
+ _verifyInvariants() {
79
+ if (this.roots.length !== 240) {
80
+ throw new Error(`E8 must have 240 roots, got ${this.roots.length}`);
81
+ }
82
+ // Verify norms
83
+ for (const r of this.roots) {
84
+ const sqNorm = r.reduce((acc, x) => acc + x * x, 0);
85
+ if (sqNorm !== 8) {
86
+ throw new Error(`Root ${r} has invalid squared norm ${sqNorm} (expected 8)`);
87
+ }
88
+ }
89
+ }
90
+
91
+ // Public API
92
+
93
+ get numRoots() { return this.roots.length; }
94
+
95
+ getRoot(i) { return this.roots[i]; }
96
+
97
+ getNegation(i) { return this.negationTable[i]; }
98
+
99
+ innerProduct(i, j) {
100
+ const r1 = this.roots[i];
101
+ const r2 = this.roots[j];
102
+ let sum = 0;
103
+ for (let k = 0; k < 8; k++) sum += r1[k] * r2[k];
104
+ // Scale down: real inner product is sum / 4 (since each vec is scaled by 2)
105
+ return sum / 4;
106
+ }
107
+
108
+ /**
109
+ * Get the 8 simple roots (Standard basis).
110
+ * Scaled by 2.
111
+ */
112
+ getSimpleRoots() {
113
+ const simple = [];
114
+
115
+ // α₁ through α₆: e_i - e_{i+1} (scaled by 2)
116
+ for (let i = 0; i < 6; i++) {
117
+ const v = new Int8Array(8);
118
+ v[i] = 2;
119
+ v[i+1] = -2;
120
+ simple.push(v);
121
+ }
122
+
123
+ // α₇ = e₆ - e₇ (scaled by 2)
124
+ const v6 = new Int8Array(8);
125
+ v6[5] = 2;
126
+ v6[6] = -2;
127
+ simple.push(v6);
128
+
129
+ // α₈ = e₇ + e₈ (scaled by 2)
130
+ const a7 = new Int8Array(8);
131
+ a7[6] = 2;
132
+ a7[7] = 2;
133
+ simple.push(a7);
134
+
135
+ // α₉ = ½(-1, -1, ..., -1) (scaled by 2 → all -1)
136
+ const a8 = new Int8Array(8).fill(-1);
137
+ simple.push(a8);
138
+
139
+ return simple;
140
+ }
141
+ }
@@ -0,0 +1,162 @@
1
+ import { Label } from './label.js';
2
+
3
+ const ATLAS_VERTEX_COUNT = 96;
4
+
5
+ /**
6
+ * Atlas of Resonance Classes
7
+ *
8
+ * A 96-vertex graph representing the stationary configuration of the
9
+ * action functional. It is the initial object for exceptional Lie groups.
10
+ */
11
+ export class Atlas {
12
+ constructor() {
13
+ this.labels = []; // Array<Label>
14
+ this.labelIndex = new Map(); // Map<string, number> (label.toString() -> index)
15
+ this.adjacency = []; // Array<Set<number>>
16
+ this.tau = []; // Array<number> (mirror pairs)
17
+ this.unityIndices = []; // Array<number>
18
+
19
+ this._initialize();
20
+ }
21
+
22
+ _initialize() {
23
+ this.labels = this._generateLabels();
24
+ this.labelIndex = new Map(this.labels.map((l, i) => [l.toString(), i]));
25
+ this.adjacency = this._buildAdjacency();
26
+ this.tau = this._computeTau();
27
+ this.unityIndices = this._findUnityPositions();
28
+
29
+ this._verifyInvariants();
30
+ }
31
+
32
+ /**
33
+ * Generate all 96 canonical labels.
34
+ */
35
+ _generateLabels() {
36
+ const labels = [];
37
+ for (let e1 = 0; e1 <= 1; e1++) {
38
+ for (let e2 = 0; e2 <= 1; e2++) {
39
+ for (let e3 = 0; e3 <= 1; e3++) {
40
+ for (let e6 = 0; e6 <= 1; e6++) {
41
+ for (let e7 = 0; e7 <= 1; e7++) {
42
+ for (let d45 = -1; d45 <= 1; d45++) {
43
+ labels.push(new Label(e1, e2, e3, d45, e6, e7));
44
+ }
45
+ }
46
+ }
47
+ }
48
+ }
49
+ }
50
+ return labels;
51
+ }
52
+
53
+ /**
54
+ * Build adjacency list based on Hamming-1 flips.
55
+ */
56
+ _buildAdjacency() {
57
+ const adjacency = new Array(this.labels.length).fill(null).map(() => new Set());
58
+
59
+ this.labels.forEach((label, i) => {
60
+ const neighbors = this._computeNeighbors(label);
61
+ for (const neighbor of neighbors) {
62
+ const key = neighbor.toString();
63
+ if (this.labelIndex.has(key)) {
64
+ const j = this.labelIndex.get(key);
65
+ if (i !== j) {
66
+ adjacency[i].add(j);
67
+ }
68
+ }
69
+ }
70
+ });
71
+
72
+ return adjacency;
73
+ }
74
+
75
+ /**
76
+ * Compute neighbors for a single label.
77
+ * Flips e1, e2, e3, e6, or e4/e5 (via d45). e7 is NOT flipped (mirror).
78
+ */
79
+ _computeNeighbors(label) {
80
+ const { e1, e2, e3, d45, e6, e7 } = label;
81
+ const neighbors = [];
82
+
83
+ // Flip e1, e2, e3, e6
84
+ neighbors.push(new Label(1 - e1, e2, e3, d45, e6, e7));
85
+ neighbors.push(new Label(e1, 1 - e2, e3, d45, e6, e7));
86
+ neighbors.push(new Label(e1, e2, 1 - e3, d45, e6, e7));
87
+ neighbors.push(new Label(e1, e2, e3, d45, 1 - e6, e7));
88
+
89
+ // Flip e4 or e5 (canonical d45 transformation)
90
+ neighbors.push(new Label(e1, e2, e3, this._flipD45ByE4(d45), e6, e7));
91
+ neighbors.push(new Label(e1, e2, e3, this._flipD45ByE5(d45), e6, e7));
92
+
93
+ return neighbors;
94
+ }
95
+
96
+ _flipD45ByE4(d) {
97
+ // -1 -> 0, 0 -> 1, 1 -> 0
98
+ if (d === -1 || d === 1) return 0;
99
+ if (d === 0) return 1;
100
+ throw new Error(`Invalid d45: ${d}`);
101
+ }
102
+
103
+ _flipD45ByE5(d) {
104
+ // -1 -> 0, 0 -> -1, 1 -> 0
105
+ if (d === -1 || d === 1) return 0;
106
+ if (d === 0) return -1;
107
+ throw new Error(`Invalid d45: ${d}`);
108
+ }
109
+
110
+ _computeTau() {
111
+ return this.labels.map(label => {
112
+ const mirror = label.mirror();
113
+ return this.labelIndex.get(mirror.toString());
114
+ });
115
+ }
116
+
117
+ _findUnityPositions() {
118
+ return this.labels
119
+ .map((l, i) => l.isUnity() ? i : -1)
120
+ .filter(i => i !== -1);
121
+ }
122
+
123
+ _verifyInvariants() {
124
+ if (this.labels.length !== ATLAS_VERTEX_COUNT) {
125
+ throw new Error(`Atlas must have ${ATLAS_VERTEX_COUNT} vertices, got ${this.labels.length}`);
126
+ }
127
+ if (this.unityIndices.length !== 2) {
128
+ throw new Error(`Must have exactly 2 unity positions, got ${this.unityIndices.length}`);
129
+ }
130
+ // Check degrees
131
+ this.adjacency.forEach((neighbors, i) => {
132
+ const deg = neighbors.size;
133
+ if (deg !== 5 && deg !== 6) {
134
+ throw new Error(`Vertex ${i} has invalid degree ${deg}`);
135
+ }
136
+ });
137
+ }
138
+
139
+ // Public API
140
+
141
+ get numVertices() { return this.labels.length; }
142
+
143
+ get numEdges() {
144
+ let sum = 0;
145
+ for (const set of this.adjacency) sum += set.size;
146
+ return sum / 2;
147
+ }
148
+
149
+ degree(v) { return this.adjacency[v].size; }
150
+
151
+ neighbors(v) { return Array.from(this.adjacency[v]); }
152
+
153
+ getLabel(v) { return this.labels[v]; }
154
+
155
+ getMirror(v) { return this.tau[v]; }
156
+
157
+ isAdjacent(v1, v2) { return this.adjacency[v1].has(v2); }
158
+
159
+ isMirrorPair(v1, v2) { return this.tau[v1] === v2; }
160
+
161
+ getUnityPositions() { return this.unityIndices; }
162
+ }
@@ -0,0 +1,14 @@
1
+ import { Label } from './label.js';
2
+ import { Atlas } from './graph.js';
3
+ import { E8RootSystem } from './e8.js';
4
+
5
+ const ATLAS = new Atlas();
6
+ const E8 = new E8RootSystem();
7
+
8
+ export {
9
+ Label,
10
+ Atlas,
11
+ E8RootSystem,
12
+ ATLAS,
13
+ E8
14
+ };
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Atlas canonical label: (e1, e2, e3, d45, e6, e7)
3
+ *
4
+ * - e1, e2, e3, e6, e7 ∈ {0, 1}
5
+ * - d45 ∈ {-1, 0, +1}
6
+ *
7
+ * Represents the position in the Atlas of Resonance Classes.
8
+ */
9
+ export class Label {
10
+ /**
11
+ * Create a new Label.
12
+ * @param {number} e1 - 0 or 1
13
+ * @param {number} e2 - 0 or 1
14
+ * @param {number} e3 - 0 or 1
15
+ * @param {number} d45 - -1, 0, or 1 (Difference e4 - e5)
16
+ * @param {number} e6 - 0 or 1
17
+ * @param {number} e7 - 0 or 1
18
+ */
19
+ constructor(e1, e2, e3, d45, e6, e7) {
20
+ if (![0, 1].includes(e1)) throw new Error(`Invalid e1: ${e1}`);
21
+ if (![0, 1].includes(e2)) throw new Error(`Invalid e2: ${e2}`);
22
+ if (![0, 1].includes(e3)) throw new Error(`Invalid e3: ${e3}`);
23
+ if (![-1, 0, 1].includes(d45)) throw new Error(`Invalid d45: ${d45}`);
24
+ if (![0, 1].includes(e6)) throw new Error(`Invalid e6: ${e6}`);
25
+ if (![0, 1].includes(e7)) throw new Error(`Invalid e7: ${e7}`);
26
+
27
+ this.e1 = e1;
28
+ this.e2 = e2;
29
+ this.e3 = e3;
30
+ this.d45 = d45;
31
+ this.e6 = e6;
32
+ this.e7 = e7;
33
+ }
34
+
35
+ /**
36
+ * Apply mirror transformation (flip e7).
37
+ * @returns {Label} New mirrored label
38
+ */
39
+ mirror() {
40
+ return new Label(
41
+ this.e1,
42
+ this.e2,
43
+ this.e3,
44
+ this.d45,
45
+ this.e6,
46
+ 1 - this.e7
47
+ );
48
+ }
49
+
50
+ /**
51
+ * Check if this is a unity position.
52
+ * Unity requires d45=0 and e1=e2=e3=e6=0.
53
+ * @returns {boolean}
54
+ */
55
+ isUnity() {
56
+ return (
57
+ this.d45 === 0 &&
58
+ this.e1 === 0 &&
59
+ this.e2 === 0 &&
60
+ this.e3 === 0 &&
61
+ this.e6 === 0
62
+ );
63
+ }
64
+
65
+ /**
66
+ * Create a unique string key for this label (for Map/Set keys).
67
+ * Format: "e1,e2,e3,d45,e6,e7"
68
+ * @returns {string}
69
+ */
70
+ toString() {
71
+ return `${this.e1},${this.e2},${this.e3},${this.d45},${this.e6},${this.e7}`;
72
+ }
73
+
74
+ /**
75
+ * Parse a label string back to object.
76
+ * @param {string} str
77
+ * @returns {Label}
78
+ */
79
+ static fromString(str) {
80
+ const [e1, e2, e3, d45, e6, e7] = str.split(',').map(Number);
81
+ return new Label(e1, e2, e3, d45, e6, e7);
82
+ }
83
+ }
package/core/index.js CHANGED
@@ -456,10 +456,14 @@ export * from './emotion.js';
456
456
  // Export non-local communication module (book.pdf Chapter 8)
457
457
  export * from './nonlocal.js';
458
458
 
459
+ // Export Atlas module (atlas-embeddings)
460
+ export * from './atlas/index.js';
461
+
459
462
  import * as gravity from './gravity.js';
460
463
  import * as oracle from './oracle.js';
461
464
  import * as emotion from './emotion.js';
462
465
  import * as nonlocal from './nonlocal.js';
466
+ import { Label, Atlas, E8RootSystem, ATLAS, E8 } from './atlas/index.js';
463
467
 
464
468
  export default {
465
469
  ...gravity,
@@ -736,5 +740,13 @@ export default {
736
740
  createAlexanderModule,
737
741
  extractSignature,
738
742
  createSignatureMemory,
739
- createSignatureExtractor
743
+ createSignatureExtractor,
744
+
745
+ // Atlas of Resonance Classes (UOR-Foundation/atlas-embeddings)
746
+ // 96-vertex graph, Label system, E8 root system
747
+ Label,
748
+ Atlas,
749
+ E8RootSystem,
750
+ ATLAS,
751
+ E8
740
752
  };
@@ -0,0 +1,530 @@
1
+ # ESM Migration Plan — `apps/sentient/lib/`
2
+
3
+ > **Generated:** 2026-02-23
4
+ > **Scope:** All `.js` files under `apps/sentient/lib/`
5
+ > **Root `package.json`** has `"type": "module"` — all `.js` files must use ESM syntax.
6
+
7
+ ---
8
+
9
+ ## Table of Contents
10
+
11
+ 1. [Summary](#1-summary)
12
+ 2. [Already Migrated Files](#2-already-migrated-files)
13
+ 3. [Remaining CJS Files — Full Dependency Graph](#3-remaining-cjs-files--full-dependency-graph)
14
+ 4. [Cross-Package Dependencies](#4-cross-package-dependencies)
15
+ 5. [Special Cases](#5-special-cases)
16
+ 6. [Migration Batches](#6-migration-batches)
17
+ 7. [Migration Checklist per File](#7-migration-checklist-per-file)
18
+
19
+ ---
20
+
21
+ ## 1. Summary
22
+
23
+ | Category | Count |
24
+ |---|---|
25
+ | Total `.js` files in `apps/sentient/lib/` | ~90 |
26
+ | Already migrated to ESM | 37 |
27
+ | Remaining CJS files | **53** |
28
+ | Pure re-export shims | 6 |
29
+ | Files with dynamic `require()` | 3 |
30
+ | Files using `__dirname` / `__filename` (CJS only) | 1 |
31
+ | Migration batches needed | 8 |
32
+
33
+ ---
34
+
35
+ ## 2. Already Migrated Files
36
+
37
+ These files already use `import` / `export` syntax and need no changes:
38
+
39
+ | # | File | Notes |
40
+ |---|---|---|
41
+ | 1 | `index.js` | Barrel — uses ESM `import` from CJS deps (will break until deps migrate) |
42
+ | 2 | `askChaperone.js` | ESM, uses `fileURLToPath` polyfill for `__dirname` |
43
+ | 3 | `chat.js` | ESM |
44
+ | 4 | `lmstudio.js` | ESM |
45
+ | 5 | `vertex-ai.js` | ESM |
46
+ | 6 | `providers/index.js` | ESM |
47
+ | 7 | `app/index.js` | ESM |
48
+ | 8 | `app/args.js` | ESM |
49
+ | 9 | `app/cli.js` | ESM |
50
+ | 10 | `app/constants.js` | ESM |
51
+ | 11 | `app/shared.js` | ESM |
52
+ | 12 | `app/server.js` | ESM, uses `fileURLToPath` polyfill |
53
+ | 13 | `app/server/index.js` | ESM |
54
+ | 14 | `app/server/chat-handler.js` | ESM |
55
+ | 15 | `app/server/learning-routes.js` | ESM |
56
+ | 16 | `app/server/network-sync.js` | ESM |
57
+ | 17 | `app/server/observer-routes.js` | ESM |
58
+ | 18 | `app/server/provider-routes.js` | ESM |
59
+ | 19 | `app/server/static-server.js` | ESM |
60
+ | 20 | `app/server/stream-routes.js` | ESM |
61
+ | 21 | `app/server/utils.js` | ESM |
62
+ | 22 | `app/server/webrtc-routes.js` | ESM |
63
+ | 23 | `webrtc/coordinator.js` | ESM |
64
+ | 24 | `webrtc/index.js` | ESM |
65
+ | 25 | `webrtc/peer.js` | ESM |
66
+ | 26 | `webrtc/room.js` | ESM |
67
+ | 27 | `webrtc/transport.js` | ESM |
68
+ | 28 | `learning/chaperone.js` | ESM |
69
+ | 29 | `learning/config.js` | ESM, uses `fileURLToPath` polyfill |
70
+ | 30 | `learning/curiosity.js` | ESM |
71
+ | 31 | `learning/index.js` | ESM |
72
+ | 32 | `learning/ingester.js` | ESM |
73
+ | 33 | `learning/learner.js` | ESM |
74
+ | 34 | `learning/next-steps.js` | ESM |
75
+ | 35 | `learning/query.js` | ESM |
76
+ | 36 | `learning/reflector.js` | ESM |
77
+ | 37 | `learning/safety-filter.js` | ESM |
78
+
79
+ ---
80
+
81
+ ## 3. Remaining CJS Files — Full Dependency Graph
82
+
83
+ ### Legend
84
+ - **Imports** = what the file `require()`s
85
+ - **Imported by** = which files `require()` this file
86
+ - **Local** = within `apps/sentient/lib/`
87
+ - **External** = npm packages or Node.js built-ins
88
+ - **Cross-pkg** = from `observer/`, `core/`, `physics/`, etc.
89
+
90
+ ---
91
+
92
+ ### 3.1 Re-export Shims (6 files)
93
+
94
+ These files are one-liners: `module.exports = require('...')`.
95
+
96
+ | File | Re-exports From | Imported By |
97
+ |---|---|---|
98
+ | `smf.js` | `observer/smf` | `specialization.js`, `collective.js`, `memory-manager.js`, `symbolic-smf.js`, `symbolic-observer.js`, `sentient-core.js`, `network.js` |
99
+ | `prsc.js` | `observer/prsc` | `sentient-core.js` |
100
+ | `temporal.js` | `observer/temporal` | `symbolic-temporal.js`, `sentient-memory.js`, `sentient-core.js`, `symbolic-observer.js` |
101
+ | `entanglement.js` | `observer/entanglement` | `sentient-memory.js`, `sentient-core.js` |
102
+ | `agency.js` | `observer/agency` | `sentient-core.js` |
103
+ | `boundary.js` | `observer/boundary` | `sentient-core.js` |
104
+ | `safety.js` | `observer/safety` | `sentient-core.js` |
105
+
106
+ ### 3.2 Leaf Files (no local imports)
107
+
108
+ | File | Imports (external only) | Imported By |
109
+ |---|---|---|
110
+ | `assays.js` | *(none)* | `index.js` (ESM) |
111
+ | `topics.js` | *(none)* | `core.js` |
112
+ | `processor.js` | *(none)* | `index.js` (ESM) |
113
+ | `senses/base.js` | *(none)* | all other `senses/*.js` |
114
+ | `quantum/math.js` | *(none)* | `quantum/analyzer.js`, `quantum/network.js`, `tools/quantum-scanner.js` |
115
+ | `tools/file-editor/prompts.js` | *(none)* | `tools/file-editor/llmBridge.js` |
116
+ | `tools/file-editor/patchEngine.js` | *(none)* | `tools/file-editor/index.js`, `tools/file-editor/transaction.js` |
117
+ | `abstraction.js` | `events` | `index.js` (ESM) |
118
+ | `agent.js` | `events` | `index.js` (ESM) |
119
+ | `profiler.js` | `events`, `perf_hooks` | *(standalone)* |
120
+ | `error-handler.js` | `events` | `secure-config.js` |
121
+ | `telemetry.js` | `events`, `http` | `network.js` (dynamic) |
122
+ | `transport/index.js` | `events` | *(standalone)* |
123
+ | `speech.js` | `child_process`, `fs`, `path`, `https`, `http` | *(standalone)* |
124
+ | `binary-serializer.js` | `fs`, `path`, `zlib`, `crypto` | *(standalone)* |
125
+ | `snapshot-integrity.js` | `fs`, `path`, `crypto`, `zlib`, `util` | *(standalone)* |
126
+ | `memory-broker.js` | `events`, `fs`, `path`, `crypto` | *(standalone)* |
127
+
128
+ ### 3.3 Files With Local Dependencies
129
+
130
+ | File | Local Imports | Cross-Pkg Imports | External Imports | Imported By |
131
+ |---|---|---|---|---|
132
+ | `vocabulary.js` | *(none)* | *(none)* | `fs`, `path` | `core.js` |
133
+ | `style.js` | *(none)* | *(none)* | `fs`, `path` | `core.js` |
134
+ | `concepts.js` | *(none)* | *(none)* | `fs`, `path` | `core.js` |
135
+ | `memory.js` | *(none)* | *(none)* | `fs`, `path` | `core.js` |
136
+ | `markdown.js` | *(none)* | *(none)* | `vm` | `index.js` (ESM) |
137
+ | `resolang.js` | *(none)* | *(none)* | `fs`, `path` | `index.js` (ESM) |
138
+ | `enochian-vocabulary.js` | *(none)* | `core/prime` | *(none)* | `enochian.js` |
139
+ | `learning/prompt-cache.js` | *(none)* | *(none)* | `crypto`, `fs`, `path`, `events` | *(standalone, in learning/)* |
140
+ | `senses/chrono.js` | `senses/base` | *(none)* | *(none)* | `senses/index.js` |
141
+ | `senses/proprio.js` | `senses/base` | *(none)* | *(none)* | `senses/index.js` |
142
+ | `senses/network.js` | `senses/base` | *(none)* | *(none)* | `senses/index.js` |
143
+ | `senses/user.js` | `senses/base` | *(none)* | *(none)* | `senses/index.js` |
144
+ | `senses/sight.js` | `senses/base` | *(none)* | *(none)* | `senses/index.js` |
145
+ | `senses/process.js` | `senses/base` | *(none)* | `os` | `senses/index.js` |
146
+ | `senses/filesystem.js` | `senses/base` | *(none)* | `fs`, `path` | `senses/index.js` |
147
+ | `senses/git.js` | `senses/base` | *(none)* | `child_process`, `path` | `senses/index.js` |
148
+ | `senses/index.js` | `senses/base`, `senses/chrono`, `senses/proprio`, `senses/filesystem`, `senses/git`, `senses/process`, `senses/network`, `senses/user`, `senses/sight` | *(none)* | *(none)* | *(standalone)* |
149
+ | `quantum/analyzer.js` | `quantum/math` | *(none)* | *(none)* | `tools/quantum-scanner.js` |
150
+ | `quantum/network.js` | `quantum/math` | *(none)* | *(none)* | `tools/quantum-scanner.js` |
151
+ | `tools/file-editor/llmBridge.js` | `tools/file-editor/prompts` | *(none)* | *(none)* | `tools/file-editor/index.js` |
152
+ | `tools/file-editor/transaction.js` | `tools/file-editor/patchEngine` | *(none)* | `fs`, `path`, `crypto` | *(standalone)* |
153
+ | `tools/file-editor/index.js` | `tools/file-editor/llmBridge`, `tools/file-editor/patchEngine` | *(none)* | `fs`, `path` | `tools.js` |
154
+ | `tools/quantum-scanner.js` | `quantum/math`, `quantum/analyzer`, `quantum/network` | *(none)* | *(none)* | `tools.js` |
155
+ | `core.js` | `vocabulary`, `style`, `topics`, `concepts`, `memory` | *(none)* | *(none)* | `index.js` (ESM) |
156
+ | `enhancer.js` | `tools` | *(none)* | *(none)* | `index.js` (ESM) |
157
+ | `tools.js` | `askChaperone` (ESM), `tools/file-editor`, `tools/quantum-scanner` | *(none)* | `fs`, `path`, `crypto`, `child_process` | `enhancer.js`, `index.js` (ESM) |
158
+ | `specialization.js` | `smf` | *(none)* | *(none)* | `routing.js` |
159
+ | `routing.js` | `specialization` | *(none)* | `events` | *(standalone)* |
160
+ | `collective.js` | `smf` | *(none)* | `events` | `index.js` (ESM) |
161
+ | `memory-manager.js` | `smf` | *(none)* | `events` | *(standalone)* |
162
+ | `secure-config.js` | `error-handler` | *(none)* | `fs`, `path`, `crypto` | *(standalone)* |
163
+ | `enochian.js` | `enochian-vocabulary` | *(none)* | *(none)* | `network.js`, `index.js` (ESM) |
164
+ | `prime-calculus.js` | *(none)* | *(none)* | *(none)* | `network.js`, `index.js` (ESM) |
165
+ | `hqe.js` | *(none)* | `core/hilbert`, `core/prime` | `crypto`, `fs`, `path`, `os` | `sentient-memory.js`, `sentient-core.js` |
166
+ | `symbolic-smf.js` | `smf` | `core/symbols`, `core/inference`, `core/compound`, `core/resonance` | *(none)* | `symbolic-observer.js` |
167
+ | `symbolic-temporal.js` | `temporal` | `core/rformer`, `core/symbols` | *(none)* | `symbolic-observer.js` |
168
+ | `sentient-memory.js` | `hqe`, `entanglement`, `temporal` | `core/hilbert`, `core/rformer`, `physics/primeon_z_ladder_multi` | `fs`, `path` | `sentient-core.js` |
169
+ | `network.js` | `smf`, `prime-calculus`, `enochian` | *(none)* | `events`, `crypto` | `index.js` (ESM) |
170
+ | `sentient-core.js` | `smf`, `prsc`, `hqe`, `temporal`, `entanglement`, `sentient-memory`, `agency`, `boundary`, `safety` | `core/hilbert`, `core/prime`, `core/events`, `core/rformer` | *(none)* | `symbolic-observer.js` |
171
+ | `symbolic-observer.js` | `sentient-core`, `symbolic-smf`, `symbolic-temporal`, `smf`, `temporal` | `core/symbols`, `core/inference`, `core/compound`, `core/resonance`, `core/topology` | *(none)* | `index.js` (ESM) |
172
+
173
+ ---
174
+
175
+ ## 4. Cross-Package Dependencies
176
+
177
+ Files in `apps/sentient/lib/` that import from outside the directory:
178
+
179
+ | Source File | External Import | Package |
180
+ |---|---|---|
181
+ | `smf.js` | `require('../../../observer/smf')` | `observer/` |
182
+ | `prsc.js` | `require('../../../observer/prsc')` | `observer/` |
183
+ | `temporal.js` | `require('../../../observer/temporal')` | `observer/` |
184
+ | `entanglement.js` | `require('../../../observer/entanglement')` | `observer/` |
185
+ | `agency.js` | `require('../../../observer/agency')` | `observer/` |
186
+ | `boundary.js` | `require('../../../observer/boundary')` | `observer/` |
187
+ | `safety.js` | `require('../../../observer/safety')` | `observer/` |
188
+ | `hqe.js` | `require('../../../core/hilbert')`, `require('../../../core/prime')` | `core/` |
189
+ | `enochian-vocabulary.js` | `require('../../../core/prime')` | `core/` |
190
+ | `sentient-memory.js` | `require('../../../core/hilbert')`, `require('../../../core/rformer')`, `require('../../../physics/primeon_z_ladder_multi')` | `core/`, `physics/` |
191
+ | `sentient-core.js` | `require('../../../core/hilbert')`, `require('../../../core/prime')`, `require('../../../core/events')`, `require('../../../core/rformer')` | `core/` |
192
+ | `symbolic-smf.js` | `require('../../../core/symbols')`, `require('../../../core/inference')`, `require('../../../core/compound')`, `require('../../../core/resonance')` | `core/` |
193
+ | `symbolic-temporal.js` | `require('../../../core/rformer')`, `require('../../../core/symbols')` | `core/` |
194
+ | `symbolic-observer.js` | `require('../../../core/symbols')`, `require('../../../core/inference')`, `require('../../../core/compound')`, `require('../../../core/resonance')`, `require('../../../core/topology')` | `core/` |
195
+ | `network.js` | `require('./telemetry')` (dynamic), `require('@sschepis/resolang')` (dynamic) | npm |
196
+ | `prime-calculus.js` | `require('@sschepis/resolang')` (dynamic) | npm |
197
+
198
+ > **Note:** The `observer/` and `core/` packages must also support ESM imports. If they still use CJS `module.exports`, the re-export shims will need `import ... from` syntax with the appropriate path + `.js` extension. The cross-package files likely use `module.exports` patterns and may need their own ESM migration, or `createRequire()` may be needed temporarily.
199
+
200
+ ---
201
+
202
+ ## 5. Special Cases
203
+
204
+ ### 5.1 Pure Re-export Shims (6 files)
205
+
206
+ These are trivial to migrate — replace the one-liner with ESM re-export:
207
+
208
+ ```js
209
+ // Before (CJS)
210
+ module.exports = require('../../../observer/smf');
211
+
212
+ // After (ESM)
213
+ export { default } from '../../../observer/smf.js';
214
+ // OR, if named exports are needed:
215
+ export * from '../../../observer/smf.js';
216
+ ```
217
+
218
+ **Files:** `smf.js`, `prsc.js`, `temporal.js`, `entanglement.js`, `agency.js`, `boundary.js`, `safety.js`
219
+
220
+ ### 5.2 Dynamic `require()` (3 files)
221
+
222
+ These use `require()` inside `try/catch` for optional dependencies:
223
+
224
+ | File | Dynamic Require | Migration Strategy |
225
+ |---|---|---|
226
+ | `network.js` (line 33) | `telemetry = require('./telemetry')` | Use dynamic `import()` in an async init or `try { const m = await import('./telemetry.js'); telemetry = m; } catch {}` |
227
+ | `network.js` (line 41) | `resolang = require('@sschepis/resolang')` | Same dynamic `import()` pattern |
228
+ | `prime-calculus.js` (line 25) | `resolang = require('@sschepis/resolang')` | Same dynamic `import()` pattern |
229
+ | `enochian.js` (line 26) | `resolang = require('@sschepis/resolang')` | Same dynamic `import()` pattern |
230
+
231
+ ### 5.3 `__dirname` / `__filename` Usage (1 CJS file)
232
+
233
+ | File | Usage | Migration |
234
+ |---|---|---|
235
+ | `resolang.js` (line 34) | `path.join(__dirname, ...)` | Add ESM polyfill: `const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename);` |
236
+
237
+ ### 5.4 Conditional `module.exports` Pattern (3 files)
238
+
239
+ The `quantum/` files use `if (typeof module !== 'undefined' && module.exports)` guard:
240
+
241
+ | File | Pattern |
242
+ |---|---|
243
+ | `quantum/math.js` | `if (typeof module !== 'undefined' && module.exports) { module.exports = {...} }` |
244
+ | `quantum/analyzer.js` | Same pattern |
245
+ | `quantum/network.js` | Same pattern |
246
+ | `tools/quantum-scanner.js` | Same pattern |
247
+
248
+ **Migration:** Remove the conditional, use `export { ... }` directly.
249
+
250
+ ### 5.5 `module.exports = { ... }` Pattern (most files)
251
+
252
+ The majority of files use `module.exports = { Class1, Class2, func1 }`. Convert to:
253
+
254
+ ```js
255
+ export { Class1, Class2, func1 };
256
+ ```
257
+
258
+ ### 5.6 `VM` module usage
259
+
260
+ | File | Notes |
261
+ |---|---|
262
+ | `markdown.js` | Uses `const { VM } = require('vm')`. The `vm` module works in ESM — just change to `import { VM } from 'vm'`. |
263
+
264
+ ---
265
+
266
+ ## 6. Migration Batches
267
+
268
+ Files must be migrated bottom-up: leaf dependencies first, then files that depend on them.
269
+
270
+ ### Batch 0 — Pre-requisite: Verify Cross-Package ESM Compatibility
271
+
272
+ Before migrating, verify that these external packages support ESM `import`:
273
+ - `observer/smf.js`, `observer/prsc.js`, `observer/temporal.js`, `observer/entanglement.js`, `observer/agency.js`, `observer/boundary.js`, `observer/safety.js`
274
+ - `core/hilbert.js`, `core/prime.js`, `core/events.js`, `core/rformer.js`, `core/symbols.js`, `core/inference.js`, `core/compound.js`, `core/resonance.js`, `core/topology.js`
275
+ - `physics/primeon_z_ladder_multi.js`
276
+
277
+ If any of these still use CJS `module.exports`, they either need to be migrated first or accessed via `createRequire()` bridge.
278
+
279
+ ---
280
+
281
+ ### Batch 1 — Leaf Nodes (no local dependencies) — 23 files
282
+
283
+ These files import only Node.js built-ins, npm packages, or nothing at all.
284
+
285
+ | # | File | Imports | Export Pattern | Notes |
286
+ |---|---|---|---|---|
287
+ | 1 | `assays.js` | *(none)* | `module.exports = { ... }` | 4 classes + 1 suite |
288
+ | 2 | `topics.js` | *(none)* | `module.exports = { TopicTracker }` | |
289
+ | 3 | `processor.js` | *(none)* | `module.exports = { ResponseProcessor }` | |
290
+ | 4 | `vocabulary.js` | `fs`, `path` | `module.exports = { VocabularyManager }` | |
291
+ | 5 | `style.js` | `fs`, `path` | `module.exports = { StyleProfiler }` | |
292
+ | 6 | `concepts.js` | `fs`, `path` | `module.exports = { ConceptGraph }` | |
293
+ | 7 | `memory.js` | `fs`, `path` | `module.exports = { ContextMemory, ... }` | |
294
+ | 8 | `markdown.js` | `vm` | `module.exports = { MarkdownRenderer, ... }` | |
295
+ | 9 | `resolang.js` | `fs`, `path` | `module.exports = { ResolangLoader, ... }` | Uses `__dirname` — needs polyfill |
296
+ | 10 | `agent.js` | `events` | `module.exports = { TaskStatus, ..., Agent, createAgent }` | Enums + classes |
297
+ | 11 | `abstraction.js` | `events` | `module.exports = { FusionDiscoveryEngine, ... }` | |
298
+ | 12 | `profiler.js` | `events`, `perf_hooks` | `module.exports = { ... }` | |
299
+ | 13 | `error-handler.js` | `events` | `module.exports = { ... }` | |
300
+ | 14 | `telemetry.js` | `events`, `http` | `module.exports = { ... }` | |
301
+ | 15 | `transport/index.js` | `events` | `module.exports = { ... }` | |
302
+ | 16 | `speech.js` | `child_process`, `fs`, `path`, `https`, `http` | `module.exports = { ... }` | |
303
+ | 17 | `binary-serializer.js` | `fs`, `path`, `zlib`, `crypto` | `module.exports = { ... }` | |
304
+ | 18 | `snapshot-integrity.js` | `fs`, `path`, `crypto`, `zlib`, `util` | `module.exports = { ... }` | |
305
+ | 19 | `memory-broker.js` | `events`, `fs`, `path`, `crypto` | `module.exports = { ... }` | |
306
+ | 20 | `senses/base.js` | *(none)* | `module.exports = { Sense }` | |
307
+ | 21 | `quantum/math.js` | *(none)* | Conditional `module.exports` | Remove guard |
308
+ | 22 | `tools/file-editor/prompts.js` | *(none)* | `module.exports = { SYSTEM_PROMPT }` | |
309
+ | 23 | `tools/file-editor/patchEngine.js` | *(none)* | `module.exports = { ... }` | |
310
+
311
+ ---
312
+
313
+ ### Batch 2 — Depends on Batch 1 only — 14 files
314
+
315
+ | # | File | Local Deps (all from Batch 1) | Notes |
316
+ |---|---|---|---|
317
+ | 1 | `core.js` | `vocabulary`, `style`, `topics`, `concepts`, `memory` | |
318
+ | 2 | `secure-config.js` | `error-handler` | |
319
+ | 3 | `senses/chrono.js` | `senses/base` | |
320
+ | 4 | `senses/proprio.js` | `senses/base` | |
321
+ | 5 | `senses/network.js` | `senses/base` | |
322
+ | 6 | `senses/user.js` | `senses/base` | |
323
+ | 7 | `senses/sight.js` | `senses/base` | |
324
+ | 8 | `senses/process.js` | `senses/base` | |
325
+ | 9 | `senses/filesystem.js` | `senses/base` | |
326
+ | 10 | `senses/git.js` | `senses/base` | |
327
+ | 11 | `quantum/analyzer.js` | `quantum/math` | Conditional exports — remove guard |
328
+ | 12 | `quantum/network.js` | `quantum/math` | Conditional exports — remove guard |
329
+ | 13 | `tools/file-editor/llmBridge.js` | `tools/file-editor/prompts` | |
330
+ | 14 | `tools/file-editor/transaction.js` | `tools/file-editor/patchEngine` | |
331
+
332
+ ---
333
+
334
+ ### Batch 3 — Depends on Batch 1–2 — 7 files
335
+
336
+ | # | File | Local Deps | Notes |
337
+ |---|---|---|---|
338
+ | 1 | `senses/index.js` | all `senses/*.js` (Batch 1–2) | Barrel file for senses subsystem |
339
+ | 2 | `tools/file-editor/index.js` | `llmBridge` (B2), `patchEngine` (B1) | |
340
+ | 3 | `tools/quantum-scanner.js` | `quantum/math` (B1), `quantum/analyzer` (B2), `quantum/network` (B2) | Conditional exports — remove guard |
341
+ | 4 | `enochian-vocabulary.js` | *(none local)* | Cross-pkg: `core/prime` |
342
+ | 5 | `prime-calculus.js` | *(none local)* | Dynamic `require('@sschepis/resolang')` — use `import()` |
343
+ | 6 | `learning/prompt-cache.js` | *(none local)* | Only uses Node built-ins; in learning/ dir but still CJS |
344
+ | 7 | `collective.js` | `smf` (re-export shim — convert in B4) | Move to B5 if smf needs to be done first. **Alternative:** convert `smf.js` shim in this batch too. |
345
+
346
+ > **Decision point for `collective.js`**: It depends on `smf.js` which is a re-export shim. Since shims are trivial, we can convert `smf.js` and all 6 re-export shims as part of Batch 3.
347
+
348
+ **Revised Batch 3** — also includes all 6 re-export shims:
349
+
350
+ | # | File | Notes |
351
+ |---|---|---|
352
+ | 1–6 | `smf.js`, `prsc.js`, `temporal.js`, `entanglement.js`, `agency.js`, `boundary.js`, `safety.js` | Convert `module.exports = require(...)` → `export * from '...'` |
353
+ | 7 | `senses/index.js` | Barrel |
354
+ | 8 | `tools/file-editor/index.js` | |
355
+ | 9 | `tools/quantum-scanner.js` | |
356
+ | 10 | `enochian-vocabulary.js` | Cross-pkg: `core/prime` |
357
+ | 11 | `prime-calculus.js` | Dynamic `require` → `import()` |
358
+ | 12 | `learning/prompt-cache.js` | |
359
+ | 13 | `collective.js` | Depends on `smf` (now converted) |
360
+
361
+ ---
362
+
363
+ ### Batch 4 — Depends on Batch 1–3 — 6 files
364
+
365
+ | # | File | Local Deps | Cross-Pkg Deps | Notes |
366
+ |---|---|---|---|---|
367
+ | 1 | `tools.js` | `askChaperone` (ESM ✓), `tools/file-editor` (B3), `tools/quantum-scanner` (B3) | *(none)* | |
368
+ | 2 | `enochian.js` | `enochian-vocabulary` (B3) | *(none)* | Dynamic `require('@sschepis/resolang')` |
369
+ | 3 | `hqe.js` | *(none local)* | `core/hilbert`, `core/prime` | Uses `fs`, `path`, `os`, `crypto` |
370
+ | 4 | `specialization.js` | `smf` (B3) | *(none)* | |
371
+ | 5 | `memory-manager.js` | `smf` (B3) | *(none)* | |
372
+ | 6 | `symbolic-smf.js` | `smf` (B3) | `core/symbols`, `core/inference`, `core/compound`, `core/resonance` | |
373
+
374
+ ---
375
+
376
+ ### Batch 5 — Depends on Batch 1–4 — 4 files
377
+
378
+ | # | File | Local Deps | Cross-Pkg Deps |
379
+ |---|---|---|---|
380
+ | 1 | `enhancer.js` | `tools` (B4) | *(none)* |
381
+ | 2 | `routing.js` | `specialization` (B4) | *(none)* |
382
+ | 3 | `symbolic-temporal.js` | `temporal` (B3 shim) | `core/rformer`, `core/symbols` |
383
+ | 4 | `sentient-memory.js` | `hqe` (B4), `entanglement` (B3), `temporal` (B3) | `core/hilbert`, `core/rformer`, `physics/primeon_z_ladder_multi` |
384
+
385
+ ---
386
+
387
+ ### Batch 6 — Depends on Batch 1–5 — 2 files
388
+
389
+ | # | File | Local Deps | Cross-Pkg Deps |
390
+ |---|---|---|---|
391
+ | 1 | `network.js` | `smf` (B3), `prime-calculus` (B3), `enochian` (B4), `telemetry` (B1, dynamic) | *(none)* |
392
+ | 2 | `sentient-core.js` | `smf` (B3), `prsc` (B3), `hqe` (B4), `temporal` (B3), `entanglement` (B3), `sentient-memory` (B5), `agency` (B3), `boundary` (B3), `safety` (B3) | `core/hilbert`, `core/prime`, `core/events`, `core/rformer` |
393
+
394
+ ---
395
+
396
+ ### Batch 7 — Final (depends on Batch 6) — 1 file
397
+
398
+ | # | File | Local Deps |
399
+ |---|---|---|
400
+ | 1 | `symbolic-observer.js` | `sentient-core` (B6), `symbolic-smf` (B4), `symbolic-temporal` (B5), `smf` (B3), `temporal` (B3) |
401
+
402
+ ---
403
+
404
+ ### Batch Summary
405
+
406
+ ```mermaid
407
+ graph TD
408
+ B0[Batch 0: Verify cross-pkg ESM compat]
409
+ B1[Batch 1: 23 leaf files]
410
+ B2[Batch 2: 14 files - depends on B1]
411
+ B3[Batch 3: 13 files - shims + barrels + deps on B1-B2]
412
+ B4[Batch 4: 6 files - depends on B1-B3]
413
+ B5[Batch 5: 4 files - depends on B1-B4]
414
+ B6[Batch 6: 2 files - network + sentient-core]
415
+ B7[Batch 7: 1 file - symbolic-observer]
416
+
417
+ B0 --> B1
418
+ B1 --> B2
419
+ B2 --> B3
420
+ B3 --> B4
421
+ B4 --> B5
422
+ B5 --> B6
423
+ B6 --> B7
424
+ ```
425
+
426
+ ---
427
+
428
+ ## 7. Migration Checklist per File
429
+
430
+ For each CJS file, apply these transformations:
431
+
432
+ ### Standard Conversion Steps
433
+
434
+ 1. **Replace `require()` with `import`:**
435
+ ```js
436
+ // Before
437
+ const { Foo } = require('./bar');
438
+ const fs = require('fs');
439
+
440
+ // After
441
+ import { Foo } from './bar.js';
442
+ import fs from 'fs';
443
+ ```
444
+
445
+ 2. **Replace `module.exports` with `export`:**
446
+ ```js
447
+ // Before
448
+ module.exports = { Foo, Bar, baz };
449
+
450
+ // After
451
+ export { Foo, Bar, baz };
452
+ ```
453
+
454
+ 3. **Add `.js` extension** to all relative import paths.
455
+
456
+ 4. **Replace dynamic `require()` with `import()`:**
457
+ ```js
458
+ // Before
459
+ try { resolang = require('@sschepis/resolang'); } catch {}
460
+
461
+ // After
462
+ try { resolang = await import('@sschepis/resolang'); } catch {}
463
+ // Note: if in module scope, wrap in async IIFE or init function
464
+ ```
465
+
466
+ 5. **Add `__dirname` polyfill where needed:**
467
+ ```js
468
+ import { fileURLToPath } from 'url';
469
+ import path from 'path';
470
+ const __filename = fileURLToPath(import.meta.url);
471
+ const __dirname = path.dirname(__filename);
472
+ ```
473
+
474
+ 6. **Remove conditional export guards:**
475
+ ```js
476
+ // Remove this pattern entirely:
477
+ if (typeof module !== 'undefined' && module.exports) {
478
+ module.exports = { ... };
479
+ }
480
+ // Replace with:
481
+ export { ... };
482
+ ```
483
+
484
+ 7. **Convert re-export shims:**
485
+ ```js
486
+ // Before
487
+ module.exports = require('../../../observer/smf');
488
+
489
+ // After — choose based on what the observer module exports:
490
+ export * from '../../../observer/smf.js';
491
+ // OR if it has a default export:
492
+ export { default } from '../../../observer/smf.js';
493
+ // OR re-export both:
494
+ export * from '../../../observer/smf.js';
495
+ export { default } from '../../../observer/smf.js';
496
+ ```
497
+
498
+ ### Testing After Each Batch
499
+
500
+ After converting each batch:
501
+ 1. Run `node --check <file>` on each converted file to verify syntax
502
+ 2. Run the test suite: `npm test`
503
+ 3. Verify no `require()` or `module.exports` remain in converted files:
504
+ ```bash
505
+ grep -rn 'require(' apps/sentient/lib/<batch-files> | grep -v node_modules
506
+ grep -rn 'module.exports' apps/sentient/lib/<batch-files>
507
+ ```
508
+
509
+ ---
510
+
511
+ ## Appendix: Files Not Imported by Anything in lib/
512
+
513
+ These files may be entry points, test utilities, or dead code:
514
+
515
+ | File | Notes |
516
+ |---|---|
517
+ | `profiler.js` | May be imported at runtime / used externally |
518
+ | `speech.js` | Standalone speech module |
519
+ | `binary-serializer.js` | Standalone serialization utility |
520
+ | `snapshot-integrity.js` | Standalone integrity checker |
521
+ | `memory-broker.js` | Standalone memory broker |
522
+ | `transport/index.js` | Standalone transport layer |
523
+ | `routing.js` | May be imported by app layer |
524
+ | `memory-manager.js` | May be imported by app layer |
525
+ | `secure-config.js` | May be imported by app layer |
526
+ | `senses/index.js` | May be imported by app layer |
527
+ | `learning/prompt-cache.js` | May be imported by learning subsystem at runtime |
528
+ | `tools/file-editor/transaction.js` | May be imported externally |
529
+
530
+ These should still be migrated but verify they are actually used before investing effort.
package/observer/index.js CHANGED
@@ -15,83 +15,134 @@
15
15
  */
16
16
 
17
17
  // Core observer components
18
- import { PrimeOscillator, PRSCLayer, EntanglementDetector, coherenceKernel } from './prsc.js';
18
+ import {
19
+ PrimeOscillator, PRSCLayer, EntanglementDetector,
20
+ computeHistogramCoherence, gaussianRandom, indexToPhase, intSin, phaseToIndex,
21
+ INT_SINE_M, INT_SINE_SCALE, INT_SINE_TABLE
22
+ } from './prsc.js';
19
23
 
20
- import { TickGate, StabilizationController, HolographicEncoder, HQE } from './hqe.js';
24
+ import {
25
+ TickGate, StabilizationController, HolographicEncoder,
26
+ HolographicMemory, HolographicSimilarity
27
+ } from './hqe.js';
21
28
 
22
- import { SedenionMemoryField, SMF_AXES, AXIS_INDEX } from './smf.js';
29
+ import {
30
+ SedenionMemoryField, SMF_AXES, AXIS_INDEX,
31
+ SMF_CODEBOOK, CODEBOOK_SIZE, codebookTunnel, getTunnelingCandidates, nearestCodebookAttractor
32
+ } from './smf.js';
23
33
 
24
34
  import { Moment, TemporalLayer, TemporalPatternDetector } from './temporal.js';
25
35
 
26
- import { AttentionFocus, Goal, Action, Intent, AgencyLayer } from './agency.js';
36
+ import { AttentionFocus, Goal, Action, AgencyLayer } from './agency.js';
27
37
 
28
- import { SensoryChannel, MotorChannel, EnvironmentalModel, SelfModel, BoundaryLayer } from './boundary.js';
38
+ import {
39
+ SensoryChannel, MotorChannel, EnvironmentalModel, SelfModel,
40
+ BoundaryLayer, ObjectivityGate
41
+ } from './boundary.js';
29
42
 
30
43
  import { EntangledPair, Phrase, EntanglementLayer } from './entanglement.js';
31
44
 
32
- import { SafetyConstraint, ViolationEvent, SafetyMonitor, DEFAULT_CONSTRAINTS } from './safety.js';
45
+ import { SafetyConstraint, ViolationEvent, SafetyMonitor, SafetyLayer } from './safety.js';
33
46
 
34
47
  // Symbolic processing extensions
35
- import { SymbolicSMF, SMFSymbolMapper, smfMapper, AXIS_SYMBOL_MAPPING, TAG_TO_AXIS } from './symbolic-smf.js';
48
+ import {
49
+ SymbolicSMF, SMFSymbolMapper, smfMapper, AXIS_SYMBOL_MAPPING, TAG_TO_AXIS,
50
+ createSymbolicSMF, fromSMF, symbolToSMF, symbolsToSMF
51
+ } from './symbolic-smf.js';
36
52
 
37
- import { SymbolicMoment, SymbolicTemporalLayer, SymbolicPatternDetector, HEXAGRAM_ARCHETYPES } from './symbolic-temporal.js';
53
+ import {
54
+ SymbolicMoment, SymbolicTemporalLayer, SymbolicPatternDetector,
55
+ HEXAGRAM_ARCHETYPES, FIRST_64_PRIMES, PHI
56
+ } from './symbolic-temporal.js';
38
57
 
39
58
  // Evaluation assays
40
- import { TimeDilationAssay, MemoryContinuityAssay, AgencyConstraintAssay, NonCommutativeMeaningAssay, AssaySuite } from './assays.js';
59
+ import {
60
+ TimeDilationAssay, MemoryContinuityAssay, AgencyConstraintAssay,
61
+ NonCommutativeMeaningAssay, AssaySuite
62
+ } from './assays.js';
41
63
 
42
64
  export {
43
65
  // PRSC - Prime Resonance Semantic Coherence
44
- PrimeOscillator,
66
+ PrimeOscillator,
45
67
  PRSCLayer,
46
68
  EntanglementDetector,
47
- coherenceKernel,
69
+ computeHistogramCoherence,
70
+ gaussianRandom,
71
+ indexToPhase,
72
+ intSin,
73
+ phaseToIndex,
74
+ INT_SINE_M,
75
+ INT_SINE_SCALE,
76
+ INT_SINE_TABLE,
77
+
48
78
  // HQE - Holographic Quaternion Engine
49
- TickGate,
79
+ TickGate,
50
80
  StabilizationController,
51
81
  HolographicEncoder,
52
- HQE,
82
+ HolographicMemory,
83
+ HolographicSimilarity,
84
+
53
85
  // SMF - Sedenion Memory Field
54
- SedenionMemoryField,
86
+ SedenionMemoryField,
55
87
  SMF_AXES,
56
88
  AXIS_INDEX,
89
+ SMF_CODEBOOK,
90
+ CODEBOOK_SIZE,
91
+ codebookTunnel,
92
+ getTunnelingCandidates,
93
+ nearestCodebookAttractor,
94
+
57
95
  // Temporal - Moment classification
58
- Moment,
96
+ Moment,
59
97
  TemporalLayer,
60
98
  TemporalPatternDetector,
99
+
61
100
  // Agency - Goals and intentions
62
- AttentionFocus,
101
+ AttentionFocus,
63
102
  Goal,
64
103
  Action,
65
- Intent,
66
104
  AgencyLayer,
105
+
67
106
  // Boundary - Self-other differentiation
68
- SensoryChannel,
107
+ SensoryChannel,
69
108
  MotorChannel,
70
109
  EnvironmentalModel,
71
110
  SelfModel,
72
111
  BoundaryLayer,
112
+ ObjectivityGate,
113
+
73
114
  // Entanglement - Semantic phrase coherence
74
- EntangledPair,
115
+ EntangledPair,
75
116
  Phrase,
76
117
  EntanglementLayer,
118
+
77
119
  // Safety - Constraint monitoring
78
- SafetyConstraint,
120
+ SafetyConstraint,
79
121
  ViolationEvent,
80
122
  SafetyMonitor,
81
- DEFAULT_CONSTRAINTS,
123
+ SafetyLayer,
124
+
82
125
  // Symbolic SMF - Symbol-grounded semantic field
83
- SymbolicSMF,
126
+ SymbolicSMF,
84
127
  SMFSymbolMapper,
85
128
  smfMapper,
86
129
  AXIS_SYMBOL_MAPPING,
87
130
  TAG_TO_AXIS,
131
+ createSymbolicSMF,
132
+ fromSMF,
133
+ symbolToSMF,
134
+ symbolsToSMF,
135
+
88
136
  // Symbolic Temporal - I-Ching moment classification
89
- SymbolicMoment,
137
+ SymbolicMoment,
90
138
  SymbolicTemporalLayer,
91
139
  SymbolicPatternDetector,
92
140
  HEXAGRAM_ARCHETYPES,
141
+ FIRST_64_PRIMES,
142
+ PHI,
143
+
93
144
  // Assays - Validation tests
94
- TimeDilationAssay,
145
+ TimeDilationAssay,
95
146
  MemoryContinuityAssay,
96
147
  AgencyConstraintAssay,
97
148
  NonCommutativeMeaningAssay,
@@ -99,60 +150,77 @@ export {
99
150
  };
100
151
 
101
152
  export default {
102
- // PRSC - Prime Resonance Semantic Coherence
103
- PrimeOscillator,
153
+ // PRSC
154
+ PrimeOscillator,
104
155
  PRSCLayer,
105
156
  EntanglementDetector,
106
- coherenceKernel,
107
- // HQE - Holographic Quaternion Engine
108
- TickGate,
157
+ computeHistogramCoherence,
158
+
159
+ // HQE
160
+ TickGate,
109
161
  StabilizationController,
110
162
  HolographicEncoder,
111
- HQE,
112
- // SMF - Sedenion Memory Field
113
- SedenionMemoryField,
163
+ HolographicMemory,
164
+ HolographicSimilarity,
165
+
166
+ // SMF
167
+ SedenionMemoryField,
114
168
  SMF_AXES,
115
169
  AXIS_INDEX,
116
- // Temporal - Moment classification
117
- Moment,
170
+
171
+ // Temporal
172
+ Moment,
118
173
  TemporalLayer,
119
174
  TemporalPatternDetector,
120
- // Agency - Goals and intentions
121
- AttentionFocus,
175
+
176
+ // Agency
177
+ AttentionFocus,
122
178
  Goal,
123
179
  Action,
124
- Intent,
125
180
  AgencyLayer,
126
- // Boundary - Self-other differentiation
127
- SensoryChannel,
181
+
182
+ // Boundary
183
+ SensoryChannel,
128
184
  MotorChannel,
129
185
  EnvironmentalModel,
130
186
  SelfModel,
131
187
  BoundaryLayer,
132
- // Entanglement - Semantic phrase coherence
133
- EntangledPair,
188
+ ObjectivityGate,
189
+
190
+ // Entanglement
191
+ EntangledPair,
134
192
  Phrase,
135
193
  EntanglementLayer,
136
- // Safety - Constraint monitoring
137
- SafetyConstraint,
194
+
195
+ // Safety
196
+ SafetyConstraint,
138
197
  ViolationEvent,
139
198
  SafetyMonitor,
140
- DEFAULT_CONSTRAINTS,
141
- // Symbolic SMF - Symbol-grounded semantic field
142
- SymbolicSMF,
199
+ SafetyLayer,
200
+
201
+ // Symbolic SMF
202
+ SymbolicSMF,
143
203
  SMFSymbolMapper,
144
204
  smfMapper,
145
205
  AXIS_SYMBOL_MAPPING,
146
206
  TAG_TO_AXIS,
147
- // Symbolic Temporal - I-Ching moment classification
148
- SymbolicMoment,
207
+ createSymbolicSMF,
208
+ fromSMF,
209
+ symbolToSMF,
210
+ symbolsToSMF,
211
+
212
+ // Symbolic Temporal
213
+ SymbolicMoment,
149
214
  SymbolicTemporalLayer,
150
215
  SymbolicPatternDetector,
151
216
  HEXAGRAM_ARCHETYPES,
152
- // Assays - Validation tests
153
- TimeDilationAssay,
217
+ FIRST_64_PRIMES,
218
+ PHI,
219
+
220
+ // Assays
221
+ TimeDilationAssay,
154
222
  MemoryContinuityAssay,
155
223
  AgencyConstraintAssay,
156
224
  NonCommutativeMeaningAssay,
157
225
  AssaySuite
158
- };
226
+ };
@@ -685,42 +685,32 @@ class SMFSymbolMapper {
685
685
  // Singleton instance
686
686
  const smfMapper = new SMFSymbolMapper();
687
687
 
688
+ // Convenience functions
689
+ const createSymbolicSMF = (components, options) => new SymbolicSMF(components, options);
690
+ const fromSMF = (smf, options) => SymbolicSMF.fromSMF(smf, options);
691
+ const symbolToSMF = (symbol) => smfMapper.symbolToSMF(symbol);
692
+ const symbolsToSMF = (symbols) => smfMapper.symbolsToSMF(symbols);
693
+
688
694
  export {
689
- // Classes
690
- SymbolicSMF,
695
+ SymbolicSMF,
691
696
  SMFSymbolMapper,
692
- // Singleton instance
693
- smfMapper,
694
- // Mappings (for external use)
695
- AXIS_SYMBOL_MAPPING,
697
+ smfMapper,
698
+ AXIS_SYMBOL_MAPPING,
696
699
  TAG_TO_AXIS,
697
- // Convenience functions
698
- createSymbolicSMF: (components,
699
- options) => new SymbolicSMF(components,
700
- options),
701
- fromSMF: (smf,
702
- options) => SymbolicSMF.fromSMF(smf,
703
- options),
704
- symbolToSMF: (symbol) => smfMapper.symbolToSMF(symbol),
705
- symbolsToSMF: (symbols) => smfMapper.symbolsToSMF(symbols)
700
+ createSymbolicSMF,
701
+ fromSMF,
702
+ symbolToSMF,
703
+ symbolsToSMF
706
704
  };
707
705
 
708
706
  export default {
709
- // Classes
710
- SymbolicSMF,
707
+ SymbolicSMF,
711
708
  SMFSymbolMapper,
712
- // Singleton instance
713
- smfMapper,
714
- // Mappings (for external use)
715
- AXIS_SYMBOL_MAPPING,
709
+ smfMapper,
710
+ AXIS_SYMBOL_MAPPING,
716
711
  TAG_TO_AXIS,
717
- // Convenience functions
718
- createSymbolicSMF: (components,
719
- options) => new SymbolicSMF(components,
720
- options),
721
- fromSMF: (smf,
722
- options) => SymbolicSMF.fromSMF(smf,
723
- options),
724
- symbolToSMF: (symbol) => smfMapper.symbolToSMF(symbol),
725
- symbolsToSMF: (symbols) => smfMapper.symbolsToSMF(symbols)
726
- };
712
+ createSymbolicSMF,
713
+ fromSMF,
714
+ symbolToSMF,
715
+ symbolsToSMF
716
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aleph-ai/tinyaleph",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "Prime-resonant semantic computing framework - hypercomplex algebra, oscillator dynamics, arithmetic topology, and entropy-minimizing reasoning",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -89,13 +89,12 @@ function estimateLyapunovFromTimeSeries(history, windowSize = 20) {
89
89
  /**
90
90
  * Classify stability based on Lyapunov exponent
91
91
  * @param {number} lyapunovExponent - The Lyapunov exponent
92
- * @returns {'stable'|'unstable'|'chaotic'|'collapsed'} Stability classification
92
+ * @returns {'STABLE'|'MARGINAL'|'CHAOTIC'} Stability classification
93
93
  */
94
94
  function classifyStability(lyapunovExponent) {
95
- if (lyapunovExponent < -0.1) return 'collapsed'; // Strong convergence
96
- if (lyapunovExponent < 0) return 'stable'; // Weak convergence
97
- if (lyapunovExponent < 0.5) return 'unstable'; // Weak divergence
98
- return 'chaotic'; // Strong divergence
95
+ if (lyapunovExponent < 0) return 'STABLE'; // Convergent (negative exponent)
96
+ if (lyapunovExponent < 0.5) return 'MARGINAL'; // Near-zero / weak divergence
97
+ return 'CHAOTIC'; // Strong divergence
99
98
  }
100
99
 
101
100
  /**