@ureck/alexandria 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -5
- package/dist/chunk-53SIGH5A.js +69 -0
- package/dist/{chunk-TFQ7WSIB.js → chunk-CIOCSIB5.js} +6 -0
- package/dist/{chunk-XY7U4CAQ.js → chunk-FBGIFNIO.js} +1 -1
- package/dist/{chunk-AXUEYSNZ.js → chunk-QB37UGO6.js} +224 -23
- package/dist/{chunk-AHBSZGSC.js → chunk-UWB6RKVN.js} +2 -1
- package/dist/{chunk-T5VNBQEC.js → chunk-ZIQYAQCF.js} +2 -2
- package/dist/cli.js +462 -129
- package/dist/hooks/on-prompt.js +15 -8
- package/dist/hooks/on-session-start.js +3 -4
- package/dist/hooks/on-stop.js +27 -3
- package/dist/mcp/server.js +11 -11
- package/dist/{viewer-2YMJBQRH.js → viewer-JQCSWJ3C.js} +2 -3
- package/package.json +1 -1
- package/dist/chunk-DEDAOKAV.js +0 -44
- package/dist/chunk-XWR74BQ2.js +0 -170
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
Alexandria automatically captures your AI prompts and sessions, searches that knowledge **before** spending tokens, and connects everything in an Obsidian-style graph. **100% local**: no database, no API keys, no telemetry, no cost.
|
|
12
12
|
|
|
13
|
-
Works with the most popular agents via MCP: **Claude Code · Cursor · OpenCode ·
|
|
13
|
+
Works with the most popular agents via MCP: **Claude Code · Cursor · OpenCode · Devin CLI · Cline · Codex CLI · Gemini CLI · VS Code (Copilot) · OpenClaw · Hermes Agent · Windsurf (legacy)**.
|
|
14
14
|
|
|
15
15
|
## Why?
|
|
16
16
|
|
|
@@ -34,7 +34,7 @@ It lives in the MCP tools themselves — their names and descriptions carry the
|
|
|
34
34
|
| MCP tool | What the agent does with it | Token payoff |
|
|
35
35
|
|---|---|---|
|
|
36
36
|
| `plan_create(title, goal, dod, tasks, design?)` | Plans like an **architect**: clarifies vague goals first, optionally records the architecture (`design` → a `## Design` section), and the response surfaces **similar past plans + relevant lessons** plus quality hints (verifiable DoD, small tasks) — suggestions, never a gate | No wandering; open plans are re-injected next session so work is resumed, not repeated |
|
|
37
|
-
| `task_verify(plan, task, passed, verify_command)` | **Runs** `verify_command` (e.g. `npm test`) and takes the verdict from the real exit code — not from the agent's word. Flags a **discrepancy** if the agent claimed otherwise; without a command the note is tagged `self-reported` and `ale audit` calls it out | "✅ 12/12 passed" (5 tokens) instead of a 500-line log; on failure it automatically surfaces **past lessons** that match |
|
|
37
|
+
| `task_verify(plan, task, passed, verify_command, cwd?)` | **Runs** `verify_command` (e.g. `npm test`) and takes the verdict from the real exit code — not from the agent's word. Flags a **discrepancy** if the agent claimed otherwise; without a command the note is tagged `self-reported` and `ale audit` calls it out | "✅ 12/12 passed" (5 tokens) instead of a 500-line log; on failure it automatically surfaces **past lessons** that match |
|
|
38
38
|
| `lesson_extract(title, lesson, links)` | Distills the root cause + fix after solving something non-obvious | ~200 tokens today replace ~20,000 tokens of re-debugging next month |
|
|
39
39
|
|
|
40
40
|
Lessons and solutions get a ranking boost in search, so the most valuable knowledge always surfaces first. The protocol is **on by default**; toggle it anytime:
|
|
@@ -63,7 +63,7 @@ Verify:
|
|
|
63
63
|
|
|
64
64
|
```bash
|
|
65
65
|
$ ale --version
|
|
66
|
-
1.
|
|
66
|
+
1.3.0
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
## Getting started
|
|
@@ -142,7 +142,7 @@ ale init --off architect.enrich,digest.map # disable from the start
|
|
|
142
142
|
ale config set tokens.solutionCache false # scriptable, one by one
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
-
The
|
|
145
|
+
The toggles: Protocol manifest (~6% of the session digest), Architect enrichment in `plan_create` (~+90 tokens/plan), solution cache (up to ~500 tokens/prompt), per-prompt semantic search (the **main saving mechanism** — up to ~1500 tokens/prompt, disabling it defeats the point), project map in the digest (up to ~1000 tokens), title index (~200 tokens), and background index rebuild at session close (costs no tokens). All on by default; nothing changes unless you touch them.
|
|
146
146
|
|
|
147
147
|
### Deep project context (`ale scan`)
|
|
148
148
|
|
|
@@ -159,6 +159,7 @@ Four read-only scanners write compact notes (one line per entry) that the agent
|
|
|
159
159
|
- **`Env - <project>`** — environment variable **NAMES only, never values** (from `.env.example` / `.env` / `.env.local`).
|
|
160
160
|
- **`Datos - <project>`** — data schema parsed from files (prisma models, drizzle tables, `CREATE TABLE` in migrations) — no DB connection.
|
|
161
161
|
- **`Convenciones - <project>`** — package manager, monorepo, TS strict, import aliases, framework.
|
|
162
|
+
- **`Flujo - <project>`** — what a request goes through: `GET /api/x → auth: requirePermiso(...) → datos: getX, createX → audits`, plus what the middleware protects. The others say what exists; this one says how it connects.
|
|
162
163
|
|
|
163
164
|
It never touches your source code, and it guarantees the vault (and personal configs) are gitignored before writing — your notes never reach a shared repo, even if you never ran `ale init`.
|
|
164
165
|
|
|
@@ -251,7 +252,8 @@ ale agents cursor,gemini # just these
|
|
|
251
252
|
| Claude Code | `.mcp.json` / `claude mcp add` + hooks | ✓ |
|
|
252
253
|
| Cursor | `~/.cursor/mcp.json` / `.cursor/mcp.json` | ✓ |
|
|
253
254
|
| OpenCode | `opencode.json` | ✓ |
|
|
254
|
-
|
|
|
255
|
+
| Devin CLI (Cognition) | `.devin/mcp_config.local.json` | ✓ |
|
|
256
|
+
| Windsurf (legacy) | `~/.codeium/windsurf/mcp_config.json` | — |
|
|
255
257
|
| Cline | `cline_mcp_settings.json` (VS Code) | — |
|
|
256
258
|
| Codex CLI | `~/.codex/config.toml` | — |
|
|
257
259
|
| Gemini CLI | `~/.gemini/settings.json` / `.gemini/settings.json` | ✓ |
|
|
@@ -291,6 +293,7 @@ AI agent session
|
|
|
291
293
|
| `ale init [--project] [--path <dir>] [--agents <ids>] [--auto\|--manual] [--no-protocol] [--portable]` | Installs everything: vault, hooks, MCP, .gitignore, project scan, CLAUDE.md. `--portable` writes an npx-based MCP command safe to commit for teams |
|
|
292
294
|
| `ale scan` | Deep project context: API routes, env var **names**, data schema (file parse), conventions → compact notes (adaptive cap ≤200 entries, fair sampling in monorepos). Read-only; ensures .gitignore |
|
|
293
295
|
| `ale toggles` | Interactive menu to enable/disable every token-spending behavior, each with its real approximate cost. Works before or after install; scriptable via `ale init --off <keys>` |
|
|
296
|
+
| `ale skills:evolve` | Generates/updates a **living skill for the project** from what the vault knows (stack, conventions, app flow, lessons). Always shows a diff and asks before writing |
|
|
294
297
|
| `ale agents [ids] [--project]` | List agents / register the MCP server |
|
|
295
298
|
| `ale search <query> [-k n] [--expand]` | Hybrid search; `--expand` pulls graph neighbors. With the Protocol on, appends the **chain** (plan + verification + lesson) connected to the top hit |
|
|
296
299
|
| `ale add <title> [-c text] [--file <path>] [-t tags]` | Save a note (inline, from file, or stdin) |
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/hooks/util.ts
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import os from "os";
|
|
6
|
+
import path from "path";
|
|
7
|
+
async function readStdinJson() {
|
|
8
|
+
const chunks = [];
|
|
9
|
+
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
10
|
+
const raw = Buffer.concat(chunks).toString("utf8").trim();
|
|
11
|
+
if (!raw) return {};
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(raw);
|
|
14
|
+
} catch {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
var expired = false;
|
|
19
|
+
function logHookError(kind, detail) {
|
|
20
|
+
try {
|
|
21
|
+
const dir = process.platform === "win32" && process.env.LOCALAPPDATA ? path.join(process.env.LOCALAPPDATA, "alexandria") : path.join(os.homedir(), ".cache", "alexandria");
|
|
22
|
+
const file = path.join(dir, "hook-errors.log");
|
|
23
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
24
|
+
try {
|
|
25
|
+
if (fs.statSync(file).size > 256 * 1024) fs.rmSync(file, { force: true });
|
|
26
|
+
} catch {
|
|
27
|
+
}
|
|
28
|
+
fs.appendFileSync(file, `${(/* @__PURE__ */ new Date()).toISOString()} ${kind} ${detail.slice(0, 500)}
|
|
29
|
+
`);
|
|
30
|
+
} catch {
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function runHook(budgetMs, body) {
|
|
34
|
+
process.env.ALEXANDRIA_HOOK = "1";
|
|
35
|
+
const cleanup = async () => {
|
|
36
|
+
try {
|
|
37
|
+
const { disposeEmbedder } = await import("./embedder-7Z4XNL6H.js");
|
|
38
|
+
await disposeEmbedder();
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const timer = setTimeout(() => {
|
|
43
|
+
expired = true;
|
|
44
|
+
logHookError("timeout", `presupuesto de ${budgetMs}ms agotado`);
|
|
45
|
+
void cleanup();
|
|
46
|
+
}, budgetMs);
|
|
47
|
+
timer.unref();
|
|
48
|
+
process.exitCode = 0;
|
|
49
|
+
readStdinJson().then((input) => body(input)).catch((e) => {
|
|
50
|
+
logHookError("error", e instanceof Error ? `${e.message}
|
|
51
|
+
${e.stack ?? ""}` : String(e));
|
|
52
|
+
}).finally(() => {
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
void cleanup();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function projectName(cwd) {
|
|
58
|
+
if (!cwd) return "general";
|
|
59
|
+
return cwd.replace(/[\\/]+$/, "").split(/[\\/]/).pop() || "general";
|
|
60
|
+
}
|
|
61
|
+
function truncate(text, max) {
|
|
62
|
+
return text.length <= max ? text : text.slice(0, max) + " \u2026";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
runHook,
|
|
67
|
+
projectName,
|
|
68
|
+
truncate
|
|
69
|
+
};
|
|
@@ -135,6 +135,12 @@ var TOKEN_TOGGLES = [
|
|
|
135
135
|
label: "\xCDndice de t\xEDtulos en el digest",
|
|
136
136
|
desc: "Lista hasta 25 t\xEDtulos de lo que la b\xF3veda ya sabe",
|
|
137
137
|
impact: "cuesta ~10% del digest (~200 tokens); orienta al agente sobre qu\xE9 buscar"
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
key: "index.autoRebuild",
|
|
141
|
+
label: "Reparar el \xEDndice al cerrar sesi\xF3n",
|
|
142
|
+
desc: "Si el \xEDndice qued\xF3 sin vectores, reconstruirlo en segundo plano al terminar la sesi\xF3n",
|
|
143
|
+
impact: "no gasta tokens; sin esto la b\xFAsqueda puede quedarse en keyword-only (peor contexto por prompt)"
|
|
138
144
|
}
|
|
139
145
|
];
|
|
140
146
|
function writeProjectConfig(projectDir, vaultPath) {
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
ensureAlias,
|
|
4
|
-
listMarkdownFiles,
|
|
5
|
-
parseNote
|
|
6
|
-
} from "./chunk-XWR74BQ2.js";
|
|
7
2
|
import {
|
|
8
3
|
DIM,
|
|
9
4
|
MODEL_ID,
|
|
@@ -13,9 +8,169 @@ import {
|
|
|
13
8
|
modelPresent
|
|
14
9
|
} from "./chunk-EDYBSJSS.js";
|
|
15
10
|
|
|
16
|
-
// src/core/
|
|
11
|
+
// src/core/notes.ts
|
|
17
12
|
import fs from "fs";
|
|
18
13
|
import path from "path";
|
|
14
|
+
import matter from "gray-matter";
|
|
15
|
+
var NOTE_TYPES = [
|
|
16
|
+
"note",
|
|
17
|
+
"prompt",
|
|
18
|
+
"session",
|
|
19
|
+
"map",
|
|
20
|
+
"plan",
|
|
21
|
+
"task",
|
|
22
|
+
"verification",
|
|
23
|
+
"lesson",
|
|
24
|
+
"solution"
|
|
25
|
+
];
|
|
26
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set([".obsidian", ".vault", ".trash", ".git", "node_modules"]);
|
|
27
|
+
function extractWikilinks(content) {
|
|
28
|
+
const out = /* @__PURE__ */ new Set();
|
|
29
|
+
const re = /\[\[([^\]|#\n]+)(?:[|#][^\]]*)?\]\]/g;
|
|
30
|
+
let m;
|
|
31
|
+
while ((m = re.exec(content)) !== null) {
|
|
32
|
+
const target = m[1].trim();
|
|
33
|
+
if (target) out.add(target);
|
|
34
|
+
}
|
|
35
|
+
return [...out];
|
|
36
|
+
}
|
|
37
|
+
function slugify(text) {
|
|
38
|
+
return text.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80) || "nota";
|
|
39
|
+
}
|
|
40
|
+
function listMarkdownFiles(root) {
|
|
41
|
+
const out = [];
|
|
42
|
+
const walk = (dir) => {
|
|
43
|
+
let entries;
|
|
44
|
+
try {
|
|
45
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
46
|
+
} catch {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
for (const e of entries) {
|
|
50
|
+
if (e.name.startsWith(".") || SKIP_DIRS.has(e.name)) continue;
|
|
51
|
+
const full = path.join(dir, e.name);
|
|
52
|
+
if (e.isDirectory()) walk(full);
|
|
53
|
+
else if (e.isFile() && e.name.endsWith(".md")) out.push(full);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
walk(root);
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
function parseNote(root, absPath) {
|
|
60
|
+
const raw = fs.readFileSync(absPath, "utf8");
|
|
61
|
+
const { data, content } = matter(raw);
|
|
62
|
+
const rel = path.relative(root, absPath).split(path.sep).join("/");
|
|
63
|
+
const title = typeof data.title === "string" && data.title || path.basename(absPath, ".md");
|
|
64
|
+
const type = NOTE_TYPES.includes(data.type) ? data.type : "note";
|
|
65
|
+
const status = ["active", "completed", "failed"].includes(data.status) ? data.status : void 0;
|
|
66
|
+
const tags = Array.isArray(data.tags) ? data.tags.map(String) : [];
|
|
67
|
+
return {
|
|
68
|
+
rel,
|
|
69
|
+
title,
|
|
70
|
+
type,
|
|
71
|
+
status,
|
|
72
|
+
tags,
|
|
73
|
+
created: data.created ? String(data.created) : void 0,
|
|
74
|
+
hits: typeof data.hits === "number" ? data.hits : 1,
|
|
75
|
+
content,
|
|
76
|
+
links: extractWikilinks(content)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function frontmatter(n) {
|
|
80
|
+
const lines = [
|
|
81
|
+
"---",
|
|
82
|
+
`title: ${JSON.stringify(n.title)}`,
|
|
83
|
+
// aliases: Obsidian resuelve [[wikilinks]] contra alias, no contra el title
|
|
84
|
+
// del frontmatter — sin esto su graph view muestra los enlaces como rotos
|
|
85
|
+
`aliases: [${JSON.stringify(n.title)}]`,
|
|
86
|
+
`type: ${n.type}`,
|
|
87
|
+
...n.status ? [`status: ${n.status}`] : [],
|
|
88
|
+
`tags: [${n.tags.map((t) => JSON.stringify(t)).join(", ")}]`,
|
|
89
|
+
`created: ${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
90
|
+
`hits: ${n.hits ?? 1}`,
|
|
91
|
+
"---",
|
|
92
|
+
""
|
|
93
|
+
];
|
|
94
|
+
return lines.join("\n");
|
|
95
|
+
}
|
|
96
|
+
function ensureAlias(absPath) {
|
|
97
|
+
try {
|
|
98
|
+
const raw = fs.readFileSync(absPath, "utf8");
|
|
99
|
+
const { data, content } = matter(raw);
|
|
100
|
+
if (!data.title || data.aliases) return false;
|
|
101
|
+
data.aliases = [String(data.title)];
|
|
102
|
+
fs.writeFileSync(absPath, matter.stringify(content, data));
|
|
103
|
+
return true;
|
|
104
|
+
} catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function createNote(managed, n) {
|
|
109
|
+
const dir = path.join(managed, n.dir ?? "notes");
|
|
110
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
111
|
+
const date = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
112
|
+
const base = `${date}-${slugify(n.title)}`;
|
|
113
|
+
let file = path.join(dir, `${base}.md`);
|
|
114
|
+
let i = 2;
|
|
115
|
+
while (fs.existsSync(file)) file = path.join(dir, `${base}-${i++}.md`);
|
|
116
|
+
fs.writeFileSync(
|
|
117
|
+
file,
|
|
118
|
+
frontmatter({ title: n.title, type: n.type ?? "note", tags: n.tags ?? [], status: n.status }) + n.content.trim() + "\n"
|
|
119
|
+
);
|
|
120
|
+
return file;
|
|
121
|
+
}
|
|
122
|
+
function setNoteStatus(absPath, status) {
|
|
123
|
+
const raw = fs.readFileSync(absPath, "utf8");
|
|
124
|
+
const { data, content } = matter(raw);
|
|
125
|
+
data.status = status;
|
|
126
|
+
data.updated = (/* @__PURE__ */ new Date()).toISOString();
|
|
127
|
+
fs.writeFileSync(absPath, matter.stringify(content, data));
|
|
128
|
+
}
|
|
129
|
+
function touchNote(absPath) {
|
|
130
|
+
const raw = fs.readFileSync(absPath, "utf8");
|
|
131
|
+
const { data, content } = matter(raw);
|
|
132
|
+
data.hits = (typeof data.hits === "number" ? data.hits : 1) + 1;
|
|
133
|
+
data.updated = (/* @__PURE__ */ new Date()).toISOString();
|
|
134
|
+
fs.writeFileSync(absPath, matter.stringify(content, data));
|
|
135
|
+
}
|
|
136
|
+
function upsertNote(managed, n) {
|
|
137
|
+
const dir = path.join(managed, n.dir ?? "notes");
|
|
138
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
139
|
+
const file = path.join(dir, `${n.fixedName}.md`);
|
|
140
|
+
if (fs.existsSync(file)) {
|
|
141
|
+
const raw = fs.readFileSync(file, "utf8");
|
|
142
|
+
const { data } = matter(raw);
|
|
143
|
+
data.updated = (/* @__PURE__ */ new Date()).toISOString();
|
|
144
|
+
fs.writeFileSync(file, matter.stringify(n.content.trim() + "\n", data));
|
|
145
|
+
} else {
|
|
146
|
+
fs.writeFileSync(
|
|
147
|
+
file,
|
|
148
|
+
frontmatter({ title: n.title, type: n.type ?? "note", tags: n.tags ?? [], status: n.status }) + n.content.trim() + "\n"
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
return file;
|
|
152
|
+
}
|
|
153
|
+
function appendToNote(managed, n) {
|
|
154
|
+
const dir = path.join(managed, n.dir ?? "sessions");
|
|
155
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
156
|
+
const file = path.join(dir, `${n.fixedName}.md`);
|
|
157
|
+
if (fs.existsSync(file)) {
|
|
158
|
+
fs.appendFileSync(file, "\n" + n.content.trim() + "\n");
|
|
159
|
+
} else {
|
|
160
|
+
fs.writeFileSync(
|
|
161
|
+
file,
|
|
162
|
+
frontmatter({ title: n.title, type: n.type ?? "session", tags: n.tags ?? [], status: n.status }) + n.content.trim() + "\n"
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
return file;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/core/index.ts
|
|
169
|
+
import fs2 from "fs";
|
|
170
|
+
import path2 from "path";
|
|
171
|
+
function isHookProcess() {
|
|
172
|
+
return process.env.ALEXANDRIA_HOOK === "1";
|
|
173
|
+
}
|
|
19
174
|
var SEMANTIC_THRESHOLD = 0.9;
|
|
20
175
|
var SEMANTIC_TOP = 3;
|
|
21
176
|
var VaultIndex = class _VaultIndex {
|
|
@@ -38,27 +193,34 @@ var VaultIndex = class _VaultIndex {
|
|
|
38
193
|
/** diccionario lazy tag/type → rels; la bóveda nunca borra, así que los
|
|
39
194
|
* escaneos lineales sobre TODAS las notas crecen para siempre — esto los evita */
|
|
40
195
|
_tagIndex = null;
|
|
196
|
+
/**
|
|
197
|
+
* ¿Puede este contexto reconstruir el índice entero (caro)? true en CLI,
|
|
198
|
+
* false en hooks — un hook con presupuesto corto jamás debe intentarlo.
|
|
199
|
+
* Default = lo que diga el proceso (runHook marca el proceso como hook), así
|
|
200
|
+
* queda cubierto CUALQUIER camino de código, no solo los que pasan el flag.
|
|
201
|
+
*/
|
|
202
|
+
allowFullRebuild = !isHookProcess();
|
|
41
203
|
get metaPath() {
|
|
42
|
-
return
|
|
204
|
+
return path2.join(this.vault.cache, "meta.json");
|
|
43
205
|
}
|
|
44
206
|
get embPath() {
|
|
45
|
-
return
|
|
207
|
+
return path2.join(this.vault.cache, "embeddings.bin");
|
|
46
208
|
}
|
|
47
209
|
static load(vault) {
|
|
48
210
|
const idx = new _VaultIndex(vault);
|
|
49
211
|
try {
|
|
50
|
-
const meta = JSON.parse(
|
|
212
|
+
const meta = JSON.parse(fs2.readFileSync(idx.metaPath, "utf8"));
|
|
51
213
|
if (meta.version === 1 && meta.model === MODEL_ID) {
|
|
52
214
|
idx.meta = meta;
|
|
53
215
|
try {
|
|
54
|
-
const buf =
|
|
216
|
+
const buf = fs2.readFileSync(idx.embPath);
|
|
55
217
|
const arr = new Float32Array(buf.buffer, buf.byteOffset, buf.byteLength / 4);
|
|
56
218
|
if (arr.length === meta.chunks.length * meta.dim) {
|
|
57
219
|
idx.emb = arr.slice();
|
|
58
220
|
} else {
|
|
59
221
|
idx.emb = null;
|
|
60
222
|
try {
|
|
61
|
-
|
|
223
|
+
fs2.rmSync(idx.embPath, { force: true });
|
|
62
224
|
} catch {
|
|
63
225
|
}
|
|
64
226
|
}
|
|
@@ -67,24 +229,50 @@ var VaultIndex = class _VaultIndex {
|
|
|
67
229
|
}
|
|
68
230
|
}
|
|
69
231
|
} catch (e) {
|
|
70
|
-
if (
|
|
232
|
+
if (fs2.existsSync(idx.metaPath)) {
|
|
71
233
|
try {
|
|
72
|
-
|
|
73
|
-
|
|
234
|
+
fs2.rmSync(idx.metaPath, { force: true });
|
|
235
|
+
fs2.rmSync(idx.embPath, { force: true });
|
|
74
236
|
} catch {
|
|
75
237
|
}
|
|
76
238
|
}
|
|
77
239
|
}
|
|
78
240
|
return idx;
|
|
79
241
|
}
|
|
242
|
+
get rebuildFlagPath() {
|
|
243
|
+
return path2.join(this.vault.cache, "needs-rebuild");
|
|
244
|
+
}
|
|
245
|
+
/** Deja constancia de que el índice está degradado y hace falta un reindex completo. */
|
|
246
|
+
markNeedsRebuild() {
|
|
247
|
+
try {
|
|
248
|
+
if (fs2.existsSync(this.rebuildFlagPath)) return;
|
|
249
|
+
fs2.mkdirSync(this.vault.cache, { recursive: true });
|
|
250
|
+
fs2.writeFileSync(this.rebuildFlagPath, (/* @__PURE__ */ new Date()).toISOString());
|
|
251
|
+
} catch {
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/** ¿El índice tiene chunks pero le faltan los vectores (búsqueda degradada)? */
|
|
255
|
+
isDegraded() {
|
|
256
|
+
return this.emb === null && this.meta.chunks.length > 0 && modelPresent();
|
|
257
|
+
}
|
|
258
|
+
/** ¿El índice quedó marcado como degradado (chunks sin vectores)? */
|
|
259
|
+
needsRebuild() {
|
|
260
|
+
return fs2.existsSync(this.rebuildFlagPath);
|
|
261
|
+
}
|
|
262
|
+
clearNeedsRebuild() {
|
|
263
|
+
try {
|
|
264
|
+
fs2.rmSync(this.rebuildFlagPath, { force: true });
|
|
265
|
+
} catch {
|
|
266
|
+
}
|
|
267
|
+
}
|
|
80
268
|
/** Escritura atómica: tmp + rename — un hook y un comando concurrentes nunca dejan el archivo a medias. */
|
|
81
269
|
writeAtomic(file, data) {
|
|
82
270
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
83
|
-
|
|
84
|
-
|
|
271
|
+
fs2.writeFileSync(tmp, data);
|
|
272
|
+
fs2.renameSync(tmp, file);
|
|
85
273
|
}
|
|
86
274
|
save() {
|
|
87
|
-
|
|
275
|
+
fs2.mkdirSync(this.vault.cache, { recursive: true });
|
|
88
276
|
this.writeAtomic(this.metaPath, JSON.stringify(this.meta));
|
|
89
277
|
if (this.emb) {
|
|
90
278
|
this.writeAtomic(this.embPath, Buffer.from(this.emb.buffer, this.emb.byteOffset, this.emb.byteLength));
|
|
@@ -101,11 +289,16 @@ var VaultIndex = class _VaultIndex {
|
|
|
101
289
|
const files = listMarkdownFiles(this.vault.root);
|
|
102
290
|
const onDisk = /* @__PURE__ */ new Map();
|
|
103
291
|
for (const abs of files) {
|
|
104
|
-
const rel =
|
|
105
|
-
onDisk.set(rel, { abs, mtime:
|
|
292
|
+
const rel = path2.relative(this.vault.root, abs).split(path2.sep).join("/");
|
|
293
|
+
onDisk.set(rel, { abs, mtime: fs2.statSync(abs).mtimeMs });
|
|
106
294
|
}
|
|
107
295
|
if (withEmbeddings && this.emb === null && this.meta.chunks.length > 0) {
|
|
108
|
-
|
|
296
|
+
if (this.allowFullRebuild) {
|
|
297
|
+
force = true;
|
|
298
|
+
} else {
|
|
299
|
+
this.markNeedsRebuild();
|
|
300
|
+
withEmbeddings = false;
|
|
301
|
+
}
|
|
109
302
|
}
|
|
110
303
|
const changed = [];
|
|
111
304
|
for (const [rel, info] of onDisk) {
|
|
@@ -133,10 +326,10 @@ var VaultIndex = class _VaultIndex {
|
|
|
133
326
|
for (const rel of changed) {
|
|
134
327
|
const info = onDisk.get(rel);
|
|
135
328
|
try {
|
|
136
|
-
const managedRel =
|
|
329
|
+
const managedRel = path2.relative(this.vault.root, this.vault.managed).split(path2.sep).join("/");
|
|
137
330
|
const inManaged = managedRel === "" || rel.startsWith(`${managedRel}/`);
|
|
138
331
|
if (inManaged && ensureAlias(info.abs)) {
|
|
139
|
-
info.mtime =
|
|
332
|
+
info.mtime = fs2.statSync(info.abs).mtimeMs;
|
|
140
333
|
}
|
|
141
334
|
const note = parseNote(this.vault.root, info.abs);
|
|
142
335
|
this.meta.notes[rel] = {
|
|
@@ -195,8 +388,10 @@ ${c.text}`),
|
|
|
195
388
|
}
|
|
196
389
|
this.rebuildLinks();
|
|
197
390
|
this.save();
|
|
391
|
+
if (this.emb !== null) this.clearNeedsRebuild();
|
|
392
|
+
else if (this.meta.chunks.length > 0 && modelPresent()) this.markNeedsRebuild();
|
|
198
393
|
try {
|
|
199
|
-
const { writeStaticGraph } = await import("./viewer-
|
|
394
|
+
const { writeStaticGraph } = await import("./viewer-JQCSWJ3C.js");
|
|
200
395
|
writeStaticGraph(this);
|
|
201
396
|
} catch {
|
|
202
397
|
}
|
|
@@ -285,5 +480,11 @@ ${c.text}`),
|
|
|
285
480
|
};
|
|
286
481
|
|
|
287
482
|
export {
|
|
483
|
+
slugify,
|
|
484
|
+
createNote,
|
|
485
|
+
setNoteStatus,
|
|
486
|
+
touchNote,
|
|
487
|
+
upsertNote,
|
|
488
|
+
appendToNote,
|
|
288
489
|
VaultIndex
|
|
289
490
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
VaultIndex
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-QB37UGO6.js";
|
|
5
5
|
import {
|
|
6
6
|
dot,
|
|
7
7
|
embed,
|
|
@@ -61,6 +61,7 @@ async function hybridSearch(vault, query, k = 6, opts = {}) {
|
|
|
61
61
|
await idx.refresh().catch(() => {
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
|
+
if (idx.isDegraded()) idx.markNeedsRebuild();
|
|
64
65
|
if (idx.meta.chunks.length === 0) return [];
|
|
65
66
|
const rrf = /* @__PURE__ */ new Map();
|
|
66
67
|
const cosineByChunk = /* @__PURE__ */ new Map();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
hybridSearch
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-UWB6RKVN.js";
|
|
5
5
|
|
|
6
6
|
// src/core/planning.ts
|
|
7
7
|
var MAX_ITEMS = 2;
|
|
@@ -173,12 +173,12 @@ export {
|
|
|
173
173
|
planContext,
|
|
174
174
|
planQualityHints,
|
|
175
175
|
architectBlock,
|
|
176
|
-
distDir,
|
|
177
176
|
registerHooks,
|
|
178
177
|
unregisterHooks,
|
|
179
178
|
projectSettingsPath,
|
|
180
179
|
globalSettingsPath,
|
|
181
180
|
hooksRegistered,
|
|
181
|
+
serverCommand,
|
|
182
182
|
registerMcpProject,
|
|
183
183
|
registerMcpGlobal,
|
|
184
184
|
mcpRegisteredProject,
|