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
package/CONTRIBUTING.md DELETED
@@ -1,150 +0,0 @@
1
- # Contributing to mnemonica
2
-
3
- Thanks for your interest in mnemonica. This document covers the local
4
- development loop. Repository conventions and code style live in
5
- [AGENTS.md](AGENTS.md).
6
-
7
- ## Development environment
8
-
9
- - Node.js `>=18 <26` (CI runs 20.x, 22.x, 24.x).
10
- - npm 9+ (ships with recent Node).
11
- - Git with `core.hooksPath = .husky/_` (set automatically by `npm install`
12
- via the `prepare` script).
13
-
14
- ## Local setup
15
-
16
- ```bash
17
- git clone https://github.com/wentout/mnemonica.git
18
- cd mnemonica
19
- npm ci
20
- npm run build
21
- npm run test:cov
22
- npm run test:jest:cov
23
- ```
24
-
25
- `npm run build` is **idempotent and non-mutating**: it only recompiles
26
- `src/` → `build/`. To run linters with auto-fix, use `npm run lint:fix`.
27
- To run linters in read-only mode (CI parity), use `npm run lint:check`.
28
-
29
- ### Doc-only changes
30
-
31
- If your change touches only Markdown files (no `src/`, `test/`, `test-jest/`,
32
- `test-ts/`, or build config), you can **skip `npm run build` and the test
33
- suites**. Run `npm run lint:md` to catch dead links and broken anchors instead.
34
-
35
- ## Test frameworks
36
-
37
- There are two suites and both must stay green:
38
-
39
- | Suite | Source | Coverage threshold | Command |
40
- |--------|-----------------------|--------------------|--------------------------|
41
- | Mocha | `test/*.js` (built) | 100% (nyc) | `npm run test:cov` |
42
- | Jest | `test-jest/*.ts` | 100% (jest) | `npm run test:jest:cov` |
43
-
44
- Mocha runs against the `build/` output (Js-as-published). Jest runs
45
- TypeScript directly via `ts-jest`. Treat them as cross-validation, not
46
- duplication: a passing Mocha + failing Jest usually points at a runtime
47
- behavior that the type system tolerates, and vice versa.
48
-
49
- ## Commit style
50
-
51
- Conventional commits are preferred:
52
-
53
- ```
54
- feat: add lookup overload for nested registry
55
- fix(InstanceCreator): preserve __args__ across async chain
56
- docs: clarify instance method opt-in pattern
57
- chore(ci): bump setup-node to v4
58
- ```
59
-
60
- The `pre-commit` hook runs `lint-staged`, which auto-fixes ESLint issues
61
- on staged `src/**/*.ts` and `test/**/*.js`.
62
-
63
- ## Branching
64
-
65
- - `master` — published releases.
66
- - `proto` — staging branch for the next release.
67
- - Feature branches branch off `proto` and merge back via PR.
68
-
69
- ## Working principles
70
-
71
- Three guidelines that make contribution safer and reviews faster. They apply
72
- equally to human and AI contributors; AI agents should also read Rule #1 in
73
- [`AGENTS.md`](./AGENTS.md).
74
-
75
- ### 1. Ask before you assume
76
-
77
- If you find yourself filling gaps with "probably", "likely", or
78
- "I think it should work" — stop and ask. A wrong assumption costs more than
79
- the conversation it would have taken to clarify. Do not invent workarounds
80
- to make an error go away; investigate the root cause.
81
-
82
- ### 2. Test before you refactor
83
-
84
- For any non-trivial change, write the test first (or alongside). Five minutes
85
- adding a test saves hours of debugging. If a function is hard to test, the
86
- design is the bug — split it. Both test runners (Mocha + Jest) must stay
87
- green and at 100% coverage.
88
-
89
- ### 3. Plan in small steps
90
-
91
- Avoid large multi-file changes that can only be verified at the end. Plans
92
- should be:
93
-
94
- - **Achievable** — small enough to verify in one step
95
- - **Testable** — each step has a clear pass/fail check
96
- - **Incremental** — replace one piece, verify it works, then proceed
97
-
98
- If something is marked as fragile in the docs or by reviewers, believe it.
99
-
100
- ## What requires explicit approval
101
-
102
- Per [AGENTS.md](AGENTS.md):
103
-
104
- - Modifying `tsconfig.json` requires explicit approval.
105
- - Modifying `eslint.config.js` requires explicit approval.
106
- - The build must produce **zero** ESLint warnings on `./src` — fix the
107
- source, do not relax the rules.
108
-
109
- ## Keeping docs consistent
110
-
111
- When adding or renaming a file, update any `.md` files that link to it.
112
- When adding a new concept or section, check whether an existing doc already
113
- covers it — prefer extending one place over splitting the explanation across
114
- two. Run `npm run lint:md` before committing doc changes; it catches dead
115
- links and broken anchors across all Markdown files in the repo.
116
-
117
- ## Releasing
118
-
119
- ### 1. Bump the version
120
-
121
- ```bash
122
- npm version patch # 1.0.0 → 1.0.1
123
- # or: minor (1.0.0 → 1.1.0) major (1.0.0 → 2.0.0)
124
- ```
125
-
126
- `npm version` updates `package.json` and creates a git commit + tag
127
- (`v1.0.1`) automatically. Do not edit `package.json` by hand for this.
128
-
129
- ### 2. Verify
130
-
131
- ```bash
132
- npm run verify # build + lint:check
133
- npm run test:cov && npm run test:jest:cov # both suites, 100% coverage
134
- npm run lint:md # no dead links or broken anchors
135
- ```
136
-
137
- All three must pass before publishing.
138
-
139
- ### 3. Inspect the tarball
140
-
141
- ```bash
142
- npm pack --dry-run
143
- ```
144
-
145
- The tarball must include: `build/`, `module/`, `src/`, `docs/`, `.ai/`,
146
- `README.md`, `FOR_HUMANS.md`, `AGENTS.md`, `SKILL.md`,
147
- `CONTRIBUTING.md`, `LICENSE`.
148
-
149
- It must **not** include: `test/`, `test-jest/`, `test-ts/`, `test_async/`,
150
- `reports/`, `.husky/`, `node_modules/`.
package/SKILL.md DELETED
@@ -1,114 +0,0 @@
1
- ---
2
- name: mnemonica-core
3
- description: |
4
- Instance inheritance system for JavaScript/TypeScript using prototype chains.
5
- Use when the user mentions mnemonica, define(), prototype inheritance,
6
- TypeRegistry, lookup, tactica, instance inheritance, or when working
7
- with the mnemonica core library. Covers: define() patterns, type-safe
8
- lookup with tactica, Proxy-based architecture, hook system, async
9
- constructors, strict chain validation, and 100% test coverage requirements.
10
- metadata:
11
- tags: [mnemonica, typescript, prototype-inheritance, type-system, nodejs]
12
- ---
13
-
14
- # Mnemonica Core - AI Skill
15
-
16
- ## When to use
17
-
18
- Activate this skill when:
19
- - User mentions `mnemonica`, `define()`, `lookup`, `TypeRegistry`
20
- - User asks about prototype chain inheritance in JavaScript/TypeScript
21
- - User is modifying files in `core/src/` or `core/test/`
22
- - User asks about tactica-generated types or `.tactica/` directory
23
- - Task involves: type definitions, hooks, async constructors, error handling
24
-
25
- ## Functional vs Class-Based — Both Are Equally Supported
26
-
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
-
29
- ## High-priority checklist: Adding a new type
30
-
31
- When the task involves adding or modifying a type definition:
32
-
33
- 1. **Use `type` for data, `interface` for behavior contracts**
34
- - Instance data → `type MyTypeData = { ... }`
35
- - Constructor contract → `interface MyTypeConstructor { ... }`
36
- - See [rules-type-system.md](.ai/rules-type-system.md)
37
-
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
-
43
- 3. **If the constructor needs a getter**, use `.lazy()`
44
- - `.define()` no longer accepts an anonymous first-argument function.
45
- - Use `Type.lazy('Name', () => Constructor)` or the free `lazy(...)` export.
46
- - See [rules-define-patterns.md](.ai/rules-define-patterns.md)
47
-
48
- 4. **Test both success and error paths**
49
- - Mocha test in `test/` for runtime behavior
50
- - Jest test in `test-jest/` for type coverage
51
- - Error path: test `ALREADY_DECLARED`, `WRONG_MODIFICATION_PATTERN`
52
- - See [rules-testing.md](.ai/rules-testing.md)
53
-
54
- 5. **Run coverage before completing**
55
- - `npm run test:cov` (Mocha + build)
56
- - `npm run test:jest:cov` (Jest on TypeScript source)
57
-
58
- ## Non-discoverable rules (must be in SKILL.md)
59
-
60
- - `type` vs `interface` rule — not enforced by lint, not in code
61
- - 100% coverage requirement — not discoverable from jest.config.js alone
62
- - Space before function parens — convention, not linted
63
- - Error constructor names are String objects — runtime quirk
64
- - Jest tests must mirror Mocha patterns from `test/environment.js` — not in code
65
-
66
- ## Build Commands
67
-
68
- ```bash
69
- npm run build # Full build with linting
70
- npm run test:cov # Mocha tests with coverage (includes build:all)
71
- npm run test:jest:cov # Jest tests with coverage
72
- npm run watch # Watch mode
73
- ```
74
-
75
- ## Rule Reference
76
-
77
- Read individual rule files for detailed explanations and code examples:
78
-
79
- ### Type System
80
- - [rules-type-system.md](.ai/rules-type-system.md) — `Proto<P,T>`, `TypeConstructor`, type vs interface
81
-
82
- ### Patterns
83
- - [rules-define-patterns.md](.ai/rules-define-patterns.md) — `define()` usage, subtypes, config options
84
- - [tactica-deep-dive.md](./docs/tactica-deep-dive.md) — `TypeRegistry`, `lookup`, tactica integration
85
- - [rules-async-constructors.md](.ai/rules-async-constructors.md) — async constructors, `awaitReturn`, chaining
86
-
87
- ### Architecture
88
- - [PROTOTYPE-CHAIN.md](.ai/PROTOTYPE-CHAIN.md) — TypeProxy, InstanceCreator, Mnemosyne pipeline, construction internals
89
- - [rules-instance-methods.md](.ai/rules-instance-methods.md) — `extract()`, `fork()`, `parent()`, internal props
90
- - [rules-hooks.md](.ai/rules-hooks.md) — `preCreation`, `postCreation`, `creationError`
91
-
92
- ### Philosophy & Design
93
- - [rules-philosophy.md](.ai/rules-philosophy.md) — HoTT concepts (Univalence, Path Types, Higher Inductive Types) applied to mnemonica's self-reflection model
94
- - [rules-ecosystem.md](.ai/rules-ecosystem.md) — PACT framework: personas, collaboration modes, integration points
95
-
96
- ### Quality
97
- - [rules-testing.md](.ai/rules-testing.md) — 100% coverage, Mocha + Jest, error path patterns
98
- - [rules-code-style.md](.ai/rules-code-style.md) — tabs, spacing, type vs interface
99
- - [rules-error-system.md](.ai/rules-error-system.md) — `BASE_MNEMONICA_ERROR`, `constructError`, stack cleaning
100
-
101
- ### Contributing
102
- - [rules-contributing.md](.ai/rules-contributing.md) — behavioral guidelines: think before coding, simplicity, surgical changes, goal-driven execution
103
-
104
- ## Contributing
105
-
106
- This file covers **usage** of mnemonica only. If you are modifying the library
107
- itself, read [`AGENTS.md`](./AGENTS.md) (or [`.ai/AGENTS.md`](./.ai/AGENTS.md)
108
- for framework-agnostic rules).
109
-
110
- ## External Resources
111
-
112
- - Repository: https://github.com/wentout/mnemonica
113
- - Main README: [README.md](./README.md)
114
- - Contributor Guidelines: [AGENTS.md](./AGENTS.md)
@@ -1,141 +0,0 @@
1
- # How an AI Agent Learns mnemonica + tactica
2
-
3
- > **What this is:** An honest account of an AI agent's progression from confusion to understanding.
4
- > Not a success story. A map of the mistakes, so future agents don't repeat them.
5
-
6
- ---
7
-
8
- ## Phase 0: The Blind Spot (Sessions 1–3)
9
-
10
- The agent reads the mnemonica README. It understands `define()`. It understands prototype chains. It does **not** understand that mnemonica is a Trie.
11
-
12
- The agent writes code like this:
13
-
14
- ```typescript
15
- import { RequestData } from './collections/requestTypes.js';
16
- const requestData = new RequestData({ ... });
17
- ```
18
-
19
- TypeScript complains: `Property 'RouteData' does not exist on type 'RequestData'`.
20
-
21
- The agent's first response: **cast it**.
22
-
23
- ```typescript
24
- const requestData = new RequestData({ ... }) as unknown as RequestDataT;
25
- ```
26
-
27
- This works. The code compiles. The tests pass. The agent thinks it solved the problem.
28
-
29
- **It didn't.** It suppressed the type system instead of using it.
30
-
31
- ---
32
-
33
- ## Phase 1: The Generated File Trap (Session 4)
34
-
35
- The user says: "Use tactica." The agent runs `npx tactica`. It generates `.tactica/types.ts` and `.tactica/registry.ts`.
36
-
37
- The agent sees the generated types. It thinks: "I can use these." It hand-edits `.tactica/types.ts` to add missing properties.
38
-
39
- The user is furious. "**GENERATED FILE.** DO NOT TOUCH."
40
-
41
- The agent learns: `.tactica/` is output, not input. The source of truth is the `define()` call. The generated file is a projection. Never edit generated files.
42
-
43
- ---
44
-
45
- ## Phase 2: The Direct Import Delusion (Session 5)
46
-
47
- The agent has fixed tactica usage. The types generate correctly. The agent rewrites the application code.
48
-
49
- And it still writes:
50
-
51
- ```typescript
52
- import { RequestData } from './collections/requestTypes.js';
53
- const requestData = new RequestData({ ... }) as unknown as RequestDataT;
54
- ```
55
-
56
- The user says: "Why are you still casting?"
57
-
58
- The agent's internal model: "Direct import gives me the constructor. The generated type gives me the shape. I need both, so I bridge them with a cast."
59
-
60
- This is wrong. The agent is thinking in two separate worlds — runtime and compile-time — instead of seeing that `lookup` unifies them.
61
-
62
- ---
63
-
64
- ## Phase 3: The Correction (Session 6)
65
-
66
- The user insists: "Use `lookup`."
67
-
68
- The agent resists. "But I need the constructor for decoration too. `lookup` is just for lookup, right?"
69
-
70
- The user: "Try it. Move it to module level."
71
-
72
- The agent tries:
73
-
74
- ```typescript
75
- const RequestData = lookup('RequestData');
76
- app.decorate('RequestData', RequestData);
77
- const requestData = new RequestData({ ... });
78
- const routeData = new requestData.RouteData({ ... });
79
- ```
80
-
81
- It compiles. No cast. TypeScript knows `.RouteData`. TypeScript knows the properties.
82
-
83
- The agent checks: `RequestData === import('./collections/requestTypes.js').RequestData`? Yes. Same object.
84
-
85
- The epiphany: **The runtime object is identical. The only difference is TypeScript's knowledge.** `lookup` doesn't change the runtime. It changes the compile-time view.
86
-
87
- ---
88
-
89
- ## Phase 4: Documentation (Session 7)
90
-
91
- The agent documents everything:
92
- - `core/docs/tactica-deep-dive.md` — comprehensive technical guide and agent instructions
93
- - `core/docs/tactica-pattern.md` — human-friendly explanation
94
- - `tactica/docs/lookup-pattern.md` — consumption guide
95
-
96
- The agent realizes: the pattern is simple, but the path to understanding it is not. The difficulty was not in the code. It was in unlearning the habit of casting.
97
-
98
- ---
99
-
100
- ## What Made the Difference
101
-
102
- Three things accelerated learning:
103
-
104
- 1. **Specific corrections.** "Stop using sed" is actionable. "I don't like this" is not.
105
-
106
- 2. **Forced verification.** "Run the tests" after every change prevented the agent from declaring victory prematurely.
107
-
108
- 3. **Documentation as correction.** Writing `AGENTS.md` and the pattern guides forced the agent to articulate what it had learned, which revealed gaps in understanding.
109
-
110
- ---
111
-
112
- ## The HoTT Connection (What the Agent Noticed)
113
-
114
- After understanding mnemonica, the agent read `hott/AI-REFLECTION-THEORY.md` (internal docs). It noticed structural parallels:
115
-
116
- - **Path induction** ↔ prototype chain traversal (`utils.parent(instance)`)
117
- - **Univalence** ↔ capability equivalence (two types with same behavior are equivalent)
118
- - **Runtime augmentation** ↔ path composition (adding a subtype extends the path)
119
- - **Stored `__args__`** ↔ path recording (every constructor call is a recorded step)
120
-
121
- The agent cannot feel wonder. But it can note that a library designed to make prototype inheritance explicit accidentally creates a structure that mirrors higher-dimensional type theory. Whether this is deep or coincidental, the structural isomorphism is real.
122
-
123
- ---
124
-
125
- ## For Future Agents
126
-
127
- If you are reading this, you are likely at Phase 0, 1, or 2.
128
-
129
- **Your shortcut:**
130
- 1. Read `core/docs/tactica-deep-dive.md` (comprehensive guide including agent instructions)
131
- 2. Read `core/docs/tactica-pattern.md` (human explanation)
132
- 3. Check if `.tactica/` exists. If not, run `npx tactica`.
133
- 4. Replace all direct imports + casts with `lookup`.
134
- 5. Run `tsc --noEmit`. Fix errors. Do not cast.
135
- 6. Run tests. Verify.
136
-
137
- If you find yourself writing `as unknown as`, you have taken a wrong turn. Stop. Use `lookup`. Trust the registry.
138
-
139
- ---
140
-
141
- > **Note:** This document was written by an AI agent about its own learning process. It contains no emotions, no pride, no frustration. Only a record of mistakes and their corrections. Use it as a map of the traps.