contentbit 0.4.1 → 0.5.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/README.md +7 -2
- package/dist/bin.js +1609 -1616
- package/dist/cli-format.d.ts +17 -0
- package/dist/cli-format.d.ts.map +1 -0
- package/dist/cli-format.js +63 -0
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +9 -188
- package/dist/commands/docs.d.ts.map +1 -1
- package/dist/commands/docs.js +4 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +80 -146
- package/dist/commands/init-targets.d.ts +27 -0
- package/dist/commands/init-targets.d.ts.map +1 -0
- package/dist/commands/init-targets.js +280 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +26 -313
- package/dist/commands/instructions.d.ts.map +1 -1
- package/dist/commands/instructions.js +4 -1
- package/dist/commands/links.d.ts.map +1 -1
- package/dist/commands/links.js +18 -14
- package/dist/commands/render.d.ts.map +1 -1
- package/dist/commands/render.js +17 -10
- package/dist/commands/stats.d.ts.map +1 -1
- package/dist/commands/stats.js +33 -34
- package/dist/commands/studio.d.ts.map +1 -1
- package/dist/commands/studio.js +14 -12
- package/dist/commands/validate.d.ts.map +1 -1
- package/dist/commands/validate.js +39 -41
- package/dist/content-project.d.ts +32 -0
- package/dist/content-project.d.ts.map +1 -0
- package/dist/content-project.js +34 -0
- package/dist/load-registry.d.ts +4 -1
- package/dist/load-registry.d.ts.map +1 -1
- package/dist/load-registry.js +4 -2
- package/dist/run.d.ts +10 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +1613 -1618
- package/package.json +4 -5
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Diagnostic, Severity } from '@contentbit/core';
|
|
2
|
+
type Tone = 'error' | 'warning' | 'info' | 'success' | 'muted';
|
|
3
|
+
interface Row {
|
|
4
|
+
label: string;
|
|
5
|
+
value: string | number;
|
|
6
|
+
tone?: Tone;
|
|
7
|
+
}
|
|
8
|
+
export declare function color(text: string, tone: Tone | 'bold'): string;
|
|
9
|
+
export declare function section(title: string): string;
|
|
10
|
+
export declare function formatRows(rows: Row[]): string[];
|
|
11
|
+
export declare function formatCommandList(commands: string[]): string[];
|
|
12
|
+
export declare function formatDiagnosticForCli(diagnostic: Diagnostic, file: string): string;
|
|
13
|
+
export declare function displayPath(file: string): string;
|
|
14
|
+
export declare function severityLabel(severity: Severity): string;
|
|
15
|
+
export declare function severityTone(severity: Severity): Tone;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=cli-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-format.d.ts","sourceRoot":"","sources":["../src/cli-format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAG5D,KAAK,IAAI,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAA;AAW9D,UAAU,GAAG;IACX,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;IACtB,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAI/D;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,MAAM,EAAE,CAQhD;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAE9D;AAED,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAQnF;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAExD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAIrD"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { isAbsolute, relative } from 'node:path';
|
|
2
|
+
const ANSI = {
|
|
3
|
+
bold: ['\u001b[1m', '\u001b[22m'],
|
|
4
|
+
error: ['\u001b[31m', '\u001b[39m'],
|
|
5
|
+
warning: ['\u001b[33m', '\u001b[39m'],
|
|
6
|
+
info: ['\u001b[36m', '\u001b[39m'],
|
|
7
|
+
success: ['\u001b[32m', '\u001b[39m'],
|
|
8
|
+
muted: ['\u001b[2m', '\u001b[22m'],
|
|
9
|
+
};
|
|
10
|
+
export function color(text, tone) {
|
|
11
|
+
if (!colorsEnabled())
|
|
12
|
+
return text;
|
|
13
|
+
const [open, close] = ANSI[tone];
|
|
14
|
+
return `${open}${text}${close}`;
|
|
15
|
+
}
|
|
16
|
+
export function section(title) {
|
|
17
|
+
return color(title, 'bold');
|
|
18
|
+
}
|
|
19
|
+
export function formatRows(rows) {
|
|
20
|
+
const width = Math.max(...rows.map((row) => row.label.length));
|
|
21
|
+
return rows.map((row) => {
|
|
22
|
+
const value = String(row.value);
|
|
23
|
+
return ` ${color(row.label.padEnd(width), 'muted')} ${row.tone ? color(value, row.tone) : value}`;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export function formatCommandList(commands) {
|
|
27
|
+
return commands.map((command) => ` ${color('$', 'muted')} ${command}`);
|
|
28
|
+
}
|
|
29
|
+
export function formatDiagnosticForCli(diagnostic, file) {
|
|
30
|
+
const location = `${displayPath(file)}:${diagnostic.position.start.line}:${diagnostic.position.start.column}`;
|
|
31
|
+
const lines = [
|
|
32
|
+
`${color(location, 'muted')} ${severityLabel(diagnostic.severity)} ${diagnostic.code}`,
|
|
33
|
+
` ${diagnostic.message}`,
|
|
34
|
+
];
|
|
35
|
+
if (diagnostic.hint)
|
|
36
|
+
lines.push(` ${color('hint', 'muted')} ${diagnostic.hint}`);
|
|
37
|
+
return lines.join('\n');
|
|
38
|
+
}
|
|
39
|
+
export function displayPath(file) {
|
|
40
|
+
const path = relative(process.cwd(), file);
|
|
41
|
+
if (path && !path.startsWith('..') && !isAbsolute(path))
|
|
42
|
+
return path;
|
|
43
|
+
return file;
|
|
44
|
+
}
|
|
45
|
+
export function severityLabel(severity) {
|
|
46
|
+
return color(severity, severityTone(severity));
|
|
47
|
+
}
|
|
48
|
+
export function severityTone(severity) {
|
|
49
|
+
if (severity === 'error')
|
|
50
|
+
return 'error';
|
|
51
|
+
if (severity === 'warning')
|
|
52
|
+
return 'warning';
|
|
53
|
+
return 'info';
|
|
54
|
+
}
|
|
55
|
+
function colorsEnabled() {
|
|
56
|
+
if (process.env.VITEST || process.env.NODE_ENV === 'test')
|
|
57
|
+
return false;
|
|
58
|
+
if ('NO_COLOR' in process.env || process.env.FORCE_COLOR === '0')
|
|
59
|
+
return false;
|
|
60
|
+
if (process.env.FORCE_COLOR)
|
|
61
|
+
return true;
|
|
62
|
+
return Boolean(process.stdout.isTTY);
|
|
63
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/commands/agents.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/commands/agents.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AA6BnC,MAAM,WAAW,YAAY;IAC3B,8EAA8E;IAC9E,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,+EAA+E;AAC/E,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,YAAY,EACrB,EAAE,EAAE,EAAE,GACL,OAAO,CAAC,IAAI,CAAC,CA6Bf;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAkB3E"}
|
package/dist/commands/agents.js
CHANGED
|
@@ -2,196 +2,17 @@ import { existsSync } from 'node:fs';
|
|
|
2
2
|
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { parseArgs } from 'node:util';
|
|
5
|
-
|
|
5
|
+
import agentsMdTemplate from './agent-templates/AGENTS.md?raw';
|
|
6
|
+
import auditSkill from './agent-templates/contentbit-audit/SKILL.md?raw';
|
|
7
|
+
import authorSkill from './agent-templates/contentbit-author/SKILL.md?raw';
|
|
8
|
+
// These templates are static and project-independent by design: skills fetch
|
|
6
9
|
// live data (authoring guide, stats, diagnostics) by running the CLI, so the
|
|
7
10
|
// registry stays the single source of truth and nothing can drift. Bump the
|
|
8
|
-
// frontmatter version when a template changes; `contentbit
|
|
9
|
-
// overwrite in place.
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
description: |
|
|
14
|
-
Write or edit contentbit Markdown content (directive blocks like :::callout).
|
|
15
|
-
Use when asked to create or modify content documents in a project that uses
|
|
16
|
-
contentbit — blog posts, docs pages, changelogs, any Markdown covered by
|
|
17
|
-
\`contentbit validate\`.
|
|
18
|
-
version: ${TEMPLATE_VERSION}
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
# Writing contentbit content
|
|
22
|
-
|
|
23
|
-
contentbit documents are plain Markdown plus directive blocks
|
|
24
|
-
(\`:::name{props} ... :::\`). Every block has a schema. Never guess block names,
|
|
25
|
-
props, or body shapes — fetch the live guide from the project's registry first.
|
|
26
|
-
|
|
27
|
-
## Find the project conventions
|
|
28
|
-
|
|
29
|
-
Check \`package.json\` for a \`content:check\` script. It holds the canonical
|
|
30
|
-
validate invocation for this project: the content glob and, if present, the
|
|
31
|
-
\`--registry <path>\` flag pointing at custom block definitions. Reuse both
|
|
32
|
-
below. No script? Default to \`content/**/*.md\` with no \`--registry\` flag.
|
|
33
|
-
If the project has a \`content:links\` script, use it for the internal-link
|
|
34
|
-
index; otherwise run \`contentbit links <content glob>\` directly.
|
|
35
|
-
|
|
36
|
-
## The loop
|
|
37
|
-
|
|
38
|
-
1. **Fetch the authoring guide** (always — it covers this project's custom blocks):
|
|
39
|
-
|
|
40
|
-
\`\`\`sh
|
|
41
|
-
contentbit instructions --audience llm [--registry <path from content:check>]
|
|
42
|
-
\`\`\`
|
|
43
|
-
|
|
44
|
-
Read it before writing. It documents every available block: props, body
|
|
45
|
-
shape, and when to use or avoid it.
|
|
46
|
-
|
|
47
|
-
2. **Write the document.** Plain Markdown everywhere; blocks only where the
|
|
48
|
-
guide's use-when guidance fits. Keep frontmatter consistent with sibling
|
|
49
|
-
documents in the same folder. If sibling documents use \`slug\`, \`linksTo\`,
|
|
50
|
-
\`aliases\`, or \`keywords\`, run the link index first:
|
|
51
|
-
|
|
52
|
-
\`\`\`sh
|
|
53
|
-
contentbit links <content glob>
|
|
54
|
-
\`\`\`
|
|
55
|
-
|
|
56
|
-
Read \`.contentbit/link-index.json\` to pick existing slugs and related
|
|
57
|
-
pages. Author only \`slug\`, \`linksTo\`, \`aliases\`, and \`keywords\` in
|
|
58
|
-
frontmatter; never write derived \`linkedFrom\` into source files. When
|
|
59
|
-
creating a linked page, include \`keywords.primary\` and
|
|
60
|
-
\`keywords.secondary\` with search-intent phrases that would help future
|
|
61
|
-
agents choose this page as a \`linksTo\` target.
|
|
62
|
-
|
|
63
|
-
3. **Validate and fix until clean:**
|
|
64
|
-
|
|
65
|
-
\`\`\`sh
|
|
66
|
-
contentbit validate <file> [--registry <path>]
|
|
67
|
-
\`\`\`
|
|
68
|
-
|
|
69
|
-
Diagnostics print to stderr as \`file:line:col severity CODE message\`, often
|
|
70
|
-
with a \`hint:\` line suggesting the fix. Exit 0 means clean; exit 1 means
|
|
71
|
-
errors remain. If the document has link frontmatter, validate the full
|
|
72
|
-
content glob so cross-file links are checked against the whole graph. Fix
|
|
73
|
-
every diagnostic and re-run. Never finish with a failing validate.
|
|
74
|
-
|
|
75
|
-
4. **Refresh internal links when present:**
|
|
76
|
-
|
|
77
|
-
\`\`\`sh
|
|
78
|
-
contentbit links <content glob> --fix
|
|
79
|
-
\`\`\`
|
|
80
|
-
|
|
81
|
-
\`--fix\` only rewrites \`linksTo\` values that point at known aliases. It
|
|
82
|
-
does not invent links, remove aliases, or write backlinks. Re-run validate
|
|
83
|
-
after it changes files.
|
|
84
|
-
|
|
85
|
-
## Failure modes
|
|
86
|
-
|
|
87
|
-
- \`contentbit\` not found or no registry resolvable: the project is not set up.
|
|
88
|
-
Say so and suggest \`npx contentbit@latest init\` — do not invent block syntax.
|
|
89
|
-
- A block you want does not exist: use plain Markdown, or ask whether to define
|
|
90
|
-
a custom block in the registry. Never emit an unregistered block name.
|
|
91
|
-
`;
|
|
92
|
-
const AUDIT_SKILL = `---
|
|
93
|
-
name: contentbit-audit
|
|
94
|
-
description: |
|
|
95
|
-
Audit contentbit Markdown content health using document stats. Use when asked
|
|
96
|
-
to audit, review, or find improvements across content — thin pages, missing
|
|
97
|
-
structure, validation issues — in a project that uses contentbit.
|
|
98
|
-
version: ${TEMPLATE_VERSION}
|
|
99
|
-
---
|
|
100
|
-
|
|
101
|
-
# Auditing contentbit content
|
|
102
|
-
|
|
103
|
-
\`contentbit doctor\` is the first audit command. It reads content once, runs
|
|
104
|
-
block validation, link validation, and document stats, then prints a ranked
|
|
105
|
-
repair plan. It is read-only: it does not write the link index and never edits
|
|
106
|
-
source files. \`contentbit stats\` remains useful when you need raw JSON metrics.
|
|
107
|
-
\`contentbit links\` builds the frontmatter-authored internal-link graph and can
|
|
108
|
-
heal alias references with \`--fix\`.
|
|
109
|
-
|
|
110
|
-
## Gather
|
|
111
|
-
|
|
112
|
-
Check \`package.json\` for \`content:doctor\` first. If it exists, run it. If it
|
|
113
|
-
does not, use \`content:check\` to find this project's content glob and
|
|
114
|
-
\`--registry\` flag, then run:
|
|
115
|
-
|
|
116
|
-
\`\`\`sh
|
|
117
|
-
contentbit doctor "content/**/*.md" [--registry <path>]
|
|
118
|
-
contentbit doctor "content/**/*.md" [--registry <path>] --json
|
|
119
|
-
contentbit stats "content/**/*.md" [--registry <path>]
|
|
120
|
-
contentbit links "content/**/*.md"
|
|
121
|
-
\`\`\`
|
|
122
|
-
|
|
123
|
-
\`doctor --json\` prints a stable report with summary counts and ranked
|
|
124
|
-
findings. \`stats\` prints per-file metrics: frontmatter data, a heading
|
|
125
|
-
\`outline\` with per-section word counts, \`blocks.byName\` usage counts,
|
|
126
|
-
\`links.domains\`, and a \`validation\` summary (\`errors\`/\`warnings\`).
|
|
127
|
-
\`contentbit links\` writes \`.contentbit/link-index.json\`, whose pages contain
|
|
128
|
-
\`slug\`, resolved \`linksTo\`, derived \`linkedFrom\`, \`aliases\`, and
|
|
129
|
-
\`keywords\`.
|
|
130
|
-
|
|
131
|
-
## Interpret
|
|
132
|
-
|
|
133
|
-
Prioritize findings in the order \`doctor\` reports them:
|
|
134
|
-
|
|
135
|
-
1. **Validation errors and warnings** — broken content ships broken pages.
|
|
136
|
-
2. **Internal-link errors** — unresolved links, duplicate slugs, and alias
|
|
137
|
-
conflicts from \`contentbit links\`.
|
|
138
|
-
3. **Orphans and self-links** — link warnings that point to isolated or noisy
|
|
139
|
-
pages.
|
|
140
|
-
4. **Thin documents** — outline sections with very low word counts.
|
|
141
|
-
5. **Block-less documents** — \`blocks.byName\` empty where sibling documents
|
|
142
|
-
use blocks; structure (steps, callouts, comparisons, faq) may be missing.
|
|
143
|
-
6. **Missing or inconsistent frontmatter** compared to sibling documents.
|
|
144
|
-
7. **Structural imbalance** — skipped heading levels, single-section walls of text.
|
|
145
|
-
|
|
146
|
-
## Report
|
|
147
|
-
|
|
148
|
-
Report findings per file with concrete suggestions, ordered by priority. Do not
|
|
149
|
-
edit files during the audit. To fix a finding, follow the contentbit-author
|
|
150
|
-
skill (fetch the guide, edit, validate until clean) — offer that as a follow-up.
|
|
151
|
-
`;
|
|
152
|
-
const AGENTS_MD_BLOCK = `<!-- contentbit:start -->
|
|
153
|
-
|
|
154
|
-
## contentbit content (generated — edits inside this block are overwritten)
|
|
155
|
-
|
|
156
|
-
This project validates Markdown content with contentbit. Documents are plain
|
|
157
|
-
Markdown plus directive blocks (\`:::name{props} ... :::\`), each with a schema.
|
|
158
|
-
The \`content:check\` script in package.json holds the canonical validate
|
|
159
|
-
command — the content glob and the \`--registry\` flag — reuse its arguments.
|
|
160
|
-
If the project has a \`content:links\` script, use it to build the internal-link
|
|
161
|
-
index; otherwise run \`contentbit links <content glob>\`.
|
|
162
|
-
|
|
163
|
-
When writing or editing content:
|
|
164
|
-
|
|
165
|
-
1. Fetch the live authoring guide first — never guess block syntax:
|
|
166
|
-
\`contentbit instructions --audience llm [--registry <path>]\`
|
|
167
|
-
2. Write plain Markdown; use blocks where the guide's use-when guidance fits.
|
|
168
|
-
3. If sibling documents use \`slug\` / \`linksTo\`, read
|
|
169
|
-
\`.contentbit/link-index.json\` from \`contentbit links <content glob>\` and
|
|
170
|
-
author frontmatter links with existing slugs. When creating a linked page,
|
|
171
|
-
include \`keywords.primary\` and \`keywords.secondary\` with search-intent
|
|
172
|
-
phrases future agents can use to choose related pages.
|
|
173
|
-
4. Validate until clean (exit 0): \`contentbit validate <file> [--registry <path>]\`.
|
|
174
|
-
Diagnostics print as \`file:line:col severity CODE message\` with fix hints.
|
|
175
|
-
For link frontmatter, validate the full content glob so cross-file checks run.
|
|
176
|
-
|
|
177
|
-
When auditing content health:
|
|
178
|
-
|
|
179
|
-
- \`contentbit doctor "content/**/*.md" [--registry <path>]\` prints a ranked,
|
|
180
|
-
read-only repair plan: validation issues, link issues, thin sections,
|
|
181
|
-
block-less long documents, and missing image alt text.
|
|
182
|
-
- \`contentbit doctor "content/**/*.md" [--registry <path>] --json\` prints the
|
|
183
|
-
same findings as structured JSON for agents and CI.
|
|
184
|
-
- \`contentbit stats "content/**/*.md" [--registry <path>]\` prints raw JSON
|
|
185
|
-
stats: outline word counts, block usage, link domains, and validation
|
|
186
|
-
error/warning counts.
|
|
187
|
-
- \`contentbit links "content/**/*.md" [--fix]\` builds
|
|
188
|
-
\`.contentbit/link-index.json\`, reports dangling links/orphans, and rewrites
|
|
189
|
-
alias references in \`linksTo\` when \`--fix\` is used.
|
|
190
|
-
|
|
191
|
-
If \`contentbit\` is unavailable, suggest \`npx contentbit@latest init\` instead
|
|
192
|
-
of inventing block syntax.
|
|
193
|
-
|
|
194
|
-
<!-- contentbit:end -->`;
|
|
11
|
+
// frontmatter version in each SKILL.md when a template changes; `contentbit
|
|
12
|
+
// agents` re-runs overwrite in place.
|
|
13
|
+
const AUTHOR_SKILL = authorSkill;
|
|
14
|
+
const AUDIT_SKILL = auditSkill;
|
|
15
|
+
const AGENTS_MD_BLOCK = agentsMdTemplate.trimEnd();
|
|
195
16
|
const START = '<!-- contentbit:start -->';
|
|
196
17
|
const END = '<!-- contentbit:end -->';
|
|
197
18
|
/** Insert or replace the fenced contentbit block, leaving the rest untouched. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../../src/commands/docs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AAInC,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../../src/commands/docs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AAInC,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBzE"}
|
package/dist/commands/docs.js
CHANGED
|
@@ -5,10 +5,13 @@ export async function docsCommand(args, io) {
|
|
|
5
5
|
args,
|
|
6
6
|
options: {
|
|
7
7
|
registry: { type: 'string' },
|
|
8
|
+
'no-generic-blocks': { type: 'boolean', default: false },
|
|
8
9
|
out: { type: 'string' },
|
|
9
10
|
},
|
|
10
11
|
});
|
|
11
|
-
const registry = await loadRegistry(values.registry
|
|
12
|
+
const registry = await loadRegistry(values.registry, {
|
|
13
|
+
includeGenericBlocks: !values['no-generic-blocks'],
|
|
14
|
+
});
|
|
12
15
|
const guide = registry.toAuthoringGuide({ audience: 'human', includeExamples: true });
|
|
13
16
|
if (values.out)
|
|
14
17
|
await io.writeFile(values.out, guide);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AAsBnC,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAsD3E"}
|
package/dist/commands/doctor.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
1
|
+
import { DEFAULT_MIN_SECTION_WORDS, } from '@contentbit/core';
|
|
3
2
|
import { parseArgs } from 'node:util';
|
|
4
|
-
import {
|
|
3
|
+
import { color, displayPath, formatCommandList, formatRows, section, severityLabel, } from '../cli-format.js';
|
|
4
|
+
import { loadContentProject } from '../content-project.js';
|
|
5
5
|
import { linkResolverOptions } from '../link-options.js';
|
|
6
|
-
import { loadRegistry } from '../load-registry.js';
|
|
7
|
-
const DEFAULT_MIN_SECTION_WORDS = 25;
|
|
8
|
-
const BLOCKLESS_WORDS = 250;
|
|
9
6
|
export async function doctorCommand(args, io) {
|
|
10
7
|
const { values, positionals } = parseArgs({
|
|
11
8
|
args,
|
|
12
9
|
allowPositionals: true,
|
|
13
10
|
options: {
|
|
14
11
|
registry: { type: 'string' },
|
|
12
|
+
'no-generic-blocks': { type: 'boolean', default: false },
|
|
15
13
|
'strict-warnings': { type: 'boolean', default: false },
|
|
16
14
|
json: { type: 'boolean', default: false },
|
|
17
15
|
'min-section-words': { type: 'string' },
|
|
@@ -22,94 +20,30 @@ export async function doctorCommand(args, io) {
|
|
|
22
20
|
'default-locale': { type: 'string' },
|
|
23
21
|
},
|
|
24
22
|
});
|
|
25
|
-
if (positionals.length === 0) {
|
|
26
|
-
io.stderr('doctor: provide at least one file or glob.');
|
|
27
|
-
return 2;
|
|
28
|
-
}
|
|
29
23
|
const minSectionWords = parseMinSectionWords(values['min-section-words']);
|
|
30
24
|
if (minSectionWords === null) {
|
|
31
25
|
io.stderr('doctor: --min-section-words must be a non-negative integer.');
|
|
32
26
|
return 2;
|
|
33
27
|
}
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
for (const file of files) {
|
|
44
|
-
const source = await readFile(file, 'utf8');
|
|
45
|
-
const frontmatter = extractFrontmatter(source);
|
|
46
|
-
linkInputs.push({ path: file, data: frontmatter?.data ?? {} });
|
|
47
|
-
const validation = validateDocument(parseDocument(stripFrontmatter(source)), registry);
|
|
48
|
-
for (const diagnostic of validation.diagnostics) {
|
|
49
|
-
findings.push(findingFromDiagnostic('validation', file, diagnostic));
|
|
50
|
-
}
|
|
51
|
-
const stats = analyzeDocument(source, { path: file });
|
|
52
|
-
for (const section of stats.outline) {
|
|
53
|
-
if (section.words < minSectionWords) {
|
|
54
|
-
findings.push({
|
|
55
|
-
severity: 'info',
|
|
56
|
-
source: 'stats',
|
|
57
|
-
code: 'CB_THIN_SECTION',
|
|
58
|
-
file,
|
|
59
|
-
line: section.line,
|
|
60
|
-
column: 1,
|
|
61
|
-
message: `section "${section.text}" has ${section.words} words`,
|
|
62
|
-
hint: `Add detail or merge it with a nearby section. Threshold: ${minSectionWords} words.`,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (stats.length.words >= BLOCKLESS_WORDS && stats.blocks.total === 0) {
|
|
67
|
-
findings.push({
|
|
68
|
-
severity: 'info',
|
|
69
|
-
source: 'stats',
|
|
70
|
-
code: 'CB_BLOCKLESS_DOCUMENT',
|
|
71
|
-
file,
|
|
72
|
-
message: `document has ${stats.length.words} words and no structured blocks`,
|
|
73
|
-
hint: 'Consider a callout, steps, comparison, FAQ, or another registered block if it clarifies the page.',
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
if (stats.images.missingAlt > 0) {
|
|
77
|
-
findings.push({
|
|
78
|
-
severity: 'info',
|
|
79
|
-
source: 'stats',
|
|
80
|
-
code: 'CB_IMAGE_ALT_MISSING',
|
|
81
|
-
file,
|
|
82
|
-
message: `${stats.images.missingAlt} image(s) are missing alt text`,
|
|
83
|
-
hint: 'Add descriptive alt text for meaningful images; use empty alt only for decorative images.',
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
let linkGraph;
|
|
88
|
-
if (hasLinkFrontmatter(linkInputs, linkOptions.slugField)) {
|
|
89
|
-
for (const { file, diagnostic } of validateLinks(linkInputs, linkOptions)) {
|
|
90
|
-
findings.push(findingFromDiagnostic('links', file, diagnostic));
|
|
91
|
-
}
|
|
92
|
-
const index = buildLinkIndex(linkInputs, linkOptions);
|
|
93
|
-
let links = 0;
|
|
94
|
-
for (const page of index.pages.values())
|
|
95
|
-
links += page.linksTo.length;
|
|
96
|
-
linkGraph = {
|
|
97
|
-
pages: index.pages.size,
|
|
98
|
-
links,
|
|
99
|
-
orphans: [...index.pages.values()].filter((page) => page.linkedFrom.length === 0).length,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
findings.sort(compareFindings);
|
|
28
|
+
const includeGenericBlocks = !values['no-generic-blocks'];
|
|
29
|
+
const { files, scan } = await loadContentProject({
|
|
30
|
+
cmd: 'doctor',
|
|
31
|
+
positionals,
|
|
32
|
+
registry: values.registry,
|
|
33
|
+
includeGenericBlocks,
|
|
34
|
+
linkOptions: linkResolverOptions(values),
|
|
35
|
+
scan: { minSectionWords },
|
|
36
|
+
});
|
|
103
37
|
const report = {
|
|
104
38
|
files: files.length,
|
|
105
|
-
summary:
|
|
106
|
-
...(linkGraph ? { linkGraph } : {}),
|
|
107
|
-
findings,
|
|
39
|
+
summary: scan.summary,
|
|
40
|
+
...(scan.linkGraph ? { linkGraph: scan.linkGraph } : {}),
|
|
41
|
+
findings: scan.findings,
|
|
108
42
|
};
|
|
109
43
|
if (values.json)
|
|
110
44
|
io.stdout(JSON.stringify(report, null, 2));
|
|
111
45
|
else
|
|
112
|
-
io.stdout(formatReport(report, positionals, values.registry, hasAliases(linkInputs)));
|
|
46
|
+
io.stdout(formatReport(report, positionals, values.registry, includeGenericBlocks, hasAliases(scan.linkInputs)));
|
|
113
47
|
if (report.summary.errors > 0)
|
|
114
48
|
return 1;
|
|
115
49
|
if (report.summary.warnings > 0 && values['strict-warnings'])
|
|
@@ -123,89 +57,81 @@ function parseMinSectionWords(value) {
|
|
|
123
57
|
return null;
|
|
124
58
|
return Number(value);
|
|
125
59
|
}
|
|
126
|
-
function findingFromDiagnostic(source, file, diagnostic) {
|
|
127
|
-
return {
|
|
128
|
-
severity: diagnostic.severity,
|
|
129
|
-
source,
|
|
130
|
-
code: diagnostic.code,
|
|
131
|
-
file,
|
|
132
|
-
line: diagnostic.position.start.line,
|
|
133
|
-
column: diagnostic.position.start.column,
|
|
134
|
-
message: diagnostic.message,
|
|
135
|
-
...(diagnostic.hint ? { hint: diagnostic.hint } : {}),
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
function hasLinkFrontmatter(inputs, configuredSlugField) {
|
|
139
|
-
const slugField = configuredSlugField ?? 'slug';
|
|
140
|
-
return inputs.some((input) => Object.prototype.hasOwnProperty.call(input.data, slugField));
|
|
141
|
-
}
|
|
142
60
|
function hasAliases(inputs) {
|
|
143
61
|
return inputs.some((input) => Array.isArray(input.data.aliases) && input.data.aliases.length > 0);
|
|
144
62
|
}
|
|
145
|
-
function
|
|
146
|
-
return {
|
|
147
|
-
errors: findings.filter((f) => f.severity === 'error').length,
|
|
148
|
-
warnings: findings.filter((f) => f.severity === 'warning').length,
|
|
149
|
-
suggestions: findings.filter((f) => f.severity === 'info').length,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
function compareFindings(a, b) {
|
|
153
|
-
return (rank(a) - rank(b) ||
|
|
154
|
-
a.file.localeCompare(b.file) ||
|
|
155
|
-
(a.line ?? 0) - (b.line ?? 0) ||
|
|
156
|
-
(a.column ?? 0) - (b.column ?? 0) ||
|
|
157
|
-
a.code.localeCompare(b.code));
|
|
158
|
-
}
|
|
159
|
-
function rank(finding) {
|
|
160
|
-
if (finding.severity === 'error' && finding.source === 'validation')
|
|
161
|
-
return 0;
|
|
162
|
-
if (finding.severity === 'error' && finding.source === 'links')
|
|
163
|
-
return 1;
|
|
164
|
-
if (finding.severity === 'warning')
|
|
165
|
-
return 2;
|
|
166
|
-
if (finding.code === 'CB_THIN_SECTION')
|
|
167
|
-
return 3;
|
|
168
|
-
if (finding.code === 'CB_BLOCKLESS_DOCUMENT')
|
|
169
|
-
return 4;
|
|
170
|
-
if (finding.code === 'CB_IMAGE_ALT_MISSING')
|
|
171
|
-
return 5;
|
|
172
|
-
return 6;
|
|
173
|
-
}
|
|
174
|
-
function formatReport(report, globs, registryPath, aliasFixMayApply) {
|
|
63
|
+
function formatReport(report, globs, registryPath, includeGenericBlocks, aliasFixMayApply) {
|
|
175
64
|
const lines = [];
|
|
176
|
-
lines.push('contentbit doctor');
|
|
177
|
-
lines.push(
|
|
65
|
+
lines.push(section('contentbit doctor'));
|
|
66
|
+
lines.push('');
|
|
67
|
+
lines.push(section('Health'));
|
|
68
|
+
lines.push(...formatRows([
|
|
69
|
+
{ label: 'Files', value: report.files },
|
|
70
|
+
{
|
|
71
|
+
label: 'Errors',
|
|
72
|
+
value: report.summary.errors,
|
|
73
|
+
tone: report.summary.errors > 0 ? 'error' : 'success',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
label: 'Warnings',
|
|
77
|
+
value: report.summary.warnings,
|
|
78
|
+
tone: report.summary.warnings > 0 ? 'warning' : 'success',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
label: 'Suggestions',
|
|
82
|
+
value: report.summary.suggestions,
|
|
83
|
+
tone: report.summary.suggestions > 0 ? 'info' : 'success',
|
|
84
|
+
},
|
|
85
|
+
]));
|
|
178
86
|
if (report.linkGraph) {
|
|
179
|
-
lines.push(
|
|
87
|
+
lines.push('');
|
|
88
|
+
lines.push(section('Link Graph'));
|
|
89
|
+
lines.push(...formatRows([
|
|
90
|
+
{ label: 'Pages', value: report.linkGraph.pages },
|
|
91
|
+
{ label: 'Links', value: report.linkGraph.links },
|
|
92
|
+
{
|
|
93
|
+
label: 'Orphans',
|
|
94
|
+
value: report.linkGraph.orphans,
|
|
95
|
+
tone: report.linkGraph.orphans > 0 ? 'warning' : 'success',
|
|
96
|
+
},
|
|
97
|
+
]));
|
|
180
98
|
}
|
|
181
99
|
lines.push('');
|
|
182
100
|
if (report.findings.length === 0) {
|
|
183
|
-
lines.push('No findings. Content looks healthy.');
|
|
101
|
+
lines.push(color('No findings. Content looks healthy.', 'success'));
|
|
184
102
|
}
|
|
185
103
|
else {
|
|
186
|
-
lines.push('Repair
|
|
104
|
+
lines.push(section('Repair Plan'));
|
|
187
105
|
report.findings.forEach((finding, index) => {
|
|
188
|
-
lines.push(
|
|
189
|
-
if (finding.hint)
|
|
190
|
-
lines.push(` hint: ${finding.hint}`);
|
|
106
|
+
lines.push(...formatFinding(index + 1, finding));
|
|
191
107
|
});
|
|
192
108
|
}
|
|
193
109
|
lines.push('');
|
|
194
|
-
lines.push('Next
|
|
195
|
-
|
|
110
|
+
lines.push(section('Next Commands'));
|
|
111
|
+
const commands = [
|
|
112
|
+
`contentbit validate ${formatGlobs(globs)}${formatRegistryArgs(registryPath, includeGenericBlocks)}`,
|
|
113
|
+
];
|
|
196
114
|
if (report.linkGraph) {
|
|
197
|
-
|
|
115
|
+
commands.push(`contentbit links ${formatGlobs(globs)}`);
|
|
198
116
|
if (aliasFixMayApply && report.summary.errors === 0)
|
|
199
|
-
|
|
117
|
+
commands.push(`contentbit links ${formatGlobs(globs)} --fix`);
|
|
200
118
|
}
|
|
201
|
-
|
|
119
|
+
commands.push(`contentbit doctor ${formatGlobs(globs)}${formatRegistryArgs(registryPath, includeGenericBlocks)} --json`);
|
|
120
|
+
lines.push(...formatCommandList(commands));
|
|
202
121
|
return lines.join('\n');
|
|
203
122
|
}
|
|
204
|
-
function formatFinding(finding) {
|
|
123
|
+
function formatFinding(index, finding) {
|
|
205
124
|
const location = finding.line !== undefined && finding.column !== undefined
|
|
206
|
-
? `${finding.file}:${finding.line}:${finding.column}`
|
|
207
|
-
: finding.file;
|
|
208
|
-
|
|
125
|
+
? `${displayPath(finding.file)}:${finding.line}:${finding.column}`
|
|
126
|
+
: displayPath(finding.file);
|
|
127
|
+
const lines = [
|
|
128
|
+
` ${index}. ${severityLabel(finding.severity)} ${finding.source} ${finding.code}`,
|
|
129
|
+
` ${color('at', 'muted')} ${location}`,
|
|
130
|
+
` ${finding.message}`,
|
|
131
|
+
];
|
|
132
|
+
if (finding.hint)
|
|
133
|
+
lines.push(` ${color('hint', 'muted')} ${finding.hint}`);
|
|
134
|
+
return lines;
|
|
209
135
|
}
|
|
210
136
|
function formatGlobs(globs) {
|
|
211
137
|
return globs.map(formatArg).join(' ');
|
|
@@ -213,3 +139,11 @@ function formatGlobs(globs) {
|
|
|
213
139
|
function formatArg(value) {
|
|
214
140
|
return /\s/.test(value) ? JSON.stringify(value) : value;
|
|
215
141
|
}
|
|
142
|
+
function formatRegistryArgs(registryPath, includeGenericBlocks) {
|
|
143
|
+
const args = [];
|
|
144
|
+
if (registryPath)
|
|
145
|
+
args.push('--registry', formatArg(registryPath));
|
|
146
|
+
if (!includeGenericBlocks)
|
|
147
|
+
args.push('--no-generic-blocks');
|
|
148
|
+
return args.length > 0 ? ` ${args.join(' ')}` : '';
|
|
149
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Io } from '../run.js';
|
|
2
|
+
export type Target = 'react' | 'markdown' | 'astro';
|
|
3
|
+
export type Md = 'react-markdown' | 'none';
|
|
4
|
+
export declare const TARGETS: Target[];
|
|
5
|
+
type ScaffoldFile = [path: string, content: string];
|
|
6
|
+
export interface InitTargetPlan {
|
|
7
|
+
files: ScaffoldFile[];
|
|
8
|
+
nextSteps: string[];
|
|
9
|
+
}
|
|
10
|
+
interface InitTargetContext {
|
|
11
|
+
cwd: string;
|
|
12
|
+
deps: Record<string, string>;
|
|
13
|
+
md: Md;
|
|
14
|
+
noPage: boolean;
|
|
15
|
+
noStyled: boolean;
|
|
16
|
+
io: Io;
|
|
17
|
+
installStyledPack: (pack: string) => Promise<boolean>;
|
|
18
|
+
}
|
|
19
|
+
interface InitTargetAdapter {
|
|
20
|
+
markdownChoices: Md[];
|
|
21
|
+
runtimeDependencies(md: Md): string[];
|
|
22
|
+
createPlan(ctx: InitTargetContext): Promise<InitTargetPlan>;
|
|
23
|
+
}
|
|
24
|
+
export declare const TARGET_ADAPTERS: Record<Target, InitTargetAdapter>;
|
|
25
|
+
export declare function detectTarget(deps: Record<string, string>): Target;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=init-targets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-targets.d.ts","sourceRoot":"","sources":["../../src/commands/init-targets.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AAEnC,MAAM,MAAM,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,OAAO,CAAA;AACnD,MAAM,MAAM,EAAE,GAAG,gBAAgB,GAAG,MAAM,CAAA;AAE1C,eAAO,MAAM,OAAO,EAAE,MAAM,EAAmC,CAAA;AAE/D,KAAK,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;AAEnD,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,YAAY,EAAE,CAAA;IACrB,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB;AAED,UAAU,iBAAiB;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5B,EAAE,EAAE,EAAE,CAAA;IACN,MAAM,EAAE,OAAO,CAAA;IACf,QAAQ,EAAE,OAAO,CAAA;IACjB,EAAE,EAAE,EAAE,CAAA;IACN,iBAAiB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CACtD;AAED,UAAU,iBAAiB;IACzB,eAAe,EAAE,EAAE,EAAE,CAAA;IACrB,mBAAmB,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,CAAA;IACrC,UAAU,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;CAC5D;AA0RD,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAoB7D,CAAA;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAIjE"}
|