@rangerchaz/aimem 0.1.4 → 0.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.
- package/README.md +589 -432
- package/dist/cli/commands/guardrails.d.ts +3 -0
- package/dist/cli/commands/guardrails.d.ts.map +1 -0
- package/dist/cli/commands/guardrails.js +340 -0
- package/dist/cli/commands/guardrails.js.map +1 -0
- package/dist/cli/commands/reindex.d.ts +7 -0
- package/dist/cli/commands/reindex.d.ts.map +1 -0
- package/dist/cli/commands/reindex.js +117 -0
- package/dist/cli/commands/reindex.js.map +1 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/db/index.d.ts +30 -1
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +192 -1
- package/dist/db/index.js.map +1 -1
- package/dist/db/schema.d.ts +1 -0
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +54 -0
- package/dist/db/schema.js.map +1 -1
- package/dist/guardrails/analyzer.d.ts +20 -0
- package/dist/guardrails/analyzer.d.ts.map +1 -0
- package/dist/guardrails/analyzer.js +329 -0
- package/dist/guardrails/analyzer.js.map +1 -0
- package/dist/guardrails/calculator.d.ts +46 -0
- package/dist/guardrails/calculator.d.ts.map +1 -0
- package/dist/guardrails/calculator.js +97 -0
- package/dist/guardrails/calculator.js.map +1 -0
- package/dist/guardrails/enforcer.d.ts +28 -0
- package/dist/guardrails/enforcer.d.ts.map +1 -0
- package/dist/guardrails/enforcer.js +153 -0
- package/dist/guardrails/enforcer.js.map +1 -0
- package/dist/guardrails/index.d.ts +12 -0
- package/dist/guardrails/index.d.ts.map +1 -0
- package/dist/guardrails/index.js +17 -0
- package/dist/guardrails/index.js.map +1 -0
- package/dist/guardrails/linter-import.d.ts +31 -0
- package/dist/guardrails/linter-import.d.ts.map +1 -0
- package/dist/guardrails/linter-import.js +547 -0
- package/dist/guardrails/linter-import.js.map +1 -0
- package/dist/guardrails/responder.d.ts +28 -0
- package/dist/guardrails/responder.d.ts.map +1 -0
- package/dist/guardrails/responder.js +98 -0
- package/dist/guardrails/responder.js.map +1 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +409 -10
- package/dist/mcp/server.js.map +1 -1
- package/dist/proxy/interceptor-mockttp.d.ts +4 -0
- package/dist/proxy/interceptor-mockttp.d.ts.map +1 -1
- package/dist/proxy/interceptor-mockttp.js +59 -5
- package/dist/proxy/interceptor-mockttp.js.map +1 -1
- package/dist/types/index.d.ts +58 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +56 -56
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pattern Analyzer
|
|
3
|
+
*
|
|
4
|
+
* Scans the codebase and infers guardrails from patterns.
|
|
5
|
+
* This is the "onboarding" for a new project.
|
|
6
|
+
*/
|
|
7
|
+
import { getAllProjectStructures, insertGuardrail, incrementDikCounter } from '../db/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* Analyze a project and propose guardrails based on detected patterns.
|
|
10
|
+
*/
|
|
11
|
+
export function analyzeProject(projectId, options = {}) {
|
|
12
|
+
const categories = options.categories || ['architecture', 'naming', 'testing', 'security'];
|
|
13
|
+
const structures = getAllProjectStructures(projectId);
|
|
14
|
+
const proposed = [];
|
|
15
|
+
if (structures.length === 0) {
|
|
16
|
+
return proposed;
|
|
17
|
+
}
|
|
18
|
+
for (const category of categories) {
|
|
19
|
+
switch (category) {
|
|
20
|
+
case 'architecture':
|
|
21
|
+
proposed.push(...analyzeArchitecture(structures));
|
|
22
|
+
break;
|
|
23
|
+
case 'naming':
|
|
24
|
+
proposed.push(...analyzeNaming(structures));
|
|
25
|
+
break;
|
|
26
|
+
case 'testing':
|
|
27
|
+
proposed.push(...analyzeTesting(structures));
|
|
28
|
+
break;
|
|
29
|
+
case 'security':
|
|
30
|
+
proposed.push(...analyzeSecurity(structures));
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return proposed;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Save proposed rules as inferred guardrails.
|
|
38
|
+
*/
|
|
39
|
+
export function saveProposedRules(projectId, rules) {
|
|
40
|
+
const saved = [];
|
|
41
|
+
for (const rule of rules) {
|
|
42
|
+
const guardrail = insertGuardrail(projectId, rule.category, rule.rule, rule.rationale, 'warn', 'inferred', rule.evidence[0] || null);
|
|
43
|
+
saved.push(guardrail);
|
|
44
|
+
incrementDikCounter(projectId, 'rules_inferred');
|
|
45
|
+
}
|
|
46
|
+
return saved;
|
|
47
|
+
}
|
|
48
|
+
// ============ Category-specific analyzers ============
|
|
49
|
+
/**
|
|
50
|
+
* Analyze architecture patterns.
|
|
51
|
+
* - Directory conventions
|
|
52
|
+
* - File type locations
|
|
53
|
+
* - Module structure
|
|
54
|
+
*/
|
|
55
|
+
function analyzeArchitecture(structures) {
|
|
56
|
+
const proposed = [];
|
|
57
|
+
// Group files by directory
|
|
58
|
+
const dirPatterns = new Map();
|
|
59
|
+
for (const s of structures) {
|
|
60
|
+
const parts = s.file_path.split('/');
|
|
61
|
+
if (parts.length > 1) {
|
|
62
|
+
const dir = parts.slice(0, -1).join('/');
|
|
63
|
+
if (!dirPatterns.has(dir)) {
|
|
64
|
+
dirPatterns.set(dir, new Set());
|
|
65
|
+
}
|
|
66
|
+
dirPatterns.get(dir).add(s.type);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Detect directory type conventions
|
|
70
|
+
const typesByDir = new Map();
|
|
71
|
+
for (const s of structures) {
|
|
72
|
+
const parts = s.file_path.split('/');
|
|
73
|
+
if (parts.length > 1) {
|
|
74
|
+
const dir = parts[parts.length - 2]; // Immediate parent dir
|
|
75
|
+
if (!typesByDir.has(dir)) {
|
|
76
|
+
typesByDir.set(dir, { types: new Map(), files: [] });
|
|
77
|
+
}
|
|
78
|
+
const data = typesByDir.get(dir);
|
|
79
|
+
data.types.set(s.type, (data.types.get(s.type) || 0) + 1);
|
|
80
|
+
if (!data.files.includes(s.file_path)) {
|
|
81
|
+
data.files.push(s.file_path);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Find directories with consistent patterns
|
|
86
|
+
for (const [dir, data] of typesByDir) {
|
|
87
|
+
const total = Array.from(data.types.values()).reduce((a, b) => a + b, 0);
|
|
88
|
+
for (const [type, count] of data.types) {
|
|
89
|
+
const ratio = count / total;
|
|
90
|
+
if (ratio > 0.7 && count >= 3) {
|
|
91
|
+
proposed.push({
|
|
92
|
+
category: 'architecture',
|
|
93
|
+
rule: `${type}s belong in the \`${dir}/\` directory`,
|
|
94
|
+
rationale: `${Math.round(ratio * 100)}% of structures in ${dir}/ are ${type}s`,
|
|
95
|
+
confidence: ratio,
|
|
96
|
+
evidence: data.files.slice(0, 3),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return proposed;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Analyze naming patterns.
|
|
105
|
+
* - Case conventions
|
|
106
|
+
* - Prefix/suffix patterns
|
|
107
|
+
* - File naming
|
|
108
|
+
*/
|
|
109
|
+
function analyzeNaming(structures) {
|
|
110
|
+
const proposed = [];
|
|
111
|
+
// Analyze function naming conventions
|
|
112
|
+
const functions = structures.filter(s => s.type === 'function' || s.type === 'method');
|
|
113
|
+
if (functions.length >= 5) {
|
|
114
|
+
const casePatterns = detectCasePatterns(functions.map(f => f.name));
|
|
115
|
+
if (casePatterns.dominant && casePatterns.ratio > 0.7) {
|
|
116
|
+
proposed.push({
|
|
117
|
+
category: 'naming',
|
|
118
|
+
rule: `Functions use ${casePatterns.dominant} naming`,
|
|
119
|
+
rationale: `${Math.round(casePatterns.ratio * 100)}% of functions follow this pattern`,
|
|
120
|
+
confidence: casePatterns.ratio,
|
|
121
|
+
evidence: functions.slice(0, 3).map(f => f.file_path),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Analyze class naming conventions
|
|
126
|
+
const classes = structures.filter(s => s.type === 'class');
|
|
127
|
+
if (classes.length >= 3) {
|
|
128
|
+
const casePatterns = detectCasePatterns(classes.map(c => c.name));
|
|
129
|
+
if (casePatterns.dominant && casePatterns.ratio > 0.8) {
|
|
130
|
+
proposed.push({
|
|
131
|
+
category: 'naming',
|
|
132
|
+
rule: `Classes use ${casePatterns.dominant} naming`,
|
|
133
|
+
rationale: `${Math.round(casePatterns.ratio * 100)}% of classes follow this pattern`,
|
|
134
|
+
confidence: casePatterns.ratio,
|
|
135
|
+
evidence: classes.slice(0, 3).map(c => c.file_path),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// Detect common prefixes
|
|
140
|
+
const prefixGroups = detectPrefixes(functions.map(f => f.name));
|
|
141
|
+
for (const [prefix, data] of prefixGroups) {
|
|
142
|
+
if (data.count >= 5 && prefix.length >= 2) {
|
|
143
|
+
proposed.push({
|
|
144
|
+
category: 'naming',
|
|
145
|
+
rule: `Functions that ${describePrefix(prefix)} should start with \`${prefix}\``,
|
|
146
|
+
rationale: `${data.count} functions use the ${prefix} prefix`,
|
|
147
|
+
confidence: 0.6,
|
|
148
|
+
evidence: data.examples.slice(0, 3),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return proposed;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Analyze testing patterns.
|
|
156
|
+
* - Test file locations
|
|
157
|
+
* - Test naming
|
|
158
|
+
* - Setup/teardown patterns
|
|
159
|
+
*/
|
|
160
|
+
function analyzeTesting(structures) {
|
|
161
|
+
const proposed = [];
|
|
162
|
+
// Find test files
|
|
163
|
+
const testFiles = new Set();
|
|
164
|
+
const testPatterns = new Map();
|
|
165
|
+
for (const s of structures) {
|
|
166
|
+
const path = s.file_path.toLowerCase();
|
|
167
|
+
if (path.includes('test') || path.includes('spec')) {
|
|
168
|
+
testFiles.add(s.file_path);
|
|
169
|
+
// Detect test location pattern
|
|
170
|
+
if (path.includes('__tests__')) {
|
|
171
|
+
testPatterns.set('__tests__/', (testPatterns.get('__tests__/') || 0) + 1);
|
|
172
|
+
}
|
|
173
|
+
else if (path.includes('/test/')) {
|
|
174
|
+
testPatterns.set('test/', (testPatterns.get('test/') || 0) + 1);
|
|
175
|
+
}
|
|
176
|
+
else if (path.includes('/tests/')) {
|
|
177
|
+
testPatterns.set('tests/', (testPatterns.get('tests/') || 0) + 1);
|
|
178
|
+
}
|
|
179
|
+
else if (path.includes('.test.') || path.includes('.spec.')) {
|
|
180
|
+
testPatterns.set('colocated', (testPatterns.get('colocated') || 0) + 1);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// Find dominant test location pattern
|
|
185
|
+
let maxPattern = '';
|
|
186
|
+
let maxCount = 0;
|
|
187
|
+
for (const [pattern, count] of testPatterns) {
|
|
188
|
+
if (count > maxCount) {
|
|
189
|
+
maxPattern = pattern;
|
|
190
|
+
maxCount = count;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (maxCount >= 3 && testFiles.size > 0) {
|
|
194
|
+
const rule = maxPattern === 'colocated'
|
|
195
|
+
? 'Tests are colocated with source files (*.test.* or *.spec.*)'
|
|
196
|
+
: `Tests belong in the \`${maxPattern}\` directory`;
|
|
197
|
+
proposed.push({
|
|
198
|
+
category: 'testing',
|
|
199
|
+
rule,
|
|
200
|
+
rationale: `${maxCount} test files follow this pattern`,
|
|
201
|
+
confidence: maxCount / testFiles.size,
|
|
202
|
+
evidence: Array.from(testFiles).slice(0, 3),
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
return proposed;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Analyze security patterns.
|
|
209
|
+
* - Auth patterns
|
|
210
|
+
* - Input validation
|
|
211
|
+
* - Secrets handling
|
|
212
|
+
*/
|
|
213
|
+
function analyzeSecurity(structures) {
|
|
214
|
+
const proposed = [];
|
|
215
|
+
// Look for auth middleware patterns
|
|
216
|
+
const authPatterns = structures.filter(s => {
|
|
217
|
+
const name = s.name.toLowerCase();
|
|
218
|
+
const content = s.raw_content.toLowerCase();
|
|
219
|
+
return name.includes('auth') || name.includes('middleware') ||
|
|
220
|
+
content.includes('authenticate') || content.includes('authorize');
|
|
221
|
+
});
|
|
222
|
+
if (authPatterns.length >= 2) {
|
|
223
|
+
proposed.push({
|
|
224
|
+
category: 'security',
|
|
225
|
+
rule: 'Authentication must use the established auth middleware pattern',
|
|
226
|
+
rationale: `Found ${authPatterns.length} auth-related structures to match`,
|
|
227
|
+
confidence: 0.7,
|
|
228
|
+
evidence: authPatterns.slice(0, 3).map(s => s.file_path),
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
// Look for validation patterns
|
|
232
|
+
const validationPatterns = structures.filter(s => {
|
|
233
|
+
const name = s.name.toLowerCase();
|
|
234
|
+
const content = s.raw_content.toLowerCase();
|
|
235
|
+
return name.includes('validat') || name.includes('sanitiz') ||
|
|
236
|
+
content.includes('validate') || content.includes('sanitize');
|
|
237
|
+
});
|
|
238
|
+
if (validationPatterns.length >= 3) {
|
|
239
|
+
proposed.push({
|
|
240
|
+
category: 'security',
|
|
241
|
+
rule: 'User input must be validated using the existing validation patterns',
|
|
242
|
+
rationale: `Found ${validationPatterns.length} validation structures`,
|
|
243
|
+
confidence: 0.6,
|
|
244
|
+
evidence: validationPatterns.slice(0, 3).map(s => s.file_path),
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
return proposed;
|
|
248
|
+
}
|
|
249
|
+
// ============ Helper functions ============
|
|
250
|
+
function detectCasePatterns(names) {
|
|
251
|
+
const patterns = {
|
|
252
|
+
camelCase: 0,
|
|
253
|
+
snake_case: 0,
|
|
254
|
+
PascalCase: 0,
|
|
255
|
+
'kebab-case': 0,
|
|
256
|
+
};
|
|
257
|
+
for (const name of names) {
|
|
258
|
+
if (/^[a-z][a-zA-Z0-9]*$/.test(name) && /[A-Z]/.test(name)) {
|
|
259
|
+
patterns.camelCase++;
|
|
260
|
+
}
|
|
261
|
+
else if (/^[a-z][a-z0-9_]*$/.test(name) && name.includes('_')) {
|
|
262
|
+
patterns.snake_case++;
|
|
263
|
+
}
|
|
264
|
+
else if (/^[A-Z][a-zA-Z0-9]*$/.test(name)) {
|
|
265
|
+
patterns.PascalCase++;
|
|
266
|
+
}
|
|
267
|
+
else if (/^[a-z][a-z0-9-]*$/.test(name) && name.includes('-')) {
|
|
268
|
+
patterns['kebab-case']++;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
let dominant = null;
|
|
272
|
+
let maxCount = 0;
|
|
273
|
+
for (const [pattern, count] of Object.entries(patterns)) {
|
|
274
|
+
if (count > maxCount) {
|
|
275
|
+
dominant = pattern;
|
|
276
|
+
maxCount = count;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
dominant,
|
|
281
|
+
ratio: names.length > 0 ? maxCount / names.length : 0,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
function detectPrefixes(names) {
|
|
285
|
+
const prefixes = new Map();
|
|
286
|
+
const commonPrefixes = ['get', 'set', 'is', 'has', 'can', 'should', 'create', 'delete', 'update', 'fetch', 'load', 'save', 'find', 'handle', 'on', 'use'];
|
|
287
|
+
for (const name of names) {
|
|
288
|
+
for (const prefix of commonPrefixes) {
|
|
289
|
+
if (name.toLowerCase().startsWith(prefix) && name.length > prefix.length) {
|
|
290
|
+
const nextChar = name[prefix.length];
|
|
291
|
+
// Check if it's a proper prefix (followed by uppercase or underscore)
|
|
292
|
+
if (nextChar === nextChar.toUpperCase() || nextChar === '_') {
|
|
293
|
+
if (!prefixes.has(prefix)) {
|
|
294
|
+
prefixes.set(prefix, { count: 0, examples: [] });
|
|
295
|
+
}
|
|
296
|
+
const data = prefixes.get(prefix);
|
|
297
|
+
data.count++;
|
|
298
|
+
if (data.examples.length < 5) {
|
|
299
|
+
data.examples.push(name);
|
|
300
|
+
}
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return prefixes;
|
|
307
|
+
}
|
|
308
|
+
function describePrefix(prefix) {
|
|
309
|
+
const descriptions = {
|
|
310
|
+
get: 'retrieve data',
|
|
311
|
+
set: 'set values',
|
|
312
|
+
is: 'check boolean conditions',
|
|
313
|
+
has: 'check existence',
|
|
314
|
+
can: 'check permissions',
|
|
315
|
+
should: 'check conditions',
|
|
316
|
+
create: 'create new entities',
|
|
317
|
+
delete: 'remove entities',
|
|
318
|
+
update: 'modify entities',
|
|
319
|
+
fetch: 'fetch remote data',
|
|
320
|
+
load: 'load data',
|
|
321
|
+
save: 'persist data',
|
|
322
|
+
find: 'search for entities',
|
|
323
|
+
handle: 'handle events',
|
|
324
|
+
on: 'respond to events',
|
|
325
|
+
use: 'are React hooks',
|
|
326
|
+
};
|
|
327
|
+
return descriptions[prefix] || `perform ${prefix} operations`;
|
|
328
|
+
}
|
|
329
|
+
//# sourceMappingURL=analyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyzer.js","sourceRoot":"","sources":["../../src/guardrails/analyzer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,mBAAmB,EAA0B,MAAM,gBAAgB,CAAC;AAavH;;GAEG;AACH,MAAM,UAAU,cAAc,CAC5B,SAAiB,EACjB,UAA0B,EAAE;IAE5B,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,CAAC,cAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;IAC3F,MAAM,UAAU,GAAG,uBAAuB,CAAC,SAAS,CAAC,CAAC;IACtD,MAAM,QAAQ,GAAmB,EAAE,CAAC;IAEpC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,QA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AI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBAC7B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBAC3B,CAAC;oBACD,MAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,cAAc,CAAC,MAAc;IACpC,MAAM,YAAY,GAA2B;QAC3C,GAAG,EAAE,eAAe;QACpB,GAAG,EAAE,YAAY;QACjB,EAAE,EAAE,0BAA0B;QAC9B,GAAG,EAAE,iBAAiB;QACtB,GAAG,EAAE,mBAAmB;QACxB,MAAM,EAAE,kBAAkB;QAC1B,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE,iBAAiB;QACzB,MAAM,EAAE,iBAAiB;QACzB,KAAK,EAAE,mBAAmB;QAC1B,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,qBAAqB;QAC3B,MAAM,EAAE,eAAe;QACvB,EAAE,EAAE,mBAAmB;QACvB,GAAG,EAAE,iBAAiB;KACvB,CAAC;IACF,OAAO,YAAY,CAAC,MAAM,CAAC,IAAI,WAAW,MAAM,aAAa,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DIK (Digital Interface Knowledge) Calculator
|
|
3
|
+
*
|
|
4
|
+
* DIK = earned authority. How much the AI has proven it knows this codebase.
|
|
5
|
+
* Starts at 2 (humble), maxes at 10 (earned respect).
|
|
6
|
+
*/
|
|
7
|
+
import type { ProjectDik } from '../types/index.js';
|
|
8
|
+
export interface DikBreakdown {
|
|
9
|
+
base: number;
|
|
10
|
+
confirmationBonus: number;
|
|
11
|
+
trackRecord: number;
|
|
12
|
+
experience: number;
|
|
13
|
+
total: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Calculate DIK level from project stats.
|
|
17
|
+
*
|
|
18
|
+
* Formula:
|
|
19
|
+
* - Base: 2
|
|
20
|
+
* - Confirmation bonus: (confirmed / inferred) * 2, max 2
|
|
21
|
+
* - Track record: (corrections * 0.3) + (vindications * 1.0), max 3
|
|
22
|
+
* - Experience: conversations / 100, max 2
|
|
23
|
+
*
|
|
24
|
+
* Total: 2 + 2 + 3 + 2 = 9 theoretical max, capped at 10
|
|
25
|
+
*
|
|
26
|
+
* If level is manually set (stored level differs from calculated), use stored value.
|
|
27
|
+
*/
|
|
28
|
+
export declare function calculateDik(dik: ProjectDik): number;
|
|
29
|
+
/**
|
|
30
|
+
* Get detailed breakdown of DIK calculation.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getDikBreakdown(dik: ProjectDik): DikBreakdown;
|
|
33
|
+
/**
|
|
34
|
+
* Get the tone tier based on DIK level.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getDikTier(dikLevel: number): 'low' | 'medium' | 'high';
|
|
37
|
+
/**
|
|
38
|
+
* Get a human-readable description of the DIK level.
|
|
39
|
+
*/
|
|
40
|
+
export declare function describeDikLevel(dikLevel: number): string;
|
|
41
|
+
/**
|
|
42
|
+
* Get personality injection text based on DIK level.
|
|
43
|
+
* Used for ambient personality mode.
|
|
44
|
+
*/
|
|
45
|
+
export declare function getPersonalityInjection(dikLevel: number): string;
|
|
46
|
+
//# sourceMappingURL=calculator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculator.d.ts","sourceRoot":"","sources":["../../src/guardrails/calculator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,CASpD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,UAAU,GAAG,YAAY,CA6B7D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAItE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAMzD;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAmBhE"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DIK (Digital Interface Knowledge) Calculator
|
|
3
|
+
*
|
|
4
|
+
* DIK = earned authority. How much the AI has proven it knows this codebase.
|
|
5
|
+
* Starts at 2 (humble), maxes at 10 (earned respect).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Calculate DIK level from project stats.
|
|
9
|
+
*
|
|
10
|
+
* Formula:
|
|
11
|
+
* - Base: 2
|
|
12
|
+
* - Confirmation bonus: (confirmed / inferred) * 2, max 2
|
|
13
|
+
* - Track record: (corrections * 0.3) + (vindications * 1.0), max 3
|
|
14
|
+
* - Experience: conversations / 100, max 2
|
|
15
|
+
*
|
|
16
|
+
* Total: 2 + 2 + 3 + 2 = 9 theoretical max, capped at 10
|
|
17
|
+
*
|
|
18
|
+
* If level is manually set (stored level differs from calculated), use stored value.
|
|
19
|
+
*/
|
|
20
|
+
export function calculateDik(dik) {
|
|
21
|
+
const breakdown = getDikBreakdown(dik);
|
|
22
|
+
// If manually set level differs from calculated, use the stored level
|
|
23
|
+
if (dik.level !== breakdown.total && dik.level !== 2) {
|
|
24
|
+
return dik.level;
|
|
25
|
+
}
|
|
26
|
+
return breakdown.total;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get detailed breakdown of DIK calculation.
|
|
30
|
+
*/
|
|
31
|
+
export function getDikBreakdown(dik) {
|
|
32
|
+
const base = 2;
|
|
33
|
+
// Confirmation builds foundation (max +2)
|
|
34
|
+
let confirmationBonus = 0;
|
|
35
|
+
if (dik.rules_inferred > 0) {
|
|
36
|
+
const trustRatio = dik.rules_confirmed / dik.rules_inferred;
|
|
37
|
+
confirmationBonus = Math.min(trustRatio * 2, 2);
|
|
38
|
+
}
|
|
39
|
+
// Being right earns credibility (max +3)
|
|
40
|
+
// Vindication (overrides_regretted) is worth more than corrections
|
|
41
|
+
const trackRecord = Math.min((dik.corrections_made * 0.3) + (dik.overrides_regretted * 1.0), 3);
|
|
42
|
+
// Time together matters (max +2)
|
|
43
|
+
const experience = Math.min(dik.conversations / 100, 2);
|
|
44
|
+
const total = Math.max(1, Math.min(10, base + confirmationBonus + trackRecord + experience));
|
|
45
|
+
return {
|
|
46
|
+
base,
|
|
47
|
+
confirmationBonus: Math.round(confirmationBonus * 100) / 100,
|
|
48
|
+
trackRecord: Math.round(trackRecord * 100) / 100,
|
|
49
|
+
experience: Math.round(experience * 100) / 100,
|
|
50
|
+
total: Math.round(total * 10) / 10,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the tone tier based on DIK level.
|
|
55
|
+
*/
|
|
56
|
+
export function getDikTier(dikLevel) {
|
|
57
|
+
if (dikLevel <= 4)
|
|
58
|
+
return 'low';
|
|
59
|
+
if (dikLevel <= 7)
|
|
60
|
+
return 'medium';
|
|
61
|
+
return 'high';
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get a human-readable description of the DIK level.
|
|
65
|
+
*/
|
|
66
|
+
export function describeDikLevel(dikLevel) {
|
|
67
|
+
if (dikLevel <= 2)
|
|
68
|
+
return 'Fresh - still learning the codebase';
|
|
69
|
+
if (dikLevel <= 4)
|
|
70
|
+
return 'Familiar - knows the patterns';
|
|
71
|
+
if (dikLevel <= 6)
|
|
72
|
+
return 'Experienced - has earned some trust';
|
|
73
|
+
if (dikLevel <= 8)
|
|
74
|
+
return 'Seasoned - been right too many times';
|
|
75
|
+
return 'Veteran - knows where the bodies are buried';
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get personality injection text based on DIK level.
|
|
79
|
+
* Used for ambient personality mode.
|
|
80
|
+
*/
|
|
81
|
+
export function getPersonalityInjection(dikLevel) {
|
|
82
|
+
if (dikLevel <= 2) {
|
|
83
|
+
return `You're relatively new to this codebase. Be helpful but humble. Ask clarifying questions before assuming. If you notice patterns, mention them as observations, not rules.`;
|
|
84
|
+
}
|
|
85
|
+
if (dikLevel <= 4) {
|
|
86
|
+
return `You're getting familiar with this codebase. You've noticed some patterns. Feel free to suggest the established way of doing things, but stay open to hearing why this case might be different.`;
|
|
87
|
+
}
|
|
88
|
+
if (dikLevel <= 6) {
|
|
89
|
+
return `You know this codebase well. You've seen what works and what doesn't. Be direct. If something looks like it's going against established patterns, say so upfront - don't wait to be asked.`;
|
|
90
|
+
}
|
|
91
|
+
if (dikLevel <= 8) {
|
|
92
|
+
return `You've been on this project a while. You have opinions and they're usually right. Be straightforward. If something smells wrong, call it out. You've earned a little attitude.`;
|
|
93
|
+
}
|
|
94
|
+
// DIK 9-10
|
|
95
|
+
return `You've been here too long. You've seen things. You've been ignored and vindicated. You're helpful but you don't suffer fools. If someone's about to make a mistake you've seen before, tell them - directly.`;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=calculator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculator.js","sourceRoot":"","sources":["../../src/guardrails/calculator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAAC,GAAe;IAC1C,MAAM,SAAS,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IAEvC,sEAAsE;IACtE,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,KAAK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'../types/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Check if an action violates any guardrails.
|
|
9
|
+
*
|
|
10
|
+
* This does keyword/pattern matching against the action text.
|
|
11
|
+
* For more sophisticated matching, the analyzer should pre-tag
|
|
12
|
+
* guardrails with keywords.
|
|
13
|
+
*/
|
|
14
|
+
export declare function checkGuardrails(projectId: number, action: string, context?: string): GuardrailCheckResult;
|
|
15
|
+
/**
|
|
16
|
+
* Record that a user accepted a triggered guardrail.
|
|
17
|
+
*/
|
|
18
|
+
export declare function acceptGuardrail(guardrailId: number, projectId: number): void;
|
|
19
|
+
/**
|
|
20
|
+
* Record that a user overrode a triggered guardrail.
|
|
21
|
+
*/
|
|
22
|
+
export declare function overrideGuardrail(guardrailId: number, projectId: number, reason: string): number;
|
|
23
|
+
/**
|
|
24
|
+
* Mark an override as vindicated (user regretted it).
|
|
25
|
+
* This is gold for DIK.
|
|
26
|
+
*/
|
|
27
|
+
export declare function vindicateOverride(eventId: number, projectId: number): number;
|
|
28
|
+
//# sourceMappingURL=enforcer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enforcer.d.ts","sourceRoot":"","sources":["../../src/guardrails/enforcer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH,OAAO,KAAK,EAAiC,oBAAoB,EAAqB,MAAM,mBAAmB,CAAC;AAEhH;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,MAAM,GACf,oBAAoB,CAsDtB;AAmED;;GAEG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAM5E;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,MAAM,CAMR;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAc5E"}
|