@ureck/alexandria 0.2.4 → 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 +16 -11
- package/dist/{chunk-O7FDC2PB.js → chunk-ADHRHLX7.js} +1 -1
- package/dist/chunk-JPHL2JHE.js +148 -0
- package/dist/chunk-KB6KYZFQ.js +99 -0
- package/dist/chunk-WPNU64MA.js +328 -0
- package/dist/{chunk-UWAIMIG2.js → chunk-ZW7XY3EN.js} +12 -1
- package/dist/cli.js +221 -223
- 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-FRJYOK3S.js +16 -0
- package/package.json +1 -1
- package/dist/chunk-CZM5NQZJ.js +0 -224
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-UWAIMIG2.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-UWAIMIG2.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, {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
buildGraphData,
|
|
4
|
+
renderGraphHtml,
|
|
5
|
+
serveGraph,
|
|
6
|
+
writeStaticGraph
|
|
7
|
+
} from "./chunk-WPNU64MA.js";
|
|
8
|
+
import "./chunk-ZW7XY3EN.js";
|
|
9
|
+
import "./chunk-JPHL2JHE.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.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-CZM5NQZJ.js
DELETED
|
@@ -1,224 +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
|
-
`type: ${n.type}`,
|
|
148
|
-
`tags: [${n.tags.map((t) => JSON.stringify(t)).join(", ")}]`,
|
|
149
|
-
`created: ${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
150
|
-
`hits: ${n.hits ?? 1}`,
|
|
151
|
-
"---",
|
|
152
|
-
""
|
|
153
|
-
];
|
|
154
|
-
return lines.join("\n");
|
|
155
|
-
}
|
|
156
|
-
function createNote(managed, n) {
|
|
157
|
-
const dir = path2.join(managed, n.dir ?? "notes");
|
|
158
|
-
fs2.mkdirSync(dir, { recursive: true });
|
|
159
|
-
const date = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
160
|
-
const base = `${date}-${slugify(n.title)}`;
|
|
161
|
-
let file = path2.join(dir, `${base}.md`);
|
|
162
|
-
let i = 2;
|
|
163
|
-
while (fs2.existsSync(file)) file = path2.join(dir, `${base}-${i++}.md`);
|
|
164
|
-
fs2.writeFileSync(
|
|
165
|
-
file,
|
|
166
|
-
frontmatter({ title: n.title, type: n.type ?? "note", tags: n.tags ?? [] }) + n.content.trim() + "\n"
|
|
167
|
-
);
|
|
168
|
-
return file;
|
|
169
|
-
}
|
|
170
|
-
function touchNote(absPath) {
|
|
171
|
-
const raw = fs2.readFileSync(absPath, "utf8");
|
|
172
|
-
const { data, content } = matter(raw);
|
|
173
|
-
data.hits = (typeof data.hits === "number" ? data.hits : 1) + 1;
|
|
174
|
-
data.updated = (/* @__PURE__ */ new Date()).toISOString();
|
|
175
|
-
fs2.writeFileSync(absPath, matter.stringify(content, data));
|
|
176
|
-
}
|
|
177
|
-
function upsertNote(managed, n) {
|
|
178
|
-
const dir = path2.join(managed, n.dir ?? "notes");
|
|
179
|
-
fs2.mkdirSync(dir, { recursive: true });
|
|
180
|
-
const file = path2.join(dir, `${n.fixedName}.md`);
|
|
181
|
-
if (fs2.existsSync(file)) {
|
|
182
|
-
const raw = fs2.readFileSync(file, "utf8");
|
|
183
|
-
const { data } = matter(raw);
|
|
184
|
-
data.updated = (/* @__PURE__ */ new Date()).toISOString();
|
|
185
|
-
fs2.writeFileSync(file, matter.stringify(n.content.trim() + "\n", data));
|
|
186
|
-
} else {
|
|
187
|
-
fs2.writeFileSync(
|
|
188
|
-
file,
|
|
189
|
-
frontmatter({ title: n.title, type: n.type ?? "note", tags: n.tags ?? [] }) + n.content.trim() + "\n"
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
return file;
|
|
193
|
-
}
|
|
194
|
-
function appendToNote(managed, n) {
|
|
195
|
-
const dir = path2.join(managed, n.dir ?? "sessions");
|
|
196
|
-
fs2.mkdirSync(dir, { recursive: true });
|
|
197
|
-
const file = path2.join(dir, `${n.fixedName}.md`);
|
|
198
|
-
if (fs2.existsSync(file)) {
|
|
199
|
-
fs2.appendFileSync(file, "\n" + n.content.trim() + "\n");
|
|
200
|
-
} else {
|
|
201
|
-
fs2.writeFileSync(
|
|
202
|
-
file,
|
|
203
|
-
frontmatter({ title: n.title, type: n.type ?? "session", tags: n.tags ?? [] }) + n.content.trim() + "\n"
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
return file;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
export {
|
|
210
|
-
globalConfigPath,
|
|
211
|
-
defaultVaultPath,
|
|
212
|
-
resolveVault,
|
|
213
|
-
vaultExists,
|
|
214
|
-
ensureVaultStructure,
|
|
215
|
-
writeGlobalConfig,
|
|
216
|
-
writeProjectConfig,
|
|
217
|
-
slugify,
|
|
218
|
-
listMarkdownFiles,
|
|
219
|
-
parseNote,
|
|
220
|
-
createNote,
|
|
221
|
-
touchNote,
|
|
222
|
-
upsertNote,
|
|
223
|
-
appendToNote
|
|
224
|
-
};
|