pi-weave 0.1.13 → 0.1.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-weave",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "An agent-native knowledge workspace for your life and your code. Smart notepad + repository exploration, readable by humans and agents alike.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -33,8 +33,8 @@ import { buildGraph, DEFAULT_MAX_NOTES, type BuildGraphInput } from "../graph/bu
33
33
  import type { GraphModel } from "../graph/model";
34
34
  import { readRepositorySide } from "../graph/current";
35
35
  import { withMutationQueue } from "../mutex";
36
- import { getNote, listNoteFolders, statNotes } from "../vault";
37
- import type { Note } from "../types";
36
+ import { getHtmlArtifact, getNote, listNoteFolders, statNotes } from "../vault";
37
+ import type { HtmlArtifact, Note } from "../types";
38
38
 
39
39
  /**
40
40
  * One build's outputs: the graph, and the notes it was built from.
@@ -53,6 +53,8 @@ export interface WorkspaceSnapshot {
53
53
  * caller mutating it would corrupt the next build.
54
54
  */
55
55
  notes: readonly Note[];
56
+ /** Exactly the HTML artifacts represented by the graph. */
57
+ artifacts: readonly HtmlArtifact[];
56
58
  }
57
59
 
58
60
  /** Cumulative counters, from construction. Callers take deltas. */
@@ -74,6 +76,12 @@ interface CachedNote {
74
76
  note: Note;
75
77
  }
76
78
 
79
+ interface CachedArtifact {
80
+ mtimeMs: number;
81
+ size: number;
82
+ artifact: HtmlArtifact;
83
+ }
84
+
77
85
  /** The repository half, held behind a TTL because assessing it spawns git. */
78
86
  interface CachedRepo {
79
87
  /** Wall-clock ms (from the injected clock) when this was captured. */
@@ -107,8 +115,8 @@ export type InvalidationScope = "vault" | "repo" | "none";
107
115
  * whether an event is worth forwarding at all, and one implementation means
108
116
  * the two can never disagree.
109
117
  *
110
- * - `vault`: a `*.md` under `<vaultRoot>/notes/`. Only note files count —
111
- * the vault manifest does not participate in the graph.
118
+ * - `vault`: a `*.md`, `*.html`, or `*.htm` under `<vaultRoot>/notes/`. Only
119
+ * vault artifacts count — the vault manifest does not participate in graph.
112
120
  * - `repo`: anything under `<cwd>/.okf/` (the derived index and its summary
113
121
  * sidecars) or under `<cwd>/.git/` (HEAD moves, staged changes), plus any
114
122
  * tracked file in the repo, since editing one makes the index stale.
@@ -141,6 +149,9 @@ function classify(
141
149
  const slug = rel.slice(0, -".md".length).split(sep).join("/");
142
150
  return { scope: "vault", slug };
143
151
  }
152
+ if (rel.toLowerCase().endsWith(".html") || rel.toLowerCase().endsWith(".htm")) {
153
+ return { scope: "vault", slug: rel.split(sep).join("/") };
154
+ }
144
155
  const base = rel.split(sep).pop() ?? rel;
145
156
  if (base.startsWith(".") || (base.includes(".") && !base.endsWith(".md"))) {
146
157
  return { scope: "none", slug: null };
@@ -178,12 +189,14 @@ export class WorkspaceCache {
178
189
  private readonly stalenessTtlMs: number;
179
190
 
180
191
  private notes = new Map<string, CachedNote>();
192
+ private artifacts = new Map<string, CachedArtifact>();
181
193
  /**
182
194
  * `.md` files present at the last refresh, including ones too malformed to
183
195
  * parse — mirrors `readVault().fileCount` so the vault node's note count
184
- * matches the uncached build exactly.
196
+ * matches the uncached build exactly. HTML artifacts have a separate count.
185
197
  */
186
198
  private fileCount = 0;
199
+ private artifactCount = 0;
187
200
  private folders: string[] = [];
188
201
  private repo: CachedRepo | null = null;
189
202
  /**
@@ -229,8 +242,8 @@ export class WorkspaceCache {
229
242
  private repoDirtiedDuringBuild = false;
230
243
  private building = false;
231
244
  /**
232
- * Whether the last {@link refreshNotes} observed any note-side movement:
233
- * a file read, a note that disappeared, or a change in the raw `.md` count.
245
+ * Whether the last {@link refreshNotes} observed any vault-side movement:
246
+ * a file read, a file that disappeared, or a change in raw file counts.
234
247
  * Read by {@link build} to decide whether {@link lastSnapshot} is reusable.
235
248
  */
236
249
  private notesChanged = true;
@@ -299,7 +312,8 @@ export class WorkspaceCache {
299
312
  invalidate(absPath: string): void {
300
313
  const { scope, slug } = classify(absPath, { cwd: this.cwd, vaultRoot: this.vaultRoot });
301
314
  if (scope === "vault" && slug !== null) {
302
- this.notes.delete(slug);
315
+ if (slug.toLowerCase().endsWith(".html") || slug.toLowerCase().endsWith(".htm")) this.artifacts.delete(slug);
316
+ else this.notes.delete(slug);
303
317
  if (this.building) this.evictedDuringBuild.add(slug);
304
318
  } else if (scope === "repo") {
305
319
  this.repo = null;
@@ -310,6 +324,7 @@ export class WorkspaceCache {
310
324
  /** Drop everything: a repo scan landed, or the vault root moved. */
311
325
  invalidateAll(): void {
312
326
  this.notes.clear();
327
+ this.artifacts.clear();
313
328
  this.repo = null;
314
329
  if (this.building) {
315
330
  // Whatever the in-flight build writes back was read before this call,
@@ -336,7 +351,8 @@ export class WorkspaceCache {
336
351
  this.allEvictedDuringBuild = false;
337
352
  this.repoDirtiedDuringBuild = false;
338
353
  try {
339
- const notes = await this.refreshNotes();
354
+ const refreshed = await this.refreshNotes();
355
+ const notes = refreshed.notes;
340
356
  const repoFresh = this.repoNeedsRefresh();
341
357
  const repo = await this.refreshRepo();
342
358
 
@@ -379,15 +395,21 @@ export class WorkspaceCache {
379
395
  exists: true,
380
396
  noteCount: this.fileCount,
381
397
  ...(this.folders.length > 0 ? { folders: this.folders } : {}),
398
+ ...(this.artifactCount > 0 ? { artifactCount: this.artifactCount } : {}),
382
399
  },
383
400
  notes: kept,
401
+ artifacts: refreshed.artifacts,
384
402
  repository: repo?.repository ?? null,
385
403
  };
386
404
  if (repo?.summaries !== undefined) input.summaries = repo.summaries;
387
405
 
388
406
  this.gitCalls += gitSpawnCount() - spawnsBefore;
389
407
  this.builtAt = this.now().toISOString();
390
- const snapshot: WorkspaceSnapshot = { model: buildGraph(input), notes: Object.freeze(kept) };
408
+ const snapshot: WorkspaceSnapshot = {
409
+ model: buildGraph(input),
410
+ notes: Object.freeze(kept),
411
+ artifacts: Object.freeze(input.artifacts ?? []),
412
+ };
391
413
  this.lastSnapshot = snapshot;
392
414
  return snapshot;
393
415
  } finally {
@@ -416,8 +438,15 @@ export class WorkspaceCache {
416
438
  * something else touches it.
417
439
  */
418
440
  private applyDeferredInvalidations(): void {
419
- if (this.allEvictedDuringBuild) this.notes.clear();
420
- else for (const slug of this.evictedDuringBuild) this.notes.delete(slug);
441
+ if (this.allEvictedDuringBuild) {
442
+ this.notes.clear();
443
+ this.artifacts.clear();
444
+ } else {
445
+ for (const slug of this.evictedDuringBuild) {
446
+ if (/\.html?$/i.test(slug)) this.artifacts.delete(slug);
447
+ else this.notes.delete(slug);
448
+ }
449
+ }
421
450
  if (this.repoDirtiedDuringBuild) this.repo = null;
422
451
  this.evictedDuringBuild.clear();
423
452
  this.allEvictedDuringBuild = false;
@@ -428,18 +457,40 @@ export class WorkspaceCache {
428
457
  * Stat every note; re-read only the ones whose mtime or size moved. Notes
429
458
  * that disappeared are evicted, so the map never outgrows the vault.
430
459
  */
431
- private async refreshNotes(): Promise<Note[]> {
460
+ private async refreshNotes(): Promise<{ notes: Note[]; artifacts: HtmlArtifact[] }> {
432
461
  const previousFolders = this.folders;
433
462
  const [stats, folders] = await Promise.all([statNotes(this.vaultRoot), listNoteFolders(this.vaultRoot)]);
434
463
  this.folders = folders;
435
464
  const previousCount = this.notes.size;
465
+ const previousArtifactCount = this.artifacts.size;
436
466
  const previousFileCount = this.fileCount;
437
- this.fileCount = stats.length;
467
+ const previousRawArtifactCount = this.artifactCount;
468
+ this.fileCount = stats.filter((st) => st.path.toLowerCase().endsWith(".md")).length;
469
+ this.artifactCount = stats.filter((st) => /\.html?$/i.test(st.path)).length;
438
470
  let read = 0;
439
471
 
440
472
  const next = new Map<string, CachedNote>();
473
+ const nextArtifacts = new Map<string, CachedArtifact>();
441
474
  const out: Note[] = [];
475
+ const artifactOut: HtmlArtifact[] = [];
442
476
  for (const st of stats) {
477
+ if (/\.html?$/i.test(st.path)) {
478
+ const hit = this.artifacts.get(st.slug);
479
+ if (hit !== undefined && hit.mtimeMs === st.mtimeMs && hit.size === st.size) {
480
+ this.notesCached += 1;
481
+ nextArtifacts.set(st.slug, hit);
482
+ artifactOut.push(hit.artifact);
483
+ continue;
484
+ }
485
+ this.notesRead += 1;
486
+ read += 1;
487
+ const artifact = await getHtmlArtifact(this.vaultRoot, st.slug);
488
+ if (artifact === null) continue;
489
+ const cached = { mtimeMs: st.mtimeMs, size: st.size, artifact };
490
+ nextArtifacts.set(st.slug, cached);
491
+ artifactOut.push(artifact);
492
+ continue;
493
+ }
443
494
  const hit = this.notes.get(st.slug);
444
495
  if (hit !== undefined && hit.mtimeMs === st.mtimeMs && hit.size === st.size) {
445
496
  this.notesCached += 1;
@@ -463,11 +514,14 @@ export class WorkspaceCache {
463
514
  folders.length !== previousFolders.length ||
464
515
  folders.some((f, i) => f !== previousFolders[i]);
465
516
  this.notesChanged =
466
- read > 0 || next.size !== previousCount || this.fileCount !== previousFileCount || foldersChanged;
517
+ read > 0 || next.size !== previousCount || nextArtifacts.size !== previousArtifactCount ||
518
+ this.fileCount !== previousFileCount || this.artifactCount !== previousRawArtifactCount || foldersChanged;
467
519
  this.notes = next;
520
+ this.artifacts = nextArtifacts;
521
+ const artifacts = artifactOut.sort((a, b) => b.updated.localeCompare(a.updated));
468
522
  // `statNotes` yields readdir (slug-ascending) order and sort is stable,
469
523
  // so ties break by slug — identical to `readVault`.
470
- return out.sort((a, b) => b.updated.localeCompare(a.updated));
524
+ return { notes: out.sort((a, b) => b.updated.localeCompare(a.updated)), artifacts };
471
525
  }
472
526
 
473
527
  /** The repository half, re-assessed only when the TTL has expired. */
@@ -8,7 +8,7 @@
8
8
  * makes the page's refresh-polling cheap.
9
9
  */
10
10
 
11
- import type { Note, RepoIndex, StalenessReport, VaultStatus } from "../types";
11
+ import type { HtmlArtifact, Note, RepoIndex, StalenessReport, VaultStatus } from "../types";
12
12
  import { createHash } from "node:crypto";
13
13
  import type { SummaryRecord } from "../summaries";
14
14
  import type { EdgeKind, GraphEdge, GraphModel, GraphNode } from "./model";
@@ -22,6 +22,8 @@ export interface BuildGraphInput {
22
22
  vault: VaultStatus;
23
23
  /** Full notes including bodies (for wiki-link extraction). */
24
24
  notes: Note[];
25
+ /** Standalone HTML/HTM artifacts under the vault's notes directory. */
26
+ artifacts?: HtmlArtifact[];
25
27
  /** Repository half; null when cwd is not an indexed git repository. */
26
28
  repository: { index: RepoIndex; staleness: StalenessReport } | null;
27
29
  /** Deep-scan summaries keyed by repo-relative path (docs/scan-modes.md). */
@@ -83,6 +85,9 @@ export function dataTimestamp(input: BuildGraphInput): string {
83
85
  for (const note of input.notes) {
84
86
  if (note.updated > max) max = note.updated;
85
87
  }
88
+ for (const artifact of input.artifacts ?? []) {
89
+ if (artifact.updated > max) max = artifact.updated;
90
+ }
86
91
  const repoStamp = input.repository?.index.updated ?? "";
87
92
  if (repoStamp > max) max = repoStamp;
88
93
  if (input.summaries) {
@@ -126,12 +131,18 @@ function buildVaultSide(
126
131
  root: input.vault.root,
127
132
  notes: String(input.vault.noteCount),
128
133
  };
134
+ const artifacts = input.artifacts ?? [];
135
+ if ((input.vault.artifactCount ?? artifacts.length) > 0) {
136
+ vaultDetail.artifacts = String(input.vault.artifactCount ?? artifacts.length);
137
+ }
129
138
  if (truncated) {
130
139
  vaultDetail.warning = `Graph shows the ${maxNotes} most recent notes — the vault holds ${input.vault.noteCount}. Wiki-links to older notes are omitted.`;
131
140
  }
132
141
  nodes.push({ id: "vault", kind: "vault", label: "Vault", provenance: null, detail: vaultDetail });
133
142
 
134
143
  const keptSlugs = new Set(kept.map((n) => n.slug));
144
+ const artifactSlugs = new Set(artifacts.map((a) => a.slug));
145
+ const artifactLinks = new Map<string, number>();
135
146
 
136
147
  // Nested notes nest under synthesized folder nodes so the vault tree groups
137
148
  // them the way the repository tree groups directories. Ids are prefixed
@@ -143,6 +154,7 @@ function buildVaultSide(
143
154
  ...new Set([
144
155
  ...(input.vault.folders ?? []),
145
156
  ...kept.map((n) => n.slug.split("/").slice(0, -1).join("/")),
157
+ ...artifacts.map((a) => a.slug.split("/").slice(0, -1).join("/")),
146
158
  ]),
147
159
  ]
148
160
  .filter((d) => d.length > 0)
@@ -179,7 +191,7 @@ function buildVaultSide(
179
191
  // The names, not just the count (§4.2). `detail` keeps carrying the count
180
192
  // because it is what the TUI's side panel prints; the structured targets
181
193
  // go on the model, where a UI can turn them into ghost nodes.
182
- const dangling = links.filter((slug) => !keptSlugs.has(slug));
194
+ const dangling = links.filter((slug) => !keptSlugs.has(slug) && !artifactSlugs.has(slug));
183
195
  if (dangling.length > 0) {
184
196
  detail["dangling links"] = String(dangling.length);
185
197
  danglingLinks[note.slug] = dangling;
@@ -191,6 +203,10 @@ function buildVaultSide(
191
203
  for (const target of resolved) {
192
204
  edges.push({ source: `note:${note.slug}`, target: `note:${target}`, kind: "links-to" });
193
205
  }
206
+ for (const target of links.filter((slug) => artifactSlugs.has(slug))) {
207
+ edges.push({ source: `note:${note.slug}`, target: `artifact:${target}`, kind: "links-to" });
208
+ artifactLinks.set(target, (artifactLinks.get(target) ?? 0) + 1);
209
+ }
194
210
  // A note body naming a repo path → `mentions` (§4.4). Emitted after the
195
211
  // wiki-links so a note's edges read vault-ward first, then code-ward, and
196
212
  // only for paths that are already nodes — `paths` is built from the repo
@@ -200,6 +216,21 @@ function buildVaultSide(
200
216
  edges.push({ source: `note:${note.slug}`, target, kind: "mentions" });
201
217
  }
202
218
  }
219
+ for (const artifact of artifacts) {
220
+ const dir = artifact.slug.split("/").slice(0, -1).join("/");
221
+ const parent = (dir.length > 0 && folderIds.get(dir)) || "vault";
222
+ const detail: Record<string, string> = {
223
+ path: artifact.slug,
224
+ title: artifact.title,
225
+ updated: artifact.updated,
226
+ size: `${artifact.size} bytes`,
227
+ };
228
+ if (artifact.description) detail.description = artifact.description;
229
+ const links = artifactLinks.get(artifact.slug) ?? 0;
230
+ if (links > 0) detail["link references"] = String(links);
231
+ nodes.push({ id: `artifact:${artifact.slug}`, kind: "file", label: artifact.title, provenance: null, detail });
232
+ edges.push({ source: parent, target: `artifact:${artifact.slug}`, kind: "contains" });
233
+ }
203
234
  return [...keptSlugs];
204
235
  }
205
236
 
@@ -101,11 +101,18 @@ export async function readRepositorySide(
101
101
  * a third readdir) is now N reads and one readdir (weave-workspace §4.1).
102
102
  */
103
103
  export async function buildCurrentGraph(cwd: string, vaultRoot: string = resolveVaultRoot()): Promise<GraphModel> {
104
- const { notes, fileCount, folders } = await readVault(vaultRoot);
104
+ const { notes, fileCount, folders, artifacts, artifactCount } = await readVault(vaultRoot);
105
105
 
106
106
  const input: BuildGraphInput = {
107
- vault: { root: vaultRoot, exists: true, noteCount: fileCount, ...(folders ? { folders } : {}) },
107
+ vault: {
108
+ root: vaultRoot,
109
+ exists: true,
110
+ noteCount: fileCount,
111
+ ...(folders ? { folders } : {}),
112
+ ...(artifactCount ? { artifactCount } : {}),
113
+ },
108
114
  notes: notes.slice(0, DEFAULT_MAX_NOTES),
115
+ ...(artifacts ? { artifacts } : {}),
109
116
  repository: null,
110
117
  };
111
118
 
@@ -23,7 +23,11 @@ export function extractWikilinks(body: string): string[] {
23
23
  for (const match of body.matchAll(WIKILINK_RE)) {
24
24
  const raw = (match[1] ?? "").trim();
25
25
  if (raw.length === 0) continue;
26
- const slug = raw.split("/").map((part) => slugify(part)).join("/");
26
+ // HTML artifacts are addressed by their vault-relative filename; unlike a
27
+ // Markdown note, the extension is part of the stable identity.
28
+ const slug = /\.html?$/i.test(raw)
29
+ ? raw.replace(/\\/g, "/").replace(/^\.\//, "")
30
+ : raw.split("/").map((part) => slugify(part)).join("/");
27
31
  if (seen.has(slug)) continue;
28
32
  seen.add(slug);
29
33
  out.push(slug);
package/src/core/index.ts CHANGED
@@ -21,11 +21,15 @@ export {
21
21
  finalizeNote,
22
22
  formatNote,
23
23
  formatRawAppend,
24
+ getHtmlArtifact,
24
25
  getNote,
25
26
  listNotes,
27
+ parseHtmlArtifact,
28
+ resolveHtmlPath,
26
29
  resolveNotePath,
27
30
  searchNotes,
28
31
  } from "./vault";
32
+ export type { HtmlArtifact } from "./types";
29
33
  export { withMutationQueue } from "./mutex";
30
34
  export { formatDashboard, formatStatusLine, getWorkspaceStatus } from "./workspace";
31
35
  export { WorkspaceCache } from "./cache/workspace";
package/src/core/types.ts CHANGED
@@ -69,6 +69,17 @@ export interface Note extends NoteMeta {
69
69
  frontMatter?: NoteFrontMatter;
70
70
  }
71
71
 
72
+ /** A standalone HTML artifact discovered under the vault's notes directory. */
73
+ export interface HtmlArtifact {
74
+ /** Vault-relative path, including the `.html`/`.htm` extension. */
75
+ slug: string;
76
+ title: string;
77
+ description: string;
78
+ /** ISO mtime and byte size, used for graph display and cache invalidation. */
79
+ updated: string;
80
+ size: number;
81
+ }
82
+
72
83
  /** Summary of one note for list/search output. */
73
84
  export interface NoteSummary extends NoteMeta {
74
85
  slug: string;
@@ -175,6 +186,8 @@ export interface VaultStatus {
175
186
  exists: boolean;
176
187
  noteCount: number;
177
188
  folders?: string[];
189
+ /** Number of discovered HTML/HTM artifacts. */
190
+ artifactCount?: number;
178
191
  }
179
192
 
180
193
  /** Status of the repository half of the workspace. */
package/src/core/vault.ts CHANGED
@@ -1,16 +1,18 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { promises as fs } from "node:fs";
3
- import { dirname, isAbsolute, join, relative } from "node:path";
3
+ import { basename, dirname, isAbsolute, join, relative } from "node:path";
4
4
  import {
5
5
  parseFrontMatter,
6
6
  parseNoteFile,
7
7
  serializeNote,
8
+ unquoteField,
8
9
  } from "./frontmatter";
9
10
  import { withMutationQueue } from "./mutex";
10
11
  import { NOTES_DIR, OKF_MANIFEST } from "./paths";
11
12
  import { slugify, uniqueSlug } from "./slug";
12
13
  import type {
13
14
  Note,
15
+ HtmlArtifact,
14
16
  NoteFrontMatter,
15
17
  NoteMeta,
16
18
  NoteSearchHit,
@@ -345,26 +347,127 @@ export async function finalizeNote(
345
347
  });
346
348
  }
347
349
 
348
- async function listNoteFiles(root: string): Promise<string[]> {
350
+ async function listVaultEntries(root: string): Promise<{ files: string[]; folders: string[] }> {
349
351
  const dir = join(root, NOTES_DIR);
350
- const out: string[] = [];
351
- async function walk(prefix: string): Promise<void> {
352
+ const files: string[] = [];
353
+ const folders: string[] = [];
354
+ const seen = new Set<string>();
355
+ async function walk(prefix: string, includeFolders = true): Promise<boolean> {
356
+ const path = prefix.length > 0 ? join(dir, prefix) : dir;
357
+ let realPath: string;
352
358
  let entries;
353
359
  try {
354
- entries = await fs.readdir(prefix.length > 0 ? join(dir, prefix) : dir, { withFileTypes: true });
360
+ realPath = await fs.realpath(path);
361
+ if (seen.has(realPath)) return false;
362
+ seen.add(realPath);
363
+ entries = await fs.readdir(path, { withFileTypes: true });
355
364
  } catch {
356
- return;
365
+ return false;
357
366
  }
358
367
  for (const entry of entries) {
359
- if (entry.isDirectory()) {
360
- await walk(prefix.length > 0 ? `${prefix}/${entry.name}` : entry.name);
361
- } else if (entry.isFile() && entry.name.endsWith(".md")) {
362
- out.push(prefix.length > 0 ? `${prefix}/${entry.name}` : entry.name);
368
+ const child = prefix.length > 0 ? `${prefix}/${entry.name}` : entry.name;
369
+ let isDirectory = entry.isDirectory();
370
+ let isFile = entry.isFile();
371
+ if (entry.isSymbolicLink()) {
372
+ try {
373
+ const stat = await fs.stat(join(dir, child));
374
+ isDirectory = stat.isDirectory();
375
+ isFile = stat.isFile();
376
+ } catch {
377
+ continue;
378
+ }
379
+ }
380
+ if (isDirectory) {
381
+ const visible = includeFolders && !entry.name.startsWith(".");
382
+ if ((await walk(child, visible)) && visible) folders.push(child);
383
+ } else if (isFile && isVaultArtifact(entry.name)) {
384
+ files.push(child);
363
385
  }
364
386
  }
387
+ return true;
365
388
  }
366
389
  await walk("");
367
- return out.sort();
390
+ return { files: files.sort(), folders: folders.sort() };
391
+ }
392
+
393
+ async function listNoteFiles(root: string): Promise<string[]> {
394
+ return (await listVaultEntries(root)).files;
395
+ }
396
+
397
+ function isMarkdown(path: string): boolean {
398
+ return path.endsWith(".md");
399
+ }
400
+
401
+ function isHtml(path: string): boolean {
402
+ return path.toLowerCase().endsWith(".html") || path.toLowerCase().endsWith(".htm");
403
+ }
404
+
405
+ function isVaultArtifact(path: string): boolean {
406
+ return isMarkdown(path) || isHtml(path);
407
+ }
408
+
409
+ /** Resolve a vault-relative HTML path without allowing traversal. */
410
+ export function resolveHtmlPath(root: string, slug: string): string | null {
411
+ if (slug.trim().length === 0 || !isHtml(slug)) return null;
412
+ const notesDir = join(root, NOTES_DIR);
413
+ const candidate = join(notesDir, slug);
414
+ const rel = relative(notesDir, candidate);
415
+ return rel.startsWith("..") || isAbsolute(rel) || rel.length === 0 ? null : candidate;
416
+ }
417
+
418
+ function decodeHtml(value: string): string {
419
+ return value
420
+ .replace(/&amp;/gi, "&")
421
+ .replace(/&lt;/gi, "<")
422
+ .replace(/&gt;/gi, ">")
423
+ .replace(/&quot;/gi, '"')
424
+ .replace(/&#39;|&apos;/gi, "'")
425
+ .replace(/&#(\d+);/g, (_, n: string) => String.fromCodePoint(Number(n)));
426
+ }
427
+
428
+ function htmlTagValue(text: string, tag: string): string {
429
+ const match = new RegExp(`<${tag}\\b[^>]*>([\\s\\S]*?)<\\/${tag}>`, "i").exec(text);
430
+ return match?.[1] === undefined ? "" : decodeHtml(match[1].replace(/<[^>]+>/g, "").trim());
431
+ }
432
+
433
+ function htmlMeta(text: string, name: string): string {
434
+ for (const match of text.matchAll(/<meta\b([^>]*)>/gi)) {
435
+ const attrs = match[1] ?? "";
436
+ const get = (key: string): string => {
437
+ const value = new RegExp(`\\b${key}\\s*=\\s*([\\\"'])(.*?)\\1`, "i").exec(attrs);
438
+ return value?.[2] ? decodeHtml(value[2].trim()) : "";
439
+ };
440
+ if (get("name").toLowerCase() === name.toLowerCase()) return get("content");
441
+ }
442
+ return "";
443
+ }
444
+
445
+ /** Parse metadata from an HTML file without attempting to interpret its body. */
446
+ export function parseHtmlArtifact(slug: string, text: string, updated = "", size = Buffer.byteLength(text)): HtmlArtifact {
447
+ const comment = /<!--[\s\S]*?---\n([\s\S]*?)\n---[\s\S]*?-->/m.exec(text);
448
+ const fields = comment ? parseFrontMatter(`---\n${comment[1]}\n---\n`)?.fields : undefined;
449
+ const fallback = basename(slug).replace(/\.html?$/i, "").replace(/[-_]+/g, " ");
450
+ return {
451
+ slug,
452
+ title: fields?.get("title") ? unquoteField(fields.get("title")!) : htmlTagValue(text, "title") || fallback,
453
+ description: fields?.get("description")
454
+ ? unquoteField(fields.get("description")!)
455
+ : htmlMeta(text, "description"),
456
+ updated,
457
+ size,
458
+ };
459
+ }
460
+
461
+ /** Read one HTML artifact by its vault-relative path. */
462
+ export async function getHtmlArtifact(root: string, slug: string): Promise<HtmlArtifact | null> {
463
+ const path = resolveHtmlPath(root, slug);
464
+ if (!path) return null;
465
+ try {
466
+ const [text, st] = await Promise.all([fs.readFile(path, "utf8"), fs.stat(path)]);
467
+ return parseHtmlArtifact(slug, text, st.mtime.toISOString(), st.size);
468
+ } catch {
469
+ return null;
470
+ }
368
471
  }
369
472
 
370
473
  export function summarizeNote(note: Note): NoteSummary {
@@ -383,25 +486,7 @@ function byUpdatedDesc(a: { updated: string }, b: { updated: string }): number {
383
486
  }
384
487
 
385
488
  export async function listNoteFolders(root: string): Promise<string[]> {
386
- const dir = join(root, NOTES_DIR);
387
- const out: string[] = [];
388
- async function walk(prefix: string): Promise<void> {
389
- let entries;
390
- try {
391
- entries = await fs.readdir(prefix.length > 0 ? join(dir, prefix) : dir, { withFileTypes: true });
392
- } catch {
393
- return;
394
- }
395
- for (const entry of entries) {
396
- if (entry.isDirectory() && !entry.name.startsWith(".")) {
397
- const folder = prefix.length > 0 ? `${prefix}/${entry.name}` : entry.name;
398
- out.push(folder);
399
- await walk(folder);
400
- }
401
- }
402
- }
403
- await walk("");
404
- return out.sort();
489
+ return (await listVaultEntries(root)).folders;
405
490
  }
406
491
 
407
492
  /**
@@ -422,21 +507,33 @@ export interface VaultSnapshot {
422
507
  fileCount: number;
423
508
  /** Subdirectories present in <vault>/notes/, including empty ones. */
424
509
  folders?: string[];
510
+ /** Readable standalone HTML/HTM artifacts. */
511
+ artifacts?: HtmlArtifact[];
512
+ /** Number of HTML/HTM files present, including malformed files. */
513
+ artifactCount?: number;
425
514
  }
426
515
 
427
516
  /** Read the whole vault in one pass: one readdir, one read per note. */
428
517
  export async function readVault(root: string): Promise<VaultSnapshot> {
429
- const [files, folders] = await Promise.all([listNoteFiles(root), listNoteFolders(root)]);
518
+ const { files, folders } = await listVaultEntries(root);
430
519
  const notes: Note[] = [];
520
+ const artifacts: HtmlArtifact[] = [];
431
521
  for (const file of files) {
432
- const note = await getNote(root, file.slice(0, -".md".length));
433
- if (!note) continue; // unreadable/malformed files are skipped, not fatal
434
- notes.push(note);
522
+ if (isMarkdown(file)) {
523
+ const note = await getNote(root, file.slice(0, -".md".length));
524
+ if (note) notes.push(note);
525
+ } else if (isHtml(file)) {
526
+ const artifact = await getHtmlArtifact(root, file);
527
+ if (artifact) artifacts.push(artifact);
528
+ }
435
529
  }
530
+ const artifactCount = files.filter(isHtml).length;
436
531
  return {
437
532
  notes: notes.sort(byUpdatedDesc),
438
- fileCount: files.length,
533
+ fileCount: files.filter(isMarkdown).length,
439
534
  ...(folders.length > 0 ? { folders } : {}),
535
+ ...(artifacts.length > 0 ? { artifacts: artifacts.sort(byUpdatedDesc) } : {}),
536
+ ...(artifactCount > 0 ? { artifactCount } : {}),
440
537
  };
441
538
  }
442
539
 
@@ -465,7 +562,7 @@ export async function statNotes(root: string): Promise<NoteStat[]> {
465
562
  const path = join(dir, file);
466
563
  try {
467
564
  const st = await fs.stat(path);
468
- return { slug: file.slice(0, -".md".length), path, mtimeMs: st.mtimeMs, size: st.size };
565
+ return { slug: isMarkdown(file) ? file.slice(0, -".md".length) : file, path, mtimeMs: st.mtimeMs, size: st.size };
469
566
  } catch {
470
567
  return null; // raced a delete
471
568
  }
@@ -480,7 +577,7 @@ export async function listNotes(root: string): Promise<NoteSummary[]> {
480
577
  }
481
578
 
482
579
  export async function noteCount(root: string): Promise<number> {
483
- return (await listNoteFiles(root)).length;
580
+ return (await listNoteFiles(root)).filter(isMarkdown).length;
484
581
  }
485
582
 
486
583
  /**
@@ -35,7 +35,10 @@ export interface DetailModel {
35
35
 
36
36
  /** Ordered meta keys shown in the detail header. */
37
37
  const META_ORDER = [
38
+ "title",
39
+ "description",
38
40
  "path",
41
+ "size",
39
42
  "slug",
40
43
  "source",
41
44
  "updated",
@@ -55,6 +58,7 @@ const META_ORDER = [
55
58
  "summarized at",
56
59
  "summary",
57
60
  "dangling links",
61
+ "link references",
58
62
  "warning",
59
63
  "stale",
60
64
  "preview",