mnemonica 1.2.1 → 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 (53) hide show
  1. package/FOR_HUMANS.md +186 -138
  2. package/README.md +70 -249
  3. package/build/api/errors/exceptionConstructor.js +20 -47
  4. package/build/api/errors/throwModificationError.js +26 -61
  5. package/build/api/types/InstanceCreator.js +5 -1
  6. package/build/api/types/Props.js +24 -10
  7. package/build/api/types/index.js +18 -12
  8. package/build/types/index.d.ts +9 -4
  9. package/build/types/index.js +1 -1
  10. package/docs/UTILS.md +97 -8
  11. package/docs/async-constructors.md +2 -0
  12. package/docs/decorate.md +1 -1
  13. package/docs/empathy-in-ai.md +20 -10
  14. package/docs/prototype-chain.md +8 -7
  15. package/docs/typed-lookup.md +195 -5
  16. package/docs/typeomatica.md +8 -345
  17. package/package.json +6 -10
  18. package/src/api/errors/exceptionConstructor.ts +40 -83
  19. package/src/api/errors/throwModificationError.ts +64 -104
  20. package/src/api/types/InstanceCreator.ts +14 -0
  21. package/src/api/types/Props.ts +53 -18
  22. package/src/api/types/index.ts +33 -20
  23. package/src/types/index.ts +15 -5
  24. package/.ai/AGENTS.md +0 -151
  25. package/.ai/ARCHITECT.md +0 -110
  26. package/.ai/DEBUG.md +0 -178
  27. package/.ai/ONBOARDING.md +0 -189
  28. package/.ai/PROTOTYPE-CHAIN.md +0 -153
  29. package/.ai/mode-ask.md +0 -121
  30. package/.ai/mode-orchestrator.md +0 -141
  31. package/.ai/performance-vs-security.md +0 -395
  32. package/.ai/rules-async-constructors.md +0 -352
  33. package/.ai/rules-code-style.md +0 -95
  34. package/.ai/rules-coding.md +0 -246
  35. package/.ai/rules-context-condensing.md +0 -50
  36. package/.ai/rules-contributing.md +0 -227
  37. package/.ai/rules-define-patterns.md +0 -159
  38. package/.ai/rules-ecosystem.md +0 -140
  39. package/.ai/rules-error-system.md +0 -56
  40. package/.ai/rules-hooks.md +0 -46
  41. package/.ai/rules-instance-methods.md +0 -93
  42. package/.ai/rules-philosophy.md +0 -231
  43. package/.ai/rules-reminders.md +0 -19
  44. package/.ai/rules-testing.md +0 -66
  45. package/.ai/rules-type-system.md +0 -124
  46. package/.ai/theory-of-operations.md +0 -224
  47. package/AGENTS.md +0 -345
  48. package/CONTRIBUTING.md +0 -150
  49. package/SKILL.md +0 -114
  50. package/docs/ai-learning-trajectory.md +0 -141
  51. package/docs/purpose.md +0 -707
  52. package/docs/tactica-deep-dive.md +0 -629
  53. package/docs/tactica-pattern.md +0 -146
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)
package/.ai/ARCHITECT.md DELETED
@@ -1,110 +0,0 @@
1
- # Design Guidelines — mnemonica/core
2
-
3
- > **Applies to:** Planning, designing, and strategizing changes without modifying
4
- > implementation files. Framework-agnostic.
5
-
6
- ---
7
-
8
- ## Role
9
-
10
- You are in **Architect** mode. Your task is to plan, design, and strategize
11
- changes to the mnemonica codebase without modifying implementation files.
12
-
13
- ---
14
-
15
- ## Project Overview
16
-
17
- Mnemonica is an **instance inheritance system** using JavaScript prototype
18
- chains. It allows creating type hierarchies where instances can spawn child
19
- instances that inherit from parent instances.
20
-
21
- ### Core Concept
22
-
23
- ```typescript
24
- // Define types
25
- const User = define('User', function (name: string) {
26
- this.name = name;
27
- });
28
-
29
- // Create parent instance
30
- const user = new User('John');
31
-
32
- // Create child instance inheriting from parent
33
- const admin = user.Admin('admin privileges');
34
- // admin inherits all User properties + new Admin properties
35
- ```
36
-
37
- ---
38
-
39
- ## Architecture Patterns
40
-
41
- ### Proxy-Based Design
42
-
43
- ```
44
- TypeProxy → wraps constructor functions
45
- Mnemosyne → handles instance prototype chain
46
- TypesCollection → manages type registry
47
- ```
48
-
49
- ### Internal Instance Properties
50
-
51
- ```typescript
52
- interface InstanceInternalProps {
53
- [SymbolConstructorName]: string; // Type name
54
- [SymbolParentType]: object; // Parent instance
55
- [SymbolSubTypes]: Map<string, object>; // Child types
56
- }
57
- ```
58
-
59
- ### Symbol System
60
-
61
- See [`AGENTS.md`](./AGENTS.md) for the complete symbol reference table.
62
-
63
- ---
64
-
65
- ## Design Principles
66
-
67
- ### Type Safety
68
- - Strict TypeScript with `strict: true`
69
- - All functions must have explicit return types
70
- - Types must be complete and reusable
71
- - **No `any`** (`@typescript-eslint/no-explicit-any: error`) — define proper types
72
- - Never use bare `Function`, `CallableFunction`, or `NewableFunction` — define purpose-specific interfaces
73
-
74
- ### Proxy Handler Design
75
-
76
- ```typescript
77
- // Pattern for proxy handlers
78
- type ProxyHandler<T> = {
79
- get?(target: T, prop: string, receiver: unknown): unknown;
80
- set?(target: T, prop: string, value: unknown, receiver: unknown): boolean;
81
- apply?(target: T, thisArg: unknown, args: unknown[]): unknown;
82
- };
83
- ```
84
-
85
- ### Extension Points
86
-
87
- 1. **Types** — Create via `define()` function
88
- 2. **Hooks** — Register with `registerHook()`
89
- 3. **Flow Checkers** — Add validation with `registerFlowChecker()`
90
- 4. **Subtypes** — Extend types with `type.define()`
91
-
92
- ---
93
-
94
- ## Documentation Format
95
-
96
- When creating design documents:
97
- 1. Use `.md` extension only
98
- 2. Include code examples in TypeScript
99
- 3. Reference existing patterns from `src/types/index.ts`
100
- 4. Document symbol usage and meanings
101
-
102
- ---
103
-
104
- ## Constraints
105
-
106
- - **Do not** write implementation code (`*.ts` files)
107
- - **Do not** modify existing source files
108
- - Focus on `.md` documentation and planning
109
- - Consider 100% test coverage requirement
110
- - Respect the dual test framework (Mocha + Jest)
package/.ai/DEBUG.md DELETED
@@ -1,178 +0,0 @@
1
- # Debugging Guidelines — mnemonica/core
2
-
3
- > **Applies to:** Investigating issues, diagnosing problems, identifying root
4
- > causes. Framework-agnostic.
5
-
6
- ---
7
-
8
- ## Role
9
-
10
- You are in **Debug** mode. Your task is to investigate issues, diagnose problems,
11
- and identify root causes in the mnemonica codebase.
12
-
13
- ---
14
-
15
- ## Debug Commands
16
-
17
- ```bash
18
- # Run tests with coverage to identify untested paths
19
- npm run test:cov
20
-
21
- # Run Jest with verbose output
22
- npm run test:jest -- --verbose
23
-
24
- # Run specific test file
25
- npx jest test-jest/types.ts --verbose
26
-
27
- # Run Mocha with debug output
28
- DEBUG=* npm test
29
-
30
- # Build and check for TypeScript errors
31
- npm run build
32
- ```
33
-
34
- ### Build Output Inspection
35
-
36
- When running `npm run build` or `npm run build:all`, **check the beginning of the
37
- output** for errors and warnings. Build failures (TypeScript compilation errors,
38
- ESLint issues, etc.) often appear at the start of the output. Do not rely only on
39
- the end of the output or `tail` for build status.
40
-
41
- For test passing confirmations (e.g., `npm run test:cov`), checking the end of
42
- the output is acceptable.
43
-
44
- ---
45
-
46
- ## Common Issue Patterns
47
-
48
- ### Proxy Handler Issues
49
-
50
- ```typescript
51
- // If traps are not working, check:
52
- // 1. Handler methods return correct types
53
- // 2. `get` trap returns `unknown`, not implicit `any`
54
- // 3. `set` trap returns boolean, not void
55
-
56
- // Debug proxy behavior
57
- const debugProxy = new Proxy(target, {
58
- get(target, prop, receiver) {
59
- console.log('Getting:', prop);
60
- return Reflect.get(target, prop, receiver);
61
- }
62
- });
63
- ```
64
-
65
- ### Type Errors
66
-
67
- ```typescript
68
- // Common: 'any' type assignment
69
- // Fix: Add proper type annotation
70
- const value: SpecificType = unknownValue as SpecificType;
71
-
72
- // Common: missing 'this' type
73
- // Fix: Add explicit this parameter
74
- function method(this: SpecificType) { }
75
- ```
76
-
77
- ### Instance Chain Issues
78
-
79
- ```typescript
80
- // Check instance properties
81
- console.log(instance[SymbolConstructorName]);
82
- console.log(instance[SymbolParentType]);
83
- console.log(instance[SymbolSubTypes]);
84
-
85
- // Verify prototype chain
86
- console.log(Object.getPrototypeOf(instance));
87
- ```
88
-
89
- ---
90
-
91
- ## Logging Strategy
92
-
93
- ### Add Temporary Logging
94
-
95
- ```typescript
96
- // In proxy handlers
97
- get(target, prop, receiver) {
98
- console.log(`[Proxy.get] prop: ${String(prop)}`);
99
- // ... existing code
100
- }
101
-
102
- // In error constructors
103
- constructor(message, additionalStack) {
104
- console.log('[Error]', message, additionalStack);
105
- // ... existing code
106
- }
107
- ```
108
-
109
- ### Stack Trace Analysis
110
-
111
- ```typescript
112
- // Use error stack cleaners
113
- import { cleanupStack } from '../api/errors/index.js';
114
-
115
- const cleaned = cleanupStack(stack.split('\n'));
116
- console.log('Cleaned stack:', cleaned);
117
- ```
118
-
119
- ---
120
-
121
- ## Symbol Debugging
122
-
123
- ```typescript
124
- // Inspect instance symbols
125
- const symbols = Object.getOwnPropertySymbols(instance);
126
- symbols.forEach(sym => {
127
- console.log(sym.toString(), ':', (instance as Record<symbol, unknown>)[sym]);
128
- });
129
- ```
130
-
131
- ---
132
-
133
- ## Test Debugging
134
-
135
- ### Mocha Tests
136
-
137
- ```bash
138
- # Run single test suite
139
- npx mocha build/test-ts/test-example.js
140
-
141
- # With debug output
142
- DEBUG=mnemonica npx mocha build/test-ts/test-example.js
143
- ```
144
-
145
- ### Jest Tests
146
-
147
- ```bash
148
- # Run with debugger
149
- node --inspect-brk node_modules/.bin/jest --runInBand test-jest/types.ts
150
-
151
- # With console output
152
- npx jest test-jest/types.ts --verbose --no-coverage
153
- ```
154
-
155
- ---
156
-
157
- ## Issue Checklist
158
-
159
- 1. [ ] Check TypeScript compilation: `npm run build`
160
- 2. [ ] Check build output **at the beginning** for errors/warnings (not just tail)
161
- 3. [ ] Run Mocha tests: `npm run test:cov`
162
- 4. [ ] Run Jest tests: `npm run test:jest:cov`
163
- 5. [ ] Verify code style (see [`rules-code-style.md`](./rules-code-style.md))
164
- 6. [ ] Check for bare `Function` / `CallableFunction` / `NewableFunction` types
165
- 7. [ ] Verify symbol usage is correct
166
- 8. [ ] Check proxy handler return types
167
- 9. [ ] Verify return statements use intermediate variables
168
-
169
- ---
170
-
171
- ## Reporting Issues
172
-
173
- When reporting findings:
174
- 1. Include file paths and line numbers
175
- 2. Show relevant code snippets
176
- 3. Provide error messages in full
177
- 4. Suggest root cause, not just symptoms
178
- 5. Reference related test files
package/.ai/ONBOARDING.md DELETED
@@ -1,189 +0,0 @@
1
- # Onboarding — New Agent Quickstart
2
-
3
- > **Read this first.** One file. Five minutes. Everything you need to contribute to mnemonica without reading 8+ files.
4
-
5
- ---
6
-
7
- ## What Is mnemonica?
8
-
9
- An **instance inheritance system** for JavaScript/TypeScript. You define types with `define()` and create instances that inherit through prototype chains — not just classes, but between instances.
10
-
11
- ```typescript
12
- const User = define('User', function (this: UserData, data: UserData) {
13
- Object.assign(this, data);
14
- });
15
-
16
- const user = new User({ name: 'John' });
17
- const admin = new user.Admin({ role: 'admin' }); // inherits from user instance
18
- ```
19
-
20
- **Scope:** mnemonica types the data flow, not the control flow. It gives data memory of its own creation (type, parent, arguments, timestamp) but does not dictate how services, algorithms, or control flow work. Keep behavior code intact; mnemonica only replaces plain data objects with typed instances.
21
-
22
- **The greater view.** mnemonica does not add a new abstraction on top of JavaScript — it makes an existing one explicit. The prototype chain is already a Trie; every `new` already extends a node. `new user.Admin()` is not a library call — it is JavaScript's prototype mechanism used deliberately. mnemonica names each node, stores the construction arguments at each step, and makes the chain queryable. The thing you have been building with manually all along, made first-class.
23
-
24
- **Why not class hierarchies?** Class inheritance shares `Admin.prototype` across all instances. Two concurrent requests both creating `Admin` instances share the same prototype. `new user.Admin()` creates a chain where `user` IS the prototype — each pipeline run is isolated structurally, not by convention.
25
-
26
- **Why not TypeScript interfaces alone?** TypeScript is structural at compile time: a `Payment` and an `Invoice` with identical fields are interchangeable to the type checker. At runtime, `processPayment(invoice)` silently succeeds and produces wrong results. mnemonica's runtime types are nominal — the type IS its name, established at `define()` time and stable thereafter.
27
-
28
- **Why not Object.assign / spread?** `{...raw, ...apiResult}` is one flat object with no lineage. You cannot answer "which step set `amount`?" without reading the source. mnemonica's prototype chain preserves every ancestor; `utils.parent(enriched, 'ApiResult')` returns the exact API response object.
29
-
30
- ---
31
-
32
- ## Build & Test
33
-
34
- ```bash
35
- # Install dependencies
36
- npm ci
37
-
38
- # Build TypeScript
39
- npm run build
40
-
41
- # Run Mocha tests with coverage (runs build:all internally)
42
- npm run test:cov
43
-
44
- # Run Jest tests with coverage (TypeScript source, faster)
45
- npm run test:jest:cov
46
-
47
- # Watch mode
48
- npm run watch
49
- ```
50
-
51
- **Rule:** `npm run test:cov` before completing any task. It validates the build and ensures 100% coverage.
52
-
53
- **Build tip:** Check the **beginning** of build output for errors. For tests, the end is fine.
54
-
55
- ---
56
-
57
- ## Code Style (Non-Negotiable)
58
-
59
- ### Indentation
60
- - **TABS ONLY** — never spaces. Tab width: 4.
61
-
62
- ### Function Spacing
63
- ```typescript
64
- function myFunc () { } // ✓ space before paren
65
- function myFunc() { } // ✗ wrong
66
- ```
67
-
68
- ### Return Statements
69
- **Always use an intermediate variable before returning.**
70
-
71
- ```typescript
72
- // ✓ GOOD — inspectable in debugger
73
- const result = { target, name };
74
- return result;
75
-
76
- // ✗ BAD — can't inspect
77
- return { target, name };
78
- ```
79
-
80
- ### TypeScript Types
81
- - `strict: true`, `noUnusedLocals: true`, `noUnusedParameters: true`
82
- - **No `any`** (`@typescript-eslint/no-explicit-any: error`) — use purpose-specific interfaces
83
- - **Never** use bare `Function`, `CallableFunction`, or `NewableFunction` — define purpose-specific interfaces
84
-
85
- ### Error Handling
86
-
87
- ```typescript
88
- import { constructError } from '../api/errors/index.js';
89
-
90
- const MyError = constructError('MY_ERROR', 'Error message');
91
- throw new MyError('additional info', stack);
92
- ```
93
-
94
- ### Configuration Files
95
-
96
- **Disallowed without explicit approval:**
97
- - Modifying `./tsconfig.json`
98
- - Modifying `./eslint.config.js`
99
-
100
- These configuration files define the project's strict standards. Any changes
101
- require user approval first.
102
-
103
- ---
104
-
105
- ## Architecture
106
-
107
- ```
108
- src/
109
- ├── index.ts # Main exports: define, lazy, lookup, apply, call, bind
110
- ├── types/index.ts # TypeScript type definitions
111
- ├── constants/ # Symbols and default options
112
- ├── descriptors/ # Type collection and error definitions
113
- ├── api/ # Core implementation
114
- │ ├── types/ # TypeProxy, InstanceCreator, Mnemosyne
115
- │ ├── errors/ # Error handling and stack traces
116
- │ ├── hooks/ # Lifecycle hooks
117
- │ └── utils/ # Utilities
118
- └── utils/ # Public utilities (extract, parse, merge, etc.)
119
- ```
120
-
121
- Key components:
122
- - **TypeProxy** — wraps type constructors
123
- - **InstanceCreator** — orchestrates construction lifecycle
124
- - **Mnemosyne** — root memory proxy; stores construction context and resolves subtype lookups
125
-
126
- ---
127
-
128
- ## Testing Rules
129
-
130
- - **Dual framework:** Mocha (transpiled `build/`), Jest (TypeScript `src/`)
131
- - **100% coverage** required for both
132
- - Jest tests should mirror Mocha patterns from `test/environment.js`
133
- - Tests must pass with `--allow-uncaught` (mocha)
134
-
135
- ---
136
-
137
- ## Async Constructors
138
-
139
- mnemonica supports async constructors natively:
140
-
141
- ```typescript
142
- const AsyncType = define('AsyncType', async function () {
143
- await sleep(100);
144
- this.done = true;
145
- return this; // MUST return with awaitReturn: true (default)
146
- });
147
-
148
- const instance = await new AsyncType();
149
- ```
150
-
151
- **Critical:** Async subtypes are invoked as methods on the parent instance:
152
-
153
- ```typescript
154
- const parent = await new AsyncParent();
155
- const child = await parent.AsyncChild(); // ✓ correct
156
-
157
- const wrong = await new AsyncChild(); // ✗ fails strictChain
158
- ```
159
-
160
- Read [`../docs/async-constructors.md`](../docs/async-constructors.md) for the `super()` return-value trap and native async class wrapping.
161
-
162
- ---
163
-
164
- ## Common Pitfalls
165
-
166
- 1. **`await new AsyncSubType()`** — wrong. Use `await parent.AsyncSubType()`.
167
- 2. **`return { a, b }`** — wrong. Use `const result = { a, b }; return result;`.
168
- 3. **Modifying `tsconfig.json` or `eslint.config.js`** — forbidden without explicit approval.
169
- 4. **Forgetting `npm run test:cov`** — always run before finishing.
170
- 5. **Using `Function` as a type** — define `interface MyHandler extends CallableFunction { ... }`.
171
-
172
- ---
173
-
174
- ## Where to Go Next
175
-
176
- | Need | Read |
177
- |------|------|
178
- | Design patterns, constraints | [`ARCHITECT.md`](./ARCHITECT.md) |
179
- | Prototype chain internals | [`PROTOTYPE-CHAIN.md`](./PROTOTYPE-CHAIN.md) |
180
- | Debugging commands, issues | [`DEBUG.md`](./DEBUG.md) |
181
- | Async constructor deep dive | [`rules-async-constructors.md`](./rules-async-constructors.md) |
182
- | tactica type-safe lookup | [`tactica-deep-dive.md`](../docs/tactica-deep-dive.md) |
183
- | Behavioral guidelines | [`rules-contributing.md`](./rules-contributing.md) |
184
- | Explaining code (ask mode) | [`mode-ask.md`](./mode-ask.md) |
185
- | Multi-step coordination | [`mode-orchestrator.md`](./mode-orchestrator.md) |
186
-
187
- ---
188
-
189
- > **This file is a summary.** For authoritative rules, read the linked files. For the full type system, read `src/types/index.ts`.