@tokenroll/llmdoc 3.5.3 → 3.9.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.
Files changed (48) hide show
  1. package/assets/viewer-app.js +11 -11
  2. package/assets/viewer-detail.js +4 -4
  3. package/assets/viewer-graph.js +3 -3
  4. package/assets/viewer.html +19 -19
  5. package/dist/cli.js +147 -71
  6. package/dist/commands/adopt.js +10 -6
  7. package/dist/commands/commit.js +232 -80
  8. package/dist/commands/context.js +85 -45
  9. package/dist/commands/dream.js +608 -0
  10. package/dist/commands/eval.js +379 -0
  11. package/dist/commands/fingerprint.js +9 -3
  12. package/dist/commands/hook.js +135 -28
  13. package/dist/commands/index.js +52 -7
  14. package/dist/commands/init-state.js +5 -5
  15. package/dist/commands/mv.js +33 -12
  16. package/dist/commands/new.js +12 -5
  17. package/dist/commands/prune.js +14 -3
  18. package/dist/commands/search.js +67 -4
  19. package/dist/commands/serve.js +1 -1
  20. package/dist/commands/show.js +40 -6
  21. package/dist/commands/status.js +46 -18
  22. package/dist/commands/tree.js +94 -6
  23. package/dist/commands/upgrade.js +15 -15
  24. package/dist/lib/config.js +502 -0
  25. package/dist/lib/constants.js +23 -0
  26. package/dist/lib/doc-shape.js +5 -5
  27. package/dist/lib/frontmatter.js +47 -0
  28. package/dist/lib/fs.js +8 -8
  29. package/dist/lib/git.js +147 -42
  30. package/dist/lib/markdown.js +8 -7
  31. package/dist/lib/output-schema.js +3 -3
  32. package/dist/lib/package-root.js +1 -1
  33. package/dist/lib/pagination.js +2 -2
  34. package/dist/lib/rewrite.js +9 -3
  35. package/dist/lib/routing.js +152 -0
  36. package/dist/lib/schema.js +16 -0
  37. package/dist/lib/search.js +35 -16
  38. package/dist/lib/source-id.js +49 -0
  39. package/dist/lib/sources.js +760 -0
  40. package/dist/lib/state.js +74 -25
  41. package/dist/lib/telemetry.js +726 -0
  42. package/dist/lib/viewer-http.js +2 -2
  43. package/dist/lib/workspace.js +187 -43
  44. package/package.json +1 -1
  45. package/schemas/config.schema.json +116 -0
  46. package/schemas/meta.schema.json +5 -1
  47. package/schemas/output.schema.json +442 -0
  48. package/schemas/probes.schema.json +90 -0
@@ -48,7 +48,7 @@ export function createViewerRequestHandler(rootDir) {
48
48
  // 仅按扫描产生的 canonical llmdocPath 查表,不接受任意文件系统路径。
49
49
  const document = workspace.documentsByLlmdocPath.get(docPath);
50
50
  if (!document) {
51
- sendJson(response, 404, { error: `未找到文档: ${docPath}` }, headOnly);
51
+ sendJson(response, 404, { error: `Document not found: ${docPath}` }, headOnly);
52
52
  return;
53
53
  }
54
54
  sendJson(response, 200, {
@@ -73,7 +73,7 @@ function sendStaticAsset(response, assetsRoot, asset, headOnly) {
73
73
  // fileName 只可能来自上方常量白名单;请求值不会参与路径解析。
74
74
  const assetPath = path.join(assetsRoot, asset.fileName);
75
75
  if (!fs.existsSync(assetPath)) {
76
- throw new CliError(`viewer 资产缺失: ${asset.fileName}`);
76
+ throw new CliError(`Viewer asset is missing: ${asset.fileName}`);
77
77
  }
78
78
  sendBody(response, 200, fs.readFileSync(assetPath), asset.contentType, headOnly);
79
79
  }
@@ -1,23 +1,28 @@
1
+ import { spawnSync } from "node:child_process";
1
2
  import fs from "node:fs";
2
3
  import path from "node:path";
3
- import matter from "gray-matter";
4
4
  import { DOC_LINE_WARNING_LIMIT } from "./constants.js";
5
5
  import { CliError } from "./errors.js";
6
6
  import { estimateTokens, extractCodeRefs, extractLinks, extractTitle, resolveDocLink, stripMarkdownLiterals, validateCodeRefTags } from "./markdown.js";
7
7
  import { assertDocKindMatchesShape, parseDocTargetShape } from "./doc-shape.js";
8
8
  import { normalizeRepoRelativePath, repoPath, resolveInsideRoot } from "./fs.js";
9
- import { gitCommitExists, isShallowRepository } from "./git.js";
9
+ import { gitCommitExists, isShallowRepository, listGitDeletedLlmdocPaths } from "./git.js";
10
10
  import { matchesCodePathPattern } from "./search.js";
11
11
  import { validateDocFrontmatter, validateMeta } from "./schema.js";
12
+ import { computeLocalPreloadBudget, LLMDOC_CONFIG_FILENAME, LLMDOC_LOCAL_CONFIG_FILENAME, loadLlmdocConfig } from "./config.js";
13
+ import { parseYamlFrontmatter } from "./frontmatter.js";
14
+ import { isSourceRef, parseSourceDocId } from "./source-id.js";
15
+ import { loadSourcesReadOnly } from "./sources.js";
12
16
  export function loadWorkspace(rootDir) {
13
17
  const configuredLlmdocDir = path.join(rootDir, "llmdoc");
14
18
  if (!fs.existsSync(configuredLlmdocDir) || !fs.statSync(configuredLlmdocDir).isDirectory()) {
15
- throw new CliError("仓库内不存在 llmdoc/ 目录。", 2);
19
+ throw new CliError("The repository does not contain an llmdoc/ directory.", 2);
16
20
  }
17
21
  resolveInsideRoot(rootDir, "llmdoc");
18
22
  const llmdocDir = configuredLlmdocDir;
19
23
  const preloadIssues = [];
20
- const documents = scanDocuments(rootDir, llmdocDir, preloadIssues);
24
+ const unparsedDocPaths = new Set();
25
+ const documents = scanDocuments(rootDir, llmdocDir, preloadIssues, unparsedDocPaths);
21
26
  const documentsByLlmdocPath = new Map(documents.map((document) => [document.llmdocPath, document]));
22
27
  const topics = new Map();
23
28
  const rootSingletons = [];
@@ -37,6 +42,8 @@ export function loadWorkspace(rootDir) {
37
42
  rootSingletons.sort((left, right) => left.llmdocPath.localeCompare(right.llmdocPath));
38
43
  const metaPath = path.join(llmdocDir, "meta.json");
39
44
  const meta = loadMeta(metaPath, preloadIssues);
45
+ const llmdocConfig = loadLlmdocConfig(rootDir, documentsByLlmdocPath);
46
+ const loadedSources = loadSourcesReadOnly(rootDir, llmdocConfig.sources);
40
47
  return {
41
48
  rootDir,
42
49
  llmdocDir,
@@ -46,10 +53,16 @@ export function loadWorkspace(rootDir) {
46
53
  topics,
47
54
  rootSingletons,
48
55
  meta,
49
- preloadIssues
56
+ llmdocConfig,
57
+ preloadIssues,
58
+ sources: loadedSources.sources,
59
+ sourcesByName: loadedSources.sourcesByName,
60
+ sourceDocuments: loadedSources.sourceDocuments,
61
+ sourceDocumentsById: loadedSources.sourceDocumentsById,
62
+ unparsedDocPaths
50
63
  };
51
64
  }
52
- function scanDocuments(rootDir, llmdocDir, preloadIssues) {
65
+ function scanDocuments(rootDir, llmdocDir, preloadIssues, unparsedDocPaths) {
53
66
  const results = [];
54
67
  walk(llmdocDir, (absolutePath) => {
55
68
  const repoRelativePath = repoPath(rootDir, absolutePath);
@@ -59,27 +72,28 @@ function scanDocuments(rootDir, llmdocDir, preloadIssues) {
59
72
  severity: "error",
60
73
  code: "file.extension.invalid",
61
74
  path: repoRelativePath,
62
- message: "llmdoc/ 下仅允许 .mdx 文档与根级唯一 meta.json。"
75
+ message: "llmdoc/ allows only .mdx documents and one root-level meta.json file."
63
76
  });
64
77
  }
65
78
  return;
66
79
  }
80
+ const llmdocPath = repoPath(llmdocDir, absolutePath);
67
81
  const raw = fs.readFileSync(absolutePath, "utf8");
68
82
  let parsed;
69
83
  try {
70
- parsed = matter(raw);
84
+ parsed = parseYamlFrontmatter(raw);
71
85
  }
72
86
  catch (error) {
87
+ unparsedDocPaths.add(llmdocPath);
73
88
  preloadIssues.push({
74
89
  severity: "error",
75
90
  code: "frontmatter.parse",
76
91
  path: repoRelativePath,
77
- message: `front matter 解析失败: ${error.message}`
92
+ message: `Front matter parse failed: ${error.message}`
78
93
  });
79
94
  return;
80
95
  }
81
96
  const frontmatter = parsed.data;
82
- const llmdocPath = repoPath(llmdocDir, absolutePath);
83
97
  const segments = llmdocPath.split("/");
84
98
  results.push({
85
99
  absolutePath,
@@ -94,7 +108,10 @@ function scanDocuments(rootDir, llmdocDir, preloadIssues) {
94
108
  links: extractLinks(parsed.content),
95
109
  codeRefs: extractCodeRefs(parsed.content),
96
110
  estimatedTokens: estimateTokens(parsed.content),
97
- lineCount: raw.split(/\r?\n/).length
111
+ lineCount: raw.split(/\r?\n/).length,
112
+ sourceName: null,
113
+ sourceRelativePath: null,
114
+ sourceMountPath: null
98
115
  });
99
116
  });
100
117
  results.sort((left, right) => left.llmdocPath.localeCompare(right.llmdocPath));
@@ -125,7 +142,7 @@ function loadMeta(metaPath, preloadIssues) {
125
142
  severity: "error",
126
143
  code: "meta.parse",
127
144
  path: "llmdoc/meta.json",
128
- message: `meta.json 解析失败: ${error.message}`
145
+ message: `meta.json parse failed: ${error.message}`
129
146
  });
130
147
  return null;
131
148
  }
@@ -136,7 +153,7 @@ function loadMeta(metaPath, preloadIssues) {
136
153
  severity: "error",
137
154
  code: "meta.invalid",
138
155
  path: "llmdoc/meta.json",
139
- message: `meta.json 非法: ${error}`
156
+ message: `Invalid meta.json: ${error}`
140
157
  });
141
158
  }
142
159
  return null;
@@ -145,13 +162,15 @@ function loadMeta(metaPath, preloadIssues) {
145
162
  }
146
163
  export function validateWorkspace(workspace) {
147
164
  const issues = [...workspace.preloadIssues];
165
+ issues.push(...workspace.llmdocConfig.issues);
148
166
  const seenDocPaths = new Set();
167
+ const declaredSourceAliases = new Set(Object.keys(workspace.llmdocConfig.config?.sources ?? {}));
149
168
  if (!workspace.meta) {
150
169
  issues.push({
151
170
  severity: "error",
152
171
  code: "meta.missing",
153
172
  path: "llmdoc/meta.json",
154
- message: "缺少 llmdoc/meta.json。请运行 `npx -y @tokenroll/llmdoc init-state` 建立台账(若仓库尚无提交,请先创建首次 Git 提交)。"
173
+ message: "llmdoc/meta.json is missing. Run `npx -y @tokenroll/llmdoc init-state` to create the ledger (create the initial Git commit first if the repository has no commits)."
155
174
  });
156
175
  }
157
176
  for (const document of workspace.documents) {
@@ -162,7 +181,7 @@ export function validateWorkspace(workspace) {
162
181
  severity: "error",
163
182
  code: "frontmatter.invalid",
164
183
  path: document.repoPath,
165
- message: `front matter 非法: ${error}`
184
+ message: `Invalid front matter: ${error}`
166
185
  });
167
186
  }
168
187
  try {
@@ -183,7 +202,15 @@ export function validateWorkspace(workspace) {
183
202
  severity: "error",
184
203
  code: "hierarchy.nested",
185
204
  path: document.repoPath,
186
- message: "topic 下不允许继续嵌套子目录。"
205
+ message: "A topic cannot contain nested subdirectories."
206
+ });
207
+ }
208
+ if (workspace.llmdocConfig.schemaVersion === 2 && document.topic?.startsWith("@")) {
209
+ issues.push({
210
+ severity: "error",
211
+ code: "hierarchy.reserved-prefix",
212
+ path: document.repoPath,
213
+ message: `Topic "${document.topic}" starts with "@", which is reserved for external sources in llmdoc.config/v2. Rename it with \`llmdoc mv llmdoc/${document.topic} llmdoc/${document.topic.slice(1)}\`.`
187
214
  });
188
215
  }
189
216
  const mdxBodyErrors = validateMdxBody(document.body);
@@ -200,10 +227,52 @@ export function validateWorkspace(workspace) {
200
227
  severity: "warning",
201
228
  code: "link.wikilink",
202
229
  path: document.repoPath,
203
- message: "正文包含 [[wikilink]] 语法;llmdoc 不解析它,请改用标准 Markdown 相对链接。"
230
+ message: "The body contains [[wikilink]] syntax, which llmdoc does not parse. Use a standard relative Markdown link."
204
231
  });
205
232
  }
206
233
  for (const relationPath of document.frontmatter.relations?.requires ?? []) {
234
+ if (isSourceRef(relationPath)) {
235
+ let parsedRef;
236
+ try {
237
+ parsedRef = parseSourceDocId(relationPath);
238
+ }
239
+ catch (error) {
240
+ issues.push({
241
+ severity: "error",
242
+ code: "relations.requires.invalid-path",
243
+ path: document.repoPath,
244
+ message: error.message
245
+ });
246
+ continue;
247
+ }
248
+ if (!declaredSourceAliases.has(parsedRef.alias)) {
249
+ issues.push({
250
+ severity: "error",
251
+ code: "relations.requires.undeclared-source",
252
+ path: document.repoPath,
253
+ message: `requires references an undeclared source: @${parsedRef.alias} (${relationPath})`
254
+ });
255
+ continue;
256
+ }
257
+ const loadedSource = workspace.sourcesByName.get(parsedRef.alias);
258
+ if (!loadedSource || loadedSource.status !== "ready") {
259
+ issues.push({
260
+ severity: "warning",
261
+ code: "relations.requires.source-unavailable",
262
+ path: document.repoPath,
263
+ message: `requires target ${parsedRef.canonicalId} could not be verified because source @${parsedRef.alias} is unavailable${loadedSource?.remedy ? ` (${loadedSource.remedy})` : ""}.`
264
+ });
265
+ }
266
+ else if (!workspace.sourceDocumentsById.has(parsedRef.canonicalId)) {
267
+ issues.push({
268
+ severity: "warning",
269
+ code: "relations.requires.source-missing",
270
+ path: document.repoPath,
271
+ message: `requires points to a missing document in @${parsedRef.alias}${loadedSource.revision ? ` (${loadedSource.revision.slice(0, 7)})` : ""}: ${parsedRef.canonicalId}`
272
+ });
273
+ }
274
+ continue;
275
+ }
207
276
  const normalizedRelation = validateLlmdocRelativePath(relationPath);
208
277
  if (!normalizedRelation.ok) {
209
278
  issues.push({
@@ -218,7 +287,7 @@ export function validateWorkspace(workspace) {
218
287
  severity: "error",
219
288
  code: "relations.requires.missing",
220
289
  path: document.repoPath,
221
- message: `requires 指向不存在的文档: ${relationPath}`
290
+ message: `requires points to a missing document: ${relationPath}`
222
291
  });
223
292
  }
224
293
  }
@@ -237,7 +306,7 @@ export function validateWorkspace(workspace) {
237
306
  severity: "error",
238
307
  code: "relations.related.missing",
239
308
  path: document.repoPath,
240
- message: `related 指向不存在的文档: ${relationPath}`
309
+ message: `related points to a missing document: ${relationPath}`
241
310
  });
242
311
  }
243
312
  }
@@ -249,7 +318,7 @@ export function validateWorkspace(workspace) {
249
318
  severity: "error",
250
319
  code: "link.invalid-path",
251
320
  path: document.repoPath,
252
- message: `正文链接非法: ${linkTarget} (${normalizedLink.message})`
321
+ message: `Invalid body link: ${linkTarget} (${normalizedLink.message})`
253
322
  });
254
323
  }
255
324
  else if (!workspace.documentsByLlmdocPath.has(normalizedLink.value)) {
@@ -257,7 +326,7 @@ export function validateWorkspace(workspace) {
257
326
  severity: "error",
258
327
  code: "link.missing",
259
328
  path: document.repoPath,
260
- message: `正文链接悬空: ${linkTarget}`
329
+ message: `Body link points to a missing document: ${linkTarget}`
261
330
  });
262
331
  }
263
332
  }
@@ -276,7 +345,7 @@ export function validateWorkspace(workspace) {
276
345
  severity: "error",
277
346
  code: "coderef.path.missing",
278
347
  path: document.repoPath,
279
- message: `CodeRef path 不存在: ${codeRef.path}`
348
+ message: `CodeRef path does not exist: ${codeRef.path}`
280
349
  });
281
350
  }
282
351
  }
@@ -295,7 +364,7 @@ export function validateWorkspace(workspace) {
295
364
  severity: "error",
296
365
  code: "code.paths.missing",
297
366
  path: document.repoPath,
298
- message: `code.paths 指向不存在的路径: ${codePath}`
367
+ message: `code.paths points to a missing path: ${codePath}`
299
368
  });
300
369
  }
301
370
  else if (normalized.isGlob &&
@@ -304,7 +373,7 @@ export function validateWorkspace(workspace) {
304
373
  severity: "error",
305
374
  code: "code.paths.unmatched",
306
375
  path: document.repoPath,
307
- message: `code.paths glob 未命中任何现有文件: ${codePath}`
376
+ message: `code.paths glob matches no existing files: ${codePath}`
308
377
  });
309
378
  }
310
379
  }
@@ -313,17 +382,72 @@ export function validateWorkspace(workspace) {
313
382
  severity: "warning",
314
383
  code: "size.line-warning",
315
384
  path: document.repoPath,
316
- message: `文档 ${document.lineCount} 行,超过建议上限 ${DOC_LINE_WARNING_LIMIT} 行。`
385
+ message: `The document has ${document.lineCount} lines, exceeding the recommended limit of ${DOC_LINE_WARNING_LIMIT}.`
386
+ });
387
+ }
388
+ }
389
+ for (const source of workspace.sources) {
390
+ if (source.status !== "ready") {
391
+ issues.push({
392
+ severity: "warning",
393
+ code: source.status === "missing" ? "source.unavailable" : "source.error",
394
+ path: LLMDOC_CONFIG_FILENAME,
395
+ message: `Source @${source.name} is unavailable: ${source.error ?? "no local snapshot"}.${source.remedy ? ` ${source.remedy}` : ""}`
396
+ });
397
+ }
398
+ for (const sourceIssue of source.issues) {
399
+ issues.push({
400
+ ...sourceIssue,
401
+ severity: "warning"
402
+ });
403
+ }
404
+ }
405
+ for (const preloadEntry of workspace.llmdocConfig.preloadEntries) {
406
+ if (preloadEntry.kind !== "source" || !preloadEntry.sourceName) {
407
+ continue;
408
+ }
409
+ const source = workspace.sourcesByName.get(preloadEntry.sourceName);
410
+ if (!source || source.status !== "ready") {
411
+ issues.push({
412
+ severity: "warning",
413
+ code: "config.startup.preload.source-unavailable",
414
+ path: LLMDOC_CONFIG_FILENAME,
415
+ message: `startup.preload source document could not be verified because @${preloadEntry.sourceName} is unavailable: ${preloadEntry.normalized}`
416
+ });
417
+ }
418
+ else if (!workspace.sourceDocumentsById.has(preloadEntry.normalized)) {
419
+ issues.push({
420
+ severity: "warning",
421
+ code: "config.startup.preload.source-missing",
422
+ path: LLMDOC_CONFIG_FILENAME,
423
+ message: `startup.preload source document does not exist in @${preloadEntry.sourceName}${source.revision ? ` (${source.revision.slice(0, 7)})` : ""}: ${preloadEntry.normalized}`
317
424
  });
318
425
  }
319
426
  }
427
+ const localPreloadBudget = computeLocalPreloadBudget(workspace.llmdocConfig, workspace.documentsByLlmdocPath);
428
+ if (localPreloadBudget.exceedsBudget) {
429
+ issues.push({
430
+ severity: "warning",
431
+ code: "config.startup.preload.budget-exceeded",
432
+ path: workspace.llmdocConfig.preloadBudgetSourceFile ?? LLMDOC_CONFIG_FILENAME,
433
+ message: `Local startup.preload totals ~${localPreloadBudget.totalEstimatedTokens} tokens, exceeding the soft budget of ${localPreloadBudget.budgetTokens} tokens. Consider removing less-frequent documents from startup.preload so they stay on progressive description/tree disclosure (or raise startup.preloadBudgetTokens).`
434
+ });
435
+ }
436
+ if (workspace.llmdocConfig.localConfigExists && isGitTrackedFile(workspace.rootDir, LLMDOC_LOCAL_CONFIG_FILENAME)) {
437
+ issues.push({
438
+ severity: "warning",
439
+ code: "config.local.tracked",
440
+ path: LLMDOC_LOCAL_CONFIG_FILENAME,
441
+ message: `${LLMDOC_LOCAL_CONFIG_FILENAME} is tracked by Git. Add it to .gitignore so machine-specific paths are not committed.`
442
+ });
443
+ }
320
444
  for (const [topic, docs] of workspace.topics) {
321
445
  if (docs.length === 0) {
322
446
  issues.push({
323
447
  severity: "warning",
324
448
  code: "topic.empty",
325
449
  path: `llmdoc/${topic}`,
326
- message: "topic 目录为空。"
450
+ message: "The topic directory is empty."
327
451
  });
328
452
  }
329
453
  }
@@ -332,35 +456,46 @@ export function validateWorkspace(workspace) {
332
456
  // 否则任何 fetch-depth:1 的 CI 都会误报陈旧。
333
457
  const shallow = isShallowRepository(workspace.rootDir);
334
458
  const revisionSeverity = shallow ? "warning" : "error";
335
- const shallowHint = shallow ? "(shallow clone;完整校验请用 fetch-depth: 0 或 git fetch --unshallow)" : "";
459
+ const shallowHint = shallow ? " (shallow clone; use fetch-depth: 0 or git fetch --unshallow for complete validation)" : "";
336
460
  if (!gitCommitExists(workspace.rootDir, workspace.meta.baseline.revision)) {
337
461
  issues.push({
338
462
  severity: revisionSeverity,
339
463
  code: "meta.baseline.revision.missing",
340
464
  path: "llmdoc/meta.json",
341
- message: `baseline.revision 不存在于当前 git 历史: ${workspace.meta.baseline.revision}${shallowHint}`
465
+ message: `baseline.revision does not exist in current Git history: ${workspace.meta.baseline.revision}${shallowHint}`
342
466
  });
343
467
  }
344
468
  const metaPaths = Object.keys(workspace.meta.documents).sort();
345
469
  const docPaths = [...seenDocPaths].sort();
470
+ const gitDeletedDocs = listGitDeletedLlmdocPaths(workspace.rootDir);
346
471
  for (const docPath of docPaths) {
347
472
  if (!(docPath in workspace.meta.documents)) {
348
473
  issues.push({
349
474
  severity: "error",
350
475
  code: "meta.entry.missing",
351
476
  path: `llmdoc/${docPath}`,
352
- message: "meta.json 缺少对应 documents entry。可用 `llmdoc adopt <path>` 无损登记。"
477
+ message: "meta.json is missing the corresponding documents entry. Use `llmdoc adopt <path>` to register it without rewriting the document."
353
478
  });
354
479
  }
355
480
  }
356
481
  for (const metaPath of metaPaths) {
357
- if (!seenDocPaths.has(metaPath)) {
358
- issues.push({
359
- severity: "error",
360
- code: "meta.entry.orphaned",
361
- path: `llmdoc/${metaPath}`,
362
- message: "meta.json 中存在孤儿 documents entry。"
363
- });
482
+ if (!seenDocPaths.has(metaPath) && !workspace.unparsedDocPaths?.has(metaPath)) {
483
+ if (gitDeletedDocs.has(metaPath)) {
484
+ issues.push({
485
+ severity: "warning",
486
+ code: "meta.entry.pending-removal",
487
+ path: `llmdoc/${metaPath}`,
488
+ message: "Document was deleted in Git; finalize with `llmdoc commit` to remove its ledger entry."
489
+ });
490
+ }
491
+ else {
492
+ issues.push({
493
+ severity: "error",
494
+ code: "meta.entry.orphaned",
495
+ path: `llmdoc/${metaPath}`,
496
+ message: "meta.json contains an orphan documents entry."
497
+ });
498
+ }
364
499
  }
365
500
  const revision = workspace.meta.documents[metaPath]?.validatedRevision;
366
501
  if (revision && !gitCommitExists(workspace.rootDir, revision)) {
@@ -368,13 +503,21 @@ export function validateWorkspace(workspace) {
368
503
  severity: revisionSeverity,
369
504
  code: "meta.document.revision.missing",
370
505
  path: `llmdoc/${metaPath}`,
371
- message: `validatedRevision 不存在于当前 git 历史: ${revision}${shallowHint}`
506
+ message: `validatedRevision does not exist in current Git history: ${revision}${shallowHint}`
372
507
  });
373
508
  }
374
509
  }
375
510
  }
376
511
  return issues;
377
512
  }
513
+ function isGitTrackedFile(rootDir, repoRelativePath) {
514
+ const result = spawnSync("git", ["ls-files", "--error-unmatch", "--", repoRelativePath], {
515
+ cwd: rootDir,
516
+ encoding: "utf8",
517
+ stdio: ["ignore", "pipe", "ignore"]
518
+ });
519
+ return result.status === 0;
520
+ }
378
521
  function isGlob(input) {
379
522
  return /[*?[\]{}]/.test(input);
380
523
  }
@@ -382,13 +525,13 @@ function validateMdxBody(body) {
382
525
  const cleanBody = stripMarkdownLiterals(body);
383
526
  const issues = [];
384
527
  if (/^\s*import\s+/m.test(cleanBody) || /^\s*export\s+/m.test(cleanBody)) {
385
- issues.push("仅允许纯 Markdown 与自闭合 CodeRef,禁止 import/export。");
528
+ issues.push("Only plain Markdown and self-closing CodeRef tags are allowed; import/export is forbidden.");
386
529
  }
387
530
  if (/<(?!CodeRef\b)[A-Za-z][^>]*>/m.test(cleanBody) || /<\/[A-Za-z][^>]*>/m.test(cleanBody)) {
388
- issues.push("仅允许自闭合 <CodeRef ... /> 组件,禁止任意 JSX 标签。");
531
+ issues.push("Only self-closing <CodeRef ... /> components are allowed; arbitrary JSX tags are forbidden.");
389
532
  }
390
533
  if (/\{[^}\n]+\}/m.test(cleanBody)) {
391
- issues.push("禁止在正文中使用 MDX/JS 表达式。");
534
+ issues.push("MDX/JS expressions are forbidden in document bodies.");
392
535
  }
393
536
  issues.push(...validateCodeRefTags(body));
394
537
  return [...new Set(issues)];
@@ -397,10 +540,10 @@ function validateLlmdocRelativePath(input) {
397
540
  try {
398
541
  const normalized = normalizeRepoRelativePath(input);
399
542
  if (!normalized.endsWith(".mdx")) {
400
- return { ok: false, message: `路径必须指向 .mdx 文档: ${input}` };
543
+ return { ok: false, message: `Path must point to an .mdx document: ${input}` };
401
544
  }
402
545
  if (normalized.startsWith("llmdoc/")) {
403
- return { ok: false, message: `路径必须是 llmdoc/ 下相对路径而非仓库根路径: ${input}` };
546
+ return { ok: false, message: `Path must be relative to llmdoc/, not the repository root: ${input}` };
404
547
  }
405
548
  return { ok: true, value: normalized };
406
549
  }
@@ -443,6 +586,7 @@ function validateCodePathPattern(rootDir, input) {
443
586
  }
444
587
  }
445
588
  function globMatchesExistingFile(rootDir, staticPrefixPath, pattern) {
589
+ const rootRealPath = fs.realpathSync(rootDir);
446
590
  const pending = [staticPrefixPath];
447
591
  while (pending.length > 0) {
448
592
  const currentPath = pending.pop();
@@ -451,7 +595,7 @@ function globMatchesExistingFile(rootDir, staticPrefixPath, pattern) {
451
595
  continue;
452
596
  }
453
597
  if (stat.isFile()) {
454
- if (matchesCodePathPattern(pattern, repoPath(rootDir, currentPath))) {
598
+ if (matchesCodePathPattern(pattern, repoPath(rootRealPath, currentPath))) {
455
599
  return true;
456
600
  }
457
601
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenroll/llmdoc",
3
- "version": "3.5.3",
3
+ "version": "3.9.0",
4
4
  "description": "V3 runtime CLI for llmdoc repositories",
5
5
  "homepage": "https://github.com/TokenRollAI/llmdoc",
6
6
  "repository": {
@@ -0,0 +1,116 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://llmdoc.tokenroll.ai/schemas/config.schema.json",
4
+ "oneOf": [
5
+ {
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": ["schema"],
9
+ "properties": {
10
+ "$schema": {
11
+ "type": "string"
12
+ },
13
+ "schema": {
14
+ "type": "string",
15
+ "const": "llmdoc.config/v1"
16
+ },
17
+ "startup": {
18
+ "$ref": "#/$defs/startup"
19
+ }
20
+ }
21
+ },
22
+ {
23
+ "type": "object",
24
+ "additionalProperties": false,
25
+ "required": ["schema"],
26
+ "properties": {
27
+ "$schema": {
28
+ "type": "string"
29
+ },
30
+ "schema": {
31
+ "type": "string",
32
+ "const": "llmdoc.config/v2"
33
+ },
34
+ "sources": {
35
+ "type": "object",
36
+ "propertyNames": {
37
+ "pattern": "^[a-z0-9][a-z0-9._-]{0,63}$"
38
+ },
39
+ "additionalProperties": {
40
+ "$ref": "#/$defs/sourceEntry"
41
+ }
42
+ },
43
+ "startup": {
44
+ "$ref": "#/$defs/startup"
45
+ }
46
+ }
47
+ }
48
+ ],
49
+ "$defs": {
50
+ "startup": {
51
+ "type": "object",
52
+ "additionalProperties": false,
53
+ "properties": {
54
+ "remindSkill": {
55
+ "type": "boolean",
56
+ "default": true
57
+ },
58
+ "preload": {
59
+ "type": "array",
60
+ "items": {
61
+ "type": "string",
62
+ "minLength": 1
63
+ },
64
+ "default": []
65
+ },
66
+ "preloadBudgetTokens": {
67
+ "type": "integer",
68
+ "minimum": 1,
69
+ "default": 4000
70
+ }
71
+ }
72
+ },
73
+ "sourceEntry": {
74
+ "oneOf": [
75
+ {
76
+ "type": "object",
77
+ "additionalProperties": false,
78
+ "required": ["git"],
79
+ "properties": {
80
+ "git": {
81
+ "type": "string",
82
+ "minLength": 1
83
+ },
84
+ "ref": {
85
+ "type": "string",
86
+ "minLength": 1
87
+ },
88
+ "dir": {
89
+ "type": "string",
90
+ "minLength": 1
91
+ },
92
+ "refresh": {
93
+ "type": "string",
94
+ "pattern": "^[1-9][0-9]*[mhd]$"
95
+ }
96
+ }
97
+ },
98
+ {
99
+ "type": "object",
100
+ "additionalProperties": false,
101
+ "required": ["path"],
102
+ "properties": {
103
+ "path": {
104
+ "type": "string",
105
+ "minLength": 1
106
+ },
107
+ "dir": {
108
+ "type": "string",
109
+ "minLength": 1
110
+ }
111
+ }
112
+ }
113
+ ]
114
+ }
115
+ }
116
+ }
@@ -34,6 +34,10 @@
34
34
  "validatedRevision": {
35
35
  "type": ["string", "null"],
36
36
  "minLength": 1
37
+ },
38
+ "verifiedAt": {
39
+ "type": "string",
40
+ "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]+)?Z$"
37
41
  }
38
42
  }
39
43
  }
@@ -49,7 +53,7 @@
49
53
  },
50
54
  "source": {
51
55
  "type": "string",
52
- "enum": ["init", "prune"]
56
+ "enum": ["init", "prune", "dream"]
53
57
  },
54
58
  "documentCount": {
55
59
  "type": "integer",