mnemonica 1.0.9 → 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 (52) 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 +96 -24
  17. package/FOR_HUMANS.md +32 -76
  18. package/README.md +35 -20
  19. package/SKILL.md +20 -20
  20. package/build/api/index.d.ts +2 -2
  21. package/build/api/types/index.js +8 -3
  22. package/build/descriptors/types/index.js +2 -2
  23. package/build/index.d.ts +10 -3
  24. package/build/index.js +17 -5
  25. package/build/types/index.d.ts +60 -21
  26. package/build/types/index.js +1 -1
  27. package/docs/ai-learning-trajectory.md +2 -3
  28. package/docs/decorate.md +123 -0
  29. package/docs/hott-primer.md +1 -1
  30. package/docs/purpose.md +3 -3
  31. package/{.ai/TACTICA-DEEP-DIVE.md → docs/tactica-deep-dive.md} +45 -2
  32. package/docs/tactica-pattern.md +1 -2
  33. package/docs/typed-lookup.md +337 -93
  34. package/package.json +6 -6
  35. package/src/api/types/index.ts +14 -4
  36. package/src/descriptors/types/index.ts +63 -58
  37. package/src/index.ts +103 -12
  38. package/src/types/index.ts +241 -41
  39. package/.ai/CODE.md +0 -111
  40. package/.ai/TACTICA-RULES.md +0 -103
  41. package/.ai/async_init.md +0 -94
  42. package/.ai/rules/REMINDERS.md +0 -63
  43. package/.ai/rules-skill/lookup-typed.md +0 -82
  44. package/.ai/rules-skill/proxy-architecture.md +0 -63
  45. package/.ai/task-templates/new-feature.md +0 -46
  46. /package/.ai/{rules-skill/code-style.md → rules-code-style.md} +0 -0
  47. /package/.ai/{rules-skill/define-patterns.md → rules-define-patterns.md} +0 -0
  48. /package/.ai/{rules-skill/ecosystem.md → rules-ecosystem.md} +0 -0
  49. /package/.ai/{rules-skill/error-system.md → rules-error-system.md} +0 -0
  50. /package/.ai/{rules-skill/hooks.md → rules-hooks.md} +0 -0
  51. /package/.ai/{rules-skill/philosophy.md → rules-philosophy.md} +0 -0
  52. /package/.ai/{rules-skill/testing.md → rules-testing.md} +0 -0
@@ -22,7 +22,7 @@ const {
22
22
 
23
23
  // here is TypesCollection.define() method
24
24
  import {
25
- define, lookup, type TypesMap
25
+ define, lookup, type TypesMap
26
26
  } from '../../api/types';
27
27
 
28
28
  import * as hooksAPI from '../../api/hooks';
@@ -35,27 +35,27 @@ const {
35
35
 
36
36
  const typesCollections = new Map();
37
37
 
38
- const TypesCollection = function ( _config: Record<string, unknown> ) {
39
-
38
+ const TypesCollection = function (_config: Record<string, unknown>) {
39
+
40
40
  const self = this;
41
41
 
42
42
  const subtypes = new Map();
43
43
 
44
44
  // default config is less important than types collection config
45
45
  const config = defaultOptionsKeys.reduce(
46
- ( o: Record<string, unknown>, key: string ) => {
46
+ (o: Record<string, unknown>, key: string) => {
47
47
  const value = _config[ key ];
48
48
  const option = defaultOptions[ key ];
49
49
  const t_conf = typeof value;
50
50
  const t_opts = typeof option;
51
- if ( t_conf === t_opts ) {
51
+ if (t_conf === t_opts) {
52
52
  o[ key ] = value;
53
53
  } else {
54
54
  o[ key ] = option;
55
55
  }
56
56
  return o;
57
57
  },
58
- {}
58
+ {}
59
59
  );
60
60
 
61
61
  odp(
@@ -65,7 +65,7 @@ const TypesCollection = function ( _config: Record<string, unknown> ) {
65
65
  get () {
66
66
  return config;
67
67
  }
68
- }
68
+ }
69
69
  );
70
70
 
71
71
  odp(
@@ -73,13 +73,13 @@ const TypesCollection = function ( _config: Record<string, unknown> ) {
73
73
  Symbol.hasInstance,
74
74
  {
75
75
  get () {
76
- const result = ( instance: { [SymbolConstructorName]?: string } ) => {
76
+ const result = (instance: { [SymbolConstructorName]?: string }) => {
77
77
  const checkResult = instance[ SymbolConstructorName ] === MNEMONICA;
78
78
  return checkResult;
79
79
  };
80
80
  return result;
81
81
  }
82
- }
82
+ }
83
83
  );
84
84
 
85
85
  odp(
@@ -89,7 +89,7 @@ const TypesCollection = function ( _config: Record<string, unknown> ) {
89
89
  get () {
90
90
  return subtypes;
91
91
  }
92
- }
92
+ }
93
93
  );
94
94
 
95
95
  // For instanceof MNEMOSYNE
@@ -98,11 +98,11 @@ const TypesCollection = function ( _config: Record<string, unknown> ) {
98
98
  MNEMOSYNE,
99
99
  {
100
100
  get () {
101
- // returning proxy
102
- const result = typesCollections.get( self );
101
+ // returning proxy
102
+ const result = typesCollections.get(self);
103
103
  return result;
104
104
  }
105
- }
105
+ }
106
106
  );
107
107
 
108
108
  // For instanceof MNEMOSYNE
@@ -111,14 +111,14 @@ const TypesCollection = function ( _config: Record<string, unknown> ) {
111
111
  MNEMOSYNE,
112
112
  {
113
113
  get () {
114
- // returning proxy
115
- const result = typesCollections.get( self );
114
+ // returning proxy
115
+ const result = typesCollections.get(self);
116
116
  return result;
117
117
  }
118
- }
118
+ }
119
119
  );
120
120
 
121
- const hooks = Object.create( null );
121
+ const hooks = Object.create(null);
122
122
  odp(
123
123
  this,
124
124
  'hooks',
@@ -126,7 +126,7 @@ const TypesCollection = function ( _config: Record<string, unknown> ) {
126
126
  get () {
127
127
  return hooks;
128
128
  }
129
- }
129
+ }
130
130
  );
131
131
 
132
132
  } as _Internal_TC_<object>;
@@ -136,10 +136,10 @@ odp(
136
136
  MNEMONICA,
137
137
  {
138
138
  get () {
139
- const result = typesCollections.get( this );
139
+ const result = typesCollections.get(this);
140
140
  return result;
141
141
  }
142
- }
142
+ }
143
143
  );
144
144
 
145
145
  odp(
@@ -154,7 +154,7 @@ odp(
154
154
  constructHandlerOrConfig?: CallableFunction | object,
155
155
  config?: object
156
156
  ) {
157
- // this - define function of mnemonica interface
157
+ // this - define function of mnemonica interface
158
158
  const defineResult = define.call(
159
159
  this as unknown,
160
160
  subtypes as TypesMap,
@@ -167,7 +167,7 @@ odp(
167
167
  return result;
168
168
  },
169
169
  enumerable : true
170
- }
170
+ }
171
171
  );
172
172
 
173
173
  odp(
@@ -180,15 +180,15 @@ odp(
180
180
  TypeNestedPath: string
181
181
  ) {
182
182
  const lookupResult = lookup.call(
183
- this.subtypes as unknown as TypesMap,
184
- TypeNestedPath
183
+ this.subtypes as unknown as TypesMap,
184
+ TypeNestedPath
185
185
  );
186
186
  return lookupResult;
187
- }.bind( this );
187
+ }.bind(this);
188
188
  return result;
189
189
  },
190
190
  enumerable : true
191
- }
191
+ }
192
192
  );
193
193
 
194
194
  odp(
@@ -196,21 +196,21 @@ odp(
196
196
  'registerHook',
197
197
  {
198
198
  get (this: TypesCollection) {
199
-
199
+
200
200
  const self = this;
201
- const result = function ( hookName: string, hookCallback: hook ) {
202
- // return proto.registerHook.call( typesCollections.get( self ), hookName, hookCallback );
201
+ const result = function (hookName: string, hookCallback: hook) {
202
+ // return proto.registerHook.call( typesCollections.get( self ), hookName, hookCallback );
203
203
  const hookResult = registerHook.call(
204
204
  self,
205
205
  hookName,
206
- hookCallback
206
+ hookCallback
207
207
  );
208
208
  return hookResult;
209
- }.bind( this );
209
+ }.bind(this);
210
210
  return result;
211
211
  },
212
212
  enumerable : true
213
- }
213
+ }
214
214
  );
215
215
 
216
216
  odp(
@@ -218,17 +218,17 @@ odp(
218
218
  'invokeHook',
219
219
  {
220
220
  get (this: TypesCollection) {
221
- const result = ( hookName: string, opts: { [index: string]: unknown } ) => {
221
+ const result = (hookName: string, opts: { [index: string]: unknown }) => {
222
222
  const hookResult = invokeHook.call(
223
- typesCollections.get( this ),
223
+ typesCollections.get(this),
224
224
  hookName,
225
- opts as hooksOpts
225
+ opts as hooksOpts
226
226
  );
227
227
  return hookResult;
228
228
  };
229
229
  return result;
230
230
  }
231
- }
231
+ }
232
232
  );
233
233
 
234
234
  odp(
@@ -236,16 +236,16 @@ odp(
236
236
  'registerFlowChecker',
237
237
  {
238
238
  get (this: TypesCollection) {
239
- const result = ( flowCheckerCallback: () => unknown ) => {
239
+ const result = (flowCheckerCallback: () => unknown) => {
240
240
  const checkerResult = registerFlowChecker.call(
241
- typesCollections.get( this ),
242
- flowCheckerCallback
241
+ typesCollections.get(this),
242
+ flowCheckerCallback
243
243
  );
244
244
  return checkerResult;
245
245
  };
246
246
  return result;
247
247
  }
248
- }
248
+ }
249
249
  );
250
250
 
251
251
 
@@ -255,57 +255,57 @@ interface TypesCollectionTarget {
255
255
  }
256
256
 
257
257
  const typesCollectionProxyHandler = {
258
- get ( target: TypesCollectionTarget, prop: string ) {
259
- if ( target.subtypes.has( prop ) ) {
258
+ get (target: TypesCollectionTarget, prop: string) {
259
+ if (target.subtypes.has(prop)) {
260
260
  // access to subtype
261
261
  // for new call or defining new type
262
- const subtypeResult = target.subtypes.get( prop );
262
+ const subtypeResult = target.subtypes.get(prop);
263
263
  return subtypeResult;
264
264
  }
265
- if ( prop === 'define' ) {
265
+ if (prop === 'define') {
266
266
  // will hopefully define new type
267
267
  return target.define;
268
268
  }
269
269
  const reflectResult = Reflect.get(
270
270
  target,
271
- prop
271
+ prop
272
272
  );
273
273
  return reflectResult;
274
274
  },
275
- set ( target: TypesCollectionTarget, TypeName: string, Constructor: FunctionConstructor ) {
275
+ set (target: TypesCollectionTarget, TypeName: string, Constructor: FunctionConstructor) {
276
276
  target.define(
277
277
  TypeName,
278
- Constructor
278
+ Constructor
279
279
  );
280
280
  return true;
281
281
  },
282
282
  // Object.prototype.hasOwnProperty.call
283
- getOwnPropertyDescriptor ( target: TypesCollectionTarget, prop: string ) {
284
- if ( target.subtypes.has( prop ) ) {
283
+ getOwnPropertyDescriptor (target: TypesCollectionTarget, prop: string) {
284
+ if (target.subtypes.has(prop)) {
285
285
  const descriptorResult = {
286
286
  configurable : true,
287
287
  enumerable : true,
288
288
  writable : false,
289
- value : target.subtypes.get( prop )
289
+ value : target.subtypes.get(prop)
290
290
  };
291
291
  return descriptorResult;
292
292
  }
293
- const ownPropResult = Reflect.getOwnPropertyDescriptor( target, prop );
293
+ const ownPropResult = Reflect.getOwnPropertyDescriptor(target, prop);
294
294
  return ownPropResult;
295
295
  }
296
296
  };
297
297
 
298
- const createTypesCollection = ( config: Record<string, unknown> = {} ) => {
298
+ const createTypesCollection = (config: Record<string, unknown> = {}) => {
299
299
 
300
- const typesCollection = new TypesCollection( config );
300
+ const typesCollection = new TypesCollection(config);
301
301
  const typesCollectionProxy = new Proxy(
302
302
  typesCollection,
303
- typesCollectionProxyHandler
303
+ typesCollectionProxyHandler
304
304
  );
305
305
 
306
306
  typesCollections.set(
307
307
  typesCollection,
308
- typesCollectionProxy
308
+ typesCollectionProxy
309
309
  );
310
310
 
311
311
  return typesCollectionProxy;
@@ -320,13 +320,18 @@ odp(
320
320
  get () {
321
321
  return true;
322
322
  }
323
- }
323
+ }
324
324
  );
325
325
 
326
326
  export const types = {
327
327
  get createTypesCollection (): CreateTypesCollectionFunction {
328
- const result = function ( config: Record<string, unknown> = {} ): TypesCollection {
329
- const collectionResult = createTypesCollection( config ) as TypesCollection;
328
+ const result = <
329
+ T extends object = {},
330
+ Parent extends object = object
331
+ > (
332
+ config: Record<string, unknown> = {}
333
+ ): TypesCollection<T, Parent> => {
334
+ const collectionResult = createTypesCollection(config) as TypesCollection<T, Parent>;
330
335
  return collectionResult;
331
336
  };
332
337
  return result;
package/src/index.ts CHANGED
@@ -15,7 +15,11 @@ import type {
15
15
  TypeAbsorber,
16
16
  MnemonicaModule,
17
17
  InstanceResult,
18
- Merge
18
+ Merge,
19
+ TypeLookup,
20
+ LookupResult,
21
+ RegistryHolderBase,
22
+ StoredConstructor
19
23
  } from './types';
20
24
 
21
25
  import TypesUtils from './api/utils/index';
@@ -25,11 +29,27 @@ export const {
25
29
  } = TypesUtils;
26
30
 
27
31
  export type {
28
- IDEF, TypeConstructor, TypeConstructorBase,
29
- InstanceOfTypeRegistry, LiteralKeysOf, ParentPath, PathOfInstance,
30
- AllParentPrefixes, ParentPathOfInstance,
31
- _Internal_TC_, Proto, ProtoFlat,
32
- hooksOpts, hook, hooksTypes, TypesCollection
32
+ IDEF,
33
+ TypeConstructor,
34
+ TypeConstructorBase,
35
+ Proto,
36
+ ProtoFlat,
37
+ constructorOptions,
38
+ hooksOpts,
39
+ hook,
40
+ hooksTypes,
41
+ IDefinitorInstance,
42
+ InstanceResult,
43
+ Merge,
44
+ Constructor,
45
+ DecoratedClass,
46
+ TypeClass,
47
+ TypeAbsorber,
48
+ TypesCollection,
49
+ TypeLookup,
50
+ LookupResult,
51
+ RegistryOf,
52
+ MnemonicaModule,
33
53
  } from './types';
34
54
 
35
55
  /**
@@ -81,6 +101,28 @@ function checkThis(pointer: typeof mnemonica | typeof exports | unknown): boolea
81
101
 
82
102
 
83
103
  // Define function using TypeAbsorber interface with proper type casting
104
+ export function define <
105
+ Reg extends object,
106
+ Parent extends object,
107
+ Path extends string,
108
+ const Name extends string,
109
+ N extends object,
110
+ Args extends unknown[],
111
+ F extends Proto<Parent, N> = Proto<Parent, N>,
112
+ ChildPath extends string = Path extends '' ? Name : `${Path}.${Name}`
113
+ >(
114
+ // explicit-source form: define(source, name, handler, config?)
115
+ // mirrors RegistryHolderBase.define; semantics follow the source object
116
+ source: RegistryHolderBase<Reg, Parent, Path>,
117
+ TypeName: Name,
118
+ constructHandler?: IDEF<N, Args>,
119
+ config?: constructorOptions
120
+ ): IDefinitorInstance<
121
+ F,
122
+ InstanceResult<F>,
123
+ Reg & Record<ChildPath, StoredConstructor<F, ChildPath>>,
124
+ ChildPath
125
+ >;
84
126
  export function define <
85
127
  T extends object,
86
128
  P extends object = object,
@@ -93,14 +135,44 @@ export function define <
93
135
  // Allow both strict IDEF and more flexible function signatures
94
136
  constructHandler?: IDEF<T> | CallableFunction | NewableFunction | object | boolean,
95
137
  config?: constructorOptions,
138
+ ): R;
139
+ export function define <
140
+ T extends object,
141
+ P extends object = object,
142
+ N extends Proto<P, T> = Proto<P, T>,
143
+ R extends IDefinitorInstance<N> = IDefinitorInstance<N>,
144
+ >(
145
+ this: unknown,
146
+ TypeNameOrSource?: string | CallableFunction | NewableFunction | RegistryHolderBase<object, object, string>,
147
+ constructHandlerOrName?: IDEF<T> | CallableFunction | NewableFunction | object | boolean | string,
148
+ configOrHandler?: constructorOptions | IDEF<T> | CallableFunction | NewableFunction | object | boolean,
149
+ config?: constructorOptions,
96
150
  ): R {
151
+
152
+ // explicit-source form: define(source, name, handler, config?)
153
+ // the source may be a TypesCollection (object) or a TypeProxy (function),
154
+ // so detection is: has a callable .define AND the next arg is a string name
155
+ const mayBeSource = (
156
+ (typeof TypeNameOrSource === 'object' && TypeNameOrSource !== null) ||
157
+ typeof TypeNameOrSource === 'function'
158
+ ) && typeof (TypeNameOrSource as { define?: unknown }).define === 'function';
159
+ if (mayBeSource && typeof constructHandlerOrName === 'string') {
160
+ const source = TypeNameOrSource as unknown as { define: TypeAbsorber };
161
+ const sourceDefineResult = source.define(
162
+ constructHandlerOrName,
163
+ configOrHandler as IDEF<T>,
164
+ config
165
+ ) as unknown as R;
166
+ return sourceDefineResult;
167
+ }
168
+
97
169
  const types = checkThis(this) ? defaultTypes : this || defaultTypes;
98
170
  // Type assertion needed because TypesCollectionProxy is a Proxy
99
171
  const defineResult = (types as { define: TypeAbsorber })
100
172
  .define(
101
- TypeName as string,
102
- constructHandler as IDEF<T>,
103
- config
173
+ TypeNameOrSource as string,
174
+ constructHandlerOrName as IDEF<T>,
175
+ configOrHandler as constructorOptions
104
176
  ) as unknown as R;
105
177
  return defineResult;
106
178
  }
@@ -109,14 +181,33 @@ export function lookup<const K extends keyof TypeRegistry>(
109
181
  this: unknown,
110
182
  TypeNestedPath: K
111
183
  ): TypeRegistry[K];
184
+ export function lookup<Reg extends object, const K extends keyof Reg & string>(
185
+ // explicit-source form: lookup(source, path)
186
+ // resolves against the registry carried by a builder/collection value
187
+ source: { lookup: TypeLookup<Reg> },
188
+ TypeNestedPath: K
189
+ ): LookupResult<Reg, K>;
112
190
  export function lookup(this: unknown, TypeNestedPath: string): TypeClass | undefined;
113
191
  export function lookup(
114
- this: unknown,
192
+ source: { lookup: (path: string) => TypeClass | undefined },
115
193
  TypeNestedPath: string
116
- ): TypeClass | undefined {
194
+ ): TypeClass | undefined;
195
+ export function lookup(
196
+ this: unknown,
197
+ arg1: unknown,
198
+ arg2?: unknown
199
+ ): unknown {
200
+
201
+ // explicit-source form: lookup(source, path)
202
+ if (typeof arg1 !== 'string' && typeof arg2 === 'string') {
203
+ const source = arg1 as { lookup: (path: string) => TypeClass | undefined };
204
+ const sourceResult = source.lookup(arg2);
205
+ return sourceResult;
206
+ }
207
+
117
208
  const types = checkThis(this) ? defaultTypes : this || defaultTypes;
118
209
  // Type assertion needed because TypesCollectionProxy is a Proxy
119
- const lookupResult = (types as { lookup: (path: string) => TypeClass | undefined }).lookup(TypeNestedPath);
210
+ const lookupResult = (types as { lookup: (path: string) => TypeClass | undefined }).lookup(arg1 as string);
120
211
  return lookupResult;
121
212
  }
122
213