add-skill-kit 3.2.3 → 3.2.4
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/lib/agent-cli/lib/audit.js +154 -0
- package/lib/agent-cli/lib/audit.test.js +100 -0
- package/lib/agent-cli/lib/auto-learn.js +319 -0
- package/lib/agent-cli/lib/auto_preview.py +148 -0
- package/lib/agent-cli/lib/backup.js +138 -0
- package/lib/agent-cli/lib/backup.test.js +78 -0
- package/lib/agent-cli/lib/checklist.py +222 -0
- package/lib/agent-cli/lib/cognitive-lesson.js +476 -0
- package/lib/agent-cli/lib/completion.js +149 -0
- package/lib/agent-cli/lib/config.js +35 -0
- package/lib/agent-cli/lib/eslint-fix.js +238 -0
- package/lib/agent-cli/lib/evolution-signal.js +215 -0
- package/lib/agent-cli/lib/export.js +86 -0
- package/lib/agent-cli/lib/export.test.js +65 -0
- package/lib/agent-cli/lib/fix.js +337 -0
- package/lib/agent-cli/lib/fix.test.js +80 -0
- package/lib/agent-cli/lib/gemini-export.js +83 -0
- package/lib/agent-cli/lib/generate-registry.js +42 -0
- package/lib/agent-cli/lib/hooks/install-hooks.js +152 -0
- package/lib/agent-cli/lib/hooks/lint-learn.js +172 -0
- package/lib/agent-cli/lib/ignore.js +116 -0
- package/lib/agent-cli/lib/ignore.test.js +58 -0
- package/lib/agent-cli/lib/init.js +124 -0
- package/lib/agent-cli/lib/learn.js +255 -0
- package/lib/agent-cli/lib/learn.test.js +70 -0
- package/lib/agent-cli/lib/migrate-to-v4.js +322 -0
- package/lib/agent-cli/lib/proposals.js +199 -0
- package/lib/agent-cli/lib/proposals.test.js +56 -0
- package/lib/agent-cli/lib/recall.js +820 -0
- package/lib/agent-cli/lib/recall.test.js +107 -0
- package/lib/agent-cli/lib/selfevolution-bridge.js +167 -0
- package/lib/agent-cli/lib/session_manager.py +120 -0
- package/lib/agent-cli/lib/settings.js +203 -0
- package/lib/agent-cli/lib/skill-learn.js +296 -0
- package/lib/agent-cli/lib/stats.js +132 -0
- package/lib/agent-cli/lib/stats.test.js +94 -0
- package/lib/agent-cli/lib/types.js +33 -0
- package/lib/agent-cli/lib/ui/audit-ui.js +146 -0
- package/lib/agent-cli/lib/ui/backup-ui.js +107 -0
- package/lib/agent-cli/lib/ui/clack-helpers.js +317 -0
- package/lib/agent-cli/lib/ui/common.js +83 -0
- package/lib/agent-cli/lib/ui/completion-ui.js +126 -0
- package/lib/agent-cli/lib/ui/custom-select.js +69 -0
- package/lib/agent-cli/lib/ui/dashboard-ui.js +123 -0
- package/lib/agent-cli/lib/ui/evolution-signals-ui.js +107 -0
- package/lib/agent-cli/lib/ui/export-ui.js +94 -0
- package/lib/agent-cli/lib/ui/fix-all-ui.js +191 -0
- package/lib/agent-cli/lib/ui/help-ui.js +49 -0
- package/lib/agent-cli/lib/ui/index.js +169 -0
- package/lib/agent-cli/lib/ui/init-ui.js +56 -0
- package/lib/agent-cli/lib/ui/knowledge-ui.js +55 -0
- package/lib/agent-cli/lib/ui/learn-ui.js +706 -0
- package/lib/agent-cli/lib/ui/lessons-ui.js +148 -0
- package/lib/agent-cli/lib/ui/pretty.js +145 -0
- package/lib/agent-cli/lib/ui/proposals-ui.js +99 -0
- package/lib/agent-cli/lib/ui/recall-ui.js +342 -0
- package/lib/agent-cli/lib/ui/routing-demo.js +79 -0
- package/lib/agent-cli/lib/ui/routing-ui.js +325 -0
- package/lib/agent-cli/lib/ui/settings-ui.js +381 -0
- package/lib/agent-cli/lib/ui/stats-ui.js +123 -0
- package/lib/agent-cli/lib/ui/watch-ui.js +236 -0
- package/lib/agent-cli/lib/verify_all.py +327 -0
- package/lib/agent-cli/lib/watcher.js +181 -0
- package/lib/agent-cli/lib/watcher.test.js +85 -0
- package/lib/agent-cli/package.json +51 -0
- package/lib/agentskillskit-cli/README.md +21 -0
- package/lib/agentskillskit-cli/ag-smart.js +158 -0
- package/lib/agentskillskit-cli/package.json +51 -0
- package/package.json +10 -6
- /package/{node_modules/agentskillskit-cli → lib/agent-cli}/README.md +0 -0
- /package/{node_modules/agentskillskit-cli → lib/agent-cli}/bin/ag-smart.js +0 -0
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cognitive Lesson Engine - Intelligence Layers
|
|
3
|
+
*
|
|
4
|
+
* This module implements the cognitive intelligence that transforms
|
|
5
|
+
* raw data (mistakes.yaml + improvements.yaml) into Cognitive Lesson Units
|
|
6
|
+
*
|
|
7
|
+
* Levels:
|
|
8
|
+
* 1. Intent Inference - detect purpose
|
|
9
|
+
* 2. Pattern Intelligence - context matching
|
|
10
|
+
* 3. Maturity Calculation - confidence & state
|
|
11
|
+
* 4. Evolution Analysis - gap detection
|
|
12
|
+
* 5. Feedback Loop - self-evolution
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import fs from 'fs';
|
|
16
|
+
import path from 'path';
|
|
17
|
+
import yaml from 'js-yaml';
|
|
18
|
+
import { fileURLToPath } from 'url';
|
|
19
|
+
|
|
20
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
21
|
+
const PROJECT_ROOT = path.join(__dirname, '../../..');
|
|
22
|
+
const KNOWLEDGE_DIR = path.join(PROJECT_ROOT, '.agent/knowledge');
|
|
23
|
+
|
|
24
|
+
// ============================================================================
|
|
25
|
+
// LEVEL 0: Data Loading
|
|
26
|
+
// ============================================================================
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Load mistakes from YAML
|
|
30
|
+
*/
|
|
31
|
+
export function loadMistakes() {
|
|
32
|
+
const filepath = path.join(KNOWLEDGE_DIR, 'mistakes.yaml');
|
|
33
|
+
if (!fs.existsSync(filepath)) {
|
|
34
|
+
return { version: 4.0, mistakes: [] };
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const content = fs.readFileSync(filepath, 'utf8');
|
|
38
|
+
return yaml.load(content) || { version: 4.0, mistakes: [] };
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error('Error loading mistakes:', error.message);
|
|
41
|
+
return { version: 4.0, mistakes: [] };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Load improvements from YAML
|
|
47
|
+
*/
|
|
48
|
+
export function loadImprovements() {
|
|
49
|
+
const filepath = path.join(KNOWLEDGE_DIR, 'improvements.yaml');
|
|
50
|
+
if (!fs.existsSync(filepath)) {
|
|
51
|
+
return { version: 4.0, improvements: [] };
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const content = fs.readFileSync(filepath, 'utf8');
|
|
55
|
+
return yaml.load(content) || { version: 4.0, improvements: [] };
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error('Error loading improvements:', error.message);
|
|
58
|
+
return { version: 4.0, improvements: [] };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ============================================================================
|
|
63
|
+
// LEVEL 1: Intent Inference
|
|
64
|
+
// ============================================================================
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Intent vocabulary - maps tag patterns to intents
|
|
68
|
+
*/
|
|
69
|
+
const INTENT_PATTERNS = {
|
|
70
|
+
'safe-rebranding': {
|
|
71
|
+
keywords: ['rebrand', 'rename', 'file-safety'],
|
|
72
|
+
goal: 'Rename files/entities without data loss or breaking changes',
|
|
73
|
+
category: 'file-operations',
|
|
74
|
+
},
|
|
75
|
+
'cli-ux-consistency': {
|
|
76
|
+
keywords: ['cli', 'ux', 'menu', 'navigation', 'clack'],
|
|
77
|
+
goal: 'Provide consistent, intuitive CLI user experience',
|
|
78
|
+
category: 'user-experience',
|
|
79
|
+
},
|
|
80
|
+
'error-prevention': {
|
|
81
|
+
keywords: ['validation', 'error', 'check', 'verify'],
|
|
82
|
+
goal: 'Prevent runtime errors through proactive validation',
|
|
83
|
+
category: 'reliability',
|
|
84
|
+
},
|
|
85
|
+
'code-quality': {
|
|
86
|
+
keywords: ['import', 'architecture', 'quality'],
|
|
87
|
+
goal: 'Maintain clean, maintainable code structure',
|
|
88
|
+
category: 'maintainability',
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Infer lesson intent from tags
|
|
94
|
+
* NO NEW FILE - computed runtime
|
|
95
|
+
*/
|
|
96
|
+
export function inferIntent(tags) {
|
|
97
|
+
if (!tags || tags.length === 0) {
|
|
98
|
+
return {
|
|
99
|
+
id: 'unknown',
|
|
100
|
+
goal: 'General code quality improvement',
|
|
101
|
+
strength: 0.3,
|
|
102
|
+
category: 'general',
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
let bestMatch = null;
|
|
107
|
+
let bestScore = 0;
|
|
108
|
+
|
|
109
|
+
for (const [intentId, pattern] of Object.entries(INTENT_PATTERNS)) {
|
|
110
|
+
const matchCount = tags.filter(tag =>
|
|
111
|
+
pattern.keywords.some(kw => tag.toLowerCase().includes(kw.toLowerCase()))
|
|
112
|
+
).length;
|
|
113
|
+
|
|
114
|
+
const score = matchCount / tags.length; // 0-1 confidence
|
|
115
|
+
|
|
116
|
+
if (score > bestScore) {
|
|
117
|
+
bestScore = score;
|
|
118
|
+
bestMatch = {
|
|
119
|
+
id: intentId,
|
|
120
|
+
goal: pattern.goal,
|
|
121
|
+
strength: score,
|
|
122
|
+
category: pattern.category,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return bestMatch || {
|
|
128
|
+
id: 'unknown',
|
|
129
|
+
goal: 'General code quality improvement',
|
|
130
|
+
strength: 0.3,
|
|
131
|
+
category: 'general',
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// ============================================================================
|
|
136
|
+
// LEVEL 2: Pattern Intelligence
|
|
137
|
+
// ============================================================================
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Build execution context from code
|
|
141
|
+
* Used for contextual pattern matching
|
|
142
|
+
*/
|
|
143
|
+
export function buildContext(filePath, code) {
|
|
144
|
+
const context = {
|
|
145
|
+
framework: null,
|
|
146
|
+
intents: [],
|
|
147
|
+
environment: 'development',
|
|
148
|
+
fileType: path.extname(filePath),
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// Detect framework from imports
|
|
152
|
+
if (code.includes('@clack/prompts')) context.framework = 'clack';
|
|
153
|
+
if (code.includes('inquirer')) context.framework = 'inquirer';
|
|
154
|
+
if (code.includes('react')) context.framework = 'react';
|
|
155
|
+
|
|
156
|
+
// Detect intent from code patterns
|
|
157
|
+
if (code.includes('p.select') || code.includes('showActionMenu')) {
|
|
158
|
+
context.intents.push('select-menu');
|
|
159
|
+
}
|
|
160
|
+
if (code.includes('rename') || code.includes('move')) {
|
|
161
|
+
context.intents.push('file-operation');
|
|
162
|
+
}
|
|
163
|
+
if (code.includes('import')) {
|
|
164
|
+
context.intents.push('module-usage');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return context;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Contextual pattern matching
|
|
172
|
+
* Smarter than text-only regex
|
|
173
|
+
*/
|
|
174
|
+
export function matchPattern(code, mistake, context) {
|
|
175
|
+
// Basic pattern match
|
|
176
|
+
const regex = new RegExp(mistake.pattern);
|
|
177
|
+
const patternMatch = regex.test(code);
|
|
178
|
+
|
|
179
|
+
if (!patternMatch) return false;
|
|
180
|
+
|
|
181
|
+
// Context filtering - skip if not applicable
|
|
182
|
+
if (mistake.when) {
|
|
183
|
+
// Check framework requirement
|
|
184
|
+
if (mistake.when.framework && context.framework !== mistake.when.framework) {
|
|
185
|
+
return false; // Wrong framework, not applicable
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Check intent requirement
|
|
189
|
+
if (mistake.when.intent && !context.intents.includes(mistake.when.intent)) {
|
|
190
|
+
return false; // Intent mismatch
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return true; // Pattern + context match
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// ============================================================================
|
|
198
|
+
// LEVEL 3: Maturity Calculation
|
|
199
|
+
// ============================================================================
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Calculate evidence score based on hit counts
|
|
203
|
+
*/
|
|
204
|
+
function calculateEvidenceScore(mistakes, improvements) {
|
|
205
|
+
const totalMistakeHits = mistakes.reduce((sum, m) => sum + (m.hitCount || 0), 0);
|
|
206
|
+
const totalImprovementHits = improvements.reduce((sum, i) => sum + (i.appliedCount || 0), 0);
|
|
207
|
+
|
|
208
|
+
const totalHits = totalMistakeHits + totalImprovementHits;
|
|
209
|
+
|
|
210
|
+
if (totalHits === 0) return 0.1; // No evidence
|
|
211
|
+
if (totalHits < 5) return 0.3; // Weak
|
|
212
|
+
if (totalHits < 20) return 0.6; // Moderate
|
|
213
|
+
return 0.9; // Strong
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Calculate recency score
|
|
218
|
+
*/
|
|
219
|
+
function calculateRecencyScore(mistakes, improvements) {
|
|
220
|
+
const now = Date.now();
|
|
221
|
+
|
|
222
|
+
const allDates = [
|
|
223
|
+
...mistakes.map(m => new Date(m.lastHit || m.added).getTime()),
|
|
224
|
+
...improvements.map(i => new Date(i.lastApplied || i.added).getTime()),
|
|
225
|
+
];
|
|
226
|
+
|
|
227
|
+
if (allDates.length === 0) return 0.5;
|
|
228
|
+
|
|
229
|
+
const lastUpdate = Math.max(...allDates);
|
|
230
|
+
const daysSinceUpdate = (now - lastUpdate) / (1000 * 60 * 60 * 24);
|
|
231
|
+
|
|
232
|
+
if (daysSinceUpdate < 7) return 1.0; // This week
|
|
233
|
+
if (daysSinceUpdate < 30) return 0.8; // This month
|
|
234
|
+
if (daysSinceUpdate < 90) return 0.5; // This quarter
|
|
235
|
+
return 0.3; // Stale
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Get recommendation based on state and confidence
|
|
240
|
+
*/
|
|
241
|
+
function getRecommendation(state, confidence) {
|
|
242
|
+
if (state === 'RAW') {
|
|
243
|
+
return 'URGENT: Discover best practices for this area';
|
|
244
|
+
}
|
|
245
|
+
if (state === 'LEARNING' && confidence < 0.5) {
|
|
246
|
+
return 'Needs more improvements to balance anti-patterns';
|
|
247
|
+
}
|
|
248
|
+
if (state === 'MATURE' && confidence > 0.8) {
|
|
249
|
+
return 'Stable - can be trusted for skill injection';
|
|
250
|
+
}
|
|
251
|
+
if (state === 'IDEAL') {
|
|
252
|
+
return 'Perfect - all best practices, no anti-patterns';
|
|
253
|
+
}
|
|
254
|
+
return 'Continue learning';
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Calculate lesson maturity metrics
|
|
259
|
+
*/
|
|
260
|
+
export function calculateMaturity(mistakes, improvements) {
|
|
261
|
+
const m = mistakes.length;
|
|
262
|
+
const i = improvements.length;
|
|
263
|
+
|
|
264
|
+
// State determination
|
|
265
|
+
let state;
|
|
266
|
+
if (i === 0 && m > 0) state = 'RAW'; // 🟥 Only mistakes
|
|
267
|
+
else if (i > 0 && m === 0) state = 'IDEAL'; // 🟦 Only improvements (rare)
|
|
268
|
+
else if (i >= m) state = 'MATURE'; // 🟩 Balanced or improvement-heavy
|
|
269
|
+
else state = 'LEARNING'; // 🟨 More mistakes than solutions
|
|
270
|
+
|
|
271
|
+
// Multi-factor confidence
|
|
272
|
+
const balanceScore = i / (m + i); // 0-1: improvement ratio
|
|
273
|
+
const evidenceScore = calculateEvidenceScore(mistakes, improvements); // 0-1: hit validation
|
|
274
|
+
const recencyScore = calculateRecencyScore(mistakes, improvements); // 0-1: freshness
|
|
275
|
+
|
|
276
|
+
const confidence = (
|
|
277
|
+
balanceScore * 0.5 + // Balance is most important
|
|
278
|
+
evidenceScore * 0.3 + // Evidence validates
|
|
279
|
+
recencyScore * 0.2 // Fresh is better
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
return {
|
|
283
|
+
state,
|
|
284
|
+
confidence: Math.round(confidence * 100) / 100,
|
|
285
|
+
indicators: {
|
|
286
|
+
balance: Math.round(balanceScore * 100) / 100,
|
|
287
|
+
evidence: Math.round(evidenceScore * 100) / 100,
|
|
288
|
+
recency: Math.round(recencyScore * 100) / 100,
|
|
289
|
+
},
|
|
290
|
+
coverage: `${m} mistakes / ${i} improvements`,
|
|
291
|
+
recommendation: getRecommendation(state, confidence),
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// ============================================================================
|
|
296
|
+
// LEVEL 4: Evolution Analysis
|
|
297
|
+
// ============================================================================
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Check if mistake has related improvement
|
|
301
|
+
*/
|
|
302
|
+
function hasRelatedImprovement(mistake, improvements) {
|
|
303
|
+
return improvements.some(i =>
|
|
304
|
+
i.tags && mistake.tags && i.tags.some(tag => mistake.tags.includes(tag))
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Determine next action from signals
|
|
310
|
+
*/
|
|
311
|
+
function determineNextAction(signals) {
|
|
312
|
+
if (signals.some(s => s.priority === 'CRITICAL')) {
|
|
313
|
+
return 'Document solution for high-frequency violations immediately';
|
|
314
|
+
}
|
|
315
|
+
if (signals.some(s => s.type === 'SUGGEST_IMPROVEMENT_DISCOVERY')) {
|
|
316
|
+
return 'Research and document best practices in underserved areas';
|
|
317
|
+
}
|
|
318
|
+
return 'Continue normal learning';
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Analyze evolution needs and gaps
|
|
323
|
+
*/
|
|
324
|
+
export function analyzeEvolution(mistakes, improvements, intent) {
|
|
325
|
+
const signals = [];
|
|
326
|
+
const missingAreas = [];
|
|
327
|
+
|
|
328
|
+
// Signal 1: Many mistakes, few solutions
|
|
329
|
+
if (mistakes.length > improvements.length * 2) {
|
|
330
|
+
signals.push({
|
|
331
|
+
type: 'SUGGEST_IMPROVEMENT_DISCOVERY',
|
|
332
|
+
priority: 'HIGH',
|
|
333
|
+
reason: `${mistakes.length} anti-patterns but only ${improvements.length} solution(s)`,
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Signal 2: Uncovered tags
|
|
338
|
+
const mistakeTags = new Set(mistakes.flatMap(m => m.tags || []));
|
|
339
|
+
const improvementTags = new Set(improvements.flatMap(i => i.tags || []));
|
|
340
|
+
|
|
341
|
+
const uncoveredTags = [...mistakeTags].filter(tag => !improvementTags.has(tag));
|
|
342
|
+
|
|
343
|
+
uncoveredTags.forEach(tag => {
|
|
344
|
+
missingAreas.push({
|
|
345
|
+
area: tag,
|
|
346
|
+
reason: 'Anti-patterns detected but no best practice documented',
|
|
347
|
+
mistakeCount: mistakes.filter(m => m.tags && m.tags.includes(tag)).length,
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
// Signal 3: High-hit mistakes without solution
|
|
352
|
+
mistakes.forEach(m => {
|
|
353
|
+
if ((m.hitCount || 0) > 10 && !hasRelatedImprovement(m, improvements)) {
|
|
354
|
+
signals.push({
|
|
355
|
+
type: 'HOT_MISTAKE_NEEDS_SOLUTION',
|
|
356
|
+
priority: 'CRITICAL',
|
|
357
|
+
mistake: m.id,
|
|
358
|
+
reason: `${m.title} hit ${m.hitCount} times but no solution documented`,
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
missingAreas.push({
|
|
362
|
+
area: `solution-for-${m.id}`,
|
|
363
|
+
reason: 'Frequently violated anti-pattern needs best practice',
|
|
364
|
+
hitCount: m.hitCount,
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
// Signal 4: Intent under-served
|
|
370
|
+
if (intent && intent.strength > 0.7) {
|
|
371
|
+
const coverageScore = improvements.length / (mistakes.length + improvements.length);
|
|
372
|
+
if (coverageScore < 0.5) {
|
|
373
|
+
signals.push({
|
|
374
|
+
type: 'INTENT_UNDER_SERVED',
|
|
375
|
+
priority: 'MEDIUM',
|
|
376
|
+
reason: `Intent "${intent.goal}" is clear but solutions are scarce`,
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
return {
|
|
382
|
+
signals,
|
|
383
|
+
missingAreas,
|
|
384
|
+
nextAction: determineNextAction(signals),
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// ============================================================================
|
|
389
|
+
// SYNTHESIS: Build Cognitive Lessons
|
|
390
|
+
// ============================================================================
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Format tag as title
|
|
394
|
+
*/
|
|
395
|
+
function formatTagAsTitle(tag) {
|
|
396
|
+
return tag
|
|
397
|
+
.split('-')
|
|
398
|
+
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
399
|
+
.join(' ');
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Synthesize Cognitive Lesson Units from mistakes + improvements
|
|
404
|
+
* THIS IS THE MAIN FUNCTION
|
|
405
|
+
*/
|
|
406
|
+
export function synthesizeLessons() {
|
|
407
|
+
const mistakesDb = loadMistakes();
|
|
408
|
+
const improvementsDb = loadImprovements();
|
|
409
|
+
|
|
410
|
+
// Group by tag
|
|
411
|
+
const groups = new Map();
|
|
412
|
+
|
|
413
|
+
// Add mistakes to groups
|
|
414
|
+
mistakesDb.mistakes.forEach(m => {
|
|
415
|
+
const tags = m.tags || ['uncategorized'];
|
|
416
|
+
tags.forEach(tag => {
|
|
417
|
+
if (!groups.has(tag)) {
|
|
418
|
+
groups.set(tag, { mistakes: [], improvements: [] });
|
|
419
|
+
}
|
|
420
|
+
groups.get(tag).mistakes.push(m);
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
// Add improvements to groups
|
|
425
|
+
improvementsDb.improvements.forEach(i => {
|
|
426
|
+
const tags = i.tags || ['uncategorized'];
|
|
427
|
+
tags.forEach(tag => {
|
|
428
|
+
if (!groups.has(tag)) {
|
|
429
|
+
groups.set(tag, { mistakes: [], improvements: [] });
|
|
430
|
+
}
|
|
431
|
+
groups.get(tag).improvements.push(i);
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
// Build Cognitive Lessons
|
|
436
|
+
const lessons = [];
|
|
437
|
+
let lessonId = 1;
|
|
438
|
+
|
|
439
|
+
groups.forEach((group, tag) => {
|
|
440
|
+
const intent = inferIntent([tag, ...group.mistakes.flatMap(m => m.tags || [])]);
|
|
441
|
+
const maturity = calculateMaturity(group.mistakes, group.improvements);
|
|
442
|
+
const evolution = analyzeEvolution(group.mistakes, group.improvements, intent);
|
|
443
|
+
|
|
444
|
+
lessons.push({
|
|
445
|
+
id: `LESSON-${String(lessonId++).padStart(3, '0')}`,
|
|
446
|
+
title: formatTagAsTitle(tag),
|
|
447
|
+
tag,
|
|
448
|
+
intent,
|
|
449
|
+
mistakes: group.mistakes,
|
|
450
|
+
improvements: group.improvements,
|
|
451
|
+
maturity,
|
|
452
|
+
evolution,
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
// Sort by maturity (MATURE first, RAW last)
|
|
457
|
+
const stateOrder = { 'IDEAL': 0, 'MATURE': 1, 'LEARNING': 2, 'RAW': 3 };
|
|
458
|
+
lessons.sort((a, b) => {
|
|
459
|
+
const stateCompare = stateOrder[a.maturity.state] - stateOrder[b.maturity.state];
|
|
460
|
+
if (stateCompare !== 0) return stateCompare;
|
|
461
|
+
return b.maturity.confidence - a.maturity.confidence; // Higher confidence first
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
return lessons;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export default {
|
|
468
|
+
loadMistakes,
|
|
469
|
+
loadImprovements,
|
|
470
|
+
inferIntent,
|
|
471
|
+
buildContext,
|
|
472
|
+
matchPattern,
|
|
473
|
+
calculateMaturity,
|
|
474
|
+
analyzeEvolution,
|
|
475
|
+
synthesizeLessons,
|
|
476
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shell completion scripts generator
|
|
3
|
+
* Supports PowerShell, Bash, and Zsh
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* All available commands for completion
|
|
8
|
+
*/
|
|
9
|
+
const COMMANDS = [
|
|
10
|
+
{ name: "learn", description: "Teach a new pattern" },
|
|
11
|
+
{ name: "recall", description: "Scan for violations" },
|
|
12
|
+
{ name: "stats", description: "View statistics" },
|
|
13
|
+
{ name: "audit", description: "Run compliance check" },
|
|
14
|
+
{ name: "watch", description: "Real-time monitoring" },
|
|
15
|
+
{ name: "settings", description: "Configure agent behavior" },
|
|
16
|
+
{ name: "backup", description: "Backup & restore data" },
|
|
17
|
+
{ name: "export", description: "Export & import data" },
|
|
18
|
+
{ name: "proposals", description: "AI agent skill updates" },
|
|
19
|
+
{ name: "completion", description: "Shell completion scripts" },
|
|
20
|
+
{ name: "init", description: "Initialize agent config" },
|
|
21
|
+
{ name: "help", description: "Show help" }
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Generate PowerShell completion script
|
|
26
|
+
* @returns {string}
|
|
27
|
+
*/
|
|
28
|
+
export function generatePowerShellCompletion() {
|
|
29
|
+
const commands = COMMANDS.map(c => `'${c.name}'`).join(", ");
|
|
30
|
+
|
|
31
|
+
return `
|
|
32
|
+
# Agent Skill Kit PowerShell Completion
|
|
33
|
+
# Add to your $PROFILE
|
|
34
|
+
|
|
35
|
+
Register-ArgumentCompleter -Native -CommandName agent -ScriptBlock {
|
|
36
|
+
param($wordToComplete, $commandAst, $cursorPosition)
|
|
37
|
+
|
|
38
|
+
$commands = @(
|
|
39
|
+
${COMMANDS.map(c => ` @{ Name = '${c.name}'; Description = '${c.description}' }`).join("\n")}
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
$commands | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object {
|
|
43
|
+
[System.Management.Automation.CompletionResult]::new(
|
|
44
|
+
$_.Name,
|
|
45
|
+
$_.Name,
|
|
46
|
+
'ParameterValue',
|
|
47
|
+
$_.Description
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
Write-Host "Agent Skill Kit completion loaded" -ForegroundColor Green
|
|
53
|
+
`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Generate Bash completion script
|
|
58
|
+
* @returns {string}
|
|
59
|
+
*/
|
|
60
|
+
export function generateBashCompletion() {
|
|
61
|
+
const commands = COMMANDS.map(c => c.name).join(" ");
|
|
62
|
+
|
|
63
|
+
return `
|
|
64
|
+
# Agent Skill Kit Bash Completion
|
|
65
|
+
# Add to ~/.bashrc or ~/.bash_completion
|
|
66
|
+
|
|
67
|
+
_agent_completions() {
|
|
68
|
+
local cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
69
|
+
local commands="${commands}"
|
|
70
|
+
|
|
71
|
+
COMPREPLY=($(compgen -W "$commands" -- "$cur"))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
complete -F _agent_completions agent
|
|
75
|
+
|
|
76
|
+
echo "Agent Skill Kit completion loaded"
|
|
77
|
+
`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Generate Zsh completion script
|
|
82
|
+
* @returns {string}
|
|
83
|
+
*/
|
|
84
|
+
export function generateZshCompletion() {
|
|
85
|
+
return `
|
|
86
|
+
#compdef agent
|
|
87
|
+
|
|
88
|
+
# Agent Skill Kit Zsh Completion
|
|
89
|
+
# Add to ~/.zshrc or place in $fpath
|
|
90
|
+
|
|
91
|
+
_agent() {
|
|
92
|
+
local -a commands
|
|
93
|
+
commands=(
|
|
94
|
+
${COMMANDS.map(c => ` '${c.name}:${c.description}'`).join("\n")}
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
_describe 'command' commands
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
compdef _agent agent
|
|
101
|
+
|
|
102
|
+
echo "Agent Skill Kit completion loaded"
|
|
103
|
+
`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Get shell type from environment
|
|
108
|
+
* @returns {string} 'powershell' | 'bash' | 'zsh' | 'unknown'
|
|
109
|
+
*/
|
|
110
|
+
export function detectShell() {
|
|
111
|
+
if (process.platform === "win32") {
|
|
112
|
+
return "powershell";
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const shell = process.env.SHELL || "";
|
|
116
|
+
if (shell.includes("zsh")) return "zsh";
|
|
117
|
+
if (shell.includes("bash")) return "bash";
|
|
118
|
+
|
|
119
|
+
return "unknown";
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Get completion script for current or specified shell
|
|
124
|
+
* @param {string} [shell] - Optional shell type
|
|
125
|
+
* @returns {{ shell: string, script: string }}
|
|
126
|
+
*/
|
|
127
|
+
export function getCompletionScript(shell) {
|
|
128
|
+
const targetShell = shell || detectShell();
|
|
129
|
+
|
|
130
|
+
switch (targetShell) {
|
|
131
|
+
case "powershell":
|
|
132
|
+
return { shell: "powershell", script: generatePowerShellCompletion() };
|
|
133
|
+
case "bash":
|
|
134
|
+
return { shell: "bash", script: generateBashCompletion() };
|
|
135
|
+
case "zsh":
|
|
136
|
+
return { shell: "zsh", script: generateZshCompletion() };
|
|
137
|
+
default:
|
|
138
|
+
return { shell: "unknown", script: "" };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export default {
|
|
143
|
+
COMMANDS,
|
|
144
|
+
generatePowerShellCompletion,
|
|
145
|
+
generateBashCompletion,
|
|
146
|
+
generateZshCompletion,
|
|
147
|
+
detectShell,
|
|
148
|
+
getCompletionScript
|
|
149
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Configuration for agent-skill-kit CLI
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
import { createRequire } from "module";
|
|
8
|
+
|
|
9
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
|
|
12
|
+
/** Current working directory */
|
|
13
|
+
export const cwd = process.cwd();
|
|
14
|
+
|
|
15
|
+
/** Path to .agent directory (configurable via AGENT_DIR env) */
|
|
16
|
+
export const AGENT_DIR = process.env.AGENT_DIR || path.join(cwd, ".agent");
|
|
17
|
+
|
|
18
|
+
/** Path to knowledge directory */
|
|
19
|
+
export const KNOWLEDGE_DIR = path.join(AGENT_DIR, "knowledge");
|
|
20
|
+
|
|
21
|
+
/** Path to lessons learned file */
|
|
22
|
+
export const LESSONS_PATH = path.join(KNOWLEDGE_DIR, "lessons-learned.yaml");
|
|
23
|
+
|
|
24
|
+
/** Path to rules directory */
|
|
25
|
+
export const RULES_DIR = path.join(AGENT_DIR, "rules");
|
|
26
|
+
|
|
27
|
+
/** CLI version - read from package.json */
|
|
28
|
+
export const VERSION = (() => {
|
|
29
|
+
try { return require("../package.json").version; }
|
|
30
|
+
catch { return "2.2.0"; }
|
|
31
|
+
})();
|
|
32
|
+
|
|
33
|
+
/** Debug mode */
|
|
34
|
+
export const DEBUG = process.env.DEBUG === "true";
|
|
35
|
+
|