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
@@ -1,63 +0,0 @@
1
- # Critical Reminders for AI Agents
2
-
3
- ## Before Writing Any Code
4
-
5
- ### 1. Type vs Interface - CRITICAL
6
- **ALWAYS** check AGENTS.md section "CRITICAL: Type vs Interface vs Instance" before defining types:
7
-
8
- ```typescript
9
- // ✅ CORRECT - Instance data uses TYPE
10
- type UserData = { name: string; age: number; };
11
-
12
- // ❌ WRONG - Instance is NOT an interface!
13
- interface UserData { name: string; age: number; }
14
-
15
- // ✅ CORRECT - Constructor/Prototype contract uses INTERFACE
16
- interface MnemonicaInstance {
17
- extract(): object;
18
- parent(): object | null;
19
- }
20
- ```
21
-
22
- **Rule of thumb:**
23
- - **Interface** = Black-box contract (constructors, callables, `implements`)
24
- - **Type** = Runtime data structure/shape (instances, POJOs)
25
-
26
- ### 2. Indentation - TABS ONLY
27
- - **NEVER** use spaces for indentation
28
- - Tab width: 4
29
- - Enforced by eslint
30
-
31
- ### 3. Function Spacing
32
- ```typescript
33
- function myFunc () { } // ✅ Space before parentheses
34
- function myFunc() { } // ❌ Wrong
35
- ```
36
-
37
- ### 4. Key Spacing
38
- ```typescript
39
- { key: value } // ✅ Space after colon
40
- { key:value } // ❌ Wrong
41
- ```
42
-
43
- ### 5. Before Each Task
44
- 1. Read AGENTS.md if context seems incomplete
45
- 2. Check existing code patterns in the same directory
46
- 3. Run `npm run build` before completing (core/ directory)
47
- 4. Run `npm run test:cov` for coverage validation (core/ directory)
48
-
49
- ## Quick Reference
50
-
51
- | Decision | Check |
52
- |----------|-------|
53
- | Type vs Interface | AGENTS.md |
54
- | Build commands | AGENTS.md |
55
- | Code style | AGENTS.md |
56
- | Error handling | AGENTS.md |
57
- | Context condensing | CONTEXT-CONDENSING.md |
58
-
59
- ## File-Specific Notes
60
-
61
- - `core/src/types/index.ts` - Export types here, use `type` for instances
62
- - `core/src/api/types/*.ts` - Internal implementations, check existing patterns
63
- - Any `provider.ts` files - Check AGENTS.md for type/interface rules
@@ -1,82 +0,0 @@
1
- ---
2
- name: mnemonica-lookup-typed
3
- description: |
4
- Type-safe lookup with lookup() and TypeRegistry augmentation.
5
- Use when the user asks about lookup, TypeRegistry, tactica-generated types,
6
- declaration merging, or type-safe constructor retrieval in mnemonica.
7
- metadata:
8
- tags: [mnemonica, lookup, types, tactica, declaration-merging]
9
- ---
10
-
11
- # Type-Safe Lookup with `lookup()`
12
-
13
- ## `lookup()` with and without `TypeRegistry` augmentation
14
-
15
- ```typescript
16
- import { lookup } from 'mnemonica';
17
-
18
- // Without augmentation: returns TypeClass | undefined
19
- const SomeType = lookup('SomeType');
20
- const instance = new SomeType({ ... }); // no type safety
21
-
22
- // With augmentation: returns the typed constructor
23
- const SomeType = lookup('SomeType');
24
- const instance = new SomeType({ ... }); // TypeScript knows the signature
25
- ```
26
-
27
- ## TypeRegistry Pattern
28
-
29
- The default `TypeRegistry` is an empty interface. Application code or
30
- `@mnemonica/tactica` augments it through TypeScript declaration merging.
31
-
32
- ```typescript
33
- // In mnemonica core
34
- export interface TypeRegistry {
35
- // Intentionally empty. Augment via declaration merging.
36
- }
37
-
38
- // Generated by tactica in .tactica/registry.ts
39
- declare module 'mnemonica' {
40
- interface TypeRegistry {
41
- 'UserType': TypeConstructor<UserTypeInstance>;
42
- 'Parent.SubType': TypeConstructor<SubTypeInstance>;
43
- }
44
- }
45
- ```
46
-
47
- ## Unaugmented vs Augmented `TypeRegistry`
48
-
49
- The axis that actually matters is whether `TypeRegistry` has been augmented for your types — not whether tactica is involved. Tactica is one way to produce the augmentation; hand-writing it is another. Runtime behaviour is identical either way.
50
-
51
- | Feature | Unaugmented `TypeRegistry` | Augmented `TypeRegistry` |
52
- |---------|---------------------------|--------------------------|
53
- | Constructor retrieval | `lookup('Name')` returns `TypeClass \| undefined` | `lookup('Name')` returns typed constructor |
54
- | Type safety | Runtime only | Compile-time + runtime |
55
- | Registry default | Empty interface | Per-key constructor signatures |
56
- | Instance properties | `any` / `unknown` | Fully typed |
57
-
58
- Two ways to augment: hand-written `.d.ts` (small projects, learning) or [`@mnemonica/tactica`](https://www.npmjs.com/package/@mnemonica/tactica) (auto-generated, recommended for non-trivial projects). See [`../../docs/typed-lookup.md`](../../docs/typed-lookup.md) for both paths side by side.
59
-
60
- ## Before/After: Adding a Type to TypeRegistry
61
-
62
- **Before** (untyped lookup)
63
- ```typescript
64
- const UserType = lookup('UserType');
65
- const user = new UserType({ name: 'John' });
66
- // user is typed as object — no IntelliSense for properties
67
- ```
68
-
69
- **After** (TypeRegistry augmented — either hand-written or tactica-generated; runtime is identical)
70
- ```typescript
71
- // In a .d.ts file (hand-written) or .tactica/registry.ts (tactica-generated)
72
- declare module 'mnemonica' {
73
- interface TypeRegistry {
74
- 'UserType': new (...args: [UserData]) => UserTypeInstance;
75
- }
76
- }
77
-
78
- // In application code
79
- const UserType = lookup('UserType');
80
- const user = new UserType({ name: 'John' });
81
- // user is fully typed as UserTypeInstance
82
- ```
@@ -1,63 +0,0 @@
1
- ---
2
- name: mnemonica-proxy-architecture
3
- description: |
4
- The Proxy-based construction pipeline: TypeProxy, InstanceCreator, Mnemosyne,
5
- and createInstanceModificator. Use when the user asks about how mnemonica
6
- creates instances, the prototype chain, TypeProxy, InstanceCreator, or the
7
- internal construction mechanism.
8
- metadata:
9
- tags: [mnemonica, proxy, architecture, construction, prototype]
10
- ---
11
-
12
- # Proxy-Based Architecture
13
-
14
- ## Construction Pipeline (8 Stages)
15
-
16
- ```
17
- define(TypeName, ctor) → new TypeDescriptor() → new TypeProxy()
18
- │
19
- ▼
20
- new InstanceCreator(type, parent, args)
21
- │
22
- ▼
23
- makeInstanceModificator(self)
24
- │
25
- ▼
26
- ModificationConstructor.call(parent, ModificatorType, proto, _addProps)
27
- │
28
- ▼
29
- user constructor runs (new ModificatorType(...args))
30
- │
31
- ▼
32
- postProcessing() → invokePostHooks()
33
- ```
34
-
35
- ## Key Components
36
-
37
- ### TypeProxy
38
- Wraps type constructors. Handles property access, `.define()`, `.lookup()`,
39
- and subtype resolution.
40
-
41
- ### InstanceCreator
42
- Orchestrates the full instance construction lifecycle:
43
- 1. **Setup** — extract type, config, prepare ModificationConstructor
44
- 2. **Stack** — collect creation stack if `submitStack` or chained
45
- 3. **blockErrors** — if parent is Error, optionally block construction
46
- 4. **Pre-hooks** — invoke `preCreation` hooks on collection and type
47
- 5. **Build** — `makeInstanceModificator()` wires prototype chain
48
- 6. **Construct** — `new InstanceModificator(...args)` runs user constructor
49
- 7. **Async** — if result is Promise, attach awaiter and subtype factories
50
- 8. **Post-proc** — validate inheritance, set `__self__`, invoke `postCreation` hooks
51
-
52
- ### Mnemosyne
53
- Handles instance method access via Proxy. Provides:
54
- - `extract()` — get all enumerable properties
55
- - `pick(...keys)` — select specific properties
56
- - `parent()` — traverse prototype chain
57
- - `fork(...args)` — create new instance with same or different args
58
- - `clone` — alias for fork()
59
-
60
- ### createInstanceModificator (ModificationConstructor)
61
- The default ModificationConstructor that wires the prototype chain by creating
62
- a Mnemosyne object inheriting from the parent instance, attaching internal props,
63
- and linking `ModificatorType.prototype` to it.
@@ -1,46 +0,0 @@
1
- # Task Template: New Feature Implementation
2
-
3
- ## Pre-Flight Checklist
4
-
5
- - [ ] Read AGENTS.md section "CRITICAL: Type vs Interface vs Instance" (lines 244-279)
6
- - [ ] Read AGENTS.md section "Build & Test Commands" (lines 102-116)
7
- - [ ] Check existing code patterns in the target directory
8
- - [ ] Run `npm run build` to ensure clean baseline (core/ directory)
9
-
10
- ## Implementation Steps
11
-
12
- 1. **Design Phase**
13
- - [ ] Define types (use `type` for instances, `interface` for constructors/contracts)
14
- - [ ] Check REMINDERS.md in `.ai/rules/`
15
-
16
- 2. **Coding Phase**
17
- - [ ] Follow indentation: TABS ONLY (width 4)
18
- - [ ] Function spacing: `function myFunc () { }`
19
- - [ ] Key spacing: `{ key: value }`
20
-
21
- 3. **Testing Phase**
22
- - [ ] Run `npm run test:cov` (validates build + 100% coverage)
23
- - [ ] Verify no ESLint warnings
24
- - [ ] Read and analyse full content of edited file as if it would be code-review
25
-
26
- 4. **Completion**
27
- - [ ] Update TODO list
28
- - [ ] Run final build
29
- - [ ] Use attempt_completion tool
30
-
31
- ## Context Condensing Protocol
32
-
33
- **CRITICAL:** If you notice yourself forgetting established patterns:
34
-
35
- → **READ** `.ai/rules/CONTEXT-CONDENSING.md` immediately
36
-
37
- ## Quick References
38
-
39
- | Check | Location |
40
- |-------|----------|
41
- | Type vs Interface | AGENTS.md |
42
- | Build commands | AGENTS.md |
43
- | Code style | AGENTS.md |
44
- | Error handling | AGENTS.md |
45
- | Lessons Learned | AGENTS.md |
46
- | Context condensing | CONTEXT-CONDENSING.md |
File without changes