@tokenroll/llmdoc 3.1.1 → 3.2.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/fs.js +30 -2
- package/dist/lib/git.js +4 -0
- package/dist/lib/workspace.js +10 -5
- package/package.json +1 -1
package/dist/lib/fs.js
CHANGED
|
@@ -9,9 +9,29 @@ export function findProjectRoot(startDir) {
|
|
|
9
9
|
throw new CliError("未找到 llmdoc/ 目录,请在仓库内运行该命令。", 2);
|
|
10
10
|
}
|
|
11
11
|
export function findProjectRootOrNull(startDir) {
|
|
12
|
-
|
|
12
|
+
const start = path.resolve(startDir);
|
|
13
|
+
const gitRoot = findNearestGitRootOrNull(start);
|
|
14
|
+
if (gitRoot) {
|
|
15
|
+
return isDirectory(path.join(gitRoot, "llmdoc")) ? gitRoot : null;
|
|
16
|
+
}
|
|
17
|
+
// Git 是 llmdoc 有效性与 delta 语义的基础;这里只为仓库初始化前的
|
|
18
|
+
// 临时目录保留兼容回退。存在 Git 边界时绝不能越界命中同级仓库。
|
|
19
|
+
let current = start;
|
|
20
|
+
while (true) {
|
|
21
|
+
if (isDirectory(path.join(current, "llmdoc"))) {
|
|
22
|
+
return current;
|
|
23
|
+
}
|
|
24
|
+
const parent = path.dirname(current);
|
|
25
|
+
if (parent === current) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
current = parent;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function findNearestGitRootOrNull(startDir) {
|
|
32
|
+
let current = startDir;
|
|
13
33
|
while (true) {
|
|
14
|
-
if (fs.existsSync(path.join(current, "
|
|
34
|
+
if (fs.existsSync(path.join(current, ".git"))) {
|
|
15
35
|
return current;
|
|
16
36
|
}
|
|
17
37
|
const parent = path.dirname(current);
|
|
@@ -21,6 +41,14 @@ export function findProjectRootOrNull(startDir) {
|
|
|
21
41
|
current = parent;
|
|
22
42
|
}
|
|
23
43
|
}
|
|
44
|
+
function isDirectory(candidate) {
|
|
45
|
+
try {
|
|
46
|
+
return fs.statSync(candidate).isDirectory();
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
24
52
|
export function normalizeRepoRelativePath(input) {
|
|
25
53
|
const normalized = input.replaceAll("\\", "/");
|
|
26
54
|
if (!normalized || normalized.startsWith("/") || normalized.includes("\0")) {
|
package/dist/lib/git.js
CHANGED
|
@@ -26,6 +26,10 @@ export function gitCommitExists(rootDir, revision) {
|
|
|
26
26
|
});
|
|
27
27
|
return result.status === 0;
|
|
28
28
|
}
|
|
29
|
+
// shallow clone(CI 常态)里历史 commit 不可达,revision 校验需要据此降级而不是误报陈旧。
|
|
30
|
+
export function isShallowRepository(rootDir) {
|
|
31
|
+
return runGitSafe(rootDir, ["rev-parse", "--is-shallow-repository"]) === "true";
|
|
32
|
+
}
|
|
29
33
|
export function readGitState(rootDir, baselineRevision) {
|
|
30
34
|
if (!isGitRepository(rootDir)) {
|
|
31
35
|
return {
|
package/dist/lib/workspace.js
CHANGED
|
@@ -6,7 +6,7 @@ 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 } from "./git.js";
|
|
9
|
+
import { gitCommitExists, isShallowRepository } from "./git.js";
|
|
10
10
|
import { validateDocFrontmatter, validateMeta } from "./schema.js";
|
|
11
11
|
export function loadWorkspace(rootDir) {
|
|
12
12
|
const configuredLlmdocDir = path.join(rootDir, "llmdoc");
|
|
@@ -318,12 +318,17 @@ export function validateWorkspace(workspace) {
|
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
if (workspace.meta) {
|
|
321
|
+
// shallow clone 中历史 commit 天然不可达:revision 缺失降级为 warning,
|
|
322
|
+
// 否则任何 fetch-depth:1 的 CI 都会误报陈旧。
|
|
323
|
+
const shallow = isShallowRepository(workspace.rootDir);
|
|
324
|
+
const revisionSeverity = shallow ? "warning" : "error";
|
|
325
|
+
const shallowHint = shallow ? "(shallow clone;完整校验请用 fetch-depth: 0 或 git fetch --unshallow)" : "";
|
|
321
326
|
if (!gitCommitExists(workspace.rootDir, workspace.meta.baseline.revision)) {
|
|
322
327
|
issues.push({
|
|
323
|
-
severity:
|
|
328
|
+
severity: revisionSeverity,
|
|
324
329
|
code: "meta.baseline.revision.missing",
|
|
325
330
|
path: "llmdoc/meta.json",
|
|
326
|
-
message: `baseline.revision 不存在于当前 git 历史: ${workspace.meta.baseline.revision}`
|
|
331
|
+
message: `baseline.revision 不存在于当前 git 历史: ${workspace.meta.baseline.revision}${shallowHint}`
|
|
327
332
|
});
|
|
328
333
|
}
|
|
329
334
|
const metaPaths = Object.keys(workspace.meta.documents).sort();
|
|
@@ -350,10 +355,10 @@ export function validateWorkspace(workspace) {
|
|
|
350
355
|
const revision = workspace.meta.documents[metaPath]?.validatedRevision;
|
|
351
356
|
if (revision && !gitCommitExists(workspace.rootDir, revision)) {
|
|
352
357
|
issues.push({
|
|
353
|
-
severity:
|
|
358
|
+
severity: revisionSeverity,
|
|
354
359
|
code: "meta.document.revision.missing",
|
|
355
360
|
path: `llmdoc/${metaPath}`,
|
|
356
|
-
message: `validatedRevision 不存在于当前 git 历史: ${revision}`
|
|
361
|
+
message: `validatedRevision 不存在于当前 git 历史: ${revision}${shallowHint}`
|
|
357
362
|
});
|
|
358
363
|
}
|
|
359
364
|
}
|