@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.
- package/assets/viewer-app.js +11 -11
- package/assets/viewer-detail.js +4 -4
- package/assets/viewer-graph.js +3 -3
- package/assets/viewer.html +19 -19
- package/dist/cli.js +147 -71
- package/dist/commands/adopt.js +10 -6
- package/dist/commands/commit.js +232 -80
- package/dist/commands/context.js +85 -45
- package/dist/commands/dream.js +608 -0
- package/dist/commands/eval.js +379 -0
- package/dist/commands/fingerprint.js +9 -3
- package/dist/commands/hook.js +135 -28
- package/dist/commands/index.js +52 -7
- package/dist/commands/init-state.js +5 -5
- package/dist/commands/mv.js +33 -12
- package/dist/commands/new.js +12 -5
- package/dist/commands/prune.js +14 -3
- package/dist/commands/search.js +67 -4
- package/dist/commands/serve.js +1 -1
- package/dist/commands/show.js +40 -6
- package/dist/commands/status.js +46 -18
- package/dist/commands/tree.js +94 -6
- package/dist/commands/upgrade.js +15 -15
- package/dist/lib/config.js +502 -0
- package/dist/lib/constants.js +23 -0
- package/dist/lib/doc-shape.js +5 -5
- package/dist/lib/frontmatter.js +47 -0
- package/dist/lib/fs.js +8 -8
- package/dist/lib/git.js +147 -42
- package/dist/lib/markdown.js +8 -7
- package/dist/lib/output-schema.js +3 -3
- package/dist/lib/package-root.js +1 -1
- package/dist/lib/pagination.js +2 -2
- package/dist/lib/rewrite.js +9 -3
- package/dist/lib/routing.js +152 -0
- package/dist/lib/schema.js +16 -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 +74 -25
- package/dist/lib/telemetry.js +726 -0
- package/dist/lib/viewer-http.js +2 -2
- package/dist/lib/workspace.js +187 -43
- package/package.json +1 -1
- package/schemas/config.schema.json +116 -0
- package/schemas/meta.schema.json +5 -1
- package/schemas/output.schema.json +442 -0
- package/schemas/probes.schema.json +90 -0
package/dist/commands/tree.js
CHANGED
|
@@ -2,11 +2,15 @@ import { paginate, paginationMetadata } from "../lib/pagination.js";
|
|
|
2
2
|
import { loadWorkspace } from "../lib/workspace.js";
|
|
3
3
|
import { formatPaginationSummary } from "../lib/format.js";
|
|
4
4
|
import { estimateTokens } from "../lib/markdown.js";
|
|
5
|
+
import { formatDocumentPath } from "../lib/source-id.js";
|
|
6
|
+
import { toSourceSummary } from "../lib/sources.js";
|
|
5
7
|
export function runTree(options) {
|
|
6
8
|
const workspace = loadWorkspace(options.cwd);
|
|
9
|
+
const sourceSummaries = workspace.sources.map(toSourceSummary);
|
|
7
10
|
if (options.docs) {
|
|
11
|
+
const allDocuments = [...workspace.documents, ...workspace.sourceDocuments];
|
|
8
12
|
const result = paginate({
|
|
9
|
-
items:
|
|
13
|
+
items: allDocuments,
|
|
10
14
|
estimate: (document) => estimateTokens(JSON.stringify(toDocumentSummary(document))),
|
|
11
15
|
options
|
|
12
16
|
});
|
|
@@ -14,14 +18,28 @@ export function runTree(options) {
|
|
|
14
18
|
return {
|
|
15
19
|
root: "llmdoc",
|
|
16
20
|
documents: result.items.map(toDocumentSummary),
|
|
21
|
+
...(sourceSummaries.length > 0 ? { sources: sourceSummaries } : {}),
|
|
17
22
|
pagination: paginationMetadata(result)
|
|
18
23
|
};
|
|
19
24
|
}
|
|
20
25
|
const lines = [`llmdoc/ (${workspace.documents.length} docs, ~${workspace.documents.reduce((sum, document) => sum + document.estimatedTokens, 0)} tokens)`, ""];
|
|
21
|
-
|
|
26
|
+
const localItems = result.items.filter((document) => !document.sourceName);
|
|
27
|
+
const sourceItems = result.items.filter((document) => Boolean(document.sourceName));
|
|
28
|
+
for (const document of localItems) {
|
|
22
29
|
lines.push(` ${document.llmdocPath} [${document.frontmatter.kind}]`);
|
|
23
30
|
lines.push(` ${document.frontmatter.description}`);
|
|
24
31
|
}
|
|
32
|
+
if (sourceItems.length > 0) {
|
|
33
|
+
const sourceTokens = sourceItems.reduce((sum, document) => sum + document.estimatedTokens, 0);
|
|
34
|
+
lines.push("", `external sources/ (${sourceItems.length} shown of ${workspace.sourceDocuments.length} docs, ~${sourceTokens} tokens)`, "");
|
|
35
|
+
for (const document of sourceItems) {
|
|
36
|
+
lines.push(` ${document.llmdocPath} [${document.frontmatter.kind}]`);
|
|
37
|
+
lines.push(` ${document.frontmatter.description}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (workspace.sources.length > 0) {
|
|
41
|
+
lines.push("", ...formatSourcesSection(workspace.sources));
|
|
42
|
+
}
|
|
25
43
|
lines.push("", ...formatPaginationSummary(result));
|
|
26
44
|
return lines.join("\n");
|
|
27
45
|
}
|
|
@@ -53,6 +71,7 @@ export function runTree(options) {
|
|
|
53
71
|
.filter((entry) => entry.type === "rootSingleton")
|
|
54
72
|
.map((entry) => toRootSingletonSummary(entry.document)),
|
|
55
73
|
topics: result.items.filter((entry) => entry.type === "topic").map((entry) => toTopicSummary(entry.topic)),
|
|
74
|
+
...(sourceSummaries.length > 0 ? { sources: sourceSummaries } : {}),
|
|
56
75
|
pagination: paginationMetadata(result)
|
|
57
76
|
};
|
|
58
77
|
}
|
|
@@ -67,21 +86,90 @@ export function runTree(options) {
|
|
|
67
86
|
lines.push(` ${entry.topic.topic}/ (${entry.topic.docs.length} docs, ~${entry.topic.estimatedTokens} tokens)`);
|
|
68
87
|
lines.push(` ${entry.topic.summary}`);
|
|
69
88
|
}
|
|
89
|
+
if (workspace.sources.length > 0) {
|
|
90
|
+
lines.push("", ...formatSourcesSection(workspace.sources));
|
|
91
|
+
}
|
|
70
92
|
lines.push("", ...formatPaginationSummary(result));
|
|
71
|
-
|
|
93
|
+
if (workspace.sources.length > 0) {
|
|
94
|
+
const firstSource = workspace.sources[0].name;
|
|
95
|
+
lines.push(`hint: use \`npx -y @tokenroll/llmdoc tree --docs\` to expand documents; \`... index --topic @${firstSource}\` to inspect a source; \`... status --refresh\` to sync git sources`);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
lines.push("hint: use `npx -y @tokenroll/llmdoc tree --docs` to expand documents; use `... index --topic <t>` for metadata");
|
|
99
|
+
}
|
|
72
100
|
return lines.join("\n");
|
|
73
101
|
}
|
|
102
|
+
export function formatSourcesSection(sources) {
|
|
103
|
+
const lines = [`sources (${sources.length} configured)`];
|
|
104
|
+
for (const source of sources) {
|
|
105
|
+
const spec = source.kind === "git"
|
|
106
|
+
? `git ${source.target}${source.ref ? `#${source.ref}` : ""}${source.dir ? `:${source.dir}` : ""}`
|
|
107
|
+
: `path ${source.target}${source.dir ? `:${source.dir}` : ""}`;
|
|
108
|
+
if (source.status === "ready") {
|
|
109
|
+
const details = [`${source.documents.length} doc(s)`];
|
|
110
|
+
if (source.kind === "git") {
|
|
111
|
+
if (source.lastSyncedAt) {
|
|
112
|
+
details.push(`synced ${formatRelativeAge(source.lastSyncedAt)}`);
|
|
113
|
+
}
|
|
114
|
+
if (source.stale) {
|
|
115
|
+
details.push("stale");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else if (source.isSubmodule) {
|
|
119
|
+
details.push("submodule");
|
|
120
|
+
}
|
|
121
|
+
if (source.revision) {
|
|
122
|
+
details.push(source.pinned ? `pinned at ${source.revision.slice(0, 7)}` : `at ${source.revision.slice(0, 7)}`);
|
|
123
|
+
}
|
|
124
|
+
lines.push(` @${source.name} ${spec} (${details.join(", ")})`);
|
|
125
|
+
if (source.error) {
|
|
126
|
+
lines.push(` warning: last refresh failed: ${source.error}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
lines.push(` @${source.name} ${spec} [${source.status}]`);
|
|
131
|
+
if (source.error) {
|
|
132
|
+
lines.push(` reason: ${source.error}`);
|
|
133
|
+
}
|
|
134
|
+
if (source.remedy) {
|
|
135
|
+
lines.push(` remedy: ${source.remedy}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return lines;
|
|
140
|
+
}
|
|
141
|
+
function formatRelativeAge(isoTimestamp) {
|
|
142
|
+
const timestamp = Date.parse(isoTimestamp);
|
|
143
|
+
if (Number.isNaN(timestamp)) {
|
|
144
|
+
return isoTimestamp;
|
|
145
|
+
}
|
|
146
|
+
const diffMs = Math.max(0, Date.now() - timestamp);
|
|
147
|
+
const diffMinutes = Math.floor(diffMs / 60_000);
|
|
148
|
+
if (diffMinutes < 1) {
|
|
149
|
+
return "just now";
|
|
150
|
+
}
|
|
151
|
+
if (diffMinutes < 60) {
|
|
152
|
+
return `${diffMinutes}m ago`;
|
|
153
|
+
}
|
|
154
|
+
const diffHours = Math.floor(diffMinutes / 60);
|
|
155
|
+
if (diffHours < 48) {
|
|
156
|
+
return `${diffHours}h ago`;
|
|
157
|
+
}
|
|
158
|
+
const diffDays = Math.floor(diffHours / 24);
|
|
159
|
+
return `${diffDays}d ago`;
|
|
160
|
+
}
|
|
74
161
|
function toDocumentSummary(document) {
|
|
75
162
|
return {
|
|
76
|
-
path:
|
|
163
|
+
path: formatDocumentPath(document),
|
|
77
164
|
kind: document.frontmatter.kind,
|
|
78
165
|
description: document.frontmatter.description,
|
|
79
|
-
topic: document.topic
|
|
166
|
+
topic: document.topic,
|
|
167
|
+
...(document.sourceName ? { source: document.sourceName } : {})
|
|
80
168
|
};
|
|
81
169
|
}
|
|
82
170
|
function toRootSingletonSummary(document) {
|
|
83
171
|
return {
|
|
84
|
-
path:
|
|
172
|
+
path: formatDocumentPath(document),
|
|
85
173
|
kind: document.frontmatter.kind,
|
|
86
174
|
description: document.frontmatter.description
|
|
87
175
|
};
|
package/dist/commands/upgrade.js
CHANGED
|
@@ -34,11 +34,11 @@ export async function runUpgrade(options) {
|
|
|
34
34
|
function inspectMissingLlmdoc() {
|
|
35
35
|
return {
|
|
36
36
|
status: "no_change",
|
|
37
|
-
summary: "
|
|
37
|
+
summary: "The repository has no llmdoc/ directory and no V2/V3 knowledge surface to upgrade.",
|
|
38
38
|
legacyPaths: [],
|
|
39
39
|
targetStructure: [],
|
|
40
40
|
requiresRecorderSemanticMigration: false,
|
|
41
|
-
notes: ["
|
|
41
|
+
notes: ["Use init, not upgrade, to create the first knowledge surface."]
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
function inspectLlmdocDirectory(llmdocDir) {
|
|
@@ -60,9 +60,9 @@ function inspectLlmdocDirectory(llmdocDir) {
|
|
|
60
60
|
if (errors.length > 0) {
|
|
61
61
|
return {
|
|
62
62
|
status: "dry_run",
|
|
63
|
-
summary: "
|
|
63
|
+
summary: "A partial V3 structure was detected, but the current knowledge surface failed V3 validation.",
|
|
64
64
|
legacyPaths: [],
|
|
65
|
-
targetStructure: ["
|
|
65
|
+
targetStructure: ["Repair the existing V3 structure before deciding whether upgrade is needed"],
|
|
66
66
|
requiresRecorderSemanticMigration: false,
|
|
67
67
|
notes: errors.slice(0, 5).map((issue) => `${issue.path ?? "unknown"}: ${issue.message}`)
|
|
68
68
|
};
|
|
@@ -71,41 +71,41 @@ function inspectLlmdocDirectory(llmdocDir) {
|
|
|
71
71
|
catch (error) {
|
|
72
72
|
return {
|
|
73
73
|
status: "dry_run",
|
|
74
|
-
summary: "
|
|
74
|
+
summary: "A partial V3 structure was detected, but the current knowledge surface cannot be loaded reliably.",
|
|
75
75
|
legacyPaths: [],
|
|
76
|
-
targetStructure: ["
|
|
76
|
+
targetStructure: ["Repair the existing V3 structure before deciding whether upgrade is needed"],
|
|
77
77
|
requiresRecorderSemanticMigration: false,
|
|
78
78
|
notes: [error.message]
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
return {
|
|
82
82
|
status: "no_change",
|
|
83
|
-
summary: "
|
|
83
|
+
summary: "The existing knowledge surface is already V3; no upgrade is needed.",
|
|
84
84
|
legacyPaths: [],
|
|
85
85
|
targetStructure: [],
|
|
86
86
|
requiresRecorderSemanticMigration: false,
|
|
87
|
-
notes: ["upgrade
|
|
87
|
+
notes: ["upgrade currently reports an inventory only and does not rewrite V3 knowledge."]
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
if (legacyPaths.length === 0 && !hasV3Meta && !hasMdx) {
|
|
91
91
|
return {
|
|
92
92
|
status: "dry_run",
|
|
93
|
-
summary: "
|
|
93
|
+
summary: "An llmdoc/ directory was found, but it has no definitive V2 or V3 structure markers.",
|
|
94
94
|
legacyPaths: [],
|
|
95
|
-
targetStructure: ["llmdoc/meta.json", "llmdoc/architecture.mdx", "llmdoc/<topic>/*.mdx (
|
|
95
|
+
targetStructure: ["llmdoc/meta.json", "llmdoc/architecture.mdx", "llmdoc/<topic>/*.mdx (plain directories, no index.mdx entry nodes)"],
|
|
96
96
|
requiresRecorderSemanticMigration: false,
|
|
97
|
-
notes: ["
|
|
97
|
+
notes: ["A human must confirm whether this directory is a legacy knowledge surface."]
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
return {
|
|
101
101
|
status: "dry_run",
|
|
102
|
-
summary: "
|
|
102
|
+
summary: "A legacy/V2 structure was detected; Recorder must perform the semantic migration to V3.",
|
|
103
103
|
legacyPaths,
|
|
104
|
-
targetStructure: ["llmdoc/meta.json", "llmdoc/architecture.mdx", "llmdoc/<topic>/*.mdx (
|
|
104
|
+
targetStructure: ["llmdoc/meta.json", "llmdoc/architecture.mdx", "llmdoc/<topic>/*.mdx (plain directories, no index.mdx entry nodes)"],
|
|
105
105
|
requiresRecorderSemanticMigration: true,
|
|
106
106
|
notes: [
|
|
107
|
-
hasV3Meta ? "
|
|
108
|
-
legacyPaths.includes("state/sync.md") ? "state/sync.md
|
|
107
|
+
hasV3Meta ? "Some V3 markers exist, but legacy structure remains; reconcile the boundary before migration." : "No complete V3 ledger was found; create a new meta.json baseline.",
|
|
108
|
+
legacyPaths.includes("state/sync.md") ? "Migrate state/sync.md to meta.json baseline.revision." : "No state/sync.md watermark was found."
|
|
109
109
|
]
|
|
110
110
|
};
|
|
111
111
|
}
|