@ureck/alexandria 0.4.0 → 0.5.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/README.md +173 -173
- package/dist/{chunk-ADHRHLX7.js → chunk-3ETM6PKR.js} +17 -4
- package/dist/{chunk-ZW7XY3EN.js → chunk-7G3NPKDO.js} +6 -2
- package/dist/{chunk-KB6KYZFQ.js → chunk-DYCARGQR.js} +19 -1
- package/dist/{chunk-KHTYRYDR.js → chunk-IQM5S5N4.js} +8 -8
- package/dist/{chunk-WPNU64MA.js → chunk-UTXUGXDB.js} +8 -4
- package/dist/{chunk-JPHL2JHE.js → chunk-XWR74BQ2.js} +26 -4
- package/dist/cli.js +181 -22
- package/dist/hooks/on-prompt.js +5 -5
- package/dist/hooks/on-session-start.js +12 -3
- package/dist/hooks/on-stop.js +2 -2
- package/dist/mcp/server.js +133 -5
- package/dist/{viewer-FRJYOK3S.js → viewer-G3N57646.js} +3 -3
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
VaultIndex
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-7G3NPKDO.js";
|
|
5
5
|
|
|
6
6
|
// src/graph/viewer.ts
|
|
7
7
|
import fs from "fs";
|
|
@@ -65,8 +65,12 @@ function renderGraphHtml(data, live) {
|
|
|
65
65
|
<div class="leg" id="leg">
|
|
66
66
|
<label><input type="checkbox" data-type="note" checked><b style="background:#7aa2f7"></b>nota</label>
|
|
67
67
|
<label><input type="checkbox" data-type="map" checked><b style="background:#f7768e"></b>mapa</label>
|
|
68
|
+
<label><input type="checkbox" data-type="plan" checked><b style="background:#bb9af7"></b>plan</label>
|
|
69
|
+
<label><input type="checkbox" data-type="verification" checked><b style="background:#2ac3de"></b>verificaci\xF3n</label>
|
|
70
|
+
<label><input type="checkbox" data-type="lesson" checked><b style="background:#ffc777"></b>lecci\xF3n</label>
|
|
71
|
+
<label><input type="checkbox" data-type="solution" checked><b style="background:#73daca"></b>soluci\xF3n</label>
|
|
68
72
|
<label><input type="checkbox" data-type="session" checked><b style="background:#9ece6a"></b>sesi\xF3n</label>
|
|
69
|
-
<label><input type="checkbox" data-type="prompt"><b style="background:#
|
|
73
|
+
<label><input type="checkbox" data-type="prompt"><b style="background:#565f89"></b>prompt</label>
|
|
70
74
|
</div>
|
|
71
75
|
<div id="hint">filtros por tipo (prompts ocultos por default \u2014 ruido) \xB7 arrastra \xB7 rueda = zoom<br>hover = conexiones \xB7 click = detalle \xB7 \u2014 s\xF3lida = [[wikilink]] \xB7 \u2025 punteada = sem\xE1ntica</div>
|
|
72
76
|
</div>
|
|
@@ -79,7 +83,7 @@ function renderGraphHtml(data, live) {
|
|
|
79
83
|
'use strict';
|
|
80
84
|
const LIVE = ${live};
|
|
81
85
|
let DATA = ${JSON.stringify(data)};
|
|
82
|
-
const COLORS = { note:'#7aa2f7', session:'#9ece6a', prompt:'#
|
|
86
|
+
const COLORS = { note:'#7aa2f7', session:'#9ece6a', prompt:'#565f89', map:'#f7768e', plan:'#bb9af7', verification:'#2ac3de', lesson:'#ffc777', solution:'#73daca', task:'#7dcfff' };
|
|
83
87
|
const cv = document.getElementById('c'), ctx = cv.getContext('2d');
|
|
84
88
|
const DPR = Math.min(devicePixelRatio || 1, 2);
|
|
85
89
|
let W, H;
|
|
@@ -91,7 +95,7 @@ let nodes = [], byId = new Map(), edges = [];
|
|
|
91
95
|
let zoom = 1, panX = 0, panY = 0, dragNode = null, hot = true, heat = 300;
|
|
92
96
|
let didFit = false, hover = null, filter = '';
|
|
93
97
|
// filtros por tipo (estilo Obsidian) \u2014 prompts ocultos por default: son ruido visual
|
|
94
|
-
const typeOn = { note: true, map: true, session: true, prompt: false };
|
|
98
|
+
const typeOn = { note: true, map: true, session: true, prompt: false, plan: true, verification: true, lesson: true, solution: true, task: true };
|
|
95
99
|
document.querySelectorAll('#leg input').forEach(cb => cb.addEventListener('change', e => {
|
|
96
100
|
typeOn[e.target.dataset.type] = e.target.checked; heat = Math.max(heat, 30); hot = true;
|
|
97
101
|
}));
|
|
@@ -4,6 +4,17 @@
|
|
|
4
4
|
import fs from "fs";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import matter from "gray-matter";
|
|
7
|
+
var NOTE_TYPES = [
|
|
8
|
+
"note",
|
|
9
|
+
"prompt",
|
|
10
|
+
"session",
|
|
11
|
+
"map",
|
|
12
|
+
"plan",
|
|
13
|
+
"task",
|
|
14
|
+
"verification",
|
|
15
|
+
"lesson",
|
|
16
|
+
"solution"
|
|
17
|
+
];
|
|
7
18
|
var SKIP_DIRS = /* @__PURE__ */ new Set([".obsidian", ".vault", ".trash", ".git", "node_modules"]);
|
|
8
19
|
function extractWikilinks(content) {
|
|
9
20
|
const out = /* @__PURE__ */ new Set();
|
|
@@ -42,12 +53,14 @@ function parseNote(root, absPath) {
|
|
|
42
53
|
const { data, content } = matter(raw);
|
|
43
54
|
const rel = path.relative(root, absPath).split(path.sep).join("/");
|
|
44
55
|
const title = typeof data.title === "string" && data.title || path.basename(absPath, ".md");
|
|
45
|
-
const type =
|
|
56
|
+
const type = NOTE_TYPES.includes(data.type) ? data.type : "note";
|
|
57
|
+
const status = ["active", "completed", "failed"].includes(data.status) ? data.status : void 0;
|
|
46
58
|
const tags = Array.isArray(data.tags) ? data.tags.map(String) : [];
|
|
47
59
|
return {
|
|
48
60
|
rel,
|
|
49
61
|
title,
|
|
50
62
|
type,
|
|
63
|
+
status,
|
|
51
64
|
tags,
|
|
52
65
|
created: data.created ? String(data.created) : void 0,
|
|
53
66
|
hits: typeof data.hits === "number" ? data.hits : 1,
|
|
@@ -63,6 +76,7 @@ function frontmatter(n) {
|
|
|
63
76
|
// del frontmatter — sin esto su graph view muestra los enlaces como rotos
|
|
64
77
|
`aliases: [${JSON.stringify(n.title)}]`,
|
|
65
78
|
`type: ${n.type}`,
|
|
79
|
+
...n.status ? [`status: ${n.status}`] : [],
|
|
66
80
|
`tags: [${n.tags.map((t) => JSON.stringify(t)).join(", ")}]`,
|
|
67
81
|
`created: ${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
68
82
|
`hits: ${n.hits ?? 1}`,
|
|
@@ -93,10 +107,17 @@ function createNote(managed, n) {
|
|
|
93
107
|
while (fs.existsSync(file)) file = path.join(dir, `${base}-${i++}.md`);
|
|
94
108
|
fs.writeFileSync(
|
|
95
109
|
file,
|
|
96
|
-
frontmatter({ title: n.title, type: n.type ?? "note", tags: n.tags ?? [] }) + n.content.trim() + "\n"
|
|
110
|
+
frontmatter({ title: n.title, type: n.type ?? "note", tags: n.tags ?? [], status: n.status }) + n.content.trim() + "\n"
|
|
97
111
|
);
|
|
98
112
|
return file;
|
|
99
113
|
}
|
|
114
|
+
function setNoteStatus(absPath, status) {
|
|
115
|
+
const raw = fs.readFileSync(absPath, "utf8");
|
|
116
|
+
const { data, content } = matter(raw);
|
|
117
|
+
data.status = status;
|
|
118
|
+
data.updated = (/* @__PURE__ */ new Date()).toISOString();
|
|
119
|
+
fs.writeFileSync(absPath, matter.stringify(content, data));
|
|
120
|
+
}
|
|
100
121
|
function touchNote(absPath) {
|
|
101
122
|
const raw = fs.readFileSync(absPath, "utf8");
|
|
102
123
|
const { data, content } = matter(raw);
|
|
@@ -116,7 +137,7 @@ function upsertNote(managed, n) {
|
|
|
116
137
|
} else {
|
|
117
138
|
fs.writeFileSync(
|
|
118
139
|
file,
|
|
119
|
-
frontmatter({ title: n.title, type: n.type ?? "note", tags: n.tags ?? [] }) + n.content.trim() + "\n"
|
|
140
|
+
frontmatter({ title: n.title, type: n.type ?? "note", tags: n.tags ?? [], status: n.status }) + n.content.trim() + "\n"
|
|
120
141
|
);
|
|
121
142
|
}
|
|
122
143
|
return file;
|
|
@@ -130,7 +151,7 @@ function appendToNote(managed, n) {
|
|
|
130
151
|
} else {
|
|
131
152
|
fs.writeFileSync(
|
|
132
153
|
file,
|
|
133
|
-
frontmatter({ title: n.title, type: n.type ?? "session", tags: n.tags ?? [] }) + n.content.trim() + "\n"
|
|
154
|
+
frontmatter({ title: n.title, type: n.type ?? "session", tags: n.tags ?? [], status: n.status }) + n.content.trim() + "\n"
|
|
134
155
|
);
|
|
135
156
|
}
|
|
136
157
|
return file;
|
|
@@ -142,6 +163,7 @@ export {
|
|
|
142
163
|
parseNote,
|
|
143
164
|
ensureAlias,
|
|
144
165
|
createNote,
|
|
166
|
+
setNoteStatus,
|
|
145
167
|
touchNote,
|
|
146
168
|
upsertNote,
|
|
147
169
|
appendToNote
|
package/dist/cli.js
CHANGED
|
@@ -13,30 +13,32 @@ import {
|
|
|
13
13
|
registerMcpGlobal,
|
|
14
14
|
registerMcpProject,
|
|
15
15
|
unregisterHooks
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-IQM5S5N4.js";
|
|
17
17
|
import {
|
|
18
18
|
hybridSearch
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-3ETM6PKR.js";
|
|
20
20
|
import {
|
|
21
21
|
defaultVaultPath,
|
|
22
22
|
ensureVaultStructure,
|
|
23
|
+
getConfigKey,
|
|
23
24
|
globalConfigPath,
|
|
24
25
|
resolveVault,
|
|
26
|
+
setConfigKey,
|
|
25
27
|
vaultExists,
|
|
26
28
|
writeGlobalConfig,
|
|
27
29
|
writeProjectConfig
|
|
28
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-DYCARGQR.js";
|
|
29
31
|
import {
|
|
30
32
|
serveGraph
|
|
31
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-UTXUGXDB.js";
|
|
32
34
|
import {
|
|
33
35
|
VaultIndex
|
|
34
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-7G3NPKDO.js";
|
|
35
37
|
import {
|
|
36
38
|
createNote,
|
|
37
39
|
slugify,
|
|
38
40
|
upsertNote
|
|
39
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-XWR74BQ2.js";
|
|
40
42
|
import {
|
|
41
43
|
MODEL_ID,
|
|
42
44
|
getEmbedder,
|
|
@@ -436,37 +438,68 @@ async function showBanner(animate) {
|
|
|
436
438
|
import fs3 from "fs";
|
|
437
439
|
import os3 from "os";
|
|
438
440
|
import path3 from "path";
|
|
441
|
+
import { execFileSync as execFileSync3 } from "child_process";
|
|
442
|
+
var PERSONAL_CONFIG_FILES = [
|
|
443
|
+
".vault.json",
|
|
444
|
+
".mcp.json",
|
|
445
|
+
".cursor/mcp.json",
|
|
446
|
+
"opencode.json",
|
|
447
|
+
".vscode/mcp.json",
|
|
448
|
+
".gemini/settings.json"
|
|
449
|
+
];
|
|
439
450
|
function ensureGitignore(projectDir, vaultRoot) {
|
|
440
451
|
if (!fs3.existsSync(path3.join(projectDir, ".git"))) return null;
|
|
452
|
+
const entries = [];
|
|
441
453
|
const rel = path3.relative(projectDir, vaultRoot);
|
|
442
|
-
if (rel.startsWith(".."))
|
|
454
|
+
if (!rel.startsWith("..")) entries.push(`${rel.split(path3.sep).join("/")}/`);
|
|
455
|
+
entries.push(...PERSONAL_CONFIG_FILES);
|
|
443
456
|
const file = path3.join(projectDir, ".gitignore");
|
|
444
|
-
const entries = [`${rel.split(path3.sep).join("/")}/`];
|
|
445
457
|
let text = "";
|
|
446
458
|
try {
|
|
447
459
|
text = fs3.readFileSync(file, "utf8");
|
|
448
460
|
} catch {
|
|
449
461
|
}
|
|
450
|
-
const
|
|
462
|
+
const has = (e) => text.split("\n").some((l) => l.trim() === e || l.trim() === e.replace(/\/$/, ""));
|
|
463
|
+
const missing = entries.filter((e) => !has(e));
|
|
451
464
|
if (missing.length === 0) return null;
|
|
452
465
|
const block = `${text.trimEnd()}
|
|
453
466
|
|
|
454
|
-
# Alexandria (conocimiento personal
|
|
467
|
+
# Alexandria (conocimiento y config personal \u2014 no del repo)
|
|
455
468
|
${missing.join("\n")}
|
|
456
469
|
`;
|
|
457
470
|
fs3.writeFileSync(file, text.trim() ? block : block.trimStart());
|
|
458
471
|
return file;
|
|
459
472
|
}
|
|
473
|
+
function untrackPersonalConfigs(projectDir) {
|
|
474
|
+
if (!fs3.existsSync(path3.join(projectDir, ".git"))) return [];
|
|
475
|
+
const untracked = [];
|
|
476
|
+
for (const f of PERSONAL_CONFIG_FILES) {
|
|
477
|
+
if (!fs3.existsSync(path3.join(projectDir, f))) continue;
|
|
478
|
+
try {
|
|
479
|
+
const tracked = execFileSync3("git", ["ls-files", "--error-unmatch", f], {
|
|
480
|
+
cwd: projectDir,
|
|
481
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
482
|
+
});
|
|
483
|
+
if (tracked.toString().trim()) {
|
|
484
|
+
execFileSync3("git", ["rm", "--cached", "--quiet", f], { cwd: projectDir, stdio: "ignore" });
|
|
485
|
+
untracked.push(f);
|
|
486
|
+
}
|
|
487
|
+
} catch {
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return untracked;
|
|
491
|
+
}
|
|
460
492
|
var CLAUDE_MD_START = "<!-- alexandria:start -->";
|
|
461
493
|
var CLAUDE_MD_END = "<!-- alexandria:end -->";
|
|
462
494
|
function configureClaudeMd(scope, projectDir) {
|
|
463
495
|
const file = scope === "project" ? path3.join(projectDir, "CLAUDE.md") : path3.join(os3.homedir(), ".claude", "CLAUDE.md");
|
|
464
496
|
const block = [
|
|
465
497
|
CLAUDE_MD_START,
|
|
466
|
-
"## Alexandria \u2014 b\xF3veda de conocimiento (uso por default)",
|
|
498
|
+
"## Alexandria \u2014 b\xF3veda de conocimiento y Protocolo (uso por default)",
|
|
467
499
|
"- ANTES de explorar c\xF3digo o re-derivar contexto: busca con la tool MCP `vault_search`; si la b\xF3veda ya lo sabe, \xFAsalo.",
|
|
468
|
-
"-
|
|
469
|
-
"-
|
|
500
|
+
"- El Protocolo Alexandria es palanca, no l\xEDmite: tareas simples se responden directo, sin ceremonia. En tareas no triviales: `plan_create` (objetivo + Definition of Done) \u2192 ejecutar con toda tu capacidad \u2192 `task_verify` con evidencia real (la evidencia elimina errores, no frena) \u2192 si algo falla, `vault_search` por lecciones previas antes de re-debuggear \u2192 `lesson_extract` al resolver algo no obvio. Soluciones cacheadas se validan contra el c\xF3digo actual antes de reutilizarse.",
|
|
501
|
+
"- Al descubrir arquitectura o decisiones: `vault_save` (con `[[wikilinks]]`; el t\xEDtulo `Mapa - <proyecto>` actualiza el mapa que se inyecta al iniciar sesi\xF3n).",
|
|
502
|
+
"- `vault_related` trae conocimiento conectado sin releer archivos.",
|
|
470
503
|
CLAUDE_MD_END
|
|
471
504
|
].join("\n");
|
|
472
505
|
fs3.mkdirSync(path3.dirname(file), { recursive: true });
|
|
@@ -484,6 +517,24 @@ function configureClaudeMd(scope, projectDir) {
|
|
|
484
517
|
fs3.writeFileSync(file, text);
|
|
485
518
|
return file;
|
|
486
519
|
}
|
|
520
|
+
function removeClaudeMd(scope, projectDir) {
|
|
521
|
+
const file = scope === "project" ? path3.join(projectDir, "CLAUDE.md") : path3.join(os3.homedir(), ".claude", "CLAUDE.md");
|
|
522
|
+
let text;
|
|
523
|
+
try {
|
|
524
|
+
text = fs3.readFileSync(file, "utf8");
|
|
525
|
+
} catch {
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
if (!text.includes(CLAUDE_MD_START)) return null;
|
|
529
|
+
const re = new RegExp(`\\n*${CLAUDE_MD_START}[\\s\\S]*?${CLAUDE_MD_END}\\n*`);
|
|
530
|
+
const cleaned = text.replace(re, "\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
531
|
+
if (cleaned === "") {
|
|
532
|
+
fs3.rmSync(file, { force: true });
|
|
533
|
+
} else {
|
|
534
|
+
fs3.writeFileSync(file, cleaned + "\n");
|
|
535
|
+
}
|
|
536
|
+
return file;
|
|
537
|
+
}
|
|
487
538
|
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", ".next", "dist", "build", ".vault", ".claude", "coverage", "Alexandria", "KnowledgeVault"]);
|
|
488
539
|
function scanProject(vault, projectDir) {
|
|
489
540
|
const name = path3.basename(projectDir);
|
|
@@ -541,15 +592,15 @@ ${readme.split("\n").slice(0, 15).join("\n")}`);
|
|
|
541
592
|
}
|
|
542
593
|
|
|
543
594
|
// src/cli.ts
|
|
544
|
-
function registerAgentsMcp(agents, scope, cwd) {
|
|
595
|
+
function registerAgentsMcp(agents, scope, cwd, portable = false) {
|
|
545
596
|
for (const agent of agents) {
|
|
546
597
|
if (agent.id === "claude") {
|
|
547
598
|
if (scope === "project") {
|
|
548
|
-
const file = registerMcpProject(cwd);
|
|
599
|
+
const file = registerMcpProject(cwd, portable);
|
|
549
600
|
console.log(pc.green(`\u2713 MCP \u2192 Claude Code (${file})`));
|
|
550
601
|
continue;
|
|
551
602
|
}
|
|
552
|
-
if (registerMcpGlobal()) {
|
|
603
|
+
if (registerMcpGlobal(portable)) {
|
|
553
604
|
console.log(pc.green("\u2713 MCP \u2192 Claude Code (scope user, v\xEDa claude mcp add)"));
|
|
554
605
|
continue;
|
|
555
606
|
}
|
|
@@ -596,7 +647,7 @@ async function ensureReady(vault = getVault()) {
|
|
|
596
647
|
program.command("init").description("Crea/conecta la b\xF3veda e instala TODO: modelo, hooks (Claude Code) y MCP en tus agentes de IA (una sola vez, persiste entre sesiones)").option("--project", "registrar para este proyecto (cwd): .vault.json + .claude/settings.json + .mcp.json").option("--global", "registrar para todas las sesiones del usuario (default)").option(
|
|
597
648
|
"--path <dir>",
|
|
598
649
|
"ruta del vault Obsidian (existente o nuevo). Default: ./Alexandria con --project, ~/Alexandria en global"
|
|
599
|
-
).option("--auto", "configurar el uso autom\xE1tico en CLAUDE.md sin preguntar").option("--manual", "no tocar CLAUDE.md (config\xFAralo t\xFA)").option("--skills", "al final, recomendar e instalar skills seg\xFAn el contenido").option(
|
|
650
|
+
).option("--auto", "configurar el uso autom\xE1tico en CLAUDE.md sin preguntar").option("--manual", "no tocar CLAUDE.md (config\xFAralo t\xFA)").option("--no-protocol", "instalar sin el Protocolo Alexandria (solo b\xF3veda cl\xE1sica)").option("--portable", "MCP con comando npx (commiteable en repos de equipo) en vez de ruta local").option("--skills", "al final, recomendar e instalar skills seg\xFAn el contenido").option(
|
|
600
651
|
"--agents <ids>",
|
|
601
652
|
`agentes de IA donde registrar el MCP: "all", "detected" o csv de ${AGENTS.map((a) => a.id).join(",")} (default: claude + detectados)`
|
|
602
653
|
).action(async (opts) => {
|
|
@@ -622,13 +673,20 @@ program.command("init").description("Crea/conecta la b\xF3veda e instala TODO: m
|
|
|
622
673
|
console.log(pc.dim(" SessionStart (digest) \xB7 UserPromptSubmit (contexto+captura) \xB7 Stop/PreCompact (sesiones)"));
|
|
623
674
|
const scope = isProject ? "project" : "global";
|
|
624
675
|
const chosen = opts.agents ? resolveAgents(opts.agents) : [...AGENTS.filter((a) => a.id === "claude" || a.detect())];
|
|
625
|
-
registerAgentsMcp(chosen, scope, cwd);
|
|
676
|
+
registerAgentsMcp(chosen, scope, cwd, opts.portable);
|
|
677
|
+
if (opts.portable) console.log(pc.dim(" MCP portable (npx) \u2014 apto para commitear en repos de equipo"));
|
|
626
678
|
const skipped = AGENTS.filter((a) => !chosen.includes(a));
|
|
627
679
|
if (skipped.length > 0) {
|
|
628
680
|
console.log(pc.dim(` Otros agentes disponibles: ${skipped.map((a) => a.id).join(", ")} \u2192 ale agents <ids>`));
|
|
629
681
|
}
|
|
630
682
|
if (isProject) {
|
|
631
683
|
const gi = ensureGitignore(cwd, vault.root);
|
|
684
|
+
if (!opts.portable) {
|
|
685
|
+
const untracked = untrackPersonalConfigs(cwd);
|
|
686
|
+
if (untracked.length > 0) {
|
|
687
|
+
console.log(pc.green(`\u2713 Configs personales sacados del \xEDndice de git: ${untracked.join(", ")}`));
|
|
688
|
+
}
|
|
689
|
+
}
|
|
632
690
|
if (gi) console.log(pc.green(`\u2713 B\xF3veda agregada a ${gi}`));
|
|
633
691
|
}
|
|
634
692
|
let auto = opts.auto ? true : opts.manual ? false : void 0;
|
|
@@ -648,6 +706,10 @@ program.command("init").description("Crea/conecta la b\xF3veda e instala TODO: m
|
|
|
648
706
|
} else {
|
|
649
707
|
console.log(pc.dim(" Sin auto-configuraci\xF3n (act\xEDvala luego con: ale init --auto)"));
|
|
650
708
|
}
|
|
709
|
+
setConfigKey("protocol", opts.protocol !== false);
|
|
710
|
+
console.log(
|
|
711
|
+
opts.protocol !== false ? pc.green("\u2713 Protocolo Alexandria activo (plan_create \xB7 task_verify \xB7 lesson_extract) \u2014 ap\xE1galo con: ale config set protocol false") : pc.dim(" Protocolo desactivado (b\xF3veda cl\xE1sica) \u2014 act\xEDvalo con: ale config set protocol true")
|
|
712
|
+
);
|
|
651
713
|
if (isProject) {
|
|
652
714
|
const map = scanProject(vault, cwd);
|
|
653
715
|
if (map) console.log(pc.green(`\u2713 Proyecto escaneado \u2192 ${path4.relative(vault.root, map)} (mapa inicial)`));
|
|
@@ -661,6 +723,72 @@ program.command("init").description("Crea/conecta la b\xF3veda e instala TODO: m
|
|
|
661
723
|
console.log(pc.dim(' Prueba: ale search "algo" \xB7 ale graph \xB7 ale stats \xB7 ale agents\n'));
|
|
662
724
|
if (opts.skills) await runSkills({ yes: false, project: isProject });
|
|
663
725
|
});
|
|
726
|
+
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) => {
|
|
727
|
+
const { vault } = await ensureReady();
|
|
728
|
+
const abs = path4.resolve(file);
|
|
729
|
+
const raw = fs4.readFileSync(abs, "utf8");
|
|
730
|
+
const heading = raw.match(/^#\s+(.+)$/m)?.[1]?.trim();
|
|
731
|
+
const title = opts.title ?? heading ?? path4.basename(abs).replace(/\.(md|txt)$/i, "");
|
|
732
|
+
const dod = [...raw.matchAll(/^[-*]\s*\[[ x]\]\s*(.+)$/gim)].map((m) => m[1].trim());
|
|
733
|
+
const noteFile = createNote(vault.managed, {
|
|
734
|
+
title: title.startsWith("Plan - ") ? title : `Plan - ${title}`,
|
|
735
|
+
type: "plan",
|
|
736
|
+
status: "active",
|
|
737
|
+
tags: ["plan"],
|
|
738
|
+
content: raw.trim()
|
|
739
|
+
});
|
|
740
|
+
await VaultIndex.load(vault).refresh();
|
|
741
|
+
console.log(pc.green(`\u2713 Plan creado: ${path4.relative(vault.root, noteFile)}`));
|
|
742
|
+
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)'}`));
|
|
743
|
+
console.log(pc.dim(" El agente lo ver\xE1 como plan abierto al iniciar sesi\xF3n y lo retomar\xE1 con task_verify."));
|
|
744
|
+
});
|
|
745
|
+
program.command("audit").description("Auditor\xEDa del Protocolo: planes sin DoD, planes abiertos, fallos sin lecci\xF3n, notas sueltas").action(async () => {
|
|
746
|
+
const { vault, idx } = await ensureReady();
|
|
747
|
+
const notes = Object.values(idx.meta.notes).filter((n) => !n.rel.split("/").includes("archive"));
|
|
748
|
+
const plans = notes.filter((n) => n.type === "plan");
|
|
749
|
+
const linked = new Set(idx.meta.links.flatMap((l) => [l.from, l.to]));
|
|
750
|
+
console.log(pc.bold("\n\u{1F3DB}\uFE0F Auditor\xEDa del Protocolo Alexandria\n"));
|
|
751
|
+
const openPlans = plans.filter((p) => p.status === "active");
|
|
752
|
+
console.log(` Planes: ${plans.length} (${pc.yellow(`${openPlans.length} abiertos`)}, ${plans.filter((p) => p.status === "completed").length} completados, ${plans.filter((p) => p.status === "failed").length} fallidos)`);
|
|
753
|
+
for (const p of openPlans.slice(0, 8)) console.log(pc.dim(` \u25CB ${p.title}`));
|
|
754
|
+
const chunksByNote = /* @__PURE__ */ new Map();
|
|
755
|
+
for (const c of idx.meta.chunks) chunksByNote.set(c.note, (chunksByNote.get(c.note) ?? "") + "\n" + c.text);
|
|
756
|
+
const noDod = plans.filter((p) => !/\[[ x]\]/i.test(chunksByNote.get(p.rel) ?? ""));
|
|
757
|
+
if (noDod.length > 0) {
|
|
758
|
+
console.log(pc.yellow(` \u26A0 Planes sin Definition of Done: ${noDod.length}`));
|
|
759
|
+
for (const p of noDod.slice(0, 5)) console.log(pc.dim(` - ${p.title}`));
|
|
760
|
+
}
|
|
761
|
+
const fails = notes.filter((n) => n.type === "verification" && n.status === "failed");
|
|
762
|
+
const lessons = notes.filter((n) => n.type === "lesson");
|
|
763
|
+
console.log(` Verificaciones: ${notes.filter((n) => n.type === "verification").length} (${pc.red(`${fails.length} fallos`)}) \xB7 Lecciones: ${pc.green(String(lessons.length))}`);
|
|
764
|
+
if (fails.length > lessons.length) {
|
|
765
|
+
console.log(pc.yellow(` \u26A0 Hay m\xE1s fallos (${fails.length}) que lecciones (${lessons.length}) \u2014 fallos resueltos sin destilar aprendizaje.`));
|
|
766
|
+
}
|
|
767
|
+
const loose = notes.filter((n) => n.type !== "prompt" && n.type !== "session" && !linked.has(n.rel));
|
|
768
|
+
if (loose.length > 0) {
|
|
769
|
+
console.log(pc.yellow(` \u26A0 Notas sin conexiones (invisibles para vault_related): ${loose.length}`));
|
|
770
|
+
for (const n of loose.slice(0, 5)) console.log(pc.dim(` - ${n.title} \u2192 con\xE9ctala con vault_link o [[wikilinks]]`));
|
|
771
|
+
}
|
|
772
|
+
if (noDod.length === 0 && loose.length === 0 && fails.length <= lessons.length) {
|
|
773
|
+
console.log(pc.green("\n \u2713 B\xF3veda sana: planes con DoD, conocimiento conectado, fallos con lecci\xF3n."));
|
|
774
|
+
}
|
|
775
|
+
console.log();
|
|
776
|
+
});
|
|
777
|
+
program.command("config").description("Configuraci\xF3n de Alexandria (ej. protocol true/false)").argument("<accion>", "get | set").argument("<clave>", "ej. protocol").argument("[valor]", "para set: true/false o texto").action((accion, clave, valor) => {
|
|
778
|
+
const key = clave.replace(/^protocol\.enabled$/, "protocol");
|
|
779
|
+
if (accion === "get") {
|
|
780
|
+
const v = getConfigKey(key);
|
|
781
|
+
console.log(v === void 0 ? pc.dim(`${key} sin definir (default: ${key === "protocol" ? "true" : "\u2014"})`) : `${key} = ${JSON.stringify(v)}`);
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
if (accion === "set") {
|
|
785
|
+
const parsed = valor === "true" ? true : valor === "false" ? false : valor;
|
|
786
|
+
setConfigKey(key, parsed);
|
|
787
|
+
console.log(pc.green(`\u2713 ${key} = ${JSON.stringify(parsed)}`));
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
console.log(pc.yellow("Acci\xF3n inv\xE1lida: usa get o set"));
|
|
791
|
+
});
|
|
664
792
|
program.command("consolidate").description("Archiva prompts viejos sin reuso: salen del grafo y de la inyecci\xF3n, pero NUNCA se pierden \u2014 siguen buscables (contexto infinito)").option("--days <n>", "antig\xFCedad m\xEDnima en d\xEDas", "45").option("--dry", "solo mostrar qu\xE9 se archivar\xEDa").action(async (opts) => {
|
|
665
793
|
const { vault, idx } = await ensureReady();
|
|
666
794
|
const cutoff = Date.now() - (parseInt(opts.days, 10) || 45) * 864e5;
|
|
@@ -712,9 +840,12 @@ program.command("agents").description("Lista los agentes de IA soportados y regi
|
|
|
712
840
|
registerAgentsMcp(chosen, opts.project ? "project" : "global", process.cwd());
|
|
713
841
|
console.log(pc.dim("\n Reinicia el agente (o recarga sus MCP) para que tome el servidor.\n"));
|
|
714
842
|
});
|
|
715
|
-
program.command("add").description("Guardar una nota manualmente").argument("<title>", "t\xEDtulo").option("-c, --content <text>", "contenido markdown (o se lee de stdin)").option("-t, --tags <tags>", "tags separados por coma").action(async (title, opts) => {
|
|
843
|
+
program.command("add").description("Guardar una nota manualmente").argument("<title>", "t\xEDtulo").option("-c, --content <text>", "contenido markdown (o se lee de stdin)").option("-f, --file <path>", "leer el contenido desde un archivo .md/.txt del proyecto").option("-t, --tags <tags>", "tags separados por coma").action(async (title, opts) => {
|
|
716
844
|
const { vault } = await ensureReady();
|
|
717
845
|
let content = opts.content;
|
|
846
|
+
if (!content && opts.file) {
|
|
847
|
+
content = fs4.readFileSync(path4.resolve(opts.file), "utf8");
|
|
848
|
+
}
|
|
718
849
|
if (!content && !process.stdin.isTTY) {
|
|
719
850
|
content = fs4.readFileSync(0, "utf8");
|
|
720
851
|
}
|
|
@@ -789,6 +920,14 @@ program.command("stats").description("Estado de la b\xF3veda y tokens ahorrados"
|
|
|
789
920
|
console.log(` Notas: ${notes.length} ${pc.dim(JSON.stringify(byType))}`);
|
|
790
921
|
console.log(` Chunks indexados: ${idx.meta.chunks.length} \xB7 Conexiones: ${idx.meta.links.length}`);
|
|
791
922
|
console.log(` B\xFAsqueda sem\xE1ntica: ${idx.emb ? pc.green("activa") : pc.yellow("keyword-only (corre ale reindex con internet)")}`);
|
|
923
|
+
console.log(pc.bold("\n\u{1F3DB}\uFE0F Protocolo"));
|
|
924
|
+
const plans = notes.filter((n) => n.type === "plan");
|
|
925
|
+
const verifs = notes.filter((n) => n.type === "verification");
|
|
926
|
+
const lessons = notes.filter((n) => n.type === "lesson");
|
|
927
|
+
const reused = lessons.filter((n) => (n.hits ?? 1) > 1).length;
|
|
928
|
+
const passed = verifs.filter((n) => n.status === "completed").length;
|
|
929
|
+
console.log(` Planes: ${plans.length} (${plans.filter((p) => p.status === "active").length} abiertos) \xB7 Verificaciones: ${verifs.length}${verifs.length ? ` (${Math.round(passed / verifs.length * 100)}% \u2713)` : ""}`);
|
|
930
|
+
console.log(` Lecciones: ${lessons.length} (${reused} reutilizadas \u2014 cada reuso = debug que no se repiti\xF3)`);
|
|
792
931
|
console.log(pc.bold("\n\u{1F4B0} Ahorro estimado"));
|
|
793
932
|
console.log(` Inyecciones de contexto: ${s.injections} (${s.solutionCacheHits} con soluci\xF3n cacheada)`);
|
|
794
933
|
console.log(` Tokens inyectados: ~${s.injectedTokens.toLocaleString()}`);
|
|
@@ -863,11 +1002,31 @@ program.command("doctor").description("Verifica y repara la instalaci\xF3n (mode
|
|
|
863
1002
|
console.log(`${pc.green("\u2713")} \xCDndice al d\xEDa (${res.changed} reindexadas, ${Object.keys(idx.meta.notes).length} notas)
|
|
864
1003
|
`);
|
|
865
1004
|
});
|
|
866
|
-
program.command("uninstall").description("
|
|
867
|
-
const
|
|
1005
|
+
program.command("uninstall").description("Reversi\xF3n limpia: quita hooks, bloque de CLAUDE.md y MCP del proyecto (no borra la b\xF3veda ni las notas)").option("--project", "quitar del proyecto (cwd)").action((opts) => {
|
|
1006
|
+
const cwd = process.cwd();
|
|
1007
|
+
const scope = opts.project ? "project" : "global";
|
|
1008
|
+
const settings = opts.project ? projectSettingsPath(cwd) : globalSettingsPath();
|
|
868
1009
|
unregisterHooks(settings);
|
|
869
1010
|
console.log(pc.green(`\u2713 Hooks de alexandria eliminados de ${settings}`));
|
|
870
|
-
|
|
1011
|
+
const claudeMd = removeClaudeMd(scope, cwd);
|
|
1012
|
+
if (claudeMd) console.log(pc.green(`\u2713 Bloque de Alexandria removido de ${claudeMd}`));
|
|
1013
|
+
if (opts.project) {
|
|
1014
|
+
const mcpFile = path4.join(cwd, ".mcp.json");
|
|
1015
|
+
try {
|
|
1016
|
+
const cfg = JSON.parse(fs4.readFileSync(mcpFile, "utf8"));
|
|
1017
|
+
if (cfg.mcpServers?.alexandria) {
|
|
1018
|
+
delete cfg.mcpServers.alexandria;
|
|
1019
|
+
if (Object.keys(cfg.mcpServers).length === 0) delete cfg.mcpServers;
|
|
1020
|
+
if (Object.keys(cfg).length === 0) fs4.rmSync(mcpFile, { force: true });
|
|
1021
|
+
else fs4.writeFileSync(mcpFile, JSON.stringify(cfg, null, 2) + "\n");
|
|
1022
|
+
console.log(pc.green("\u2713 MCP removido de .mcp.json"));
|
|
1023
|
+
}
|
|
1024
|
+
} catch {
|
|
1025
|
+
}
|
|
1026
|
+
console.log(pc.dim(' Otros agentes (Cursor/OpenCode/\u2026): quita "alexandria" de su config si lo registraste.'));
|
|
1027
|
+
} else {
|
|
1028
|
+
console.log(pc.dim(" MCP global: qu\xEDtalo con `claude mcp remove alexandria`. Tus notas quedan intactas."));
|
|
1029
|
+
}
|
|
871
1030
|
});
|
|
872
1031
|
program.command("serve-mcp").description("Correr el servidor MCP por stdio (lo usa Claude Code internamente)").action(async () => {
|
|
873
1032
|
await import("./mcp/server.js");
|
package/dist/hooks/on-prompt.js
CHANGED
|
@@ -9,16 +9,16 @@ import {
|
|
|
9
9
|
} from "../chunk-DEDAOKAV.js";
|
|
10
10
|
import {
|
|
11
11
|
hybridSearch
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-3ETM6PKR.js";
|
|
13
13
|
import {
|
|
14
14
|
resolveVault,
|
|
15
15
|
vaultExists
|
|
16
|
-
} from "../chunk-
|
|
17
|
-
import "../chunk-
|
|
16
|
+
} from "../chunk-DYCARGQR.js";
|
|
17
|
+
import "../chunk-7G3NPKDO.js";
|
|
18
18
|
import {
|
|
19
19
|
createNote,
|
|
20
20
|
touchNote
|
|
21
|
-
} from "../chunk-
|
|
21
|
+
} from "../chunk-XWR74BQ2.js";
|
|
22
22
|
import "../chunk-EDYBSJSS.js";
|
|
23
23
|
|
|
24
24
|
// src/hooks/on-prompt.ts
|
|
@@ -53,7 +53,7 @@ runHook(25e3, async (input) => {
|
|
|
53
53
|
const lines = [];
|
|
54
54
|
if (cached) {
|
|
55
55
|
lines.push(
|
|
56
|
-
`\u26A1 Ya resolviste algo casi id\xE9ntico antes (\xAB${cached.note.title}\xBB).
|
|
56
|
+
`\u26A1 Ya resolviste algo casi id\xE9ntico antes (\xAB${cached.note.title}\xBB). Parte de esa soluci\xF3n en vez de re-derivarla \u2014 valida que siga aplicando si el c\xF3digo cambi\xF3:
|
|
57
57
|
${truncate(cached.excerpts.join("\n"), 2e3)}`
|
|
58
58
|
);
|
|
59
59
|
}
|
|
@@ -8,13 +8,14 @@ import {
|
|
|
8
8
|
truncate
|
|
9
9
|
} from "../chunk-DEDAOKAV.js";
|
|
10
10
|
import {
|
|
11
|
+
protocolEnabled,
|
|
11
12
|
resolveVault,
|
|
12
13
|
vaultExists
|
|
13
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-DYCARGQR.js";
|
|
14
15
|
import {
|
|
15
16
|
VaultIndex
|
|
16
|
-
} from "../chunk-
|
|
17
|
-
import "../chunk-
|
|
17
|
+
} from "../chunk-7G3NPKDO.js";
|
|
18
|
+
import "../chunk-XWR74BQ2.js";
|
|
18
19
|
import "../chunk-EDYBSJSS.js";
|
|
19
20
|
|
|
20
21
|
// src/hooks/on-session-start.ts
|
|
@@ -31,6 +32,14 @@ runHook(15e3, async (input) => {
|
|
|
31
32
|
if (notes.length === 0) return;
|
|
32
33
|
const proj = projectName(input.cwd);
|
|
33
34
|
const parts = [];
|
|
35
|
+
if (protocolEnabled()) {
|
|
36
|
+
const openPlans = notes.filter((n) => n.type === "plan" && n.status === "active");
|
|
37
|
+
parts.push(
|
|
38
|
+
`## Protocolo Alexandria (activo)
|
|
39
|
+
El protocolo es PALANCA, no l\xEDmite: \xFAsalo para rendir m\xE1s con menos tokens, nunca como burocracia. Tareas simples \u2192 responde directo, sin ceremonia. Tareas no triviales \u2192 ciclo con las tools MCP: 1) plan_create (objetivo + Definition of Done) \u2192 2) ejecuta con toda tu capacidad \u2192 3) task_verify con evidencia real (tests/build \u2014 la evidencia elimina errores, no te frena) \u2192 si algo falla, vault_search por lecciones ANTES de re-debuggear (conocimiento previo = tokens gratis) \u2192 4) lesson_extract si resolviste algo no obvio. Reutiliza lo cacheado con criterio: valida que siga aplicando si el c\xF3digo cambi\xF3.` + (openPlans.length > 0 ? `
|
|
40
|
+
**Planes abiertos:** ${openPlans.map((p) => p.title).join(" \xB7 ")} \u2014 ret\xF3malos, no dupliques.` : "")
|
|
41
|
+
);
|
|
42
|
+
}
|
|
34
43
|
const map = notes.find(
|
|
35
44
|
(n) => (n.type === "map" || n.title.toLowerCase().startsWith("mapa - ")) && n.title.toLowerCase().includes(proj.toLowerCase())
|
|
36
45
|
);
|
package/dist/hooks/on-stop.js
CHANGED
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
ensureVaultStructure,
|
|
9
9
|
resolveVault,
|
|
10
10
|
vaultExists
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-DYCARGQR.js";
|
|
12
12
|
import {
|
|
13
13
|
appendToNote
|
|
14
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-XWR74BQ2.js";
|
|
15
15
|
|
|
16
16
|
// src/hooks/on-stop.ts
|
|
17
17
|
import fs from "fs";
|