@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.
@@ -1,22 +1,23 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  pkgVersion
4
- } from "../chunk-KHTYRYDR.js";
4
+ } from "../chunk-IQM5S5N4.js";
5
5
  import {
6
6
  hybridSearch
7
- } from "../chunk-ADHRHLX7.js";
7
+ } from "../chunk-3ETM6PKR.js";
8
8
  import {
9
9
  ensureVaultStructure,
10
10
  resolveVault
11
- } from "../chunk-KB6KYZFQ.js";
11
+ } from "../chunk-DYCARGQR.js";
12
12
  import {
13
13
  VaultIndex
14
- } from "../chunk-ZW7XY3EN.js";
14
+ } from "../chunk-7G3NPKDO.js";
15
15
  import {
16
16
  createNote,
17
+ setNoteStatus,
17
18
  slugify,
18
19
  upsertNote
19
- } from "../chunk-JPHL2JHE.js";
20
+ } from "../chunk-XWR74BQ2.js";
20
21
  import "../chunk-EDYBSJSS.js";
21
22
 
22
23
  // src/mcp/server.ts
@@ -28,6 +29,15 @@ import { z } from "zod";
28
29
  var vault = resolveVault({ cwd: process.cwd() });
29
30
  var server = new McpServer({ name: "alexandria", version: pkgVersion() });
30
31
  var text = (t) => ({ content: [{ type: "text", text: t }] });
32
+ function findMap(idx) {
33
+ return Object.values(idx.meta.notes).find((n) => n.type === "map" || n.title.startsWith("Mapa - "));
34
+ }
35
+ function findByTitle(idx, t) {
36
+ const lower = t.toLowerCase();
37
+ return Object.values(idx.meta.notes).find(
38
+ (n) => n.title.toLowerCase() === lower || n.rel.toLowerCase() === lower
39
+ );
40
+ }
31
41
  server.tool(
32
42
  "vault_search",
33
43
  "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.",
@@ -118,4 +128,122 @@ server.tool(
118
128
  return text(`Conectado: \xAB${a.title}\xBB \u2192 [[${b.title}]]`);
119
129
  }
120
130
  );
131
+ server.tool(
132
+ "plan_create",
133
+ 'PROTOCOLO paso 1 (solo tareas NO triviales \u2014 las simples resp\xF3ndelas directo, sin ceremonia): crea el plan con Definition of Done (criterios verificables de "terminado") y tareas numeradas. Verifica cada tarea con task_verify. El plan enfoca tu capacidad, no la limita; y deja huella reutilizable.',
134
+ {
135
+ title: z.string().describe('Nombre corto del objetivo, ej. "Login con Google"'),
136
+ goal: z.string().describe("Qu\xE9 se quiere lograr, en una o dos frases"),
137
+ dod: z.array(z.string()).describe("Definition of Done: criterios verificables de \xE9xito"),
138
+ tasks: z.array(z.string()).describe("Tareas numeradas, chicas y verificables")
139
+ },
140
+ async ({ title, goal, dod, tasks }) => {
141
+ ensureVaultStructure(vault);
142
+ const idx = VaultIndex.load(vault);
143
+ const map = findMap(idx);
144
+ const content = [
145
+ `## Objetivo
146
+ ${goal}`,
147
+ `## Definition of Done
148
+ ${dod.map((d) => `- [ ] ${d}`).join("\n")}`,
149
+ `## Tareas
150
+ ${tasks.map((t, i) => `${i + 1}. ${t}`).join("\n")}`,
151
+ map ? `Proyecto: [[${map.title}]]` : ""
152
+ ].join("\n\n");
153
+ const file = createNote(vault.managed, {
154
+ title: `Plan - ${title}`,
155
+ type: "plan",
156
+ status: "active",
157
+ tags: ["plan"],
158
+ dir: "notes",
159
+ content
160
+ });
161
+ await VaultIndex.load(vault).refresh().catch(() => {
162
+ });
163
+ return text(
164
+ `Plan guardado en ${path.relative(vault.root, file)}. Ejecuta las tareas UNA por una; tras cada una llama task_verify con evidencia real (salida de tests/build). Al terminar todo, llama lesson_extract.`
165
+ );
166
+ }
167
+ );
168
+ server.tool(
169
+ "task_verify",
170
+ "PROTOCOLO paso 2: registra el resultado VERIFICADO de una tarea con evidencia real (salida de tests, build, curl \u2014 no lo des por hecho sin correrlo). Guarda el veredicto compacto; si fall\xF3, busca lecciones previas con vault_search antes de improvisar.",
171
+ {
172
+ plan: z.string().describe('T\xEDtulo del plan al que pertenece (ej. "Plan - Login con Google")'),
173
+ task: z.string().describe("Qu\xE9 tarea se verific\xF3"),
174
+ passed: z.boolean().describe("true si la evidencia confirma que funciona"),
175
+ evidence: z.string().describe('Evidencia compacta: "npm test \u2192 12/12 passed", c\xF3digo de error, etc.'),
176
+ completes_plan: z.boolean().optional().describe("true si esta era la \xFAltima tarea y el plan queda completado")
177
+ },
178
+ async ({ plan, task, passed, evidence, completes_plan }) => {
179
+ ensureVaultStructure(vault);
180
+ const idx = VaultIndex.load(vault);
181
+ const planNote = findByTitle(idx, plan);
182
+ const file = createNote(vault.managed, {
183
+ title: `${passed ? "OK" : "FALLO"} - ${task.slice(0, 60)}`,
184
+ type: "verification",
185
+ status: passed ? "completed" : "failed",
186
+ tags: ["verificacion"],
187
+ dir: "notes",
188
+ content: `**Tarea:** ${task}
189
+
190
+ **Veredicto:** ${passed ? "\u2705 pas\xF3" : "\u274C fall\xF3"}
191
+
192
+ **Evidencia:**
193
+ \`\`\`
194
+ ${evidence.slice(0, 1500)}
195
+ \`\`\`
196
+
197
+ ${planNote ? `Plan: [[${planNote.title}]]` : ""}`
198
+ });
199
+ if (completes_plan && planNote) {
200
+ try {
201
+ setNoteStatus(path.join(vault.root, planNote.rel), passed ? "completed" : "failed");
202
+ } catch {
203
+ }
204
+ }
205
+ await VaultIndex.load(vault).refresh().catch(() => {
206
+ });
207
+ if (!passed) {
208
+ const lessons = await hybridSearch(vault, `${task} ${evidence.slice(0, 200)}`, 3);
209
+ const useful = lessons.filter((l) => l.note.type === "lesson" || l.note.type === "solution");
210
+ if (useful.length > 0) {
211
+ return text(
212
+ `Fallo registrado (${path.relative(vault.root, file)}). LECCIONES PREVIAS que podr\xEDan aplicar \u2014 \xFAsalas antes de improvisar:
213
+ ` + useful.map((l) => `- \xAB${l.note.title}\xBB: ${l.excerpts[0]?.slice(0, 300) ?? ""}`).join("\n")
214
+ );
215
+ }
216
+ return text(`Fallo registrado. Sin lecciones previas para esto \u2014 cuando lo resuelvas, guarda la lecci\xF3n con lesson_extract.`);
217
+ }
218
+ return text(`Verificaci\xF3n guardada${completes_plan ? " y plan marcado como completado" : ""}. ${completes_plan ? "Cierra con lesson_extract si hubo aprendizaje." : "Siguiente tarea."}`);
219
+ }
220
+ );
221
+ server.tool(
222
+ "lesson_extract",
223
+ "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.",
224
+ {
225
+ title: z.string().describe('Lecci\xF3n en una frase, ej. "GOOGLE_CLIENT_SECRET debe ir en .env"'),
226
+ lesson: z.string().describe("Qu\xE9 pas\xF3, causa ra\xEDz, y c\xF3mo aplicarla la pr\xF3xima vez"),
227
+ links: z.array(z.string()).optional().describe("T\xEDtulos de notas relacionadas (plan, feature, etc.)")
228
+ },
229
+ async ({ title, lesson, links }) => {
230
+ ensureVaultStructure(vault);
231
+ const idx = VaultIndex.load(vault);
232
+ const map = findMap(idx);
233
+ const wikilinks = (links ?? []).map((l) => findByTitle(idx, l)).filter((n) => Boolean(n)).map((n) => `[[${n.title}]]`);
234
+ if (map) wikilinks.push(`[[${map.title}]]`);
235
+ const file = createNote(vault.managed, {
236
+ title: `Lecci\xF3n - ${title.slice(0, 70)}`,
237
+ type: "lesson",
238
+ tags: ["leccion"],
239
+ dir: "notes",
240
+ content: `${lesson}
241
+
242
+ ${wikilinks.length ? `Relacionado: ${[...new Set(wikilinks)].join(" \xB7 ")}` : ""}`
243
+ });
244
+ await VaultIndex.load(vault).refresh().catch(() => {
245
+ });
246
+ return text(`Lecci\xF3n guardada en ${path.relative(vault.root, file)} \u2014 se inyectar\xE1 autom\xE1ticamente cuando el tema reaparezca.`);
247
+ }
248
+ );
121
249
  await server.connect(new StdioServerTransport());
@@ -4,9 +4,9 @@ import {
4
4
  renderGraphHtml,
5
5
  serveGraph,
6
6
  writeStaticGraph
7
- } from "./chunk-WPNU64MA.js";
8
- import "./chunk-ZW7XY3EN.js";
9
- import "./chunk-JPHL2JHE.js";
7
+ } from "./chunk-UTXUGXDB.js";
8
+ import "./chunk-7G3NPKDO.js";
9
+ import "./chunk-XWR74BQ2.js";
10
10
  import "./chunk-EDYBSJSS.js";
11
11
  export {
12
12
  buildGraphData,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ureck/alexandria",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "Alexandria — bóveda de conocimiento local para agentes de IA (Claude Code, Cursor, OpenCode, Windsurf y más): captura automática, búsqueda semántica offline y grafo de conexiones estilo Obsidian. Ahorra tokens inyectando solo el contexto relevante.",
5
5
  "type": "module",
6
6
  "license": "MIT",