@tokenroll/llmdoc 3.5.3 → 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/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 +68 -68
- package/dist/commands/adopt.js +6 -6
- package/dist/commands/commit.js +6 -6
- package/dist/commands/context.js +1 -1
- package/dist/commands/fingerprint.js +3 -3
- package/dist/commands/hook.js +62 -28
- package/dist/commands/init-state.js +5 -5
- package/dist/commands/mv.js +25 -12
- package/dist/commands/new.js +5 -5
- package/dist/commands/prune.js +13 -3
- package/dist/commands/search.js +1 -1
- package/dist/commands/serve.js +1 -1
- package/dist/commands/show.js +1 -1
- package/dist/commands/status.js +1 -1
- package/dist/commands/tree.js +1 -1
- package/dist/commands/upgrade.js +15 -15
- package/dist/lib/config.js +145 -0
- package/dist/lib/doc-shape.js +5 -5
- package/dist/lib/fs.js +8 -8
- package/dist/lib/git.js +6 -6
- package/dist/lib/markdown.js +5 -5
- 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/schema.js +8 -0
- package/dist/lib/state.js +16 -15
- package/dist/lib/viewer-http.js +2 -2
- package/dist/lib/workspace.js +32 -28
- package/package.json +1 -1
- package/schemas/config.schema.json +34 -0
- package/schemas/output.schema.json +12 -0
package/assets/viewer-app.js
CHANGED
|
@@ -58,7 +58,7 @@ async function loadState() {
|
|
|
58
58
|
const response = await fetch("/api/state", { headers: { accept: "application/json" } });
|
|
59
59
|
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
60
60
|
const nextState = await response.json();
|
|
61
|
-
if (!Array.isArray(nextState.nodes) || !Array.isArray(nextState.edges)) throw new Error("
|
|
61
|
+
if (!Array.isArray(nextState.nodes) || !Array.isArray(nextState.edges)) throw new Error("The server returned invalid state");
|
|
62
62
|
state = nextState;
|
|
63
63
|
topicColors = createTopicColors(state.nodes);
|
|
64
64
|
if (selectedDocument && !state.nodes.some((node) => node.path === selectedDocument)) selectedDocument = null;
|
|
@@ -83,15 +83,15 @@ function renderHeader() {
|
|
|
83
83
|
const baseline = state.baseline;
|
|
84
84
|
const shortRevision = baseline.revision?.slice(0, 7);
|
|
85
85
|
if (!baseline.revision) {
|
|
86
|
-
setChip(elements.statBaseline, "baseline
|
|
86
|
+
setChip(elements.statBaseline, "baseline missing", "bad");
|
|
87
87
|
} else if (baseline.degradedReason || baseline.relevantBehindHead === null) {
|
|
88
|
-
setChip(elements.statBaseline, `baseline ${shortRevision} ·
|
|
88
|
+
setChip(elements.statBaseline, `baseline ${shortRevision} · status unknown`, "warn");
|
|
89
89
|
} else if (baseline.relevantBehindHead > 0) {
|
|
90
|
-
setChip(elements.statBaseline, `baseline ${shortRevision} · ${baseline.relevantBehindHead}
|
|
90
|
+
setChip(elements.statBaseline, `baseline ${shortRevision} · ${baseline.relevantBehindHead} source commit(s) need review`, "warn");
|
|
91
91
|
} else if (baseline.metadataOnlyBehind) {
|
|
92
|
-
setChip(elements.statBaseline, `baseline ${shortRevision} · metadata-only
|
|
92
|
+
setChip(elements.statBaseline, `baseline ${shortRevision} · metadata-only, knowledge clean`, "ok");
|
|
93
93
|
} else {
|
|
94
|
-
setChip(elements.statBaseline, `baseline ${shortRevision} ·
|
|
94
|
+
setChip(elements.statBaseline, `baseline ${shortRevision} · current`, "ok");
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
const validation = state.validate;
|
|
@@ -103,9 +103,9 @@ function renderHeader() {
|
|
|
103
103
|
|
|
104
104
|
const stale = state.nodes.filter((node) => node.status !== "fresh").length;
|
|
105
105
|
const unmapped = state.delta.unmappedCommittedPaths.length + state.delta.unmappedDirtyPaths.length;
|
|
106
|
-
if (stale) setChip(elements.statDelta, `${stale}
|
|
107
|
-
else if (unmapped) setChip(elements.statDelta, `${unmapped}
|
|
108
|
-
else setChip(elements.statDelta, "
|
|
106
|
+
if (stale) setChip(elements.statDelta, `${stale} document(s) pending · ${state.delta.suggestedMode} recommended`, "warn");
|
|
107
|
+
else if (unmapped) setChip(elements.statDelta, `${unmapped} unmapped change(s) · ${state.delta.suggestedMode} recommended`, "warn");
|
|
108
|
+
else setChip(elements.statDelta, "knowledge is current", "ok");
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
function setChip(chip, text, stateClass) {
|
|
@@ -154,7 +154,7 @@ function renderSidebar() {
|
|
|
154
154
|
fragment.append(item);
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
if (!fragment.childNodes.length) fragment.append(element("div", "empty-list", "
|
|
157
|
+
if (!fragment.childNodes.length) fragment.append(element("div", "empty-list", "No matching documents"));
|
|
158
158
|
elements.documentList.replaceChildren(fragment);
|
|
159
159
|
}
|
|
160
160
|
|
|
@@ -195,7 +195,7 @@ async function selectDocument(path) {
|
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
function showError(message) {
|
|
198
|
-
elements.error.textContent = `Viewer
|
|
198
|
+
elements.error.textContent = `Viewer load failed: ${message}`;
|
|
199
199
|
elements.error.hidden = false;
|
|
200
200
|
}
|
|
201
201
|
|
package/assets/viewer-detail.js
CHANGED
|
@@ -9,7 +9,7 @@ const DROP_TAGS = new Set(["EMBED", "FORM", "IFRAME", "INPUT", "LINK", "META", "
|
|
|
9
9
|
export function createDetailRenderer({ panel, container, onSelectDocument, getState }) {
|
|
10
10
|
let activeRequest = null;
|
|
11
11
|
|
|
12
|
-
function showPlaceholder(message = "
|
|
12
|
+
function showPlaceholder(message = "Select a topic or document to view details") {
|
|
13
13
|
activeRequest?.abort();
|
|
14
14
|
const placeholder = element("div", "placeholder", message);
|
|
15
15
|
container.replaceChildren(placeholder);
|
|
@@ -31,7 +31,7 @@ export function createDetailRenderer({ panel, container, onSelectDocument, getSt
|
|
|
31
31
|
const description = element(
|
|
32
32
|
"div",
|
|
33
33
|
"desc",
|
|
34
|
-
`${documents.length} docs · ~${tokenCount} tokens ·
|
|
34
|
+
`${documents.length} docs · ~${tokenCount} tokens · worst status ${worstStatus(documents)}`
|
|
35
35
|
);
|
|
36
36
|
const cards = documents.map((node) => {
|
|
37
37
|
const card = element("button", "topic-doc-card");
|
|
@@ -52,7 +52,7 @@ export function createDetailRenderer({ panel, container, onSelectDocument, getSt
|
|
|
52
52
|
activeRequest?.abort();
|
|
53
53
|
activeRequest = new AbortController();
|
|
54
54
|
const request = activeRequest;
|
|
55
|
-
container.replaceChildren(element("div", "placeholder", "
|
|
55
|
+
container.replaceChildren(element("div", "placeholder", "Loading document…"));
|
|
56
56
|
openPanel();
|
|
57
57
|
|
|
58
58
|
try {
|
|
@@ -64,7 +64,7 @@ export function createDetailRenderer({ panel, container, onSelectDocument, getSt
|
|
|
64
64
|
} catch (error) {
|
|
65
65
|
if (error instanceof DOMException && error.name === "AbortError") return;
|
|
66
66
|
const message = error instanceof Error ? error.message : String(error);
|
|
67
|
-
container.replaceChildren(element("div", "placeholder",
|
|
67
|
+
container.replaceChildren(element("div", "placeholder", `Load failed: ${message}`));
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
package/assets/viewer-graph.js
CHANGED
|
@@ -332,11 +332,11 @@ export function createGraphController(options) {
|
|
|
332
332
|
|
|
333
333
|
function setGraphChrome(mode) {
|
|
334
334
|
hint.textContent = mode === "topics"
|
|
335
|
-
? "Topic
|
|
336
|
-
: "
|
|
335
|
+
? "Topic topology · edge width shows cross-domain references · click to drill down"
|
|
336
|
+
: "Document graph · click for details · drag to pan / scroll to zoom";
|
|
337
337
|
legend.replaceChildren();
|
|
338
338
|
const edgeItems = mode === "topics"
|
|
339
|
-
? [["", "
|
|
339
|
+
? [["", "Cross-domain references"]]
|
|
340
340
|
: [["", "requires"], ["related", "related"], ["link", "link"]];
|
|
341
341
|
for (const [className, label] of edgeItems) {
|
|
342
342
|
const item = document.createElement("span");
|
package/assets/viewer.html
CHANGED
|
@@ -12,46 +12,46 @@
|
|
|
12
12
|
<body>
|
|
13
13
|
<header class="app-header">
|
|
14
14
|
<h1>llmdoc <span class="repo" id="repo"></span></h1>
|
|
15
|
-
<div class="health-strip" aria-label="
|
|
15
|
+
<div class="health-strip" aria-label="Knowledge status">
|
|
16
16
|
<span class="chip" id="stat-docs"></span>
|
|
17
17
|
<span class="chip" id="stat-baseline"></span>
|
|
18
18
|
<span class="chip" id="stat-validate"></span>
|
|
19
19
|
<span class="chip" id="stat-delta"></span>
|
|
20
20
|
</div>
|
|
21
|
-
<button class="chip button" id="refresh" type="button" aria-label="
|
|
22
|
-
<div class="toggle" role="group" aria-label="
|
|
23
|
-
<button id="mode-topics" type="button">
|
|
24
|
-
<button id="mode-docs" type="button">
|
|
21
|
+
<button class="chip button" id="refresh" type="button" aria-label="Refresh knowledge">↻ Refresh</button>
|
|
22
|
+
<div class="toggle" role="group" aria-label="Graph display mode">
|
|
23
|
+
<button id="mode-topics" type="button">Topic topology</button>
|
|
24
|
+
<button id="mode-docs" type="button">All documents</button>
|
|
25
25
|
</div>
|
|
26
26
|
</header>
|
|
27
27
|
|
|
28
28
|
<div id="load-error" class="load-error" role="alert" hidden></div>
|
|
29
29
|
|
|
30
30
|
<main>
|
|
31
|
-
<nav id="sidebar" aria-label="llmdoc
|
|
31
|
+
<nav id="sidebar" aria-label="llmdoc document list">
|
|
32
32
|
<label class="search-box">
|
|
33
|
-
<span class="sr-only"
|
|
34
|
-
<input id="search" type="search" placeholder="
|
|
33
|
+
<span class="sr-only">Filter documents</span>
|
|
34
|
+
<input id="search" type="search" placeholder="Filter by path, title, or description" autocomplete="off" />
|
|
35
35
|
<kbd>/</kbd>
|
|
36
36
|
</label>
|
|
37
37
|
<div id="doc-list"></div>
|
|
38
38
|
</nav>
|
|
39
39
|
|
|
40
|
-
<section id="graph-wrap" aria-label="
|
|
41
|
-
<svg id="graph" role="application" tabindex="0" aria-label="
|
|
40
|
+
<section id="graph-wrap" aria-label="Knowledge relationship graph">
|
|
41
|
+
<svg id="graph" role="application" tabindex="0" aria-label="Knowledge graph; drag to pan, scroll to zoom, press 0 to reset"></svg>
|
|
42
42
|
<div id="graph-hint" aria-live="polite"></div>
|
|
43
|
-
<div id="graph-toolbar" role="group" aria-label="
|
|
44
|
-
<button id="zoom-out" type="button" title="
|
|
45
|
-
<button id="zoom-reset" type="button" title="
|
|
46
|
-
<button id="zoom-in" type="button" title="
|
|
43
|
+
<div id="graph-toolbar" role="group" aria-label="Graph zoom controls">
|
|
44
|
+
<button id="zoom-out" type="button" title="Zoom out">−</button>
|
|
45
|
+
<button id="zoom-reset" type="button" title="Reset view">Fit</button>
|
|
46
|
+
<button id="zoom-in" type="button" title="Zoom in">+</button>
|
|
47
47
|
</div>
|
|
48
|
-
<div id="legend" aria-label="
|
|
49
|
-
<div id="graph-empty" hidden
|
|
48
|
+
<div id="legend" aria-label="Legend"></div>
|
|
49
|
+
<div id="graph-empty" hidden>No documents to display</div>
|
|
50
50
|
</section>
|
|
51
51
|
|
|
52
|
-
<aside id="detail" aria-label="
|
|
53
|
-
<button id="detail-close" type="button" aria-label="
|
|
54
|
-
<div class="inner"><div class="placeholder"
|
|
52
|
+
<aside id="detail" aria-label="Document details">
|
|
53
|
+
<button id="detail-close" type="button" aria-label="Close details">×</button>
|
|
54
|
+
<div class="inner"><div class="placeholder">Select a topic or document to view details</div></div>
|
|
55
55
|
</aside>
|
|
56
56
|
</main>
|
|
57
57
|
</body>
|
package/dist/cli.js
CHANGED
|
@@ -43,38 +43,38 @@ export async function runCli(argv, cwd = process.cwd(), stdin = "") {
|
|
|
43
43
|
}
|
|
44
44
|
program
|
|
45
45
|
.name("llmdoc")
|
|
46
|
-
.description("
|
|
47
|
-
.version(readPackageVersion(), "--version", "
|
|
48
|
-
.helpOption("-h, --help", "
|
|
49
|
-
.helpCommand("help [command]", "
|
|
50
|
-
.showHelpAfterError("(
|
|
46
|
+
.description("Project knowledge CLI for LLMs: progressively retrieve llmdoc/ documents and maintain the revision ledger")
|
|
47
|
+
.version(readPackageVersion(), "--version", "output the CLI version")
|
|
48
|
+
.helpOption("-h, --help", "display help")
|
|
49
|
+
.helpCommand("help [command]", "display help for a command")
|
|
50
|
+
.showHelpAfterError("(use --help to view usage)");
|
|
51
51
|
program
|
|
52
|
-
.option("--json", "
|
|
53
|
-
.option("--cursor <cursor>", "
|
|
54
|
-
.option("--budget <tokens>", "
|
|
55
|
-
.option("--limit <n>", "
|
|
52
|
+
.option("--json", "emit schema-validated JSON")
|
|
53
|
+
.option("--cursor <cursor>", "continue from a cursor returned by a truncated response")
|
|
54
|
+
.option("--budget <tokens>", "truncate output at this token budget and return a cursor", parseInteger)
|
|
55
|
+
.option("--limit <n>", "maximum number of items to return", parseInteger);
|
|
56
56
|
program.addHelpText("after", [
|
|
57
57
|
"",
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
58
|
+
"Quick reference by purpose:",
|
|
59
|
+
" Retrieval (read-only) tree → index / search / context → show",
|
|
60
|
+
" State diagnostics status · delta · validate",
|
|
61
|
+
" Structural mutation new · adopt · mv · fingerprint · init-state · commit",
|
|
62
|
+
" Maintenance prune · upgrade",
|
|
63
|
+
" Integration hook · serve",
|
|
64
64
|
"",
|
|
65
|
-
"
|
|
66
|
-
" llmdoc tree --docs
|
|
67
|
-
" llmdoc search \"
|
|
68
|
-
" llmdoc context --files src/api/retry.ts
|
|
69
|
-
" llmdoc show api-client/retry-policy.mdx
|
|
70
|
-
" llmdoc commit -m \"docs: ...\"
|
|
65
|
+
"Common examples:",
|
|
66
|
+
" llmdoc tree --docs expand the global map to documents",
|
|
67
|
+
" llmdoc search \"retry policy\" --limit 5 search documents lexically",
|
|
68
|
+
" llmdoc context --files src/api/retry.ts map source files to documents to read",
|
|
69
|
+
" llmdoc show api-client/retry-policy.mdx read selected bodies",
|
|
70
|
+
" llmdoc commit -m \"docs: ...\" validate and commit the llmdoc write set",
|
|
71
71
|
"",
|
|
72
|
-
"
|
|
72
|
+
"All retrieval commands support --json / --budget / --limit; use --cursor to continue truncated output."
|
|
73
73
|
].join("\n"));
|
|
74
74
|
program
|
|
75
75
|
.command("tree")
|
|
76
|
-
.description("
|
|
77
|
-
.option("--docs", "
|
|
76
|
+
.description("output the global llmdoc map (topics by default)")
|
|
77
|
+
.option("--docs", "expand to document level")
|
|
78
78
|
.action((commandOptions) => {
|
|
79
79
|
const rootDir = findProjectRoot(cwd);
|
|
80
80
|
const result = runTree({ ...globalOptions, ...commandOptions, cwd: rootDir });
|
|
@@ -82,35 +82,35 @@ export async function runCli(argv, cwd = process.cwd(), stdin = "") {
|
|
|
82
82
|
});
|
|
83
83
|
program
|
|
84
84
|
.command("index")
|
|
85
|
-
.description("
|
|
86
|
-
.option("--topic <topic>", "
|
|
87
|
-
.option("--kind <kind>", "
|
|
85
|
+
.description("list document metadata without reading bodies")
|
|
86
|
+
.option("--topic <topic>", "list documents only under this topic")
|
|
87
|
+
.option("--kind <kind>", "filter by kind: architecture | guide | reference")
|
|
88
88
|
.action((commandOptions) => {
|
|
89
89
|
const rootDir = findProjectRoot(cwd);
|
|
90
90
|
output.push(writeOutput("index", runIndex({ ...globalOptions, ...commandOptions, cwd: rootDir }), globalOptions.json));
|
|
91
91
|
});
|
|
92
92
|
program
|
|
93
93
|
.command("show")
|
|
94
|
-
.description("
|
|
95
|
-
.argument("<path...>", "llmdoc
|
|
94
|
+
.description("read one or more document bodies")
|
|
95
|
+
.argument("<path...>", "paths relative to llmdoc/, such as api-client/retry-policy.mdx")
|
|
96
96
|
.action((paths) => {
|
|
97
97
|
const rootDir = findProjectRoot(cwd);
|
|
98
98
|
output.push(writeOutput("show", runShow({ ...globalOptions, cwd: rootDir, paths }), globalOptions.json));
|
|
99
99
|
});
|
|
100
100
|
program
|
|
101
101
|
.command("search")
|
|
102
|
-
.description("
|
|
103
|
-
.argument("<query>", "
|
|
104
|
-
.option("--topic <topic>", "
|
|
105
|
-
.option("--kind <kind>", "
|
|
102
|
+
.description("search llmdoc documents lexically (Chinese segmentation with CJK bigram fallback)")
|
|
103
|
+
.argument("<query>", "search query")
|
|
104
|
+
.option("--topic <topic>", "limit to a topic")
|
|
105
|
+
.option("--kind <kind>", "filter by kind: architecture | guide | reference")
|
|
106
106
|
.action((query, commandOptions) => {
|
|
107
107
|
const rootDir = findProjectRoot(cwd);
|
|
108
108
|
output.push(writeOutput("search", runSearch({ ...globalOptions, ...commandOptions, cwd: rootDir, query }), globalOptions.json));
|
|
109
109
|
});
|
|
110
110
|
program
|
|
111
111
|
.command("context")
|
|
112
|
-
.description("
|
|
113
|
-
.requiredOption("--files <files...>", "
|
|
112
|
+
.description("map source files to documents to read, including the requires closure")
|
|
113
|
+
.requiredOption("--files <files...>", "one or more source file paths")
|
|
114
114
|
.action((commandOptions) => {
|
|
115
115
|
const rootDir = findProjectRoot(cwd);
|
|
116
116
|
output.push(writeOutput("context", runContext({
|
|
@@ -121,7 +121,7 @@ export async function runCli(argv, cwd = process.cwd(), stdin = "") {
|
|
|
121
121
|
});
|
|
122
122
|
program
|
|
123
123
|
.command("validate")
|
|
124
|
-
.description("
|
|
124
|
+
.description("validate llmdoc structure and references")
|
|
125
125
|
.action((commandOptions) => {
|
|
126
126
|
const rootDir = findProjectRoot(cwd);
|
|
127
127
|
const result = runValidate({ ...globalOptions, ...commandOptions, cwd: rootDir });
|
|
@@ -130,24 +130,24 @@ export async function runCli(argv, cwd = process.cwd(), stdin = "") {
|
|
|
130
130
|
});
|
|
131
131
|
program
|
|
132
132
|
.command("status")
|
|
133
|
-
.description("
|
|
133
|
+
.description("inspect baseline, dirty, and growth state")
|
|
134
134
|
.action((commandOptions) => {
|
|
135
135
|
const rootDir = findProjectRoot(cwd);
|
|
136
136
|
output.push(writeOutput("status", runStatus({ ...globalOptions, ...commandOptions, cwd: rootDir }), globalOptions.json));
|
|
137
137
|
});
|
|
138
138
|
program
|
|
139
139
|
.command("delta")
|
|
140
|
-
.description("
|
|
141
|
-
.option("--scope <scope...>", "
|
|
140
|
+
.description("inspect document impacts from code changes and choose light or deep update mode")
|
|
141
|
+
.option("--scope <scope...>", "limit comparison to selected topics or documents")
|
|
142
142
|
.action((commandOptions) => {
|
|
143
143
|
const rootDir = findProjectRoot(cwd);
|
|
144
144
|
output.push(writeOutput("delta", runDelta({ ...globalOptions, ...commandOptions, cwd: rootDir }), globalOptions.json));
|
|
145
145
|
});
|
|
146
146
|
program
|
|
147
147
|
.command("fingerprint")
|
|
148
|
-
.description("
|
|
149
|
-
.option("--update <path...>", "
|
|
150
|
-
.option("--all", "
|
|
148
|
+
.description("refresh document validatedRevision values to the current HEAD")
|
|
149
|
+
.option("--update <path...>", "refresh only selected documents")
|
|
150
|
+
.option("--all", "refresh every document and advance the baseline")
|
|
151
151
|
.action((commandOptions) => {
|
|
152
152
|
const rootDir = findProjectRoot(cwd);
|
|
153
153
|
output.push(writeOutput("fingerprint", runFingerprint({
|
|
@@ -159,8 +159,8 @@ export async function runCli(argv, cwd = process.cwd(), stdin = "") {
|
|
|
159
159
|
});
|
|
160
160
|
program
|
|
161
161
|
.command("init-state")
|
|
162
|
-
.description("
|
|
163
|
-
.addHelpText("after", "\
|
|
162
|
+
.description("create the initial llmdoc/meta.json ledger with null validatedRevision values")
|
|
163
|
+
.addHelpText("after", "\nPrerequisite: Git HEAD must reference a real commit. Then run validate and finish bootstrap with commit --all.")
|
|
164
164
|
.action(async () => {
|
|
165
165
|
const { runInitState } = await import("./commands/init-state.js");
|
|
166
166
|
const rootDir = findProjectRoot(cwd);
|
|
@@ -168,11 +168,11 @@ export async function runCli(argv, cwd = process.cwd(), stdin = "") {
|
|
|
168
168
|
});
|
|
169
169
|
program
|
|
170
170
|
.command("commit")
|
|
171
|
-
.description("
|
|
171
|
+
.description("finalize atomically: validate, optionally commit prose, refresh revisions, and commit metadata")
|
|
172
172
|
.option("-m, --message <message>", "docs commit message")
|
|
173
|
-
.option("--all", "fingerprint
|
|
174
|
-
.option("--verified <paths...>", "
|
|
175
|
-
.option("--no-verify", "
|
|
173
|
+
.option("--all", "fingerprint every document and advance the baseline")
|
|
174
|
+
.option("--verified <paths...>", "refresh validatedRevision for reviewed documents whose bodies did not change")
|
|
175
|
+
.option("--no-verify", "pass --no-verify through to git commit")
|
|
176
176
|
.action(async (commandOptions) => {
|
|
177
177
|
const { runCommit } = await import("./commands/commit.js");
|
|
178
178
|
const rootDir = findProjectRoot(cwd);
|
|
@@ -187,11 +187,11 @@ export async function runCli(argv, cwd = process.cwd(), stdin = "") {
|
|
|
187
187
|
});
|
|
188
188
|
program
|
|
189
189
|
.command("new")
|
|
190
|
-
.description("
|
|
191
|
-
.argument("<path>", "
|
|
192
|
-
.requiredOption("--kind <kind>", "
|
|
193
|
-
.option("--description <description>", "front matter
|
|
194
|
-
.addHelpText("after", "\
|
|
190
|
+
.description("scaffold a document under llmdoc/")
|
|
191
|
+
.argument("<path>", "target path, such as api-client/retry-policy.mdx")
|
|
192
|
+
.requiredOption("--kind <kind>", "document kind: architecture | guide | reference")
|
|
193
|
+
.option("--description <description>", "one-line front matter description")
|
|
194
|
+
.addHelpText("after", "\nThe first document creates llmdoc/ automatically. Finish bootstrap with init-state → validate → commit --all.")
|
|
195
195
|
.action((targetPath, commandOptions) => {
|
|
196
196
|
output.push(writeOutput("new", runNew({
|
|
197
197
|
...globalOptions,
|
|
@@ -203,8 +203,8 @@ export async function runCli(argv, cwd = process.cwd(), stdin = "") {
|
|
|
203
203
|
});
|
|
204
204
|
program
|
|
205
205
|
.command("adopt")
|
|
206
|
-
.description("
|
|
207
|
-
.argument("<path...>", "
|
|
206
|
+
.description("register existing .mdx documents in meta.json without rewriting them")
|
|
207
|
+
.argument("<path...>", "one or more existing paths under llmdoc/")
|
|
208
208
|
.action(async (paths) => {
|
|
209
209
|
const { runAdopt } = await import("./commands/adopt.js");
|
|
210
210
|
const rootDir = findProjectRoot(cwd);
|
|
@@ -212,55 +212,55 @@ export async function runCli(argv, cwd = process.cwd(), stdin = "") {
|
|
|
212
212
|
});
|
|
213
213
|
program
|
|
214
214
|
.command("mv")
|
|
215
|
-
.description("
|
|
216
|
-
.argument("<from>", "
|
|
217
|
-
.argument("<to>", "
|
|
215
|
+
.description("move or rename a document or topic and rewrite internal references")
|
|
216
|
+
.argument("<from>", "source path")
|
|
217
|
+
.argument("<to>", "target path")
|
|
218
218
|
.action((from, to) => {
|
|
219
219
|
const rootDir = findProjectRoot(cwd);
|
|
220
220
|
output.push(writeOutput("mv", runMove({ ...globalOptions, cwd: rootDir, from, to }), globalOptions.json));
|
|
221
221
|
});
|
|
222
222
|
program
|
|
223
223
|
.command("prune")
|
|
224
|
-
.description("
|
|
225
|
-
.option("--report", "
|
|
224
|
+
.description("output a read-only convergence report")
|
|
225
|
+
.option("--report", "output the read-only report")
|
|
226
226
|
.action((commandOptions) => {
|
|
227
227
|
const rootDir = findProjectRoot(cwd);
|
|
228
228
|
output.push(writeOutput("prune", runPrune({ ...globalOptions, cwd: rootDir, report: commandOptions.report }), globalOptions.json));
|
|
229
229
|
});
|
|
230
230
|
program
|
|
231
231
|
.command("upgrade")
|
|
232
|
-
.description("
|
|
232
|
+
.description("inventory legacy/V2 to V3 migration needs")
|
|
233
233
|
.action(async (commandOptions) => {
|
|
234
234
|
const { runUpgrade } = await import("./commands/upgrade.js");
|
|
235
235
|
const rootDir = findProjectRootOrNull(cwd) ?? cwd;
|
|
236
236
|
output.push(writeOutput("upgrade", await runUpgrade({ ...globalOptions, ...commandOptions, cwd: rootDir }), globalOptions.json));
|
|
237
237
|
});
|
|
238
|
-
const hookCommand = program.command("hook").description("
|
|
238
|
+
const hookCommand = program.command("hook").description("read-only, fail-open signals for editor and Agent hooks");
|
|
239
239
|
hookCommand
|
|
240
240
|
.command("session-start")
|
|
241
|
-
.description("
|
|
241
|
+
.description("output SessionStart state and apply optional llmdoc.config.json startup config")
|
|
242
242
|
.action(() => {
|
|
243
243
|
const rootDir = findProjectRootOrNull(cwd) ?? cwd;
|
|
244
244
|
output.push(runHook({ cwd: rootDir, mode: "session-start", stdin }));
|
|
245
245
|
});
|
|
246
246
|
hookCommand
|
|
247
247
|
.command("stop")
|
|
248
|
-
.description("
|
|
248
|
+
.description("output the Stop hook JSON reminder")
|
|
249
249
|
.action(() => {
|
|
250
250
|
const rootDir = findProjectRootOrNull(cwd) ?? cwd;
|
|
251
251
|
output.push(parseAndValidateJsonString("hook", runHook({ cwd: rootDir, mode: "stop", stdin })));
|
|
252
252
|
});
|
|
253
253
|
hookCommand
|
|
254
254
|
.command("compact")
|
|
255
|
-
.description("
|
|
255
|
+
.description("output the PreCompact hook JSON instruction")
|
|
256
256
|
.action(() => {
|
|
257
257
|
const rootDir = findProjectRootOrNull(cwd) ?? cwd;
|
|
258
258
|
output.push(parseAndValidateJsonString("hook", runHook({ cwd: rootDir, mode: "compact", stdin })));
|
|
259
259
|
});
|
|
260
260
|
program
|
|
261
261
|
.command("serve")
|
|
262
|
-
.description("
|
|
263
|
-
.option("--port <port>", "
|
|
262
|
+
.description("start the local Web Viewer; press Ctrl-C to stop")
|
|
263
|
+
.option("--port <port>", "listening port", parseInteger)
|
|
264
264
|
.action(async (commandOptions) => {
|
|
265
265
|
const { runServe } = await import("./commands/serve.js");
|
|
266
266
|
const rootDir = findProjectRoot(cwd);
|
|
@@ -295,7 +295,7 @@ function writeOutput(schemaName, value, expectJson = false) {
|
|
|
295
295
|
function parseInteger(input) {
|
|
296
296
|
const value = Number.parseInt(input, 10);
|
|
297
297
|
if (Number.isNaN(value) || value <= 0) {
|
|
298
|
-
throw new CliError(
|
|
298
|
+
throw new CliError(`Invalid integer: ${input}`);
|
|
299
299
|
}
|
|
300
300
|
return value;
|
|
301
301
|
}
|
package/dist/commands/adopt.js
CHANGED
|
@@ -10,21 +10,21 @@ export function runAdopt(options) {
|
|
|
10
10
|
const rootDir = findProjectRoot(options.cwd);
|
|
11
11
|
const workspace = loadWorkspace(rootDir);
|
|
12
12
|
if (!workspace.meta) {
|
|
13
|
-
throw new CliError("
|
|
13
|
+
throw new CliError("llmdoc/meta.json is missing; run llmdoc init-state first.");
|
|
14
14
|
}
|
|
15
15
|
const llmdocPaths = options.paths.map((input) => {
|
|
16
16
|
const repoRelativePath = normalizeRepoRelativePath(input.startsWith("llmdoc/") ? input : `llmdoc/${input}`);
|
|
17
17
|
if (!repoRelativePath.startsWith("llmdoc/") || !repoRelativePath.endsWith(".mdx")) {
|
|
18
|
-
throw new CliError(`adopt
|
|
18
|
+
throw new CliError(`adopt can register only .mdx documents under llmdoc/: ${input}`);
|
|
19
19
|
}
|
|
20
20
|
const shape = parseDocTargetShape(repoRelativePath);
|
|
21
21
|
assertDocKindMatchesShape(shape);
|
|
22
22
|
const absolutePath = resolveInsideRoot(rootDir, repoRelativePath, { allowMissing: true });
|
|
23
23
|
if (!fs.existsSync(absolutePath)) {
|
|
24
|
-
throw new CliError(
|
|
24
|
+
throw new CliError(`Target does not exist; adopt registers existing documents only (use llmdoc new to create one): ${repoRelativePath}`);
|
|
25
25
|
}
|
|
26
26
|
if (!workspace.documentsByLlmdocPath.has(shape.llmdocPath)) {
|
|
27
|
-
throw new CliError(
|
|
27
|
+
throw new CliError(`The workspace did not recognize the document (its front matter may be invalid): ${repoRelativePath}`);
|
|
28
28
|
}
|
|
29
29
|
return shape.llmdocPath;
|
|
30
30
|
});
|
|
@@ -32,7 +32,7 @@ export function runAdopt(options) {
|
|
|
32
32
|
const targetRepoPaths = new Set(llmdocPaths.map((llmdocPath) => `llmdoc/${llmdocPath}`));
|
|
33
33
|
const blockingIssues = validateWorkspace(workspace).filter((issue) => issue.severity === "error" && issue.path !== undefined && targetRepoPaths.has(issue.path) && issue.code !== "meta.entry.missing");
|
|
34
34
|
if (blockingIssues.length > 0) {
|
|
35
|
-
throw new CliError(
|
|
35
|
+
throw new CliError(`Target documents failed validation; refusing to register them:\n${blockingIssues.map((issue) => ` ${issue.code} (${issue.path}) ${issue.message}`).join("\n")}`);
|
|
36
36
|
}
|
|
37
37
|
const adopted = [];
|
|
38
38
|
const alreadyRegistered = [];
|
|
@@ -59,7 +59,7 @@ export function runAdopt(options) {
|
|
|
59
59
|
lines.push(`already registered (no-op): ${alreadyRegistered.join(", ")}`);
|
|
60
60
|
}
|
|
61
61
|
if (adopted.length > 0) {
|
|
62
|
-
lines.push("validatedRevision
|
|
62
|
+
lines.push("validatedRevision was registered as null; after validation, use fingerprint/commit to write a valid revision.");
|
|
63
63
|
}
|
|
64
64
|
return lines.join("\n");
|
|
65
65
|
}
|
package/dist/commands/commit.js
CHANGED
|
@@ -10,22 +10,22 @@ export function runCommit(options) {
|
|
|
10
10
|
const preflightWorkspace = loadWorkspace(rootDir);
|
|
11
11
|
const verifiedPaths = uniquePaths((options.verified ?? []).map((value) => (value.startsWith("llmdoc/") ? value.slice("llmdoc/".length) : value)));
|
|
12
12
|
if (options.all && verifiedPaths.length > 0) {
|
|
13
|
-
throw new CliError("commit
|
|
13
|
+
throw new CliError("commit cannot use --all and --verified together.");
|
|
14
14
|
}
|
|
15
15
|
for (const docPath of verifiedPaths) {
|
|
16
16
|
if (!preflightWorkspace.documentsByLlmdocPath.has(docPath)) {
|
|
17
|
-
throw new CliError(
|
|
17
|
+
throw new CliError(`Document does not exist: ${docPath}`);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
const issues = validateWorkspace(preflightWorkspace);
|
|
21
21
|
const errors = issues.filter((issue) => issue.severity === "error");
|
|
22
22
|
if (errors.length > 0) {
|
|
23
|
-
throw new CliError(`
|
|
23
|
+
throw new CliError(`Validation failed; refusing to commit:\n${errors.map((issue) => ` ${issue.code} (${issue.path})`).join("\n")}`);
|
|
24
24
|
}
|
|
25
25
|
const porcelain = runGit(rootDir, ["status", "--porcelain", "--", "llmdoc"]);
|
|
26
26
|
const hasLlmdocChanges = Boolean(porcelain.trim());
|
|
27
27
|
if (!hasLlmdocChanges && !options.all && verifiedPaths.length === 0) {
|
|
28
|
-
return options.json ? { status: "no_change", commits: [], updated: [] } : "no_change: llmdoc/
|
|
28
|
+
return options.json ? { status: "no_change", commits: [], updated: [] } : "no_change: llmdoc/ has no changes to commit";
|
|
29
29
|
}
|
|
30
30
|
const changedDocPaths = porcelain
|
|
31
31
|
.split(/\r?\n/)
|
|
@@ -48,7 +48,7 @@ export function runCommit(options) {
|
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
catch (error) {
|
|
51
|
-
throw new CliError(`
|
|
51
|
+
throw new CliError(`Fingerprint preflight failed; no commit was created: ${error.message}`, 70);
|
|
52
52
|
}
|
|
53
53
|
if (changedDocPaths.length === 0) {
|
|
54
54
|
return commitMetaOnly({
|
|
@@ -150,7 +150,7 @@ function uniquePaths(paths) {
|
|
|
150
150
|
function runGit(rootDir, args) {
|
|
151
151
|
const result = spawnSync("git", ["-c", "core.quotePath=false", ...args], { cwd: rootDir, encoding: "utf8" });
|
|
152
152
|
if (result.status !== 0) {
|
|
153
|
-
throw new CliError((result.stderr || result.stdout || `git ${args[0]}
|
|
153
|
+
throw new CliError((result.stderr || result.stdout || `git ${args[0]} failed`).trim());
|
|
154
154
|
}
|
|
155
155
|
return result.stdout;
|
|
156
156
|
}
|
package/dist/commands/context.js
CHANGED
|
@@ -7,7 +7,7 @@ import { normalizeRepoRelativePath, resolveInsideRoot } from "../lib/fs.js";
|
|
|
7
7
|
import { estimateTokens } from "../lib/markdown.js";
|
|
8
8
|
export function runContext(options) {
|
|
9
9
|
if (options.files.length === 0) {
|
|
10
|
-
throw new CliError("context
|
|
10
|
+
throw new CliError("context requires at least one --files input.");
|
|
11
11
|
}
|
|
12
12
|
const workspace = loadWorkspace(options.cwd);
|
|
13
13
|
const normalizedFiles = options.files.map((file) => {
|
|
@@ -5,14 +5,14 @@ export function runFingerprint(options) {
|
|
|
5
5
|
const workspace = loadWorkspace(options.cwd);
|
|
6
6
|
const targetPaths = options.update?.map((value) => (value.startsWith("llmdoc/") ? value.slice("llmdoc/".length) : value)) ?? [];
|
|
7
7
|
if (options.all && targetPaths.length > 0) {
|
|
8
|
-
throw new CliError("fingerprint
|
|
8
|
+
throw new CliError("fingerprint cannot use --all and --update together.");
|
|
9
9
|
}
|
|
10
10
|
if (!options.all && targetPaths.length === 0) {
|
|
11
|
-
throw new CliError("fingerprint
|
|
11
|
+
throw new CliError("fingerprint requires --all or --update <path...>.");
|
|
12
12
|
}
|
|
13
13
|
for (const docPath of targetPaths) {
|
|
14
14
|
if (!workspace.documentsByLlmdocPath.has(docPath)) {
|
|
15
|
-
throw new CliError(
|
|
15
|
+
throw new CliError(`Document does not exist: ${docPath}`);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
try {
|