@tokenroll/llmdoc 3.6.0 → 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.
- package/dist/cli.js +86 -10
- package/dist/commands/adopt.js +4 -0
- package/dist/commands/commit.js +224 -72
- package/dist/commands/context.js +84 -44
- package/dist/commands/dream.js +608 -0
- package/dist/commands/eval.js +379 -0
- package/dist/commands/fingerprint.js +6 -0
- package/dist/commands/hook.js +79 -6
- package/dist/commands/index.js +52 -7
- package/dist/commands/mv.js +8 -0
- package/dist/commands/new.js +7 -0
- package/dist/commands/prune.js +2 -1
- package/dist/commands/search.js +66 -3
- package/dist/commands/show.js +40 -6
- package/dist/commands/status.js +45 -17
- package/dist/commands/tree.js +94 -6
- package/dist/lib/config.js +403 -46
- package/dist/lib/constants.js +23 -0
- package/dist/lib/frontmatter.js +47 -0
- package/dist/lib/git.js +141 -36
- package/dist/lib/markdown.js +3 -2
- package/dist/lib/rewrite.js +9 -3
- package/dist/lib/routing.js +152 -0
- package/dist/lib/schema.js +8 -0
- package/dist/lib/search.js +35 -16
- package/dist/lib/source-id.js +49 -0
- package/dist/lib/sources.js +760 -0
- package/dist/lib/state.js +60 -12
- package/dist/lib/telemetry.js +726 -0
- package/dist/lib/workspace.js +157 -17
- package/package.json +1 -1
- package/schemas/config.schema.json +92 -10
- package/schemas/meta.schema.json +5 -1
- package/schemas/output.schema.json +430 -0
- package/schemas/probes.schema.json +90 -0
package/dist/commands/context.js
CHANGED
|
@@ -1,35 +1,43 @@
|
|
|
1
1
|
import { loadWorkspace } from "../lib/workspace.js";
|
|
2
|
-
import { matchesCodePathPattern } from "../lib/search.js";
|
|
3
2
|
import { CliError } from "../lib/errors.js";
|
|
4
3
|
import { formatPaginationSummary } from "../lib/format.js";
|
|
5
4
|
import { paginate, paginationMetadata } from "../lib/pagination.js";
|
|
6
|
-
import { normalizeRepoRelativePath, resolveInsideRoot } from "../lib/fs.js";
|
|
7
5
|
import { estimateTokens } from "../lib/markdown.js";
|
|
6
|
+
import { getDocumentRequires, matchLocalContextFiles, resolveContextFileInput, resolveContextFiles } from "../lib/routing.js";
|
|
7
|
+
import { formatDocumentPath, isSourceRef, parseSourceDocId } from "../lib/source-id.js";
|
|
8
|
+
import { ensureSourcesForRead } from "../lib/sources.js";
|
|
9
|
+
import { recordTelemetryEvent } from "../lib/telemetry.js";
|
|
8
10
|
export function runContext(options) {
|
|
9
11
|
if (options.files.length === 0) {
|
|
10
12
|
throw new CliError("context requires at least one --files input.");
|
|
11
13
|
}
|
|
12
14
|
const workspace = loadWorkspace(options.cwd);
|
|
13
|
-
const normalizedFiles = options.files.map((file) =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
const normalizedFiles = options.files.map((file) => resolveContextFileInput(workspace.rootDir, file));
|
|
16
|
+
const prematchedLocal = matchLocalContextFiles(workspace, normalizedFiles);
|
|
17
|
+
const { localImpacted, unmappedFiles } = prematchedLocal;
|
|
18
|
+
const warnings = [];
|
|
19
|
+
const warnedAliases = new Set();
|
|
20
|
+
const relevantGitAliases = collectRelevantGitAliases(workspace, localImpacted);
|
|
21
|
+
if (relevantGitAliases.length > 0) {
|
|
22
|
+
const cold = ensureSourcesForRead(workspace, relevantGitAliases);
|
|
23
|
+
warnings.push(...cold.warnings);
|
|
24
|
+
for (const alias of relevantGitAliases) {
|
|
25
|
+
const source = workspace.sourcesByName.get(alias);
|
|
26
|
+
if (source && source.status !== "ready") {
|
|
27
|
+
warnedAliases.add(alias);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
for (const source of workspace.sources) {
|
|
32
|
+
if (source.kind === "git" && source.status !== "ready" && !warnedAliases.has(source.name)) {
|
|
33
|
+
warnedAliases.add(source.name);
|
|
34
|
+
warnings.push(`Source @${source.name} was not searched because it is unavailable: ${source.error ?? "no local snapshot"}.${source.remedy ? ` ${source.remedy}` : ""}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const { sourceImpacted, impacted, prerequisites, missingPrerequisites } = resolveContextFiles(workspace, normalizedFiles, {
|
|
38
|
+
includeSources: true,
|
|
39
|
+
prematchedLocal
|
|
22
40
|
});
|
|
23
|
-
const documentsByFile = normalizedFiles.map((file) => ({
|
|
24
|
-
file,
|
|
25
|
-
documents: workspace.documents.filter((document) => (document.frontmatter.code?.paths ?? []).some((pattern) => matchesCodePathPattern(pattern, file.normalized)))
|
|
26
|
-
}));
|
|
27
|
-
const impactedPaths = new Set(documentsByFile.flatMap(({ documents }) => documents.map((document) => document.llmdocPath)));
|
|
28
|
-
const impacted = workspace.documents.filter((document) => impactedPaths.has(document.llmdocPath));
|
|
29
|
-
const unmappedFiles = documentsByFile
|
|
30
|
-
.filter(({ documents }) => documents.length === 0)
|
|
31
|
-
.map(({ file }) => file.normalized);
|
|
32
|
-
const prerequisites = collectRequires(workspace, impacted);
|
|
33
41
|
const rows = [
|
|
34
42
|
...impacted.map((document) => ({ role: "impacted", document })),
|
|
35
43
|
...prerequisites.map((document) => ({ role: "requires", document }))
|
|
@@ -39,53 +47,85 @@ export function runContext(options) {
|
|
|
39
47
|
estimate: (row) => estimateTokens(JSON.stringify({ role: row.role, ...toPayload(row.document) })),
|
|
40
48
|
options
|
|
41
49
|
});
|
|
50
|
+
recordTelemetryEvent(workspace.rootDir, {
|
|
51
|
+
type: "context",
|
|
52
|
+
docs: localImpacted.map((document) => document.llmdocPath),
|
|
53
|
+
unmapped: unmappedFiles
|
|
54
|
+
});
|
|
42
55
|
if (options.json) {
|
|
43
56
|
return {
|
|
44
57
|
impacted: result.items.filter((row) => row.role === "impacted").map((row) => toPayload(row.document)),
|
|
45
58
|
prerequisites: result.items.filter((row) => row.role === "requires").map((row) => toPayload(row.document)),
|
|
59
|
+
...(missingPrerequisites.length > 0 ? { missingPrerequisites } : {}),
|
|
46
60
|
unmappedFiles,
|
|
61
|
+
...(warnings.length > 0 ? { warnings } : {}),
|
|
47
62
|
pagination: paginationMetadata(result)
|
|
48
63
|
};
|
|
49
64
|
}
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
lines.push(
|
|
55
|
-
|
|
65
|
+
const impactedWord = impacted.length === 1 ? "document" : "documents";
|
|
66
|
+
const prereqWord = prerequisites.length === 1 ? "prerequisite" : "prerequisites";
|
|
67
|
+
const lines = [`${impacted.length} ${impactedWord} impacted, ${prerequisites.length} recommended ${prereqWord}:`];
|
|
68
|
+
if (result.items.length > 0) {
|
|
69
|
+
lines.push("");
|
|
70
|
+
for (const row of result.items) {
|
|
71
|
+
const prefix = row.role === "requires" ? " requires -> " : " ";
|
|
72
|
+
const document = row.document;
|
|
73
|
+
lines.push(`${prefix}${formatDocumentPath(document)} [${document.frontmatter.kind}]`);
|
|
74
|
+
lines.push(` ${document.frontmatter.description}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (missingPrerequisites.length > 0) {
|
|
78
|
+
lines.push("", `missing external prerequisites: ${missingPrerequisites.length}`);
|
|
79
|
+
for (const missing of missingPrerequisites) {
|
|
80
|
+
lines.push(` missing -> ${missing.path} (${missing.reason})`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (warnings.length > 0) {
|
|
84
|
+
lines.push("");
|
|
85
|
+
for (const warning of warnings) {
|
|
86
|
+
lines.push(`warning: ${warning}`);
|
|
87
|
+
}
|
|
56
88
|
}
|
|
57
|
-
|
|
89
|
+
const hasExternalHitsWithUnmapped = sourceImpacted.length > 0 && unmappedFiles.length > 0;
|
|
90
|
+
lines.push("", hasExternalHitsWithUnmapped
|
|
91
|
+
? `unmapped files: ${unmappedFiles.length} (no local llmdoc owner)`
|
|
92
|
+
: `unmapped files: ${unmappedFiles.length}`);
|
|
58
93
|
for (const file of unmappedFiles) {
|
|
59
94
|
lines.push(` unmapped -> ${file}`);
|
|
60
95
|
}
|
|
61
96
|
lines.push("", ...formatPaginationSummary(result));
|
|
62
97
|
return lines.join("\n");
|
|
63
98
|
}
|
|
64
|
-
function
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
99
|
+
function collectRelevantGitAliases(workspace, localImpacted) {
|
|
100
|
+
const aliases = new Set();
|
|
101
|
+
for (const source of workspace.sources) {
|
|
102
|
+
if (source.kind === "git" && source.status === "missing") {
|
|
103
|
+
aliases.add(source.name);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
for (const document of localImpacted) {
|
|
107
|
+
for (const req of getDocumentRequires(document)) {
|
|
108
|
+
if (!isSourceRef(req)) {
|
|
72
109
|
continue;
|
|
73
110
|
}
|
|
74
|
-
|
|
75
|
-
|
|
111
|
+
try {
|
|
112
|
+
const parsed = parseSourceDocId(req);
|
|
113
|
+
if (workspace.sourcesByName.get(parsed.alias)?.kind === "git") {
|
|
114
|
+
aliases.add(parsed.alias);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
76
118
|
continue;
|
|
77
119
|
}
|
|
78
|
-
seen.add(requirement);
|
|
79
|
-
results.push(next);
|
|
80
|
-
queue.push(next);
|
|
81
120
|
}
|
|
82
121
|
}
|
|
83
|
-
return
|
|
122
|
+
return [...aliases];
|
|
84
123
|
}
|
|
85
124
|
function toPayload(document) {
|
|
86
125
|
return {
|
|
87
|
-
path:
|
|
126
|
+
path: formatDocumentPath(document),
|
|
88
127
|
kind: document.frontmatter.kind,
|
|
89
|
-
description: document.frontmatter.description
|
|
128
|
+
description: document.frontmatter.description,
|
|
129
|
+
...(document.sourceName ? { source: document.sourceName } : {})
|
|
90
130
|
};
|
|
91
131
|
}
|