@citemap/cli 0.2.0 → 0.3.2

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 (3) hide show
  1. package/README.md +104 -0
  2. package/dist/index.js +86 -36
  3. package/package.json +6 -5
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.js CHANGED
@@ -1,17 +1,20 @@
1
1
  #!/usr/bin/env node
2
+ "use strict";
2
3
 
3
4
  // 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";
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";
8
9
  var colors = {
9
10
  reset: "\x1B[0m",
10
11
  bright: "\x1B[1m",
12
+ dim: "\x1B[2m",
11
13
  red: "\x1B[31m",
12
14
  green: "\x1B[32m",
13
15
  yellow: "\x1B[33m",
14
16
  blue: "\x1B[34m",
17
+ magenta: "\x1B[35m",
15
18
  cyan: "\x1B[36m"
16
19
  };
17
20
  function printUsage() {
@@ -20,7 +23,7 @@ ${colors.bright}citemap${colors.reset} \u2014 Validate citemap.json files for AI
20
23
 
21
24
  ${colors.bright}Usage:${colors.reset}
22
25
  citemap validate <path> Validate a citemap.json file
23
- citemap diagnose <path> Run detailed analysis with scores
26
+ citemap diagnose <path> Run detailed analysis with scores and level assessment
24
27
  citemap --help Show this help message
25
28
  citemap --version Show version number
26
29
 
@@ -37,8 +40,8 @@ function printVersion() {
37
40
  }
38
41
  function loadJSON(filePath) {
39
42
  try {
40
- const absolutePath = resolve(filePath);
41
- const content = readFileSync(absolutePath, "utf-8");
43
+ const absolutePath = (0, import_path.resolve)(filePath);
44
+ const content = (0, import_fs.readFileSync)(absolutePath, "utf-8");
42
45
  return JSON.parse(content);
43
46
  } catch (error) {
44
47
  if (error instanceof SyntaxError) {
@@ -53,60 +56,113 @@ function loadJSON(filePath) {
53
56
  process.exit(1);
54
57
  }
55
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
+ }
56
69
  function formatValidationOutput(result) {
57
70
  const statusIcon = result.valid ? `${colors.green}\u2713${colors.reset}` : `${colors.red}\u2717${colors.reset}`;
58
71
  const statusText = result.valid ? `${colors.green}Valid${colors.reset}` : `${colors.red}Invalid${colors.reset}`;
59
72
  console.log(`
60
- ${statusIcon} ${statusText} citemap.json
61
- `);
62
- if (result.errors && result.errors.length > 0) {
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) {
63
82
  console.log(`${colors.red}${colors.bright}Errors (${result.errors.length}):${colors.reset}`);
64
83
  result.errors.forEach((error) => {
65
- console.log(` ${colors.red}\u2022${colors.reset} ${error}`);
84
+ console.log(` ${colors.red}\u2022${colors.reset} ${error.path}: ${error.message}`);
66
85
  });
67
86
  console.log();
68
87
  }
69
- if (result.warnings && result.warnings.length > 0) {
88
+ if (result.warnings.length > 0) {
70
89
  console.log(`${colors.yellow}${colors.bright}Warnings (${result.warnings.length}):${colors.reset}`);
71
90
  result.warnings.forEach((warning) => {
72
- console.log(` ${colors.yellow}\u2022${colors.reset} ${warning}`);
91
+ console.log(` ${colors.yellow}\u2022${colors.reset} ${warning.path}: ${warning.message}`);
92
+ console.log(` ${colors.dim}\u2192 ${warning.suggestion}${colors.reset}`);
73
93
  });
74
94
  console.log();
75
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();
76
102
  if (result.valid) {
77
103
  console.log(`${colors.green}All validations passed.${colors.reset}
78
104
  `);
79
105
  }
80
106
  process.exit(result.valid ? 0 : 1);
81
107
  }
82
- function formatDiagnosticOutput(result) {
108
+ function formatDiagnosticOutput(data) {
109
+ const result = (0, import_validator.validateAndDiagnose)(data);
110
+ const diag = result.diagnosis;
83
111
  const statusIcon = result.valid ? `${colors.green}\u2713${colors.reset}` : `${colors.red}\u2717${colors.reset}`;
84
112
  const statusText = result.valid ? `${colors.green}Valid${colors.reset}` : `${colors.red}Invalid${colors.reset}`;
85
113
  console.log(`
86
- ${statusIcon} ${statusText} citemap.json
87
- `);
88
- if (result.errors && result.errors.length > 0) {
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) {
89
123
  console.log(`${colors.red}${colors.bright}Errors (${result.errors.length}):${colors.reset}`);
90
124
  result.errors.forEach((error) => {
91
- console.log(` ${colors.red}\u2022${colors.reset} ${error}`);
125
+ console.log(` ${colors.red}\u2022${colors.reset} ${error.path}: ${error.message}`);
92
126
  });
93
127
  console.log();
94
128
  }
95
- if (result.warnings && result.warnings.length > 0) {
129
+ if (result.warnings.length > 0) {
96
130
  console.log(`${colors.yellow}${colors.bright}Warnings (${result.warnings.length}):${colors.reset}`);
97
131
  result.warnings.forEach((warning) => {
98
- console.log(` ${colors.yellow}\u2022${colors.reset} ${warning}`);
132
+ console.log(` ${colors.yellow}\u2022${colors.reset} ${warning.path}: ${warning.message}`);
133
+ console.log(` ${colors.dim}\u2192 ${warning.suggestion}${colors.reset}`);
99
134
  });
100
135
  console.log();
101
136
  }
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}`);
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}`);
110
166
  });
111
167
  console.log();
112
168
  }
@@ -119,11 +175,6 @@ ${statusIcon} ${statusText} citemap.json
119
175
  }
120
176
  process.exit(result.valid ? 0 : 1);
121
177
  }
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
178
  async function main() {
128
179
  const args = process.argv.slice(2);
129
180
  if (args.length === 0 || args[0] === "--help") {
@@ -151,11 +202,10 @@ async function main() {
151
202
  }
152
203
  const data = loadJSON(filePath);
153
204
  if (command === "validate") {
154
- const result = validate(data);
205
+ const result = (0, import_validator.validate)(data);
155
206
  formatValidationOutput(result);
156
207
  } else if (command === "diagnose") {
157
- const result = diagnose(data);
158
- formatDiagnosticOutput(result);
208
+ formatDiagnosticOutput(data);
159
209
  }
160
210
  }
161
211
  main().catch((error) => {
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@citemap/cli",
3
- "version": "0.2.0",
3
+ "version": "0.3.2",
4
4
  "description": "Command-line tool for validating citemap.json files",
5
- "type": "module",
6
5
  "bin": {
7
6
  "citemap": "./dist/index.js"
8
7
  },
@@ -10,8 +9,9 @@
10
9
  "dist"
11
10
  ],
12
11
  "scripts": {
13
- "build": "tsup src/index.ts --format cjs --dts",
14
- "dev": "node --loader ts-node/esm src/index.ts"
12
+ "build": "tsup src/index.ts --format cjs --no-dts --out-dir dist && test -f dist/index.cjs && mv dist/index.cjs dist/index.js || true",
13
+ "dev": "node --loader ts-node/esm src/index.ts",
14
+ "prepublishOnly": "npm run build"
15
15
  },
16
16
  "keywords": [
17
17
  "citemap",
@@ -29,9 +29,10 @@
29
29
  "node": ">=18.0.0"
30
30
  },
31
31
  "dependencies": {
32
- "@citemap/validator": "^0.2.0"
32
+ "@citemap/validator": "^0.3.1"
33
33
  },
34
34
  "devDependencies": {
35
+ "@types/node": "^25.5.0",
35
36
  "tsup": "^8.0.0",
36
37
  "typescript": "^5.4.0"
37
38
  }