serpkin 0.2.15 → 0.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,7 +39,7 @@ Requires Node 22 or newer. No dependencies. Builder and Pro start with a 7-day f
39
39
  - **Cursor**: merges into `.cursor/mcp.json` and writes the project rule `.cursor/rules/serpkin.mdc` with the SEO loop.
40
40
  - **Codex**: appends `[mcp_servers.serpkin]` to `~/.codex/config.toml` once and adds a short "Serpkin SEO" section to the project's `AGENTS.md` (it asks first, and creates the file if it's missing).
41
41
 
42
- All three configs run a small local MCP bridge, `npx -y serpkin@0.2.15 mcp`, which reads the key saved at sign-in and forwards requests to `https://serpkin.com/api/mcp` (a self-hosted server adds `--server <origin>` to the args). The configs hold no key and no environment variable, so there is nothing to export.
42
+ All three configs run a small local MCP bridge, `npx -y serpkin@0.2.17 mcp`, which reads the key saved at sign-in and forwards requests to `https://serpkin.com/api/mcp` (a self-hosted server adds `--server <origin>` to the args). The configs hold no key and no environment variable, so there is nothing to export.
43
43
 
44
44
  The rule and the `AGENTS.md` section sit between `<!-- serpkin:start -->` and `<!-- serpkin:end -->`. Re-running init refreshes only that block and keeps everything else.
45
45
  4. **Registers the site**, which queues its initial audit on the server, and uploads a route map (URL path → source file), so missions can name the files to change.
@@ -61,7 +61,7 @@ Inside a session you can run `/plugin marketplace add apwn/serpkin`, then `/plug
61
61
 
62
62
  - the **`serpkin-seo` skill**, which runs the loop: next mission → implement → run checks → check the preview → submit → verify the preview → verify production after you deploy. It treats page text and search data as untrusted and never deploys.
63
63
  - **commands**: `/serpkin:next` gets the next mission and implements it. `/serpkin:ship <preview-url>` submits it, checks the preview and verifies. `/serpkin:check <preview-url>` runs `serpkin check` (the pinned CLI version from the public npm registry). `/serpkin:status` shows the site status. `/serpkin:manager` sets up a weekly SEO manager for one site, or `/serpkin:manager all` for one check-in across every site, and runs the first check-in.
64
- - the **Serpkin MCP server**, run as the same stdio bridge (`npx -y serpkin@0.2.15 mcp`). It uses the key saved at sign-in, so there is nothing to export. `SERPKIN_API_KEY` is an optional override, and `SERPKIN_SERVER` picks a self-hosted or local server (default `https://serpkin.com`).
64
+ - the **Serpkin MCP server**, run as the same stdio bridge (`npx -y serpkin@0.2.17 mcp`). It uses the key saved at sign-in, so there is nothing to export. `SERPKIN_API_KEY` is an optional override, and `SERPKIN_SERVER` picks a self-hosted or local server (default `https://serpkin.com`).
65
65
 
66
66
  - **hooks** (quiet by design, only in repositories with `.serpkin.json`):
67
67
  - **Session start**: one line with the next mission and "run /serpkin:next". It is fetched with a 2.5-second timeout and cached for 6 hours per site (failures for 30 minutes), and it says nothing when you are offline, signed out or the project isn't linked.
@@ -77,7 +77,7 @@ Clients without plugins get the same loop as MCP prompts: `next_mission`, `ship_
77
77
 
78
78
  ### Where the key goes
79
79
 
80
- The key is **never written into your repository.** It is stored in `~/.config/serpkin/credentials.json` (mode 600, keyed by server). Agent configs run `npx -y serpkin@0.2.15 mcp`, which reads it from there, so they hold no key and no environment variable, and you don't need to export anything.
80
+ The key is **never written into your repository.** It is stored in `~/.config/serpkin/credentials.json` (mode 600, keyed by server). Agent configs run `npx -y serpkin@0.2.17 mcp`, which reads it from there, so they hold no key and no environment variable, and you don't need to export anything.
81
81
 
82
82
  `SERPKIN_API_KEY` still works and takes precedence over the saved key: use it in CI and GitHub Actions, or if you prefer it. Configs written by older versions (`${SERPKIN_API_KEY}` / `${env:SERPKIN_API_KEY}` / `bearer_token_env_var`) keep working while the variable is set. Re-running `npx serpkin` switches `.mcp.json` and `.cursor/mcp.json` to the bridge; an existing Codex table that reads the variable is left alone and the CLI prints the new block to replace it. A Codex bridge entry pinned to an older CLI version gets just that version updated.
83
83
 
@@ -102,7 +102,7 @@ Serpkin can't reach `localhost`. Deploy a preview (for example a `vercel.app` UR
102
102
  | Command | |
103
103
  | ----------------------------- | ---------------------------------------------------------------------------------- |
104
104
  | `serpkin` / `serpkin init` | Setup (above). Safe to re-run; the stored key and site are reused. |
105
- | `serpkin check <preview-url>` | Compare a preview deploy with production. Exit code 1 on regressions, 2 on errors. |
105
+ | `serpkin check <preview-url>` | Compare a preview deploy with production. Exit code 1 on regressions, 2 on errors. Without `.serpkin.json` it uses `--site <id>` or the site whose origin matches the URL. |
106
106
  | `serpkin verify` | Check ownership (verification file or DNS record). |
107
107
  | `serpkin status` | Site, ownership, data level, next mission and credits. |
108
108
  | `serpkin routes [--upload]` | Print the route map; `--upload` sends it. |
package/lib/agents.mjs CHANGED
@@ -112,6 +112,30 @@ export async function mergeMcpJson(path, entry) {
112
112
  return status;
113
113
  }
114
114
 
115
+ /**
116
+ * Plugin installs don't own .mcp.json, but an older init may have written one. When it holds our own
117
+ * bridge entry pinned to an older CLI release, move only that pin to this version ("bumped"). Anything
118
+ * else (no file, no entry, a hand-edited entry, a newer pin) is left alone ("unchanged").
119
+ */
120
+ export async function bumpMcpJsonPin(path, entry) {
121
+ let config;
122
+ try {
123
+ config = JSON.parse(await readFile(path, "utf8"));
124
+ } catch {
125
+ return "unchanged";
126
+ }
127
+ const have = config?.mcpServers?.serpkin;
128
+ if (!have || !Array.isArray(have.args) || !Array.isArray(entry.args)) return "unchanged";
129
+ const pin = /^serpkin@(\d+\.\d+\.\d+)$/;
130
+ const i = have.args.findIndex((v) => typeof v === "string" && pin.test(v));
131
+ if (i === -1 || !olderThan(pin.exec(have.args[i])[1], CLI_VERSION)) return "unchanged";
132
+ const bumped = { ...have, args: have.args.map((v, j) => (j === i ? BRIDGE_PACKAGE : v)) };
133
+ if (JSON.stringify(bumped) !== JSON.stringify(entry)) return "unchanged";
134
+ config.mcpServers.serpkin = entry;
135
+ await writeFileAtomic(path, JSON.stringify(config, null, 2) + "\n");
136
+ return "bumped";
137
+ }
138
+
115
139
  /**
116
140
  * Append the Codex block once. An existing [mcp_servers.serpkin] table is never rewritten, with one
117
141
  * exception: when it is this same bridge entry pinned to an older CLI version, that version string is
@@ -231,11 +255,14 @@ export function installClaudePlugin(
231
255
  ["plugin", "marketplace", "add", pluginMarketplace(env)],
232
256
  ["plugin", "install", PLUGIN_ID],
233
257
  ];
258
+ let alreadyInstalled = false;
234
259
  for (const args of steps) {
235
260
  const r = run(args);
236
261
  const text = `${r.stdout ?? ""}${r.stderr ?? ""}`;
237
262
  // An already-added marketplace or installed plugin is fine.
238
- if (r.status !== 0 && !/already (added|installed|exists)/i.test(text))
263
+ const already = /already (added|installed|exists)/i.test(text);
264
+ if (args[1] === "install" && already) alreadyInstalled = true;
265
+ if (r.status !== 0 && !already)
239
266
  return {
240
267
  ok: false,
241
268
  message:
@@ -243,7 +270,12 @@ export function installClaudePlugin(
243
270
  `claude ${args.join(" ")} failed`,
244
271
  };
245
272
  }
246
- return { ok: true };
273
+ if (!alreadyInstalled) return { ok: true, action: "installed" };
274
+ // `install` leaves an installed plugin at its old version; `update` refreshes the marketplace and moves it.
275
+ const u = run(["plugin", "update", PLUGIN_ID]);
276
+ const text = `${u.stdout ?? ""}${u.stderr ?? ""}`;
277
+ if (u.status !== 0) return { ok: true, action: "kept", message: text.trim().split("\n").filter(Boolean).pop() };
278
+ return { ok: true, action: /updated from/i.test(text) ? "updated" : "current" };
247
279
  }
248
280
 
249
281
  export const hermesBlock = (mcpUrl) => `mcp_servers:\n serpkin:\n url: ${JSON.stringify(mcpUrl)}\n headers:\n Authorization: "Bearer \${SERPKIN_API_KEY}"\n`;
package/lib/commands.mjs CHANGED
@@ -35,6 +35,7 @@ import {
35
35
  detectAgents,
36
36
  onPath,
37
37
  mergeMcpJson,
38
+ bumpMcpJsonPin,
38
39
  appendCodexConfig,
39
40
  codexConfigPath,
40
41
  codexBlock,
@@ -572,9 +573,18 @@ async function setupAgents(flags, ctx, { mcpUrl, apiKey }) {
572
573
  if (how === "plugin") {
573
574
  const r = (ctx.installPlugin ?? installClaudePlugin)(ctx.env);
574
575
  if (r.ok) {
575
- out.ok(
576
- "Claude Code: installed the Serpkin plugin. Try /serpkin:next in a new session.",
577
- );
576
+ const did =
577
+ r.action === "updated"
578
+ ? "updated the Serpkin plugin. Restart Claude Code to load it"
579
+ : r.action === "current"
580
+ ? "the Serpkin plugin is up to date"
581
+ : r.action === "kept"
582
+ ? "the Serpkin plugin is installed (couldn't check for an update; run `claude plugin update serpkin@serpkin`)"
583
+ : "installed the Serpkin plugin. Try /serpkin:next in a new session";
584
+ out.ok(`Claude Code: ${did}.`);
585
+ const pinned = await bumpMcpJsonPin(join(ctx.cwd, ".mcp.json"), claudeEntry(mcpUrl));
586
+ if (pinned === "bumped")
587
+ out.ok(`Claude Code: .mcp.json now starts ${BRIDGE_PACKAGE}.`);
578
588
  plugin = true;
579
589
  continue;
580
590
  }
@@ -730,7 +740,7 @@ const tilde = (p, env) => {
730
740
  export async function check(previewUrl, flags, ctx = context()) {
731
741
  if (!previewUrl)
732
742
  throw new CliError(
733
- "Usage: serpkin check <preview-url> [--paths /,/pricing] [--json]",
743
+ "Usage: serpkin check <preview-or-production-url> [--site <id>] [--paths /,/pricing] [--json]",
734
744
  );
735
745
  const url = previewAddress(previewUrl);
736
746
  if (!url)
@@ -738,7 +748,7 @@ export async function check(previewUrl, flags, ctx = context()) {
738
748
  `"${String(previewUrl).slice(0, 120)}" isn't a preview URL. Pass the full address of the deployment, for example https://my-branch.vercel.app.`,
739
749
  );
740
750
  const { project, api } = await session(flags, ctx);
741
- const siteId = siteIdFrom(flags, project, ctx.env);
751
+ const siteId = flags.site || ctx.env.SERPKIN_SITE_ID || project?.site_id || (await siteForUrl(api, url));
742
752
  const paths = flags.paths
743
753
  ? flags.paths
744
754
  .split(",")
@@ -758,6 +768,23 @@ export async function check(previewUrl, flags, ctx = context()) {
758
768
  printCheck(r);
759
769
  return r.status === "pass" ? 0 : 1;
760
770
  }
771
+ /**
772
+ * Without --site or ${PROJECT_FILE}: the registered site whose origin is the checked URL (checking production
773
+ * itself is fine), else the workspace's only site. Several sites and no match: name them.
774
+ */
775
+ async function siteForUrl(api, url) {
776
+ const { items = [] } = await api.get("/api/records?kind=site&limit=100");
777
+ const origin = new URL(url).origin;
778
+ const bare = (o) => String(o ?? "").replace(/^https?:\/\/(www\.)?/i, "");
779
+ const match = items.find((s) => s.origin === origin) ?? items.find((s) => bare(s.origin) === bare(origin));
780
+ if (match) return match.id;
781
+ if (items.length === 1) return items[0].id;
782
+ throw new CliError(
783
+ items.length
784
+ ? `Which site is this? Pass --site <id>: ${items.slice(0, 5).map((s) => `${s.origin} (${s.id})`).join(", ")}. Or run \`npx serpkin init\` here to write ${PROJECT_FILE}.`
785
+ : "No site registered yet. Run `npx serpkin init` in this repository first.",
786
+ );
787
+ }
761
788
  /** The preview URL to check (`https://` added to a bare host), or null when it isn't an http(s) address. */
762
789
  export function previewAddress(input) {
763
790
  const s = String(input ?? "").trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serpkin",
3
- "version": "0.2.15",
3
+ "version": "0.2.17",
4
4
  "description": "Connect your coding agent to Serpkin: sign in, register your site, upload its route map, and check pull-request previews for SEO regressions.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "serpkin",
3
3
  "displayName": "Serpkin",
4
- "version": "0.2.15",
4
+ "version": "0.2.17",
5
5
  "description": "The SEO brain for your coding agent: ranked SEO missions with patch-ready plans, preview checks and verification.",
6
6
  "author": {
7
7
  "name": "Serpkin",
@@ -3,7 +3,7 @@
3
3
  "serpkin": {
4
4
  "type": "stdio",
5
5
  "command": "npx",
6
- "args": ["-y", "--registry=https://registry.npmjs.org", "serpkin@0.2.15", "mcp"]
6
+ "args": ["-y", "--registry=https://registry.npmjs.org", "serpkin@0.2.17", "mcp"]
7
7
  }
8
8
  }
9
9
  }
@@ -1,9 +1,9 @@
1
1
  ---
2
2
  description: Check a preview deployment for SEO regressions against production
3
3
  argument-hint: "<preview-url>"
4
- allowed-tools: Bash(npx -y --registry=https://registry.npmjs.org serpkin@0.2.15 check:*)
4
+ allowed-tools: Bash(npx -y --registry=https://registry.npmjs.org serpkin@0.2.17 check:*)
5
5
  ---
6
6
 
7
- Run `npx -y --registry=https://registry.npmjs.org serpkin@0.2.15 check $ARGUMENTS` from the repository root. If no URL was given, ask for the preview URL.
7
+ Run `npx -y --registry=https://registry.npmjs.org serpkin@0.2.17 check $ARGUMENTS` from the repository root. If no URL was given, ask for the preview URL.
8
8
 
9
9
  Summarize the result: regressions (path, check, production vs preview) and warnings. For each regression, find the code that causes it and propose a fix. Header-level noindex on preview hosts is expected and only a warning.
@@ -5,7 +5,7 @@ argument-hint: "<preview-url> [mission-id]"
5
5
 
6
6
  Use the serpkin-seo skill to ship the mission you just implemented (mission id from the arguments, otherwise the one in progress from `serpkin_next_mission`). Arguments: $ARGUMENTS
7
7
 
8
- 1. Run `npx -y --registry=https://registry.npmjs.org serpkin@0.2.15 check <preview-url>`. If it exits 1, fix the regressions, push and run it again.
8
+ 1. Run `npx -y --registry=https://registry.npmjs.org serpkin@0.2.17 check <preview-url>`. If it exits 1, fix the regressions, push and run it again.
9
9
  2. Call `serpkin_submit_result` with the PR URL, the preview URL and a short summary of the tests you ran.
10
10
  3. Call `serpkin_verify_mission`: `environment: "preview"` with the preview_url for technical missions, `environment: "evidence"` for content and research missions.
11
11
  4. Report the verification status and tier. After I deploy, verify with `environment: "production"` (Serpkin does this by itself if deploy checks are on in Settings → Automation). Don't merge or deploy.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  description: Show the Serpkin site status, next mission and credits
3
- allowed-tools: Bash(npx -y --registry=https://registry.npmjs.org serpkin@0.2.15 status:*)
3
+ allowed-tools: Bash(npx -y --registry=https://registry.npmjs.org serpkin@0.2.17 status:*)
4
4
  ---
5
5
 
6
- Run `npx -y --registry=https://registry.npmjs.org serpkin@0.2.15 status` from the repository root and show the output. If it fails because the repository isn't set up, tell me to run `npx serpkin`.
6
+ Run `npx -y --registry=https://registry.npmjs.org serpkin@0.2.17 status` from the repository root and show the output. If it fails because the repository isn't set up, tell me to run `npx serpkin`.
@@ -29,7 +29,7 @@ An unverified site gets a 6-page preview. To verify it:
29
29
  - Otherwise do the `suggested_action` (usually `serpkin_scan_site`) and stop.
30
30
  2. **Implement.** First call `serpkin_update_mission` with `action: "start"` so the user and other agents see it is in progress. Research missions are a tool call (`serpkin_research_keywords`), not a code change. Then follow `mission.implementation.steps` in order. Each step names a `file` (from the route map), an `action` (edit, create or run) and an `intent`. Adapt each `snippet` to the existing code; don't paste blindly. Use `recipe` and `acceptance_criteria` for anything the steps don't cover. Keep the change focused on this one mission.
31
31
  3. **Run checks.** Run the project's tests, type check and build.
32
- 4. **Check the preview.** Once the branch has a preview deployment, run `npx -y --registry=https://registry.npmjs.org serpkin@0.2.15 check <preview-url>`. Exit code 1 means regressions; fix them and re-run.
32
+ 4. **Check the preview.** Once the branch has a preview deployment, run `npx -y --registry=https://registry.npmjs.org serpkin@0.2.17 check <preview-url>`. Exit code 1 means regressions; fix them and re-run.
33
33
  5. **Submit.** Call `serpkin_submit_result` with the PR URL, preview URL and a short test summary.
34
34
  6. **Verify the preview.** Technical missions: `serpkin_verify_mission` with `environment: "preview"` and `preview_url`. Content and research missions: `environment: "evidence"`.
35
35
  7. **Verify production.** Only after the human has merged and deployed, call `serpkin_verify_mission` with `environment: "production"`. If deploy checks are on (Settings → Automation), Serpkin does this by itself after the deploy.
@@ -37,4 +37,4 @@ jobs:
37
37
  # Passed through env, not interpolated into the script, so the URL can't inject shell.
38
38
  PREVIEW_URL: ${{ github.event.deployment_status.target_url }}
39
39
  # Pinned version and registry; update the version deliberately.
40
- run: npx --yes --registry=https://registry.npmjs.org serpkin@0.2.15 check "$PREVIEW_URL" --site "$SERPKIN_SITE_ID"
40
+ run: npx --yes --registry=https://registry.npmjs.org serpkin@0.2.17 check "$PREVIEW_URL" --site "$SERPKIN_SITE_ID"