@tokenroll/llmdoc 3.5.2 → 3.6.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/lib/state.js CHANGED
@@ -2,6 +2,7 @@ import fs from "node:fs";
2
2
  import { canAdvanceRevisions, gitCommitExists, readChangedPathsSince, readGitState } from "./git.js";
3
3
  import { normalizeRepoRelativePath } from "./fs.js";
4
4
  import { matchesCodePathPattern } from "./search.js";
5
+ import { LLMDOC_CONFIG_FILENAME } from "./config.js";
5
6
  export function analyzeDelta(workspace, scope) {
6
7
  const git = readWorkspaceGitState(workspace);
7
8
  const ignorePatterns = loadIgnorePatterns(workspace.rootDir);
@@ -30,8 +31,8 @@ export function analyzeDelta(workspace, scope) {
30
31
  if (revisionInvalid) {
31
32
  invalidRevisionDocuments.push(document);
32
33
  invalidRevisionReasons.push(!validatedRevision
33
- ? `文档 ${document.llmdocPath} 缺少 validatedRevision`
34
- : `文档 ${document.llmdocPath} 的 validatedRevision 不存在于当前 git 历史: ${validatedRevision}`);
34
+ ? `Document ${document.llmdocPath} has no validatedRevision`
35
+ : `Document ${document.llmdocPath} has a validatedRevision that does not exist in current Git history: ${validatedRevision}`);
35
36
  }
36
37
  const changedCommittedPaths = !revisionInvalid && git.headRevision && validatedRevision !== git.headRevision
37
38
  ? getChangedPathsForRevision(workspace.rootDir, validatedRevision, git.headRevision, changedPathsByRevision).filter((filePath) => isSurface(filePath) && documentMatchesPath(document, filePath))
@@ -71,26 +72,24 @@ export function analyzeDelta(workspace, scope) {
71
72
  const unmappedDirtyPaths = dirtyPaths.filter((filePath) => !workspace.documents.some((document) => documentMatchesPath(document, filePath)));
72
73
  const reasons = [];
73
74
  if (!git.available || git.degradedReason) {
74
- reasons.push(git.degradedReason ?? "git 状态不可用");
75
+ reasons.push(git.degradedReason ?? "Git state is unavailable");
75
76
  }
76
77
  if (invalidRevisionReasons.length > 0) {
77
78
  reasons.push(...invalidRevisionReasons);
78
79
  }
79
80
  if (unmappedCommittedPaths.length > 0 || unmappedDirtyPaths.length > 0) {
80
- reasons.push("存在未映射代码路径");
81
+ reasons.push("Unmapped code paths exist");
81
82
  }
82
83
  if (needsReview.length > 0) {
83
- reasons.push("存在 requires 反向一跳需复核文档");
84
+ reasons.push("Documents in the reverse requires closure need review");
84
85
  }
85
86
  if (directImpacts.length > 8) {
86
- reasons.push("受影响文档过多,建议 deep");
87
+ reasons.push("Too many documents are impacted; deep mode is recommended");
87
88
  }
88
89
  if (dirtyDocuments.length > 0) {
89
- reasons.push("存在未提交 dirty 关联代码");
90
+ reasons.push("Mapped implementation code has uncommitted changes");
90
91
  }
91
- const suggestedMode = reasons.some((reason) => ["未映射", "需复核", "过多", "dirty", "不可用", "不存在于当前 git 历史", "validatedRevision", "缺少"].some((keyword) => reason.includes(keyword)))
92
- ? "deep"
93
- : "light";
92
+ const suggestedMode = reasons.length > 0 ? "deep" : "light";
94
93
  return {
95
94
  git,
96
95
  impacts: directImpacts.sort((left, right) => left.document.llmdocPath.localeCompare(right.document.llmdocPath)),
@@ -124,7 +123,7 @@ export function parseScope(values, workspace) {
124
123
  continue;
125
124
  }
126
125
  if (!workspace.documentsByLlmdocPath.has(normalized)) {
127
- throw new Error(`scope 未命中任何 topic 或文档: ${raw}`);
126
+ throw new Error(`Scope did not match any topic or document: ${raw}`);
128
127
  }
129
128
  documentPaths.add(normalized);
130
129
  }
@@ -153,7 +152,7 @@ export function computeGrowthState(workspace) {
153
152
  export function assertRevisionAdvancePreconditions(input) {
154
153
  const { workspace, llmdocPaths, updateAll } = input;
155
154
  if (!workspace.meta) {
156
- throw new Error("缺少 meta.json");
155
+ throw new Error("meta.json is missing");
157
156
  }
158
157
  const git = readWorkspaceGitState(workspace);
159
158
  const advance = canAdvanceRevisions(git);
@@ -171,8 +170,8 @@ export function assertRevisionAdvancePreconditions(input) {
171
170
  });
172
171
  if (blocked.length > 0) {
173
172
  throw new Error(updateAll
174
- ? `全量 fingerprint 时以下文档关联代码存在 dirty 变更,不能伪造 revision: ${blocked.join(", ")}`
175
- : `以下文档关联代码存在 dirty 变更,不能伪造 revision: ${blocked.join(", ")}`);
173
+ ? `A full fingerprint cannot advance while mapped code for these documents is dirty: ${blocked.join(", ")}`
174
+ : `Cannot advance revisions while mapped code for these documents is dirty: ${blocked.join(", ")}`);
176
175
  }
177
176
  return { git, targetPaths };
178
177
  }
@@ -257,7 +256,9 @@ export function loadIgnorePatterns(rootDir) {
257
256
  return patterns;
258
257
  }
259
258
  export function isImplementationSurfacePath(repoRelativePath, ignorePatterns = []) {
260
- if (repoRelativePath.startsWith("llmdoc/") || repoRelativePath.startsWith(".llmdoc-tmp/")) {
259
+ if (repoRelativePath === LLMDOC_CONFIG_FILENAME ||
260
+ repoRelativePath.startsWith("llmdoc/") ||
261
+ repoRelativePath.startsWith(".llmdoc-tmp/")) {
261
262
  return false;
262
263
  }
263
264
  const basename = repoRelativePath.split("/").pop() ?? repoRelativePath;
@@ -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
  }
@@ -9,10 +9,11 @@ import { normalizeRepoRelativePath, repoPath, resolveInsideRoot } from "./fs.js"
9
9
  import { gitCommitExists, isShallowRepository } from "./git.js";
10
10
  import { matchesCodePathPattern } from "./search.js";
11
11
  import { validateDocFrontmatter, validateMeta } from "./schema.js";
12
+ import { loadLlmdocConfig } from "./config.js";
12
13
  export function loadWorkspace(rootDir) {
13
14
  const configuredLlmdocDir = path.join(rootDir, "llmdoc");
14
15
  if (!fs.existsSync(configuredLlmdocDir) || !fs.statSync(configuredLlmdocDir).isDirectory()) {
15
- throw new CliError("仓库内不存在 llmdoc/ 目录。", 2);
16
+ throw new CliError("The repository does not contain an llmdoc/ directory.", 2);
16
17
  }
17
18
  resolveInsideRoot(rootDir, "llmdoc");
18
19
  const llmdocDir = configuredLlmdocDir;
@@ -37,6 +38,7 @@ export function loadWorkspace(rootDir) {
37
38
  rootSingletons.sort((left, right) => left.llmdocPath.localeCompare(right.llmdocPath));
38
39
  const metaPath = path.join(llmdocDir, "meta.json");
39
40
  const meta = loadMeta(metaPath, preloadIssues);
41
+ const llmdocConfig = loadLlmdocConfig(rootDir, documentsByLlmdocPath);
40
42
  return {
41
43
  rootDir,
42
44
  llmdocDir,
@@ -46,6 +48,7 @@ export function loadWorkspace(rootDir) {
46
48
  topics,
47
49
  rootSingletons,
48
50
  meta,
51
+ llmdocConfig,
49
52
  preloadIssues
50
53
  };
51
54
  }
@@ -59,7 +62,7 @@ function scanDocuments(rootDir, llmdocDir, preloadIssues) {
59
62
  severity: "error",
60
63
  code: "file.extension.invalid",
61
64
  path: repoRelativePath,
62
- message: "llmdoc/ 下仅允许 .mdx 文档与根级唯一 meta.json。"
65
+ message: "llmdoc/ allows only .mdx documents and one root-level meta.json file."
63
66
  });
64
67
  }
65
68
  return;
@@ -74,7 +77,7 @@ function scanDocuments(rootDir, llmdocDir, preloadIssues) {
74
77
  severity: "error",
75
78
  code: "frontmatter.parse",
76
79
  path: repoRelativePath,
77
- message: `front matter 解析失败: ${error.message}`
80
+ message: `Front matter parse failed: ${error.message}`
78
81
  });
79
82
  return;
80
83
  }
@@ -125,7 +128,7 @@ function loadMeta(metaPath, preloadIssues) {
125
128
  severity: "error",
126
129
  code: "meta.parse",
127
130
  path: "llmdoc/meta.json",
128
- message: `meta.json 解析失败: ${error.message}`
131
+ message: `meta.json parse failed: ${error.message}`
129
132
  });
130
133
  return null;
131
134
  }
@@ -136,7 +139,7 @@ function loadMeta(metaPath, preloadIssues) {
136
139
  severity: "error",
137
140
  code: "meta.invalid",
138
141
  path: "llmdoc/meta.json",
139
- message: `meta.json 非法: ${error}`
142
+ message: `Invalid meta.json: ${error}`
140
143
  });
141
144
  }
142
145
  return null;
@@ -145,13 +148,14 @@ function loadMeta(metaPath, preloadIssues) {
145
148
  }
146
149
  export function validateWorkspace(workspace) {
147
150
  const issues = [...workspace.preloadIssues];
151
+ issues.push(...workspace.llmdocConfig.issues);
148
152
  const seenDocPaths = new Set();
149
153
  if (!workspace.meta) {
150
154
  issues.push({
151
155
  severity: "error",
152
156
  code: "meta.missing",
153
157
  path: "llmdoc/meta.json",
154
- message: "缺少 llmdoc/meta.json。"
158
+ 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
159
  });
156
160
  }
157
161
  for (const document of workspace.documents) {
@@ -162,7 +166,7 @@ export function validateWorkspace(workspace) {
162
166
  severity: "error",
163
167
  code: "frontmatter.invalid",
164
168
  path: document.repoPath,
165
- message: `front matter 非法: ${error}`
169
+ message: `Invalid front matter: ${error}`
166
170
  });
167
171
  }
168
172
  try {
@@ -183,7 +187,7 @@ export function validateWorkspace(workspace) {
183
187
  severity: "error",
184
188
  code: "hierarchy.nested",
185
189
  path: document.repoPath,
186
- message: "topic 下不允许继续嵌套子目录。"
190
+ message: "A topic cannot contain nested subdirectories."
187
191
  });
188
192
  }
189
193
  const mdxBodyErrors = validateMdxBody(document.body);
@@ -200,7 +204,7 @@ export function validateWorkspace(workspace) {
200
204
  severity: "warning",
201
205
  code: "link.wikilink",
202
206
  path: document.repoPath,
203
- message: "正文包含 [[wikilink]] 语法;llmdoc 不解析它,请改用标准 Markdown 相对链接。"
207
+ message: "The body contains [[wikilink]] syntax, which llmdoc does not parse. Use a standard relative Markdown link."
204
208
  });
205
209
  }
206
210
  for (const relationPath of document.frontmatter.relations?.requires ?? []) {
@@ -218,7 +222,7 @@ export function validateWorkspace(workspace) {
218
222
  severity: "error",
219
223
  code: "relations.requires.missing",
220
224
  path: document.repoPath,
221
- message: `requires 指向不存在的文档: ${relationPath}`
225
+ message: `requires points to a missing document: ${relationPath}`
222
226
  });
223
227
  }
224
228
  }
@@ -237,7 +241,7 @@ export function validateWorkspace(workspace) {
237
241
  severity: "error",
238
242
  code: "relations.related.missing",
239
243
  path: document.repoPath,
240
- message: `related 指向不存在的文档: ${relationPath}`
244
+ message: `related points to a missing document: ${relationPath}`
241
245
  });
242
246
  }
243
247
  }
@@ -249,7 +253,7 @@ export function validateWorkspace(workspace) {
249
253
  severity: "error",
250
254
  code: "link.invalid-path",
251
255
  path: document.repoPath,
252
- message: `正文链接非法: ${linkTarget} (${normalizedLink.message})`
256
+ message: `Invalid body link: ${linkTarget} (${normalizedLink.message})`
253
257
  });
254
258
  }
255
259
  else if (!workspace.documentsByLlmdocPath.has(normalizedLink.value)) {
@@ -257,7 +261,7 @@ export function validateWorkspace(workspace) {
257
261
  severity: "error",
258
262
  code: "link.missing",
259
263
  path: document.repoPath,
260
- message: `正文链接悬空: ${linkTarget}`
264
+ message: `Body link points to a missing document: ${linkTarget}`
261
265
  });
262
266
  }
263
267
  }
@@ -276,7 +280,7 @@ export function validateWorkspace(workspace) {
276
280
  severity: "error",
277
281
  code: "coderef.path.missing",
278
282
  path: document.repoPath,
279
- message: `CodeRef path 不存在: ${codeRef.path}`
283
+ message: `CodeRef path does not exist: ${codeRef.path}`
280
284
  });
281
285
  }
282
286
  }
@@ -295,7 +299,7 @@ export function validateWorkspace(workspace) {
295
299
  severity: "error",
296
300
  code: "code.paths.missing",
297
301
  path: document.repoPath,
298
- message: `code.paths 指向不存在的路径: ${codePath}`
302
+ message: `code.paths points to a missing path: ${codePath}`
299
303
  });
300
304
  }
301
305
  else if (normalized.isGlob &&
@@ -304,7 +308,7 @@ export function validateWorkspace(workspace) {
304
308
  severity: "error",
305
309
  code: "code.paths.unmatched",
306
310
  path: document.repoPath,
307
- message: `code.paths glob 未命中任何现有文件: ${codePath}`
311
+ message: `code.paths glob matches no existing files: ${codePath}`
308
312
  });
309
313
  }
310
314
  }
@@ -313,7 +317,7 @@ export function validateWorkspace(workspace) {
313
317
  severity: "warning",
314
318
  code: "size.line-warning",
315
319
  path: document.repoPath,
316
- message: `文档 ${document.lineCount} 行,超过建议上限 ${DOC_LINE_WARNING_LIMIT} 行。`
320
+ message: `The document has ${document.lineCount} lines, exceeding the recommended limit of ${DOC_LINE_WARNING_LIMIT}.`
317
321
  });
318
322
  }
319
323
  }
@@ -323,7 +327,7 @@ export function validateWorkspace(workspace) {
323
327
  severity: "warning",
324
328
  code: "topic.empty",
325
329
  path: `llmdoc/${topic}`,
326
- message: "topic 目录为空。"
330
+ message: "The topic directory is empty."
327
331
  });
328
332
  }
329
333
  }
@@ -332,13 +336,13 @@ export function validateWorkspace(workspace) {
332
336
  // 否则任何 fetch-depth:1 的 CI 都会误报陈旧。
333
337
  const shallow = isShallowRepository(workspace.rootDir);
334
338
  const revisionSeverity = shallow ? "warning" : "error";
335
- const shallowHint = shallow ? "(shallow clone;完整校验请用 fetch-depth: 0 或 git fetch --unshallow)" : "";
339
+ const shallowHint = shallow ? " (shallow clone; use fetch-depth: 0 or git fetch --unshallow for complete validation)" : "";
336
340
  if (!gitCommitExists(workspace.rootDir, workspace.meta.baseline.revision)) {
337
341
  issues.push({
338
342
  severity: revisionSeverity,
339
343
  code: "meta.baseline.revision.missing",
340
344
  path: "llmdoc/meta.json",
341
- message: `baseline.revision 不存在于当前 git 历史: ${workspace.meta.baseline.revision}${shallowHint}`
345
+ message: `baseline.revision does not exist in current Git history: ${workspace.meta.baseline.revision}${shallowHint}`
342
346
  });
343
347
  }
344
348
  const metaPaths = Object.keys(workspace.meta.documents).sort();
@@ -349,7 +353,7 @@ export function validateWorkspace(workspace) {
349
353
  severity: "error",
350
354
  code: "meta.entry.missing",
351
355
  path: `llmdoc/${docPath}`,
352
- message: "meta.json 缺少对应 documents entry。可用 `llmdoc adopt <path>` 无损登记。"
356
+ message: "meta.json is missing the corresponding documents entry. Use `llmdoc adopt <path>` to register it without rewriting the document."
353
357
  });
354
358
  }
355
359
  }
@@ -359,7 +363,7 @@ export function validateWorkspace(workspace) {
359
363
  severity: "error",
360
364
  code: "meta.entry.orphaned",
361
365
  path: `llmdoc/${metaPath}`,
362
- message: "meta.json 中存在孤儿 documents entry。"
366
+ message: "meta.json contains an orphan documents entry."
363
367
  });
364
368
  }
365
369
  const revision = workspace.meta.documents[metaPath]?.validatedRevision;
@@ -368,7 +372,7 @@ export function validateWorkspace(workspace) {
368
372
  severity: revisionSeverity,
369
373
  code: "meta.document.revision.missing",
370
374
  path: `llmdoc/${metaPath}`,
371
- message: `validatedRevision 不存在于当前 git 历史: ${revision}${shallowHint}`
375
+ message: `validatedRevision does not exist in current Git history: ${revision}${shallowHint}`
372
376
  });
373
377
  }
374
378
  }
@@ -382,13 +386,13 @@ function validateMdxBody(body) {
382
386
  const cleanBody = stripMarkdownLiterals(body);
383
387
  const issues = [];
384
388
  if (/^\s*import\s+/m.test(cleanBody) || /^\s*export\s+/m.test(cleanBody)) {
385
- issues.push("仅允许纯 Markdown 与自闭合 CodeRef,禁止 import/export。");
389
+ issues.push("Only plain Markdown and self-closing CodeRef tags are allowed; import/export is forbidden.");
386
390
  }
387
391
  if (/<(?!CodeRef\b)[A-Za-z][^>]*>/m.test(cleanBody) || /<\/[A-Za-z][^>]*>/m.test(cleanBody)) {
388
- issues.push("仅允许自闭合 <CodeRef ... /> 组件,禁止任意 JSX 标签。");
392
+ issues.push("Only self-closing <CodeRef ... /> components are allowed; arbitrary JSX tags are forbidden.");
389
393
  }
390
394
  if (/\{[^}\n]+\}/m.test(cleanBody)) {
391
- issues.push("禁止在正文中使用 MDX/JS 表达式。");
395
+ issues.push("MDX/JS expressions are forbidden in document bodies.");
392
396
  }
393
397
  issues.push(...validateCodeRefTags(body));
394
398
  return [...new Set(issues)];
@@ -397,10 +401,10 @@ function validateLlmdocRelativePath(input) {
397
401
  try {
398
402
  const normalized = normalizeRepoRelativePath(input);
399
403
  if (!normalized.endsWith(".mdx")) {
400
- return { ok: false, message: `路径必须指向 .mdx 文档: ${input}` };
404
+ return { ok: false, message: `Path must point to an .mdx document: ${input}` };
401
405
  }
402
406
  if (normalized.startsWith("llmdoc/")) {
403
- return { ok: false, message: `路径必须是 llmdoc/ 下相对路径而非仓库根路径: ${input}` };
407
+ return { ok: false, message: `Path must be relative to llmdoc/, not the repository root: ${input}` };
404
408
  }
405
409
  return { ok: true, value: normalized };
406
410
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenroll/llmdoc",
3
- "version": "3.5.2",
3
+ "version": "3.6.0",
4
4
  "description": "V3 runtime CLI for llmdoc repositories",
5
5
  "homepage": "https://github.com/TokenRollAI/llmdoc",
6
6
  "repository": {
@@ -0,0 +1,34 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://llmdoc.tokenroll.ai/schemas/config.schema.json",
4
+ "type": "object",
5
+ "additionalProperties": false,
6
+ "required": ["schema"],
7
+ "properties": {
8
+ "$schema": {
9
+ "type": "string"
10
+ },
11
+ "schema": {
12
+ "type": "string",
13
+ "const": "llmdoc.config/v1"
14
+ },
15
+ "startup": {
16
+ "type": "object",
17
+ "additionalProperties": false,
18
+ "properties": {
19
+ "remindSkill": {
20
+ "type": "boolean",
21
+ "default": true
22
+ },
23
+ "preload": {
24
+ "type": "array",
25
+ "items": {
26
+ "type": "string",
27
+ "minLength": 1
28
+ },
29
+ "default": []
30
+ }
31
+ }
32
+ }
33
+ }
34
+ }
@@ -374,6 +374,7 @@
374
374
  "additionalProperties": false,
375
375
  "required": [
376
376
  "query",
377
+ "searchMode",
377
378
  "results",
378
379
  "pagination"
379
380
  ],
@@ -382,6 +383,13 @@
382
383
  "type": "string",
383
384
  "minLength": 1
384
385
  },
386
+ "searchMode": {
387
+ "type": "string",
388
+ "enum": [
389
+ "lexical",
390
+ "cjk-bigram-fallback"
391
+ ]
392
+ },
385
393
  "results": {
386
394
  "type": "array",
387
395
  "items": {
@@ -719,6 +727,7 @@
719
727
  "status",
720
728
  "writable",
721
729
  "growth",
730
+ "startupPreloads",
722
731
  "duplicateCandidates",
723
732
  "mergeCandidates"
724
733
  ],
@@ -734,6 +743,13 @@
734
743
  "growth": {
735
744
  "$ref": "#/$defs/growth"
736
745
  },
746
+ "startupPreloads": {
747
+ "type": "array",
748
+ "items": {
749
+ "type": "string",
750
+ "minLength": 1
751
+ }
752
+ },
737
753
  "duplicateCandidates": {
738
754
  "type": "array",
739
755
  "items": {
@@ -859,12 +875,19 @@
859
875
  "type": "object",
860
876
  "additionalProperties": false,
861
877
  "required": [
862
- "created"
878
+ "created",
879
+ "next"
863
880
  ],
864
881
  "properties": {
865
882
  "created": {
866
883
  "type": "string",
867
884
  "minLength": 1
885
+ },
886
+ "next": {
887
+ "type": [
888
+ "string",
889
+ "null"
890
+ ]
868
891
  }
869
892
  }
870
893
  },
@@ -897,6 +920,7 @@
897
920
  "additionalProperties": false,
898
921
  "required": [
899
922
  "moved",
923
+ "rewrittenConfig",
900
924
  "rewrittenDocuments"
901
925
  ],
902
926
  "properties": {
@@ -924,6 +948,9 @@
924
948
  "type": "string",
925
949
  "minLength": 1
926
950
  }
951
+ },
952
+ "rewrittenConfig": {
953
+ "type": "boolean"
927
954
  }
928
955
  }
929
956
  },