@ureck/alexandria 0.2.0 → 0.2.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 CHANGED
@@ -18,6 +18,8 @@ npm install -g @ureck/alexandria
18
18
  bun add -g @ureck/alexandria
19
19
  # deno
20
20
  deno install -grA -n ale npm:@ureck/alexandria/ale
21
+ # (si Deno se queja de "minimum dependency date", el paquete tiene <24h publicado:
22
+ # agrega --minimum-dependency-age=0)
21
23
 
22
24
  ale init # global: registra el MCP en Claude Code + agentes detectados
23
25
  # o dentro de un proyecto:
@@ -29,7 +31,7 @@ ale init --agents all # todos los soportados
29
31
  ale init --agents claude,cursor,opencode # solo esos
30
32
  ```
31
33
 
32
- `ale init` instala **todo** una sola vez: descarga el modelo de embeddings (~120MB, multilingüe, offline), registra hooks (Claude Code) y el servidor MCP en tus agentes, y construye el índice. Después no hay nada que reconectar — cada sesión nueva funciona sola.
34
+ `ale init` instala **todo** una sola vez: descarga el modelo de embeddings (~130MB, multilingüe, offline), registra hooks (Claude Code) y el servidor MCP en tus agentes, y construye el índice. Después no hay nada que reconectar — cada sesión nueva funciona sola.
33
35
 
34
36
  ## Agentes soportados
35
37
 
@@ -72,6 +74,8 @@ Sesión del agente de IA
72
74
  - **Búsqueda híbrida**: embeddings locales (transformers.js, modelo multilingüe) + BM25, combinados con RRF y boost por recencia/uso. Sin internet funciona en modo keyword.
73
75
  - **Índice incremental**: solo re-procesa notas cuyo mtime cambió. El grafo nunca se recalcula completo.
74
76
  - **Deduplicación**: prompts casi idénticos no crean notas nuevas — suman `hits` (y suben en el ranking).
77
+ - **Sobre los scores**: el modelo e5 comprime los cosenos (~0.76–0.86 incluso entre temas sin relación); el *ranking* es lo confiable, no el número crudo. Por eso `ale search` muestra una etiqueta de relevancia (alta/media/baja) relativa al mejor resultado.
78
+ - **Tamaño mínimo útil**: `--expand` y el grafo brillan a partir de ~20-30 notas conectadas; con un puñado de notas verás poco — es acumulativo por diseño.
75
79
 
76
80
  ## Comandos
77
81
 
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/core/register.ts
4
+ import fs from "fs";
5
+ import os from "os";
6
+ import path from "path";
7
+ import { fileURLToPath } from "url";
8
+ import { execFileSync } from "child_process";
9
+ function distDir() {
10
+ const here = path.dirname(fileURLToPath(import.meta.url));
11
+ return here.endsWith(`${path.sep}hooks`) || here.endsWith(`${path.sep}mcp`) ? path.dirname(here) : here;
12
+ }
13
+ var MARKER = "alexandria";
14
+ function hookCommand(script, timeout) {
15
+ return { type: "command", command: `node "${script}"`, timeout };
16
+ }
17
+ function isOurs(cmd) {
18
+ return cmd.includes(MARKER) || cmd.includes(distDir());
19
+ }
20
+ function registerHooks(settingsPath) {
21
+ const d = distDir();
22
+ const wanted = {
23
+ SessionStart: hookCommand(path.join(d, "hooks", "on-session-start.js"), 20),
24
+ UserPromptSubmit: hookCommand(path.join(d, "hooks", "on-prompt.js"), 30),
25
+ Stop: hookCommand(path.join(d, "hooks", "on-stop.js"), 30),
26
+ PreCompact: hookCommand(path.join(d, "hooks", "on-stop.js"), 30)
27
+ };
28
+ fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
29
+ let settings = {};
30
+ try {
31
+ settings = JSON.parse(fs.readFileSync(settingsPath, "utf8"));
32
+ } catch {
33
+ if (fs.existsSync(settingsPath)) {
34
+ throw new Error(`No pude parsear ${settingsPath} \u2014 rev\xEDsalo manualmente antes de registrar hooks.`);
35
+ }
36
+ }
37
+ settings.hooks ??= {};
38
+ for (const [event, cmd] of Object.entries(wanted)) {
39
+ const matchers = (settings.hooks[event] ?? []).filter(
40
+ (m) => !m.hooks?.some((h) => isOurs(h.command))
41
+ );
42
+ matchers.push({ hooks: [cmd] });
43
+ settings.hooks[event] = matchers;
44
+ }
45
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + "\n");
46
+ }
47
+ function unregisterHooks(settingsPath) {
48
+ try {
49
+ const settings = JSON.parse(fs.readFileSync(settingsPath, "utf8"));
50
+ if (!settings.hooks) return;
51
+ for (const event of Object.keys(settings.hooks)) {
52
+ settings.hooks[event] = settings.hooks[event].map((m) => ({ ...m, hooks: m.hooks.filter((h) => !isOurs(h.command)) })).filter((m) => m.hooks.length > 0);
53
+ if (settings.hooks[event].length === 0) delete settings.hooks[event];
54
+ }
55
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + "\n");
56
+ } catch {
57
+ }
58
+ }
59
+ function projectSettingsPath(projectDir) {
60
+ return path.join(projectDir, ".claude", "settings.json");
61
+ }
62
+ function globalSettingsPath() {
63
+ return path.join(os.homedir(), ".claude", "settings.json");
64
+ }
65
+ function hooksRegistered(settingsPath) {
66
+ try {
67
+ const settings = JSON.parse(fs.readFileSync(settingsPath, "utf8"));
68
+ const hooks = settings.hooks ?? {};
69
+ return ["SessionStart", "UserPromptSubmit"].every(
70
+ (ev) => (hooks[ev] ?? []).some((m) => m.hooks?.some((h) => isOurs(h.command)))
71
+ );
72
+ } catch {
73
+ return false;
74
+ }
75
+ }
76
+ function registerMcpProject(projectDir) {
77
+ const file = path.join(projectDir, ".mcp.json");
78
+ let cfg = {};
79
+ try {
80
+ cfg = JSON.parse(fs.readFileSync(file, "utf8"));
81
+ } catch {
82
+ if (fs.existsSync(file)) {
83
+ throw new Error(`No pude parsear ${file} \u2014 rev\xEDsalo manualmente.`);
84
+ }
85
+ }
86
+ cfg.mcpServers ??= {};
87
+ cfg.mcpServers["alexandria"] = {
88
+ command: "node",
89
+ args: [path.join(distDir(), "mcp", "server.js")]
90
+ };
91
+ fs.writeFileSync(file, JSON.stringify(cfg, null, 2) + "\n");
92
+ return file;
93
+ }
94
+ function registerMcpGlobal() {
95
+ const server = path.join(distDir(), "mcp", "server.js");
96
+ try {
97
+ execFileSync("claude", ["mcp", "add", "--scope", "user", "alexandria", "--", "node", server], {
98
+ stdio: "pipe",
99
+ timeout: 15e3
100
+ });
101
+ return true;
102
+ } catch {
103
+ return false;
104
+ }
105
+ }
106
+ function mcpRegisteredProject(projectDir) {
107
+ try {
108
+ const cfg = JSON.parse(fs.readFileSync(path.join(projectDir, ".mcp.json"), "utf8"));
109
+ return Boolean(cfg.mcpServers?.alexandria);
110
+ } catch {
111
+ return false;
112
+ }
113
+ }
114
+
115
+ // src/core/pkg.ts
116
+ import fs2 from "fs";
117
+ import path2 from "path";
118
+ var cached = null;
119
+ function pkgVersion() {
120
+ if (cached) return cached;
121
+ try {
122
+ const pkg = JSON.parse(fs2.readFileSync(path2.join(distDir(), "..", "package.json"), "utf8"));
123
+ cached = String(pkg.version);
124
+ } catch {
125
+ cached = "0.0.0";
126
+ }
127
+ return cached;
128
+ }
129
+
130
+ export {
131
+ distDir,
132
+ registerHooks,
133
+ unregisterHooks,
134
+ projectSettingsPath,
135
+ globalSettingsPath,
136
+ hooksRegistered,
137
+ registerMcpProject,
138
+ registerMcpGlobal,
139
+ mcpRegisteredProject,
140
+ pkgVersion
141
+ };
package/dist/cli.js CHANGED
@@ -2,6 +2,18 @@
2
2
  import {
3
3
  readStats
4
4
  } from "./chunk-OPUPZRP6.js";
5
+ import {
6
+ distDir,
7
+ globalSettingsPath,
8
+ hooksRegistered,
9
+ mcpRegisteredProject,
10
+ pkgVersion,
11
+ projectSettingsPath,
12
+ registerHooks,
13
+ registerMcpGlobal,
14
+ registerMcpProject,
15
+ unregisterHooks
16
+ } from "./chunk-KHTYRYDR.js";
5
17
  import {
6
18
  hybridSearch
7
19
  } from "./chunk-O7FDC2PB.js";
@@ -25,128 +37,16 @@ import {
25
37
  } from "./chunk-EDYBSJSS.js";
26
38
 
27
39
  // src/cli.ts
28
- import fs5 from "fs";
29
- import path5 from "path";
40
+ import fs4 from "fs";
41
+ import path4 from "path";
30
42
  import readline from "readline/promises";
31
43
  import { Command } from "commander";
32
44
  import pc from "picocolors";
33
45
 
34
- // src/core/register.ts
35
- import fs from "fs";
36
- import os from "os";
37
- import path from "path";
38
- import { fileURLToPath } from "url";
39
- import { execFileSync } from "child_process";
40
- function distDir() {
41
- const here = path.dirname(fileURLToPath(import.meta.url));
42
- return here.endsWith(`${path.sep}hooks`) || here.endsWith(`${path.sep}mcp`) ? path.dirname(here) : here;
43
- }
44
- var MARKER = "alexandria";
45
- function hookCommand(script, timeout) {
46
- return { type: "command", command: `node "${script}"`, timeout };
47
- }
48
- function isOurs(cmd) {
49
- return cmd.includes(MARKER) || cmd.includes(distDir());
50
- }
51
- function registerHooks(settingsPath) {
52
- const d = distDir();
53
- const wanted = {
54
- SessionStart: hookCommand(path.join(d, "hooks", "on-session-start.js"), 20),
55
- UserPromptSubmit: hookCommand(path.join(d, "hooks", "on-prompt.js"), 30),
56
- Stop: hookCommand(path.join(d, "hooks", "on-stop.js"), 30),
57
- PreCompact: hookCommand(path.join(d, "hooks", "on-stop.js"), 30)
58
- };
59
- fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
60
- let settings = {};
61
- try {
62
- settings = JSON.parse(fs.readFileSync(settingsPath, "utf8"));
63
- } catch {
64
- if (fs.existsSync(settingsPath)) {
65
- throw new Error(`No pude parsear ${settingsPath} \u2014 rev\xEDsalo manualmente antes de registrar hooks.`);
66
- }
67
- }
68
- settings.hooks ??= {};
69
- for (const [event, cmd] of Object.entries(wanted)) {
70
- const matchers = (settings.hooks[event] ?? []).filter(
71
- (m) => !m.hooks?.some((h) => isOurs(h.command))
72
- );
73
- matchers.push({ hooks: [cmd] });
74
- settings.hooks[event] = matchers;
75
- }
76
- fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + "\n");
77
- }
78
- function unregisterHooks(settingsPath) {
79
- try {
80
- const settings = JSON.parse(fs.readFileSync(settingsPath, "utf8"));
81
- if (!settings.hooks) return;
82
- for (const event of Object.keys(settings.hooks)) {
83
- settings.hooks[event] = settings.hooks[event].map((m) => ({ ...m, hooks: m.hooks.filter((h) => !isOurs(h.command)) })).filter((m) => m.hooks.length > 0);
84
- if (settings.hooks[event].length === 0) delete settings.hooks[event];
85
- }
86
- fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + "\n");
87
- } catch {
88
- }
89
- }
90
- function projectSettingsPath(projectDir) {
91
- return path.join(projectDir, ".claude", "settings.json");
92
- }
93
- function globalSettingsPath() {
94
- return path.join(os.homedir(), ".claude", "settings.json");
95
- }
96
- function hooksRegistered(settingsPath) {
97
- try {
98
- const settings = JSON.parse(fs.readFileSync(settingsPath, "utf8"));
99
- const hooks = settings.hooks ?? {};
100
- return ["SessionStart", "UserPromptSubmit"].every(
101
- (ev) => (hooks[ev] ?? []).some((m) => m.hooks?.some((h) => isOurs(h.command)))
102
- );
103
- } catch {
104
- return false;
105
- }
106
- }
107
- function registerMcpProject(projectDir) {
108
- const file = path.join(projectDir, ".mcp.json");
109
- let cfg = {};
110
- try {
111
- cfg = JSON.parse(fs.readFileSync(file, "utf8"));
112
- } catch {
113
- if (fs.existsSync(file)) {
114
- throw new Error(`No pude parsear ${file} \u2014 rev\xEDsalo manualmente.`);
115
- }
116
- }
117
- cfg.mcpServers ??= {};
118
- cfg.mcpServers["alexandria"] = {
119
- command: "node",
120
- args: [path.join(distDir(), "mcp", "server.js")]
121
- };
122
- fs.writeFileSync(file, JSON.stringify(cfg, null, 2) + "\n");
123
- return file;
124
- }
125
- function registerMcpGlobal() {
126
- const server = path.join(distDir(), "mcp", "server.js");
127
- try {
128
- execFileSync("claude", ["mcp", "add", "--scope", "user", "alexandria", "--", "node", server], {
129
- stdio: "pipe",
130
- timeout: 15e3
131
- });
132
- return true;
133
- } catch {
134
- return false;
135
- }
136
- }
137
- function mcpRegisteredProject(projectDir) {
138
- try {
139
- const cfg = JSON.parse(fs.readFileSync(path.join(projectDir, ".mcp.json"), "utf8"));
140
- return Boolean(cfg.mcpServers?.alexandria);
141
- } catch {
142
- return false;
143
- }
144
- }
145
-
146
46
  // src/graph/viewer.ts
147
- import fs2 from "fs";
47
+ import fs from "fs";
148
48
  import http from "http";
149
- import path2 from "path";
49
+ import path from "path";
150
50
  import { spawn } from "child_process";
151
51
  function buildGraphData(idx) {
152
52
  const deg = /* @__PURE__ */ new Map();
@@ -297,8 +197,8 @@ async function serveGraph(vault, opts = {}) {
297
197
  });
298
198
  const html = renderGraphHtml(buildGraphData(idx));
299
199
  if (opts.out) {
300
- const file = path2.resolve(opts.out);
301
- fs2.writeFileSync(file, html);
200
+ const file = path.resolve(opts.out);
201
+ fs.writeFileSync(file, html);
302
202
  return file;
303
203
  }
304
204
  return new Promise((resolve) => {
@@ -317,10 +217,10 @@ async function serveGraph(vault, opts = {}) {
317
217
  }
318
218
 
319
219
  // src/skills/recommend.ts
320
- import fs3 from "fs";
321
- import os2 from "os";
322
- import path3 from "path";
323
- import { execFileSync as execFileSync2 } from "child_process";
220
+ import fs2 from "fs";
221
+ import os from "os";
222
+ import path2 from "path";
223
+ import { execFileSync } from "child_process";
324
224
  var RULES = [
325
225
  { skill: "pdf-report-gen", keywords: ["pdf", "reporte pdf", "membrete"] },
326
226
  { skill: "excel-report-gen", keywords: ["excel", "xlsx", "spreadsheet", "hoja de calculo", "hoja de c\xE1lculo"] },
@@ -339,7 +239,7 @@ var RULES = [
339
239
  ];
340
240
  var MIN_MENTIONS = 3;
341
241
  function localSkillsRepo() {
342
- return path3.join(os2.homedir(), "Documents", "Projects", "Skills");
242
+ return path2.join(os.homedir(), "Documents", "Projects", "Skills");
343
243
  }
344
244
  function recommendSkills(vault, installedDirs) {
345
245
  const idx = VaultIndex.load(vault);
@@ -347,7 +247,7 @@ function recommendSkills(vault, installedDirs) {
347
247
  const installed = /* @__PURE__ */ new Set();
348
248
  for (const dir of installedDirs) {
349
249
  try {
350
- for (const e of fs3.readdirSync(dir)) installed.add(e);
250
+ for (const e of fs2.readdirSync(dir)) installed.add(e);
351
251
  } catch {
352
252
  }
353
253
  }
@@ -363,7 +263,7 @@ function recommendSkills(vault, installedDirs) {
363
263
  mentions += count;
364
264
  }
365
265
  if (mentions >= MIN_MENTIONS) {
366
- const local = fs3.existsSync(path3.join(localSkillsRepo(), rule.skill));
266
+ const local = fs2.existsSync(path2.join(localSkillsRepo(), rule.skill));
367
267
  out.push({
368
268
  skill: rule.skill,
369
269
  mentions,
@@ -375,22 +275,22 @@ function recommendSkills(vault, installedDirs) {
375
275
  return out.sort((a, b) => b.mentions - a.mentions);
376
276
  }
377
277
  function installSkill(rec, targetDir) {
378
- fs3.mkdirSync(targetDir, { recursive: true });
379
- const dest = path3.join(targetDir, rec.skill);
380
- if (fs3.existsSync(dest)) return { ok: true, detail: "ya instalada" };
278
+ fs2.mkdirSync(targetDir, { recursive: true });
279
+ const dest = path2.join(targetDir, rec.skill);
280
+ if (fs2.existsSync(dest)) return { ok: true, detail: "ya instalada" };
381
281
  if (rec.source === "local") {
382
282
  try {
383
- fs3.cpSync(path3.join(localSkillsRepo(), rec.skill), dest, { recursive: true });
283
+ fs2.cpSync(path2.join(localSkillsRepo(), rec.skill), dest, { recursive: true });
384
284
  return { ok: true, detail: `copiada desde ${localSkillsRepo()}` };
385
285
  } catch (e) {
386
286
  return { ok: false, detail: `error copiando: ${e.message}` };
387
287
  }
388
288
  }
389
289
  try {
390
- execFileSync2("npx", ["--yes", "skills", "add", rec.skill, "--yes"], {
290
+ execFileSync("npx", ["--yes", "skills", "add", rec.skill, "--yes"], {
391
291
  stdio: "pipe",
392
292
  timeout: 12e4,
393
- cwd: path3.dirname(targetDir)
293
+ cwd: path2.dirname(targetDir)
394
294
  });
395
295
  return { ok: true, detail: "instalada desde skills.sh" };
396
296
  } catch {
@@ -402,22 +302,22 @@ function installSkill(rec, targetDir) {
402
302
  }
403
303
 
404
304
  // src/core/agents.ts
405
- import fs4 from "fs";
406
- import os3 from "os";
407
- import path4 from "path";
408
- import { execFileSync as execFileSync3 } from "child_process";
409
- var serverScript = () => path4.join(distDir(), "mcp", "server.js");
305
+ import fs3 from "fs";
306
+ import os2 from "os";
307
+ import path3 from "path";
308
+ import { execFileSync as execFileSync2 } from "child_process";
309
+ var serverScript = () => path3.join(distDir(), "mcp", "server.js");
410
310
  function readJsonSafe(file) {
411
311
  try {
412
- return JSON.parse(fs4.readFileSync(file, "utf8"));
312
+ return JSON.parse(fs3.readFileSync(file, "utf8"));
413
313
  } catch {
414
- if (fs4.existsSync(file)) throw new Error(`no pude parsear ${file} \u2014 rev\xEDsalo manualmente`);
314
+ if (fs3.existsSync(file)) throw new Error(`no pude parsear ${file} \u2014 rev\xEDsalo manualmente`);
415
315
  return {};
416
316
  }
417
317
  }
418
318
  function writeJson(file, data) {
419
- fs4.mkdirSync(path4.dirname(file), { recursive: true });
420
- fs4.writeFileSync(file, JSON.stringify(data, null, 2) + "\n");
319
+ fs3.mkdirSync(path3.dirname(file), { recursive: true });
320
+ fs3.writeFileSync(file, JSON.stringify(data, null, 2) + "\n");
421
321
  }
422
322
  function mergeMcpServers(file, key = "mcpServers") {
423
323
  try {
@@ -432,11 +332,11 @@ function mergeMcpServers(file, key = "mcpServers") {
432
332
  }
433
333
  }
434
334
  function home(...p) {
435
- return path4.join(os3.homedir(), ...p);
335
+ return path3.join(os2.homedir(), ...p);
436
336
  }
437
337
  function vscodeUserDir() {
438
338
  if (process.platform === "darwin") return home("Library", "Application Support", "Code", "User");
439
- if (process.platform === "win32") return path4.join(process.env.APPDATA ?? home("AppData", "Roaming"), "Code", "User");
339
+ if (process.platform === "win32") return path3.join(process.env.APPDATA ?? home("AppData", "Roaming"), "Code", "User");
440
340
  return home(".config", "Code", "User");
441
341
  }
442
342
  var AGENTS = [
@@ -444,9 +344,9 @@ var AGENTS = [
444
344
  id: "claude",
445
345
  name: "Claude Code",
446
346
  supportsProject: true,
447
- detect: () => fs4.existsSync(home(".claude")),
347
+ detect: () => fs3.existsSync(home(".claude")),
448
348
  register(scope, projectDir) {
449
- if (scope === "project") return mergeMcpServers(path4.join(projectDir, ".mcp.json"));
349
+ if (scope === "project") return mergeMcpServers(path3.join(projectDir, ".mcp.json"));
450
350
  return mergeMcpServers(home(".claude.json"));
451
351
  }
452
352
  },
@@ -454,9 +354,9 @@ var AGENTS = [
454
354
  id: "cursor",
455
355
  name: "Cursor",
456
356
  supportsProject: true,
457
- detect: () => fs4.existsSync(home(".cursor")),
357
+ detect: () => fs3.existsSync(home(".cursor")),
458
358
  register(scope, projectDir) {
459
- const file = scope === "project" ? path4.join(projectDir, ".cursor", "mcp.json") : home(".cursor", "mcp.json");
359
+ const file = scope === "project" ? path3.join(projectDir, ".cursor", "mcp.json") : home(".cursor", "mcp.json");
460
360
  return mergeMcpServers(file);
461
361
  }
462
362
  },
@@ -464,9 +364,9 @@ var AGENTS = [
464
364
  id: "opencode",
465
365
  name: "OpenCode",
466
366
  supportsProject: true,
467
- detect: () => fs4.existsSync(home(".config", "opencode")) || fs4.existsSync(home(".opencode")),
367
+ detect: () => fs3.existsSync(home(".config", "opencode")) || fs3.existsSync(home(".opencode")),
468
368
  register(scope, projectDir) {
469
- const file = scope === "project" ? path4.join(projectDir, "opencode.json") : home(".config", "opencode", "opencode.json");
369
+ const file = scope === "project" ? path3.join(projectDir, "opencode.json") : home(".config", "opencode", "opencode.json");
470
370
  try {
471
371
  const cfg = readJsonSafe(file);
472
372
  cfg["$schema"] ??= "https://opencode.ai/config.json";
@@ -484,7 +384,7 @@ var AGENTS = [
484
384
  id: "windsurf",
485
385
  name: "Windsurf",
486
386
  supportsProject: false,
487
- detect: () => fs4.existsSync(home(".codeium", "windsurf")),
387
+ detect: () => fs3.existsSync(home(".codeium", "windsurf")),
488
388
  register() {
489
389
  return mergeMcpServers(home(".codeium", "windsurf", "mcp_config.json"));
490
390
  }
@@ -493,9 +393,9 @@ var AGENTS = [
493
393
  id: "cline",
494
394
  name: "Cline (VS Code)",
495
395
  supportsProject: false,
496
- detect: () => fs4.existsSync(path4.join(vscodeUserDir(), "globalStorage", "saoudrizwan.claude-dev")),
396
+ detect: () => fs3.existsSync(path3.join(vscodeUserDir(), "globalStorage", "saoudrizwan.claude-dev")),
497
397
  register() {
498
- const file = path4.join(
398
+ const file = path3.join(
499
399
  vscodeUserDir(),
500
400
  "globalStorage",
501
401
  "saoudrizwan.claude-dev",
@@ -509,7 +409,7 @@ var AGENTS = [
509
409
  id: "codex",
510
410
  name: "Codex CLI (OpenAI)",
511
411
  supportsProject: false,
512
- detect: () => fs4.existsSync(home(".codex")),
412
+ detect: () => fs3.existsSync(home(".codex")),
513
413
  register() {
514
414
  const file = home(".codex", "config.toml");
515
415
  const block = `[mcp_servers.alexandria]
@@ -519,7 +419,7 @@ args = ["${serverScript().replace(/\\/g, "\\\\")}"]
519
419
  try {
520
420
  let text = "";
521
421
  try {
522
- text = fs4.readFileSync(file, "utf8");
422
+ text = fs3.readFileSync(file, "utf8");
523
423
  } catch {
524
424
  }
525
425
  if (/^\[mcp_servers\.alexandria\]/m.test(text)) {
@@ -527,8 +427,8 @@ args = ["${serverScript().replace(/\\/g, "\\\\")}"]
527
427
  } else {
528
428
  text = text.trimEnd() + (text.trim() ? "\n\n" : "") + block;
529
429
  }
530
- fs4.mkdirSync(path4.dirname(file), { recursive: true });
531
- fs4.writeFileSync(file, text);
430
+ fs3.mkdirSync(path3.dirname(file), { recursive: true });
431
+ fs3.writeFileSync(file, text);
532
432
  return { ok: true, file };
533
433
  } catch (e) {
534
434
  return { ok: false, file, detail: e.message };
@@ -539,9 +439,9 @@ args = ["${serverScript().replace(/\\/g, "\\\\")}"]
539
439
  id: "gemini",
540
440
  name: "Gemini CLI",
541
441
  supportsProject: true,
542
- detect: () => fs4.existsSync(home(".gemini")),
442
+ detect: () => fs3.existsSync(home(".gemini")),
543
443
  register(scope, projectDir) {
544
- const file = scope === "project" ? path4.join(projectDir, ".gemini", "settings.json") : home(".gemini", "settings.json");
444
+ const file = scope === "project" ? path3.join(projectDir, ".gemini", "settings.json") : home(".gemini", "settings.json");
545
445
  return mergeMcpServers(file);
546
446
  }
547
447
  },
@@ -549,7 +449,7 @@ args = ["${serverScript().replace(/\\/g, "\\\\")}"]
549
449
  id: "openclaw",
550
450
  name: "OpenClaw",
551
451
  supportsProject: false,
552
- detect: () => fs4.existsSync(home(".openclaw")),
452
+ detect: () => fs3.existsSync(home(".openclaw")),
553
453
  register() {
554
454
  const file = home(".openclaw", "openclaw.json");
555
455
  try {
@@ -568,11 +468,11 @@ args = ["${serverScript().replace(/\\/g, "\\\\")}"]
568
468
  id: "hermes",
569
469
  name: "Hermes Agent (Nous)",
570
470
  supportsProject: false,
571
- detect: () => fs4.existsSync(home(".hermes")),
471
+ detect: () => fs3.existsSync(home(".hermes")),
572
472
  register() {
573
473
  const file = home(".hermes", "config.yaml");
574
474
  try {
575
- execFileSync3("hermes", ["mcp", "add", "alexandria", "--command", "node", "--args", serverScript()], {
475
+ execFileSync2("hermes", ["mcp", "add", "alexandria", "--command", "node", "--args", serverScript()], {
576
476
  stdio: "pipe",
577
477
  timeout: 15e3
578
478
  });
@@ -582,7 +482,7 @@ args = ["${serverScript().replace(/\\/g, "\\\\")}"]
582
482
  try {
583
483
  let text = "";
584
484
  try {
585
- text = fs4.readFileSync(file, "utf8");
485
+ text = fs3.readFileSync(file, "utf8");
586
486
  } catch {
587
487
  }
588
488
  if (/^\s*alexandria:/m.test(text)) return { ok: true, file, detail: "ya registrado" };
@@ -600,8 +500,8 @@ ${entry.trimEnd()}`);
600
500
  } else {
601
501
  text = text.trimEnd() + (text.trim() ? "\n\n" : "") + "mcp_servers:\n" + entry;
602
502
  }
603
- fs4.mkdirSync(path4.dirname(file), { recursive: true });
604
- fs4.writeFileSync(file, text);
503
+ fs3.mkdirSync(path3.dirname(file), { recursive: true });
504
+ fs3.writeFileSync(file, text);
605
505
  return { ok: true, file };
606
506
  } catch (e) {
607
507
  return { ok: false, file, detail: e.message };
@@ -612,9 +512,9 @@ ${entry.trimEnd()}`);
612
512
  id: "vscode",
613
513
  name: "VS Code (Copilot)",
614
514
  supportsProject: true,
615
- detect: () => fs4.existsSync(vscodeUserDir()),
515
+ detect: () => fs3.existsSync(vscodeUserDir()),
616
516
  register(scope, projectDir) {
617
- const file = scope === "project" ? path4.join(projectDir, ".vscode", "mcp.json") : path4.join(vscodeUserDir(), "mcp.json");
517
+ const file = scope === "project" ? path3.join(projectDir, ".vscode", "mcp.json") : path3.join(vscodeUserDir(), "mcp.json");
618
518
  try {
619
519
  const cfg = readJsonSafe(file);
620
520
  const servers = cfg["servers"] ?? {};
@@ -723,7 +623,7 @@ function registerAgentsMcp(agents, scope, cwd) {
723
623
  }
724
624
  }
725
625
  var program = new Command();
726
- program.name("ale").description("Alexandria \u2014 b\xF3veda de conocimiento local para agentes de IA (Claude Code, Cursor, OpenCode, Windsurf y m\xE1s): captura autom\xE1tica, b\xFAsqueda sem\xE1ntica offline y grafo de conexiones.").version("0.2.0").option("--vault <path>", "ruta de la b\xF3veda (anula la configuraci\xF3n)");
626
+ program.name("ale").description("Alexandria \u2014 b\xF3veda de conocimiento local para agentes de IA (Claude Code, Cursor, OpenCode, Windsurf y m\xE1s): captura autom\xE1tica, b\xFAsqueda sem\xE1ntica offline y grafo de conexiones.").version(pkgVersion()).option("--vault <path>", "ruta de la b\xF3veda (anula la configuraci\xF3n)");
727
627
  var getVault = () => resolveVault({ flag: program.opts().vault });
728
628
  async function downloadModelIfMissing() {
729
629
  if (modelPresent()) return true;
@@ -756,7 +656,7 @@ program.command("init").description("Crea/conecta la b\xF3veda e instala TODO: m
756
656
  `agentes de IA donde registrar el MCP: "all", "detected" o csv de ${AGENTS.map((a) => a.id).join(",")} (default: claude + detectados)`
757
657
  ).action(async (opts) => {
758
658
  const isProject = Boolean(opts.project) && !opts.global;
759
- const vaultPath = path5.resolve(opts.path);
659
+ const vaultPath = path4.resolve(opts.path);
760
660
  const cwd = process.cwd();
761
661
  await showBanner();
762
662
  console.log(pc.bold(`Instalaci\xF3n ${isProject ? "por proyecto" : "global"}
@@ -815,7 +715,7 @@ program.command("add").description("Guardar una nota manualmente").argument("<ti
815
715
  const { vault } = await ensureReady();
816
716
  let content = opts.content;
817
717
  if (!content && !process.stdin.isTTY) {
818
- content = fs5.readFileSync(0, "utf8");
718
+ content = fs4.readFileSync(0, "utf8");
819
719
  }
820
720
  const file = createNote(vault.managed, {
821
721
  title,
@@ -823,7 +723,7 @@ program.command("add").description("Guardar una nota manualmente").argument("<ti
823
723
  tags: opts.tags ? opts.tags.split(",").map((t) => t.trim()) : []
824
724
  });
825
725
  await VaultIndex.load(vault).refresh();
826
- console.log(pc.green(`\u2713 ${path5.relative(vault.root, file)}`));
726
+ console.log(pc.green(`\u2713 ${path4.relative(vault.root, file)}`));
827
727
  });
828
728
  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) => {
829
729
  const vault = getVault();
@@ -837,10 +737,17 @@ program.command("search").description("B\xFAsqueda h\xEDbrida (sem\xE1ntica + ke
837
737
  console.log(pc.dim("Sin resultados."));
838
738
  return;
839
739
  }
740
+ const maxCos = results.reduce((m, r) => Math.max(m, r.cosine), 0);
741
+ const relevanceLabel = (cos) => {
742
+ if (maxCos === 0 || cos === 0) return "";
743
+ if (cos >= 0.82 && cos >= maxCos - 0.02) return pc.green(" \u25CF relevancia alta");
744
+ if (cos >= 0.79 && cos >= maxCos - 0.05) return pc.yellow(" \u25CF relevancia media");
745
+ return pc.dim(" \u25CF relevancia baja");
746
+ };
840
747
  for (const r of results) {
841
748
  const cos = r.cosine > 0 ? pc.dim(` cos ${r.cosine.toFixed(2)}`) : "";
842
749
  console.log(`
843
- ${pc.bold(pc.cyan(r.note.title))} ${pc.dim(`(${r.note.rel}, ${r.note.type})`)}${cos}`);
750
+ ${pc.bold(pc.cyan(r.note.title))} ${pc.dim(`(${r.note.rel}, ${r.note.type})`)}${relevanceLabel(r.cosine)}${cos}`);
844
751
  for (const e of r.excerpts) {
845
752
  console.log(pc.dim(" " + e.replace(/\n+/g, " ").slice(0, 220)));
846
753
  }
@@ -890,7 +797,7 @@ program.command("stats").description("Estado de la b\xF3veda y tokens ahorrados"
890
797
  async function runSkills(opts) {
891
798
  const { vault } = await ensureReady();
892
799
  const cwd = process.cwd();
893
- const targetDir = opts.project ? path5.join(cwd, ".claude", "skills") : path5.join(process.env.HOME ?? process.env.USERPROFILE ?? cwd, ".claude", "skills");
800
+ const targetDir = opts.project ? path4.join(cwd, ".claude", "skills") : path4.join(process.env.HOME ?? process.env.USERPROFILE ?? cwd, ".claude", "skills");
894
801
  const recs = recommendSkills(vault, [targetDir]);
895
802
  if (recs.length === 0) {
896
803
  console.log(pc.dim("Sin recomendaciones nuevas: la b\xF3veda a\xFAn no tiene suficientes patrones (o ya est\xE1 todo instalado)."));
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ pkgVersion
4
+ } from "../chunk-KHTYRYDR.js";
2
5
  import {
3
6
  hybridSearch
4
7
  } from "../chunk-O7FDC2PB.js";
@@ -21,7 +24,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
21
24
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
22
25
  import { z } from "zod";
23
26
  var vault = resolveVault({ cwd: process.cwd() });
24
- var server = new McpServer({ name: "alexandria", version: "0.1.0" });
27
+ var server = new McpServer({ name: "alexandria", version: pkgVersion() });
25
28
  var text = (t) => ({ content: [{ type: "text", text: t }] });
26
29
  server.tool(
27
30
  "vault_search",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ureck/alexandria",
3
- "version": "0.2.0",
3
+ "version": "0.2.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",
@@ -52,6 +52,6 @@
52
52
  },
53
53
  "repository": {
54
54
  "type": "git",
55
- "url": "https://github.com/ureck/alexandria"
55
+ "url": "git+https://github.com/ureck/alexandria.git"
56
56
  }
57
57
  }