@mulmoclaude/core 6.0.1 → 7.1.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/dist/collection/index.cjs +1 -1
- package/dist/collection/index.js +1 -1
- package/dist/collection/registry/server/index.cjs +6 -6
- package/dist/collection/registry/server/index.js +6 -6
- package/dist/collection/server/index.cjs +1 -1
- package/dist/collection/server/index.js +1 -1
- package/dist/collection-watchers/index.cjs +2 -2
- package/dist/collection-watchers/index.js +2 -2
- package/dist/feeds/server/index.cjs +4 -4
- package/dist/feeds/server/index.js +4 -4
- package/dist/files/index.cjs +11 -31
- package/dist/files/index.cjs.map +1 -1
- package/dist/files/index.d.ts +1 -0
- package/dist/files/index.js +4 -28
- package/dist/files/index.js.map +1 -1
- package/dist/files/withinRoot.d.ts +7 -0
- package/dist/google/index.cjs +3 -3
- package/dist/google/index.js +3 -3
- package/dist/plugin-vue/index.cjs +181 -267
- package/dist/plugin-vue/index.cjs.map +1 -1
- package/dist/plugin-vue/index.js +181 -267
- package/dist/plugin-vue/index.js.map +1 -1
- package/dist/remote-host/server/index.cjs +1 -1
- package/dist/remote-host/server/index.js +1 -1
- package/dist/{server-CQ88wv71.cjs → server-CnCUBmSn.cjs} +5 -5
- package/dist/{server-CQ88wv71.cjs.map → server-CnCUBmSn.cjs.map} +1 -1
- package/dist/{server-Dh7pgRRg.js → server-Dp5KWarO.js} +5 -5
- package/dist/{server-Dh7pgRRg.js.map → server-Dp5KWarO.js.map} +1 -1
- package/dist/whisper/index.cjs +1 -1
- package/dist/whisper/index.js +1 -1
- package/dist/wiki/index.cjs +1 -1
- package/dist/wiki/index.js +1 -1
- package/dist/wiki/server/fs.d.ts +0 -2
- package/dist/wiki/server/index.cjs +64 -47
- package/dist/wiki/server/index.cjs.map +1 -1
- package/dist/wiki/server/index.js +65 -48
- package/dist/wiki/server/index.js.map +1 -1
- package/dist/wiki/server/locations.d.ts +10 -0
- package/dist/withinRoot-Bbj6E-Lf.js +84 -0
- package/dist/withinRoot-Bbj6E-Lf.js.map +1 -0
- package/dist/withinRoot-FLjxC8oP.cjs +121 -0
- package/dist/withinRoot-FLjxC8oP.cjs.map +1 -0
- package/package.json +9 -9
package/dist/whisper/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_rolldown_runtime = require("../rolldown-runtime-CmQyd0Gu.cjs");
|
|
3
|
-
const require_dist = require("../dist-734JaRYi.cjs");
|
|
4
3
|
require("../errors-B9mCEVG9.cjs");
|
|
4
|
+
const require_dist = require("../dist-734JaRYi.cjs");
|
|
5
5
|
let node_fs = require("node:fs");
|
|
6
6
|
let node_path = require("node:path");
|
|
7
7
|
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
package/dist/whisper/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as hasStringProp, t as errorMessage } from "../dist-BmO4oSQy.js";
|
|
2
1
|
import "../errors-0QwjDxsv.js";
|
|
2
|
+
import { i as hasStringProp, t as errorMessage } from "../dist-BmO4oSQy.js";
|
|
3
3
|
import { createWriteStream, mkdirSync, renameSync, statSync, unlinkSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { randomUUID } from "node:crypto";
|
package/dist/wiki/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_dist = require("../dist-734JaRYi.cjs");
|
|
3
2
|
const require_graph = require("../graph-BvVMZfDV.cjs");
|
|
4
3
|
const require_slug = require("../slug-DVkuPjIv.cjs");
|
|
4
|
+
const require_dist = require("../dist-734JaRYi.cjs");
|
|
5
5
|
// src/wiki/route.ts
|
|
6
6
|
var WIKI_ROUTE_SECTION = {
|
|
7
7
|
pages: "pages",
|
package/dist/wiki/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { c as isRecord, n as escapeHtml } from "../dist-BmO4oSQy.js";
|
|
2
1
|
import { _ as resolveLinkTarget, a as findMissingFiles, b as parseWikiLink, c as formatLintReport, d as buildTableColumnMap, f as extractHashTags, g as matchWikiSlug, h as parseTagsCell, i as findBrokenLinksInPage, l as BULLET_LINK_PATTERN, m as parseIndexEntries, n as incomingLinks, o as findOrphanPages, p as extractSlugFromBulletHref, r as pageOutgoingSlugs, s as findTagDrift, t as buildWikiGraph, u as BULLET_WIKI_LINK_PATTERN, v as slugByIndexTitle, y as WIKI_LINK_PATTERN } from "../graph-DBbzemby.js";
|
|
3
2
|
import { n as wikiPageStem, r as wikiSlugify, t as isSafeSlug } from "../slug-D24AYqCZ.js";
|
|
3
|
+
import { c as isRecord, n as escapeHtml } from "../dist-BmO4oSQy.js";
|
|
4
4
|
// src/wiki/route.ts
|
|
5
5
|
var WIKI_ROUTE_SECTION = {
|
|
6
6
|
pages: "pages",
|
package/dist/wiki/server/fs.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import { Dirent, Stats } from 'node:fs';
|
|
2
|
-
export declare function readTextSafe(absPath: string): Promise<string | null>;
|
|
3
|
-
export declare function readTextSafeSync(absPath: string): string | null;
|
|
4
2
|
export declare function statSafeAsync(absPath: string): Promise<Stats | null>;
|
|
5
3
|
export declare function readDirSafeAsync(absPath: string): Promise<Dirent[]>;
|
|
@@ -1,28 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_rolldown_runtime = require("../../rolldown-runtime-CmQyd0Gu.cjs");
|
|
3
|
+
const require_wiki_paths = require("../paths.cjs");
|
|
3
4
|
const require_graph = require("../../graph-BvVMZfDV.cjs");
|
|
4
5
|
const require_slug = require("../../slug-DVkuPjIv.cjs");
|
|
5
|
-
const
|
|
6
|
-
let node_fs = require("node:fs");
|
|
6
|
+
const require_withinRoot = require("../../withinRoot-FLjxC8oP.cjs");
|
|
7
7
|
let node_path = require("node:path");
|
|
8
8
|
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
9
9
|
let node_fs_promises = require("node:fs/promises");
|
|
10
10
|
let _mulmoclaude_markdown_utils_markdown_frontmatter = require("@mulmoclaude/markdown-utils/markdown/frontmatter");
|
|
11
11
|
// src/wiki/server/fs.ts
|
|
12
|
-
async function readTextSafe(absPath) {
|
|
13
|
-
try {
|
|
14
|
-
return await (0, node_fs_promises.readFile)(absPath, "utf-8");
|
|
15
|
-
} catch {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function readTextSafeSync(absPath) {
|
|
20
|
-
try {
|
|
21
|
-
return (0, node_fs.readFileSync)(absPath, "utf-8");
|
|
22
|
-
} catch {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
12
|
async function statSafeAsync(absPath) {
|
|
27
13
|
try {
|
|
28
14
|
return await (0, node_fs_promises.stat)(absPath);
|
|
@@ -84,10 +70,29 @@ function parseFrontmatterTags(content) {
|
|
|
84
70
|
if (!Array.isArray(tagsValue)) return [];
|
|
85
71
|
return tagsValue.filter((item) => typeof item === "string").map(cleanTagToken).filter((token) => token.length > 0);
|
|
86
72
|
}
|
|
73
|
+
// src/wiki/server/locations.ts
|
|
74
|
+
function wikiReadLocations(workspace) {
|
|
75
|
+
const dirs = require_wiki_paths.wikiDirs(workspace);
|
|
76
|
+
const workspaceReal = require_withinRoot.realpathSyncOrNull(workspace);
|
|
77
|
+
const insideWorkspace = (absPath) => {
|
|
78
|
+
const candidateReal = workspaceReal === null ? null : require_withinRoot.realpathSyncOrNull(node_path.default.resolve(workspaceReal, node_path.default.relative(workspace, absPath)));
|
|
79
|
+
return workspaceReal !== null && candidateReal !== null && require_withinRoot.isWithinRoot(workspaceReal, candidateReal) ? candidateReal : null;
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
pagesDir: dirs.pagesDir,
|
|
83
|
+
workspaceReal,
|
|
84
|
+
pagesReal: insideWorkspace(dirs.pagesDir),
|
|
85
|
+
indexReal: insideWorkspace(dirs.indexFile),
|
|
86
|
+
logReal: insideWorkspace(dirs.logFile)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
87
89
|
// src/wiki/server/engine.ts
|
|
88
90
|
var MIN_FUZZY_SLUG_LEN = 6;
|
|
89
|
-
function readFileOrEmpty(absPath) {
|
|
90
|
-
return
|
|
91
|
+
function readFileOrEmpty(absPath, workspaceReal) {
|
|
92
|
+
return absPath === null || workspaceReal === null ? "" : require_withinRoot.readTextWithinRootSync(workspaceReal, absPath) ?? "";
|
|
93
|
+
}
|
|
94
|
+
async function pageSlugs(locations) {
|
|
95
|
+
return locations.pagesReal === null ? /* @__PURE__ */ new Map() : (await getPageIndex(locations.pagesReal)).slugs;
|
|
91
96
|
}
|
|
92
97
|
/** Walk every indexed slug for an `includes`-style match. Returns the
|
|
93
98
|
* single best candidate, or null when the slug is too short OR several
|
|
@@ -113,8 +118,8 @@ function pickFuzzyMatch(slug, slugs) {
|
|
|
113
118
|
/** File matching an index.md entry whose title equals `target` — the
|
|
114
119
|
* last resort for a link written as the display title rather than
|
|
115
120
|
* the page's own name. */
|
|
116
|
-
function fileByIndexTitle(
|
|
117
|
-
const entries = require_graph.parseIndexEntries(readFileOrEmpty(
|
|
121
|
+
function fileByIndexTitle(locations, target, slugs) {
|
|
122
|
+
const entries = require_graph.parseIndexEntries(readFileOrEmpty(locations.indexReal, locations.workspaceReal));
|
|
118
123
|
const trimmed = target.trim();
|
|
119
124
|
const titleMatch = entries.find((entry) => entry.title === trimmed);
|
|
120
125
|
return titleMatch ? slugs.get(titleMatch.slug) : void 0;
|
|
@@ -124,21 +129,25 @@ function fileByIndexTitle(indexFile, target, slugs) {
|
|
|
124
129
|
* the `[[target|display]]` form; `parseWikiLink` strips the display
|
|
125
130
|
* half so the lookup uses just the target. */
|
|
126
131
|
async function resolvePagePath(workspace, pageName) {
|
|
127
|
-
const
|
|
128
|
-
const
|
|
132
|
+
const locations = wikiReadLocations(workspace);
|
|
133
|
+
const fileName = await resolvePageFile(locations, pageName);
|
|
134
|
+
return fileName === null ? null : node_path.default.join(locations.pagesDir, fileName);
|
|
135
|
+
}
|
|
136
|
+
async function resolvePageFile(locations, pageName) {
|
|
137
|
+
const slugs = await pageSlugs(locations);
|
|
129
138
|
if (slugs.size === 0) return null;
|
|
130
139
|
const { target } = require_graph.parseWikiLink(pageName);
|
|
131
140
|
const matched = require_graph.matchWikiSlug(target, slugs);
|
|
132
141
|
const matchedFile = matched === null ? void 0 : slugs.get(matched);
|
|
133
|
-
if (matchedFile) return
|
|
142
|
+
if (matchedFile) return matchedFile;
|
|
134
143
|
const fuzzy = pickFuzzyMatch(require_slug.wikiSlugify(target), slugs);
|
|
135
|
-
if (fuzzy) return
|
|
136
|
-
|
|
137
|
-
return titleFile ? node_path.default.join(pagesDir, titleFile) : null;
|
|
144
|
+
if (fuzzy) return fuzzy;
|
|
145
|
+
return fileByIndexTitle(locations, target, slugs) ?? null;
|
|
138
146
|
}
|
|
139
147
|
/** Raw `index.md` content + its parsed entries. */
|
|
140
148
|
function readWikiIndex(workspace) {
|
|
141
|
-
const
|
|
149
|
+
const locations = wikiReadLocations(workspace);
|
|
150
|
+
const content = readFileOrEmpty(locations.indexReal, locations.workspaceReal);
|
|
142
151
|
return {
|
|
143
152
|
content,
|
|
144
153
|
entries: require_graph.parseIndexEntries(content)
|
|
@@ -146,42 +155,50 @@ function readWikiIndex(workspace) {
|
|
|
146
155
|
}
|
|
147
156
|
/** Raw `log.md` content (empty string if absent). */
|
|
148
157
|
function readWikiLog(workspace) {
|
|
149
|
-
|
|
158
|
+
const locations = wikiReadLocations(workspace);
|
|
159
|
+
return readFileOrEmpty(locations.logReal, locations.workspaceReal);
|
|
150
160
|
}
|
|
151
161
|
/** Resolve + read a page. Distinguishes missing (`exists: false`) from
|
|
152
162
|
* empty-but-present (`exists: true`, `content: ""`). */
|
|
153
163
|
async function readWikiPage(workspace, pageName) {
|
|
154
|
-
const
|
|
155
|
-
const
|
|
156
|
-
|
|
164
|
+
const locations = wikiReadLocations(workspace);
|
|
165
|
+
const fileName = await resolvePageFile(locations, pageName);
|
|
166
|
+
if (fileName === null || locations.pagesReal === null) return {
|
|
167
|
+
filePath: null,
|
|
168
|
+
content: "",
|
|
169
|
+
exists: false,
|
|
170
|
+
resolvedTitle: pageName
|
|
171
|
+
};
|
|
172
|
+
const content = readFileOrEmpty(node_path.default.join(locations.pagesReal, fileName), locations.workspaceReal);
|
|
157
173
|
return {
|
|
158
|
-
filePath,
|
|
174
|
+
filePath: node_path.default.join(locations.pagesDir, fileName),
|
|
159
175
|
content,
|
|
160
|
-
exists:
|
|
161
|
-
resolvedTitle
|
|
176
|
+
exists: true,
|
|
177
|
+
resolvedTitle: node_path.default.basename(fileName, ".md")
|
|
162
178
|
};
|
|
163
179
|
}
|
|
164
180
|
/** Page body, or "" when the file vanished between indexing and reading. */
|
|
165
|
-
async function readPageBody(
|
|
166
|
-
|
|
181
|
+
async function readPageBody(locations, fileName) {
|
|
182
|
+
const { pagesReal, workspaceReal } = locations;
|
|
183
|
+
return pagesReal === null || workspaceReal === null ? "" : await require_withinRoot.readTextWithinRoot(workspaceReal, node_path.default.join(pagesReal, fileName)) ?? "";
|
|
167
184
|
}
|
|
168
185
|
/** Read every page + the index and build the page→page link graph.
|
|
169
186
|
* No cache: the graph is requested explicitly and a content edit does
|
|
170
187
|
* not advance the pagesDir mtime the page index caches on. */
|
|
171
188
|
async function loadWikiGraph(workspace) {
|
|
172
|
-
const
|
|
173
|
-
const
|
|
189
|
+
const locations = wikiReadLocations(workspace);
|
|
190
|
+
const slugs = await pageSlugs(locations);
|
|
174
191
|
const pages = await Promise.all([...slugs.entries()].map(async ([slug, fileName]) => ({
|
|
175
192
|
slug,
|
|
176
|
-
content: await readPageBody(
|
|
193
|
+
content: await readPageBody(locations, fileName)
|
|
177
194
|
})));
|
|
178
|
-
const indexEntries = require_graph.parseIndexEntries(readFileOrEmpty(
|
|
195
|
+
const indexEntries = require_graph.parseIndexEntries(readFileOrEmpty(locations.indexReal, locations.workspaceReal));
|
|
179
196
|
return require_graph.buildWikiGraph(pages, indexEntries);
|
|
180
197
|
}
|
|
181
|
-
async function readPageBodies(
|
|
198
|
+
async function readPageBodies(locations, fileNames) {
|
|
182
199
|
return Promise.all(fileNames.map(async (fileName) => ({
|
|
183
200
|
fileName,
|
|
184
|
-
content: await readPageBody(
|
|
201
|
+
content: await readPageBody(locations, fileName)
|
|
185
202
|
})));
|
|
186
203
|
}
|
|
187
204
|
/** Frontmatter `tags:` per page, keyed for `findTagDrift`. Lowercased so
|
|
@@ -196,13 +213,13 @@ function frontmatterTagIndex(bodies) {
|
|
|
196
213
|
}
|
|
197
214
|
/** Run every lint rule over the on-disk wiki, returning issue strings. */
|
|
198
215
|
async function collectLintIssues(workspace) {
|
|
199
|
-
const
|
|
200
|
-
const
|
|
201
|
-
if (slugs.size === 0) return ["- Wiki `pages/` directory does not exist yet. Start ingesting sources."];
|
|
202
|
-
const pageEntries = require_graph.parseIndexEntries(readFileOrEmpty(
|
|
216
|
+
const locations = wikiReadLocations(workspace);
|
|
217
|
+
const slugs = await pageSlugs(locations);
|
|
218
|
+
if (slugs.size === 0 || locations.pagesReal === null) return ["- Wiki `pages/` directory does not exist yet. Start ingesting sources."];
|
|
219
|
+
const pageEntries = require_graph.parseIndexEntries(readFileOrEmpty(locations.indexReal, locations.workspaceReal));
|
|
203
220
|
const fileSlugs = new Set(slugs.keys());
|
|
204
221
|
const slugByTitle = require_graph.slugByIndexTitle(pageEntries);
|
|
205
|
-
const bodies = await readPageBodies(
|
|
222
|
+
const bodies = await readPageBodies(locations, [...slugs.values()]);
|
|
206
223
|
return [
|
|
207
224
|
...require_graph.findOrphanPages(fileSlugs, new Set(pageEntries.map((entry) => entry.slug))),
|
|
208
225
|
...require_graph.findMissingFiles(pageEntries, fileSlugs),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["readFile","readFileSync","stat","readdir","parseFrontmatter","parseIndexEntries","wikiDirs","parseWikiLink","matchWikiSlug","path","wikiSlugify","buildWikiGraph","slugByIndexTitle","findOrphanPages","findMissingFiles","findBrokenLinksInPage","findTagDrift"],"sources":["../../../src/wiki/server/fs.ts","../../../src/wiki/server/pageIndex.ts","../../../src/wiki/server/frontmatter.ts","../../../src/wiki/server/engine.ts"],"sourcesContent":["// Minimal ENOENT-swallowing fs wrappers for the wiki read-engine.\n// Self-contained (core can't reach the host's `server/utils/files/safe.ts`);\n// only the handful of helpers the wiki engine needs. Same \"return\n// null / [] on any error\" contract so callers branch on the value\n// instead of try/catch.\n\nimport type { Dirent, Stats } from \"node:fs\";\nimport { readFileSync } from \"node:fs\";\nimport { readFile, readdir, stat } from \"node:fs/promises\";\n\nexport async function readTextSafe(absPath: string): Promise<string | null> {\n try {\n return await readFile(absPath, \"utf-8\");\n } catch {\n return null;\n }\n}\n\nexport function readTextSafeSync(absPath: string): string | null {\n try {\n return readFileSync(absPath, \"utf-8\");\n } catch {\n return null;\n }\n}\n\nexport async function statSafeAsync(absPath: string): Promise<Stats | null> {\n try {\n return await stat(absPath);\n } catch {\n return null;\n }\n}\n\nexport async function readDirSafeAsync(absPath: string): Promise<Dirent[]> {\n try {\n return await readdir(absPath, { withFileTypes: true });\n } catch {\n return [];\n }\n}\n","// In-memory index of `<pagesDir>/*.md` keyed by slug (= filename\n// without the `.md` extension). Kept fresh via `pagesDir` mtime —\n// adding, removing, or renaming a file under `pagesDir` advances the\n// directory's mtime on every major filesystem we target (macOS APFS,\n// Linux ext4, Windows NTFS), so one cheap `stat()` per request is\n// enough to decide whether to rebuild.\n\nimport { readDirSafeAsync, statSafeAsync } from \"./fs.js\";\n\nexport interface PageIndex {\n mtimeMs: number;\n /** slug → filename (e.g. \"sakura-internet\" → \"sakura-internet.md\"). */\n slugs: Map<string, string>;\n}\n\n// Keyed by `pagesDir`: the engine is workspace-injected and may be\n// called with more than one pages directory in a single process. A\n// single global slot would let one workspace's slug map be returned\n// for another whenever their mtimes happen to tie (Codex P2 on #1876).\nconst cache = new Map<string, PageIndex>();\n\n/**\n * Get the page index for `pagesDir`. Returns a cached value as long as\n * THAT directory's mtime hasn't advanced; otherwise rebuilds. Safe to\n * call concurrently — racing builds produce the same result.\n */\nexport async function getPageIndex(pagesDir: string): Promise<PageIndex> {\n const stat = await statSafeAsync(pagesDir);\n if (!stat) {\n // Dir doesn't exist yet (never ingested). Return empty but don't\n // cache a stale-forever value — the next call re-stats.\n return { mtimeMs: 0, slugs: new Map() };\n }\n const cached = cache.get(pagesDir);\n if (cached && cached.mtimeMs >= stat.mtimeMs) return cached;\n const entries = await readDirSafeAsync(pagesDir);\n const slugs = new Map<string, string>();\n for (const entry of entries) {\n if (!entry.isFile()) continue;\n const { name } = entry;\n if (!name.endsWith(\".md\")) continue;\n slugs.set(name.slice(0, -\".md\".length), name);\n }\n const built: PageIndex = { mtimeMs: stat.mtimeMs, slugs };\n cache.set(pagesDir, built);\n return built;\n}\n\n/** Test-only: drop the module-level cache (all directories). */\nexport function __resetPageIndexCache(): void {\n cache.clear();\n}\n","// Read-side frontmatter helpers for the wiki engine. The generic\n// `---\\n…\\n---\\n` envelope parsing is the canonical value-preserving\n// (FAILSAFE_SCHEMA) parser in `@mulmoclaude/markdown-utils`; only the\n// wiki-specific `tags:` reader stays here. Re-exporting `parseFrontmatter`\n// keeps the `@mulmoclaude/core/wiki/server` barrel surface stable — it now\n// returns the richer `{ meta, body, hasHeader }` shape.\n\nimport { parseFrontmatter } from \"@mulmoclaude/markdown-utils/markdown/frontmatter\";\n\nexport { parseFrontmatter };\n\nfunction cleanTagToken(token: string): string {\n return token\n .trim()\n .replace(/^['\"]|['\"]$/g, \"\")\n .replace(/^#/, \"\")\n .toLowerCase();\n}\n\n/** Narrow `tags:` reader. Handles flow (`tags: [a, b]`) and block-list\n * style; anything unparseable returns `[]` (best-effort, never throws). */\nexport function parseFrontmatterTags(content: string): string[] {\n const parsed = parseFrontmatter(content);\n if (!parsed.hasHeader) return [];\n const tagsValue = parsed.meta.tags;\n if (!Array.isArray(tagsValue)) return [];\n return tagsValue\n .filter((item): item is string => typeof item === \"string\")\n .map(cleanTagToken)\n .filter((token) => token.length > 0);\n}\n","// Workspace-injected wiki read-engine — the filesystem layer that feeds\n// the pure helpers in `@mulmoclaude/core/wiki`. Shared by every host so\n// the two apps reading the same `data/wiki/` can't disagree on slug\n// resolution, graph edges, or lint findings. Mirrors the bodies that\n// previously lived in MulmoClaude's `server/api/routes/wiki.ts`; the\n// hosts keep only their HTTP response shaping on top.\n//\n// The read/write WRITE side (writeWikiPage / snapshots) stays host-side\n// until a host needs it shared.\n\nimport path from \"node:path\";\nimport { parseWikiLink } from \"../link.js\";\nimport { wikiSlugify } from \"../slug.js\";\nimport { matchWikiSlug, slugByIndexTitle } from \"../resolve.js\";\nimport { type WikiPageEntry, parseIndexEntries } from \"../index-parse.js\";\nimport { findBrokenLinksInPage, findMissingFiles, findOrphanPages, findTagDrift } from \"../lint.js\";\nimport { type WikiGraph, buildWikiGraph } from \"../graph.js\";\nimport { readTextSafe, readTextSafeSync } from \"./fs.js\";\nimport { getPageIndex } from \"./pageIndex.js\";\nimport { parseFrontmatterTags } from \"./frontmatter.js\";\nimport { wikiDirs } from \"./paths.js\";\n\n// Below this length the fuzzy `includes` step is skipped — CJK /\n// emoji-only / very-short page names slugify down to a short noise\n// tail that partial-matches almost anything; the index.md title-match\n// fallback still handles the legitimate non-ASCII case (#1194).\nconst MIN_FUZZY_SLUG_LEN = 6;\n\nfunction readFileOrEmpty(absPath: string): string {\n return readTextSafeSync(absPath) ?? \"\";\n}\n\n/** Walk every indexed slug for an `includes`-style match. Returns the\n * single best candidate, or null when the slug is too short OR several\n * candidates tie at the top score (ambiguous → defer to the caller's\n * title-match fallback). Score = min/max length, decoupled from Map\n * iteration order so resolution is deterministic across hosts. */\nexport function pickFuzzyMatch(slug: string, slugs: ReadonlyMap<string, string>): string | null {\n if (slug.length < MIN_FUZZY_SLUG_LEN) return null;\n let bestFile: string | null = null;\n let bestScore = 0;\n let bestIsTied = false;\n for (const [key, file] of slugs) {\n if (!slug.includes(key) && !key.includes(slug)) continue;\n const shorter = Math.min(slug.length, key.length);\n const longer = Math.max(slug.length, key.length);\n const score = shorter / longer;\n if (score > bestScore) {\n bestScore = score;\n bestFile = file;\n bestIsTied = false;\n } else if (score === bestScore) {\n bestIsTied = true;\n }\n }\n return bestIsTied ? null : bestFile;\n}\n\n/** File matching an index.md entry whose title equals `target` — the\n * last resort for a link written as the display title rather than\n * the page's own name. */\nfunction fileByIndexTitle(indexFile: string, target: string, slugs: ReadonlyMap<string, string>): string | undefined {\n const entries = parseIndexEntries(readFileOrEmpty(indexFile));\n const trimmed = target.trim();\n const titleMatch = entries.find((entry) => entry.title === trimmed);\n return titleMatch ? slugs.get(titleMatch.slug) : undefined;\n}\n\n/** Resolve a page name to an absolute `.md` path: known slug (literal\n * or slugified) → fuzzy → index-title fallback. `pageName` may carry\n * the `[[target|display]]` form; `parseWikiLink` strips the display\n * half so the lookup uses just the target. */\nexport async function resolvePagePath(workspace: string, pageName: string): Promise<string | null> {\n const { pagesDir, indexFile } = wikiDirs(workspace);\n const { slugs } = await getPageIndex(pagesDir);\n if (slugs.size === 0) return null;\n\n const { target } = parseWikiLink(pageName);\n const matched = matchWikiSlug(target, slugs);\n const matchedFile = matched === null ? undefined : slugs.get(matched);\n if (matchedFile) return path.join(pagesDir, matchedFile);\n\n const fuzzy = pickFuzzyMatch(wikiSlugify(target), slugs);\n if (fuzzy) return path.join(pagesDir, fuzzy);\n\n const titleFile = fileByIndexTitle(indexFile, target, slugs);\n return titleFile ? path.join(pagesDir, titleFile) : null;\n}\n\n/** Raw `index.md` content + its parsed entries. */\nexport function readWikiIndex(workspace: string): { content: string; entries: WikiPageEntry[] } {\n const content = readFileOrEmpty(wikiDirs(workspace).indexFile);\n return { content, entries: parseIndexEntries(content) };\n}\n\n/** Raw `log.md` content (empty string if absent). */\nexport function readWikiLog(workspace: string): string {\n return readFileOrEmpty(wikiDirs(workspace).logFile);\n}\n\nexport interface WikiPageRead {\n /** Absolute path of the resolved file, or null when nothing matched. */\n filePath: string | null;\n /** File body (empty when missing OR when the file is an empty placeholder). */\n content: string;\n /** True iff a page file resolved (distinct from empty content). */\n exists: boolean;\n /** Title to display — the resolved filename stem, or the raw pageName. */\n resolvedTitle: string;\n}\n\n/** Resolve + read a page. Distinguishes missing (`exists: false`) from\n * empty-but-present (`exists: true`, `content: \"\"`). */\nexport async function readWikiPage(workspace: string, pageName: string): Promise<WikiPageRead> {\n const filePath = await resolvePagePath(workspace, pageName);\n const content = filePath ? readFileOrEmpty(filePath) : \"\";\n const resolvedTitle = filePath ? path.basename(filePath, \".md\") : pageName;\n return { filePath, content, exists: Boolean(filePath), resolvedTitle };\n}\n\n/** Page body, or \"\" when the file vanished between indexing and reading. */\nasync function readPageBody(pagesDir: string, fileName: string): Promise<string> {\n return (await readTextSafe(path.join(pagesDir, fileName))) ?? \"\";\n}\n\n/** Read every page + the index and build the page→page link graph.\n * No cache: the graph is requested explicitly and a content edit does\n * not advance the pagesDir mtime the page index caches on. */\nexport async function loadWikiGraph(workspace: string): Promise<WikiGraph> {\n const { pagesDir, indexFile } = wikiDirs(workspace);\n const { slugs } = await getPageIndex(pagesDir);\n const pages = await Promise.all([...slugs.entries()].map(async ([slug, fileName]) => ({ slug, content: await readPageBody(pagesDir, fileName) })));\n const indexEntries = parseIndexEntries(readFileOrEmpty(indexFile));\n return buildWikiGraph(pages, indexEntries);\n}\n\nexport interface PageBody {\n fileName: string;\n content: string;\n}\n\nasync function readPageBodies(pagesDir: string, fileNames: readonly string[]): Promise<PageBody[]> {\n return Promise.all(fileNames.map(async (fileName) => ({ fileName, content: await readPageBody(pagesDir, fileName) })));\n}\n\n/** Frontmatter `tags:` per page, keyed for `findTagDrift`. Lowercased so\n * a `MyPage.md` filename matches an `entry.slug` of `mypage`, which is\n * what the drift rule looks up. */\nexport function frontmatterTagIndex(bodies: readonly PageBody[]): Map<string, string[]> {\n const tagsBySlug = new Map<string, string[]>();\n bodies.forEach(({ fileName, content }) => {\n tagsBySlug.set(fileName.replace(/\\.md$/i, \"\").toLowerCase(), parseFrontmatterTags(content));\n });\n return tagsBySlug;\n}\n\n/** Run every lint rule over the on-disk wiki, returning issue strings. */\nexport async function collectLintIssues(workspace: string): Promise<string[]> {\n const { pagesDir, indexFile } = wikiDirs(workspace);\n const { slugs } = await getPageIndex(pagesDir);\n if (slugs.size === 0) {\n return [\"- Wiki `pages/` directory does not exist yet. Start ingesting sources.\"];\n }\n const pageEntries = parseIndexEntries(readFileOrEmpty(indexFile));\n const fileSlugs = new Set(slugs.keys());\n const slugByTitle = slugByIndexTitle(pageEntries);\n const bodies = await readPageBodies(pagesDir, [...slugs.values()]);\n return [\n ...findOrphanPages(fileSlugs, new Set(pageEntries.map((entry) => entry.slug))),\n ...findMissingFiles(pageEntries, fileSlugs),\n ...bodies.flatMap(({ fileName, content }) => findBrokenLinksInPage(fileName, content, fileSlugs, slugByTitle)),\n ...findTagDrift(pageEntries, frontmatterTagIndex(bodies)),\n ];\n}\n"],"mappings":";;;;;;;;;;;AAUA,eAAsB,aAAa,SAAyC;CAC1E,IAAI;EACF,OAAO,OAAA,GAAMA,iBAAAA,SAAAA,CAAS,SAAS,OAAO;CACxC,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAgB,iBAAiB,SAAgC;CAC/D,IAAI;EACF,QAAA,GAAOC,QAAAA,aAAAA,CAAa,SAAS,OAAO;CACtC,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAsB,cAAc,SAAwC;CAC1E,IAAI;EACF,OAAO,OAAA,GAAMC,iBAAAA,KAAAA,CAAK,OAAO;CAC3B,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAsB,iBAAiB,SAAoC;CACzE,IAAI;EACF,OAAO,OAAA,GAAMC,iBAAAA,QAAAA,CAAQ,SAAS,EAAE,eAAe,KAAK,C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,WAAmD;CACjG,OAAO,QAAQ,IAAI,UAAU,IAAI,OAAO,cAAc;EAAE;EAAU,SAAS,MAAM,aAAa,UAAU,QAAQ;CAAE,EAAE,CAAC;AACvH;;;;AAKA,SAAgB,oBAAoB,QAAoD;CACtF,MAAM,6BAAa,IAAI,IAAsB;CAC7C,OAAO,SAAS,EAAE,UAAU,cAAc;EACxC,WAAW,IAAI,SAAS,QAAQ,UAAU,EAAE,CAAC,CAAC,YAAY,GAAG,qBAAqB,OAAO,CAAC;CAC5F,CAAC;CACD,OAAO;AACT;;AAGA,eAAsB,kBAAkB,WAAsC;CAC5E,MAAM,EAAE,UAAU,cAAcL,mBAAAA,SAAS,SAAS;CAClD,MAAM,EAAE,UAAU,MAAM,aAAa,QAAQ;CAC7C,IAAI,MAAM,SAAS,GACjB,OAAO,CAAC,wEAAwE;CAElF,MAAM,cAAcD,cAAAA,kBAAkB,gBAAgB,SAAS,CAAC;CAChE,MAAM,YAAY,IAAI,IAAI,MAAM,KAAK,CAAC;CACtC,MAAM,cAAcO,cAAAA,iBAAiB,WAAW;CAChD,MAAM,SAAS,MAAM,eAAe,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC;CACjE,OAAO;EACL,GAAGC,cAAAA,gBAAgB,WAAW,IAAI,IAAI,YAAY,KAAK,UAAU,MAAM,IAAI,CAAC,CAAC;EAC7E,GAAGC,cAAAA,iBAAiB,aAAa,SAAS;EAC1C,GAAG,OAAO,SAAS,EAAE,UAAU,cAAcC,cAAAA,sBAAsB,UAAU,SAAS,WAAW,WAAW,CAAC;EAC7G,GAAGC,cAAAA,aAAa,aAAa,oBAAoB,MAAM,CAAC;CAC1D;AACF"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["stat","readdir","parseFrontmatter","wikiDirs","realpathSyncOrNull","path","isWithinRoot","readTextWithinRootSync","parseIndexEntries","path","parseWikiLink","matchWikiSlug","wikiSlugify","readTextWithinRoot","buildWikiGraph","slugByIndexTitle","findOrphanPages","findMissingFiles","findBrokenLinksInPage","findTagDrift"],"sources":["../../../src/wiki/server/fs.ts","../../../src/wiki/server/pageIndex.ts","../../../src/wiki/server/frontmatter.ts","../../../src/wiki/server/locations.ts","../../../src/wiki/server/engine.ts"],"sourcesContent":["// Minimal ENOENT-swallowing fs wrappers for the wiki read-engine.\n// Self-contained (core can't reach the host's `server/utils/files/safe.ts`);\n// only the handful of helpers the wiki engine needs. Same \"return\n// null / [] on any error\" contract so callers branch on the value\n// instead of try/catch.\n\nimport type { Dirent, Stats } from \"node:fs\";\nimport { readdir, stat } from \"node:fs/promises\";\n\nexport async function statSafeAsync(absPath: string): Promise<Stats | null> {\n try {\n return await stat(absPath);\n } catch {\n return null;\n }\n}\n\nexport async function readDirSafeAsync(absPath: string): Promise<Dirent[]> {\n try {\n return await readdir(absPath, { withFileTypes: true });\n } catch {\n return [];\n }\n}\n","// In-memory index of `<pagesDir>/*.md` keyed by slug (= filename\n// without the `.md` extension). Kept fresh via `pagesDir` mtime —\n// adding, removing, or renaming a file under `pagesDir` advances the\n// directory's mtime on every major filesystem we target (macOS APFS,\n// Linux ext4, Windows NTFS), so one cheap `stat()` per request is\n// enough to decide whether to rebuild.\n\nimport { readDirSafeAsync, statSafeAsync } from \"./fs.js\";\n\nexport interface PageIndex {\n mtimeMs: number;\n /** slug → filename (e.g. \"sakura-internet\" → \"sakura-internet.md\"). */\n slugs: Map<string, string>;\n}\n\n// Keyed by `pagesDir`: the engine is workspace-injected and may be\n// called with more than one pages directory in a single process. A\n// single global slot would let one workspace's slug map be returned\n// for another whenever their mtimes happen to tie (Codex P2 on #1876).\nconst cache = new Map<string, PageIndex>();\n\n/**\n * Get the page index for `pagesDir`. Returns a cached value as long as\n * THAT directory's mtime hasn't advanced; otherwise rebuilds. Safe to\n * call concurrently — racing builds produce the same result.\n */\nexport async function getPageIndex(pagesDir: string): Promise<PageIndex> {\n const stat = await statSafeAsync(pagesDir);\n if (!stat) {\n // Dir doesn't exist yet (never ingested). Return empty but don't\n // cache a stale-forever value — the next call re-stats.\n return { mtimeMs: 0, slugs: new Map() };\n }\n const cached = cache.get(pagesDir);\n if (cached && cached.mtimeMs >= stat.mtimeMs) return cached;\n const entries = await readDirSafeAsync(pagesDir);\n const slugs = new Map<string, string>();\n for (const entry of entries) {\n if (!entry.isFile()) continue;\n const { name } = entry;\n if (!name.endsWith(\".md\")) continue;\n slugs.set(name.slice(0, -\".md\".length), name);\n }\n const built: PageIndex = { mtimeMs: stat.mtimeMs, slugs };\n cache.set(pagesDir, built);\n return built;\n}\n\n/** Test-only: drop the module-level cache (all directories). */\nexport function __resetPageIndexCache(): void {\n cache.clear();\n}\n","// Read-side frontmatter helpers for the wiki engine. The generic\n// `---\\n…\\n---\\n` envelope parsing is the canonical value-preserving\n// (FAILSAFE_SCHEMA) parser in `@mulmoclaude/markdown-utils`; only the\n// wiki-specific `tags:` reader stays here. Re-exporting `parseFrontmatter`\n// keeps the `@mulmoclaude/core/wiki/server` barrel surface stable — it now\n// returns the richer `{ meta, body, hasHeader }` shape.\n\nimport { parseFrontmatter } from \"@mulmoclaude/markdown-utils/markdown/frontmatter\";\n\nexport { parseFrontmatter };\n\nfunction cleanTagToken(token: string): string {\n return token\n .trim()\n .replace(/^['\"]|['\"]$/g, \"\")\n .replace(/^#/, \"\")\n .toLowerCase();\n}\n\n/** Narrow `tags:` reader. Handles flow (`tags: [a, b]`) and block-list\n * style; anything unparseable returns `[]` (best-effort, never throws). */\nexport function parseFrontmatterTags(content: string): string[] {\n const parsed = parseFrontmatter(content);\n if (!parsed.hasHeader) return [];\n const tagsValue = parsed.meta.tags;\n if (!Array.isArray(tagsValue)) return [];\n return tagsValue\n .filter((item): item is string => typeof item === \"string\")\n .map(cleanTagToken)\n .filter((token) => token.length > 0);\n}\n","// A wiki folder or file that leads out of the workspace counts as absent, so nothing outside is listed or read.\n\nimport path from \"node:path\";\nimport { isWithinRoot, realpathSyncOrNull } from \"../../files/withinRoot.js\";\nimport { wikiDirs } from \"./paths.js\";\n\nexport interface WikiReadLocations {\n /** `<workspace>/data/wiki/pages` as the caller spelled it: resolved page paths handed back are joined onto this. */\n pagesDir: string;\n /** The workspace's realpath: every read re-checks against it after opening. */\n workspaceReal: string | null;\n pagesReal: string | null;\n indexReal: string | null;\n logReal: string | null;\n}\n\nexport function wikiReadLocations(workspace: string): WikiReadLocations {\n const dirs = wikiDirs(workspace);\n const workspaceReal = realpathSyncOrNull(workspace);\n const insideWorkspace = (absPath: string): string | null => {\n const candidateReal = workspaceReal === null ? null : realpathSyncOrNull(path.resolve(workspaceReal, path.relative(workspace, absPath)));\n return workspaceReal !== null && candidateReal !== null && isWithinRoot(workspaceReal, candidateReal) ? candidateReal : null;\n };\n return {\n pagesDir: dirs.pagesDir,\n workspaceReal,\n pagesReal: insideWorkspace(dirs.pagesDir),\n indexReal: insideWorkspace(dirs.indexFile),\n logReal: insideWorkspace(dirs.logFile),\n };\n}\n","// Workspace-injected wiki read-engine — the filesystem layer that feeds\n// the pure helpers in `@mulmoclaude/core/wiki`. Shared by every host so\n// the two apps reading the same `data/wiki/` can't disagree on slug\n// resolution, graph edges, or lint findings. Mirrors the bodies that\n// previously lived in MulmoClaude's `server/api/routes/wiki.ts`; the\n// hosts keep only their HTTP response shaping on top.\n//\n// The read/write WRITE side (writeWikiPage / snapshots) stays host-side\n// until a host needs it shared.\n\nimport path from \"node:path\";\nimport { parseWikiLink } from \"../link.js\";\nimport { wikiSlugify } from \"../slug.js\";\nimport { matchWikiSlug, slugByIndexTitle } from \"../resolve.js\";\nimport { type WikiPageEntry, parseIndexEntries } from \"../index-parse.js\";\nimport { findBrokenLinksInPage, findMissingFiles, findOrphanPages, findTagDrift } from \"../lint.js\";\nimport { type WikiGraph, buildWikiGraph } from \"../graph.js\";\nimport { readTextWithinRoot, readTextWithinRootSync } from \"../../files/withinRoot.js\";\nimport { getPageIndex } from \"./pageIndex.js\";\nimport { parseFrontmatterTags } from \"./frontmatter.js\";\nimport { type WikiReadLocations, wikiReadLocations } from \"./locations.js\";\n\n// Below this length the fuzzy `includes` step is skipped — CJK /\n// emoji-only / very-short page names slugify down to a short noise\n// tail that partial-matches almost anything; the index.md title-match\n// fallback still handles the legitimate non-ASCII case (#1194).\nconst MIN_FUZZY_SLUG_LEN = 6;\n\nfunction readFileOrEmpty(absPath: string | null, workspaceReal: string | null): string {\n return absPath === null || workspaceReal === null ? \"\" : (readTextWithinRootSync(workspaceReal, absPath) ?? \"\");\n}\n\nasync function pageSlugs(locations: WikiReadLocations): Promise<Map<string, string>> {\n return locations.pagesReal === null ? new Map() : (await getPageIndex(locations.pagesReal)).slugs;\n}\n\n/** Walk every indexed slug for an `includes`-style match. Returns the\n * single best candidate, or null when the slug is too short OR several\n * candidates tie at the top score (ambiguous → defer to the caller's\n * title-match fallback). Score = min/max length, decoupled from Map\n * iteration order so resolution is deterministic across hosts. */\nexport function pickFuzzyMatch(slug: string, slugs: ReadonlyMap<string, string>): string | null {\n if (slug.length < MIN_FUZZY_SLUG_LEN) return null;\n let bestFile: string | null = null;\n let bestScore = 0;\n let bestIsTied = false;\n for (const [key, file] of slugs) {\n if (!slug.includes(key) && !key.includes(slug)) continue;\n const shorter = Math.min(slug.length, key.length);\n const longer = Math.max(slug.length, key.length);\n const score = shorter / longer;\n if (score > bestScore) {\n bestScore = score;\n bestFile = file;\n bestIsTied = false;\n } else if (score === bestScore) {\n bestIsTied = true;\n }\n }\n return bestIsTied ? null : bestFile;\n}\n\n/** File matching an index.md entry whose title equals `target` — the\n * last resort for a link written as the display title rather than\n * the page's own name. */\nfunction fileByIndexTitle(locations: WikiReadLocations, target: string, slugs: ReadonlyMap<string, string>): string | undefined {\n const entries = parseIndexEntries(readFileOrEmpty(locations.indexReal, locations.workspaceReal));\n const trimmed = target.trim();\n const titleMatch = entries.find((entry) => entry.title === trimmed);\n return titleMatch ? slugs.get(titleMatch.slug) : undefined;\n}\n\n/** Resolve a page name to an absolute `.md` path: known slug (literal\n * or slugified) → fuzzy → index-title fallback. `pageName` may carry\n * the `[[target|display]]` form; `parseWikiLink` strips the display\n * half so the lookup uses just the target. */\nexport async function resolvePagePath(workspace: string, pageName: string): Promise<string | null> {\n const locations = wikiReadLocations(workspace);\n const fileName = await resolvePageFile(locations, pageName);\n return fileName === null ? null : path.join(locations.pagesDir, fileName);\n}\n\nasync function resolvePageFile(locations: WikiReadLocations, pageName: string): Promise<string | null> {\n const slugs = await pageSlugs(locations);\n if (slugs.size === 0) return null;\n\n const { target } = parseWikiLink(pageName);\n const matched = matchWikiSlug(target, slugs);\n const matchedFile = matched === null ? undefined : slugs.get(matched);\n if (matchedFile) return matchedFile;\n\n const fuzzy = pickFuzzyMatch(wikiSlugify(target), slugs);\n if (fuzzy) return fuzzy;\n\n return fileByIndexTitle(locations, target, slugs) ?? null;\n}\n\n/** Raw `index.md` content + its parsed entries. */\nexport function readWikiIndex(workspace: string): { content: string; entries: WikiPageEntry[] } {\n const locations = wikiReadLocations(workspace);\n const content = readFileOrEmpty(locations.indexReal, locations.workspaceReal);\n return { content, entries: parseIndexEntries(content) };\n}\n\n/** Raw `log.md` content (empty string if absent). */\nexport function readWikiLog(workspace: string): string {\n const locations = wikiReadLocations(workspace);\n return readFileOrEmpty(locations.logReal, locations.workspaceReal);\n}\n\nexport interface WikiPageRead {\n /** Absolute path of the resolved file, or null when nothing matched. */\n filePath: string | null;\n /** File body (empty when missing OR when the file is an empty placeholder). */\n content: string;\n /** True iff a page file resolved (distinct from empty content). */\n exists: boolean;\n /** Title to display — the resolved filename stem, or the raw pageName. */\n resolvedTitle: string;\n}\n\n/** Resolve + read a page. Distinguishes missing (`exists: false`) from\n * empty-but-present (`exists: true`, `content: \"\"`). */\nexport async function readWikiPage(workspace: string, pageName: string): Promise<WikiPageRead> {\n const locations = wikiReadLocations(workspace);\n const fileName = await resolvePageFile(locations, pageName);\n if (fileName === null || locations.pagesReal === null) return { filePath: null, content: \"\", exists: false, resolvedTitle: pageName };\n const content = readFileOrEmpty(path.join(locations.pagesReal, fileName), locations.workspaceReal);\n return { filePath: path.join(locations.pagesDir, fileName), content, exists: true, resolvedTitle: path.basename(fileName, \".md\") };\n}\n\n/** Page body, or \"\" when the file vanished between indexing and reading. */\nasync function readPageBody(locations: WikiReadLocations, fileName: string): Promise<string> {\n const { pagesReal, workspaceReal } = locations;\n return pagesReal === null || workspaceReal === null ? \"\" : ((await readTextWithinRoot(workspaceReal, path.join(pagesReal, fileName))) ?? \"\");\n}\n\n/** Read every page + the index and build the page→page link graph.\n * No cache: the graph is requested explicitly and a content edit does\n * not advance the pagesDir mtime the page index caches on. */\nexport async function loadWikiGraph(workspace: string): Promise<WikiGraph> {\n const locations = wikiReadLocations(workspace);\n const slugs = await pageSlugs(locations);\n const pages = await Promise.all([...slugs.entries()].map(async ([slug, fileName]) => ({ slug, content: await readPageBody(locations, fileName) })));\n const indexEntries = parseIndexEntries(readFileOrEmpty(locations.indexReal, locations.workspaceReal));\n return buildWikiGraph(pages, indexEntries);\n}\n\nexport interface PageBody {\n fileName: string;\n content: string;\n}\n\nasync function readPageBodies(locations: WikiReadLocations, fileNames: readonly string[]): Promise<PageBody[]> {\n return Promise.all(fileNames.map(async (fileName) => ({ fileName, content: await readPageBody(locations, fileName) })));\n}\n\n/** Frontmatter `tags:` per page, keyed for `findTagDrift`. Lowercased so\n * a `MyPage.md` filename matches an `entry.slug` of `mypage`, which is\n * what the drift rule looks up. */\nexport function frontmatterTagIndex(bodies: readonly PageBody[]): Map<string, string[]> {\n const tagsBySlug = new Map<string, string[]>();\n bodies.forEach(({ fileName, content }) => {\n tagsBySlug.set(fileName.replace(/\\.md$/i, \"\").toLowerCase(), parseFrontmatterTags(content));\n });\n return tagsBySlug;\n}\n\n/** Run every lint rule over the on-disk wiki, returning issue strings. */\nexport async function collectLintIssues(workspace: string): Promise<string[]> {\n const locations = wikiReadLocations(workspace);\n const slugs = await pageSlugs(locations);\n if (slugs.size === 0 || locations.pagesReal === null) {\n return [\"- Wiki `pages/` directory does not exist yet. Start ingesting sources.\"];\n }\n const pageEntries = parseIndexEntries(readFileOrEmpty(locations.indexReal, locations.workspaceReal));\n const fileSlugs = new Set(slugs.keys());\n const slugByTitle = slugByIndexTitle(pageEntries);\n const bodies = await readPageBodies(locations, [...slugs.values()]);\n return [\n ...findOrphanPages(fileSlugs, new Set(pageEntries.map((entry) => entry.slug))),\n ...findMissingFiles(pageEntries, fileSlugs),\n ...bodies.flatMap(({ fileName, content }) => findBrokenLinksInPage(fileName, content, fileSlugs, slugByTitle)),\n ...findTagDrift(pageEntries, frontmatterTagIndex(bodies)),\n ];\n}\n"],"mappings":";;;;;;;;;;;AASA,eAAsB,cAAc,SAAwC;CAC1E,IAAI;EACF,OAAO,OAAA,GAAMA,iBAAAA,KAAAA,CAAK,OAAO;CAC3B,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAsB,iBAAiB,SAAoC;CACzE,IAAI;EACF,OAAO,OAAA,GAAMC,iBAAAA,QAAAA,CAAQ,SAAS,EAAE,eAAe,KAAK,CAAC;CACvD,QAAQ;EACN,OAAO,CAAC;CACV;AACF;;ACJA,IAAM,wBAAQ,IAAI,IAAuB;;;;;;AAOzC,eAAsB,aAAa,UAAsC;CACvE,MAAM,OAAO,MAAM,cAAc,QAAQ;CACzC,IAAI,CAAC,MAGH,OAAO;EAAE,SAAS;EAAG,uBAAO,IAAI,IAAI;CAAE;CAExC,MAAM,SAAS,MAAM,IAAI,QAAQ;CACjC,IAAI,UAAU,OAAO,WAAW,KAAK,SAAS,OAAO;CACrD,MAAM,UAAU,MAAM,iBAAiB,QAAQ;CAC/C,MAAM,wBAAQ,IAAI,IAAoB;CACtC,KAAK,MAAM,SAAS,SAAS;EAC3B,IAAI,CAAC,MAAM,OAAO,GAAG;EACrB,MAAM,EAAE,SAAS;EACjB,IAAI,CAAC,KAAK,SAAS,KAAK,GAAG;EAC3B,MAAM,IAAI,KAAK,MAAM,GAAG,EAAa,GAAG,IAAI;CAC9C;CACA,MAAM,QAAmB;EAAE,SAAS,KAAK;EAAS;CAAM;CACxD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,GAAGC,cAAAA,iBAAiB,aAAa,SAAS;EAC1C,GAAG,OAAO,SAAS,EAAE,UAAU,cAAcC,cAAAA,sBAAsB,UAAU,SAAS,WAAW,WAAW,CAAC;EAC7G,GAAGC,cAAAA,aAAa,aAAa,oBAAoB,MAAM,CAAC;CAC1D;AACF"}
|
|
@@ -1,25 +1,11 @@
|
|
|
1
|
+
import { wikiDirs, wikiSlugFromAbsPath } from "../paths.js";
|
|
1
2
|
import { a as findMissingFiles, b as parseWikiLink, g as matchWikiSlug, i as findBrokenLinksInPage, m as parseIndexEntries, o as findOrphanPages, s as findTagDrift, t as buildWikiGraph, v as slugByIndexTitle } from "../../graph-DBbzemby.js";
|
|
2
3
|
import { r as wikiSlugify } from "../../slug-D24AYqCZ.js";
|
|
3
|
-
import {
|
|
4
|
-
import { readFileSync } from "node:fs";
|
|
4
|
+
import { i as realpathSyncOrNull, n as readTextWithinRoot, r as readTextWithinRootSync, t as isWithinRoot } from "../../withinRoot-Bbj6E-Lf.js";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import {
|
|
6
|
+
import { readdir, stat } from "node:fs/promises";
|
|
7
7
|
import { parseFrontmatter } from "@mulmoclaude/markdown-utils/markdown/frontmatter";
|
|
8
8
|
// src/wiki/server/fs.ts
|
|
9
|
-
async function readTextSafe(absPath) {
|
|
10
|
-
try {
|
|
11
|
-
return await readFile(absPath, "utf-8");
|
|
12
|
-
} catch {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function readTextSafeSync(absPath) {
|
|
17
|
-
try {
|
|
18
|
-
return readFileSync(absPath, "utf-8");
|
|
19
|
-
} catch {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
9
|
async function statSafeAsync(absPath) {
|
|
24
10
|
try {
|
|
25
11
|
return await stat(absPath);
|
|
@@ -81,10 +67,29 @@ function parseFrontmatterTags(content) {
|
|
|
81
67
|
if (!Array.isArray(tagsValue)) return [];
|
|
82
68
|
return tagsValue.filter((item) => typeof item === "string").map(cleanTagToken).filter((token) => token.length > 0);
|
|
83
69
|
}
|
|
70
|
+
// src/wiki/server/locations.ts
|
|
71
|
+
function wikiReadLocations(workspace) {
|
|
72
|
+
const dirs = wikiDirs(workspace);
|
|
73
|
+
const workspaceReal = realpathSyncOrNull(workspace);
|
|
74
|
+
const insideWorkspace = (absPath) => {
|
|
75
|
+
const candidateReal = workspaceReal === null ? null : realpathSyncOrNull(path.resolve(workspaceReal, path.relative(workspace, absPath)));
|
|
76
|
+
return workspaceReal !== null && candidateReal !== null && isWithinRoot(workspaceReal, candidateReal) ? candidateReal : null;
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
pagesDir: dirs.pagesDir,
|
|
80
|
+
workspaceReal,
|
|
81
|
+
pagesReal: insideWorkspace(dirs.pagesDir),
|
|
82
|
+
indexReal: insideWorkspace(dirs.indexFile),
|
|
83
|
+
logReal: insideWorkspace(dirs.logFile)
|
|
84
|
+
};
|
|
85
|
+
}
|
|
84
86
|
// src/wiki/server/engine.ts
|
|
85
87
|
var MIN_FUZZY_SLUG_LEN = 6;
|
|
86
|
-
function readFileOrEmpty(absPath) {
|
|
87
|
-
return
|
|
88
|
+
function readFileOrEmpty(absPath, workspaceReal) {
|
|
89
|
+
return absPath === null || workspaceReal === null ? "" : readTextWithinRootSync(workspaceReal, absPath) ?? "";
|
|
90
|
+
}
|
|
91
|
+
async function pageSlugs(locations) {
|
|
92
|
+
return locations.pagesReal === null ? /* @__PURE__ */ new Map() : (await getPageIndex(locations.pagesReal)).slugs;
|
|
88
93
|
}
|
|
89
94
|
/** Walk every indexed slug for an `includes`-style match. Returns the
|
|
90
95
|
* single best candidate, or null when the slug is too short OR several
|
|
@@ -110,8 +115,8 @@ function pickFuzzyMatch(slug, slugs) {
|
|
|
110
115
|
/** File matching an index.md entry whose title equals `target` — the
|
|
111
116
|
* last resort for a link written as the display title rather than
|
|
112
117
|
* the page's own name. */
|
|
113
|
-
function fileByIndexTitle(
|
|
114
|
-
const entries = parseIndexEntries(readFileOrEmpty(
|
|
118
|
+
function fileByIndexTitle(locations, target, slugs) {
|
|
119
|
+
const entries = parseIndexEntries(readFileOrEmpty(locations.indexReal, locations.workspaceReal));
|
|
115
120
|
const trimmed = target.trim();
|
|
116
121
|
const titleMatch = entries.find((entry) => entry.title === trimmed);
|
|
117
122
|
return titleMatch ? slugs.get(titleMatch.slug) : void 0;
|
|
@@ -121,21 +126,25 @@ function fileByIndexTitle(indexFile, target, slugs) {
|
|
|
121
126
|
* the `[[target|display]]` form; `parseWikiLink` strips the display
|
|
122
127
|
* half so the lookup uses just the target. */
|
|
123
128
|
async function resolvePagePath(workspace, pageName) {
|
|
124
|
-
const
|
|
125
|
-
const
|
|
129
|
+
const locations = wikiReadLocations(workspace);
|
|
130
|
+
const fileName = await resolvePageFile(locations, pageName);
|
|
131
|
+
return fileName === null ? null : path.join(locations.pagesDir, fileName);
|
|
132
|
+
}
|
|
133
|
+
async function resolvePageFile(locations, pageName) {
|
|
134
|
+
const slugs = await pageSlugs(locations);
|
|
126
135
|
if (slugs.size === 0) return null;
|
|
127
136
|
const { target } = parseWikiLink(pageName);
|
|
128
137
|
const matched = matchWikiSlug(target, slugs);
|
|
129
138
|
const matchedFile = matched === null ? void 0 : slugs.get(matched);
|
|
130
|
-
if (matchedFile) return
|
|
139
|
+
if (matchedFile) return matchedFile;
|
|
131
140
|
const fuzzy = pickFuzzyMatch(wikiSlugify(target), slugs);
|
|
132
|
-
if (fuzzy) return
|
|
133
|
-
|
|
134
|
-
return titleFile ? path.join(pagesDir, titleFile) : null;
|
|
141
|
+
if (fuzzy) return fuzzy;
|
|
142
|
+
return fileByIndexTitle(locations, target, slugs) ?? null;
|
|
135
143
|
}
|
|
136
144
|
/** Raw `index.md` content + its parsed entries. */
|
|
137
145
|
function readWikiIndex(workspace) {
|
|
138
|
-
const
|
|
146
|
+
const locations = wikiReadLocations(workspace);
|
|
147
|
+
const content = readFileOrEmpty(locations.indexReal, locations.workspaceReal);
|
|
139
148
|
return {
|
|
140
149
|
content,
|
|
141
150
|
entries: parseIndexEntries(content)
|
|
@@ -143,42 +152,50 @@ function readWikiIndex(workspace) {
|
|
|
143
152
|
}
|
|
144
153
|
/** Raw `log.md` content (empty string if absent). */
|
|
145
154
|
function readWikiLog(workspace) {
|
|
146
|
-
|
|
155
|
+
const locations = wikiReadLocations(workspace);
|
|
156
|
+
return readFileOrEmpty(locations.logReal, locations.workspaceReal);
|
|
147
157
|
}
|
|
148
158
|
/** Resolve + read a page. Distinguishes missing (`exists: false`) from
|
|
149
159
|
* empty-but-present (`exists: true`, `content: ""`). */
|
|
150
160
|
async function readWikiPage(workspace, pageName) {
|
|
151
|
-
const
|
|
152
|
-
const
|
|
153
|
-
|
|
161
|
+
const locations = wikiReadLocations(workspace);
|
|
162
|
+
const fileName = await resolvePageFile(locations, pageName);
|
|
163
|
+
if (fileName === null || locations.pagesReal === null) return {
|
|
164
|
+
filePath: null,
|
|
165
|
+
content: "",
|
|
166
|
+
exists: false,
|
|
167
|
+
resolvedTitle: pageName
|
|
168
|
+
};
|
|
169
|
+
const content = readFileOrEmpty(path.join(locations.pagesReal, fileName), locations.workspaceReal);
|
|
154
170
|
return {
|
|
155
|
-
filePath,
|
|
171
|
+
filePath: path.join(locations.pagesDir, fileName),
|
|
156
172
|
content,
|
|
157
|
-
exists:
|
|
158
|
-
resolvedTitle
|
|
173
|
+
exists: true,
|
|
174
|
+
resolvedTitle: path.basename(fileName, ".md")
|
|
159
175
|
};
|
|
160
176
|
}
|
|
161
177
|
/** Page body, or "" when the file vanished between indexing and reading. */
|
|
162
|
-
async function readPageBody(
|
|
163
|
-
|
|
178
|
+
async function readPageBody(locations, fileName) {
|
|
179
|
+
const { pagesReal, workspaceReal } = locations;
|
|
180
|
+
return pagesReal === null || workspaceReal === null ? "" : await readTextWithinRoot(workspaceReal, path.join(pagesReal, fileName)) ?? "";
|
|
164
181
|
}
|
|
165
182
|
/** Read every page + the index and build the page→page link graph.
|
|
166
183
|
* No cache: the graph is requested explicitly and a content edit does
|
|
167
184
|
* not advance the pagesDir mtime the page index caches on. */
|
|
168
185
|
async function loadWikiGraph(workspace) {
|
|
169
|
-
const
|
|
170
|
-
const
|
|
186
|
+
const locations = wikiReadLocations(workspace);
|
|
187
|
+
const slugs = await pageSlugs(locations);
|
|
171
188
|
const pages = await Promise.all([...slugs.entries()].map(async ([slug, fileName]) => ({
|
|
172
189
|
slug,
|
|
173
|
-
content: await readPageBody(
|
|
190
|
+
content: await readPageBody(locations, fileName)
|
|
174
191
|
})));
|
|
175
|
-
const indexEntries = parseIndexEntries(readFileOrEmpty(
|
|
192
|
+
const indexEntries = parseIndexEntries(readFileOrEmpty(locations.indexReal, locations.workspaceReal));
|
|
176
193
|
return buildWikiGraph(pages, indexEntries);
|
|
177
194
|
}
|
|
178
|
-
async function readPageBodies(
|
|
195
|
+
async function readPageBodies(locations, fileNames) {
|
|
179
196
|
return Promise.all(fileNames.map(async (fileName) => ({
|
|
180
197
|
fileName,
|
|
181
|
-
content: await readPageBody(
|
|
198
|
+
content: await readPageBody(locations, fileName)
|
|
182
199
|
})));
|
|
183
200
|
}
|
|
184
201
|
/** Frontmatter `tags:` per page, keyed for `findTagDrift`. Lowercased so
|
|
@@ -193,13 +210,13 @@ function frontmatterTagIndex(bodies) {
|
|
|
193
210
|
}
|
|
194
211
|
/** Run every lint rule over the on-disk wiki, returning issue strings. */
|
|
195
212
|
async function collectLintIssues(workspace) {
|
|
196
|
-
const
|
|
197
|
-
const
|
|
198
|
-
if (slugs.size === 0) return ["- Wiki `pages/` directory does not exist yet. Start ingesting sources."];
|
|
199
|
-
const pageEntries = parseIndexEntries(readFileOrEmpty(
|
|
213
|
+
const locations = wikiReadLocations(workspace);
|
|
214
|
+
const slugs = await pageSlugs(locations);
|
|
215
|
+
if (slugs.size === 0 || locations.pagesReal === null) return ["- Wiki `pages/` directory does not exist yet. Start ingesting sources."];
|
|
216
|
+
const pageEntries = parseIndexEntries(readFileOrEmpty(locations.indexReal, locations.workspaceReal));
|
|
200
217
|
const fileSlugs = new Set(slugs.keys());
|
|
201
218
|
const slugByTitle = slugByIndexTitle(pageEntries);
|
|
202
|
-
const bodies = await readPageBodies(
|
|
219
|
+
const bodies = await readPageBodies(locations, [...slugs.values()]);
|
|
203
220
|
return [
|
|
204
221
|
...findOrphanPages(fileSlugs, new Set(pageEntries.map((entry) => entry.slug))),
|
|
205
222
|
...findMissingFiles(pageEntries, fileSlugs),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/wiki/server/fs.ts","../../../src/wiki/server/pageIndex.ts","../../../src/wiki/server/frontmatter.ts","../../../src/wiki/server/engine.ts"],"sourcesContent":["// Minimal ENOENT-swallowing fs wrappers for the wiki read-engine.\n// Self-contained (core can't reach the host's `server/utils/files/safe.ts`);\n// only the handful of helpers the wiki engine needs. Same \"return\n// null / [] on any error\" contract so callers branch on the value\n// instead of try/catch.\n\nimport type { Dirent, Stats } from \"node:fs\";\nimport { readFileSync } from \"node:fs\";\nimport { readFile, readdir, stat } from \"node:fs/promises\";\n\nexport async function readTextSafe(absPath: string): Promise<string | null> {\n try {\n return await readFile(absPath, \"utf-8\");\n } catch {\n return null;\n }\n}\n\nexport function readTextSafeSync(absPath: string): string | null {\n try {\n return readFileSync(absPath, \"utf-8\");\n } catch {\n return null;\n }\n}\n\nexport async function statSafeAsync(absPath: string): Promise<Stats | null> {\n try {\n return await stat(absPath);\n } catch {\n return null;\n }\n}\n\nexport async function readDirSafeAsync(absPath: string): Promise<Dirent[]> {\n try {\n return await readdir(absPath, { withFileTypes: true });\n } catch {\n return [];\n }\n}\n","// In-memory index of `<pagesDir>/*.md` keyed by slug (= filename\n// without the `.md` extension). Kept fresh via `pagesDir` mtime —\n// adding, removing, or renaming a file under `pagesDir` advances the\n// directory's mtime on every major filesystem we target (macOS APFS,\n// Linux ext4, Windows NTFS), so one cheap `stat()` per request is\n// enough to decide whether to rebuild.\n\nimport { readDirSafeAsync, statSafeAsync } from \"./fs.js\";\n\nexport interface PageIndex {\n mtimeMs: number;\n /** slug → filename (e.g. \"sakura-internet\" → \"sakura-internet.md\"). */\n slugs: Map<string, string>;\n}\n\n// Keyed by `pagesDir`: the engine is workspace-injected and may be\n// called with more than one pages directory in a single process. A\n// single global slot would let one workspace's slug map be returned\n// for another whenever their mtimes happen to tie (Codex P2 on #1876).\nconst cache = new Map<string, PageIndex>();\n\n/**\n * Get the page index for `pagesDir`. Returns a cached value as long as\n * THAT directory's mtime hasn't advanced; otherwise rebuilds. Safe to\n * call concurrently — racing builds produce the same result.\n */\nexport async function getPageIndex(pagesDir: string): Promise<PageIndex> {\n const stat = await statSafeAsync(pagesDir);\n if (!stat) {\n // Dir doesn't exist yet (never ingested). Return empty but don't\n // cache a stale-forever value — the next call re-stats.\n return { mtimeMs: 0, slugs: new Map() };\n }\n const cached = cache.get(pagesDir);\n if (cached && cached.mtimeMs >= stat.mtimeMs) return cached;\n const entries = await readDirSafeAsync(pagesDir);\n const slugs = new Map<string, string>();\n for (const entry of entries) {\n if (!entry.isFile()) continue;\n const { name } = entry;\n if (!name.endsWith(\".md\")) continue;\n slugs.set(name.slice(0, -\".md\".length), name);\n }\n const built: PageIndex = { mtimeMs: stat.mtimeMs, slugs };\n cache.set(pagesDir, built);\n return built;\n}\n\n/** Test-only: drop the module-level cache (all directories). */\nexport function __resetPageIndexCache(): void {\n cache.clear();\n}\n","// Read-side frontmatter helpers for the wiki engine. The generic\n// `---\\n…\\n---\\n` envelope parsing is the canonical value-preserving\n// (FAILSAFE_SCHEMA) parser in `@mulmoclaude/markdown-utils`; only the\n// wiki-specific `tags:` reader stays here. Re-exporting `parseFrontmatter`\n// keeps the `@mulmoclaude/core/wiki/server` barrel surface stable — it now\n// returns the richer `{ meta, body, hasHeader }` shape.\n\nimport { parseFrontmatter } from \"@mulmoclaude/markdown-utils/markdown/frontmatter\";\n\nexport { parseFrontmatter };\n\nfunction cleanTagToken(token: string): string {\n return token\n .trim()\n .replace(/^['\"]|['\"]$/g, \"\")\n .replace(/^#/, \"\")\n .toLowerCase();\n}\n\n/** Narrow `tags:` reader. Handles flow (`tags: [a, b]`) and block-list\n * style; anything unparseable returns `[]` (best-effort, never throws). */\nexport function parseFrontmatterTags(content: string): string[] {\n const parsed = parseFrontmatter(content);\n if (!parsed.hasHeader) return [];\n const tagsValue = parsed.meta.tags;\n if (!Array.isArray(tagsValue)) return [];\n return tagsValue\n .filter((item): item is string => typeof item === \"string\")\n .map(cleanTagToken)\n .filter((token) => token.length > 0);\n}\n","// Workspace-injected wiki read-engine — the filesystem layer that feeds\n// the pure helpers in `@mulmoclaude/core/wiki`. Shared by every host so\n// the two apps reading the same `data/wiki/` can't disagree on slug\n// resolution, graph edges, or lint findings. Mirrors the bodies that\n// previously lived in MulmoClaude's `server/api/routes/wiki.ts`; the\n// hosts keep only their HTTP response shaping on top.\n//\n// The read/write WRITE side (writeWikiPage / snapshots) stays host-side\n// until a host needs it shared.\n\nimport path from \"node:path\";\nimport { parseWikiLink } from \"../link.js\";\nimport { wikiSlugify } from \"../slug.js\";\nimport { matchWikiSlug, slugByIndexTitle } from \"../resolve.js\";\nimport { type WikiPageEntry, parseIndexEntries } from \"../index-parse.js\";\nimport { findBrokenLinksInPage, findMissingFiles, findOrphanPages, findTagDrift } from \"../lint.js\";\nimport { type WikiGraph, buildWikiGraph } from \"../graph.js\";\nimport { readTextSafe, readTextSafeSync } from \"./fs.js\";\nimport { getPageIndex } from \"./pageIndex.js\";\nimport { parseFrontmatterTags } from \"./frontmatter.js\";\nimport { wikiDirs } from \"./paths.js\";\n\n// Below this length the fuzzy `includes` step is skipped — CJK /\n// emoji-only / very-short page names slugify down to a short noise\n// tail that partial-matches almost anything; the index.md title-match\n// fallback still handles the legitimate non-ASCII case (#1194).\nconst MIN_FUZZY_SLUG_LEN = 6;\n\nfunction readFileOrEmpty(absPath: string): string {\n return readTextSafeSync(absPath) ?? \"\";\n}\n\n/** Walk every indexed slug for an `includes`-style match. Returns the\n * single best candidate, or null when the slug is too short OR several\n * candidates tie at the top score (ambiguous → defer to the caller's\n * title-match fallback). Score = min/max length, decoupled from Map\n * iteration order so resolution is deterministic across hosts. */\nexport function pickFuzzyMatch(slug: string, slugs: ReadonlyMap<string, string>): string | null {\n if (slug.length < MIN_FUZZY_SLUG_LEN) return null;\n let bestFile: string | null = null;\n let bestScore = 0;\n let bestIsTied = false;\n for (const [key, file] of slugs) {\n if (!slug.includes(key) && !key.includes(slug)) continue;\n const shorter = Math.min(slug.length, key.length);\n const longer = Math.max(slug.length, key.length);\n const score = shorter / longer;\n if (score > bestScore) {\n bestScore = score;\n bestFile = file;\n bestIsTied = false;\n } else if (score === bestScore) {\n bestIsTied = true;\n }\n }\n return bestIsTied ? null : bestFile;\n}\n\n/** File matching an index.md entry whose title equals `target` — the\n * last resort for a link written as the display title rather than\n * the page's own name. */\nfunction fileByIndexTitle(indexFile: string, target: string, slugs: ReadonlyMap<string, string>): string | undefined {\n const entries = parseIndexEntries(readFileOrEmpty(indexFile));\n const trimmed = target.trim();\n const titleMatch = entries.find((entry) => entry.title === trimmed);\n return titleMatch ? slugs.get(titleMatch.slug) : undefined;\n}\n\n/** Resolve a page name to an absolute `.md` path: known slug (literal\n * or slugified) → fuzzy → index-title fallback. `pageName` may carry\n * the `[[target|display]]` form; `parseWikiLink` strips the display\n * half so the lookup uses just the target. */\nexport async function resolvePagePath(workspace: string, pageName: string): Promise<string | null> {\n const { pagesDir, indexFile } = wikiDirs(workspace);\n const { slugs } = await getPageIndex(pagesDir);\n if (slugs.size === 0) return null;\n\n const { target } = parseWikiLink(pageName);\n const matched = matchWikiSlug(target, slugs);\n const matchedFile = matched === null ? undefined : slugs.get(matched);\n if (matchedFile) return path.join(pagesDir, matchedFile);\n\n const fuzzy = pickFuzzyMatch(wikiSlugify(target), slugs);\n if (fuzzy) return path.join(pagesDir, fuzzy);\n\n const titleFile = fileByIndexTitle(indexFile, target, slugs);\n return titleFile ? path.join(pagesDir, titleFile) : null;\n}\n\n/** Raw `index.md` content + its parsed entries. */\nexport function readWikiIndex(workspace: string): { content: string; entries: WikiPageEntry[] } {\n const content = readFileOrEmpty(wikiDirs(workspace).indexFile);\n return { content, entries: parseIndexEntries(content) };\n}\n\n/** Raw `log.md` content (empty string if absent). */\nexport function readWikiLog(workspace: string): string {\n return readFileOrEmpty(wikiDirs(workspace).logFile);\n}\n\nexport interface WikiPageRead {\n /** Absolute path of the resolved file, or null when nothing matched. */\n filePath: string | null;\n /** File body (empty when missing OR when the file is an empty placeholder). */\n content: string;\n /** True iff a page file resolved (distinct from empty content). */\n exists: boolean;\n /** Title to display — the resolved filename stem, or the raw pageName. */\n resolvedTitle: string;\n}\n\n/** Resolve + read a page. Distinguishes missing (`exists: false`) from\n * empty-but-present (`exists: true`, `content: \"\"`). */\nexport async function readWikiPage(workspace: string, pageName: string): Promise<WikiPageRead> {\n const filePath = await resolvePagePath(workspace, pageName);\n const content = filePath ? readFileOrEmpty(filePath) : \"\";\n const resolvedTitle = filePath ? path.basename(filePath, \".md\") : pageName;\n return { filePath, content, exists: Boolean(filePath), resolvedTitle };\n}\n\n/** Page body, or \"\" when the file vanished between indexing and reading. */\nasync function readPageBody(pagesDir: string, fileName: string): Promise<string> {\n return (await readTextSafe(path.join(pagesDir, fileName))) ?? \"\";\n}\n\n/** Read every page + the index and build the page→page link graph.\n * No cache: the graph is requested explicitly and a content edit does\n * not advance the pagesDir mtime the page index caches on. */\nexport async function loadWikiGraph(workspace: string): Promise<WikiGraph> {\n const { pagesDir, indexFile } = wikiDirs(workspace);\n const { slugs } = await getPageIndex(pagesDir);\n const pages = await Promise.all([...slugs.entries()].map(async ([slug, fileName]) => ({ slug, content: await readPageBody(pagesDir, fileName) })));\n const indexEntries = parseIndexEntries(readFileOrEmpty(indexFile));\n return buildWikiGraph(pages, indexEntries);\n}\n\nexport interface PageBody {\n fileName: string;\n content: string;\n}\n\nasync function readPageBodies(pagesDir: string, fileNames: readonly string[]): Promise<PageBody[]> {\n return Promise.all(fileNames.map(async (fileName) => ({ fileName, content: await readPageBody(pagesDir, fileName) })));\n}\n\n/** Frontmatter `tags:` per page, keyed for `findTagDrift`. Lowercased so\n * a `MyPage.md` filename matches an `entry.slug` of `mypage`, which is\n * what the drift rule looks up. */\nexport function frontmatterTagIndex(bodies: readonly PageBody[]): Map<string, string[]> {\n const tagsBySlug = new Map<string, string[]>();\n bodies.forEach(({ fileName, content }) => {\n tagsBySlug.set(fileName.replace(/\\.md$/i, \"\").toLowerCase(), parseFrontmatterTags(content));\n });\n return tagsBySlug;\n}\n\n/** Run every lint rule over the on-disk wiki, returning issue strings. */\nexport async function collectLintIssues(workspace: string): Promise<string[]> {\n const { pagesDir, indexFile } = wikiDirs(workspace);\n const { slugs } = await getPageIndex(pagesDir);\n if (slugs.size === 0) {\n return [\"- Wiki `pages/` directory does not exist yet. Start ingesting sources.\"];\n }\n const pageEntries = parseIndexEntries(readFileOrEmpty(indexFile));\n const fileSlugs = new Set(slugs.keys());\n const slugByTitle = slugByIndexTitle(pageEntries);\n const bodies = await readPageBodies(pagesDir, [...slugs.values()]);\n return [\n ...findOrphanPages(fileSlugs, new Set(pageEntries.map((entry) => entry.slug))),\n ...findMissingFiles(pageEntries, fileSlugs),\n ...bodies.flatMap(({ fileName, content }) => findBrokenLinksInPage(fileName, content, fileSlugs, slugByTitle)),\n ...findTagDrift(pageEntries, frontmatterTagIndex(bodies)),\n ];\n}\n"],"mappings":";;;;;;;;AAUA,eAAsB,aAAa,SAAyC;CAC1E,IAAI;EACF,OAAO,MAAM,SAAS,SAAS,OAAO;CACxC,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAgB,iBAAiB,SAAgC;CAC/D,IAAI;EACF,OAAO,aAAa,SAAS,OAAO;CACtC,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAsB,cAAc,SAAwC;CAC1E,IAAI;EACF,OAAO,MAAM,KAAK,OAAO;CAC3B,QAAQ;EACN,O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c;EAAE;EAAU,SAAS,MAAM,aAAa,UAAU,QAAQ;CAAE,EAAE,CAAC;AACvH;;;;AAKA,SAAgB,oBAAoB,QAAoD;CACtF,MAAM,6BAAa,IAAI,IAAsB;CAC7C,OAAO,SAAS,EAAE,UAAU,cAAc;EACxC,WAAW,IAAI,SAAS,QAAQ,UAAU,EAAE,CAAC,CAAC,YAAY,GAAG,qBAAqB,OAAO,CAAC;CAC5F,CAAC;CACD,OAAO;AACT;;AAGA,eAAsB,kBAAkB,WAAsC;CAC5E,MAAM,EAAE,UAAU,cAAc,SAAS,SAAS;CAClD,MAAM,EAAE,UAAU,MAAM,aAAa,QAAQ;CAC7C,IAAI,MAAM,SAAS,GACjB,OAAO,CAAC,wEAAwE;CAElF,MAAM,cAAc,kBAAkB,gBAAgB,SAAS,CAAC;CAChE,MAAM,YAAY,IAAI,IAAI,MAAM,KAAK,CAAC;CACtC,MAAM,cAAc,iBAAiB,WAAW;CAChD,MAAM,SAAS,MAAM,eAAe,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC;CACjE,OAAO;EACL,GAAG,gBAAgB,WAAW,IAAI,IAAI,YAAY,KAAK,UAAU,MAAM,IAAI,CAAC,CAAC;EAC7E,GAAG,iBAAiB,aAAa,SAAS;EAC1C,GAAG,OAAO,SAAS,EAAE,UAAU,cAAc,sBAAsB,UAAU,SAAS,WAAW,WAAW,CAAC;EAC7G,GAAG,aAAa,aAAa,oBAAoB,MAAM,CAAC;CAC1D;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/wiki/server/fs.ts","../../../src/wiki/server/pageIndex.ts","../../../src/wiki/server/frontmatter.ts","../../../src/wiki/server/locations.ts","../../../src/wiki/server/engine.ts"],"sourcesContent":["// Minimal ENOENT-swallowing fs wrappers for the wiki read-engine.\n// Self-contained (core can't reach the host's `server/utils/files/safe.ts`);\n// only the handful of helpers the wiki engine needs. Same \"return\n// null / [] on any error\" contract so callers branch on the value\n// instead of try/catch.\n\nimport type { Dirent, Stats } from \"node:fs\";\nimport { readdir, stat } from \"node:fs/promises\";\n\nexport async function statSafeAsync(absPath: string): Promise<Stats | null> {\n try {\n return await stat(absPath);\n } catch {\n return null;\n }\n}\n\nexport async function readDirSafeAsync(absPath: string): Promise<Dirent[]> {\n try {\n return await readdir(absPath, { withFileTypes: true });\n } catch {\n return [];\n }\n}\n","// In-memory index of `<pagesDir>/*.md` keyed by slug (= filename\n// without the `.md` extension). Kept fresh via `pagesDir` mtime —\n// adding, removing, or renaming a file under `pagesDir` advances the\n// directory's mtime on every major filesystem we target (macOS APFS,\n// Linux ext4, Windows NTFS), so one cheap `stat()` per request is\n// enough to decide whether to rebuild.\n\nimport { readDirSafeAsync, statSafeAsync } from \"./fs.js\";\n\nexport interface PageIndex {\n mtimeMs: number;\n /** slug → filename (e.g. \"sakura-internet\" → \"sakura-internet.md\"). */\n slugs: Map<string, string>;\n}\n\n// Keyed by `pagesDir`: the engine is workspace-injected and may be\n// called with more than one pages directory in a single process. A\n// single global slot would let one workspace's slug map be returned\n// for another whenever their mtimes happen to tie (Codex P2 on #1876).\nconst cache = new Map<string, PageIndex>();\n\n/**\n * Get the page index for `pagesDir`. Returns a cached value as long as\n * THAT directory's mtime hasn't advanced; otherwise rebuilds. Safe to\n * call concurrently — racing builds produce the same result.\n */\nexport async function getPageIndex(pagesDir: string): Promise<PageIndex> {\n const stat = await statSafeAsync(pagesDir);\n if (!stat) {\n // Dir doesn't exist yet (never ingested). Return empty but don't\n // cache a stale-forever value — the next call re-stats.\n return { mtimeMs: 0, slugs: new Map() };\n }\n const cached = cache.get(pagesDir);\n if (cached && cached.mtimeMs >= stat.mtimeMs) return cached;\n const entries = await readDirSafeAsync(pagesDir);\n const slugs = new Map<string, string>();\n for (const entry of entries) {\n if (!entry.isFile()) continue;\n const { name } = entry;\n if (!name.endsWith(\".md\")) continue;\n slugs.set(name.slice(0, -\".md\".length), name);\n }\n const built: PageIndex = { mtimeMs: stat.mtimeMs, slugs };\n cache.set(pagesDir, built);\n return built;\n}\n\n/** Test-only: drop the module-level cache (all directories). */\nexport function __resetPageIndexCache(): void {\n cache.clear();\n}\n","// Read-side frontmatter helpers for the wiki engine. The generic\n// `---\\n…\\n---\\n` envelope parsing is the canonical value-preserving\n// (FAILSAFE_SCHEMA) parser in `@mulmoclaude/markdown-utils`; only the\n// wiki-specific `tags:` reader stays here. Re-exporting `parseFrontmatter`\n// keeps the `@mulmoclaude/core/wiki/server` barrel surface stable — it now\n// returns the richer `{ meta, body, hasHeader }` shape.\n\nimport { parseFrontmatter } from \"@mulmoclaude/markdown-utils/markdown/frontmatter\";\n\nexport { parseFrontmatter };\n\nfunction cleanTagToken(token: string): string {\n return token\n .trim()\n .replace(/^['\"]|['\"]$/g, \"\")\n .replace(/^#/, \"\")\n .toLowerCase();\n}\n\n/** Narrow `tags:` reader. Handles flow (`tags: [a, b]`) and block-list\n * style; anything unparseable returns `[]` (best-effort, never throws). */\nexport function parseFrontmatterTags(content: string): string[] {\n const parsed = parseFrontmatter(content);\n if (!parsed.hasHeader) return [];\n const tagsValue = parsed.meta.tags;\n if (!Array.isArray(tagsValue)) return [];\n return tagsValue\n .filter((item): item is string => typeof item === \"string\")\n .map(cleanTagToken)\n .filter((token) => token.length > 0);\n}\n","// A wiki folder or file that leads out of the workspace counts as absent, so nothing outside is listed or read.\n\nimport path from \"node:path\";\nimport { isWithinRoot, realpathSyncOrNull } from \"../../files/withinRoot.js\";\nimport { wikiDirs } from \"./paths.js\";\n\nexport interface WikiReadLocations {\n /** `<workspace>/data/wiki/pages` as the caller spelled it: resolved page paths handed back are joined onto this. */\n pagesDir: string;\n /** The workspace's realpath: every read re-checks against it after opening. */\n workspaceReal: string | null;\n pagesReal: string | null;\n indexReal: string | null;\n logReal: string | null;\n}\n\nexport function wikiReadLocations(workspace: string): WikiReadLocations {\n const dirs = wikiDirs(workspace);\n const workspaceReal = realpathSyncOrNull(workspace);\n const insideWorkspace = (absPath: string): string | null => {\n const candidateReal = workspaceReal === null ? null : realpathSyncOrNull(path.resolve(workspaceReal, path.relative(workspace, absPath)));\n return workspaceReal !== null && candidateReal !== null && isWithinRoot(workspaceReal, candidateReal) ? candidateReal : null;\n };\n return {\n pagesDir: dirs.pagesDir,\n workspaceReal,\n pagesReal: insideWorkspace(dirs.pagesDir),\n indexReal: insideWorkspace(dirs.indexFile),\n logReal: insideWorkspace(dirs.logFile),\n };\n}\n","// Workspace-injected wiki read-engine — the filesystem layer that feeds\n// the pure helpers in `@mulmoclaude/core/wiki`. Shared by every host so\n// the two apps reading the same `data/wiki/` can't disagree on slug\n// resolution, graph edges, or lint findings. Mirrors the bodies that\n// previously lived in MulmoClaude's `server/api/routes/wiki.ts`; the\n// hosts keep only their HTTP response shaping on top.\n//\n// The read/write WRITE side (writeWikiPage / snapshots) stays host-side\n// until a host needs it shared.\n\nimport path from \"node:path\";\nimport { parseWikiLink } from \"../link.js\";\nimport { wikiSlugify } from \"../slug.js\";\nimport { matchWikiSlug, slugByIndexTitle } from \"../resolve.js\";\nimport { type WikiPageEntry, parseIndexEntries } from \"../index-parse.js\";\nimport { findBrokenLinksInPage, findMissingFiles, findOrphanPages, findTagDrift } from \"../lint.js\";\nimport { type WikiGraph, buildWikiGraph } from \"../graph.js\";\nimport { readTextWithinRoot, readTextWithinRootSync } from \"../../files/withinRoot.js\";\nimport { getPageIndex } from \"./pageIndex.js\";\nimport { parseFrontmatterTags } from \"./frontmatter.js\";\nimport { type WikiReadLocations, wikiReadLocations } from \"./locations.js\";\n\n// Below this length the fuzzy `includes` step is skipped — CJK /\n// emoji-only / very-short page names slugify down to a short noise\n// tail that partial-matches almost anything; the index.md title-match\n// fallback still handles the legitimate non-ASCII case (#1194).\nconst MIN_FUZZY_SLUG_LEN = 6;\n\nfunction readFileOrEmpty(absPath: string | null, workspaceReal: string | null): string {\n return absPath === null || workspaceReal === null ? \"\" : (readTextWithinRootSync(workspaceReal, absPath) ?? \"\");\n}\n\nasync function pageSlugs(locations: WikiReadLocations): Promise<Map<string, string>> {\n return locations.pagesReal === null ? new Map() : (await getPageIndex(locations.pagesReal)).slugs;\n}\n\n/** Walk every indexed slug for an `includes`-style match. Returns the\n * single best candidate, or null when the slug is too short OR several\n * candidates tie at the top score (ambiguous → defer to the caller's\n * title-match fallback). Score = min/max length, decoupled from Map\n * iteration order so resolution is deterministic across hosts. */\nexport function pickFuzzyMatch(slug: string, slugs: ReadonlyMap<string, string>): string | null {\n if (slug.length < MIN_FUZZY_SLUG_LEN) return null;\n let bestFile: string | null = null;\n let bestScore = 0;\n let bestIsTied = false;\n for (const [key, file] of slugs) {\n if (!slug.includes(key) && !key.includes(slug)) continue;\n const shorter = Math.min(slug.length, key.length);\n const longer = Math.max(slug.length, key.length);\n const score = shorter / longer;\n if (score > bestScore) {\n bestScore = score;\n bestFile = file;\n bestIsTied = false;\n } else if (score === bestScore) {\n bestIsTied = true;\n }\n }\n return bestIsTied ? null : bestFile;\n}\n\n/** File matching an index.md entry whose title equals `target` — the\n * last resort for a link written as the display title rather than\n * the page's own name. */\nfunction fileByIndexTitle(locations: WikiReadLocations, target: string, slugs: ReadonlyMap<string, string>): string | undefined {\n const entries = parseIndexEntries(readFileOrEmpty(locations.indexReal, locations.workspaceReal));\n const trimmed = target.trim();\n const titleMatch = entries.find((entry) => entry.title === trimmed);\n return titleMatch ? slugs.get(titleMatch.slug) : undefined;\n}\n\n/** Resolve a page name to an absolute `.md` path: known slug (literal\n * or slugified) → fuzzy → index-title fallback. `pageName` may carry\n * the `[[target|display]]` form; `parseWikiLink` strips the display\n * half so the lookup uses just the target. */\nexport async function resolvePagePath(workspace: string, pageName: string): Promise<string | null> {\n const locations = wikiReadLocations(workspace);\n const fileName = await resolvePageFile(locations, pageName);\n return fileName === null ? null : path.join(locations.pagesDir, fileName);\n}\n\nasync function resolvePageFile(locations: WikiReadLocations, pageName: string): Promise<string | null> {\n const slugs = await pageSlugs(locations);\n if (slugs.size === 0) return null;\n\n const { target } = parseWikiLink(pageName);\n const matched = matchWikiSlug(target, slugs);\n const matchedFile = matched === null ? undefined : slugs.get(matched);\n if (matchedFile) return matchedFile;\n\n const fuzzy = pickFuzzyMatch(wikiSlugify(target), slugs);\n if (fuzzy) return fuzzy;\n\n return fileByIndexTitle(locations, target, slugs) ?? null;\n}\n\n/** Raw `index.md` content + its parsed entries. */\nexport function readWikiIndex(workspace: string): { content: string; entries: WikiPageEntry[] } {\n const locations = wikiReadLocations(workspace);\n const content = readFileOrEmpty(locations.indexReal, locations.workspaceReal);\n return { content, entries: parseIndexEntries(content) };\n}\n\n/** Raw `log.md` content (empty string if absent). */\nexport function readWikiLog(workspace: string): string {\n const locations = wikiReadLocations(workspace);\n return readFileOrEmpty(locations.logReal, locations.workspaceReal);\n}\n\nexport interface WikiPageRead {\n /** Absolute path of the resolved file, or null when nothing matched. */\n filePath: string | null;\n /** File body (empty when missing OR when the file is an empty placeholder). */\n content: string;\n /** True iff a page file resolved (distinct from empty content). */\n exists: boolean;\n /** Title to display — the resolved filename stem, or the raw pageName. */\n resolvedTitle: string;\n}\n\n/** Resolve + read a page. Distinguishes missing (`exists: false`) from\n * empty-but-present (`exists: true`, `content: \"\"`). */\nexport async function readWikiPage(workspace: string, pageName: string): Promise<WikiPageRead> {\n const locations = wikiReadLocations(workspace);\n const fileName = await resolvePageFile(locations, pageName);\n if (fileName === null || locations.pagesReal === null) return { filePath: null, content: \"\", exists: false, resolvedTitle: pageName };\n const content = readFileOrEmpty(path.join(locations.pagesReal, fileName), locations.workspaceReal);\n return { filePath: path.join(locations.pagesDir, fileName), content, exists: true, resolvedTitle: path.basename(fileName, \".md\") };\n}\n\n/** Page body, or \"\" when the file vanished between indexing and reading. */\nasync function readPageBody(locations: WikiReadLocations, fileName: string): Promise<string> {\n const { pagesReal, workspaceReal } = locations;\n return pagesReal === null || workspaceReal === null ? \"\" : ((await readTextWithinRoot(workspaceReal, path.join(pagesReal, fileName))) ?? \"\");\n}\n\n/** Read every page + the index and build the page→page link graph.\n * No cache: the graph is requested explicitly and a content edit does\n * not advance the pagesDir mtime the page index caches on. */\nexport async function loadWikiGraph(workspace: string): Promise<WikiGraph> {\n const locations = wikiReadLocations(workspace);\n const slugs = await pageSlugs(locations);\n const pages = await Promise.all([...slugs.entries()].map(async ([slug, fileName]) => ({ slug, content: await readPageBody(locations, fileName) })));\n const indexEntries = parseIndexEntries(readFileOrEmpty(locations.indexReal, locations.workspaceReal));\n return buildWikiGraph(pages, indexEntries);\n}\n\nexport interface PageBody {\n fileName: string;\n content: string;\n}\n\nasync function readPageBodies(locations: WikiReadLocations, fileNames: readonly string[]): Promise<PageBody[]> {\n return Promise.all(fileNames.map(async (fileName) => ({ fileName, content: await readPageBody(locations, fileName) })));\n}\n\n/** Frontmatter `tags:` per page, keyed for `findTagDrift`. Lowercased so\n * a `MyPage.md` filename matches an `entry.slug` of `mypage`, which is\n * what the drift rule looks up. */\nexport function frontmatterTagIndex(bodies: readonly PageBody[]): Map<string, string[]> {\n const tagsBySlug = new Map<string, string[]>();\n bodies.forEach(({ fileName, content }) => {\n tagsBySlug.set(fileName.replace(/\\.md$/i, \"\").toLowerCase(), parseFrontmatterTags(content));\n });\n return tagsBySlug;\n}\n\n/** Run every lint rule over the on-disk wiki, returning issue strings. */\nexport async function collectLintIssues(workspace: string): Promise<string[]> {\n const locations = wikiReadLocations(workspace);\n const slugs = await pageSlugs(locations);\n if (slugs.size === 0 || locations.pagesReal === null) {\n return [\"- Wiki `pages/` directory does not exist yet. Start ingesting sources.\"];\n }\n const pageEntries = parseIndexEntries(readFileOrEmpty(locations.indexReal, locations.workspaceReal));\n const fileSlugs = new Set(slugs.keys());\n const slugByTitle = slugByIndexTitle(pageEntries);\n const bodies = await readPageBodies(locations, [...slugs.values()]);\n return [\n ...findOrphanPages(fileSlugs, new Set(pageEntries.map((entry) => entry.slug))),\n ...findMissingFiles(pageEntries, fileSlugs),\n ...bodies.flatMap(({ fileName, content }) => findBrokenLinksInPage(fileName, content, fileSlugs, slugByTitle)),\n ...findTagDrift(page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