mnemonica 1.2.3 → 1.2.7
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/FOR_HUMANS.md +160 -125
- package/README.md +70 -249
- package/build/api/types/index.js +18 -12
- package/build/index.js +6 -2
- package/docs/UTILS.md +97 -8
- package/docs/decorate.md +1 -1
- package/docs/empathy-in-ai.md +20 -10
- package/docs/prototype-chain.md +8 -7
- package/docs/typed-lookup.md +195 -5
- package/docs/typeomatica.md +8 -345
- package/package.json +6 -10
- package/src/api/types/index.ts +33 -20
- package/src/index.ts +12 -1
- package/.ai/AGENTS.md +0 -151
- package/.ai/ARCHITECT.md +0 -110
- package/.ai/DEBUG.md +0 -178
- package/.ai/ONBOARDING.md +0 -189
- package/.ai/PROTOTYPE-CHAIN.md +0 -155
- package/.ai/mode-ask.md +0 -121
- package/.ai/mode-orchestrator.md +0 -141
- package/.ai/performance-vs-security.md +0 -395
- package/.ai/rules-async-constructors.md +0 -352
- package/.ai/rules-code-style.md +0 -95
- package/.ai/rules-coding.md +0 -246
- package/.ai/rules-context-condensing.md +0 -50
- package/.ai/rules-contributing.md +0 -227
- package/.ai/rules-define-patterns.md +0 -159
- package/.ai/rules-ecosystem.md +0 -140
- package/.ai/rules-error-system.md +0 -66
- package/.ai/rules-hooks.md +0 -46
- package/.ai/rules-instance-methods.md +0 -93
- package/.ai/rules-philosophy.md +0 -231
- package/.ai/rules-reminders.md +0 -19
- package/.ai/rules-testing.md +0 -66
- package/.ai/rules-type-system.md +0 -124
- package/.ai/theory-of-operations.md +0 -224
- package/AGENTS.md +0 -345
- package/CONTRIBUTING.md +0 -150
- package/SKILL.md +0 -114
- package/docs/ai-learning-trajectory.md +0 -141
- package/docs/purpose.md +0 -707
- package/docs/tactica-deep-dive.md +0 -629
- package/docs/tactica-pattern.md +0 -146
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# Context Condensing Protocol
|
|
2
|
-
|
|
3
|
-
**CRITICAL:** When conversation context condenses (you notice yourself forgetting established patterns):
|
|
4
|
-
|
|
5
|
-
## When This Happens
|
|
6
|
-
|
|
7
|
-
Context condenses when:
|
|
8
|
-
- Conversation becomes long (many tool calls)
|
|
9
|
-
- User says "you already know this" or "I explained this before"
|
|
10
|
-
- You find yourself asking questions that were already answered
|
|
11
|
-
- You revert to patterns that were previously corrected
|
|
12
|
-
- You forget about `raw*` types and start using complex casting
|
|
13
|
-
|
|
14
|
-
## Immediate Action Required
|
|
15
|
-
|
|
16
|
-
1. **STOP** - Do not continue implementing
|
|
17
|
-
2. **Re-read AGENTS.md files:**
|
|
18
|
-
- `AGENTS.md` in workspace root (if exists)
|
|
19
|
-
- `.ai/rules-coding.md`
|
|
20
|
-
3. **Check specific sections:**
|
|
21
|
-
- "CRITICAL: Type vs Interface vs Instance" (lines 244-279)
|
|
22
|
-
- "Lessons Learned from Recent Refactoring" (lines 99-191)
|
|
23
|
-
4. **Re-read** `.ai/rules-reminders.md`
|
|
24
|
-
5. **Review recent code** - Look at the last few files you edited to confirm patterns
|
|
25
|
-
6. **Resume** only after context is refreshed
|
|
26
|
-
|
|
27
|
-
## Warning Signs
|
|
28
|
-
|
|
29
|
-
| Sign | What You're Forgetting |
|
|
30
|
-
|------|----------------------|
|
|
31
|
-
| Using `(obj as unknown as {...}).Type` casting | Use `raw*` types instead |
|
|
32
|
-
| Adding `loadFromFile` to model classes | Actions belong in Registry (controller) |
|
|
33
|
-
| Re-reading files to find data | Store data during parsing (lineNumber, etc.) |
|
|
34
|
-
| Creating redundant types (typeEntry + rawTypeEntry) | Use single `raw*` naming |
|
|
35
|
-
| Forgetting space before parentheses `myFunc()` | Code style: `myFunc ()` |
|
|
36
|
-
| Using `;` after type definitions | Tactica types end with `}` not `;` |
|
|
37
|
-
|
|
38
|
-
## Quick Recovery
|
|
39
|
-
|
|
40
|
-
If you catch yourself making these mistakes:
|
|
41
|
-
|
|
42
|
-
1. Acknowledge to user: "My context condensed, re-reading rules..."
|
|
43
|
-
2. Read the relevant AGENTS.md sections
|
|
44
|
-
3. Fix your approach before continuing
|
|
45
|
-
|
|
46
|
-
## Prevention
|
|
47
|
-
|
|
48
|
-
- Read AGENTS.md **before** starting any significant work
|
|
49
|
-
- Check REMINDERS at start of each task
|
|
50
|
-
- When uncertain, ask: "Does this align with Lessons Learned?"
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: mnemonica-contributing
|
|
3
|
-
description: |
|
|
4
|
-
Behavioral guidelines for contributing to mnemonica.
|
|
5
|
-
Use when modifying mnemonica source code, adding features, fixing bugs,
|
|
6
|
-
or reviewing code. Covers: avoiding assumptions, simplicity, surgical
|
|
7
|
-
changes, and goal-driven execution with 100% coverage as success criteria.
|
|
8
|
-
Derived from Andrej Karpathy's LLM coding principles, adapted for
|
|
9
|
-
mnemonica's proxy-based architecture and type system.
|
|
10
|
-
metadata:
|
|
11
|
-
tags: [mnemonica, contributing, behavior, guidelines, karpathy]
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
# Contributing Guidelines
|
|
15
|
-
|
|
16
|
-
> **Tradeoff:** These guidelines bias toward caution over speed.
|
|
17
|
-
> For trivial tasks (typo fixes, obvious one-liners), use judgment.
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## 1. Think Before Coding
|
|
22
|
-
|
|
23
|
-
**Don't assume. Don't hide confusion. Surface tradeoffs.**
|
|
24
|
-
|
|
25
|
-
Before implementing, analyze the type graph impact:
|
|
26
|
-
|
|
27
|
-
- State your assumptions explicitly. If uncertain, ask.
|
|
28
|
-
- If multiple interpretations exist, present them — don't pick silently.
|
|
29
|
-
- If a simpler approach exists, say so. Push back when warranted.
|
|
30
|
-
- If something is unclear, stop. Name what's confusing. Ask.
|
|
31
|
-
|
|
32
|
-
### Mnemonica-Specific Checklist
|
|
33
|
-
|
|
34
|
-
Before modifying `src/types/index.ts` or the type system:
|
|
35
|
-
1. Does this change affect `Proto<P,T>` merging?
|
|
36
|
-
2. Does it break `_Internal_TC_` / `TypeConstructor` contracts?
|
|
37
|
-
3. Will the `TypeRegistry` augmentation (hand-written or tactica-generated) need to be updated?
|
|
38
|
-
4. Are subtypes in the Trie affected?
|
|
39
|
-
|
|
40
|
-
### Example: Hidden Assumptions
|
|
41
|
-
|
|
42
|
-
**User Request:** "Add a config option to TypeProxy"
|
|
43
|
-
|
|
44
|
-
**❌ Wrong** (assumes where to add, ignores Proxy handler compatibility)
|
|
45
|
-
```typescript
|
|
46
|
-
// Adds config to TypeProxy without checking handler compatibility
|
|
47
|
-
TypeProxy.prototype.set = function (_target, name, value) {
|
|
48
|
-
if (name === 'newConfig') { /* ... */ }
|
|
49
|
-
// ... existing code
|
|
50
|
-
};
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
**✅ Correct** (surfaces assumptions, checks impact)
|
|
54
|
-
```
|
|
55
|
-
Before implementing, I need to clarify:
|
|
56
|
-
|
|
57
|
-
1. **Scope**: Should this config be per-type or per-collection?
|
|
58
|
-
2. **Proxy compatibility**: TypeProxy handles `.get`, `.set`, `.construct`.
|
|
59
|
-
Adding config requires checking all three traps.
|
|
60
|
-
3. **Existing options**: `strictChain`, `blockErrors`, `awaitReturn`
|
|
61
|
-
already exist. Does this fit the pattern?
|
|
62
|
-
4. **TypeRegistry impact**: Will tactica need to regenerate types?
|
|
63
|
-
|
|
64
|
-
What's the use case — can an existing option cover it?
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
---
|
|
68
|
-
|
|
69
|
-
## 2. Simplicity First
|
|
70
|
-
|
|
71
|
-
**Minimum code that solves the problem. Nothing speculative.**
|
|
72
|
-
|
|
73
|
-
- No features beyond what was asked.
|
|
74
|
-
- No abstractions for single-use code.
|
|
75
|
-
- No "flexibility" or "configurability" that wasn't requested.
|
|
76
|
-
- No error handling for impossible scenarios.
|
|
77
|
-
- If you write 200 lines and it could be 50, rewrite it.
|
|
78
|
-
|
|
79
|
-
### Mnemonica-Specific: Respect the Proxy Architecture
|
|
80
|
-
|
|
81
|
-
The construction pipeline (`TypeProxy` → `InstanceCreator` → `Mnemosyne`) is already
|
|
82
|
-
sophisticated. Don't add wrapper layers.
|
|
83
|
-
|
|
84
|
-
**❌ Over-engineered**
|
|
85
|
-
```typescript
|
|
86
|
-
class TypeBuilder {
|
|
87
|
-
private name: string;
|
|
88
|
-
private handler?: CallableFunction;
|
|
89
|
-
private config?: constructorOptions;
|
|
90
|
-
|
|
91
|
-
withName(name: string) { this.name = name; return this; }
|
|
92
|
-
withHandler(handler: CallableFunction) { this.handler = handler; return this; }
|
|
93
|
-
withConfig(config: constructorOptions) { this.config = config; return this; }
|
|
94
|
-
|
|
95
|
-
build() {
|
|
96
|
-
return define(this.name, this.handler, this.config);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// 50 lines for: define('MyType', handler, config)
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
**✅ Simple**
|
|
104
|
-
```typescript
|
|
105
|
-
const MyType = define('MyType', function (this: MyType, data: Data) {
|
|
106
|
-
Object.assign(this, data);
|
|
107
|
-
});
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
### The Test
|
|
111
|
-
|
|
112
|
-
> "Would a senior engineer say this is overcomplicated?" If yes, simplify.
|
|
113
|
-
|
|
114
|
-
For mnemonica: "Does this respect the existing proxy architecture, or does it
|
|
115
|
-
add indirection that the framework already handles?"
|
|
116
|
-
|
|
117
|
-
---
|
|
118
|
-
|
|
119
|
-
## 3. Surgical Changes
|
|
120
|
-
|
|
121
|
-
**Touch only what you must. Clean up only your own mess.**
|
|
122
|
-
|
|
123
|
-
When editing existing code:
|
|
124
|
-
- Don't "improve" adjacent code, comments, or formatting.
|
|
125
|
-
- Don't refactor things that aren't broken.
|
|
126
|
-
- Match existing style, even if you'd do it differently.
|
|
127
|
-
- If you notice unrelated dead code, mention it — don't delete it.
|
|
128
|
-
|
|
129
|
-
When your changes create orphans:
|
|
130
|
-
- Remove imports/variables/functions that YOUR changes made unused.
|
|
131
|
-
- Don't remove pre-existing dead code unless asked.
|
|
132
|
-
|
|
133
|
-
### Mnemonica-Specific: Instance Chain Immutability
|
|
134
|
-
|
|
135
|
-
The prototype chain is fragile. Every changed line should trace directly to the
|
|
136
|
-
user's request.
|
|
137
|
-
|
|
138
|
-
**Critical rules:**
|
|
139
|
-
- Don't modify `tsconfig.json` or `eslint.config.js` without approval.
|
|
140
|
-
- Don't reformat files unrelated to the task.
|
|
141
|
-
- Don't change `Object.setPrototypeOf` patterns without explicit reason.
|
|
142
|
-
- Don't "improve" JSDoc comments in files you don't touch.
|
|
143
|
-
|
|
144
|
-
### The Test
|
|
145
|
-
|
|
146
|
-
> Every changed line should trace directly to the user's request.
|
|
147
|
-
|
|
148
|
-
For mnemonica: "Does this change affect the prototype chain of existing types?
|
|
149
|
-
If yes, is it necessary?"
|
|
150
|
-
|
|
151
|
-
---
|
|
152
|
-
|
|
153
|
-
## 4. Goal-Driven Execution
|
|
154
|
-
|
|
155
|
-
**Define success criteria. Loop until verified.**
|
|
156
|
-
|
|
157
|
-
Transform tasks into verifiable goals:
|
|
158
|
-
|
|
159
|
-
| Instead of... | Transform to... |
|
|
160
|
-
|---------------|-----------------|
|
|
161
|
-
| "Add a feature" | "Write tests, run `npm run test:cov`, achieve 100%" |
|
|
162
|
-
| "Fix the bug" | "Write a test that reproduces it, then make it pass" |
|
|
163
|
-
| "Refactor X" | "Ensure tests pass before and after" |
|
|
164
|
-
|
|
165
|
-
### Multi-Step Task Plan
|
|
166
|
-
|
|
167
|
-
```
|
|
168
|
-
1. [Analyze type impact] → verify: `npm run build` compiles
|
|
169
|
-
2. [Implement change] → verify: `npm run build` still passes
|
|
170
|
-
3. [Add tests] → verify: `npm run test:cov` shows 100% coverage
|
|
171
|
-
4. [Check style] → verify: `npm run lint` passes
|
|
172
|
-
5. [Review] → verify: Only requested lines changed
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
### Strong vs Weak Criteria
|
|
176
|
-
|
|
177
|
-
- **Weak:** "Make it work" → requires constant clarification
|
|
178
|
-
- **Strong:** "Add `strictChain` validation to `postProcessing`, test with
|
|
179
|
-
`ALREADY_DECLARED` and `WRONG_MODIFICATION_PATTERN`, verify 100% coverage" →
|
|
180
|
-
lets the agent loop independently
|
|
181
|
-
|
|
182
|
-
---
|
|
183
|
-
|
|
184
|
-
## How to Know It's Working
|
|
185
|
-
|
|
186
|
-
These guidelines are working if you see:
|
|
187
|
-
|
|
188
|
-
- **Fewer unnecessary changes in diffs** — Only requested changes appear
|
|
189
|
-
- **Fewer rewrites due to overcomplication** — Code is simple the first time
|
|
190
|
-
- **Clarifying questions come before implementation** — Not after mistakes
|
|
191
|
-
- **Clean, minimal PRs** — No drive-by refactoring or "improvements"
|
|
192
|
-
- **100% coverage maintained** — Tests verify every change
|
|
193
|
-
|
|
194
|
-
---
|
|
195
|
-
|
|
196
|
-
## New Feature Checklist
|
|
197
|
-
|
|
198
|
-
Folded in from the former `.ai/task-templates/new-feature.md`.
|
|
199
|
-
|
|
200
|
-
### Pre-Flight
|
|
201
|
-
|
|
202
|
-
- [ ] Read `AGENTS.md` (root) sections on type vs interface vs instance and build/test commands
|
|
203
|
-
- [ ] Check existing code patterns in the target directory
|
|
204
|
-
- [ ] Run `npm run build` to ensure a clean baseline
|
|
205
|
-
|
|
206
|
-
### Implementation
|
|
207
|
-
|
|
208
|
-
1. **Design**
|
|
209
|
-
- [ ] Define types (use `type` for instances, `interface` for constructors/contracts)
|
|
210
|
-
- [ ] Check `.ai/rules-reminders.md`
|
|
211
|
-
2. **Coding**
|
|
212
|
-
- [ ] Indentation: TABS ONLY (width 4)
|
|
213
|
-
- [ ] Function spacing: `function myFunc () { }`
|
|
214
|
-
- [ ] Key spacing: `{ key : value }` (colons aligned)
|
|
215
|
-
3. **Testing**
|
|
216
|
-
- [ ] Run `npm run test:cov` (validates build + 100% coverage)
|
|
217
|
-
- [ ] Verify no ESLint warnings
|
|
218
|
-
- [ ] Re-read the full content of each edited file as if it were a code review
|
|
219
|
-
4. **Completion**
|
|
220
|
-
- [ ] Update the TODO list
|
|
221
|
-
- [ ] Run the final build
|
|
222
|
-
|
|
223
|
-
### Context Condensing
|
|
224
|
-
|
|
225
|
-
**CRITICAL:** If you notice yourself forgetting established patterns:
|
|
226
|
-
|
|
227
|
-
→ **READ** `.ai/rules-context-condensing.md` immediately
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: mnemonica-define-patterns
|
|
3
|
-
description: |
|
|
4
|
-
Patterns for defining types and subtypes with mnemonica's define() function.
|
|
5
|
-
Use when the user asks about define(), creating types, subtype inheritance,
|
|
6
|
-
strictChain, blockErrors, awaitReturn, or type configuration options.
|
|
7
|
-
metadata:
|
|
8
|
-
tags: [mnemonica, define, types, subtypes, inheritance]
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
# Define Patterns
|
|
12
|
-
|
|
13
|
-
## The define() Function
|
|
14
|
-
|
|
15
|
-
`define(TypeName, constructHandler, config?)` creates a constructor with prototype
|
|
16
|
-
chain inheritance. The constructor has additional methods: `.define()`, `.lookup()`,
|
|
17
|
-
`.registerHook()`.
|
|
18
|
-
|
|
19
|
-
```typescript
|
|
20
|
-
const MyType = define('MyType', function (this: MyType, data: Data) {
|
|
21
|
-
Object.assign(this, data);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const SubType = MyType.define('SubType', function (this: SubType, extra: string) {
|
|
25
|
-
this.extra = extra;
|
|
26
|
-
});
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Functional vs Class-Based — Both Are Equally Supported
|
|
30
|
-
|
|
31
|
-
`define()` (functional) and `@decorate()` (class-based) are runtime equivalents. Choose based on the style of the surrounding codebase — never assume one is preferred over the other.
|
|
32
|
-
|
|
33
|
-
| | Functional (`define`) | Class-based (`@decorate`) |
|
|
34
|
-
|---|---|---|
|
|
35
|
-
| Define a type | `define('User', function(data) { ... })` | `@decorate() class User { constructor(data) { ... } }` |
|
|
36
|
-
| Define a subtype | `User.define('Admin', function() { ... })` | `@decorate(User) class Admin { ... }` |
|
|
37
|
-
| Create instance | `new User(data)` | `new User(data)` |
|
|
38
|
-
| Create subtype | `new user.Admin()` | `new user.Admin()` |
|
|
39
|
-
| Config options | third arg: `define('T', fn, config)` | first/second arg: `@decorate(Parent, config)` |
|
|
40
|
-
|
|
41
|
-
When working in a codebase that uses one style: **stay consistent with that style** rather than mixing.
|
|
42
|
-
|
|
43
|
-
## Calling Conventions
|
|
44
|
-
|
|
45
|
-
### 1. Modern (explicit name)
|
|
46
|
-
```typescript
|
|
47
|
-
define('UserType', function (this: UserType, data: UserData) {
|
|
48
|
-
Object.assign(this, data);
|
|
49
|
-
});
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### 2. Legacy (name from constructor)
|
|
53
|
-
```typescript
|
|
54
|
-
define(function UserType(this: UserType, data: UserData) {
|
|
55
|
-
Object.assign(this, data);
|
|
56
|
-
});
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### 3. Nested (dot-path)
|
|
60
|
-
```typescript
|
|
61
|
-
define('Parent.Child', function (this: Child, data: Data) {
|
|
62
|
-
Object.assign(this, data);
|
|
63
|
-
});
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Lazy definitions
|
|
67
|
-
|
|
68
|
-
Use `.lazy()` when the constructor must be resolved through a getter — for
|
|
69
|
-
example, to break a circular dependency or to defer constructor selection until
|
|
70
|
-
definition time. `.define()` no longer accepts an anonymous function as its
|
|
71
|
-
first argument; that form has moved to `.lazy()`.
|
|
72
|
-
|
|
73
|
-
### Unnamed (name from returned constructor)
|
|
74
|
-
```typescript
|
|
75
|
-
const LazyType = define('RootType', function () {})
|
|
76
|
-
.lazy(() => function LazySubType(this: LazySubType, data: LazyData) {
|
|
77
|
-
Object.assign(this, data);
|
|
78
|
-
});
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### Named (explicit type name)
|
|
82
|
-
```typescript
|
|
83
|
-
const NamedLazy = RootType.lazy('NamedLazy', () => function (data: NamedData) {
|
|
84
|
-
Object.assign(this, data);
|
|
85
|
-
});
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### Free-function form
|
|
89
|
-
```typescript
|
|
90
|
-
import { lazy } from 'mnemonica';
|
|
91
|
-
|
|
92
|
-
const LazyRoot = lazy('LazyRoot', () => class LazyRoot {
|
|
93
|
-
field: string;
|
|
94
|
-
constructor(field: string) {
|
|
95
|
-
this.field = field;
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
The getter is called once at definition time. The returned constructor is
|
|
101
|
-
registered exactly like a constructor passed directly to `define()`, and the
|
|
102
|
-
resulting type supports `.define()`, `.lazy()`, `.lookup()`, and subtype
|
|
103
|
-
chaining.
|
|
104
|
-
|
|
105
|
-
## Export root constructors only when needed; never export subtypes
|
|
106
|
-
|
|
107
|
-
Subtypes live on the parent constructor and on parent instances. Exporting a subtype splits the Trie and usually loses the parent part of the chain.
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
// WRONG
|
|
111
|
-
export const Admin = User.define('Admin', function (this: Admin, data: AdminData) {
|
|
112
|
-
Object.assign(this, data);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// RIGHT
|
|
116
|
-
User.define('Admin', function (this: Admin, data: AdminData) {
|
|
117
|
-
Object.assign(this, data);
|
|
118
|
-
});
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
Root constructors **may** be exported when tactica has generated standalone instance types that include the sub-constructor chain, so consumers can do `new user.Admin(...)`. Even then, `lookup('User')` is the safer default.
|
|
122
|
-
|
|
123
|
-
## Config Options
|
|
124
|
-
|
|
125
|
-
| Option | Default | Description |
|
|
126
|
-
|--------|---------|-------------|
|
|
127
|
-
| `strictChain` | `true` | Enforce subtype creation only from direct parent |
|
|
128
|
-
| `blockErrors` | `true` | Block construction if error exists in prototype chain |
|
|
129
|
-
| `submitStack` | `false` | Collect stack trace as `__stack__` property |
|
|
130
|
-
| `awaitReturn` | `true` | `await new Constructor()` must return a value |
|
|
131
|
-
| `asClass` | auto-detected | Force class mode detection |
|
|
132
|
-
|
|
133
|
-
## Instance Method Opt-In
|
|
134
|
-
|
|
135
|
-
Starting from v1.0.6, `extract()`, `pick()`, `parent()`, `fork()`, `exception()`,
|
|
136
|
-
`sibling()`, and `clone()` are **not** auto-injected on instances. Use the standalone
|
|
137
|
-
`utils` export, or attach the methods to the constructor's prototype before calling
|
|
138
|
-
`define()`.
|
|
139
|
-
|
|
140
|
-
## Before/After: strictChain
|
|
141
|
-
|
|
142
|
-
**Before** (strictChain: false — allows broken chains)
|
|
143
|
-
```typescript
|
|
144
|
-
const RootType = define('RootType', function () {});
|
|
145
|
-
const ChildType = RootType.define('ChildType', function () {}, { strictChain: false });
|
|
146
|
-
|
|
147
|
-
// This would succeed even if made from wrong parent
|
|
148
|
-
const wrong = new SomeOtherType();
|
|
149
|
-
const child = new ChildType.call(wrong); // chain corruption possible
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
**After** (strictChain: true — default, enforced)
|
|
153
|
-
```typescript
|
|
154
|
-
const RootType = define('RootType', function () {});
|
|
155
|
-
const ChildType = RootType.define('ChildType', function () {});
|
|
156
|
-
|
|
157
|
-
const root = new RootType();
|
|
158
|
-
const child = new root.ChildType(); // inherits correctly from root instance
|
|
159
|
-
```
|
package/.ai/rules-ecosystem.md
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: mnemonica-ecosystem
|
|
3
|
-
description: |
|
|
4
|
-
The mnemonica ecosystem: PACT framework, user personas, tool integration,
|
|
5
|
-
and collaboration modes. Use when the user asks about how mnemonica fits
|
|
6
|
-
into a larger workflow, who uses it, what tools integrate with it, or
|
|
7
|
-
the ecosystem architecture (tactica, strategy, mnemographica, topologica).
|
|
8
|
-
metadata:
|
|
9
|
-
tags: [mnemonica, ecosystem, pact, tools, integration]
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
# Ecosystem Overview
|
|
13
|
-
|
|
14
|
-
Mnemonica is not a single library — it is an ecosystem of tools for building
|
|
15
|
-
self-reflective, type-safe systems.
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## PACT Framework
|
|
20
|
-
|
|
21
|
-
PACT (People-Activities-Context-Technologies) describes how the ecosystem
|
|
22
|
-
supports different users.
|
|
23
|
-
|
|
24
|
-
### People (Personas)
|
|
25
|
-
|
|
26
|
-
| Persona | Goal | Needs | Skills |
|
|
27
|
-
|---------|------|-------|--------|
|
|
28
|
-
| **AI Agent Developer** | Build self-reflective, self-extending AI systems | Runtime type introspection, memory persistence, command execution | TypeScript, prototype chains, MCP protocols |
|
|
29
|
-
| **Application Developer** | Build robust inheritance-based applications | Type safety, IDE support, debugging tools | JavaScript/TypeScript, OOP patterns |
|
|
30
|
-
| **Library Maintainer** | Extend mnemonica with new features | Understanding internal architecture, test coverage | Advanced TypeScript, AST manipulation |
|
|
31
|
-
|
|
32
|
-
### Activities
|
|
33
|
-
|
|
34
|
-
| Activity | Who | Frequency | Complexity |
|
|
35
|
-
|----------|-----|-----------|------------|
|
|
36
|
-
| Define new types | All | High | Low |
|
|
37
|
-
| Navigate type hierarchy | AI Agent, App Dev | High | Medium |
|
|
38
|
-
| Debug prototype chains | All | Medium | High |
|
|
39
|
-
| Extend via MCP | AI Agent | Medium | High |
|
|
40
|
-
| Visualize inheritance | App Dev | Low | Low |
|
|
41
|
-
|
|
42
|
-
### Activity Flow: Type Definition
|
|
43
|
-
|
|
44
|
-
```
|
|
45
|
-
1. Write define() call
|
|
46
|
-
2. Tactica analyzes AST
|
|
47
|
-
3. Types generated in .tactica/
|
|
48
|
-
4. IDE provides autocomplete
|
|
49
|
-
5. Mnemographica visualizes
|
|
50
|
-
6. Strategy MCP exposes for AI
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### Context
|
|
54
|
-
|
|
55
|
-
#### Development Environments
|
|
56
|
-
|
|
57
|
-
| Environment | Tools |
|
|
58
|
-
|-------------|-------|
|
|
59
|
-
| **VS Code** | Mnemographica extension, Tactica CLI, Mnemonica Logger |
|
|
60
|
-
| **Runtime (Node.js)** | CDP Connection (port 9229), Strategy MCP (ports 9230/9231) |
|
|
61
|
-
|
|
62
|
-
#### Collaboration Modes
|
|
63
|
-
|
|
64
|
-
| Mode | Human | AI | Tools |
|
|
65
|
-
|------|-------|-----|-------|
|
|
66
|
-
| Solo Coding | Active | None | Tactica |
|
|
67
|
-
| AI Pairing | Active | Assistant | Strategy MCP |
|
|
68
|
-
| AI Autonomous | Supervisory | Active | Full ecosystem |
|
|
69
|
-
|
|
70
|
-
---
|
|
71
|
-
|
|
72
|
-
## Technology Stack
|
|
73
|
-
|
|
74
|
-
```
|
|
75
|
-
┌─────────────────────────────────────────┐
|
|
76
|
-
│ Mnemonica Ecosystem │
|
|
77
|
-
├─────────────────────────────────────────┤
|
|
78
|
-
│ mnemographica │ VS Code Extension │
|
|
79
|
-
│ tactica │ Type Generator/CLI │
|
|
80
|
-
│ strategy │ MCP Server │
|
|
81
|
-
│ topologica │ Module Loader │
|
|
82
|
-
│ mnemonica │ Core Runtime │
|
|
83
|
-
├─────────────────────────────────────────┤
|
|
84
|
-
│ Chrome Debug Protocol (CDP) │
|
|
85
|
-
│ Model Context Protocol (MCP) │
|
|
86
|
-
└─────────────────────────────────────────┘
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### Integration Points
|
|
90
|
-
|
|
91
|
-
1. **Tactica → VS Code**: CLI type generator
|
|
92
|
-
2. **Strategy → CDP**: Runtime evaluation
|
|
93
|
-
3. **Mnemographica → Strategy**: HTTP/WebSocket servers
|
|
94
|
-
4. **All → Topologica**: Module loading
|
|
95
|
-
|
|
96
|
-
---
|
|
97
|
-
|
|
98
|
-
## Design Principles
|
|
99
|
-
|
|
100
|
-
### 1. Progressive Disclosure
|
|
101
|
-
- Simple `define()` for beginners
|
|
102
|
-
- Advanced hooks for power users
|
|
103
|
-
- MCP tools for AI agents
|
|
104
|
-
|
|
105
|
-
### 2. Self-Hosting
|
|
106
|
-
- Extension uses mnemonica internally
|
|
107
|
-
- Types self-generate
|
|
108
|
-
- Documentation is executable
|
|
109
|
-
|
|
110
|
-
### 3. Inheritance as UI
|
|
111
|
-
- Tree view shows hierarchy
|
|
112
|
-
- Graph shows relationships
|
|
113
|
-
- Code navigation follows prototype chain
|
|
114
|
-
|
|
115
|
-
---
|
|
116
|
-
|
|
117
|
-
## Future: PACT eslint Rule
|
|
118
|
-
|
|
119
|
-
When implemented, a custom eslint rule will enforce:
|
|
120
|
-
|
|
121
|
-
```typescript
|
|
122
|
-
// ❌ ERROR: Instance data should use TYPE
|
|
123
|
-
interface UserData { name: string; }
|
|
124
|
-
|
|
125
|
-
// ✅ PASS: Instance uses TYPE
|
|
126
|
-
type UserData = { name: string; };
|
|
127
|
-
|
|
128
|
-
// ❌ ERROR: Constructor contract should use INTERFACE
|
|
129
|
-
type Runnable = { run(): void };
|
|
130
|
-
|
|
131
|
-
// ✅ PASS: Contract uses INTERFACE
|
|
132
|
-
interface Runnable { run(): void; }
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
---
|
|
136
|
-
|
|
137
|
-
## References
|
|
138
|
-
|
|
139
|
-
- [Wikipedia: PACT (interaction design)](https://en.wikipedia.org/wiki/PACT_%28interaction_design%29)
|
|
140
|
-
- `strategy/README.md` — MCP architecture
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: mnemonica-error-system
|
|
3
|
-
description: |
|
|
4
|
-
Error handling in mnemonica: BASE_MNEMONICA_ERROR, constructError, stack
|
|
5
|
-
cleaning, and error constructor quirks. Use when the user asks about errors,
|
|
6
|
-
WRONG_MODIFICATION_PATTERN, ALREADY_DECLARED, or error handling in mnemonica.
|
|
7
|
-
metadata:
|
|
8
|
-
tags: [mnemonica, errors, stack, exceptions]
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
# Error System
|
|
12
|
-
|
|
13
|
-
## BASE_MNEMONICA_ERROR
|
|
14
|
-
|
|
15
|
-
All errors extend from `BASE_MNEMONICA_ERROR` which provides:
|
|
16
|
-
- Stack cleaning via configurable regex filters
|
|
17
|
-
- Additional stack prepending
|
|
18
|
-
- BaseStack preservation
|
|
19
|
-
|
|
20
|
-
## Error Data Lives in Props, Not on the Error Object
|
|
21
|
-
|
|
22
|
-
Mnemonica errors are plain `Error` objects: only `.message` and `.stack` are
|
|
23
|
-
own properties. All mnemonica-specific data (`args`, `originalError`,
|
|
24
|
-
`instance`, `exceptionReason`, `reasons`, `surplus`, `error`) is stored in the
|
|
25
|
-
external props storage — read it with `getProps(error)`, write it with
|
|
26
|
-
`setProps(error, …)` (see `.ai/PROTOTYPE-CHAIN.md` for the two key-spaces).
|
|
27
|
-
Never read `error.originalError` etc. directly, and never add those fields back
|
|
28
|
-
onto the error object.
|
|
29
|
-
|
|
30
|
-
## constructError Factory
|
|
31
|
-
|
|
32
|
-
```typescript
|
|
33
|
-
import { constructError } from '../api/errors/index.js';
|
|
34
|
-
|
|
35
|
-
const MyError = constructError('MY_ERROR', 'Error message');
|
|
36
|
-
throw new MyError('additional info', stack);
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Error Constructor Names Are String Objects
|
|
40
|
-
|
|
41
|
-
Error constructor names are `String` objects, not primitives. Compare as strings:
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
// ❌ Wrong — may fail
|
|
45
|
-
expect(error).toBeInstanceOf(ErrorsTypes.ALREADY_DECLARED);
|
|
46
|
-
|
|
47
|
-
// ✅ Correct
|
|
48
|
-
const expectedName = (err as { name: string }).name;
|
|
49
|
-
const actualName = (error as Error).constructor.name;
|
|
50
|
-
expect(String(actualName)).toEqual(String(expectedName));
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## Common Error Types
|
|
54
|
-
|
|
55
|
-
| Error | When Thrown |
|
|
56
|
-
|-------|------------|
|
|
57
|
-
| `WRONG_TYPE_DEFINITION` | Invalid type name, non-function handler |
|
|
58
|
-
| `WRONG_INSTANCE_INVOCATION` | extract() on non-object |
|
|
59
|
-
| `WRONG_MODIFICATION_PATTERN` | Bad prototype chain, wrong parent type |
|
|
60
|
-
| `ALREADY_DECLARED` | Type name already exists |
|
|
61
|
-
| `WRONG_ARGUMENTS_USED` | Invalid constructor arguments |
|
|
62
|
-
| `WRONG_HOOK_TYPE` | Unknown hook type |
|
|
63
|
-
| `MISSING_HOOK_CALLBACK` | registerHook without callback |
|
|
64
|
-
| `MISSING_CALLBACK_ARGUMENT` | Callback required but missing |
|
|
65
|
-
| `OPTIONS_ERROR` | Invalid config options |
|
|
66
|
-
| `WRONG_STACK_CLEANER` | Invalid stack cleaner regex |
|
package/.ai/rules-hooks.md
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: mnemonica-hooks
|
|
3
|
-
description: |
|
|
4
|
-
Lifecycle hooks in mnemonica: preCreation, postCreation, creationError.
|
|
5
|
-
Use when the user asks about hooks, registerHook, lifecycle events, or
|
|
6
|
-
when adding hook-related functionality to mnemonica.
|
|
7
|
-
metadata:
|
|
8
|
-
tags: [mnemonica, hooks, lifecycle, events]
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
# Lifecycle Hooks
|
|
12
|
-
|
|
13
|
-
## Hook Types
|
|
14
|
-
|
|
15
|
-
| Hook | When Fired | Data |
|
|
16
|
-
|------|-----------|------|
|
|
17
|
-
| `preCreation` | Before constructor runs | type, existentInstance, args, InstanceModificator |
|
|
18
|
-
| `postCreation` | After successful construction | type, existentInstance, inheritedInstance, args, creator |
|
|
19
|
-
| `creationError` | After constructor throws | type, existentInstance, inheritedInstance, args, creator |
|
|
20
|
-
|
|
21
|
-
## Registration Levels
|
|
22
|
-
|
|
23
|
-
Hooks can be registered at two levels:
|
|
24
|
-
|
|
25
|
-
### Type-level
|
|
26
|
-
```typescript
|
|
27
|
-
MyType.registerHook('postCreation', (opts) => {
|
|
28
|
-
console.log(`Created ${opts.type.TypeName}`);
|
|
29
|
-
});
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### Collection-level
|
|
33
|
-
```typescript
|
|
34
|
-
import { registerHook } from 'mnemonica';
|
|
35
|
-
registerHook(MyType, 'preCreation', (opts) => {
|
|
36
|
-
console.log('About to create instance');
|
|
37
|
-
});
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Hook Execution Order
|
|
41
|
-
|
|
42
|
-
1. Collection `preCreation`
|
|
43
|
-
2. Type `preCreation`
|
|
44
|
-
3. Constructor invocation
|
|
45
|
-
4. If error: Collection `creationError`, Type `creationError`
|
|
46
|
-
5. If success: Collection `postCreation`, Type `postCreation`
|