@sysvv/ai-skill 1.6.2 → 1.7.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/dist/index.js +59 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -159,19 +159,78 @@ async function installSkills(agent) {
|
|
|
159
159
|
}
|
|
160
160
|
if (mcpsToInstall.size > 0) {
|
|
161
161
|
console.log('');
|
|
162
|
+
const envVarsNeeded = new Map();
|
|
162
163
|
for (const mcpName of mcpsToInstall) {
|
|
163
164
|
try {
|
|
164
165
|
const mcp = await loadMcp(mcpName);
|
|
165
166
|
const mcpTarget = await writeMcp(agent, mcp);
|
|
166
167
|
console.log(` ${GREEN}✔${ANSI.reset} MCP ${ANSI.bold}${mcpName}${ANSI.reset} ${ANSI.dim}→ ${mcpTarget}${ANSI.reset}`);
|
|
168
|
+
// Coleta env vars do MCP
|
|
169
|
+
if (mcp.env) {
|
|
170
|
+
for (const key of Object.keys(mcp.env)) {
|
|
171
|
+
envVarsNeeded.set(key, mcpName);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
167
174
|
}
|
|
168
175
|
catch (err) {
|
|
169
176
|
console.log(` ${RED}✖${ANSI.reset} MCP ${mcpName}: ${err.message}`);
|
|
170
177
|
}
|
|
171
178
|
}
|
|
179
|
+
// Atualiza .env
|
|
180
|
+
if (envVarsNeeded.size > 0) {
|
|
181
|
+
await ensureEnvFile(envVarsNeeded);
|
|
182
|
+
}
|
|
172
183
|
}
|
|
173
184
|
console.log(`\n Skills instaladas em ${ANSI.bold}${destBase}/${ANSI.reset}\n`);
|
|
174
185
|
}
|
|
186
|
+
// ── .env ────────────────────────────────────────────────────────────────
|
|
187
|
+
/** Garante que o .env tenha as variáveis necessárias dos MCPs */
|
|
188
|
+
async function ensureEnvFile(envVars) {
|
|
189
|
+
const envPath = path.resolve(".env");
|
|
190
|
+
// Lê .env existente
|
|
191
|
+
let existing = '';
|
|
192
|
+
if (await fs.pathExists(envPath)) {
|
|
193
|
+
existing = await fs.readFile(envPath, "utf8");
|
|
194
|
+
}
|
|
195
|
+
// Descobre quais chaves já existem
|
|
196
|
+
const existingKeys = new Set();
|
|
197
|
+
for (const line of existing.split('\n')) {
|
|
198
|
+
const match = line.match(/^([A-Z_][A-Z0-9_]*)=/);
|
|
199
|
+
if (match)
|
|
200
|
+
existingKeys.add(match[1]);
|
|
201
|
+
}
|
|
202
|
+
// Filtra só as que faltam
|
|
203
|
+
const missing = [];
|
|
204
|
+
for (const [key, mcp] of envVars) {
|
|
205
|
+
if (!existingKeys.has(key)) {
|
|
206
|
+
missing.push({ key, mcp });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (missing.length === 0)
|
|
210
|
+
return;
|
|
211
|
+
// Monta as linhas novas
|
|
212
|
+
const lines = [];
|
|
213
|
+
if (existing.length > 0 && !existing.endsWith('\n')) {
|
|
214
|
+
lines.push('');
|
|
215
|
+
}
|
|
216
|
+
// Agrupa por MCP
|
|
217
|
+
const byMcp = new Map();
|
|
218
|
+
for (const { key, mcp } of missing) {
|
|
219
|
+
if (!byMcp.has(mcp))
|
|
220
|
+
byMcp.set(mcp, []);
|
|
221
|
+
byMcp.get(mcp).push(key);
|
|
222
|
+
}
|
|
223
|
+
for (const [mcp, keys] of byMcp) {
|
|
224
|
+
lines.push(`# ${mcp}`);
|
|
225
|
+
for (const key of keys) {
|
|
226
|
+
lines.push(`${key}=`);
|
|
227
|
+
}
|
|
228
|
+
lines.push('');
|
|
229
|
+
}
|
|
230
|
+
await fs.writeFile(envPath, existing + lines.join('\n'), "utf8");
|
|
231
|
+
console.log(`\n ${GREEN}✔${ANSI.reset} .env ${ANSI.dim}→ ${missing.map(m => m.key).join(', ')}${ANSI.reset}`);
|
|
232
|
+
console.log(` ${YELLOW}!${ANSI.reset} Preencha as variáveis no ${ANSI.bold}.env${ANSI.reset} antes de usar`);
|
|
233
|
+
}
|
|
175
234
|
// ── Clear ───────────────────────────────────────────────────────────────
|
|
176
235
|
/** Todas as pastas/arquivos que o CLI pode criar, por agent */
|
|
177
236
|
const AGENT_ROOTS = {
|