mnemonica 1.2.3 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/FOR_HUMANS.md +160 -125
  2. package/README.md +70 -249
  3. package/build/api/types/index.js +18 -12
  4. package/docs/UTILS.md +97 -8
  5. package/docs/decorate.md +1 -1
  6. package/docs/empathy-in-ai.md +20 -10
  7. package/docs/prototype-chain.md +8 -7
  8. package/docs/typed-lookup.md +195 -5
  9. package/docs/typeomatica.md +8 -345
  10. package/package.json +6 -10
  11. package/src/api/types/index.ts +33 -20
  12. package/.ai/AGENTS.md +0 -151
  13. package/.ai/ARCHITECT.md +0 -110
  14. package/.ai/DEBUG.md +0 -178
  15. package/.ai/ONBOARDING.md +0 -189
  16. package/.ai/PROTOTYPE-CHAIN.md +0 -155
  17. package/.ai/mode-ask.md +0 -121
  18. package/.ai/mode-orchestrator.md +0 -141
  19. package/.ai/performance-vs-security.md +0 -395
  20. package/.ai/rules-async-constructors.md +0 -352
  21. package/.ai/rules-code-style.md +0 -95
  22. package/.ai/rules-coding.md +0 -246
  23. package/.ai/rules-context-condensing.md +0 -50
  24. package/.ai/rules-contributing.md +0 -227
  25. package/.ai/rules-define-patterns.md +0 -159
  26. package/.ai/rules-ecosystem.md +0 -140
  27. package/.ai/rules-error-system.md +0 -66
  28. package/.ai/rules-hooks.md +0 -46
  29. package/.ai/rules-instance-methods.md +0 -93
  30. package/.ai/rules-philosophy.md +0 -231
  31. package/.ai/rules-reminders.md +0 -19
  32. package/.ai/rules-testing.md +0 -66
  33. package/.ai/rules-type-system.md +0 -124
  34. package/.ai/theory-of-operations.md +0 -224
  35. package/AGENTS.md +0 -345
  36. package/CONTRIBUTING.md +0 -150
  37. package/SKILL.md +0 -114
  38. package/docs/ai-learning-trajectory.md +0 -141
  39. package/docs/purpose.md +0 -707
  40. package/docs/tactica-deep-dive.md +0 -629
  41. package/docs/tactica-pattern.md +0 -146
package/docs/purpose.md DELETED
@@ -1,707 +0,0 @@
1
- # The Purpose of Mnemonica
2
-
3
- ## A Guide for AI Agents (and Humans)
4
-
5
- This document exists to prevent a specific recurring misunderstanding: **Mnemonica is about DATA FLOW, not CONTROL FLOW**. When an AI agent (like myself) starts "protecting" algorithms or worrying about behavior changes, reference this document. The user is not asking to modify control flow. Ever.
6
-
7
- ---
8
-
9
- ## Part 1: The Abstract - Data Flow vs Control Flow
10
-
11
- ### Data Flow Diagram (DFD) - What Mnemonica Addresses
12
-
13
- ```
14
- ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
15
- │ Raw Data │ ───► │ Transform │ ───► │ Output │
16
- │ (Input) │ │ (Process) │ │ (Result) │
17
- └─────────────┘ └─────────────┘ └─────────────┘
18
- ```
19
-
20
- **Data Flow** is about:
21
- - What data enters the system
22
- - How data transforms as it moves
23
- - What data exits the system
24
- - The structure and relationships of data at each stage
25
-
26
- **Mnemonica operates here**: It types, structures, and tracks the data itself.
27
-
28
- ### Control Flow / Execution Flow - What Mnemonica Does NOT Address
29
-
30
- ```
31
- if (condition) { // Control flow: decision point
32
- executeA(); // Execution flow: what runs when
33
- } else {
34
- executeB();
35
- }
36
-
37
- for (item of items) { // Control flow: iteration
38
- process(item); // Execution flow: repeated action
39
- }
40
- ```
41
-
42
- **Control Flow** is about:
43
- - Decision points (if/else, switch)
44
- - Iteration (loops, recursion)
45
- - Execution order
46
- - Algorithm logic
47
- - Service orchestration
48
-
49
- **Mnemonica does NOT touch this**: Algorithms remain unchanged. Services stay intact. Control flow is crafted by developers (and AI agents) as needed.
50
-
51
- ### What Mnemonica Does NOT Do — Concrete Examples
52
-
53
- ```typescript
54
- // ❌ Mnemonica does NOT replace if/else
55
- if (user.role === 'admin') {
56
- // This logic is yours. Mnemonica provides the typed data,
57
- // not the decision rule.
58
- }
59
-
60
- // ❌ Mnemonica does NOT replace loops
61
- for (const item of items) {
62
- // Iteration control is yours.
63
- }
64
-
65
- // ❌ Mnemonica does NOT replace async/await orchestration
66
- const a = await serviceA.get();
67
- const b = await serviceB.process(a);
68
- // Mnemonica types the data, not the execution order.
69
-
70
- // ❌ Mnemonica does NOT replace service boundaries
71
- // You still write HTTP handlers, database queries, message queues.
72
- // Mnemonica types the data that flows through them.
73
-
74
- // ✅ Mnemonica DOES type the data at each stage
75
- const RequestData = define('RequestData', function(req) { this.method = req.method; });
76
- const ResponseData = RequestData.define('ResponseData', function(res) { this.body = res.body; });
77
- // The types track lineage; the services remain unchanged.
78
- ```
79
-
80
- ---
81
-
82
- ## Part 2: The Problem - Data Without Memory
83
-
84
- ### Traditional Approach: Plain Data Objects
85
-
86
- ```typescript
87
- // A plain log entry - just data, no history
88
- interface LogEntry {
89
- level: string;
90
- message: string;
91
- timestamp: number;
92
- }
93
-
94
- function log(message: string) {
95
- const entry: LogEntry = {
96
- level: 'info',
97
- message,
98
- timestamp: Date.now()
99
- };
100
- logs.push(entry);
101
- }
102
- ```
103
-
104
- **The Problem**: When you look at `entry`, you see:
105
- - ✓ The data (level, message, timestamp)
106
- - ✗ No metadata about how it was created
107
- - ✗ No type information beyond the interface
108
- - ✗ No relationship to parent types
109
- - ✗ No traceability through the system
110
-
111
- The data is **amnesiac** - it doesn't remember its own creation story.
112
-
113
- ### The Real-World Cost
114
-
115
- When debugging, you ask:
116
- - "Where was this log entry created?"
117
- - "What type of object created it?"
118
- - "Was it part of a batch or single call?"
119
- - "What's the parent context?"
120
-
121
- With plain data: You grep through code, hope for good variable names, trace manually.
122
-
123
- ---
124
-
125
- ## Part 3: The Solution - Mnemonica as Historical Reflection
126
-
127
- ### Mnemonica Approach: Data That Remembers
128
-
129
- ```typescript
130
- import { define, getProps } from 'mnemonica';
131
-
132
- // Mnemonica type definition
133
- const LoggerTab = define('LoggerTab', function() {
134
- this.createdAt = Date.now();
135
- });
136
-
137
- const LogEntry = LoggerTab.define('LogEntry', function(data) {
138
- this.level = data.level;
139
- this.message = data.message;
140
- this.timestamp = data.timestamp;
141
- });
142
-
143
- // Usage - same control flow, different data
144
- function log(message: string) {
145
- const loggerTab = new LoggerTab(); // Data root
146
- const entry = new loggerTab.LogEntry({ // Typed instance
147
- level: 'info',
148
- message,
149
- timestamp: Date.now()
150
- });
151
- logs.push(entry);
152
-
153
- // Later: introspect the instance
154
- const props = getProps(entry);
155
- console.log(props.__type__.TypeName); // 'LogEntry'
156
- console.log(props.__parent__); // LoggerTab instance
157
- console.log(props.__args__); // [{level, message, timestamp}]
158
- }
159
- ```
160
-
161
- **What Mnemonica Adds**:
162
-
163
- 1. **Type Hierarchy**: `entry` knows it's a `LogEntry` which belongs to `LoggerTab`
164
- 2. **Constructor Arguments**: Stored internally, accessible via `getProps(instance)`
165
- 3. **Creation Timestamp**: `loggerTab.createdAt` tracks when the context was created
166
- 4. **Inheritance Chain**: Can traverse `entry → LogEntry → LoggerTab`
167
- 5. **Usage Tracking**: Tracked separately via tooling (see Part 7: Ecosystem)
168
-
169
- ### The Data Now Carries Its History
170
-
171
- Looking at `entry`:
172
- - ✓ The data (level, message, timestamp)
173
- - ✓ Type metadata (`entry instanceof LogEntry`)
174
- - ✓ Parent relationship (`getProps(entry).__parent__` → LoggerTab instance)
175
- - ✓ Creation context (arguments stored internally)
176
- - ✓ System trace (via separate tooling)
177
-
178
- The data is **mnemonic** - it remembers how it was crafted.
179
-
180
- ---
181
-
182
- ## Part 4: What Mnemonica Is NOT
183
-
184
- ### Mnemonica Is NOT a Framework
185
-
186
- It doesn't dictate:
187
- - How you structure your services
188
- - How you write your algorithms
189
- - How you handle control flow
190
- - How you organize your code
191
-
192
- ### Mnemonica Is NOT a Control Flow Tool
193
-
194
- It doesn't:
195
- - Replace if/else statements
196
- - Change loop structures
197
- - Modify execution order
198
- - Touch service orchestration
199
- - Affect algorithm logic
200
-
201
- ### Mnemonica Is NOT About Behavior
202
-
203
- When you see code like:
204
- ```typescript
205
- class LoggerService {
206
- // THIS IS BEHAVIOR - stays untouched
207
- info(message: string) {
208
- this.outputChannel.appendLine(message);
209
- }
210
- }
211
- ```
212
-
213
- Mnemonica doesn't want to change the `info()` method. It doesn't care about `outputChannel`. The behavior (what the service does) remains completely under developer control.
214
-
215
- ---
216
-
217
- ## Part 5: What Mnemonica IS
218
-
219
- ### Mnemonica Is a Data Typing System
220
-
221
- It provides:
222
- - **Type constructors** (`define()` function)
223
- - **Instance creation** (`new Type()` pattern)
224
- - **Prototype chains** (inheritance via `Type.define()`)
225
- - **Property storage** (constructor args preserved internally)
226
- - **Type introspection** (`instanceof`, `getProps()`)
227
-
228
- ### Mnemonica Is Historical Reflection in Data
229
-
230
- Every Mnemonica instance carries:
231
- 1. **Type Identity**: What type of thing am I?
232
- 2. **Lineage**: What types am I descended from?
233
- 3. **Creation Context**: What arguments created me?
234
- 4. **Usage Points**: Where in the codebase was I instantiated?
235
-
236
- ### Mnemonica Is the DNA of Data Flow
237
-
238
- Just as DNA carries the instructions for building an organism, Mnemonica types carry the structure and history of data as it flows through a system.
239
-
240
- ---
241
-
242
- ## Part 6: Nominal Type System and Security
243
-
244
- ### TypeScript's Structural vs Mnemonica's Nominal Typing
245
-
246
- **TypeScript uses Structural Typing**:
247
- ```typescript
248
- interface Point { x: number; y: number; }
249
- interface Vector { x: number; y: number; }
250
-
251
- const p: Point = { x: 1, y: 2 };
252
- const v: Vector = p; // ✓ Valid - same shape, so compatible
253
- ```
254
-
255
- TypeScript cares about **shape compatibility**. If two types have the same properties, they're interchangeable.
256
-
257
- **Mnemonica uses Nominal Typing**:
258
- ```typescript
259
- const Point = define('Point', function(data) {
260
- this.x = data.x;
261
- this.y = data.y;
262
- });
263
-
264
- const Vector = define('Vector', function(data) {
265
- this.x = data.x;
266
- this.y = data.y;
267
- });
268
-
269
- const p = new Point({ x: 1, y: 2 });
270
- const v = new Vector({ x: 1, y: 2 });
271
-
272
- p instanceof Point; // true
273
- p instanceof Vector; // false - same shape, different nominal type!
274
- ```
275
-
276
- Mnemonica cares about **constructor identity**. Same shape, different type = not compatible.
277
-
278
- ### Protected `constructor.name` - Defense-in-Depth
279
-
280
- Mnemonica types have **read-only, protected constructor names**:
281
-
282
- ```typescript
283
- const User = define('User', function(data) {
284
- this.name = data.name;
285
- });
286
-
287
- const user = new User({ name: 'Alice' });
288
- user.constructor.name; // 'User' - readable
289
- user.constructor.name = 'Admin'; // ✗ Ignored/Fails - protected
290
- ```
291
-
292
- **Why This Matters**:
293
- - Prototype pollution attacks that rely on name spoofing are **blocked at the assignment level**
294
- - `instanceof` checks **prototype object references**, not constructor names, so name changes do not affect type identity
295
- - Constructor names are getter-protected and non-enumerable, making casual tampering impossible
296
- - Type identity is immutable once established
297
-
298
- **Threat Model**: This is defense-in-depth, not cryptographic security. A fully compromised execution environment can still use `Object.defineProperty` to redefine the getter. The protection targets casual prototype pollution and accidental corruption, not a determined attacker with full runtime access.
299
-
300
- ### Security Through `Object.create(null)`
301
-
302
- Mnemonica instances are **NOT instances of Object or Function**:
303
-
304
- ```typescript
305
- const instance = new MyType({...});
306
-
307
- instance instanceof Object; // false
308
- instance instanceof Function; // false
309
- Object.prototype.isPrototypeOf(instance); // false
310
- ```
311
-
312
- **How It's Achieved**:
313
- ```typescript
314
- // Mnemonica internally uses:
315
- const proto = Object.create(null); // No Object.prototype chain
316
- // ...type setup...
317
- const instance = Object.create(proto); // Pure prototype, no Object inheritance
318
- ```
319
-
320
- **Security Benefits**:
321
- 1. **No prototype pollution attacks** - `Object.prototype` mutations don't affect Mnemonica instances
322
- 2. **No injection via the legacy `__proto__` accessor** - Instances don't inherit from Object
323
- 3. **Isolated namespace** - Properties like `constructor`, `toString`, `valueOf` don't exist unless explicitly defined
324
- 4. **Clean property enumeration** - `for...in` loops don't see inherited Object properties
325
-
326
- ### The instanceof Check - Nominal Verification
327
-
328
- ```typescript
329
- const Admin = User.define('Admin', function(data) {
330
- this.permissions = data.permissions;
331
- });
332
-
333
- const admin = new Admin({ name: 'Bob', permissions: ['read', 'write'] });
334
-
335
- admin instanceof Admin; // true - exact type match
336
- admin instanceof User; // true - inheritance chain
337
- admin instanceof Object; // false - NOT an Object!
338
-
339
- // Structural typing would say "same shape = same type"
340
- // Nominal typing says "different constructor = different type"
341
- ```
342
-
343
- **Key Insight**: Mnemonica's `instanceof` answers the question **"was this instance created by this specific constructor?"** not **"does this instance have these properties?"**
344
-
345
- ### Why Nominal Types Matter for Data Flow
346
-
347
- When data flows through a system:
348
-
349
- ```typescript
350
- // Structural typing (TypeScript default):
351
- function processPayment(payment: { amount: number; currency: string }) {
352
- // Could receive Invoice, Refund, Deposit... anything with amount+currency
353
- // No way to distinguish at runtime!
354
- }
355
-
356
- // Nominal typing (Mnemonica):
357
- function processPayment(payment: InstanceType<typeof Payment>) {
358
- // Guaranteed to be a Payment instance
359
- // Can check: payment instanceof Refund ? handleRefund() : process()
360
- }
361
- ```
362
-
363
- Nominal types **preserve intent** as data flows. The type tells you **what the data represents**, not just **what properties it has**.
364
-
365
- ---
366
-
367
- ## Part 7: The Mnemonica Ecosystem - Complete Toolchain
368
-
369
- Mnemonica is not just a library - it's a **complete ecosystem** for type-safe, self-documenting data architecture. Here's how the pieces fit together:
370
-
371
- ### 1. Core: `mnemonica` - The Foundation
372
-
373
- **Purpose**: Runtime instance inheritance system
374
-
375
- ```bash
376
- npm install mnemonica
377
- ```
378
-
379
- **What it does**:
380
- - Defines types with `define()`
381
- - Creates instances with `new Type()`
382
- - Manages prototype chains for inheritance
383
- - Provides utilities: `getProps()`, `extract()`, `parse()`, `merge()`, `parent()`
384
-
385
- **Key Export**: `getProps(instance)` - Access internal properties:
386
- ```typescript
387
- import { getProps } from 'mnemonica';
388
-
389
- const user = new User({ name: 'Alice' });
390
- const props = getProps(user);
391
- // props.__type__ - Type definition
392
- // props.__parent__ - Parent instance
393
- // props.__args__ - Constructor arguments
394
- // props.__timestamp__ - Creation time
395
- // props.__subtypes__ - Child type registry
396
- ```
397
-
398
- **Note**: Properties are stored internally (WeakMap), NOT in prototype chain. Use `getProps()` to access them.
399
-
400
- ---
401
-
402
- ### 2. Tactica: `@mnemonica/tactica` - Type Generator
403
-
404
- **Purpose**: Static analysis + TypeScript generation
405
-
406
- **What it does**:
407
- - Scans your codebase for `define()` calls
408
- - Generates TypeScript definitions (`.tactica/types.ts`)
409
- - Creates type registry augmentation (`.tactica/registry.ts`)
410
- - Tracks type instantiations (`.tactica/usages.json`)
411
- - Builds definition map (`.tactica/definitions.json`)
412
-
413
- **Usage**:
414
- ```bash
415
- npx tactica # Analyze and generate types
416
- ```
417
-
418
- **Generated Files**:
419
- - `types.ts` - Complete TypeScript interfaces
420
- - `registry.ts` - TypeRegistry augmentation for `lookup()`
421
- - `definitions.json` - Type metadata (properties, location)
422
- - `usages.json` - Where types are instantiated
423
-
424
- **The Magic**: Enables type-safe `lookup()`:
425
- ```typescript
426
- import { lookup } from 'mnemonica';
427
- import './.tactica/registry'; // Augments TypeRegistry
428
-
429
- const UserType = lookup('UserType'); // TypeScript knows the type!
430
- const user = new UserType({ name: 'Alice' }); // Full intellisense!
431
- ```
432
-
433
- ---
434
-
435
- ### 3. Topologica: `@mnemonica/topologica` - File Discovery
436
-
437
- **Purpose**: Filesystem-based type discovery
438
-
439
- **What it does**:
440
- - Scans directories for type definitions
441
- - Supports nested directory structure (Parent/Child/index.js)
442
- - Supports flat files (Parent.js with Child definitions)
443
- - Automatically wires up inheritance
444
-
445
- **Usage**:
446
- ```javascript
447
- const { loader } = require('@mnemonica/topologica');
448
- const { define } = require('mnemonica');
449
-
450
- const types = loader('./src/models', define);
451
- // types.User, types.User.Admin, etc.
452
- ```
453
-
454
- **Why**: Eliminates manual type registration. Just create files/directories, Topologica finds and wires them.
455
-
456
- ---
457
-
458
- ### 4. Typeomatica: `@mnemonica/typeomatica` - Runtime Types
459
-
460
- **Purpose**: Runtime type checking with TypeScript parity
461
-
462
- **What it does**:
463
- - Validates data at runtime against Mnemonica types
464
- - Provides type guards
465
- - Ensures data integrity
466
-
467
- **The Vision**: Type-safe at compile time (TypeScript) AND runtime (Typeomatica)
468
-
469
- ---
470
-
471
- ### 5. MnemoGraphica: VS Code Extension - Visualization
472
-
473
- **Purpose**: Visualize your type system
474
-
475
- **What it does**:
476
- - Tree view of type hierarchies
477
- - 2D/3D graph visualization
478
- - Navigation to type definitions
479
- - Usage tracking
480
-
481
- **The Self-Referential Moment**: MnemoGraphica visualizes its own Mnemonica types!
482
-
483
- ---
484
-
485
- ### 6. Strategy: `@mnemonica/strategy` - MCP Server
486
-
487
- **Purpose**: AI integration via Model Context Protocol
488
-
489
- **What it does**:
490
- - Exposes Mnemonica types to AI agents
491
- - Enables runtime type introspection
492
- - Facilitates AI self-reflection
493
-
494
- ---
495
-
496
- ## Part 8: HoTT - Homotopy Type Theory (The Sexy Math)
497
-
498
- ### Why HoTT Matters for Mnemonica
499
-
500
- **Warning**: This section contains advanced mathematics that is simultaneously:
501
- - Incredibly profound
502
- - Potentially overwhelming
503
- - Surprisingly applicable to prototype inheritance
504
-
505
- ### The Univalence Axiom: Equivalence is Equality
506
-
507
- In Homotopy Type Theory:
508
- > **Univalence Axiom**: `(A ≃ B) ≅ (A = B)`
509
- >
510
- > Two types are equal if they are equivalent.
511
-
512
- In Mnemonica terms:
513
- > Two data structures are the same if they carry the same information, regardless of their specific shape.
514
-
515
- ### Path Types: Prototype Chains as Paths
516
-
517
- In HoTT, a **path** represents continuous transformation from one point to another:
518
- > `Path_A(x, y)` - A path from x to y in space A
519
-
520
- In Mnemonica, prototype chains ARE paths:
521
- ```typescript
522
- const User = define('User', function() {});
523
- const Admin = User.define('Admin', function() {});
524
- const SuperAdmin = Admin.define('SuperAdmin', function() {});
525
-
526
- // Path: User ──► Admin ──► SuperAdmin
527
- const superAdmin = new SuperAdmin({});
528
-
529
- // Each instance is a point in the "space of types"
530
- // The prototype chain is the path connecting them
531
- ```
532
-
533
- **The Hot Connection**: In HoTT, paths can be composed, inverted, and transformed. In Mnemonica:
534
- - **Composition**: `new user.SubType()` extends the path
535
- - **Inversion**: `utils.parent(instance)` traverses backward
536
- - **Transformation**: `utils.fork(instance)` creates a new path with same starting point
537
-
538
- ### Higher Inductive Types: The Family Tree
539
-
540
- HoTT's **Higher Inductive Types** (HITs) have both:
541
- - **Point constructors** (objects)
542
- - **Path constructors** (relationships)
543
-
544
- Mnemonica instances are exactly this:
545
- ```typescript
546
- const Family = define('Family', function() {});
547
- const Parent = Family.define('Parent', function() {});
548
- const Child = Parent.define('Child', function() {});
549
-
550
- // Point constructors: Family, Parent, Child instances
551
- // Path constructors: prototype chain relationships
552
-
553
- const child = new Child({});
554
- // child is a point
555
- // Object.getPrototypeOf(child) → Child.prototype is a path
556
- // Object.getPrototypeOf(Child.prototype) → Parent.prototype is another path
557
- // And so on...
558
- ```
559
-
560
- ### The Sexy Math Joke (You Asked For It)
561
-
562
- In Homotopy Type Theory, **univalence** tells us that equivalence IS equality.
563
-
564
- In Mnemonica, when we do:
565
- ```typescript
566
- const child = new parent.Child({});
567
- ```
568
-
569
- We are performing the **sexual reproduction of types**:
570
- - The **parent instance** is the... parent (obviously)
571
- - The **Child constructor** carries the genetic blueprint
572
- - The **new instance** is the offspring
573
- - The **prototype chain** is the family tree
574
-
575
- This is literally HoTT's path composition: we create a new point (instance) by composing paths (constructor + parent).
576
-
577
- **Why it's hot**: Because in HoTT, equivalent paths are equal. And in Mnemonica, equivalent data flows are the same type. The univalence axiom ensures that if two instances carry the same information, they're essentially the same - even if they came from different parents.
578
-
579
- **The punchline**: Mnemonica is doing homotopy theory with JavaScript prototypes. We're just too busy to notice because we're having too much fun with the family tree metaphors.
580
-
581
- ---
582
-
583
- ## Part 9: Practical Examples
584
-
585
- ### Example 1: Logger Service (Data Layer Only)
586
-
587
- ```typescript
588
- // BEFORE: Plain data, no history
589
- class LoggerService {
590
- private logs: Array<{level: string, message: string}> = [];
591
-
592
- info(message: string) {
593
- this.logs.push({level: 'info', message}); // Amnesiac data
594
- }
595
- }
596
-
597
- // AFTER: Mnemonica data with embedded history
598
- import { LoggerTab, LogEntry } from './models';
599
-
600
- class LoggerService {
601
- private loggerTab = new LoggerTab(); // Data root
602
- private logs: InstanceType<typeof LoggerTab.LogEntry>[] = [];
603
-
604
- info(message: string) {
605
- const entry = new this.loggerTab.LogEntry({ // Mnemonic data
606
- level: 'info',
607
- message,
608
- timestamp: Date.now()
609
- });
610
- this.logs.push(entry); // Data now carries its type history
611
- }
612
- }
613
- ```
614
-
615
- **Note**: The service (behavior) is identical. Only the data storage changed.
616
-
617
- ### Example 2: Accessing Instance Properties
618
-
619
- ```typescript
620
- import { define, getProps } from 'mnemonica';
621
-
622
- const User = define('User', function(data) {
623
- this.name = data.name;
624
- this.email = data.email;
625
- });
626
-
627
- const user = new User({ name: 'Alice', email: 'alice@example.com' });
628
-
629
- // Access internal properties
630
- const props = getProps(user);
631
-
632
- console.log(props.__type__.TypeName); // 'User'
633
- console.log(props.__args__); // [{name: 'Alice', email: '...'}]
634
- console.log(props.__timestamp__); // 1234567890
635
- console.log(props.__parent__); // undefined (root type)
636
- ```
637
-
638
- **Important**: Use `getProps()` - properties are NOT stored in prototype chain!
639
-
640
- ---
641
-
642
- ## Part 10: For Future AI Agents
643
-
644
- ### When Working with Mnemonica
645
-
646
- **DO**:
647
- - Transform data storage into Mnemonica instances
648
- - Keep services/classes intact (they're behavior)
649
- - Track where `new Type()` calls happen
650
- - Think "what data structure fits here?"
651
- - Ask "what's the parent type of this data?"
652
- - Use `getProps(instance)` to introspect
653
-
654
- **DON'T**:
655
- - Worry about changing control flow (it's not happening)
656
- - Protect algorithms from modification (not requested)
657
- - Overthink service architecture (stay focused on data)
658
- - Assume the user wants behavior changes (they don't)
659
-
660
- ### The Golden Rule
661
-
662
- > If you're worrying about "how the code executes" or "what the algorithm does" - you're thinking about the wrong layer. Mnemonica is about "what shape the data has" and "where the data came from."
663
-
664
- ---
665
-
666
- ## Part 11: Summary
667
-
668
- **Mnemonica Is**:
669
- - A way to give data memory of its own creation
670
- - A typing system for data flow
671
- - Historical reflection embedded in data structures
672
- - The DNA of data as it moves through systems
673
- - A **nominal type system** (constructor identity, not shape)
674
- - A **secure** system (defense-in-depth against prototype pollution, nominal typing prevents type confusion)
675
-
676
- **Mnemonica Is NOT**:
677
- - A control flow framework
678
- - An algorithm modification tool
679
- - A service orchestration system
680
- - About changing how code executes
681
-
682
- **The Ecosystem**:
683
- - **Core** (`mnemonica`): Runtime instance inheritance
684
- - **Tactica** (`@mnemonica/tactica`): Type generation and static analysis
685
- - **Topologica** (`@mnemonica/topologica`): Filesystem-based type discovery
686
- - **Typeomatica** (`@mnemonica/typeomatica`): Runtime type checking
687
- - **MnemoGraphica**: VS Code visualization
688
- - **Strategy** (`@mnemonica/strategy`): AI integration via MCP
689
-
690
- **The User Is**:
691
- - Asking to transform data storage (not behavior)
692
- - Seeking self-referential data architecture
693
- - Not trying to break control flow (ever)
694
- - Probably smiling while reading this
695
- - Possibly making math jokes about HoTT being "hot"
696
-
697
- ---
698
-
699
- ## Final Note
700
-
701
- When in doubt, remember: **Mnemonica types are the answer to "what is this data?" and "where did it come from?" - never "how does this code work?"**
702
-
703
- The algorithms work however they need to work. The data just carries better metadata about itself.
704
-
705
- And yes, the HoTT connection is real. Prototype inheritance IS homotopy theory in disguise. We're just doing topology with JavaScript objects, and it's beautiful.
706
-
707
- *This document exists because an AI agent (me) needed to be reminded that the user is not mad, is not trying to break control flow, and that HoTT is indeed hot. Thank you for your patience.*