@ureck/alexandria 0.3.0 → 0.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.
@@ -1,10 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- MANAGED_DIR,
4
3
  ensureAlias,
5
4
  listMarkdownFiles,
6
5
  parseNote
7
- } from "./chunk-CF2GLMR3.js";
6
+ } from "./chunk-XWR74BQ2.js";
8
7
  import {
9
8
  DIM,
10
9
  MODEL_ID,
@@ -106,7 +105,9 @@ var VaultIndex = class _VaultIndex {
106
105
  for (const rel of changed) {
107
106
  const info = onDisk.get(rel);
108
107
  try {
109
- if (rel.startsWith(`${MANAGED_DIR}/`) && ensureAlias(info.abs)) {
108
+ const managedRel = path.relative(this.vault.root, this.vault.managed).split(path.sep).join("/");
109
+ const inManaged = managedRel === "" || rel.startsWith(`${managedRel}/`);
110
+ if (inManaged && ensureAlias(info.abs)) {
110
111
  info.mtime = fs.statSync(info.abs).mtimeMs;
111
112
  }
112
113
  const note = parseNote(this.vault.root, info.abs);
@@ -114,6 +115,7 @@ var VaultIndex = class _VaultIndex {
114
115
  rel,
115
116
  title: note.title,
116
117
  type: note.type,
118
+ status: note.status,
117
119
  tags: note.tags,
118
120
  created: note.created,
119
121
  hits: note.hits,
@@ -166,7 +168,7 @@ ${c.text}`),
166
168
  this.rebuildLinks();
167
169
  this.save();
168
170
  try {
169
- const { writeStaticGraph } = await import("./viewer-LD4RTZE7.js");
171
+ const { writeStaticGraph } = await import("./viewer-57T7UOFE.js");
170
172
  writeStaticGraph(this);
171
173
  } catch {
172
174
  }
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  VaultIndex
4
- } from "./chunk-VN7QOAG2.js";
4
+ } from "./chunk-MLA3KZPZ.js";
5
5
 
6
6
  // src/graph/viewer.ts
7
7
  import fs from "fs";
@@ -15,7 +15,7 @@ function buildGraphData(idx) {
15
15
  deg.set(l.to, (deg.get(l.to) ?? 0) + 1);
16
16
  }
17
17
  return {
18
- nodes: Object.values(idx.meta.notes).map((n) => ({
18
+ nodes: Object.values(idx.meta.notes).filter((n) => !n.rel.split("/").includes("archive")).map((n) => ({
19
19
  id: n.rel,
20
20
  title: n.title,
21
21
  type: n.type,
@@ -44,6 +44,8 @@ function renderGraphHtml(data, live) {
44
44
  #hud .sub{color:var(--dim);font-size:12px}
45
45
  .leg{display:flex;gap:12px;flex-wrap:wrap;margin-top:8px;font-size:12px;color:var(--dim)}
46
46
  .leg b{display:inline-block;width:9px;height:9px;border-radius:50%;margin-right:5px;vertical-align:-1px}
47
+ .leg label{cursor:pointer;user-select:none}
48
+ .leg input{accent-color:#7aa2f7;margin-right:4px;vertical-align:-2px}
47
49
  #hint{color:var(--dim);font-size:11px;margin-top:6px}
48
50
  #info{bottom:14px;left:14px;padding:12px 16px;max-width:440px;display:none}
49
51
  #info b{font-size:14px}
@@ -60,13 +62,17 @@ function renderGraphHtml(data, live) {
60
62
  <div id="hud" class="card">
61
63
  <h1>\u{1F3DB}\uFE0F Alexandria</h1>
62
64
  <div class="sub" id="counts"></div>
63
- <div class="leg">
64
- <span><b style="background:#7aa2f7"></b>nota</span>
65
- <span><b style="background:#9ece6a"></b>sesi\xF3n</span>
66
- <span><b style="background:#e0af68"></b>prompt</span>
67
- <span><b style="background:#f7768e"></b>mapa</span>
65
+ <div class="leg" id="leg">
66
+ <label><input type="checkbox" data-type="note" checked><b style="background:#7aa2f7"></b>nota</label>
67
+ <label><input type="checkbox" data-type="map" checked><b style="background:#f7768e"></b>mapa</label>
68
+ <label><input type="checkbox" data-type="plan" checked><b style="background:#bb9af7"></b>plan</label>
69
+ <label><input type="checkbox" data-type="verification" checked><b style="background:#2ac3de"></b>verificaci\xF3n</label>
70
+ <label><input type="checkbox" data-type="lesson" checked><b style="background:#ffc777"></b>lecci\xF3n</label>
71
+ <label><input type="checkbox" data-type="solution" checked><b style="background:#73daca"></b>soluci\xF3n</label>
72
+ <label><input type="checkbox" data-type="session" checked><b style="background:#9ece6a"></b>sesi\xF3n</label>
73
+ <label><input type="checkbox" data-type="prompt"><b style="background:#565f89"></b>prompt</label>
68
74
  </div>
69
- <div id="hint">arrastra \xB7 rueda = zoom \xB7 hover = conexiones \xB7 click = detalle<br>\u2014 s\xF3lida = [[wikilink]] \xB7 \u2025 punteada = sem\xE1ntica</div>
75
+ <div id="hint">filtros por tipo (prompts ocultos por default \u2014 ruido) \xB7 arrastra \xB7 rueda = zoom<br>hover = conexiones \xB7 click = detalle \xB7 \u2014 s\xF3lida = [[wikilink]] \xB7 \u2025 punteada = sem\xE1ntica</div>
70
76
  </div>
71
77
  <div id="search"><input id="q" placeholder="filtrar notas\u2026" autocomplete="off"></div>
72
78
  <div id="live" class="card">\u25CF <b>en vivo</b> \u2014 se actualiza solo</div>
@@ -77,7 +83,7 @@ function renderGraphHtml(data, live) {
77
83
  'use strict';
78
84
  const LIVE = ${live};
79
85
  let DATA = ${JSON.stringify(data)};
80
- const COLORS = { note:'#7aa2f7', session:'#9ece6a', prompt:'#e0af68', map:'#f7768e' };
86
+ const COLORS = { note:'#7aa2f7', session:'#9ece6a', prompt:'#565f89', map:'#f7768e', plan:'#bb9af7', verification:'#2ac3de', lesson:'#ffc777', solution:'#73daca', task:'#7dcfff' };
81
87
  const cv = document.getElementById('c'), ctx = cv.getContext('2d');
82
88
  const DPR = Math.min(devicePixelRatio || 1, 2);
83
89
  let W, H;
@@ -88,6 +94,11 @@ fit(); addEventListener('resize', () => { fit(); fitView(); });
88
94
  let nodes = [], byId = new Map(), edges = [];
89
95
  let zoom = 1, panX = 0, panY = 0, dragNode = null, hot = true, heat = 300;
90
96
  let didFit = false, hover = null, filter = '';
97
+ // filtros por tipo (estilo Obsidian) \u2014 prompts ocultos por default: son ruido visual
98
+ const typeOn = { note: true, map: true, session: true, prompt: false, plan: true, verification: true, lesson: true, solution: true, task: true };
99
+ document.querySelectorAll('#leg input').forEach(cb => cb.addEventListener('change', e => {
100
+ typeOn[e.target.dataset.type] = e.target.checked; heat = Math.max(heat, 30); hot = true;
101
+ }));
91
102
  function radius(n){ return 5 + Math.min(n.deg,14)*1.1 + Math.min(n.hits,8)*0.6; }
92
103
  function loadData(data, keepPositions){
93
104
  const old = keepPositions ? byId : new Map();
@@ -125,14 +136,20 @@ function step(){
125
136
  let dx = e.b.x-e.a.x, dy = e.b.y-e.a.y;
126
137
  const d = Math.sqrt(dx*dx+dy*dy) + 0.01;
127
138
  const want = e.type === 'wikilink' ? 120 : 175;
128
- const k = (d - want) * (e.type === 'wikilink' ? 0.006 : 0.003);
139
+ // resorte lineal ACOTADO \u2014 jam\xE1s multiplicar por d otra vez (explota a NaN)
140
+ const f = Math.max(-6, Math.min(6, (d - want) * (e.type === 'wikilink' ? 0.03 : 0.015)));
129
141
  dx /= d; dy /= d;
130
- e.a.vx += dx*k*d; e.a.vy += dy*k*d; e.b.vx -= dx*k*d; e.b.vy -= dy*k*d;
142
+ e.a.vx += dx*f; e.a.vy += dy*f; e.b.vx -= dx*f; e.b.vy -= dy*f;
131
143
  }
144
+ const VMAX = 14;
132
145
  for (const n of nodes){
133
146
  n.vx += (W/2 - n.x) * 0.0005; n.vy += (H/2 - n.y) * 0.0005;
134
147
  n.vx *= 0.86; n.vy *= 0.86;
148
+ // velocidad acotada + saneo: la simulaci\xF3n no puede reventar con ning\xFAn grafo
149
+ n.vx = Math.max(-VMAX, Math.min(VMAX, n.vx)) || 0;
150
+ n.vy = Math.max(-VMAX, Math.min(VMAX, n.vy)) || 0;
135
151
  if (n !== dragNode){ n.x += n.vx; n.y += n.vy; }
152
+ if (!Number.isFinite(n.x) || !Number.isFinite(n.y)){ n.x = W/2; n.y = H/2; n.vx = n.vy = 0; }
136
153
  }
137
154
  if (--heat <= 0 && !dragNode) { hot = false; if (!didFit) fitView(); }
138
155
  }
@@ -161,9 +178,11 @@ function draw(){
161
178
 
162
179
  const active = hover ? new Set([hover, ...edges.filter(e=>e.a===hover||e.b===hover).flatMap(e=>[e.a,e.b])]) : null;
163
180
  const match = filter ? new Set(nodes.filter(n => n.title.toLowerCase().includes(filter) || n.tags.join(' ').toLowerCase().includes(filter))) : null;
181
+ const shown = (n) => typeOn[n.type] !== false;
164
182
  const visible = (n) => (!active || active.has(n)) && (!match || match.has(n));
165
183
 
166
184
  for (const e of edges){
185
+ if (!shown(e.a) || !shown(e.b)) continue;
167
186
  const on = visible(e.a) && visible(e.b) && (!active || e.a===hover || e.b===hover);
168
187
  ctx.beginPath();
169
188
  ctx.setLineDash(e.type === 'semantic' ? [5,5] : []);
@@ -177,6 +196,7 @@ function draw(){
177
196
  ctx.setLineDash([]);
178
197
 
179
198
  for (const n of nodes){
199
+ if (!shown(n)) continue;
180
200
  const on = visible(n);
181
201
  const color = COLORS[n.type] || '#7aa2f7';
182
202
  ctx.globalAlpha = on ? 1 : 0.12;
@@ -195,7 +215,7 @@ function draw(){
195
215
  ctx.font = (12/Math.max(zoom,0.8)) + 'px -apple-system,system-ui,sans-serif';
196
216
  ctx.lineWidth = 3/Math.max(zoom,0.8); ctx.strokeStyle = '#0b0d13';
197
217
  for (const n of nodes){
198
- if (!visible(n)) continue;
218
+ if (!shown(n) || !visible(n)) continue;
199
219
  if (!(showAll || n.deg > 1 || n === hover)) continue;
200
220
  const label = n.title.length > 34 ? n.title.slice(0,33)+'\u2026' : n.title;
201
221
  ctx.globalAlpha = n === hover ? 1 : 0.85;
@@ -209,7 +229,7 @@ function draw(){
209
229
 
210
230
  // ---------- interacci\xF3n ----------
211
231
  const toWorld = (x,y) => [(x-panX)/zoom, (y-panY)/zoom];
212
- const pick = (x,y) => { const [wx,wy] = toWorld(x,y); return nodes.find(n => { const dx=n.x-wx, dy=n.y-wy; return dx*dx+dy*dy <= (n.r+6)*(n.r+6); }); };
232
+ const pick = (x,y) => { const [wx,wy] = toWorld(x,y); return nodes.find(n => { if (typeOn[n.type] === false) return false; const dx=n.x-wx, dy=n.y-wy; return dx*dx+dy*dy <= (n.r+6)*(n.r+6); }); };
213
233
  let panning = false, px = 0, py = 0, moved = false;
214
234
  const tip = document.getElementById('tip');
215
235
  cv.addEventListener('mousedown', e => { moved = false; const n = pick(e.clientX, e.clientY); if (n){ dragNode = n; hot = true; heat = 120; } else { panning = true; px = e.clientX; py = e.clientY; } cv.classList.add('dragging'); });
@@ -0,0 +1,170 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/core/notes.ts
4
+ import fs from "fs";
5
+ import path from "path";
6
+ import matter from "gray-matter";
7
+ var NOTE_TYPES = [
8
+ "note",
9
+ "prompt",
10
+ "session",
11
+ "map",
12
+ "plan",
13
+ "task",
14
+ "verification",
15
+ "lesson",
16
+ "solution"
17
+ ];
18
+ var SKIP_DIRS = /* @__PURE__ */ new Set([".obsidian", ".vault", ".trash", ".git", "node_modules"]);
19
+ function extractWikilinks(content) {
20
+ const out = /* @__PURE__ */ new Set();
21
+ const re = /\[\[([^\]|#\n]+)(?:[|#][^\]]*)?\]\]/g;
22
+ let m;
23
+ while ((m = re.exec(content)) !== null) {
24
+ const target = m[1].trim();
25
+ if (target) out.add(target);
26
+ }
27
+ return [...out];
28
+ }
29
+ function slugify(text) {
30
+ return text.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80) || "nota";
31
+ }
32
+ function listMarkdownFiles(root) {
33
+ const out = [];
34
+ const walk = (dir) => {
35
+ let entries;
36
+ try {
37
+ entries = fs.readdirSync(dir, { withFileTypes: true });
38
+ } catch {
39
+ return;
40
+ }
41
+ for (const e of entries) {
42
+ if (e.name.startsWith(".") || SKIP_DIRS.has(e.name)) continue;
43
+ const full = path.join(dir, e.name);
44
+ if (e.isDirectory()) walk(full);
45
+ else if (e.isFile() && e.name.endsWith(".md")) out.push(full);
46
+ }
47
+ };
48
+ walk(root);
49
+ return out;
50
+ }
51
+ function parseNote(root, absPath) {
52
+ const raw = fs.readFileSync(absPath, "utf8");
53
+ const { data, content } = matter(raw);
54
+ const rel = path.relative(root, absPath).split(path.sep).join("/");
55
+ const title = typeof data.title === "string" && data.title || path.basename(absPath, ".md");
56
+ const type = NOTE_TYPES.includes(data.type) ? data.type : "note";
57
+ const status = ["active", "completed", "failed"].includes(data.status) ? data.status : void 0;
58
+ const tags = Array.isArray(data.tags) ? data.tags.map(String) : [];
59
+ return {
60
+ rel,
61
+ title,
62
+ type,
63
+ status,
64
+ tags,
65
+ created: data.created ? String(data.created) : void 0,
66
+ hits: typeof data.hits === "number" ? data.hits : 1,
67
+ content,
68
+ links: extractWikilinks(content)
69
+ };
70
+ }
71
+ function frontmatter(n) {
72
+ const lines = [
73
+ "---",
74
+ `title: ${JSON.stringify(n.title)}`,
75
+ // aliases: Obsidian resuelve [[wikilinks]] contra alias, no contra el title
76
+ // del frontmatter — sin esto su graph view muestra los enlaces como rotos
77
+ `aliases: [${JSON.stringify(n.title)}]`,
78
+ `type: ${n.type}`,
79
+ ...n.status ? [`status: ${n.status}`] : [],
80
+ `tags: [${n.tags.map((t) => JSON.stringify(t)).join(", ")}]`,
81
+ `created: ${(/* @__PURE__ */ new Date()).toISOString()}`,
82
+ `hits: ${n.hits ?? 1}`,
83
+ "---",
84
+ ""
85
+ ];
86
+ return lines.join("\n");
87
+ }
88
+ function ensureAlias(absPath) {
89
+ try {
90
+ const raw = fs.readFileSync(absPath, "utf8");
91
+ const { data, content } = matter(raw);
92
+ if (!data.title || data.aliases) return false;
93
+ data.aliases = [String(data.title)];
94
+ fs.writeFileSync(absPath, matter.stringify(content, data));
95
+ return true;
96
+ } catch {
97
+ return false;
98
+ }
99
+ }
100
+ function createNote(managed, n) {
101
+ const dir = path.join(managed, n.dir ?? "notes");
102
+ fs.mkdirSync(dir, { recursive: true });
103
+ const date = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
104
+ const base = `${date}-${slugify(n.title)}`;
105
+ let file = path.join(dir, `${base}.md`);
106
+ let i = 2;
107
+ while (fs.existsSync(file)) file = path.join(dir, `${base}-${i++}.md`);
108
+ fs.writeFileSync(
109
+ file,
110
+ frontmatter({ title: n.title, type: n.type ?? "note", tags: n.tags ?? [], status: n.status }) + n.content.trim() + "\n"
111
+ );
112
+ return file;
113
+ }
114
+ function setNoteStatus(absPath, status) {
115
+ const raw = fs.readFileSync(absPath, "utf8");
116
+ const { data, content } = matter(raw);
117
+ data.status = status;
118
+ data.updated = (/* @__PURE__ */ new Date()).toISOString();
119
+ fs.writeFileSync(absPath, matter.stringify(content, data));
120
+ }
121
+ function touchNote(absPath) {
122
+ const raw = fs.readFileSync(absPath, "utf8");
123
+ const { data, content } = matter(raw);
124
+ data.hits = (typeof data.hits === "number" ? data.hits : 1) + 1;
125
+ data.updated = (/* @__PURE__ */ new Date()).toISOString();
126
+ fs.writeFileSync(absPath, matter.stringify(content, data));
127
+ }
128
+ function upsertNote(managed, n) {
129
+ const dir = path.join(managed, n.dir ?? "notes");
130
+ fs.mkdirSync(dir, { recursive: true });
131
+ const file = path.join(dir, `${n.fixedName}.md`);
132
+ if (fs.existsSync(file)) {
133
+ const raw = fs.readFileSync(file, "utf8");
134
+ const { data } = matter(raw);
135
+ data.updated = (/* @__PURE__ */ new Date()).toISOString();
136
+ fs.writeFileSync(file, matter.stringify(n.content.trim() + "\n", data));
137
+ } else {
138
+ fs.writeFileSync(
139
+ file,
140
+ frontmatter({ title: n.title, type: n.type ?? "note", tags: n.tags ?? [], status: n.status }) + n.content.trim() + "\n"
141
+ );
142
+ }
143
+ return file;
144
+ }
145
+ function appendToNote(managed, n) {
146
+ const dir = path.join(managed, n.dir ?? "sessions");
147
+ fs.mkdirSync(dir, { recursive: true });
148
+ const file = path.join(dir, `${n.fixedName}.md`);
149
+ if (fs.existsSync(file)) {
150
+ fs.appendFileSync(file, "\n" + n.content.trim() + "\n");
151
+ } else {
152
+ fs.writeFileSync(
153
+ file,
154
+ frontmatter({ title: n.title, type: n.type ?? "session", tags: n.tags ?? [], status: n.status }) + n.content.trim() + "\n"
155
+ );
156
+ }
157
+ return file;
158
+ }
159
+
160
+ export {
161
+ slugify,
162
+ listMarkdownFiles,
163
+ parseNote,
164
+ ensureAlias,
165
+ createNote,
166
+ setNoteStatus,
167
+ touchNote,
168
+ upsertNote,
169
+ appendToNote
170
+ };