@ureck/alexandria 0.3.0 → 0.4.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 +10 -9
- package/dist/{chunk-FID2RAOH.js → chunk-ADHRHLX7.js} +1 -1
- package/dist/chunk-JPHL2JHE.js +148 -0
- package/dist/chunk-KB6KYZFQ.js +99 -0
- package/dist/{chunk-I2ZBQUZD.js → chunk-WPNU64MA.js} +28 -12
- package/dist/{chunk-VN7QOAG2.js → chunk-ZW7XY3EN.js} +5 -4
- package/dist/cli.js +185 -17
- package/dist/hooks/on-prompt.js +16 -7
- package/dist/hooks/on-session-start.js +5 -4
- package/dist/hooks/on-stop.js +4 -2
- package/dist/mcp/server.js +16 -5
- package/dist/{viewer-LD4RTZE7.js → viewer-FRJYOK3S.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-CF2GLMR3.js +0 -241
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ Confirma que quedó instalado:
|
|
|
38
38
|
|
|
39
39
|
```bash
|
|
40
40
|
$ ale --version
|
|
41
|
-
0.
|
|
41
|
+
0.4.0
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
## Primeros pasos
|
|
@@ -46,10 +46,10 @@ $ ale --version
|
|
|
46
46
|
Un solo comando instala todo (modelo de embeddings ~130MB una única vez, hooks, MCP, índice):
|
|
47
47
|
|
|
48
48
|
```bash
|
|
49
|
-
# Global — una bóveda compartida para todas tus sesiones (~/
|
|
49
|
+
# Global — una bóveda compartida para todas tus sesiones (~/Alexandria)
|
|
50
50
|
ale init
|
|
51
51
|
|
|
52
|
-
# Por proyecto — bóveda DENTRO del repo (./
|
|
52
|
+
# Por proyecto — bóveda DENTRO del repo (./Alexandria)
|
|
53
53
|
cd mi-proyecto
|
|
54
54
|
ale init --project
|
|
55
55
|
|
|
@@ -72,7 +72,7 @@ ale init --agents claude,cursor,opencode # solo esos
|
|
|
72
72
|
|
|
73
73
|
Instalación por proyecto
|
|
74
74
|
|
|
75
|
-
✓ Bóveda en /Users/tu/mi-proyecto/
|
|
75
|
+
✓ Bóveda en /Users/tu/mi-proyecto/Alexandria (vault Obsidian válido)
|
|
76
76
|
✓ Config del proyecto: /Users/tu/mi-proyecto/.vault.json
|
|
77
77
|
✓ Hooks registrados en /Users/tu/mi-proyecto/.claude/settings.json
|
|
78
78
|
SessionStart (digest) · UserPromptSubmit (contexto+captura) · Stop/PreCompact (sesiones)
|
|
@@ -88,7 +88,7 @@ Instalación por proyecto
|
|
|
88
88
|
|
|
89
89
|
Después de `init` no hay nada que reconectar, nunca. Importante: los hooks cargan **al arrancar** una sesión — abre una sesión *nueva* de tu agente en esa carpeta (una que ya estaba abierta no los verá). Desde ahí, cada prompt busca en la bóveda antes de gastar tokens y cada cierre de sesión guarda lo aprendido.
|
|
90
90
|
|
|
91
|
-
>
|
|
91
|
+
> `ale init --project` también agrega la bóveda a tu `.gitignore` automáticamente, escanea el proyecto (stack, estructura, comandos → mapa inicial) y te ofrece configurar en `CLAUDE.md` que Claude use Alexandria por default en cada sesión (`--auto` / `--manual` para decidir sin pregunta).
|
|
92
92
|
|
|
93
93
|
## Uso diario — ejemplos
|
|
94
94
|
|
|
@@ -138,7 +138,7 @@ ale graph # visor EN VIVO en tu navegador: se actualiza solo
|
|
|
138
138
|
ale graph --out otro.html # copia estática a otra ruta (opcional)
|
|
139
139
|
```
|
|
140
140
|
|
|
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.
|
|
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, y **filtros por tipo estilo Obsidian** (los prompts vienen ocultos por default — son ruido visual; actívalos con su checkbox). El grafo brilla a partir de ~20-30 notas — es acumulativo por diseño.
|
|
142
142
|
|
|
143
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.
|
|
144
144
|
|
|
@@ -147,7 +147,7 @@ Nodos = notas (tamaño = conexiones, color = tipo), líneas sólidas = `[[wikili
|
|
|
147
147
|
```bash
|
|
148
148
|
$ ale stats
|
|
149
149
|
|
|
150
|
-
🧠 Bóveda: /Users/tu/
|
|
150
|
+
🧠 Bóveda: /Users/tu/Alexandria (global)
|
|
151
151
|
Notas: 142 {"note":80,"prompt":38,"session":22,"map":2}
|
|
152
152
|
Chunks indexados: 385 · Conexiones: 91
|
|
153
153
|
Búsqueda semántica: activa
|
|
@@ -242,7 +242,7 @@ En cualquier agente conectado, pídele cosas como *"busca en mi bóveda cómo co
|
|
|
242
242
|
|
|
243
243
|
| Comando | Qué hace |
|
|
244
244
|
|---|---|
|
|
245
|
-
| `ale init [--project] [--path <dir>] [--agents <ids>] [--
|
|
245
|
+
| `ale init [--project] [--path <dir>] [--agents <ids>] [--auto\|--manual]` | Instala todo: bóveda (default `./Alexandria` / `~/Alexandria`), hooks, MCP, .gitignore, escaneo inicial y CLAUDE.md |
|
|
246
246
|
| `ale agents [ids] [--project]` | Lista agentes / registra el MCP en ellos |
|
|
247
247
|
| `ale search <query> [-k n] [--expand]` | Búsqueda híbrida; `--expand` trae vecinos del grafo |
|
|
248
248
|
| `ale add <título> [-c texto] [-t tags]` | Guardar nota manual (o por stdin) |
|
|
@@ -251,6 +251,7 @@ En cualquier agente conectado, pídele cosas como *"busca en mi bóveda cómo co
|
|
|
251
251
|
| `ale stats` | Notas, conexiones y tokens ahorrados estimados |
|
|
252
252
|
| `ale reindex [--force]` | Reindexar (incremental por default) |
|
|
253
253
|
| `ale doctor [--project]` | Verifica y repara: modelo, hooks, MCP, índice |
|
|
254
|
+
| `ale consolidate [--days n] [--dry]` | Archiva prompts viejos sin reuso — fuera del grafo/inyección, siguen buscables: nada se pierde |
|
|
254
255
|
| `ale uninstall [--project]` | Quita hooks (las notas quedan intactas) |
|
|
255
256
|
| `ale --vault <ruta> <comando>` | Cualquier comando contra otra bóveda |
|
|
256
257
|
|
|
@@ -266,7 +267,7 @@ En cualquier agente conectado, pídele cosas como *"busca en mi bóveda cómo co
|
|
|
266
267
|
## V2 (roadmap)
|
|
267
268
|
|
|
268
269
|
- Bot de Telegram (grammY, polling local — sin servidor público): `/search`, `/save` desde el teléfono.
|
|
269
|
-
|
|
270
|
+
|
|
270
271
|
|
|
271
272
|
## Código y contribuciones
|
|
272
273
|
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/core/notes.ts
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import matter from "gray-matter";
|
|
7
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set([".obsidian", ".vault", ".trash", ".git", "node_modules"]);
|
|
8
|
+
function extractWikilinks(content) {
|
|
9
|
+
const out = /* @__PURE__ */ new Set();
|
|
10
|
+
const re = /\[\[([^\]|#\n]+)(?:[|#][^\]]*)?\]\]/g;
|
|
11
|
+
let m;
|
|
12
|
+
while ((m = re.exec(content)) !== null) {
|
|
13
|
+
const target = m[1].trim();
|
|
14
|
+
if (target) out.add(target);
|
|
15
|
+
}
|
|
16
|
+
return [...out];
|
|
17
|
+
}
|
|
18
|
+
function slugify(text) {
|
|
19
|
+
return text.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80) || "nota";
|
|
20
|
+
}
|
|
21
|
+
function listMarkdownFiles(root) {
|
|
22
|
+
const out = [];
|
|
23
|
+
const walk = (dir) => {
|
|
24
|
+
let entries;
|
|
25
|
+
try {
|
|
26
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
27
|
+
} catch {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
for (const e of entries) {
|
|
31
|
+
if (e.name.startsWith(".") || SKIP_DIRS.has(e.name)) continue;
|
|
32
|
+
const full = path.join(dir, e.name);
|
|
33
|
+
if (e.isDirectory()) walk(full);
|
|
34
|
+
else if (e.isFile() && e.name.endsWith(".md")) out.push(full);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
walk(root);
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
function parseNote(root, absPath) {
|
|
41
|
+
const raw = fs.readFileSync(absPath, "utf8");
|
|
42
|
+
const { data, content } = matter(raw);
|
|
43
|
+
const rel = path.relative(root, absPath).split(path.sep).join("/");
|
|
44
|
+
const title = typeof data.title === "string" && data.title || path.basename(absPath, ".md");
|
|
45
|
+
const type = ["note", "prompt", "session", "map"].includes(data.type) ? data.type : "note";
|
|
46
|
+
const tags = Array.isArray(data.tags) ? data.tags.map(String) : [];
|
|
47
|
+
return {
|
|
48
|
+
rel,
|
|
49
|
+
title,
|
|
50
|
+
type,
|
|
51
|
+
tags,
|
|
52
|
+
created: data.created ? String(data.created) : void 0,
|
|
53
|
+
hits: typeof data.hits === "number" ? data.hits : 1,
|
|
54
|
+
content,
|
|
55
|
+
links: extractWikilinks(content)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function frontmatter(n) {
|
|
59
|
+
const lines = [
|
|
60
|
+
"---",
|
|
61
|
+
`title: ${JSON.stringify(n.title)}`,
|
|
62
|
+
// aliases: Obsidian resuelve [[wikilinks]] contra alias, no contra el title
|
|
63
|
+
// del frontmatter — sin esto su graph view muestra los enlaces como rotos
|
|
64
|
+
`aliases: [${JSON.stringify(n.title)}]`,
|
|
65
|
+
`type: ${n.type}`,
|
|
66
|
+
`tags: [${n.tags.map((t) => JSON.stringify(t)).join(", ")}]`,
|
|
67
|
+
`created: ${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
68
|
+
`hits: ${n.hits ?? 1}`,
|
|
69
|
+
"---",
|
|
70
|
+
""
|
|
71
|
+
];
|
|
72
|
+
return lines.join("\n");
|
|
73
|
+
}
|
|
74
|
+
function ensureAlias(absPath) {
|
|
75
|
+
try {
|
|
76
|
+
const raw = fs.readFileSync(absPath, "utf8");
|
|
77
|
+
const { data, content } = matter(raw);
|
|
78
|
+
if (!data.title || data.aliases) return false;
|
|
79
|
+
data.aliases = [String(data.title)];
|
|
80
|
+
fs.writeFileSync(absPath, matter.stringify(content, data));
|
|
81
|
+
return true;
|
|
82
|
+
} catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function createNote(managed, n) {
|
|
87
|
+
const dir = path.join(managed, n.dir ?? "notes");
|
|
88
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
89
|
+
const date = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
90
|
+
const base = `${date}-${slugify(n.title)}`;
|
|
91
|
+
let file = path.join(dir, `${base}.md`);
|
|
92
|
+
let i = 2;
|
|
93
|
+
while (fs.existsSync(file)) file = path.join(dir, `${base}-${i++}.md`);
|
|
94
|
+
fs.writeFileSync(
|
|
95
|
+
file,
|
|
96
|
+
frontmatter({ title: n.title, type: n.type ?? "note", tags: n.tags ?? [] }) + n.content.trim() + "\n"
|
|
97
|
+
);
|
|
98
|
+
return file;
|
|
99
|
+
}
|
|
100
|
+
function touchNote(absPath) {
|
|
101
|
+
const raw = fs.readFileSync(absPath, "utf8");
|
|
102
|
+
const { data, content } = matter(raw);
|
|
103
|
+
data.hits = (typeof data.hits === "number" ? data.hits : 1) + 1;
|
|
104
|
+
data.updated = (/* @__PURE__ */ new Date()).toISOString();
|
|
105
|
+
fs.writeFileSync(absPath, matter.stringify(content, data));
|
|
106
|
+
}
|
|
107
|
+
function upsertNote(managed, n) {
|
|
108
|
+
const dir = path.join(managed, n.dir ?? "notes");
|
|
109
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
110
|
+
const file = path.join(dir, `${n.fixedName}.md`);
|
|
111
|
+
if (fs.existsSync(file)) {
|
|
112
|
+
const raw = fs.readFileSync(file, "utf8");
|
|
113
|
+
const { data } = matter(raw);
|
|
114
|
+
data.updated = (/* @__PURE__ */ new Date()).toISOString();
|
|
115
|
+
fs.writeFileSync(file, matter.stringify(n.content.trim() + "\n", data));
|
|
116
|
+
} else {
|
|
117
|
+
fs.writeFileSync(
|
|
118
|
+
file,
|
|
119
|
+
frontmatter({ title: n.title, type: n.type ?? "note", tags: n.tags ?? [] }) + n.content.trim() + "\n"
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
return file;
|
|
123
|
+
}
|
|
124
|
+
function appendToNote(managed, n) {
|
|
125
|
+
const dir = path.join(managed, n.dir ?? "sessions");
|
|
126
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
127
|
+
const file = path.join(dir, `${n.fixedName}.md`);
|
|
128
|
+
if (fs.existsSync(file)) {
|
|
129
|
+
fs.appendFileSync(file, "\n" + n.content.trim() + "\n");
|
|
130
|
+
} else {
|
|
131
|
+
fs.writeFileSync(
|
|
132
|
+
file,
|
|
133
|
+
frontmatter({ title: n.title, type: n.type ?? "session", tags: n.tags ?? [] }) + n.content.trim() + "\n"
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
return file;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export {
|
|
140
|
+
slugify,
|
|
141
|
+
listMarkdownFiles,
|
|
142
|
+
parseNote,
|
|
143
|
+
ensureAlias,
|
|
144
|
+
createNote,
|
|
145
|
+
touchNote,
|
|
146
|
+
upsertNote,
|
|
147
|
+
appendToNote
|
|
148
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/core/vault.ts
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import os from "os";
|
|
6
|
+
import path from "path";
|
|
7
|
+
var MANAGED_DIR = "Alexandria";
|
|
8
|
+
function configDir() {
|
|
9
|
+
if (process.platform === "win32" && process.env.APPDATA) {
|
|
10
|
+
return path.join(process.env.APPDATA, "alexandria");
|
|
11
|
+
}
|
|
12
|
+
return path.join(os.homedir(), ".config", "alexandria");
|
|
13
|
+
}
|
|
14
|
+
function globalConfigPath() {
|
|
15
|
+
return path.join(configDir(), "config.json");
|
|
16
|
+
}
|
|
17
|
+
function defaultVaultPath() {
|
|
18
|
+
const legacy = path.join(os.homedir(), "KnowledgeVault");
|
|
19
|
+
if (fs.existsSync(legacy)) return legacy;
|
|
20
|
+
return path.join(os.homedir(), "Alexandria");
|
|
21
|
+
}
|
|
22
|
+
function readJson(file) {
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function findProjectConfig(from) {
|
|
30
|
+
let dir = path.resolve(from);
|
|
31
|
+
for (; ; ) {
|
|
32
|
+
const candidate = path.join(dir, ".vault.json");
|
|
33
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
34
|
+
const parent = path.dirname(dir);
|
|
35
|
+
if (parent === dir) return null;
|
|
36
|
+
dir = parent;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function build(root, source, projectConfig) {
|
|
40
|
+
const managed = path.basename(root).toLowerCase() === MANAGED_DIR.toLowerCase() ? root : path.join(root, MANAGED_DIR);
|
|
41
|
+
return {
|
|
42
|
+
root,
|
|
43
|
+
managed,
|
|
44
|
+
cache: path.join(root, ".vault"),
|
|
45
|
+
source,
|
|
46
|
+
projectConfig
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function resolveVault(opts = {}) {
|
|
50
|
+
if (opts.flag) return build(path.resolve(opts.flag), "flag");
|
|
51
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
52
|
+
const projectFile = findProjectConfig(cwd);
|
|
53
|
+
if (projectFile) {
|
|
54
|
+
const cfg = readJson(projectFile);
|
|
55
|
+
if (cfg?.vaultPath) {
|
|
56
|
+
const base = path.dirname(projectFile);
|
|
57
|
+
return build(path.resolve(base, cfg.vaultPath), "project", projectFile);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const globalCfg = readJson(globalConfigPath());
|
|
61
|
+
if (globalCfg?.vaultPath) return build(globalCfg.vaultPath, "global");
|
|
62
|
+
return build(defaultVaultPath(), "default");
|
|
63
|
+
}
|
|
64
|
+
function vaultExists(v) {
|
|
65
|
+
return fs.existsSync(v.managed) || fs.existsSync(v.cache);
|
|
66
|
+
}
|
|
67
|
+
function ensureVaultStructure(v) {
|
|
68
|
+
for (const dir of [
|
|
69
|
+
v.root,
|
|
70
|
+
v.managed,
|
|
71
|
+
path.join(v.managed, "notes"),
|
|
72
|
+
path.join(v.managed, "prompts"),
|
|
73
|
+
path.join(v.managed, "sessions"),
|
|
74
|
+
v.cache
|
|
75
|
+
]) {
|
|
76
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function writeGlobalConfig(vaultPath) {
|
|
80
|
+
fs.mkdirSync(configDir(), { recursive: true });
|
|
81
|
+
fs.writeFileSync(globalConfigPath(), JSON.stringify({ vaultPath }, null, 2) + "\n");
|
|
82
|
+
}
|
|
83
|
+
function writeProjectConfig(projectDir, vaultPath) {
|
|
84
|
+
const file = path.join(projectDir, ".vault.json");
|
|
85
|
+
const rel = path.relative(projectDir, vaultPath) || ".";
|
|
86
|
+
const stored = rel.startsWith("..") ? vaultPath : rel;
|
|
87
|
+
fs.writeFileSync(file, JSON.stringify({ vaultPath: stored }, null, 2) + "\n");
|
|
88
|
+
return file;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export {
|
|
92
|
+
globalConfigPath,
|
|
93
|
+
defaultVaultPath,
|
|
94
|
+
resolveVault,
|
|
95
|
+
vaultExists,
|
|
96
|
+
ensureVaultStructure,
|
|
97
|
+
writeGlobalConfig,
|
|
98
|
+
writeProjectConfig
|
|
99
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
VaultIndex
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-ZW7XY3EN.js";
|
|
5
5
|
|
|
6
6
|
// src/graph/viewer.ts
|
|
7
7
|
import fs from "fs";
|
|
@@ -15,7 +15,7 @@ function buildGraphData(idx) {
|
|
|
15
15
|
deg.set(l.to, (deg.get(l.to) ?? 0) + 1);
|
|
16
16
|
}
|
|
17
17
|
return {
|
|
18
|
-
nodes: Object.values(idx.meta.notes).map((n) => ({
|
|
18
|
+
nodes: Object.values(idx.meta.notes).filter((n) => !n.rel.split("/").includes("archive")).map((n) => ({
|
|
19
19
|
id: n.rel,
|
|
20
20
|
title: n.title,
|
|
21
21
|
type: n.type,
|
|
@@ -44,6 +44,8 @@ function renderGraphHtml(data, live) {
|
|
|
44
44
|
#hud .sub{color:var(--dim);font-size:12px}
|
|
45
45
|
.leg{display:flex;gap:12px;flex-wrap:wrap;margin-top:8px;font-size:12px;color:var(--dim)}
|
|
46
46
|
.leg b{display:inline-block;width:9px;height:9px;border-radius:50%;margin-right:5px;vertical-align:-1px}
|
|
47
|
+
.leg label{cursor:pointer;user-select:none}
|
|
48
|
+
.leg input{accent-color:#7aa2f7;margin-right:4px;vertical-align:-2px}
|
|
47
49
|
#hint{color:var(--dim);font-size:11px;margin-top:6px}
|
|
48
50
|
#info{bottom:14px;left:14px;padding:12px 16px;max-width:440px;display:none}
|
|
49
51
|
#info b{font-size:14px}
|
|
@@ -60,13 +62,13 @@ function renderGraphHtml(data, live) {
|
|
|
60
62
|
<div id="hud" class="card">
|
|
61
63
|
<h1>\u{1F3DB}\uFE0F Alexandria</h1>
|
|
62
64
|
<div class="sub" id="counts"></div>
|
|
63
|
-
<div class="leg">
|
|
64
|
-
<
|
|
65
|
-
<
|
|
66
|
-
<
|
|
67
|
-
<
|
|
65
|
+
<div class="leg" id="leg">
|
|
66
|
+
<label><input type="checkbox" data-type="note" checked><b style="background:#7aa2f7"></b>nota</label>
|
|
67
|
+
<label><input type="checkbox" data-type="map" checked><b style="background:#f7768e"></b>mapa</label>
|
|
68
|
+
<label><input type="checkbox" data-type="session" checked><b style="background:#9ece6a"></b>sesi\xF3n</label>
|
|
69
|
+
<label><input type="checkbox" data-type="prompt"><b style="background:#e0af68"></b>prompt</label>
|
|
68
70
|
</div>
|
|
69
|
-
<div id="hint">arrastra \xB7 rueda = zoom
|
|
71
|
+
<div id="hint">filtros por tipo (prompts ocultos por default \u2014 ruido) \xB7 arrastra \xB7 rueda = zoom<br>hover = conexiones \xB7 click = detalle \xB7 \u2014 s\xF3lida = [[wikilink]] \xB7 \u2025 punteada = sem\xE1ntica</div>
|
|
70
72
|
</div>
|
|
71
73
|
<div id="search"><input id="q" placeholder="filtrar notas\u2026" autocomplete="off"></div>
|
|
72
74
|
<div id="live" class="card">\u25CF <b>en vivo</b> \u2014 se actualiza solo</div>
|
|
@@ -88,6 +90,11 @@ fit(); addEventListener('resize', () => { fit(); fitView(); });
|
|
|
88
90
|
let nodes = [], byId = new Map(), edges = [];
|
|
89
91
|
let zoom = 1, panX = 0, panY = 0, dragNode = null, hot = true, heat = 300;
|
|
90
92
|
let didFit = false, hover = null, filter = '';
|
|
93
|
+
// filtros por tipo (estilo Obsidian) \u2014 prompts ocultos por default: son ruido visual
|
|
94
|
+
const typeOn = { note: true, map: true, session: true, prompt: false };
|
|
95
|
+
document.querySelectorAll('#leg input').forEach(cb => cb.addEventListener('change', e => {
|
|
96
|
+
typeOn[e.target.dataset.type] = e.target.checked; heat = Math.max(heat, 30); hot = true;
|
|
97
|
+
}));
|
|
91
98
|
function radius(n){ return 5 + Math.min(n.deg,14)*1.1 + Math.min(n.hits,8)*0.6; }
|
|
92
99
|
function loadData(data, keepPositions){
|
|
93
100
|
const old = keepPositions ? byId : new Map();
|
|
@@ -125,14 +132,20 @@ function step(){
|
|
|
125
132
|
let dx = e.b.x-e.a.x, dy = e.b.y-e.a.y;
|
|
126
133
|
const d = Math.sqrt(dx*dx+dy*dy) + 0.01;
|
|
127
134
|
const want = e.type === 'wikilink' ? 120 : 175;
|
|
128
|
-
|
|
135
|
+
// resorte lineal ACOTADO \u2014 jam\xE1s multiplicar por d otra vez (explota a NaN)
|
|
136
|
+
const f = Math.max(-6, Math.min(6, (d - want) * (e.type === 'wikilink' ? 0.03 : 0.015)));
|
|
129
137
|
dx /= d; dy /= d;
|
|
130
|
-
e.a.vx += dx*
|
|
138
|
+
e.a.vx += dx*f; e.a.vy += dy*f; e.b.vx -= dx*f; e.b.vy -= dy*f;
|
|
131
139
|
}
|
|
140
|
+
const VMAX = 14;
|
|
132
141
|
for (const n of nodes){
|
|
133
142
|
n.vx += (W/2 - n.x) * 0.0005; n.vy += (H/2 - n.y) * 0.0005;
|
|
134
143
|
n.vx *= 0.86; n.vy *= 0.86;
|
|
144
|
+
// velocidad acotada + saneo: la simulaci\xF3n no puede reventar con ning\xFAn grafo
|
|
145
|
+
n.vx = Math.max(-VMAX, Math.min(VMAX, n.vx)) || 0;
|
|
146
|
+
n.vy = Math.max(-VMAX, Math.min(VMAX, n.vy)) || 0;
|
|
135
147
|
if (n !== dragNode){ n.x += n.vx; n.y += n.vy; }
|
|
148
|
+
if (!Number.isFinite(n.x) || !Number.isFinite(n.y)){ n.x = W/2; n.y = H/2; n.vx = n.vy = 0; }
|
|
136
149
|
}
|
|
137
150
|
if (--heat <= 0 && !dragNode) { hot = false; if (!didFit) fitView(); }
|
|
138
151
|
}
|
|
@@ -161,9 +174,11 @@ function draw(){
|
|
|
161
174
|
|
|
162
175
|
const active = hover ? new Set([hover, ...edges.filter(e=>e.a===hover||e.b===hover).flatMap(e=>[e.a,e.b])]) : null;
|
|
163
176
|
const match = filter ? new Set(nodes.filter(n => n.title.toLowerCase().includes(filter) || n.tags.join(' ').toLowerCase().includes(filter))) : null;
|
|
177
|
+
const shown = (n) => typeOn[n.type] !== false;
|
|
164
178
|
const visible = (n) => (!active || active.has(n)) && (!match || match.has(n));
|
|
165
179
|
|
|
166
180
|
for (const e of edges){
|
|
181
|
+
if (!shown(e.a) || !shown(e.b)) continue;
|
|
167
182
|
const on = visible(e.a) && visible(e.b) && (!active || e.a===hover || e.b===hover);
|
|
168
183
|
ctx.beginPath();
|
|
169
184
|
ctx.setLineDash(e.type === 'semantic' ? [5,5] : []);
|
|
@@ -177,6 +192,7 @@ function draw(){
|
|
|
177
192
|
ctx.setLineDash([]);
|
|
178
193
|
|
|
179
194
|
for (const n of nodes){
|
|
195
|
+
if (!shown(n)) continue;
|
|
180
196
|
const on = visible(n);
|
|
181
197
|
const color = COLORS[n.type] || '#7aa2f7';
|
|
182
198
|
ctx.globalAlpha = on ? 1 : 0.12;
|
|
@@ -195,7 +211,7 @@ function draw(){
|
|
|
195
211
|
ctx.font = (12/Math.max(zoom,0.8)) + 'px -apple-system,system-ui,sans-serif';
|
|
196
212
|
ctx.lineWidth = 3/Math.max(zoom,0.8); ctx.strokeStyle = '#0b0d13';
|
|
197
213
|
for (const n of nodes){
|
|
198
|
-
if (!visible(n)) continue;
|
|
214
|
+
if (!shown(n) || !visible(n)) continue;
|
|
199
215
|
if (!(showAll || n.deg > 1 || n === hover)) continue;
|
|
200
216
|
const label = n.title.length > 34 ? n.title.slice(0,33)+'\u2026' : n.title;
|
|
201
217
|
ctx.globalAlpha = n === hover ? 1 : 0.85;
|
|
@@ -209,7 +225,7 @@ function draw(){
|
|
|
209
225
|
|
|
210
226
|
// ---------- interacci\xF3n ----------
|
|
211
227
|
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); }); };
|
|
228
|
+
const pick = (x,y) => { const [wx,wy] = toWorld(x,y); return nodes.find(n => { if (typeOn[n.type] === false) return false; const dx=n.x-wx, dy=n.y-wy; return dx*dx+dy*dy <= (n.r+6)*(n.r+6); }); };
|
|
213
229
|
let panning = false, px = 0, py = 0, moved = false;
|
|
214
230
|
const tip = document.getElementById('tip');
|
|
215
231
|
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'); });
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
MANAGED_DIR,
|
|
4
3
|
ensureAlias,
|
|
5
4
|
listMarkdownFiles,
|
|
6
5
|
parseNote
|
|
7
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-JPHL2JHE.js";
|
|
8
7
|
import {
|
|
9
8
|
DIM,
|
|
10
9
|
MODEL_ID,
|
|
@@ -106,7 +105,9 @@ var VaultIndex = class _VaultIndex {
|
|
|
106
105
|
for (const rel of changed) {
|
|
107
106
|
const info = onDisk.get(rel);
|
|
108
107
|
try {
|
|
109
|
-
|
|
108
|
+
const managedRel = path.relative(this.vault.root, this.vault.managed).split(path.sep).join("/");
|
|
109
|
+
const inManaged = managedRel === "" || rel.startsWith(`${managedRel}/`);
|
|
110
|
+
if (inManaged && ensureAlias(info.abs)) {
|
|
110
111
|
info.mtime = fs.statSync(info.abs).mtimeMs;
|
|
111
112
|
}
|
|
112
113
|
const note = parseNote(this.vault.root, info.abs);
|
|
@@ -166,7 +167,7 @@ ${c.text}`),
|
|
|
166
167
|
this.rebuildLinks();
|
|
167
168
|
this.save();
|
|
168
169
|
try {
|
|
169
|
-
const { writeStaticGraph } = await import("./viewer-
|
|
170
|
+
const { writeStaticGraph } = await import("./viewer-FRJYOK3S.js");
|
|
170
171
|
writeStaticGraph(this);
|
|
171
172
|
} catch {
|
|
172
173
|
}
|
package/dist/cli.js
CHANGED
|
@@ -16,15 +16,8 @@ import {
|
|
|
16
16
|
} from "./chunk-KHTYRYDR.js";
|
|
17
17
|
import {
|
|
18
18
|
hybridSearch
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-ADHRHLX7.js";
|
|
20
20
|
import {
|
|
21
|
-
serveGraph
|
|
22
|
-
} from "./chunk-I2ZBQUZD.js";
|
|
23
|
-
import {
|
|
24
|
-
VaultIndex
|
|
25
|
-
} from "./chunk-VN7QOAG2.js";
|
|
26
|
-
import {
|
|
27
|
-
createNote,
|
|
28
21
|
defaultVaultPath,
|
|
29
22
|
ensureVaultStructure,
|
|
30
23
|
globalConfigPath,
|
|
@@ -32,7 +25,18 @@ import {
|
|
|
32
25
|
vaultExists,
|
|
33
26
|
writeGlobalConfig,
|
|
34
27
|
writeProjectConfig
|
|
35
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-KB6KYZFQ.js";
|
|
29
|
+
import {
|
|
30
|
+
serveGraph
|
|
31
|
+
} from "./chunk-WPNU64MA.js";
|
|
32
|
+
import {
|
|
33
|
+
VaultIndex
|
|
34
|
+
} from "./chunk-ZW7XY3EN.js";
|
|
35
|
+
import {
|
|
36
|
+
createNote,
|
|
37
|
+
slugify,
|
|
38
|
+
upsertNote
|
|
39
|
+
} from "./chunk-JPHL2JHE.js";
|
|
36
40
|
import {
|
|
37
41
|
MODEL_ID,
|
|
38
42
|
getEmbedder,
|
|
@@ -40,8 +44,8 @@ import {
|
|
|
40
44
|
} from "./chunk-EDYBSJSS.js";
|
|
41
45
|
|
|
42
46
|
// src/cli.ts
|
|
43
|
-
import
|
|
44
|
-
import
|
|
47
|
+
import fs4 from "fs";
|
|
48
|
+
import path4 from "path";
|
|
45
49
|
import readline from "readline/promises";
|
|
46
50
|
import { Command } from "commander";
|
|
47
51
|
import pc from "picocolors";
|
|
@@ -428,6 +432,114 @@ async function showBanner(animate) {
|
|
|
428
432
|
}
|
|
429
433
|
}
|
|
430
434
|
|
|
435
|
+
// src/core/setup.ts
|
|
436
|
+
import fs3 from "fs";
|
|
437
|
+
import os3 from "os";
|
|
438
|
+
import path3 from "path";
|
|
439
|
+
function ensureGitignore(projectDir, vaultRoot) {
|
|
440
|
+
if (!fs3.existsSync(path3.join(projectDir, ".git"))) return null;
|
|
441
|
+
const rel = path3.relative(projectDir, vaultRoot);
|
|
442
|
+
if (rel.startsWith("..")) return null;
|
|
443
|
+
const file = path3.join(projectDir, ".gitignore");
|
|
444
|
+
const entries = [`${rel.split(path3.sep).join("/")}/`];
|
|
445
|
+
let text = "";
|
|
446
|
+
try {
|
|
447
|
+
text = fs3.readFileSync(file, "utf8");
|
|
448
|
+
} catch {
|
|
449
|
+
}
|
|
450
|
+
const missing = entries.filter((e) => !text.split("\n").some((l) => l.trim() === e || l.trim() === e.slice(0, -1)));
|
|
451
|
+
if (missing.length === 0) return null;
|
|
452
|
+
const block = `${text.trimEnd()}
|
|
453
|
+
|
|
454
|
+
# Alexandria (conocimiento personal, no del repo)
|
|
455
|
+
${missing.join("\n")}
|
|
456
|
+
`;
|
|
457
|
+
fs3.writeFileSync(file, text.trim() ? block : block.trimStart());
|
|
458
|
+
return file;
|
|
459
|
+
}
|
|
460
|
+
var CLAUDE_MD_START = "<!-- alexandria:start -->";
|
|
461
|
+
var CLAUDE_MD_END = "<!-- alexandria:end -->";
|
|
462
|
+
function configureClaudeMd(scope, projectDir) {
|
|
463
|
+
const file = scope === "project" ? path3.join(projectDir, "CLAUDE.md") : path3.join(os3.homedir(), ".claude", "CLAUDE.md");
|
|
464
|
+
const block = [
|
|
465
|
+
CLAUDE_MD_START,
|
|
466
|
+
"## Alexandria \u2014 b\xF3veda de conocimiento (uso por default)",
|
|
467
|
+
"- ANTES de explorar c\xF3digo o re-derivar contexto: busca con la tool MCP `vault_search`; si la b\xF3veda ya lo sabe, \xFAsalo.",
|
|
468
|
+
"- Al descubrir arquitectura, decisiones o soluciones: gu\xE1rdalas con `vault_save` (usa `[[wikilinks]]` a notas relacionadas; el t\xEDtulo `Mapa - <proyecto>` actualiza el mapa que se inyecta al inicio de cada sesi\xF3n).",
|
|
469
|
+
"- Usa `vault_related` para traer conocimiento conectado sin releer archivos.",
|
|
470
|
+
CLAUDE_MD_END
|
|
471
|
+
].join("\n");
|
|
472
|
+
fs3.mkdirSync(path3.dirname(file), { recursive: true });
|
|
473
|
+
let text = "";
|
|
474
|
+
try {
|
|
475
|
+
text = fs3.readFileSync(file, "utf8");
|
|
476
|
+
} catch {
|
|
477
|
+
}
|
|
478
|
+
if (text.includes(CLAUDE_MD_START)) {
|
|
479
|
+
const re = new RegExp(`${CLAUDE_MD_START}[\\s\\S]*?${CLAUDE_MD_END}`);
|
|
480
|
+
text = text.replace(re, block);
|
|
481
|
+
} else {
|
|
482
|
+
text = (text.trimEnd() + "\n\n" + block + "\n").trimStart();
|
|
483
|
+
}
|
|
484
|
+
fs3.writeFileSync(file, text);
|
|
485
|
+
return file;
|
|
486
|
+
}
|
|
487
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", ".next", "dist", "build", ".vault", ".claude", "coverage", "Alexandria", "KnowledgeVault"]);
|
|
488
|
+
function scanProject(vault, projectDir) {
|
|
489
|
+
const name = path3.basename(projectDir);
|
|
490
|
+
const mapFile = path3.join(vault.managed, "notes", `mapa-${slugify(name)}.md`);
|
|
491
|
+
if (fs3.existsSync(mapFile)) return null;
|
|
492
|
+
const parts = [`Mapa inicial generado por \`ale init\` (escaneo autom\xE1tico). Actual\xEDzalo con vault_save.`];
|
|
493
|
+
try {
|
|
494
|
+
const pkg = JSON.parse(fs3.readFileSync(path3.join(projectDir, "package.json"), "utf8"));
|
|
495
|
+
const deps = Object.keys({ ...pkg.dependencies }).slice(0, 18);
|
|
496
|
+
const dev = Object.keys({ ...pkg.devDependencies }).slice(0, 10);
|
|
497
|
+
parts.push(`## Stack
|
|
498
|
+
${pkg.name ? `Paquete: ${pkg.name}` : ""}
|
|
499
|
+
- deps: ${deps.join(", ") || "\u2014"}
|
|
500
|
+
- dev: ${dev.join(", ") || "\u2014"}`);
|
|
501
|
+
const scripts = Object.entries(pkg.scripts ?? {}).slice(0, 12);
|
|
502
|
+
if (scripts.length) {
|
|
503
|
+
parts.push(`## Comandos
|
|
504
|
+
${scripts.map(([k, v]) => `- \`npm run ${k}\` \u2014 ${v}`).join("\n")}`);
|
|
505
|
+
}
|
|
506
|
+
} catch {
|
|
507
|
+
}
|
|
508
|
+
const tree = [];
|
|
509
|
+
const walk = (dir, depth, prefix) => {
|
|
510
|
+
if (depth > 2 || tree.length > 60) return;
|
|
511
|
+
let entries = [];
|
|
512
|
+
try {
|
|
513
|
+
entries = fs3.readdirSync(dir, { withFileTypes: true }).filter((e) => !e.name.startsWith(".") && !SKIP_DIRS.has(e.name));
|
|
514
|
+
} catch {
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
for (const e of entries.filter((x) => x.isDirectory()).slice(0, 14)) {
|
|
518
|
+
tree.push(`${prefix}${e.name}/`);
|
|
519
|
+
walk(path3.join(dir, e.name), depth + 1, prefix + " ");
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
walk(projectDir, 1, "");
|
|
523
|
+
if (tree.length) parts.push(`## Estructura
|
|
524
|
+
\`\`\`
|
|
525
|
+
${tree.join("\n")}
|
|
526
|
+
\`\`\``);
|
|
527
|
+
try {
|
|
528
|
+
const readme = fs3.readFileSync(path3.join(projectDir, "README.md"), "utf8");
|
|
529
|
+
parts.push(`## README (extracto)
|
|
530
|
+
${readme.split("\n").slice(0, 15).join("\n")}`);
|
|
531
|
+
} catch {
|
|
532
|
+
}
|
|
533
|
+
return upsertNote(vault.managed, {
|
|
534
|
+
fixedName: `mapa-${slugify(name)}`,
|
|
535
|
+
title: `Mapa - ${name}`,
|
|
536
|
+
type: "map",
|
|
537
|
+
tags: [name, "mapa"],
|
|
538
|
+
dir: "notes",
|
|
539
|
+
content: parts.join("\n\n")
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
|
|
431
543
|
// src/cli.ts
|
|
432
544
|
function registerAgentsMcp(agents, scope, cwd) {
|
|
433
545
|
for (const agent of agents) {
|
|
@@ -483,14 +595,14 @@ async function ensureReady(vault = getVault()) {
|
|
|
483
595
|
}
|
|
484
596
|
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(
|
|
485
597
|
"--path <dir>",
|
|
486
|
-
"ruta del vault Obsidian (existente o nuevo). Default: ./
|
|
487
|
-
).option("--skills", "al final, recomendar e instalar skills seg\xFAn el contenido").option(
|
|
598
|
+
"ruta del vault Obsidian (existente o nuevo). Default: ./Alexandria con --project, ~/Alexandria en global"
|
|
599
|
+
).option("--auto", "configurar el uso autom\xE1tico en CLAUDE.md sin preguntar").option("--manual", "no tocar CLAUDE.md (config\xFAralo t\xFA)").option("--skills", "al final, recomendar e instalar skills seg\xFAn el contenido").option(
|
|
488
600
|
"--agents <ids>",
|
|
489
601
|
`agentes de IA donde registrar el MCP: "all", "detected" o csv de ${AGENTS.map((a) => a.id).join(",")} (default: claude + detectados)`
|
|
490
602
|
).action(async (opts) => {
|
|
491
603
|
const isProject = Boolean(opts.project) && !opts.global;
|
|
492
604
|
const cwd = process.cwd();
|
|
493
|
-
const vaultPath =
|
|
605
|
+
const vaultPath = path4.resolve(opts.path ?? (isProject ? path4.join(cwd, "Alexandria") : defaultVaultPath()));
|
|
494
606
|
await showBanner();
|
|
495
607
|
console.log(pc.bold(`Instalaci\xF3n ${isProject ? "por proyecto" : "global"}
|
|
496
608
|
`));
|
|
@@ -515,6 +627,31 @@ program.command("init").description("Crea/conecta la b\xF3veda e instala TODO: m
|
|
|
515
627
|
if (skipped.length > 0) {
|
|
516
628
|
console.log(pc.dim(` Otros agentes disponibles: ${skipped.map((a) => a.id).join(", ")} \u2192 ale agents <ids>`));
|
|
517
629
|
}
|
|
630
|
+
if (isProject) {
|
|
631
|
+
const gi = ensureGitignore(cwd, vault.root);
|
|
632
|
+
if (gi) console.log(pc.green(`\u2713 B\xF3veda agregada a ${gi}`));
|
|
633
|
+
}
|
|
634
|
+
let auto = opts.auto ? true : opts.manual ? false : void 0;
|
|
635
|
+
if (auto === void 0) {
|
|
636
|
+
if (process.stdin.isTTY) {
|
|
637
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
638
|
+
const ans = (await rl.question(pc.bold("\xBFConfigurar a Claude para usar Alexandria autom\xE1ticamente (CLAUDE.md)? [S/n] "))).trim().toLowerCase();
|
|
639
|
+
rl.close();
|
|
640
|
+
auto = ans === "" || ans === "s" || ans === "si" || ans === "s\xED" || ans === "y";
|
|
641
|
+
} else {
|
|
642
|
+
auto = true;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
if (auto) {
|
|
646
|
+
const file = configureClaudeMd(isProject ? "project" : "global", cwd);
|
|
647
|
+
console.log(pc.green(`\u2713 Uso autom\xE1tico configurado en ${file}`));
|
|
648
|
+
} else {
|
|
649
|
+
console.log(pc.dim(" Sin auto-configuraci\xF3n (act\xEDvala luego con: ale init --auto)"));
|
|
650
|
+
}
|
|
651
|
+
if (isProject) {
|
|
652
|
+
const map = scanProject(vault, cwd);
|
|
653
|
+
if (map) console.log(pc.green(`\u2713 Proyecto escaneado \u2192 ${path4.relative(vault.root, map)} (mapa inicial)`));
|
|
654
|
+
}
|
|
518
655
|
await downloadModelIfMissing();
|
|
519
656
|
const idx = VaultIndex.load(vault);
|
|
520
657
|
const res = await idx.refresh();
|
|
@@ -524,6 +661,37 @@ program.command("init").description("Crea/conecta la b\xF3veda e instala TODO: m
|
|
|
524
661
|
console.log(pc.dim(' Prueba: ale search "algo" \xB7 ale graph \xB7 ale stats \xB7 ale agents\n'));
|
|
525
662
|
if (opts.skills) await runSkills({ yes: false, project: isProject });
|
|
526
663
|
});
|
|
664
|
+
program.command("consolidate").description("Archiva prompts viejos sin reuso: salen del grafo y de la inyecci\xF3n, pero NUNCA se pierden \u2014 siguen buscables (contexto infinito)").option("--days <n>", "antig\xFCedad m\xEDnima en d\xEDas", "45").option("--dry", "solo mostrar qu\xE9 se archivar\xEDa").action(async (opts) => {
|
|
665
|
+
const { vault, idx } = await ensureReady();
|
|
666
|
+
const cutoff = Date.now() - (parseInt(opts.days, 10) || 45) * 864e5;
|
|
667
|
+
const stale = Object.values(idx.meta.notes).filter(
|
|
668
|
+
(n) => n.type === "prompt" && (n.hits ?? 1) <= 1 && !n.rel.split("/").includes("archive") && n.created !== void 0 && Date.parse(n.created) < cutoff
|
|
669
|
+
);
|
|
670
|
+
if (stale.length === 0) {
|
|
671
|
+
console.log(pc.dim("Nada que consolidar: sin prompts viejos sin uso."));
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
const archiveDir = path4.join(vault.managed, "archive");
|
|
675
|
+
if (!opts.dry) fs4.mkdirSync(archiveDir, { recursive: true });
|
|
676
|
+
for (const n of stale) {
|
|
677
|
+
console.log(
|
|
678
|
+
`${opts.dry ? pc.yellow("se archivar\xEDa") : pc.cyan("archivado")} ${n.rel} ${pc.dim(`(${(n.created ?? "").slice(0, 10)}, hits ${n.hits})`)}`
|
|
679
|
+
);
|
|
680
|
+
if (!opts.dry) {
|
|
681
|
+
fs4.renameSync(path4.join(vault.root, n.rel), path4.join(archiveDir, path4.basename(n.rel)));
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
if (!opts.dry) {
|
|
685
|
+
await VaultIndex.load(vault).refresh();
|
|
686
|
+
console.log(
|
|
687
|
+
pc.green(`
|
|
688
|
+
\u2713 ${stale.length} prompts archivados en ${path4.relative(vault.root, archiveDir)}/ \u2014 fuera del grafo, siguen buscables. Nada se pierde.`)
|
|
689
|
+
);
|
|
690
|
+
} else {
|
|
691
|
+
console.log(pc.dim(`
|
|
692
|
+
${stale.length} candidatos. Corre sin --dry para archivarlos.`));
|
|
693
|
+
}
|
|
694
|
+
});
|
|
527
695
|
program.command("agents").description("Lista los agentes de IA soportados y registra el MCP de Alexandria en los que elijas").argument("[ids]", `"all", "detected" o csv (${AGENTS.map((a) => a.id).join(",")})`).option("--project", "registrar a nivel proyecto (cwd) cuando el agente lo soporte").action((ids, opts) => {
|
|
528
696
|
if (!ids) {
|
|
529
697
|
console.log(pc.bold("\n\u{1F3DB}\uFE0F Agentes de IA soportados:\n"));
|
|
@@ -548,7 +716,7 @@ program.command("add").description("Guardar una nota manualmente").argument("<ti
|
|
|
548
716
|
const { vault } = await ensureReady();
|
|
549
717
|
let content = opts.content;
|
|
550
718
|
if (!content && !process.stdin.isTTY) {
|
|
551
|
-
content =
|
|
719
|
+
content = fs4.readFileSync(0, "utf8");
|
|
552
720
|
}
|
|
553
721
|
const file = createNote(vault.managed, {
|
|
554
722
|
title,
|
|
@@ -556,7 +724,7 @@ program.command("add").description("Guardar una nota manualmente").argument("<ti
|
|
|
556
724
|
tags: opts.tags ? opts.tags.split(",").map((t) => t.trim()) : []
|
|
557
725
|
});
|
|
558
726
|
await VaultIndex.load(vault).refresh();
|
|
559
|
-
console.log(pc.green(`\u2713 ${
|
|
727
|
+
console.log(pc.green(`\u2713 ${path4.relative(vault.root, file)}`));
|
|
560
728
|
});
|
|
561
729
|
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) => {
|
|
562
730
|
const vault = getVault();
|
|
@@ -630,7 +798,7 @@ program.command("stats").description("Estado de la b\xF3veda y tokens ahorrados"
|
|
|
630
798
|
async function runSkills(opts) {
|
|
631
799
|
const { vault } = await ensureReady();
|
|
632
800
|
const cwd = process.cwd();
|
|
633
|
-
const targetDir = opts.project ?
|
|
801
|
+
const targetDir = opts.project ? path4.join(cwd, ".claude", "skills") : path4.join(process.env.HOME ?? process.env.USERPROFILE ?? cwd, ".claude", "skills");
|
|
634
802
|
const recs = recommendSkills(vault, [targetDir]);
|
|
635
803
|
if (recs.length === 0) {
|
|
636
804
|
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,16 @@ import {
|
|
|
9
9
|
} from "../chunk-DEDAOKAV.js";
|
|
10
10
|
import {
|
|
11
11
|
hybridSearch
|
|
12
|
-
} from "../chunk-
|
|
13
|
-
import "../chunk-VN7QOAG2.js";
|
|
12
|
+
} from "../chunk-ADHRHLX7.js";
|
|
14
13
|
import {
|
|
15
|
-
createNote,
|
|
16
14
|
resolveVault,
|
|
17
|
-
touchNote,
|
|
18
15
|
vaultExists
|
|
19
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-KB6KYZFQ.js";
|
|
17
|
+
import "../chunk-ZW7XY3EN.js";
|
|
18
|
+
import {
|
|
19
|
+
createNote,
|
|
20
|
+
touchNote
|
|
21
|
+
} from "../chunk-JPHL2JHE.js";
|
|
20
22
|
import "../chunk-EDYBSJSS.js";
|
|
21
23
|
|
|
22
24
|
// src/hooks/on-prompt.ts
|
|
@@ -33,7 +35,14 @@ runHook(25e3, async (input) => {
|
|
|
33
35
|
if (prompt.length < MIN_PROMPT_CHARS || prompt.startsWith("/")) return;
|
|
34
36
|
const vault = resolveVault({ cwd: input.cwd });
|
|
35
37
|
if (!vaultExists(vault)) return;
|
|
36
|
-
const
|
|
38
|
+
const rawResults = await hybridSearch(vault, prompt, 5, { expand: true });
|
|
39
|
+
const STALE_DAYS = 60;
|
|
40
|
+
const results = rawResults.filter((r) => {
|
|
41
|
+
if (r.note.type !== "prompt" && r.note.type !== "session") return true;
|
|
42
|
+
if ((r.note.hits ?? 1) > 1) return true;
|
|
43
|
+
const age = r.note.created ? (Date.now() - Date.parse(r.note.created)) / 864e5 : 0;
|
|
44
|
+
return age <= STALE_DAYS;
|
|
45
|
+
});
|
|
37
46
|
const maxCos = results.reduce((m, r) => Math.max(m, r.cosine), 0);
|
|
38
47
|
const relevant = maxCos > 0 ? results.filter((r) => r.cosine >= RELEVANT_COSINE && r.cosine >= maxCos - RELEVANT_MARGIN) : results.filter((r) => r.score > 0.02);
|
|
39
48
|
let injected = "";
|
|
@@ -66,7 +75,7 @@ Contexto recuperado de la b\xF3veda local (usa esto antes de releer archivos o r
|
|
|
66
75
|
promptChars: prompt.length
|
|
67
76
|
});
|
|
68
77
|
}
|
|
69
|
-
const dupe =
|
|
78
|
+
const dupe = rawResults.find((r) => r.note.type === "prompt" && r.cosine >= DEDUP_COSINE);
|
|
70
79
|
if (dupe) {
|
|
71
80
|
try {
|
|
72
81
|
touchNote(path.join(vault.root, dupe.note.rel));
|
|
@@ -7,13 +7,14 @@ import {
|
|
|
7
7
|
runHook,
|
|
8
8
|
truncate
|
|
9
9
|
} from "../chunk-DEDAOKAV.js";
|
|
10
|
-
import {
|
|
11
|
-
VaultIndex
|
|
12
|
-
} from "../chunk-VN7QOAG2.js";
|
|
13
10
|
import {
|
|
14
11
|
resolveVault,
|
|
15
12
|
vaultExists
|
|
16
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-KB6KYZFQ.js";
|
|
14
|
+
import {
|
|
15
|
+
VaultIndex
|
|
16
|
+
} from "../chunk-ZW7XY3EN.js";
|
|
17
|
+
import "../chunk-JPHL2JHE.js";
|
|
17
18
|
import "../chunk-EDYBSJSS.js";
|
|
18
19
|
|
|
19
20
|
// src/hooks/on-session-start.ts
|
package/dist/hooks/on-stop.js
CHANGED
|
@@ -5,11 +5,13 @@ import {
|
|
|
5
5
|
truncate
|
|
6
6
|
} from "../chunk-DEDAOKAV.js";
|
|
7
7
|
import {
|
|
8
|
-
appendToNote,
|
|
9
8
|
ensureVaultStructure,
|
|
10
9
|
resolveVault,
|
|
11
10
|
vaultExists
|
|
12
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-KB6KYZFQ.js";
|
|
12
|
+
import {
|
|
13
|
+
appendToNote
|
|
14
|
+
} from "../chunk-JPHL2JHE.js";
|
|
13
15
|
|
|
14
16
|
// src/hooks/on-stop.ts
|
|
15
17
|
import fs from "fs";
|
package/dist/mcp/server.js
CHANGED
|
@@ -4,17 +4,19 @@ import {
|
|
|
4
4
|
} from "../chunk-KHTYRYDR.js";
|
|
5
5
|
import {
|
|
6
6
|
hybridSearch
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-ADHRHLX7.js";
|
|
8
|
+
import {
|
|
9
|
+
ensureVaultStructure,
|
|
10
|
+
resolveVault
|
|
11
|
+
} from "../chunk-KB6KYZFQ.js";
|
|
8
12
|
import {
|
|
9
13
|
VaultIndex
|
|
10
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-ZW7XY3EN.js";
|
|
11
15
|
import {
|
|
12
16
|
createNote,
|
|
13
|
-
ensureVaultStructure,
|
|
14
|
-
resolveVault,
|
|
15
17
|
slugify,
|
|
16
18
|
upsertNote
|
|
17
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-JPHL2JHE.js";
|
|
18
20
|
import "../chunk-EDYBSJSS.js";
|
|
19
21
|
|
|
20
22
|
// src/mcp/server.ts
|
|
@@ -50,6 +52,15 @@ server.tool(
|
|
|
50
52
|
},
|
|
51
53
|
async ({ title, content, tags }) => {
|
|
52
54
|
ensureVaultStructure(vault);
|
|
55
|
+
if (!title.startsWith("Mapa - ") && !/\[\[/.test(content)) {
|
|
56
|
+
const idxPre = VaultIndex.load(vault);
|
|
57
|
+
const map = Object.values(idxPre.meta.notes).find(
|
|
58
|
+
(n) => n.type === "map" || n.title.startsWith("Mapa - ")
|
|
59
|
+
);
|
|
60
|
+
if (map) content = `${content.trim()}
|
|
61
|
+
|
|
62
|
+
Proyecto: [[${map.title}]]`;
|
|
63
|
+
}
|
|
53
64
|
let file;
|
|
54
65
|
if (title.startsWith("Mapa - ")) {
|
|
55
66
|
file = upsertNote(vault.managed, {
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
renderGraphHtml,
|
|
5
5
|
serveGraph,
|
|
6
6
|
writeStaticGraph
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-WPNU64MA.js";
|
|
8
|
+
import "./chunk-ZW7XY3EN.js";
|
|
9
|
+
import "./chunk-JPHL2JHE.js";
|
|
10
10
|
import "./chunk-EDYBSJSS.js";
|
|
11
11
|
export {
|
|
12
12
|
buildGraphData,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ureck/alexandria",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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",
|
package/dist/chunk-CF2GLMR3.js
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// src/core/vault.ts
|
|
4
|
-
import fs from "fs";
|
|
5
|
-
import os from "os";
|
|
6
|
-
import path from "path";
|
|
7
|
-
var MANAGED_DIR = "Alexandria";
|
|
8
|
-
function configDir() {
|
|
9
|
-
if (process.platform === "win32" && process.env.APPDATA) {
|
|
10
|
-
return path.join(process.env.APPDATA, "alexandria");
|
|
11
|
-
}
|
|
12
|
-
return path.join(os.homedir(), ".config", "alexandria");
|
|
13
|
-
}
|
|
14
|
-
function globalConfigPath() {
|
|
15
|
-
return path.join(configDir(), "config.json");
|
|
16
|
-
}
|
|
17
|
-
function defaultVaultPath() {
|
|
18
|
-
return path.join(os.homedir(), "KnowledgeVault");
|
|
19
|
-
}
|
|
20
|
-
function readJson(file) {
|
|
21
|
-
try {
|
|
22
|
-
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
23
|
-
} catch {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function findProjectConfig(from) {
|
|
28
|
-
let dir = path.resolve(from);
|
|
29
|
-
for (; ; ) {
|
|
30
|
-
const candidate = path.join(dir, ".vault.json");
|
|
31
|
-
if (fs.existsSync(candidate)) return candidate;
|
|
32
|
-
const parent = path.dirname(dir);
|
|
33
|
-
if (parent === dir) return null;
|
|
34
|
-
dir = parent;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function build(root, source, projectConfig) {
|
|
38
|
-
return {
|
|
39
|
-
root,
|
|
40
|
-
managed: path.join(root, MANAGED_DIR),
|
|
41
|
-
cache: path.join(root, ".vault"),
|
|
42
|
-
source,
|
|
43
|
-
projectConfig
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function resolveVault(opts = {}) {
|
|
47
|
-
if (opts.flag) return build(path.resolve(opts.flag), "flag");
|
|
48
|
-
const cwd = opts.cwd ?? process.cwd();
|
|
49
|
-
const projectFile = findProjectConfig(cwd);
|
|
50
|
-
if (projectFile) {
|
|
51
|
-
const cfg = readJson(projectFile);
|
|
52
|
-
if (cfg?.vaultPath) {
|
|
53
|
-
const base = path.dirname(projectFile);
|
|
54
|
-
return build(path.resolve(base, cfg.vaultPath), "project", projectFile);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const globalCfg = readJson(globalConfigPath());
|
|
58
|
-
if (globalCfg?.vaultPath) return build(globalCfg.vaultPath, "global");
|
|
59
|
-
return build(defaultVaultPath(), "default");
|
|
60
|
-
}
|
|
61
|
-
function vaultExists(v) {
|
|
62
|
-
return fs.existsSync(v.managed) || fs.existsSync(v.cache);
|
|
63
|
-
}
|
|
64
|
-
function ensureVaultStructure(v) {
|
|
65
|
-
for (const dir of [
|
|
66
|
-
v.root,
|
|
67
|
-
v.managed,
|
|
68
|
-
path.join(v.managed, "notes"),
|
|
69
|
-
path.join(v.managed, "prompts"),
|
|
70
|
-
path.join(v.managed, "sessions"),
|
|
71
|
-
v.cache
|
|
72
|
-
]) {
|
|
73
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function writeGlobalConfig(vaultPath) {
|
|
77
|
-
fs.mkdirSync(configDir(), { recursive: true });
|
|
78
|
-
fs.writeFileSync(globalConfigPath(), JSON.stringify({ vaultPath }, null, 2) + "\n");
|
|
79
|
-
}
|
|
80
|
-
function writeProjectConfig(projectDir, vaultPath) {
|
|
81
|
-
const file = path.join(projectDir, ".vault.json");
|
|
82
|
-
const rel = path.relative(projectDir, vaultPath) || ".";
|
|
83
|
-
const stored = rel.startsWith("..") ? vaultPath : rel;
|
|
84
|
-
fs.writeFileSync(file, JSON.stringify({ vaultPath: stored }, null, 2) + "\n");
|
|
85
|
-
return file;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// src/core/notes.ts
|
|
89
|
-
import fs2 from "fs";
|
|
90
|
-
import path2 from "path";
|
|
91
|
-
import matter from "gray-matter";
|
|
92
|
-
var SKIP_DIRS = /* @__PURE__ */ new Set([".obsidian", ".vault", ".trash", ".git", "node_modules"]);
|
|
93
|
-
function extractWikilinks(content) {
|
|
94
|
-
const out = /* @__PURE__ */ new Set();
|
|
95
|
-
const re = /\[\[([^\]|#\n]+)(?:[|#][^\]]*)?\]\]/g;
|
|
96
|
-
let m;
|
|
97
|
-
while ((m = re.exec(content)) !== null) {
|
|
98
|
-
const target = m[1].trim();
|
|
99
|
-
if (target) out.add(target);
|
|
100
|
-
}
|
|
101
|
-
return [...out];
|
|
102
|
-
}
|
|
103
|
-
function slugify(text) {
|
|
104
|
-
return text.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80) || "nota";
|
|
105
|
-
}
|
|
106
|
-
function listMarkdownFiles(root) {
|
|
107
|
-
const out = [];
|
|
108
|
-
const walk = (dir) => {
|
|
109
|
-
let entries;
|
|
110
|
-
try {
|
|
111
|
-
entries = fs2.readdirSync(dir, { withFileTypes: true });
|
|
112
|
-
} catch {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
for (const e of entries) {
|
|
116
|
-
if (e.name.startsWith(".") || SKIP_DIRS.has(e.name)) continue;
|
|
117
|
-
const full = path2.join(dir, e.name);
|
|
118
|
-
if (e.isDirectory()) walk(full);
|
|
119
|
-
else if (e.isFile() && e.name.endsWith(".md")) out.push(full);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
walk(root);
|
|
123
|
-
return out;
|
|
124
|
-
}
|
|
125
|
-
function parseNote(root, absPath) {
|
|
126
|
-
const raw = fs2.readFileSync(absPath, "utf8");
|
|
127
|
-
const { data, content } = matter(raw);
|
|
128
|
-
const rel = path2.relative(root, absPath).split(path2.sep).join("/");
|
|
129
|
-
const title = typeof data.title === "string" && data.title || path2.basename(absPath, ".md");
|
|
130
|
-
const type = ["note", "prompt", "session", "map"].includes(data.type) ? data.type : "note";
|
|
131
|
-
const tags = Array.isArray(data.tags) ? data.tags.map(String) : [];
|
|
132
|
-
return {
|
|
133
|
-
rel,
|
|
134
|
-
title,
|
|
135
|
-
type,
|
|
136
|
-
tags,
|
|
137
|
-
created: data.created ? String(data.created) : void 0,
|
|
138
|
-
hits: typeof data.hits === "number" ? data.hits : 1,
|
|
139
|
-
content,
|
|
140
|
-
links: extractWikilinks(content)
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
function frontmatter(n) {
|
|
144
|
-
const lines = [
|
|
145
|
-
"---",
|
|
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)}]`,
|
|
150
|
-
`type: ${n.type}`,
|
|
151
|
-
`tags: [${n.tags.map((t) => JSON.stringify(t)).join(", ")}]`,
|
|
152
|
-
`created: ${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
153
|
-
`hits: ${n.hits ?? 1}`,
|
|
154
|
-
"---",
|
|
155
|
-
""
|
|
156
|
-
];
|
|
157
|
-
return lines.join("\n");
|
|
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
|
-
}
|
|
171
|
-
function createNote(managed, n) {
|
|
172
|
-
const dir = path2.join(managed, n.dir ?? "notes");
|
|
173
|
-
fs2.mkdirSync(dir, { recursive: true });
|
|
174
|
-
const date = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
175
|
-
const base = `${date}-${slugify(n.title)}`;
|
|
176
|
-
let file = path2.join(dir, `${base}.md`);
|
|
177
|
-
let i = 2;
|
|
178
|
-
while (fs2.existsSync(file)) file = path2.join(dir, `${base}-${i++}.md`);
|
|
179
|
-
fs2.writeFileSync(
|
|
180
|
-
file,
|
|
181
|
-
frontmatter({ title: n.title, type: n.type ?? "note", tags: n.tags ?? [] }) + n.content.trim() + "\n"
|
|
182
|
-
);
|
|
183
|
-
return file;
|
|
184
|
-
}
|
|
185
|
-
function touchNote(absPath) {
|
|
186
|
-
const raw = fs2.readFileSync(absPath, "utf8");
|
|
187
|
-
const { data, content } = matter(raw);
|
|
188
|
-
data.hits = (typeof data.hits === "number" ? data.hits : 1) + 1;
|
|
189
|
-
data.updated = (/* @__PURE__ */ new Date()).toISOString();
|
|
190
|
-
fs2.writeFileSync(absPath, matter.stringify(content, data));
|
|
191
|
-
}
|
|
192
|
-
function upsertNote(managed, n) {
|
|
193
|
-
const dir = path2.join(managed, n.dir ?? "notes");
|
|
194
|
-
fs2.mkdirSync(dir, { recursive: true });
|
|
195
|
-
const file = path2.join(dir, `${n.fixedName}.md`);
|
|
196
|
-
if (fs2.existsSync(file)) {
|
|
197
|
-
const raw = fs2.readFileSync(file, "utf8");
|
|
198
|
-
const { data } = matter(raw);
|
|
199
|
-
data.updated = (/* @__PURE__ */ new Date()).toISOString();
|
|
200
|
-
fs2.writeFileSync(file, matter.stringify(n.content.trim() + "\n", data));
|
|
201
|
-
} else {
|
|
202
|
-
fs2.writeFileSync(
|
|
203
|
-
file,
|
|
204
|
-
frontmatter({ title: n.title, type: n.type ?? "note", tags: n.tags ?? [] }) + n.content.trim() + "\n"
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
return file;
|
|
208
|
-
}
|
|
209
|
-
function appendToNote(managed, n) {
|
|
210
|
-
const dir = path2.join(managed, n.dir ?? "sessions");
|
|
211
|
-
fs2.mkdirSync(dir, { recursive: true });
|
|
212
|
-
const file = path2.join(dir, `${n.fixedName}.md`);
|
|
213
|
-
if (fs2.existsSync(file)) {
|
|
214
|
-
fs2.appendFileSync(file, "\n" + n.content.trim() + "\n");
|
|
215
|
-
} else {
|
|
216
|
-
fs2.writeFileSync(
|
|
217
|
-
file,
|
|
218
|
-
frontmatter({ title: n.title, type: n.type ?? "session", tags: n.tags ?? [] }) + n.content.trim() + "\n"
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
return file;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
export {
|
|
225
|
-
MANAGED_DIR,
|
|
226
|
-
globalConfigPath,
|
|
227
|
-
defaultVaultPath,
|
|
228
|
-
resolveVault,
|
|
229
|
-
vaultExists,
|
|
230
|
-
ensureVaultStructure,
|
|
231
|
-
writeGlobalConfig,
|
|
232
|
-
writeProjectConfig,
|
|
233
|
-
slugify,
|
|
234
|
-
listMarkdownFiles,
|
|
235
|
-
parseNote,
|
|
236
|
-
ensureAlias,
|
|
237
|
-
createNote,
|
|
238
|
-
touchNote,
|
|
239
|
-
upsertNote,
|
|
240
|
-
appendToNote
|
|
241
|
-
};
|