seo-supervisor 0.0.0-stage → 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 (218) hide show
  1. package/.claude-plugin/icon.png +0 -0
  2. package/.claude-plugin/marketplace.json +16 -0
  3. package/.claude-plugin/plugin.json +27 -0
  4. package/CHANGELOG.md +461 -0
  5. package/LICENSE +25 -0
  6. package/NOTICE +7 -0
  7. package/README.md +402 -2
  8. package/agents/seo-auditor.md +16 -0
  9. package/agents/seo-reviewer.md +16 -0
  10. package/bin/agents.mjs +230 -0
  11. package/bin/extras.mjs +422 -0
  12. package/bin/prompt.mjs +96 -0
  13. package/bin/seo-supervisor.mjs +477 -0
  14. package/commands/seo-audit.md +33 -0
  15. package/commands/seo-brief.md +28 -0
  16. package/commands/seo-connect.md +27 -0
  17. package/commands/seo-fix.md +34 -0
  18. package/commands/seo-grow.md +26 -0
  19. package/commands/seo-launch.md +21 -0
  20. package/commands/seo-review.md +19 -0
  21. package/commands/seo-rewrite.md +25 -0
  22. package/commands/seo-setup.md +35 -0
  23. package/commands/seo-watch.md +28 -0
  24. package/hooks/hooks.json +117 -0
  25. package/package.json +58 -4
  26. package/skills/seo-supervisor/NOTICE +7 -0
  27. package/skills/seo-supervisor/SKILL.md +480 -0
  28. package/skills/seo-supervisor/audience.md +61 -0
  29. package/skills/seo-supervisor/examples/drafts/security.md +41 -0
  30. package/skills/seo-supervisor/examples/hooks/README.md +28 -0
  31. package/skills/seo-supervisor/examples/hooks/claude-code-settings.json +15 -0
  32. package/skills/seo-supervisor/examples/hooks/codex-hooks.json +17 -0
  33. package/skills/seo-supervisor/examples/hooks/copilot-hooks.json +15 -0
  34. package/skills/seo-supervisor/examples/hooks/cursor-hooks.json +11 -0
  35. package/skills/seo-supervisor/examples/hooks/github-actions.yml +21 -0
  36. package/skills/seo-supervisor/examples/hooks/pre-commit +17 -0
  37. package/skills/seo-supervisor/examples/hooks/reading-ease.yml +24 -0
  38. package/skills/seo-supervisor/examples/sample-audit.json +532 -0
  39. package/skills/seo-supervisor/examples/sample-report.html +704 -0
  40. package/skills/seo-supervisor/examples/sample-report.md +360 -0
  41. package/skills/seo-supervisor/examples/scheduled-runs.md +89 -0
  42. package/skills/seo-supervisor/examples/security-tools-profile.md +73 -0
  43. package/skills/seo-supervisor/examples/snippets.md +781 -0
  44. package/skills/seo-supervisor/frameworks/nextjs.md +98 -0
  45. package/skills/seo-supervisor/frameworks/rails.md +34 -0
  46. package/skills/seo-supervisor/frameworks/spa.md +14 -0
  47. package/skills/seo-supervisor/grow.md +342 -0
  48. package/skills/seo-supervisor/og-images.md +85 -0
  49. package/skills/seo-supervisor/page-types.md +124 -0
  50. package/skills/seo-supervisor/planning.md +157 -0
  51. package/skills/seo-supervisor/profile-template.md +96 -0
  52. package/skills/seo-supervisor/report-format.md +313 -0
  53. package/skills/seo-supervisor/rewrite.md +59 -0
  54. package/skills/seo-supervisor/rules/ai-search.md +93 -0
  55. package/skills/seo-supervisor/rules/content.md +84 -0
  56. package/skills/seo-supervisor/rules/crawl-index.md +92 -0
  57. package/skills/seo-supervisor/rules/internal-linking.md +104 -0
  58. package/skills/seo-supervisor/rules/launch-monitoring.md +57 -0
  59. package/skills/seo-supervisor/rules/media.md +42 -0
  60. package/skills/seo-supervisor/rules/metadata.md +71 -0
  61. package/skills/seo-supervisor/rules/performance.md +78 -0
  62. package/skills/seo-supervisor/rules/rendering.md +79 -0
  63. package/skills/seo-supervisor/rules/search-intent.md +32 -0
  64. package/skills/seo-supervisor/rules/sitemaps-robots.md +49 -0
  65. package/skills/seo-supervisor/rules/structured-data.md +98 -0
  66. package/skills/seo-supervisor/rules/trust-security.md +48 -0
  67. package/skills/seo-supervisor/rules/urls.md +54 -0
  68. package/skills/seo-supervisor/scripts/ai-answers.mjs +314 -0
  69. package/skills/seo-supervisor/scripts/backlinks.mjs +412 -0
  70. package/skills/seo-supervisor/scripts/change-check.mjs +281 -0
  71. package/skills/seo-supervisor/scripts/checks/agents.mjs +488 -0
  72. package/skills/seo-supervisor/scripts/checks/assets.mjs +404 -0
  73. package/skills/seo-supervisor/scripts/checks/bots.mjs +146 -0
  74. package/skills/seo-supervisor/scripts/checks/business-type.mjs +193 -0
  75. package/skills/seo-supervisor/scripts/checks/content.mjs +391 -0
  76. package/skills/seo-supervisor/scripts/checks/coverage.mjs +184 -0
  77. package/skills/seo-supervisor/scripts/checks/crawl.mjs +95 -0
  78. package/skills/seo-supervisor/scripts/checks/hreflang.mjs +396 -0
  79. package/skills/seo-supervisor/scripts/checks/hygiene.mjs +227 -0
  80. package/skills/seo-supervisor/scripts/checks/lighthouse.mjs +271 -0
  81. package/skills/seo-supervisor/scripts/checks/link-strength.mjs +59 -0
  82. package/skills/seo-supervisor/scripts/checks/links.mjs +360 -0
  83. package/skills/seo-supervisor/scripts/checks/local.mjs +101 -0
  84. package/skills/seo-supervisor/scripts/checks/media.mjs +194 -0
  85. package/skills/seo-supervisor/scripts/checks/outbound.mjs +53 -0
  86. package/skills/seo-supervisor/scripts/checks/page.mjs +223 -0
  87. package/skills/seo-supervisor/scripts/checks/probes.mjs +130 -0
  88. package/skills/seo-supervisor/scripts/checks/render.mjs +552 -0
  89. package/skills/seo-supervisor/scripts/checks/robots.mjs +144 -0
  90. package/skills/seo-supervisor/scripts/checks/schema.mjs +206 -0
  91. package/skills/seo-supervisor/scripts/checks/site-agents.mjs +79 -0
  92. package/skills/seo-supervisor/scripts/checks/site-content.mjs +135 -0
  93. package/skills/seo-supervisor/scripts/checks/site-hygiene.mjs +202 -0
  94. package/skills/seo-supervisor/scripts/checks/site-pages.mjs +474 -0
  95. package/skills/seo-supervisor/scripts/checks/site-security.mjs +102 -0
  96. package/skills/seo-supervisor/scripts/checks/sitemap.mjs +473 -0
  97. package/skills/seo-supervisor/scripts/checks/speed.mjs +267 -0
  98. package/skills/seo-supervisor/scripts/checks/technical.mjs +368 -0
  99. package/skills/seo-supervisor/scripts/checks/tls.mjs +297 -0
  100. package/skills/seo-supervisor/scripts/checks/trust.mjs +421 -0
  101. package/skills/seo-supervisor/scripts/checks/visual.mjs +1132 -0
  102. package/skills/seo-supervisor/scripts/checks/writing.mjs +192 -0
  103. package/skills/seo-supervisor/scripts/commoncrawl.mjs +452 -0
  104. package/skills/seo-supervisor/scripts/connect-keys.mjs +422 -0
  105. package/skills/seo-supervisor/scripts/content-scan.mjs +530 -0
  106. package/skills/seo-supervisor/scripts/crawl/catalog.mjs +1248 -0
  107. package/skills/seo-supervisor/scripts/crawl/fetch.mjs +362 -0
  108. package/skills/seo-supervisor/scripts/crawl/page.mjs +741 -0
  109. package/skills/seo-supervisor/scripts/crawl/queue.mjs +190 -0
  110. package/skills/seo-supervisor/scripts/dashboard.mjs +140 -0
  111. package/skills/seo-supervisor/scripts/data/ai-bots.json +38 -0
  112. package/skills/seo-supervisor/scripts/data/build-schema-vocab.mjs +57 -0
  113. package/skills/seo-supervisor/scripts/data/business-types.json +338 -0
  114. package/skills/seo-supervisor/scripts/data/google-rich-results.json +79 -0
  115. package/skills/seo-supervisor/scripts/data/schema-vocab.json +1 -0
  116. package/skills/seo-supervisor/scripts/deploy-check.mjs +462 -0
  117. package/skills/seo-supervisor/scripts/disavow.mjs +176 -0
  118. package/skills/seo-supervisor/scripts/doctor.mjs +174 -0
  119. package/skills/seo-supervisor/scripts/fonts/OFL-BricolageGrotesque.txt +93 -0
  120. package/skills/seo-supervisor/scripts/fonts/OFL-Geist.txt +93 -0
  121. package/skills/seo-supervisor/scripts/fonts/OFL-GeistMono.txt +93 -0
  122. package/skills/seo-supervisor/scripts/fonts/bricolage-grotesque.woff2 +0 -0
  123. package/skills/seo-supervisor/scripts/fonts/geist-mono.woff2 +0 -0
  124. package/skills/seo-supervisor/scripts/fonts/geist.woff2 +0 -0
  125. package/skills/seo-supervisor/scripts/geo-grid.mjs +371 -0
  126. package/skills/seo-supervisor/scripts/google/search-console.mjs +151 -0
  127. package/skills/seo-supervisor/scripts/google/session.mjs +167 -0
  128. package/skills/seo-supervisor/scripts/google-updates.mjs +189 -0
  129. package/skills/seo-supervisor/scripts/google.mjs +1341 -0
  130. package/skills/seo-supervisor/scripts/gsc-import.mjs +298 -0
  131. package/skills/seo-supervisor/scripts/guard/adapters/claude-code.mjs +149 -0
  132. package/skills/seo-supervisor/scripts/guard/adapters/cline.mjs +28 -0
  133. package/skills/seo-supervisor/scripts/guard/adapters/codex.mjs +26 -0
  134. package/skills/seo-supervisor/scripts/guard/adapters/copilot.mjs +36 -0
  135. package/skills/seo-supervisor/scripts/guard/adapters/cursor.mjs +33 -0
  136. package/skills/seo-supervisor/scripts/guard/adapters/devin.mjs +25 -0
  137. package/skills/seo-supervisor/scripts/guard/adapters/edits.mjs +124 -0
  138. package/skills/seo-supervisor/scripts/guard/mode.mjs +37 -0
  139. package/skills/seo-supervisor/scripts/guard/rules.mjs +931 -0
  140. package/skills/seo-supervisor/scripts/guard.mjs +74 -0
  141. package/skills/seo-supervisor/scripts/images.mjs +408 -0
  142. package/skills/seo-supervisor/scripts/indexnow.mjs +300 -0
  143. package/skills/seo-supervisor/scripts/issues.mjs +217 -0
  144. package/skills/seo-supervisor/scripts/keys/authority.mjs +135 -0
  145. package/skills/seo-supervisor/scripts/keys/bing.mjs +239 -0
  146. package/skills/seo-supervisor/scripts/keys/clarity.mjs +137 -0
  147. package/skills/seo-supervisor/scripts/keys/dataforseo.mjs +57 -0
  148. package/skills/seo-supervisor/scripts/keys/googleplaces.mjs +26 -0
  149. package/skills/seo-supervisor/scripts/keys/http.mjs +212 -0
  150. package/skills/seo-supervisor/scripts/keys/matomo.mjs +138 -0
  151. package/skills/seo-supervisor/scripts/keys/openai.mjs +26 -0
  152. package/skills/seo-supervisor/scripts/keys/perplexity.mjs +26 -0
  153. package/skills/seo-supervisor/scripts/keys/posthog.mjs +165 -0
  154. package/skills/seo-supervisor/scripts/keys/semrush.mjs +25 -0
  155. package/skills/seo-supervisor/scripts/keys/services.mjs +41 -0
  156. package/skills/seo-supervisor/scripts/keys/store.mjs +140 -0
  157. package/skills/seo-supervisor/scripts/keys/visits.mjs +58 -0
  158. package/skills/seo-supervisor/scripts/keys/youtube.mjs +84 -0
  159. package/skills/seo-supervisor/scripts/keyword-data.mjs +316 -0
  160. package/skills/seo-supervisor/scripts/keyword-ideas.mjs +503 -0
  161. package/skills/seo-supervisor/scripts/lib/args.mjs +56 -0
  162. package/skills/seo-supervisor/scripts/lib/business.mjs +27 -0
  163. package/skills/seo-supervisor/scripts/lib/cdp.mjs +242 -0
  164. package/skills/seo-supervisor/scripts/lib/cli.mjs +56 -0
  165. package/skills/seo-supervisor/scripts/lib/csv.mjs +38 -0
  166. package/skills/seo-supervisor/scripts/lib/findings.mjs +100 -0
  167. package/skills/seo-supervisor/scripts/lib/google-client.mjs +9 -0
  168. package/skills/seo-supervisor/scripts/lib/html.mjs +146 -0
  169. package/skills/seo-supervisor/scripts/lib/http.mjs +28 -0
  170. package/skills/seo-supervisor/scripts/lib/image-size.mjs +78 -0
  171. package/skills/seo-supervisor/scripts/lib/is-main.mjs +13 -0
  172. package/skills/seo-supervisor/scripts/lib/net.mjs +116 -0
  173. package/skills/seo-supervisor/scripts/lib/proxy.mjs +47 -0
  174. package/skills/seo-supervisor/scripts/lib/recheck.mjs +106 -0
  175. package/skills/seo-supervisor/scripts/lib/redact.mjs +78 -0
  176. package/skills/seo-supervisor/scripts/lib/robots.mjs +73 -0
  177. package/skills/seo-supervisor/scripts/lib/score.mjs +266 -0
  178. package/skills/seo-supervisor/scripts/lib/settings-dir.mjs +81 -0
  179. package/skills/seo-supervisor/scripts/links-import.mjs +603 -0
  180. package/skills/seo-supervisor/scripts/log-scan.mjs +597 -0
  181. package/skills/seo-supervisor/scripts/og-card.mjs +273 -0
  182. package/skills/seo-supervisor/scripts/osm.mjs +359 -0
  183. package/skills/seo-supervisor/scripts/rdap.mjs +164 -0
  184. package/skills/seo-supervisor/scripts/render-report.mjs +340 -0
  185. package/skills/seo-supervisor/scripts/report/client.js +37 -0
  186. package/skills/seo-supervisor/scripts/report/diff.mjs +264 -0
  187. package/skills/seo-supervisor/scripts/report/findings.mjs +165 -0
  188. package/skills/seo-supervisor/scripts/report/format.mjs +111 -0
  189. package/skills/seo-supervisor/scripts/report/markdown.mjs +250 -0
  190. package/skills/seo-supervisor/scripts/report/model.mjs +171 -0
  191. package/skills/seo-supervisor/scripts/report/overview-lines.mjs +158 -0
  192. package/skills/seo-supervisor/scripts/report/overview.mjs +224 -0
  193. package/skills/seo-supervisor/scripts/report/page.mjs +127 -0
  194. package/skills/seo-supervisor/scripts/report/panel.mjs +172 -0
  195. package/skills/seo-supervisor/scripts/report/panels/ai.mjs +211 -0
  196. package/skills/seo-supervisor/scripts/report/panels/connections.mjs +139 -0
  197. package/skills/seo-supervisor/scripts/report/panels/content.mjs +204 -0
  198. package/skills/seo-supervisor/scripts/report/panels/data-search.mjs +379 -0
  199. package/skills/seo-supervisor/scripts/report/panels/data-site.mjs +44 -0
  200. package/skills/seo-supervisor/scripts/report/panels/links.mjs +380 -0
  201. package/skills/seo-supervisor/scripts/report/panels/local.mjs +221 -0
  202. package/skills/seo-supervisor/scripts/report/panels/site.mjs +359 -0
  203. package/skills/seo-supervisor/scripts/report/panels/speed-media.mjs +267 -0
  204. package/skills/seo-supervisor/scripts/report/sources.mjs +163 -0
  205. package/skills/seo-supervisor/scripts/report/styles.css +223 -0
  206. package/skills/seo-supervisor/scripts/report/traffic.mjs +264 -0
  207. package/skills/seo-supervisor/scripts/report-plan.mjs +241 -0
  208. package/skills/seo-supervisor/scripts/schema-check.mjs +717 -0
  209. package/skills/seo-supervisor/scripts/seo-crawl.mjs +1151 -0
  210. package/skills/seo-supervisor/scripts/seo-diff.mjs +584 -0
  211. package/skills/seo-supervisor/scripts/update-check.mjs +82 -0
  212. package/skills/seo-supervisor/site-types/content.md +55 -0
  213. package/skills/seo-supervisor/site-types/ecommerce.md +64 -0
  214. package/skills/seo-supervisor/site-types/local-business.md +118 -0
  215. package/skills/seo-supervisor/site-types/services.md +68 -0
  216. package/skills/seo-supervisor/site-types/tools.md +127 -0
  217. package/skills/seo-supervisor/strategy.md +232 -0
  218. package/skills/seo-supervisor/troubleshooting.md +56 -0
package/bin/agents.mjs ADDED
@@ -0,0 +1,230 @@
1
+ // @ts-check
2
+ // Where each coding agent reads skills from, and how to tell it's installed. Skill paths follow the open skills CLI.
3
+ // https://github.com/vercel-labs/skills
4
+ import { existsSync } from "node:fs";
5
+ import { join } from "node:path";
6
+
7
+ const config = c => c.env.XDG_CONFIG_HOME || join(c.home, ".config");
8
+ const claudeHome = c => c.env.CLAUDE_CONFIG_DIR || join(c.home, ".claude");
9
+ const codexHome = c => c.env.CODEX_HOME || join(c.home, ".codex");
10
+ const grokHome = c => c.env.GROK_HOME || join(c.home, ".grok");
11
+ // COPILOT_HOME moves ~/.copilot.
12
+ // https://docs.github.com/en/copilot/reference/copilot-cli-reference/cli-hooks-reference
13
+ const copilotHome = c => c.env.COPILOT_HOME || join(c.home, ".copilot");
14
+ // https://docs.devin.ai/cli/extensibility/skills
15
+ const devinHome = c => (c.env.APPDATA ? join(c.env.APPDATA, "devin") : join(config(c), "devin"));
16
+ const shared = c => join(c.home, ".agents", "skills"); // read by Codex, Cline, Goose, Zed, Warp and others
17
+
18
+ // An agent that keeps everything in ~/<dir>, with skills in <dir>/skills.
19
+ const plain = (key, name, dir, more = {}) => ({
20
+ key,
21
+ name,
22
+ detect: c => [join(c.home, dir)],
23
+ user: c => join(c.home, dir, "skills"),
24
+ project: `${dir}/skills`,
25
+ ...more,
26
+ });
27
+
28
+ // Extras besides the skill: commands from commands/*.md ("md" as is, "roo" without $ARGUMENTS, "toml" for Gemini CLI),
29
+ // subagents from agents/*.md, and hooks that run scripts/guard.mjs, each in the agent's own format.
30
+ /** @typedef {{ user: string | ((c: any) => string), project: string, format: string }} Place */
31
+ /** @type {{ key: string, name: string, aliases?: string[], detect: (c: any) => string[], user: string | ((c: any) => string), project: string, commands?: Place, subagents?: Place, hooks?: Place }[]} */
32
+ export const AGENTS = [
33
+ {
34
+ key: "claude-code",
35
+ name: "Claude Code",
36
+ detect: c => [claudeHome(c)],
37
+ user: c => join(claudeHome(c), "skills"),
38
+ project: ".claude/skills",
39
+ commands: { user: c => join(claudeHome(c), "commands"), project: ".claude/commands", format: "md" },
40
+ },
41
+ // Codex reads a project's .codex/hooks.json only once the project is trusted.
42
+ // https://learn.chatgpt.com/docs/hooks
43
+ {
44
+ key: "codex",
45
+ name: "Codex",
46
+ detect: c => [codexHome(c)],
47
+ user: shared,
48
+ project: ".agents/skills",
49
+ hooks: { user: c => join(codexHome(c), "hooks.json"), project: ".codex/hooks.json", format: "codex" },
50
+ },
51
+ // https://cursor.com/docs/hooks
52
+ // https://cursor.com/docs/subagents
53
+ {
54
+ key: "cursor",
55
+ name: "Cursor",
56
+ detect: c => [join(c.home, ".cursor")],
57
+ user: c => join(c.home, ".cursor", "skills"),
58
+ project: ".agents/skills",
59
+ hooks: { user: c => join(c.home, ".cursor", "hooks.json"), project: ".cursor/hooks.json", format: "cursor" },
60
+ subagents: { user: c => join(c.home, ".cursor", "agents"), project: ".cursor/agents", format: "cursor" },
61
+ },
62
+ // Devin replaced Windsurf, whose docs redirect to docs.devin.ai. Project hooks own the whole .devin/hooks.v1.json;
63
+ // user hooks sit under the "hooks" key of config.json.
64
+ {
65
+ key: "devin",
66
+ aliases: ["windsurf"],
67
+ name: "Devin (formerly Windsurf)",
68
+ detect: c => [devinHome(c), join(c.home, ".codeium", "windsurf")],
69
+ user: c => join(devinHome(c), "skills"),
70
+ project: ".devin/skills",
71
+ hooks: { user: c => join(devinHome(c), "config.json"), project: ".devin/hooks.v1.json", format: "devin" },
72
+ },
73
+ // https://geminicli.com/docs/cli/custom-commands
74
+ {
75
+ key: "gemini-cli",
76
+ name: "Gemini CLI",
77
+ detect: c => [join(c.home, ".gemini")],
78
+ user: c => join(c.home, ".gemini", "skills"),
79
+ project: ".agents/skills",
80
+ commands: { user: c => join(c.home, ".gemini", "commands"), project: ".gemini/commands", format: "toml" },
81
+ },
82
+ // The app and the CLI both read ~/.gemini/config/skills.
83
+ // https://antigravity.google/docs/customization-discovery
84
+ {
85
+ key: "antigravity",
86
+ name: "Antigravity",
87
+ detect: c => ["config", "antigravity", "antigravity-cli"].map(d => join(c.home, ".gemini", d)),
88
+ user: c => join(c.home, ".gemini", "config", "skills"),
89
+ project: ".agents/skills",
90
+ },
91
+ // Copilot CLI loads every *.json in its hooks folders, and custom agents as *.agent.md.
92
+ // https://docs.github.com/en/copilot/reference/copilot-cli-reference/cli-hooks-reference
93
+ {
94
+ key: "github-copilot",
95
+ name: "GitHub Copilot",
96
+ detect: c => [copilotHome(c)],
97
+ user: c => join(copilotHome(c), "skills"),
98
+ project: ".agents/skills",
99
+ hooks: {
100
+ user: c => join(copilotHome(c), "hooks", "seo-supervisor-guard.json"),
101
+ project: ".github/hooks/seo-supervisor-guard.json",
102
+ format: "copilot",
103
+ },
104
+ subagents: { user: c => join(copilotHome(c), "agents"), project: ".github/agents", format: "copilot" },
105
+ },
106
+ // https://opencode.ai/docs/commands
107
+ // https://opencode.ai/docs/agents
108
+ {
109
+ key: "opencode",
110
+ name: "OpenCode",
111
+ detect: c => [join(config(c), "opencode")],
112
+ user: c => join(config(c), "opencode", "skills"),
113
+ project: ".agents/skills",
114
+ commands: { user: c => join(config(c), "opencode", "commands"), project: ".opencode/commands", format: "md" },
115
+ subagents: { user: c => join(config(c), "opencode", "agents"), project: ".opencode/agents", format: "opencode" },
116
+ },
117
+ {
118
+ key: "grok",
119
+ name: "Grok Build",
120
+ detect: c => [grokHome(c)],
121
+ user: c => join(grokHome(c), "skills"),
122
+ project: ".grok/skills",
123
+ },
124
+ // https://docs.cline.bot/customization/plugins
125
+ {
126
+ key: "cline",
127
+ name: "Cline",
128
+ detect: c => [join(c.home, ".cline")],
129
+ user: shared,
130
+ project: ".agents/skills",
131
+ hooks: {
132
+ user: c => join(c.home, ".cline", "plugins", "seo-supervisor-guard.js"),
133
+ project: ".cline/plugins/seo-supervisor-guard.js",
134
+ format: "cline",
135
+ },
136
+ },
137
+ // The IDE and the CLI both read these folders.
138
+ // https://kiro.dev/docs/skills
139
+ plain("kiro-cli", "Kiro", ".kiro", { aliases: ["kiro"] }),
140
+ // Roo commands have no argument placeholder.
141
+ // https://roocodeinc.github.io/Roo-Code/features/slash-commands
142
+ plain("roo", "Roo Code", ".roo", {
143
+ commands: { user: c => join(c.home, ".roo", "commands"), project: ".roo/commands", format: "roo" },
144
+ }),
145
+ // Continue's docs don't describe SKILL.md skills. The row keeps --agent continue working, labelled as unconfirmed.
146
+ // https://docs.continue.dev
147
+ plain("continue", "Continue (unconfirmed folder)", ".continue"),
148
+ {
149
+ key: "amp",
150
+ name: "Amp",
151
+ detect: c => [join(config(c), "amp")],
152
+ user: c => join(config(c), "agents", "skills"),
153
+ project: ".agents/skills",
154
+ },
155
+ // https://goose-docs.ai/docs/guides/context-engineering/using-skills
156
+ { key: "goose", name: "Goose", detect: c => [join(config(c), "goose")], user: shared, project: ".agents/skills" },
157
+ plain("junie", "Junie", ".junie"),
158
+ plain("qwen-code", "Qwen Code", ".qwen"),
159
+ plain("trae", "Trae", ".trae"),
160
+ // https://docs.augmentcode.com/cli/skills
161
+ // https://docs.augmentcode.com/cli/custom-commands
162
+ plain("augment", "Augment", ".augment", {
163
+ commands: { user: c => join(c.home, ".augment", "commands"), project: ".augment/commands", format: "md" },
164
+ }),
165
+ {
166
+ key: "zed",
167
+ name: "Zed",
168
+ detect: c => [join(config(c), "zed"), ...(c.env.APPDATA ? [join(c.env.APPDATA, "Zed")] : [])],
169
+ user: shared,
170
+ project: ".agents/skills",
171
+ },
172
+ { key: "warp", name: "Warp", detect: c => [join(c.home, ".warp")], user: shared, project: ".agents/skills" },
173
+ {
174
+ key: "other",
175
+ name: "Other agents (shared .agents folder)",
176
+ detect: () => [],
177
+ user: shared,
178
+ project: ".agents/skills",
179
+ },
180
+ ];
181
+
182
+ /** Looks an agent up by key or alias (windsurf finds devin). */
183
+ export const agentByKey = key => AGENTS.find(a => a.key === key || a.aliases?.includes(key));
184
+
185
+ /** Keys of the agents whose home folder exists, in table order. */
186
+ export function detectAgents(c, exists = existsSync) {
187
+ return AGENTS.filter(a => a.detect(c).some(p => exists(p))).map(a => a.key);
188
+ }
189
+
190
+ const resolve = (where, c) => (typeof where === "function" ? where(c) : join(c.cwd, ...where.split("/")));
191
+
192
+ /** One install target per skills folder, so agents that share a folder get one copy. Each extra is
193
+ * { key, kind: "commands" | "subagents" | "hooks", path, format }. */
194
+ export function targetsFor(keys, scope, c) {
195
+ const byDir = new Map();
196
+ for (const key of keys) {
197
+ const a = agentByKey(key);
198
+ const skills = resolve(scope === "project" ? a.project : a.user, c);
199
+ const t = byDir.get(skills) || byDir.set(skills, { skills, agents: [], extras: [] }).get(skills);
200
+ if (t.agents.includes(a.name)) continue;
201
+ t.agents.push(a.name);
202
+ for (const kind of ["commands", "subagents", "hooks"])
203
+ if (a[kind])
204
+ t.extras.push({
205
+ key: a.key,
206
+ kind,
207
+ path: resolve(scope === "project" ? a[kind].project : a[kind].user, c),
208
+ format: a[kind].format,
209
+ });
210
+ }
211
+ return [...byDir.values()];
212
+ }
213
+
214
+ // Windsurf's and Goose's own skills folders, used by v1.x. Uninstall still removes the skill from them.
215
+ const LEGACY = [
216
+ { user: c => join(c.home, ".codeium", "windsurf", "skills"), project: ".windsurf/skills" },
217
+ { user: c => join(config(c), "goose", "skills"), project: ".goose/skills" },
218
+ ];
219
+
220
+ /** Every skills folder any agent could use in this scope, plus the legacy ones, for uninstall. */
221
+ export function allTargets(scope, c) {
222
+ return [
223
+ ...targetsFor(
224
+ AGENTS.map(a => a.key),
225
+ scope,
226
+ c,
227
+ ),
228
+ ...LEGACY.map(l => ({ skills: resolve(scope === "project" ? l.project : l.user, c), agents: [], extras: [] })),
229
+ ];
230
+ }
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
+ }