@ureck/alexandria 1.0.0 → 1.2.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 +17 -2
- package/dist/chunk-53SIGH5A.js +69 -0
- package/dist/{chunk-DYCARGQR.js → chunk-CIOCSIB5.js} +50 -0
- package/dist/{chunk-DCKYTO4O.js → chunk-FBGIFNIO.js} +1 -1
- package/dist/chunk-QB37UGO6.js +490 -0
- package/dist/{chunk-RZI7TYAG.js → chunk-UWB6RKVN.js} +2 -1
- package/dist/{chunk-DHXL36RG.js → chunk-ZIQYAQCF.js} +19 -33
- package/dist/cli.js +574 -159
- package/dist/hooks/on-prompt.js +41 -27
- package/dist/hooks/on-session-start.js +9 -9
- package/dist/hooks/on-stop.js +27 -3
- package/dist/mcp/server.js +10 -10
- package/dist/{viewer-73ZWPIDC.js → viewer-JQCSWJ3C.js} +2 -3
- package/package.json +1 -1
- package/dist/chunk-D5ROL42O.js +0 -267
- package/dist/chunk-DEDAOKAV.js +0 -44
- package/dist/chunk-XWR74BQ2.js +0 -170
package/dist/hooks/on-prompt.js
CHANGED
|
@@ -6,19 +6,19 @@ import {
|
|
|
6
6
|
projectName,
|
|
7
7
|
runHook,
|
|
8
8
|
truncate
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-53SIGH5A.js";
|
|
10
10
|
import {
|
|
11
11
|
hybridSearch
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-UWB6RKVN.js";
|
|
13
13
|
import {
|
|
14
14
|
resolveVault,
|
|
15
|
+
toggleEnabled,
|
|
15
16
|
vaultExists
|
|
16
|
-
} from "../chunk-
|
|
17
|
-
import "../chunk-D5ROL42O.js";
|
|
17
|
+
} from "../chunk-CIOCSIB5.js";
|
|
18
18
|
import {
|
|
19
19
|
createNote,
|
|
20
20
|
touchNote
|
|
21
|
-
} from "../chunk-
|
|
21
|
+
} from "../chunk-QB37UGO6.js";
|
|
22
22
|
import "../chunk-EDYBSJSS.js";
|
|
23
23
|
|
|
24
24
|
// src/hooks/on-prompt.ts
|
|
@@ -30,12 +30,13 @@ var DEDUP_COSINE = 0.93;
|
|
|
30
30
|
var SOLUTION_COSINE = 0.93;
|
|
31
31
|
var RELEVANT_COSINE = 0.82;
|
|
32
32
|
var RELEVANT_MARGIN = 0.04;
|
|
33
|
-
|
|
33
|
+
var KEYWORD_REL_FACTOR = 0.6;
|
|
34
|
+
runHook(5e3, async (input) => {
|
|
34
35
|
const prompt = (input.prompt ?? "").trim();
|
|
35
36
|
if (prompt.length < MIN_PROMPT_CHARS || prompt.startsWith("/")) return;
|
|
36
37
|
const vault = resolveVault({ cwd: input.cwd });
|
|
37
38
|
if (!vaultExists(vault)) return;
|
|
38
|
-
const rawResults = await hybridSearch(vault, prompt, 5, { expand: true });
|
|
39
|
+
const rawResults = await hybridSearch(vault, prompt, 5, { expand: true, refresh: false });
|
|
39
40
|
const STALE_DAYS = 60;
|
|
40
41
|
const results = rawResults.filter((r) => {
|
|
41
42
|
if (r.note.type !== "prompt" && r.note.type !== "session") return true;
|
|
@@ -44,12 +45,21 @@ runHook(25e3, async (input) => {
|
|
|
44
45
|
return age <= STALE_DAYS;
|
|
45
46
|
});
|
|
46
47
|
const maxCos = results.reduce((m, r) => Math.max(m, r.cosine), 0);
|
|
47
|
-
const
|
|
48
|
+
const maxScore = results.reduce((m, r) => Math.max(m, r.score), 0);
|
|
49
|
+
const relevant = maxCos > 0 ? results.filter((r) => r.cosine >= RELEVANT_COSINE && r.cosine >= maxCos - RELEVANT_MARGIN) : (
|
|
50
|
+
// Keyword-only: criterio RELATIVO al mejor resultado, nunca absoluto. El
|
|
51
|
+
// umbral fijo de 0.02 era inalcanzable — el RRF máximo es 1/(60+1)=0.0164,
|
|
52
|
+
// así que notas tipo note/session/prompt (boost ≤1.0) jamás lo cruzaban y
|
|
53
|
+
// la mayoría de la bóveda quedaba invisible en modo degradado.
|
|
54
|
+
results.filter((r) => maxScore > 0 && r.score >= maxScore * KEYWORD_REL_FACTOR).slice(0, 3)
|
|
55
|
+
);
|
|
56
|
+
const solutionCacheOn = toggleEnabled("tokens.solutionCache");
|
|
57
|
+
const promptSearchOn = toggleEnabled("tokens.promptSearch");
|
|
48
58
|
let injected = "";
|
|
49
|
-
if (relevant.length > 0) {
|
|
50
|
-
const cached = relevant.find(
|
|
59
|
+
if (relevant.length > 0 && (solutionCacheOn || promptSearchOn)) {
|
|
60
|
+
const cached = solutionCacheOn ? relevant.find(
|
|
51
61
|
(r) => (r.note.type === "prompt" || r.note.type === "session") && r.cosine >= SOLUTION_COSINE
|
|
52
|
-
);
|
|
62
|
+
) : void 0;
|
|
53
63
|
const lines = [];
|
|
54
64
|
if (cached) {
|
|
55
65
|
lines.push(
|
|
@@ -57,28 +67,32 @@ runHook(25e3, async (input) => {
|
|
|
57
67
|
${truncate(cached.excerpts.join("\n"), 2e3)}`
|
|
58
68
|
);
|
|
59
69
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
if (promptSearchOn) {
|
|
71
|
+
for (const r of relevant) {
|
|
72
|
+
if (r === cached) continue;
|
|
73
|
+
lines.push(`\u2022 \xAB${r.note.title}\xBB (${r.note.rel}):
|
|
63
74
|
${truncate(r.excerpts.join("\n"), 900)}`);
|
|
64
|
-
|
|
75
|
+
if (lines.join("\n\n").length > MAX_INJECT_CHARS) break;
|
|
76
|
+
}
|
|
65
77
|
}
|
|
66
|
-
|
|
78
|
+
if (lines.length > 0) {
|
|
79
|
+
injected = `<alexandria-contexto>
|
|
67
80
|
Contexto recuperado de la b\xF3veda local (usa esto antes de releer archivos o re-explorar):
|
|
68
81
|
|
|
69
82
|
` + truncate(lines.join("\n\n"), MAX_INJECT_CHARS) + `
|
|
70
83
|
</alexandria-contexto>`;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
process.stdout.write(injected);
|
|
85
|
+
logInjection(vault, {
|
|
86
|
+
kind: cached ? "solution-cache" : "inject",
|
|
87
|
+
injectedChars: injected.length,
|
|
88
|
+
promptChars: prompt.length
|
|
89
|
+
});
|
|
90
|
+
for (const r of relevant) {
|
|
91
|
+
if (r.note.type === "lesson" || r.note.type === "solution") {
|
|
92
|
+
try {
|
|
93
|
+
touchNote(path.join(vault.root, r.note.rel));
|
|
94
|
+
} catch {
|
|
95
|
+
}
|
|
82
96
|
}
|
|
83
97
|
}
|
|
84
98
|
}
|
|
@@ -6,16 +6,16 @@ import {
|
|
|
6
6
|
projectName,
|
|
7
7
|
runHook,
|
|
8
8
|
truncate
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-53SIGH5A.js";
|
|
10
10
|
import {
|
|
11
11
|
protocolEnabled,
|
|
12
12
|
resolveVault,
|
|
13
|
+
toggleEnabled,
|
|
13
14
|
vaultExists
|
|
14
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-CIOCSIB5.js";
|
|
15
16
|
import {
|
|
16
17
|
VaultIndex
|
|
17
|
-
} from "../chunk-
|
|
18
|
-
import "../chunk-XWR74BQ2.js";
|
|
18
|
+
} from "../chunk-QB37UGO6.js";
|
|
19
19
|
import "../chunk-EDYBSJSS.js";
|
|
20
20
|
|
|
21
21
|
// src/hooks/on-session-start.ts
|
|
@@ -33,7 +33,7 @@ runHook(15e3, async (input) => {
|
|
|
33
33
|
const proj = projectName(input.cwd);
|
|
34
34
|
const parts = [];
|
|
35
35
|
if (protocolEnabled()) {
|
|
36
|
-
const openPlans =
|
|
36
|
+
const openPlans = idx.notesByTag("plan").filter((n) => n.status === "active");
|
|
37
37
|
parts.push(
|
|
38
38
|
`## Protocolo Alexandria (activo)
|
|
39
39
|
El protocolo es PALANCA, no l\xEDmite: \xFAsalo para rendir m\xE1s con menos tokens, nunca como burocracia. Tareas simples \u2192 responde directo, sin ceremonia. Tareas no triviales \u2192 ciclo con las tools MCP: 1) plan_create (objetivo + Definition of Done) \u2192 2) ejecuta con toda tu capacidad \u2192 3) task_verify con evidencia real (tests/build \u2014 la evidencia elimina errores, no te frena) \u2192 si algo falla, vault_search por lecciones ANTES de re-debuggear (conocimiento previo = tokens gratis) \u2192 4) lesson_extract si resolviste algo no obvio. Reutiliza lo cacheado con criterio: valida que siga aplicando si el c\xF3digo cambi\xF3.` + (openPlans.length > 0 ? `
|
|
@@ -43,7 +43,7 @@ El protocolo es PALANCA, no l\xEDmite: \xFAsalo para rendir m\xE1s con menos tok
|
|
|
43
43
|
const map = notes.find(
|
|
44
44
|
(n) => (n.type === "map" || n.title.toLowerCase().startsWith("mapa - ")) && n.title.toLowerCase().includes(proj.toLowerCase())
|
|
45
45
|
);
|
|
46
|
-
if (map) {
|
|
46
|
+
if (map && toggleEnabled("digest.map")) {
|
|
47
47
|
try {
|
|
48
48
|
const raw = fs.readFileSync(path.join(vault.root, map.rel), "utf8");
|
|
49
49
|
const body = raw.replace(/^---[\s\S]*?---\n/, "");
|
|
@@ -52,19 +52,19 @@ ${truncate(body.trim(), 4e3)}`);
|
|
|
52
52
|
} catch {
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
const sessions =
|
|
55
|
+
const sessions = idx.notesByTag("session").sort((a, b) => (b.created ?? "").localeCompare(a.created ?? "")).slice(0, 3);
|
|
56
56
|
if (sessions.length > 0) {
|
|
57
57
|
const lines = sessions.map((s) => `- ${s.title} (${(s.created ?? "").slice(0, 10)})`);
|
|
58
58
|
parts.push(`## Sesiones recientes en la b\xF3veda
|
|
59
59
|
${lines.join("\n")}`);
|
|
60
60
|
}
|
|
61
|
-
const distilled =
|
|
61
|
+
const distilled = idx.notesByTag("note").length + idx.notesByTag("lesson").length;
|
|
62
62
|
if (map && distilled < 3) {
|
|
63
63
|
parts.push(
|
|
64
64
|
`B\xF3veda joven (${distilled} notas destiladas): al descubrir decisiones, m\xF3dulos o vocabulario del dominio, gu\xE1rdalos compactos con vault_save \u2014 tokens gratis en sesiones futuras.`
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
|
-
const titles = notes.filter((n) => n.type !== "prompt").sort((a, b) => (b.hits ?? 1) - (a.hits ?? 1)).slice(0, 25).map((n) => n.title);
|
|
67
|
+
const titles = toggleEnabled("digest.titleIndex") ? notes.filter((n) => n.type !== "prompt").sort((a, b) => (b.hits ?? 1) - (a.hits ?? 1)).slice(0, 25).map((n) => n.title) : [];
|
|
68
68
|
if (titles.length > 0) {
|
|
69
69
|
parts.push(`## La b\xF3veda ya tiene conocimiento sobre
|
|
70
70
|
${titles.join(" \xB7 ")}`);
|
package/dist/hooks/on-stop.js
CHANGED
|
@@ -3,18 +3,24 @@ import {
|
|
|
3
3
|
projectName,
|
|
4
4
|
runHook,
|
|
5
5
|
truncate
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-53SIGH5A.js";
|
|
7
7
|
import {
|
|
8
8
|
ensureVaultStructure,
|
|
9
9
|
resolveVault,
|
|
10
|
+
toggleEnabled,
|
|
10
11
|
vaultExists
|
|
11
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-CIOCSIB5.js";
|
|
12
13
|
import {
|
|
14
|
+
VaultIndex,
|
|
13
15
|
appendToNote
|
|
14
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-QB37UGO6.js";
|
|
17
|
+
import "../chunk-EDYBSJSS.js";
|
|
15
18
|
|
|
16
19
|
// src/hooks/on-stop.ts
|
|
17
20
|
import fs from "fs";
|
|
21
|
+
import path from "path";
|
|
22
|
+
import { spawn } from "child_process";
|
|
23
|
+
import { fileURLToPath } from "url";
|
|
18
24
|
function textOf(msg) {
|
|
19
25
|
const c = msg.message?.content;
|
|
20
26
|
if (typeof c === "string") return c;
|
|
@@ -62,4 +68,22 @@ runHook(25e3, async (input) => {
|
|
|
62
68
|
|
|
63
69
|
Proyecto: [[Mapa - ${proj}]]`
|
|
64
70
|
});
|
|
71
|
+
await maybeRebuildInBackground(vault);
|
|
65
72
|
});
|
|
73
|
+
async function maybeRebuildInBackground(vault) {
|
|
74
|
+
try {
|
|
75
|
+
if (!toggleEnabled("index.autoRebuild")) return;
|
|
76
|
+
const idx = VaultIndex.load(vault);
|
|
77
|
+
if (!idx.needsRebuild() && !idx.isDegraded()) return;
|
|
78
|
+
const cli = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "cli.js");
|
|
79
|
+
if (!fs.existsSync(cli)) return;
|
|
80
|
+
const child = spawn(process.execPath, [cli, "--vault", vault.root, "reindex", "--force"], {
|
|
81
|
+
detached: true,
|
|
82
|
+
stdio: "ignore",
|
|
83
|
+
env: { ...process.env, ALEXANDRIA_HOOK: "" }
|
|
84
|
+
// proceso CLI: sí puede reconstruir
|
|
85
|
+
});
|
|
86
|
+
child.unref();
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
}
|
package/dist/mcp/server.js
CHANGED
|
@@ -4,23 +4,22 @@ import {
|
|
|
4
4
|
pkgVersion,
|
|
5
5
|
planContext,
|
|
6
6
|
planQualityHints
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-ZIQYAQCF.js";
|
|
8
8
|
import {
|
|
9
9
|
hybridSearch
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-UWB6RKVN.js";
|
|
11
11
|
import {
|
|
12
12
|
ensureVaultStructure,
|
|
13
|
-
resolveVault
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
VaultIndex
|
|
17
|
-
} from "../chunk-D5ROL42O.js";
|
|
13
|
+
resolveVault,
|
|
14
|
+
toggleEnabled
|
|
15
|
+
} from "../chunk-CIOCSIB5.js";
|
|
18
16
|
import {
|
|
17
|
+
VaultIndex,
|
|
19
18
|
createNote,
|
|
20
19
|
setNoteStatus,
|
|
21
20
|
slugify,
|
|
22
21
|
upsertNote
|
|
23
|
-
} from "../chunk-
|
|
22
|
+
} from "../chunk-QB37UGO6.js";
|
|
24
23
|
import "../chunk-EDYBSJSS.js";
|
|
25
24
|
|
|
26
25
|
// src/mcp/server.ts
|
|
@@ -145,8 +144,9 @@ server.tool(
|
|
|
145
144
|
},
|
|
146
145
|
async ({ title, goal, dod, tasks, design }) => {
|
|
147
146
|
ensureVaultStructure(vault);
|
|
148
|
-
const
|
|
149
|
-
const
|
|
147
|
+
const enrich = toggleEnabled("architect.enrich");
|
|
148
|
+
const ctx = enrich ? await planContext(vault, `${title} ${goal}`) : { similarPlans: [], lessons: [] };
|
|
149
|
+
const hints = enrich ? planQualityHints(dod, tasks, design) : [];
|
|
150
150
|
const idx = VaultIndex.load(vault);
|
|
151
151
|
const map = findMap(idx);
|
|
152
152
|
const content = [
|
|
@@ -4,9 +4,8 @@ import {
|
|
|
4
4
|
renderGraphHtml,
|
|
5
5
|
serveGraph,
|
|
6
6
|
writeStaticGraph
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-XWR74BQ2.js";
|
|
7
|
+
} from "./chunk-FBGIFNIO.js";
|
|
8
|
+
import "./chunk-QB37UGO6.js";
|
|
10
9
|
import "./chunk-EDYBSJSS.js";
|
|
11
10
|
export {
|
|
12
11
|
buildGraphData,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ureck/alexandria",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.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-D5ROL42O.js
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
ensureAlias,
|
|
4
|
-
listMarkdownFiles,
|
|
5
|
-
parseNote
|
|
6
|
-
} from "./chunk-XWR74BQ2.js";
|
|
7
|
-
import {
|
|
8
|
-
DIM,
|
|
9
|
-
MODEL_ID,
|
|
10
|
-
chunkMarkdown,
|
|
11
|
-
dot,
|
|
12
|
-
embed,
|
|
13
|
-
modelPresent
|
|
14
|
-
} from "./chunk-EDYBSJSS.js";
|
|
15
|
-
|
|
16
|
-
// src/core/index.ts
|
|
17
|
-
import fs from "fs";
|
|
18
|
-
import path from "path";
|
|
19
|
-
var SEMANTIC_THRESHOLD = 0.9;
|
|
20
|
-
var SEMANTIC_TOP = 3;
|
|
21
|
-
var VaultIndex = class _VaultIndex {
|
|
22
|
-
constructor(vault) {
|
|
23
|
-
this.vault = vault;
|
|
24
|
-
this.meta = {
|
|
25
|
-
version: 1,
|
|
26
|
-
model: MODEL_ID,
|
|
27
|
-
dim: DIM,
|
|
28
|
-
mtimes: {},
|
|
29
|
-
notes: {},
|
|
30
|
-
chunks: [],
|
|
31
|
-
links: []
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
vault;
|
|
35
|
-
meta;
|
|
36
|
-
/** filas de embeddings alineadas 1:1 con meta.chunks; null = índice sin vectores */
|
|
37
|
-
emb = null;
|
|
38
|
-
get metaPath() {
|
|
39
|
-
return path.join(this.vault.cache, "meta.json");
|
|
40
|
-
}
|
|
41
|
-
get embPath() {
|
|
42
|
-
return path.join(this.vault.cache, "embeddings.bin");
|
|
43
|
-
}
|
|
44
|
-
static load(vault) {
|
|
45
|
-
const idx = new _VaultIndex(vault);
|
|
46
|
-
try {
|
|
47
|
-
const meta = JSON.parse(fs.readFileSync(idx.metaPath, "utf8"));
|
|
48
|
-
if (meta.version === 1 && meta.model === MODEL_ID) {
|
|
49
|
-
idx.meta = meta;
|
|
50
|
-
try {
|
|
51
|
-
const buf = fs.readFileSync(idx.embPath);
|
|
52
|
-
const arr = new Float32Array(buf.buffer, buf.byteOffset, buf.byteLength / 4);
|
|
53
|
-
if (arr.length === meta.chunks.length * meta.dim) {
|
|
54
|
-
idx.emb = arr.slice();
|
|
55
|
-
} else {
|
|
56
|
-
idx.emb = null;
|
|
57
|
-
try {
|
|
58
|
-
fs.rmSync(idx.embPath, { force: true });
|
|
59
|
-
} catch {
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
} catch {
|
|
63
|
-
idx.emb = null;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
} catch (e) {
|
|
67
|
-
if (fs.existsSync(idx.metaPath)) {
|
|
68
|
-
try {
|
|
69
|
-
fs.rmSync(idx.metaPath, { force: true });
|
|
70
|
-
fs.rmSync(idx.embPath, { force: true });
|
|
71
|
-
} catch {
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return idx;
|
|
76
|
-
}
|
|
77
|
-
/** Escritura atómica: tmp + rename — un hook y un comando concurrentes nunca dejan el archivo a medias. */
|
|
78
|
-
writeAtomic(file, data) {
|
|
79
|
-
const tmp = `${file}.${process.pid}.tmp`;
|
|
80
|
-
fs.writeFileSync(tmp, data);
|
|
81
|
-
fs.renameSync(tmp, file);
|
|
82
|
-
}
|
|
83
|
-
save() {
|
|
84
|
-
fs.mkdirSync(this.vault.cache, { recursive: true });
|
|
85
|
-
this.writeAtomic(this.metaPath, JSON.stringify(this.meta));
|
|
86
|
-
if (this.emb) {
|
|
87
|
-
this.writeAtomic(this.embPath, Buffer.from(this.emb.buffer, this.emb.byteOffset, this.emb.byteLength));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
row(i) {
|
|
91
|
-
return this.emb.subarray(i * this.meta.dim, (i + 1) * this.meta.dim);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Reindexado incremental por mtime. Solo procesa archivos nuevos/cambiados.
|
|
95
|
-
* `withEmbeddings=false` → índice keyword-only (sin cargar modelo).
|
|
96
|
-
*/
|
|
97
|
-
async refresh(withEmbeddings = modelPresent(), force = false) {
|
|
98
|
-
const files = listMarkdownFiles(this.vault.root);
|
|
99
|
-
const onDisk = /* @__PURE__ */ new Map();
|
|
100
|
-
for (const abs of files) {
|
|
101
|
-
const rel = path.relative(this.vault.root, abs).split(path.sep).join("/");
|
|
102
|
-
onDisk.set(rel, { abs, mtime: fs.statSync(abs).mtimeMs });
|
|
103
|
-
}
|
|
104
|
-
if (withEmbeddings && this.emb === null && this.meta.chunks.length > 0) {
|
|
105
|
-
force = true;
|
|
106
|
-
}
|
|
107
|
-
const changed = [];
|
|
108
|
-
for (const [rel, info] of onDisk) {
|
|
109
|
-
if (force || this.meta.mtimes[rel] !== info.mtime) changed.push(rel);
|
|
110
|
-
}
|
|
111
|
-
const removed = Object.keys(this.meta.mtimes).filter((rel) => !onDisk.has(rel));
|
|
112
|
-
if (changed.length === 0 && removed.length === 0) {
|
|
113
|
-
return { changed: 0, removed: 0, embedded: this.emb !== null };
|
|
114
|
-
}
|
|
115
|
-
const keep = new Set(
|
|
116
|
-
this.meta.chunks.map((_, i) => i).filter((i) => {
|
|
117
|
-
const rel = this.meta.chunks[i].note;
|
|
118
|
-
return onDisk.has(rel) && !changed.includes(rel);
|
|
119
|
-
})
|
|
120
|
-
);
|
|
121
|
-
const newChunks = [];
|
|
122
|
-
const keptRows = [];
|
|
123
|
-
const hadEmb = this.emb !== null;
|
|
124
|
-
for (const i of keep) {
|
|
125
|
-
newChunks.push(this.meta.chunks[i]);
|
|
126
|
-
if (hadEmb) keptRows.push(this.row(i).slice());
|
|
127
|
-
}
|
|
128
|
-
const freshChunks = [];
|
|
129
|
-
for (const rel of changed) {
|
|
130
|
-
const info = onDisk.get(rel);
|
|
131
|
-
try {
|
|
132
|
-
const managedRel = path.relative(this.vault.root, this.vault.managed).split(path.sep).join("/");
|
|
133
|
-
const inManaged = managedRel === "" || rel.startsWith(`${managedRel}/`);
|
|
134
|
-
if (inManaged && ensureAlias(info.abs)) {
|
|
135
|
-
info.mtime = fs.statSync(info.abs).mtimeMs;
|
|
136
|
-
}
|
|
137
|
-
const note = parseNote(this.vault.root, info.abs);
|
|
138
|
-
this.meta.notes[rel] = {
|
|
139
|
-
rel,
|
|
140
|
-
title: note.title,
|
|
141
|
-
type: note.type,
|
|
142
|
-
status: note.status,
|
|
143
|
-
tags: note.tags,
|
|
144
|
-
created: note.created,
|
|
145
|
-
hits: note.hits,
|
|
146
|
-
links: note.links
|
|
147
|
-
};
|
|
148
|
-
const pieces = chunkMarkdown(note.content);
|
|
149
|
-
const titlePrefix = note.title ? `${note.title}. ` : "";
|
|
150
|
-
for (const p of pieces) {
|
|
151
|
-
freshChunks.push({ note: rel, heading: p.heading, text: p.text });
|
|
152
|
-
}
|
|
153
|
-
if (pieces.length === 0 && note.title) {
|
|
154
|
-
freshChunks.push({ note: rel, text: titlePrefix });
|
|
155
|
-
}
|
|
156
|
-
} catch {
|
|
157
|
-
}
|
|
158
|
-
this.meta.mtimes[rel] = info.mtime;
|
|
159
|
-
}
|
|
160
|
-
for (const rel of removed) {
|
|
161
|
-
delete this.meta.mtimes[rel];
|
|
162
|
-
delete this.meta.notes[rel];
|
|
163
|
-
}
|
|
164
|
-
for (const rel of Object.keys(this.meta.notes)) {
|
|
165
|
-
if (!onDisk.has(rel)) delete this.meta.notes[rel];
|
|
166
|
-
}
|
|
167
|
-
let embedded = hadEmb || newChunks.length === 0;
|
|
168
|
-
let freshRows = [];
|
|
169
|
-
if (withEmbeddings && freshChunks.length > 0) {
|
|
170
|
-
try {
|
|
171
|
-
freshRows = await embed(
|
|
172
|
-
freshChunks.map((c) => `${this.meta.notes[c.note]?.title ?? ""}
|
|
173
|
-
${c.heading ?? ""}
|
|
174
|
-
${c.text}`),
|
|
175
|
-
"passage"
|
|
176
|
-
);
|
|
177
|
-
embedded = true;
|
|
178
|
-
} catch {
|
|
179
|
-
embedded = false;
|
|
180
|
-
}
|
|
181
|
-
} else if (freshChunks.length > 0) {
|
|
182
|
-
embedded = false;
|
|
183
|
-
}
|
|
184
|
-
this.meta.chunks = [...newChunks, ...freshChunks];
|
|
185
|
-
if (embedded && (hadEmb || newChunks.length === 0) && freshRows.length === freshChunks.length) {
|
|
186
|
-
const all = new Float32Array(this.meta.chunks.length * this.meta.dim);
|
|
187
|
-
[...keptRows, ...freshRows].forEach((r, i) => all.set(r, i * this.meta.dim));
|
|
188
|
-
this.emb = all;
|
|
189
|
-
} else if (freshChunks.length > 0 && !embedded) {
|
|
190
|
-
this.emb = null;
|
|
191
|
-
}
|
|
192
|
-
this.rebuildLinks();
|
|
193
|
-
this.save();
|
|
194
|
-
try {
|
|
195
|
-
const { writeStaticGraph } = await import("./viewer-73ZWPIDC.js");
|
|
196
|
-
writeStaticGraph(this);
|
|
197
|
-
} catch {
|
|
198
|
-
}
|
|
199
|
-
return { changed: changed.length, removed: removed.length, embedded: this.emb !== null };
|
|
200
|
-
}
|
|
201
|
-
/** Wikilinks (título → nota) + links semánticos (similitud entre notas). */
|
|
202
|
-
rebuildLinks() {
|
|
203
|
-
const byTitle = /* @__PURE__ */ new Map();
|
|
204
|
-
for (const n of Object.values(this.meta.notes)) {
|
|
205
|
-
byTitle.set(n.title.toLowerCase(), n.rel);
|
|
206
|
-
byTitle.set(n.rel.replace(/\.md$/, "").split("/").pop().toLowerCase(), n.rel);
|
|
207
|
-
}
|
|
208
|
-
const links = [];
|
|
209
|
-
for (const n of Object.values(this.meta.notes)) {
|
|
210
|
-
for (const target of n.links) {
|
|
211
|
-
const to = byTitle.get(target.toLowerCase());
|
|
212
|
-
if (to && to !== n.rel) links.push({ from: n.rel, to, type: "wikilink" });
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
if (this.emb) {
|
|
216
|
-
const rels = Object.keys(this.meta.notes);
|
|
217
|
-
const noteVec = /* @__PURE__ */ new Map();
|
|
218
|
-
for (const rel of rels) {
|
|
219
|
-
const idxs = this.meta.chunks.map((c, i) => c.note === rel ? i : -1).filter((i) => i >= 0);
|
|
220
|
-
if (idxs.length === 0) continue;
|
|
221
|
-
const v = new Float32Array(this.meta.dim);
|
|
222
|
-
for (const i of idxs) {
|
|
223
|
-
const r = this.row(i);
|
|
224
|
-
for (let d = 0; d < this.meta.dim; d++) v[d] += r[d];
|
|
225
|
-
}
|
|
226
|
-
let norm = 0;
|
|
227
|
-
for (let d = 0; d < this.meta.dim; d++) norm += v[d] * v[d];
|
|
228
|
-
norm = Math.sqrt(norm) || 1;
|
|
229
|
-
for (let d = 0; d < this.meta.dim; d++) v[d] /= norm;
|
|
230
|
-
noteVec.set(rel, v);
|
|
231
|
-
}
|
|
232
|
-
const seen = new Set(links.map((l) => `${l.from}\u2192${l.to}`));
|
|
233
|
-
const vecRels = [...noteVec.keys()];
|
|
234
|
-
for (const a of vecRels) {
|
|
235
|
-
const sims = [];
|
|
236
|
-
for (const b of vecRels) {
|
|
237
|
-
if (a === b) continue;
|
|
238
|
-
sims.push({ rel: b, s: dot(noteVec.get(a), noteVec.get(b)) });
|
|
239
|
-
}
|
|
240
|
-
sims.sort((x, y) => y.s - x.s);
|
|
241
|
-
for (const { rel: b, s } of sims.slice(0, SEMANTIC_TOP)) {
|
|
242
|
-
if (s < SEMANTIC_THRESHOLD) break;
|
|
243
|
-
const key = a < b ? `${a}\u2192${b}` : `${b}\u2192${a}`;
|
|
244
|
-
if (seen.has(key) || seen.has(`${a}\u2192${b}`) || seen.has(`${b}\u2192${a}`)) continue;
|
|
245
|
-
seen.add(key);
|
|
246
|
-
links.push({ from: a, to: b, type: "semantic", w: Math.round(s * 100) / 100 });
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
this.meta.links = links;
|
|
251
|
-
}
|
|
252
|
-
/** Vecinos directos de una nota en el grafo (sin releer archivos). */
|
|
253
|
-
neighbors(rel) {
|
|
254
|
-
const out = [];
|
|
255
|
-
for (const l of this.meta.links) {
|
|
256
|
-
const other = l.from === rel ? l.to : l.to === rel ? l.from : null;
|
|
257
|
-
if (other && this.meta.notes[other]) {
|
|
258
|
-
out.push({ note: this.meta.notes[other], type: l.type, w: l.w });
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
return out;
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
export {
|
|
266
|
-
VaultIndex
|
|
267
|
-
};
|
package/dist/chunk-DEDAOKAV.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// src/hooks/util.ts
|
|
4
|
-
async function readStdinJson() {
|
|
5
|
-
const chunks = [];
|
|
6
|
-
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
7
|
-
const raw = Buffer.concat(chunks).toString("utf8").trim();
|
|
8
|
-
if (!raw) return {};
|
|
9
|
-
try {
|
|
10
|
-
return JSON.parse(raw);
|
|
11
|
-
} catch {
|
|
12
|
-
return {};
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function runHook(budgetMs, body) {
|
|
16
|
-
const cleanup = async () => {
|
|
17
|
-
try {
|
|
18
|
-
const { disposeEmbedder } = await import("./embedder-7Z4XNL6H.js");
|
|
19
|
-
await disposeEmbedder();
|
|
20
|
-
} catch {
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const timer = setTimeout(() => void cleanup(), budgetMs);
|
|
24
|
-
timer.unref();
|
|
25
|
-
process.exitCode = 0;
|
|
26
|
-
readStdinJson().then((input) => body(input)).catch(() => {
|
|
27
|
-
}).finally(() => {
|
|
28
|
-
clearTimeout(timer);
|
|
29
|
-
void cleanup();
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
function projectName(cwd) {
|
|
33
|
-
if (!cwd) return "general";
|
|
34
|
-
return cwd.replace(/[\\/]+$/, "").split(/[\\/]/).pop() || "general";
|
|
35
|
-
}
|
|
36
|
-
function truncate(text, max) {
|
|
37
|
-
return text.length <= max ? text : text.slice(0, max) + " \u2026";
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export {
|
|
41
|
-
runHook,
|
|
42
|
-
projectName,
|
|
43
|
-
truncate
|
|
44
|
-
};
|