mnemonica 1.1.0 → 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 (49) 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 +62 -31
  17. package/FOR_HUMANS.md +20 -72
  18. package/README.md +23 -21
  19. package/SKILL.md +20 -20
  20. package/build/api/types/index.js +8 -3
  21. package/build/index.d.ts +9 -2
  22. package/build/index.js +17 -5
  23. package/build/types/index.d.ts +2 -0
  24. package/build/types/index.js +1 -1
  25. package/docs/ai-learning-trajectory.md +2 -3
  26. package/docs/decorate.md +123 -0
  27. package/docs/hott-primer.md +1 -1
  28. package/docs/purpose.md +3 -3
  29. package/{.ai/TACTICA-DEEP-DIVE.md → docs/tactica-deep-dive.md} +44 -1
  30. package/docs/tactica-pattern.md +1 -2
  31. package/docs/typed-lookup.md +170 -54
  32. package/package.json +1 -1
  33. package/src/api/types/index.ts +14 -4
  34. package/src/index.ts +84 -7
  35. package/src/types/index.ts +15 -0
  36. package/.ai/CODE.md +0 -111
  37. package/.ai/TACTICA-RULES.md +0 -103
  38. package/.ai/async_init.md +0 -94
  39. package/.ai/rules/REMINDERS.md +0 -63
  40. package/.ai/rules-skill/lookup-typed.md +0 -82
  41. package/.ai/rules-skill/proxy-architecture.md +0 -63
  42. package/.ai/task-templates/new-feature.md +0 -46
  43. /package/.ai/{rules-skill/code-style.md → rules-code-style.md} +0 -0
  44. /package/.ai/{rules-skill/define-patterns.md → rules-define-patterns.md} +0 -0
  45. /package/.ai/{rules-skill/ecosystem.md → rules-ecosystem.md} +0 -0
  46. /package/.ai/{rules-skill/error-system.md → rules-error-system.md} +0 -0
  47. /package/.ai/{rules-skill/hooks.md → rules-hooks.md} +0 -0
  48. /package/.ai/{rules-skill/philosophy.md → rules-philosophy.md} +0 -0
  49. /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)
@@ -136,12 +151,18 @@ Runtime behavior is identical whether `TypeRegistry` is augmented or not; the on
136
151
 
137
152
  ### Typed registry builders
138
153
 
139
- Mnemonica has two type-system paths for the same runtime API:
154
+ Mnemonica has three compile-time paths for the same runtime API:
140
155
 
141
- - **Builder mode** — chain `.define()` on the exported `mnemonica` object or on
156
+ - **Builder mode** (default) — chain `.define()` on the exported `mnemonica` object or on
142
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`).
143
162
  - **Augmented mode** — use free `define()`/`lookup()` or `@decorate()`, and let
144
- Tactica (or a hand-written file) populate the global `TypeRegistry`.
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.
145
166
 
146
167
  Public types involved:
147
168
 
@@ -149,6 +170,8 @@ Public types involved:
149
170
  - `MnemonicaModule<Registry>` — type of the exported `mnemonica` object.
150
171
  - `IDefinitorInstance<N, R, Registry, Path>` — type of constructors returned by
151
172
  `.define()`.
173
+ - `RegistryOf<T>` — extracts the accumulated `Registry` from any of the above,
174
+ for the bridge.
152
175
 
153
176
  Quick builder example:
154
177
 
@@ -168,11 +191,19 @@ const user = new User({ name: 'Ada' });
168
191
  const admin = new user.Admin({ role: 'root' });
169
192
  ```
170
193
 
171
- The free `define()`/`lookup()` exports still rely on `TypeRegistry`
172
- augmentation. The builder API is the preferred path when Tactica is not used.
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.
173
204
 
174
- For the full guide — relative `.define()` names, relative `lookup()` on
175
- constructors, `strictChain` notes, and `@decorate` limitations — see
205
+ For the full guide — multi-file threading, the bridge, two-arg overloads,
206
+ `strictChain` notes, and `@decorate` limitations — see
176
207
  [`docs/typed-lookup.md`](./docs/typed-lookup.md).
177
208
 
178
209
  ### Type System Structure
@@ -257,7 +288,7 @@ This applies to **all** `return` statements where the expression is anything oth
257
288
 
258
289
  ## TypeScript Type Rules
259
290
 
260
- **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.
261
292
 
262
293
  ## Preserving Design Comments and Memory Notes
263
294
 
@@ -275,7 +306,7 @@ If a comment becomes technically inaccurate after a change, update it rather tha
275
306
 
276
307
  ## Testing Requirements
277
308
 
278
- 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.
279
310
 
280
311
  ## Common Patterns
281
312
 
package/FOR_HUMANS.md CHANGED
@@ -57,7 +57,7 @@ Mnemonica has one runtime behavior, but TypeScript cannot see the type graph cre
57
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
58
  2. **Augmented mode** — use the free `define()` / `lookup()` exports and augment the global `TypeRegistry` by hand or with `@mnemonica/tactica`.
59
59
 
60
- At runtime these are identical. The only difference is where TypeScript looks up the types. See [`docs/typed-lookup.md`](./docs/typed-lookup.md) for details.
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
61
 
62
62
  ---
63
63
 
@@ -204,35 +204,12 @@ console.log(admin.role); // 'admin' (own property)
204
204
 
205
205
  ### Class-Based (TypeScript)
206
206
 
207
- Both styles are **equally supported**. The `@decorate()` decorator registers a class as a mnemonica type and works identically to `define()` at runtime:
208
-
209
- ```typescript
210
- import { decorate, apply } from 'mnemonica';
211
-
212
- // Define a type using a class
213
- @decorate()
214
- class UserType {
215
- name: string;
216
- email: string;
217
- constructor (data: { name: string; email: string }) {
218
- Object.assign(this, data);
219
- }
220
- }
221
-
222
- // Create an instance
223
- const user = new UserType({ name: 'John', email: 'john@example.com' });
224
-
225
- // Define a subtype
226
- @decorate(UserType)
227
- class AdminType {
228
- role: string = 'admin';
229
- }
230
-
231
- // Create a nested instance (inherits from user)
232
- const admin = new user.AdminType();
233
- console.log(admin.name); // 'John' (inherited)
234
- console.log(admin.role); // 'admin' (own property)
235
- ```
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.
236
213
 
237
214
  ### ESM
238
215
 
@@ -249,12 +226,12 @@ import { define, lookup } from 'mnemonica/module';
249
226
  | Change type | Read before starting |
250
227
  |---|---|
251
228
  | Any `src/` change | [`AGENTS.md`](./AGENTS.md) + [`.ai/ONBOARDING.md`](./.ai/ONBOARDING.md) |
252
- | Involves `define()` / type graph | + [`.ai/rules-skill/define-patterns.md`](./.ai/rules-skill/define-patterns.md) |
253
- | Involves hooks | + [`.ai/rules-skill/hooks.md`](./.ai/rules-skill/hooks.md) |
254
- | Involves async constructors | + [`.ai/rules-skill/async-constructors.md`](./.ai/rules-skill/async-constructors.md) + [`.ai/async_init.md`](./.ai/async_init.md) |
255
- | Involves TypeScript types | + [`.ai/rules-skill/type-system.md`](./.ai/rules-skill/type-system.md) |
256
- | Involves proxy internals | + [`.ai/rules-skill/proxy-architecture.md`](./.ai/rules-skill/proxy-architecture.md) |
257
- | 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) |
258
235
  | Docs-only change | README section you're touching only |
259
236
  | Unfamiliar with the codebase | [`.ai/ONBOARDING.md`](./.ai/ONBOARDING.md) first — one file, five minutes |
260
237
 
@@ -522,7 +499,7 @@ const AsyncTypeNoReturn = define('AsyncType', async function () {
522
499
  | Get parent instance | `utils.parent(instance)` or `utils.parent(instance, 'TypeName')` |
523
500
  | Flatten to plain object | `utils.extract(instance)` |
524
501
  | Add lifecycle hooks | `type.registerHook('postCreation', cb)` |
525
- | Use classes | `@decorate()` decorator |
502
+ | Use classes (requires Tactica) | see [`docs/decorate.md`](./docs/decorate.md) |
526
503
 
527
504
  ### Core Functions
528
505
 
@@ -607,49 +584,20 @@ const subInstance = createSub('arg1', 'arg2');
607
584
 
608
585
  #### `decorate(target?, config?)`
609
586
 
610
- 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.
611
591
 
612
592
  ```typescript
613
593
  import { decorate } from 'mnemonica';
614
594
 
615
- // Basic decoration
616
595
  @decorate()
617
596
  class MyClass {
618
597
  field: number = 123;
619
598
  }
620
-
621
- // Nested decoration (define as subtype)
622
- @decorate()
623
- class ParentClass {
624
- parentField: string = 'parent';
625
- }
626
-
627
- @decorate(ParentClass)
628
- class ChildClass {
629
- childField: string = 'child';
630
- }
631
-
632
- // Create parent instance, then child from it
633
- const parent = new ParentClass();
634
- const child = new parent.ChildClass();
635
599
  ```
636
600
 
637
- **With configuration:**
638
-
639
- ```typescript
640
- @decorate({ strictChain: false, blockErrors: true })
641
- class ConfiguredClass {
642
- field: number = 123;
643
- }
644
-
645
- @decorate(ParentClass, { strictChain: false })
646
- class ConfiguredChildClass {
647
- field: number = 123;
648
- }
649
- ```
650
-
651
- **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).
652
-
653
601
  #### `registerHook(Constructor, hookType, callback)`
654
602
 
655
603
  Registers a hook for a specific constructor.
@@ -673,7 +621,7 @@ For advanced TypeScript usage, the following types are exported from `mnemonica`
673
621
  | `IDEF<T>` | Base constructor function type | `define('Name', fn: IDEF<MyType>)` |
674
622
  | `MnemonicaInstance` | Optional helper interface | Can be used when attaching the legacy instance methods to your own prototype |
675
623
  | `TypeClass` | Base type constructor | `const MyType: TypeClass = define(...)` |
676
- | `DecoratedClass<T>` | Decorated class type | `@decorate() class MyClass {}` |
624
+ | `DecoratedClass<T>` | Decorated class type | `@decorate() class MyClass {}` (see [`docs/decorate.md`](./docs/decorate.md)) |
677
625
  | `IDefinitorInstance<N, S>` | Constructor with subtypes | Returned by `define()` with `.define()` method |
678
626
  | `ConstructorFunction<T>` | Constructor with prototype | Generic constructor function signature |
679
627
  | `constructorOptions` | Configuration options | `{ strictChain: true, blockErrors: true }` |
@@ -1142,7 +1090,7 @@ defaultTypes[SymbolConfig].blockErrors = false;
1142
1090
 
1143
1091
  ## Usage with TypeØmatica
1144
1092
 
1145
- 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).
1146
1094
 
1147
1095
  ```typescript
1148
1096
  import { BaseClass } from 'typeomatica';
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
 
@@ -32,12 +32,13 @@ Every instance carries its full history. That history is queryable at runtime wi
32
32
 
33
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
34
 
35
- TypeScript, however, cannot see the type graph created by runtime `define()` calls. To solve this, mnemonica offers two compile-time paths:
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
36
 
37
- 1. **Builder mode** — 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.
38
- 2. **Augmented mode** — use the free `define()` / `lookup()` exports and augment the global `TypeRegistry` by hand or with `@mnemonica/tactica`.
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.
39
40
 
40
- At runtime the two modes 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.
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.
41
42
 
42
43
  See [`docs/typed-lookup.md`](./docs/typed-lookup.md) for the full comparison and examples.
43
44
 
@@ -67,7 +68,7 @@ const engineer = new alice.Employee({ role: 'Engineer' });
67
68
  // ^^^^^ instance-level inheritance, not class-level
68
69
 
69
70
  engineer instanceof Person; // true — path back to root
70
- utils.parent(engineer); // returns alice (literal __proto__)
71
+ utils.parent(engineer); // returns alice — Object.getPrototypeOf(engineer) === alice
71
72
  getProps(engineer); // { __type__, __parent__, __args__, __timestamp__, ... }
72
73
  ```
73
74
 
@@ -140,18 +141,18 @@ These are the two assumptions that most reliably produce incorrect code.
140
141
  - **`utils.parent(instance, 'TypeName')`** — walks to a named ancestor in O(depth), no manual counting
141
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.
142
143
 
143
- 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.
144
145
 
145
146
  **2. "`Person.define('Employee')` is `class Employee extends Person`."** It isn't. The difference is where `new` goes:
146
147
 
147
148
  ```typescript
148
149
  // Class-level (NOT mnemonica):
149
150
  const engineer = new Employee({ role: 'Engineer' });
150
- // engineer.__proto__ === Employee.prototype — shared across all employees
151
+ // Object.getPrototypeOf(engineer) === Employee.prototype — shared across all employees
151
152
 
152
153
  // Instance-level (mnemonica):
153
154
  const engineer = new alice.Employee({ role: 'Engineer' });
154
- // engineer.__proto__ === alice — private to this specific alice
155
+ // Object.getPrototypeOf(engineer) === alice — private to this specific alice
155
156
  ```
156
157
 
157
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.
@@ -184,7 +185,7 @@ These restrictions are not arbitrary. They are runtime enforcement of the identi
184
185
  ```typescript
185
186
  const user = new UserType({ name: 'Alice' });
186
187
  const admin = new user.AdminType({ role: 'admin' });
187
- // admin.__proto__ === user
188
+ // Object.getPrototypeOf(admin) === user
188
189
  // admin instanceof UserType → true (path back to root)
189
190
  // admin instanceof AdminType → true
190
191
  ```
@@ -210,7 +211,7 @@ These terms are used throughout the codebase and documentation with precise mean
210
211
  | **ModificatorType** | The actual constructor function used for `new` calls. Its prototype is linked to Mnemosyne, which is linked to the parent instance. |
211
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. |
212
213
 
213
- 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).
214
215
 
215
216
  ---
216
217
 
@@ -423,7 +424,7 @@ new instance.SubType(args)
423
424
 
424
425
  See [`src/api/types/InstanceCreator.ts`](./src/api/types/InstanceCreator.ts) and [`src/api/types/TypeProxy.ts`](./src/api/types/TypeProxy.ts).
425
426
 
426
- 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).
427
428
 
428
429
  ### Type system primitives (TypeScript)
429
430
 
@@ -468,22 +469,23 @@ Everything below ships with this package.
468
469
  2. [`FOR_HUMANS.md`](./FOR_HUMANS.md) — gentler, example-heavy walkthrough for human developers
469
470
  3. [`SKILL.md`](./SKILL.md) — quick reference for usage patterns
470
471
  4. [`docs/prototype-chain.md`](./docs/prototype-chain.md) — how mnemonica builds the per-instance prototype chain and why the layers exist
471
- 5. [`docs/typed-lookup.md`](./docs/typed-lookup.md) — using `lookup()` with or without tactica (the `TypeRegistry` augmentation pattern)
472
- 5. [`docs/hott-primer.md`](./docs/hott-primer.md) — HoTT concepts mapped to mnemonica (monad, path types, univalence, HITs, fibrations)
473
- 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
474
477
 
475
478
  **For *modifying* mnemonica** (when you touch `src/`):
476
479
 
477
480
  1. [`AGENTS.md`](./AGENTS.md) — Rule #1, change-type reading guide, code style, editing rules
478
481
  2. [`.ai/ONBOARDING.md`](./.ai/ONBOARDING.md) — five-minute editor onboarding
479
482
  3. [`CONTRIBUTING.md`](./CONTRIBUTING.md) — local workflow, branching, release process
480
- 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
481
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
482
- 6. [`.ai/CODE.md`](./.ai/CODE.md), [`.ai/ARCHITECT.md`](./.ai/ARCHITECT.md), [`.ai/DEBUG.md`](./.ai/DEBUG.md) — role-specific deeper rules
483
- 6. [`.ai/TACTICA-DEEP-DIVE.md`](./.ai/TACTICA-DEEP-DIVE.md) — deeper tactica integration patterns
484
- 7. [`.ai/async_init.md`](./.ai/async_init.md) — async constructor patterns
485
- 8. [`.ai/rules-skill/`](./.ai/rules-skill/) — granular rules for type system, hooks, code style, errors, testing
486
- 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
487
489
 
488
490
  The full TypeScript source is in [`src/`](./src/) (on GitHub; the npm package ships compiled output in `build/` and `module/`).
489
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