mnemonica 1.0.0 → 1.0.6
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/.ai/ONBOARDING.md +1 -1
- package/.ai/ask/AGENTS.md +15 -9
- package/.ai/async_init.md +2 -2
- package/.ai/rules-skill/contributing.md +1 -1
- package/.ai/rules-skill/define-patterns.md +8 -2
- package/.ai/rules-skill/ecosystem.md +4 -4
- package/.ai/rules-skill/instance-methods.md +48 -15
- package/.ai/rules-skill/type-system.md +12 -2
- package/AGENTS.md +6 -2
- package/CONTRIBUTING.md +61 -9
- package/FOR_HUMANS.md +149 -239
- package/README.md +75 -40
- package/SKILL.md +1 -1
- package/build/api/errors/exceptionConstructor.js +20 -12
- package/build/api/errors/index.js +9 -5
- package/build/api/errors/throwModificationError.js +15 -9
- package/build/api/index.js +35 -2
- package/build/api/types/InstanceCreator.js +5 -2
- package/build/api/types/Mnemosyne.d.ts +6 -6
- package/build/api/types/Mnemosyne.js +43 -120
- package/build/api/types/Props.js +5 -3
- package/build/api/types/TypeProxy.js +13 -9
- package/build/api/types/compileNewModificatorFunctionBody.js +14 -8
- package/build/api/types/index.js +56 -13
- package/build/api/utils/index.js +21 -12
- package/build/constants/index.js +11 -8
- package/build/descriptors/types/index.js +79 -26
- package/build/index.d.ts +4 -4
- package/build/index.js +62 -15
- package/build/types/index.d.ts +52 -31
- package/build/types/index.js +1 -1
- package/build/utils/clone.d.ts +1 -0
- package/build/utils/clone.js +11 -0
- package/build/utils/collectConstructors.js +5 -3
- package/build/utils/exception.d.ts +1 -0
- package/build/utils/exception.js +14 -0
- package/build/utils/extract.d.ts +2 -3
- package/build/utils/extract.js +3 -2
- package/build/utils/fork.d.ts +1 -0
- package/build/utils/fork.js +33 -0
- package/build/utils/index.d.ts +2 -3
- package/build/utils/index.js +21 -7
- package/build/utils/merge.d.ts +2 -1
- package/build/utils/merge.js +10 -6
- package/build/utils/parent.d.ts +1 -1
- package/build/utils/parent.js +3 -2
- package/build/utils/parse.d.ts +2 -12
- package/build/utils/parse.js +1 -1
- package/build/utils/pick.d.ts +4 -3
- package/build/utils/pick.js +4 -5
- package/build/utils/sibling.d.ts +1 -0
- package/build/utils/sibling.js +25 -0
- package/build/utils/toJSON.d.ts +1 -1
- package/build/utils/toJSON.js +3 -2
- package/docs/UTILS.md +184 -0
- package/docs/ai-learning-trajectory.md +1 -1
- package/docs/async-constructors.md +3 -1
- package/docs/empathy-in-ai.md +170 -0
- package/docs/hott-primer.md +47 -0
- package/docs/performance-vs-security.md +395 -0
- package/docs/purpose.md +38 -7
- package/docs/tactica-pattern.md +10 -10
- package/docs/theory-of-operations.md +224 -0
- package/docs/typed-lookup.md +12 -12
- package/docs/typeomatica.md +1 -1
- package/package.json +13 -6
- package/src/api/errors/exceptionConstructor.ts +14 -9
- package/src/api/errors/index.ts +8 -4
- package/src/api/errors/throwModificationError.ts +10 -9
- package/src/api/types/InstanceCreator.ts +5 -8
- package/src/api/types/Mnemosyne.ts +72 -231
- package/src/api/types/Props.ts +4 -2
- package/src/api/types/TypeProxy.ts +7 -11
- package/src/api/types/compileNewModificatorFunctionBody.ts +13 -7
- package/src/api/types/index.ts +15 -8
- package/src/api/utils/index.ts +16 -14
- package/src/constants/index.ts +6 -9
- package/src/descriptors/types/index.ts +44 -24
- package/src/index.ts +28 -21
- package/src/types/index.ts +101 -69
- package/src/utils/clone.ts +11 -0
- package/src/utils/collectConstructors.ts +4 -2
- package/src/utils/exception.ts +16 -0
- package/src/utils/extract.ts +5 -2
- package/src/utils/fork.ts +57 -0
- package/src/utils/index.ts +32 -13
- package/src/utils/merge.ts +18 -6
- package/src/utils/parent.ts +4 -6
- package/src/utils/parse.ts +5 -4
- package/src/utils/pick.ts +10 -2
- package/src/utils/sibling.ts +33 -0
- package/src/utils/toJSON.ts +3 -2
package/build/utils/parse.js
CHANGED
|
@@ -42,4 +42,4 @@ const parse = (self) => {
|
|
|
42
42
|
return result;
|
|
43
43
|
};
|
|
44
44
|
exports.parse = parse;
|
|
45
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
45
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGFyc2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvcGFyc2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsWUFBWSxDQUFDOzs7QUFHYixrREFBb0Q7QUFDcEQsTUFBTSxFQUNMLDBCQUEwQixFQUMxQixvQkFBb0IsRUFDcEIsR0FBRyxvQkFBVyxDQUFDO0FBUWhCLHVDQUFvQztBQUc3QixNQUFNLEtBQUssR0FBRyxDQUFvQixJQUFPLEVBQWMsRUFBRTtJQUUvRCxJQUFLLENBQUMsSUFBSSxJQUFJLENBQUcsSUFBNEMsQ0FBQyxXQUFXLEVBQUcsQ0FBQztRQUM1RSxNQUFNLElBQUksMEJBQTBCLENBQUM7SUFDdEMsQ0FBQztJQUVELE1BQU0sS0FBSyxHQUFHLE9BQU8sQ0FBQyxjQUFjLENBQUUsSUFBSSxDQUFZLENBQUM7SUFFdkQsTUFBTSxlQUFlLEdBQUssSUFBMkMsQ0FBQyxXQUFXLENBQUM7SUFDbEYsTUFBTSxnQkFBZ0IsR0FBSyxLQUE0QyxDQUFDLFdBQVcsQ0FBQztJQUVwRixJQUFLLGVBQWUsQ0FBQyxJQUFJLENBQUMsUUFBUSxFQUFFLEtBQUssZ0JBQWdCLENBQUMsSUFBSSxDQUFDLFFBQVEsRUFBRSxFQUFHLENBQUM7UUFDNUUsTUFBTSxHQUFHLEdBQUcsaUNBQWlDO1lBQzVDLElBQUksZUFBZSxDQUFDLElBQUksU0FBUyxnQkFBZ0IsQ0FBQyxJQUFJLEdBQUcsQ0FBQztRQUMzRCxNQUFNLElBQUksb0JBQW9CLENBQUUsR0FBRyxDQUFFLENBQUM7SUFDdkMsQ0FBQztJQUVELE1BQU0sVUFBVSxHQUFZLE9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xuXHRcdHByb3RvLFxuXG5cdFx0am9pbnQsXG5cdFx0Ly8gYXJncyxcblx0XHRwYXJlbnQsXG5cblx0fTtcblx0cmV0dXJuIHJlc3VsdDtcbn07XG4iXX0=
|
package/build/utils/pick.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
[
|
|
3
|
-
};
|
|
1
|
+
export declare function pick<T extends object, K extends keyof T>(instance: T, ...args: (K | K[])[]): {
|
|
2
|
+
[P in K]: T[P];
|
|
3
|
+
} & {};
|
|
4
|
+
export declare function pick<T extends object>(instance: T, ...args: (string | string[])[]): Record<string, unknown>;
|
package/build/utils/pick.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pick =
|
|
3
|
+
exports.pick = pick;
|
|
4
4
|
const errors_1 = require("../descriptors/errors");
|
|
5
5
|
const { WRONG_INSTANCE_INVOCATION } = errors_1.ErrorsTypes;
|
|
6
|
-
|
|
6
|
+
function pick(instance, ...args) {
|
|
7
7
|
if (instance !== Object(instance)) {
|
|
8
8
|
throw new WRONG_INSTANCE_INVOCATION;
|
|
9
9
|
}
|
|
@@ -22,6 +22,5 @@ const pick = (instance, ...args) => {
|
|
|
22
22
|
return obj;
|
|
23
23
|
}, {});
|
|
24
24
|
return picked;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGljay5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9waWNrLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLFlBQVksQ0FBQzs7O0FBRWIsa0RBQW9EO0FBQ3BELE1BQU0sRUFBRSx5QkFBeUIsRUFBRSxHQUFHLG9CQUFXLENBQUM7QUFFM0MsTUFBTSxJQUF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HRhcnIucHVzaCggLi4uZWwgKTtcblx0XHRcdH0gZWxzZSB7XG5cdFx0XHRcdGFyci5wdXNoKCBlbCApO1xuXHRcdFx0fVxuXHRcdFx0cmV0dXJuIGFycjtcblx0XHR9LFxuXHRcdFtdIFxuXHQpO1xuXG5cdGNvbnN0IHJlY29yZCA9IGluc3RhbmNlIGFzIFJlY29yZDxzdHJpbmcsIHVua25vd24+O1xuXHRjb25zdCBwaWNrZWQgPSBwcm9wcy5yZWR1Y2UoXG5cdFx0KCBvYmo6IHsgWyBpbmRleDogc3RyaW5nIF06IHVua25vd24gfSwgbmFtZTogc3RyaW5nICkgPT4ge1xuXHRcdFx0b2JqWyBuYW1lIF0gPSByZWNvcmRbIG5hbWUgXTtcblx0XHRcdHJldHVybiBvYmo7XG5cdFx0fSxcblx0XHR7fSBcblx0KTtcblxuXHRyZXR1cm4gcGlja2VkO1xuXG59XG4iXX0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sibling: (instance: object) => unknown;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sibling = void 0;
|
|
4
|
+
const Props_1 = require("../api/types/Props");
|
|
5
|
+
const sibling = (instance) => {
|
|
6
|
+
const siblings = (SiblingTypeName) => {
|
|
7
|
+
const props = (0, Props_1.getProps)(instance);
|
|
8
|
+
const { __collection__: collection, } = props;
|
|
9
|
+
const answer = collection[SiblingTypeName];
|
|
10
|
+
return answer;
|
|
11
|
+
};
|
|
12
|
+
const result = new Proxy(siblings, {
|
|
13
|
+
get(_, prop) {
|
|
14
|
+
const proxyResult = siblings(prop);
|
|
15
|
+
return proxyResult;
|
|
16
|
+
},
|
|
17
|
+
apply(_, __, args) {
|
|
18
|
+
const proxyResult = siblings(args[0]);
|
|
19
|
+
return proxyResult;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
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LFFBQUEsT0FBTyxXQXlCbEIiLCJzb3VyY2VzQ29udGVudCI6WyIndXNlIHN0cmljdCc7XG5cbmltcG9ydCB7XG5cdGdldFByb3BzLFxuXHRQcm9wc1xufSBmcm9tICcuLi9hcGkvdHlwZXMvUHJvcHMnO1xuXG5leHBvcnQgY29uc3Qgc2libGluZyA9IChpbnN0YW5jZTogb2JqZWN0KTogdW5rbm93biA9PiB7XG5cblx0Y29uc3Qgc2libGluZ3MgPSAoU2libGluZ1R5cGVOYW1lOiBzdHJpbmcpID0+IHtcblx0XHRjb25zdCBwcm9wcyA9IGdldFByb3BzKGluc3RhbmNlKSBhcyBQcm9wcztcblx0XHRjb25zdCB7IF9fY29sbGVjdGlvbl9fOiBjb2xsZWN0aW9uLCB9ID0gcHJvcHM7XG5cdFx0Y29uc3QgYW5zd2VyID0gY29sbGVjdGlvblsgU2libGluZ1R5cGVOYW1lIF07XG5cdFx0cmV0dXJuIGFuc3dlcjtcblx0fTtcblxuXHRjb25zdCByZXN1bHQgPSBuZXcgUHJveHkoXG5cdFx0c2libGluZ3MsXG5cdFx0e1xuXHRcdFx0Z2V0IChfLCBwcm9wOiBzdHJpbmcpIHtcblx0XHRcdFx0Y29uc3QgcHJveHlSZXN1bHQgPSBzaWJsaW5ncyhwcm9wKTtcblx0XHRcdFx0cmV0dXJuIHByb3h5UmVzdWx0O1xuXHRcdFx0fSxcblx0XHRcdGFwcGx5IChfLCBfXywgYXJncywpIHtcblx0XHRcdFx0Y29uc3QgcHJveHlSZXN1bHQgPSBzaWJsaW5ncyhhcmdzWyAwIF0pO1xuXHRcdFx0XHRyZXR1cm4gcHJveHlSZXN1bHQ7XG5cdFx0XHR9XG5cdFx0fVxuXHQpO1xuXG5cdHJldHVybiByZXN1bHQ7XG5cbn07XG4iXX0=
|
package/build/utils/toJSON.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const toJSON: (instance:
|
|
1
|
+
export declare const toJSON: <T extends object>(instance: T) => string;
|
package/build/utils/toJSON.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.toJSON = void 0;
|
|
|
4
4
|
const extract_1 = require("./extract");
|
|
5
5
|
const toJSON = (instance) => {
|
|
6
6
|
const extracted = (0, extract_1.extract)(instance);
|
|
7
|
-
|
|
7
|
+
const result = Object.entries(extracted).reduce((o, entry) => {
|
|
8
8
|
const [name, _value] = entry;
|
|
9
9
|
if ([null, undefined].includes(_value)) {
|
|
10
10
|
return o;
|
|
@@ -26,6 +26,7 @@ const toJSON = (instance) => {
|
|
|
26
26
|
return o;
|
|
27
27
|
}, '{')
|
|
28
28
|
.replace(/,$/, '}');
|
|
29
|
+
return result;
|
|
29
30
|
};
|
|
30
31
|
exports.toJSON = toJSON;
|
|
31
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
32
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidG9KU09OLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWxzL3RvSlNPTi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxZQUFZLENBQUM7OztBQUViLHVDQUFvQztBQUM3QixNQUFNLE1BQU0sR0FBRyxDQUFvQixRQUFXLEVBQUcsRUFBRTtJQUV6RCxNQUFNLFNBQVMsR0FBRyxJQUFBLGlCQUFPLEVBQUUsUUFBUSxDQUFFLENBQUM7SUFDdEMsTUFBTSxNQUFNLEdBQUcsTUFBTSxDQUFDLE9BQU8sQ0FBRSxTQUFTLENBQUUsQ0FBQyxNQUFNLENBQ2hELENBQUUsQ0FBUyxFQUFFLEtBQTBCLEVBQUcsRUFBRTtRQUUzQyxNQUFNLENBQUUsSUFBSSxFQUFFLE1BQU0sQ0FBRSxHQUFHLEtBQUssQ0FBQztRQUMvQixJQUFLLENBQUUsSUFBSSxFQUFFLFNBQVMsQ0FBRSxDQUFDLFFBQVEsQ0FBRSxNQUEwQixDQUFFLEVBQUcsQ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alone versions of the instance introspection
|
|
4
|
+
and manipulation methods. Every utility that accepts an instance infers its
|
|
5
|
+
type parameter from that instance, so ordinary code needs no explicit `<T>`
|
|
6
|
+
casts.
|
|
7
|
+
|
|
8
|
+
```typescript
|
|
9
|
+
import { utils } from 'mnemonica';
|
|
10
|
+
|
|
11
|
+
const extracted = utils.extract(user); // Extracted<typeof user>
|
|
12
|
+
const picked = utils.pick(user, 'name', 'age');
|
|
13
|
+
const cloned = utils.clone(user); // typeof user
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Core helper types
|
|
19
|
+
|
|
20
|
+
These types live in `src/types/index.ts` and define how the utilities present
|
|
21
|
+
their results.
|
|
22
|
+
|
|
23
|
+
### `Extracted<T>`
|
|
24
|
+
|
|
25
|
+
A plain-object view of an instance's enumerable string-keyed user properties.
|
|
26
|
+
`MnemonicaInstance` method names (`extract`, `pick`, `parent`, `clone`, `fork`,
|
|
27
|
+
`exception`, `sibling`) are filtered out. Optionality is preserved from the
|
|
28
|
+
source type.
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
export type Extracted<T extends object> = {
|
|
32
|
+
[K in keyof T as K extends string ? (K extends MnemonicaInstanceMethodKeys ? never : K) : never]: T[K];
|
|
33
|
+
} & {};
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### `MnemonicaInstanceMethodKeys`
|
|
37
|
+
|
|
38
|
+
The set of prototype method names that must disappear from data-only views:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
export type MnemonicaInstanceMethodKeys =
|
|
42
|
+
'extract' | 'pick' | 'parent' | 'clone' | 'fork' | 'exception' | 'sibling';
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### `Merge<E, T>`
|
|
46
|
+
|
|
47
|
+
Merges two instance shapes into a flat field object. `T` wins on conflicts;
|
|
48
|
+
`E` contributes only keys that `T` does not define. Method names are filtered
|
|
49
|
+
out. Used by `apply` / `call` / `bind` and by `utils.merge`.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
export type Merge<E extends object, T extends object> = {
|
|
53
|
+
[K in keyof T | keyof E as K extends MnemonicaInstanceMethodKeys ? never : K]:
|
|
54
|
+
K extends keyof T ? T[K] : E[K & keyof E];
|
|
55
|
+
};
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### `InstanceResult<N, Config>`
|
|
59
|
+
|
|
60
|
+
The public instance surface. It renders in hover tooltips as a plain field
|
|
61
|
+
object literal first, then `& MnemonicaInstance<{ ... }>` once:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
export type InstanceResult<
|
|
65
|
+
N extends object,
|
|
66
|
+
Config extends constructorOptions,
|
|
67
|
+
> = IsHidingMethods<Config> extends true
|
|
68
|
+
? { [K in keyof N]: N[K] }
|
|
69
|
+
: { [K in keyof N]: N[K] } & MnemonicaInstance<{ [K in keyof N]: N[K] }>;
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### `Parsed<T>`
|
|
73
|
+
|
|
74
|
+
The shape returned by `utils.parse(instance)` — a one-level snapshot of the
|
|
75
|
+
instance's prototype chain:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
export type Parsed<T extends object> = {
|
|
79
|
+
name: string;
|
|
80
|
+
props: Extracted<T>;
|
|
81
|
+
self: T;
|
|
82
|
+
proto: object;
|
|
83
|
+
joint: Record<string, unknown>;
|
|
84
|
+
parent: object | undefined;
|
|
85
|
+
};
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### `SiblingAccessor`
|
|
89
|
+
|
|
90
|
+
A callable/proxy object returned by `utils.sibling(instance)`:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
export interface SiblingAccessor {
|
|
94
|
+
(SiblingTypeName: string): TypeClass | undefined;
|
|
95
|
+
[key: string]: TypeClass | undefined;
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Utility reference
|
|
102
|
+
|
|
103
|
+
| Utility | Inferred return type | Notes |
|
|
104
|
+
|---|---|---|
|
|
105
|
+
| `utils.extract(instance)` | `Extracted<T>` | Data-only view; methods filtered. |
|
|
106
|
+
| `utils.pick(instance, 'a', 'b')` | `{ a: T['a'], b: T['b'] } & {}` | Literal keys → typed subset. Dynamic `string[]` → `Record<string, unknown>`. |
|
|
107
|
+
| `utils.clone(instance)` | `T` | Same instance type. |
|
|
108
|
+
| `utils.fork(instance)` | `(this: object, ...args: unknown[]) => T` | Returns a fork constructor. |
|
|
109
|
+
| `utils.parent(instance, path?)` | `object \| undefined` | Structural only; nominal path typing needs `TypeRegistry`. |
|
|
110
|
+
| `utils.sibling(instance)` | `SiblingAccessor` | Look up sibling constructors by string name or property access. |
|
|
111
|
+
| `utils.merge(A, B, ...args)` | `InstanceResult<Merge<B, A>, constructorOptions>` | `A` wins; `B` fills non-overlapping keys; methods shown once. |
|
|
112
|
+
| `utils.parse(instance)` | `Parsed<T>` | One-level prototype-chain snapshot. |
|
|
113
|
+
| `utils.toJSON(instance)` | `string` | Generic so the instance type is captured at the call site. |
|
|
114
|
+
| `utils.collectConstructors(instance, flat?)` | `(CallableFunction \| string)[]` | Introspection helper. |
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## `utils.merge(A, B, ...args)` in detail
|
|
119
|
+
|
|
120
|
+
`merge(a, b)` is implemented as `fork(a).call(b, ...args)`. The result is a **new
|
|
121
|
+
instance of `a`’s type** whose parent/existent instance is `b`. That means:
|
|
122
|
+
|
|
123
|
+
- `a` provides the primary fields.
|
|
124
|
+
- `b` contributes only the fields `a` does not define.
|
|
125
|
+
- The result is a flat field object (`A` wins) with no auto-injected instance
|
|
126
|
+
methods.
|
|
127
|
+
|
|
128
|
+
The type `InstanceResult<Merge<B, A>>` expresses this: a flat field object
|
|
129
|
+
(`A` wins).
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
const UserType = define('User', function (this: { name: string; age: number }) {
|
|
133
|
+
this.name = 'Alice';
|
|
134
|
+
this.age = 30;
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const RoleType = define('Role', function (this: { role: string }) {
|
|
138
|
+
this.role = 'admin';
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const user = new UserType();
|
|
142
|
+
const role = new RoleType();
|
|
143
|
+
|
|
144
|
+
// hover: { name: string; age: number; role: string; }
|
|
145
|
+
const merged = utils.merge(user, role);
|
|
146
|
+
merged.name; // string
|
|
147
|
+
merged.role; // string
|
|
148
|
+
utils.extract(merged); // OK
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## `utils.parse(instance)` in detail
|
|
154
|
+
|
|
155
|
+
`parse` returns a one-level snapshot of the instance's prototype chain:
|
|
156
|
+
|
|
157
|
+
- `name` — constructor name of the immediate prototype.
|
|
158
|
+
- `props` — `Extracted<T>` from the instance itself.
|
|
159
|
+
- `self` — the original instance reference (`T`).
|
|
160
|
+
- `proto` — `Object.getPrototypeOf(instance)`.
|
|
161
|
+
- `joint` — enumerable properties copied from `proto`.
|
|
162
|
+
- `parent` — `Object.getPrototypeOf(proto)` (the next link up; currently not
|
|
163
|
+
recursively parsed).
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
const parsed = utils.parse(user);
|
|
167
|
+
const name: string = parsed.name;
|
|
168
|
+
const propsName: string | undefined = parsed.props.name;
|
|
169
|
+
const self: typeof user = parsed.self;
|
|
170
|
+
const parent: object | undefined = parsed.parent;
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Limitations
|
|
176
|
+
|
|
177
|
+
- `utils.parent(instance, 'TypeName')` cannot return a specific nominal parent
|
|
178
|
+
type without a user-augmented `TypeRegistry`. This is the same limitation as
|
|
179
|
+
`lookupTyped()`: TypeScript cannot retroactively learn the type graph created
|
|
180
|
+
by `define()` calls. See [`./typed-lookup.md`](./typed-lookup.md).
|
|
181
|
+
- `utils.parse()` returns `parent` as `object | undefined` because deep recursive
|
|
182
|
+
parsing is not implemented at runtime.
|
|
183
|
+
- `utils.toJSON()` always returns `string`; the generic parameter only preserves
|
|
184
|
+
the instance type at the call site for consistency with the other utilities.
|
|
@@ -114,7 +114,7 @@ Three things accelerated learning:
|
|
|
114
114
|
|
|
115
115
|
After understanding mnemonica, the agent read `hott/AI-REFLECTION-THEORY.md` (internal docs). It noticed structural parallels:
|
|
116
116
|
|
|
117
|
-
- **Path induction** ↔ prototype chain traversal (`
|
|
117
|
+
- **Path induction** ↔ prototype chain traversal (`utils.parent(instance)`)
|
|
118
118
|
- **Univalence** ↔ capability equivalence (two types with same behavior are equivalent)
|
|
119
119
|
- **Runtime augmentation** ↔ path composition (adding a subtype extends the path)
|
|
120
120
|
- **Stored `__args__`** ↔ path recording (every constructor call is a recorded step)
|
|
@@ -180,6 +180,8 @@ console.log(child instanceof AsyncChild); // true
|
|
|
180
180
|
mnemonica's most powerful async feature is chainable awaits:
|
|
181
181
|
|
|
182
182
|
```js
|
|
183
|
+
const { utils } = require('mnemonica');
|
|
184
|
+
|
|
183
185
|
const result = await new UserTypeConstructor({
|
|
184
186
|
email: 'async@gmail.com',
|
|
185
187
|
password: 32123
|
|
@@ -191,7 +193,7 @@ const result = await new UserTypeConstructor({
|
|
|
191
193
|
.Async2Sync2nd({ sync: 'is' })
|
|
192
194
|
.AsyncChain3rd({ async: '3rd' });
|
|
193
195
|
|
|
194
|
-
console.log(
|
|
196
|
+
console.log(utils.extract(result));
|
|
195
197
|
// {
|
|
196
198
|
// email: 'async@gmail.com',
|
|
197
199
|
// password: undefined,
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# Empathy in AI: Data That Remembers Its Path
|
|
2
|
+
|
|
3
|
+
This document connects mnemonica's data-flow model to a specific AI design problem: **how an agent understands another agent's state**. The connection is not metaphorical decoration. It follows directly from the library's structure.
|
|
4
|
+
|
|
5
|
+
> If you want the deeper theory first, see the HoTT framing in [`docs/hott-primer.md`](./hott-primer.md) and the original vision in [`../../articles/inheritance.md`](../../articles/inheritance.md). This document stays at the API level.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## The problem with stateless understanding
|
|
10
|
+
|
|
11
|
+
Most AI pipelines process inputs as snapshots:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
const intent = classifyIntent(userMessage);
|
|
15
|
+
const response = generateResponse(intent);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`intent` is a label. It carries no history. If the classifier says `"frustrated"`, the generator has no access to:
|
|
19
|
+
- what the user asked three turns ago
|
|
20
|
+
- which previous response led to the current message
|
|
21
|
+
- whether the frustration is new or accumulated
|
|
22
|
+
|
|
23
|
+
The data is **amnesiac**. It answers "what" without "how did we get here." Empathy — in the minimal, technical sense of understanding another's state in context — requires the second question.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Mnemonica's contribution: state as lineage
|
|
28
|
+
|
|
29
|
+
Mnemonica makes every data value carry its own construction history. The mechanism is the same one used everywhere else in the library: `new current.Next(args)`.
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { define } from 'mnemonica';
|
|
33
|
+
|
|
34
|
+
const UserInput = define('UserInput', function (this: UserInput, text: string) {
|
|
35
|
+
this.text = text;
|
|
36
|
+
this.turn = 1;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const UnderstoodIntent = UserInput.define('UnderstoodIntent', function (this: UnderstoodIntent, intent: string) {
|
|
40
|
+
this.intent = intent;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const EmotionalState = UnderstoodIntent.define('EmotionalState', function (this: EmotionalState, emotion: string) {
|
|
44
|
+
this.emotion = emotion;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const ResponsePlan = EmotionalState.define('ResponsePlan', function (this: ResponsePlan, plan: string) {
|
|
48
|
+
this.plan = plan;
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
A single conversation turn is now a typed path:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const raw = new UserInput('I already told you the shipping address.');
|
|
56
|
+
const intent = new raw.UnderstoodIntent('correction');
|
|
57
|
+
const emotion = new intent.EmotionalState('frustrated');
|
|
58
|
+
const plan = new emotion.ResponsePlan('acknowledge + locate prior turn');
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The `plan` instance is not a flat object. Its prototype chain is the conversation history. `getProps(plan)` returns the full trace: type, parent, args, timestamp, creator.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Why this is empathy-infrastructure
|
|
66
|
+
|
|
67
|
+
Empathy, stripped to a design requirement, is **understanding another's present state as the endpoint of a path that includes their history**. Mnemonica provides the path.
|
|
68
|
+
|
|
69
|
+
| Capability | mnemonica operation | What it gives an AI agent |
|
|
70
|
+
|---|---|---|
|
|
71
|
+
| **Provenance** | `getProps(instance)` | "This response plan came from an `EmotionalState('frustrated')` that came from an `UnderstoodIntent('correction')` that came from `UserInput('I already told you...')`." |
|
|
72
|
+
| **Perspective-taking** | `utils.parent(instance, 'UserInput')` | "Let me look at the original input again, from the current endpoint." |
|
|
73
|
+
| **Reconstruction** | `utils.extract(instance)` | "Flatten the whole interaction into a single state object for the model prompt." |
|
|
74
|
+
| **Continuity** | `new current.Next(args)` | "Every transformation preserves the previous state as context; nothing is overwritten." |
|
|
75
|
+
|
|
76
|
+
The agent does not "feel" frustration. It has structural access to the fact that the current state is path-connected to a correction-intent and a repeated prior claim. That access is sufficient for behavior that humans experience as empathetic.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Concrete example: multi-turn intent resolution
|
|
81
|
+
|
|
82
|
+
Consider a support bot. A user's real goal may only become clear across several turns. Without lineage, each turn is re-classified from scratch. With mnemonica, the type graph itself records the unfolding understanding.
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
const Turn = define('Turn', function (this: Turn, text: string) {
|
|
86
|
+
this.text = text;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const ClarifiedNeed = Turn.define('ClarifiedNeed', function (this: ClarifiedNeed, need: string) {
|
|
90
|
+
this.need = need;
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const EscalationReason = ClarifiedNeed.define('EscalationReason', function (this: EscalationReason, reason: string) {
|
|
94
|
+
this.reason = reason;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Turn 1
|
|
98
|
+
const t1 = new Turn('My order is wrong.');
|
|
99
|
+
const c1 = new t1.ClarifiedNeed('missing_item');
|
|
100
|
+
|
|
101
|
+
// Turn 2: the user adds detail
|
|
102
|
+
const t2 = new c1.Turn('I ordered two, only one arrived.');
|
|
103
|
+
const c2 = new t2.ClarifiedNeed('quantity_error');
|
|
104
|
+
|
|
105
|
+
// Turn 3: escalation becomes appropriate
|
|
106
|
+
const t3 = new c2.Turn('This is the third time this month.');
|
|
107
|
+
const escalation = new t3.EscalationReason('repeat_issue');
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`escalation` knows it is a `EscalationReason` whose parent is `Turn('This is the third time this month.')`, whose parent is `ClarifiedNeed('quantity_error')`, whose parent is `Turn('I ordered two, only one arrived.')`, and so on. The decision to escalate is not a label produced by a classifier. It is a position in a reconstructible path.
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Self-reflection: an agent understanding its own path
|
|
115
|
+
|
|
116
|
+
The same structure lets an AI reflect on its own reasoning. Define a type for each stage of internal deliberation:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
const Observation = define('Observation', function (this: Observation, fact: string) {
|
|
120
|
+
this.fact = fact;
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const Hypothesis = Observation.define('Hypothesis', function (this: Hypothesis, guess: string) {
|
|
124
|
+
this.guess = guess;
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const Action = Hypothesis.define('Action', function (this: Action, action: string) {
|
|
128
|
+
this.action = action;
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const observed = new Observation('user repeated the question');
|
|
132
|
+
const hypothesis = new observed.Hypothesis('previous answer was unclear');
|
|
133
|
+
const action = new hypothesis.Action('rephrase with concrete example');
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The agent can query `utils.parent(action, 'Observation')` to recover the original evidence that justified its action. This is not logging. The evidence is part of the action's identity. The agent can answer "why did you do that?" by walking its own type chain.
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Connection to the original vision
|
|
141
|
+
|
|
142
|
+
The earliest mnemonica article asked: **"How will you explain Empathy in JavaScript?"** The answer proposed there was the prototype chain: each instance inherits from a specific predecessor, so data carries its own history by construction.
|
|
143
|
+
|
|
144
|
+
This document is the same answer, made operational. In mnemonica:
|
|
145
|
+
|
|
146
|
+
- **Identity is not shape**. Two instances with identical fields but different construction paths are different types. This matches the intuition that "I'm fine" can mean different things depending on history.
|
|
147
|
+
- **Transformation is not replacement**. `new current.Next(args)` extends the path; it does not delete the previous point. The past remains reachable.
|
|
148
|
+
- **Understanding is traversal**. To understand an instance is to walk its chain and see what it came from.
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Scope boundary
|
|
153
|
+
|
|
154
|
+
Mnemonica provides **infrastructure** for empathetic AI, not empathy itself. It does not:
|
|
155
|
+
|
|
156
|
+
- classify emotions
|
|
157
|
+
- model Theory of Mind
|
|
158
|
+
- generate appropriate responses
|
|
159
|
+
- guarantee benevolent behavior
|
|
160
|
+
|
|
161
|
+
What it provides is a data model where context and lineage are first-class. Higher layers — classifiers, planners, safety filters — can then operate on data that already knows where it came from.
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## See also
|
|
166
|
+
|
|
167
|
+
- [`docs/hott-primer.md`](./hott-primer.md) — formal background on paths, identity, and transport
|
|
168
|
+
- [`docs/purpose.md`](./purpose.md) — data flow vs control flow, and what mnemonica does not do
|
|
169
|
+
- [`../../articles/inheritance.md`](../../articles/inheritance.md) — the original 2019 essay that posed the empathy question
|
|
170
|
+
- [`../../hott/theory/MEMORY-AND-ESSENCE.md`](../../hott/theory/MEMORY-AND-ESSENCE.md) — the HoTT treatment of identity as path-connectedness
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# A brief HoTT primer (for agents who don't have one loaded)
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
**Scope boundary first.** Mnemonica is **inspired by** HoTT, not a formal implementation of it. The structural correspondences are productive analogies that illuminate why the Trie model is the right structure for typed data pipelines. They are not claims of a mathematical embedding. Specifically:
|
|
6
|
+
- **Higher paths** (paths between paths) have no direct analogue in mnemonica
|
|
7
|
+
- **Univalence** is an intuition about nominal typing, not a formal axiom
|
|
8
|
+
- **Higher Inductive Types** are a useful framing, not a literal implementation
|
|
9
|
+
|
|
10
|
+
Where the correspondence *is* exact — the monad laws, path uniqueness, and the Trie structure — that precision is worth highlighting.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## The Trie as a monad
|
|
15
|
+
|
|
16
|
+
The monad claim is the most precisely correct analogy. In mnemonica:
|
|
17
|
+
|
|
18
|
+
| Monad Law | mnemonica Equivalent | Holds? |
|
|
19
|
+
|---|---|---|
|
|
20
|
+
| **Left identity** (`return x >>= f = f x`) | `define(T) >>= construct` produces an instance of `T` | Structurally ✓ |
|
|
21
|
+
| **Right identity** (`m >>= return = m`) | `instance >>= define(SubT)` produces `instance` with `SubT` context | By construction ✓ |
|
|
22
|
+
| **Associativity** (`(m >>= f) >>= g = m >>= (λx. f x >>= g)`) | Chaining `a.SubType().SubSubType()` is prototype-chain associative | Structurally ✓ |
|
|
23
|
+
|
|
24
|
+
The `bind` operation is `new instance.SubType(args)`: it takes a value in context (`instance`), applies a function that produces a new contextualized value (`SubType` constructor), and returns a value in the combined context (`child` inherits from `instance` and carries `SubType` type). The associativity holds because the prototype chain is inherently associative: `instance -> Mnemosyne -> parent` extends linearly without reordering.
|
|
25
|
+
|
|
26
|
+
## The five HoTT concepts
|
|
27
|
+
|
|
28
|
+
**Univalence Axiom.** In HoTT, equivalence and identity coincide — there is no gap between "same structure" and "same thing." Mnemonica's nominal typing makes this intuition natural: two instances with identical property shapes but different constructors are *different types*. The constructor name (frozen at `define()` time) is the identity, not the shape. This is an **analogy** — mnemonica does not implement the univalence axiom formally, but the intuition that "identity is determined by constructor, not structure" is HoTT-inspired.
|
|
29
|
+
|
|
30
|
+
**Path Types.** In HoTT, equality is a type. `Id(a, b)` is the type of *paths* witnessing that `a` and `b` are equal. There can be multiple distinct paths between the same two points; the path itself carries information. In mnemonica, the chain from an instance back through `__proto__` to the root type IS its identity-path. The `__args__` along the way parameterize that path. This correspondence is **structurally exact**.
|
|
31
|
+
|
|
32
|
+
**Higher Inductive Types (HITs).** A type defined by its constructors AND by paths between values. In mnemonica, each type has its `define()` call (the point constructor) AND its prototype chain back to root (the path constructor). The Trie structure can be **viewed as** a HIT. This is a productive analogy, not a formal encoding — mnemonica does not implement path constructors as first-class operations.
|
|
33
|
+
|
|
34
|
+
**Synthetic Topology.** In HoTT, types are spaces and functions between types are continuous maps. Mnemonica's Trie is a connected topological space: every defined type is reachable from the root by construction edges, and the connectivity persists for the lifetime of the process. The `defaultTypes.subtypes` Map is the runtime representation of this space. This is a **useful metaphor** for understanding type reachability.
|
|
35
|
+
|
|
36
|
+
**Fibrations.** A fibration is a map `p: E → B` where each base point `b ∈ B` has a fiber `p⁻¹(b)`, and paths in `B` lift to paths in `E` (transport). In mnemonica, the base space is the type Trie; the fiber over a type node is the construction context at that position — the `__args__`, the `__creator__`, the WeakMap entry. A subtype creation `new instance.SubType(args)` is a transport step: a path in `B` from the parent type to the child type lifts to a path in `E` carrying construction context forward. Hooks are the *lifting protocol*: `preCreation` can refuse the lift, `postCreation` observes the lifted endpoint, `creationError` records when the lift fails. This is a **productive analogy** for understanding how construction context propagates.
|
|
37
|
+
|
|
38
|
+
## Summary table
|
|
39
|
+
|
|
40
|
+
| HoTT Concept | Status | Mnemonica Realization | Code in this package |
|
|
41
|
+
|---|---|---|---|
|
|
42
|
+
| Monad (bind/unit/associativity) | **Exact** | `new instance.SubType()` threads context; prototype chain is associative | [`src/api/types/InstanceCreator.ts`](../src/api/types/InstanceCreator.ts) |
|
|
43
|
+
| Path Types | **Exact** | The proto chain to root IS the identity-path | [`src/api/types/createInstanceModificator.ts`](../src/api/types/createInstanceModificator.ts) |
|
|
44
|
+
| Univalence | **Analogy** | Nominal typing: constructor name = identity, not shape | [`src/api/types/index.ts`](../src/api/types/index.ts) (`Symbol.hasInstance`) |
|
|
45
|
+
| HITs | **Analogy** | Types as point constructors + parent-edge path constructors | The Trie itself |
|
|
46
|
+
| Synthetic Topology | **Metaphor** | Trie as connected, always-on topological space | `defaultTypes.subtypes` Map |
|
|
47
|
+
| Fibrations | **Analogy** | Construction contexts as fibers; hooks as lifting protocol | `preCreation` / `postCreation` / `creationError` |
|