@ureck/alexandria 0.2.0 → 0.2.2
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 +9 -5
- package/dist/chunk-KHTYRYDR.js +141 -0
- package/dist/cli.js +82 -172
- package/dist/mcp/server.js +4 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -18,18 +18,20 @@ 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
|
-
ale init # global:
|
|
24
|
+
ale init # global: bóveda compartida en ~/KnowledgeVault, MCP en Claude Code + agentes detectados
|
|
23
25
|
# o dentro de un proyecto:
|
|
24
|
-
ale init --project #
|
|
25
|
-
# apuntar a tu vault Obsidian existente:
|
|
26
|
+
ale init --project # bóveda DENTRO del repo (./KnowledgeVault) + .vault.json, .claude/settings.json, .mcp.json…
|
|
27
|
+
# apuntar a tu vault Obsidian existente (funciona con ambos modos):
|
|
26
28
|
ale init --path ~/Documents/MiVaultObsidian
|
|
27
29
|
# elegir agentes explícitamente:
|
|
28
30
|
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 (~
|
|
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,12 +74,14 @@ 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
|
|
|
78
82
|
| Comando | Qué hace |
|
|
79
83
|
|---|---|
|
|
80
|
-
| `ale init [--project] [--path <dir>] [--agents <ids>]` | Instala todo (una vez) |
|
|
84
|
+
| `ale init [--project] [--path <dir>] [--agents <ids>]` | Instala todo (una vez). Default de bóveda: `./KnowledgeVault` con `--project`, `~/KnowledgeVault` en global |
|
|
81
85
|
| `ale agents [ids] [--project]` | Lista agentes / registra el MCP en ellos |
|
|
82
86
|
| `ale search <query> [--expand]` | Búsqueda híbrida; `--expand` trae vecinos del grafo |
|
|
83
87
|
| `ale add <título> [-c texto] [-t tags]` | Guardar nota manual (o por stdin) |
|
|
@@ -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
|
|
29
|
-
import
|
|
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
|
|
47
|
+
import fs from "fs";
|
|
148
48
|
import http from "http";
|
|
149
|
-
import
|
|
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 =
|
|
301
|
-
|
|
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
|
|
321
|
-
import
|
|
322
|
-
import
|
|
323
|
-
import { execFileSync
|
|
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
|
|
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
|
|
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 =
|
|
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
|
-
|
|
379
|
-
const dest =
|
|
380
|
-
if (
|
|
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
|
-
|
|
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
|
-
|
|
290
|
+
execFileSync("npx", ["--yes", "skills", "add", rec.skill, "--yes"], {
|
|
391
291
|
stdio: "pipe",
|
|
392
292
|
timeout: 12e4,
|
|
393
|
-
cwd:
|
|
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
|
|
406
|
-
import
|
|
407
|
-
import
|
|
408
|
-
import { execFileSync as
|
|
409
|
-
var serverScript = () =>
|
|
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(
|
|
312
|
+
return JSON.parse(fs3.readFileSync(file, "utf8"));
|
|
413
313
|
} catch {
|
|
414
|
-
if (
|
|
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
|
-
|
|
420
|
-
|
|
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
|
|
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
|
|
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: () =>
|
|
347
|
+
detect: () => fs3.existsSync(home(".claude")),
|
|
448
348
|
register(scope, projectDir) {
|
|
449
|
-
if (scope === "project") return mergeMcpServers(
|
|
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: () =>
|
|
357
|
+
detect: () => fs3.existsSync(home(".cursor")),
|
|
458
358
|
register(scope, projectDir) {
|
|
459
|
-
const file = scope === "project" ?
|
|
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: () =>
|
|
367
|
+
detect: () => fs3.existsSync(home(".config", "opencode")) || fs3.existsSync(home(".opencode")),
|
|
468
368
|
register(scope, projectDir) {
|
|
469
|
-
const file = scope === "project" ?
|
|
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: () =>
|
|
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: () =>
|
|
396
|
+
detect: () => fs3.existsSync(path3.join(vscodeUserDir(), "globalStorage", "saoudrizwan.claude-dev")),
|
|
497
397
|
register() {
|
|
498
|
-
const file =
|
|
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: () =>
|
|
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 =
|
|
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
|
-
|
|
531
|
-
|
|
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: () =>
|
|
442
|
+
detect: () => fs3.existsSync(home(".gemini")),
|
|
543
443
|
register(scope, projectDir) {
|
|
544
|
-
const file = scope === "project" ?
|
|
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: () =>
|
|
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: () =>
|
|
471
|
+
detect: () => fs3.existsSync(home(".hermes")),
|
|
572
472
|
register() {
|
|
573
473
|
const file = home(".hermes", "config.yaml");
|
|
574
474
|
try {
|
|
575
|
-
|
|
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 =
|
|
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
|
-
|
|
604
|
-
|
|
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: () =>
|
|
515
|
+
detect: () => fs3.existsSync(vscodeUserDir()),
|
|
616
516
|
register(scope, projectDir) {
|
|
617
|
-
const file = scope === "project" ?
|
|
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(
|
|
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;
|
|
@@ -751,13 +651,16 @@ async function ensureReady(vault = getVault()) {
|
|
|
751
651
|
const res = await idx.refresh();
|
|
752
652
|
return { vault, idx, res };
|
|
753
653
|
}
|
|
754
|
-
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(
|
|
654
|
+
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(
|
|
655
|
+
"--path <dir>",
|
|
656
|
+
"ruta del vault Obsidian (existente o nuevo). Default: ./KnowledgeVault con --project, ~/KnowledgeVault en global"
|
|
657
|
+
).option("--skills", "al final, recomendar e instalar skills seg\xFAn el contenido").option(
|
|
755
658
|
"--agents <ids>",
|
|
756
659
|
`agentes de IA donde registrar el MCP: "all", "detected" o csv de ${AGENTS.map((a) => a.id).join(",")} (default: claude + detectados)`
|
|
757
660
|
).action(async (opts) => {
|
|
758
661
|
const isProject = Boolean(opts.project) && !opts.global;
|
|
759
|
-
const vaultPath = path5.resolve(opts.path);
|
|
760
662
|
const cwd = process.cwd();
|
|
663
|
+
const vaultPath = path4.resolve(opts.path ?? (isProject ? path4.join(cwd, "KnowledgeVault") : defaultVaultPath()));
|
|
761
664
|
await showBanner();
|
|
762
665
|
console.log(pc.bold(`Instalaci\xF3n ${isProject ? "por proyecto" : "global"}
|
|
763
666
|
`));
|
|
@@ -815,7 +718,7 @@ program.command("add").description("Guardar una nota manualmente").argument("<ti
|
|
|
815
718
|
const { vault } = await ensureReady();
|
|
816
719
|
let content = opts.content;
|
|
817
720
|
if (!content && !process.stdin.isTTY) {
|
|
818
|
-
content =
|
|
721
|
+
content = fs4.readFileSync(0, "utf8");
|
|
819
722
|
}
|
|
820
723
|
const file = createNote(vault.managed, {
|
|
821
724
|
title,
|
|
@@ -823,7 +726,7 @@ program.command("add").description("Guardar una nota manualmente").argument("<ti
|
|
|
823
726
|
tags: opts.tags ? opts.tags.split(",").map((t) => t.trim()) : []
|
|
824
727
|
});
|
|
825
728
|
await VaultIndex.load(vault).refresh();
|
|
826
|
-
console.log(pc.green(`\u2713 ${
|
|
729
|
+
console.log(pc.green(`\u2713 ${path4.relative(vault.root, file)}`));
|
|
827
730
|
});
|
|
828
731
|
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
732
|
const vault = getVault();
|
|
@@ -837,10 +740,17 @@ program.command("search").description("B\xFAsqueda h\xEDbrida (sem\xE1ntica + ke
|
|
|
837
740
|
console.log(pc.dim("Sin resultados."));
|
|
838
741
|
return;
|
|
839
742
|
}
|
|
743
|
+
const maxCos = results.reduce((m, r) => Math.max(m, r.cosine), 0);
|
|
744
|
+
const relevanceLabel = (cos) => {
|
|
745
|
+
if (maxCos === 0 || cos === 0) return "";
|
|
746
|
+
if (cos >= 0.82 && cos >= maxCos - 0.02) return pc.green(" \u25CF relevancia alta");
|
|
747
|
+
if (cos >= 0.79 && cos >= maxCos - 0.05) return pc.yellow(" \u25CF relevancia media");
|
|
748
|
+
return pc.dim(" \u25CF relevancia baja");
|
|
749
|
+
};
|
|
840
750
|
for (const r of results) {
|
|
841
751
|
const cos = r.cosine > 0 ? pc.dim(` cos ${r.cosine.toFixed(2)}`) : "";
|
|
842
752
|
console.log(`
|
|
843
|
-
${pc.bold(pc.cyan(r.note.title))} ${pc.dim(`(${r.note.rel}, ${r.note.type})`)}${cos}`);
|
|
753
|
+
${pc.bold(pc.cyan(r.note.title))} ${pc.dim(`(${r.note.rel}, ${r.note.type})`)}${relevanceLabel(r.cosine)}${cos}`);
|
|
844
754
|
for (const e of r.excerpts) {
|
|
845
755
|
console.log(pc.dim(" " + e.replace(/\n+/g, " ").slice(0, 220)));
|
|
846
756
|
}
|
|
@@ -890,7 +800,7 @@ program.command("stats").description("Estado de la b\xF3veda y tokens ahorrados"
|
|
|
890
800
|
async function runSkills(opts) {
|
|
891
801
|
const { vault } = await ensureReady();
|
|
892
802
|
const cwd = process.cwd();
|
|
893
|
-
const targetDir = opts.project ?
|
|
803
|
+
const targetDir = opts.project ? path4.join(cwd, ".claude", "skills") : path4.join(process.env.HOME ?? process.env.USERPROFILE ?? cwd, ".claude", "skills");
|
|
894
804
|
const recs = recommendSkills(vault, [targetDir]);
|
|
895
805
|
if (recs.length === 0) {
|
|
896
806
|
console.log(pc.dim("Sin recomendaciones nuevas: la b\xF3veda a\xFAn no tiene suficientes patrones (o ya est\xE1 todo instalado)."));
|
package/dist/mcp/server.js
CHANGED
|
@@ -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:
|
|
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.
|
|
3
|
+
"version": "0.2.2",
|
|
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
|
}
|