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.
- package/FOR_HUMANS.md +160 -125
- package/README.md +70 -249
- package/build/api/types/index.js +18 -12
- package/docs/UTILS.md +97 -8
- package/docs/decorate.md +1 -1
- package/docs/empathy-in-ai.md +20 -10
- package/docs/prototype-chain.md +8 -7
- package/docs/typed-lookup.md +195 -5
- package/docs/typeomatica.md +8 -345
- package/package.json +6 -10
- package/src/api/types/index.ts +33 -20
- package/.ai/AGENTS.md +0 -151
- package/.ai/ARCHITECT.md +0 -110
- package/.ai/DEBUG.md +0 -178
- package/.ai/ONBOARDING.md +0 -189
- package/.ai/PROTOTYPE-CHAIN.md +0 -155
- package/.ai/mode-ask.md +0 -121
- package/.ai/mode-orchestrator.md +0 -141
- package/.ai/performance-vs-security.md +0 -395
- package/.ai/rules-async-constructors.md +0 -352
- package/.ai/rules-code-style.md +0 -95
- package/.ai/rules-coding.md +0 -246
- package/.ai/rules-context-condensing.md +0 -50
- package/.ai/rules-contributing.md +0 -227
- package/.ai/rules-define-patterns.md +0 -159
- package/.ai/rules-ecosystem.md +0 -140
- package/.ai/rules-error-system.md +0 -66
- package/.ai/rules-hooks.md +0 -46
- package/.ai/rules-instance-methods.md +0 -93
- package/.ai/rules-philosophy.md +0 -231
- package/.ai/rules-reminders.md +0 -19
- package/.ai/rules-testing.md +0 -66
- package/.ai/rules-type-system.md +0 -124
- package/.ai/theory-of-operations.md +0 -224
- package/AGENTS.md +0 -345
- package/CONTRIBUTING.md +0 -150
- package/SKILL.md +0 -114
- package/docs/ai-learning-trajectory.md +0 -141
- package/docs/purpose.md +0 -707
- package/docs/tactica-deep-dive.md +0 -629
- package/docs/tactica-pattern.md +0 -146
package/docs/typeomatica.md
CHANGED
|
@@ -13,12 +13,8 @@ TypeØmatica is a companion library that provides strict runtime type checking f
|
|
|
13
13
|
- [Core Concepts](#core-concepts)
|
|
14
14
|
- [API Reference](#api-reference)
|
|
15
15
|
- [Integration Patterns](#integration-patterns)
|
|
16
|
-
- [Type Examples](#type-examples)
|
|
17
|
-
- [Working with Wrapped Values](#working-with-wrapped-values)
|
|
18
|
-
- [Error Handling](#error-handling)
|
|
19
|
-
- [Advanced: Custom Fields](#advanced-custom-fields)
|
|
20
16
|
- [Complete Integration Example](#complete-integration-example)
|
|
21
|
-
- [
|
|
17
|
+
- [Benefits Summary](#benefits-summary)
|
|
22
18
|
|
|
23
19
|
---
|
|
24
20
|
|
|
@@ -96,68 +92,11 @@ Decorators apply **bottom-to-top** (inner to outer). `@Strict` wraps the class f
|
|
|
96
92
|
|
|
97
93
|
## API Reference
|
|
98
94
|
|
|
99
|
-
|
|
95
|
+
The full typeomatica API — `BaseClass`, `BasePrototype`, the `@Strict()` decorator and its options, `FieldConstructor`, `SymbolTypeomaticaProxyReference`, `SymbolInitialValue`, and the complete error reference (`Type Mismatch`, `Value Access Denied`, and friends) — is documented in the typeomatica package itself:
|
|
100
96
|
|
|
101
|
-
|
|
97
|
+
**<https://www.npmjs.com/package/typeomatica>**
|
|
102
98
|
|
|
103
|
-
|
|
104
|
-
import { BaseClass } from 'typeomatica';
|
|
105
|
-
|
|
106
|
-
class MyClass extends BaseClass {
|
|
107
|
-
field: string = 'value';
|
|
108
|
-
constructor() {
|
|
109
|
-
super();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### BasePrototype / BaseConstructorPrototype
|
|
115
|
-
|
|
116
|
-
Functional equivalent of `BaseClass`.
|
|
117
|
-
|
|
118
|
-
```typescript
|
|
119
|
-
import { BasePrototype } from 'typeomatica';
|
|
120
|
-
|
|
121
|
-
const Base = BasePrototype({ initialProp: 123 });
|
|
122
|
-
class MyClass extends Base { }
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
### @Strict() Decorator
|
|
126
|
-
|
|
127
|
-
Apply strict typing to any class without extending BaseClass.
|
|
128
|
-
|
|
129
|
-
```typescript
|
|
130
|
-
import { Strict } from 'typeomatica';
|
|
131
|
-
|
|
132
|
-
@Strict({ deep: true })
|
|
133
|
-
class MyClass {
|
|
134
|
-
field: number = 0;
|
|
135
|
-
}
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
**Options:**
|
|
139
|
-
- `deep: true` - Enables recursive/deep property checking
|
|
140
|
-
- Pass initial values as properties to pre-define types
|
|
141
|
-
|
|
142
|
-
### SymbolTypeomaticaProxyReference
|
|
143
|
-
|
|
144
|
-
Access the internal proxy reference.
|
|
145
|
-
|
|
146
|
-
```typescript
|
|
147
|
-
import { SymbolTypeomaticaProxyReference } from 'typeomatica';
|
|
148
|
-
|
|
149
|
-
const proxyRef = instance[SymbolTypeomaticaProxyReference];
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
### SymbolInitialValue
|
|
153
|
-
|
|
154
|
-
Access the original initial value of a property.
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
import { SymbolInitialValue } from 'typeomatica';
|
|
158
|
-
|
|
159
|
-
const originalValue = instance[SymbolInitialValue]('fieldName');
|
|
160
|
-
```
|
|
99
|
+
The sections below cover only what you need to combine typeomatica with mnemonica.
|
|
161
100
|
|
|
162
101
|
---
|
|
163
102
|
|
|
@@ -251,275 +190,14 @@ const PremiumCustomer = Customer.define('PremiumCustomer', function(this: { tier
|
|
|
251
190
|
this.tier = 'gold';
|
|
252
191
|
});
|
|
253
192
|
|
|
254
|
-
const
|
|
193
|
+
const premiumCustomer = new Customer();
|
|
194
|
+
const premium = new premiumCustomer.PremiumCustomer();
|
|
255
195
|
// @ts-ignore
|
|
256
196
|
premium.tier = 123; // ✗ TypeError: Type Mismatch
|
|
257
197
|
```
|
|
258
198
|
|
|
259
199
|
---
|
|
260
200
|
|
|
261
|
-
## Type Examples
|
|
262
|
-
|
|
263
|
-
### Primitives
|
|
264
|
-
|
|
265
|
-
All primitive types are fully supported and enforced.
|
|
266
|
-
|
|
267
|
-
```typescript
|
|
268
|
-
class Primitives extends BaseClass {
|
|
269
|
-
str: string = 'hello';
|
|
270
|
-
num: number = 42;
|
|
271
|
-
bool: boolean = true;
|
|
272
|
-
bigint: bigint = BigInt(100);
|
|
273
|
-
sym: symbol = Symbol('test');
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
const p = new Primitives();
|
|
277
|
-
|
|
278
|
-
// Valid assignments
|
|
279
|
-
p.str = 'world'; // ✓ string → string
|
|
280
|
-
p.num = 100; // ✓ number → number
|
|
281
|
-
p.bool = false; // ✓ boolean → boolean
|
|
282
|
-
p.bigint = BigInt(200); // ✓ bigint → bigint
|
|
283
|
-
|
|
284
|
-
// Invalid assignments throw TypeError
|
|
285
|
-
// @ts-ignore
|
|
286
|
-
p.str = 123; // ✗ TypeError: Type Mismatch
|
|
287
|
-
// @ts-ignore
|
|
288
|
-
p.num = '100'; // ✗ TypeError: Type Mismatch
|
|
289
|
-
// @ts-ignore
|
|
290
|
-
p.bool = 'true'; // ✗ TypeError: Type Mismatch
|
|
291
|
-
// @ts-ignore
|
|
292
|
-
p.bigint = 100; // ✗ TypeError: Type Mismatch
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
### Null and Undefined
|
|
296
|
-
|
|
297
|
-
Null and undefined are distinct types.
|
|
298
|
-
|
|
299
|
-
```typescript
|
|
300
|
-
class Nullable extends BaseClass {
|
|
301
|
-
nullValue: null = null;
|
|
302
|
-
undefinedValue: undefined = undefined;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
const n = new Nullable();
|
|
306
|
-
|
|
307
|
-
n.nullValue = null; // ✓
|
|
308
|
-
n.undefinedValue = undefined; // ✓
|
|
309
|
-
|
|
310
|
-
// @ts-ignore
|
|
311
|
-
n.nullValue = undefined; // ✗ TypeError: Type Mismatch
|
|
312
|
-
// @ts-ignore
|
|
313
|
-
n.nullValue = 0; // ✗ TypeError: Type Mismatch
|
|
314
|
-
// @ts-ignore
|
|
315
|
-
n.undefinedValue = null; // ✗ TypeError: Type Mismatch
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
### Objects
|
|
319
|
-
|
|
320
|
-
Object types are strictly enforced by constructor.
|
|
321
|
-
|
|
322
|
-
```typescript
|
|
323
|
-
class WithObject extends BaseClass {
|
|
324
|
-
data: object = {};
|
|
325
|
-
list: number[] = [];
|
|
326
|
-
map: Map<string, number> = new Map();
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const w = new WithObject();
|
|
330
|
-
|
|
331
|
-
w.data = { a: 1 }; // ✓ Same type (object)
|
|
332
|
-
w.data = { b: 2 }; // ✓ Same type (object)
|
|
333
|
-
w.list = [1, 2, 3]; // ✓ Array → Array
|
|
334
|
-
w.map = new Map(); // ✓ Map → Map
|
|
335
|
-
|
|
336
|
-
// @ts-ignore
|
|
337
|
-
w.data = 123; // ✗ TypeError: Type Mismatch
|
|
338
|
-
// @ts-ignore
|
|
339
|
-
w.data = new Set(); // ✗ TypeError: Type Mismatch (Set !== Object)
|
|
340
|
-
// @ts-ignore
|
|
341
|
-
w.list = new Set(); // ✗ TypeError: Type Mismatch (Set !== Array)
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
---
|
|
345
|
-
|
|
346
|
-
## Working with Wrapped Values
|
|
347
|
-
|
|
348
|
-
TypeØmatica wraps primitive values to enforce type safety. Use `valueOf()` to access the raw value for operations.
|
|
349
|
-
|
|
350
|
-
### Numeric Operations
|
|
351
|
-
|
|
352
|
-
```typescript
|
|
353
|
-
class Calculations extends BaseClass {
|
|
354
|
-
count: number = 10;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
const calc = new Calculations();
|
|
358
|
-
|
|
359
|
-
// ✗ Direct arithmetic throws
|
|
360
|
-
try {
|
|
361
|
-
const result = calc.count + 5;
|
|
362
|
-
} catch (e) {
|
|
363
|
-
// ReferenceError: Value Access Denied
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
// ✓ Use valueOf() for operations
|
|
367
|
-
const result = calc.count.valueOf() + 5; // 15
|
|
368
|
-
|
|
369
|
-
// ✓ Use unary + for coercion
|
|
370
|
-
const sum = 3 + +calc.count; // 13
|
|
371
|
-
|
|
372
|
-
// ✓ Comparison works with valueOf()
|
|
373
|
-
if (calc.count.valueOf() > 5) {
|
|
374
|
-
// ...
|
|
375
|
-
}
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
### String Operations
|
|
379
|
-
|
|
380
|
-
```typescript
|
|
381
|
-
class TextData extends BaseClass {
|
|
382
|
-
message: string = 'hello';
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
const text = new TextData();
|
|
386
|
-
|
|
387
|
-
// Access string methods through valueOf()
|
|
388
|
-
text.message.valueOf().toUpperCase(); // 'HELLO'
|
|
389
|
-
text.message.valueOf().length; // 5
|
|
390
|
-
text.message.valueOf().substring(0, 2); // 'he'
|
|
391
|
-
|
|
392
|
-
// Template literals require valueOf()
|
|
393
|
-
const greeting = `Message: ${text.message.valueOf()}`;
|
|
394
|
-
```
|
|
395
|
-
|
|
396
|
-
### Boolean Operations
|
|
397
|
-
|
|
398
|
-
```typescript
|
|
399
|
-
class Flags extends BaseClass {
|
|
400
|
-
active: boolean = true;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
const flags = new Flags();
|
|
404
|
-
|
|
405
|
-
// ✗ Direct comparison throws
|
|
406
|
-
try {
|
|
407
|
-
if (flags.active) { } // May throw in some contexts
|
|
408
|
-
} catch (e) {
|
|
409
|
-
// ReferenceError: Value Access Denied
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
// ✓ Use valueOf() for conditions
|
|
413
|
-
if (flags.active.valueOf()) {
|
|
414
|
-
// ...
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// ✓ Comparison with valueOf()
|
|
418
|
-
const isActive = flags.active.valueOf() === true;
|
|
419
|
-
```
|
|
420
|
-
|
|
421
|
-
---
|
|
422
|
-
|
|
423
|
-
## Error Handling
|
|
424
|
-
|
|
425
|
-
TypeØmatica throws specific error types for different violations.
|
|
426
|
-
|
|
427
|
-
```typescript
|
|
428
|
-
import { BaseClass } from 'typeomatica';
|
|
429
|
-
|
|
430
|
-
class SecureData extends BaseClass {
|
|
431
|
-
id: number = 1;
|
|
432
|
-
name: string = 'test';
|
|
433
|
-
data: object = {};
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
const secure = new SecureData();
|
|
437
|
-
|
|
438
|
-
// Type Mismatch - wrong type assignment
|
|
439
|
-
try {
|
|
440
|
-
// @ts-ignore
|
|
441
|
-
secure.id = 'not a number';
|
|
442
|
-
} catch (e: any) {
|
|
443
|
-
console.log(e.message); // 'Type Mismatch'
|
|
444
|
-
console.log(e instanceof TypeError); // true
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
// Access Denied - wrong receiver context
|
|
448
|
-
const upper = Object.create(secure);
|
|
449
|
-
try {
|
|
450
|
-
upper.id = 2;
|
|
451
|
-
} catch (e: any) {
|
|
452
|
-
console.log(e.message); // 'Value Access Denied'
|
|
453
|
-
console.log(e instanceof ReferenceError); // true
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
// Undefined Property - accessing non-existent
|
|
457
|
-
try {
|
|
458
|
-
// @ts-ignore
|
|
459
|
-
secure.nonExistent;
|
|
460
|
-
} catch (e: any) {
|
|
461
|
-
console.log(e.message);
|
|
462
|
-
// 'Attempt to Access to Undefined Prop: [ nonExistent ] for SecureData'
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
// Functions Restricted - methods on data objects
|
|
466
|
-
try {
|
|
467
|
-
// @ts-ignore
|
|
468
|
-
secure.name = function() {};
|
|
469
|
-
} catch (e: any) {
|
|
470
|
-
console.log(e.message); // 'Functions are Restricted'
|
|
471
|
-
}
|
|
472
|
-
```
|
|
473
|
-
|
|
474
|
-
---
|
|
475
|
-
|
|
476
|
-
## Advanced: Custom Fields
|
|
477
|
-
|
|
478
|
-
Use `FieldConstructor` to create custom property behavior.
|
|
479
|
-
|
|
480
|
-
```typescript
|
|
481
|
-
import { BaseClass, FieldConstructor, SymbolInitialValue } from 'typeomatica';
|
|
482
|
-
|
|
483
|
-
// Read-only field implementation
|
|
484
|
-
class ReadOnlyField extends FieldConstructor<string> {
|
|
485
|
-
private _value: string;
|
|
486
|
-
|
|
487
|
-
constructor(value: string) {
|
|
488
|
-
super(value);
|
|
489
|
-
this._value = value;
|
|
490
|
-
// Make enumerable for Object.keys()
|
|
491
|
-
Reflect.defineProperty(this, 'enumerable', { value: true });
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
get() {
|
|
495
|
-
return this._value;
|
|
496
|
-
}
|
|
497
|
-
// No set() method = read-only
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// Usage
|
|
501
|
-
const readOnly = new ReadOnlyField('v1.0.0');
|
|
502
|
-
|
|
503
|
-
class Config extends BaseClass {
|
|
504
|
-
version = readOnly;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
const cfg = new Config();
|
|
508
|
-
console.log(cfg.version); // 'v1.0.0'
|
|
509
|
-
|
|
510
|
-
try {
|
|
511
|
-
cfg.version = 'v2.0.0'; // ✗ Throws!
|
|
512
|
-
} catch (e: any) {
|
|
513
|
-
console.log(e.message); // 'Re-Assirnment is Forbidden'
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
// Access initial value
|
|
517
|
-
const initial = cfg[SymbolInitialValue]('version');
|
|
518
|
-
console.log(initial); // 'v1.0.0'
|
|
519
|
-
```
|
|
520
|
-
|
|
521
|
-
---
|
|
522
|
-
|
|
523
201
|
## Complete Integration Example
|
|
524
202
|
|
|
525
203
|
Full example combining mnemonica's inheritance with typeomatica's runtime safety.
|
|
@@ -569,8 +247,8 @@ const Admin = User.define('Admin', function(this: {
|
|
|
569
247
|
// Create instances with full type safety
|
|
570
248
|
// ==========================================
|
|
571
249
|
const entity = new Entity();
|
|
572
|
-
const user = new User();
|
|
573
|
-
const admin = new Admin();
|
|
250
|
+
const user = new entity.User(); // subtypes construct from a parent instance
|
|
251
|
+
const admin = new user.Admin();
|
|
574
252
|
|
|
575
253
|
// Runtime type enforcement prevents bugs
|
|
576
254
|
user.email = 'john@example.com'; // ✓ Works
|
|
@@ -589,21 +267,6 @@ const id = entity.id.valueOf(); // Get raw string value
|
|
|
589
267
|
|
|
590
268
|
---
|
|
591
269
|
|
|
592
|
-
## Error Reference
|
|
593
|
-
|
|
594
|
-
| Error Message | Error Type | When Thrown |
|
|
595
|
-
|---------------|------------|-------------|
|
|
596
|
-
| `Type Mismatch` | TypeError | Assigning wrong type to property (e.g., string to number field) |
|
|
597
|
-
| `Value Access Denied` | ReferenceError | Accessing property from wrong context/receiver |
|
|
598
|
-
| `Attempt to Access to Undefined Prop` | Error | Reading property that doesn't exist on the object |
|
|
599
|
-
| `Functions are Restricted` | TypeError | Assigning function to data type property |
|
|
600
|
-
| `Re-Assirnment is Forbidden` | TypeError | Modifying read-only field (FieldConstructor without setter) |
|
|
601
|
-
| `Setting prototype is not allowed` | Error | Calling `Object.setPrototypeOf()` on instance |
|
|
602
|
-
| `Defining new Properties is not allowed` | Error | Calling `Object.defineProperty()` on instance |
|
|
603
|
-
| `Properties Deletion is not allowed` | Error | Calling `delete` on instance property |
|
|
604
|
-
|
|
605
|
-
---
|
|
606
|
-
|
|
607
270
|
## Benefits Summary
|
|
608
271
|
|
|
609
272
|
| Feature | TypeScript | TypeØmatica | Mnemonica |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mnemonica",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "AI-agent ready instance inheritance system for JavaScript/TypeScript via prototype chains",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./build/index.js",
|
|
@@ -22,10 +22,6 @@
|
|
|
22
22
|
"README.md",
|
|
23
23
|
"FOR_HUMANS.md",
|
|
24
24
|
"LICENSE",
|
|
25
|
-
"AGENTS.md",
|
|
26
|
-
"SKILL.md",
|
|
27
|
-
"CONTRIBUTING.md",
|
|
28
|
-
".ai",
|
|
29
25
|
"docs",
|
|
30
26
|
"src",
|
|
31
27
|
"module",
|
|
@@ -97,11 +93,11 @@
|
|
|
97
93
|
"devDependencies": {
|
|
98
94
|
"@eslint/eslintrc": "^3.3.6",
|
|
99
95
|
"@eslint/js": "^9.21.0",
|
|
100
|
-
"@mnemonica/tactica": "^0.1.
|
|
96
|
+
"@mnemonica/tactica": "^0.1.5",
|
|
101
97
|
"@types/jest": "^29.5.14",
|
|
102
98
|
"@types/node": "^22.20.1",
|
|
103
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
104
|
-
"@typescript-eslint/parser": "^8.
|
|
99
|
+
"@typescript-eslint/eslint-plugin": "^8.67.0",
|
|
100
|
+
"@typescript-eslint/parser": "^8.67.0",
|
|
105
101
|
"chai": "^5.3.3",
|
|
106
102
|
"eslint": "^9.39.5",
|
|
107
103
|
"eslint-plugin-import": "^2.32.0",
|
|
@@ -113,12 +109,12 @@
|
|
|
113
109
|
"json5": "^2.2.3",
|
|
114
110
|
"lint-staged": "^15.5.2",
|
|
115
111
|
"markdown-link-check": "^3.15.0",
|
|
116
|
-
"mocha": "^11.
|
|
112
|
+
"mocha": "^11.8.0",
|
|
117
113
|
"mocha-lcov-reporter": "^1.3.0",
|
|
118
114
|
"nyc": "^17.1.0",
|
|
119
115
|
"oxlint": "^0.16.12",
|
|
120
116
|
"ts-jest": "^29.4.12",
|
|
121
|
-
"typeomatica": "^0.3.
|
|
117
|
+
"typeomatica": "^0.3.60",
|
|
122
118
|
"typescript": "^6.0.3"
|
|
123
119
|
},
|
|
124
120
|
"engines": {
|
package/src/api/types/index.ts
CHANGED
|
@@ -149,22 +149,7 @@ const TypeDescriptor = function (
|
|
|
149
149
|
|
|
150
150
|
config,
|
|
151
151
|
|
|
152
|
-
hooks : Object.create(null)
|
|
153
|
-
|
|
154
|
-
decorate : function (options?: object) {
|
|
155
|
-
const self = type;
|
|
156
|
-
const decorator = function (cstr: CallableFunction) {
|
|
157
|
-
const { name } = cstr;
|
|
158
|
-
const defineResult = self.define(
|
|
159
|
-
name,
|
|
160
|
-
cstr,
|
|
161
|
-
options
|
|
162
|
-
);
|
|
163
|
-
const decoratedResult = defineResult as unknown as CallableFunction;
|
|
164
|
-
return decoratedResult;
|
|
165
|
-
};
|
|
166
|
-
return decorator;
|
|
167
|
-
},
|
|
152
|
+
hooks : Object.create(null)
|
|
168
153
|
|
|
169
154
|
}
|
|
170
155
|
);
|
|
@@ -281,6 +266,34 @@ TypeDescriptor.prototype.lookup = function (
|
|
|
281
266
|
return rootResult;
|
|
282
267
|
};
|
|
283
268
|
|
|
269
|
+
// prototype-level getter (not a plain method) so that both call
|
|
270
|
+
// forms keep working: type.decorate(options) and the destructured
|
|
271
|
+
// const { decorate } = type — the getter binds the current
|
|
272
|
+
// descriptor at access time, same as the collection-level decorate
|
|
273
|
+
odp(
|
|
274
|
+
TypeDescriptor.prototype,
|
|
275
|
+
'decorate', {
|
|
276
|
+
get (this: TypeDescriptorInstance) {
|
|
277
|
+
const self = this;
|
|
278
|
+
const result = function (options?: object) {
|
|
279
|
+
const decorator = function (cstr: CallableFunction) {
|
|
280
|
+
const { name } = cstr;
|
|
281
|
+
const defineResult = self.define(
|
|
282
|
+
name,
|
|
283
|
+
cstr,
|
|
284
|
+
options
|
|
285
|
+
);
|
|
286
|
+
const decoratedResult = defineResult as unknown as CallableFunction;
|
|
287
|
+
return decoratedResult;
|
|
288
|
+
};
|
|
289
|
+
return decorator;
|
|
290
|
+
};
|
|
291
|
+
return result;
|
|
292
|
+
},
|
|
293
|
+
enumerable : true
|
|
294
|
+
}
|
|
295
|
+
);
|
|
296
|
+
|
|
284
297
|
odp(
|
|
285
298
|
TypeDescriptor.prototype,
|
|
286
299
|
Symbol.hasInstance, {
|
|
@@ -325,8 +338,8 @@ const resolveDefinitionContext = function (
|
|
|
325
338
|
|
|
326
339
|
if (rest.length > 0) {
|
|
327
340
|
const nestedResult = resolveDefinitionContext(
|
|
328
|
-
parent.subtypes as TypesMap,
|
|
329
|
-
rest.join('.')
|
|
341
|
+
parent.subtypes as TypesMap,
|
|
342
|
+
rest.join('.')
|
|
330
343
|
);
|
|
331
344
|
return nestedResult;
|
|
332
345
|
}
|
|
@@ -619,8 +632,8 @@ export const lookup = function (
|
|
|
619
632
|
return undefined;
|
|
620
633
|
}
|
|
621
634
|
const result = lookup.call(
|
|
622
|
-
type.subtypes as unknown as TypesMap,
|
|
623
|
-
NextNestedPath
|
|
635
|
+
type.subtypes as unknown as TypesMap,
|
|
636
|
+
NextNestedPath
|
|
624
637
|
);
|
|
625
638
|
return result;
|
|
626
639
|
|
package/.ai/AGENTS.md
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
# AI Agent Guidelines — mnemonica/core
|
|
2
|
-
|
|
3
|
-
> **Entry point for AI agents contributing to mnemonica core.**
|
|
4
|
-
> This directory is for *editing the library*. Documentation for *using* the
|
|
5
|
-
> library (humans and agents alike) lives in [`docs/`](../docs/).
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## What This Project Is
|
|
10
|
-
|
|
11
|
-
**mnemonica** is an instance inheritance system for JavaScript / TypeScript.
|
|
12
|
-
It enables prototype chain-based type definitions through the `define()`
|
|
13
|
-
function, creating explicit inheritance graphs that eliminate common prototype
|
|
14
|
-
bugs.
|
|
15
|
-
|
|
16
|
-
Key insight: JavaScript prototype inheritance is a Trie data structure, but
|
|
17
|
-
developers don't realize this. Mnemonica forces explicit declaration of
|
|
18
|
-
inheritance graphs, making certain classes of bugs impossible by design.
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
## Files in This Directory
|
|
23
|
-
|
|
24
|
-
| File | Purpose |
|
|
25
|
-
|------|---------|
|
|
26
|
-
| [`AGENTS.md`](./AGENTS.md) | This file — main entry point and overview |
|
|
27
|
-
| [`ONBOARDING.md`](./ONBOARDING.md) | Five-minute editor quickstart |
|
|
28
|
-
| [`ARCHITECT.md`](./ARCHITECT.md) | Design guidelines: patterns, planning, constraints |
|
|
29
|
-
| [`DEBUG.md`](./DEBUG.md) | Debugging guidelines: commands, common issues, logging |
|
|
30
|
-
| [`PROTOTYPE-CHAIN.md`](./PROTOTYPE-CHAIN.md) | The exact shape of the prototype chain, layer by layer |
|
|
31
|
-
| [`theory-of-operations.md`](./theory-of-operations.md) | Full construction pipeline, stage by stage |
|
|
32
|
-
| [`performance-vs-security.md`](./performance-vs-security.md) | Performance/security trade-off analysis |
|
|
33
|
-
| [`mode-ask.md`](./mode-ask.md) | Ask mode: explaining concepts, analyzing code |
|
|
34
|
-
| [`mode-orchestrator.md`](./mode-orchestrator.md) | Orchestrator mode: multi-step task coordination |
|
|
35
|
-
| [`rules-coding.md`](./rules-coding.md) | Extended coding rules: models vs controllers, raw* prefix, full file reading |
|
|
36
|
-
| [`rules-reminders.md`](./rules-reminders.md) | Quick reference pointers to canonical sources |
|
|
37
|
-
| [`rules-context-condensing.md`](./rules-context-condensing.md) | Recovery protocol when context condenses |
|
|
38
|
-
| [`rules-contributing.md`](./rules-contributing.md) | Behavioral guidelines + new feature checklist |
|
|
39
|
-
| [`rules-type-system.md`](./rules-type-system.md) | `Proto<P,T>`, `TypeConstructor`, type vs interface |
|
|
40
|
-
| [`rules-define-patterns.md`](./rules-define-patterns.md) | `define()` usage, subtypes, config options |
|
|
41
|
-
| [`rules-async-constructors.md`](./rules-async-constructors.md) | Async constructors, `awaitReturn`, chaining |
|
|
42
|
-
| [`rules-hooks.md`](./rules-hooks.md) | `preCreation`, `postCreation`, `creationError` |
|
|
43
|
-
| [`rules-instance-methods.md`](./rules-instance-methods.md) | `extract()`, `fork()`, `parent()`, internal props |
|
|
44
|
-
| [`rules-code-style.md`](./rules-code-style.md) | Tabs, spacing, type vs interface |
|
|
45
|
-
| [`rules-testing.md`](./rules-testing.md) | 100% coverage, Mocha + Jest, error path patterns |
|
|
46
|
-
| [`rules-error-system.md`](./rules-error-system.md) | `BASE_MNEMONICA_ERROR`, `constructError`, stack cleaning |
|
|
47
|
-
| [`rules-philosophy.md`](./rules-philosophy.md) | HoTT concepts applied to mnemonica's self-reflection model |
|
|
48
|
-
| [`rules-ecosystem.md`](./rules-ecosystem.md) | PACT framework: personas, collaboration modes, integration points |
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
|
|
52
|
-
## Quick Start for Agents
|
|
53
|
-
|
|
54
|
-
### First Time Here?
|
|
55
|
-
|
|
56
|
-
Read [`ONBOARDING.md`](./ONBOARDING.md) — a single-file quickstart covering everything you need to know before touching code.
|
|
57
|
-
|
|
58
|
-
### Before You Write Any Code
|
|
59
|
-
|
|
60
|
-
1. Read [`ONBOARDING.md`](./ONBOARDING.md) — style rules, TypeScript rules, testing requirements.
|
|
61
|
-
2. Read [`ARCHITECT.md`](./ARCHITECT.md) — design patterns and constraints.
|
|
62
|
-
3. If debugging: read [`DEBUG.md`](./DEBUG.md).
|
|
63
|
-
4. If working with async constructors: read [`rules-async-constructors.md`](./rules-async-constructors.md) — the `super()` return-value pattern and native async class wrapping.
|
|
64
|
-
|
|
65
|
-
### Build & Test Commands
|
|
66
|
-
|
|
67
|
-
```bash
|
|
68
|
-
# Full build with linting
|
|
69
|
-
npm run build
|
|
70
|
-
|
|
71
|
-
# Run Mocha tests with coverage (runs npm run build:all internally)
|
|
72
|
-
npm run test:cov
|
|
73
|
-
|
|
74
|
-
# Run Jest tests with coverage (TypeScript source)
|
|
75
|
-
npm run test:jest:cov
|
|
76
|
-
|
|
77
|
-
# Watch mode
|
|
78
|
-
npm run watch
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
**Critical**: `npm run test:cov` runs `npm run build:all` internally. You do
|
|
82
|
-
not need to run `npm run build` first.
|
|
83
|
-
|
|
84
|
-
**Must run `npm run test:cov` before completing any task** — this validates
|
|
85
|
-
build and ensures 100% coverage.
|
|
86
|
-
|
|
87
|
-
---
|
|
88
|
-
|
|
89
|
-
## Architecture at a Glance
|
|
90
|
-
|
|
91
|
-
```
|
|
92
|
-
src/
|
|
93
|
-
├── index.ts # Main exports: define, lookup, apply, call, bind
|
|
94
|
-
├── types/index.ts # TypeScript type definitions
|
|
95
|
-
├── constants/ # Symbols and default options
|
|
96
|
-
├── descriptors/ # Type collection and error definitions
|
|
97
|
-
├── api/ # Core implementation
|
|
98
|
-
│ ├── types/ # TypeProxy, InstanceCreator, Mnemosyne
|
|
99
|
-
│ ├── errors/ # Error handling and stack traces
|
|
100
|
-
│ ├── hooks/ # Lifecycle hooks
|
|
101
|
-
│ └── utils/ # Utilities
|
|
102
|
-
└── utils/ # Public utilities (extract, parse, merge, etc.)
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### Proxy-Based Architecture
|
|
106
|
-
|
|
107
|
-
- **TypeProxy** (`src/api/types/TypeProxy.ts`): Wraps type constructors
|
|
108
|
-
- **Mnemosyne** (`src/api/types/Mnemosyne.ts`): Handles instance method access
|
|
109
|
-
- **TypesCollection Proxy** (`src/descriptors/types/index.ts`): Dynamic type lookup
|
|
110
|
-
|
|
111
|
-
### Key Symbols
|
|
112
|
-
|
|
113
|
-
| Symbol | Purpose |
|
|
114
|
-
|--------|---------|
|
|
115
|
-
| `SymbolConstructorName` | Stores type name on constructors |
|
|
116
|
-
| `SymbolParentType` | Links to parent type |
|
|
117
|
-
| `SymbolDefaultTypesCollection` | Default collection identifier |
|
|
118
|
-
| `SymbolConfig` | Type configuration storage |
|
|
119
|
-
|
|
120
|
-
---
|
|
121
|
-
|
|
122
|
-
## How Agents Discover These Docs
|
|
123
|
-
|
|
124
|
-
Based on observed agent behavior:
|
|
125
|
-
|
|
126
|
-
| What agents do | Result |
|
|
127
|
-
|----------------|--------|
|
|
128
|
-
| Read `README.md` first | Usually discovers the `.ai/` pointer |
|
|
129
|
-
| Read `package.json` second | Learns scripts, dependencies |
|
|
130
|
-
| Read source code third | Infers architecture from implementation |
|
|
131
|
-
| Skip `AGENTS.md` unless told | Often misses build rules, style constraints |
|
|
132
|
-
|
|
133
|
-
**If you are an agent reading this:** You likely arrived via `README.md` → `AGENTS.md` → `.ai/AGENTS.md`. Good path. Now read `ONBOARDING.md` for the condensed version, or `ARCHITECT.md` + `DEBUG.md` for full detail.
|
|
134
|
-
|
|
135
|
-
**If you are a human:** This directory documents *contributing to the core*. For *using* the library, see [`docs/`](../docs/).
|
|
136
|
-
|
|
137
|
-
---
|
|
138
|
-
|
|
139
|
-
## Related Files
|
|
140
|
-
|
|
141
|
-
| File | Purpose |
|
|
142
|
-
|------|---------|
|
|
143
|
-
| [`../SKILL.md`](../SKILL.md) | Condensed skill reference for framework injection |
|
|
144
|
-
| [`../AGENTS.md`](../AGENTS.md) | Root agent guidelines |
|
|
145
|
-
| [`rules-philosophy.md`](./rules-philosophy.md) | HoTT concepts applied to mnemonica's self-reflection model |
|
|
146
|
-
| [`rules-ecosystem.md`](./rules-ecosystem.md) | PACT framework: personas, collaboration modes, integration points |
|
|
147
|
-
| [`rules-contributing.md`](./rules-contributing.md) | Behavioral guidelines for AI contributors |
|
|
148
|
-
| [`../docs/tactica-deep-dive.md`](../docs/tactica-deep-dive.md) | Comprehensive tactica + lookup technical guide |
|
|
149
|
-
| [`../docs/async-constructors.md`](../docs/async-constructors.md) | Async constructors: super() return values, native class mixing, chains |
|
|
150
|
-
|
|
151
|
-
- Main README: [`../README.md`](../README.md)
|