@ureck/alexandria 1.3.3 → 1.5.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 +77 -32
- package/dist/chunk-B7HCWKPJ.js +260 -0
- package/dist/{chunk-QB37UGO6.js → chunk-BV2KJV5W.js} +21 -7
- package/dist/{chunk-7LWLBJAD.js → chunk-CEHNXDUE.js} +87 -1
- package/dist/{chunk-FBGIFNIO.js → chunk-GP5A2GWI.js} +1 -1
- package/dist/{chunk-XITAQVOZ.js → chunk-POA77JSS.js} +26 -4
- package/dist/chunk-SAKIVZMP.js +495 -0
- package/dist/chunk-UU4MGB2C.js +262 -0
- package/dist/{chunk-UWB6RKVN.js → chunk-Y6S6SKH4.js} +1 -1
- package/dist/{chunk-53SIGH5A.js → chunk-ZDS6VULX.js} +20 -2
- package/dist/cli.js +558 -159
- package/dist/hooks/on-prompt.js +13 -11
- package/dist/hooks/on-read.js +70 -0
- package/dist/hooks/on-session-start.js +15 -11
- package/dist/hooks/on-stop.js +35 -27
- package/dist/mcp/server.js +111 -49
- package/dist/{viewer-JQCSWJ3C.js → viewer-WQQSQETT.js} +2 -2
- package/package.json +31 -12
- package/dist/chunk-5A6CC74D.js +0 -188
package/dist/hooks/on-prompt.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
} from "../chunk-XITAQVOZ.js";
|
|
5
|
-
import {
|
|
3
|
+
emitContext,
|
|
6
4
|
projectName,
|
|
7
5
|
runHook,
|
|
8
6
|
truncate
|
|
9
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-ZDS6VULX.js";
|
|
10
8
|
import {
|
|
11
9
|
hybridSearch
|
|
12
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-Y6S6SKH4.js";
|
|
11
|
+
import {
|
|
12
|
+
logInjection
|
|
13
|
+
} from "../chunk-POA77JSS.js";
|
|
13
14
|
import {
|
|
15
|
+
isHarnessInjected,
|
|
14
16
|
resolveVault,
|
|
15
17
|
toggleEnabled,
|
|
16
18
|
vaultExists
|
|
17
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-CEHNXDUE.js";
|
|
18
20
|
import {
|
|
19
21
|
createNote,
|
|
20
22
|
touchNote
|
|
21
|
-
} from "../chunk-
|
|
23
|
+
} from "../chunk-BV2KJV5W.js";
|
|
22
24
|
import "../chunk-EDYBSJSS.js";
|
|
23
25
|
|
|
24
26
|
// src/hooks/on-prompt.ts
|
|
@@ -33,7 +35,7 @@ var RELEVANT_MARGIN = 0.04;
|
|
|
33
35
|
var KEYWORD_REL_FACTOR = 0.6;
|
|
34
36
|
runHook(5e3, async (input) => {
|
|
35
37
|
const prompt = (input.prompt ?? "").trim();
|
|
36
|
-
if (prompt.length < MIN_PROMPT_CHARS || prompt.startsWith("/")) return;
|
|
38
|
+
if (prompt.length < MIN_PROMPT_CHARS || prompt.startsWith("/") || isHarnessInjected(prompt)) return;
|
|
37
39
|
const vault = resolveVault({ cwd: input.cwd });
|
|
38
40
|
if (!vaultExists(vault)) return;
|
|
39
41
|
const rawResults = await hybridSearch(vault, prompt, 5, { expand: true, refresh: false });
|
|
@@ -81,8 +83,8 @@ Contexto recuperado de la b\xF3veda local (usa esto antes de releer archivos o r
|
|
|
81
83
|
|
|
82
84
|
` + truncate(lines.join("\n\n"), MAX_INJECT_CHARS) + `
|
|
83
85
|
</alexandria-contexto>`;
|
|
84
|
-
|
|
85
|
-
logInjection(vault, {
|
|
86
|
+
const written = emitContext("prompt", injected);
|
|
87
|
+
if (written > 0) logInjection(vault, {
|
|
86
88
|
kind: cached ? "solution-cache" : "inject",
|
|
87
89
|
injectedChars: injected.length,
|
|
88
90
|
promptChars: prompt.length
|
|
@@ -119,4 +121,4 @@ Contexto recuperado de la b\xF3veda local (usa esto antes de releer archivos o r
|
|
|
119
121
|
|
|
120
122
|
${truncate(prompt, 4e3)}`
|
|
121
123
|
});
|
|
122
|
-
});
|
|
124
|
+
}, "prompt");
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
runHook
|
|
4
|
+
} from "../chunk-ZDS6VULX.js";
|
|
5
|
+
import {
|
|
6
|
+
PDF_TOKENS_PER_PAGE,
|
|
7
|
+
formatOf
|
|
8
|
+
} from "../chunk-UU4MGB2C.js";
|
|
9
|
+
import {
|
|
10
|
+
resolveVault,
|
|
11
|
+
toggleEnabled,
|
|
12
|
+
vaultExists
|
|
13
|
+
} from "../chunk-CEHNXDUE.js";
|
|
14
|
+
|
|
15
|
+
// src/hooks/on-read.ts
|
|
16
|
+
import fs from "fs";
|
|
17
|
+
import path from "path";
|
|
18
|
+
var MIN_BYTES = 20 * 1024;
|
|
19
|
+
var INTERCEPT = /* @__PURE__ */ new Set(["pdf", "docx", "xlsx", "csv"]);
|
|
20
|
+
var MAX_SESSIONS = 20;
|
|
21
|
+
function shouldIntercept(cacheDir, sessionId, file) {
|
|
22
|
+
const store = path.join(cacheDir, "read-intercepts.json");
|
|
23
|
+
let data = {};
|
|
24
|
+
try {
|
|
25
|
+
data = JSON.parse(fs.readFileSync(store, "utf8"));
|
|
26
|
+
} catch {
|
|
27
|
+
}
|
|
28
|
+
const seen = data[sessionId] ?? [];
|
|
29
|
+
if (seen.includes(file)) return false;
|
|
30
|
+
data[sessionId] = [...seen, file];
|
|
31
|
+
const keys = Object.keys(data);
|
|
32
|
+
for (const k of keys.slice(0, Math.max(0, keys.length - MAX_SESSIONS))) delete data[k];
|
|
33
|
+
try {
|
|
34
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
35
|
+
fs.writeFileSync(store, JSON.stringify(data));
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
runHook(2e3, async (input) => {
|
|
42
|
+
if (!toggleEnabled("docs.interceptRead")) return;
|
|
43
|
+
const file = input.filePath;
|
|
44
|
+
if (!file || input.toolName && input.toolName !== "Read") return;
|
|
45
|
+
const format = formatOf(file);
|
|
46
|
+
if (!format || !INTERCEPT.has(format)) return;
|
|
47
|
+
let size = 0;
|
|
48
|
+
try {
|
|
49
|
+
size = fs.statSync(file).size;
|
|
50
|
+
} catch {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (size < MIN_BYTES) return;
|
|
54
|
+
const vault = resolveVault({ cwd: input.cwd });
|
|
55
|
+
if (!vaultExists(vault)) return;
|
|
56
|
+
if (!shouldIntercept(vault.cache, input.session_id ?? "sin-sesion", path.resolve(file))) return;
|
|
57
|
+
const cost = format === "pdf" ? `un PDF le\xEDdo directo cuesta ~${PDF_TOKENS_PER_PAGE.toLocaleString("en")} tokens POR P\xC1GINA (imagen + texto)` : `leer el ${format.toUpperCase()} completo cuesta ~${Math.ceil(size / 4).toLocaleString("en")} tokens`;
|
|
58
|
+
process.stdout.write(
|
|
59
|
+
JSON.stringify({
|
|
60
|
+
hookSpecificOutput: {
|
|
61
|
+
hookEventName: "PreToolUse",
|
|
62
|
+
permissionDecision: "deny",
|
|
63
|
+
permissionDecisionReason: `Alexandria: ${cost}. Usa la tool MCP doc_ingest con path "${file}" (devuelve el \xEDndice de secciones, ~200 tokens) y luego doc_read con las secciones o una pregunta. Si de verdad necesitas ver im\xE1genes o gr\xE1ficas del archivo, vuelve a llamar Read: el segundo intento pasa.`
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
export {
|
|
69
|
+
shouldIntercept
|
|
70
|
+
};
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
} from "../chunk-XITAQVOZ.js";
|
|
5
|
-
import {
|
|
3
|
+
emitContext,
|
|
6
4
|
projectName,
|
|
7
5
|
runHook,
|
|
8
6
|
truncate
|
|
9
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-ZDS6VULX.js";
|
|
8
|
+
import {
|
|
9
|
+
logInjection
|
|
10
|
+
} from "../chunk-POA77JSS.js";
|
|
10
11
|
import {
|
|
11
12
|
protocolEnabled,
|
|
12
13
|
resolveVault,
|
|
13
14
|
toggleEnabled,
|
|
14
15
|
vaultExists
|
|
15
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-CEHNXDUE.js";
|
|
16
17
|
import {
|
|
17
18
|
VaultIndex
|
|
18
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-BV2KJV5W.js";
|
|
19
20
|
import "../chunk-EDYBSJSS.js";
|
|
20
21
|
|
|
21
22
|
// src/hooks/on-session-start.ts
|
|
@@ -33,7 +34,11 @@ runHook(15e3, async (input) => {
|
|
|
33
34
|
const proj = projectName(input.cwd);
|
|
34
35
|
const parts = [];
|
|
35
36
|
if (protocolEnabled()) {
|
|
36
|
-
const
|
|
37
|
+
const recent = Date.now() - 30 * 864e5;
|
|
38
|
+
const seen = /* @__PURE__ */ new Set();
|
|
39
|
+
const openPlans = idx.notesByTag("plan").filter((n) => n.status === "active" && !n.rel.split("/").includes("archive")).filter(
|
|
40
|
+
(n) => n.tags.some((t) => t.toLowerCase() === proj.toLowerCase()) || n.tags.every((t) => t === "plan") && Date.parse(n.created ?? "") > recent
|
|
41
|
+
).filter((n) => !seen.has(n.title) && Boolean(seen.add(n.title))).slice(0, 8);
|
|
37
42
|
parts.push(
|
|
38
43
|
`## Protocolo Alexandria (activo)
|
|
39
44
|
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 ? `
|
|
@@ -52,7 +57,7 @@ ${truncate(body.trim(), 4e3)}`);
|
|
|
52
57
|
} catch {
|
|
53
58
|
}
|
|
54
59
|
}
|
|
55
|
-
const sessions = idx.notesByTag("session").sort((a, b) => (b.created ?? "").localeCompare(a.created ?? "")).slice(0, 3);
|
|
60
|
+
const sessions = idx.notesByTag("session").filter((s) => s.tags.some((t) => t.toLowerCase() === proj.toLowerCase())).sort((a, b) => (b.created ?? "").localeCompare(a.created ?? "")).slice(0, 3);
|
|
56
61
|
if (sessions.length > 0) {
|
|
57
62
|
const lines = sessions.map((s) => `- ${s.title} (${(s.created ?? "").slice(0, 10)})`);
|
|
58
63
|
parts.push(`## Sesiones recientes en la b\xF3veda
|
|
@@ -75,6 +80,5 @@ B\xF3veda de conocimiento local activa (${notes.length} notas). ANTES de explora
|
|
|
75
80
|
|
|
76
81
|
` + truncate(parts.join("\n\n"), MAX_CHARS) + `
|
|
77
82
|
</alexandria-digest>`;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
83
|
+
if (emitContext("session", digest) > 0) logInjection(vault, { kind: "session-start", injectedChars: digest.length });
|
|
84
|
+
}, "session");
|
package/dist/hooks/on-stop.js
CHANGED
|
@@ -3,17 +3,23 @@ import {
|
|
|
3
3
|
projectName,
|
|
4
4
|
runHook,
|
|
5
5
|
truncate
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-ZDS6VULX.js";
|
|
7
|
+
import {
|
|
8
|
+
autoCleanDue,
|
|
9
|
+
markCleaned
|
|
10
|
+
} from "../chunk-B7HCWKPJ.js";
|
|
11
|
+
import "../chunk-POA77JSS.js";
|
|
7
12
|
import {
|
|
8
13
|
ensureVaultStructure,
|
|
14
|
+
lastExchange,
|
|
9
15
|
resolveVault,
|
|
10
16
|
toggleEnabled,
|
|
11
17
|
vaultExists
|
|
12
|
-
} from "../chunk-
|
|
18
|
+
} from "../chunk-CEHNXDUE.js";
|
|
13
19
|
import {
|
|
14
20
|
VaultIndex,
|
|
15
21
|
appendToNote
|
|
16
|
-
} from "../chunk-
|
|
22
|
+
} from "../chunk-BV2KJV5W.js";
|
|
17
23
|
import "../chunk-EDYBSJSS.js";
|
|
18
24
|
|
|
19
25
|
// src/hooks/on-stop.ts
|
|
@@ -21,39 +27,24 @@ import fs from "fs";
|
|
|
21
27
|
import path from "path";
|
|
22
28
|
import { spawn } from "child_process";
|
|
23
29
|
import { fileURLToPath } from "url";
|
|
24
|
-
function textOf(msg) {
|
|
25
|
-
const c = msg.message?.content;
|
|
26
|
-
if (typeof c === "string") return c;
|
|
27
|
-
if (Array.isArray(c)) {
|
|
28
|
-
return c.filter((p) => p.type === "text" && typeof p.text === "string").map((p) => p.text).join("\n");
|
|
29
|
-
}
|
|
30
|
-
return "";
|
|
31
|
-
}
|
|
32
30
|
runHook(25e3, async (input) => {
|
|
33
|
-
if (!input.transcript_path || !fs.existsSync(input.transcript_path)) return;
|
|
34
31
|
const vault = resolveVault({ cwd: input.cwd });
|
|
35
32
|
if (!vaultExists(vault)) return;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const msg = JSON.parse(line);
|
|
44
|
-
const text = textOf(msg).trim();
|
|
45
|
-
if (!text) continue;
|
|
46
|
-
if (msg.type === "user" && !text.startsWith("<")) lastUser = text;
|
|
47
|
-
if (msg.type === "assistant") lastAssistant = text;
|
|
48
|
-
} catch {
|
|
49
|
-
}
|
|
33
|
+
let lastUser = input.prompt?.trim() ?? "";
|
|
34
|
+
let lastAssistant = input.answer?.trim() ?? "";
|
|
35
|
+
if (!lastAssistant && input.transcript_path && fs.existsSync(input.transcript_path)) {
|
|
36
|
+
const lines = fs.readFileSync(input.transcript_path, "utf8").split("\n").filter(Boolean);
|
|
37
|
+
const ex = lastExchange(lines.slice(-200));
|
|
38
|
+
lastAssistant = ex.assistant;
|
|
39
|
+
lastUser ||= ex.user;
|
|
50
40
|
}
|
|
51
41
|
if (!lastAssistant) return;
|
|
42
|
+
ensureVaultStructure(vault);
|
|
52
43
|
const proj = projectName(input.cwd);
|
|
53
44
|
const date = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
54
45
|
const sid = (input.session_id ?? "sesion").slice(0, 8);
|
|
55
46
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().slice(11, 16);
|
|
56
|
-
const isCompact = input.
|
|
47
|
+
const isCompact = input.compact;
|
|
57
48
|
appendToNote(vault.managed, {
|
|
58
49
|
fixedName: `${date}-${proj}-${sid}`,
|
|
59
50
|
title: `Sesi\xF3n ${date} \u2014 ${proj}`,
|
|
@@ -69,7 +60,24 @@ runHook(25e3, async (input) => {
|
|
|
69
60
|
Proyecto: [[Mapa - ${proj}]]`
|
|
70
61
|
});
|
|
71
62
|
await maybeRebuildInBackground(vault);
|
|
63
|
+
maybeCleanInBackground(vault);
|
|
72
64
|
});
|
|
65
|
+
function maybeCleanInBackground(vault) {
|
|
66
|
+
try {
|
|
67
|
+
if (!toggleEnabled("clean.auto") || !autoCleanDue(vault)) return;
|
|
68
|
+
markCleaned(vault);
|
|
69
|
+
const cli = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "cli.js");
|
|
70
|
+
if (!fs.existsSync(cli)) return;
|
|
71
|
+
const child = spawn(process.execPath, [cli, "--vault", vault.root, "clean", "--yes", "--quiet"], {
|
|
72
|
+
detached: true,
|
|
73
|
+
stdio: "ignore",
|
|
74
|
+
windowsHide: true,
|
|
75
|
+
env: { ...process.env, ALEXANDRIA_HOOK: "" }
|
|
76
|
+
});
|
|
77
|
+
child.unref();
|
|
78
|
+
} catch {
|
|
79
|
+
}
|
|
80
|
+
}
|
|
73
81
|
async function maybeRebuildInBackground(vault) {
|
|
74
82
|
try {
|
|
75
83
|
if (!toggleEnabled("index.autoRebuild")) return;
|
package/dist/mcp/server.js
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
architectBlock,
|
|
4
|
+
ingestAndOutline,
|
|
4
5
|
pkgVersion,
|
|
5
6
|
planContext,
|
|
6
|
-
planQualityHints
|
|
7
|
-
|
|
7
|
+
planQualityHints,
|
|
8
|
+
readDoc
|
|
9
|
+
} from "../chunk-SAKIVZMP.js";
|
|
8
10
|
import {
|
|
9
11
|
hybridSearch
|
|
10
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-Y6S6SKH4.js";
|
|
13
|
+
import {
|
|
14
|
+
searchArchive
|
|
15
|
+
} from "../chunk-B7HCWKPJ.js";
|
|
16
|
+
import "../chunk-POA77JSS.js";
|
|
17
|
+
import "../chunk-UU4MGB2C.js";
|
|
11
18
|
import {
|
|
12
19
|
ensureVaultStructure,
|
|
13
20
|
resolveVault,
|
|
14
21
|
toggleEnabled
|
|
15
|
-
} from "../chunk-
|
|
22
|
+
} from "../chunk-CEHNXDUE.js";
|
|
16
23
|
import {
|
|
17
24
|
VaultIndex,
|
|
18
25
|
createNote,
|
|
19
26
|
setNoteStatus,
|
|
20
27
|
slugify,
|
|
21
28
|
upsertNote
|
|
22
|
-
} from "../chunk-
|
|
29
|
+
} from "../chunk-BV2KJV5W.js";
|
|
23
30
|
import "../chunk-EDYBSJSS.js";
|
|
24
31
|
|
|
25
32
|
// src/mcp/server.ts
|
|
@@ -54,21 +61,33 @@ var server = new McpServer({ name: "alexandria", version: pkgVersion() });
|
|
|
54
61
|
var text = (t) => ({ content: [{ type: "text", text: t }] });
|
|
55
62
|
var tail = (s, n) => s.length > n ? "\u2026\n" + s.slice(-n) : s;
|
|
56
63
|
function findMap(idx) {
|
|
57
|
-
|
|
64
|
+
const maps = Object.values(idx.meta.notes).filter((n) => n.type === "map" || n.title.startsWith("Mapa - "));
|
|
65
|
+
const own = `Mapa - ${path.basename(process.cwd())}`.toLowerCase();
|
|
66
|
+
return maps.find((n) => n.title.toLowerCase() === own) ?? maps[0];
|
|
58
67
|
}
|
|
59
68
|
function findByTitle(idx, t) {
|
|
60
69
|
const lower = t.toLowerCase();
|
|
70
|
+
const alt = lower.startsWith("plan - ") ? lower : `plan - ${lower}`;
|
|
61
71
|
return Object.values(idx.meta.notes).find(
|
|
62
|
-
(n) => n.title.toLowerCase()
|
|
72
|
+
(n) => [lower, alt].includes(n.title.toLowerCase()) || n.rel.toLowerCase() === lower
|
|
63
73
|
);
|
|
64
74
|
}
|
|
65
|
-
server.
|
|
75
|
+
server.registerTool(
|
|
66
76
|
"vault_search",
|
|
67
|
-
|
|
68
|
-
|
|
77
|
+
{
|
|
78
|
+
description: "Busca conocimiento en la b\xF3veda local (b\xFAsqueda sem\xE1ntica + keyword). \xDAsala ANTES de explorar c\xF3digo o re-derivar contexto: si la b\xF3veda ya lo sabe, ahorras tokens.",
|
|
79
|
+
inputSchema: { query: z.string().describe("Qu\xE9 buscar, en lenguaje natural"), k: z.number().int().min(1).max(15).optional() }
|
|
80
|
+
},
|
|
69
81
|
async ({ query, k }) => {
|
|
70
82
|
const results = await hybridSearch(vault, query, k ?? 5, { expand: true });
|
|
71
|
-
if (results.length === 0)
|
|
83
|
+
if (results.length === 0) {
|
|
84
|
+
const arch = searchArchive(vault, query, 3);
|
|
85
|
+
if (arch.length === 0) return text("Sin resultados en la b\xF3veda.");
|
|
86
|
+
return text(
|
|
87
|
+
"Sin resultados en el \xEDndice; en el archivo de prompts compactados:\n\n" + arch.map((h, i) => `${i + 1}. \xAB${h.heading}\xBB (${h.file})
|
|
88
|
+
${h.excerpt.replace(/\n/g, " ").slice(0, 400)}`).join("\n\n")
|
|
89
|
+
);
|
|
90
|
+
}
|
|
72
91
|
const out = results.map(
|
|
73
92
|
(r, i) => `${i + 1}. \xAB${r.note.title}\xBB (${r.note.rel}, tipo: ${r.note.type})
|
|
74
93
|
${r.excerpts.map((e) => " " + e.replace(/\n/g, "\n ").slice(0, 900)).join("\n")}`
|
|
@@ -76,21 +95,20 @@ ${r.excerpts.map((e) => " " + e.replace(/\n/g, "\n ").slice(0, 900)).join("\
|
|
|
76
95
|
return text(out);
|
|
77
96
|
}
|
|
78
97
|
);
|
|
79
|
-
server.
|
|
98
|
+
server.registerTool(
|
|
80
99
|
"vault_save",
|
|
81
|
-
'Guarda conocimiento destilado en la b\xF3veda (decisiones, arquitectura, soluciones). Si title empieza con "Mapa - " actualiza/crea el mapa del proyecto (se inyecta al inicio de cada sesi\xF3n).',
|
|
82
100
|
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
101
|
+
description: 'Guarda conocimiento destilado en la b\xF3veda (decisiones, arquitectura, soluciones). Si title empieza con "Mapa - " actualiza/crea el mapa del proyecto (se inyecta al inicio de cada sesi\xF3n).',
|
|
102
|
+
inputSchema: {
|
|
103
|
+
title: z.string(),
|
|
104
|
+
content: z.string().describe("Markdown; puede incluir [[wikilinks]] a otras notas"),
|
|
105
|
+
tags: z.array(z.string()).optional()
|
|
106
|
+
}
|
|
86
107
|
},
|
|
87
108
|
async ({ title, content, tags }) => {
|
|
88
109
|
ensureVaultStructure(vault);
|
|
89
110
|
if (!title.startsWith("Mapa - ") && !/\[\[/.test(content)) {
|
|
90
|
-
const
|
|
91
|
-
const map = Object.values(idxPre.meta.notes).find(
|
|
92
|
-
(n) => n.type === "map" || n.title.startsWith("Mapa - ")
|
|
93
|
-
);
|
|
111
|
+
const map = findMap(VaultIndex.load(vault));
|
|
94
112
|
if (map) content = `${content.trim()}
|
|
95
113
|
|
|
96
114
|
Proyecto: [[${map.title}]]`;
|
|
@@ -113,10 +131,12 @@ Proyecto: [[${map.title}]]`;
|
|
|
113
131
|
return text(`Guardado en ${path.relative(vault.root, file)}`);
|
|
114
132
|
}
|
|
115
133
|
);
|
|
116
|
-
server.
|
|
134
|
+
server.registerTool(
|
|
117
135
|
"vault_related",
|
|
118
|
-
|
|
119
|
-
|
|
136
|
+
{
|
|
137
|
+
description: "Vecinos de una nota en el grafo de conocimiento (wikilinks + conexiones sem\xE1nticas) \u2014 trae conocimiento conectado sin releer archivos.",
|
|
138
|
+
inputSchema: { title: z.string().describe("T\xEDtulo o ruta relativa de la nota") }
|
|
139
|
+
},
|
|
120
140
|
async ({ title }) => {
|
|
121
141
|
const idx = VaultIndex.load(vault);
|
|
122
142
|
const lower = title.toLowerCase();
|
|
@@ -131,10 +151,12 @@ server.tool(
|
|
|
131
151
|
);
|
|
132
152
|
}
|
|
133
153
|
);
|
|
134
|
-
server.
|
|
154
|
+
server.registerTool(
|
|
135
155
|
"vault_link",
|
|
136
|
-
|
|
137
|
-
|
|
156
|
+
{
|
|
157
|
+
description: "Crea una conexi\xF3n expl\xEDcita [[wikilink]] entre dos notas de la b\xF3veda.",
|
|
158
|
+
inputSchema: { from: z.string(), to: z.string() }
|
|
159
|
+
},
|
|
138
160
|
async ({ from, to }) => {
|
|
139
161
|
const idx = VaultIndex.load(vault);
|
|
140
162
|
const find = (t) => Object.values(idx.meta.notes).find(
|
|
@@ -152,15 +174,49 @@ server.tool(
|
|
|
152
174
|
return text(`Conectado: \xAB${a.title}\xBB \u2192 [[${b.title}]]`);
|
|
153
175
|
}
|
|
154
176
|
);
|
|
155
|
-
server.
|
|
177
|
+
server.registerTool(
|
|
178
|
+
"doc_ingest",
|
|
179
|
+
{
|
|
180
|
+
description: "\xDAsala EN VEZ de leer directamente un PDF, DOCX, XLSX, CSV o HTML (leer un PDF cuesta ~2,000 tokens por p\xE1gina). La convierte localmente a markdown por secciones, la indexa y devuelve SOLO el \xEDndice de secciones (~200 tokens). Si el archivo no cambi\xF3, reutiliza la conversi\xF3n. Despu\xE9s pide lo que necesites con doc_read.",
|
|
181
|
+
inputSchema: {
|
|
182
|
+
path: z.string().describe("Ruta del archivo (absoluta o relativa al proyecto)"),
|
|
183
|
+
force: z.boolean().optional().describe("Reconvertir aunque no haya cambiado")
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
async ({ path: p, force }) => {
|
|
187
|
+
try {
|
|
188
|
+
const abs = path.isAbsolute(p) ? p : path.resolve(process.cwd(), p);
|
|
189
|
+
const res = await ingestAndOutline(vault, abs, { force });
|
|
190
|
+
return text(res.text);
|
|
191
|
+
} catch (e) {
|
|
192
|
+
return text(`No pude ingerir \xAB${p}\xBB: ${e.message}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
server.registerTool(
|
|
197
|
+
"doc_read",
|
|
198
|
+
{
|
|
199
|
+
description: "Lee un documento ya ingerido SIN cargarlo completo: por ids de secci\xF3n (del \xEDndice de doc_ingest) o por pregunta (devuelve las secciones m\xE1s relevantes). Nunca pasa de max_tokens y dice qu\xE9 secciones quedaron fuera para que pidas m\xE1s solo si hace falta.",
|
|
200
|
+
inputSchema: {
|
|
201
|
+
doc: z.string().describe("Ruta del archivo original, t\xEDtulo o parte del nombre"),
|
|
202
|
+
sections: z.array(z.string()).optional().describe('Ids de secci\xF3n, ej. ["s2","s5"]'),
|
|
203
|
+
query: z.string().optional().describe("Pregunta: devuelve las secciones que la responden"),
|
|
204
|
+
max_tokens: z.number().int().min(200).max(2e4).optional().describe("Presupuesto de tokens (default 1500)")
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
async ({ doc, sections, query, max_tokens }) => text(await readDoc(vault, doc, { sections, query, maxTokens: max_tokens }))
|
|
208
|
+
);
|
|
209
|
+
server.registerTool(
|
|
156
210
|
"plan_create",
|
|
157
|
-
"PROTOCOLO paso 1 (solo tareas NO triviales \u2014 las simples resp\xF3ndelas directo, sin ceremonia): crea el plan como un ARQUITECTO. Si el objetivo es vago, haz 2-3 preguntas de aclaraci\xF3n al usuario ANTES de crear el plan (qu\xE9 es \xE9xito, restricciones, alcance). DoD = criterios verificables por comando; tareas chicas y en orden de construcci\xF3n. Para planes grandes pasa `design` (stack/decisiones de arquitectura). La respuesta trae planes similares previos y lecciones \u2014 \xFAsalos para planear mejor. Verifica cada tarea con task_verify.",
|
|
158
211
|
{
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
212
|
+
description: "PROTOCOLO paso 1 (solo tareas NO triviales \u2014 las simples resp\xF3ndelas directo, sin ceremonia): crea el plan como un ARQUITECTO. Si el objetivo es vago, haz 2-3 preguntas de aclaraci\xF3n al usuario ANTES de crear el plan (qu\xE9 es \xE9xito, restricciones, alcance). DoD = criterios verificables por comando; tareas chicas y en orden de construcci\xF3n. Para planes grandes pasa `design` (stack/decisiones de arquitectura). La respuesta trae planes similares previos y lecciones \u2014 \xFAsalos para planear mejor. Verifica cada tarea con task_verify.",
|
|
213
|
+
inputSchema: {
|
|
214
|
+
title: z.string().describe('Nombre corto del objetivo, ej. "Login con Google"'),
|
|
215
|
+
goal: z.string().describe("Qu\xE9 se quiere lograr, en una o dos frases"),
|
|
216
|
+
dod: z.array(z.string()).describe("Definition of Done: criterios verificables de \xE9xito"),
|
|
217
|
+
tasks: z.array(z.string()).describe("Tareas numeradas, chicas y verificables, en orden de construcci\xF3n"),
|
|
218
|
+
design: z.string().optional().describe('Decisiones de arquitectura/stack del plan (el "blueprint"): qu\xE9 se eligi\xF3 y por qu\xE9. Recomendado en planes de >5 tareas.')
|
|
219
|
+
}
|
|
164
220
|
},
|
|
165
221
|
async ({ title, goal, dod, tasks, design }) => {
|
|
166
222
|
ensureVaultStructure(vault);
|
|
@@ -180,11 +236,13 @@ ${dod.map((d) => `- [ ] ${d}`).join("\n")}`,
|
|
|
180
236
|
${tasks.map((t, i) => `${i + 1}. ${t}`).join("\n")}`,
|
|
181
237
|
map ? `Proyecto: [[${map.title}]]` : ""
|
|
182
238
|
].filter(Boolean).join("\n\n");
|
|
239
|
+
const cleanTitle = title.replace(/^\s*(plan\s*-\s*)+/i, "").trim() || title;
|
|
183
240
|
const file = createNote(vault.managed, {
|
|
184
|
-
title: `Plan - ${
|
|
241
|
+
title: `Plan - ${cleanTitle}`,
|
|
185
242
|
type: "plan",
|
|
186
243
|
status: "active",
|
|
187
|
-
|
|
244
|
+
// tag del proyecto: el digest de inicio muestra solo los planes de este proyecto
|
|
245
|
+
tags: ["plan", path.basename(process.cwd())],
|
|
188
246
|
dir: "notes",
|
|
189
247
|
content
|
|
190
248
|
});
|
|
@@ -198,17 +256,19 @@ ${extra}` : "")
|
|
|
198
256
|
);
|
|
199
257
|
}
|
|
200
258
|
);
|
|
201
|
-
server.
|
|
259
|
+
server.registerTool(
|
|
202
260
|
"task_verify",
|
|
203
|
-
'PROTOCOLO paso 2: verifica una tarea con EVIDENCIA REAL, no con tu palabra. Pasa verify_command (ej. "npm test", "npm run build", "curl -sf localhost:3000") y Alexandria lo EJECUTA \u2014 el veredicto sale del exit code real. Si no puedes correr un comando, pasa evidence textual, pero se marca como auto-reportado (m\xE1s d\xE9bil). Si falla, busca lecciones previas antes de improvisar.',
|
|
204
261
|
{
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
262
|
+
description: 'PROTOCOLO paso 2: verifica una tarea con EVIDENCIA REAL, no con tu palabra. Pasa verify_command (ej. "npm test", "npm run build", "curl -sf localhost:3000") y Alexandria lo EJECUTA \u2014 el veredicto sale del exit code real. Si no puedes correr un comando, pasa evidence textual, pero se marca como auto-reportado (m\xE1s d\xE9bil). Si falla, busca lecciones previas antes de improvisar.',
|
|
263
|
+
inputSchema: {
|
|
264
|
+
plan: z.string().describe('T\xEDtulo del plan al que pertenece, tal como lo devolvi\xF3 plan_create (ej. "Plan - Login con Google")'),
|
|
265
|
+
task: z.string().describe("Qu\xE9 tarea se verific\xF3"),
|
|
266
|
+
passed: z.boolean().describe("Lo que T\xDA crees que pas\xF3 (se compara contra el resultado real del comando)"),
|
|
267
|
+
verify_command: z.string().optional().describe('Comando a EJECUTAR para verificar de verdad; exit 0 = pas\xF3. Ej. "npm test", "npm run build". Preferido sobre evidence.'),
|
|
268
|
+
cwd: z.string().optional().describe("Directorio donde correr verify_command. Por defecto se usa el del agente (a menudo la RA\xCDZ del workspace, no tu subproyecto): si tu comando usa rutas relativas, pasa aqu\xED la carpeta del proyecto."),
|
|
269
|
+
evidence: z.string().optional().describe("Solo si NO hay comando: evidencia textual (queda marcada como auto-reportada, sin verificar)."),
|
|
270
|
+
completes_plan: z.boolean().optional().describe("true si esta era la \xFAltima tarea y el plan queda completado")
|
|
271
|
+
}
|
|
212
272
|
},
|
|
213
273
|
async ({ plan, task, passed, verify_command, cwd, evidence, completes_plan }) => {
|
|
214
274
|
ensureVaultStructure(vault);
|
|
@@ -295,13 +355,15 @@ Sin lecciones previas \u2014 cuando lo resuelvas, gu\xE1rdala con lesson_extract
|
|
|
295
355
|
);
|
|
296
356
|
}
|
|
297
357
|
);
|
|
298
|
-
server.
|
|
358
|
+
server.registerTool(
|
|
299
359
|
"lesson_extract",
|
|
300
|
-
"PROTOCOLO paso 3: al resolver un error o terminar un plan, destila LA lecci\xF3n (qu\xE9 fall\xF3/funcion\xF3 y c\xF3mo evitarlo/repetirlo). 200 tokens hoy ahorran 20,000 de re-debug ma\xF1ana. Se inyecta autom\xE1ticamente cuando el problema reaparezca.",
|
|
301
360
|
{
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
361
|
+
description: "PROTOCOLO paso 3: al resolver un error o terminar un plan, destila LA lecci\xF3n (qu\xE9 fall\xF3/funcion\xF3 y c\xF3mo evitarlo/repetirlo). 200 tokens hoy ahorran 20,000 de re-debug ma\xF1ana. Se inyecta autom\xE1ticamente cuando el problema reaparezca.",
|
|
362
|
+
inputSchema: {
|
|
363
|
+
title: z.string().describe('Lecci\xF3n en una frase, ej. "GOOGLE_CLIENT_SECRET debe ir en .env"'),
|
|
364
|
+
lesson: z.string().describe("Qu\xE9 pas\xF3, causa ra\xEDz, y c\xF3mo aplicarla la pr\xF3xima vez"),
|
|
365
|
+
links: z.array(z.string()).optional().describe("T\xEDtulos de notas relacionadas (plan, feature, etc.)")
|
|
366
|
+
}
|
|
305
367
|
},
|
|
306
368
|
async ({ title, lesson, links }) => {
|
|
307
369
|
ensureVaultStructure(vault);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ureck/alexandria",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Alexandria — bóveda de conocimiento local para agentes de IA (Claude Code, Cursor, OpenCode
|
|
3
|
+
"version": "1.5.0",
|
|
4
|
+
"description": "Alexandria — bóveda de conocimiento local para agentes de IA (Claude Code, Codex, Gemini CLI, Cursor, OpenCode y más): captura automática por hooks, búsqueda semántica offline y grafo estilo Obsidian. Ahorra tokens inyectando solo el contexto relevante.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -30,25 +30,44 @@
|
|
|
30
30
|
"semantic-search",
|
|
31
31
|
"mcp",
|
|
32
32
|
"embeddings",
|
|
33
|
-
"local-first"
|
|
33
|
+
"local-first",
|
|
34
|
+
"codex",
|
|
35
|
+
"gemini-cli",
|
|
36
|
+
"cursor",
|
|
37
|
+
"opencode",
|
|
38
|
+
"hooks",
|
|
39
|
+
"ai-memory",
|
|
40
|
+
"agents-md",
|
|
41
|
+
"pdf",
|
|
42
|
+
"docx",
|
|
43
|
+
"xlsx",
|
|
44
|
+
"document-reading",
|
|
45
|
+
"token-optimization"
|
|
34
46
|
],
|
|
35
47
|
"dependencies": {
|
|
36
|
-
"@huggingface/transformers": "^
|
|
37
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
38
|
-
"commander": "^
|
|
48
|
+
"@huggingface/transformers": "^4.3.2",
|
|
49
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
50
|
+
"commander": "^15.0.0",
|
|
51
|
+
"exceljs": "^4.4.0",
|
|
39
52
|
"gray-matter": "^4.0.3",
|
|
53
|
+
"mammoth": "^1.13.0",
|
|
40
54
|
"minisearch": "^7.1.2",
|
|
41
55
|
"picocolors": "^1.1.1",
|
|
42
|
-
"
|
|
56
|
+
"turndown": "^7.2.4",
|
|
57
|
+
"unpdf": "^1.9.1",
|
|
58
|
+
"zod": "^4.6.7"
|
|
43
59
|
},
|
|
44
60
|
"overrides": {
|
|
45
|
-
"sharp": "^0.35.
|
|
61
|
+
"sharp": "^0.35.5",
|
|
62
|
+
"uuid": "^11.1.1"
|
|
46
63
|
},
|
|
47
64
|
"devDependencies": {
|
|
48
|
-
"@types/node": "^22.
|
|
49
|
-
"
|
|
65
|
+
"@types/node": "^22.20.5",
|
|
66
|
+
"@types/turndown": "^5.0.6",
|
|
67
|
+
"jszip": "^3.10.2",
|
|
68
|
+
"tsup": "^9.0.0",
|
|
50
69
|
"typescript": "^5.7.3",
|
|
51
|
-
"vitest": "^
|
|
70
|
+
"vitest": "^5.0.5"
|
|
52
71
|
},
|
|
53
72
|
"author": "Ureck <urielgomezbecerril@gmail.com>",
|
|
54
73
|
"publishConfig": {
|
|
@@ -58,7 +77,7 @@
|
|
|
58
77
|
"type": "git",
|
|
59
78
|
"url": "git+https://github.com/UreckChan/alexandria.git"
|
|
60
79
|
},
|
|
61
|
-
"homepage": "https://
|
|
80
|
+
"homepage": "https://alexandria.ureck.dev",
|
|
62
81
|
"bugs": {
|
|
63
82
|
"url": "https://github.com/UreckChan/alexandria/issues"
|
|
64
83
|
}
|