@ureck/alexandria 1.4.0 → 1.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 +30 -3
- package/dist/{chunk-2ESJQAP4.js → chunk-B7HCWKPJ.js} +6 -4
- package/dist/{chunk-3CB7GRFJ.js → chunk-BV2KJV5W.js} +7 -3
- package/dist/{chunk-MDGFK6UC.js → chunk-CEHNXDUE.js} +9 -53
- package/dist/{chunk-4ZSTD3CU.js → chunk-GP5A2GWI.js} +1 -1
- package/dist/chunk-POA77JSS.js +76 -0
- package/dist/chunk-SAKIVZMP.js +495 -0
- package/dist/chunk-UU4MGB2C.js +262 -0
- package/dist/{chunk-FPKJVQ2X.js → chunk-Y6S6SKH4.js} +1 -1
- package/dist/{chunk-U2U53TU2.js → chunk-ZDS6VULX.js} +1 -1
- package/dist/cli.js +84 -8
- package/dist/hooks/on-prompt.js +7 -5
- package/dist/hooks/on-read.js +70 -0
- package/dist/hooks/on-session-start.js +6 -4
- package/dist/hooks/on-stop.js +5 -4
- package/dist/mcp/server.js +42 -6
- package/dist/{viewer-OU4TB3X5.js → viewer-WQQSQETT.js} +2 -2
- package/package.json +15 -3
- package/dist/chunk-JI2L66DF.js +0 -189
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ Verify:
|
|
|
63
63
|
|
|
64
64
|
```bash
|
|
65
65
|
$ ale --version
|
|
66
|
-
1.
|
|
66
|
+
1.5.0
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
## Getting started
|
|
@@ -132,6 +132,30 @@ ale add "Vercel deploy" -c "Region cdg1, see [[Prisma setup]]" -t deploy
|
|
|
132
132
|
|
|
133
133
|
(Automatic capture via hooks already does this in every Claude Code, Codex, Gemini CLI, Cursor and OpenCode session — `add` is for extra knowledge.)
|
|
134
134
|
|
|
135
|
+
### Read documents without paying for the whole thing (PDF, DOCX, XLSX, CSV, HTML)
|
|
136
|
+
|
|
137
|
+
Reading a PDF directly costs an agent ~1,500–3,000 tokens **per page** (Claude sends each page as image + text). Alexandria converts documents locally to markdown sections and the agent asks only for what it needs:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
ale ingest "Manual Tecnico.pdf" reports/ # file or folder (pdf, docx, xlsx, csv, tsv, html, md, txt)
|
|
141
|
+
ale docs # list ingested documents
|
|
142
|
+
ale docs read "Manual Tecnico" -q "which env vars does the deploy need?"
|
|
143
|
+
ale docs read pagos.xlsx -q "F-137 pagado" # spreadsheets: returns the MATCHING ROWS
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
From any agent, the MCP tools `doc_ingest` (returns a ~200-token section outline) and `doc_read` (sections by id or by question, never over `max_tokens`, always telling what was left out) do the same. Measured on real documents:
|
|
147
|
+
|
|
148
|
+
| Document | Read directly | Outline | Answer to one question |
|
|
149
|
+
|---|---|---|---|
|
|
150
|
+
| 10-page technical manual (PDF) | ~20,000 tokens | ~248 | ~179 |
|
|
151
|
+
| 2,016-row spreadsheet (XLSX) | ~1,241,000 tokens | ~526 | ~579 (matching rows) |
|
|
152
|
+
|
|
153
|
+
- **PDF**: headings detected by font size (multi-line titles merged), source page kept for citations; scanned PDFs (no text layer) are flagged — Alexandria doesn't do OCR.
|
|
154
|
+
- **Spreadsheets**: never sent whole — a per-column summary (type, distinct values, samples) plus 50-row blocks; huge cells (geometries, JSON) are trimmed.
|
|
155
|
+
- **Claude Code**: the first direct `Read` of a large PDF/DOCX/XLSX/CSV in a session is redirected to `doc_ingest`/`doc_read`; a second attempt goes through (for when the agent really needs to see images). Toggle: `docs.interceptRead`.
|
|
156
|
+
- Unchanged files are never reconverted (sha256). Documents live in `Alexandria/docs/`, outside the vector index (a big spreadsheet would be thousands of chunks); section vectors are computed once per document version and cached.
|
|
157
|
+
- `ale stats` shows the **measured** document savings: tokens of the originals vs tokens actually served.
|
|
158
|
+
|
|
135
159
|
### Control what spends tokens (`ale toggles`)
|
|
136
160
|
|
|
137
161
|
Every token-spending behavior is opt-out — before or after installing (the config is global, independent of the vault):
|
|
@@ -142,7 +166,7 @@ ale init --off architect.enrich,digest.map # disable from the start
|
|
|
142
166
|
ale config set tokens.solutionCache false # scriptable, one by one
|
|
143
167
|
```
|
|
144
168
|
|
|
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), background index rebuild at session close, and weekly background cleanup `clean.auto` (neither costs tokens). All on by default; nothing changes unless you touch them.
|
|
169
|
+
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), redirecting direct reads of large PDFs/spreadsheets to `doc_read` (`docs.interceptRead`), background index rebuild at session close, and weekly background cleanup `clean.auto` (neither costs tokens). All on by default; nothing changes unless you touch them.
|
|
146
170
|
|
|
147
171
|
### Deep project context (`ale scan`)
|
|
148
172
|
|
|
@@ -289,6 +313,7 @@ AI agent session
|
|
|
289
313
|
├─ Every prompt ──► local hybrid search → injects only what's relevant (hooks)
|
|
290
314
|
│ └─ near-identical prompt already solved → injects the solution (cache)
|
|
291
315
|
├─ MCP tools ─────► vault_search · vault_save · vault_related · vault_link (all agents)
|
|
316
|
+
│ doc_ingest · doc_read (documents by section, token budget)
|
|
292
317
|
│ plan_create · task_verify · lesson_extract (the Protocol)
|
|
293
318
|
└─ Stop/PreCompact► saves the session outcome into the vault (hooks)
|
|
294
319
|
hooks: Claude Code · Codex · Gemini CLI · Cursor · OpenCode (one set of scripts, --harness=<id>)
|
|
@@ -324,7 +349,9 @@ AI agent session
|
|
|
324
349
|
| `ale consolidate [--days n] [--dry]` | Alias of `ale clean --prompts-only` |
|
|
325
350
|
| `ale doctor [--project]` | Check & repair: model, hooks, MCP, index |
|
|
326
351
|
| `ale uninstall [--project]` | Remove hooks, MCP and instruction blocks from every agent (notes stay untouched) |
|
|
327
|
-
| `ale
|
|
352
|
+
| `ale ingest <paths...> [--force]` | Convert PDF/DOCX/XLSX/CSV/HTML/MD to markdown sections and store them in the vault |
|
|
353
|
+
| `ale docs` / `ale docs read <doc> [-s ids] [-q question] [--max-tokens n]` | List ingested documents / read only the sections (or spreadsheet rows) you need |
|
|
354
|
+
| `ale hook <session-start\|prompt\|stop\|read> [--harness id]` | Run a hook (used by the plugins) |
|
|
328
355
|
| `ale --vault <path> <cmd>` | Run any command against another vault |
|
|
329
356
|
|
|
330
357
|
`alexandria` works as an alias of `ale`.
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
charsToTokens
|
|
3
|
+
charsToTokens
|
|
4
|
+
} from "./chunk-POA77JSS.js";
|
|
5
|
+
import {
|
|
4
6
|
isHarnessInjected
|
|
5
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-CEHNXDUE.js";
|
|
6
8
|
import {
|
|
7
9
|
isoDate
|
|
8
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-BV2KJV5W.js";
|
|
9
11
|
import {
|
|
10
12
|
MODEL_ID,
|
|
11
13
|
modelCacheDir
|
|
@@ -106,7 +108,7 @@ function oldStatsLines(vault) {
|
|
|
106
108
|
return fs.readFileSync(path.join(vault.cache, "stats.jsonl"), "utf8").split("\n").filter((l) => {
|
|
107
109
|
try {
|
|
108
110
|
const o = JSON.parse(l);
|
|
109
|
-
return o.t !== "summary" && Date.parse(o.t ?? "") < cutoff;
|
|
111
|
+
return o.t !== "summary" && o.kind !== "doc" && Date.parse(o.t ?? "") < cutoff;
|
|
110
112
|
} catch {
|
|
111
113
|
return false;
|
|
112
114
|
}
|
|
@@ -22,7 +22,8 @@ var NOTE_TYPES = [
|
|
|
22
22
|
"verification",
|
|
23
23
|
"lesson",
|
|
24
24
|
"solution",
|
|
25
|
-
"archive"
|
|
25
|
+
"archive",
|
|
26
|
+
"document"
|
|
26
27
|
];
|
|
27
28
|
var SKIP_DIRS = /* @__PURE__ */ new Set([".obsidian", ".vault", ".trash", ".git", "node_modules"]);
|
|
28
29
|
function extractWikilinks(content) {
|
|
@@ -295,7 +296,10 @@ var VaultIndex = class _VaultIndex {
|
|
|
295
296
|
* `withEmbeddings=false` → índice keyword-only (sin cargar modelo).
|
|
296
297
|
*/
|
|
297
298
|
async refresh(withEmbeddings = modelPresent(), force = false) {
|
|
298
|
-
const files = listMarkdownFiles(this.vault.root, [
|
|
299
|
+
const files = listMarkdownFiles(this.vault.root, [
|
|
300
|
+
path2.join(this.vault.managed, "archive"),
|
|
301
|
+
path2.join(this.vault.managed, "docs")
|
|
302
|
+
]);
|
|
299
303
|
const onDisk = /* @__PURE__ */ new Map();
|
|
300
304
|
for (const abs of files) {
|
|
301
305
|
const rel = path2.relative(this.vault.root, abs).split(path2.sep).join("/");
|
|
@@ -400,7 +404,7 @@ ${c.text}`),
|
|
|
400
404
|
if (this.emb !== null) this.clearNeedsRebuild();
|
|
401
405
|
else if (this.meta.chunks.length > 0 && modelPresent()) this.markNeedsRebuild();
|
|
402
406
|
if (!isHookProcess()) try {
|
|
403
|
-
const { writeStaticGraph } = await import("./viewer-
|
|
407
|
+
const { writeStaticGraph } = await import("./viewer-WQQSQETT.js");
|
|
404
408
|
writeStaticGraph(this);
|
|
405
409
|
} catch {
|
|
406
410
|
}
|
|
@@ -148,6 +148,12 @@ var TOKEN_TOGGLES = [
|
|
|
148
148
|
desc: "Si el \xEDndice qued\xF3 sin vectores, reconstruirlo en segundo plano al terminar la sesi\xF3n",
|
|
149
149
|
impact: "no gasta tokens; sin esto la b\xFAsqueda puede quedarse en keyword-only (peor contexto por prompt)"
|
|
150
150
|
},
|
|
151
|
+
{
|
|
152
|
+
key: "docs.interceptRead",
|
|
153
|
+
label: "Redirigir lectura de PDF/DOCX/XLSX",
|
|
154
|
+
desc: "En Claude Code, la primera lectura directa de un PDF/DOCX/XLSX/CSV grande se redirige a doc_ingest/doc_read (el segundo intento pasa)",
|
|
155
|
+
impact: "ahorra ~2,000 tokens por p\xE1gina de PDF; desact\xEDvalo si sueles necesitar ver im\xE1genes/gr\xE1ficas"
|
|
156
|
+
},
|
|
151
157
|
{
|
|
152
158
|
key: "clean.auto",
|
|
153
159
|
label: "Limpieza autom\xE1tica semanal",
|
|
@@ -163,55 +169,6 @@ function writeProjectConfig(projectDir, vaultPath) {
|
|
|
163
169
|
return file;
|
|
164
170
|
}
|
|
165
171
|
|
|
166
|
-
// src/core/stats.ts
|
|
167
|
-
import fs2 from "fs";
|
|
168
|
-
import path2 from "path";
|
|
169
|
-
var charsToTokens = (chars) => Math.round(chars / 4);
|
|
170
|
-
function logInjection(vault, line) {
|
|
171
|
-
try {
|
|
172
|
-
fs2.mkdirSync(vault.cache, { recursive: true });
|
|
173
|
-
fs2.appendFileSync(
|
|
174
|
-
path2.join(vault.cache, "stats.jsonl"),
|
|
175
|
-
JSON.stringify({ t: (/* @__PURE__ */ new Date()).toISOString(), ...line }) + "\n"
|
|
176
|
-
);
|
|
177
|
-
} catch {
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
var EST_LOW = 3;
|
|
181
|
-
var EST_HIGH = 8;
|
|
182
|
-
function readStats(vault) {
|
|
183
|
-
const file = path2.join(vault.cache, "stats.jsonl");
|
|
184
|
-
const summary = {
|
|
185
|
-
injections: 0,
|
|
186
|
-
solutionCacheHits: 0,
|
|
187
|
-
injectedTokens: 0,
|
|
188
|
-
cacheHitTokens: 0,
|
|
189
|
-
estSavedLow: 0,
|
|
190
|
-
estSavedHigh: 0
|
|
191
|
-
};
|
|
192
|
-
try {
|
|
193
|
-
for (const raw of fs2.readFileSync(file, "utf8").split("\n")) {
|
|
194
|
-
if (!raw.trim()) continue;
|
|
195
|
-
try {
|
|
196
|
-
const line = JSON.parse(raw);
|
|
197
|
-
const n = line.count ?? 1;
|
|
198
|
-
summary.injections += n;
|
|
199
|
-
const tk = line.tokens ?? charsToTokens(line.injectedChars);
|
|
200
|
-
summary.injectedTokens += tk;
|
|
201
|
-
if (line.kind === "solution-cache") {
|
|
202
|
-
summary.solutionCacheHits += n;
|
|
203
|
-
summary.cacheHitTokens += tk;
|
|
204
|
-
}
|
|
205
|
-
} catch {
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
} catch {
|
|
209
|
-
}
|
|
210
|
-
summary.estSavedLow = summary.injectedTokens * EST_LOW;
|
|
211
|
-
summary.estSavedHigh = summary.injectedTokens * EST_HIGH;
|
|
212
|
-
return summary;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
172
|
// src/hooks/adapters.ts
|
|
216
173
|
var HARNESSES = ["claude", "codex", "gemini", "cursor", "opencode"];
|
|
217
174
|
function currentHarness(argv = process.argv) {
|
|
@@ -226,7 +183,9 @@ function normalizeInput(raw) {
|
|
|
226
183
|
cwd: raw.cwd ?? raw.workspace_roots?.[0],
|
|
227
184
|
prompt: raw.prompt,
|
|
228
185
|
answer: raw.last_assistant_message ?? raw.prompt_response ?? raw.text,
|
|
229
|
-
compact: /^(PreCompact|PreCompress|preCompact)$/.test(event) || Boolean(raw.trigger)
|
|
186
|
+
compact: /^(PreCompact|PreCompress|preCompact)$/.test(event) || Boolean(raw.trigger),
|
|
187
|
+
toolName: raw.tool_name,
|
|
188
|
+
filePath: raw.tool_input?.file_path
|
|
230
189
|
};
|
|
231
190
|
}
|
|
232
191
|
function formatContext(harness, kind, text) {
|
|
@@ -292,9 +251,6 @@ export {
|
|
|
292
251
|
initScopeWarning,
|
|
293
252
|
TOKEN_TOGGLES,
|
|
294
253
|
writeProjectConfig,
|
|
295
|
-
charsToTokens,
|
|
296
|
-
logInjection,
|
|
297
|
-
readStats,
|
|
298
254
|
currentHarness,
|
|
299
255
|
normalizeInput,
|
|
300
256
|
formatContext,
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/core/stats.ts
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
var charsToTokens = (chars) => Math.round(chars / 4);
|
|
7
|
+
function logInjection(vault, line) {
|
|
8
|
+
try {
|
|
9
|
+
fs.mkdirSync(vault.cache, { recursive: true });
|
|
10
|
+
fs.appendFileSync(
|
|
11
|
+
path.join(vault.cache, "stats.jsonl"),
|
|
12
|
+
JSON.stringify({ t: (/* @__PURE__ */ new Date()).toISOString(), ...line }) + "\n"
|
|
13
|
+
);
|
|
14
|
+
} catch {
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function logDocUse(vault, line) {
|
|
18
|
+
try {
|
|
19
|
+
fs.mkdirSync(vault.cache, { recursive: true });
|
|
20
|
+
fs.appendFileSync(path.join(vault.cache, "stats.jsonl"), JSON.stringify({ t: (/* @__PURE__ */ new Date()).toISOString(), kind: "doc", ...line }) + "\n");
|
|
21
|
+
} catch {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
var EST_LOW = 3;
|
|
25
|
+
var EST_HIGH = 8;
|
|
26
|
+
function readStats(vault) {
|
|
27
|
+
const file = path.join(vault.cache, "stats.jsonl");
|
|
28
|
+
const summary = {
|
|
29
|
+
injections: 0,
|
|
30
|
+
solutionCacheHits: 0,
|
|
31
|
+
injectedTokens: 0,
|
|
32
|
+
cacheHitTokens: 0,
|
|
33
|
+
estSavedLow: 0,
|
|
34
|
+
estSavedHigh: 0,
|
|
35
|
+
docIngests: 0,
|
|
36
|
+
docReads: 0,
|
|
37
|
+
docTokensOriginal: 0,
|
|
38
|
+
docTokensServed: 0
|
|
39
|
+
};
|
|
40
|
+
try {
|
|
41
|
+
for (const raw of fs.readFileSync(file, "utf8").split("\n")) {
|
|
42
|
+
if (!raw.trim()) continue;
|
|
43
|
+
try {
|
|
44
|
+
const line = JSON.parse(raw);
|
|
45
|
+
if (line.kind === "doc") {
|
|
46
|
+
const d = line;
|
|
47
|
+
if (d.op === "ingest") summary.docIngests++;
|
|
48
|
+
else summary.docReads++;
|
|
49
|
+
summary.docTokensOriginal += d.tokensOriginal ?? 0;
|
|
50
|
+
summary.docTokensServed += d.tokensServed ?? 0;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const n = line.count ?? 1;
|
|
54
|
+
summary.injections += n;
|
|
55
|
+
const tk = line.tokens ?? charsToTokens(line.injectedChars);
|
|
56
|
+
summary.injectedTokens += tk;
|
|
57
|
+
if (line.kind === "solution-cache") {
|
|
58
|
+
summary.solutionCacheHits += n;
|
|
59
|
+
summary.cacheHitTokens += tk;
|
|
60
|
+
}
|
|
61
|
+
} catch {
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
} catch {
|
|
65
|
+
}
|
|
66
|
+
summary.estSavedLow = summary.injectedTokens * EST_LOW;
|
|
67
|
+
summary.estSavedHigh = summary.injectedTokens * EST_HIGH;
|
|
68
|
+
return summary;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export {
|
|
72
|
+
charsToTokens,
|
|
73
|
+
logInjection,
|
|
74
|
+
logDocUse,
|
|
75
|
+
readStats
|
|
76
|
+
};
|