contentbit 0.6.0 → 0.7.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.
Files changed (46) hide show
  1. package/README.md +14 -0
  2. package/dist/bin.js +1652 -318
  3. package/dist/commands/adopt.d.ts +13 -0
  4. package/dist/commands/adopt.d.ts.map +1 -0
  5. package/dist/commands/agents.d.ts +1 -0
  6. package/dist/commands/agents.d.ts.map +1 -1
  7. package/dist/commands/brief.d.ts.map +1 -1
  8. package/dist/commands/docs.d.ts.map +1 -1
  9. package/dist/commands/doctor.d.ts +1 -0
  10. package/dist/commands/doctor.d.ts.map +1 -1
  11. package/dist/commands/init-targets.d.ts.map +1 -1
  12. package/dist/commands/init.d.ts.map +1 -1
  13. package/dist/commands/instructions.d.ts.map +1 -1
  14. package/dist/commands/links.d.ts.map +1 -1
  15. package/dist/commands/render.d.ts.map +1 -1
  16. package/dist/commands/stats.d.ts.map +1 -1
  17. package/dist/commands/studio.d.ts.map +1 -1
  18. package/dist/commands/validate.d.ts.map +1 -1
  19. package/dist/content-project.d.ts +2 -2
  20. package/dist/content-project.d.ts.map +1 -1
  21. package/dist/project-config.d.ts +8 -0
  22. package/dist/project-config.d.ts.map +1 -0
  23. package/dist/run.d.ts +1 -1
  24. package/dist/run.d.ts.map +1 -1
  25. package/dist/run.js +1652 -318
  26. package/dist/script-defaults.d.ts +14 -0
  27. package/dist/script-defaults.d.ts.map +1 -0
  28. package/package.json +6 -7
  29. package/dist/cli-format.js +0 -63
  30. package/dist/commands/agents.js +0 -64
  31. package/dist/commands/brief.js +0 -52
  32. package/dist/commands/docs.js +0 -12
  33. package/dist/commands/doctor.js +0 -173
  34. package/dist/commands/init-targets.js +0 -280
  35. package/dist/commands/init.js +0 -382
  36. package/dist/commands/instructions.js +0 -15
  37. package/dist/commands/links.js +0 -84
  38. package/dist/commands/render.js +0 -33
  39. package/dist/commands/stats.js +0 -38
  40. package/dist/commands/studio.js +0 -65
  41. package/dist/commands/validate.js +0 -49
  42. package/dist/content-project.js +0 -25
  43. package/dist/link-options.js +0 -31
  44. package/dist/links-io.js +0 -14
  45. package/dist/load-registry.js +0 -1
  46. package/dist/seo-config.js +0 -21
@@ -0,0 +1,14 @@
1
+ import type { LinkOptionValues } from './link-options.js';
2
+ export interface ContentCommandDefaults extends LinkOptionValues {
3
+ cwd?: string;
4
+ globs: string[];
5
+ registry?: string;
6
+ noGenericBlocks?: boolean;
7
+ seoConfig?: string;
8
+ noSeo?: boolean;
9
+ source?: string;
10
+ }
11
+ type ContentCommand = 'validate' | 'doctor' | 'studio' | 'links' | 'stats' | 'brief';
12
+ export declare function discoverContentCommandDefaults(command: ContentCommand, explicitGlobs: string[], startDir?: string): Promise<ContentCommandDefaults>;
13
+ export {};
14
+ //# sourceMappingURL=script-defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-defaults.d.ts","sourceRoot":"","sources":["../src/script-defaults.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAIzD,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB;IAC9D,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,KAAK,cAAc,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAA;AAWpF,wBAAsB,8BAA8B,CAClD,OAAO,EAAE,cAAc,EACvB,aAAa,EAAE,MAAM,EAAE,EACvB,QAAQ,SAAgB,GACvB,OAAO,CAAC,sBAAsB,CAAC,CAoCjC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentbit",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "CLI for Content Blocks: validate, render, and generate LLM authoring instructions from your registry.",
5
5
  "keywords": [
6
6
  "cli",
@@ -38,22 +38,21 @@
38
38
  "@clack/prompts": "^1.5.1",
39
39
  "commander": "^15.0.0",
40
40
  "tinyglobby": "^0.2.10",
41
- "@contentbit/blocks": "0.6.0",
42
- "@contentbit/core": "0.6.0",
43
- "@contentbit/project": "0.6.0",
44
- "@contentbit/studio": "0.6.0"
41
+ "@contentbit/blocks": "0.7.0",
42
+ "@contentbit/core": "0.7.0"
45
43
  },
46
44
  "devDependencies": {
47
45
  "@types/node": "^25.0.9",
48
46
  "esbuild": "^0.28.0",
49
47
  "typescript": "^5.9.3",
50
- "vitest": "^4.0.17"
48
+ "vitest": "^4.0.17",
49
+ "@contentbit/studio": "0.7.0"
51
50
  },
52
51
  "engines": {
53
52
  "node": ">=22.18"
54
53
  },
55
54
  "scripts": {
56
- "build": "tsc -p tsconfig.build.json && node build.mjs",
55
+ "build": "node build.mjs && tsc -p tsconfig.build.json --emitDeclarationOnly",
57
56
  "test": "vitest run",
58
57
  "test:watch": "vitest"
59
58
  }
@@ -1,63 +0,0 @@
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,64 +0,0 @@
1
- import { existsSync } from 'node:fs';
2
- import { mkdir, readFile, writeFile } from 'node:fs/promises';
3
- import { join } from 'node:path';
4
- import agentsMdTemplate from './agent-templates/AGENTS.md?raw';
5
- import auditSkill from './agent-templates/contentbit-audit/SKILL.md?raw';
6
- import authorSkill from './agent-templates/contentbit-author/SKILL.md?raw';
7
- // These templates are static and project-independent by design: skills fetch
8
- // live data (authoring guide, stats, diagnostics) by running the CLI, so the
9
- // registry stays the single source of truth and nothing can drift. Bump the
10
- // frontmatter version in each SKILL.md when a template changes; `contentbit
11
- // agents` re-runs overwrite in place.
12
- const AUTHOR_SKILL = authorSkill;
13
- const AUDIT_SKILL = auditSkill;
14
- const AGENTS_MD_BLOCK = agentsMdTemplate.trimEnd();
15
- const START = '<!-- contentbit:start -->';
16
- const END = '<!-- contentbit:end -->';
17
- /** Insert or replace the fenced contentbit block, leaving the rest untouched. */
18
- function upsertBlock(existing) {
19
- const start = existing.indexOf(START);
20
- const end = existing.indexOf(END);
21
- if (start !== -1 && end !== -1) {
22
- return existing.slice(0, start) + AGENTS_MD_BLOCK + existing.slice(end + END.length);
23
- }
24
- if (existing.trim() === '')
25
- return `${AGENTS_MD_BLOCK}\n`;
26
- return `${existing.replace(/\n*$/, '\n\n')}${AGENTS_MD_BLOCK}\n`;
27
- }
28
- /** Install or refresh the agent integration. Shared by `agents` and `init`. */
29
- export async function installAgentIntegration(cwd, options, io) {
30
- const claude = options.claude ?? existsSync(join(cwd, '.claude'));
31
- const agentsMd = options.agentsMd ?? true;
32
- if (agentsMd) {
33
- const path = join(cwd, 'AGENTS.md');
34
- let existing = '';
35
- try {
36
- existing = await readFile(path, 'utf8');
37
- }
38
- catch {
39
- /* not there yet */
40
- }
41
- const created = existing === '';
42
- await writeFile(path, upsertBlock(existing), 'utf8');
43
- io.stdout(`${created ? 'created' : 'updated'}: AGENTS.md (contentbit block)`);
44
- }
45
- if (claude) {
46
- const skills = [
47
- ['contentbit-author', AUTHOR_SKILL],
48
- ['contentbit-audit', AUDIT_SKILL],
49
- ];
50
- for (const [name, content] of skills) {
51
- const dir = join(cwd, '.claude/skills', name);
52
- await mkdir(dir, { recursive: true });
53
- await writeFile(join(dir, 'SKILL.md'), content, 'utf8');
54
- io.stdout(`installed: .claude/skills/${name}/SKILL.md`);
55
- }
56
- }
57
- }
58
- export async function agentsCommand(input, io) {
59
- await installAgentIntegration(input.cwd ?? process.cwd(), {
60
- claude: input.claude || undefined, // false means "detect", not "skip"
61
- agentsMd: !input.noAgentsMd,
62
- }, io);
63
- return 0;
64
- }
@@ -1,52 +0,0 @@
1
- import { createSeoBrief, formatSeoBriefMarkdown } from '@contentbit/core';
2
- import { glob } from 'tinyglobby';
3
- import { loadContentProject } from '../content-project.js';
4
- import { linkResolverOptions } from '../link-options.js';
5
- import { loadSeoConfig } from '../seo-config.js';
6
- const DEFAULT_BRIEF_GLOBS = ['content/**/*.{md,mdx}'];
7
- export async function briefCommand(input, io) {
8
- const seoConfig = await loadSeoConfig({ seoConfig: input.seoConfig });
9
- if (!seoConfig.config) {
10
- io.stderr('brief: no SEO config found. Add contentbit.seo.config.ts or pass --seo-config <path>.');
11
- return 2;
12
- }
13
- const includeGenericBlocks = !input.noGenericBlocks;
14
- const explicitGlobs = input.globs.length > 0;
15
- const globs = explicitGlobs ? input.globs : await defaultBriefGlobs();
16
- const { scan } = await loadContentProject({
17
- cmd: 'brief',
18
- positionals: globs,
19
- registry: input.registry,
20
- includeGenericBlocks,
21
- linkOptions: linkResolverOptions(input),
22
- scan: { seoConfig: seoConfig.config, seoConfigPath: seoConfig.path },
23
- allowEmpty: !explicitGlobs && globs.length === 0,
24
- });
25
- if (!scan.seo) {
26
- io.stderr('brief: SEO scan did not produce a result.');
27
- return 1;
28
- }
29
- const configErrors = scan.seo.findings.filter((finding) => finding.severity === 'error');
30
- if (configErrors.length > 0) {
31
- for (const finding of configErrors)
32
- io.stderr(`${finding.file}: ${finding.message}`);
33
- return 1;
34
- }
35
- let brief;
36
- try {
37
- brief = createSeoBrief(scan.seo, input.target);
38
- }
39
- catch (err) {
40
- io.stderr(err instanceof Error ? `brief: ${err.message}` : `brief: ${String(err)}`);
41
- return 1;
42
- }
43
- if (input.json)
44
- io.stdout(JSON.stringify(brief, null, 2));
45
- else
46
- io.stdout(formatSeoBriefMarkdown(brief));
47
- return 0;
48
- }
49
- async function defaultBriefGlobs() {
50
- const matches = await glob(DEFAULT_BRIEF_GLOBS);
51
- return matches.length > 0 ? DEFAULT_BRIEF_GLOBS : [];
52
- }
@@ -1,12 +0,0 @@
1
- import { loadRegistry } from '../load-registry.js';
2
- export async function docsCommand(input, io) {
3
- const registry = await loadRegistry(input.registry, {
4
- includeGenericBlocks: !input.noGenericBlocks,
5
- });
6
- const guide = registry.toAuthoringGuide({ audience: 'human', includeExamples: true });
7
- if (input.out)
8
- await io.writeFile(input.out, guide);
9
- else
10
- io.stdout(guide);
11
- return 0;
12
- }
@@ -1,173 +0,0 @@
1
- import { DEFAULT_MIN_SECTION_WORDS, } from '@contentbit/core';
2
- import { color, displayPath, formatCommandList, formatRows, section, severityLabel, } from '../cli-format.js';
3
- import { loadContentProject } from '../content-project.js';
4
- import { linkResolverOptions } from '../link-options.js';
5
- import { loadSeoConfig } from '../seo-config.js';
6
- export async function doctorCommand(input, io) {
7
- const minSectionWords = parseMinSectionWords(input.minSectionWords);
8
- if (minSectionWords === null) {
9
- io.stderr('doctor: --min-section-words must be a non-negative integer.');
10
- return 2;
11
- }
12
- const includeGenericBlocks = !input.noGenericBlocks;
13
- const linkOptions = linkResolverOptions(input);
14
- const seoConfig = await loadSeoConfig({ seoConfig: input.seoConfig, noSeo: input.noSeo });
15
- const { files, scan } = await loadContentProject({
16
- cmd: 'doctor',
17
- positionals: input.globs,
18
- registry: input.registry,
19
- includeGenericBlocks,
20
- linkOptions,
21
- scan: { minSectionWords, seoConfig: seoConfig.config, seoConfigPath: seoConfig.path },
22
- });
23
- const report = {
24
- files: files.length,
25
- summary: scan.summary,
26
- ...(scan.linkGraph ? { linkGraph: scan.linkGraph } : {}),
27
- ...(scan.seo
28
- ? {
29
- seo: {
30
- schemaVersion: scan.seo.schemaVersion,
31
- pages: scan.seo.pages.length,
32
- findings: scan.seo.findings,
33
- },
34
- }
35
- : {}),
36
- findings: scan.findings,
37
- };
38
- if (input.json)
39
- io.stdout(JSON.stringify(report, null, 2));
40
- else
41
- io.stdout(formatReport(report, input.globs, input.registry, includeGenericBlocks, linkOptions, hasAliases(scan.linkInputs)));
42
- if (report.summary.errors > 0)
43
- return 1;
44
- if (report.summary.warnings > 0 && input.strictWarnings)
45
- return 1;
46
- if (input.strictSeo && report.seo?.findings.some((finding) => finding.severity === 'warning')) {
47
- return 1;
48
- }
49
- return 0;
50
- }
51
- function parseMinSectionWords(value) {
52
- if (value === undefined)
53
- return DEFAULT_MIN_SECTION_WORDS;
54
- if (!/^\d+$/.test(value))
55
- return null;
56
- return Number(value);
57
- }
58
- function hasAliases(inputs) {
59
- return inputs.some((input) => Array.isArray(input.data.aliases) && input.data.aliases.length > 0);
60
- }
61
- function formatReport(report, globs, registryPath, includeGenericBlocks, linkOptions, aliasFixMayApply) {
62
- const lines = [];
63
- lines.push(section('contentbit doctor'));
64
- lines.push('');
65
- lines.push(section('Health'));
66
- lines.push(...formatRows([
67
- { label: 'Files', value: report.files },
68
- {
69
- label: 'Errors',
70
- value: report.summary.errors,
71
- tone: report.summary.errors > 0 ? 'error' : 'success',
72
- },
73
- {
74
- label: 'Warnings',
75
- value: report.summary.warnings,
76
- tone: report.summary.warnings > 0 ? 'warning' : 'success',
77
- },
78
- {
79
- label: 'Suggestions',
80
- value: report.summary.suggestions,
81
- tone: report.summary.suggestions > 0 ? 'info' : 'success',
82
- },
83
- ]));
84
- if (report.linkGraph) {
85
- lines.push('');
86
- lines.push(section('Link Graph'));
87
- lines.push(...formatRows([
88
- { label: 'Pages', value: report.linkGraph.pages },
89
- { label: 'Links', value: report.linkGraph.links },
90
- {
91
- label: 'Orphans',
92
- value: report.linkGraph.orphans,
93
- tone: report.linkGraph.orphans > 0 ? 'warning' : 'success',
94
- },
95
- ]));
96
- }
97
- if (report.seo) {
98
- lines.push('');
99
- lines.push(section('SEO'));
100
- lines.push(...formatRows([
101
- { label: 'Pages', value: report.seo.pages },
102
- {
103
- label: 'Findings',
104
- value: report.seo.findings.length,
105
- tone: report.seo.findings.length > 0 ? 'warning' : 'success',
106
- },
107
- ]));
108
- }
109
- lines.push('');
110
- if (report.findings.length === 0) {
111
- lines.push(color('No findings. Content looks healthy.', 'success'));
112
- }
113
- else {
114
- lines.push(section('Repair Plan'));
115
- report.findings.forEach((finding, index) => {
116
- lines.push(...formatFinding(index + 1, finding));
117
- });
118
- }
119
- lines.push('');
120
- lines.push(section('Next Commands'));
121
- const registryArgs = formatRegistryArgs(registryPath, includeGenericBlocks);
122
- const linkArgs = formatLinkArgs(linkOptions);
123
- const commands = [`contentbit validate ${formatGlobs(globs)}${registryArgs}${linkArgs}`];
124
- if (report.linkGraph) {
125
- commands.push(`contentbit links ${formatGlobs(globs)}${linkArgs}`);
126
- if (aliasFixMayApply && report.summary.errors === 0)
127
- commands.push(`contentbit links ${formatGlobs(globs)}${linkArgs} --fix`);
128
- }
129
- commands.push(`contentbit doctor ${formatGlobs(globs)}${registryArgs}${linkArgs} --json`);
130
- lines.push(...formatCommandList(commands));
131
- return lines.join('\n');
132
- }
133
- function formatFinding(index, finding) {
134
- const location = finding.line !== undefined && finding.column !== undefined
135
- ? `${displayPath(finding.file)}:${finding.line}:${finding.column}`
136
- : displayPath(finding.file);
137
- const lines = [
138
- ` ${index}. ${severityLabel(finding.severity)} ${finding.source} ${finding.code}`,
139
- ` ${color('at', 'muted')} ${location}`,
140
- ` ${finding.message}`,
141
- ];
142
- if (finding.hint)
143
- lines.push(` ${color('hint', 'muted')} ${finding.hint}`);
144
- return lines;
145
- }
146
- function formatGlobs(globs) {
147
- return globs.map(formatArg).join(' ');
148
- }
149
- function formatArg(value) {
150
- return /\s/.test(value) ? JSON.stringify(value) : value;
151
- }
152
- function formatRegistryArgs(registryPath, includeGenericBlocks) {
153
- const args = [];
154
- if (registryPath)
155
- args.push('--registry', formatArg(registryPath));
156
- if (!includeGenericBlocks)
157
- args.push('--no-generic-blocks');
158
- return args.length > 0 ? ` ${args.join(' ')}` : '';
159
- }
160
- function formatLinkArgs(options) {
161
- const args = [];
162
- if (options.resolve)
163
- args.push('--link-resolve', options.resolve);
164
- if (options.localeField)
165
- args.push('--locale-field', formatArg(options.localeField));
166
- if (options.slugField)
167
- args.push('--slug-field', formatArg(options.slugField));
168
- if (options.keyField)
169
- args.push('--key-field', formatArg(options.keyField));
170
- if (options.defaultLocale)
171
- args.push('--default-locale', formatArg(options.defaultLocale));
172
- return args.length > 0 ? ` ${args.join(' ')}` : '';
173
- }