@indiccoder/mentis-cli 1.0.8 ā 1.1.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/.mentis/commands/ls.md +12 -0
- package/dist/commands/Command.js +6 -0
- package/dist/commands/CommandCreator.js +286 -0
- package/dist/commands/CommandManager.js +268 -0
- package/dist/commands/SlashCommandTool.js +160 -0
- package/dist/repl/ReplManager.js +245 -3
- package/dist/skills/LoadSkillTool.js +133 -0
- package/dist/skills/Skill.js +6 -0
- package/dist/skills/SkillCreator.js +247 -0
- package/dist/skills/SkillsManager.js +337 -0
- package/dist/ui/UIManager.js +2 -2
- package/dist/utils/ContextVisualizer.js +92 -0
- package/dist/utils/ConversationCompacter.js +98 -0
- package/dist/utils/ProjectInitializer.js +181 -0
- package/docs/SKILLS.md +319 -0
- package/examples/skills/code-reviewer/SKILL.md +88 -0
- package/examples/skills/commit-helper/SKILL.md +66 -0
- package/examples/skills/pdf-processing/SKILL.md +108 -0
- package/package.json +4 -3
- package/src/commands/Command.ts +40 -0
- package/src/commands/CommandCreator.ts +281 -0
- package/src/commands/CommandManager.ts +280 -0
- package/src/commands/SlashCommandTool.ts +152 -0
- package/src/repl/ReplManager.ts +302 -3
- package/src/skills/LoadSkillTool.ts +168 -0
- package/src/skills/Skill.ts +51 -0
- package/src/skills/SkillCreator.ts +237 -0
- package/src/skills/SkillsManager.ts +354 -0
- package/src/ui/UIManager.ts +2 -2
- package/src/utils/ContextVisualizer.ts +105 -0
- package/src/utils/ConversationCompacter.ts +124 -0
- package/src/utils/ProjectInitializer.ts +170 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SkillCreator - Interactive wizard for creating new skills
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.SkillCreator = void 0;
|
|
43
|
+
exports.validateSkills = validateSkills;
|
|
44
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
45
|
+
const fs = __importStar(require("fs"));
|
|
46
|
+
const path = __importStar(require("path"));
|
|
47
|
+
const os = __importStar(require("os"));
|
|
48
|
+
const SkillsManager_1 = require("./SkillsManager");
|
|
49
|
+
class SkillCreator {
|
|
50
|
+
constructor(skillsManager) {
|
|
51
|
+
this.skillsManager = skillsManager || new SkillsManager_1.SkillsManager();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Run the interactive skill creation wizard
|
|
55
|
+
*/
|
|
56
|
+
async run(name) {
|
|
57
|
+
console.log('\nš Create a new Skill\n');
|
|
58
|
+
let skillName;
|
|
59
|
+
let skillType;
|
|
60
|
+
let description;
|
|
61
|
+
let allowedTools;
|
|
62
|
+
// Step 1: Skill Name
|
|
63
|
+
if (name) {
|
|
64
|
+
skillName = name;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
const { name: inputName } = await inquirer_1.default.prompt([
|
|
68
|
+
{
|
|
69
|
+
type: 'input',
|
|
70
|
+
name: 'name',
|
|
71
|
+
message: 'Skill name (lowercase, numbers, hyphens only):',
|
|
72
|
+
validate: (input) => {
|
|
73
|
+
if (!input)
|
|
74
|
+
return 'Name is required';
|
|
75
|
+
if (!/^[a-z0-9-]+$/.test(input)) {
|
|
76
|
+
return 'Name must contain only lowercase letters, numbers, and hyphens';
|
|
77
|
+
}
|
|
78
|
+
if (input.length > 64)
|
|
79
|
+
return 'Name must be 64 characters or less';
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
]);
|
|
84
|
+
skillName = inputName;
|
|
85
|
+
}
|
|
86
|
+
// Step 2: Skill Type
|
|
87
|
+
const { type } = await inquirer_1.default.prompt([
|
|
88
|
+
{
|
|
89
|
+
type: 'list',
|
|
90
|
+
name: 'type',
|
|
91
|
+
message: 'Skill type:',
|
|
92
|
+
choices: [
|
|
93
|
+
{ name: 'Personal (available in all projects)', value: 'personal' },
|
|
94
|
+
{ name: 'Project (shared with team via git)', value: 'project' }
|
|
95
|
+
],
|
|
96
|
+
default: 'personal'
|
|
97
|
+
}
|
|
98
|
+
]);
|
|
99
|
+
skillType = type;
|
|
100
|
+
// Step 3: Description
|
|
101
|
+
const { desc } = await inquirer_1.default.prompt([
|
|
102
|
+
{
|
|
103
|
+
type: 'input',
|
|
104
|
+
name: 'desc',
|
|
105
|
+
message: 'Description (what it does + when to use it):',
|
|
106
|
+
validate: (input) => {
|
|
107
|
+
if (!input)
|
|
108
|
+
return 'Description is required';
|
|
109
|
+
if (input.length > 1024)
|
|
110
|
+
return 'Description must be 1024 characters or less';
|
|
111
|
+
if (!input.toLowerCase().includes('use when') && !input.toLowerCase().includes('use for')) {
|
|
112
|
+
return 'Tip: Include when to use this skill (e.g., "Use when...")';
|
|
113
|
+
}
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
]);
|
|
118
|
+
description = desc;
|
|
119
|
+
// Step 4: Allowed Tools (optional)
|
|
120
|
+
const { useAllowedTools } = await inquirer_1.default.prompt([
|
|
121
|
+
{
|
|
122
|
+
type: 'confirm',
|
|
123
|
+
name: 'useAllowedTools',
|
|
124
|
+
message: 'Restrict which tools this skill can use?',
|
|
125
|
+
default: false
|
|
126
|
+
}
|
|
127
|
+
]);
|
|
128
|
+
if (useAllowedTools) {
|
|
129
|
+
const { tools } = await inquirer_1.default.prompt([
|
|
130
|
+
{
|
|
131
|
+
type: 'checkbox',
|
|
132
|
+
name: 'tools',
|
|
133
|
+
message: 'Select allowed tools:',
|
|
134
|
+
choices: [
|
|
135
|
+
{ name: 'Read (read_file)', value: 'Read' },
|
|
136
|
+
{ name: 'Write (write_file)', value: 'Write' },
|
|
137
|
+
{ name: 'Edit (edit_file)', value: 'Edit' },
|
|
138
|
+
{ name: 'Grep (search files)', value: 'Grep' },
|
|
139
|
+
{ name: 'Glob (find files)', value: 'Glob' },
|
|
140
|
+
{ name: 'ListDir (list directory)', value: 'ListDir' },
|
|
141
|
+
{ name: 'SearchFile (search in files)', value: 'SearchFile' },
|
|
142
|
+
{ name: 'RunShell (run shell command)', value: 'RunShell' },
|
|
143
|
+
{ name: 'WebSearch (web search)', value: 'WebSearch' },
|
|
144
|
+
{ name: 'GitStatus', value: 'GitStatus' },
|
|
145
|
+
{ name: 'GitDiff', value: 'GitDiff' },
|
|
146
|
+
{ name: 'GitCommit', value: 'GitCommit' },
|
|
147
|
+
{ name: 'GitPush', value: 'GitPush' },
|
|
148
|
+
{ name: 'GitPull', value: 'GitPull' }
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
]);
|
|
152
|
+
allowedTools = tools.length > 0 ? tools : undefined;
|
|
153
|
+
}
|
|
154
|
+
// Step 5: Create the skill
|
|
155
|
+
return this.createSkill(skillName, skillType, description, allowedTools);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Create the skill file and directory
|
|
159
|
+
*/
|
|
160
|
+
async createSkill(name, type, description, allowedTools) {
|
|
161
|
+
const baseDir = type === 'personal'
|
|
162
|
+
? path.join(os.homedir(), '.mentis', 'skills')
|
|
163
|
+
: path.join(process.cwd(), '.mentis', 'skills');
|
|
164
|
+
const skillDir = path.join(baseDir, name);
|
|
165
|
+
const skillFile = path.join(skillDir, 'SKILL.md');
|
|
166
|
+
// Check if skill already exists
|
|
167
|
+
if (fs.existsSync(skillFile)) {
|
|
168
|
+
const { overwrite } = await inquirer_1.default.prompt([
|
|
169
|
+
{
|
|
170
|
+
type: 'confirm',
|
|
171
|
+
name: 'overwrite',
|
|
172
|
+
message: `Skill "${name}" already exists. Overwrite?`,
|
|
173
|
+
default: false
|
|
174
|
+
}
|
|
175
|
+
]);
|
|
176
|
+
if (!overwrite) {
|
|
177
|
+
console.log('Cancelled.');
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Create directory
|
|
182
|
+
if (!fs.existsSync(skillDir)) {
|
|
183
|
+
fs.mkdirSync(skillDir, { recursive: true });
|
|
184
|
+
}
|
|
185
|
+
// Generate SKILL.md content
|
|
186
|
+
let content = `---\nname: ${name}\ndescription: ${description}\n`;
|
|
187
|
+
if (allowedTools && allowedTools.length > 0) {
|
|
188
|
+
content += `allowed-tools: [${allowedTools.map(t => `"${t}"`).join(', ')}]\n`;
|
|
189
|
+
}
|
|
190
|
+
content += `---\n\n# ${this.formatTitle(name)}\n\n`;
|
|
191
|
+
content += `## Overview\n\n`;
|
|
192
|
+
content += `This skill provides...\n\n`;
|
|
193
|
+
content += `## Instructions\n\n`;
|
|
194
|
+
content += `### Step 1: ...\n\n`;
|
|
195
|
+
content += `### Step 2: ...\n\n`;
|
|
196
|
+
content += `## Examples\n\n`;
|
|
197
|
+
content += `\`\`\`\n`;
|
|
198
|
+
content += `// Example usage\n`;
|
|
199
|
+
content += `\`\`\`\n`;
|
|
200
|
+
// Write SKILL.md
|
|
201
|
+
fs.writeFileSync(skillFile, content, 'utf-8');
|
|
202
|
+
console.log(`\nā Skill created at: ${skillFile}`);
|
|
203
|
+
console.log(`\nNext steps:`);
|
|
204
|
+
console.log(` 1. Edit ${skillFile} to add instructions`);
|
|
205
|
+
console.log(` 2. Add supporting files (reference.md, examples.md, scripts/) as needed`);
|
|
206
|
+
console.log(` 3. Restart Mentis to load the new skill`);
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Format skill name to title case
|
|
211
|
+
*/
|
|
212
|
+
formatTitle(name) {
|
|
213
|
+
return name
|
|
214
|
+
.split('-')
|
|
215
|
+
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
216
|
+
.join(' ');
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
exports.SkillCreator = SkillCreator;
|
|
220
|
+
/**
|
|
221
|
+
* Validate skills and show results
|
|
222
|
+
*/
|
|
223
|
+
async function validateSkills(skillsManager) {
|
|
224
|
+
const results = skillsManager.validateAllSkills();
|
|
225
|
+
console.log('\nš Skill Validation Results\n');
|
|
226
|
+
let hasErrors = false;
|
|
227
|
+
let hasWarnings = false;
|
|
228
|
+
for (const [name, result] of results) {
|
|
229
|
+
if (result.isValid) {
|
|
230
|
+
console.log(`ā ${name}`);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
console.log(`ā ${name}`);
|
|
234
|
+
hasErrors = true;
|
|
235
|
+
}
|
|
236
|
+
if (result.errors.length > 0) {
|
|
237
|
+
result.errors.forEach(err => console.log(` ERROR: ${err}`));
|
|
238
|
+
}
|
|
239
|
+
if (result.warnings.length > 0) {
|
|
240
|
+
hasWarnings = true;
|
|
241
|
+
result.warnings.forEach(warn => console.log(` WARNING: ${warn}`));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (!hasErrors && !hasWarnings) {
|
|
245
|
+
console.log('\nā All skills are valid!');
|
|
246
|
+
}
|
|
247
|
+
}
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SkillsManager - Core module for Agent Skills system
|
|
4
|
+
* Handles discovery, loading, and validation of skills
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
40
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
41
|
+
};
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.SkillsManager = void 0;
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
const path = __importStar(require("path"));
|
|
46
|
+
const os = __importStar(require("os"));
|
|
47
|
+
const fast_glob_1 = require("fast-glob");
|
|
48
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
49
|
+
class SkillsManager {
|
|
50
|
+
constructor(cwd = process.cwd()) {
|
|
51
|
+
this.skills = new Map();
|
|
52
|
+
this.personalSkillsDir = path.join(os.homedir(), '.mentis', 'skills');
|
|
53
|
+
this.projectSkillsDir = path.join(cwd, '.mentis', 'skills');
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Discover all skills from configured directories
|
|
57
|
+
*/
|
|
58
|
+
async discoverSkills(options = {}) {
|
|
59
|
+
const { includePersonal = true, includeProject = true, includePlugin = false // Plugin skills not implemented yet
|
|
60
|
+
} = options;
|
|
61
|
+
const discovered = [];
|
|
62
|
+
if (includePersonal) {
|
|
63
|
+
discovered.push(...await this.discoverSkillsInDirectory(this.personalSkillsDir, 'personal'));
|
|
64
|
+
}
|
|
65
|
+
if (includeProject) {
|
|
66
|
+
discovered.push(...await this.discoverSkillsInDirectory(this.projectSkillsDir, 'project'));
|
|
67
|
+
}
|
|
68
|
+
// Store skills in map for quick lookup
|
|
69
|
+
for (const skill of discovered) {
|
|
70
|
+
this.skills.set(skill.name, skill);
|
|
71
|
+
}
|
|
72
|
+
return Array.from(this.skills.values());
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Discover skills in a specific directory
|
|
76
|
+
*/
|
|
77
|
+
async discoverSkillsInDirectory(dir, type) {
|
|
78
|
+
if (!fs.existsSync(dir)) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
const skills = [];
|
|
82
|
+
try {
|
|
83
|
+
// Find all SKILL.md files in subdirectories
|
|
84
|
+
const skillFiles = await (0, fast_glob_1.glob)('**/SKILL.md', {
|
|
85
|
+
cwd: dir,
|
|
86
|
+
absolute: true,
|
|
87
|
+
onlyFiles: true
|
|
88
|
+
});
|
|
89
|
+
for (const skillFile of skillFiles) {
|
|
90
|
+
const skillDir = path.dirname(skillFile);
|
|
91
|
+
const skillName = path.basename(skillDir);
|
|
92
|
+
const skill = await this.loadSkillMetadata(skillFile, skillDir, type);
|
|
93
|
+
if (skill) {
|
|
94
|
+
skills.push(skill);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
console.error(`Error discovering skills in ${dir}: ${error.message}`);
|
|
100
|
+
}
|
|
101
|
+
return skills;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Load only the metadata (YAML frontmatter) from a SKILL.md file
|
|
105
|
+
* This is used for progressive disclosure - only name/description loaded at startup
|
|
106
|
+
*/
|
|
107
|
+
async loadSkillMetadata(skillPath, skillDir, type) {
|
|
108
|
+
try {
|
|
109
|
+
const content = fs.readFileSync(skillPath, 'utf-8');
|
|
110
|
+
const frontmatter = this.extractFrontmatter(content);
|
|
111
|
+
if (!frontmatter) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
// Convert SkillFrontmatter to SkillMetadata for validation
|
|
115
|
+
const metadata = {
|
|
116
|
+
name: frontmatter.name,
|
|
117
|
+
description: frontmatter.description,
|
|
118
|
+
allowedTools: frontmatter['allowed-tools']
|
|
119
|
+
};
|
|
120
|
+
const validation = this.validateSkillMetadata(metadata);
|
|
121
|
+
const skill = {
|
|
122
|
+
name: frontmatter.name,
|
|
123
|
+
description: frontmatter.description,
|
|
124
|
+
allowedTools: frontmatter['allowed-tools'],
|
|
125
|
+
path: skillPath,
|
|
126
|
+
directory: skillDir,
|
|
127
|
+
type,
|
|
128
|
+
isValid: validation.isValid,
|
|
129
|
+
errors: validation.errors.length > 0 ? validation.errors : undefined
|
|
130
|
+
};
|
|
131
|
+
return skill;
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
console.error(`Error loading skill metadata from ${skillPath}: ${error.message}`);
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Load the full content of a skill (for progressive disclosure)
|
|
140
|
+
*/
|
|
141
|
+
async loadFullSkill(name) {
|
|
142
|
+
const skill = this.skills.get(name);
|
|
143
|
+
if (!skill) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
const content = fs.readFileSync(skill.path, 'utf-8');
|
|
148
|
+
skill.content = content;
|
|
149
|
+
return skill;
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
console.error(`Error loading full skill ${name}: ${error.message}`);
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Extract YAML frontmatter from markdown content
|
|
158
|
+
*/
|
|
159
|
+
extractFrontmatter(content) {
|
|
160
|
+
const frontmatterRegex = /^---\s*\n([\s\S]*?)\n---\s*\n/;
|
|
161
|
+
const match = content.match(frontmatterRegex);
|
|
162
|
+
if (!match) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
const parsed = yaml_1.default.parse(match[1]);
|
|
167
|
+
return parsed;
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Validate skill metadata according to Claude Code spec
|
|
175
|
+
*/
|
|
176
|
+
validateSkillMetadata(metadata) {
|
|
177
|
+
const errors = [];
|
|
178
|
+
const warnings = [];
|
|
179
|
+
// Check required fields
|
|
180
|
+
if (!metadata.name) {
|
|
181
|
+
errors.push('Missing required field: name');
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
// Name validation: lowercase letters, numbers, hyphens only, max 64 chars
|
|
185
|
+
const nameRegex = /^[a-z0-9-]+$/;
|
|
186
|
+
if (!nameRegex.test(metadata.name)) {
|
|
187
|
+
errors.push('Name must contain only lowercase letters, numbers, and hyphens');
|
|
188
|
+
}
|
|
189
|
+
if (metadata.name.length > 64) {
|
|
190
|
+
errors.push('Name must be 64 characters or less');
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (!metadata.description) {
|
|
194
|
+
errors.push('Missing required field: description');
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
if (metadata.description.length > 1024) {
|
|
198
|
+
errors.push('Description must be 1024 characters or less');
|
|
199
|
+
}
|
|
200
|
+
// Check if description mentions when to use
|
|
201
|
+
if (!metadata.description.toLowerCase().includes('use when') &&
|
|
202
|
+
!metadata.description.toLowerCase().includes('use for')) {
|
|
203
|
+
warnings.push('Description should include when to use this skill (e.g., "Use when...")');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Validate allowed-tools if present
|
|
207
|
+
if (metadata.allowedTools) {
|
|
208
|
+
const validTools = [
|
|
209
|
+
'Read', 'Write', 'Edit', 'Grep', 'Glob', 'Bash', 'WebSearch',
|
|
210
|
+
'GitStatus', 'GitDiff', 'GitCommit', 'GitPush', 'GitPull',
|
|
211
|
+
'ListDir', 'SearchFile', 'RunShell'
|
|
212
|
+
];
|
|
213
|
+
const invalidTools = metadata.allowedTools.filter(t => !validTools.includes(t));
|
|
214
|
+
if (invalidTools.length > 0) {
|
|
215
|
+
warnings.push(`Unknown tools in allowed-tools: ${invalidTools.join(', ')}`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
isValid: errors.length === 0,
|
|
220
|
+
errors,
|
|
221
|
+
warnings
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Get skill by name
|
|
226
|
+
*/
|
|
227
|
+
getSkill(name) {
|
|
228
|
+
return this.skills.get(name);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Get all skills
|
|
232
|
+
*/
|
|
233
|
+
getAllSkills() {
|
|
234
|
+
return Array.from(this.skills.values());
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get skills formatted for model context injection
|
|
238
|
+
* This provides only metadata for progressive disclosure
|
|
239
|
+
*/
|
|
240
|
+
getSkillsContext() {
|
|
241
|
+
const skills = this.getAllSkills().filter(s => s.isValid);
|
|
242
|
+
if (skills.length === 0) {
|
|
243
|
+
return '';
|
|
244
|
+
}
|
|
245
|
+
const context = skills.map(skill => {
|
|
246
|
+
return `- ${skill.name}: ${skill.description}`;
|
|
247
|
+
}).join('\n');
|
|
248
|
+
return `Available Skills:\n${context}`;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Get skills as SkillContext array
|
|
252
|
+
*/
|
|
253
|
+
getSkillsContextArray() {
|
|
254
|
+
return this.getAllSkills()
|
|
255
|
+
.filter(s => s.isValid)
|
|
256
|
+
.map(s => ({
|
|
257
|
+
name: s.name,
|
|
258
|
+
description: s.description
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Validate all loaded skills
|
|
263
|
+
*/
|
|
264
|
+
validateAllSkills() {
|
|
265
|
+
const results = new Map();
|
|
266
|
+
for (const [name, skill] of this.skills) {
|
|
267
|
+
const metadata = {
|
|
268
|
+
name: skill.name,
|
|
269
|
+
description: skill.description,
|
|
270
|
+
allowedTools: skill.allowedTools
|
|
271
|
+
};
|
|
272
|
+
results.set(name, this.validateSkillMetadata(metadata));
|
|
273
|
+
}
|
|
274
|
+
return results;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Read a supporting file from a skill directory
|
|
278
|
+
* Used for progressive disclosure of skill resources
|
|
279
|
+
*/
|
|
280
|
+
readSkillFile(skillName, fileName) {
|
|
281
|
+
const skill = this.skills.get(skillName);
|
|
282
|
+
if (!skill) {
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
const filePath = path.join(skill.directory, fileName);
|
|
286
|
+
if (!fs.existsSync(filePath)) {
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
try {
|
|
290
|
+
return fs.readFileSync(filePath, 'utf-8');
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* List supporting files in a skill directory
|
|
298
|
+
*/
|
|
299
|
+
listSkillFiles(skillName) {
|
|
300
|
+
const skill = this.skills.get(skillName);
|
|
301
|
+
if (!skill) {
|
|
302
|
+
return [];
|
|
303
|
+
}
|
|
304
|
+
if (!fs.existsSync(skill.directory)) {
|
|
305
|
+
return [];
|
|
306
|
+
}
|
|
307
|
+
try {
|
|
308
|
+
const files = fs.readdirSync(skill.directory);
|
|
309
|
+
// Exclude SKILL.md as it's the main file
|
|
310
|
+
return files.filter(f => f !== 'SKILL.md');
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
return [];
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Create skills directories if they don't exist
|
|
318
|
+
*/
|
|
319
|
+
ensureDirectoriesExist() {
|
|
320
|
+
if (!fs.existsSync(this.personalSkillsDir)) {
|
|
321
|
+
fs.mkdirSync(this.personalSkillsDir, { recursive: true });
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Get personal skills directory path
|
|
326
|
+
*/
|
|
327
|
+
getPersonalSkillsDir() {
|
|
328
|
+
return this.personalSkillsDir;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Get project skills directory path
|
|
332
|
+
*/
|
|
333
|
+
getProjectSkillsDir() {
|
|
334
|
+
return this.projectSkillsDir;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
exports.SkillsManager = SkillsManager;
|
package/dist/ui/UIManager.js
CHANGED
|
@@ -19,12 +19,12 @@ class UIManager {
|
|
|
19
19
|
whitespaceBreak: true,
|
|
20
20
|
});
|
|
21
21
|
console.log(gradient_string_1.default.pastel.multiline(logoText));
|
|
22
|
-
console.log(chalk_1.default.gray(' v1.0
|
|
22
|
+
console.log(chalk_1.default.gray(' v1.1.0 - AI Coding Agent'));
|
|
23
23
|
console.log('');
|
|
24
24
|
}
|
|
25
25
|
static renderDashboard(config) {
|
|
26
26
|
const { model, cwd } = config;
|
|
27
|
-
const version = 'v1.0
|
|
27
|
+
const version = 'v1.1.0';
|
|
28
28
|
// Layout: Left (Status/Welcome) | Right (Tips/Activity)
|
|
29
29
|
// Total width ~80 chars.
|
|
30
30
|
// Left ~45, Right ~30.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ContextVisualizer - Auto context bar display
|
|
4
|
+
* Shows token usage as a colored progress bar
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ContextVisualizer = void 0;
|
|
11
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
12
|
+
class ContextVisualizer {
|
|
13
|
+
constructor(maxTokens) {
|
|
14
|
+
this.maxTokens = 128000; // Default context window
|
|
15
|
+
if (maxTokens) {
|
|
16
|
+
this.maxTokens = maxTokens;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Calculate approximate token count from text
|
|
21
|
+
* Rough estimate: ~4 characters per token
|
|
22
|
+
*/
|
|
23
|
+
estimateTokens(text) {
|
|
24
|
+
if (!text)
|
|
25
|
+
return 0;
|
|
26
|
+
// Rough estimation: ~4 characters per token for English text
|
|
27
|
+
return Math.ceil(text.length / 4);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Calculate total tokens from message history
|
|
31
|
+
*/
|
|
32
|
+
calculateUsage(history) {
|
|
33
|
+
let totalChars = 0;
|
|
34
|
+
for (const msg of history) {
|
|
35
|
+
if (msg.content) {
|
|
36
|
+
totalChars += msg.content.length;
|
|
37
|
+
}
|
|
38
|
+
if (msg.tool_calls) {
|
|
39
|
+
totalChars += JSON.stringify(msg.tool_calls).length;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Add overhead for system prompt, skills, etc.
|
|
43
|
+
totalChars += 2000;
|
|
44
|
+
// Rough estimation: ~4 characters per token
|
|
45
|
+
const tokens = Math.ceil(totalChars / 4);
|
|
46
|
+
const percentage = Math.min(100, Math.round((tokens / this.maxTokens) * 100));
|
|
47
|
+
return { tokens, percentage, maxTokens: this.maxTokens };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Format the context bar for display
|
|
51
|
+
*/
|
|
52
|
+
formatBar(usage) {
|
|
53
|
+
const { percentage, tokens, maxTokens } = usage;
|
|
54
|
+
// Create progress bar (20 chars wide)
|
|
55
|
+
const filled = Math.round(percentage / 5);
|
|
56
|
+
const empty = 20 - filled;
|
|
57
|
+
let bar;
|
|
58
|
+
if (percentage < 60) {
|
|
59
|
+
bar = chalk_1.default.green('ā'.repeat(filled)) + chalk_1.default.gray('ā'.repeat(empty));
|
|
60
|
+
}
|
|
61
|
+
else if (percentage < 80) {
|
|
62
|
+
bar = chalk_1.default.yellow('ā'.repeat(filled)) + chalk_1.default.gray('ā'.repeat(empty));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
bar = chalk_1.default.red('ā'.repeat(filled)) + chalk_1.default.gray('ā'.repeat(empty));
|
|
66
|
+
}
|
|
67
|
+
const tokensK = Math.round(tokens / 1000);
|
|
68
|
+
const maxTokensK = Math.round(maxTokens / 1000);
|
|
69
|
+
return `${bar} ${percentage}% | ${tokensK}k/${maxTokensK} tokens`;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get the context bar string for current history
|
|
73
|
+
*/
|
|
74
|
+
getContextBar(history) {
|
|
75
|
+
const usage = this.calculateUsage(history);
|
|
76
|
+
return this.formatBar(usage);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Check if context is at warning threshold (>=80%)
|
|
80
|
+
*/
|
|
81
|
+
shouldCompact(history) {
|
|
82
|
+
const usage = this.calculateUsage(history);
|
|
83
|
+
return usage.percentage >= 80;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Set custom max tokens (for different models)
|
|
87
|
+
*/
|
|
88
|
+
setMaxTokens(max) {
|
|
89
|
+
this.maxTokens = max;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.ContextVisualizer = ContextVisualizer;
|