@ureck/alexandria 0.2.4 → 0.3.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 +7 -3
- package/dist/{chunk-CZM5NQZJ.js → chunk-CF2GLMR3.js} +17 -0
- package/dist/{chunk-O7FDC2PB.js → chunk-FID2RAOH.js} +1 -1
- package/dist/chunk-I2ZBQUZD.js +312 -0
- package/dist/{chunk-UWAIMIG2.js → chunk-VN7QOAG2.js} +11 -1
- package/dist/cli.js +53 -223
- package/dist/hooks/on-prompt.js +3 -3
- package/dist/hooks/on-session-start.js +2 -2
- package/dist/hooks/on-stop.js +1 -1
- package/dist/mcp/server.js +3 -3
- package/dist/viewer-LD4RTZE7.js +16 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -131,12 +131,16 @@ ale add "Deploy en Vercel" -c "Regiones cdg1, ver [[Configuración de Prisma]]"
|
|
|
131
131
|
|
|
132
132
|
### Ver el grafo de conexiones
|
|
133
133
|
|
|
134
|
+
**El grafo se mantiene solo** — no hay que generarlo: cada vez que la bóveda cambia (captura automática, `ale add`, reindex), se regenera `<bóveda>/grafo.html`. Doble clic y siempre está al día.
|
|
135
|
+
|
|
134
136
|
```bash
|
|
135
|
-
ale graph #
|
|
136
|
-
ale graph --out
|
|
137
|
+
ale graph # visor EN VIVO en tu navegador: se actualiza solo cada 3s
|
|
138
|
+
ale graph --out otro.html # copia estática a otra ruta (opcional)
|
|
137
139
|
```
|
|
138
140
|
|
|
139
|
-
Nodos = notas (tamaño = conexiones), líneas sólidas = `[[wikilinks]]`, punteadas = similitud semántica.
|
|
141
|
+
Nodos = notas (tamaño = conexiones, color = tipo), líneas sólidas = `[[wikilinks]]`, punteadas = similitud semántica. Auto-encuadre, hover resalta vecinos, click muestra detalle y conexiones, caja para filtrar por título/tag. El grafo brilla a partir de ~20-30 notas — es acumulativo por diseño.
|
|
142
|
+
|
|
143
|
+
**En Obsidian**: abre la carpeta de la bóveda como vault y usa su graph view nativo — las notas llevan `aliases` en el frontmatter para que Obsidian resuelva los `[[wikilinks]]` (sin eso los ve como enlaces rotos). Las notas viejas se migran solas en el siguiente reindex. Ojo: `grafo.html` no se abre *dentro* de Obsidian (no renderiza HTML) — es para el navegador.
|
|
140
144
|
|
|
141
145
|
### Medir cuánto te está ahorrando
|
|
142
146
|
|
|
@@ -144,6 +144,9 @@ function frontmatter(n) {
|
|
|
144
144
|
const lines = [
|
|
145
145
|
"---",
|
|
146
146
|
`title: ${JSON.stringify(n.title)}`,
|
|
147
|
+
// aliases: Obsidian resuelve [[wikilinks]] contra alias, no contra el title
|
|
148
|
+
// del frontmatter — sin esto su graph view muestra los enlaces como rotos
|
|
149
|
+
`aliases: [${JSON.stringify(n.title)}]`,
|
|
147
150
|
`type: ${n.type}`,
|
|
148
151
|
`tags: [${n.tags.map((t) => JSON.stringify(t)).join(", ")}]`,
|
|
149
152
|
`created: ${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
@@ -153,6 +156,18 @@ function frontmatter(n) {
|
|
|
153
156
|
];
|
|
154
157
|
return lines.join("\n");
|
|
155
158
|
}
|
|
159
|
+
function ensureAlias(absPath) {
|
|
160
|
+
try {
|
|
161
|
+
const raw = fs2.readFileSync(absPath, "utf8");
|
|
162
|
+
const { data, content } = matter(raw);
|
|
163
|
+
if (!data.title || data.aliases) return false;
|
|
164
|
+
data.aliases = [String(data.title)];
|
|
165
|
+
fs2.writeFileSync(absPath, matter.stringify(content, data));
|
|
166
|
+
return true;
|
|
167
|
+
} catch {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
156
171
|
function createNote(managed, n) {
|
|
157
172
|
const dir = path2.join(managed, n.dir ?? "notes");
|
|
158
173
|
fs2.mkdirSync(dir, { recursive: true });
|
|
@@ -207,6 +222,7 @@ function appendToNote(managed, n) {
|
|
|
207
222
|
}
|
|
208
223
|
|
|
209
224
|
export {
|
|
225
|
+
MANAGED_DIR,
|
|
210
226
|
globalConfigPath,
|
|
211
227
|
defaultVaultPath,
|
|
212
228
|
resolveVault,
|
|
@@ -217,6 +233,7 @@ export {
|
|
|
217
233
|
slugify,
|
|
218
234
|
listMarkdownFiles,
|
|
219
235
|
parseNote,
|
|
236
|
+
ensureAlias,
|
|
220
237
|
createNote,
|
|
221
238
|
touchNote,
|
|
222
239
|
upsertNote,
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
VaultIndex
|
|
4
|
+
} from "./chunk-VN7QOAG2.js";
|
|
5
|
+
|
|
6
|
+
// src/graph/viewer.ts
|
|
7
|
+
import fs from "fs";
|
|
8
|
+
import http from "http";
|
|
9
|
+
import path from "path";
|
|
10
|
+
import { spawn } from "child_process";
|
|
11
|
+
function buildGraphData(idx) {
|
|
12
|
+
const deg = /* @__PURE__ */ new Map();
|
|
13
|
+
for (const l of idx.meta.links) {
|
|
14
|
+
deg.set(l.from, (deg.get(l.from) ?? 0) + 1);
|
|
15
|
+
deg.set(l.to, (deg.get(l.to) ?? 0) + 1);
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
nodes: Object.values(idx.meta.notes).map((n) => ({
|
|
19
|
+
id: n.rel,
|
|
20
|
+
title: n.title,
|
|
21
|
+
type: n.type,
|
|
22
|
+
deg: deg.get(n.rel) ?? 0,
|
|
23
|
+
hits: n.hits ?? 1,
|
|
24
|
+
tags: n.tags
|
|
25
|
+
})),
|
|
26
|
+
edges: idx.meta.links.map((l) => ({ s: l.from, t: l.to, type: l.type, w: l.w })),
|
|
27
|
+
generated: (/* @__PURE__ */ new Date()).toISOString()
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function renderGraphHtml(data, live) {
|
|
31
|
+
return `<!doctype html>
|
|
32
|
+
<html lang="es">
|
|
33
|
+
<head>
|
|
34
|
+
<meta charset="utf-8">
|
|
35
|
+
<title>Alexandria \u2014 grafo de conocimiento</title>
|
|
36
|
+
<style>
|
|
37
|
+
:root { --bg:#0b0d13; --panel:#141826f2; --line:#232a3d; --txt:#dde3f4; --dim:#8b93ad; }
|
|
38
|
+
html,body{margin:0;height:100%;background:var(--bg);color:var(--txt);font:14px/1.45 -apple-system,system-ui,sans-serif;overflow:hidden}
|
|
39
|
+
canvas{display:block;cursor:grab}
|
|
40
|
+
canvas.dragging{cursor:grabbing}
|
|
41
|
+
.card{position:fixed;background:var(--panel);border:1px solid var(--line);border-radius:14px;backdrop-filter:blur(12px);box-shadow:0 8px 30px #0008}
|
|
42
|
+
#hud{top:14px;left:14px;padding:12px 16px;max-width:330px}
|
|
43
|
+
#hud h1{font-size:15px;margin:0 0 2px;letter-spacing:.3px}
|
|
44
|
+
#hud .sub{color:var(--dim);font-size:12px}
|
|
45
|
+
.leg{display:flex;gap:12px;flex-wrap:wrap;margin-top:8px;font-size:12px;color:var(--dim)}
|
|
46
|
+
.leg b{display:inline-block;width:9px;height:9px;border-radius:50%;margin-right:5px;vertical-align:-1px}
|
|
47
|
+
#hint{color:var(--dim);font-size:11px;margin-top:6px}
|
|
48
|
+
#info{bottom:14px;left:14px;padding:12px 16px;max-width:440px;display:none}
|
|
49
|
+
#info b{font-size:14px}
|
|
50
|
+
#info .meta{color:var(--dim);font-size:12px;margin-top:2px}
|
|
51
|
+
#tip{padding:6px 10px;font-size:12px;pointer-events:none;display:none;border-radius:8px;white-space:nowrap}
|
|
52
|
+
#live{top:14px;right:14px;padding:6px 12px;font-size:11px;color:var(--dim);display:${live ? "block" : "none"}}
|
|
53
|
+
#live b{color:#9ece6a}
|
|
54
|
+
#search{position:fixed;top:14px;left:50%;transform:translateX(-50%);}
|
|
55
|
+
#search input{background:var(--panel);border:1px solid var(--line);border-radius:10px;color:var(--txt);padding:7px 12px;width:230px;font-size:13px;outline:none}
|
|
56
|
+
#search input:focus{border-color:#7aa2f7}
|
|
57
|
+
</style>
|
|
58
|
+
</head>
|
|
59
|
+
<body>
|
|
60
|
+
<div id="hud" class="card">
|
|
61
|
+
<h1>\u{1F3DB}\uFE0F Alexandria</h1>
|
|
62
|
+
<div class="sub" id="counts"></div>
|
|
63
|
+
<div class="leg">
|
|
64
|
+
<span><b style="background:#7aa2f7"></b>nota</span>
|
|
65
|
+
<span><b style="background:#9ece6a"></b>sesi\xF3n</span>
|
|
66
|
+
<span><b style="background:#e0af68"></b>prompt</span>
|
|
67
|
+
<span><b style="background:#f7768e"></b>mapa</span>
|
|
68
|
+
</div>
|
|
69
|
+
<div id="hint">arrastra \xB7 rueda = zoom \xB7 hover = conexiones \xB7 click = detalle<br>\u2014 s\xF3lida = [[wikilink]] \xB7 \u2025 punteada = sem\xE1ntica</div>
|
|
70
|
+
</div>
|
|
71
|
+
<div id="search"><input id="q" placeholder="filtrar notas\u2026" autocomplete="off"></div>
|
|
72
|
+
<div id="live" class="card">\u25CF <b>en vivo</b> \u2014 se actualiza solo</div>
|
|
73
|
+
<div id="info" class="card"></div>
|
|
74
|
+
<div id="tip" class="card"></div>
|
|
75
|
+
<canvas id="c"></canvas>
|
|
76
|
+
<script>
|
|
77
|
+
'use strict';
|
|
78
|
+
const LIVE = ${live};
|
|
79
|
+
let DATA = ${JSON.stringify(data)};
|
|
80
|
+
const COLORS = { note:'#7aa2f7', session:'#9ece6a', prompt:'#e0af68', map:'#f7768e' };
|
|
81
|
+
const cv = document.getElementById('c'), ctx = cv.getContext('2d');
|
|
82
|
+
const DPR = Math.min(devicePixelRatio || 1, 2);
|
|
83
|
+
let W, H;
|
|
84
|
+
function fit(){ W = innerWidth; H = innerHeight; cv.width = W*DPR; cv.height = H*DPR; cv.style.width = W+'px'; cv.style.height = H+'px'; }
|
|
85
|
+
fit(); addEventListener('resize', () => { fit(); fitView(); });
|
|
86
|
+
|
|
87
|
+
// Estado global ANTES de loadData: asigna heat/hot al cargar (evita TDZ)
|
|
88
|
+
let nodes = [], byId = new Map(), edges = [];
|
|
89
|
+
let zoom = 1, panX = 0, panY = 0, dragNode = null, hot = true, heat = 300;
|
|
90
|
+
let didFit = false, hover = null, filter = '';
|
|
91
|
+
function radius(n){ return 5 + Math.min(n.deg,14)*1.1 + Math.min(n.hits,8)*0.6; }
|
|
92
|
+
function loadData(data, keepPositions){
|
|
93
|
+
const old = keepPositions ? byId : new Map();
|
|
94
|
+
nodes = data.nodes.map((n,i) => {
|
|
95
|
+
const prev = old.get(n.id);
|
|
96
|
+
const angle = i/Math.max(data.nodes.length,1)*6.283;
|
|
97
|
+
return Object.assign({}, n, {
|
|
98
|
+
x: prev ? prev.x : W/2 + Math.cos(angle)*Math.min(W,H)*0.28 + (Math.random()-.5)*30,
|
|
99
|
+
y: prev ? prev.y : H/2 + Math.sin(angle)*Math.min(W,H)*0.28 + (Math.random()-.5)*30,
|
|
100
|
+
vx: 0, vy: 0, r: radius(n)
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
byId = new Map(nodes.map(n => [n.id, n]));
|
|
104
|
+
edges = data.edges.filter(e => byId.has(e.s) && byId.has(e.t)).map(e => ({ a: byId.get(e.s), b: byId.get(e.t), type: e.type, w: e.w || 0.5 }));
|
|
105
|
+
document.getElementById('counts').textContent = nodes.length + ' notas \xB7 ' + edges.length + ' conexiones';
|
|
106
|
+
heat = 280; hot = true;
|
|
107
|
+
}
|
|
108
|
+
loadData(DATA, false);
|
|
109
|
+
|
|
110
|
+
// ---------- f\xEDsica ----------
|
|
111
|
+
function step(){
|
|
112
|
+
if (!hot) return;
|
|
113
|
+
for (let i = 0; i < nodes.length; i++) for (let j = i+1; j < nodes.length; j++){
|
|
114
|
+
const a = nodes[i], b = nodes[j];
|
|
115
|
+
let dx = b.x-a.x, dy = b.y-a.y;
|
|
116
|
+
const d2 = dx*dx + dy*dy + 0.01, d = Math.sqrt(d2);
|
|
117
|
+
// repulsi\xF3n + colisi\xF3n suave (nunca encimados)
|
|
118
|
+
let f = Math.min(2600/d2, 10);
|
|
119
|
+
const minD = a.r + b.r + 14;
|
|
120
|
+
if (d < minD) f += (minD - d) * 0.06;
|
|
121
|
+
dx /= d; dy /= d;
|
|
122
|
+
a.vx -= dx*f; a.vy -= dy*f; b.vx += dx*f; b.vy += dy*f;
|
|
123
|
+
}
|
|
124
|
+
for (const e of edges){
|
|
125
|
+
let dx = e.b.x-e.a.x, dy = e.b.y-e.a.y;
|
|
126
|
+
const d = Math.sqrt(dx*dx+dy*dy) + 0.01;
|
|
127
|
+
const want = e.type === 'wikilink' ? 120 : 175;
|
|
128
|
+
const k = (d - want) * (e.type === 'wikilink' ? 0.006 : 0.003);
|
|
129
|
+
dx /= d; dy /= d;
|
|
130
|
+
e.a.vx += dx*k*d; e.a.vy += dy*k*d; e.b.vx -= dx*k*d; e.b.vy -= dy*k*d;
|
|
131
|
+
}
|
|
132
|
+
for (const n of nodes){
|
|
133
|
+
n.vx += (W/2 - n.x) * 0.0005; n.vy += (H/2 - n.y) * 0.0005;
|
|
134
|
+
n.vx *= 0.86; n.vy *= 0.86;
|
|
135
|
+
if (n !== dragNode){ n.x += n.vx; n.y += n.vy; }
|
|
136
|
+
}
|
|
137
|
+
if (--heat <= 0 && !dragNode) { hot = false; if (!didFit) fitView(); }
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ---------- auto-encuadre ----------
|
|
141
|
+
function fitView(){
|
|
142
|
+
if (!nodes.length) return;
|
|
143
|
+
didFit = true;
|
|
144
|
+
let x0=1e9, y0=1e9, x1=-1e9, y1=-1e9;
|
|
145
|
+
for (const n of nodes){ x0=Math.min(x0,n.x); y0=Math.min(y0,n.y); x1=Math.max(x1,n.x); y1=Math.max(y1,n.y); }
|
|
146
|
+
const pad = 90, w = Math.max(x1-x0, 60), h = Math.max(y1-y0, 60);
|
|
147
|
+
zoom = Math.min((W-pad*2)/w, (H-pad*2)/h, 1.6);
|
|
148
|
+
panX = W/2 - (x0+x1)/2 * zoom;
|
|
149
|
+
panY = H/2 - (y0+y1)/2 * zoom;
|
|
150
|
+
}
|
|
151
|
+
setTimeout(fitView, 900); // encuadre inicial tras estabilizar
|
|
152
|
+
|
|
153
|
+
// ---------- render ----------
|
|
154
|
+
function draw(){
|
|
155
|
+
ctx.setTransform(DPR,0,0,DPR,0,0);
|
|
156
|
+
ctx.clearRect(0,0,W,H);
|
|
157
|
+
const g = ctx.createRadialGradient(W/2,H/2,80, W/2,H/2,Math.max(W,H)*0.7);
|
|
158
|
+
g.addColorStop(0,'#11141d'); g.addColorStop(1,'#0b0d13');
|
|
159
|
+
ctx.fillStyle = g; ctx.fillRect(0,0,W,H);
|
|
160
|
+
ctx.setTransform(DPR*zoom,0,0,DPR*zoom,DPR*panX,DPR*panY);
|
|
161
|
+
|
|
162
|
+
const active = hover ? new Set([hover, ...edges.filter(e=>e.a===hover||e.b===hover).flatMap(e=>[e.a,e.b])]) : null;
|
|
163
|
+
const match = filter ? new Set(nodes.filter(n => n.title.toLowerCase().includes(filter) || n.tags.join(' ').toLowerCase().includes(filter))) : null;
|
|
164
|
+
const visible = (n) => (!active || active.has(n)) && (!match || match.has(n));
|
|
165
|
+
|
|
166
|
+
for (const e of edges){
|
|
167
|
+
const on = visible(e.a) && visible(e.b) && (!active || e.a===hover || e.b===hover);
|
|
168
|
+
ctx.beginPath();
|
|
169
|
+
ctx.setLineDash(e.type === 'semantic' ? [5,5] : []);
|
|
170
|
+
ctx.strokeStyle = e.type === 'semantic' ? '#3d4560' : '#57648f';
|
|
171
|
+
ctx.globalAlpha = on ? (e.type==='semantic'?0.55:0.8) : 0.07;
|
|
172
|
+
ctx.lineWidth = on && active ? 2 : 1.2;
|
|
173
|
+
const mx = (e.a.x+e.b.x)/2 - (e.b.y-e.a.y)*0.08;
|
|
174
|
+
const my = (e.a.y+e.b.y)/2 + (e.b.x-e.a.x)*0.08;
|
|
175
|
+
ctx.moveTo(e.a.x, e.a.y); ctx.quadraticCurveTo(mx, my, e.b.x, e.b.y); ctx.stroke();
|
|
176
|
+
}
|
|
177
|
+
ctx.setLineDash([]);
|
|
178
|
+
|
|
179
|
+
for (const n of nodes){
|
|
180
|
+
const on = visible(n);
|
|
181
|
+
const color = COLORS[n.type] || '#7aa2f7';
|
|
182
|
+
ctx.globalAlpha = on ? 1 : 0.12;
|
|
183
|
+
ctx.shadowColor = color; ctx.shadowBlur = on ? (n === hover ? 26 : 12) : 0;
|
|
184
|
+
ctx.beginPath();
|
|
185
|
+
ctx.fillStyle = color;
|
|
186
|
+
ctx.arc(n.x, n.y, n === hover ? n.r*1.25 : n.r, 0, 6.283); ctx.fill();
|
|
187
|
+
ctx.shadowBlur = 0;
|
|
188
|
+
ctx.beginPath();
|
|
189
|
+
ctx.strokeStyle = '#ffffff2e'; ctx.lineWidth = 1;
|
|
190
|
+
ctx.arc(n.x, n.y, n === hover ? n.r*1.25 : n.r, 0, 6.283); ctx.stroke();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// etiquetas con halo para legibilidad
|
|
194
|
+
const showAll = nodes.length <= 40 || zoom > 1.15;
|
|
195
|
+
ctx.font = (12/Math.max(zoom,0.8)) + 'px -apple-system,system-ui,sans-serif';
|
|
196
|
+
ctx.lineWidth = 3/Math.max(zoom,0.8); ctx.strokeStyle = '#0b0d13';
|
|
197
|
+
for (const n of nodes){
|
|
198
|
+
if (!visible(n)) continue;
|
|
199
|
+
if (!(showAll || n.deg > 1 || n === hover)) continue;
|
|
200
|
+
const label = n.title.length > 34 ? n.title.slice(0,33)+'\u2026' : n.title;
|
|
201
|
+
ctx.globalAlpha = n === hover ? 1 : 0.85;
|
|
202
|
+
ctx.strokeText(label, n.x + n.r + 5, n.y + 4);
|
|
203
|
+
ctx.fillStyle = '#cdd6f4';
|
|
204
|
+
ctx.fillText(label, n.x + n.r + 5, n.y + 4);
|
|
205
|
+
}
|
|
206
|
+
ctx.globalAlpha = 1;
|
|
207
|
+
}
|
|
208
|
+
(function loop(){ step(); draw(); requestAnimationFrame(loop); })();
|
|
209
|
+
|
|
210
|
+
// ---------- interacci\xF3n ----------
|
|
211
|
+
const toWorld = (x,y) => [(x-panX)/zoom, (y-panY)/zoom];
|
|
212
|
+
const pick = (x,y) => { const [wx,wy] = toWorld(x,y); return nodes.find(n => { const dx=n.x-wx, dy=n.y-wy; return dx*dx+dy*dy <= (n.r+6)*(n.r+6); }); };
|
|
213
|
+
let panning = false, px = 0, py = 0, moved = false;
|
|
214
|
+
const tip = document.getElementById('tip');
|
|
215
|
+
cv.addEventListener('mousedown', e => { moved = false; const n = pick(e.clientX, e.clientY); if (n){ dragNode = n; hot = true; heat = 120; } else { panning = true; px = e.clientX; py = e.clientY; } cv.classList.add('dragging'); });
|
|
216
|
+
addEventListener('mousemove', e => {
|
|
217
|
+
if (dragNode){ const [wx,wy] = toWorld(e.clientX, e.clientY); dragNode.x = wx; dragNode.y = wy; moved = true; hot = true; heat = Math.max(heat, 40); return; }
|
|
218
|
+
if (panning){ panX += e.clientX-px; panY += e.clientY-py; px = e.clientX; py = e.clientY; moved = true; return; }
|
|
219
|
+
const n = pick(e.clientX, e.clientY);
|
|
220
|
+
if (n !== hover){ hover = n; }
|
|
221
|
+
if (n){ tip.style.display='block'; tip.style.left = (e.clientX+14)+'px'; tip.style.top = (e.clientY+14)+'px'; tip.textContent = n.title; }
|
|
222
|
+
else tip.style.display = 'none';
|
|
223
|
+
});
|
|
224
|
+
addEventListener('mouseup', () => { dragNode = null; panning = false; cv.classList.remove('dragging'); });
|
|
225
|
+
cv.addEventListener('click', e => {
|
|
226
|
+
if (moved) return;
|
|
227
|
+
const n = pick(e.clientX, e.clientY);
|
|
228
|
+
const info = document.getElementById('info');
|
|
229
|
+
if (n){
|
|
230
|
+
const nbs = edges.filter(x => x.a===n || x.b===n).map(x => (x.a===n?x.b:x.a).title);
|
|
231
|
+
info.style.display = 'block';
|
|
232
|
+
info.innerHTML = '<b>' + n.title + '</b><div class="meta">' + n.id + '<br>tipo: ' + n.type + ' \xB7 usos: ' + n.hits + (n.tags.length ? ' \xB7 #' + n.tags.join(' #') : '') + '</div>' +
|
|
233
|
+
(nbs.length ? '<div class="meta" style="margin-top:6px">conecta con: ' + nbs.slice(0,6).join(' \xB7 ') + (nbs.length>6 ? ' +' + (nbs.length-6) : '') + '</div>' : '');
|
|
234
|
+
} else info.style.display = 'none';
|
|
235
|
+
});
|
|
236
|
+
cv.addEventListener('wheel', e => {
|
|
237
|
+
e.preventDefault();
|
|
238
|
+
const f = e.deltaY < 0 ? 1.12 : 0.89;
|
|
239
|
+
panX = e.clientX - (e.clientX - panX)*f; panY = e.clientY - (e.clientY - panY)*f; zoom *= f;
|
|
240
|
+
}, { passive: false });
|
|
241
|
+
document.getElementById('q').addEventListener('input', e => { filter = e.target.value.trim().toLowerCase(); });
|
|
242
|
+
|
|
243
|
+
// ---------- modo en vivo: el grafo se actualiza solo ----------
|
|
244
|
+
if (LIVE) setInterval(async () => {
|
|
245
|
+
try {
|
|
246
|
+
const res = await fetch('/data.json');
|
|
247
|
+
const fresh = await res.json();
|
|
248
|
+
if (fresh.generated !== DATA.generated && (fresh.nodes.length !== DATA.nodes.length || fresh.edges.length !== DATA.edges.length)){
|
|
249
|
+
DATA = fresh; loadData(fresh, true);
|
|
250
|
+
} else { DATA = fresh; }
|
|
251
|
+
} catch { /* server cerrado */ }
|
|
252
|
+
}, 3000);
|
|
253
|
+
</script>
|
|
254
|
+
</body>
|
|
255
|
+
</html>`;
|
|
256
|
+
}
|
|
257
|
+
function writeStaticGraph(idx) {
|
|
258
|
+
const file = path.join(idx.vault.root, "grafo.html");
|
|
259
|
+
fs.writeFileSync(file, renderGraphHtml(buildGraphData(idx), false));
|
|
260
|
+
return file;
|
|
261
|
+
}
|
|
262
|
+
function openBrowser(url) {
|
|
263
|
+
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
264
|
+
const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
|
|
265
|
+
try {
|
|
266
|
+
spawn(cmd, args, { detached: true, stdio: "ignore" }).unref();
|
|
267
|
+
} catch {
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
async function serveGraph(vault, opts = {}) {
|
|
271
|
+
const fresh = async () => {
|
|
272
|
+
const idx = VaultIndex.load(vault);
|
|
273
|
+
await idx.refresh(false).catch(() => {
|
|
274
|
+
});
|
|
275
|
+
return idx;
|
|
276
|
+
};
|
|
277
|
+
if (opts.out) {
|
|
278
|
+
const file = path.resolve(opts.out);
|
|
279
|
+
fs.writeFileSync(file, renderGraphHtml(buildGraphData(await fresh()), false));
|
|
280
|
+
return file;
|
|
281
|
+
}
|
|
282
|
+
return new Promise((resolve) => {
|
|
283
|
+
const server = http.createServer(async (req, res) => {
|
|
284
|
+
try {
|
|
285
|
+
if (req.url?.startsWith("/data.json")) {
|
|
286
|
+
res.writeHead(200, { "content-type": "application/json" });
|
|
287
|
+
res.end(JSON.stringify(buildGraphData(await fresh())));
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
res.writeHead(200, { "content-type": "text/html; charset=utf-8" });
|
|
291
|
+
res.end(renderGraphHtml(buildGraphData(await fresh()), true));
|
|
292
|
+
} catch (e) {
|
|
293
|
+
res.writeHead(500);
|
|
294
|
+
res.end(String(e));
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
server.listen(0, "127.0.0.1", () => {
|
|
298
|
+
const addr = server.address();
|
|
299
|
+
const port = typeof addr === "object" && addr ? addr.port : 0;
|
|
300
|
+
const url = `http://127.0.0.1:${port}`;
|
|
301
|
+
if (opts.open !== false) openBrowser(url);
|
|
302
|
+
resolve(url);
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export {
|
|
308
|
+
buildGraphData,
|
|
309
|
+
renderGraphHtml,
|
|
310
|
+
writeStaticGraph,
|
|
311
|
+
serveGraph
|
|
312
|
+
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
MANAGED_DIR,
|
|
4
|
+
ensureAlias,
|
|
3
5
|
listMarkdownFiles,
|
|
4
6
|
parseNote
|
|
5
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-CF2GLMR3.js";
|
|
6
8
|
import {
|
|
7
9
|
DIM,
|
|
8
10
|
MODEL_ID,
|
|
@@ -104,6 +106,9 @@ var VaultIndex = class _VaultIndex {
|
|
|
104
106
|
for (const rel of changed) {
|
|
105
107
|
const info = onDisk.get(rel);
|
|
106
108
|
try {
|
|
109
|
+
if (rel.startsWith(`${MANAGED_DIR}/`) && ensureAlias(info.abs)) {
|
|
110
|
+
info.mtime = fs.statSync(info.abs).mtimeMs;
|
|
111
|
+
}
|
|
107
112
|
const note = parseNote(this.vault.root, info.abs);
|
|
108
113
|
this.meta.notes[rel] = {
|
|
109
114
|
rel,
|
|
@@ -160,6 +165,11 @@ ${c.text}`),
|
|
|
160
165
|
}
|
|
161
166
|
this.rebuildLinks();
|
|
162
167
|
this.save();
|
|
168
|
+
try {
|
|
169
|
+
const { writeStaticGraph } = await import("./viewer-LD4RTZE7.js");
|
|
170
|
+
writeStaticGraph(this);
|
|
171
|
+
} catch {
|
|
172
|
+
}
|
|
163
173
|
return { changed: changed.length, removed: removed.length, embedded: this.emb !== null };
|
|
164
174
|
}
|
|
165
175
|
/** Wikilinks (título → nota) + links semánticos (similitud entre notas). */
|
package/dist/cli.js
CHANGED
|
@@ -16,10 +16,13 @@ import {
|
|
|
16
16
|
} from "./chunk-KHTYRYDR.js";
|
|
17
17
|
import {
|
|
18
18
|
hybridSearch
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-FID2RAOH.js";
|
|
20
|
+
import {
|
|
21
|
+
serveGraph
|
|
22
|
+
} from "./chunk-I2ZBQUZD.js";
|
|
20
23
|
import {
|
|
21
24
|
VaultIndex
|
|
22
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-VN7QOAG2.js";
|
|
23
26
|
import {
|
|
24
27
|
createNote,
|
|
25
28
|
defaultVaultPath,
|
|
@@ -29,7 +32,7 @@ import {
|
|
|
29
32
|
vaultExists,
|
|
30
33
|
writeGlobalConfig,
|
|
31
34
|
writeProjectConfig
|
|
32
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-CF2GLMR3.js";
|
|
33
36
|
import {
|
|
34
37
|
MODEL_ID,
|
|
35
38
|
getEmbedder,
|
|
@@ -37,189 +40,16 @@ import {
|
|
|
37
40
|
} from "./chunk-EDYBSJSS.js";
|
|
38
41
|
|
|
39
42
|
// src/cli.ts
|
|
40
|
-
import
|
|
41
|
-
import
|
|
43
|
+
import fs3 from "fs";
|
|
44
|
+
import path3 from "path";
|
|
42
45
|
import readline from "readline/promises";
|
|
43
46
|
import { Command } from "commander";
|
|
44
47
|
import pc from "picocolors";
|
|
45
48
|
|
|
46
|
-
// src/graph/viewer.ts
|
|
47
|
-
import fs from "fs";
|
|
48
|
-
import http from "http";
|
|
49
|
-
import path from "path";
|
|
50
|
-
import { spawn } from "child_process";
|
|
51
|
-
function buildGraphData(idx) {
|
|
52
|
-
const deg = /* @__PURE__ */ new Map();
|
|
53
|
-
for (const l of idx.meta.links) {
|
|
54
|
-
deg.set(l.from, (deg.get(l.from) ?? 0) + 1);
|
|
55
|
-
deg.set(l.to, (deg.get(l.to) ?? 0) + 1);
|
|
56
|
-
}
|
|
57
|
-
const nodes = Object.values(idx.meta.notes).map((n) => ({
|
|
58
|
-
id: n.rel,
|
|
59
|
-
title: n.title,
|
|
60
|
-
type: n.type,
|
|
61
|
-
deg: deg.get(n.rel) ?? 0,
|
|
62
|
-
hits: n.hits ?? 1
|
|
63
|
-
}));
|
|
64
|
-
const edges = idx.meta.links.map((l) => ({ s: l.from, t: l.to, type: l.type }));
|
|
65
|
-
return { nodes, edges };
|
|
66
|
-
}
|
|
67
|
-
function renderGraphHtml(data) {
|
|
68
|
-
return `<!doctype html>
|
|
69
|
-
<html lang="es">
|
|
70
|
-
<head>
|
|
71
|
-
<meta charset="utf-8">
|
|
72
|
-
<title>Alexandria \u2014 grafo de conocimiento</title>
|
|
73
|
-
<style>
|
|
74
|
-
html,body{margin:0;height:100%;background:#0f1117;color:#e6e6e6;font:14px/1.4 system-ui,sans-serif;overflow:hidden}
|
|
75
|
-
#hud{position:fixed;top:12px;left:12px;background:#1a1d27cc;padding:10px 14px;border-radius:10px;max-width:340px}
|
|
76
|
-
#hud h1{font-size:15px;margin:0 0 4px}
|
|
77
|
-
#hud .leg span{display:inline-block;width:10px;height:10px;border-radius:50%;margin:0 4px 0 10px}
|
|
78
|
-
#info{position:fixed;bottom:12px;left:12px;background:#1a1d27cc;padding:10px 14px;border-radius:10px;max-width:420px;display:none}
|
|
79
|
-
canvas{display:block}
|
|
80
|
-
</style>
|
|
81
|
-
</head>
|
|
82
|
-
<body>
|
|
83
|
-
<div id="hud">
|
|
84
|
-
<h1>\u{1F9E0} Alexandria \u2014 grafo</h1>
|
|
85
|
-
<div id="counts"></div>
|
|
86
|
-
<div class="leg">
|
|
87
|
-
<span style="background:#7aa2f7"></span>nota
|
|
88
|
-
<span style="background:#9ece6a"></span>sesi\xF3n
|
|
89
|
-
<span style="background:#e0af68"></span>prompt
|
|
90
|
-
<span style="background:#f7768e"></span>mapa
|
|
91
|
-
</div>
|
|
92
|
-
<div style="opacity:.7;margin-top:4px">arrastra nodos \xB7 rueda = zoom \xB7 click = detalle<br>l\xEDnea s\xF3lida = [[wikilink]] \xB7 punteada = sem\xE1ntica</div>
|
|
93
|
-
</div>
|
|
94
|
-
<div id="info"></div>
|
|
95
|
-
<canvas id="c"></canvas>
|
|
96
|
-
<script>
|
|
97
|
-
const DATA = ${JSON.stringify(data)};
|
|
98
|
-
const COLORS = { note:'#7aa2f7', session:'#9ece6a', prompt:'#e0af68', map:'#f7768e' };
|
|
99
|
-
const cv = document.getElementById('c'), ctx = cv.getContext('2d');
|
|
100
|
-
let W, H; const fit = () => { W = cv.width = innerWidth; H = cv.height = innerHeight; };
|
|
101
|
-
fit(); addEventListener('resize', fit);
|
|
102
|
-
document.getElementById('counts').textContent = DATA.nodes.length + ' notas \xB7 ' + DATA.edges.length + ' conexiones';
|
|
103
|
-
|
|
104
|
-
const nodes = DATA.nodes.map((n,i) => ({...n,
|
|
105
|
-
x: Math.cos(i/DATA.nodes.length*6.283)*Math.min(W,H)*.3 + W/2 + (Math.random()-.5)*40,
|
|
106
|
-
y: Math.sin(i/DATA.nodes.length*6.283)*Math.min(W,H)*.3 + H/2 + (Math.random()-.5)*40,
|
|
107
|
-
vx:0, vy:0, r: 4 + Math.min(n.deg,12)*1.2 + Math.min(n.hits,8)*.5
|
|
108
|
-
}));
|
|
109
|
-
const byId = new Map(nodes.map(n=>[n.id,n]));
|
|
110
|
-
const edges = DATA.edges.filter(e=>byId.has(e.s)&&byId.has(e.t)).map(e=>({a:byId.get(e.s), b:byId.get(e.t), type:e.type}));
|
|
111
|
-
|
|
112
|
-
let zoom = 1, panX = 0, panY = 0, dragNode = null, hot = true, heat = 300;
|
|
113
|
-
function step(){
|
|
114
|
-
if(!hot) return;
|
|
115
|
-
// repulsi\xF3n O(n\xB2) \u2014 bien hasta ~1500 nodos
|
|
116
|
-
for(let i=0;i<nodes.length;i++) for(let j=i+1;j<nodes.length;j++){
|
|
117
|
-
const a=nodes[i], b=nodes[j];
|
|
118
|
-
let dx=b.x-a.x, dy=b.y-a.y, d2=dx*dx+dy*dy+0.01, d=Math.sqrt(d2);
|
|
119
|
-
const f = Math.min(1800/d2, 8);
|
|
120
|
-
dx/=d; dy/=d;
|
|
121
|
-
a.vx-=dx*f; a.vy-=dy*f; b.vx+=dx*f; b.vy+=dy*f;
|
|
122
|
-
}
|
|
123
|
-
for(const e of edges){
|
|
124
|
-
let dx=e.b.x-e.a.x, dy=e.b.y-e.a.y, d=Math.sqrt(dx*dx+dy*dy)+0.01;
|
|
125
|
-
const want = e.type==='wikilink'?110:160;
|
|
126
|
-
const f=(d-want)*0.004*(e.type==='wikilink'?1.4:0.7);
|
|
127
|
-
dx/=d; dy/=d;
|
|
128
|
-
e.a.vx+=dx*f*d; e.a.vy+=dy*f*d; e.b.vx-=dx*f*d; e.b.vy-=dy*f*d;
|
|
129
|
-
}
|
|
130
|
-
for(const n of nodes){
|
|
131
|
-
n.vx += (W/2-n.x)*0.0004; n.vy += (H/2-n.y)*0.0004; // gravedad al centro
|
|
132
|
-
n.vx*=0.85; n.vy*=0.85;
|
|
133
|
-
if(n!==dragNode){ n.x+=n.vx; n.y+=n.vy; }
|
|
134
|
-
}
|
|
135
|
-
if(--heat<=0 && !dragNode) hot=false;
|
|
136
|
-
}
|
|
137
|
-
function draw(){
|
|
138
|
-
ctx.setTransform(1,0,0,1,0,0); ctx.clearRect(0,0,W,H);
|
|
139
|
-
ctx.setTransform(zoom,0,0,zoom,panX,panY);
|
|
140
|
-
for(const e of edges){
|
|
141
|
-
ctx.beginPath();
|
|
142
|
-
ctx.setLineDash(e.type==='semantic'?[4,4]:[]);
|
|
143
|
-
ctx.strokeStyle = e.type==='semantic' ? '#3b4261' : '#565f89';
|
|
144
|
-
ctx.lineWidth = 1;
|
|
145
|
-
ctx.moveTo(e.a.x,e.a.y); ctx.lineTo(e.b.x,e.b.y); ctx.stroke();
|
|
146
|
-
}
|
|
147
|
-
ctx.setLineDash([]);
|
|
148
|
-
for(const n of nodes){
|
|
149
|
-
ctx.beginPath(); ctx.fillStyle = COLORS[n.type]||'#7aa2f7';
|
|
150
|
-
ctx.arc(n.x,n.y,n.r,0,6.283); ctx.fill();
|
|
151
|
-
}
|
|
152
|
-
if(zoom>0.6){
|
|
153
|
-
ctx.fillStyle='#c0caf5'; ctx.font = (11/Math.max(zoom,1))+'px system-ui';
|
|
154
|
-
for(const n of nodes){ if(n.deg>0||zoom>1.1) ctx.fillText(n.title.slice(0,28), n.x+n.r+3, n.y+3); }
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
(function loop(){ step(); draw(); requestAnimationFrame(loop); })();
|
|
158
|
-
|
|
159
|
-
const toWorld = (x,y)=>[(x-panX)/zoom,(y-panY)/zoom];
|
|
160
|
-
const pick = (x,y)=>{ const [wx,wy]=toWorld(x,y); return nodes.find(n=>{const dx=n.x-wx,dy=n.y-wy;return dx*dx+dy*dy<=(n.r+4)*(n.r+4);}); };
|
|
161
|
-
let panning=false, px=0, py=0;
|
|
162
|
-
cv.addEventListener('mousedown',e=>{ const n=pick(e.clientX,e.clientY); if(n){dragNode=n;hot=true;heat=150;} else {panning=true;px=e.clientX;py=e.clientY;} });
|
|
163
|
-
addEventListener('mousemove',e=>{
|
|
164
|
-
if(dragNode){ const [wx,wy]=toWorld(e.clientX,e.clientY); dragNode.x=wx; dragNode.y=wy; }
|
|
165
|
-
else if(panning){ panX+=e.clientX-px; panY+=e.clientY-py; px=e.clientX; py=e.clientY; }
|
|
166
|
-
});
|
|
167
|
-
addEventListener('mouseup',e=>{
|
|
168
|
-
if(dragNode===null && !panning) return;
|
|
169
|
-
if(dragNode){ dragNode=null; }
|
|
170
|
-
panning=false;
|
|
171
|
-
});
|
|
172
|
-
cv.addEventListener('click',e=>{
|
|
173
|
-
const n=pick(e.clientX,e.clientY); const info=document.getElementById('info');
|
|
174
|
-
if(n){ info.style.display='block'; info.innerHTML='<b>'+n.title+'</b><br><span style="opacity:.7">'+n.id+'</span><br>tipo: '+n.type+' \xB7 conexiones: '+n.deg+' \xB7 usos: '+n.hits; }
|
|
175
|
-
else info.style.display='none';
|
|
176
|
-
});
|
|
177
|
-
cv.addEventListener('wheel',e=>{
|
|
178
|
-
e.preventDefault();
|
|
179
|
-
const f = e.deltaY<0?1.1:0.9;
|
|
180
|
-
panX = e.clientX-(e.clientX-panX)*f; panY = e.clientY-(e.clientY-panY)*f; zoom*=f;
|
|
181
|
-
},{passive:false});
|
|
182
|
-
</script>
|
|
183
|
-
</body>
|
|
184
|
-
</html>`;
|
|
185
|
-
}
|
|
186
|
-
function openBrowser(url) {
|
|
187
|
-
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
188
|
-
const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
|
|
189
|
-
try {
|
|
190
|
-
spawn(cmd, args, { detached: true, stdio: "ignore" }).unref();
|
|
191
|
-
} catch {
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
async function serveGraph(vault, opts = {}) {
|
|
195
|
-
const idx = VaultIndex.load(vault);
|
|
196
|
-
await idx.refresh(false).catch(() => {
|
|
197
|
-
});
|
|
198
|
-
const html = renderGraphHtml(buildGraphData(idx));
|
|
199
|
-
if (opts.out) {
|
|
200
|
-
const file = path.resolve(opts.out);
|
|
201
|
-
fs.writeFileSync(file, html);
|
|
202
|
-
return file;
|
|
203
|
-
}
|
|
204
|
-
return new Promise((resolve) => {
|
|
205
|
-
const server = http.createServer((_req, res) => {
|
|
206
|
-
res.writeHead(200, { "content-type": "text/html; charset=utf-8" });
|
|
207
|
-
res.end(html);
|
|
208
|
-
});
|
|
209
|
-
server.listen(0, "127.0.0.1", () => {
|
|
210
|
-
const addr = server.address();
|
|
211
|
-
const port = typeof addr === "object" && addr ? addr.port : 0;
|
|
212
|
-
const url = `http://127.0.0.1:${port}`;
|
|
213
|
-
if (opts.open !== false) openBrowser(url);
|
|
214
|
-
resolve(url);
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
|
|
219
49
|
// src/skills/recommend.ts
|
|
220
|
-
import
|
|
50
|
+
import fs from "fs";
|
|
221
51
|
import os from "os";
|
|
222
|
-
import
|
|
52
|
+
import path from "path";
|
|
223
53
|
import { execFileSync } from "child_process";
|
|
224
54
|
var RULES = [
|
|
225
55
|
{ skill: "pdf-report-gen", keywords: ["pdf", "reporte pdf", "membrete"] },
|
|
@@ -239,7 +69,7 @@ var RULES = [
|
|
|
239
69
|
];
|
|
240
70
|
var MIN_MENTIONS = 3;
|
|
241
71
|
function localSkillsRepo() {
|
|
242
|
-
return
|
|
72
|
+
return path.join(os.homedir(), "Documents", "Projects", "Skills");
|
|
243
73
|
}
|
|
244
74
|
function recommendSkills(vault, installedDirs) {
|
|
245
75
|
const idx = VaultIndex.load(vault);
|
|
@@ -247,7 +77,7 @@ function recommendSkills(vault, installedDirs) {
|
|
|
247
77
|
const installed = /* @__PURE__ */ new Set();
|
|
248
78
|
for (const dir of installedDirs) {
|
|
249
79
|
try {
|
|
250
|
-
for (const e of
|
|
80
|
+
for (const e of fs.readdirSync(dir)) installed.add(e);
|
|
251
81
|
} catch {
|
|
252
82
|
}
|
|
253
83
|
}
|
|
@@ -263,7 +93,7 @@ function recommendSkills(vault, installedDirs) {
|
|
|
263
93
|
mentions += count;
|
|
264
94
|
}
|
|
265
95
|
if (mentions >= MIN_MENTIONS) {
|
|
266
|
-
const local =
|
|
96
|
+
const local = fs.existsSync(path.join(localSkillsRepo(), rule.skill));
|
|
267
97
|
out.push({
|
|
268
98
|
skill: rule.skill,
|
|
269
99
|
mentions,
|
|
@@ -275,12 +105,12 @@ function recommendSkills(vault, installedDirs) {
|
|
|
275
105
|
return out.sort((a, b) => b.mentions - a.mentions);
|
|
276
106
|
}
|
|
277
107
|
function installSkill(rec, targetDir) {
|
|
278
|
-
|
|
279
|
-
const dest =
|
|
280
|
-
if (
|
|
108
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
109
|
+
const dest = path.join(targetDir, rec.skill);
|
|
110
|
+
if (fs.existsSync(dest)) return { ok: true, detail: "ya instalada" };
|
|
281
111
|
if (rec.source === "local") {
|
|
282
112
|
try {
|
|
283
|
-
|
|
113
|
+
fs.cpSync(path.join(localSkillsRepo(), rec.skill), dest, { recursive: true });
|
|
284
114
|
return { ok: true, detail: `copiada desde ${localSkillsRepo()}` };
|
|
285
115
|
} catch (e) {
|
|
286
116
|
return { ok: false, detail: `error copiando: ${e.message}` };
|
|
@@ -290,7 +120,7 @@ function installSkill(rec, targetDir) {
|
|
|
290
120
|
execFileSync("npx", ["--yes", "skills", "add", rec.skill, "--yes"], {
|
|
291
121
|
stdio: "pipe",
|
|
292
122
|
timeout: 12e4,
|
|
293
|
-
cwd:
|
|
123
|
+
cwd: path.dirname(targetDir)
|
|
294
124
|
});
|
|
295
125
|
return { ok: true, detail: "instalada desde skills.sh" };
|
|
296
126
|
} catch {
|
|
@@ -302,22 +132,22 @@ function installSkill(rec, targetDir) {
|
|
|
302
132
|
}
|
|
303
133
|
|
|
304
134
|
// src/core/agents.ts
|
|
305
|
-
import
|
|
135
|
+
import fs2 from "fs";
|
|
306
136
|
import os2 from "os";
|
|
307
|
-
import
|
|
137
|
+
import path2 from "path";
|
|
308
138
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
309
|
-
var serverScript = () =>
|
|
139
|
+
var serverScript = () => path2.join(distDir(), "mcp", "server.js");
|
|
310
140
|
function readJsonSafe(file) {
|
|
311
141
|
try {
|
|
312
|
-
return JSON.parse(
|
|
142
|
+
return JSON.parse(fs2.readFileSync(file, "utf8"));
|
|
313
143
|
} catch {
|
|
314
|
-
if (
|
|
144
|
+
if (fs2.existsSync(file)) throw new Error(`no pude parsear ${file} \u2014 rev\xEDsalo manualmente`);
|
|
315
145
|
return {};
|
|
316
146
|
}
|
|
317
147
|
}
|
|
318
148
|
function writeJson(file, data) {
|
|
319
|
-
|
|
320
|
-
|
|
149
|
+
fs2.mkdirSync(path2.dirname(file), { recursive: true });
|
|
150
|
+
fs2.writeFileSync(file, JSON.stringify(data, null, 2) + "\n");
|
|
321
151
|
}
|
|
322
152
|
function mergeMcpServers(file, key = "mcpServers") {
|
|
323
153
|
try {
|
|
@@ -332,11 +162,11 @@ function mergeMcpServers(file, key = "mcpServers") {
|
|
|
332
162
|
}
|
|
333
163
|
}
|
|
334
164
|
function home(...p) {
|
|
335
|
-
return
|
|
165
|
+
return path2.join(os2.homedir(), ...p);
|
|
336
166
|
}
|
|
337
167
|
function vscodeUserDir() {
|
|
338
168
|
if (process.platform === "darwin") return home("Library", "Application Support", "Code", "User");
|
|
339
|
-
if (process.platform === "win32") return
|
|
169
|
+
if (process.platform === "win32") return path2.join(process.env.APPDATA ?? home("AppData", "Roaming"), "Code", "User");
|
|
340
170
|
return home(".config", "Code", "User");
|
|
341
171
|
}
|
|
342
172
|
var AGENTS = [
|
|
@@ -344,9 +174,9 @@ var AGENTS = [
|
|
|
344
174
|
id: "claude",
|
|
345
175
|
name: "Claude Code",
|
|
346
176
|
supportsProject: true,
|
|
347
|
-
detect: () =>
|
|
177
|
+
detect: () => fs2.existsSync(home(".claude")),
|
|
348
178
|
register(scope, projectDir) {
|
|
349
|
-
if (scope === "project") return mergeMcpServers(
|
|
179
|
+
if (scope === "project") return mergeMcpServers(path2.join(projectDir, ".mcp.json"));
|
|
350
180
|
return mergeMcpServers(home(".claude.json"));
|
|
351
181
|
}
|
|
352
182
|
},
|
|
@@ -354,9 +184,9 @@ var AGENTS = [
|
|
|
354
184
|
id: "cursor",
|
|
355
185
|
name: "Cursor",
|
|
356
186
|
supportsProject: true,
|
|
357
|
-
detect: () =>
|
|
187
|
+
detect: () => fs2.existsSync(home(".cursor")),
|
|
358
188
|
register(scope, projectDir) {
|
|
359
|
-
const file = scope === "project" ?
|
|
189
|
+
const file = scope === "project" ? path2.join(projectDir, ".cursor", "mcp.json") : home(".cursor", "mcp.json");
|
|
360
190
|
return mergeMcpServers(file);
|
|
361
191
|
}
|
|
362
192
|
},
|
|
@@ -364,9 +194,9 @@ var AGENTS = [
|
|
|
364
194
|
id: "opencode",
|
|
365
195
|
name: "OpenCode",
|
|
366
196
|
supportsProject: true,
|
|
367
|
-
detect: () =>
|
|
197
|
+
detect: () => fs2.existsSync(home(".config", "opencode")) || fs2.existsSync(home(".opencode")),
|
|
368
198
|
register(scope, projectDir) {
|
|
369
|
-
const file = scope === "project" ?
|
|
199
|
+
const file = scope === "project" ? path2.join(projectDir, "opencode.json") : home(".config", "opencode", "opencode.json");
|
|
370
200
|
try {
|
|
371
201
|
const cfg = readJsonSafe(file);
|
|
372
202
|
cfg["$schema"] ??= "https://opencode.ai/config.json";
|
|
@@ -384,7 +214,7 @@ var AGENTS = [
|
|
|
384
214
|
id: "windsurf",
|
|
385
215
|
name: "Windsurf",
|
|
386
216
|
supportsProject: false,
|
|
387
|
-
detect: () =>
|
|
217
|
+
detect: () => fs2.existsSync(home(".codeium", "windsurf")),
|
|
388
218
|
register() {
|
|
389
219
|
return mergeMcpServers(home(".codeium", "windsurf", "mcp_config.json"));
|
|
390
220
|
}
|
|
@@ -393,9 +223,9 @@ var AGENTS = [
|
|
|
393
223
|
id: "cline",
|
|
394
224
|
name: "Cline (VS Code)",
|
|
395
225
|
supportsProject: false,
|
|
396
|
-
detect: () =>
|
|
226
|
+
detect: () => fs2.existsSync(path2.join(vscodeUserDir(), "globalStorage", "saoudrizwan.claude-dev")),
|
|
397
227
|
register() {
|
|
398
|
-
const file =
|
|
228
|
+
const file = path2.join(
|
|
399
229
|
vscodeUserDir(),
|
|
400
230
|
"globalStorage",
|
|
401
231
|
"saoudrizwan.claude-dev",
|
|
@@ -409,7 +239,7 @@ var AGENTS = [
|
|
|
409
239
|
id: "codex",
|
|
410
240
|
name: "Codex CLI (OpenAI)",
|
|
411
241
|
supportsProject: false,
|
|
412
|
-
detect: () =>
|
|
242
|
+
detect: () => fs2.existsSync(home(".codex")),
|
|
413
243
|
register() {
|
|
414
244
|
const file = home(".codex", "config.toml");
|
|
415
245
|
const block = `[mcp_servers.alexandria]
|
|
@@ -419,7 +249,7 @@ args = ["${serverScript().replace(/\\/g, "\\\\")}"]
|
|
|
419
249
|
try {
|
|
420
250
|
let text = "";
|
|
421
251
|
try {
|
|
422
|
-
text =
|
|
252
|
+
text = fs2.readFileSync(file, "utf8");
|
|
423
253
|
} catch {
|
|
424
254
|
}
|
|
425
255
|
if (/^\[mcp_servers\.alexandria\]/m.test(text)) {
|
|
@@ -427,8 +257,8 @@ args = ["${serverScript().replace(/\\/g, "\\\\")}"]
|
|
|
427
257
|
} else {
|
|
428
258
|
text = text.trimEnd() + (text.trim() ? "\n\n" : "") + block;
|
|
429
259
|
}
|
|
430
|
-
|
|
431
|
-
|
|
260
|
+
fs2.mkdirSync(path2.dirname(file), { recursive: true });
|
|
261
|
+
fs2.writeFileSync(file, text);
|
|
432
262
|
return { ok: true, file };
|
|
433
263
|
} catch (e) {
|
|
434
264
|
return { ok: false, file, detail: e.message };
|
|
@@ -439,9 +269,9 @@ args = ["${serverScript().replace(/\\/g, "\\\\")}"]
|
|
|
439
269
|
id: "gemini",
|
|
440
270
|
name: "Gemini CLI",
|
|
441
271
|
supportsProject: true,
|
|
442
|
-
detect: () =>
|
|
272
|
+
detect: () => fs2.existsSync(home(".gemini")),
|
|
443
273
|
register(scope, projectDir) {
|
|
444
|
-
const file = scope === "project" ?
|
|
274
|
+
const file = scope === "project" ? path2.join(projectDir, ".gemini", "settings.json") : home(".gemini", "settings.json");
|
|
445
275
|
return mergeMcpServers(file);
|
|
446
276
|
}
|
|
447
277
|
},
|
|
@@ -449,7 +279,7 @@ args = ["${serverScript().replace(/\\/g, "\\\\")}"]
|
|
|
449
279
|
id: "openclaw",
|
|
450
280
|
name: "OpenClaw",
|
|
451
281
|
supportsProject: false,
|
|
452
|
-
detect: () =>
|
|
282
|
+
detect: () => fs2.existsSync(home(".openclaw")),
|
|
453
283
|
register() {
|
|
454
284
|
const file = home(".openclaw", "openclaw.json");
|
|
455
285
|
try {
|
|
@@ -468,7 +298,7 @@ args = ["${serverScript().replace(/\\/g, "\\\\")}"]
|
|
|
468
298
|
id: "hermes",
|
|
469
299
|
name: "Hermes Agent (Nous)",
|
|
470
300
|
supportsProject: false,
|
|
471
|
-
detect: () =>
|
|
301
|
+
detect: () => fs2.existsSync(home(".hermes")),
|
|
472
302
|
register() {
|
|
473
303
|
const file = home(".hermes", "config.yaml");
|
|
474
304
|
try {
|
|
@@ -482,7 +312,7 @@ args = ["${serverScript().replace(/\\/g, "\\\\")}"]
|
|
|
482
312
|
try {
|
|
483
313
|
let text = "";
|
|
484
314
|
try {
|
|
485
|
-
text =
|
|
315
|
+
text = fs2.readFileSync(file, "utf8");
|
|
486
316
|
} catch {
|
|
487
317
|
}
|
|
488
318
|
if (/^\s*alexandria:/m.test(text)) return { ok: true, file, detail: "ya registrado" };
|
|
@@ -500,8 +330,8 @@ ${entry.trimEnd()}`);
|
|
|
500
330
|
} else {
|
|
501
331
|
text = text.trimEnd() + (text.trim() ? "\n\n" : "") + "mcp_servers:\n" + entry;
|
|
502
332
|
}
|
|
503
|
-
|
|
504
|
-
|
|
333
|
+
fs2.mkdirSync(path2.dirname(file), { recursive: true });
|
|
334
|
+
fs2.writeFileSync(file, text);
|
|
505
335
|
return { ok: true, file };
|
|
506
336
|
} catch (e) {
|
|
507
337
|
return { ok: false, file, detail: e.message };
|
|
@@ -512,9 +342,9 @@ ${entry.trimEnd()}`);
|
|
|
512
342
|
id: "vscode",
|
|
513
343
|
name: "VS Code (Copilot)",
|
|
514
344
|
supportsProject: true,
|
|
515
|
-
detect: () =>
|
|
345
|
+
detect: () => fs2.existsSync(vscodeUserDir()),
|
|
516
346
|
register(scope, projectDir) {
|
|
517
|
-
const file = scope === "project" ?
|
|
347
|
+
const file = scope === "project" ? path2.join(projectDir, ".vscode", "mcp.json") : path2.join(vscodeUserDir(), "mcp.json");
|
|
518
348
|
try {
|
|
519
349
|
const cfg = readJsonSafe(file);
|
|
520
350
|
const servers = cfg["servers"] ?? {};
|
|
@@ -660,7 +490,7 @@ program.command("init").description("Crea/conecta la b\xF3veda e instala TODO: m
|
|
|
660
490
|
).action(async (opts) => {
|
|
661
491
|
const isProject = Boolean(opts.project) && !opts.global;
|
|
662
492
|
const cwd = process.cwd();
|
|
663
|
-
const vaultPath =
|
|
493
|
+
const vaultPath = path3.resolve(opts.path ?? (isProject ? path3.join(cwd, "KnowledgeVault") : defaultVaultPath()));
|
|
664
494
|
await showBanner();
|
|
665
495
|
console.log(pc.bold(`Instalaci\xF3n ${isProject ? "por proyecto" : "global"}
|
|
666
496
|
`));
|
|
@@ -718,7 +548,7 @@ program.command("add").description("Guardar una nota manualmente").argument("<ti
|
|
|
718
548
|
const { vault } = await ensureReady();
|
|
719
549
|
let content = opts.content;
|
|
720
550
|
if (!content && !process.stdin.isTTY) {
|
|
721
|
-
content =
|
|
551
|
+
content = fs3.readFileSync(0, "utf8");
|
|
722
552
|
}
|
|
723
553
|
const file = createNote(vault.managed, {
|
|
724
554
|
title,
|
|
@@ -726,7 +556,7 @@ program.command("add").description("Guardar una nota manualmente").argument("<ti
|
|
|
726
556
|
tags: opts.tags ? opts.tags.split(",").map((t) => t.trim()) : []
|
|
727
557
|
});
|
|
728
558
|
await VaultIndex.load(vault).refresh();
|
|
729
|
-
console.log(pc.green(`\u2713 ${
|
|
559
|
+
console.log(pc.green(`\u2713 ${path3.relative(vault.root, file)}`));
|
|
730
560
|
});
|
|
731
561
|
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) => {
|
|
732
562
|
const vault = getVault();
|
|
@@ -800,7 +630,7 @@ program.command("stats").description("Estado de la b\xF3veda y tokens ahorrados"
|
|
|
800
630
|
async function runSkills(opts) {
|
|
801
631
|
const { vault } = await ensureReady();
|
|
802
632
|
const cwd = process.cwd();
|
|
803
|
-
const targetDir = opts.project ?
|
|
633
|
+
const targetDir = opts.project ? path3.join(cwd, ".claude", "skills") : path3.join(process.env.HOME ?? process.env.USERPROFILE ?? cwd, ".claude", "skills");
|
|
804
634
|
const recs = recommendSkills(vault, [targetDir]);
|
|
805
635
|
if (recs.length === 0) {
|
|
806
636
|
console.log(pc.dim("Sin recomendaciones nuevas: la b\xF3veda a\xFAn no tiene suficientes patrones (o ya est\xE1 todo instalado)."));
|
package/dist/hooks/on-prompt.js
CHANGED
|
@@ -9,14 +9,14 @@ import {
|
|
|
9
9
|
} from "../chunk-DEDAOKAV.js";
|
|
10
10
|
import {
|
|
11
11
|
hybridSearch
|
|
12
|
-
} from "../chunk-
|
|
13
|
-
import "../chunk-
|
|
12
|
+
} from "../chunk-FID2RAOH.js";
|
|
13
|
+
import "../chunk-VN7QOAG2.js";
|
|
14
14
|
import {
|
|
15
15
|
createNote,
|
|
16
16
|
resolveVault,
|
|
17
17
|
touchNote,
|
|
18
18
|
vaultExists
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-CF2GLMR3.js";
|
|
20
20
|
import "../chunk-EDYBSJSS.js";
|
|
21
21
|
|
|
22
22
|
// src/hooks/on-prompt.ts
|
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
} from "../chunk-DEDAOKAV.js";
|
|
10
10
|
import {
|
|
11
11
|
VaultIndex
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-VN7QOAG2.js";
|
|
13
13
|
import {
|
|
14
14
|
resolveVault,
|
|
15
15
|
vaultExists
|
|
16
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-CF2GLMR3.js";
|
|
17
17
|
import "../chunk-EDYBSJSS.js";
|
|
18
18
|
|
|
19
19
|
// src/hooks/on-session-start.ts
|
package/dist/hooks/on-stop.js
CHANGED
package/dist/mcp/server.js
CHANGED
|
@@ -4,17 +4,17 @@ import {
|
|
|
4
4
|
} from "../chunk-KHTYRYDR.js";
|
|
5
5
|
import {
|
|
6
6
|
hybridSearch
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-FID2RAOH.js";
|
|
8
8
|
import {
|
|
9
9
|
VaultIndex
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-VN7QOAG2.js";
|
|
11
11
|
import {
|
|
12
12
|
createNote,
|
|
13
13
|
ensureVaultStructure,
|
|
14
14
|
resolveVault,
|
|
15
15
|
slugify,
|
|
16
16
|
upsertNote
|
|
17
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-CF2GLMR3.js";
|
|
18
18
|
import "../chunk-EDYBSJSS.js";
|
|
19
19
|
|
|
20
20
|
// src/mcp/server.ts
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
buildGraphData,
|
|
4
|
+
renderGraphHtml,
|
|
5
|
+
serveGraph,
|
|
6
|
+
writeStaticGraph
|
|
7
|
+
} from "./chunk-I2ZBQUZD.js";
|
|
8
|
+
import "./chunk-VN7QOAG2.js";
|
|
9
|
+
import "./chunk-CF2GLMR3.js";
|
|
10
|
+
import "./chunk-EDYBSJSS.js";
|
|
11
|
+
export {
|
|
12
|
+
buildGraphData,
|
|
13
|
+
renderGraphHtml,
|
|
14
|
+
serveGraph,
|
|
15
|
+
writeStaticGraph
|
|
16
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ureck/alexandria",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|