seenkite 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +65 -2
- package/dist/cli.js +599 -0
- package/package.json +24 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 the Seenkite authors
|
|
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,66 @@
|
|
|
1
|
-
#
|
|
1
|
+
# seenkite
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The command line for [Seenkite](https://seenkite.com), the SEO and AI visibility audit and
|
|
4
|
+
reporting platform. See your sites and fixes, check a fix on the live site, and fail a CI build
|
|
5
|
+
when critical problems come back.
|
|
6
|
+
|
|
7
|
+
It's a thin client for the Seenkite API: audits, scoring and AI checks run on Seenkite's servers.
|
|
8
|
+
You need a Seenkite account (every plan includes the API) and Node.js 20 or newer.
|
|
9
|
+
|
|
10
|
+
## Start
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npx seenkite login # paste an API key from Settings → API keys
|
|
14
|
+
npx seenkite sites
|
|
15
|
+
npx seenkite fixes example.com
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Or install it: `npm install -g seenkite`, then run `seenkite …`.
|
|
19
|
+
|
|
20
|
+
## Commands
|
|
21
|
+
|
|
22
|
+
| Command | What it does |
|
|
23
|
+
|---|---|
|
|
24
|
+
| `login [--key <key>]` | Saves an API key (checked with the server first) |
|
|
25
|
+
| `logout` | Forgets the saved key |
|
|
26
|
+
| `doctor` | Checks the key, the server and which sites you can see |
|
|
27
|
+
| `sites` | Lists your sites |
|
|
28
|
+
| `fixes <site> [--status open\|all\|…]` | Open fixes for a site, most important first |
|
|
29
|
+
| `fix <fix>` | One fix in full: the page, what's there now, what to change and why |
|
|
30
|
+
| `verify <fix>` | Checks the fix on the live site; exits 1 if it isn't fixed yet |
|
|
31
|
+
| `applied <fix> [--commit sha] [--note text]` | Marks a fix as applied |
|
|
32
|
+
| `audit <site> [--wait] [--fail-on critical\|warning\|info]` | Starts an audit; `--fail-on` waits and exits 1 if fixes at that level or worse are open |
|
|
33
|
+
| `report <site>` | The latest report in Markdown |
|
|
34
|
+
| `connect <claude-code\|cursor\|vscode>` | How to add Seenkite to your coding agent (MCP) |
|
|
35
|
+
|
|
36
|
+
`<site>` is the domain (`example.com`), the address, the site name or its id. `<fix>` is the fix
|
|
37
|
+
id shown by `fixes` (like `TTL-3fa9c21b`) or its uuid.
|
|
38
|
+
|
|
39
|
+
Every command takes `--json` for scripts. Exit codes: `0` done, `1` failed (or fixes found with
|
|
40
|
+
`--fail-on`), `2` wrong usage.
|
|
41
|
+
|
|
42
|
+
## In CI
|
|
43
|
+
|
|
44
|
+
```yaml
|
|
45
|
+
- run: npx seenkite@0 audit example.com --fail-on critical
|
|
46
|
+
env:
|
|
47
|
+
SEENKITE_API_KEY: ${{ secrets.SEENKITE_API_KEY }}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Use a read-and-write key limited to that site (Settings → API keys). Audits count toward your
|
|
51
|
+
plan's audits started by hand.
|
|
52
|
+
|
|
53
|
+
## Where the key is kept
|
|
54
|
+
|
|
55
|
+
`login` saves the key in `~/.config/seenkite/config.json`, readable only by you. `SEENKITE_API_KEY`
|
|
56
|
+
or `--key` override it. Remove it with `logout` or by revoking the key in Settings → API keys.
|
|
57
|
+
|
|
58
|
+
Text from websites (page titles, quotes) is shown with terminal control codes removed.
|
|
59
|
+
|
|
60
|
+
## Help
|
|
61
|
+
|
|
62
|
+
`seenkite --help`, the [API docs](https://seenkite.com/docs/api), or support@seenkite.com.
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
MIT. This package is only the command-line client; the Seenkite service itself is not open source.
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { createInterface } from "node:readline";
|
|
5
|
+
import { Writable } from "node:stream";
|
|
6
|
+
|
|
7
|
+
// ../../packages/config/src/brand.ts
|
|
8
|
+
var processEnv = typeof process !== "undefined" && process.env ? process.env : {};
|
|
9
|
+
function createBrand(env = processEnv) {
|
|
10
|
+
const slug = env.BRAND_SLUG ?? "seenkite";
|
|
11
|
+
const appUrl = (env.APP_URL ?? "http://localhost:5173").replace(/\/+$/, "");
|
|
12
|
+
const botName = env.BRAND_BOT_NAME ?? "seenkitebot";
|
|
13
|
+
const apiKeyPrefix = env.BRAND_API_KEY_PREFIX ?? "skt";
|
|
14
|
+
return {
|
|
15
|
+
/** Display name, e.g. in page titles and emails. */
|
|
16
|
+
name: env.BRAND_NAME ?? "Seenkite",
|
|
17
|
+
/** Lowercase id: cookies, storage keys, file names. */
|
|
18
|
+
slug,
|
|
19
|
+
domain: env.BRAND_DOMAIN ?? "seenkite.com",
|
|
20
|
+
appUrl,
|
|
21
|
+
supportEmail: env.BRAND_SUPPORT_EMAIL ?? "support@seenkite.com",
|
|
22
|
+
emailFrom: env.EMAIL_FROM ?? "Seenkite <no-reply@seenkite.com>",
|
|
23
|
+
/** API keys look like `${apiKeyPrefix}_live_…`. */
|
|
24
|
+
apiKeyPrefix,
|
|
25
|
+
botName,
|
|
26
|
+
/** CLI binary name, used in agent instructions in reports. */
|
|
27
|
+
cliName: env.BRAND_CLI_NAME ?? "seenkite",
|
|
28
|
+
/** Temporary: shows a small "Beta" next to the logo and a beta note in the terms. Off with BRAND_BETA=0. */
|
|
29
|
+
beta: env.BRAND_BETA !== "0",
|
|
30
|
+
colors: { accent: env.BRAND_ACCENT ?? "#111113" },
|
|
31
|
+
/** The company behind the product (legal operator). Empty env values fall back to the default. */
|
|
32
|
+
legal: {
|
|
33
|
+
/**
|
|
34
|
+
* Temporary (owner, 2026-11-10): the company name is hidden until the payment provider (Polar) approves the
|
|
35
|
+
* store; pages and emails then name only the product. BRAND_SHOW_COMPANY=1 shows it again.
|
|
36
|
+
*/
|
|
37
|
+
showCompany: env.BRAND_SHOW_COMPANY === "1",
|
|
38
|
+
companyName: env.BRAND_COMPANY || "Felicity Systems",
|
|
39
|
+
address: env.BRAND_ADDRESS ?? "",
|
|
40
|
+
url: env.BRAND_COMPANY_URL || "https://felicitysystems.com"
|
|
41
|
+
},
|
|
42
|
+
/** Public paths of brand assets (files live in apps/web/static/brand/). */
|
|
43
|
+
assets: {
|
|
44
|
+
logo: "/brand/logo.svg",
|
|
45
|
+
wordmark: "/brand/wordmark.svg",
|
|
46
|
+
/** Light-text wordmark for dark backgrounds. */
|
|
47
|
+
wordmarkDark: "/brand/wordmark-dark.svg",
|
|
48
|
+
favicon: "/brand/favicon.svg",
|
|
49
|
+
ogImage: "/brand/og.png",
|
|
50
|
+
emailLogo: "/brand/email-logo.png"
|
|
51
|
+
},
|
|
52
|
+
/** Crawler user-agent: `${botName}/1.0 (+${appUrl}/bot)`. */
|
|
53
|
+
botUserAgent: `${botName}/1.0 (+${appUrl}/bot)`,
|
|
54
|
+
/** Prefix for live API keys, e.g. `skt_live_`. */
|
|
55
|
+
liveKeyPrefix: `${apiKeyPrefix}_live_`,
|
|
56
|
+
/** Env var name customers put their API key in, e.g. `SEENKITE_API_KEY`. */
|
|
57
|
+
apiKeyEnvVar: `${slug.toUpperCase().replace(/[^A-Z0-9]/g, "_")}_API_KEY`,
|
|
58
|
+
cookieName: (name) => `${slug}_${name}`,
|
|
59
|
+
storageKey: (name) => `${slug}:${name}`
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
var brand = createBrand();
|
|
63
|
+
|
|
64
|
+
// src/main.ts
|
|
65
|
+
import { parseArgs } from "node:util";
|
|
66
|
+
|
|
67
|
+
// src/api.ts
|
|
68
|
+
var CliError = class extends Error {
|
|
69
|
+
constructor(message, exitCode = 1, code2) {
|
|
70
|
+
super(message);
|
|
71
|
+
this.exitCode = exitCode;
|
|
72
|
+
this.code = code2;
|
|
73
|
+
}
|
|
74
|
+
exitCode;
|
|
75
|
+
code;
|
|
76
|
+
};
|
|
77
|
+
var Api = class {
|
|
78
|
+
constructor(baseUrl, key, fetchImpl = fetch, userAgent = "cli") {
|
|
79
|
+
this.baseUrl = baseUrl;
|
|
80
|
+
this.key = key;
|
|
81
|
+
this.fetchImpl = fetchImpl;
|
|
82
|
+
this.userAgent = userAgent;
|
|
83
|
+
}
|
|
84
|
+
baseUrl;
|
|
85
|
+
key;
|
|
86
|
+
fetchImpl;
|
|
87
|
+
userAgent;
|
|
88
|
+
async request(method, path, body) {
|
|
89
|
+
let res;
|
|
90
|
+
try {
|
|
91
|
+
res = await this.fetchImpl(`${this.baseUrl}/api/v1${path}`, {
|
|
92
|
+
method,
|
|
93
|
+
headers: {
|
|
94
|
+
authorization: `Bearer ${this.key}`,
|
|
95
|
+
accept: "application/json, text/markdown",
|
|
96
|
+
"user-agent": this.userAgent,
|
|
97
|
+
...body !== void 0 ? { "content-type": "application/json" } : {}
|
|
98
|
+
},
|
|
99
|
+
...body !== void 0 ? { body: JSON.stringify(body) } : {},
|
|
100
|
+
signal: AbortSignal.timeout(6e4)
|
|
101
|
+
});
|
|
102
|
+
} catch (err) {
|
|
103
|
+
throw new CliError(
|
|
104
|
+
`Couldn't reach ${this.baseUrl} (${err instanceof Error ? err.message : String(err)}). Check your connection.`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
if (res.ok) return res;
|
|
108
|
+
let code2 = `http_${res.status}`;
|
|
109
|
+
let message = `The server answered ${res.status}.`;
|
|
110
|
+
try {
|
|
111
|
+
const j = await res.json();
|
|
112
|
+
if (j.error?.code) code2 = j.error.code;
|
|
113
|
+
if (j.error?.message) message = j.error.message;
|
|
114
|
+
} catch {
|
|
115
|
+
}
|
|
116
|
+
if (res.status === 401)
|
|
117
|
+
message = `${message} Your API key was refused: run "login" again with a key from Settings \u2192 API keys.`;
|
|
118
|
+
throw new CliError(message, 1, code2);
|
|
119
|
+
}
|
|
120
|
+
async data(method, path, body) {
|
|
121
|
+
return (await (await this.request(method, path, body)).json()).data;
|
|
122
|
+
}
|
|
123
|
+
sites() {
|
|
124
|
+
return this.data("GET", "/sites");
|
|
125
|
+
}
|
|
126
|
+
fixes(siteId, status = "open") {
|
|
127
|
+
return this.data(
|
|
128
|
+
"GET",
|
|
129
|
+
`/sites/${encodeURIComponent(siteId)}/fixes?status=${encodeURIComponent(status)}`
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
fix(fixId) {
|
|
133
|
+
return this.data("GET", `/fixes/${encodeURIComponent(fixId)}`);
|
|
134
|
+
}
|
|
135
|
+
async verify(fixId) {
|
|
136
|
+
const res = await this.request("POST", `/fixes/${encodeURIComponent(fixId)}/verify`);
|
|
137
|
+
return await res.json();
|
|
138
|
+
}
|
|
139
|
+
async applied(fixId, body) {
|
|
140
|
+
const res = await this.request("POST", `/fixes/${encodeURIComponent(fixId)}/applied`, body);
|
|
141
|
+
return await res.json();
|
|
142
|
+
}
|
|
143
|
+
async startAudit(siteId) {
|
|
144
|
+
const res = await this.request("POST", `/sites/${encodeURIComponent(siteId)}/runs`);
|
|
145
|
+
return await res.json();
|
|
146
|
+
}
|
|
147
|
+
run(runId) {
|
|
148
|
+
return this.data("GET", `/runs/${encodeURIComponent(runId)}`);
|
|
149
|
+
}
|
|
150
|
+
async latestReport(siteId) {
|
|
151
|
+
const res = await this.request("GET", `/sites/${encodeURIComponent(siteId)}/reports/latest.md`);
|
|
152
|
+
return res.text();
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
156
|
+
var isUuid = (s) => UUID.test(s);
|
|
157
|
+
function hostOf(s) {
|
|
158
|
+
const raw = s.trim().toLowerCase();
|
|
159
|
+
try {
|
|
160
|
+
return new URL(raw.includes("://") ? raw : `https://${raw}`).hostname.replace(/^www\./, "");
|
|
161
|
+
} catch {
|
|
162
|
+
return raw;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function pickSite(sites, ref) {
|
|
166
|
+
if (isUuid(ref)) {
|
|
167
|
+
const s = sites.find((x) => x.id === ref.toLowerCase());
|
|
168
|
+
if (s) return s;
|
|
169
|
+
}
|
|
170
|
+
const host = hostOf(ref);
|
|
171
|
+
const byHost = sites.filter((x) => hostOf(x.url) === host);
|
|
172
|
+
if (byHost.length === 1) return byHost[0];
|
|
173
|
+
const byName = sites.filter((x) => x.name.toLowerCase() === ref.trim().toLowerCase());
|
|
174
|
+
if (byName.length === 1) return byName[0];
|
|
175
|
+
const matches = byHost.length ? byHost : byName;
|
|
176
|
+
if (matches.length > 1)
|
|
177
|
+
throw new CliError(
|
|
178
|
+
`"${ref}" matches ${matches.length} sites. Use the site id instead: ${matches.map((m) => m.id).join(", ")}`,
|
|
179
|
+
2
|
|
180
|
+
);
|
|
181
|
+
throw new CliError(
|
|
182
|
+
sites.length ? `No site "${ref}". Your sites: ${sites.map((s) => hostOf(s.url)).join(", ")}` : "This organisation has no sites yet. Add one in the web app first.",
|
|
183
|
+
2
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
var SEVERITY_RANK = { info: 0, warning: 1, critical: 2 };
|
|
187
|
+
|
|
188
|
+
// src/config.ts
|
|
189
|
+
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
190
|
+
import { homedir } from "node:os";
|
|
191
|
+
import { join } from "node:path";
|
|
192
|
+
function configPath(slug, env = process.env) {
|
|
193
|
+
const base = env.XDG_CONFIG_HOME || (process.platform === "win32" && env.APPDATA ? env.APPDATA : join(homedir(), ".config"));
|
|
194
|
+
return join(base, slug, "config.json");
|
|
195
|
+
}
|
|
196
|
+
function readSaved(path) {
|
|
197
|
+
try {
|
|
198
|
+
const j = JSON.parse(readFileSync(path, "utf8"));
|
|
199
|
+
return typeof j === "object" && j ? j : {};
|
|
200
|
+
} catch {
|
|
201
|
+
return {};
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function writeSaved(path, saved) {
|
|
205
|
+
mkdirSync(join(path, ".."), { recursive: true, mode: 448 });
|
|
206
|
+
writeFileSync(path, JSON.stringify(saved, null, 2) + "\n", { mode: 384 });
|
|
207
|
+
}
|
|
208
|
+
function forget(path) {
|
|
209
|
+
rmSync(path, { force: true });
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/text.ts
|
|
213
|
+
function clean(s, max = 2e3) {
|
|
214
|
+
const str = String(s ?? "").replace(/\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][^\u0007\u001b]*(\u0007|\u001b\\)?|\u001b./g, "").replace(/[\p{Cc}\p{Cf}]/gu, (c) => c === "\n" || c === " " ? c : "");
|
|
215
|
+
return str.length > max ? `${str.slice(0, max - 1)}\u2026` : str;
|
|
216
|
+
}
|
|
217
|
+
var line = (s, max = 200) => clean(s, max).replace(/\s+/g, " ").trim();
|
|
218
|
+
function shortDate(iso) {
|
|
219
|
+
if (!iso) return "never";
|
|
220
|
+
const d = new Date(iso);
|
|
221
|
+
return Number.isNaN(d.getTime()) ? iso : d.toISOString().slice(0, 16).replace("T", " ") + " UTC";
|
|
222
|
+
}
|
|
223
|
+
function table(rows) {
|
|
224
|
+
if (!rows.length) return "";
|
|
225
|
+
const widths = rows[0].map((_, i) => Math.max(...rows.map((r) => (r[i] ?? "").length)));
|
|
226
|
+
return rows.map(
|
|
227
|
+
(r) => r.map((c, i) => i === r.length - 1 ? c : c.padEnd(widths[i])).join(" ").trimEnd()
|
|
228
|
+
).join("\n");
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// src/main.ts
|
|
232
|
+
var brand2 = createBrand({});
|
|
233
|
+
var ENV_KEY = brand2.apiKeyEnvVar;
|
|
234
|
+
var ENV_URL = ENV_KEY.replace(/_API_KEY$/, "_API_URL");
|
|
235
|
+
var DEFAULT_URL = `https://${brand2.domain}`;
|
|
236
|
+
var CLI = brand2.cliName;
|
|
237
|
+
var HELP = `${CLI}: your ${brand2.name} sites, fixes and audits from the terminal or CI.
|
|
238
|
+
|
|
239
|
+
Usage: ${CLI} <command> [options]
|
|
240
|
+
|
|
241
|
+
Commands
|
|
242
|
+
login [--key <key>] Save an API key (Settings \u2192 API keys in ${brand2.name})
|
|
243
|
+
logout Forget the saved key
|
|
244
|
+
doctor Check the key, the server and which sites you can see
|
|
245
|
+
sites List your sites
|
|
246
|
+
fixes <site> [--status s] Open fixes for a site (s: open, all, applied, verified, \u2026)
|
|
247
|
+
fix <fix> One fix in full
|
|
248
|
+
verify <fix> Check a fix on the live site (exit 1 if it isn't fixed yet)
|
|
249
|
+
applied <fix> [--commit sha] [--note text]
|
|
250
|
+
Mark a fix as applied; the next check confirms it
|
|
251
|
+
audit <site> [--wait] [--fail-on critical|warning|info] [--timeout 30]
|
|
252
|
+
Start an audit; --fail-on waits and exits 1 if fixes at that
|
|
253
|
+
level or worse are open (for CI)
|
|
254
|
+
report <site> The latest report in Markdown
|
|
255
|
+
connect <claude-code|cursor|vscode>
|
|
256
|
+
How to add ${brand2.name} to your coding agent (MCP)
|
|
257
|
+
|
|
258
|
+
<site> is the domain (example.com), the address, the name or the id.
|
|
259
|
+
<fix> is the fix id from "fixes" (e.g. TTL-3fa9c21b) or its uuid.
|
|
260
|
+
|
|
261
|
+
Options
|
|
262
|
+
--json Machine-readable output
|
|
263
|
+
--api <url> Server (default ${DEFAULT_URL}; or ${ENV_URL})
|
|
264
|
+
--key <key> API key for this command (or ${ENV_KEY})
|
|
265
|
+
-h, --help This help
|
|
266
|
+
-v, --version Version
|
|
267
|
+
|
|
268
|
+
Exit codes: 0 done, 1 failed (or fixes found with --fail-on), 2 wrong usage.`;
|
|
269
|
+
var OPTIONS = {
|
|
270
|
+
json: { type: "boolean" },
|
|
271
|
+
api: { type: "string" },
|
|
272
|
+
key: { type: "string" },
|
|
273
|
+
status: { type: "string" },
|
|
274
|
+
commit: { type: "string" },
|
|
275
|
+
note: { type: "string" },
|
|
276
|
+
wait: { type: "boolean" },
|
|
277
|
+
"fail-on": { type: "string" },
|
|
278
|
+
timeout: { type: "string" },
|
|
279
|
+
help: { type: "boolean", short: "h" },
|
|
280
|
+
version: { type: "boolean", short: "v" }
|
|
281
|
+
};
|
|
282
|
+
async function run(argv, io) {
|
|
283
|
+
try {
|
|
284
|
+
return await main(argv, io);
|
|
285
|
+
} catch (err) {
|
|
286
|
+
if (err instanceof CliError) {
|
|
287
|
+
io.err(`Error: ${clean(err.message, 1e3)}`);
|
|
288
|
+
return err.exitCode;
|
|
289
|
+
}
|
|
290
|
+
io.err(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
291
|
+
return 1;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
async function main(argv, io) {
|
|
295
|
+
let parsed;
|
|
296
|
+
try {
|
|
297
|
+
parsed = parseArgs({ args: argv, options: OPTIONS, allowPositionals: true, strict: true });
|
|
298
|
+
} catch (err) {
|
|
299
|
+
throw new CliError(`${err.message}
|
|
300
|
+
Run "${CLI} --help".`, 2);
|
|
301
|
+
}
|
|
302
|
+
const { values: o, positionals } = parsed;
|
|
303
|
+
const [cmd, ...args] = positionals;
|
|
304
|
+
if (o.version) {
|
|
305
|
+
io.out(io.version);
|
|
306
|
+
return 0;
|
|
307
|
+
}
|
|
308
|
+
if (o.help || !cmd || cmd === "help") {
|
|
309
|
+
io.out(HELP);
|
|
310
|
+
return 0;
|
|
311
|
+
}
|
|
312
|
+
const json = !!o.json;
|
|
313
|
+
const print = (human, data) => io.out(json ? JSON.stringify(data, null, 2) : human);
|
|
314
|
+
const saved = readSaved(io.configFile);
|
|
315
|
+
const apiUrl = (o.api ?? io.env[ENV_URL] ?? saved.apiUrl ?? DEFAULT_URL).replace(/\/+$/, "");
|
|
316
|
+
if (!/^https:\/\/|^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?(\/|$)/.test(apiUrl))
|
|
317
|
+
throw new CliError(`--api must be an https:// address (or http://localhost for testing).`, 2);
|
|
318
|
+
const need = (n, usage) => {
|
|
319
|
+
if (args.length < n) throw new CliError(`Usage: ${CLI} ${usage}`, 2);
|
|
320
|
+
};
|
|
321
|
+
const keySource = o.key ? "option" : io.env[ENV_KEY] ? ENV_KEY : saved.apiKey ? "saved" : null;
|
|
322
|
+
const key = o.key ?? io.env[ENV_KEY] ?? saved.apiKey;
|
|
323
|
+
const api = () => {
|
|
324
|
+
if (!key)
|
|
325
|
+
throw new CliError(
|
|
326
|
+
`Not logged in. Run "${CLI} login" with a key from Settings \u2192 API keys, or set ${ENV_KEY}.`,
|
|
327
|
+
2
|
|
328
|
+
);
|
|
329
|
+
return new Api(apiUrl, key, io.fetch, `${CLI}-cli/${io.version}`);
|
|
330
|
+
};
|
|
331
|
+
const site = async (ref) => pickSite(await api().sites(), ref);
|
|
332
|
+
const fixRef = async (ref) => {
|
|
333
|
+
const a = api();
|
|
334
|
+
if (isUuid(ref)) return a.fix(ref);
|
|
335
|
+
for (const s of await a.sites()) {
|
|
336
|
+
const f = (await a.fixes(s.id, "all")).find((x) => x.id.toLowerCase() === ref.toLowerCase());
|
|
337
|
+
if (f) return f;
|
|
338
|
+
}
|
|
339
|
+
throw new CliError(`No fix "${ref}". Use an id or uuid from "${CLI} fixes <site>".`, 2);
|
|
340
|
+
};
|
|
341
|
+
switch (cmd) {
|
|
342
|
+
case "login": {
|
|
343
|
+
const k = (o.key ?? await io.askSecret(`API key (Settings \u2192 API keys): `)).trim();
|
|
344
|
+
if (!k) throw new CliError("No key given.", 2);
|
|
345
|
+
const sites = await new Api(apiUrl, k, io.fetch, `${CLI}-cli/${io.version}`).sites();
|
|
346
|
+
writeSaved(io.configFile, { apiKey: k, ...apiUrl !== DEFAULT_URL ? { apiUrl } : {} });
|
|
347
|
+
print(
|
|
348
|
+
`Logged in to ${apiUrl}. This key sees ${sites.length} site${sites.length === 1 ? "" : "s"}. Saved in ${io.configFile}.`,
|
|
349
|
+
{ ok: true, api: apiUrl, sites: sites.length, saved_to: io.configFile }
|
|
350
|
+
);
|
|
351
|
+
return 0;
|
|
352
|
+
}
|
|
353
|
+
case "logout": {
|
|
354
|
+
forget(io.configFile);
|
|
355
|
+
print("Logged out: the saved key is removed.", { ok: true });
|
|
356
|
+
return 0;
|
|
357
|
+
}
|
|
358
|
+
case "doctor": {
|
|
359
|
+
const sites = await api().sites();
|
|
360
|
+
print(
|
|
361
|
+
[
|
|
362
|
+
`Server ${apiUrl} ok`,
|
|
363
|
+
`Key ${keySource === "saved" ? `saved (${io.configFile})` : keySource}, ends in ${key.slice(-4)} ok`,
|
|
364
|
+
`Sites ${sites.length ? sites.map((s) => hostOf(s.url)).join(", ") : "none yet"}`,
|
|
365
|
+
`Version ${io.version}`
|
|
366
|
+
].join("\n"),
|
|
367
|
+
{ ok: true, api: apiUrl, key_source: keySource, sites: sites.map((s) => s.url) }
|
|
368
|
+
);
|
|
369
|
+
return 0;
|
|
370
|
+
}
|
|
371
|
+
case "sites": {
|
|
372
|
+
const sites = await api().sites();
|
|
373
|
+
print(
|
|
374
|
+
sites.length ? table([
|
|
375
|
+
["SITE", "LAST AUDIT", "ID"],
|
|
376
|
+
...sites.map((s) => [line(hostOf(s.url)), shortDate(s.last_run_at), s.id])
|
|
377
|
+
]) : "No sites yet. Add one in the web app.",
|
|
378
|
+
sites
|
|
379
|
+
);
|
|
380
|
+
return 0;
|
|
381
|
+
}
|
|
382
|
+
case "fixes": {
|
|
383
|
+
need(1, "fixes <site> [--status open|all|\u2026]");
|
|
384
|
+
const s = await site(args[0]);
|
|
385
|
+
const fixes = await api().fixes(s.id, o.status ?? "open");
|
|
386
|
+
print(
|
|
387
|
+
fixes.length ? table([
|
|
388
|
+
["SEVERITY", "ID", "FIX", "PAGE"],
|
|
389
|
+
...fixes.map((f) => [
|
|
390
|
+
f.severity,
|
|
391
|
+
f.id,
|
|
392
|
+
line(f.title, 80),
|
|
393
|
+
f.url ? line(pathOf(f.url), 60) : ""
|
|
394
|
+
])
|
|
395
|
+
]) : `No ${o.status && o.status !== "open" ? o.status : "open"} fixes for ${hostOf(s.url)}.`,
|
|
396
|
+
fixes
|
|
397
|
+
);
|
|
398
|
+
return 0;
|
|
399
|
+
}
|
|
400
|
+
case "fix": {
|
|
401
|
+
need(1, "fix <fix>");
|
|
402
|
+
const f = await fixRef(args[0]);
|
|
403
|
+
print(
|
|
404
|
+
[
|
|
405
|
+
`${line(f.title, 300)}`,
|
|
406
|
+
`${f.severity} \xB7 ${f.status} \xB7 ${f.category} \xB7 effort ${f.effort} \xB7 ${f.id} (${f.uuid})`,
|
|
407
|
+
f.url ? `Page: ${line(f.url, 500)}` : null,
|
|
408
|
+
f.current ? `
|
|
409
|
+
Now:
|
|
410
|
+
${clean(f.current)}` : null,
|
|
411
|
+
f.proposed ? `
|
|
412
|
+
Change to:
|
|
413
|
+
${clean(f.proposed)}` : null,
|
|
414
|
+
`
|
|
415
|
+
Why: ${clean(f.why)}`,
|
|
416
|
+
f.needs_human ? "\nNeeds a person to confirm before it goes live." : null,
|
|
417
|
+
f.last_verify_result ? `
|
|
418
|
+
Last check (${shortDate(f.last_verified_at)}): ${f.last_verify_result.pass ? "fixed" : "not fixed yet"}. ${line(f.last_verify_result.detail, 300)}` : null,
|
|
419
|
+
`
|
|
420
|
+
When it's live: ${CLI} verify ${f.id}`
|
|
421
|
+
].filter((x) => x !== null).join("\n"),
|
|
422
|
+
f
|
|
423
|
+
);
|
|
424
|
+
return 0;
|
|
425
|
+
}
|
|
426
|
+
case "verify": {
|
|
427
|
+
need(1, "verify <fix>");
|
|
428
|
+
const f = await fixRef(args[0]);
|
|
429
|
+
const r = await api().verify(f.uuid);
|
|
430
|
+
print(
|
|
431
|
+
`${r.pass ? "Fixed" : "Not fixed yet"}: ${line(f.title, 120)}
|
|
432
|
+
${clean(r.detail, 1e3)}`,
|
|
433
|
+
{ fix: f.id, uuid: f.uuid, ...r }
|
|
434
|
+
);
|
|
435
|
+
return r.pass ? 0 : 1;
|
|
436
|
+
}
|
|
437
|
+
case "applied": {
|
|
438
|
+
need(1, "applied <fix> [--commit sha] [--note text]");
|
|
439
|
+
const f = await fixRef(args[0]);
|
|
440
|
+
await api().applied(f.uuid, {
|
|
441
|
+
...o.commit ? { commit: o.commit } : {},
|
|
442
|
+
...o.note ? { note: o.note } : {}
|
|
443
|
+
});
|
|
444
|
+
print(`Marked applied: ${line(f.title, 120)}. Run "${CLI} verify ${f.id}" once it's live.`, {
|
|
445
|
+
ok: true,
|
|
446
|
+
fix: f.id,
|
|
447
|
+
uuid: f.uuid,
|
|
448
|
+
status: "applied"
|
|
449
|
+
});
|
|
450
|
+
return 0;
|
|
451
|
+
}
|
|
452
|
+
case "report": {
|
|
453
|
+
need(1, "report <site>");
|
|
454
|
+
const s = await site(args[0]);
|
|
455
|
+
const md = await api().latestReport(s.id);
|
|
456
|
+
io.out(json ? JSON.stringify({ site: s.id, markdown: md }) : clean(md, 5e6));
|
|
457
|
+
return 0;
|
|
458
|
+
}
|
|
459
|
+
case "audit": {
|
|
460
|
+
need(1, "audit <site> [--wait] [--fail-on critical|warning|info] [--timeout minutes]");
|
|
461
|
+
const failOn = o["fail-on"];
|
|
462
|
+
if (failOn && !(failOn in SEVERITY_RANK))
|
|
463
|
+
throw new CliError("--fail-on must be critical, warning or info.", 2);
|
|
464
|
+
const minutes = Number(o.timeout ?? 30);
|
|
465
|
+
if (!Number.isFinite(minutes) || minutes <= 0)
|
|
466
|
+
throw new CliError("--timeout is in minutes, e.g. --timeout 30.", 2);
|
|
467
|
+
const s = await site(args[0]);
|
|
468
|
+
const a = api();
|
|
469
|
+
const started = await a.startAudit(s.id);
|
|
470
|
+
if (!o.wait && !failOn) {
|
|
471
|
+
print(
|
|
472
|
+
`${started.existing ? "An audit was already running" : "Audit started"} for ${hostOf(s.url)}. Run id ${started.run_id}.`,
|
|
473
|
+
{ site: s.id, run_id: started.run_id, existing: started.existing }
|
|
474
|
+
);
|
|
475
|
+
return 0;
|
|
476
|
+
}
|
|
477
|
+
if (!json)
|
|
478
|
+
io.err(`Audit ${started.existing ? "already running" : "started"} for ${hostOf(s.url)}\u2026`);
|
|
479
|
+
const deadline = Date.now() + minutes * 6e4;
|
|
480
|
+
let seen = 0;
|
|
481
|
+
for (; ; ) {
|
|
482
|
+
const r = await a.run(started.run_id);
|
|
483
|
+
if (!json)
|
|
484
|
+
for (const st of r.steps.slice(seen))
|
|
485
|
+
io.err(
|
|
486
|
+
` ${line(st.step, 40)}: ${line(st.status, 20)}${st.message ? ` ${line(st.message, 120)}` : ""}`
|
|
487
|
+
);
|
|
488
|
+
seen = r.steps.length;
|
|
489
|
+
if (["succeeded", "partial", "failed", "cancelled"].includes(r.status)) {
|
|
490
|
+
if (r.status === "failed" || r.status === "cancelled") {
|
|
491
|
+
print(`The audit ${r.status}${r.error ? `: ${line(r.error, 300)}` : "."}`, {
|
|
492
|
+
run_id: r.id,
|
|
493
|
+
status: r.status,
|
|
494
|
+
error: r.error
|
|
495
|
+
});
|
|
496
|
+
return 1;
|
|
497
|
+
}
|
|
498
|
+
const open = await a.fixes(s.id, "open");
|
|
499
|
+
const count = { critical: 0, warning: 0, info: 0 };
|
|
500
|
+
for (const f of open) count[f.severity] += 1;
|
|
501
|
+
const over = failOn ? open.filter(
|
|
502
|
+
(f) => SEVERITY_RANK[f.severity] >= SEVERITY_RANK[failOn]
|
|
503
|
+
) : [];
|
|
504
|
+
print(
|
|
505
|
+
[
|
|
506
|
+
`Audit ${r.status === "partial" ? "finished with some steps skipped" : "finished"} for ${hostOf(s.url)}: ${count.critical} critical, ${count.warning} warnings, ${count.info} info open.`,
|
|
507
|
+
...failOn ? over.length ? [
|
|
508
|
+
`Failing: ${over.length} open fix${over.length === 1 ? "" : "es"} at ${failOn} or worse.`,
|
|
509
|
+
...over.slice(0, 20).map((f) => ` ${f.severity} ${f.id} ${line(f.title, 100)}`)
|
|
510
|
+
] : [`Passed: nothing at ${failOn} or worse.`] : []
|
|
511
|
+
].join("\n"),
|
|
512
|
+
{
|
|
513
|
+
run_id: r.id,
|
|
514
|
+
status: r.status,
|
|
515
|
+
open: count,
|
|
516
|
+
fail_on: failOn ?? null,
|
|
517
|
+
failing: over.map((f) => f.id)
|
|
518
|
+
}
|
|
519
|
+
);
|
|
520
|
+
return over.length ? 1 : 0;
|
|
521
|
+
}
|
|
522
|
+
if (Date.now() > deadline) {
|
|
523
|
+
print(`Still running after ${minutes} minutes; stopped waiting. Run id ${r.id}.`, {
|
|
524
|
+
run_id: r.id,
|
|
525
|
+
status: r.status,
|
|
526
|
+
timed_out: true
|
|
527
|
+
});
|
|
528
|
+
return 1;
|
|
529
|
+
}
|
|
530
|
+
await io.sleep(1e4);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
case "connect": {
|
|
534
|
+
need(1, "connect <claude-code|cursor|vscode>");
|
|
535
|
+
const url = `${apiUrl}/mcp`;
|
|
536
|
+
const header = `Bearer \${${ENV_KEY}}`;
|
|
537
|
+
const snippets = {
|
|
538
|
+
"claude-code": `claude mcp add --transport http ${brand2.slug} ${url} \\
|
|
539
|
+
--header "Authorization: Bearer $${ENV_KEY}"`,
|
|
540
|
+
cursor: `Add to ~/.cursor/mcp.json (or .cursor/mcp.json in the project):
|
|
541
|
+
${JSON.stringify({ mcpServers: { [brand2.slug]: { url, headers: { Authorization: header } } } }, null, 2)}`,
|
|
542
|
+
vscode: `Add to .vscode/mcp.json:
|
|
543
|
+
${JSON.stringify({ servers: { [brand2.slug]: { type: "http", url, headers: { Authorization: header } } } }, null, 2)}`
|
|
544
|
+
};
|
|
545
|
+
const out = snippets[args[0]];
|
|
546
|
+
if (!out)
|
|
547
|
+
throw new CliError(`Unknown agent "${args[0]}". Use claude-code, cursor or vscode.`, 2);
|
|
548
|
+
print(
|
|
549
|
+
`${out}
|
|
550
|
+
|
|
551
|
+
Set ${ENV_KEY} to your API key first. Claude.ai and ChatGPT connect without a key: see Settings \u2192 Integrations \u2192 AI assistants.`,
|
|
552
|
+
{ agent: args[0], url, config: out }
|
|
553
|
+
);
|
|
554
|
+
return 0;
|
|
555
|
+
}
|
|
556
|
+
default:
|
|
557
|
+
throw new CliError(`Unknown command "${cmd}". Run "${CLI} --help".`, 2);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
function pathOf(u) {
|
|
561
|
+
try {
|
|
562
|
+
const x = new URL(u);
|
|
563
|
+
return x.pathname + x.search;
|
|
564
|
+
} catch {
|
|
565
|
+
return u;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// src/cli.ts
|
|
570
|
+
function askSecret(prompt) {
|
|
571
|
+
process.stderr.write(prompt);
|
|
572
|
+
let muted = true;
|
|
573
|
+
const output = new Writable({
|
|
574
|
+
write(chunk, _enc, cb) {
|
|
575
|
+
if (!muted) process.stderr.write(chunk);
|
|
576
|
+
cb();
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
const rl = createInterface({ input: process.stdin, output, terminal: true });
|
|
580
|
+
return new Promise((resolve) => {
|
|
581
|
+
rl.question("", (answer) => {
|
|
582
|
+
muted = false;
|
|
583
|
+
rl.close();
|
|
584
|
+
process.stderr.write("\n");
|
|
585
|
+
resolve(answer);
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
var code = await run(process.argv.slice(2), {
|
|
590
|
+
out: (s) => process.stdout.write(s + "\n"),
|
|
591
|
+
err: (s) => process.stderr.write(s + "\n"),
|
|
592
|
+
env: process.env,
|
|
593
|
+
fetch,
|
|
594
|
+
askSecret,
|
|
595
|
+
sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
596
|
+
configFile: configPath(createBrand({}).slug),
|
|
597
|
+
version: true ? "0.1.1" : "dev"
|
|
598
|
+
});
|
|
599
|
+
process.exitCode = code;
|
package/package.json
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "seenkite",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Command line for Seenkite: your sites, fixes and audits from the terminal or CI.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"seenkite": "dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/cli.js",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=20"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://seenkite.com/docs/api",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"keywords": [
|
|
20
|
+
"seo",
|
|
21
|
+
"ai-visibility",
|
|
22
|
+
"audit",
|
|
23
|
+
"mcp",
|
|
24
|
+
"cli"
|
|
25
|
+
]
|
|
26
|
+
}
|