mnemonica 1.2.7 → 1.2.9
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.
- package/README.md +13 -3
- package/docs/hott-correspondence.md +186 -0
- package/docs/tooling.md +50 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -259,7 +259,7 @@ This is not pseudocode — it is a working pattern for production HTTP request h
|
|
|
259
259
|
|
|
260
260
|
You don't need to know Homotopy Type Theory to use mnemonica. You do need it to appreciate *why* the design is what it is. Five concepts matter here — the monad laws, path uniqueness, and the Trie structure have precise correspondences; univalence, HITs, synthetic topology, and fibrations are productive analogies.
|
|
261
261
|
|
|
262
|
-
**The short version:** Mnemonica is **inspired by** HoTT, not a formal implementation of it. The Trie behaves monadically; the prototype chain IS the identity-path; nominal typing captures the univalence intuition. See [`docs/hott-primer.md`](./docs/hott-primer.md) for the full treatment with formal definitions and status table.
|
|
262
|
+
**The short version:** Mnemonica is **inspired by** HoTT, not a formal implementation of it. The Trie behaves monadically; the prototype chain IS the identity-path; nominal typing captures the univalence intuition. See [`docs/hott-primer.md`](./docs/hott-primer.md) for the full treatment with formal definitions and status table, and [`docs/hott-correspondence.md`](./docs/hott-correspondence.md) for the citable version with CI-verified witnesses.
|
|
263
263
|
|
|
264
264
|
---
|
|
265
265
|
|
|
@@ -294,7 +294,9 @@ The full API reference — every signature, config option, hook data shape, the
|
|
|
294
294
|
| What the prototype chain under your instance looks like | [`docs/prototype-chain.md`](./docs/prototype-chain.md) |
|
|
295
295
|
| Runtime field enforcement with typeomatica | [`docs/typeomatica.md`](./docs/typeomatica.md) |
|
|
296
296
|
| HoTT framing, with an honesty table | [`docs/hott-primer.md`](./docs/hott-primer.md) |
|
|
297
|
+
| HoTT correspondence, citable and CI-verified | [`docs/hott-correspondence.md`](./docs/hott-correspondence.md) |
|
|
297
298
|
| Why lineage is infrastructure for empathetic AI | [`docs/empathy-in-ai.md`](./docs/empathy-in-ai.md) |
|
|
299
|
+
| The toolchain around the library: tracing, live-craft, test debugging | [`docs/tooling.md`](./docs/tooling.md) |
|
|
298
300
|
|
|
299
301
|
How construction flows, in one line:
|
|
300
302
|
|
|
@@ -313,8 +315,9 @@ The object carries none of the internal props as own properties — they live in
|
|
|
313
315
|
- **[`typeomatica`](https://www.npmjs.com/package/typeomatica)** — Runtime field-type enforcement via Proxy, with the `@Strict` decorator. See [`docs/typeomatica.md`](./docs/typeomatica.md).
|
|
314
316
|
- **[`@mnemonica/dive`](https://www.npmjs.com/package/@mnemonica/dive)** — Execution-flow tracing: a palette of wrappers that let you see which request/flow a failure belongs to, without AsyncLocalStorage.
|
|
315
317
|
- **[`@mnemonica/topologica`](https://www.npmjs.com/package/@mnemonica/topologica)** — Module loader that self-defines directory trees of mnemonica types.
|
|
316
|
-
- **nestjs-adapter** — NestJS integration (dive-powered flow tracing across DI boundaries); in active development.
|
|
317
|
-
- **mnemographica** — VS Code extension
|
|
318
|
+
- **nestjs-adapter** (`@mnemonica/nestjs`) — NestJS integration (dive-powered flow tracing across DI boundaries, OTel/Jaeger spans); in active development.
|
|
319
|
+
- **mnemographica** — VS Code extension: `.tactica` tree views with go-to-definition, an interactive 3D type graph, and a Live Trace sidebar fed by a running app; in active development.
|
|
320
|
+
- **strategy** (`@mnemonica/strategy`) — the live bridge to a running application: trace streaming plus live-craft (define/swap constructors without a restart); in active development. See [`docs/tooling.md`](./docs/tooling.md).
|
|
318
321
|
|
|
319
322
|
---
|
|
320
323
|
|
|
@@ -327,8 +330,15 @@ npm run build # tsc only — lint is a separate gate
|
|
|
327
330
|
npx eslint ./src # zero warnings allowed
|
|
328
331
|
npm run test:cov # Mocha on built JS (100% coverage required)
|
|
329
332
|
npm run test:jest:cov # Jest on TS source (100% coverage required)
|
|
333
|
+
npm run debug # step through the mocha suite under CDP (chrome://inspect)
|
|
330
334
|
```
|
|
331
335
|
|
|
336
|
+
Walking the test suite under a debugger is the fastest honest tour of the
|
|
337
|
+
internals — every `return` in `src/` goes through an intermediate variable
|
|
338
|
+
exactly so you can hover it at a breakpoint. See
|
|
339
|
+
[`docs/tooling.md`](./docs/tooling.md) for this and the rest of the
|
|
340
|
+
surrounding toolchain.
|
|
341
|
+
|
|
332
342
|
`tsconfig.json` and `eslint.config.js` are off-limits without explicit user approval.
|
|
333
343
|
|
|
334
344
|
---
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Identity as Path — Mnemonica's Correspondence with Homotopy Type Theory
|
|
2
|
+
|
|
3
|
+
A citable statement of what mnemonica borrows from Homotopy Type Theory (HoTT),
|
|
4
|
+
what it does not, and where each claim is verified in code.
|
|
5
|
+
|
|
6
|
+
**Audience:** reviewers who want to check the claims, not take them on faith.
|
|
7
|
+
**Companion:** [`docs/hott-primer.md`](./hott-primer.md) — the informal version.
|
|
8
|
+
|
|
9
|
+
## Abstract
|
|
10
|
+
|
|
11
|
+
Mnemonica is an instance-inheritance runtime: types are declared with
|
|
12
|
+
`define()`, and subtypes are constructed from parent *instances*
|
|
13
|
+
(`new instance.SubType(args)`), so every instance carries a prototype chain
|
|
14
|
+
back to the root of its type trie. We claim a small number of **structurally
|
|
15
|
+
exact** correspondences with HoTT — the prototype chain as an identity path,
|
|
16
|
+
and the monadic structure of construction — and a larger number of honest
|
|
17
|
+
**analogies** — univalence as nominal typing, higher inductive types as the
|
|
18
|
+
type trie, fibrations as construction-context transport. Each exact claim is
|
|
19
|
+
pinned by an executable witness that runs in CI
|
|
20
|
+
(`test/hott-laws.js`); analogies are labeled as such
|
|
21
|
+
and no formal embedding is claimed.
|
|
22
|
+
|
|
23
|
+
## 1. Honesty levels
|
|
24
|
+
|
|
25
|
+
Every claim in this note carries exactly one of three statuses:
|
|
26
|
+
|
|
27
|
+
- **Exact** — the structures coincide up to a translation given in §2, and a
|
|
28
|
+
CI witness fails if the correspondence breaks.
|
|
29
|
+
- **Analogy** — the HoTT concept explains the design decision and predicts
|
|
30
|
+
its behavior, but no formal statement is made or checked.
|
|
31
|
+
- **Metaphor** — a vocabulary aid only.
|
|
32
|
+
|
|
33
|
+
Non-claims are listed in §5. The most important one up front: mnemonica is
|
|
34
|
+
**inspired by** HoTT; it is not an implementation of HoTT, and nothing here
|
|
35
|
+
is a proof in a proof-assistant sense.
|
|
36
|
+
|
|
37
|
+
## 2. Definitions (the translation)
|
|
38
|
+
|
|
39
|
+
- **Type trie.** Each `define(name, handler)` call adds a node; each
|
|
40
|
+
`Parent.define(name, handler)` adds a child edge. The trie is rooted at the
|
|
41
|
+
type collection (`defaultTypes` or a custom `createTypesCollection()`).
|
|
42
|
+
Implementation: [`src/api/types/`](../src/api/types/).
|
|
43
|
+
- **Instance.** The result of `new Type(args)`. Instances are linked lists of
|
|
44
|
+
prototype hops: `Object.getPrototypeOf` walks from the instance through its
|
|
45
|
+
Mnemosyne memory layer to the parent *instance*, up to the root instance.
|
|
46
|
+
- **Construction path.** For an instance `x`, the sequence
|
|
47
|
+
`x → Object.getPrototypeOf(x) → … → root` — a literal, materialized chain
|
|
48
|
+
of object references held by the runtime for the lifetime of the process.
|
|
49
|
+
- **Context.** The construction record (`args`, creator, timestamps) stored
|
|
50
|
+
per instance in a `WeakMap`, read via `getProps(instance)`.
|
|
51
|
+
|
|
52
|
+
Under this translation, "type" ≈ node in the trie, "instance of type T" ≈
|
|
53
|
+
point equipped with a path to the node T, and "equality witness" ≈ the path
|
|
54
|
+
itself.
|
|
55
|
+
|
|
56
|
+
## 3. Exact correspondences
|
|
57
|
+
|
|
58
|
+
### 3.1 Path types (Exact)
|
|
59
|
+
|
|
60
|
+
**Statement.** In HoTT, the identity type `Id(a, b)` is the type of paths
|
|
61
|
+
from `a` to `b`; a proof of identity *is* a path. In mnemonica, the identity
|
|
62
|
+
of an instance *is* its construction path: the prototype chain is a
|
|
63
|
+
first-class, inspectable object reference chain, present in memory, not
|
|
64
|
+
reconstructed on demand.
|
|
65
|
+
|
|
66
|
+
**Witness.** `test/hott-laws.js` › "path types: the prototype chain IS the
|
|
67
|
+
identity path to root" — asserts the parent instance objects are literally
|
|
68
|
+
elements of the child's `Object.getPrototypeOf` chain, in construction order.
|
|
69
|
+
|
|
70
|
+
**Corollary (path uniqueness as context).** Two instances of the same type
|
|
71
|
+
built by different paths carry different contexts; the path, not the
|
|
72
|
+
endpoint, is the identity. Witness: "path uniqueness: different construction
|
|
73
|
+
order, different identity".
|
|
74
|
+
|
|
75
|
+
**Corollary (comparators are comparable).** The naming path extracted by
|
|
76
|
+
`collectConstructors` (`src/utils/collectConstructors.ts`) is a legitimate
|
|
77
|
+
comparison instrument: extraction is a deterministic function of the chain
|
|
78
|
+
(witness: "comparators are comparable: naming-path extraction is
|
|
79
|
+
deterministic"), comparison of spines is direction-blind, and comparison
|
|
80
|
+
results respect the path order (extending a path extends its comparison
|
|
81
|
+
results) — the latter two mechanically checked in the
|
|
82
|
+
[hott](https://github.com/mythographica/hott) repo's `SpineAlgebra.lean`
|
|
83
|
+
(`sharedSpinePrefix_comm`, `sharedSpinePrefix_mono`).
|
|
84
|
+
|
|
85
|
+
### 3.2 Monad structure (Exact)
|
|
86
|
+
|
|
87
|
+
**Statement.** Let `return` be root construction (`new T(args)`) and `bind`
|
|
88
|
+
be `new instance.SubType(args)`. Then:
|
|
89
|
+
|
|
90
|
+
- **Right identity** — binding a subtype preserves the parent context:
|
|
91
|
+
the child is still an instance of every ancestor type.
|
|
92
|
+
Witness: "monad right identity: binding a subtype preserves the parent
|
|
93
|
+
context".
|
|
94
|
+
- **Associativity** — prototype-chain extension associates:
|
|
95
|
+
`((x >>= A) >>= B)` and `(x >>= (λx. x >>= A >>= B))` yield chains with the
|
|
96
|
+
same ordered ancestry. Witness: "monad associativity: chain extension order
|
|
97
|
+
is irrelevant to grouping".
|
|
98
|
+
|
|
99
|
+
Left identity holds trivially: `define` produces the constructor, and the
|
|
100
|
+
first `new` is `return`. The bind operation is implemented in
|
|
101
|
+
[`src/api/types/InstanceCreator.ts`](../src/api/types/InstanceCreator.ts).
|
|
102
|
+
|
|
103
|
+
## 4. Analogies
|
|
104
|
+
|
|
105
|
+
### 4.1 Univalence — as nominal typing (Analogy)
|
|
106
|
+
|
|
107
|
+
HoTT's univalence axiom identifies equivalence with identity. Mnemonica's
|
|
108
|
+
nominal typing is the contrapositive intuition: identical *structure* does
|
|
109
|
+
not give identity — two types with byte-identical constructor bodies are
|
|
110
|
+
different types, and re-declaring a name is refused (`ALREADY_DECLARED`).
|
|
111
|
+
The constructor name, frozen at `define()` time, is the identity.
|
|
112
|
+
|
|
113
|
+
This is why we call univalence an *analogy*: mnemonica does not identify
|
|
114
|
+
equivalent structures — it refuses to, and that refusal is the design
|
|
115
|
+
decision the axiom illuminates. Witness (for the refusal, not the axiom):
|
|
116
|
+
"identity is nominal (univalence intuition): shape does not identify".
|
|
117
|
+
|
|
118
|
+
### 4.2 Higher Inductive Types — as the type trie (Analogy)
|
|
119
|
+
|
|
120
|
+
A HIT is generated by point constructors *and* path constructors. A mnemonica
|
|
121
|
+
type is generated by its `define()` call (point) and its parent edge (path).
|
|
122
|
+
The analogy predicts the design's emphasis: the edge is as much a part of the
|
|
123
|
+
type as the handler — which is exactly why subtypes cannot be constructed
|
|
124
|
+
except from parent instances (`WRONG_MODIFICATION_PATTERN` otherwise).
|
|
125
|
+
|
|
126
|
+
### 4.3 Fibrations — as context transport (Analogy)
|
|
127
|
+
|
|
128
|
+
Read the trie as a base space and construction contexts as fibers over nodes;
|
|
129
|
+
`new instance.SubType(args)` is transport along an edge, lifting the parent's
|
|
130
|
+
context into the child's fiber. Hooks (`preCreation`, `postCreation`,
|
|
131
|
+
`creationError`) are the lifting protocol: refuse, observe, record.
|
|
132
|
+
Implementation: [`src/api/hooks/`](../src/api/hooks/).
|
|
133
|
+
|
|
134
|
+
## 5. Non-claims
|
|
135
|
+
|
|
136
|
+
- **No higher paths.** Paths between paths have no counterpart; prototype
|
|
137
|
+
chains form a tree, not a higher groupoid.
|
|
138
|
+
- **No formal univalence.** Nothing in the runtime computes or transports
|
|
139
|
+
along equivalences of types.
|
|
140
|
+
- **No path constructors as operations.** HIT-style quotienting (e.g.
|
|
141
|
+
identifying two nodes) is impossible by design — see §4.1.
|
|
142
|
+
- **No proof relevance beyond the chain itself.** The path carries context
|
|
143
|
+
data, but the runtime does not compute with paths as values.
|
|
144
|
+
|
|
145
|
+
### 5.1 The comparison tower, and where it grounds
|
|
146
|
+
|
|
147
|
+
Comparison forms a tower: instances (JS objects) → naming paths →
|
|
148
|
+
comparators → comparison of comparators → proofs of comparability → …
|
|
149
|
+
The tower does not regress infinitely; it grounds in three named places:
|
|
150
|
+
|
|
151
|
+
- **Bottom — primitive.** Two instances as JS objects are comparable only by
|
|
152
|
+
reference identity (`Object.is`). The algebra never claims the fiber:
|
|
153
|
+
instances are incomparable even when `instanceof` proves the same type.
|
|
154
|
+
- **Middle — self-similar.** Every level above the bottom is the *same*
|
|
155
|
+
datatype: comparators are spines, comparison results are spines
|
|
156
|
+
(`sharedSpinePrefix : Spine → Spine → Spine` is an endo-operation), so the
|
|
157
|
+
theorems of §3 — which quantify over all spines — already govern
|
|
158
|
+
comparison-of-comparison at any meta-depth. No meta-level needs a new
|
|
159
|
+
proof; the tower is infinite in height but closed in content.
|
|
160
|
+
- **Top — trusted.** The meta-level proofs are checked by the Lean kernel.
|
|
161
|
+
The kernel itself is trusted, as in every proof assistant; this is where
|
|
162
|
+
formal proof ends by convention, not a hole in the claims.
|
|
163
|
+
|
|
164
|
+
## 6. Synthetic topology (Metaphor)
|
|
165
|
+
|
|
166
|
+
"The trie is a connected space; every type is reachable from the root" is a
|
|
167
|
+
useful picture for reachability and tooling (graph views, static analysis via
|
|
168
|
+
[tactica](https://www.npmjs.com/package/@mnemonica/tactica)). It proves
|
|
169
|
+
nothing.
|
|
170
|
+
|
|
171
|
+
## 7. Verification
|
|
172
|
+
|
|
173
|
+
All witnesses live in `test/hott-laws.js` and run in
|
|
174
|
+
the standard suites (`npm run test:cov`, `npm run test:jest:cov`). A broken
|
|
175
|
+
witness is a falsified claim — treat any such failure as a retraction event
|
|
176
|
+
for §3 until the note is updated.
|
|
177
|
+
|
|
178
|
+
## References
|
|
179
|
+
|
|
180
|
+
1. The Univalent Foundations Program. *Homotopy Type Theory: Univalent
|
|
181
|
+
Foundations of Mathematics.* Institute for Advanced Study, 2013.
|
|
182
|
+
https://homotopytypetheory.org/book/
|
|
183
|
+
2. Mnemonica source: [`src/api/types/`](../src/api/types/) (TypeProxy,
|
|
184
|
+
InstanceCreator, Mnemosyne), [`src/api/hooks/`](../src/api/hooks/).
|
|
185
|
+
3. [`docs/hott-primer.md`](./hott-primer.md) — informal primer and status
|
|
186
|
+
table.
|
package/docs/tooling.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Tooling around mnemonica
|
|
2
|
+
|
|
3
|
+
The library itself is runtime-only — but the ecosystem around it has grown
|
|
4
|
+
a toolchain for **seeing** what your type graph does. This page is the map.
|
|
5
|
+
|
|
6
|
+
| Tool | Status | What it gives you |
|
|
7
|
+
|---|---|---|
|
|
8
|
+
| [`@mnemonica/tactica`](https://www.npmjs.com/package/@mnemonica/tactica) | published | Static analysis + codegen: scans `define()`/`@decorate()` and emits `.tactica/` artifacts (types.ts, hierarchy/definitions/usages/flow JSON) |
|
|
9
|
+
| [`@mnemonica/dive`](https://www.npmjs.com/package/@mnemonica/dive) | published | Execution-flow tracing: wrapped calls/creations as a trace ring, errors pinned to the instance that carried them — no AsyncLocalStorage |
|
|
10
|
+
| [`typeomatica`](https://www.npmjs.com/package/typeomatica) | published | Runtime field-type enforcement via Proxy ([`./typeomatica.md`](./typeomatica.md)) |
|
|
11
|
+
| [`@mnemonica/topologica`](https://www.npmjs.com/package/@mnemonica/topologica) | published | Module loader that self-defines directory trees of types |
|
|
12
|
+
| `@mnemonica/nestjs` (nestjs-adapter) | in active development | NestJS wiring: DTO → validated mnemonica instance, dive tracing across DI boundaries, OTel spans (Jaeger) per request and per construction |
|
|
13
|
+
| mnemographica | in active development | VS Code extension: `.tactica` as tree views + interactive 3D type graph + a Live Trace sidebar fed by a running app |
|
|
14
|
+
| `@mnemonica/strategy` | in active development | The live bridge: attaches to a running app (CDP, or the app's own embedded WS channel) and exposes it to agents/tooling — trace streaming, and live-craft (below) |
|
|
15
|
+
|
|
16
|
+
## Two modes worth knowing about
|
|
17
|
+
|
|
18
|
+
### Watch a running application
|
|
19
|
+
|
|
20
|
+
With the nestjs adapter installed, a running app emits dive trace events and
|
|
21
|
+
OTel spans. mnemographica's **Live Trace** view collects them (recent traces,
|
|
22
|
+
errored ones in red, click to isolate in the 3D graph or open in Jaeger), and
|
|
23
|
+
its **App Channel** tab connects straight to the app's embedded strategy WS
|
|
24
|
+
channel — no debugger involved.
|
|
25
|
+
|
|
26
|
+
### Live-craft: change constructors without a restart
|
|
27
|
+
|
|
28
|
+
The strategy channel can also **define new types and swap their constructors
|
|
29
|
+
inside a running process** — a development mode: you craft a type and
|
|
30
|
+
immediately see it. Types born this way are *shimmed*: mnemonica keeps a
|
|
31
|
+
stable shell constructor forever while the real implementation lives behind
|
|
32
|
+
it, replaceable via `swap`. Source-born types are never swappable. The full
|
|
33
|
+
story lives in strategy's `docs/live-craft.md`.
|
|
34
|
+
|
|
35
|
+
## Debug the library's own tests (and learn the internals)
|
|
36
|
+
|
|
37
|
+
Mnemonica's own mocha suite runs under the Chrome DevTools Protocol — the
|
|
38
|
+
same protocol the strategy bridge uses:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm run debug # builds src, then mocha --inspect-brk on test/
|
|
42
|
+
npm run test:jest:debug # the jest suite, likewise
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Then open `chrome://inspect` (or attach VS Code) and step through the suite
|
|
46
|
+
construction by construction. Every `return` in `src/` goes through an
|
|
47
|
+
intermediate variable exactly so you can hover it at a `return` breakpoint —
|
|
48
|
+
walking the tests this way is the fastest honest tour of the internals:
|
|
49
|
+
proxy construction, the Mnemosyne memory layer, hooks firing, error paths.
|
|
50
|
+
Much better than reading logs.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mnemonica",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9",
|
|
4
4
|
"description": "AI-agent ready instance inheritance system for JavaScript/TypeScript via prototype chains",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./build/index.js",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"browser": "./module/index.js",
|
|
17
17
|
"require": "./build/index.js",
|
|
18
18
|
"default": "./build/index.js"
|
|
19
|
-
}
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json"
|
|
20
21
|
},
|
|
21
22
|
"files": [
|
|
22
23
|
"README.md",
|