citedwise 0.0.0-stage → 0.1.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 (5) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -2
  3. package/cli.js +215 -0
  4. package/package.json +39 -4
  5. package/product.js +18 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CitedWise
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,16 @@
1
- # Temporary Holding Version
1
+ # citedwise
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Check how ready a web page is to be read and cited by AI search engines: ChatGPT, Claude, Perplexity, Gemini and Google AI Overviews.
4
+
5
+ The CLI calls the CitedWise API. Get a free API key (50 audits a month) at https://citedwise.com/login.
6
+
7
+ ```bash
8
+ export CITEDWISE_API_KEY=cw_live_...
9
+ npx citedwise example.com
10
+ npx citedwise example.com --json
11
+ npx citedwise example.com --fail-under 80 # CI gate
12
+ npx citedwise site example.com # whole-site audit (paid plans)
13
+ npx citedwise llms-txt example.com > public/llms.txt
14
+ ```
15
+
16
+ Checks include AI crawler access in robots.txt (search vs. training bots), noindex/nosnippet, llms.txt, sitemap, server-side rendering, structured data, headings, metadata, trust signals, and domain/TLS health.
package/cli.js ADDED
@@ -0,0 +1,215 @@
1
+ #!/usr/bin/env node
2
+ // CitedWise CLI: a thin client for the CitedWise API. It contains no audit logic of its own;
3
+ // audits run on the server, are stored, and come back with a shareable report link.
4
+ // Only type imports from the rest of the codebase (plus the dependency-free product.ts),
5
+ // so the published package stays tiny.
6
+ import { parseArgs } from 'node:util';
7
+ import { PRODUCT, PRODUCT_URL } from './product.js';
8
+ const DEFAULT_API = PRODUCT_URL;
9
+ const BIN = PRODUCT.slug;
10
+ const ENV_KEY = `${PRODUCT.envPrefix}_API_KEY`;
11
+ const ENV_URL = `${PRODUCT.envPrefix}_API_URL`;
12
+ const HELP = `${BIN}: check how ready a page is to be read and cited by AI search
13
+
14
+ Usage
15
+ ${BIN} <url> [options] audit one page
16
+ ${BIN} site <url> [--max-pages n] audit a whole site (Pro and Agency plans)
17
+ ${BIN} llms-txt <url> generate an llms.txt draft
18
+ ${BIN} whoami show your plan and usage
19
+
20
+ Options
21
+ --json Print the full JSON result
22
+ --fail-under <n> Exit with code 1 if the score is below n (for CI)
23
+ --fresh Ignore the 10-minute result cache
24
+ --api-key <key> API key (default: $${ENV_KEY})
25
+ --api-url <url> API base URL (default: $${ENV_URL} or ${DEFAULT_API})
26
+ -h, --help Show this help
27
+
28
+ Get a free API key (50 audits/month) at ${DEFAULT_API}/login.
29
+
30
+ Exit codes: 0 ok, 1 below --fail-under, 2 usage error, 3 audit/API error, 4 auth/plan/quota.
31
+ `;
32
+ const tty = process.stdout.isTTY && !process.env.NO_COLOR;
33
+ const c = (code) => (s) => (tty ? `\x1b[${code}m${s}\x1b[0m` : s);
34
+ const green = c('32'), yellow = c('33'), red = c('31'), dim = c('2'), bold = c('1'), cyan = c('36');
35
+ const ICON = { pass: green('✔'), warn: yellow('▲'), fail: red('✖'), info: dim('ℹ') };
36
+ const gradeColor = (score) => (score >= 80 ? green : score >= 65 ? yellow : red);
37
+ export class ApiError extends Error {
38
+ status;
39
+ code;
40
+ constructor(status, code, message) {
41
+ super(message);
42
+ this.status = status;
43
+ this.code = code;
44
+ }
45
+ }
46
+ export function renderText(r, fixes, reportUrl) {
47
+ const out = [];
48
+ const col = gradeColor(r.score);
49
+ out.push('', `${bold(`${PRODUCT.name} AI-readiness report`)} ${dim(r.finalUrl)}`, '');
50
+ out.push(` Score ${col(bold(`${r.score}/100`))} Grade ${col(bold(r.grade))}`);
51
+ out.push(` ${r.summary}`, '');
52
+ for (const cat of r.categories) {
53
+ const bar = '█'.repeat(Math.round(cat.score / 10)).padEnd(10, '░');
54
+ out.push(` ${cat.label.padEnd(30)} ${gradeColor(cat.score)(bar)} ${String(cat.score).padStart(3)}`);
55
+ }
56
+ out.push('');
57
+ for (const ch of r.checks)
58
+ out.push(` ${ICON[ch.status]} ${ch.title}${dim(' — ' + ch.message)}`);
59
+ if (fixes.length) {
60
+ out.push('', bold(' Top fixes'));
61
+ fixes.slice(0, 5).forEach((f, i) => out.push(` ${i + 1}. ${cyan(f.title)}: ${f.fix ?? f.message}`));
62
+ }
63
+ if (reportUrl)
64
+ out.push('', ` Full report: ${reportUrl}`);
65
+ out.push('');
66
+ return out.join('\n');
67
+ }
68
+ export class Client {
69
+ base;
70
+ key;
71
+ constructor(base, key) {
72
+ this.base = base.replace(/\/$/, '');
73
+ this.key = key;
74
+ }
75
+ async call(method, path, body) {
76
+ for (let attempt = 0;; attempt++) {
77
+ let res;
78
+ try {
79
+ res = await fetch(this.base + path, {
80
+ method,
81
+ headers: { authorization: `Bearer ${this.key}`, 'content-type': 'application/json', 'user-agent': `${BIN}-cli` },
82
+ body: body === undefined ? undefined : JSON.stringify(body),
83
+ signal: AbortSignal.timeout(120_000),
84
+ });
85
+ }
86
+ catch (e) {
87
+ if (attempt < 3) {
88
+ await new Promise((r) => setTimeout(r, 2000 * (attempt + 1)));
89
+ continue;
90
+ }
91
+ throw e;
92
+ }
93
+ const text = await res.text();
94
+ let json;
95
+ try {
96
+ json = JSON.parse(text);
97
+ }
98
+ catch {
99
+ json = {};
100
+ }
101
+ // Busy, per-minute rate limit, or a proxy/gateway error page: back off and retry a few times.
102
+ const retryable = [502, 503, 504].includes(res.status) || (res.status === 429 && json.error?.code === 'rate_limited');
103
+ if (retryable && attempt < 3) {
104
+ await new Promise((r) => setTimeout(r, Math.min(30, Number(res.headers.get('retry-after')) || 5 * (attempt + 1)) * 1000));
105
+ continue;
106
+ }
107
+ if (!json || !Object.keys(json).length)
108
+ throw new ApiError(res.status, 'bad_response', `Unexpected response from ${this.base} (HTTP ${res.status}).`);
109
+ if (!res.ok)
110
+ throw new ApiError(res.status, json.error?.code ?? 'error', json.error?.message ?? `HTTP ${res.status}`);
111
+ return json;
112
+ }
113
+ }
114
+ }
115
+ const write = (s) => process.stdout.write(s);
116
+ async function main(argv, env = process.env) {
117
+ const { values, positionals } = parseArgs({
118
+ args: argv,
119
+ allowPositionals: true,
120
+ options: {
121
+ json: { type: 'boolean', default: false },
122
+ 'fail-under': { type: 'string' },
123
+ 'max-pages': { type: 'string' },
124
+ fresh: { type: 'boolean', default: false },
125
+ 'api-key': { type: 'string' },
126
+ 'api-url': { type: 'string' },
127
+ help: { type: 'boolean', short: 'h', default: false },
128
+ },
129
+ });
130
+ if (values.help) {
131
+ write(HELP);
132
+ return 0;
133
+ }
134
+ if (positionals.length === 0) {
135
+ write(HELP);
136
+ return 2;
137
+ }
138
+ const key = values['api-key'] || env[ENV_KEY] || '';
139
+ if (!key) {
140
+ process.stderr.write(`${BIN}: no API key. Get a free one at ${DEFAULT_API}/login and set ${ENV_KEY}.\n`);
141
+ return 4;
142
+ }
143
+ const client = new Client(values['api-url'] || env[ENV_URL] || DEFAULT_API, key);
144
+ const threshold = values['fail-under'] !== undefined ? Number(values['fail-under']) : null;
145
+ if (threshold !== null && !Number.isFinite(threshold)) {
146
+ process.stderr.write(`${BIN}: --fail-under must be a number\n`);
147
+ return 2;
148
+ }
149
+ const gate = (score) => {
150
+ if (threshold !== null && (score === null || score < threshold)) {
151
+ process.stderr.write(`${BIN}: score ${score ?? 'n/a'} is below the required ${threshold}\n`);
152
+ return 1;
153
+ }
154
+ return 0;
155
+ };
156
+ const [cmd, arg] = positionals;
157
+ if (cmd === 'whoami') {
158
+ const me = await client.call('GET', '/api/v1/me');
159
+ write(values.json ? JSON.stringify(me, null, 2) + '\n' : `${me.email}: ${me.plan} plan, ${me.usage.used}/${me.usage.limit} audits this ${me.usage.period}\n`);
160
+ return 0;
161
+ }
162
+ if (cmd === 'llms-txt') {
163
+ if (!arg)
164
+ return usage(`${BIN} llms-txt <url>`);
165
+ const r = await client.call('POST', '/api/v1/llms-txt', { url: arg });
166
+ write(values.json ? JSON.stringify(r, null, 2) + '\n' : r.llmsTxt);
167
+ return 0;
168
+ }
169
+ if (cmd === 'site') {
170
+ if (!arg)
171
+ return usage(`${BIN} site <url> [--max-pages n]`);
172
+ const maxPages = values['max-pages'] ? Number(values['max-pages']) : undefined;
173
+ let s = (await client.call('POST', '/api/v1/sites', { url: arg, maxPages })).site;
174
+ let last = '';
175
+ while (s.status === 'queued' || s.status === 'running') {
176
+ const line = s.status === 'queued' ? 'queued…' : `${s.pagesDone}/${s.pagesTotal || '?'} pages`;
177
+ if (!values.json && process.stderr.isTTY && line !== last)
178
+ process.stderr.write(`\r ${line} `);
179
+ last = line;
180
+ await new Promise((r) => setTimeout(r, 3000));
181
+ s = (await client.call('GET', `/api/v1/sites/${s.id}`)).site;
182
+ }
183
+ if (!values.json && process.stderr.isTTY)
184
+ process.stderr.write('\r');
185
+ if (values.json)
186
+ write(JSON.stringify(s, null, 2) + '\n');
187
+ else if (s.status === 'failed')
188
+ process.stderr.write(`${BIN}: ${s.error}\n`);
189
+ else {
190
+ write(`\n${bold('Whole-site AI readiness')} ${dim(arg)}\n\n Average score ${gradeColor(s.score ?? 0)(bold(`${s.score}/100`))} across ${s.summary?.pagesAudited} pages\n\n`);
191
+ for (const i of s.summary?.issues.slice(0, 8) ?? [])
192
+ write(` ${i.fail ? ICON.fail : ICON.warn} ${i.title} ${dim(`— ${i.fail} failing, ${i.warn} to improve`)}\n`);
193
+ write(`\n Full report: ${s.reportUrl}\n\n`);
194
+ }
195
+ if (s.status === 'failed')
196
+ return 3;
197
+ return gate(s.score);
198
+ }
199
+ const r = await client.call('POST', '/api/v1/audits', { url: cmd, fresh: values.fresh });
200
+ write(values.json ? JSON.stringify(r, null, 2) + '\n' : renderText(r.report, r.fixes, r.reportUrl));
201
+ return gate(r.report.score);
202
+ }
203
+ function usage(text) {
204
+ process.stderr.write(`Usage: ${text}\n`);
205
+ return 2;
206
+ }
207
+ if (import.meta.main) {
208
+ main(process.argv.slice(2)).then((code) => process.exit(code), (err) => {
209
+ process.stderr.write(`${BIN}: ${err.message}\n`);
210
+ const auth = err instanceof ApiError && [401, 403].includes(err.status);
211
+ const quota = err instanceof ApiError && err.code === 'quota_exceeded';
212
+ process.exit(auth || quota ? 4 : 3);
213
+ });
214
+ }
215
+ export { main };
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "citedwise",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Check how ready a web page is to be read and cited by AI search (ChatGPT, Claude, Perplexity, Gemini). CI-friendly.",
5
+ "keywords": [
6
+ "geo",
7
+ "aeo",
8
+ "llms.txt",
9
+ "seo",
10
+ "ai-search",
11
+ "chatgpt",
12
+ "robots.txt",
13
+ "audit",
14
+ "cli"
15
+ ],
16
+ "license": "MIT",
17
+ "type": "module",
18
+ "bin": {
19
+ "citedwise": "cli.js"
20
+ },
21
+ "engines": {
22
+ "node": ">=20.11"
23
+ },
24
+ "homepage": "https://citedwise.com",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/martinsuchenak/citedwise.git"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/martinsuchenak/citedwise/issues"
31
+ },
32
+ "files": [
33
+ "cli.js",
34
+ "product.js",
35
+ "README.md",
36
+ "LICENSE"
37
+ ],
38
+ "publishConfig": {
39
+ "access": "public"
40
+ }
41
+ }
package/product.js ADDED
@@ -0,0 +1,18 @@
1
+ // Product identity in one place. Renaming the product = edit this file (plus the
2
+ // package names in package.json / action.yml, which npm and GitHub read statically).
3
+ // Dependency-free on purpose: the published CLI imports it too.
4
+ export const PRODUCT = {
5
+ /** Display name in pages, emails and reports. */
6
+ name: 'CitedWise',
7
+ /** Lower-case wordmark, npm package and CLI binary name. */
8
+ slug: 'citedwise',
9
+ /** Public domain (no scheme). */
10
+ domain: 'citedwise.com',
11
+ /** Our crawler's user-agent token. */
12
+ bot: 'CitedWiseBot',
13
+ /** Prefix for the CLI's environment variables, e.g. CITEDWISE_API_KEY. */
14
+ envPrefix: 'CITEDWISE',
15
+ /** Prefix of API keys (`cw_live_…`) and the session cookie (`cw_session`). */
16
+ keyPrefix: 'cw',
17
+ };
18
+ export const PRODUCT_URL = `https://${PRODUCT.domain}`;