@ureck/alexandria 0.3.0 → 0.5.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 +173 -172
- package/dist/{chunk-FID2RAOH.js → chunk-BCLBZ7NX.js} +17 -4
- package/dist/chunk-DYCARGQR.js +117 -0
- package/dist/{chunk-VN7QOAG2.js → chunk-MLA3KZPZ.js} +6 -4
- package/dist/{chunk-I2ZBQUZD.js → chunk-RLVCH6CZ.js} +33 -13
- package/dist/chunk-XWR74BQ2.js +170 -0
- package/dist/cli.js +270 -18
- package/dist/hooks/on-prompt.js +17 -8
- package/dist/hooks/on-session-start.js +14 -4
- package/dist/hooks/on-stop.js +4 -2
- package/dist/mcp/server.js +144 -5
- package/dist/{viewer-LD4RTZE7.js → viewer-57T7UOFE.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-CF2GLMR3.js +0 -241
|
@@ -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-RLVCH6CZ.js";
|
|
8
|
+
import "./chunk-MLA3KZPZ.js";
|
|
9
|
+
import "./chunk-XWR74BQ2.js";
|
|
10
10
|
import "./chunk-EDYBSJSS.js";
|
|
11
11
|
export {
|
|
12
12
|
buildGraphData,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ureck/alexandria",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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
|
-
};
|