@ureck/alexandria 1.6.0 → 1.6.1

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 CHANGED
@@ -63,7 +63,7 @@ Verify:
63
63
 
64
64
  ```bash
65
65
  $ ale --version
66
- 1.6.0
66
+ 1.6.1
67
67
  ```
68
68
 
69
69
  ## Getting started
@@ -163,7 +163,7 @@ function inferType(values) {
163
163
  function sheetsToMarkdown(sheets) {
164
164
  const out = [];
165
165
  for (const { name, rows } of sheets) {
166
- const clean = rows.filter((r) => r.some((c) => c !== ""));
166
+ const clean = rows.map((r) => Array.from(r ?? [], (c) => c ?? "")).filter((r) => r.some((c) => c !== ""));
167
167
  if (clean.length === 0) continue;
168
168
  const [header, ...data] = clean;
169
169
  const cols = header.map((h, i) => h || `col${i + 1}`);
@@ -188,35 +188,15 @@ function sheetsToMarkdown(sheets) {
188
188
  return out.join("\n\n");
189
189
  }
190
190
  async function xlsxToMarkdown(buf) {
191
- const ExcelJS = (await import("exceljs")).default;
192
- const wb = new ExcelJS.Workbook();
193
- await wb.xlsx.load(buf);
194
- const sheets = [];
191
+ const { readXlsx } = await import("./xlsx-THZM4FNX.js");
192
+ const sheets = await readXlsx(buf);
195
193
  let totalRows = 0;
196
194
  let rawChars = 0;
197
- wb.eachSheet((ws) => {
198
- const rows = [];
199
- ws.eachRow({ includeEmpty: false }, (row) => {
200
- const vals = row.values.slice(1).map(cellText);
201
- rows.push(vals);
202
- rawChars += vals.join(",").length + 1;
203
- });
204
- totalRows += Math.max(0, rows.length - 1);
205
- sheets.push({ name: ws.name, rows });
206
- });
207
- return { format: "xlsx", markdown: sheetsToMarkdown(sheets), rows: totalRows, tokensOriginal: Math.ceil(rawChars / 4) };
208
- }
209
- function cellText(v) {
210
- if (v === null || v === void 0) return "";
211
- if (v instanceof Date) return v.toISOString().slice(0, 10);
212
- if (typeof v === "object") {
213
- const o = v;
214
- if (o.richText) return o.richText.map((t) => t.text).join("");
215
- if (o.text !== void 0) return String(o.text);
216
- if (o.result !== void 0) return cellText(o.result);
217
- return "";
195
+ for (const sh of sheets) {
196
+ totalRows += Math.max(0, sh.rows.length - 1);
197
+ for (const r of sh.rows) rawChars += r.join(",").length + 1;
218
198
  }
219
- return String(v);
199
+ return { format: "xlsx", markdown: sheetsToMarkdown(sheets), rows: totalRows, tokensOriginal: Math.ceil(rawChars / 4) };
220
200
  }
221
201
  function sniffDelimiter(text) {
222
202
  const first = text.split(/\r?\n/, 1)[0] ?? "";
@@ -8,7 +8,7 @@ import {
8
8
  import {
9
9
  convertFile,
10
10
  htmlToMarkdown
11
- } from "./chunk-I5H4BN3F.js";
11
+ } from "./chunk-NUG7HLOU.js";
12
12
  import {
13
13
  logDocUse
14
14
  } from "./chunk-X4V6SYYA.js";
package/dist/cli.js CHANGED
@@ -24,7 +24,7 @@ import {
24
24
  serverCommand,
25
25
  symbolSource,
26
26
  unregisterHooks
27
- } from "./chunk-BXVNQVLX.js";
27
+ } from "./chunk-YNCL5JSF.js";
28
28
  import {
29
29
  hybridSearch,
30
30
  protocolChain
@@ -46,7 +46,7 @@ import {
46
46
  } from "./chunk-44QPE5IM.js";
47
47
  import {
48
48
  formatOf
49
- } from "./chunk-I5H4BN3F.js";
49
+ } from "./chunk-NUG7HLOU.js";
50
50
  import {
51
51
  listRuns,
52
52
  runCommand,
@@ -5,7 +5,7 @@ import {
5
5
  import {
6
6
  PDF_TOKENS_PER_PAGE,
7
7
  formatOf
8
- } from "../chunk-I5H4BN3F.js";
8
+ } from "../chunk-NUG7HLOU.js";
9
9
  import {
10
10
  resolveVault,
11
11
  toggleEnabled,
@@ -10,7 +10,7 @@ import {
10
10
  planQualityHints,
11
11
  readDoc,
12
12
  symbolSource
13
- } from "../chunk-BXVNQVLX.js";
13
+ } from "../chunk-YNCL5JSF.js";
14
14
  import {
15
15
  hybridSearch
16
16
  } from "../chunk-47S5I3D3.js";
@@ -25,7 +25,7 @@ import {
25
25
  supersedeNote,
26
26
  upsertNote
27
27
  } from "../chunk-44QPE5IM.js";
28
- import "../chunk-I5H4BN3F.js";
28
+ import "../chunk-NUG7HLOU.js";
29
29
  import {
30
30
  showRun
31
31
  } from "../chunk-OGVWOBYH.js";
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/docs/xlsx.ts
4
+ import JSZip from "jszip";
5
+ var ENTITIES = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" };
6
+ function decodeXml(s) {
7
+ return s.replace(/&(#x[0-9a-f]+|#\d+|\w+);/gi, (m, e) => {
8
+ if (e[0] === "#") {
9
+ const code = e[1] === "x" || e[1] === "X" ? parseInt(e.slice(2), 16) : parseInt(e.slice(1), 10);
10
+ return Number.isFinite(code) ? String.fromCodePoint(code) : m;
11
+ }
12
+ return ENTITIES[e] ?? m;
13
+ });
14
+ }
15
+ var attr = (tag, name) => tag.match(new RegExp(`\\b${name}="([^"]*)"`))?.[1];
16
+ function textOf(xml) {
17
+ let out = "";
18
+ for (const m of xml.matchAll(/<t(?:\s[^>]*)?>([\s\S]*?)<\/t>/g)) out += m[1];
19
+ return decodeXml(out);
20
+ }
21
+ function colIndex(ref) {
22
+ const letters = ref.match(/^[A-Z]+/i)?.[0].toUpperCase() ?? "A";
23
+ let n = 0;
24
+ for (const ch of letters) n = n * 26 + (ch.charCodeAt(0) - 64);
25
+ return n - 1;
26
+ }
27
+ var DATE_IDS = /* @__PURE__ */ new Set([14, 15, 16, 17, 18, 19, 20, 21, 22, 27, 30, 36, 45, 46, 47, 50, 57]);
28
+ function isDateFormat(code) {
29
+ const c = code.replace(/"[^"]*"|\[[^\]]*\]|\\./g, "");
30
+ return /[dmyh]/i.test(c) && !/^[#0.,%\s]+$/.test(c);
31
+ }
32
+ function excelDate(serial, date1904 = false) {
33
+ const ms = Math.round((serial + (date1904 ? 1462 : 0) - 25569) * 864e5);
34
+ const d = new Date(ms);
35
+ return isNaN(d.getTime()) ? String(serial) : d.toISOString().slice(0, 10);
36
+ }
37
+ function numText(v) {
38
+ const n = Number(v);
39
+ return Number.isFinite(n) ? String(n) : v;
40
+ }
41
+ async function readXlsx(buf) {
42
+ const zip = await JSZip.loadAsync(buf);
43
+ const read = async (p) => await zip.file(p)?.async("string") ?? "";
44
+ const workbook = await read("xl/workbook.xml");
45
+ const date1904 = /<workbookPr\b[^>]*\bdate1904="(1|true)"/.test(workbook);
46
+ const rels = await read("xl/_rels/workbook.xml.rels");
47
+ const target = /* @__PURE__ */ new Map();
48
+ for (const m of rels.matchAll(/<Relationship\b[^>]*>/g)) {
49
+ const id = attr(m[0], "Id");
50
+ const t = attr(m[0], "Target");
51
+ if (id && t) target.set(id, t.startsWith("/") ? t.slice(1) : t.startsWith("xl/") ? t : `xl/${t}`);
52
+ }
53
+ const shared = [];
54
+ for (const m of (await read("xl/sharedStrings.xml")).matchAll(/<si>([\s\S]*?)<\/si>/g)) shared.push(textOf(m[1]));
55
+ const styles = await read("xl/styles.xml");
56
+ const customFmt = /* @__PURE__ */ new Map();
57
+ for (const m of styles.matchAll(/<numFmt\b[^>]*>/g)) {
58
+ const id = Number(attr(m[0], "numFmtId"));
59
+ const code = attr(m[0], "formatCode");
60
+ if (code !== void 0) customFmt.set(id, decodeXml(code));
61
+ }
62
+ const dateStyle = [];
63
+ const xfs = styles.match(/<cellXfs\b[^>]*>([\s\S]*?)<\/cellXfs>/)?.[1] ?? "";
64
+ for (const m of xfs.matchAll(/<xf\b[^>]*>/g)) {
65
+ const id = Number(attr(m[0], "numFmtId") ?? 0);
66
+ dateStyle.push(DATE_IDS.has(id) || customFmt.has(id) && isDateFormat(customFmt.get(id)));
67
+ }
68
+ const sheets = [];
69
+ for (const m of workbook.matchAll(/<sheet\b[^>]*>/g)) {
70
+ const name = decodeXml(attr(m[0], "name") ?? `Hoja${sheets.length + 1}`);
71
+ const rid = attr(m[0], "r:id") ?? attr(m[0], "id");
72
+ const file = rid && target.get(rid) || `xl/worksheets/sheet${sheets.length + 1}.xml`;
73
+ const xml = await read(file);
74
+ const rows = [];
75
+ const rowsByNum = /* @__PURE__ */ new Map();
76
+ for (const r of xml.matchAll(/<row\b[^>]*?(?:\/>|>([\s\S]*?)<\/row>)/g)) {
77
+ const row = [];
78
+ let next = 0;
79
+ for (const c of (r[1] ?? "").matchAll(/<c\b([^>]*?)(?:\/>|>([\s\S]*?)<\/c>)/g)) {
80
+ const a = c[1];
81
+ const inner = c[2] ?? "";
82
+ const ref = attr(a, "r");
83
+ const col = ref ? colIndex(ref) : next;
84
+ next = col + 1;
85
+ const t = attr(a, "t");
86
+ const v = inner.match(/<v>([\s\S]*?)<\/v>/)?.[1];
87
+ let val = "";
88
+ if (t === "s") val = v !== void 0 ? shared[Number(v)] ?? "" : "";
89
+ else if (t === "inlineStr") val = textOf(inner.match(/<is>([\s\S]*?)<\/is>/)?.[1] ?? "");
90
+ else if (t === "b") val = v === "1" ? "true" : v === "0" ? "false" : "";
91
+ else if (t === "str" || t === "e") val = v !== void 0 ? decodeXml(v) : "";
92
+ else if (v !== void 0) {
93
+ const s = Number(attr(a, "s") ?? 0);
94
+ val = dateStyle[s] && Number.isFinite(Number(v)) ? excelDate(Number(v), date1904) : numText(v);
95
+ }
96
+ if (val === "") continue;
97
+ while (row.length < col) row.push("");
98
+ row[col] = val;
99
+ }
100
+ rowsByNum.set(Number(attr(r[0], "r") ?? rowsByNum.size + 1), row);
101
+ }
102
+ for (const mc of xml.matchAll(/<mergeCell\b[^>]*\bref="([A-Z]+)(\d+):([A-Z]+)(\d+)"/gi)) {
103
+ const [c1, r1, c2, r2] = [colIndex(mc[1]), Number(mc[2]), colIndex(mc[3]), Number(mc[4])];
104
+ const master = rowsByNum.get(r1)?.[c1] ?? "";
105
+ if (!master) continue;
106
+ for (let rn = r1; rn <= r2; rn++) {
107
+ const row = rowsByNum.get(rn) ?? [];
108
+ for (let cn = c1; cn <= c2; cn++) {
109
+ while (row.length < cn) row.push("");
110
+ row[cn] = master;
111
+ }
112
+ rowsByNum.set(rn, row);
113
+ }
114
+ }
115
+ for (const n of [...rowsByNum.keys()].sort((a, b) => a - b)) {
116
+ const row = rowsByNum.get(n);
117
+ if (row.some((x) => x !== "")) rows.push(row);
118
+ }
119
+ sheets.push({ name, rows });
120
+ }
121
+ return sheets;
122
+ }
123
+ export {
124
+ colIndex,
125
+ decodeXml,
126
+ excelDate,
127
+ readXlsx
128
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ureck/alexandria",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "Alexandria — bóveda de conocimiento local para agentes de IA (Claude Code, Codex, Gemini CLI, Cursor, OpenCode y más): captura automática por hooks, búsqueda semántica offline y grafo estilo Obsidian. Ahorra tokens inyectando solo el contexto relevante.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -48,8 +48,8 @@
48
48
  "@huggingface/transformers": "^4.3.2",
49
49
  "@modelcontextprotocol/sdk": "^1.32.2",
50
50
  "commander": "^15.0.0",
51
- "exceljs": "^4.4.0",
52
51
  "gray-matter": "^4.0.3",
52
+ "jszip": "^3.10.2",
53
53
  "mammoth": "^1.13.0",
54
54
  "minisearch": "^7.1.2",
55
55
  "picocolors": "^1.1.1",
@@ -64,7 +64,7 @@
64
64
  "devDependencies": {
65
65
  "@types/node": "^22.20.5",
66
66
  "@types/turndown": "^5.0.6",
67
- "jszip": "^3.10.2",
67
+ "exceljs": "^4.4.0",
68
68
  "tsup": "^9.0.0",
69
69
  "typescript": "^5.7.3",
70
70
  "vitest": "^5.0.5"