contentbit 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.js CHANGED
@@ -19946,9 +19946,11 @@ function normalizeSeoPages(config2, files, linkIndex, linkOptions = {}) {
19946
19946
  for (const file2 of files) {
19947
19947
  const facts = readContentPageFacts(file2.frontmatter, linkOptions);
19948
19948
  const fm = facts.frontmatter;
19949
- const id = contentPageIdentity(facts, file2.path);
19949
+ const identity = contentPageIdentity(facts, file2.path);
19950
+ const id = seoPageId(facts, identity);
19950
19951
  const defaults = pageDefaultsForPath(config2.pageDefaults, file2.path);
19951
- const planned = byId.get(id) ?? (facts.slug ? byId.get(facts.slug) : void 0) ?? findPlannedByPath(byConfigId, file2.path);
19952
+ const planned = byId.get(id) ?? (facts.key ? byId.get(facts.key) : void 0) ?? (facts.slug ? byId.get(facts.slug) : void 0) ?? findPlannedByPath(byConfigId, file2.path);
19953
+ const pageId = planned && !facts.locale ? planned.id : id;
19952
19954
  const linkPage = linkPageByPath.get(file2.path);
19953
19955
  const page = {
19954
19956
  ...planned ?? {
@@ -19958,7 +19960,7 @@ function normalizeSeoPages(config2, files, linkIndex, linkOptions = {}) {
19958
19960
  linkedFrom: [],
19959
19961
  frontmatter: {}
19960
19962
  },
19961
- id: planned?.id ?? id,
19963
+ id: pageId,
19962
19964
  source: "existing",
19963
19965
  path: file2.path,
19964
19966
  key: facts.key ?? planned?.key,
@@ -20112,6 +20114,9 @@ function pathMatches(configId, filePath) {
20112
20114
  function normalizePath(path2) {
20113
20115
  return path2.replaceAll("\\", "/").replace(/^\.\/+/, "");
20114
20116
  }
20117
+ function seoPageId(facts, identity) {
20118
+ return facts.locale ? `${identity}:${facts.locale}` : identity;
20119
+ }
20115
20120
  function plannedLinks(page) {
20116
20121
  return stringArray2(page.frontmatter.linksTo) ?? [];
20117
20122
  }
package/dist/run.js CHANGED
@@ -19945,9 +19945,11 @@ function normalizeSeoPages(config2, files, linkIndex, linkOptions = {}) {
19945
19945
  for (const file2 of files) {
19946
19946
  const facts = readContentPageFacts(file2.frontmatter, linkOptions);
19947
19947
  const fm = facts.frontmatter;
19948
- const id = contentPageIdentity(facts, file2.path);
19948
+ const identity = contentPageIdentity(facts, file2.path);
19949
+ const id = seoPageId(facts, identity);
19949
19950
  const defaults = pageDefaultsForPath(config2.pageDefaults, file2.path);
19950
- const planned = byId.get(id) ?? (facts.slug ? byId.get(facts.slug) : void 0) ?? findPlannedByPath(byConfigId, file2.path);
19951
+ const planned = byId.get(id) ?? (facts.key ? byId.get(facts.key) : void 0) ?? (facts.slug ? byId.get(facts.slug) : void 0) ?? findPlannedByPath(byConfigId, file2.path);
19952
+ const pageId = planned && !facts.locale ? planned.id : id;
19951
19953
  const linkPage = linkPageByPath.get(file2.path);
19952
19954
  const page = {
19953
19955
  ...planned ?? {
@@ -19957,7 +19959,7 @@ function normalizeSeoPages(config2, files, linkIndex, linkOptions = {}) {
19957
19959
  linkedFrom: [],
19958
19960
  frontmatter: {}
19959
19961
  },
19960
- id: planned?.id ?? id,
19962
+ id: pageId,
19961
19963
  source: "existing",
19962
19964
  path: file2.path,
19963
19965
  key: facts.key ?? planned?.key,
@@ -20111,6 +20113,9 @@ function pathMatches(configId, filePath) {
20111
20113
  function normalizePath(path2) {
20112
20114
  return path2.replaceAll("\\", "/").replace(/^\.\/+/, "");
20113
20115
  }
20116
+ function seoPageId(facts, identity) {
20117
+ return facts.locale ? `${identity}:${facts.locale}` : identity;
20118
+ }
20114
20119
  function plannedLinks(page) {
20115
20120
  return stringArray2(page.frontmatter.linksTo) ?? [];
20116
20121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentbit",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "CLI for Content Blocks: validate, render, and generate LLM authoring instructions from your registry.",
5
5
  "keywords": [
6
6
  "cli",
@@ -38,10 +38,9 @@
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.6.1",
42
+ "@contentbit/core": "0.6.1",
43
+ "@contentbit/studio": "0.6.1"
45
44
  },
46
45
  "devDependencies": {
47
46
  "@types/node": "^25.0.9",
@@ -53,7 +52,7 @@
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
- }