@getmikk/intent-engine 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +257 -0
- package/package.json +31 -27
- package/src/conflict-detector.ts +302 -302
- package/src/index.ts +6 -6
- package/src/interpreter.ts +216 -216
- package/src/preflight.ts +44 -44
- package/src/suggester.ts +104 -104
- package/src/types.ts +54 -54
- package/tests/intent-engine.test.ts +210 -210
- package/tests/smoke.test.ts +5 -5
- package/tsconfig.json +15 -15
package/README.md
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
# @getmikk/intent-engine
|
|
2
|
+
|
|
3
|
+
> AI pre-flight system — parses natural-language prompts into structured intents, detects constraint conflicts, and generates implementation suggestions before any code changes happen.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@getmikk/intent-engine)
|
|
6
|
+
[](../../LICENSE)
|
|
7
|
+
|
|
8
|
+
`@getmikk/intent-engine` is the "pre-flight check" layer. Given a developer's natural-language description of what they want to do (e.g., *"add a caching layer to the auth module"*), the engine:
|
|
9
|
+
|
|
10
|
+
1. **Interprets** the prompt into structured `Intent` objects
|
|
11
|
+
2. **Detects** conflicts against architectural constraints defined in `mikk.json`
|
|
12
|
+
3. **Suggests** which files to touch, what to create, and the estimated blast radius
|
|
13
|
+
|
|
14
|
+
All of this happens *before* any code is written — giving AI coding agents (or human developers) a guardrail system.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @getmikk/intent-engine
|
|
22
|
+
# or
|
|
23
|
+
bun add @getmikk/intent-engine
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Peer dependency:** `@getmikk/core`
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { PreflightPipeline } from '@getmikk/intent-engine'
|
|
34
|
+
import { ContractReader, LockReader } from '@getmikk/core'
|
|
35
|
+
|
|
36
|
+
const contract = await new ContractReader().read('./mikk.json')
|
|
37
|
+
const lock = await new LockReader().read('./mikk.lock.json')
|
|
38
|
+
|
|
39
|
+
const pipeline = new PreflightPipeline(contract, lock)
|
|
40
|
+
const result = await pipeline.run('Add a Redis caching layer to the auth module')
|
|
41
|
+
|
|
42
|
+
console.log(result.intents) // Parsed intent objects
|
|
43
|
+
console.log(result.conflicts) // Constraint violations found
|
|
44
|
+
console.log(result.suggestions) // File-level implementation plan
|
|
45
|
+
console.log(result.approved) // true if no blocking conflicts
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Pipeline Architecture
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
Natural Language Prompt
|
|
54
|
+
│
|
|
55
|
+
▼
|
|
56
|
+
┌──────────────────┐
|
|
57
|
+
│ IntentInterpreter │ → Intent[]
|
|
58
|
+
└────────┬─────────┘
|
|
59
|
+
│
|
|
60
|
+
▼
|
|
61
|
+
┌──────────────────┐
|
|
62
|
+
│ ConflictDetector │ → ConflictResult
|
|
63
|
+
└────────┬─────────┘
|
|
64
|
+
│
|
|
65
|
+
▼
|
|
66
|
+
┌──────────────────┐
|
|
67
|
+
│ Suggester │ → Suggestion[]
|
|
68
|
+
└────────┬─────────┘
|
|
69
|
+
│
|
|
70
|
+
▼
|
|
71
|
+
PreflightResult
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## API Reference
|
|
77
|
+
|
|
78
|
+
### PreflightPipeline
|
|
79
|
+
|
|
80
|
+
The main entry point — orchestrates the full interpret → detect → suggest flow.
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { PreflightPipeline } from '@getmikk/intent-engine'
|
|
84
|
+
|
|
85
|
+
const pipeline = new PreflightPipeline(contract, lock)
|
|
86
|
+
const result = await pipeline.run('refactor the payment module to use Stripe')
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**`PreflightResult`:**
|
|
90
|
+
|
|
91
|
+
| Field | Type | Description |
|
|
92
|
+
|-------|------|-------------|
|
|
93
|
+
| `intents` | `Intent[]` | Structured interpretation of the prompt |
|
|
94
|
+
| `conflicts` | `ConflictResult` | Any constraint violations detected |
|
|
95
|
+
| `suggestions` | `Suggestion[]` | Concrete implementation suggestions |
|
|
96
|
+
| `approved` | `boolean` | `true` if no error-level conflicts |
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
### IntentInterpreter
|
|
101
|
+
|
|
102
|
+
Parses natural-language prompts into structured intent objects using heuristic keyword matching and fuzzy matching against the lock file's function/module inventory.
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { IntentInterpreter } from '@getmikk/intent-engine'
|
|
106
|
+
|
|
107
|
+
const interpreter = new IntentInterpreter(contract, lock)
|
|
108
|
+
const intents = await interpreter.interpret('add input validation to the signup form')
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**How it works:**
|
|
112
|
+
|
|
113
|
+
1. **Action verb detection** — Scans for keywords like `create`, `add`, `modify`, `update`, `delete`, `remove`, `refactor`, `move`, `rename`
|
|
114
|
+
2. **Target resolution** — Matches mentioned names against lock file functions, classes, modules, and files using fuzzy matching
|
|
115
|
+
3. **Confidence scoring** — Higher confidence for exact matches, lower for fuzzy
|
|
116
|
+
|
|
117
|
+
**`Intent`:**
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
type Intent = {
|
|
121
|
+
action: 'create' | 'modify' | 'delete' | 'refactor' | 'move'
|
|
122
|
+
target: {
|
|
123
|
+
type: 'function' | 'class' | 'module' | 'file'
|
|
124
|
+
name: string
|
|
125
|
+
moduleId?: string // Which module contains the target
|
|
126
|
+
filePath?: string // Resolved file path
|
|
127
|
+
}
|
|
128
|
+
reason: string // Why this intent was derived
|
|
129
|
+
confidence: number // 0-1 confidence score
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
### ConflictDetector
|
|
136
|
+
|
|
137
|
+
Rule-based constraint checker that validates intents against the architectural rules in `mikk.json`.
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { ConflictDetector } from '@getmikk/intent-engine'
|
|
141
|
+
|
|
142
|
+
const detector = new ConflictDetector(contract, lock)
|
|
143
|
+
const result = detector.detect(intents)
|
|
144
|
+
|
|
145
|
+
if (result.hasConflicts) {
|
|
146
|
+
for (const conflict of result.conflicts) {
|
|
147
|
+
console.warn(`[${conflict.severity}] ${conflict.message}`)
|
|
148
|
+
if (conflict.suggestedFix) {
|
|
149
|
+
console.log(` Fix: ${conflict.suggestedFix}`)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Constraint types checked:**
|
|
156
|
+
|
|
157
|
+
| Constraint | Description | Example |
|
|
158
|
+
|-----------|-------------|---------|
|
|
159
|
+
| `no-import` | Module A must not import from Module B | `"no-import": ["payments"]` in the auth module |
|
|
160
|
+
| `must-use` | Module must use specified dependencies | `"must-use": ["@getmikk/core"]` |
|
|
161
|
+
| `no-call` | Functions in module must not call specified targets | `"no-call": ["database.rawQuery"]` |
|
|
162
|
+
| `layer` | Enforces layered architecture ordering | `"layer": 2` — can only import from lower layers |
|
|
163
|
+
| `naming` | Enforces naming patterns for functions/files | `"naming": { "functions": "^handle|^use|^get" }` |
|
|
164
|
+
| `max-files` | Limits the number of files in a module | `"max-files": 20` |
|
|
165
|
+
|
|
166
|
+
**Additional checks:**
|
|
167
|
+
- **Boundary crossing** — Detects when an intent would create a new cross-module dependency
|
|
168
|
+
- **Missing dependencies** — Flags when a target module doesn't exist
|
|
169
|
+
- **Ownership warnings** — Warns when modifying code owned by a different team/module
|
|
170
|
+
|
|
171
|
+
**`Conflict`:**
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
type Conflict = {
|
|
175
|
+
type: 'constraint-violation' | 'ownership-conflict' | 'boundary-crossing' | 'missing-dependency'
|
|
176
|
+
severity: 'error' | 'warning'
|
|
177
|
+
message: string
|
|
178
|
+
relatedIntent: Intent
|
|
179
|
+
suggestedFix?: string
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
### Suggester
|
|
186
|
+
|
|
187
|
+
Generates concrete implementation suggestions based on intents and the current codebase state.
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
import { Suggester } from '@getmikk/intent-engine'
|
|
191
|
+
|
|
192
|
+
const suggester = new Suggester(contract, lock)
|
|
193
|
+
const suggestions = suggester.suggest(intents)
|
|
194
|
+
|
|
195
|
+
for (const s of suggestions) {
|
|
196
|
+
console.log(`Action: ${s.intent.action} ${s.intent.target.name}`)
|
|
197
|
+
console.log(`Affected files: ${s.affectedFiles.join(', ')}`)
|
|
198
|
+
console.log(`New files: ${s.newFiles.join(', ')}`)
|
|
199
|
+
console.log(`Impact: ${s.estimatedImpact}`)
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
**`Suggestion`:**
|
|
204
|
+
|
|
205
|
+
| Field | Type | Description |
|
|
206
|
+
|-------|------|-------------|
|
|
207
|
+
| `intent` | `Intent` | The original intent this suggestion addresses |
|
|
208
|
+
| `affectedFiles` | `string[]` | Existing files that would need changes |
|
|
209
|
+
| `newFiles` | `string[]` | Files that would need to be created |
|
|
210
|
+
| `estimatedImpact` | `'low' \| 'medium' \| 'high'` | Blast radius estimate |
|
|
211
|
+
| `implementation` | `string` | Natural-language implementation guidance |
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Usage with AI Agents
|
|
216
|
+
|
|
217
|
+
The intent engine is designed to be called by AI coding agents as a pre-flight check:
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
// In your AI agent's planning phase:
|
|
221
|
+
const pipeline = new PreflightPipeline(contract, lock)
|
|
222
|
+
const preflight = await pipeline.run(userPrompt)
|
|
223
|
+
|
|
224
|
+
if (!preflight.approved) {
|
|
225
|
+
// Show conflicts to user, ask for confirmation
|
|
226
|
+
const errors = preflight.conflicts.conflicts.filter(c => c.severity === 'error')
|
|
227
|
+
throw new Error(`Blocked: ${errors.map(e => e.message).join('; ')}`)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Use suggestions to guide implementation
|
|
231
|
+
for (const suggestion of preflight.suggestions) {
|
|
232
|
+
// suggestion.affectedFiles — files to read/modify
|
|
233
|
+
// suggestion.newFiles — files to create
|
|
234
|
+
// suggestion.implementation — guidance text
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## Types
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
import type {
|
|
244
|
+
Intent,
|
|
245
|
+
Conflict,
|
|
246
|
+
ConflictResult,
|
|
247
|
+
Suggestion,
|
|
248
|
+
PreflightResult,
|
|
249
|
+
AIProviderConfig,
|
|
250
|
+
} from '@getmikk/intent-engine'
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
[Apache-2.0](../../LICENSE)
|
package/package.json
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@getmikk/intent-engine",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
},
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
}
|
|
27
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@getmikk/intent-engine",
|
|
3
|
+
"version": "1.3.1",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/Ansh-dhanani/mikk"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"test": "bun test",
|
|
21
|
+
"dev": "tsc --watch"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@getmikk/core": "^1.3.1",
|
|
25
|
+
"zod": "^3.22.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "^5.7.0",
|
|
29
|
+
"@types/node": "^22.0.0"
|
|
30
|
+
}
|
|
31
|
+
}
|