mnemonica 0.9.99787 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/.ai/AGENTS.md +138 -0
  2. package/.ai/ARCHITECT.md +110 -0
  3. package/.ai/CODE.md +111 -0
  4. package/.ai/DEBUG.md +179 -0
  5. package/.ai/ONBOARDING.md +171 -0
  6. package/.ai/TACTICA-DEEP-DIVE.md +583 -0
  7. package/.ai/TACTICA-RULES.md +103 -0
  8. package/.ai/ask/AGENTS.md +115 -0
  9. package/.ai/async_init.md +94 -0
  10. package/.ai/orchestrator/AGENTS.md +158 -0
  11. package/.ai/rules/CODING.md +229 -0
  12. package/.ai/rules/CONTEXT-CONDENSING.md +50 -0
  13. package/.ai/rules/REMINDERS.md +63 -0
  14. package/.ai/rules-skill/async-constructors.md +206 -0
  15. package/.ai/rules-skill/code-style.md +95 -0
  16. package/.ai/rules-skill/contributing.md +192 -0
  17. package/.ai/rules-skill/define-patterns.md +96 -0
  18. package/.ai/rules-skill/ecosystem.md +140 -0
  19. package/.ai/rules-skill/error-system.md +56 -0
  20. package/.ai/rules-skill/hooks.md +46 -0
  21. package/.ai/rules-skill/instance-methods.md +60 -0
  22. package/.ai/rules-skill/lookup-typed.md +84 -0
  23. package/.ai/rules-skill/philosophy.md +231 -0
  24. package/.ai/rules-skill/proxy-architecture.md +63 -0
  25. package/.ai/rules-skill/testing.md +66 -0
  26. package/.ai/rules-skill/type-system.md +114 -0
  27. package/.ai/task-templates/new-feature.md +46 -0
  28. package/AGENTS.md +250 -0
  29. package/CONTRIBUTING.md +112 -0
  30. package/FOR_HUMANS.md +1391 -0
  31. package/README.md +306 -999
  32. package/SKILL.md +109 -0
  33. package/build/api/errors/exceptionConstructor.js +3 -2
  34. package/build/api/errors/index.d.ts +5 -1
  35. package/build/api/errors/index.js +1 -1
  36. package/build/api/errors/throwModificationError.d.ts +1 -19
  37. package/build/api/errors/throwModificationError.js +5 -3
  38. package/build/api/hooks/HookInvocation.d.ts +15 -0
  39. package/build/api/hooks/HookInvocation.js +38 -0
  40. package/build/api/hooks/flowCheckers.d.ts +3 -2
  41. package/build/api/hooks/flowCheckers.js +1 -1
  42. package/build/api/hooks/invokeHook.d.ts +2 -3
  43. package/build/api/hooks/invokeHook.js +12 -21
  44. package/build/api/hooks/registerHook.d.ts +2 -1
  45. package/build/api/hooks/registerHook.js +1 -1
  46. package/build/api/index.d.ts +5 -7
  47. package/build/api/types/InstanceCreator.d.ts +9 -30
  48. package/build/api/types/InstanceCreator.js +38 -18
  49. package/build/api/types/InstanceModificator.d.ts +2 -1
  50. package/build/api/types/InstanceModificator.js +1 -1
  51. package/build/api/types/Mnemosyne.d.ts +8 -24
  52. package/build/api/types/Mnemosyne.js +15 -8
  53. package/build/api/types/Props.d.ts +2 -2
  54. package/build/api/types/Props.js +7 -3
  55. package/build/api/types/TypeProxy.d.ts +17 -14
  56. package/build/api/types/TypeProxy.js +5 -6
  57. package/build/api/types/compileNewModificatorFunctionBody.d.ts +13 -1
  58. package/build/api/types/compileNewModificatorFunctionBody.js +1 -1
  59. package/build/api/types/createInstanceModificator.d.ts +3 -2
  60. package/build/api/types/createInstanceModificator.js +1 -1
  61. package/build/api/types/index.d.ts +3 -2
  62. package/build/api/types/index.js +91 -73
  63. package/build/api/utils/index.d.ts +5 -2
  64. package/build/api/utils/index.js +1 -1
  65. package/build/constants/index.js +1 -1
  66. package/build/descriptors/errors/index.js +1 -1
  67. package/build/descriptors/index.d.ts +1 -1
  68. package/build/descriptors/index.js +1 -1
  69. package/build/descriptors/types/index.js +20 -17
  70. package/build/index.d.ts +3 -3
  71. package/build/index.js +7 -4
  72. package/build/types/index.d.ts +100 -67
  73. package/build/types/index.js +1 -1
  74. package/build/utils/collectConstructors.js +1 -1
  75. package/build/utils/defineStackCleaner.js +1 -1
  76. package/build/utils/extract.js +1 -1
  77. package/build/utils/hop.js +1 -1
  78. package/build/utils/index.js +3 -2
  79. package/build/utils/merge.js +1 -1
  80. package/build/utils/parent.js +1 -1
  81. package/build/utils/parse.js +9 -4
  82. package/build/utils/pick.js +1 -1
  83. package/build/utils/toJSON.js +1 -1
  84. package/docs/ai-learning-trajectory.md +142 -0
  85. package/docs/async-constructors.md +273 -0
  86. package/docs/purpose.md +676 -0
  87. package/docs/tactica-pattern.md +147 -0
  88. package/docs/typed-lookup.md +157 -0
  89. package/docs/typeomatica.md +622 -0
  90. package/examples/AsyncNewTest.js +12 -0
  91. package/examples/ClassReName.js +23 -0
  92. package/examples/README.md +40 -0
  93. package/examples/v8bug.js +64 -0
  94. package/module/index.js +19 -11
  95. package/package.json +27 -8
  96. package/src/api/errors/exceptionConstructor.ts +271 -0
  97. package/src/api/errors/index.ts +138 -0
  98. package/src/api/errors/throwModificationError.ts +272 -0
  99. package/src/api/hooks/HookInvocation.ts +69 -0
  100. package/src/api/hooks/flowCheckers.ts +27 -0
  101. package/src/api/hooks/index.ts +6 -0
  102. package/src/api/hooks/invokeHook.ts +67 -0
  103. package/src/api/hooks/registerHook.ts +35 -0
  104. package/src/api/index.ts +32 -0
  105. package/src/api/types/InstanceCreator.ts +463 -0
  106. package/src/api/types/InstanceModificator.ts +35 -0
  107. package/src/api/types/Mnemosyne.ts +445 -0
  108. package/src/api/types/Props.ts +262 -0
  109. package/src/api/types/TypeProxy.ts +215 -0
  110. package/src/api/types/compileNewModificatorFunctionBody.ts +215 -0
  111. package/src/api/types/createInstanceModificator.ts +70 -0
  112. package/src/api/types/index.ts +556 -0
  113. package/src/api/utils/index.ts +313 -0
  114. package/src/constants/index.ts +141 -0
  115. package/src/descriptors/errors/index.ts +26 -0
  116. package/src/descriptors/index.ts +13 -0
  117. package/src/descriptors/types/index.ts +319 -0
  118. package/src/index.ts +319 -0
  119. package/src/types/index.ts +538 -0
  120. package/src/utils/collectConstructors.ts +83 -0
  121. package/src/utils/defineStackCleaner.ts +13 -0
  122. package/src/utils/extract.ts +30 -0
  123. package/src/utils/hop.ts +6 -0
  124. package/src/utils/index.ts +55 -0
  125. package/src/utils/merge.ts +29 -0
  126. package/src/utils/parent.ts +42 -0
  127. package/src/utils/parse.ts +85 -0
  128. package/src/utils/pick.ts +36 -0
  129. package/src/utils/toJSON.ts +44 -0
package/.ai/AGENTS.md ADDED
@@ -0,0 +1,138 @@
1
+ # AI Agent Guidelines — mnemonica/core
2
+
3
+ > **Framework-agnostic entry point for all AI agents.**
4
+ > This directory is the authoritative source.
5
+
6
+ ---
7
+
8
+ ## What This Project Is
9
+
10
+ **mnemonica** is an instance inheritance system for JavaScript / TypeScript.
11
+ It enables prototype chain-based type definitions through the `define()`
12
+ function, creating explicit inheritance graphs that eliminate common prototype
13
+ bugs.
14
+
15
+ Key insight: JavaScript prototype inheritance is a Trie data structure, but
16
+ developers don't realize this. Mnemonica forces explicit declaration of
17
+ inheritance graphs, making certain classes of bugs impossible by design.
18
+
19
+ ---
20
+
21
+ ## Files in This Directory
22
+
23
+ | File | Purpose |
24
+ |------|---------|
25
+ | [`AGENTS.md`](./AGENTS.md) | This file — main entry point and overview |
26
+ | [`CODE.md`](./CODE.md) | Coding standards: style, TypeScript rules, testing |
27
+ | [`ARCHITECT.md`](./ARCHITECT.md) | Design guidelines: patterns, planning, constraints |
28
+ | [`DEBUG.md`](./DEBUG.md) | Debugging guidelines: commands, common issues, logging |
29
+ | [`async_init.md`](./async_init.md) | Async class constructor support: wrapper pattern, `Symbol.hasInstance`, tests |
30
+ | [`ask/AGENTS.md`](./ask/AGENTS.md) | Ask mode: explaining concepts, analyzing code |
31
+ | [`orchestrator/AGENTS.md`](./orchestrator/AGENTS.md) | Orchestrator mode: multi-step task coordination |
32
+ | [`rules/CODING.md`](./rules/CODING.md) | Extended coding rules: models vs controllers, raw* prefix, full file reading |
33
+ | [`rules/REMINDERS.md`](./rules/REMINDERS.md) | Quick reference: type vs interface, spacing, before-task checklist |
34
+ | [`rules/CONTEXT-CONDENSING.md`](./rules/CONTEXT-CONDENSING.md) | Recovery protocol when context condenses |
35
+ | [`task-templates/`](./task-templates/) | Reusable task templates |
36
+
37
+ ---
38
+
39
+ ## Quick Start for Agents
40
+
41
+ ### First Time Here?
42
+
43
+ Read [`ONBOARDING.md`](./ONBOARDING.md) — a single-file quickstart covering everything you need to know before touching code.
44
+
45
+ ### Before You Write Any Code
46
+
47
+ 1. Read [`CODE.md`](./CODE.md) — style rules, TypeScript rules, testing requirements.
48
+ 2. Read [`ARCHITECT.md`](./ARCHITECT.md) — design patterns and constraints.
49
+ 3. If debugging: read [`DEBUG.md`](./DEBUG.md).
50
+ 4. If working with async constructors: read [`../docs/async-constructors.md`](../docs/async-constructors.md) — the `super()` return-value pattern and native async class wrapping.
51
+
52
+ ### Build & Test Commands
53
+
54
+ ```bash
55
+ # Full build with linting
56
+ npm run build
57
+
58
+ # Run Mocha tests with coverage (runs npm run build:all internally)
59
+ npm run test:cov
60
+
61
+ # Run Jest tests with coverage (TypeScript source)
62
+ npm run test:jest:cov
63
+
64
+ # Watch mode
65
+ npm run watch
66
+ ```
67
+
68
+ **Critical**: `npm run test:cov` runs `npm run build:all` internally. You do
69
+ not need to run `npm run build` first.
70
+
71
+ **Must run `npm run test:cov` before completing any task** — this validates
72
+ build and ensures 100% coverage.
73
+
74
+ ---
75
+
76
+ ## Architecture at a Glance
77
+
78
+ ```
79
+ src/
80
+ ├── index.ts # Main exports: define, lookup, apply, call, bind
81
+ ├── types/index.ts # TypeScript type definitions
82
+ ├── constants/ # Symbols and default options
83
+ ├── descriptors/ # Type collection and error definitions
84
+ ├── api/ # Core implementation
85
+ │ ├── types/ # TypeProxy, InstanceCreator, Mnemosyne
86
+ │ ├── errors/ # Error handling and stack traces
87
+ │ ├── hooks/ # Lifecycle hooks
88
+ │ └── utils/ # Utilities
89
+ └── utils/ # Public utilities (extract, parse, merge, etc.)
90
+ ```
91
+
92
+ ### Proxy-Based Architecture
93
+
94
+ - **TypeProxy** (`src/api/types/TypeProxy.ts`): Wraps type constructors
95
+ - **Mnemosyne** (`src/api/types/Mnemosyne.ts`): Handles instance method access
96
+ - **TypesCollection Proxy** (`src/descriptors/types/index.ts`): Dynamic type lookup
97
+
98
+ ### Key Symbols
99
+
100
+ | Symbol | Purpose |
101
+ |--------|---------|
102
+ | `SymbolConstructorName` | Stores type name on constructors |
103
+ | `SymbolParentType` | Links to parent type |
104
+ | `SymbolDefaultTypesCollection` | Default collection identifier |
105
+ | `SymbolConfig` | Type configuration storage |
106
+
107
+ ---
108
+
109
+ ## How Agents Discover These Docs
110
+
111
+ Based on observed agent behavior:
112
+
113
+ | What agents do | Result |
114
+ |----------------|--------|
115
+ | Read `README.md` first | Usually discovers the `.ai/` pointer |
116
+ | Read `package.json` second | Learns scripts, dependencies |
117
+ | Read source code third | Infers architecture from implementation |
118
+ | Skip `AGENTS.md` unless told | Often misses build rules, style constraints |
119
+
120
+ **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 `CODE.md` + `ARCHITECT.md` for full detail.
121
+
122
+ **If you are a human:** These docs are for AI agents. The human-facing docs live in `docs/`.
123
+
124
+ ---
125
+
126
+ ## Related Files
127
+
128
+ | File | Purpose |
129
+ |------|---------|
130
+ | [`../SKILL.md`](../SKILL.md) | Condensed skill reference for framework injection |
131
+ | [`../AGENTS.md`](../AGENTS.md) | Root agent guidelines |
132
+ | [`rules-skill/philosophy.md`](./rules-skill/philosophy.md) | HoTT concepts applied to mnemonica's self-reflection model |
133
+ | [`rules-skill/ecosystem.md`](./rules-skill/ecosystem.md) | PACT framework: personas, collaboration modes, integration points |
134
+ | [`rules-skill/contributing.md`](./rules-skill/contributing.md) | Behavioral guidelines for AI contributors |
135
+ | [`TACTICA-DEEP-DIVE.md`](./TACTICA-DEEP-DIVE.md) | Comprehensive tactica + lookupTyped technical guide |
136
+ | [`../docs/async-constructors.md`](../docs/async-constructors.md) | Async constructors: super() return values, native class mixing, chains |
137
+
138
+ - Main README: [`../README.md`](../README.md)
@@ -0,0 +1,110 @@
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/CODE.md ADDED
@@ -0,0 +1,111 @@
1
+ # Coding Standards — mnemonica/core
2
+
3
+ > **Applies to:** All code changes. Framework-agnostic.
4
+ > See also `.ai/rules/CODING.md` for extended coding rules.
5
+
6
+ ---
7
+
8
+ ## Build & Test Commands
9
+
10
+ See [`rules-skill/testing.md`](./rules-skill/testing.md) for the full reference. Summary:
11
+ ```bash
12
+ npm run build # full build with linting
13
+ npm run test:cov # Mocha + coverage (runs build:all internally)
14
+ npm run test:jest:cov # Jest on TypeScript source
15
+ npm run watch # watch mode
16
+ ```
17
+ **Must run `npm run test:cov` before completing any task.**
18
+
19
+ ---
20
+
21
+ ## Code Style Rules
22
+
23
+ See [`rules-skill/code-style.md`](./rules-skill/code-style.md) for the full style guide (tabs, function spacing, aligned colons, TypeScript strictness, no `any`).
24
+
25
+ The return-statement rule is design-critical and is documented in full in [`../AGENTS.md`](../AGENTS.md#return-statement-design-rule). Summary: **always use an intermediate variable before returning** so Chrome DevTools can inspect the value at a breakpoint.
26
+
27
+ ---
28
+
29
+ ## TypeScript Type Rules
30
+
31
+ **Never use bare `Function`, `CallableFunction`, or `NewableFunction` as parameter or return types.** Define a purpose-specific interface that extends them. See [`rules-skill/code-style.md`](./rules-skill/code-style.md) for examples and allowed exceptions.
32
+
33
+ ---
34
+
35
+ ## Build Output Inspection
36
+
37
+ When running `npm run build` or `npm run build:all`, **check the beginning of the output** for errors and warnings. Build failures (TypeScript compilation errors, ESLint issues, etc.) often appear at the start of the output. Do not rely only on the end of the output or `tail` for build status.
38
+
39
+ For test passing confirmations (e.g., `npm run test:cov`), checking the end of the output is acceptable.
40
+
41
+ ---
42
+
43
+ ## Type Patterns
44
+
45
+ ### Proxy Handlers
46
+ ```typescript
47
+ type ProxyHandler<T> = {
48
+ get?(target: T, prop: string, receiver: unknown): unknown;
49
+ set?(target: T, prop: string, value: unknown, receiver: unknown): boolean;
50
+ };
51
+ ```
52
+
53
+ ### Internal Instance Properties
54
+ ```typescript
55
+ interface MnemonicaInstance {
56
+ [SymbolConstructorName]?: string;
57
+ [SymbolParentType]?: object;
58
+ [SymbolSubTypes]?: Map<string, object>;
59
+ }
60
+ ```
61
+
62
+ ---
63
+
64
+ ## Testing Requirements
65
+
66
+ See [`rules-skill/testing.md`](./rules-skill/testing.md) for full details. 100% coverage required on both Mocha and Jest. Jest tests should mirror Mocha patterns from `test/environment.js`.
67
+
68
+ ---
69
+
70
+ ## Symbols Reference
71
+
72
+ See [`AGENTS.md`](./AGENTS.md) for the complete symbol reference table.
73
+
74
+ ---
75
+
76
+ ## Adding Type Definitions
77
+
78
+ ```typescript
79
+ // 1. Define type in src/types/index.ts
80
+ export interface NewTypeConfig {
81
+ property: string;
82
+ }
83
+
84
+ // 2. Update existing interfaces if needed
85
+ export interface MnemonicaInstance {
86
+ newProperty?: NewTypeConfig;
87
+ }
88
+ ```
89
+
90
+ ---
91
+
92
+ ## Error Handling
93
+
94
+ ```typescript
95
+ // Use MnemonicaErrorConstructor for custom errors
96
+ import { constructError } from '../api/errors/index.js';
97
+
98
+ const MyError = constructError('MY_ERROR', 'Error message');
99
+ throw new MyError('additional info', stack);
100
+ ```
101
+
102
+ ---
103
+
104
+ ## Configuration Files
105
+
106
+ **Disallowed without explicit approval:**
107
+ - Modifying `./tsconfig.json`
108
+ - Modifying `./eslint.config.js`
109
+
110
+ These configuration files define the project's strict standards. Any changes
111
+ require user approval first.
package/.ai/DEBUG.md ADDED
@@ -0,0 +1,179 @@
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:mocha`
162
+ 4. [ ] Run Jest tests: `npm run test:jest`
163
+ 5. [ ] Check test coverage: `npm run test:cov`
164
+ 6. [ ] Verify indentation (tabs not spaces)
165
+ 7. [ ] Check for bare `Function` / `CallableFunction` / `NewableFunction` types
166
+ 8. [ ] Verify symbol usage is correct
167
+ 9. [ ] Check proxy handler return types
168
+ 10. [ ] Verify return statements use intermediate variables
169
+
170
+ ---
171
+
172
+ ## Reporting Issues
173
+
174
+ When reporting findings:
175
+ 1. Include file paths and line numbers
176
+ 2. Show relevant code snippets
177
+ 3. Provide error messages in full
178
+ 4. Suggest root cause, not just symptoms
179
+ 5. Reference related test files
@@ -0,0 +1,171 @@
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; `enriched.parent('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
+ ---
86
+
87
+ ## Architecture
88
+
89
+ ```
90
+ src/
91
+ ├── index.ts # Main exports: define, lookup, apply, call, bind
92
+ ├── types/index.ts # TypeScript type definitions
93
+ ├── constants/ # Symbols and default options
94
+ ├── descriptors/ # Type collection and error definitions
95
+ ├── api/ # Core implementation
96
+ │ ├── types/ # TypeProxy, InstanceCreator, Mnemosyne
97
+ │ ├── errors/ # Error handling and stack traces
98
+ │ ├── hooks/ # Lifecycle hooks
99
+ │ └── utils/ # Utilities
100
+ └── utils/ # Public utilities (extract, parse, merge, etc.)
101
+ ```
102
+
103
+ Key components:
104
+ - **TypeProxy** — wraps type constructors
105
+ - **InstanceCreator** — orchestrates construction lifecycle
106
+ - **Mnemosyne** — handles instance method access via Proxy
107
+
108
+ ---
109
+
110
+ ## Testing Rules
111
+
112
+ - **Dual framework:** Mocha (transpiled `build/`), Jest (TypeScript `src/`)
113
+ - **100% coverage** required for both
114
+ - Jest tests should mirror Mocha patterns from `test/environment.js`
115
+ - Tests must pass with `--allow-uncaught` (mocha)
116
+
117
+ ---
118
+
119
+ ## Async Constructors
120
+
121
+ mnemonica supports async constructors natively:
122
+
123
+ ```typescript
124
+ const AsyncType = define('AsyncType', async function () {
125
+ await sleep(100);
126
+ this.done = true;
127
+ return this; // MUST return with awaitReturn: true (default)
128
+ });
129
+
130
+ const instance = await new AsyncType();
131
+ ```
132
+
133
+ **Critical:** Async subtypes are invoked as methods on the parent instance:
134
+
135
+ ```typescript
136
+ const parent = await new AsyncParent();
137
+ const child = await parent.AsyncChild(); // ✓ correct
138
+
139
+ const wrong = await new AsyncChild(); // ✗ fails strictChain
140
+ ```
141
+
142
+ Read [`../docs/async-constructors.md`](../docs/async-constructors.md) for the `super()` return-value trap and native async class wrapping.
143
+
144
+ ---
145
+
146
+ ## Common Pitfalls
147
+
148
+ 1. **`await new AsyncSubType()`** — wrong. Use `await parent.AsyncSubType()`.
149
+ 2. **`return { a, b }`** — wrong. Use `const result = { a, b }; return result;`.
150
+ 3. **Modifying `tsconfig.json` or `eslint.config.js`** — forbidden without explicit approval.
151
+ 4. **Forgetting `npm run test:cov`** — always run before finishing.
152
+ 5. **Using `Function` as a type** — define `interface MyHandler extends CallableFunction { ... }`.
153
+
154
+ ---
155
+
156
+ ## Where to Go Next
157
+
158
+ | Need | Read |
159
+ |------|------|
160
+ | Coding standards, type rules | [`CODE.md`](./CODE.md) |
161
+ | Design patterns, constraints | [`ARCHITECT.md`](./ARCHITECT.md) |
162
+ | Debugging commands, issues | [`DEBUG.md`](./DEBUG.md) |
163
+ | Async constructor deep dive | [`../docs/async-constructors.md`](../docs/async-constructors.md) |
164
+ | tactica type-safe lookup | [`TACTICA-RULES.md`](./TACTICA-RULES.md) |
165
+ | Behavioral guidelines | [`rules-skill/contributing.md`](./rules-skill/contributing.md) |
166
+ | Explaining code (ask mode) | [`ask/AGENTS.md`](./ask/AGENTS.md) |
167
+ | Multi-step coordination | [`orchestrator/AGENTS.md`](./orchestrator/AGENTS.md) |
168
+
169
+ ---
170
+
171
+ > **This file is a summary.** For authoritative rules, read the linked files. For the full type system, read `src/types/index.ts`.