@crawl82/cli 0.0.0-stage → 0.5.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.
- package/AGENTS.md +257 -0
- package/README.md +120 -2
- package/dist/api-types.generated.js +12 -0
- package/dist/api-types.generated.js.map +1 -0
- package/dist/commands/api.js +111 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/auth.js +284 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/completion.js +120 -0
- package/dist/commands/completion.js.map +1 -0
- package/dist/commands/doctor.js +141 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/feedback.js +39 -0
- package/dist/commands/feedback.js.map +1 -0
- package/dist/commands/help-json.js +144 -0
- package/dist/commands/help-json.js.map +1 -0
- package/dist/commands/mcp.js +129 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/read.js +107 -0
- package/dist/commands/read.js.map +1 -0
- package/dist/commands/sites.js +604 -0
- package/dist/commands/sites.js.map +1 -0
- package/dist/credentials.js +151 -0
- package/dist/credentials.js.map +1 -0
- package/dist/errors.js +150 -0
- package/dist/errors.js.map +1 -0
- package/dist/exit-codes.js +82 -0
- package/dist/exit-codes.js.map +1 -0
- package/dist/http.js +260 -0
- package/dist/http.js.map +1 -0
- package/dist/index.js +158 -0
- package/dist/index.js.map +1 -0
- package/dist/keychain.js +185 -0
- package/dist/keychain.js.map +1 -0
- package/dist/oauth/browser.js +33 -0
- package/dist/oauth/browser.js.map +1 -0
- package/dist/oauth/pkce.js +118 -0
- package/dist/oauth/pkce.js.map +1 -0
- package/dist/oauth/server.js +281 -0
- package/dist/oauth/server.js.map +1 -0
- package/dist/operations.generated.js +6290 -0
- package/dist/operations.generated.js.map +1 -0
- package/dist/output.js +161 -0
- package/dist/output.js.map +1 -0
- package/dist/refresh-lock.js +84 -0
- package/dist/refresh-lock.js.map +1 -0
- package/dist/run.js +186 -0
- package/dist/run.js.map +1 -0
- package/dist/session.js +147 -0
- package/dist/session.js.map +1 -0
- package/dist/version.js +34 -0
- package/dist/version.js.map +1 -0
- package/package.json +47 -4
|
@@ -0,0 +1,604 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `crawl82 sites | brief | issues | pages | actions | crawls | controls`: Crawl82's own commands.
|
|
3
|
+
*
|
|
4
|
+
* The same operations as the REST API (`/v1/sites/...`) and the MCP tools; the coverage test fails when an
|
|
5
|
+
* operation has no command here or a field has no flag. The rules of every command in this CLI:
|
|
6
|
+
*
|
|
7
|
+
* 1. One write per command, so a command cannot half-fail.
|
|
8
|
+
* 2. `session.printer.data(raw, view)`: the RAW object goes to JSON, the view only to a terminal.
|
|
9
|
+
* 3. Exit codes carry meaning (`run()` maps the API's error families).
|
|
10
|
+
* 4. `--help` is the documentation most people and every agent read: written for someone new.
|
|
11
|
+
*
|
|
12
|
+
* `crawl82 brief <site_id>` is the one an agent starts from: in a terminal it prints the Markdown brief
|
|
13
|
+
* itself, ready to read; `--json` gives the whole object.
|
|
14
|
+
*/
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
16
|
+
import { ACTION_STATUS_VALUES, ISSUE_PRIORITY_VALUES, SETTABLE_ACTION_STATUS_VALUES, SITE_CADENCE_VALUES, } from "../api-types.generated.js";
|
|
17
|
+
import { formatDate, formatNumber } from "../output.js";
|
|
18
|
+
import { CliError, usageError } from "../errors.js";
|
|
19
|
+
import { EXIT } from "../exit-codes.js";
|
|
20
|
+
import { confirmSpend, run, typedCommand, unwrap } from "../run.js";
|
|
21
|
+
const list = (values) => values.join(" | ");
|
|
22
|
+
const csv = (value) => (value === undefined ? undefined : value.split(",").map((v) => v.trim()).filter(Boolean));
|
|
23
|
+
const int = (value, flag) => {
|
|
24
|
+
if (value === undefined)
|
|
25
|
+
return undefined;
|
|
26
|
+
const n = Number(value);
|
|
27
|
+
if (!Number.isInteger(n))
|
|
28
|
+
throw usageError(`${flag} takes a whole number.`, flag.slice(2));
|
|
29
|
+
return n;
|
|
30
|
+
};
|
|
31
|
+
const str = (value) => (value === null || value === undefined ? "-" : String(value));
|
|
32
|
+
export function registerSites(program) {
|
|
33
|
+
// ── sites ────────────────────────────────────────────────────────────────
|
|
34
|
+
const sites = program.command("sites").description("The workspace's sites: list, add, read, change");
|
|
35
|
+
sites
|
|
36
|
+
.command("list")
|
|
37
|
+
.description("List sites with their last crawl and open actions")
|
|
38
|
+
.action(async (_options, command) => {
|
|
39
|
+
await run(command, async (session) => {
|
|
40
|
+
const data = unwrap((await session.client.request("GET", "/sites")).body);
|
|
41
|
+
session.printer.data(data, {
|
|
42
|
+
rows: data.sites,
|
|
43
|
+
columns: [
|
|
44
|
+
{ header: "ID", value: (row) => row.id },
|
|
45
|
+
{ header: "NAME", value: (row) => row.name },
|
|
46
|
+
{ header: "CADENCE", value: (row) => row.cadence },
|
|
47
|
+
{ header: "OPEN ACTIONS", value: (row) => str(row.open_actions) },
|
|
48
|
+
{ header: "NEXT CRAWL", value: (row) => (row.next_crawl_at ? formatDate(row.next_crawl_at) : "-") },
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
sites
|
|
54
|
+
.command("add <url>")
|
|
55
|
+
.description("Add a site and start its first crawl (reads from the plan's pages a month; needs crawls:create)")
|
|
56
|
+
.option("--cadence <cadence>", list(SITE_CADENCE_VALUES))
|
|
57
|
+
.option("--max-urls <n>", "URLs per crawl, the first one included (default: the plan's limit)")
|
|
58
|
+
.option("-y, --yes", "Start the first crawl without asking")
|
|
59
|
+
.action(async (url, options, command) => {
|
|
60
|
+
await run(command, async (session) => {
|
|
61
|
+
await confirmSpend(session, `Add ${url} and crawl it now? Its first crawl reads from your plan's pages this month.`, { yes: options.yes, command: typedCommand(command, ["-y", "--yes"]), spends: "credits" });
|
|
62
|
+
const response = await session.client.request("POST", "/sites", { body: { url, ...(options.cadence ? { cadence: options.cadence } : {}), ...(options.maxUrls !== undefined ? { max_urls: int(options.maxUrls, "--max-urls") } : {}) } });
|
|
63
|
+
const data = unwrap(response.body);
|
|
64
|
+
session.printer.data(data, { fields: [{ label: "Site", value: data.siteId }, { label: "Crawling", value: data.crawlStarted ? "yes" : "no" }] });
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
sites
|
|
68
|
+
.command("get <site_id>")
|
|
69
|
+
.description("A site's settings and its crawl log, newest first")
|
|
70
|
+
.action(async (siteId, _options, command) => {
|
|
71
|
+
await run(command, async (session) => {
|
|
72
|
+
const data = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}`)).body);
|
|
73
|
+
session.printer.data(data, {
|
|
74
|
+
fields: [
|
|
75
|
+
{ label: "Name", value: data.site.name },
|
|
76
|
+
{ label: "Start URL", value: data.site.start_url },
|
|
77
|
+
{ label: "Cadence", value: data.site.cadence },
|
|
78
|
+
{ label: "URLs per crawl", value: formatNumber(data.site.max_urls) },
|
|
79
|
+
],
|
|
80
|
+
rows: data.crawls,
|
|
81
|
+
columns: [
|
|
82
|
+
{ header: "CRAWL", value: (row) => `#${str(row.number)}` },
|
|
83
|
+
{ header: "ID", value: (row) => row.id },
|
|
84
|
+
{ header: "STATUS", value: (row) => row.status },
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
sites
|
|
90
|
+
.command("overview <site_id>")
|
|
91
|
+
.description("The latest crawl, Search Console over 28 days, the open actions")
|
|
92
|
+
.action(async (siteId, _options, command) => {
|
|
93
|
+
await run(command, async (session) => {
|
|
94
|
+
const data = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}/overview`)).body);
|
|
95
|
+
session.printer.data(data, { fields: [{ label: "Latest crawl", value: data.crawl ? `#${str(data.crawl.number)}, ${str(data.crawl.finished_at)}` : "none yet" }, { label: "Open actions", value: String(data.open_actions.length) }] });
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
sites
|
|
99
|
+
.command("update <site_id>")
|
|
100
|
+
.description("Change a site's name, start URL, cadence, crawl days, URL budget, or include and exclude patterns")
|
|
101
|
+
.option("--name <name>", "New name")
|
|
102
|
+
.option("--start-url <url>", "New start URL")
|
|
103
|
+
.option("--cadence <cadence>", list(SITE_CADENCE_VALUES))
|
|
104
|
+
.option("--crawl-days <days>", "Weekly: the days, comma separated (mon,thu); one on Starter, several on Pro")
|
|
105
|
+
.option("--max-urls <n>", "URLs per crawl, within the plan's limit")
|
|
106
|
+
.option("--include <globs>", "Only crawl URLs matching these globs, comma separated (/blog/*). Replaces the list")
|
|
107
|
+
.option("--exclude <globs>", "Never crawl URLs matching these globs, comma separated. Replaces the list")
|
|
108
|
+
.action(async (siteId, options, command) => {
|
|
109
|
+
await run(command, async (session) => {
|
|
110
|
+
const body = {
|
|
111
|
+
...(options.name !== undefined ? { name: options.name } : {}),
|
|
112
|
+
...(options.startUrl !== undefined ? { start_url: options.startUrl } : {}),
|
|
113
|
+
...(options.cadence !== undefined ? { cadence: options.cadence } : {}),
|
|
114
|
+
...(options.crawlDays !== undefined ? { crawl_days: (csv(options.crawlDays) ?? []).map((d) => d.toLowerCase().slice(0, 3)) } : {}),
|
|
115
|
+
...(options.maxUrls !== undefined ? { max_urls: int(options.maxUrls, "--max-urls") } : {}),
|
|
116
|
+
...(options.include !== undefined ? { include: csv(options.include) } : {}),
|
|
117
|
+
...(options.exclude !== undefined ? { exclude: csv(options.exclude) } : {}),
|
|
118
|
+
};
|
|
119
|
+
if (!Object.keys(body).length)
|
|
120
|
+
throw usageError("Pass at least one setting to change.", "name");
|
|
121
|
+
const data = unwrap((await session.client.request("PATCH", `/sites/${encodeURIComponent(siteId)}`, { body })).body);
|
|
122
|
+
session.printer.data(data, { summary: "Updated. It takes effect from the next crawl." });
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
sites
|
|
126
|
+
.command("identity <site_id>")
|
|
127
|
+
.description("Read a site's Identity Card (offer, audience, money pages, competitors, official anchors)")
|
|
128
|
+
.action(async (siteId, _options, command) => {
|
|
129
|
+
await run(command, async (session) => {
|
|
130
|
+
const data = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}/identity`)).body);
|
|
131
|
+
session.printer.data(data);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
sites
|
|
135
|
+
.command("schema-plan <site_id>")
|
|
136
|
+
.description("Structured data plan per template: role, types to carry, each field's state and where the page shows it")
|
|
137
|
+
.option("--crawl-id <id>", "A past crawl (default: the latest)")
|
|
138
|
+
.action(async (siteId, options, command) => {
|
|
139
|
+
await run(command, async (session) => {
|
|
140
|
+
const data = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}/schema-plan`, { query: { crawl_id: options.crawlId } })).body);
|
|
141
|
+
session.printer.data(data);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
sites
|
|
145
|
+
.command("identity-update <site_id>")
|
|
146
|
+
.description("Update a site's Identity Card and optional GA4 property")
|
|
147
|
+
.option("--summary <text>", "Short business summary")
|
|
148
|
+
.option("--audience <text>", "Target buyer or reader persona")
|
|
149
|
+
.option("--offer <text>", "Core commercial offer")
|
|
150
|
+
.option("--language <code>", "Primary ISO-639-1 language code")
|
|
151
|
+
.option("--site-profile <profile>", "Vertical profile: general | saas | ecommerce | jobs | local | media")
|
|
152
|
+
.option("--strategic-pages <json>", 'Strategic pages JSON array, e.g. \'[{"path":"/pricing","role":"money","goal":"Trials"}]\'')
|
|
153
|
+
.option("--money-pages <paths>", "Pinned money page paths, comma separated")
|
|
154
|
+
.option("--excluded-money-pages <paths>", "Excluded money page paths, comma separated")
|
|
155
|
+
.option("--competitors <hosts>", "Competitor hostnames, comma separated")
|
|
156
|
+
.option("--ga4-property <id>", "Optional GA4 property id")
|
|
157
|
+
.action(async (siteId, options, command) => {
|
|
158
|
+
await run(command, async (session) => {
|
|
159
|
+
let strategicPages;
|
|
160
|
+
if (options.strategicPages !== undefined) {
|
|
161
|
+
try {
|
|
162
|
+
strategicPages = JSON.parse(options.strategicPages);
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
throw usageError("--strategic-pages must be valid JSON.", "strategic-pages");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const body = {
|
|
169
|
+
...(options.summary !== undefined ? { summary: options.summary } : {}),
|
|
170
|
+
...(options.audience !== undefined ? { audience: options.audience } : {}),
|
|
171
|
+
...(options.offer !== undefined ? { offer: options.offer } : {}),
|
|
172
|
+
...(options.language !== undefined ? { language: options.language } : {}),
|
|
173
|
+
...(options.siteProfile !== undefined ? { site_profile: options.siteProfile } : {}),
|
|
174
|
+
...(strategicPages !== undefined ? { strategic_pages: strategicPages } : {}),
|
|
175
|
+
...(options.moneyPages !== undefined ? { money_pages: csv(options.moneyPages) } : {}),
|
|
176
|
+
...(options.excludedMoneyPages !== undefined ? { excluded_money_pages: csv(options.excludedMoneyPages) } : {}),
|
|
177
|
+
...(options.competitors !== undefined ? { competitors: csv(options.competitors) } : {}),
|
|
178
|
+
...(options.ga4Property !== undefined ? { ga4_property: options.ga4Property || null } : {}),
|
|
179
|
+
};
|
|
180
|
+
const data = unwrap((await session.client.request("PATCH", `/sites/${encodeURIComponent(siteId)}/identity`, { body })).body);
|
|
181
|
+
session.printer.data(data, { summary: "Site identity updated." });
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
// ── brief ────────────────────────────────────────────────────────────────
|
|
185
|
+
program
|
|
186
|
+
.command("brief <site_id>")
|
|
187
|
+
.description("The fixes worth doing first on a site, written for a coding agent (start here)")
|
|
188
|
+
.option("--limit <n>", "How many actions (1-20, default 5)")
|
|
189
|
+
.action(async (siteId, options, command) => {
|
|
190
|
+
await run(command, async (session) => {
|
|
191
|
+
const data = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}/brief`, { query: { limit: options.limit } })).body);
|
|
192
|
+
if (session.printer.resolution.mode === "table")
|
|
193
|
+
process.stdout.write(`${data.markdown}\n`);
|
|
194
|
+
else
|
|
195
|
+
session.printer.data(data);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
// ── issues ───────────────────────────────────────────────────────────────
|
|
199
|
+
const issues = program.command("issues").description("A crawl's findings, by control");
|
|
200
|
+
issues
|
|
201
|
+
.command("list <site_id>")
|
|
202
|
+
.description("The controls that found something, highest priority first")
|
|
203
|
+
.option("--crawl-id <id>", "A past crawl (default: the latest)")
|
|
204
|
+
.option("--category <name>", "Only this category, e.g. 'Response codes'")
|
|
205
|
+
.option("--priority <priority>", list(ISSUE_PRIORITY_VALUES))
|
|
206
|
+
.action(async (siteId, options, command) => {
|
|
207
|
+
await run(command, async (session) => {
|
|
208
|
+
const data = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}/issues`, { query: { crawl_id: options.crawlId, category: options.category, priority: options.priority } })).body);
|
|
209
|
+
session.printer.data(data, {
|
|
210
|
+
rows: data.controls,
|
|
211
|
+
columns: [
|
|
212
|
+
{ header: "CODE", value: (row) => row.code },
|
|
213
|
+
{ header: "PRIORITY", value: (row) => row.priority },
|
|
214
|
+
{ header: "URLS", value: (row) => formatNumber(row.urls) },
|
|
215
|
+
{ header: "LABEL", value: (row) => row.label },
|
|
216
|
+
],
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
issues
|
|
221
|
+
.command("urls <site_id> <code>")
|
|
222
|
+
.description("The URLs one control flagged, 50 at a time")
|
|
223
|
+
.option("--crawl-id <id>", "A past crawl (default: the latest)")
|
|
224
|
+
.option("--offset <n>", "Skip this many URLs")
|
|
225
|
+
.action(async (siteId, code, options, command) => {
|
|
226
|
+
await run(command, async (session) => {
|
|
227
|
+
const data = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}/issues/${encodeURIComponent(code)}/urls`, { query: { crawl_id: options.crawlId, offset: options.offset } })).body);
|
|
228
|
+
session.printer.data(data, { rows: data.urls, columns: [{ header: "URL", value: (row) => row.url }], summary: `${formatNumber(data.total)} in all` });
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
// ── pages ────────────────────────────────────────────────────────────────
|
|
232
|
+
const pages = program.command("pages").description("The crawled pages, like the page explorer");
|
|
233
|
+
pages
|
|
234
|
+
.command("query <site_id>")
|
|
235
|
+
.description("Query crawled URLs with conditions, a sort and columns (50 rows at most)")
|
|
236
|
+
.option("--crawl-id <id>", "A past crawl (default: the latest)")
|
|
237
|
+
.option("--join <join>", "and | or: how the conditions combine (default and)")
|
|
238
|
+
.option("--conditions <json>", 'A JSON array of conditions, e.g. \'[{"column":"status","op":"gte","value":400}]\'')
|
|
239
|
+
.option("--search <text>", "Text the URL or title contains")
|
|
240
|
+
.option("--sort <field>", "Field to sort by (default unique_inlinks)")
|
|
241
|
+
.option("--dir <dir>", "asc | desc")
|
|
242
|
+
.option("--columns <fields>", "Fields to return, comma separated (url always first)")
|
|
243
|
+
.option("--limit <n>", "Rows, at most 50 (default 25)")
|
|
244
|
+
.option("--offset <n>", "Skip this many rows")
|
|
245
|
+
.action(async (siteId, options, command) => {
|
|
246
|
+
await run(command, async (session) => {
|
|
247
|
+
let conditions;
|
|
248
|
+
if (options.conditions !== undefined) {
|
|
249
|
+
try {
|
|
250
|
+
conditions = JSON.parse(options.conditions);
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
throw usageError("--conditions takes a JSON array.", "conditions");
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const body = {
|
|
257
|
+
...(options.crawlId ? { crawl_id: options.crawlId } : {}),
|
|
258
|
+
...(options.join ? { join: options.join } : {}),
|
|
259
|
+
...(conditions !== undefined ? { conditions } : {}),
|
|
260
|
+
...(options.search ? { search: options.search } : {}),
|
|
261
|
+
...(options.sort ? { sort: options.sort } : {}),
|
|
262
|
+
...(options.dir ? { dir: options.dir } : {}),
|
|
263
|
+
...(options.columns ? { columns: csv(options.columns) } : {}),
|
|
264
|
+
...(options.limit !== undefined ? { limit: int(options.limit, "--limit") } : {}),
|
|
265
|
+
...(options.offset !== undefined ? { offset: int(options.offset, "--offset") } : {}),
|
|
266
|
+
};
|
|
267
|
+
const data = unwrap((await session.client.request("POST", `/sites/${encodeURIComponent(siteId)}/pages/query`, { body })).body);
|
|
268
|
+
session.printer.data(data, { rows: data.rows, summary: `${formatNumber(data.total)} match` });
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
pages
|
|
272
|
+
.command("get <site_id>")
|
|
273
|
+
.description("One crawled URL in full: status, headings, links, Search Console, findings")
|
|
274
|
+
.requiredOption("--url <url>", "The full URL")
|
|
275
|
+
.option("--crawl-id <id>", "A past crawl (default: the latest)")
|
|
276
|
+
.action(async (siteId, options, command) => {
|
|
277
|
+
await run(command, async (session) => {
|
|
278
|
+
const data = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}/page`, { query: { url: options.url, crawl_id: options.crawlId } })).body);
|
|
279
|
+
session.printer.data(data);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
pages
|
|
283
|
+
.command("search <site_id>")
|
|
284
|
+
.description("Search the crawled pages: exact words (URL, title, H1, text) and the pages nearest in meaning")
|
|
285
|
+
.requiredOption("--q <text>", "Search term or phrase")
|
|
286
|
+
.option("--section <name>", "Optional top-level path section")
|
|
287
|
+
.option("--lang <code>", "Optional language code")
|
|
288
|
+
.option("--indexable-only", "Only search indexable pages")
|
|
289
|
+
.option("--limit <n>", "Max matches (1-50)")
|
|
290
|
+
.action(async (siteId, options, command) => {
|
|
291
|
+
await run(command, async (session) => {
|
|
292
|
+
const data = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}/search`, {
|
|
293
|
+
query: {
|
|
294
|
+
q: options.q,
|
|
295
|
+
section: options.section,
|
|
296
|
+
lang: options.lang,
|
|
297
|
+
indexable_only: options.indexableOnly ? "true" : undefined,
|
|
298
|
+
limit: options.limit,
|
|
299
|
+
},
|
|
300
|
+
})).body);
|
|
301
|
+
session.printer.data(data);
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
pages
|
|
305
|
+
.command("outline <site_id>")
|
|
306
|
+
.description("Compact LLM-friendly outline of one crawled URL")
|
|
307
|
+
.requiredOption("--url <url>", "The full URL")
|
|
308
|
+
.option("--crawl-id <id>", "A past crawl (default: the latest)")
|
|
309
|
+
.action(async (siteId, options, command) => {
|
|
310
|
+
await run(command, async (session) => {
|
|
311
|
+
const data = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}/page/outline`, { query: { url: options.url, crawl_id: options.crawlId } })).body);
|
|
312
|
+
session.printer.data(data);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
pages
|
|
316
|
+
.command("links <site_id>")
|
|
317
|
+
.description("Local internal link neighborhood around one URL (inlinks, outlinks, siblings)")
|
|
318
|
+
.requiredOption("--url <url>", "The full URL")
|
|
319
|
+
.option("--crawl-id <id>", "A past crawl (default: the latest)")
|
|
320
|
+
.action(async (siteId, options, command) => {
|
|
321
|
+
await run(command, async (session) => {
|
|
322
|
+
const data = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}/page/links`, { query: { url: options.url, crawl_id: options.crawlId } })).body);
|
|
323
|
+
session.printer.data(data);
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
// ── actions ──────────────────────────────────────────────────────────────
|
|
327
|
+
const actions = program.command("actions").description("The fixes worth doing, and their status");
|
|
328
|
+
actions
|
|
329
|
+
.command("list <site_id>")
|
|
330
|
+
.description("A site's actions, highest score first (open and planned by default)")
|
|
331
|
+
.option("--status <status>", list(ACTION_STATUS_VALUES))
|
|
332
|
+
.option("--offset <n>", "Skip this many actions")
|
|
333
|
+
.action(async (siteId, options, command) => {
|
|
334
|
+
await run(command, async (session) => {
|
|
335
|
+
const data = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}/actions`, { query: { status: options.status, offset: options.offset } })).body);
|
|
336
|
+
session.printer.data(data, {
|
|
337
|
+
rows: data.actions,
|
|
338
|
+
columns: [
|
|
339
|
+
{ header: "ID", value: (row) => row.id },
|
|
340
|
+
{ header: "STATUS", value: (row) => row.status },
|
|
341
|
+
{ header: "LANE", value: (row) => row.lane },
|
|
342
|
+
{ header: "TITLE", value: (row) => row.title },
|
|
343
|
+
],
|
|
344
|
+
summary: `${formatNumber(data.total)} in all`,
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
actions
|
|
349
|
+
.command("update <site_id>")
|
|
350
|
+
.description("Mark actions planned, done or dismissed (only a crawl marks them verified)")
|
|
351
|
+
.requiredOption("--action-ids <ids>", "Action ids, comma separated")
|
|
352
|
+
.requiredOption("--status <status>", list(SETTABLE_ACTION_STATUS_VALUES))
|
|
353
|
+
.option("--reason <text>", "For dismissed: why, in a sentence")
|
|
354
|
+
.action(async (siteId, options, command) => {
|
|
355
|
+
await run(command, async (session) => {
|
|
356
|
+
const body = { action_ids: csv(options.actionIds), status: options.status, ...(options.reason ? { reason: options.reason } : {}) };
|
|
357
|
+
const data = unwrap((await session.client.request("PATCH", `/sites/${encodeURIComponent(siteId)}/actions`, { body })).body);
|
|
358
|
+
session.printer.data(data, { summary: `${data.updated} updated` });
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
// ── crawls ───────────────────────────────────────────────────────────────
|
|
362
|
+
const crawls = program.command("crawls").description("Start, follow and stop crawls");
|
|
363
|
+
crawls
|
|
364
|
+
.command("quote <site_id>")
|
|
365
|
+
.description("What a crawl started now would read, what is left this month, and whether it can start (free)")
|
|
366
|
+
.action(async (siteId, _options, command) => {
|
|
367
|
+
await run(command, async (session) => {
|
|
368
|
+
const data = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}/crawls/quote`)).body);
|
|
369
|
+
session.printer.data(data, {
|
|
370
|
+
fields: [
|
|
371
|
+
{ label: "URLs at most", value: formatNumber(data.urls_max) },
|
|
372
|
+
{ label: "From this month's pages", value: `${formatNumber(data.pages.from_plan)} of ${formatNumber(data.pages.left)} left` },
|
|
373
|
+
{ label: "Credits at most", value: data.credits.max ? `${formatNumber(data.credits.max)} for ${formatNumber(data.pages.from_credits)} more pages (${data.credits.pages_per_credit} a credit) of ${formatNumber(data.credits.balance)}` : "none" },
|
|
374
|
+
{ label: "Last crawl", value: data.last_crawl?.finished_at ? `${formatDate(data.last_crawl.finished_at)}, ${formatNumber(data.last_crawl.urls ?? 0)} URLs` : "-" },
|
|
375
|
+
{ label: "Next scheduled", value: data.next_scheduled_at ? formatDate(data.next_scheduled_at) : "-" },
|
|
376
|
+
],
|
|
377
|
+
summary: data.message,
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
crawls
|
|
382
|
+
.command("start <site_id>")
|
|
383
|
+
.description("Crawl a site now: from the plan's pages a month, then credits past them (says how much first). Returns at once: follow it with crawls get")
|
|
384
|
+
.option("-y, --yes", "Start without asking")
|
|
385
|
+
.action(async (siteId, options, command) => {
|
|
386
|
+
await run(command, async (session) => {
|
|
387
|
+
const quote = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}/crawls/quote`)).body);
|
|
388
|
+
if (!quote.can_start)
|
|
389
|
+
throw new CliError(quote.message, { exitCode: EXIT.CONFLICT, code: quote.blocked_reason === "running" ? "conflict" : "invalid_request" });
|
|
390
|
+
// Only a crawl that spends credits (pages past the month's) is asked about; the plan's pages are not money.
|
|
391
|
+
if (quote.credits.max > 0)
|
|
392
|
+
await confirmSpend(session, `${quote.message} Start it?`, { yes: options.yes, command: `crawls start ${siteId}`, reviewCommand: `crawls quote ${siteId}`, spends: "credits" });
|
|
393
|
+
const data = unwrap((await session.client.request("POST", `/sites/${encodeURIComponent(siteId)}/crawls`)).body);
|
|
394
|
+
session.printer.data(data, { fields: [{ label: "Crawl", value: data.crawl_id }], summary: `Follow it: crawl82 crawls get ${siteId} ${data.crawl_id}` });
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
crawls
|
|
398
|
+
.command("get <site_id> <crawl_id>")
|
|
399
|
+
.description("A crawl's status and progress")
|
|
400
|
+
.action(async (siteId, crawlId, _options, command) => {
|
|
401
|
+
await run(command, async (session) => {
|
|
402
|
+
const data = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}/crawls/${encodeURIComponent(crawlId)}`)).body);
|
|
403
|
+
session.printer.data(data);
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
crawls
|
|
407
|
+
.command("cancel <site_id> <crawl_id>")
|
|
408
|
+
.description("Stop a crawl at its next batch (URLs already read stay counted)")
|
|
409
|
+
.action(async (siteId, crawlId, _options, command) => {
|
|
410
|
+
await run(command, async (session) => {
|
|
411
|
+
const data = unwrap((await session.client.request("POST", `/sites/${encodeURIComponent(siteId)}/crawls/${encodeURIComponent(crawlId)}/cancel`)).body);
|
|
412
|
+
session.printer.data(data, { summary: data.cancelled ? "Stopping." : "Nothing to stop." });
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
// ── controls ─────────────────────────────────────────────────────────────
|
|
416
|
+
program
|
|
417
|
+
.command("controls")
|
|
418
|
+
.description("The controls Crawl82 runs")
|
|
419
|
+
.command("get <code>")
|
|
420
|
+
.description("Why a control's threshold is what it is, and its sources")
|
|
421
|
+
.action(async (code, _options, command) => {
|
|
422
|
+
await run(command, async (session) => {
|
|
423
|
+
const data = unwrap((await session.client.request("GET", `/controls/${encodeURIComponent(code)}`)).body);
|
|
424
|
+
session.printer.data(data);
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
// ── sql (read-only agentic SQL over CrawlDb) ────────────────────────────
|
|
428
|
+
const sqlCmd = program.command("sql").description("Read-only SQLite schema and SELECT queries on a crawl");
|
|
429
|
+
sqlCmd
|
|
430
|
+
.command("schema <site_id>")
|
|
431
|
+
.description("Describe tables, columns, and row counts of a crawl")
|
|
432
|
+
.option("--crawl-id <id>", "A past crawl (default: the latest)")
|
|
433
|
+
.action(async (siteId, options, command) => {
|
|
434
|
+
await run(command, async (session) => {
|
|
435
|
+
const data = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}/schema`, { query: { crawl_id: options.crawlId } })).body);
|
|
436
|
+
session.printer.data(data);
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
sqlCmd
|
|
440
|
+
.command("query <site_id>")
|
|
441
|
+
.description("Execute a read-only SELECT or WITH query on a crawl or site history (max 200 rows)")
|
|
442
|
+
.requiredOption("--sql <query>", "Read-only SQL SELECT or WITH query")
|
|
443
|
+
.option("--target <target>", "crawl (default) or history (GSC daily history, issue trends, URL inspections, CWV history, change log)")
|
|
444
|
+
.option("--crawl-id <id>", "A past crawl (when target is crawl; default: the latest)")
|
|
445
|
+
.option("--limit <n>", "Max rows (1-200)")
|
|
446
|
+
.action(async (siteId, options, command) => {
|
|
447
|
+
await run(command, async (session) => {
|
|
448
|
+
const body = {
|
|
449
|
+
sql: options.sql,
|
|
450
|
+
...(options.target ? { target: options.target } : {}),
|
|
451
|
+
...(options.crawlId ? { crawl_id: options.crawlId } : {}),
|
|
452
|
+
...(options.limit !== undefined ? { limit: int(options.limit, "--limit") } : {}),
|
|
453
|
+
};
|
|
454
|
+
const data = unwrap((await session.client.request("POST", `/sites/${encodeURIComponent(siteId)}/sql`, { body })).body);
|
|
455
|
+
session.printer.data(data);
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
// ── links (raw internal links & anchor hygiene) ──────────────────────────
|
|
459
|
+
const links = program.command("links").description("Raw internal links and anchor hygiene");
|
|
460
|
+
links
|
|
461
|
+
.command("list <site_id>")
|
|
462
|
+
.description("List internal links with anchor hygiene flags")
|
|
463
|
+
.option("--crawl-id <id>", "A past crawl (default: the latest)")
|
|
464
|
+
.option("--q <text>", "Filter by source, target, or anchor text")
|
|
465
|
+
.option("--position <pos>", "DOM position (content, nav, header, footer)")
|
|
466
|
+
.option("--flag <flag>", "Hygiene flag: empty, generic, long_block, cannibalized, nofollow, broken_or_redirect")
|
|
467
|
+
.option("--conditions <json>", 'Conditions on any link field, a JSON array, e.g. \'[{"column":"generic","op":"is_true"}]\'')
|
|
468
|
+
.option("--join <join>", "and | or: how the conditions combine (default and)")
|
|
469
|
+
.option("--offset <n>", "Rows to skip")
|
|
470
|
+
.option("--limit <n>", "Rows to return (1-200)")
|
|
471
|
+
.action(async (siteId, options, command) => {
|
|
472
|
+
await run(command, async (session) => {
|
|
473
|
+
const data = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}/links`, {
|
|
474
|
+
query: { crawl_id: options.crawlId, q: options.q, position: options.position, flag: options.flag, conditions: options.conditions, join: options.join, offset: options.offset, limit: options.limit },
|
|
475
|
+
})).body);
|
|
476
|
+
session.printer.data(data);
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
// ── modules ──────────────────────────────────────────────────────────────
|
|
480
|
+
const modules = program.command("modules").description("Read SEO/GEO intelligence modules");
|
|
481
|
+
modules
|
|
482
|
+
.command("get <site_id> <module>")
|
|
483
|
+
.description("Read one module: technical, linking, pruning, serp, opportunities, backlinks, ai_readiness")
|
|
484
|
+
.option("--crawl-id <id>", "A past crawl (default: the latest)")
|
|
485
|
+
.action(async (siteId, mod, options, command) => {
|
|
486
|
+
await run(command, async (session) => {
|
|
487
|
+
const data = unwrap((await session.client.request("GET", `/sites/${encodeURIComponent(siteId)}/modules/${encodeURIComponent(mod)}`, { query: { crawl_id: options.crawlId } })).body);
|
|
488
|
+
session.printer.data(data);
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
// ── recipes ──────────────────────────────────────────────────────────────
|
|
492
|
+
const recipes = program.command("recipes").description("List and run SEO/GEO intelligence recipes");
|
|
493
|
+
recipes
|
|
494
|
+
.command("list")
|
|
495
|
+
.description("List all modules and runnable SEO/GEO recipes with their cost; --recipe for one with how to read its result")
|
|
496
|
+
.option("--recipe <id>", "One recipe, with its summary and how to read its result")
|
|
497
|
+
.action(async (options, command) => {
|
|
498
|
+
await run(command, async (session) => {
|
|
499
|
+
const data = unwrap((await session.client.request("GET", "/recipes", options.recipe ? { query: { recipe: options.recipe } } : {})).body);
|
|
500
|
+
session.printer.data(data);
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
recipes
|
|
504
|
+
.command("run <site_id> <recipe>")
|
|
505
|
+
.description("Run an SEO/GEO recipe. A paid one is quoted first and asks before spending (--yes to skip the question, --max-credits for a ceiling)")
|
|
506
|
+
.option("--mode <mode>", "standard | ai")
|
|
507
|
+
.option("--url <url>", "Single target page URL or path")
|
|
508
|
+
.option("--urls <list>", "Comma-separated list of target page URLs or paths")
|
|
509
|
+
.option("--url-pattern <pattern>", "Path regex or glob (e.g. ^/blog/ or /blog/**) for batch targeting")
|
|
510
|
+
.option("--all-urls", "Target all matching crawled pages (up to the recipe's batch ceiling)")
|
|
511
|
+
.option("--preview-url <url>", "Preview URL (check_preview_url)")
|
|
512
|
+
.option("--query <text>", "Target search query or topic")
|
|
513
|
+
.option("--keywords <list>", "Comma-separated keywords")
|
|
514
|
+
.option("--page-type <type>", "vs | alternatives | how_to | tool | landing")
|
|
515
|
+
.option("--draft-title <text>", "Draft title for plan_page_links or build_page_brief")
|
|
516
|
+
.option("--draft-text <text>", "Draft text for plan_page_links")
|
|
517
|
+
.option("--redirects-file <path>", "check_redirect_map: a file with one redirect per line, old URL then new URL")
|
|
518
|
+
.option("--csv-file <path>", "audit_indexation_health: Google Search Console Pages CSV export file")
|
|
519
|
+
.option("--default-reason <text>", "audit_indexation_health: reason label for a single-reason GSC CSV")
|
|
520
|
+
.option("--log-file <path>", "audit_bot_logs: server/CDN log file (NDJSON, Combined, or CSV)")
|
|
521
|
+
.option("--site-profile <profile>", "audit_vertical_seo: general | saas | ecommerce | jobs | local | media")
|
|
522
|
+
.option("--min-clicks <n>", "diagnose_traffic_drop: minimum baseline clicks for affected pages")
|
|
523
|
+
.option("--action-id <id>", "verify_fix_impact: action id to link or filter; notify_search_engines: send the action's pages")
|
|
524
|
+
.option("--change-kind <kind>", "verify_fix_impact: title_meta | content | technical | links | schema | pruning | migration | other")
|
|
525
|
+
.option("--change-summary <text>", "verify_fix_impact: summary of a deployed fix to log")
|
|
526
|
+
.option("--commit-sha <sha>", "verify_fix_impact: optional git commit SHA")
|
|
527
|
+
.option("--lang <code>", "Language code")
|
|
528
|
+
.option("--country <code>", "Country code")
|
|
529
|
+
.option("--limit <n>", "Max pages or items (up to 200)")
|
|
530
|
+
.option("--runs <n>", "check_ai_citations: times each engine is asked each question (1 to 3, default 3)")
|
|
531
|
+
.option("--force-refresh", "Bypass fresh result cache and underlying raw caches")
|
|
532
|
+
.option("--dry-run", "Quote the credits, matched URL count, and revision, spend nothing")
|
|
533
|
+
.option("--expected-revision <rev>", "Revision returned by --dry-run")
|
|
534
|
+
.option("--max-credits <n>", "Refuse the run when it may take more credits than this")
|
|
535
|
+
.option("-y, --yes", "Run a paid recipe without asking (it is still quoted first)")
|
|
536
|
+
.action(async (siteId, recipe, options, command) => {
|
|
537
|
+
await run(command, async (session) => {
|
|
538
|
+
const body = {
|
|
539
|
+
...(options.mode ? { mode: options.mode } : {}),
|
|
540
|
+
...(options.url ? { url: options.url } : {}),
|
|
541
|
+
...(options.urls ? { urls: csv(options.urls) } : {}),
|
|
542
|
+
...(options.urlPattern ? { url_pattern: options.urlPattern } : {}),
|
|
543
|
+
...(options.allUrls ? { all_urls: true } : {}),
|
|
544
|
+
...(options.previewUrl ? { preview_url: options.previewUrl } : {}),
|
|
545
|
+
...(options.query ? { query: options.query } : {}),
|
|
546
|
+
...(options.keywords ? { keywords: csv(options.keywords) } : {}),
|
|
547
|
+
...(options.pageType ? { page_type: options.pageType } : {}),
|
|
548
|
+
...(options.draftTitle ? { draft_title: options.draftTitle } : {}),
|
|
549
|
+
...(options.draftText ? { draft_text: options.draftText } : {}),
|
|
550
|
+
...(options.redirectsFile ? { redirects: readFileSync(options.redirectsFile, "utf8") } : {}),
|
|
551
|
+
...(options.csvFile ? { csv_data: readFileSync(options.csvFile, "utf8") } : {}),
|
|
552
|
+
...(options.defaultReason ? { default_reason: options.defaultReason } : {}),
|
|
553
|
+
...(options.logFile ? { log_data: readFileSync(options.logFile, "utf8") } : {}),
|
|
554
|
+
...(options.siteProfile ? { profile: options.siteProfile } : {}),
|
|
555
|
+
...(options.minClicks !== undefined ? { min_clicks: int(options.minClicks, "--min-clicks") } : {}),
|
|
556
|
+
...(options.actionId ? { action_id: options.actionId } : {}),
|
|
557
|
+
...(options.changeKind ? { change_kind: options.changeKind } : {}),
|
|
558
|
+
...(options.changeSummary ? { change_summary: options.changeSummary } : {}),
|
|
559
|
+
...(options.commitSha ? { commit_sha: options.commitSha } : {}),
|
|
560
|
+
...(options.lang ? { lang: options.lang } : {}),
|
|
561
|
+
...(options.country ? { country: options.country } : {}),
|
|
562
|
+
...(options.limit !== undefined ? { limit: int(options.limit, "--limit") } : {}),
|
|
563
|
+
...(options.runs !== undefined ? { runs: int(options.runs, "--runs") } : {}),
|
|
564
|
+
...(options.forceRefresh ? { force_refresh: true } : {}),
|
|
565
|
+
...(options.maxCredits !== undefined ? { max_credits: int(options.maxCredits, "--max-credits") } : {}),
|
|
566
|
+
};
|
|
567
|
+
const path = `/sites/${encodeURIComponent(siteId)}/recipes/${encodeURIComponent(recipe)}`;
|
|
568
|
+
// Quote first, always: a paid run is confirmed against its price and pinned to that revision.
|
|
569
|
+
const quote = unwrap((await session.client.request("POST", path, { body: { ...body, dry_run: true } })).body);
|
|
570
|
+
if (options.dryRun) {
|
|
571
|
+
session.printer.data(quote, { summary: quote.estimate.free ? "Free." : `About ${quote.estimate.typical} credits, at most ${quote.estimate.max} (balance ${formatNumber(quote.balance)}). Run it with --expected-revision ${quote.revision}.` });
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
const openingCachedFree = Boolean(!quote.estimate.free && quote.cached_available && !options.forceRefresh);
|
|
575
|
+
let revision = options.expectedRevision;
|
|
576
|
+
let maxCredits = options.maxCredits !== undefined ? int(options.maxCredits, "--max-credits") : undefined;
|
|
577
|
+
if (openingCachedFree) {
|
|
578
|
+
// Opening a cached result must never silently charge if it expires before execution.
|
|
579
|
+
revision = options.expectedRevision ?? quote.revision;
|
|
580
|
+
maxCredits = maxCredits ?? 0;
|
|
581
|
+
}
|
|
582
|
+
else if (!quote.estimate.free) {
|
|
583
|
+
if (quote.within_max_credits === false)
|
|
584
|
+
throw usageError(`This run may take up to ${quote.estimate.max} credits, above --max-credits ${options.maxCredits}. Nothing was charged.`, "max_credits");
|
|
585
|
+
if (quote.balance < quote.estimate.max)
|
|
586
|
+
throw new CliError(`This run may take up to ${quote.estimate.max} credits and the workspace has ${formatNumber(quote.balance)}.`, { exitCode: EXIT.USAGE, code: "insufficient_credits", hint: "Buy credits in the app (Billing), or use --mode standard when the recipe has it." });
|
|
587
|
+
// A few credits run without asking (CONFIRM_ABOVE_CREDITS on the server says when to ask).
|
|
588
|
+
if (quote.confirm_required !== false)
|
|
589
|
+
await confirmSpend(session, `${recipe} takes about ${quote.estimate.typical} credits, at most ${quote.estimate.max} (balance ${formatNumber(quote.balance)}). Run it?`, { yes: options.yes, command: typedCommand(command, ["-y", "--yes"]), reviewCommand: `${typedCommand(command, ["-y", "--yes"])} --dry-run` });
|
|
590
|
+
revision = options.expectedRevision ?? quote.revision;
|
|
591
|
+
maxCredits = maxCredits ?? quote.estimate.max;
|
|
592
|
+
}
|
|
593
|
+
const data = unwrap((await session.client.request("POST", path, {
|
|
594
|
+
body: {
|
|
595
|
+
...body,
|
|
596
|
+
...(revision ? { expected_revision: revision } : {}),
|
|
597
|
+
...(maxCredits !== undefined ? { max_credits: maxCredits } : {}),
|
|
598
|
+
},
|
|
599
|
+
})).body);
|
|
600
|
+
session.printer.data(data, { summary: typeof data.credits === "number" ? `${data.cached ? "From cache, " : ""}${data.credits} credits spent, ${formatNumber(Number(data.credits_remaining ?? 0))} left.` : undefined });
|
|
601
|
+
});
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
//# sourceMappingURL=sites.js.map
|