mnemonica 1.0.9 → 1.2.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 (52) hide show
  1. package/.ai/AGENTS.md +31 -18
  2. package/.ai/DEBUG.md +7 -8
  3. package/.ai/ONBOARDING.md +23 -6
  4. package/.ai/PROTOTYPE-CHAIN.md +21 -0
  5. package/.ai/{ask/AGENTS.md → mode-ask.md} +1 -1
  6. package/.ai/{orchestrator/AGENTS.md → mode-orchestrator.md} +2 -19
  7. package/{docs → .ai}/performance-vs-security.md +1 -1
  8. package/.ai/{rules-skill/async-constructors.md → rules-async-constructors.md} +66 -0
  9. package/.ai/{rules/CODING.md → rules-coding.md} +19 -2
  10. package/.ai/{rules/CONTEXT-CONDENSING.md → rules-context-condensing.md} +2 -2
  11. package/.ai/{rules-skill/contributing.md → rules-contributing.md} +35 -0
  12. package/.ai/{rules-skill/instance-methods.md → rules-instance-methods.md} +1 -1
  13. package/.ai/rules-reminders.md +19 -0
  14. package/.ai/{rules-skill/type-system.md → rules-type-system.md} +1 -1
  15. package/{docs → .ai}/theory-of-operations.md +4 -4
  16. package/AGENTS.md +96 -24
  17. package/FOR_HUMANS.md +32 -76
  18. package/README.md +35 -20
  19. package/SKILL.md +20 -20
  20. package/build/api/index.d.ts +2 -2
  21. package/build/api/types/index.js +8 -3
  22. package/build/descriptors/types/index.js +2 -2
  23. package/build/index.d.ts +10 -3
  24. package/build/index.js +17 -5
  25. package/build/types/index.d.ts +60 -21
  26. package/build/types/index.js +1 -1
  27. package/docs/ai-learning-trajectory.md +2 -3
  28. package/docs/decorate.md +123 -0
  29. package/docs/hott-primer.md +1 -1
  30. package/docs/purpose.md +3 -3
  31. package/{.ai/TACTICA-DEEP-DIVE.md → docs/tactica-deep-dive.md} +45 -2
  32. package/docs/tactica-pattern.md +1 -2
  33. package/docs/typed-lookup.md +337 -93
  34. package/package.json +6 -6
  35. package/src/api/types/index.ts +14 -4
  36. package/src/descriptors/types/index.ts +63 -58
  37. package/src/index.ts +103 -12
  38. package/src/types/index.ts +241 -41
  39. package/.ai/CODE.md +0 -111
  40. package/.ai/TACTICA-RULES.md +0 -103
  41. package/.ai/async_init.md +0 -94
  42. package/.ai/rules/REMINDERS.md +0 -63
  43. package/.ai/rules-skill/lookup-typed.md +0 -82
  44. package/.ai/rules-skill/proxy-architecture.md +0 -63
  45. package/.ai/task-templates/new-feature.md +0 -46
  46. /package/.ai/{rules-skill/code-style.md → rules-code-style.md} +0 -0
  47. /package/.ai/{rules-skill/define-patterns.md → rules-define-patterns.md} +0 -0
  48. /package/.ai/{rules-skill/ecosystem.md → rules-ecosystem.md} +0 -0
  49. /package/.ai/{rules-skill/error-system.md → rules-error-system.md} +0 -0
  50. /package/.ai/{rules-skill/hooks.md → rules-hooks.md} +0 -0
  51. /package/.ai/{rules-skill/philosophy.md → rules-philosophy.md} +0 -0
  52. /package/.ai/{rules-skill/testing.md → rules-testing.md} +0 -0
package/AGENTS.md CHANGED
@@ -10,17 +10,26 @@ project, start with [`README.md`](./README.md).
10
10
 
11
11
  **This is the highest-priority rule. It overrides everything else in this file.**
12
12
 
13
- You MUST pause and ask the user before proceeding if any of these is true:
13
+ STOP and ask the user before proceeding when ANY of these is true:
14
14
 
15
- 1. **An editing error occurred** — `Edit` failed, `Write` produced unexpected
16
- results, or any tool returned an error.
15
+ 1. **An error occurred** — `Edit` failed, `Write` produced unexpected
16
+ results, or any tool returned an error. A successful retry does NOT
17
+ cancel this rule: report the error AND how you recovered.
17
18
  2. **You are uncertain** — about what change to make, how a function works,
18
19
  or what the user intended.
19
20
  3. **You are filling gaps with assumption** — "probably", "likely",
20
21
  "I think", "it should work" are signals to stop.
21
-
22
- When in doubt: STOP, ask a clear specific question, WAIT for the answer.
23
- Do not invent workarounds (no `sed`, no `python -c`, no console hacks).
22
+ 4. **A tool or environment constraint conflicts with the user's stated
23
+ preference** — surface the conflict verbatim; never silently satisfy
24
+ the tool at the user's expense.
25
+ 5. **You are about to create or duplicate a file the user did not
26
+ explicitly request** — ask first. Never copy content when `mv`,
27
+ rename, or a reference suffices.
28
+
29
+ When in doubt: STOP, ask one clear specific question, WAIT for the answer.
30
+ Do not invent workarounds (no `sed`, no `python -c`, no console hacks,
31
+ no rewriting files to bypass a tool restriction).
32
+ **Silent recovery is a violation, even when the outcome looks fine.**
24
33
 
25
34
  The reason this rule exists: wrong assumptions waste both your time and the
26
35
  user's. The library encodes non-obvious design intent (data-flow vs control-flow,
@@ -30,11 +39,17 @@ Confident guesses produce code that compiles but corrupts the design.
30
39
  ---
31
40
 
32
41
  > **Note:** Framework-agnostic rules are also available in `.ai/`:
33
- > [`AGENTS.md`](./.ai/AGENTS.md), [`CODE.md`](./.ai/CODE.md),
34
- > [`ARCHITECT.md`](./.ai/ARCHITECT.md), [`DEBUG.md`](./.ai/DEBUG.md),
35
- > [`async_init.md`](./.ai/async_init.md).
42
+ > [`AGENTS.md`](./.ai/AGENTS.md),
43
+ > [`ARCHITECT.md`](./.ai/ARCHITECT.md), [`DEBUG.md`](./.ai/DEBUG.md).
36
44
  > These rules apply to all agent frameworks.
37
45
 
46
+ > **Document locations:** this repository is agent-tools-agnostic. Documents
47
+ > about *contributing to the core* live in [`.ai/`](./.ai/); documents about
48
+ > *using the library* (for humans and agents alike) live in
49
+ > [`docs/`](./docs/). Tool-specific directories (`.kilo/`, `.kilocode/`,
50
+ > `.opencode/`, etc.) are for tool configuration only — never put project
51
+ > documents (plans, rules, guides) there.
52
+
38
53
  ## What and why
39
54
 
40
55
  For the library's thesis, the four data mistakes it eliminates, the Trie observation, the pipeline pattern, and the HoTT framing, read [`README.md`](./README.md). This file assumes you have.
@@ -48,26 +63,26 @@ Load the docs that match your change type. The wrong context produces broken cod
48
63
  | Change type | Read before starting |
49
64
  |---|---|
50
65
  | Any `src/` change | This file + [`.ai/ONBOARDING.md`](./.ai/ONBOARDING.md) |
51
- | Involves `define()` / type graph | + [`.ai/rules-skill/define-patterns.md`](./.ai/rules-skill/define-patterns.md) |
52
- | Involves hooks | + [`.ai/rules-skill/hooks.md`](./.ai/rules-skill/hooks.md) |
53
- | Involves async constructors | + [`.ai/rules-skill/async-constructors.md`](./.ai/rules-skill/async-constructors.md) + [`.ai/async_init.md`](./.ai/async_init.md) |
54
- | Involves TypeScript types | + [`.ai/rules-skill/type-system.md`](./.ai/rules-skill/type-system.md) |
55
- | Involves proxy internals | + [`.ai/rules-skill/proxy-architecture.md`](./.ai/rules-skill/proxy-architecture.md) |
56
- | Uses tactica / `lookup` | + [`.ai/TACTICA-RULES.md`](./.ai/TACTICA-RULES.md) |
66
+ | Involves `define()` / type graph | + [`.ai/rules-define-patterns.md`](./.ai/rules-define-patterns.md) |
67
+ | Involves hooks | + [`.ai/rules-hooks.md`](./.ai/rules-hooks.md) |
68
+ | Involves async constructors | + [`.ai/rules-async-constructors.md`](./.ai/rules-async-constructors.md) |
69
+ | Involves TypeScript types | + [`.ai/rules-type-system.md`](./.ai/rules-type-system.md) |
70
+ | Involves proxy internals | + [`.ai/PROTOTYPE-CHAIN.md`](./.ai/PROTOTYPE-CHAIN.md) |
71
+ | Uses tactica / `lookup` | + [`docs/tactica-deep-dive.md`](./docs/tactica-deep-dive.md) |
57
72
  | Docs-only change | README section you're touching only |
58
73
 
59
74
  **This file + `.ai/ONBOARDING.md` are the always-required baseline for any `src/` edit.**
60
75
 
61
76
  ### Framework-specific rules
62
77
 
63
- Mode-specific files in `.ai/rules/`:
64
- - [`.ai/rules/CODING.md`](./.ai/rules/CODING.md) — universal coding rules
65
- - [`.ai/rules/REMINDERS.md`](./.ai/rules/REMINDERS.md) — type vs interface, spacing reminders
66
- - [`.ai/rules/CONTEXT-CONDENSING.md`](./.ai/rules/CONTEXT-CONDENSING.md) — context recovery protocol
78
+ Mode-specific files in `.ai/`:
79
+ - [`.ai/rules-coding.md`](./.ai/rules-coding.md) — universal coding rules
80
+ - [`.ai/rules-reminders.md`](./.ai/rules-reminders.md) — type vs interface, spacing reminders
81
+ - [`.ai/rules-context-condensing.md`](./.ai/rules-context-condensing.md) — context recovery protocol
67
82
 
68
83
  ## Build/Test Commands
69
84
 
70
- See [`.ai/rules-skill/testing.md`](./.ai/rules-skill/testing.md) for the full command reference, dual-framework details, and coverage requirements. Summary:
85
+ See [`.ai/rules-testing.md`](./.ai/rules-testing.md) for the full command reference, dual-framework details, and coverage requirements. Summary:
71
86
 
72
87
  ```bash
73
88
  npm run build # full build with linting
@@ -82,7 +97,7 @@ npm run watch # watch mode
82
97
 
83
98
  ## Code Style (Project-Specific)
84
99
 
85
- See [`.ai/rules-skill/code-style.md`](./.ai/rules-skill/code-style.md) for the full style reference. Key rules: tabs only, space before function parens, colons aligned in object literals, `strict: true`, **no `any`** (`no-explicit-any: error`).
100
+ See [`.ai/rules-code-style.md`](./.ai/rules-code-style.md) for the full style reference. Key rules: tabs only, space before function parens, colons aligned in object literals, `strict: true`, **no `any`** (`no-explicit-any: error`).
86
101
 
87
102
  ## Architecture Patterns
88
103
 
@@ -94,7 +109,7 @@ The core API is `define(TypeName, constructHandler, config?)` in `src/index.ts`.
94
109
 
95
110
  ### The `lookup()` Function
96
111
 
97
- For user-facing semantics, see [`README.md`](./README.md) and [`.ai/TACTICA-RULES.md`](./.ai/TACTICA-RULES.md). The contributor-relevant detail is the implementation pattern: `TypeRegistry` starts empty, and `lookup()` uses overloads so augmented keys return the typed constructor while unaugmented keys fall back to `TypeClass | undefined`.
112
+ For user-facing semantics, see [`README.md`](./README.md) and [`docs/tactica-deep-dive.md`](./docs/tactica-deep-dive.md). The contributor-relevant detail is the implementation pattern: `TypeRegistry` starts empty, and `lookup()` uses overloads so augmented keys return the typed constructor while unaugmented keys fall back to `TypeClass | undefined`.
98
113
 
99
114
  ```typescript
100
115
  // In mnemonica core (src/index.ts)
@@ -134,6 +149,63 @@ Runtime behavior is identical whether `TypeRegistry` is augmented or not; the on
134
149
  > on constructors that preserves the prototype chain) is designed but not
135
150
  > yet shipped.
136
151
 
152
+ ### Typed registry builders
153
+
154
+ Mnemonica has three compile-time paths for the same runtime API:
155
+
156
+ - **Builder mode** (default) — chain `.define()` on the exported `mnemonica` object or on
157
+ a `createTypesCollection()` result. No `TypeRegistry` augmentation, no Tactica.
158
+ - **Registry bridge** — one hand-written line merges a builder's local registry
159
+ into the global `TypeRegistry`:
160
+ `interface TypeRegistry extends RegistryOf<typeof App> {}`
161
+ (inside `declare module 'mnemonica'`, in a dedicated `registry.ts`).
162
+ - **Augmented mode** — use free `define()`/`lookup()` or `@decorate()`, and let
163
+ Tactica (or a hand-written file) populate the global `TypeRegistry`. Required
164
+ for `@decorate()`: TypeScript never applies a class decorator's return type
165
+ to the class binding, so no local-registry mechanism can type decorators.
166
+
167
+ Public types involved:
168
+
169
+ - `TypesCollection<T, Parent, Path>` — type of `createTypesCollection()`.
170
+ - `MnemonicaModule<Registry>` — type of the exported `mnemonica` object.
171
+ - `IDefinitorInstance<N, R, Registry, Path>` — type of constructors returned by
172
+ `.define()`.
173
+ - `RegistryOf<T>` — extracts the accumulated `Registry` from any of the above,
174
+ for the bridge.
175
+
176
+ Quick builder example:
177
+
178
+ ```typescript
179
+ import { mnemonica } from 'mnemonica';
180
+
181
+ const App = mnemonica
182
+ .define('User', function (this: User, data: { name: string }) {
183
+ this.name = data.name;
184
+ })
185
+ .define('Admin', function (this: Admin, data: { role: string }) {
186
+ this.role = data.role;
187
+ });
188
+
189
+ const User = App.lookup('User');
190
+ const user = new User({ name: 'Ada' });
191
+ const admin = new user.Admin({ role: 'root' });
192
+ ```
193
+
194
+ Constructor `.lookup()` resolves **relative first, then root fallback**: the
195
+ type's own subtypes are searched first, then the same string is resolved as an
196
+ absolute path from the collection root. Exported builder values carry the
197
+ registry across files (registry threading).
198
+
199
+ The free `define()`/`lookup()` exports resolve against the global
200
+ `TypeRegistry` (augmentation or bridge). When you hold a builder value, prefer
201
+ the explicit-source forms — `lookup(source, path)` and
202
+ `define(source, name, handler)` — which infer the registry from the source
203
+ instead of falling back to the global interface.
204
+
205
+ For the full guide — multi-file threading, the bridge, two-arg overloads,
206
+ `strictChain` notes, and `@decorate` limitations — see
207
+ [`docs/typed-lookup.md`](./docs/typed-lookup.md).
208
+
137
209
  ### Type System Structure
138
210
  ```
139
211
  src/
@@ -216,7 +288,7 @@ This applies to **all** `return` statements where the expression is anything oth
216
288
 
217
289
  ## TypeScript Type Rules
218
290
 
219
- **Never use bare `Function`, `CallableFunction`, or `NewableFunction` as types** — always define a purpose-specific interface that extends them. See [`.ai/rules-skill/code-style.md`](./.ai/rules-skill/code-style.md) for examples and allowed exceptions.
291
+ **Never use bare `Function`, `CallableFunction`, or `NewableFunction` as types** — always define a purpose-specific interface that extends them. See [`.ai/rules-code-style.md`](./.ai/rules-code-style.md) for examples and allowed exceptions.
220
292
 
221
293
  ## Preserving Design Comments and Memory Notes
222
294
 
@@ -234,7 +306,7 @@ If a comment becomes technically inaccurate after a change, update it rather tha
234
306
 
235
307
  ## Testing Requirements
236
308
 
237
- See [`.ai/rules-skill/testing.md`](./.ai/rules-skill/testing.md) for full coverage requirements and patterns. 100% required on both Mocha and Jest. Must run `npm run test:cov` before completing any task.
309
+ See [`.ai/rules-testing.md`](./.ai/rules-testing.md) for full coverage requirements and patterns. 100% required on both Mocha and Jest. Must run `npm run test:cov` before completing any task.
238
310
 
239
311
  ## Common Patterns
240
312
 
package/FOR_HUMANS.md CHANGED
@@ -50,6 +50,15 @@ The key inversion: subtypes are instantiated *from parent instances*, not from c
50
50
 
51
51
  **Why it matters:** in any system where data transformation order matters — HTTP pipelines, ETL flows, AI agent chains — the construction history *is* the business logic. mnemonica makes that history first-class.
52
52
 
53
+ ### One runtime, two type-system paths
54
+
55
+ Mnemonica has one runtime behavior, but TypeScript cannot see the type graph created by runtime `define()` calls. To solve this, there are two compile-time paths:
56
+
57
+ 1. **Builder mode** — chain `.define()` on the `mnemonica` object or on `createTypesCollection()`. The returned object carries a local type registry, so `.lookup()` is typed without any global augmentation.
58
+ 2. **Augmented mode** — use the free `define()` / `lookup()` exports and augment the global `TypeRegistry` by hand or with `@mnemonica/tactica`.
59
+
60
+ There is also a one-line middle path: the `RegistryOf` bridge merges a builder's local registry into the global `TypeRegistry` by hand. At runtime all paths are identical — the only difference is where TypeScript looks up the types. See [`docs/typed-lookup.md`](./docs/typed-lookup.md) for details.
61
+
53
62
  ---
54
63
 
55
64
  Most software treats data as anonymous values that flow through functions. The values get passed around, transformed, returned — and somewhere along the way, you lose track of *where they came from*.
@@ -93,7 +102,7 @@ const engineer = new alice.Employee({ role: 'Engineer' });
93
102
  engineer.name; // 'Alice' (inherited from alice)
94
103
  engineer.role; // 'Engineer'
95
104
  engineer instanceof Person; // true
96
- engineer.parent(); // returns alice (the specific Person it came from)
105
+ utils.parent(engineer); // returns alice (the specific Person it came from)
97
106
 
98
107
  const story = getProps(engineer);
99
108
  // story.__type__ — the Employee type
@@ -111,7 +120,7 @@ The key inversion: `new` is called on the **parent instance** (`alice`), not on
111
120
  - **Want a guided tour?** Continue reading — [Quick Start](#quick-start), [Core Concepts](#core-concepts).
112
121
  - **Looking for a specific function?** Jump to the [API Reference](#api-reference).
113
122
  - **Curious about the theory?** Read [`README.md`](./README.md) — the HoTT framing, the Trie observation, the pipeline pattern, the AI-agent angle.
114
- - **Want examples you can run?** See the [`examples/`](./examples/) directory and [Examples](#examples) below.
123
+ - **Want examples you can run?** See the [Examples](#examples) section below.
115
124
  - **Going deeper on philosophy?** Read [`docs/purpose.md`](./docs/purpose.md).
116
125
  - **Background reading:** [Inheritance in JavaScript: Factory of Constructors with Prototype Chain](https://github.com/mythographica/stash/blob/master/inheritance.md) · [Architecture of Prototype Inheritance in JavaScript](https://dev.to/wentout/architecture-of-prototype-inheritance-in-javascript-ce6) · [Dead Simple type checker for JavaScript](https://dev.to/wentout/dead-simple-type-checker-for-javascript-4l40)
117
126
 
@@ -195,35 +204,12 @@ console.log(admin.role); // 'admin' (own property)
195
204
 
196
205
  ### Class-Based (TypeScript)
197
206
 
198
- Both styles are **equally supported**. The `@decorate()` decorator registers a class as a mnemonica type and works identically to `define()` at runtime:
199
-
200
- ```typescript
201
- import { decorate, apply } from 'mnemonica';
202
-
203
- // Define a type using a class
204
- @decorate()
205
- class UserType {
206
- name: string;
207
- email: string;
208
- constructor (data: { name: string; email: string }) {
209
- Object.assign(this, data);
210
- }
211
- }
212
-
213
- // Create an instance
214
- const user = new UserType({ name: 'John', email: 'john@example.com' });
215
-
216
- // Define a subtype
217
- @decorate(UserType)
218
- class AdminType {
219
- role: string = 'admin';
220
- }
221
-
222
- // Create a nested instance (inherits from user)
223
- const admin = new user.AdminType();
224
- console.log(admin.name); // 'John' (inherited)
225
- console.log(admin.role); // 'admin' (own property)
226
- ```
207
+ A class-based style also exists via the `@decorate()` decorator, and it works
208
+ identically to `define()` at runtime. It is **not the default path**: it
209
+ requires [`@mnemonica/tactica`](https://www.npmjs.com/package/@mnemonica/tactica)
210
+ (or hand-written augmentation) to be typed, because TypeScript never applies a
211
+ class decorator's return type to the class binding. See
212
+ [`docs/decorate.md`](./docs/decorate.md) for the full guide and examples.
227
213
 
228
214
  ### ESM
229
215
 
@@ -240,12 +226,12 @@ import { define, lookup } from 'mnemonica/module';
240
226
  | Change type | Read before starting |
241
227
  |---|---|
242
228
  | Any `src/` change | [`AGENTS.md`](./AGENTS.md) + [`.ai/ONBOARDING.md`](./.ai/ONBOARDING.md) |
243
- | Involves `define()` / type graph | + [`.ai/rules-skill/define-patterns.md`](./.ai/rules-skill/define-patterns.md) |
244
- | Involves hooks | + [`.ai/rules-skill/hooks.md`](./.ai/rules-skill/hooks.md) |
245
- | Involves async constructors | + [`.ai/rules-skill/async-constructors.md`](./.ai/rules-skill/async-constructors.md) + [`.ai/async_init.md`](./.ai/async_init.md) |
246
- | Involves TypeScript types | + [`.ai/rules-skill/type-system.md`](./.ai/rules-skill/type-system.md) |
247
- | Involves proxy internals | + [`.ai/rules-skill/proxy-architecture.md`](./.ai/rules-skill/proxy-architecture.md) |
248
- | Uses tactica / `lookup` | + [`.ai/TACTICA-RULES.md`](./.ai/TACTICA-RULES.md) |
229
+ | Involves `define()` / type graph | + [`.ai/rules-define-patterns.md`](./.ai/rules-define-patterns.md) |
230
+ | Involves hooks | + [`.ai/rules-hooks.md`](./.ai/rules-hooks.md) |
231
+ | Involves async constructors | + [`.ai/rules-async-constructors.md`](./.ai/rules-async-constructors.md) |
232
+ | Involves TypeScript types | + [`.ai/rules-type-system.md`](./.ai/rules-type-system.md) |
233
+ | Involves proxy internals | + [`.ai/PROTOTYPE-CHAIN.md`](./.ai/PROTOTYPE-CHAIN.md) |
234
+ | Uses tactica / `lookup` | + [`docs/tactica-deep-dive.md`](./docs/tactica-deep-dive.md) |
249
235
  | Docs-only change | README section you're touching only |
250
236
  | Unfamiliar with the codebase | [`.ai/ONBOARDING.md`](./.ai/ONBOARDING.md) first — one file, five minutes |
251
237
 
@@ -513,7 +499,7 @@ const AsyncTypeNoReturn = define('AsyncType', async function () {
513
499
  | Get parent instance | `utils.parent(instance)` or `utils.parent(instance, 'TypeName')` |
514
500
  | Flatten to plain object | `utils.extract(instance)` |
515
501
  | Add lifecycle hooks | `type.registerHook('postCreation', cb)` |
516
- | Use classes | `@decorate()` decorator |
502
+ | Use classes (requires Tactica) | see [`docs/decorate.md`](./docs/decorate.md) |
517
503
 
518
504
  ### Core Functions
519
505
 
@@ -598,49 +584,20 @@ const subInstance = createSub('arg1', 'arg2');
598
584
 
599
585
  #### `decorate(target?, config?)`
600
586
 
601
- TypeScript decorator for class-based definitions.
587
+ TypeScript decorator for class-based definitions; runtime-equivalent to
588
+ `define()`. Requires Tactica (or hand-written `TypeRegistry` augmentation) to
589
+ be typed — see [`docs/decorate.md`](./docs/decorate.md) for the full guide,
590
+ including nested decoration, configuration, and the TypeØmatica integration.
602
591
 
603
592
  ```typescript
604
593
  import { decorate } from 'mnemonica';
605
594
 
606
- // Basic decoration
607
595
  @decorate()
608
596
  class MyClass {
609
597
  field: number = 123;
610
598
  }
611
-
612
- // Nested decoration (define as subtype)
613
- @decorate()
614
- class ParentClass {
615
- parentField: string = 'parent';
616
- }
617
-
618
- @decorate(ParentClass)
619
- class ChildClass {
620
- childField: string = 'child';
621
- }
622
-
623
- // Create parent instance, then child from it
624
- const parent = new ParentClass();
625
- const child = new parent.ChildClass();
626
599
  ```
627
600
 
628
- **With configuration:**
629
-
630
- ```typescript
631
- @decorate({ strictChain: false, blockErrors: true })
632
- class ConfiguredClass {
633
- field: number = 123;
634
- }
635
-
636
- @decorate(ParentClass, { strictChain: false })
637
- class ConfiguredChildClass {
638
- field: number = 123;
639
- }
640
- ```
641
-
642
- **Note:** After a class is decorated with `@decorate()`, it can be used as a decorator for nested types (advanced pattern; may require `@ts-ignore` due to TypeScript limitations with callable class types).
643
-
644
601
  #### `registerHook(Constructor, hookType, callback)`
645
602
 
646
603
  Registers a hook for a specific constructor.
@@ -664,7 +621,7 @@ For advanced TypeScript usage, the following types are exported from `mnemonica`
664
621
  | `IDEF<T>` | Base constructor function type | `define('Name', fn: IDEF<MyType>)` |
665
622
  | `MnemonicaInstance` | Optional helper interface | Can be used when attaching the legacy instance methods to your own prototype |
666
623
  | `TypeClass` | Base type constructor | `const MyType: TypeClass = define(...)` |
667
- | `DecoratedClass<T>` | Decorated class type | `@decorate() class MyClass {}` |
624
+ | `DecoratedClass<T>` | Decorated class type | `@decorate() class MyClass {}` (see [`docs/decorate.md`](./docs/decorate.md)) |
668
625
  | `IDefinitorInstance<N, S>` | Constructor with subtypes | Returned by `define()` with `.define()` method |
669
626
  | `ConstructorFunction<T>` | Constructor with prototype | Generic constructor function signature |
670
627
  | `constructorOptions` | Configuration options | `{ strictChain: true, blockErrors: true }` |
@@ -1133,7 +1090,7 @@ defaultTypes[SymbolConfig].blockErrors = false;
1133
1090
 
1134
1091
  ## Usage with TypeØmatica
1135
1092
 
1136
- TypeØmatica is a companion library that provides strict runtime type checking using JavaScript Proxies. It enforces types at runtime exactly as TypeScript expects at compile time.
1093
+ TypeØmatica is a companion library that provides strict runtime type checking using JavaScript Proxies. It enforces types at runtime exactly as TypeScript expects at compile time. The `@decorate()` usage below requires Tactica — see [`docs/decorate.md`](./docs/decorate.md).
1137
1094
 
1138
1095
  ```typescript
1139
1096
  import { BaseClass } from 'typeomatica';
@@ -1165,9 +1122,8 @@ For complete documentation including integration patterns, error handling, and a
1165
1122
 
1166
1123
  ## Examples
1167
1124
 
1168
- Runnable scripts in [`examples/`](examples/) demonstrate edge cases and
1169
- integration patterns. See [examples/README.md](examples/README.md). Quick
1170
- runners are wired up in `package.json`:
1125
+ Runnable scripts in the `test/` and `test-ts/` directories demonstrate edge
1126
+ cases and integration patterns. Quick runners are wired up in `package.json`:
1171
1127
 
1172
1128
  ```bash
1173
1129
  npm run example:async # async constructor edge case
package/README.md CHANGED
@@ -18,7 +18,7 @@ If any concept seems abstract before the examples land: [The four data mistakes]
18
18
 
19
19
  ## What this is
20
20
 
21
- The JavaScript prototype chain is a Trie. Every `new` call you write extends a node — the new instance inherits from the parent via `__proto__`. Property lookups traverse leaf-to-root. You have been working inside this structure your entire career. It is not an analogy; it is the actual runtime mechanism.
21
+ The JavaScript prototype chain is a Trie. Every `new` call you write extends a node — the new instance inherits from the parent through the prototype link that `Object.getPrototypeOf(instance)` returns. Property lookups traverse leaf-to-root. You have been working inside this structure your entire career. It is not an analogy; it is the actual runtime mechanism.
22
22
 
23
23
  Mnemonica promotes the Trie from implementation detail to first-class data model. The complete interface for most use cases:
24
24
 
@@ -28,6 +28,20 @@ Mnemonica promotes the Trie from implementation detail to first-class data model
28
28
 
29
29
  Every instance carries its full history. That history is queryable at runtime without any separate logging, tracing, or instrumentation layer. The construction record *is the object*.
30
30
 
31
+ ### One runtime, two type-system paths
32
+
33
+ Mnemonica has exactly one runtime behavior. Whether you write `define('Person', ...)` or `mnemonica.define('Person', ...)`, the same constructor is registered and the same prototype chain is built.
34
+
35
+ TypeScript, however, cannot see the type graph created by runtime `define()` calls. To solve this, mnemonica offers three compile-time paths, which compose:
36
+
37
+ 1. **Builder mode** (default) — chain `.define()` on the `mnemonica` module object or on `createTypesCollection()`. The returned object carries a **local type registry**, so `.lookup()` is typed without any global augmentation. No tooling required; exported builder values carry the registry across files.
38
+ 2. **Registry bridge** — merge the builder's local registry into the global `TypeRegistry` with one hand-written line: `interface TypeRegistry extends RegistryOf<typeof App> {}`. Now the free `lookup()` is typed too, with no codegen and nothing to keep in sync.
39
+ 3. **Augmented mode** — use the free `define()` / `lookup()` exports and `@decorate()`, with the global `TypeRegistry` populated by `@mnemonica/tactica` (or written by hand). Required for `@decorate()`, which neither of the other paths can type.
40
+
41
+ At runtime all paths are identical. The only difference is where TypeScript looks up the types. The runtime is the source of truth; the type-system path is a projection chosen by the developer.
42
+
43
+ See [`docs/typed-lookup.md`](./docs/typed-lookup.md) for the full comparison and examples.
44
+
31
45
  The design is **inspired by** Homotopy Type Theory. The Trie behaves monadically — `new instance.SubType()` threads construction context forward like bind. Parent plus constructor uniquely determines position in the Trie; there is no "equivalent but distinct." An instance is not a snapshot of state — it is a point on a constructible, replayable path. These are productive analogies that illuminate why the structure works, not claims of a formal HoTT embedding.
32
46
 
33
47
  You do not need HoTT to use mnemonica. The [primer](./docs/hott-primer.md) is there when you want the formal picture. If theory feels abstract before examples land, [The four data mistakes](#the-four-data-mistakes-mnemonica-fixes) is the right starting point.
@@ -54,7 +68,7 @@ const engineer = new alice.Employee({ role: 'Engineer' });
54
68
  // ^^^^^ instance-level inheritance, not class-level
55
69
 
56
70
  engineer instanceof Person; // true — path back to root
57
- engineer.parent(); // returns alice (literal __proto__)
71
+ utils.parent(engineer); // returns alice — Object.getPrototypeOf(engineer) === alice
58
72
  getProps(engineer); // { __type__, __parent__, __args__, __timestamp__, ... }
59
73
  ```
60
74
 
@@ -127,18 +141,18 @@ These are the two assumptions that most reliably produce incorrect code.
127
141
  - **`utils.parent(instance, 'TypeName')`** — walks to a named ancestor in O(depth), no manual counting
128
142
  - **`lookup(path)`** — resolves any type by path string with full TypeScript inference, against an augmented `TypeRegistry` (hand-written or `tactica`-generated — see [`docs/typed-lookup.md`](./docs/typed-lookup.md)). Paths may use dots, slashes, colons, or bracket notation, and may be single-segment names when the lookup is relative to a collection or type.
129
143
 
130
- For any traversal deeper than a single step, prefer `parent('TypeName')` or `lookup`. The manual chain form in examples is illustrative only. See [`.ai/TACTICA-RULES.md`](./.ai/TACTICA-RULES.md) for the full `lookup` usage guide.
144
+ For any traversal deeper than a single step, prefer `parent('TypeName')` or `lookup`. The manual chain form in examples is illustrative only. See [`docs/tactica-deep-dive.md`](./docs/tactica-deep-dive.md) for the full `lookup` usage guide.
131
145
 
132
146
  **2. "`Person.define('Employee')` is `class Employee extends Person`."** It isn't. The difference is where `new` goes:
133
147
 
134
148
  ```typescript
135
149
  // Class-level (NOT mnemonica):
136
150
  const engineer = new Employee({ role: 'Engineer' });
137
- // engineer.__proto__ === Employee.prototype — shared across all employees
151
+ // Object.getPrototypeOf(engineer) === Employee.prototype — shared across all employees
138
152
 
139
153
  // Instance-level (mnemonica):
140
154
  const engineer = new alice.Employee({ role: 'Engineer' });
141
- // engineer.__proto__ === alice — private to this specific alice
155
+ // Object.getPrototypeOf(engineer) === alice — private to this specific alice
142
156
  ```
143
157
 
144
158
  `alice.Employee` and `bob.Employee` are distinct Trie paths. They share the `Employee` type definition but produce independent prototype chain segments. Two concurrent pipeline runs are two isolated paths — no shared prototype state, no cross-contamination between runs. The construction history of one pipeline is invisible to another.
@@ -171,7 +185,7 @@ These restrictions are not arbitrary. They are runtime enforcement of the identi
171
185
  ```typescript
172
186
  const user = new UserType({ name: 'Alice' });
173
187
  const admin = new user.AdminType({ role: 'admin' });
174
- // admin.__proto__ === user
188
+ // Object.getPrototypeOf(admin) === user
175
189
  // admin instanceof UserType → true (path back to root)
176
190
  // admin instanceof AdminType → true
177
191
  ```
@@ -197,7 +211,7 @@ These terms are used throughout the codebase and documentation with precise mean
197
211
  | **ModificatorType** | The actual constructor function used for `new` calls. Its prototype is linked to Mnemosyne, which is linked to the parent instance. |
198
212
  | **WeakMap key** | Internal properties are stored in a `WeakMap` keyed by the **Mnemosyne object**, not the instance itself. This keeps instance enumeration clean and shares metadata across instances of the same type. |
199
213
 
200
- For the full construction pipeline from `define()` through `TypeProxy` → `InstanceCreator` → `Mnemosyne` → instance, see [`docs/theory-of-operations.md`](./docs/theory-of-operations.md).
214
+ For the full construction pipeline from `define()` through `TypeProxy` → `InstanceCreator` → `Mnemosyne` → instance, see [`.ai/theory-of-operations.md`](./.ai/theory-of-operations.md).
201
215
 
202
216
  ---
203
217
 
@@ -253,9 +267,9 @@ function handle (req: { method: string; url: string }) {
253
267
  const page = new route.PageData({ template: 'default' });
254
268
  const response = new page.ResponseData({ body: render(page) });
255
269
  return response;
256
- // response.parent() === page
257
- // response.parent().parent() === route
258
- // response.parent().parent().parent() === request
270
+ // utils.parent(response, 'PageData') === page
271
+ // utils.parent(response, 'RouteData') === route
272
+ // utils.parent(response, 'RequestData') === request
259
273
  // The full lineage is queryable at any point.
260
274
  }
261
275
  ```
@@ -410,7 +424,7 @@ new instance.SubType(args)
410
424
 
411
425
  See [`src/api/types/InstanceCreator.ts`](./src/api/types/InstanceCreator.ts) and [`src/api/types/TypeProxy.ts`](./src/api/types/TypeProxy.ts).
412
426
 
413
- For the full construction pipeline with source file references for every stage, see [`docs/theory-of-operations.md`](./docs/theory-of-operations.md).
427
+ For the full construction pipeline with source file references for every stage, see [`.ai/theory-of-operations.md`](./.ai/theory-of-operations.md).
414
428
 
415
429
  ### Type system primitives (TypeScript)
416
430
 
@@ -455,22 +469,23 @@ Everything below ships with this package.
455
469
  2. [`FOR_HUMANS.md`](./FOR_HUMANS.md) — gentler, example-heavy walkthrough for human developers
456
470
  3. [`SKILL.md`](./SKILL.md) — quick reference for usage patterns
457
471
  4. [`docs/prototype-chain.md`](./docs/prototype-chain.md) — how mnemonica builds the per-instance prototype chain and why the layers exist
458
- 5. [`docs/typed-lookup.md`](./docs/typed-lookup.md) — using `lookup()` with or without tactica (the `TypeRegistry` augmentation pattern)
459
- 5. [`docs/hott-primer.md`](./docs/hott-primer.md) — HoTT concepts mapped to mnemonica (monad, path types, univalence, HITs, fibrations)
460
- 6. [`docs/empathy-in-ai.md`](./docs/empathy-in-ai.md) — why reconstructible data lineage is infrastructure for empathetic AI
472
+ 5. [`docs/typed-lookup.md`](./docs/typed-lookup.md) — typed `lookup()`/`define()`: builder mode, the `RegistryOf` bridge, tactica
473
+ 6. [`docs/decorate.md`](./docs/decorate.md) — `@decorate()` class-based definitions (requires tactica)
474
+ 7. [`docs/tactica-deep-dive.md`](./docs/tactica-deep-dive.md) — the `TypeRegistry` augmentation pattern in depth
475
+ 8. [`docs/hott-primer.md`](./docs/hott-primer.md) — HoTT concepts mapped to mnemonica (monad, path types, univalence, HITs, fibrations)
476
+ 9. [`docs/empathy-in-ai.md`](./docs/empathy-in-ai.md) — why reconstructible data lineage is infrastructure for empathetic AI
461
477
 
462
478
  **For *modifying* mnemonica** (when you touch `src/`):
463
479
 
464
480
  1. [`AGENTS.md`](./AGENTS.md) — Rule #1, change-type reading guide, code style, editing rules
465
481
  2. [`.ai/ONBOARDING.md`](./.ai/ONBOARDING.md) — five-minute editor onboarding
466
482
  3. [`CONTRIBUTING.md`](./CONTRIBUTING.md) — local workflow, branching, release process
467
- 4. [`docs/theory-of-operations.md`](./docs/theory-of-operations.md) — full construction pipeline from `define()` through `InstanceCreator` to instance return, with source file references for every stage
483
+ 4. [`.ai/theory-of-operations.md`](./.ai/theory-of-operations.md) — full construction pipeline from `define()` through `InstanceCreator` to instance return, with source file references for every stage
468
484
  5. [`.ai/PROTOTYPE-CHAIN.md`](./.ai/PROTOTYPE-CHAIN.md) — the exact shape of the prototype chain, what each layer holds, and how subtype lookup walks it
469
- 6. [`.ai/CODE.md`](./.ai/CODE.md), [`.ai/ARCHITECT.md`](./.ai/ARCHITECT.md), [`.ai/DEBUG.md`](./.ai/DEBUG.md) — role-specific deeper rules
470
- 6. [`.ai/TACTICA-DEEP-DIVE.md`](./.ai/TACTICA-DEEP-DIVE.md) — deeper tactica integration patterns
471
- 7. [`.ai/async_init.md`](./.ai/async_init.md) — async constructor patterns
472
- 8. [`.ai/rules-skill/`](./.ai/rules-skill/) — granular rules for type system, hooks, code style, errors, testing
473
- 9. [`.ai/rules/`](./.ai/rules/) — broader contributor rules
485
+ 6. [`.ai/ARCHITECT.md`](./.ai/ARCHITECT.md), [`.ai/DEBUG.md`](./.ai/DEBUG.md) — role-specific deeper rules
486
+ 7. [`.ai/performance-vs-security.md`](./.ai/performance-vs-security.md) — performance/security trade-off analysis
487
+ 8. [`.ai/rules-async-constructors.md`](./.ai/rules-async-constructors.md) — async constructor patterns
488
+ 9. [`.ai/`](./.ai/) — the remaining `rules-*.md` (type system, hooks, code style, errors, testing) and mode guides
474
489
 
475
490
  The full TypeScript source is in [`src/`](./src/) (on GitHub; the npm package ships compiled output in `build/` and `module/`).
476
491
 
package/SKILL.md CHANGED
@@ -24,7 +24,7 @@ Activate this skill when:
24
24
 
25
25
  ## Functional vs Class-Based — Both Are Equally Supported
26
26
 
27
- `define()` and `@decorate()` are runtime equivalents. When working in a codebase, **match the style already in use**. See [rules-skill/define-patterns.md](.ai/rules-skill/define-patterns.md) for a side-by-side comparison.
27
+ `define()` and `@decorate()` are runtime equivalents. When working in a codebase, **match the style already in use**. See [rules-define-patterns.md](.ai/rules-define-patterns.md) for a side-by-side comparison.
28
28
 
29
29
  ## High-priority checklist: Adding a new type
30
30
 
@@ -33,18 +33,18 @@ When the task involves adding or modifying a type definition:
33
33
  1. **Use `type` for data, `interface` for behavior contracts**
34
34
  - Instance data → `type MyTypeData = { ... }`
35
35
  - Constructor contract → `interface MyTypeConstructor { ... }`
36
- - See [rules-skill/type-system.md](.ai/rules-skill/type-system.md)
36
+ - See [rules-type-system.md](.ai/rules-type-system.md)
37
37
 
38
- 2. **Check TypeRegistry augmentation** (if using tactica)
39
- - Does `.tactica/types.ts` need updating?
40
- - Is `lookup('MyType')` properly typed?
41
- - See [rules-skill/lookup-typed.md](.ai/rules-skill/lookup-typed.md)
38
+ 2. **Check how `lookup()` is typed** (in order of preference)
39
+ - Builder mode (`mnemonica.define` / `createTypesCollection`)? Nothing to do — the registry is local.
40
+ - Free `lookup()` on a builder project? Use the one-line `RegistryOf` bridge — see [docs/typed-lookup.md](./docs/typed-lookup.md).
41
+ - Using tactica / `@decorate()`? Does `.tactica/types.ts` need updating? Is `lookup('MyType')` properly typed? See [tactica-deep-dive.md](./docs/tactica-deep-dive.md)
42
42
 
43
43
  3. **Test both success and error paths**
44
44
  - Mocha test in `test/` for runtime behavior
45
45
  - Jest test in `test-jest/` for type coverage
46
46
  - Error path: test `ALREADY_DECLARED`, `WRONG_MODIFICATION_PATTERN`
47
- - See [rules-skill/testing.md](.ai/rules-skill/testing.md)
47
+ - See [rules-testing.md](.ai/rules-testing.md)
48
48
 
49
49
  4. **Run coverage before completing**
50
50
  - `npm run test:cov` (Mocha + build)
@@ -72,29 +72,29 @@ npm run watch # Watch mode
72
72
  Read individual rule files for detailed explanations and code examples:
73
73
 
74
74
  ### Type System
75
- - [rules-skill/type-system.md](.ai/rules-skill/type-system.md) — `Proto<P,T>`, `TypeConstructor`, type vs interface
75
+ - [rules-type-system.md](.ai/rules-type-system.md) — `Proto<P,T>`, `TypeConstructor`, type vs interface
76
76
 
77
77
  ### Patterns
78
- - [rules-skill/define-patterns.md](.ai/rules-skill/define-patterns.md) — `define()` usage, subtypes, config options
79
- - [rules-skill/lookup-typed.md](.ai/rules-skill/lookup-typed.md) — `TypeRegistry`, `lookup`, tactica integration
80
- - [rules-skill/async-constructors.md](.ai/rules-skill/async-constructors.md) — async constructors, `awaitReturn`, chaining
78
+ - [rules-define-patterns.md](.ai/rules-define-patterns.md) — `define()` usage, subtypes, config options
79
+ - [tactica-deep-dive.md](./docs/tactica-deep-dive.md) — `TypeRegistry`, `lookup`, tactica integration
80
+ - [rules-async-constructors.md](.ai/rules-async-constructors.md) — async constructors, `awaitReturn`, chaining
81
81
 
82
82
  ### Architecture
83
- - [rules-skill/proxy-architecture.md](.ai/rules-skill/proxy-architecture.md) — TypeProxy, InstanceCreator, Mnemosyne pipeline
84
- - [rules-skill/instance-methods.md](.ai/rules-skill/instance-methods.md) — `extract()`, `fork()`, `parent()`, internal props
85
- - [rules-skill/hooks.md](.ai/rules-skill/hooks.md) — `preCreation`, `postCreation`, `creationError`
83
+ - [PROTOTYPE-CHAIN.md](.ai/PROTOTYPE-CHAIN.md) — TypeProxy, InstanceCreator, Mnemosyne pipeline, construction internals
84
+ - [rules-instance-methods.md](.ai/rules-instance-methods.md) — `extract()`, `fork()`, `parent()`, internal props
85
+ - [rules-hooks.md](.ai/rules-hooks.md) — `preCreation`, `postCreation`, `creationError`
86
86
 
87
87
  ### Philosophy & Design
88
- - [rules-skill/philosophy.md](.ai/rules-skill/philosophy.md) — HoTT concepts (Univalence, Path Types, Higher Inductive Types) applied to mnemonica's self-reflection model
89
- - [rules-skill/ecosystem.md](.ai/rules-skill/ecosystem.md) — PACT framework: personas, collaboration modes, integration points
88
+ - [rules-philosophy.md](.ai/rules-philosophy.md) — HoTT concepts (Univalence, Path Types, Higher Inductive Types) applied to mnemonica's self-reflection model
89
+ - [rules-ecosystem.md](.ai/rules-ecosystem.md) — PACT framework: personas, collaboration modes, integration points
90
90
 
91
91
  ### Quality
92
- - [rules-skill/testing.md](.ai/rules-skill/testing.md) — 100% coverage, Mocha + Jest, error path patterns
93
- - [rules-skill/code-style.md](.ai/rules-skill/code-style.md) — tabs, spacing, type vs interface
94
- - [rules-skill/error-system.md](.ai/rules-skill/error-system.md) — `BASE_MNEMONICA_ERROR`, `constructError`, stack cleaning
92
+ - [rules-testing.md](.ai/rules-testing.md) — 100% coverage, Mocha + Jest, error path patterns
93
+ - [rules-code-style.md](.ai/rules-code-style.md) — tabs, spacing, type vs interface
94
+ - [rules-error-system.md](.ai/rules-error-system.md) — `BASE_MNEMONICA_ERROR`, `constructError`, stack cleaning
95
95
 
96
96
  ### Contributing
97
- - [rules-skill/contributing.md](.ai/rules-skill/contributing.md) — behavioral guidelines: think before coding, simplicity, surgical changes, goal-driven execution
97
+ - [rules-contributing.md](.ai/rules-contributing.md) — behavioral guidelines: think before coding, simplicity, surgical changes, goal-driven execution
98
98
 
99
99
  ## Contributing
100
100
 
@@ -5,6 +5,6 @@ export declare const hooks: {
5
5
  registerFlowChecker: (this: import("../types").Hookable, cb: () => unknown) => void;
6
6
  };
7
7
  export declare const types: {
8
- define: (this: unknown, subtypes: import("./types").TypesMap, TypeOrTypeName: string | CallableFunction, constructHandlerOrConfig?: CallableFunction | object, config?: object) => import("../types").TypeClass;
9
- lookup: (this: import("./types").TypesMap, TypeNestedPath: string) => import("../types").TypeClass | undefined;
8
+ define: (this: unknown, subtypes: import("./types").TypesMap, TypeOrTypeName: string | CallableFunction, constructHandlerOrConfig?: CallableFunction | object, config?: object) => import("..").TypeClass;
9
+ lookup: (this: import("./types").TypesMap, TypeNestedPath: string) => import("..").TypeClass | undefined;
10
10
  };