seo-supervisor 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/.claude-plugin/icon.png +0 -0
  2. package/.claude-plugin/marketplace.json +2 -2
  3. package/.claude-plugin/plugin.json +16 -3
  4. package/CHANGELOG.md +430 -0
  5. package/NOTICE +7 -0
  6. package/README.md +230 -25
  7. package/agents/seo-auditor.md +16 -0
  8. package/agents/seo-reviewer.md +16 -0
  9. package/bin/agents.mjs +194 -29
  10. package/bin/extras.mjs +422 -0
  11. package/bin/prompt.mjs +34 -14
  12. package/bin/seo-supervisor.mjs +386 -53
  13. package/commands/seo-audit.md +29 -3
  14. package/commands/seo-brief.md +28 -0
  15. package/commands/seo-connect.md +27 -0
  16. package/commands/seo-fix.md +24 -3
  17. package/commands/seo-grow.md +26 -0
  18. package/commands/seo-launch.md +17 -3
  19. package/commands/seo-review.md +13 -1
  20. package/commands/seo-rewrite.md +25 -0
  21. package/commands/seo-setup.md +17 -1
  22. package/commands/seo-watch.md +28 -0
  23. package/hooks/hooks.json +117 -0
  24. package/package.json +20 -7
  25. package/skills/seo-supervisor/NOTICE +7 -0
  26. package/skills/seo-supervisor/SKILL.md +302 -21
  27. package/skills/seo-supervisor/audience.md +61 -0
  28. package/skills/seo-supervisor/examples/drafts/security.md +41 -0
  29. package/skills/seo-supervisor/examples/hooks/README.md +28 -0
  30. package/skills/seo-supervisor/examples/hooks/claude-code-settings.json +15 -0
  31. package/skills/seo-supervisor/examples/hooks/codex-hooks.json +17 -0
  32. package/skills/seo-supervisor/examples/hooks/copilot-hooks.json +15 -0
  33. package/skills/seo-supervisor/examples/hooks/cursor-hooks.json +11 -0
  34. package/skills/seo-supervisor/examples/hooks/github-actions.yml +21 -0
  35. package/skills/seo-supervisor/examples/hooks/pre-commit +17 -0
  36. package/skills/seo-supervisor/examples/hooks/reading-ease.yml +24 -0
  37. package/skills/seo-supervisor/examples/sample-audit.json +94 -2
  38. package/skills/seo-supervisor/examples/sample-report.html +111 -61
  39. package/skills/seo-supervisor/examples/sample-report.md +147 -44
  40. package/skills/seo-supervisor/examples/scheduled-runs.md +89 -0
  41. package/skills/seo-supervisor/examples/snippets.md +648 -1
  42. package/skills/seo-supervisor/grow.md +342 -0
  43. package/skills/seo-supervisor/og-images.md +85 -0
  44. package/skills/seo-supervisor/page-types.md +124 -0
  45. package/skills/seo-supervisor/planning.md +19 -7
  46. package/skills/seo-supervisor/profile-template.md +41 -0
  47. package/skills/seo-supervisor/report-format.md +177 -10
  48. package/skills/seo-supervisor/rewrite.md +59 -0
  49. package/skills/seo-supervisor/rules/ai-search.md +65 -12
  50. package/skills/seo-supervisor/rules/content.md +33 -9
  51. package/skills/seo-supervisor/rules/crawl-index.md +33 -6
  52. package/skills/seo-supervisor/rules/internal-linking.md +49 -6
  53. package/skills/seo-supervisor/rules/launch-monitoring.md +17 -8
  54. package/skills/seo-supervisor/rules/media.md +13 -1
  55. package/skills/seo-supervisor/rules/metadata.md +41 -9
  56. package/skills/seo-supervisor/rules/performance.md +50 -5
  57. package/skills/seo-supervisor/rules/rendering.md +39 -2
  58. package/skills/seo-supervisor/rules/search-intent.md +32 -0
  59. package/skills/seo-supervisor/rules/sitemaps-robots.md +24 -12
  60. package/skills/seo-supervisor/rules/structured-data.md +37 -14
  61. package/skills/seo-supervisor/rules/trust-security.md +25 -2
  62. package/skills/seo-supervisor/rules/urls.md +10 -2
  63. package/skills/seo-supervisor/scripts/ai-answers.mjs +314 -0
  64. package/skills/seo-supervisor/scripts/backlinks.mjs +412 -0
  65. package/skills/seo-supervisor/scripts/change-check.mjs +281 -0
  66. package/skills/seo-supervisor/scripts/checks/agents.mjs +488 -0
  67. package/skills/seo-supervisor/scripts/checks/assets.mjs +404 -0
  68. package/skills/seo-supervisor/scripts/checks/bots.mjs +146 -0
  69. package/skills/seo-supervisor/scripts/checks/business-type.mjs +193 -0
  70. package/skills/seo-supervisor/scripts/checks/content.mjs +391 -0
  71. package/skills/seo-supervisor/scripts/checks/coverage.mjs +184 -0
  72. package/skills/seo-supervisor/scripts/checks/crawl.mjs +95 -0
  73. package/skills/seo-supervisor/scripts/checks/hreflang.mjs +396 -0
  74. package/skills/seo-supervisor/scripts/checks/hygiene.mjs +227 -0
  75. package/skills/seo-supervisor/scripts/checks/lighthouse.mjs +271 -0
  76. package/skills/seo-supervisor/scripts/checks/link-strength.mjs +59 -0
  77. package/skills/seo-supervisor/scripts/checks/links.mjs +360 -0
  78. package/skills/seo-supervisor/scripts/checks/local.mjs +101 -0
  79. package/skills/seo-supervisor/scripts/checks/media.mjs +194 -0
  80. package/skills/seo-supervisor/scripts/checks/outbound.mjs +53 -0
  81. package/skills/seo-supervisor/scripts/checks/page.mjs +223 -0
  82. package/skills/seo-supervisor/scripts/checks/probes.mjs +130 -0
  83. package/skills/seo-supervisor/scripts/checks/render.mjs +552 -0
  84. package/skills/seo-supervisor/scripts/checks/robots.mjs +144 -0
  85. package/skills/seo-supervisor/scripts/checks/schema.mjs +206 -0
  86. package/skills/seo-supervisor/scripts/checks/site-agents.mjs +79 -0
  87. package/skills/seo-supervisor/scripts/checks/site-content.mjs +135 -0
  88. package/skills/seo-supervisor/scripts/checks/site-hygiene.mjs +202 -0
  89. package/skills/seo-supervisor/scripts/checks/site-pages.mjs +474 -0
  90. package/skills/seo-supervisor/scripts/checks/site-security.mjs +102 -0
  91. package/skills/seo-supervisor/scripts/checks/sitemap.mjs +473 -0
  92. package/skills/seo-supervisor/scripts/checks/speed.mjs +267 -0
  93. package/skills/seo-supervisor/scripts/checks/technical.mjs +368 -0
  94. package/skills/seo-supervisor/scripts/checks/tls.mjs +297 -0
  95. package/skills/seo-supervisor/scripts/checks/trust.mjs +421 -0
  96. package/skills/seo-supervisor/scripts/checks/visual.mjs +1132 -0
  97. package/skills/seo-supervisor/scripts/checks/writing.mjs +192 -0
  98. package/skills/seo-supervisor/scripts/commoncrawl.mjs +452 -0
  99. package/skills/seo-supervisor/scripts/connect-keys.mjs +422 -0
  100. package/skills/seo-supervisor/scripts/content-scan.mjs +515 -158
  101. package/skills/seo-supervisor/scripts/crawl/catalog.mjs +1248 -0
  102. package/skills/seo-supervisor/scripts/crawl/fetch.mjs +362 -0
  103. package/skills/seo-supervisor/scripts/crawl/page.mjs +741 -0
  104. package/skills/seo-supervisor/scripts/crawl/queue.mjs +190 -0
  105. package/skills/seo-supervisor/scripts/dashboard.mjs +140 -0
  106. package/skills/seo-supervisor/scripts/data/ai-bots.json +38 -0
  107. package/skills/seo-supervisor/scripts/data/build-schema-vocab.mjs +57 -0
  108. package/skills/seo-supervisor/scripts/data/business-types.json +338 -0
  109. package/skills/seo-supervisor/scripts/data/google-rich-results.json +79 -0
  110. package/skills/seo-supervisor/scripts/data/schema-vocab.json +1 -0
  111. package/skills/seo-supervisor/scripts/deploy-check.mjs +462 -0
  112. package/skills/seo-supervisor/scripts/disavow.mjs +176 -0
  113. package/skills/seo-supervisor/scripts/doctor.mjs +174 -0
  114. package/skills/seo-supervisor/scripts/geo-grid.mjs +371 -0
  115. package/skills/seo-supervisor/scripts/google/search-console.mjs +151 -0
  116. package/skills/seo-supervisor/scripts/google/session.mjs +167 -0
  117. package/skills/seo-supervisor/scripts/google-updates.mjs +189 -0
  118. package/skills/seo-supervisor/scripts/google.mjs +1341 -0
  119. package/skills/seo-supervisor/scripts/gsc-import.mjs +298 -0
  120. package/skills/seo-supervisor/scripts/guard/adapters/claude-code.mjs +149 -0
  121. package/skills/seo-supervisor/scripts/guard/adapters/cline.mjs +28 -0
  122. package/skills/seo-supervisor/scripts/guard/adapters/codex.mjs +26 -0
  123. package/skills/seo-supervisor/scripts/guard/adapters/copilot.mjs +36 -0
  124. package/skills/seo-supervisor/scripts/guard/adapters/cursor.mjs +33 -0
  125. package/skills/seo-supervisor/scripts/guard/adapters/devin.mjs +25 -0
  126. package/skills/seo-supervisor/scripts/guard/adapters/edits.mjs +124 -0
  127. package/skills/seo-supervisor/scripts/guard/mode.mjs +37 -0
  128. package/skills/seo-supervisor/scripts/guard/rules.mjs +931 -0
  129. package/skills/seo-supervisor/scripts/guard.mjs +74 -0
  130. package/skills/seo-supervisor/scripts/images.mjs +408 -0
  131. package/skills/seo-supervisor/scripts/indexnow.mjs +300 -0
  132. package/skills/seo-supervisor/scripts/issues.mjs +217 -0
  133. package/skills/seo-supervisor/scripts/keys/authority.mjs +135 -0
  134. package/skills/seo-supervisor/scripts/keys/bing.mjs +239 -0
  135. package/skills/seo-supervisor/scripts/keys/clarity.mjs +137 -0
  136. package/skills/seo-supervisor/scripts/keys/dataforseo.mjs +57 -0
  137. package/skills/seo-supervisor/scripts/keys/googleplaces.mjs +26 -0
  138. package/skills/seo-supervisor/scripts/keys/http.mjs +212 -0
  139. package/skills/seo-supervisor/scripts/keys/matomo.mjs +138 -0
  140. package/skills/seo-supervisor/scripts/keys/openai.mjs +26 -0
  141. package/skills/seo-supervisor/scripts/keys/perplexity.mjs +26 -0
  142. package/skills/seo-supervisor/scripts/keys/posthog.mjs +165 -0
  143. package/skills/seo-supervisor/scripts/keys/semrush.mjs +25 -0
  144. package/skills/seo-supervisor/scripts/keys/services.mjs +41 -0
  145. package/skills/seo-supervisor/scripts/keys/store.mjs +140 -0
  146. package/skills/seo-supervisor/scripts/keys/visits.mjs +58 -0
  147. package/skills/seo-supervisor/scripts/keys/youtube.mjs +84 -0
  148. package/skills/seo-supervisor/scripts/keyword-data.mjs +316 -0
  149. package/skills/seo-supervisor/scripts/keyword-ideas.mjs +503 -0
  150. package/skills/seo-supervisor/scripts/lib/args.mjs +56 -0
  151. package/skills/seo-supervisor/scripts/lib/business.mjs +27 -0
  152. package/skills/seo-supervisor/scripts/lib/cdp.mjs +242 -0
  153. package/skills/seo-supervisor/scripts/lib/cli.mjs +56 -0
  154. package/skills/seo-supervisor/scripts/lib/csv.mjs +38 -0
  155. package/skills/seo-supervisor/scripts/lib/findings.mjs +100 -0
  156. package/skills/seo-supervisor/scripts/lib/google-client.mjs +9 -0
  157. package/skills/seo-supervisor/scripts/lib/html.mjs +146 -0
  158. package/skills/seo-supervisor/scripts/lib/http.mjs +28 -0
  159. package/skills/seo-supervisor/scripts/lib/image-size.mjs +78 -0
  160. package/skills/seo-supervisor/scripts/lib/is-main.mjs +13 -0
  161. package/skills/seo-supervisor/scripts/lib/net.mjs +116 -0
  162. package/skills/seo-supervisor/scripts/lib/proxy.mjs +47 -0
  163. package/skills/seo-supervisor/scripts/lib/recheck.mjs +106 -0
  164. package/skills/seo-supervisor/scripts/lib/redact.mjs +78 -0
  165. package/skills/seo-supervisor/scripts/lib/robots.mjs +73 -0
  166. package/skills/seo-supervisor/scripts/lib/score.mjs +266 -0
  167. package/skills/seo-supervisor/scripts/lib/settings-dir.mjs +81 -0
  168. package/skills/seo-supervisor/scripts/links-import.mjs +603 -0
  169. package/skills/seo-supervisor/scripts/log-scan.mjs +597 -0
  170. package/skills/seo-supervisor/scripts/og-card.mjs +273 -0
  171. package/skills/seo-supervisor/scripts/osm.mjs +359 -0
  172. package/skills/seo-supervisor/scripts/rdap.mjs +164 -0
  173. package/skills/seo-supervisor/scripts/render-report.mjs +324 -690
  174. package/skills/seo-supervisor/scripts/report/client.js +37 -0
  175. package/skills/seo-supervisor/scripts/report/diff.mjs +264 -0
  176. package/skills/seo-supervisor/scripts/report/findings.mjs +165 -0
  177. package/skills/seo-supervisor/scripts/report/format.mjs +111 -0
  178. package/skills/seo-supervisor/scripts/report/markdown.mjs +250 -0
  179. package/skills/seo-supervisor/scripts/report/model.mjs +171 -0
  180. package/skills/seo-supervisor/scripts/report/overview-lines.mjs +158 -0
  181. package/skills/seo-supervisor/scripts/report/overview.mjs +224 -0
  182. package/skills/seo-supervisor/scripts/report/page.mjs +127 -0
  183. package/skills/seo-supervisor/scripts/report/panel.mjs +172 -0
  184. package/skills/seo-supervisor/scripts/report/panels/ai.mjs +211 -0
  185. package/skills/seo-supervisor/scripts/report/panels/connections.mjs +139 -0
  186. package/skills/seo-supervisor/scripts/report/panels/content.mjs +204 -0
  187. package/skills/seo-supervisor/scripts/report/panels/data-search.mjs +379 -0
  188. package/skills/seo-supervisor/scripts/report/panels/data-site.mjs +44 -0
  189. package/skills/seo-supervisor/scripts/report/panels/links.mjs +380 -0
  190. package/skills/seo-supervisor/scripts/report/panels/local.mjs +221 -0
  191. package/skills/seo-supervisor/scripts/report/panels/site.mjs +359 -0
  192. package/skills/seo-supervisor/scripts/report/panels/speed-media.mjs +267 -0
  193. package/skills/seo-supervisor/scripts/report/sources.mjs +163 -0
  194. package/skills/seo-supervisor/scripts/report/styles.css +223 -0
  195. package/skills/seo-supervisor/scripts/report/traffic.mjs +264 -0
  196. package/skills/seo-supervisor/scripts/report-plan.mjs +112 -33
  197. package/skills/seo-supervisor/scripts/schema-check.mjs +717 -0
  198. package/skills/seo-supervisor/scripts/seo-crawl.mjs +1086 -638
  199. package/skills/seo-supervisor/scripts/seo-diff.mjs +584 -0
  200. package/skills/seo-supervisor/scripts/update-check.mjs +82 -0
  201. package/skills/seo-supervisor/site-types/content.md +34 -1
  202. package/skills/seo-supervisor/site-types/ecommerce.md +38 -1
  203. package/skills/seo-supervisor/site-types/local-business.md +96 -6
  204. package/skills/seo-supervisor/site-types/services.md +46 -0
  205. package/skills/seo-supervisor/site-types/tools.md +3 -3
  206. package/skills/seo-supervisor/strategy.md +232 -0
  207. package/skills/seo-supervisor/troubleshooting.md +56 -0
package/bin/extras.mjs ADDED
@@ -0,0 +1,422 @@
1
+ // @ts-check
2
+ // Slash commands, subagents and the guard hook, each in the agent's own format (bin/agents.mjs). Every path an install
3
+ // creates is recorded in the skill folder, so --uninstall removes exactly that. A hook entry is ours only if it runs
4
+ // this skill's guard.mjs.
5
+ import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, rmdirSync, writeFileSync } from "node:fs";
6
+ import { dirname, isAbsolute, join, relative } from "node:path";
7
+
8
+ export const NAME = "seo-supervisor";
9
+ // Command names from earlier versions, so uninstall removes those files too when they're ours.
10
+ export const RETIRED_COMMANDS = [];
11
+ const RECORD = ".seo-supervisor-install.json";
12
+ const OURS = /seo-supervisor[\\/]+scripts[\\/]+guard\.mjs/;
13
+ const mine = text => typeof text === "string" && text.includes(NAME);
14
+
15
+ // Recorded paths are relative to the scope's root (home or project), so a committed project install can be removed on
16
+ // another machine.
17
+ export function readRecord(skillDir) {
18
+ try {
19
+ return JSON.parse(readFileSync(join(skillDir, RECORD), "utf8")).created || [];
20
+ } catch {
21
+ return [];
22
+ }
23
+ }
24
+ export const writeRecord = (skillDir, created) =>
25
+ writeFileSync(join(skillDir, RECORD), JSON.stringify({ created: [...new Set(created)] }, null, 2) + "\n");
26
+
27
+ /** Makes a folder, remembering each folder that wasn't there before. */
28
+ export function mkdirs(dir, created, root) {
29
+ const missing = [];
30
+ for (let d = dir; !existsSync(d) && dirname(d) !== d; d = dirname(d)) missing.unshift(d);
31
+ mkdirSync(dir, { recursive: true });
32
+ for (const d of missing) created.push(rel(root, d));
33
+ }
34
+ const rel = (root, p) => {
35
+ const r = relative(root, p);
36
+ return r.startsWith("..") || isAbsolute(r) ? p : r.split("\\").join("/");
37
+ };
38
+ const abs = (root, p) => (isAbsolute(p) ? p : join(root, p));
39
+ /** Writes a file, remembering it (and its new folders) when it's new. */
40
+ function put(file, text, created, root) {
41
+ mkdirs(dirname(file), created, root);
42
+ if (!existsSync(file)) created.push(rel(root, file));
43
+ writeFileSync(file, text);
44
+ }
45
+
46
+ /** Removes recorded folders once they're empty, deepest first. Files are left alone: a created file that's still
47
+ * there may have gained someone else's hooks since. */
48
+ export function prune(created, root) {
49
+ for (const p of [...new Set(created)].map(x => abs(root, x)).sort((a, b) => b.length - a.length)) {
50
+ try {
51
+ if (readdirSync(p).length === 0) rmdirSync(p);
52
+ } catch {}
53
+ }
54
+ }
55
+
56
+ // ---- commands ----
57
+ const frontmatter = md => {
58
+ const m = md.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/);
59
+ return { head: m ? m[1] : "", body: m ? md.slice(m[0].length) : md };
60
+ };
61
+ const field = (head, k) => head.match(new RegExp(`^${k}:[^\\n]*(?:\\n[ \\t]+[^\\n]*)*`, "m"))?.[0];
62
+ const unquote = v => {
63
+ const s = v.trim();
64
+ return /^["'].*["']$/.test(s) ? s.slice(1, -1) : s;
65
+ };
66
+ /** A command file in one agent's format: { name, text }. Roo has no argument placeholder, so its text points at what
67
+ * follows the command. Gemini CLI gets TOML with {{args}}; a JSON string is a valid TOML basic string. */
68
+ export function commandFile(file, md, format) {
69
+ const base = file.replace(/\.md$/, "");
70
+ if (format === "roo") return { name: `${base}.md`, text: md.replaceAll("$ARGUMENTS", "the text after the command") };
71
+ if (format !== "toml") return { name: `${base}.md`, text: md };
72
+ const { head, body } = frontmatter(md),
73
+ desc = field(head, "description");
74
+ return {
75
+ name: `${base}.toml`,
76
+ text: `${desc ? `description = ${JSON.stringify(unquote(desc.slice(12)))}\n` : ""}prompt = ${JSON.stringify(body.trim().replaceAll("$ARGUMENTS", "{{args}}"))}\n`,
77
+ };
78
+ }
79
+
80
+ // ---- subagents ----
81
+ /** A Claude Code subagent (agents/*.md) in another agent's format: { name, text }, or null without a name. Only name,
82
+ * description and instructions carry over, since tool and model names differ per agent. ${CLAUDE_PLUGIN_ROOT} becomes
83
+ * skillDir, and the plugin-only site setting is replaced with a note. */
84
+ export function subagentFile(md, format, skillDir = "") {
85
+ const { head, body } = frontmatter(md),
86
+ name = field(head, "name"),
87
+ desc = field(head, "description");
88
+ if (!name) return null;
89
+ const id = unquote(name.slice(5)),
90
+ note = `\n\n<!-- Installed by ${NAME}; npx ${NAME} --uninstall removes it. -->\n`;
91
+ const fm = { cursor: [name, desc, "model: inherit"], opencode: [desc, "mode: subagent"], copilot: [name, desc] }[
92
+ format
93
+ ].filter(Boolean);
94
+ const text = body
95
+ .trimEnd()
96
+ .replaceAll("${CLAUDE_PLUGIN_ROOT}/skills/seo-supervisor", skillDir)
97
+ .replaceAll("`${user_config.site_url}`", "(only in the Claude Code plugin)");
98
+ return {
99
+ name: format === "copilot" ? `${id}.agent.md` : `${id}.md`,
100
+ text: `---\n${fm.join("\n")}\n---\n${text}${note}`,
101
+ };
102
+ }
103
+
104
+ // ---- the guard's hook entries ----
105
+ // The guard's path is always quoted for the shell that runs it, so ' & ( ) or a space in a home folder can't break the
106
+ // command. sh writes ' as '\''; PowerShell doubles ' and the curly quotes it also reads as '; cmd needs only "…", as a
107
+ // Windows path can't hold a ". Known gap, rare in home folders: % under cmd, or $ and ` where PowerShell reads "…".
108
+ // Codex runs $SHELL -lc, or cmd via commandWindows on Windows; Cursor runs PowerShell on Windows, else sh; Copilot has
109
+ // bash and powershell fields. Devin's docs don't say, so Windows gets "…", read alike by cmd, PowerShell and Git Bash.
110
+ // https://learn.chatgpt.com/docs/hooks
111
+ // https://cursor.com/docs/hooks
112
+ const QUOTE = {
113
+ sh: p => `'${p.replaceAll("'", "'\\''")}'`,
114
+ ps: p => `'${p.replace(/['‘’‚‛]/g, "$&$&")}'`,
115
+ cmd: p => `"${p}"`,
116
+ };
117
+ // A project install is committed and the agent may start in a subfolder. Cursor runs project hooks from the project
118
+ // root and Copilot takes a cwd relative to the repo root, so a relative path works there. Codex runs hooks from the
119
+ // session's folder and Devin sets DEVIN_PROJECT_DIR, each under a shell that varies by machine, so for those two node
120
+ // walks up from DEVIN_PROJECT_DIR or the cwd to the first folder holding the guard. The script has no " $ ` % ! or \,
121
+ // so sh, cmd and PowerShell all pass it to node unchanged.
122
+ // https://docs.devin.ai/cli/extensibility/hooks/overview
123
+ const finder = (rel, format, event) =>
124
+ `node -e "const p=require('path'),f=require('fs');let d=${format === "devin" ? "process.env.DEVIN_PROJECT_DIR||" : ""}process.cwd(),g;for(;;d=p.dirname(d)){g=p.join(d,'${rel}');if(f.existsSync(g)||p.dirname(d)==d)break}process.exitCode=require('child_process').spawnSync(process.execPath,[g,'--agent','${format}','--event','${event}'],{stdio:'inherit'}).status??1"`;
125
+ /** The hook entries for one agent, by event. guard is absolute, or relative to the project for a project install. */
126
+ function entries(format, guard, project) {
127
+ const win = process.platform === "win32",
128
+ found = project && (format === "codex" || format === "devin");
129
+ const run = (event, shell) =>
130
+ found ? finder(guard, format, event) : `node ${QUOTE[shell](guard)} --agent ${format} --event ${event}`;
131
+ if (format === "cursor") {
132
+ const c = e => ({ command: run(e, win ? "ps" : "sh") });
133
+ return {
134
+ beforeShellExecution: [c("beforeShellExecution")],
135
+ preToolUse: [{ ...c("preToolUse"), matcher: "Write|Delete" }],
136
+ beforeSubmitPrompt: [c("beforeSubmitPrompt")],
137
+ };
138
+ }
139
+ if (format === "copilot") {
140
+ // Copilot's preToolUse denies the tool when a command hook fails, so a missing node must still exit 0.
141
+ const cp = event => ({
142
+ type: "command",
143
+ bash: `${run(event, "sh")} || true`,
144
+ powershell: `${run(event, "ps")}; exit 0`,
145
+ ...(project ? { cwd: "." } : {}),
146
+ timeoutSec: 10,
147
+ });
148
+ return {
149
+ preToolUse: [{ ...cp("preToolUse"), matcher: "bash|powershell|edit|create|str_replace_editor|apply_patch" }],
150
+ userPromptTransformed: [cp("userPromptTransformed")],
151
+ };
152
+ }
153
+ const hook = event =>
154
+ format === "codex"
155
+ ? {
156
+ type: "command",
157
+ command: run(event, "sh"),
158
+ ...(found ? {} : { commandWindows: run(event, "cmd") }),
159
+ statusMessage: "SEO Supervisor guard",
160
+ }
161
+ : { type: "command", command: run(event, win ? "cmd" : "sh"), timeout: 10 };
162
+ const group = (event, matcher) => ({ ...(matcher !== undefined ? { matcher } : {}), hooks: [hook(event)] });
163
+ if (format === "codex")
164
+ return { PreToolUse: [group("PreToolUse", "^(Bash|apply_patch)$")], UserPromptSubmit: [group("UserPromptSubmit")] };
165
+ return {
166
+ PreToolUse: [group("PreToolUse", "^(exec|edit|write|apply_patch)$")],
167
+ UserPromptSubmit: [group("UserPromptSubmit", "")],
168
+ };
169
+ }
170
+ // Cline runs plugins in a worker, so the plugin runs the guard in a child process and returns what it prints. A
171
+ // missing node, a crash or a timeout lets the call through, so the guard can't lock up the agent. A relative guard path
172
+ // resolves from the project root, two folders above .cline/plugins, whatever folder the session started in.
173
+ // https://docs.cline.bot/sdk/plugins
174
+ const clinePlugin =
175
+ guard => `// SEO Supervisor's guard for Cline. Installed by npx ${NAME}; npx ${NAME} --uninstall removes it.
176
+ // Cline runs plugins in its CLI, SDK and Kanban, not yet in the VS Code or JetBrains extension.
177
+ import { spawnSync } from "node:child_process";
178
+ import { existsSync } from "node:fs";
179
+ import { isAbsolute, join } from "node:path";
180
+ import { fileURLToPath } from "node:url";
181
+ const GUARD = ${JSON.stringify(guard)};
182
+ let cwd = process.cwd(), root = "";
183
+ try { root = fileURLToPath(new URL("../..", import.meta.url)); } catch {}
184
+ export default {
185
+ name: "seo-supervisor-guard",
186
+ manifest: { capabilities: ["hooks"] },
187
+ setup(api, ctx) { if (ctx && ctx.cwd) cwd = ctx.cwd; },
188
+ hooks: {
189
+ beforeTool(context) {
190
+ const guard = isAbsolute(GUARD) ? GUARD : [root, cwd].filter(Boolean).map(d => join(d, GUARD)).find(p => existsSync(p)) || GUARD;
191
+ const r = spawnSync("node", [guard, "--agent", "cline", "--event", "beforeTool"], { cwd, encoding: "utf8", timeout: 2500,
192
+ input: JSON.stringify({ tool: context && context.toolCall && context.toolCall.name, input: context && context.input, cwd }) });
193
+ try { return r.status === 0 && r.stdout.trim() ? JSON.parse(r.stdout) : undefined; } catch { return undefined; }
194
+ },
195
+ },
196
+ };
197
+ `;
198
+
199
+ // Where the events live in each JSON hook file: the whole file (Devin's hooks.v1.json) or its "hooks" key.
200
+ const eventsOf = (format, file, o) =>
201
+ format === "devin" && file.endsWith("hooks.v1.json")
202
+ ? o
203
+ : (o.hooks = o.hooks && typeof o.hooks === "object" ? o.hooks : {});
204
+ const fresh = format => (format === "cursor" ? { version: 1, hooks: {} } : format === "codex" ? { hooks: {} } : {});
205
+ /** Takes the guard's entries out of an events map, keeping every other hook, including those in a shared group. */
206
+ function strip(events) {
207
+ for (const [event, list] of Object.entries(events)) {
208
+ if (!Array.isArray(list) || !OURS.test(JSON.stringify(list))) continue;
209
+ const kept = [];
210
+ for (const item of list) {
211
+ if (!Array.isArray(item?.hooks)) {
212
+ if (!OURS.test(JSON.stringify(item))) kept.push(item);
213
+ continue;
214
+ }
215
+ const hooks = item.hooks.filter(h => !OURS.test(JSON.stringify(h)));
216
+ if (hooks.length) kept.push({ ...item, hooks });
217
+ }
218
+ if (kept.length) events[event] = kept;
219
+ else delete events[event];
220
+ }
221
+ }
222
+ /** A JSON object file plus its formatting (BOM, indent, line ending, final newline), so a rewrite changes only the
223
+ * guard's entries. Some Windows editors add a UTF-8 BOM, which JSON.parse alone rejects. */
224
+ function readJson(file) {
225
+ if (!existsSync(file)) return null;
226
+ const text = readFileSync(file, "utf8"),
227
+ body = text.replace(/^/, ""),
228
+ o = JSON.parse(body);
229
+ if (!o || typeof o !== "object" || Array.isArray(o)) throw new Error("not a JSON object");
230
+ // No indented line: a one-line file stays one line, an empty {} gets two spaces.
231
+ return {
232
+ o,
233
+ look: {
234
+ bom: text === body ? "" : "",
235
+ indent: /^[ \t]+(?=\S)/m.exec(body)?.[0] ?? (/^\{\s*\}$|\n/.test(body.trim()) ? 2 : 0),
236
+ eol: body.includes("\r\n") ? "\r\n" : "\n",
237
+ end: /\n$/.test(body),
238
+ },
239
+ };
240
+ }
241
+ const NEW = { bom: "", indent: /** @type {string | number} */ (2), eol: "\n", end: true };
242
+ const writeJson = (o, look = NEW) =>
243
+ look.bom + JSON.stringify(o, null, look.indent).replaceAll("\n", look.eol) + (look.end ? look.eol : "");
244
+
245
+ // Codex warns when one folder declares hooks in both hooks.json and config.toml, so when config.toml holds the hooks
246
+ // the guard's go there too, as inline TOML tables between marker lines. JSON strings are valid TOML basic strings.
247
+ // https://learn.chatgpt.com/docs/hooks
248
+ const BLOCK = /\n# >>> seo-supervisor guard[^\n]*\n[\s\S]*?# <<< seo-supervisor guard\n/;
249
+ const tomlBlock = events =>
250
+ `\n# >>> seo-supervisor guard (npx ${NAME} --uninstall removes this block)\n${Object.entries(events)
251
+ .flatMap(([ev, groups]) =>
252
+ groups.flatMap(g => [
253
+ `[[hooks.${ev}]]`,
254
+ ...(g.matcher !== undefined ? [`matcher = ${JSON.stringify(g.matcher)}`] : []),
255
+ ...g.hooks.flatMap(h => [
256
+ `[[hooks.${ev}.hooks]]`,
257
+ ...Object.entries(h).map(([k, v]) => `${k} = ${JSON.stringify(v)}`),
258
+ ]),
259
+ ]),
260
+ )
261
+ .join("\n")}\n# <<< seo-supervisor guard\n`;
262
+ const readText = f => {
263
+ try {
264
+ return readFileSync(f, "utf8");
265
+ } catch {
266
+ return null;
267
+ }
268
+ };
269
+ /** Codex's config.toml beside hooks.json when the guard belongs there, else null: it declares hooks, hooks.json has
270
+ * none, and they aren't plain arrays (PreToolUse = [...]) that a table can't be added to. */
271
+ function codexToml(file) {
272
+ const toml = join(dirname(file), "config.toml"),
273
+ text = readText(toml)?.replace(BLOCK, "");
274
+ if (!text || !/^[ \t]*\[\[?hooks[.\]]/m.test(text) || /^[ \t]*(PreToolUse|UserPromptSubmit)[ \t]*=/m.test(text))
275
+ return null;
276
+ let r;
277
+ try {
278
+ r = readJson(file);
279
+ } catch {
280
+ return null;
281
+ } // the JSON path reports an invalid hooks.json
282
+ if (r) strip(eventsOf("codex", file, r.o));
283
+ return !r || !Object.keys(r.o.hooks).length ? toml : null;
284
+ }
285
+ /** Takes the guard's block out of the config.toml beside a Codex hooks.json: [["kept", path]], or [] if it had none. */
286
+ function untoml(file) {
287
+ const toml = join(dirname(file), "config.toml"),
288
+ text = readText(toml);
289
+ if (text === null || !BLOCK.test(text)) return [];
290
+ writeFileSync(toml, text.replace(BLOCK, ""));
291
+ return [["kept", toml]];
292
+ }
293
+
294
+ /** Adds the guard for one agent (replacing an older copy). project: guard is relative to the project root.
295
+ * Returns a problem message, or null. */
296
+ export function addHooks(format, file, guard, created, root, project = false) {
297
+ if (format === "copilot")
298
+ return (put(file, writeJson({ version: 1, hooks: entries(format, guard, project) }), created, root), null);
299
+ if (format === "cline") return (put(file, clinePlugin(guard), created, root), null);
300
+ const toml = format === "codex" ? codexToml(file) : null;
301
+ if (toml) {
302
+ removeHooks(format, file, created, root); // an older copy, in either file
303
+ const text = readFileSync(toml, "utf8");
304
+ writeFileSync(toml, text + (text.endsWith("\n") ? "" : "\n") + tomlBlock(entries(format, guard, project)));
305
+ return null;
306
+ }
307
+ if (format === "codex") untoml(file); // hooks moved to hooks.json, so the guard's follow
308
+ let r;
309
+ try {
310
+ r = readJson(file) ?? { o: fresh(format), look: NEW };
311
+ } catch {
312
+ return `${file} isn't valid JSON, so the guard wasn't added to it`;
313
+ }
314
+ // Cursor requires "version". https://cursor.com/docs/hooks
315
+ if (format === "cursor" && r.o.version === undefined) r.o = { version: 1, ...r.o };
316
+ const events = eventsOf(format, file, r.o);
317
+ strip(events);
318
+ for (const [event, list] of Object.entries(entries(format, guard, project)))
319
+ events[event] = [...(Array.isArray(events[event]) ? events[event] : []), ...list];
320
+ put(file, writeJson(r.o, r.look), created, root);
321
+ return null;
322
+ }
323
+
324
+ /** Takes the guard out of one agent's hook file (and Codex's config.toml), deleting a file the install created once
325
+ * nothing else is left. Returns [what, file] pairs: "removed", or "kept" when other hooks remain. */
326
+ export function removeHooks(format, file, created, root) {
327
+ const out = format === "codex" ? untoml(file) : [];
328
+ if (!existsSync(file)) return out;
329
+ if (format === "copilot" || format === "cline") {
330
+ if (OURS.test(readFileSync(file, "utf8"))) {
331
+ rmSync(file);
332
+ out.push(["removed", file]);
333
+ }
334
+ return out;
335
+ }
336
+ let r;
337
+ try {
338
+ r = readJson(file);
339
+ } catch {
340
+ return out;
341
+ }
342
+ if (!r || !OURS.test(JSON.stringify(r.o))) return out;
343
+ const o = r.o;
344
+ strip(eventsOf(format, file, o));
345
+ // Devin's user config.json holds other settings too: an emptied "hooks" key goes.
346
+ if (format === "devin" && o.hooks && !Object.keys(o.hooks).length) delete o.hooks;
347
+ const ours = created.includes(rel(root, file)),
348
+ empty = JSON.stringify(o) === JSON.stringify(fresh(format));
349
+ if (ours && empty) rmSync(file);
350
+ else writeFileSync(file, writeJson(o, r.look));
351
+ return [...out, [ours && empty ? "removed" : "kept", file]];
352
+ }
353
+
354
+ /** Installs one target's extras. src: { commands: [[file, md]], subagents: [md] }. guard: false skips the hook (and
355
+ * takes an older one out). Returns lines to print and problems. */
356
+ export function installExtras(t, { src, guard, force, scope, root, created, show }) {
357
+ const lines = [],
358
+ problems = [];
359
+ const ref = p => (scope === "project" ? rel(root, p) : p.split("\\").join("/")); // a committed project install names its own files
360
+ const skillRef = ref(join(t.skills, NAME)),
361
+ guardRef = `${skillRef}/scripts/guard.mjs`;
362
+ for (const x of t.extras) {
363
+ if (x.kind === "hooks") {
364
+ if (!guard) {
365
+ for (const [, f] of removeHooks(x.format, x.path, created, root))
366
+ lines.push(`removed the guard from ${show(f)} (--no-guard)`);
367
+ continue;
368
+ }
369
+ const err = addHooks(x.format, x.path, guardRef, created, root, scope === "project" && !isAbsolute(guardRef));
370
+ if (err) problems.push(err);
371
+ else lines.push(`guard ${show((x.format === "codex" && codexToml(x.path)) || x.path)}`);
372
+ continue;
373
+ }
374
+ const files =
375
+ x.kind === "commands"
376
+ ? src.commands.map(([f, md]) => commandFile(f, md, x.format))
377
+ : src.subagents.map(md => subagentFile(md, x.format, skillRef)).filter(Boolean);
378
+ const added = [];
379
+ for (const { name, text } of files) {
380
+ const file = join(x.path, name);
381
+ if (existsSync(file) && !mine(readFileSync(file, "utf8")) && !force) {
382
+ problems.push(`${show(file)}: a different one exists (use --force to replace it)`);
383
+ continue;
384
+ }
385
+ put(file, text, created, root);
386
+ added.push(name.replace(/(\.agent)?\.(md|toml)$/, ""));
387
+ }
388
+ if (added.length)
389
+ lines.push(
390
+ `${x.kind === "commands" ? "commands" : "agents "} ${added.map(n => (x.kind === "commands" ? "/" : "") + n).join(" ")} (${show(x.path)})`,
391
+ );
392
+ }
393
+ return { lines, problems };
394
+ }
395
+
396
+ /** Removes one target's extras: its commands (current and retired names), subagents and guard entries. Returns
397
+ * [what, file] pairs: "removed", or "kept" for a hook file that only lost the guard. */
398
+ export function removeExtras(t, { src, created, root }) {
399
+ const gone = [];
400
+ for (const x of t.extras) {
401
+ if (x.kind === "hooks") {
402
+ gone.push(...removeHooks(x.format, x.path, created, root));
403
+ continue;
404
+ }
405
+ const names =
406
+ x.kind === "commands"
407
+ ? [...src.commands.map(([f]) => f), ...RETIRED_COMMANDS.map(n => `${n}.md`)].map(
408
+ f => commandFile(f, "", x.format).name,
409
+ )
410
+ : src.subagents.map(md => subagentFile(md, x.format)?.name).filter(Boolean);
411
+ for (const name of names) {
412
+ const file = join(x.path, name);
413
+ try {
414
+ if (mine(readFileSync(file, "utf8"))) {
415
+ rmSync(file);
416
+ gone.push(["removed", file]);
417
+ }
418
+ } catch {}
419
+ }
420
+ }
421
+ return gone;
422
+ }
package/bin/prompt.mjs CHANGED
@@ -1,9 +1,12 @@
1
- // Tiny keyboard prompts with no dependencies: a single choice and a checklist.
2
- // They read keypresses from any stream, so tests can drive them with a PassThrough.
1
+ // @ts-check
2
+ // Dependency-free keyboard prompts. They read keypresses from any stream, so tests can drive them with a PassThrough.
3
3
  import { emitKeypressEvents } from "node:readline";
4
4
 
5
+ // The legacy Windows console can't draw these glyphs; Windows Terminal sets WT_SESSION.
5
6
  const plainGlyphs = process.platform === "win32" && !process.env.WT_SESSION && !process.env.TERM_PROGRAM;
6
- const G = plainGlyphs ? { ptr: ">", on: "(*)", off: "( )", yes: "[x]", no: "[ ]" } : { ptr: "❯", on: "●", off: "○", yes: "◉", no: "◯" };
7
+ const G = plainGlyphs
8
+ ? { ptr: ">", on: "(*)", off: "( )", yes: "[x]", no: "[ ]" }
9
+ : { ptr: "❯", on: "●", off: "○", yes: "◉", no: "◯" };
7
10
 
8
11
  function ask({ input, output, render, onKey }) {
9
12
  const paint = (code, s) => (output.isTTY && !process.env.NO_COLOR ? `\x1b[${code}m${s}\x1b[0m` : s);
@@ -27,7 +30,8 @@ function ask({ input, output, render, onKey }) {
27
30
  settle(value);
28
31
  };
29
32
  const onPress = (str, key = {}) => {
30
- if (key.ctrl && key.name === "c") return finish(reject, Object.assign(new Error("Cancelled"), { code: "CANCELLED" }));
33
+ if (key.ctrl && key.name === "c")
34
+ return finish(reject, Object.assign(new Error("Cancelled"), { code: "CANCELLED" }));
31
35
  const r = onKey(str, key) || {};
32
36
  draw(r.note);
33
37
  if ("value" in r) finish(resolve, r.value);
@@ -42,8 +46,16 @@ function ask({ input, output, render, onKey }) {
42
46
  export function select({ message, items, initial = 0, input = process.stdin, output = process.stdout }) {
43
47
  let i = initial;
44
48
  return ask({
45
- input, output,
46
- render: paint => [`${paint(36, "?")} ${paint(1, message)}`, ...items.map((it, n) => `${n === i ? paint(36, G.ptr) : " "} ${n === i ? paint(36, G.on) : G.off} ${it.label}${it.hint ? ` ${paint(2, it.hint)}` : ""}`)].join("\n"),
49
+ input,
50
+ output,
51
+ render: paint =>
52
+ [
53
+ `${paint(36, "?")} ${paint(1, message)}`,
54
+ ...items.map(
55
+ (it, n) =>
56
+ `${n === i ? paint(36, G.ptr) : " "} ${n === i ? paint(36, G.on) : G.off} ${it.label}${it.hint ? ` ${paint(2, it.hint)}` : ""}`,
57
+ ),
58
+ ].join("\n"),
47
59
  onKey: (s, k) => {
48
60
  if (k.name === "up" || k.name === "k") i = (i - 1 + items.length) % items.length;
49
61
  else if (k.name === "down" || k.name === "j") i = (i + 1) % items.length;
@@ -52,22 +64,30 @@ export function select({ message, items, initial = 0, input = process.stdin, out
52
64
  });
53
65
  }
54
66
 
55
- /** A checklist. Space toggles, a toggles all, enter confirms (at least one). Resolves to the chosen values in list order. */
67
+ /** A checklist: space toggles, a toggles all, enter confirms at least one. Resolves to the values in list order. */
56
68
  export function multiSelect({ message, items, selected = [], input = process.stdin, output = process.stdout }) {
57
69
  let i = 0;
58
70
  const on = new Set(selected);
59
71
  return ask({
60
- input, output,
61
- render: paint => [
62
- `${paint(36, "?")} ${paint(1, message)} ${paint(2, "(space to select, a for all, enter to confirm)")}`,
63
- ...items.map((it, n) => `${n === i ? paint(36, G.ptr) : " "} ${on.has(it.value) ? paint(32, G.yes) : G.no} ${it.label}${it.hint ? ` ${paint(2, it.hint)}` : ""}`),
64
- ].join("\n"),
72
+ input,
73
+ output,
74
+ render: paint =>
75
+ [
76
+ `${paint(36, "?")} ${paint(1, message)} ${paint(2, "(space to select, a for all, enter to confirm)")}`,
77
+ ...items.map(
78
+ (it, n) =>
79
+ `${n === i ? paint(36, G.ptr) : " "} ${on.has(it.value) ? paint(32, G.yes) : G.no} ${it.label}${it.hint ? ` ${paint(2, it.hint)}` : ""}`,
80
+ ),
81
+ ].join("\n"),
65
82
  onKey: (s, k) => {
66
83
  if (k.name === "up" || k.name === "k") i = (i - 1 + items.length) % items.length;
67
84
  else if (k.name === "down" || k.name === "j") i = (i + 1) % items.length;
68
85
  else if (k.name === "space") on.has(items[i].value) ? on.delete(items[i].value) : on.add(items[i].value);
69
- else if (k.name === "a") { const all = on.size === items.length; on.clear(); if (!all) items.forEach(it => on.add(it.value)); }
70
- else if (k.name === "return") {
86
+ else if (k.name === "a") {
87
+ const all = on.size === items.length;
88
+ on.clear();
89
+ if (!all) items.forEach(it => on.add(it.value));
90
+ } else if (k.name === "return") {
71
91
  if (!on.size) return { note: "Select at least one with space." };
72
92
  return { value: items.filter(it => on.has(it.value)).map(it => it.value) };
73
93
  }