mnemonica 1.2.3 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/FOR_HUMANS.md +160 -125
  2. package/README.md +70 -249
  3. package/build/api/types/index.js +18 -12
  4. package/docs/UTILS.md +97 -8
  5. package/docs/decorate.md +1 -1
  6. package/docs/empathy-in-ai.md +20 -10
  7. package/docs/prototype-chain.md +8 -7
  8. package/docs/typed-lookup.md +195 -5
  9. package/docs/typeomatica.md +8 -345
  10. package/package.json +6 -10
  11. package/src/api/types/index.ts +33 -20
  12. package/.ai/AGENTS.md +0 -151
  13. package/.ai/ARCHITECT.md +0 -110
  14. package/.ai/DEBUG.md +0 -178
  15. package/.ai/ONBOARDING.md +0 -189
  16. package/.ai/PROTOTYPE-CHAIN.md +0 -155
  17. package/.ai/mode-ask.md +0 -121
  18. package/.ai/mode-orchestrator.md +0 -141
  19. package/.ai/performance-vs-security.md +0 -395
  20. package/.ai/rules-async-constructors.md +0 -352
  21. package/.ai/rules-code-style.md +0 -95
  22. package/.ai/rules-coding.md +0 -246
  23. package/.ai/rules-context-condensing.md +0 -50
  24. package/.ai/rules-contributing.md +0 -227
  25. package/.ai/rules-define-patterns.md +0 -159
  26. package/.ai/rules-ecosystem.md +0 -140
  27. package/.ai/rules-error-system.md +0 -66
  28. package/.ai/rules-hooks.md +0 -46
  29. package/.ai/rules-instance-methods.md +0 -93
  30. package/.ai/rules-philosophy.md +0 -231
  31. package/.ai/rules-reminders.md +0 -19
  32. package/.ai/rules-testing.md +0 -66
  33. package/.ai/rules-type-system.md +0 -124
  34. package/.ai/theory-of-operations.md +0 -224
  35. package/AGENTS.md +0 -345
  36. package/CONTRIBUTING.md +0 -150
  37. package/SKILL.md +0 -114
  38. package/docs/ai-learning-trajectory.md +0 -141
  39. package/docs/purpose.md +0 -707
  40. package/docs/tactica-deep-dive.md +0 -629
  41. package/docs/tactica-pattern.md +0 -146
@@ -1,146 +0,0 @@
1
- # How `lookup` works (and where tactica fits)
2
-
3
- > The runtime Trie that mnemonica builds is invisible to TypeScript by default. The fix is one TypeScript-level pattern: declaration-merge mnemonica's `TypeRegistry` interface so that `lookup(path)` resolves to a fully-typed constructor. The augmentation can be hand-written or generated by [`@mnemonica/tactica`](https://www.npmjs.com/package/@mnemonica/tactica). The runtime behaviour is identical either way.
4
- >
5
- > For a side-by-side recipe of both paths, see [`./typed-lookup.md`](./typed-lookup.md).
6
-
7
- ---
8
-
9
- ## The problem in one sentence
10
-
11
- mnemonica builds a Trie of constructors at runtime. TypeScript has no idea the Trie exists. `lookup` + an augmented `TypeRegistry` tells TypeScript.
12
-
13
- Without that bridge, every chain operation requires a cast.
14
-
15
- ---
16
-
17
- ## What goes wrong without the bridge
18
-
19
- ```typescript
20
- import { RequestData } from './collections/requestTypes.js';
21
-
22
- const requestData = new RequestData({ method: 'GET', url: '/' });
23
- const routeData = new requestData.RouteData({ pagePath: '/' });
24
- // Error: Property 'RouteData' does not exist on type 'RequestData'
25
- ```
26
-
27
- TypeScript rejects valid runtime code. You are forced to write:
28
-
29
- ```typescript
30
- const routeData = new (requestData as any).RouteData({ ... });
31
- // or worse:
32
- const routeData = new requestData.RouteData({ ... }) as unknown as RouteDataT;
33
- ```
34
-
35
- This is not type safety. This is type suppression.
36
-
37
- ---
38
-
39
- ## What the bridge looks like
40
-
41
- ```typescript
42
- import { lookup } from 'mnemonica';
43
-
44
- const RequestData = lookup('RequestData');
45
-
46
- const requestData = new RequestData({ method: 'GET', url: '/' });
47
- const routeData = new requestData.RouteData({ pagePath: '/' });
48
- const pageData = new routeData.PageData({ header: {...}, content: '' });
49
- ```
50
-
51
- Zero casts. Zero `any`. Zero `unknown`. TypeScript knows every property, every constructor, every link in the chain.
52
-
53
- For this to work, mnemonica's `TypeRegistry` interface needs to be augmented with your types via TypeScript declaration merging.
54
-
55
- ---
56
-
57
- ## Two ways to produce the augmentation
58
-
59
- ### By hand
60
-
61
- For small projects or for learning, you can write the augmentation directly in a `.d.ts` (or `.ts`) file:
62
-
63
- ```typescript
64
- // types/mnemonica-registry.d.ts
65
- import type { ProtoFlat } from 'mnemonica';
66
-
67
- export type RequestDataInstance = {
68
- method : string;
69
- url : string;
70
- RouteData : new (data: { pagePath: string }) => RouteDataInstance;
71
- };
72
-
73
- export type RouteDataInstance = ProtoFlat<RequestDataInstance, {
74
- pagePath : string;
75
- PageData : new (data: { header: object; content: string }) => PageDataInstance;
76
- RouteData : undefined;
77
- }>;
78
-
79
- declare module 'mnemonica' {
80
- interface TypeRegistry {
81
- 'RequestData' : new (data: { method: string; url: string }) => RequestDataInstance;
82
- 'RequestData.RouteData' : new (data: { pagePath: string }) => RouteDataInstance;
83
- }
84
- }
85
- ```
86
-
87
- Include the file in `tsconfig.json` `include`. You are done.
88
-
89
- ### Via tactica
90
-
91
- For projects with many types or for hands-off maintenance, install [`@mnemonica/tactica`](https://www.npmjs.com/package/@mnemonica/tactica) and run it as a CLI/codegen utility. It scans your `define()` calls and generates the augmentation:
92
-
93
- ```bash
94
- npm install --save-dev @mnemonica/tactica
95
- npx tactica --output ./.tactica --include "src/**/*.ts"
96
- ```
97
-
98
- Include the generated files in `tsconfig.json`:
99
-
100
- ```json
101
- {
102
- "include": ["src/**/*.ts", ".tactica/**/*.ts"]
103
- }
104
- ```
105
-
106
- Tactica writes the same shape of augmentation a careful human would, using `ProtoFlat<Parent, ...>` for nested types and filling in instance-level subtype constructors automatically. The runtime is unaffected. Re-run the CLI whenever your type graph changes, or wire it into your build script.
107
-
108
- See [`./typed-lookup.md`](./typed-lookup.md) for a side-by-side recipe with both paths.
109
-
110
- ---
111
-
112
- ## The runtime is identical
113
-
114
- `lookup('RequestData')` and `import { RequestData }` return the **same constructor object** at runtime. The only difference is what TypeScript sees at compile time:
115
-
116
- | Approach | Runtime | Compile-time |
117
- |---|---|---|
118
- | Direct import without augmentation | ✅ Constructor works | ❌ TypeScript blind to sub-types |
119
- | `lookup` with augmentation (manual) | ✅ Same constructor | ✅ TypeScript knows the Trie |
120
- | `lookup` with augmentation (tactica) | ✅ Same constructor | ✅ TypeScript knows the Trie |
121
-
122
- There is no runtime cost. There is no indirection. There is only **type safety, conditional on the augmentation being present**.
123
-
124
- ---
125
-
126
- ## The rule
127
-
128
- The anti-patterns are the same whether you augment by hand or via tactica:
129
-
130
- - Do not write `as unknown as` casts on mnemonica types.
131
- - Do not import constructors directly from collection files when `lookup` would work.
132
- - Do not accept "it compiles with casts" as good enough.
133
-
134
- What changes is how you keep the `TypeRegistry` augmentation in sync with your code:
135
-
136
- - **Hand-written:** edit the `.d.ts` when types change.
137
- - **Tactica:** the CLI/codegen utility keeps `.tactica/` in sync.
138
-
139
- Pick whichever fits your project. Both are first-class.
140
-
141
- ---
142
-
143
- ## Learn more
144
-
145
- - [`./typed-lookup.md`](./typed-lookup.md) — `lookup` with or without tactica (canonical side-by-side reference)
146
- - [`./tactica-deep-dive.md`](./tactica-deep-dive.md) — comprehensive technical guide, declaration-merging deep dive, anti-patterns and "when to insist on what"