@ureck/alexandria 1.1.0 → 1.3.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 +8 -5
- package/dist/chunk-53SIGH5A.js +69 -0
- package/dist/{chunk-TFQ7WSIB.js → chunk-CIOCSIB5.js} +6 -0
- package/dist/{chunk-XY7U4CAQ.js → chunk-FBGIFNIO.js} +1 -1
- package/dist/{chunk-AXUEYSNZ.js → chunk-QB37UGO6.js} +224 -23
- package/dist/{chunk-AHBSZGSC.js → chunk-UWB6RKVN.js} +2 -1
- package/dist/{chunk-T5VNBQEC.js → chunk-ZIQYAQCF.js} +2 -2
- package/dist/cli.js +462 -129
- package/dist/hooks/on-prompt.js +15 -8
- package/dist/hooks/on-session-start.js +3 -4
- package/dist/hooks/on-stop.js +27 -3
- package/dist/mcp/server.js +11 -11
- package/dist/{viewer-2YMJBQRH.js → viewer-JQCSWJ3C.js} +2 -3
- package/package.json +1 -1
- package/dist/chunk-DEDAOKAV.js +0 -44
- package/dist/chunk-XWR74BQ2.js +0 -170
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
} from "./chunk-XITAQVOZ.js";
|
|
5
5
|
import {
|
|
6
6
|
architectBlock,
|
|
7
|
-
distDir,
|
|
8
7
|
globalSettingsPath,
|
|
9
8
|
hooksRegistered,
|
|
10
9
|
mcpRegisteredProject,
|
|
@@ -15,12 +14,13 @@ import {
|
|
|
15
14
|
registerHooks,
|
|
16
15
|
registerMcpGlobal,
|
|
17
16
|
registerMcpProject,
|
|
17
|
+
serverCommand,
|
|
18
18
|
unregisterHooks
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-ZIQYAQCF.js";
|
|
20
20
|
import {
|
|
21
21
|
hybridSearch,
|
|
22
22
|
protocolChain
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-UWB6RKVN.js";
|
|
24
24
|
import {
|
|
25
25
|
TOKEN_TOGGLES,
|
|
26
26
|
defaultVaultPath,
|
|
@@ -34,18 +34,16 @@ import {
|
|
|
34
34
|
vaultExists,
|
|
35
35
|
writeGlobalConfig,
|
|
36
36
|
writeProjectConfig
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-CIOCSIB5.js";
|
|
38
38
|
import {
|
|
39
39
|
serveGraph
|
|
40
|
-
} from "./chunk-
|
|
41
|
-
import {
|
|
42
|
-
VaultIndex
|
|
43
|
-
} from "./chunk-AXUEYSNZ.js";
|
|
40
|
+
} from "./chunk-FBGIFNIO.js";
|
|
44
41
|
import {
|
|
42
|
+
VaultIndex,
|
|
45
43
|
createNote,
|
|
46
44
|
slugify,
|
|
47
45
|
upsertNote
|
|
48
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-QB37UGO6.js";
|
|
49
47
|
import {
|
|
50
48
|
MODEL_ID,
|
|
51
49
|
dot,
|
|
@@ -55,8 +53,8 @@ import {
|
|
|
55
53
|
} from "./chunk-EDYBSJSS.js";
|
|
56
54
|
|
|
57
55
|
// src/cli.ts
|
|
58
|
-
import
|
|
59
|
-
import
|
|
56
|
+
import fs6 from "fs";
|
|
57
|
+
import path6 from "path";
|
|
60
58
|
import readline from "readline/promises";
|
|
61
59
|
import { Command } from "commander";
|
|
62
60
|
import pc from "picocolors";
|
|
@@ -185,29 +183,182 @@ function installSkill(rec, targetDir) {
|
|
|
185
183
|
}
|
|
186
184
|
}
|
|
187
185
|
|
|
188
|
-
// src/
|
|
186
|
+
// src/skills/evolve.ts
|
|
189
187
|
import fs2 from "fs";
|
|
190
188
|
import os2 from "os";
|
|
191
189
|
import path2 from "path";
|
|
190
|
+
var MAX_BODY_CHARS = 6e3;
|
|
191
|
+
var MAX_LESSONS = 12;
|
|
192
|
+
function skillTargetDir(projectDir, global) {
|
|
193
|
+
return global ? path2.join(os2.homedir(), ".claude", "skills") : path2.join(projectDir, ".claude", "skills");
|
|
194
|
+
}
|
|
195
|
+
function noteBody(vault, rel) {
|
|
196
|
+
try {
|
|
197
|
+
return fs2.readFileSync(path2.join(vault.root, rel), "utf8").replace(/^---[\s\S]*?---\n/, "").trim();
|
|
198
|
+
} catch {
|
|
199
|
+
return "";
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function cleanScanNote(text) {
|
|
203
|
+
return text.replace(/^[^\n]*`ale scan`[^\n]*\n+/g, "").replace(/\n*Proyecto: \[\[[^\]]+\]\]\s*$/g, "").trim();
|
|
204
|
+
}
|
|
205
|
+
function buildSkill(vault, projectName) {
|
|
206
|
+
const idx = VaultIndex.load(vault);
|
|
207
|
+
const slug = slugify(projectName);
|
|
208
|
+
const byTitle = (prefix) => idx.notesByTag("map").find((n) => n.title.toLowerCase() === `${prefix} - ${projectName}`.toLowerCase());
|
|
209
|
+
const flujoNote = byTitle("Flujo");
|
|
210
|
+
const convNote = byTitle("Convenciones");
|
|
211
|
+
const mapaNote = byTitle("Mapa");
|
|
212
|
+
const apiNote = byTitle("API");
|
|
213
|
+
const todasLecciones = idx.notesByTag("lesson").sort((a, b) => (b.hits ?? 1) - (a.hits ?? 1));
|
|
214
|
+
const propias = todasLecciones.filter((n) => n.tags.includes(projectName) || n.rel.includes(slug));
|
|
215
|
+
const lecciones = (propias.length > 0 ? propias : todasLecciones).slice(0, MAX_LESSONS);
|
|
216
|
+
if (!flujoNote && !convNote && !mapaNote && lecciones.length === 0) return null;
|
|
217
|
+
const parts = [];
|
|
218
|
+
parts.push(`# ${projectName}
|
|
219
|
+
`);
|
|
220
|
+
parts.push(
|
|
221
|
+
`Conocimiento vivo de este proyecto, destilado por Alexandria desde su b\xF3veda. Refl\xE9jalo al trabajar aqu\xED: evita re-explorar lo que ya est\xE1 mapeado.
|
|
222
|
+
`
|
|
223
|
+
);
|
|
224
|
+
if (convNote) {
|
|
225
|
+
const t = cleanScanNote(noteBody(vault, convNote.rel));
|
|
226
|
+
if (t) parts.push(`## Stack y convenciones
|
|
227
|
+
|
|
228
|
+
${t}
|
|
229
|
+
`);
|
|
230
|
+
}
|
|
231
|
+
if (flujoNote) {
|
|
232
|
+
const t = cleanScanNote(noteBody(vault, flujoNote.rel));
|
|
233
|
+
if (t) parts.push(`## Flujo de la aplicaci\xF3n
|
|
234
|
+
|
|
235
|
+
C\xF3mo recorre una petici\xF3n el sistema:
|
|
236
|
+
|
|
237
|
+
${t}
|
|
238
|
+
`);
|
|
239
|
+
} else if (apiNote) {
|
|
240
|
+
const t = cleanScanNote(noteBody(vault, apiNote.rel));
|
|
241
|
+
if (t) parts.push(`## Superficie de API
|
|
242
|
+
|
|
243
|
+
${t}
|
|
244
|
+
`);
|
|
245
|
+
}
|
|
246
|
+
if (lecciones.length) {
|
|
247
|
+
const items = lecciones.map((l) => {
|
|
248
|
+
const cuerpo = cleanScanNote(noteBody(vault, l.rel)).split("\n").filter(Boolean).slice(0, 2).join(" ");
|
|
249
|
+
const titulo = l.title.replace(/^Lección\s*-\s*/i, "");
|
|
250
|
+
return `- **${titulo}** \u2014 ${cuerpo.slice(0, 240)}`;
|
|
251
|
+
}).join("\n");
|
|
252
|
+
parts.push(`## Lecciones aprendidas aqu\xED
|
|
253
|
+
|
|
254
|
+
Errores ya pagados: no los repitas.
|
|
255
|
+
|
|
256
|
+
${items}
|
|
257
|
+
`);
|
|
258
|
+
}
|
|
259
|
+
let body = parts.join("\n");
|
|
260
|
+
if (body.length > MAX_BODY_CHARS) body = body.slice(0, MAX_BODY_CHARS) + "\n\n\u2026(truncado)\n";
|
|
261
|
+
const skillName = `proyecto-${slug}`;
|
|
262
|
+
const desc = `Conocimiento vivo del proyecto ${projectName}: stack, convenciones, flujo de la aplicaci\xF3n y lecciones ya aprendidas. \xDAsala al trabajar en ${projectName} \u2014 antes de explorar el c\xF3digo o decidir arquitectura.`;
|
|
263
|
+
const front = [
|
|
264
|
+
"---",
|
|
265
|
+
`name: ${skillName}`,
|
|
266
|
+
`description: ${desc}`,
|
|
267
|
+
"metadata:",
|
|
268
|
+
" author: alexandria",
|
|
269
|
+
` version: "${nextVersion(null)}"`,
|
|
270
|
+
` generated: ${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}`,
|
|
271
|
+
" source: ale skills evolve",
|
|
272
|
+
"---",
|
|
273
|
+
""
|
|
274
|
+
].join("\n");
|
|
275
|
+
const file = path2.join("SKILL.md");
|
|
276
|
+
return {
|
|
277
|
+
skillName,
|
|
278
|
+
file,
|
|
279
|
+
content: front + body.trimEnd() + "\n",
|
|
280
|
+
previous: null,
|
|
281
|
+
changed: true,
|
|
282
|
+
sources: {
|
|
283
|
+
flujo: Boolean(flujoNote),
|
|
284
|
+
convenciones: Boolean(convNote),
|
|
285
|
+
mapa: Boolean(mapaNote),
|
|
286
|
+
lecciones: lecciones.length
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
function nextVersion(previous) {
|
|
291
|
+
if (!previous) return "1.0.0";
|
|
292
|
+
const m = previous.match(/version:\s*["']?(\d+)\.(\d+)\.(\d+)/);
|
|
293
|
+
if (!m) return "1.0.0";
|
|
294
|
+
return `${m[1]}.${Number(m[2]) + 1}.0`;
|
|
295
|
+
}
|
|
296
|
+
function evolveSkill(vault, projectName, targetDir) {
|
|
297
|
+
const built = buildSkill(vault, projectName);
|
|
298
|
+
if (!built) return null;
|
|
299
|
+
const dir = path2.join(targetDir, built.skillName);
|
|
300
|
+
const file = path2.join(dir, "SKILL.md");
|
|
301
|
+
let previous = null;
|
|
302
|
+
try {
|
|
303
|
+
previous = fs2.readFileSync(file, "utf8");
|
|
304
|
+
} catch {
|
|
305
|
+
}
|
|
306
|
+
let content = built.content;
|
|
307
|
+
if (previous) {
|
|
308
|
+
content = content.replace(/(\n {2}version: ")[^"]+(")/, `$1${nextVersion(previous)}$2`);
|
|
309
|
+
}
|
|
310
|
+
const norm = (s) => s.replace(/^ {2}(?:version|generated):.*$/gm, "").trim();
|
|
311
|
+
return {
|
|
312
|
+
...built,
|
|
313
|
+
file,
|
|
314
|
+
content,
|
|
315
|
+
previous,
|
|
316
|
+
changed: !previous || norm(previous) !== norm(content)
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
function writeSkill(result) {
|
|
320
|
+
fs2.mkdirSync(path2.dirname(result.file), { recursive: true });
|
|
321
|
+
fs2.writeFileSync(result.file, result.content);
|
|
322
|
+
}
|
|
323
|
+
function simpleDiff(previous, next) {
|
|
324
|
+
if (!previous) return next.split("\n").map((l) => `+ ${l}`);
|
|
325
|
+
const a = previous.split("\n");
|
|
326
|
+
const b = next.split("\n");
|
|
327
|
+
const setA = new Set(a);
|
|
328
|
+
const setB = new Set(b);
|
|
329
|
+
const out = [];
|
|
330
|
+
for (const l of a) if (!setB.has(l)) out.push(`- ${l}`);
|
|
331
|
+
for (const l of b) if (!setA.has(l)) out.push(`+ ${l}`);
|
|
332
|
+
return out;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// src/core/agents.ts
|
|
336
|
+
import fs3 from "fs";
|
|
337
|
+
import os3 from "os";
|
|
338
|
+
import path3 from "path";
|
|
192
339
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
193
|
-
var
|
|
340
|
+
var portableMode = false;
|
|
341
|
+
function setPortableMode(on) {
|
|
342
|
+
portableMode = on;
|
|
343
|
+
}
|
|
344
|
+
var serverCmd = () => serverCommand(portableMode);
|
|
194
345
|
function readJsonSafe(file) {
|
|
195
346
|
try {
|
|
196
|
-
return JSON.parse(
|
|
347
|
+
return JSON.parse(fs3.readFileSync(file, "utf8"));
|
|
197
348
|
} catch {
|
|
198
|
-
if (
|
|
349
|
+
if (fs3.existsSync(file)) throw new Error(`no pude parsear ${file} \u2014 rev\xEDsalo manualmente`);
|
|
199
350
|
return {};
|
|
200
351
|
}
|
|
201
352
|
}
|
|
202
353
|
function writeJson(file, data) {
|
|
203
|
-
|
|
204
|
-
|
|
354
|
+
fs3.mkdirSync(path3.dirname(file), { recursive: true });
|
|
355
|
+
fs3.writeFileSync(file, JSON.stringify(data, null, 2) + "\n");
|
|
205
356
|
}
|
|
206
357
|
function mergeMcpServers(file, key = "mcpServers") {
|
|
207
358
|
try {
|
|
208
359
|
const cfg = readJsonSafe(file);
|
|
209
360
|
const servers = cfg[key] ?? {};
|
|
210
|
-
servers["alexandria"] =
|
|
361
|
+
servers["alexandria"] = serverCmd();
|
|
211
362
|
cfg[key] = servers;
|
|
212
363
|
writeJson(file, cfg);
|
|
213
364
|
return { ok: true, file };
|
|
@@ -216,21 +367,59 @@ function mergeMcpServers(file, key = "mcpServers") {
|
|
|
216
367
|
}
|
|
217
368
|
}
|
|
218
369
|
function home(...p) {
|
|
219
|
-
return
|
|
370
|
+
return path3.join(os3.homedir(), ...p);
|
|
371
|
+
}
|
|
372
|
+
function replaceTomlTable(text, table, block) {
|
|
373
|
+
const lines = text.split("\n");
|
|
374
|
+
const isHeader = (l) => /^\s*\[/.test(l);
|
|
375
|
+
const belongsToTable = (l) => {
|
|
376
|
+
const m = l.match(/^\s*\[+\s*([^\]]+?)\s*\]+/);
|
|
377
|
+
if (!m) return false;
|
|
378
|
+
const name = m[1].trim();
|
|
379
|
+
return name === table || name.startsWith(`${table}.`);
|
|
380
|
+
};
|
|
381
|
+
const out = [];
|
|
382
|
+
let i = 0;
|
|
383
|
+
let replaced = false;
|
|
384
|
+
while (i < lines.length) {
|
|
385
|
+
if (belongsToTable(lines[i])) {
|
|
386
|
+
if (!replaced) {
|
|
387
|
+
out.push(...block.replace(/\n+$/, "").split("\n"));
|
|
388
|
+
replaced = true;
|
|
389
|
+
}
|
|
390
|
+
i++;
|
|
391
|
+
while (i < lines.length && !isHeader(lines[i])) i++;
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
out.push(lines[i]);
|
|
395
|
+
i++;
|
|
396
|
+
}
|
|
397
|
+
let result = out.join("\n");
|
|
398
|
+
if (!replaced) {
|
|
399
|
+
result = result.trimEnd() + (result.trim() ? "\n\n" : "") + block;
|
|
400
|
+
}
|
|
401
|
+
return result.replace(/\n{3,}/g, "\n\n");
|
|
220
402
|
}
|
|
221
403
|
function vscodeUserDir() {
|
|
222
404
|
if (process.platform === "darwin") return home("Library", "Application Support", "Code", "User");
|
|
223
|
-
if (process.platform === "win32") return
|
|
405
|
+
if (process.platform === "win32") return path3.join(process.env.APPDATA ?? home("AppData", "Roaming"), "Code", "User");
|
|
224
406
|
return home(".config", "Code", "User");
|
|
225
407
|
}
|
|
408
|
+
function hasCopilotChatExtension() {
|
|
409
|
+
try {
|
|
410
|
+
return fs3.readdirSync(home(".vscode", "extensions")).some((d) => d.toLowerCase().startsWith("github.copilot-chat"));
|
|
411
|
+
} catch {
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
226
415
|
var AGENTS = [
|
|
227
416
|
{
|
|
228
417
|
id: "claude",
|
|
229
418
|
name: "Claude Code",
|
|
230
419
|
supportsProject: true,
|
|
231
|
-
detect: () =>
|
|
420
|
+
detect: () => fs3.existsSync(home(".claude")),
|
|
232
421
|
register(scope, projectDir) {
|
|
233
|
-
if (scope === "project") return mergeMcpServers(
|
|
422
|
+
if (scope === "project") return mergeMcpServers(path3.join(projectDir, ".mcp.json"));
|
|
234
423
|
return mergeMcpServers(home(".claude.json"));
|
|
235
424
|
}
|
|
236
425
|
},
|
|
@@ -238,9 +427,9 @@ var AGENTS = [
|
|
|
238
427
|
id: "cursor",
|
|
239
428
|
name: "Cursor",
|
|
240
429
|
supportsProject: true,
|
|
241
|
-
detect: () =>
|
|
430
|
+
detect: () => fs3.existsSync(home(".cursor")),
|
|
242
431
|
register(scope, projectDir) {
|
|
243
|
-
const file = scope === "project" ?
|
|
432
|
+
const file = scope === "project" ? path3.join(projectDir, ".cursor", "mcp.json") : home(".cursor", "mcp.json");
|
|
244
433
|
return mergeMcpServers(file);
|
|
245
434
|
}
|
|
246
435
|
},
|
|
@@ -248,14 +437,14 @@ var AGENTS = [
|
|
|
248
437
|
id: "opencode",
|
|
249
438
|
name: "OpenCode",
|
|
250
439
|
supportsProject: true,
|
|
251
|
-
detect: () =>
|
|
440
|
+
detect: () => fs3.existsSync(home(".config", "opencode")) || fs3.existsSync(home(".opencode")),
|
|
252
441
|
register(scope, projectDir) {
|
|
253
|
-
const file = scope === "project" ?
|
|
442
|
+
const file = scope === "project" ? path3.join(projectDir, "opencode.json") : home(".config", "opencode", "opencode.json");
|
|
254
443
|
try {
|
|
255
444
|
const cfg = readJsonSafe(file);
|
|
256
445
|
cfg["$schema"] ??= "https://opencode.ai/config.json";
|
|
257
446
|
const mcp = cfg["mcp"] ?? {};
|
|
258
|
-
mcp["alexandria"] = { type: "local", command: [
|
|
447
|
+
mcp["alexandria"] = { type: "local", command: [serverCmd().command, ...serverCmd().args], enabled: true };
|
|
259
448
|
cfg["mcp"] = mcp;
|
|
260
449
|
writeJson(file, cfg);
|
|
261
450
|
return { ok: true, file };
|
|
@@ -266,20 +455,41 @@ var AGENTS = [
|
|
|
266
455
|
},
|
|
267
456
|
{
|
|
268
457
|
id: "windsurf",
|
|
269
|
-
name: "Windsurf",
|
|
458
|
+
name: "Windsurf (legacy \u2192 Devin)",
|
|
270
459
|
supportsProject: false,
|
|
271
|
-
detect: () =>
|
|
460
|
+
detect: () => fs3.existsSync(home(".codeium", "windsurf")),
|
|
272
461
|
register() {
|
|
273
462
|
return mergeMcpServers(home(".codeium", "windsurf", "mcp_config.json"));
|
|
274
463
|
}
|
|
275
464
|
},
|
|
465
|
+
{
|
|
466
|
+
id: "devin",
|
|
467
|
+
name: "Devin CLI (Cognition)",
|
|
468
|
+
supportsProject: true,
|
|
469
|
+
// El CLI vive en ~/.local/bin/devin y guarda config MCP por proyecto en .devin/
|
|
470
|
+
detect: () => fs3.existsSync(home(".devin")) || fs3.existsSync(home(".local", "bin", "devin")),
|
|
471
|
+
register(scope, projectDir) {
|
|
472
|
+
const dir = scope === "project" ? projectDir : home();
|
|
473
|
+
const file = path3.join(dir, ".devin", "mcp_config.local.json");
|
|
474
|
+
try {
|
|
475
|
+
const cfg = readJsonSafe(file);
|
|
476
|
+
const servers = cfg["mcpServers"] ?? {};
|
|
477
|
+
servers["alexandria"] = { ...serverCmd(), transport: "stdio" };
|
|
478
|
+
cfg["mcpServers"] = servers;
|
|
479
|
+
writeJson(file, cfg);
|
|
480
|
+
return { ok: true, file };
|
|
481
|
+
} catch (e) {
|
|
482
|
+
return { ok: false, file, detail: e.message };
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
},
|
|
276
486
|
{
|
|
277
487
|
id: "cline",
|
|
278
488
|
name: "Cline (VS Code)",
|
|
279
489
|
supportsProject: false,
|
|
280
|
-
detect: () =>
|
|
490
|
+
detect: () => fs3.existsSync(path3.join(vscodeUserDir(), "globalStorage", "saoudrizwan.claude-dev")),
|
|
281
491
|
register() {
|
|
282
|
-
const file =
|
|
492
|
+
const file = path3.join(
|
|
283
493
|
vscodeUserDir(),
|
|
284
494
|
"globalStorage",
|
|
285
495
|
"saoudrizwan.claude-dev",
|
|
@@ -293,26 +503,24 @@ var AGENTS = [
|
|
|
293
503
|
id: "codex",
|
|
294
504
|
name: "Codex CLI (OpenAI)",
|
|
295
505
|
supportsProject: false,
|
|
296
|
-
detect: () =>
|
|
506
|
+
detect: () => fs3.existsSync(home(".codex")),
|
|
297
507
|
register() {
|
|
298
508
|
const file = home(".codex", "config.toml");
|
|
509
|
+
const { command, args } = serverCmd();
|
|
510
|
+
const tomlArgs = args.map((a) => `"${a.replace(/\\/g, "\\\\")}"`).join(", ");
|
|
299
511
|
const block = `[mcp_servers.alexandria]
|
|
300
|
-
command = "
|
|
301
|
-
args = [
|
|
512
|
+
command = "${command}"
|
|
513
|
+
args = [${tomlArgs}]
|
|
302
514
|
`;
|
|
303
515
|
try {
|
|
304
516
|
let text = "";
|
|
305
517
|
try {
|
|
306
|
-
text =
|
|
518
|
+
text = fs3.readFileSync(file, "utf8");
|
|
307
519
|
} catch {
|
|
308
520
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
text = text.trimEnd() + (text.trim() ? "\n\n" : "") + block;
|
|
313
|
-
}
|
|
314
|
-
fs2.mkdirSync(path2.dirname(file), { recursive: true });
|
|
315
|
-
fs2.writeFileSync(file, text);
|
|
521
|
+
text = replaceTomlTable(text, "mcp_servers.alexandria", block);
|
|
522
|
+
fs3.mkdirSync(path3.dirname(file), { recursive: true });
|
|
523
|
+
fs3.writeFileSync(file, text);
|
|
316
524
|
return { ok: true, file };
|
|
317
525
|
} catch (e) {
|
|
318
526
|
return { ok: false, file, detail: e.message };
|
|
@@ -323,9 +531,9 @@ args = ["${serverScript().replace(/\\/g, "\\\\")}"]
|
|
|
323
531
|
id: "gemini",
|
|
324
532
|
name: "Gemini CLI",
|
|
325
533
|
supportsProject: true,
|
|
326
|
-
detect: () =>
|
|
534
|
+
detect: () => fs3.existsSync(home(".gemini")),
|
|
327
535
|
register(scope, projectDir) {
|
|
328
|
-
const file = scope === "project" ?
|
|
536
|
+
const file = scope === "project" ? path3.join(projectDir, ".gemini", "settings.json") : home(".gemini", "settings.json");
|
|
329
537
|
return mergeMcpServers(file);
|
|
330
538
|
}
|
|
331
539
|
},
|
|
@@ -333,13 +541,13 @@ args = ["${serverScript().replace(/\\/g, "\\\\")}"]
|
|
|
333
541
|
id: "openclaw",
|
|
334
542
|
name: "OpenClaw",
|
|
335
543
|
supportsProject: false,
|
|
336
|
-
detect: () =>
|
|
544
|
+
detect: () => fs3.existsSync(home(".openclaw")),
|
|
337
545
|
register() {
|
|
338
546
|
const file = home(".openclaw", "openclaw.json");
|
|
339
547
|
try {
|
|
340
548
|
const cfg = readJsonSafe(file);
|
|
341
549
|
const servers = cfg["mcpServers"] ?? {};
|
|
342
|
-
servers["alexandria"] = {
|
|
550
|
+
servers["alexandria"] = { ...serverCmd(), transport: "stdio" };
|
|
343
551
|
cfg["mcpServers"] = servers;
|
|
344
552
|
writeJson(file, cfg);
|
|
345
553
|
return { ok: true, file, detail: "reinicia el gateway de OpenClaw para que lo tome" };
|
|
@@ -352,11 +560,11 @@ args = ["${serverScript().replace(/\\/g, "\\\\")}"]
|
|
|
352
560
|
id: "hermes",
|
|
353
561
|
name: "Hermes Agent (Nous)",
|
|
354
562
|
supportsProject: false,
|
|
355
|
-
detect: () =>
|
|
563
|
+
detect: () => fs3.existsSync(home(".hermes")),
|
|
356
564
|
register() {
|
|
357
565
|
const file = home(".hermes", "config.yaml");
|
|
358
566
|
try {
|
|
359
|
-
execFileSync2("hermes", ["mcp", "add", "alexandria", "--command",
|
|
567
|
+
execFileSync2("hermes", ["mcp", "add", "alexandria", "--command", serverCmd().command, "--args", serverCmd().args.join(" ")], {
|
|
360
568
|
stdio: "pipe",
|
|
361
569
|
timeout: 15e3
|
|
362
570
|
});
|
|
@@ -366,15 +574,16 @@ args = ["${serverScript().replace(/\\/g, "\\\\")}"]
|
|
|
366
574
|
try {
|
|
367
575
|
let text = "";
|
|
368
576
|
try {
|
|
369
|
-
text =
|
|
577
|
+
text = fs3.readFileSync(file, "utf8");
|
|
370
578
|
} catch {
|
|
371
579
|
}
|
|
372
580
|
if (/^\s*alexandria:/m.test(text)) return { ok: true, file, detail: "ya registrado" };
|
|
581
|
+
const hc = serverCmd();
|
|
373
582
|
const entry = ` alexandria:
|
|
374
583
|
type: stdio
|
|
375
|
-
command:
|
|
584
|
+
command: ${hc.command}
|
|
376
585
|
args:
|
|
377
|
-
- "${
|
|
586
|
+
${hc.args.map((a) => ` - "${a}"`).join("\n")}
|
|
378
587
|
`;
|
|
379
588
|
if (/^mcp_servers:\s*$/m.test(text)) {
|
|
380
589
|
text = text.replace(/^mcp_servers:\s*$/m, (m) => `${m}
|
|
@@ -384,8 +593,8 @@ ${entry.trimEnd()}`);
|
|
|
384
593
|
} else {
|
|
385
594
|
text = text.trimEnd() + (text.trim() ? "\n\n" : "") + "mcp_servers:\n" + entry;
|
|
386
595
|
}
|
|
387
|
-
|
|
388
|
-
|
|
596
|
+
fs3.mkdirSync(path3.dirname(file), { recursive: true });
|
|
597
|
+
fs3.writeFileSync(file, text);
|
|
389
598
|
return { ok: true, file };
|
|
390
599
|
} catch (e) {
|
|
391
600
|
return { ok: false, file, detail: e.message };
|
|
@@ -396,13 +605,16 @@ ${entry.trimEnd()}`);
|
|
|
396
605
|
id: "vscode",
|
|
397
606
|
name: "VS Code (Copilot)",
|
|
398
607
|
supportsProject: true,
|
|
399
|
-
|
|
608
|
+
// Señal REAL de soporte MCP: un mcp.json existente o la extensión de Copilot
|
|
609
|
+
// Chat instalada. Antes bastaba con que existiera el User dir, así que
|
|
610
|
+
// cualquiera con VS Code aparecía como agente detectado aunque no use MCP.
|
|
611
|
+
detect: () => fs3.existsSync(path3.join(vscodeUserDir(), "mcp.json")) || hasCopilotChatExtension(),
|
|
400
612
|
register(scope, projectDir) {
|
|
401
|
-
const file = scope === "project" ?
|
|
613
|
+
const file = scope === "project" ? path3.join(projectDir, ".vscode", "mcp.json") : path3.join(vscodeUserDir(), "mcp.json");
|
|
402
614
|
try {
|
|
403
615
|
const cfg = readJsonSafe(file);
|
|
404
616
|
const servers = cfg["servers"] ?? {};
|
|
405
|
-
servers["alexandria"] = { type: "stdio",
|
|
617
|
+
servers["alexandria"] = { type: "stdio", ...serverCmd() };
|
|
406
618
|
cfg["servers"] = servers;
|
|
407
619
|
writeJson(file, cfg);
|
|
408
620
|
return { ok: true, file };
|
|
@@ -483,9 +695,9 @@ async function showBanner(animate) {
|
|
|
483
695
|
}
|
|
484
696
|
|
|
485
697
|
// src/core/setup.ts
|
|
486
|
-
import
|
|
487
|
-
import
|
|
488
|
-
import
|
|
698
|
+
import fs4 from "fs";
|
|
699
|
+
import os4 from "os";
|
|
700
|
+
import path4 from "path";
|
|
489
701
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
490
702
|
var PERSONAL_CONFIG_FILES = [
|
|
491
703
|
".vault.json",
|
|
@@ -493,18 +705,19 @@ var PERSONAL_CONFIG_FILES = [
|
|
|
493
705
|
".cursor/mcp.json",
|
|
494
706
|
"opencode.json",
|
|
495
707
|
".vscode/mcp.json",
|
|
496
|
-
".gemini/settings.json"
|
|
708
|
+
".gemini/settings.json",
|
|
709
|
+
".devin/mcp_config.local.json"
|
|
497
710
|
];
|
|
498
711
|
function ensureGitignore(projectDir, vaultRoot) {
|
|
499
|
-
if (!
|
|
712
|
+
if (!fs4.existsSync(path4.join(projectDir, ".git"))) return null;
|
|
500
713
|
const entries = [];
|
|
501
|
-
const rel =
|
|
502
|
-
if (!rel.startsWith("..")) entries.push(`${rel.split(
|
|
714
|
+
const rel = path4.relative(projectDir, vaultRoot);
|
|
715
|
+
if (!rel.startsWith("..")) entries.push(`${rel.split(path4.sep).join("/")}/`);
|
|
503
716
|
entries.push(...PERSONAL_CONFIG_FILES);
|
|
504
|
-
const file =
|
|
717
|
+
const file = path4.join(projectDir, ".gitignore");
|
|
505
718
|
let text = "";
|
|
506
719
|
try {
|
|
507
|
-
text =
|
|
720
|
+
text = fs4.readFileSync(file, "utf8");
|
|
508
721
|
} catch {
|
|
509
722
|
}
|
|
510
723
|
const has = (e) => text.split("\n").some((l) => l.trim() === e || l.trim() === e.replace(/\/$/, ""));
|
|
@@ -515,14 +728,14 @@ function ensureGitignore(projectDir, vaultRoot) {
|
|
|
515
728
|
# Alexandria (conocimiento y config personal \u2014 no del repo)
|
|
516
729
|
${missing.join("\n")}
|
|
517
730
|
`;
|
|
518
|
-
|
|
731
|
+
fs4.writeFileSync(file, text.trim() ? block : block.trimStart());
|
|
519
732
|
return file;
|
|
520
733
|
}
|
|
521
734
|
function untrackPersonalConfigs(projectDir) {
|
|
522
|
-
if (!
|
|
735
|
+
if (!fs4.existsSync(path4.join(projectDir, ".git"))) return [];
|
|
523
736
|
const untracked = [];
|
|
524
737
|
for (const f of PERSONAL_CONFIG_FILES) {
|
|
525
|
-
if (!
|
|
738
|
+
if (!fs4.existsSync(path4.join(projectDir, f))) continue;
|
|
526
739
|
try {
|
|
527
740
|
const tracked = execFileSync3("git", ["ls-files", "--error-unmatch", f], {
|
|
528
741
|
cwd: projectDir,
|
|
@@ -540,7 +753,7 @@ function untrackPersonalConfigs(projectDir) {
|
|
|
540
753
|
var CLAUDE_MD_START = "<!-- alexandria:start -->";
|
|
541
754
|
var CLAUDE_MD_END = "<!-- alexandria:end -->";
|
|
542
755
|
function configureClaudeMd(scope, projectDir) {
|
|
543
|
-
const file = scope === "project" ?
|
|
756
|
+
const file = scope === "project" ? path4.join(projectDir, "CLAUDE.md") : path4.join(os4.homedir(), ".claude", "CLAUDE.md");
|
|
544
757
|
const block = [
|
|
545
758
|
CLAUDE_MD_START,
|
|
546
759
|
"## Alexandria \u2014 b\xF3veda de conocimiento y Protocolo (uso por default)",
|
|
@@ -552,10 +765,10 @@ function configureClaudeMd(scope, projectDir) {
|
|
|
552
765
|
"- `vault_related` trae conocimiento conectado sin releer archivos.",
|
|
553
766
|
CLAUDE_MD_END
|
|
554
767
|
].join("\n");
|
|
555
|
-
|
|
768
|
+
fs4.mkdirSync(path4.dirname(file), { recursive: true });
|
|
556
769
|
let text = "";
|
|
557
770
|
try {
|
|
558
|
-
text =
|
|
771
|
+
text = fs4.readFileSync(file, "utf8");
|
|
559
772
|
} catch {
|
|
560
773
|
}
|
|
561
774
|
if (text.includes(CLAUDE_MD_START)) {
|
|
@@ -564,14 +777,14 @@ function configureClaudeMd(scope, projectDir) {
|
|
|
564
777
|
} else {
|
|
565
778
|
text = (text.trimEnd() + "\n\n" + block + "\n").trimStart();
|
|
566
779
|
}
|
|
567
|
-
|
|
780
|
+
fs4.writeFileSync(file, text);
|
|
568
781
|
return file;
|
|
569
782
|
}
|
|
570
783
|
function removeClaudeMd(scope, projectDir) {
|
|
571
|
-
const file = scope === "project" ?
|
|
784
|
+
const file = scope === "project" ? path4.join(projectDir, "CLAUDE.md") : path4.join(os4.homedir(), ".claude", "CLAUDE.md");
|
|
572
785
|
let text;
|
|
573
786
|
try {
|
|
574
|
-
text =
|
|
787
|
+
text = fs4.readFileSync(file, "utf8");
|
|
575
788
|
} catch {
|
|
576
789
|
return null;
|
|
577
790
|
}
|
|
@@ -579,20 +792,20 @@ function removeClaudeMd(scope, projectDir) {
|
|
|
579
792
|
const re = new RegExp(`\\n*${CLAUDE_MD_START}[\\s\\S]*?${CLAUDE_MD_END}\\n*`);
|
|
580
793
|
const cleaned = text.replace(re, "\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
581
794
|
if (cleaned === "") {
|
|
582
|
-
|
|
795
|
+
fs4.rmSync(file, { force: true });
|
|
583
796
|
} else {
|
|
584
|
-
|
|
797
|
+
fs4.writeFileSync(file, cleaned + "\n");
|
|
585
798
|
}
|
|
586
799
|
return file;
|
|
587
800
|
}
|
|
588
801
|
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", ".next", "dist", "build", ".vault", ".claude", "coverage", "Alexandria", "KnowledgeVault"]);
|
|
589
802
|
function scanProject(vault, projectDir) {
|
|
590
|
-
const name =
|
|
591
|
-
const mapFile =
|
|
592
|
-
if (
|
|
803
|
+
const name = path4.basename(projectDir);
|
|
804
|
+
const mapFile = path4.join(vault.managed, "notes", `mapa-${slugify(name)}.md`);
|
|
805
|
+
if (fs4.existsSync(mapFile)) return null;
|
|
593
806
|
const parts = [`Mapa inicial generado por \`ale init\` (escaneo autom\xE1tico). Actual\xEDzalo con vault_save.`];
|
|
594
807
|
try {
|
|
595
|
-
const pkg = JSON.parse(
|
|
808
|
+
const pkg = JSON.parse(fs4.readFileSync(path4.join(projectDir, "package.json"), "utf8"));
|
|
596
809
|
const deps = Object.keys({ ...pkg.dependencies }).slice(0, 18);
|
|
597
810
|
const dev = Object.keys({ ...pkg.devDependencies }).slice(0, 10);
|
|
598
811
|
parts.push(`## Stack
|
|
@@ -611,13 +824,13 @@ ${scripts.map(([k, v]) => `- \`npm run ${k}\` \u2014 ${v}`).join("\n")}`);
|
|
|
611
824
|
if (depth > 2 || tree.length > 60) return;
|
|
612
825
|
let entries = [];
|
|
613
826
|
try {
|
|
614
|
-
entries =
|
|
827
|
+
entries = fs4.readdirSync(dir, { withFileTypes: true }).filter((e) => !e.name.startsWith(".") && !SKIP_DIRS.has(e.name));
|
|
615
828
|
} catch {
|
|
616
829
|
return;
|
|
617
830
|
}
|
|
618
831
|
for (const e of entries.filter((x) => x.isDirectory()).slice(0, 14)) {
|
|
619
832
|
tree.push(`${prefix}${e.name}/`);
|
|
620
|
-
walk(
|
|
833
|
+
walk(path4.join(dir, e.name), depth + 1, prefix + " ");
|
|
621
834
|
}
|
|
622
835
|
};
|
|
623
836
|
walk(projectDir, 1, "");
|
|
@@ -626,7 +839,7 @@ ${scripts.map(([k, v]) => `- \`npm run ${k}\` \u2014 ${v}`).join("\n")}`);
|
|
|
626
839
|
${tree.join("\n")}
|
|
627
840
|
\`\`\``);
|
|
628
841
|
try {
|
|
629
|
-
const readme =
|
|
842
|
+
const readme = fs4.readFileSync(path4.join(projectDir, "README.md"), "utf8");
|
|
630
843
|
parts.push(`## README (extracto)
|
|
631
844
|
${readme.split("\n").slice(0, 15).join("\n")}`);
|
|
632
845
|
} catch {
|
|
@@ -642,8 +855,8 @@ ${readme.split("\n").slice(0, 15).join("\n")}`);
|
|
|
642
855
|
}
|
|
643
856
|
|
|
644
857
|
// src/core/scan.ts
|
|
645
|
-
import
|
|
646
|
-
import
|
|
858
|
+
import fs5 from "fs";
|
|
859
|
+
import path5 from "path";
|
|
647
860
|
var SKIP_DIRS2 = /* @__PURE__ */ new Set([
|
|
648
861
|
"node_modules",
|
|
649
862
|
".git",
|
|
@@ -688,15 +901,15 @@ function collectSourceFiles(projectDir) {
|
|
|
688
901
|
for (const dir of level) {
|
|
689
902
|
let entries = [];
|
|
690
903
|
try {
|
|
691
|
-
entries =
|
|
904
|
+
entries = fs5.readdirSync(dir, { withFileTypes: true });
|
|
692
905
|
} catch {
|
|
693
906
|
continue;
|
|
694
907
|
}
|
|
695
908
|
for (const e of entries) {
|
|
696
909
|
if (e.name.startsWith(".") || SKIP_DIRS2.has(e.name)) continue;
|
|
697
|
-
const full =
|
|
910
|
+
const full = path5.join(dir, e.name);
|
|
698
911
|
if (e.isDirectory()) next.push(full);
|
|
699
|
-
else if (e.isFile() && SOURCE_EXT.has(
|
|
912
|
+
else if (e.isFile() && SOURCE_EXT.has(path5.extname(e.name))) {
|
|
700
913
|
candidates.push(full);
|
|
701
914
|
if (candidates.length >= TRAVERSE_SAFETY) break;
|
|
702
915
|
}
|
|
@@ -709,7 +922,7 @@ function collectSourceFiles(projectDir) {
|
|
|
709
922
|
if (candidates.length > MAX_FILES) {
|
|
710
923
|
const groups = /* @__PURE__ */ new Map();
|
|
711
924
|
for (const c of candidates) {
|
|
712
|
-
const key =
|
|
925
|
+
const key = path5.relative(projectDir, c).split(path5.sep)[0];
|
|
713
926
|
const g = groups.get(key);
|
|
714
927
|
if (g) g.push(c);
|
|
715
928
|
else groups.set(key, [c]);
|
|
@@ -731,10 +944,10 @@ function collectSourceFiles(projectDir) {
|
|
|
731
944
|
const out = [];
|
|
732
945
|
for (const full of chosen) {
|
|
733
946
|
try {
|
|
734
|
-
if (
|
|
947
|
+
if (fs5.statSync(full).size > MAX_FILE_BYTES) continue;
|
|
735
948
|
out.push({
|
|
736
|
-
rel:
|
|
737
|
-
content:
|
|
949
|
+
rel: path5.relative(projectDir, full).split(path5.sep).join("/"),
|
|
950
|
+
content: fs5.readFileSync(full, "utf8")
|
|
738
951
|
});
|
|
739
952
|
} catch {
|
|
740
953
|
}
|
|
@@ -778,12 +991,61 @@ function scanApi(files) {
|
|
|
778
991
|
}
|
|
779
992
|
return lines;
|
|
780
993
|
}
|
|
994
|
+
function scanFlow(files) {
|
|
995
|
+
const lines = [];
|
|
996
|
+
for (const f of files) {
|
|
997
|
+
if (!/(^|\/)(middleware|proxy)\.[tj]sx?$/.test(f.rel)) continue;
|
|
998
|
+
const matcher = f.content.match(/matcher:\s*\[([^\]]+)\]/)?.[1] ?? f.content.match(/matcher:\s*['"`]([^'"`]+)/)?.[1];
|
|
999
|
+
const rutas = matcher ? matcher.replace(/['"`\s]/g, " ").trim().split(/\s+/).slice(0, 6).join(", ") : "todas las rutas";
|
|
1000
|
+
const auth = /auth|session|token|jwt|cookie/i.test(f.content) ? " (verifica sesi\xF3n)" : "";
|
|
1001
|
+
lines.push(`- middleware protege: ${rutas}${auth} \u2014 ${f.rel}`);
|
|
1002
|
+
}
|
|
1003
|
+
for (const f of files) {
|
|
1004
|
+
if (lines.length >= RAW_SAFETY) break;
|
|
1005
|
+
const body = f.content.replace(/^\s*import[\s\S]*?from\s+['"][^'"]+['"];?\s*$/gm, "");
|
|
1006
|
+
const isRoute = /(^|\/)route\.[tj]sx?$/.test(f.rel) && /(^|\/)app\//.test(f.rel);
|
|
1007
|
+
const isPagesApi = /(?:^|\/)pages\/api\//.test(f.rel);
|
|
1008
|
+
const isAction = /^\s*['"]use server['"]/m.test(f.content.slice(0, 400));
|
|
1009
|
+
if (!isRoute && !isPagesApi && !isAction) continue;
|
|
1010
|
+
const parts = [];
|
|
1011
|
+
if (isRoute) {
|
|
1012
|
+
const methods = HTTP_METHODS.filter(
|
|
1013
|
+
(m) => new RegExp(`export\\s+(?:async\\s+)?(?:function\\s+${m}\\b|const\\s+${m}\\s*=)`).test(f.content)
|
|
1014
|
+
);
|
|
1015
|
+
parts.push(`${methods.join("/") || "handler"} ${appRoutePath(f.rel)}`);
|
|
1016
|
+
} else if (isPagesApi) {
|
|
1017
|
+
parts.push(`handler /api/${f.rel.replace(/.*pages\/api\//, "").replace(/\.[tj]sx?$/, "")}`);
|
|
1018
|
+
} else {
|
|
1019
|
+
const fns = [...f.content.matchAll(/export\s+(?:async\s+)?function\s+(\w+)/g)].map((m) => m[1]);
|
|
1020
|
+
parts.push(`action ${fns.slice(0, 3).join("/") || "(an\xF3nima)"}`);
|
|
1021
|
+
}
|
|
1022
|
+
const authCall = body.match(
|
|
1023
|
+
/\b(require(?:Auth|User|Permiso|Permission|Role|Session)\w*|getServerSession|getSession|currentUser|verifyToken|getToken|auth)\s*\(\s*(["'`]([^"'`]+)["'`])?/
|
|
1024
|
+
);
|
|
1025
|
+
if (authCall) {
|
|
1026
|
+
parts.push(authCall[3] ? `auth: ${authCall[1]}(${authCall[3]})` : `auth: ${authCall[1]}`);
|
|
1027
|
+
}
|
|
1028
|
+
const datos = /* @__PURE__ */ new Set();
|
|
1029
|
+
for (const m of body.matchAll(/\bprisma\.(\w+)\.(\w+)/g)) datos.add(`${m[1]}.${m[2]}`);
|
|
1030
|
+
if (/\bdb\s*\.\s*(?:select|insert|update|delete)\s*\(/.test(body)) datos.add("drizzle");
|
|
1031
|
+
for (const m of body.matchAll(/\b(?:FROM|INTO|UPDATE|JOIN)\s+["'`]?(\w{3,})["'`]?/g)) datos.add(m[1].toLowerCase());
|
|
1032
|
+
for (const imp of f.content.matchAll(/import\s*\{([^}]+)\}\s*from\s*['"][^'"]*(?:queries|db|repository|dal|models?)['"]/g)) {
|
|
1033
|
+
for (const fn of imp[1].split(",").map((x) => x.trim().split(/\s+as\s+/)[0]).filter(Boolean)) datos.add(fn);
|
|
1034
|
+
}
|
|
1035
|
+
if (datos.size) parts.push(`datos: ${[...datos].slice(0, 4).join(", ")}${datos.size > 4 ? "\u2026" : ""}`);
|
|
1036
|
+
if (/\b(?:auditar|audit|logEvent)\s*\(/.test(body)) parts.push("audita");
|
|
1037
|
+
if (/\b(?:fetch|axios)\s*\(/.test(body)) parts.push("llama API externa");
|
|
1038
|
+
if (/\b(?:revalidatePath|revalidateTag|updateTag)\s*\(/.test(body)) parts.push("revalida cach\xE9");
|
|
1039
|
+
lines.push(`- ${parts.join(" \u2192 ")} \u2014 ${f.rel}`);
|
|
1040
|
+
}
|
|
1041
|
+
return lines;
|
|
1042
|
+
}
|
|
781
1043
|
function scanEnvNames(projectDir) {
|
|
782
1044
|
const seen = /* @__PURE__ */ new Map();
|
|
783
1045
|
for (const file of [".env.example", ".env", ".env.local"]) {
|
|
784
1046
|
let text;
|
|
785
1047
|
try {
|
|
786
|
-
text =
|
|
1048
|
+
text = fs5.readFileSync(path5.join(projectDir, file), "utf8");
|
|
787
1049
|
} catch {
|
|
788
1050
|
continue;
|
|
789
1051
|
}
|
|
@@ -797,7 +1059,7 @@ function scanEnvNames(projectDir) {
|
|
|
797
1059
|
function scanDataSchema(projectDir, files) {
|
|
798
1060
|
const lines = [];
|
|
799
1061
|
try {
|
|
800
|
-
const schema =
|
|
1062
|
+
const schema = fs5.readFileSync(path5.join(projectDir, "prisma", "schema.prisma"), "utf8");
|
|
801
1063
|
for (const m of schema.matchAll(/model\s+(\w+)\s*\{([^}]*)\}/g)) {
|
|
802
1064
|
const fields = m[2].split("\n").map((l) => l.trim()).filter((l) => l && !l.startsWith("@@") && !l.startsWith("//")).map((l) => l.split(/\s+/)[0]);
|
|
803
1065
|
const shown = fields.slice(0, 8).join(", ");
|
|
@@ -814,14 +1076,14 @@ function scanDataSchema(projectDir, files) {
|
|
|
814
1076
|
for (const dir of migDirs) {
|
|
815
1077
|
let sqlFiles = [];
|
|
816
1078
|
try {
|
|
817
|
-
sqlFiles =
|
|
1079
|
+
sqlFiles = fs5.readdirSync(path5.join(projectDir, dir)).filter((f) => f.endsWith(".sql")).slice(0, 30);
|
|
818
1080
|
} catch {
|
|
819
1081
|
continue;
|
|
820
1082
|
}
|
|
821
1083
|
const tables = /* @__PURE__ */ new Set();
|
|
822
1084
|
for (const f of sqlFiles) {
|
|
823
1085
|
try {
|
|
824
|
-
const sql =
|
|
1086
|
+
const sql = fs5.readFileSync(path5.join(projectDir, dir, f), "utf8");
|
|
825
1087
|
for (const m of sql.matchAll(/CREATE TABLE (?:IF NOT EXISTS )?["'`]?(\w+)/gi)) tables.add(m[1]);
|
|
826
1088
|
} catch {
|
|
827
1089
|
}
|
|
@@ -832,17 +1094,17 @@ function scanDataSchema(projectDir, files) {
|
|
|
832
1094
|
}
|
|
833
1095
|
function scanConventions(projectDir) {
|
|
834
1096
|
const lines = [];
|
|
835
|
-
const has = (f) =>
|
|
1097
|
+
const has = (f) => fs5.existsSync(path5.join(projectDir, f));
|
|
836
1098
|
const pm = has("bun.lockb") || has("bun.lock") ? "bun" : has("pnpm-lock.yaml") ? "pnpm" : has("yarn.lock") ? "yarn" : has("package-lock.json") ? "npm" : null;
|
|
837
1099
|
if (pm) lines.push(`- gestor de paquetes: ${pm}`);
|
|
838
1100
|
let pkg = {};
|
|
839
1101
|
try {
|
|
840
|
-
pkg = JSON.parse(
|
|
1102
|
+
pkg = JSON.parse(fs5.readFileSync(path5.join(projectDir, "package.json"), "utf8"));
|
|
841
1103
|
} catch {
|
|
842
1104
|
}
|
|
843
1105
|
if (pkg.workspaces || has("pnpm-workspace.yaml") || has("turbo.json")) lines.push("- monorepo: s\xED (workspaces)");
|
|
844
1106
|
try {
|
|
845
|
-
const ts = JSON.parse(
|
|
1107
|
+
const ts = JSON.parse(fs5.readFileSync(path5.join(projectDir, "tsconfig.json"), "utf8"));
|
|
846
1108
|
const co = ts.compilerOptions ?? {};
|
|
847
1109
|
lines.push(`- TypeScript${co.strict ? " strict" : ""}`);
|
|
848
1110
|
const paths = Object.keys(co.paths ?? {}).slice(0, 5);
|
|
@@ -864,18 +1126,18 @@ function scanConventions(projectDir) {
|
|
|
864
1126
|
}
|
|
865
1127
|
function linkMapToScans(vault, name, titles) {
|
|
866
1128
|
if (titles.length === 0) return;
|
|
867
|
-
const mapFile =
|
|
1129
|
+
const mapFile = path5.join(vault.managed, "notes", `mapa-${slugify(name)}.md`);
|
|
868
1130
|
try {
|
|
869
|
-
const text =
|
|
1131
|
+
const text = fs5.readFileSync(mapFile, "utf8");
|
|
870
1132
|
if (text.includes("Contexto ampliado:")) return;
|
|
871
|
-
|
|
1133
|
+
fs5.appendFileSync(mapFile, `
|
|
872
1134
|
Contexto ampliado: ${titles.map((t) => `[[${t}]]`).join(" \xB7 ")}
|
|
873
1135
|
`);
|
|
874
1136
|
} catch {
|
|
875
1137
|
}
|
|
876
1138
|
}
|
|
877
1139
|
function scanAll(vault, projectDir) {
|
|
878
|
-
const name =
|
|
1140
|
+
const name = path5.basename(projectDir);
|
|
879
1141
|
const gitignored = ensureGitignore(projectDir, vault.root) !== null;
|
|
880
1142
|
try {
|
|
881
1143
|
untrackPersonalConfigs(projectDir);
|
|
@@ -901,6 +1163,7 @@ function scanAll(vault, projectDir) {
|
|
|
901
1163
|
const env = run(() => scanEnvNames(projectDir));
|
|
902
1164
|
const data = run(() => scanDataSchema(projectDir, files));
|
|
903
1165
|
const conventions = run(() => scanConventions(projectDir));
|
|
1166
|
+
const flow = run(() => scanFlow(files));
|
|
904
1167
|
const notes = [];
|
|
905
1168
|
const titles = [];
|
|
906
1169
|
const truncated = [];
|
|
@@ -929,12 +1192,28 @@ Proyecto: [[Mapa - ${name}]]`
|
|
|
929
1192
|
write("env", `Env - ${name}`, `Variables de entorno (SOLO nombres \u2014 los valores nunca se guardan).`, env);
|
|
930
1193
|
write("datos", `Datos - ${name}`, `Esquema de datos detectado en archivos (sin conexi\xF3n a BD).`, data);
|
|
931
1194
|
write("convenciones", `Convenciones - ${name}`, `Convenciones detectadas por \`ale scan\`.`, conventions);
|
|
1195
|
+
write(
|
|
1196
|
+
"flujo",
|
|
1197
|
+
`Flujo - ${name}`,
|
|
1198
|
+
`Flujo de la app: qu\xE9 recorre una petici\xF3n (entrada \u2192 auth \u2192 datos). Detectado por \`ale scan\`.`,
|
|
1199
|
+
flow
|
|
1200
|
+
);
|
|
932
1201
|
linkMapToScans(vault, name, titles);
|
|
933
|
-
return {
|
|
1202
|
+
return {
|
|
1203
|
+
api: api.length,
|
|
1204
|
+
env: env.length,
|
|
1205
|
+
data: data.length,
|
|
1206
|
+
conventions: conventions.length,
|
|
1207
|
+
flow: flow.length,
|
|
1208
|
+
notes,
|
|
1209
|
+
gitignored,
|
|
1210
|
+
truncated
|
|
1211
|
+
};
|
|
934
1212
|
}
|
|
935
1213
|
|
|
936
1214
|
// src/cli.ts
|
|
937
1215
|
function registerAgentsMcp(agents, scope, cwd, portable = false) {
|
|
1216
|
+
setPortableMode(portable);
|
|
938
1217
|
for (const agent of agents) {
|
|
939
1218
|
if (agent.id === "claude") {
|
|
940
1219
|
if (scope === "project") {
|
|
@@ -995,7 +1274,7 @@ program.command("init").description("Crea/conecta la b\xF3veda e instala TODO: m
|
|
|
995
1274
|
).action(async (opts) => {
|
|
996
1275
|
const isProject = Boolean(opts.project) && !opts.global;
|
|
997
1276
|
const cwd = process.cwd();
|
|
998
|
-
const vaultPath =
|
|
1277
|
+
const vaultPath = path6.resolve(opts.path ?? (isProject ? path6.join(cwd, "Alexandria") : defaultVaultPath()));
|
|
999
1278
|
await showBanner();
|
|
1000
1279
|
console.log(pc.bold(`Instalaci\xF3n ${isProject ? "por proyecto" : "global"}
|
|
1001
1280
|
`));
|
|
@@ -1067,7 +1346,7 @@ program.command("init").description("Crea/conecta la b\xF3veda e instala TODO: m
|
|
|
1067
1346
|
}
|
|
1068
1347
|
if (isProject) {
|
|
1069
1348
|
const s = scanAll(vault, cwd);
|
|
1070
|
-
console.log(pc.green(`\u2713 Proyecto escaneado \u2192 API: ${s.api} \xB7 Env: ${s.env} \xB7 Datos: ${s.data} \xB7 Convenciones: ${s.conventions} (re-ejecuta con: ale scan)`));
|
|
1349
|
+
console.log(pc.green(`\u2713 Proyecto escaneado \u2192 API: ${s.api} \xB7 Env: ${s.env} \xB7 Datos: ${s.data} \xB7 Flujo: ${s.flow} \xB7 Convenciones: ${s.conventions} (re-ejecuta con: ale scan)`));
|
|
1071
1350
|
}
|
|
1072
1351
|
await downloadModelIfMissing();
|
|
1073
1352
|
const idx = VaultIndex.load(vault);
|
|
@@ -1081,10 +1360,10 @@ program.command("init").description("Crea/conecta la b\xF3veda e instala TODO: m
|
|
|
1081
1360
|
});
|
|
1082
1361
|
program.command("plan").description("Crear un plan del Protocolo desde un archivo .md/.txt (en vez de escribirlo en la terminal)").argument("<file>", 'archivo con el plan (los checkboxes "- [ ]" se toman como Definition of Done)').option("--title <t>", "t\xEDtulo del plan (default: nombre del archivo o primer heading)").action(async (file, opts) => {
|
|
1083
1362
|
const { vault } = await ensureReady();
|
|
1084
|
-
const abs =
|
|
1085
|
-
const raw =
|
|
1363
|
+
const abs = path6.resolve(file);
|
|
1364
|
+
const raw = fs6.readFileSync(abs, "utf8");
|
|
1086
1365
|
const heading = raw.match(/^#\s+(.+)$/m)?.[1]?.trim();
|
|
1087
|
-
const title = opts.title ?? heading ??
|
|
1366
|
+
const title = opts.title ?? heading ?? path6.basename(abs).replace(/\.(md|txt)$/i, "");
|
|
1088
1367
|
const dod = [...raw.matchAll(/^[-*]\s*\[[ x]\]\s*(.+)$/gim)].map((m) => m[1].trim());
|
|
1089
1368
|
const noteFile = createNote(vault.managed, {
|
|
1090
1369
|
title: title.startsWith("Plan - ") ? title : `Plan - ${title}`,
|
|
@@ -1094,7 +1373,7 @@ program.command("plan").description("Crear un plan del Protocolo desde un archiv
|
|
|
1094
1373
|
content: raw.trim()
|
|
1095
1374
|
});
|
|
1096
1375
|
await VaultIndex.load(vault).refresh();
|
|
1097
|
-
console.log(pc.green(`\u2713 Plan creado: ${
|
|
1376
|
+
console.log(pc.green(`\u2713 Plan creado: ${path6.relative(vault.root, noteFile)}`));
|
|
1098
1377
|
console.log(pc.dim(` DoD detectada: ${dod.length} criterios${dod.length ? " \u2014 " + dod.slice(0, 3).join(" \xB7 ") + (dod.length > 3 ? " \u2026" : "") : ' (agrega checkboxes "- [ ]" para criterios verificables)'}`));
|
|
1099
1378
|
console.log(pc.dim(" El agente lo ver\xE1 como plan abierto al iniciar sesi\xF3n y lo retomar\xE1 con task_verify."));
|
|
1100
1379
|
const tasks = [...raw.matchAll(/^\s*\d+[.)]\s+(.+)$/gm)].map((m) => m[1].trim());
|
|
@@ -1166,21 +1445,21 @@ program.command("consolidate").description("Archiva prompts viejos sin reuso: sa
|
|
|
1166
1445
|
console.log(pc.dim("Nada que consolidar: sin prompts viejos sin uso."));
|
|
1167
1446
|
return;
|
|
1168
1447
|
}
|
|
1169
|
-
const archiveDir =
|
|
1170
|
-
if (!opts.dry)
|
|
1448
|
+
const archiveDir = path6.join(vault.managed, "archive");
|
|
1449
|
+
if (!opts.dry) fs6.mkdirSync(archiveDir, { recursive: true });
|
|
1171
1450
|
for (const n of stale) {
|
|
1172
1451
|
console.log(
|
|
1173
1452
|
`${opts.dry ? pc.yellow("se archivar\xEDa") : pc.cyan("archivado")} ${n.rel} ${pc.dim(`(${(n.created ?? "").slice(0, 10)}, hits ${n.hits})`)}`
|
|
1174
1453
|
);
|
|
1175
1454
|
if (!opts.dry) {
|
|
1176
|
-
|
|
1455
|
+
fs6.renameSync(path6.join(vault.root, n.rel), path6.join(archiveDir, path6.basename(n.rel)));
|
|
1177
1456
|
}
|
|
1178
1457
|
}
|
|
1179
1458
|
if (!opts.dry) {
|
|
1180
1459
|
await VaultIndex.load(vault).refresh();
|
|
1181
1460
|
console.log(
|
|
1182
1461
|
pc.green(`
|
|
1183
|
-
\u2713 ${stale.length} prompts archivados en ${
|
|
1462
|
+
\u2713 ${stale.length} prompts archivados en ${path6.relative(vault.root, archiveDir)}/ \u2014 fuera del grafo, siguen buscables. Nada se pierde.`)
|
|
1184
1463
|
);
|
|
1185
1464
|
} else {
|
|
1186
1465
|
console.log(pc.dim(`
|
|
@@ -1211,10 +1490,10 @@ program.command("add").description("Guardar una nota manualmente").argument("<ti
|
|
|
1211
1490
|
const { vault } = await ensureReady();
|
|
1212
1491
|
let content = opts.content;
|
|
1213
1492
|
if (!content && opts.file) {
|
|
1214
|
-
content =
|
|
1493
|
+
content = fs6.readFileSync(path6.resolve(opts.file), "utf8");
|
|
1215
1494
|
}
|
|
1216
1495
|
if (!content && !process.stdin.isTTY) {
|
|
1217
|
-
content =
|
|
1496
|
+
content = fs6.readFileSync(0, "utf8");
|
|
1218
1497
|
}
|
|
1219
1498
|
const file = createNote(vault.managed, {
|
|
1220
1499
|
title,
|
|
@@ -1222,7 +1501,7 @@ program.command("add").description("Guardar una nota manualmente").argument("<ti
|
|
|
1222
1501
|
tags: opts.tags ? opts.tags.split(",").map((t) => t.trim()) : []
|
|
1223
1502
|
});
|
|
1224
1503
|
await VaultIndex.load(vault).refresh();
|
|
1225
|
-
console.log(pc.green(`\u2713 ${
|
|
1504
|
+
console.log(pc.green(`\u2713 ${path6.relative(vault.root, file)}`));
|
|
1226
1505
|
});
|
|
1227
1506
|
program.command("search").description("B\xFAsqueda h\xEDbrida (sem\xE1ntica + keyword) en la b\xF3veda").argument("<query...>", "qu\xE9 buscar").option("-k <n>", "n\xFAmero de resultados", "6").option("--expand", "incluir vecinos del grafo").action(async (query, opts) => {
|
|
1228
1507
|
const vault = getVault();
|
|
@@ -1311,12 +1590,12 @@ program.command("scan").description("Escanea el proyecto (API, env-nombres, dato
|
|
|
1311
1590
|
const idx = VaultIndex.load(vault);
|
|
1312
1591
|
await idx.refresh().catch(() => {
|
|
1313
1592
|
});
|
|
1314
|
-
console.log(pc.green(`\u2713 API: ${s.api} rutas \xB7 Env: ${s.env} vars (solo nombres) \xB7 Datos: ${s.data} \xB7 Convenciones: ${s.conventions}${s.gitignored ? " \xB7 .gitignore \u2713" : ""}`));
|
|
1593
|
+
console.log(pc.green(`\u2713 API: ${s.api} rutas \xB7 Env: ${s.env} vars (solo nombres) \xB7 Datos: ${s.data} \xB7 Flujo: ${s.flow} \xB7 Convenciones: ${s.conventions}${s.gitignored ? " \xB7 .gitignore \u2713" : ""}`));
|
|
1315
1594
|
if (s.truncated.length) {
|
|
1316
1595
|
console.log(pc.yellow(` \u26A0 Notas truncadas por el cap: ${s.truncated.join(", ")} \u2014 s\xFAbelo con: ale config set scan.maxEntries <n>`));
|
|
1317
1596
|
}
|
|
1318
1597
|
if (s.notes.length) {
|
|
1319
|
-
for (const n of s.notes) console.log(pc.dim(` ${
|
|
1598
|
+
for (const n of s.notes) console.log(pc.dim(` ${path6.relative(vault.root, n)}`));
|
|
1320
1599
|
} else {
|
|
1321
1600
|
console.log(pc.dim(" Nada detectado (\xBFproyecto sin package.json/api/env?)"));
|
|
1322
1601
|
}
|
|
@@ -1377,7 +1656,7 @@ program.command("stats").description("Estado de la b\xF3veda y tokens ahorrados"
|
|
|
1377
1656
|
async function runSkills(opts) {
|
|
1378
1657
|
const { vault } = await ensureReady();
|
|
1379
1658
|
const cwd = process.cwd();
|
|
1380
|
-
const targetDir = opts.project ?
|
|
1659
|
+
const targetDir = opts.project ? path6.join(cwd, ".claude", "skills") : path6.join(process.env.HOME ?? process.env.USERPROFILE ?? cwd, ".claude", "skills");
|
|
1381
1660
|
const recs = await recommendSkills(vault, [targetDir]);
|
|
1382
1661
|
if (recs.length === 0) {
|
|
1383
1662
|
console.log(pc.dim("Sin recomendaciones nuevas: la b\xF3veda a\xFAn no tiene suficientes patrones (o ya est\xE1 todo instalado)."));
|
|
@@ -1416,6 +1695,54 @@ async function runSkills(opts) {
|
|
|
1416
1695
|
}
|
|
1417
1696
|
}
|
|
1418
1697
|
program.command("skills").description("Analiza la b\xF3veda y recomienda/instala skills de Claude (skills.sh o repo local)").option("-y, --yes", "instalar sin preguntar").option("--project", "instalar en .claude/skills del proyecto (default: global del usuario)").action(runSkills);
|
|
1698
|
+
program.command("skills:evolve").alias("evolve").description("Genera/actualiza una skill VIVA del proyecto con lo que la b\xF3veda sabe (flujo, convenciones, lecciones). Muestra el diff y pide aprobaci\xF3n").option("-y, --yes", "escribir sin preguntar (para scripts)").option("--global", "guardar en ~/.claude/skills en vez de .claude/skills del proyecto").action(async (opts) => {
|
|
1699
|
+
const { vault } = await ensureReady();
|
|
1700
|
+
const cwd = process.cwd();
|
|
1701
|
+
const proj = path6.basename(cwd);
|
|
1702
|
+
const targetDir = skillTargetDir(cwd, Boolean(opts.global));
|
|
1703
|
+
const result = evolveSkill(vault, proj, targetDir);
|
|
1704
|
+
if (!result) {
|
|
1705
|
+
console.log(pc.yellow(`Sin material todav\xEDa para \xAB${proj}\xBB.`));
|
|
1706
|
+
console.log(pc.dim(" Corre `ale scan` (flujo/convenciones) y acumula lecciones con el Protocolo; luego repite."));
|
|
1707
|
+
return;
|
|
1708
|
+
}
|
|
1709
|
+
const s = result.sources;
|
|
1710
|
+
console.log(pc.bold(`
|
|
1711
|
+
\u{1F9EC} Skill del proyecto: ${result.skillName}`));
|
|
1712
|
+
console.log(pc.dim(` fuentes \u2192 flujo:${s.flujo ? "\u2713" : "\u2014"} convenciones:${s.convenciones ? "\u2713" : "\u2014"} lecciones:${s.lecciones}`));
|
|
1713
|
+
console.log(pc.dim(` destino \u2192 ${result.file}`));
|
|
1714
|
+
if (!result.changed) {
|
|
1715
|
+
console.log(pc.green("\n\u2713 La skill ya est\xE1 al d\xEDa \u2014 nada que cambiar.\n"));
|
|
1716
|
+
return;
|
|
1717
|
+
}
|
|
1718
|
+
const diff = simpleDiff(result.previous, result.content);
|
|
1719
|
+
console.log(pc.bold(`
|
|
1720
|
+
${result.previous ? "Cambios" : "Contenido nuevo"} (${diff.length} l\xEDneas):
|
|
1721
|
+
`));
|
|
1722
|
+
for (const l of diff.slice(0, 40)) {
|
|
1723
|
+
console.log(l.startsWith("+") ? pc.green(l) : pc.red(l));
|
|
1724
|
+
}
|
|
1725
|
+
if (diff.length > 40) console.log(pc.dim(` \u2026 +${diff.length - 40} l\xEDneas m\xE1s`));
|
|
1726
|
+
let ok = Boolean(opts.yes);
|
|
1727
|
+
if (!ok) {
|
|
1728
|
+
if (!process.stdin.isTTY) {
|
|
1729
|
+
console.log(pc.yellow("\n(no interactivo: no se escribi\xF3 nada \u2014 usa `--yes` para aplicar)\n"));
|
|
1730
|
+
return;
|
|
1731
|
+
}
|
|
1732
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
1733
|
+
const ans = (await rl.question(pc.bold("\n\xBFEscribir esta skill? [s/N] "))).trim().toLowerCase();
|
|
1734
|
+
rl.close();
|
|
1735
|
+
ok = ans === "s" || ans === "si" || ans === "s\xED" || ans === "y";
|
|
1736
|
+
}
|
|
1737
|
+
if (!ok) {
|
|
1738
|
+
console.log(pc.dim("Sin cambios.\n"));
|
|
1739
|
+
return;
|
|
1740
|
+
}
|
|
1741
|
+
writeSkill(result);
|
|
1742
|
+
console.log(pc.green(`
|
|
1743
|
+
\u2713 Skill escrita en ${result.file}`));
|
|
1744
|
+
console.log(pc.dim(" Se recarga al abrir una sesi\xF3n nueva del agente en este proyecto.\n"));
|
|
1745
|
+
});
|
|
1419
1746
|
program.command("doctor").description("Verifica y repara la instalaci\xF3n (modelo, hooks, MCP, \xEDndice)").option("--project", "revisar registros del proyecto (cwd) en vez de los globales").action(async (opts) => {
|
|
1420
1747
|
const vault = getVault();
|
|
1421
1748
|
const cwd = process.cwd();
|
|
@@ -1450,12 +1777,18 @@ program.command("doctor").description("Verifica y repara la instalaci\xF3n (mode
|
|
|
1450
1777
|
console.log(pc.yellow("\u26A0 Embeddings desalineados con el \xEDndice \u2014 corre `ale reindex --force`"));
|
|
1451
1778
|
} else if (idx.emb) {
|
|
1452
1779
|
console.log(`${pc.green("\u2713")} Embeddings alineados (${idx.meta.chunks.length} chunks)`);
|
|
1780
|
+
} else if (idx.meta.chunks.length > 0 && model) {
|
|
1781
|
+
console.log(pc.yellow(`\u26A0 \xCDndice SIN vectores (${idx.meta.chunks.length} chunks) \u2014 b\xFAsqueda degradada a keyword. Reconstruyendo\u2026`));
|
|
1782
|
+
const rebuilt = await idx.refresh(true, true);
|
|
1783
|
+
console.log(
|
|
1784
|
+
idx.emb ? `${pc.green("\u2713")} \xCDndice sem\xE1ntico reconstruido (${rebuilt.changed} notas)` : pc.yellow("\u26A0 No se pudo reconstruir \u2014 corre `ale reindex --force` y revisa el modelo")
|
|
1785
|
+
);
|
|
1453
1786
|
}
|
|
1454
1787
|
try {
|
|
1455
|
-
const name =
|
|
1456
|
-
const mapFile =
|
|
1457
|
-
const pkgM =
|
|
1458
|
-
const mapM =
|
|
1788
|
+
const name = path6.basename(cwd);
|
|
1789
|
+
const mapFile = path6.join(vault.managed, "notes", `mapa-${slugify(name)}.md`);
|
|
1790
|
+
const pkgM = fs6.statSync(path6.join(cwd, "package.json")).mtimeMs;
|
|
1791
|
+
const mapM = fs6.statSync(mapFile).mtimeMs;
|
|
1459
1792
|
if (pkgM > mapM) {
|
|
1460
1793
|
console.log(pc.yellow("\u26A0 package.json cambi\xF3 despu\xE9s del \xFAltimo escaneo \u2014 corre `ale scan` para refrescar el contexto"));
|
|
1461
1794
|
} else {
|
|
@@ -1464,7 +1797,7 @@ program.command("doctor").description("Verifica y repara la instalaci\xF3n (mode
|
|
|
1464
1797
|
} catch {
|
|
1465
1798
|
}
|
|
1466
1799
|
const skillsRepoCfg = localSkillsRepo();
|
|
1467
|
-
if (skillsRepoCfg && !
|
|
1800
|
+
if (skillsRepoCfg && !fs6.existsSync(skillsRepoCfg)) {
|
|
1468
1801
|
console.log(pc.yellow(`\u26A0 skills.repo apunta a ${skillsRepoCfg} y no existe \u2014 corr\xEDgelo: ale config set skills.repo <ruta>`));
|
|
1469
1802
|
}
|
|
1470
1803
|
console.log();
|
|
@@ -1478,14 +1811,14 @@ program.command("uninstall").description("Reversi\xF3n limpia: quita hooks, bloq
|
|
|
1478
1811
|
const claudeMd = removeClaudeMd(scope, cwd);
|
|
1479
1812
|
if (claudeMd) console.log(pc.green(`\u2713 Bloque de Alexandria removido de ${claudeMd}`));
|
|
1480
1813
|
if (opts.project) {
|
|
1481
|
-
const mcpFile =
|
|
1814
|
+
const mcpFile = path6.join(cwd, ".mcp.json");
|
|
1482
1815
|
try {
|
|
1483
|
-
const cfg = JSON.parse(
|
|
1816
|
+
const cfg = JSON.parse(fs6.readFileSync(mcpFile, "utf8"));
|
|
1484
1817
|
if (cfg.mcpServers?.alexandria) {
|
|
1485
1818
|
delete cfg.mcpServers.alexandria;
|
|
1486
1819
|
if (Object.keys(cfg.mcpServers).length === 0) delete cfg.mcpServers;
|
|
1487
|
-
if (Object.keys(cfg).length === 0)
|
|
1488
|
-
else
|
|
1820
|
+
if (Object.keys(cfg).length === 0) fs6.rmSync(mcpFile, { force: true });
|
|
1821
|
+
else fs6.writeFileSync(mcpFile, JSON.stringify(cfg, null, 2) + "\n");
|
|
1489
1822
|
console.log(pc.green("\u2713 MCP removido de .mcp.json"));
|
|
1490
1823
|
}
|
|
1491
1824
|
} catch {
|