@citemap/cli 0.2.0 → 0.3.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/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # @citemap/cli
2
+
3
+ Command-line tool for validating [citemap.json](https://citemaps.org) files — schema checks, quality scoring, level assessment, and diagnostic recommendations.
4
+
5
+ Supports CiteMap v2.0 and v3.0.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install -g @citemap/cli
11
+ ```
12
+
13
+ Or use with npx:
14
+
15
+ ```bash
16
+ npx @citemap/cli validate ./citemap.json
17
+ ```
18
+
19
+ ## Commands
20
+
21
+ ### `citemap validate <path>`
22
+
23
+ Validate a citemap.json file against the schema. Shows errors, warnings, quality score, and level badge.
24
+
25
+ ```
26
+ $ citemap validate .well-known/citemap.json
27
+
28
+ ✓ Valid citemap.json v3.0
29
+ Level 3 ★★★
30
+
31
+ Quality Score: 85%
32
+ Completeness 100% [████████████████████]
33
+ Modules 100% [████████████████████]
34
+ Trust 50% [██████████░░░░░░░░░░]
35
+
36
+ All validations passed.
37
+ ```
38
+
39
+ ### `citemap diagnose <path>`
40
+
41
+ Full diagnostic analysis with module coverage, field coverage, next-level hints, and recommendations.
42
+
43
+ ```
44
+ $ citemap diagnose .well-known/citemap.json
45
+
46
+ ✓ Valid citemap.json v3.0
47
+ Level 2 ★★☆
48
+
49
+ Quality Scores:
50
+ Overall 78% [████████████████░░░░]
51
+ Completeness 100% [████████████████████]
52
+ Modules 100% [████████████████████]
53
+ Trust 25% [█████░░░░░░░░░░░░░░░]
54
+
55
+ Diagnosis:
56
+ Site type: local-business
57
+ Field coverage: 135/135 (100%)
58
+ Modules present: localBusiness
59
+
60
+ To reach Level 3:
61
+ → Add a verification block with externalVerifiers or fieldConfidence
62
+ → Add verifiedClaims with externally checkable identifiers (NPI, EIN, etc.)
63
+
64
+ Recommendations:
65
+ • Add a verification block with externalVerifiers or fieldConfidence to build trust
66
+ • To reach Level 3: Add verifiedClaims with externally checkable identifiers
67
+
68
+ ✓ All validations passed.
69
+ ```
70
+
71
+ ### Other
72
+
73
+ ```bash
74
+ citemap --version # Show version
75
+ citemap --help # Show usage
76
+ ```
77
+
78
+ ## Exit Codes
79
+
80
+ - `0` — Valid citemap
81
+ - `1` — Invalid citemap or error
82
+
83
+ ## Level System
84
+
85
+ The CLI displays the computed CiteMap Level as a badge:
86
+
87
+ | Level | Badge | Requirements |
88
+ |-------|-------|-------------|
89
+ | 1 | `Level 1 ★☆☆` | Core profile (brand, lastVerified) |
90
+ | 2 | `Level 2 ★★☆` | + at least 1 module + answerContent + citationContract |
91
+ | 3 | `Level 3 ★★★` | + verification + verifiedClaims |
92
+
93
+ If a citemap claims a level via `citemapLevel` that doesn't match actual content, the CLI flags the mismatch.
94
+
95
+ ## Links
96
+
97
+ - [CiteMap Spec](https://citemaps.org)
98
+ - [GitHub](https://github.com/citemaps/citemap)
99
+ - [@citemap/schema](https://www.npmjs.com/package/@citemap/schema) — Schema + TypeScript types
100
+ - [@citemap/validator](https://www.npmjs.com/package/@citemap/validator) — Validation + quality scoring
101
+
102
+ ## License
103
+
104
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,214 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ // src/index.ts
5
+ var import_fs = require("fs");
6
+ var import_path = require("path");
7
+ var import_validator = require("@citemap/validator");
8
+ var VERSION = "0.3.0";
9
+ var colors = {
10
+ reset: "\x1B[0m",
11
+ bright: "\x1B[1m",
12
+ dim: "\x1B[2m",
13
+ red: "\x1B[31m",
14
+ green: "\x1B[32m",
15
+ yellow: "\x1B[33m",
16
+ blue: "\x1B[34m",
17
+ magenta: "\x1B[35m",
18
+ cyan: "\x1B[36m"
19
+ };
20
+ function printUsage() {
21
+ console.log(`
22
+ ${colors.bright}citemap${colors.reset} \u2014 Validate citemap.json files for AI accuracy
23
+
24
+ ${colors.bright}Usage:${colors.reset}
25
+ citemap validate <path> Validate a citemap.json file
26
+ citemap diagnose <path> Run detailed analysis with scores and level assessment
27
+ citemap --help Show this help message
28
+ citemap --version Show version number
29
+
30
+ ${colors.bright}Examples:${colors.reset}
31
+ citemap validate ./citemap.json
32
+ citemap diagnose .well-known/citemap.json
33
+
34
+ ${colors.bright}Learn more:${colors.reset}
35
+ https://github.com/citemaps/citemap
36
+ `);
37
+ }
38
+ function printVersion() {
39
+ console.log(`citemap v${VERSION}`);
40
+ }
41
+ function loadJSON(filePath) {
42
+ try {
43
+ const absolutePath = (0, import_path.resolve)(filePath);
44
+ const content = (0, import_fs.readFileSync)(absolutePath, "utf-8");
45
+ return JSON.parse(content);
46
+ } catch (error) {
47
+ if (error instanceof SyntaxError) {
48
+ console.error(`${colors.red}\u2717 Invalid JSON${colors.reset}: ${error.message}`);
49
+ process.exit(1);
50
+ }
51
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
52
+ console.error(`${colors.red}\u2717 File not found${colors.reset}: ${filePath}`);
53
+ process.exit(1);
54
+ }
55
+ console.error(`${colors.red}\u2717 Error reading file${colors.reset}: ${error instanceof Error ? error.message : String(error)}`);
56
+ process.exit(1);
57
+ }
58
+ }
59
+ function getProgressBar(percentage, width = 20) {
60
+ const filled = Math.round(percentage / 100 * width);
61
+ const empty = width - filled;
62
+ return `[${colors.green}${"\u2588".repeat(filled)}${colors.reset}${colors.dim}${"\u2591".repeat(empty)}${colors.reset}]`;
63
+ }
64
+ function scoreColor(score) {
65
+ if (score >= 80) return colors.green;
66
+ if (score >= 60) return colors.yellow;
67
+ return colors.red;
68
+ }
69
+ function formatValidationOutput(result) {
70
+ const statusIcon = result.valid ? `${colors.green}\u2713${colors.reset}` : `${colors.red}\u2717${colors.reset}`;
71
+ const statusText = result.valid ? `${colors.green}Valid${colors.reset}` : `${colors.red}Invalid${colors.reset}`;
72
+ console.log(`
73
+ ${statusIcon} ${statusText} citemap.json ${colors.dim}v${result.version}${colors.reset}`);
74
+ const lvl = result.level;
75
+ const levelColor = lvl.current === 3 ? colors.green : lvl.current === 2 ? colors.cyan : colors.yellow;
76
+ console.log(` ${levelColor}${colors.bright}${lvl.badge}${colors.reset}`);
77
+ if (!lvl.claimAccurate && lvl.claimed != null) {
78
+ console.log(` ${colors.yellow}\u26A0 Claimed Level ${lvl.claimed}, actual Level ${lvl.current}${colors.reset}`);
79
+ }
80
+ console.log();
81
+ if (result.errors.length > 0) {
82
+ console.log(`${colors.red}${colors.bright}Errors (${result.errors.length}):${colors.reset}`);
83
+ result.errors.forEach((error) => {
84
+ console.log(` ${colors.red}\u2022${colors.reset} ${error.path}: ${error.message}`);
85
+ });
86
+ console.log();
87
+ }
88
+ if (result.warnings.length > 0) {
89
+ console.log(`${colors.yellow}${colors.bright}Warnings (${result.warnings.length}):${colors.reset}`);
90
+ result.warnings.forEach((warning) => {
91
+ console.log(` ${colors.yellow}\u2022${colors.reset} ${warning.path}: ${warning.message}`);
92
+ console.log(` ${colors.dim}\u2192 ${warning.suggestion}${colors.reset}`);
93
+ });
94
+ console.log();
95
+ }
96
+ const s = result.score;
97
+ console.log(`${colors.bright}Quality Score: ${scoreColor(s.overall)}${s.overall}%${colors.reset}`);
98
+ console.log(` Completeness ${scoreColor(s.completeness)}${s.completeness.toString().padStart(3)}%${colors.reset} ${getProgressBar(s.completeness)}`);
99
+ console.log(` Modules ${scoreColor(s.modules)}${s.modules.toString().padStart(3)}%${colors.reset} ${getProgressBar(s.modules)}`);
100
+ console.log(` Trust ${scoreColor(s.trust)}${s.trust.toString().padStart(3)}%${colors.reset} ${getProgressBar(s.trust)}`);
101
+ console.log();
102
+ if (result.valid) {
103
+ console.log(`${colors.green}All validations passed.${colors.reset}
104
+ `);
105
+ }
106
+ process.exit(result.valid ? 0 : 1);
107
+ }
108
+ function formatDiagnosticOutput(data) {
109
+ const result = (0, import_validator.validateAndDiagnose)(data);
110
+ const diag = result.diagnosis;
111
+ const statusIcon = result.valid ? `${colors.green}\u2713${colors.reset}` : `${colors.red}\u2717${colors.reset}`;
112
+ const statusText = result.valid ? `${colors.green}Valid${colors.reset}` : `${colors.red}Invalid${colors.reset}`;
113
+ console.log(`
114
+ ${statusIcon} ${statusText} citemap.json ${colors.dim}v${result.version}${colors.reset}`);
115
+ const lvl = result.level;
116
+ const levelColor = lvl.current === 3 ? colors.green : lvl.current === 2 ? colors.cyan : colors.yellow;
117
+ console.log(` ${levelColor}${colors.bright}${lvl.badge}${colors.reset}`);
118
+ if (!lvl.claimAccurate && lvl.claimed != null) {
119
+ console.log(` ${colors.yellow}\u26A0 Claimed Level ${lvl.claimed}, actual Level ${lvl.current}${colors.reset}`);
120
+ }
121
+ console.log();
122
+ if (result.errors.length > 0) {
123
+ console.log(`${colors.red}${colors.bright}Errors (${result.errors.length}):${colors.reset}`);
124
+ result.errors.forEach((error) => {
125
+ console.log(` ${colors.red}\u2022${colors.reset} ${error.path}: ${error.message}`);
126
+ });
127
+ console.log();
128
+ }
129
+ if (result.warnings.length > 0) {
130
+ console.log(`${colors.yellow}${colors.bright}Warnings (${result.warnings.length}):${colors.reset}`);
131
+ result.warnings.forEach((warning) => {
132
+ console.log(` ${colors.yellow}\u2022${colors.reset} ${warning.path}: ${warning.message}`);
133
+ console.log(` ${colors.dim}\u2192 ${warning.suggestion}${colors.reset}`);
134
+ });
135
+ console.log();
136
+ }
137
+ const s = result.score;
138
+ console.log(`${colors.bright}Quality Scores:${colors.reset}`);
139
+ console.log(` Overall ${scoreColor(s.overall)}${s.overall.toString().padStart(3)}%${colors.reset} ${getProgressBar(s.overall)}`);
140
+ console.log(` Completeness ${scoreColor(s.completeness)}${s.completeness.toString().padStart(3)}%${colors.reset} ${getProgressBar(s.completeness)}`);
141
+ console.log(` Modules ${scoreColor(s.modules)}${s.modules.toString().padStart(3)}%${colors.reset} ${getProgressBar(s.modules)}`);
142
+ console.log(` Trust ${scoreColor(s.trust)}${s.trust.toString().padStart(3)}%${colors.reset} ${getProgressBar(s.trust)}`);
143
+ console.log();
144
+ console.log(`${colors.bright}Diagnosis:${colors.reset}`);
145
+ console.log(` Site type: ${colors.cyan}${diag.siteType}${colors.reset}`);
146
+ console.log(` Field coverage: ${scoreColor(diag.fieldCoverage.percentage)}${diag.fieldCoverage.filled}/${diag.fieldCoverage.total} (${diag.fieldCoverage.percentage}%)${colors.reset}`);
147
+ if (diag.presentModules.length > 0) {
148
+ console.log(` Modules present: ${colors.green}${diag.presentModules.join(", ")}${colors.reset}`);
149
+ }
150
+ if (diag.missingModules.length > 0) {
151
+ console.log(` Modules missing: ${colors.yellow}${diag.missingModules.join(", ")}${colors.reset}`);
152
+ }
153
+ console.log();
154
+ if (lvl.nextLevelHints.length > 0) {
155
+ const nextLevel = lvl.current + 1;
156
+ console.log(`${colors.bright}To reach Level ${nextLevel}:${colors.reset}`);
157
+ lvl.nextLevelHints.forEach((hint) => {
158
+ console.log(` ${colors.magenta}\u2192${colors.reset} ${hint}`);
159
+ });
160
+ console.log();
161
+ }
162
+ if (diag.recommendations.length > 0) {
163
+ console.log(`${colors.bright}Recommendations:${colors.reset}`);
164
+ diag.recommendations.forEach((rec) => {
165
+ console.log(` ${colors.blue}\u2022${colors.reset} ${rec}`);
166
+ });
167
+ console.log();
168
+ }
169
+ if (result.valid) {
170
+ console.log(`${colors.green}\u2713 All validations passed.${colors.reset}
171
+ `);
172
+ } else {
173
+ console.log(`${colors.red}\u2717 Validation failed. See errors above.${colors.reset}
174
+ `);
175
+ }
176
+ process.exit(result.valid ? 0 : 1);
177
+ }
178
+ async function main() {
179
+ const args = process.argv.slice(2);
180
+ if (args.length === 0 || args[0] === "--help") {
181
+ printUsage();
182
+ process.exit(0);
183
+ }
184
+ if (args[0] === "--version") {
185
+ printVersion();
186
+ process.exit(0);
187
+ }
188
+ const command = args[0];
189
+ const filePath = args[1];
190
+ if (!filePath) {
191
+ console.error(`${colors.red}Error: File path required${colors.reset}
192
+ `);
193
+ printUsage();
194
+ process.exit(1);
195
+ }
196
+ if (command !== "validate" && command !== "diagnose") {
197
+ console.error(`${colors.red}Error: Unknown command '${command}'${colors.reset}
198
+ `);
199
+ console.error(`Supported commands: ${colors.cyan}validate${colors.reset}, ${colors.cyan}diagnose${colors.reset}
200
+ `);
201
+ process.exit(1);
202
+ }
203
+ const data = loadJSON(filePath);
204
+ if (command === "validate") {
205
+ const result = (0, import_validator.validate)(data);
206
+ formatValidationOutput(result);
207
+ } else if (command === "diagnose") {
208
+ formatDiagnosticOutput(data);
209
+ }
210
+ }
211
+ main().catch((error) => {
212
+ console.error(`${colors.red}Fatal error:${colors.reset}`, error instanceof Error ? error.message : String(error));
213
+ process.exit(1);
214
+ });
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@citemap/cli",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Command-line tool for validating citemap.json files",
5
5
  "type": "module",
6
6
  "bin": {
7
- "citemap": "./dist/index.js"
7
+ "citemap": "./dist/index.cjs"
8
8
  },
9
9
  "files": [
10
10
  "dist"
11
11
  ],
12
12
  "scripts": {
13
- "build": "tsup src/index.ts --format cjs --dts",
14
- "dev": "node --loader ts-node/esm src/index.ts"
13
+ "build": "tsup src/index.ts --format cjs --no-dts",
14
+ "dev": "node --loader ts-node/esm src/index.ts",
15
+ "prepublishOnly": "npm run build"
15
16
  },
16
17
  "keywords": [
17
18
  "citemap",
@@ -29,9 +30,10 @@
29
30
  "node": ">=18.0.0"
30
31
  },
31
32
  "dependencies": {
32
- "@citemap/validator": "^0.2.0"
33
+ "@citemap/validator": "^0.3.1"
33
34
  },
34
35
  "devDependencies": {
36
+ "@types/node": "^25.5.0",
35
37
  "tsup": "^8.0.0",
36
38
  "typescript": "^5.4.0"
37
39
  }
package/dist/index.js DELETED
@@ -1,164 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/index.ts
4
- import { readFileSync } from "fs";
5
- import { resolve } from "path";
6
- import { validate, diagnose } from "@citemap/validator";
7
- var VERSION = "0.2.0";
8
- var colors = {
9
- reset: "\x1B[0m",
10
- bright: "\x1B[1m",
11
- red: "\x1B[31m",
12
- green: "\x1B[32m",
13
- yellow: "\x1B[33m",
14
- blue: "\x1B[34m",
15
- cyan: "\x1B[36m"
16
- };
17
- function printUsage() {
18
- console.log(`
19
- ${colors.bright}citemap${colors.reset} \u2014 Validate citemap.json files for AI accuracy
20
-
21
- ${colors.bright}Usage:${colors.reset}
22
- citemap validate <path> Validate a citemap.json file
23
- citemap diagnose <path> Run detailed analysis with scores
24
- citemap --help Show this help message
25
- citemap --version Show version number
26
-
27
- ${colors.bright}Examples:${colors.reset}
28
- citemap validate ./citemap.json
29
- citemap diagnose .well-known/citemap.json
30
-
31
- ${colors.bright}Learn more:${colors.reset}
32
- https://github.com/citemaps/citemap
33
- `);
34
- }
35
- function printVersion() {
36
- console.log(`citemap v${VERSION}`);
37
- }
38
- function loadJSON(filePath) {
39
- try {
40
- const absolutePath = resolve(filePath);
41
- const content = readFileSync(absolutePath, "utf-8");
42
- return JSON.parse(content);
43
- } catch (error) {
44
- if (error instanceof SyntaxError) {
45
- console.error(`${colors.red}\u2717 Invalid JSON${colors.reset}: ${error.message}`);
46
- process.exit(1);
47
- }
48
- if (error instanceof Error && "code" in error && error.code === "ENOENT") {
49
- console.error(`${colors.red}\u2717 File not found${colors.reset}: ${filePath}`);
50
- process.exit(1);
51
- }
52
- console.error(`${colors.red}\u2717 Error reading file${colors.reset}: ${error instanceof Error ? error.message : String(error)}`);
53
- process.exit(1);
54
- }
55
- }
56
- function formatValidationOutput(result) {
57
- const statusIcon = result.valid ? `${colors.green}\u2713${colors.reset}` : `${colors.red}\u2717${colors.reset}`;
58
- const statusText = result.valid ? `${colors.green}Valid${colors.reset}` : `${colors.red}Invalid${colors.reset}`;
59
- console.log(`
60
- ${statusIcon} ${statusText} citemap.json
61
- `);
62
- if (result.errors && result.errors.length > 0) {
63
- console.log(`${colors.red}${colors.bright}Errors (${result.errors.length}):${colors.reset}`);
64
- result.errors.forEach((error) => {
65
- console.log(` ${colors.red}\u2022${colors.reset} ${error}`);
66
- });
67
- console.log();
68
- }
69
- if (result.warnings && result.warnings.length > 0) {
70
- console.log(`${colors.yellow}${colors.bright}Warnings (${result.warnings.length}):${colors.reset}`);
71
- result.warnings.forEach((warning) => {
72
- console.log(` ${colors.yellow}\u2022${colors.reset} ${warning}`);
73
- });
74
- console.log();
75
- }
76
- if (result.valid) {
77
- console.log(`${colors.green}All validations passed.${colors.reset}
78
- `);
79
- }
80
- process.exit(result.valid ? 0 : 1);
81
- }
82
- function formatDiagnosticOutput(result) {
83
- const statusIcon = result.valid ? `${colors.green}\u2713${colors.reset}` : `${colors.red}\u2717${colors.reset}`;
84
- const statusText = result.valid ? `${colors.green}Valid${colors.reset}` : `${colors.red}Invalid${colors.reset}`;
85
- console.log(`
86
- ${statusIcon} ${statusText} citemap.json
87
- `);
88
- if (result.errors && result.errors.length > 0) {
89
- console.log(`${colors.red}${colors.bright}Errors (${result.errors.length}):${colors.reset}`);
90
- result.errors.forEach((error) => {
91
- console.log(` ${colors.red}\u2022${colors.reset} ${error}`);
92
- });
93
- console.log();
94
- }
95
- if (result.warnings && result.warnings.length > 0) {
96
- console.log(`${colors.yellow}${colors.bright}Warnings (${result.warnings.length}):${colors.reset}`);
97
- result.warnings.forEach((warning) => {
98
- console.log(` ${colors.yellow}\u2022${colors.reset} ${warning}`);
99
- });
100
- console.log();
101
- }
102
- if (result.scores) {
103
- console.log(`${colors.bright}Quality Scores:${colors.reset}`);
104
- const scores = result.scores;
105
- Object.entries(scores).forEach(([key, score]) => {
106
- const percentage = Math.round(score * 100);
107
- const scoreColor = percentage >= 80 ? colors.green : percentage >= 60 ? colors.yellow : colors.red;
108
- const bar = getProgressBar(percentage);
109
- console.log(` ${key.padEnd(20)} ${scoreColor}${percentage.toString().padStart(3)}%${colors.reset} ${bar}`);
110
- });
111
- console.log();
112
- }
113
- if (result.valid) {
114
- console.log(`${colors.green}\u2713 All validations passed.${colors.reset}
115
- `);
116
- } else {
117
- console.log(`${colors.red}\u2717 Validation failed. See errors above.${colors.reset}
118
- `);
119
- }
120
- process.exit(result.valid ? 0 : 1);
121
- }
122
- function getProgressBar(percentage, width = 20) {
123
- const filled = Math.round(percentage / 100 * width);
124
- const empty = width - filled;
125
- return `[${colors.green}${"\u2588".repeat(filled)}${colors.reset}${colors.bright}${"\u2591".repeat(empty)}${colors.reset}]`;
126
- }
127
- async function main() {
128
- const args = process.argv.slice(2);
129
- if (args.length === 0 || args[0] === "--help") {
130
- printUsage();
131
- process.exit(0);
132
- }
133
- if (args[0] === "--version") {
134
- printVersion();
135
- process.exit(0);
136
- }
137
- const command = args[0];
138
- const filePath = args[1];
139
- if (!filePath) {
140
- console.error(`${colors.red}Error: File path required${colors.reset}
141
- `);
142
- printUsage();
143
- process.exit(1);
144
- }
145
- if (command !== "validate" && command !== "diagnose") {
146
- console.error(`${colors.red}Error: Unknown command '${command}'${colors.reset}
147
- `);
148
- console.error(`Supported commands: ${colors.cyan}validate${colors.reset}, ${colors.cyan}diagnose${colors.reset}
149
- `);
150
- process.exit(1);
151
- }
152
- const data = loadJSON(filePath);
153
- if (command === "validate") {
154
- const result = validate(data);
155
- formatValidationOutput(result);
156
- } else if (command === "diagnose") {
157
- const result = diagnose(data);
158
- formatDiagnosticOutput(result);
159
- }
160
- }
161
- main().catch((error) => {
162
- console.error(`${colors.red}Fatal error:${colors.reset}`, error instanceof Error ? error.message : String(error));
163
- process.exit(1);
164
- });