serpkin 0.2.23 → 0.2.24

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.23 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.24 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.
@@ -77,10 +77,10 @@ Inside a session you can run `/plugin marketplace add apwn/serpkin`, then `/plug
77
77
 
78
78
  - 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.
79
79
  - **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.
80
- - the **Serpkin MCP server**, run as the same stdio bridge (`npx -y serpkin@0.2.23 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`).
80
+ - the **Serpkin MCP server**, run as the same stdio bridge (`npx -y serpkin@0.2.24 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`).
81
81
 
82
82
  - **hooks** (quiet by design, only in repositories with `.serpkin.json`):
83
- - **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.
83
+ - **Session start**: one line with the next mission and "run /serpkin:next". It is fetched with a 2.5-second timeout and cached for an hour per site (failures for 30 minutes); submitting, verifying, starting, dismissing or creating a mission through the Serpkin tools clears the cache, so the line never names a mission you just shipped. It says nothing when you are offline, signed out or the project isn't linked.
84
84
  - **After a push or deploy** (`git push`, `vercel deploy`/`--prod`, `netlify deploy`, `wrangler deploy`, `fly deploy`, `firebase deploy`, `railway up`, `npm|pnpm|yarn|bun run deploy`): one reminder per session to run `/serpkin:check <preview-url>`.
85
85
  - **Turn them off** with `SERPKIN_HOOKS=off` in your shell or in Claude Code's `settings.json` `env`. Keep just one with `SERPKIN_HOOKS=session` or `SERPKIN_HOOKS=deploy`.
86
86
  - **Safety**: the hooks run only the plugin's own scripts (never a binary or script from the repository), never print or cache your key, and follow the same server rules as the CLI: a server named only in `.serpkin.json` is used only when it is `https://serpkin.com` or a server you already signed in to, and the key is only sent to `SERPKIN_SERVER` (or `https://serpkin.com`). The command text of a push or deploy is never echoed.
@@ -93,7 +93,7 @@ Clients without plugins get the same loop as MCP prompts: `next_mission`, `ship_
93
93
 
94
94
  ### Where the key goes
95
95
 
96
- 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.23 mcp`, which reads it from there, so they hold no key and no environment variable, and you don't need to export anything.
96
+ 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.24 mcp`, which reads it from there, so they hold no key and no environment variable, and you don't need to export anything.
97
97
 
98
98
  `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.
99
99
 
package/lib/commands.mjs CHANGED
@@ -1048,7 +1048,7 @@ export function printCheck(r) {
1048
1048
  if (r.mode === "local") {
1049
1049
  if (r.status === "pass") out.ok(`No SEO regressions on the local build across ${pages}.`);
1050
1050
  else out.fail(`Found regressions on the local build (${pages} checked). Fix them before deploying.`);
1051
- out.note("After the deploy, check production (`npx serpkin check <production-url>`) and verify the mission with environment \"production\".");
1051
+ out.note("After the deploy, check production (`npx serpkin check <production-url>`) and verify the mission with the environment its verify step names (\"production\" for technical fixes, \"evidence\" for links and content).");
1052
1052
  return;
1053
1053
  }
1054
1054
  if (r.status === "pass")
package/lib/next.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // `serpkin next [--oneline]`: the next mission in one line, fast (2.5 s timeout, cached ≤ 1 request per
2
- // 6 hours per site). Shares its implementation with the Claude Code SessionStart hook
2
+ // hour per site, cleared when a mission changes). Shares its implementation with the Claude Code SessionStart hook
3
3
  // (plugin/serpkin/scripts/next-line.mjs), including the server-trust rules from config.mjs.
4
4
  import { nextLine } from "../plugin/serpkin/scripts/next-line.mjs";
5
5
  import { out, c } from "./ui.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serpkin",
3
- "version": "0.2.23",
3
+ "version": "0.2.24",
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.23",
4
+ "version": "0.2.24",
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.23", "mcp"]
6
+ "args": ["-y", "--registry=https://registry.npmjs.org", "serpkin@0.2.24", "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.23 check:*)
4
+ allowed-tools: Bash(npx -y --registry=https://registry.npmjs.org serpkin@0.2.24 check:*)
5
5
  ---
6
6
 
7
- Run `npx -y --registry=https://registry.npmjs.org serpkin@0.2.23 check $ARGUMENTS` from the repository root. If no URL was given, ask for the preview URL. A site without previews can pass its local production build (for example `http://localhost:3000`): the CLI reads it on this machine and compares it with production. Report that as a pre-deploy check, not production verification.
7
+ Run `npx -y --registry=https://registry.npmjs.org serpkin@0.2.24 check $ARGUMENTS` from the repository root. If no URL was given, ask for the preview URL. A site without previews can pass its local production build (for example `http://localhost:3000`): the CLI reads it on this machine and compares it with production. Report that as a pre-deploy check, not production verification.
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.23 check <preview-url>`. If it exits 1, fix the regressions, push and run it again. A site without previews passes its local production build instead (for example `http://localhost:3000`): that is a pre-deploy check, not verification, so skip step 3 and verify in production after I deploy.
8
+ 1. Run `npx -y --registry=https://registry.npmjs.org serpkin@0.2.24 check <preview-url>`. If it exits 1, fix the regressions, push and run it again. A site without previews passes its local production build instead (for example `http://localhost:3000`): that is a pre-deploy check, not verification, so skip step 3 and verify in production after I deploy.
9
9
  2. Call `serpkin_submit_result` with the PR URL, the preview URL (no previews: `deployment_url` once deployed), a short summary of the tests you ran and `files_changed` when you know it. The answer is short; pass `view: "full"` only if you need the whole mission.
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. For a speed mission, `serpkin_lab_check` (free) shows the page's lab numbers; say they are lab data. 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.23 status:*)
3
+ allowed-tools: Bash(npx -y --registry=https://registry.npmjs.org serpkin@0.2.24 status:*)
4
4
  ---
5
5
 
6
- Run `npx -y --registry=https://registry.npmjs.org serpkin@0.2.23 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`. Without a plan the output shows the preview's first mission and a Checkout row: show them as they are, once, and don't add a sales pitch or ask again.
6
+ Run `npx -y --registry=https://registry.npmjs.org serpkin@0.2.24 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`. Without a plan the output shows the preview's first mission and a Checkout row: show them as they are, once, and don't add a sales pitch or ask again.
@@ -1,5 +1,5 @@
1
1
  {
2
- "description": "Serpkin: one line with the next SEO mission at session start (linked projects only), and one /serpkin:check reminder after a push or deploy. Opt out with SERPKIN_HOOKS=off.",
2
+ "description": "Serpkin: one line with the next SEO mission at session start (linked projects only; refreshed when a mission is submitted, verified or changed), and one /serpkin:check reminder after a push or deploy. Opt out with SERPKIN_HOOKS=off.",
3
3
  "hooks": {
4
4
  "SessionStart": [
5
5
  {
@@ -132,6 +132,16 @@
132
132
  "timeout": 5
133
133
  }
134
134
  ]
135
+ },
136
+ {
137
+ "matcher": "mcp__.*serpkin.*__serpkin_(submit_result|verify_mission|update_mission|create_mission)",
138
+ "hooks": [
139
+ {
140
+ "type": "command",
141
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/scripts/mission-changed.mjs\"",
142
+ "timeout": 5
143
+ }
144
+ ]
135
145
  }
136
146
  ]
137
147
  }
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ // PostToolUse hook on the Serpkin MCP tools that change missions (submit, verify, start/dismiss/done,
3
+ // create): clear the cached session-start line so the next session names the mission that is really next,
4
+ // not one that just shipped. Prints nothing; always exits 0. Runs only this plugin's own code.
5
+ import { forgetNext, hookEnabled } from "./next-line.mjs";
6
+
7
+ /** Tools whose calls can change which mission is next (any MCP server name that contains "serpkin"). */
8
+ export const MISSION_TOOL = /^mcp__[A-Za-z0-9_-]*serpkin[A-Za-z0-9_-]*__serpkin_(?:submit_result|verify_mission|update_mission|create_mission)$/;
9
+
10
+ /** Hook input JSON from stdin; gives up after 1 s (or on oversized input) so the hook never hangs. */
11
+ function stdin() {
12
+ if (process.stdin.isTTY) return Promise.resolve({});
13
+ return new Promise((resolve) => {
14
+ let raw = "";
15
+ const done = () => {
16
+ clearTimeout(timer);
17
+ process.stdin.pause();
18
+ try {
19
+ resolve(JSON.parse(raw));
20
+ } catch {
21
+ resolve({});
22
+ }
23
+ };
24
+ const timer = setTimeout(done, 1000);
25
+ process.stdin.setEncoding("utf8");
26
+ process.stdin.on("data", (d) => {
27
+ raw += d;
28
+ if (raw.length > 1_000_000) done();
29
+ });
30
+ process.stdin.on("end", done);
31
+ process.stdin.on("error", done);
32
+ });
33
+ }
34
+
35
+ /** true when the cached line was cleared. */
36
+ export async function missionChanged({ input = {}, env = process.env } = {}) {
37
+ if (!hookEnabled("session", env)) return false;
38
+ if (!MISSION_TOOL.test(String(input.tool_name ?? ""))) return false;
39
+ const cwd = env.CLAUDE_PROJECT_DIR || (typeof input.cwd === "string" ? input.cwd : process.cwd());
40
+ return forgetNext({ cwd, env });
41
+ }
42
+
43
+ if (import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith("mission-changed.mjs")) {
44
+ await missionChanged({ input: await stdin() }).catch(() => false);
45
+ process.exit(0);
46
+ }
@@ -1,20 +1,21 @@
1
1
  // One line with the next Serpkin mission for the linked project: used by the Claude Code SessionStart hook
2
2
  // and `serpkin next --oneline`. Dependency-free (the plugin ships without the CLI's lib/).
3
3
  //
4
- // Fast and quiet by design: a short request timeout, a cache (≤ 1 request per 6 hours per site; failures
5
- // are remembered for 30 minutes), and no output at all when the project isn't linked (.serpkin.json),
4
+ // Fast and quiet by design: a short request timeout, a cache (≤ 1 request per hour per site; failures
5
+ // are remembered for 30 minutes; cleared by mission-changed.mjs when a mission is submitted, verified,
6
+ // started, dismissed or created through the Serpkin MCP tools), and no output at all when the project isn't linked (.serpkin.json),
6
7
  // the user isn't signed in, the server isn't trusted, or the network is down.
7
8
  //
8
9
  // Same server rules as the CLI (cli/lib/config.mjs): a server named only by .serpkin.json (repository
9
10
  // content) is used only when it is the hosted default or a server the user already signed in to, and
10
11
  // SERPKIN_API_KEY is only sent to SERPKIN_SERVER (or the default). The key is never printed or cached.
11
- import { readFile, writeFile, mkdir, rename } from "node:fs/promises";
12
+ import { readFile, writeFile, mkdir, rename, rm } from "node:fs/promises";
12
13
  import { createHash } from "node:crypto";
13
14
  import { homedir } from "node:os";
14
15
  import { join, dirname } from "node:path";
15
16
 
16
17
  export const DEFAULT_SERVER = "https://serpkin.com";
17
- export const CACHE_MS = 6 * 60 * 60 * 1000;
18
+ export const CACHE_MS = 60 * 60 * 1000;
18
19
  export const FAILURE_CACHE_MS = 30 * 60 * 1000;
19
20
  export const TIMEOUT_MS = 2500;
20
21
  const SITE_ID = /^[A-Za-z0-9_-]{1,80}$/;
@@ -67,6 +68,18 @@ export async function resolveTarget(cwd, env = process.env) {
67
68
  const cachePath = (env, server, site) =>
68
69
  join(configDir(env), "cache", `next-${createHash("sha256").update(`${server}\n${site}`).digest("hex").slice(0, 24)}.json`);
69
70
 
71
+ /** Drop the cached line for this project so the next session asks again. Never throws. */
72
+ export async function forgetNext({ cwd = process.cwd(), env = process.env } = {}) {
73
+ try {
74
+ const t = await resolveTarget(cwd, env);
75
+ if (!t) return false;
76
+ await rm(cachePath(env, t.server, t.site_id), { force: true });
77
+ return true;
78
+ } catch {
79
+ return false;
80
+ }
81
+ }
82
+
70
83
  /**
71
84
  * The line, or "" when there is nothing to say. Never throws. `fetchImpl` and `now` are test seams.
72
85
  * { line, cached } — `line` is plain text: "Next SEO mission: <title>" (+ how many more are queued).
@@ -43,8 +43,8 @@ An unverified site gets a 6-page preview. To verify it:
43
43
  - Otherwise do the `suggested_action` (usually `serpkin_scan_site`) and stop.
44
44
  2. **Implement.** First call `serpkin_update_mission` with `action: "start"` so the user and other agents see it is in progress (several at once: `mission_ids: [...]`, one call; each id gets its own result). Start and submit answer with the mission's summary and `next_step`; pass `view: "full"` only if you need the whole mission again. 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.
45
45
  3. **Run checks.** Run the project's tests, type check and build.
46
- 4. **Check the preview.** Once the branch has a preview deployment, run `npx -y --registry=https://registry.npmjs.org serpkin@0.2.23 check <preview-url>`. Exit code 1 means regressions; fix them and re-run.
47
- **No previews** (the site deploys straight to production, for example `wrangler deploy` to Cloudflare Workers): before the human deploys, serve a production build locally (`next build && next start`, or the project's preview script) and run `npx -y --registry=https://registry.npmjs.org serpkin@0.2.23 check http://localhost:3000` (your port). The CLI reads the local pages and Serpkin compares them with production; Serpkin never fetches localhost. Say plainly that this is a pre-deploy check, not production verification. Preview hosts on Vercel, Netlify, Cloudflare Pages and Workers (`*.workers.dev`), Render, Fly, Railway, Firebase and Amplify work directly; for the project's own staging domain, ask the user before running `check <url> --allow-host` once.
46
+ 4. **Check the preview.** Once the branch has a preview deployment, run `npx -y --registry=https://registry.npmjs.org serpkin@0.2.24 check <preview-url>`. Exit code 1 means regressions; fix them and re-run.
47
+ **No previews** (the site deploys straight to production, for example `wrangler deploy` to Cloudflare Workers): before the human deploys, serve a production build locally (`next build && next start`, or the project's preview script) and run `npx -y --registry=https://registry.npmjs.org serpkin@0.2.24 check http://localhost:3000` (your port). The CLI reads the local pages and Serpkin compares them with production; Serpkin never fetches localhost. Say plainly that this is a pre-deploy check, not production verification. Preview hosts on Vercel, Netlify, Cloudflare Pages and Workers (`*.workers.dev`), Render, Fly, Railway, Firebase and Amplify work directly; for the project's own staging domain, ask the user before running `check <url> --allow-host` once.
48
48
  5. **Submit.** Call `serpkin_submit_result` with the PR URL, preview URL, a short test summary and `files_changed` when you know it (no preview: `deployment_url` after the deploy, and mention the local pre-deploy check in `test_summary`).
49
49
  6. **Verify the preview.** Technical missions: `serpkin_verify_mission` with `environment: "preview"` and `preview_url`. Content and research missions: `environment: "evidence"`.
50
50
  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.23 check "$PREVIEW_URL" --site "$SERPKIN_SITE_ID"
40
+ run: npx --yes --registry=https://registry.npmjs.org serpkin@0.2.24 check "$PREVIEW_URL" --site "$SERPKIN_SITE_ID"