@seoagent-official/seoagent 1.22.1 → 1.23.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.
package/index.js CHANGED
@@ -1,31 +1,31 @@
1
1
  #!/usr/bin/env node
2
- import{Command as Mr}from"commander";import{intro as lo,outro as uo,text as Et,select as _e,spinner as po,isCancel as j,cancel as N,confirm as fo}from"@clack/prompts";import{existsSync as Ve,mkdirSync as Je,readFileSync as hn,writeFileSync as Xe}from"fs";import{join as ge}from"path";var C=[".env.local",".env.production",".env"],Ke=["NEXT_PUBLIC_SITE_URL","SITE_URL","NEXT_PUBLIC_URL","NEXTAUTH_URL","VITE_SITE_URL"];import{homedir as un}from"os";import{join as z}from"path";var m=".seoagent",He=["audit","strategy/clusters","briefs","content","content/images","performance"],T={AGENTS:".agents/skills/seoagent",CLAUDE:".claude/skills/seoagent"},Y=".claude/settings.json",ze=".pull-receipt.json",Ye=`# SEOAgent local files
2
+ import{Command as Kr}from"commander";import{intro as uo,outro as po,text as It,select as _e,spinner as fo,isCancel as j,cancel as N,confirm as mo}from"@clack/prompts";import{existsSync as Je,mkdirSync as Xe,readFileSync as yn,writeFileSync as qe}from"fs";import{join as ge}from"path";var C=[".env.local",".env.production",".env"],He=["NEXT_PUBLIC_SITE_URL","SITE_URL","NEXT_PUBLIC_URL","NEXTAUTH_URL","VITE_SITE_URL"];import{homedir as pn}from"os";import{join as z}from"path";var g=".seoagent",ze=["audit","strategy/clusters","briefs","content","content/images","performance"],$={AGENTS:".agents/skills/seoagent",CLAUDE:".claude/skills/seoagent"},Y=".claude/settings.json",Ye=".pull-receipt.json",Ve=`# SEOAgent local files
3
3
  .legacy/
4
4
  content/images/*
5
5
  !content/images/.gitkeep
6
6
  .pull-receipt.json
7
- `,pn=process.env.XDG_CONFIG_HOME&&process.env.XDG_CONFIG_HOME.trim().length>0?process.env.XDG_CONFIG_HOME:z(un(),".config"),S=z(pn,"seoagent"),v=z(S,"auth.json"),de=z(S,"state");var D="https://seoagent.com",R=process.env.SEOAGENT_API_BASE&&process.env.SEOAGENT_API_BASE.trim().length>0?process.env.SEOAGENT_API_BASE.replace(/\/$/,""):D,k={BASE:R,PRICING:`${R}/pricing`,LEAD_API:`${R}/api/cli/lead`,CLI_AUTH_PAGE:`${R}/cli/auth`,CLI_AUTH_POLL:`${R}/api/cli/auth/poll`,CLI_SYNC:`${R}/api/cli/sync`};var V="0.2.0";import{existsSync as dn,readFileSync as fn}from"fs";var J="---";function mn(e){let t=e.trim();return t===""?"":t==="null"||t==="~"?null:t==="true"?!0:t==="false"?!1:t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1):/^-?\d+$/.test(t)||/^-?\d+\.\d+$/.test(t)?Number(t):t}function fe(e){let t=e.split(/\r?\n/);if(t[0]?.trim()!==J)return{data:{},body:e};let n={},o=1;for(;o<t.length;o++){if(t[o].trim()===J){o++;break}let r=t[o],i=r.indexOf(":");if(i===-1)continue;let s=r.slice(0,i).trim(),a=r.slice(i+1);s&&(n[s]=mn(a))}return{data:n,body:t.slice(o).join(`
8
- `)}}function X(e){if(!dn(e))return null;try{return fe(fn(e,"utf-8"))}catch{return null}}function gn(e){if(e===null)return"null";if(typeof e=="boolean")return e?"true":"false";if(typeof e=="number")return String(e);let t=String(e);return t===""||/[:#\[\]{}&*!|>'"%@`,]/.test(t)||/^\s|\s$/.test(t)?`"${t.replace(/"/g,'\\"')}"`:t}function me(e,t=""){let n=[J];for(let[r,i]of Object.entries(e))i!==void 0&&n.push(`${r}: ${gn(i)}`);n.push(J);let o=t.length===0?"":t.startsWith(`
7
+ `,dn=process.env.XDG_CONFIG_HOME&&process.env.XDG_CONFIG_HOME.trim().length>0?process.env.XDG_CONFIG_HOME:z(pn(),".config"),k=z(dn,"seoagent"),w=z(k,"auth.json"),de=z(k,"state");var D="https://seoagent.com",R=process.env.SEOAGENT_API_BASE&&process.env.SEOAGENT_API_BASE.trim().length>0?process.env.SEOAGENT_API_BASE.replace(/\/$/,""):D,S={BASE:R,PRICING:`${R}/pricing`,LEAD_API:`${R}/api/cli/lead`,CLI_AUTH_PAGE:`${R}/cli/auth`,CLI_AUTH_POLL:`${R}/api/cli/auth/poll`,CLI_SYNC:`${R}/api/cli/sync`};var V="0.2.0";import{existsSync as fn,readFileSync as mn}from"fs";var J="---";function gn(e){let t=e.trim();return t===""?"":t==="null"||t==="~"?null:t==="true"?!0:t==="false"?!1:t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1):/^-?\d+$/.test(t)||/^-?\d+\.\d+$/.test(t)?Number(t):t}function fe(e){let t=e.split(/\r?\n/);if(t[0]?.trim()!==J)return{data:{},body:e};let n={},o=1;for(;o<t.length;o++){if(t[o].trim()===J){o++;break}let r=t[o],i=r.indexOf(":");if(i===-1)continue;let s=r.slice(0,i).trim(),a=r.slice(i+1);s&&(n[s]=gn(a))}return{data:n,body:t.slice(o).join(`
8
+ `)}}function X(e){if(!fn(e))return null;try{return fe(mn(e,"utf-8"))}catch{return null}}function hn(e){if(e===null)return"null";if(typeof e=="boolean")return e?"true":"false";if(typeof e=="number")return String(e);let t=String(e);return t===""||/[:#\[\]{}&*!|>'"%@`,]/.test(t)||/^\s|\s$/.test(t)?`"${t.replace(/"/g,'\\"')}"`:t}function me(e,t=""){let n=[J];for(let[r,i]of Object.entries(e))i!==void 0&&n.push(`${r}: ${hn(i)}`);n.push(J);let o=t.length===0?"":t.startsWith(`
9
9
  `)?t:`
10
10
  ${t}`;return n.join(`
11
11
  `)+o+(o.endsWith(`
12
12
  `)?"":`
13
- `)}var yn=new Set(["strapi","wordpress","sanity","contentful","ghost","webflow","shopify","payload","directus","mdx-local","none"]),Sn="project.md";function M(e){return ge(e,m)}function q(e){return ge(M(e),Sn)}function qe(e){return Ve(q(e))}function g(e){let t=X(q(e));if(!t)return null;let n=t.data;if(typeof n.domain!="string"||!n.domain)return null;let o=typeof n.image_provider=="string"?n.image_provider:void 0,r=typeof n.cms=="string"?n.cms:void 0,i=r&&yn.has(r)?r:void 0;return{domain:n.domain,site_type:typeof n.site_type=="string"?n.site_type:"unknown",language:typeof n.language=="string"?n.language:"en",initialized_at:typeof n.initialized_at=="string"?n.initialized_at:"",seoagent_version:typeof n.seoagent_version=="string"?n.seoagent_version:"",image_provider:o==="openai"||o==="fal"||o==="replicate"||o==="none"?o:void 0,cms:i,blog_path:typeof n.blog_path=="string"&&n.blog_path?n.blog_path:void 0}}function kn(e){return["",`# SEOAgent Project \u2014 ${e.domain}`,"","This file holds project-level configuration for the SEOAgent skill.","The skill reads it on every session to know which domain it is working on.","",`Initialized ${e.initialized_at} with seoagent ${e.seoagent_version}.`,""].join(`
14
- `)}function xn(e){let t={domain:e.domain,site_type:e.site_type,language:e.language,initialized_at:e.initialized_at,seoagent_version:e.seoagent_version};return e.image_provider&&(t.image_provider=e.image_provider),e.cms&&(t.cms=e.cms),e.blog_path&&(t.blog_path=e.blog_path),t}function Ze(e,t){let n=M(e);Je(n,{recursive:!0});let o=me(xn(t),kn(t));Xe(q(e),o,"utf-8")}function Qe(e,t){let n=q(e);if(!Ve(n))return!1;let o=fe(hn(n,"utf-8")),r={...o.data,...t};return Xe(n,me(r,o.body),"utf-8"),!0}function et(e){let t=M(e);for(let n of He)Je(ge(t,n),{recursive:!0})}import{existsSync as Z,mkdirSync as Q,writeFileSync as tt,readFileSync as nt,readdirSync as bn,statSync as vn}from"fs";import{join as x,dirname as ot,relative as wn}from"path";import{fileURLToPath as _n}from"url";var En=ot(_n(import.meta.url));function rt(){return x(En,"skills")}function Pn(){let e=x(rt(),"seoagent.md");if(Z(e))return nt(e,"utf-8");throw new Error(`Could not find skill file at: ${e}`)}function it(e,t){let n=[];if(!Z(e))return n;for(let o of bn(e,{withFileTypes:!0})){let r=x(e,o.name),i=x(t,o.name);o.isDirectory()?(Q(i,{recursive:!0}),n.push(...it(r,i))):o.isFile()&&(Q(ot(i),{recursive:!0}),tt(i,nt(r)),n.push(i))}return n}function st(e,t){return In(e,t).skillFile}function In(e,t){let n=Z(x(e,".agents")),o=x(e,n?T.AGENTS:T.CLAUDE),r=x(o,"SKILL.md");Q(o,{recursive:!0}),tt(r,t??Pn(),"utf-8");let i=x(rt(),"references"),s=x(o,"references"),a=[];try{Z(i)&&vn(i).isDirectory()&&(Q(s,{recursive:!0}),a=it(i,s).map(c=>wn(o,c)))}catch{}return{skillFile:r,referenceFiles:a}}import{existsSync as ee,mkdirSync as he,readFileSync as An,writeFileSync as B}from"fs";import{dirname as at,join as $}from"path";var Cn="npx -y @seoagent-official/seoagent sync --silent";function ct(e){let t=$(e,m);he(t,{recursive:!0});let n=$(t,".gitignore");B(n,Ye,"utf-8");let o=$(t,"content","images",".gitkeep");return he(at(o),{recursive:!0}),ee(o)||B(o,"","utf-8"),n}function ye(e){if(!ee(e))return{};try{let t=An(e,"utf-8");return JSON.parse(t)}catch{return{}}}function Se(e){return e.command.includes("@seoagent-official/seoagent")&&e.command.includes("sync")}function lt(e){let t=$(e,Y);he(at(t),{recursive:!0});let n=ye(t);n.hooks=n.hooks??{};let o=n.hooks.PostToolUse=n.hooks.PostToolUse??[],r=o.find(i=>(i.matcher??"").includes("Write"));return r||(r={matcher:"Write|Edit",hooks:[]},o.push(r)),r.hooks.some(Se)?(B(t,JSON.stringify(n,null,2)+`
15
- `,"utf-8"),{file:t,added:!1}):(r.hooks.push({type:"command",command:Cn}),B(t,JSON.stringify(n,null,2)+`
16
- `,"utf-8"),{file:t,added:!0})}function ut(e){let t=$(e,Y);if(!ee(t))return!1;let n=ye(t).hooks?.PostToolUse;return Array.isArray(n)?n.some(o=>o.hooks?.some(Se)):!1}function pt(e){let t=$(e,Y);if(!ee(t))return{file:t,removed:!1};let n=ye(t),o=n.hooks?.PostToolUse;if(!Array.isArray(o))return{file:t,removed:!1};let r=!1;for(let i of o){let s=i.hooks.length;i.hooks=i.hooks.filter(a=>!Se(a)),i.hooks.length!==s&&(r=!0)}return r?(n.hooks.PostToolUse=o.filter(i=>i.hooks.length>0),n.hooks.PostToolUse.length===0&&delete n.hooks.PostToolUse,n.hooks&&Object.keys(n.hooks).length===0&&delete n.hooks,B(t,JSON.stringify(n,null,2)+`
17
- `,"utf-8"),{file:t,removed:!0}):{file:t,removed:!1}}import{readFileSync as ki,writeFileSync as Tn,existsSync as xi}from"fs";import{join as Rn}from"path";function dt(e){let t=[];t.push("# Business Context"),t.push("");let n=[["Name","name"],["Type","type"],["Audience","audience"],["Industry","industry"],["Location","location"],["Description","description"]];for(let[r,i]of n){let s=e.business[i];t.push(`- **${r}:** ${s||""}`)}let o=new Set(n.map(([,r])=>r));for(let[r,i]of Object.entries(e.business))if(!o.has(r)&&i){let s=r.charAt(0).toUpperCase()+r.slice(1);t.push(`- **${s}:** ${i}`)}if(t.push(""),t.push("# Writing Instructions"),t.push(""),e.writingInstructions.length>0)for(let r of e.writingInstructions)t.push(`- ${r}`);else t.push("- (Add your content writing guidelines here)");if(t.push(""),t.push("# Reference URLs"),t.push(""),e.referenceUrls.length>0)for(let r of e.referenceUrls)r.description?t.push(`- ${r.url} \u2014 ${r.description}`):t.push(`- ${r.url}`);else t.push("- (Add URLs the agent should reference for tone/style)");if(t.push(""),t.push("# Topics to Avoid"),t.push(""),e.topicsToAvoid.length>0)for(let r of e.topicsToAvoid)t.push(`- ${r}`);else t.push("- (Add topics the agent should never write about)");return t.push(""),t.push("# Content Tone"),t.push(""),t.push(e.contentTone||"professional"),t.push(""),t.push("# Additional Notes"),t.push(""),t.push(e.additionalNotes||"(Any other context you want the agent to know about your business, products, or audience.)"),t.push(""),t.join(`
18
- `)}var $n="context.md";function On(e,t){let n=Rn(e,".seoagent",$n),o=dt(t);Tn(n,o,"utf-8")}function ft(e,t){On(e,{business:{type:t||""},writingInstructions:[],referenceUrls:[],topicsToAvoid:[],contentTone:null,additionalNotes:null})}import{existsSync as G,readFileSync as mt,readdirSync as jn,statSync as gt}from"fs";import{join as _}from"path";var Nn=[{cms:"strapi",deps:["strapi","@strapi/strapi","@strapi/"],envKeys:["STRAPI_URL","STRAPI_API_URL","NEXT_PUBLIC_STRAPI_URL","STRAPI_API_TOKEN"],fsMarkers:["strapi/","apps/strapi/","packages/strapi/","cms/"]},{cms:"wordpress",deps:["wpapi","wp-graphql","@wordpress/api-fetch","@wordpress/"],envKeys:["WORDPRESS_API_URL","WP_API_URL","NEXT_PUBLIC_WORDPRESS_URL"],fsMarkers:[]},{cms:"sanity",deps:["@sanity/client","next-sanity","sanity"],envKeys:["SANITY_PROJECT_ID","NEXT_PUBLIC_SANITY_PROJECT_ID","SANITY_API_TOKEN"],fsMarkers:["sanity/","studio/","sanity.config.ts","sanity.config.js"]},{cms:"contentful",deps:["contentful","@contentful/rich-text-react-renderer","@contentful/"],envKeys:["CONTENTFUL_SPACE_ID","CONTENTFUL_ACCESS_TOKEN","NEXT_PUBLIC_CONTENTFUL_SPACE_ID"],fsMarkers:[]},{cms:"ghost",deps:["@tryghost/content-api","@tryghost/"],envKeys:["GHOST_URL","GHOST_API_KEY","NEXT_PUBLIC_GHOST_URL"],fsMarkers:[]},{cms:"webflow",deps:["webflow-api"],envKeys:["WEBFLOW_API_TOKEN","WEBFLOW_SITE_ID"],fsMarkers:[]},{cms:"shopify",deps:["@shopify/hydrogen","@shopify/storefront-api-client","@shopify/shopify-api","@shopify/"],envKeys:["SHOPIFY_STOREFRONT_TOKEN","SHOPIFY_STORE_DOMAIN","SHOPIFY_ADMIN_API_TOKEN"],fsMarkers:["shopify.config.ts","shopify.config.js"]},{cms:"payload",deps:["payload","@payloadcms/next","@payloadcms/"],envKeys:["PAYLOAD_SECRET","PAYLOAD_PUBLIC_SERVER_URL"],fsMarkers:["payload.config.ts","payload.config.js"]},{cms:"directus",deps:["@directus/sdk","directus"],envKeys:["DIRECTUS_URL","DIRECTUS_TOKEN"],fsMarkers:[]}];function Ln(e){let t=_(e,"package.json");if(!G(t))return{deps:{},source:"package.json"};try{let n=JSON.parse(mt(t,"utf-8"));return{deps:{...n.dependencies,...n.devDependencies,...n.peerDependencies},source:"package.json"}}catch{return{deps:{},source:"package.json"}}}function Fn(e,t){for(let n of t)if(n.endsWith("/")){if(e.startsWith(n))return!0}else if(e===n)return!0;return!1}function Un(e){let t={};for(let n of C){let o=_(e,n);if(G(o))try{let r=mt(o,"utf-8");for(let i of r.split(/\r?\n/)){let s=i.trim();if(!s||s.startsWith("#"))continue;let a=s.indexOf("=");if(a===-1)continue;let c=s.slice(0,a).trim();c&&!(c in t)&&(t[c]=n)}}catch{}}return t}function Dn(e,t){let n=_(e,t.replace(/\/$/,""));if(!G(n))return!1;if(t.endsWith("/"))try{return gt(n).isDirectory()}catch{return!1}return!0}function Mn(e){let t=["content","_posts","posts",_("src","content")];for(let n of t){let o=_(e,n);if(G(o))try{if(!gt(o).isDirectory())continue;let r=[o],i=0;for(;r.length>0&&i<50;){let s=r.pop();for(let a of jn(s,{withFileTypes:!0}))if(i++,!a.name.startsWith(".")){if(a.isDirectory()&&r.length<5){r.push(_(s,a.name));continue}if(a.isFile()&&/\.(md|mdx)$/i.test(a.name))return{type:"directory",detail:n,source:`${n}/${a.name}`}}}}catch{}}return null}function Bn(e){let t=[{marker:"app/blog/page.tsx",path:"/blog"},{marker:"app/blog/page.jsx",path:"/blog"},{marker:"app/blog/page.js",path:"/blog"},{marker:"src/app/blog/page.tsx",path:"/blog"},{marker:"src/app/blog/page.jsx",path:"/blog"},{marker:"pages/blog/index.tsx",path:"/blog"},{marker:"pages/blog/index.jsx",path:"/blog"},{marker:"pages/blog/index.js",path:"/blog"},{marker:"src/pages/blog/index.tsx",path:"/blog"},{marker:"app/(blog)/page.tsx",path:"/blog"},{marker:"app/articles/page.tsx",path:"/articles"},{marker:"pages/articles/index.tsx",path:"/articles"},{marker:"app/posts/page.tsx",path:"/posts"},{marker:"pages/posts/index.tsx",path:"/posts"},{marker:"app/learn/page.tsx",path:"/learn"},{marker:"app/resources/page.tsx",path:"/resources"}];for(let n of t)if(G(_(e,n.marker)))return n.path;return null}function ht(e){let t=[],{deps:n}=Ln(e),o=Un(e),r="none";for(let s of Nn){let a=[];for(let c of Object.keys(n))if(Fn(c,s.deps)){a.push({type:"dep",detail:c,source:"package.json"});break}for(let c of s.envKeys)if(o[c]){a.push({type:"env",detail:c,source:o[c]});break}for(let c of s.fsMarkers)if(Dn(e,c)){let u=c.endsWith("/")?"directory":"file";a.push({type:u,detail:c,source:c});break}if(a.length>0){r=s.cms,t.push(...a);break}}if(r==="none"){let s=Mn(e);s&&(r="mdx-local",t.push(s))}let i=Bn(e);return{cms:r,blog_path:i,evidence:t}}import{existsSync as E,readFileSync as ke}from"fs";import{join as P}from"path";function yt(e){try{return new URL(e).hostname}catch{return e}}function St(e){let t=e.toLowerCase();return!!(t==="github.com"||t.endsWith(".github.com")||t==="gitlab.com"||t.endsWith(".gitlab.com")||t==="bitbucket.org"||t.endsWith(".bitbucket.org")||t==="dev.azure.com"||t==="visualstudio.com"||t.endsWith(".visualstudio.com")||t==="npmjs.com"||t.endsWith(".npmjs.com"))}function Gn(e){for(let t of C){let n=P(e,t);if(!E(n))continue;let o=ke(n,"utf-8");for(let r of Ke){let i=o.match(new RegExp(`^${r}=(.+)$`,"m"));if(i){let s=i[1].trim().replace(/^["']|["']$/g,""),a=yt(s);if(St(a))continue;return{value:a,source:`${t} (${r})`}}}}return null}function Wn(e){let t=P(e,"package.json");if(!E(t))return null;try{let n=JSON.parse(ke(t,"utf-8"));if(!n.homepage)return null;let o=yt(n.homepage);return St(o)?null:{value:o,source:"package.json (homepage)"}}catch{return null}}function kt(e,t){let n=[];t?.("Checking for monorepo / workspace layout\u2026"),E(P(e,"pnpm-workspace.yaml"))&&n.push({field:"context",detail:"Monorepo workspace detected",source:"pnpm-workspace.yaml \u2014 using this directory for project signals"});let o=null;t?.("Scanning .env files for public / site URLs\u2026");let r=Gn(e);if(r)o=r.value,n.push({field:"domain",detail:r.value,source:r.source});else{t?.("Reading package.json homepage (skipping GitHub/GitLab repo URLs)\u2026");let a=Wn(e);a&&(o=a.value,n.push({field:"domain",detail:a.value,source:a.source}))}let i=P(e,"package.json"),s=null;if(E(i))try{t?.("Reading dependencies to infer site type\u2026");let a=JSON.parse(ke(i,"utf-8")),c=Object.keys({...a.dependencies,...a.devDependencies}),u=(...p)=>p.some(d=>c.includes(d));if(u("@shopify/hydrogen","@shopify/polaris")||E(P(e,"shopify.config.js"))||E(P(e,"shopify.config.ts"))){s="product";let p=u("@shopify/hydrogen","@shopify/polaris")?"Shopify-related dependencies in package.json":E(P(e,"shopify.config.ts"))?"shopify.config.ts":"shopify.config.js";n.push({field:"site_type",detail:"product",source:p})}else{let p=u("stripe","@stripe/stripe-js","@stripe/react-stripe-js","paddle","@paddle/paddle-js"),d=u("next-auth","@auth/core","lucia","clerk","@clerk/nextjs","@clerk/clerk-react"),h=u("next");p&&(h||d)?(s="saas",n.push({field:"site_type",detail:"saas",source:h?"payment SDK + Next.js in package.json":"payment SDK + auth library in package.json"})):!p&&u("astro","gatsby","contentlayer","next-mdx-remote","mdx-bundler","vitepress","vuepress","@docusaurus/core","docusaurus","nextra")&&(s="content",n.push({field:"site_type",detail:"content",source:u("vitepress","vuepress","@docusaurus/core","docusaurus","nextra")?"documentation / site generator in package.json (VitePress, Docusaurus, Nextra, etc.)":"content-oriented dependencies in package.json (no payment SDKs detected)"}))}}catch{}return{domain:o,siteType:s,evidence:n}}import{existsSync as Kn,readFileSync as Hn,readdirSync as zn,statSync as Yn}from"fs";import{join as I,sep as Vn}from"path";var xt=["tsx","jsx","js","mdx","md"],Jn=["astro","md","mdx"],Xn=5e3;function bt(e,t){let n=new Map,o=0,r=(i,s,a=!1)=>{let c=qn(i);if(c===null){o++;return}let u=n.get(c);if(u){u.in_sitemap=u.in_sitemap||a,u.source.includes(s)||(u.source+=`, ${s}`);return}n.set(c,{route:c,url:so(t,c),in_sitemap:a,source:s})};for(let i of["app",I("src","app")]){let s=I(e,i);if(xe(s))for(let a of be(s)){let c=ve(s,a),u=c[c.length-1];no(u)&&(c.some(p=>p.startsWith("@"))||r(Zn(c.slice(0,-1)),"app router"))}}for(let i of["pages",I("src","pages")]){let s=I(e,i);if(xe(s))for(let a of be(s)){let c=ve(s,a);if(c[0]==="api")continue;let u=c[c.length-1],p=we(u),d=xt.includes(p),h=Jn.includes(p);if(!d&&!h)continue;let A=te(u);oo(A)||r(Qn(c),h?"astro":"pages router")}}for(let i of[".","public"]){let s=I(e,i);if(xe(s))for(let a of be(s,i==="."?1:1/0)){let c=ve(s,a),u=c[c.length-1];we(u)==="html"&&(c.some(p=>p==="node_modules"||p.startsWith("."))||r(eo(c),"static html"))}}for(let i of["public/sitemap.xml","sitemap.xml"]){let s=I(e,...i.split("/"));if(Kn(s)){for(let a of ro(s)){let c=to(a);c!==null&&r(c,"sitemap.xml",!0)}break}}return{pages:[...n.values()].sort((i,s)=>i.route.localeCompare(s.route)),dynamicCount:o}}function qn(e){let t=e.trim();return t===""||t==="/"||(t.startsWith("/")||(t=`/${t}`),t=t.replace(/\/+$/,""),t==="")?"/":/\[.*\]/.test(t)?null:t}function Zn(e){return"/"+e.filter(n=>!(n.startsWith("(")&&n.endsWith(")"))).join("/")}function Qn(e){let t=[...e],n=te(t[t.length-1]);return n==="index"?t.pop():t[t.length-1]=n,"/"+t.join("/")}function eo(e){let t=[...e],n=te(t[t.length-1]);return n==="index"?t.pop():t[t.length-1]=n,"/"+t.join("/")}function to(e){try{return new URL(e).pathname||"/"}catch{return e.startsWith("/")?e:null}}function no(e){return te(e)==="page"&&xt.includes(we(e))}function oo(e){return["_app","_document","_error","404","500","middleware"].includes(e)}function ro(e){try{let t=Hn(e,"utf-8"),n=[],o=/<loc>\s*([^<\s]+)\s*<\/loc>/gi,r;for(;(r=o.exec(t))!==null;)n.push(r[1].trim());return n}catch{return[]}}var io=new Set(["node_modules",".git",".next","dist","build",".vercel","out"]);function xe(e){try{return Yn(e).isDirectory()}catch{return!1}}function*be(e,t=1/0){let n=0;function*o(r,i){if(i>t)return;let s;try{s=zn(r,{withFileTypes:!0})}catch{return}for(let a of s){if(n>=Xn)return;if(a.name.startsWith("."))continue;let c=I(r,a.name);if(a.isDirectory()){if(io.has(a.name))continue;yield*o(c,i+1)}else a.isFile()&&(n++,yield c)}}yield*o(e,1)}function ve(e,t){return t.slice(e.length).replace(/^[/\\]+/,"").split(Vn).filter(Boolean)}function we(e){let t=e.lastIndexOf(".");return t===-1?"":e.slice(t+1).toLowerCase()}function te(e){let t=e.lastIndexOf(".");return t===-1?e:e.slice(0,t)}function so(e,t){return e?`https://${e.replace(/^https?:\/\//,"").replace(/\/$/,"")}${t==="/"?"/":t}`:t}import{mkdirSync as ao,writeFileSync as co}from"fs";import{join as vt}from"path";function _t(e,t){if(t.length===0)return;let n=vt(e,m);ao(n,{recursive:!0});let o=["---","generated: false",`discovered_at: ${new Date().toISOString()}`,`row_count: ${t.length}`,"---"].join(`
13
+ `)}var Sn=new Set(["strapi","wordpress","sanity","contentful","ghost","webflow","shopify","payload","directus","mdx-local","none"]),kn="project.md";function M(e){return ge(e,g)}function q(e){return ge(M(e),kn)}function Ze(e){return Je(q(e))}function f(e){let t=X(q(e));if(!t)return null;let n=t.data;if(typeof n.domain!="string"||!n.domain)return null;let o=typeof n.image_provider=="string"?n.image_provider:void 0,r=typeof n.cms=="string"?n.cms:void 0,i=r&&Sn.has(r)?r:void 0;return{domain:n.domain,site_type:typeof n.site_type=="string"?n.site_type:"unknown",language:typeof n.language=="string"?n.language:"en",initialized_at:typeof n.initialized_at=="string"?n.initialized_at:"",seoagent_version:typeof n.seoagent_version=="string"?n.seoagent_version:"",image_provider:o==="openai"||o==="fal"||o==="replicate"||o==="none"?o:void 0,cms:i,blog_path:typeof n.blog_path=="string"&&n.blog_path?n.blog_path:void 0}}function xn(e){return["",`# SEOAgent Project \u2014 ${e.domain}`,"","This file holds project-level configuration for the SEOAgent skill.","The skill reads it on every session to know which domain it is working on.","",`Initialized ${e.initialized_at} with seoagent ${e.seoagent_version}.`,""].join(`
14
+ `)}function bn(e){let t={domain:e.domain,site_type:e.site_type,language:e.language,initialized_at:e.initialized_at,seoagent_version:e.seoagent_version};return e.image_provider&&(t.image_provider=e.image_provider),e.cms&&(t.cms=e.cms),e.blog_path&&(t.blog_path=e.blog_path),t}function Qe(e,t){let n=M(e);Xe(n,{recursive:!0});let o=me(bn(t),xn(t));qe(q(e),o,"utf-8")}function et(e,t){let n=q(e);if(!Je(n))return!1;let o=fe(yn(n,"utf-8")),r={...o.data,...t};return qe(n,me(r,o.body),"utf-8"),!0}function tt(e){let t=M(e);for(let n of ze)Xe(ge(t,n),{recursive:!0})}import{existsSync as Z,mkdirSync as Q,writeFileSync as nt,readFileSync as ot,readdirSync as vn,statSync as wn}from"fs";import{join as b,dirname as rt,relative as _n}from"path";import{fileURLToPath as En}from"url";var In=rt(En(import.meta.url));function it(){return b(In,"skills")}function Pn(){let e=b(it(),"seoagent.md");if(Z(e))return ot(e,"utf-8");throw new Error(`Could not find skill file at: ${e}`)}function st(e,t){let n=[];if(!Z(e))return n;for(let o of vn(e,{withFileTypes:!0})){let r=b(e,o.name),i=b(t,o.name);o.isDirectory()?(Q(i,{recursive:!0}),n.push(...st(r,i))):o.isFile()&&(Q(rt(i),{recursive:!0}),nt(i,ot(r)),n.push(i))}return n}function at(e,t){return An(e,t).skillFile}function An(e,t){let n=Z(b(e,".agents")),o=b(e,n?$.AGENTS:$.CLAUDE),r=b(o,"SKILL.md");Q(o,{recursive:!0}),nt(r,t??Pn(),"utf-8");let i=b(it(),"references"),s=b(o,"references"),a=[];try{Z(i)&&wn(i).isDirectory()&&(Q(s,{recursive:!0}),a=st(i,s).map(l=>_n(o,l)))}catch{}return{skillFile:r,referenceFiles:a}}import{existsSync as ee,mkdirSync as he,readFileSync as Cn,writeFileSync as B}from"fs";import{dirname as ct,join as T}from"path";var $n="npx -y @seoagent-official/seoagent sync --silent";function lt(e){let t=T(e,g);he(t,{recursive:!0});let n=T(t,".gitignore");B(n,Ve,"utf-8");let o=T(t,"content","images",".gitkeep");return he(ct(o),{recursive:!0}),ee(o)||B(o,"","utf-8"),n}function ye(e){if(!ee(e))return{};try{let t=Cn(e,"utf-8");return JSON.parse(t)}catch{return{}}}function Se(e){return e.command.includes("@seoagent-official/seoagent")&&e.command.includes("sync")}function ut(e){let t=T(e,Y);he(ct(t),{recursive:!0});let n=ye(t);n.hooks=n.hooks??{};let o=n.hooks.PostToolUse=n.hooks.PostToolUse??[],r=o.find(i=>(i.matcher??"").includes("Write"));return r||(r={matcher:"Write|Edit",hooks:[]},o.push(r)),r.hooks.some(Se)?(B(t,JSON.stringify(n,null,2)+`
15
+ `,"utf-8"),{file:t,added:!1}):(r.hooks.push({type:"command",command:$n}),B(t,JSON.stringify(n,null,2)+`
16
+ `,"utf-8"),{file:t,added:!0})}function pt(e){let t=T(e,Y);if(!ee(t))return!1;let n=ye(t).hooks?.PostToolUse;return Array.isArray(n)?n.some(o=>o.hooks?.some(Se)):!1}function dt(e){let t=T(e,Y);if(!ee(t))return{file:t,removed:!1};let n=ye(t),o=n.hooks?.PostToolUse;if(!Array.isArray(o))return{file:t,removed:!1};let r=!1;for(let i of o){let s=i.hooks.length;i.hooks=i.hooks.filter(a=>!Se(a)),i.hooks.length!==s&&(r=!0)}return r?(n.hooks.PostToolUse=o.filter(i=>i.hooks.length>0),n.hooks.PostToolUse.length===0&&delete n.hooks.PostToolUse,n.hooks&&Object.keys(n.hooks).length===0&&delete n.hooks,B(t,JSON.stringify(n,null,2)+`
17
+ `,"utf-8"),{file:t,removed:!0}):{file:t,removed:!1}}import{readFileSync as wi,writeFileSync as Rn,existsSync as _i}from"fs";import{join as Tn}from"path";function ft(e){let t=[];t.push("# Business Context"),t.push("");let n=[["Name","name"],["Type","type"],["Audience","audience"],["Industry","industry"],["Location","location"],["Description","description"]];for(let[r,i]of n){let s=e.business[i];t.push(`- **${r}:** ${s||""}`)}let o=new Set(n.map(([,r])=>r));for(let[r,i]of Object.entries(e.business))if(!o.has(r)&&i){let s=r.charAt(0).toUpperCase()+r.slice(1);t.push(`- **${s}:** ${i}`)}if(t.push(""),t.push("# Writing Instructions"),t.push(""),e.writingInstructions.length>0)for(let r of e.writingInstructions)t.push(`- ${r}`);else t.push("- (Add your content writing guidelines here)");if(t.push(""),t.push("# Reference URLs"),t.push(""),e.referenceUrls.length>0)for(let r of e.referenceUrls)r.description?t.push(`- ${r.url} \u2014 ${r.description}`):t.push(`- ${r.url}`);else t.push("- (Add URLs the agent should reference for tone/style)");if(t.push(""),t.push("# Topics to Avoid"),t.push(""),e.topicsToAvoid.length>0)for(let r of e.topicsToAvoid)t.push(`- ${r}`);else t.push("- (Add topics the agent should never write about)");return t.push(""),t.push("# Content Tone"),t.push(""),t.push(e.contentTone||"professional"),t.push(""),t.push("# Additional Notes"),t.push(""),t.push(e.additionalNotes||"(Any other context you want the agent to know about your business, products, or audience.)"),t.push(""),t.join(`
18
+ `)}var On="context.md";function jn(e,t){let n=Tn(e,".seoagent",On),o=ft(t);Rn(n,o,"utf-8")}function mt(e,t){jn(e,{business:{type:t||""},writingInstructions:[],referenceUrls:[],topicsToAvoid:[],contentTone:null,additionalNotes:null})}import{existsSync as G,readFileSync as gt,readdirSync as Nn,statSync as ht}from"fs";import{join as _}from"path";var Ln=[{cms:"strapi",deps:["strapi","@strapi/strapi","@strapi/"],envKeys:["STRAPI_URL","STRAPI_API_URL","NEXT_PUBLIC_STRAPI_URL","STRAPI_API_TOKEN"],fsMarkers:["strapi/","apps/strapi/","packages/strapi/","cms/"]},{cms:"wordpress",deps:["wpapi","wp-graphql","@wordpress/api-fetch","@wordpress/"],envKeys:["WORDPRESS_API_URL","WP_API_URL","NEXT_PUBLIC_WORDPRESS_URL"],fsMarkers:[]},{cms:"sanity",deps:["@sanity/client","next-sanity","sanity"],envKeys:["SANITY_PROJECT_ID","NEXT_PUBLIC_SANITY_PROJECT_ID","SANITY_API_TOKEN"],fsMarkers:["sanity/","studio/","sanity.config.ts","sanity.config.js"]},{cms:"contentful",deps:["contentful","@contentful/rich-text-react-renderer","@contentful/"],envKeys:["CONTENTFUL_SPACE_ID","CONTENTFUL_ACCESS_TOKEN","NEXT_PUBLIC_CONTENTFUL_SPACE_ID"],fsMarkers:[]},{cms:"ghost",deps:["@tryghost/content-api","@tryghost/"],envKeys:["GHOST_URL","GHOST_API_KEY","NEXT_PUBLIC_GHOST_URL"],fsMarkers:[]},{cms:"webflow",deps:["webflow-api"],envKeys:["WEBFLOW_API_TOKEN","WEBFLOW_SITE_ID"],fsMarkers:[]},{cms:"shopify",deps:["@shopify/hydrogen","@shopify/storefront-api-client","@shopify/shopify-api","@shopify/"],envKeys:["SHOPIFY_STOREFRONT_TOKEN","SHOPIFY_STORE_DOMAIN","SHOPIFY_ADMIN_API_TOKEN"],fsMarkers:["shopify.config.ts","shopify.config.js"]},{cms:"payload",deps:["payload","@payloadcms/next","@payloadcms/"],envKeys:["PAYLOAD_SECRET","PAYLOAD_PUBLIC_SERVER_URL"],fsMarkers:["payload.config.ts","payload.config.js"]},{cms:"directus",deps:["@directus/sdk","directus"],envKeys:["DIRECTUS_URL","DIRECTUS_TOKEN"],fsMarkers:[]}];function Fn(e){let t=_(e,"package.json");if(!G(t))return{deps:{},source:"package.json"};try{let n=JSON.parse(gt(t,"utf-8"));return{deps:{...n.dependencies,...n.devDependencies,...n.peerDependencies},source:"package.json"}}catch{return{deps:{},source:"package.json"}}}function Un(e,t){for(let n of t)if(n.endsWith("/")){if(e.startsWith(n))return!0}else if(e===n)return!0;return!1}function Dn(e){let t={};for(let n of C){let o=_(e,n);if(G(o))try{let r=gt(o,"utf-8");for(let i of r.split(/\r?\n/)){let s=i.trim();if(!s||s.startsWith("#"))continue;let a=s.indexOf("=");if(a===-1)continue;let l=s.slice(0,a).trim();l&&!(l in t)&&(t[l]=n)}}catch{}}return t}function Mn(e,t){let n=_(e,t.replace(/\/$/,""));if(!G(n))return!1;if(t.endsWith("/"))try{return ht(n).isDirectory()}catch{return!1}return!0}function Bn(e){let t=["content","_posts","posts",_("src","content")];for(let n of t){let o=_(e,n);if(G(o))try{if(!ht(o).isDirectory())continue;let r=[o],i=0;for(;r.length>0&&i<50;){let s=r.pop();for(let a of Nn(s,{withFileTypes:!0}))if(i++,!a.name.startsWith(".")){if(a.isDirectory()&&r.length<5){r.push(_(s,a.name));continue}if(a.isFile()&&/\.(md|mdx)$/i.test(a.name))return{type:"directory",detail:n,source:`${n}/${a.name}`}}}}catch{}}return null}function Gn(e){let t=[{marker:"app/blog/page.tsx",path:"/blog"},{marker:"app/blog/page.jsx",path:"/blog"},{marker:"app/blog/page.js",path:"/blog"},{marker:"src/app/blog/page.tsx",path:"/blog"},{marker:"src/app/blog/page.jsx",path:"/blog"},{marker:"pages/blog/index.tsx",path:"/blog"},{marker:"pages/blog/index.jsx",path:"/blog"},{marker:"pages/blog/index.js",path:"/blog"},{marker:"src/pages/blog/index.tsx",path:"/blog"},{marker:"app/(blog)/page.tsx",path:"/blog"},{marker:"app/articles/page.tsx",path:"/articles"},{marker:"pages/articles/index.tsx",path:"/articles"},{marker:"app/posts/page.tsx",path:"/posts"},{marker:"pages/posts/index.tsx",path:"/posts"},{marker:"app/learn/page.tsx",path:"/learn"},{marker:"app/resources/page.tsx",path:"/resources"}];for(let n of t)if(G(_(e,n.marker)))return n.path;return null}function yt(e){let t=[],{deps:n}=Fn(e),o=Dn(e),r="none";for(let s of Ln){let a=[];for(let l of Object.keys(n))if(Un(l,s.deps)){a.push({type:"dep",detail:l,source:"package.json"});break}for(let l of s.envKeys)if(o[l]){a.push({type:"env",detail:l,source:o[l]});break}for(let l of s.fsMarkers)if(Mn(e,l)){let u=l.endsWith("/")?"directory":"file";a.push({type:u,detail:l,source:l});break}if(a.length>0){r=s.cms,t.push(...a);break}}if(r==="none"){let s=Bn(e);s&&(r="mdx-local",t.push(s))}let i=Gn(e);return{cms:r,blog_path:i,evidence:t}}import{existsSync as E,readFileSync as ke}from"fs";import{join as I}from"path";function St(e){try{return new URL(e).hostname}catch{return e}}function kt(e){let t=e.toLowerCase();return!!(t==="github.com"||t.endsWith(".github.com")||t==="gitlab.com"||t.endsWith(".gitlab.com")||t==="bitbucket.org"||t.endsWith(".bitbucket.org")||t==="dev.azure.com"||t==="visualstudio.com"||t.endsWith(".visualstudio.com")||t==="npmjs.com"||t.endsWith(".npmjs.com"))}function Wn(e){for(let t of C){let n=I(e,t);if(!E(n))continue;let o=ke(n,"utf-8");for(let r of He){let i=o.match(new RegExp(`^${r}=(.+)$`,"m"));if(i){let s=i[1].trim().replace(/^["']|["']$/g,""),a=St(s);if(kt(a))continue;return{value:a,source:`${t} (${r})`}}}}return null}function Kn(e){let t=I(e,"package.json");if(!E(t))return null;try{let n=JSON.parse(ke(t,"utf-8"));if(!n.homepage)return null;let o=St(n.homepage);return kt(o)?null:{value:o,source:"package.json (homepage)"}}catch{return null}}function xt(e,t){let n=[];t?.("Checking for monorepo / workspace layout\u2026"),E(I(e,"pnpm-workspace.yaml"))&&n.push({field:"context",detail:"Monorepo workspace detected",source:"pnpm-workspace.yaml \u2014 using this directory for project signals"});let o=null;t?.("Scanning .env files for public / site URLs\u2026");let r=Wn(e);if(r)o=r.value,n.push({field:"domain",detail:r.value,source:r.source});else{t?.("Reading package.json homepage (skipping GitHub/GitLab repo URLs)\u2026");let a=Kn(e);a&&(o=a.value,n.push({field:"domain",detail:a.value,source:a.source}))}let i=I(e,"package.json"),s=null;if(E(i))try{t?.("Reading dependencies to infer site type\u2026");let a=JSON.parse(ke(i,"utf-8")),l=Object.keys({...a.dependencies,...a.devDependencies}),u=(...p)=>p.some(d=>l.includes(d));if(u("@shopify/hydrogen","@shopify/polaris")||E(I(e,"shopify.config.js"))||E(I(e,"shopify.config.ts"))){s="product";let p=u("@shopify/hydrogen","@shopify/polaris")?"Shopify-related dependencies in package.json":E(I(e,"shopify.config.ts"))?"shopify.config.ts":"shopify.config.js";n.push({field:"site_type",detail:"product",source:p})}else{let p=u("stripe","@stripe/stripe-js","@stripe/react-stripe-js","paddle","@paddle/paddle-js"),d=u("next-auth","@auth/core","lucia","clerk","@clerk/nextjs","@clerk/clerk-react"),h=u("next");p&&(h||d)?(s="saas",n.push({field:"site_type",detail:"saas",source:h?"payment SDK + Next.js in package.json":"payment SDK + auth library in package.json"})):!p&&u("astro","gatsby","contentlayer","next-mdx-remote","mdx-bundler","vitepress","vuepress","@docusaurus/core","docusaurus","nextra")&&(s="content",n.push({field:"site_type",detail:"content",source:u("vitepress","vuepress","@docusaurus/core","docusaurus","nextra")?"documentation / site generator in package.json (VitePress, Docusaurus, Nextra, etc.)":"content-oriented dependencies in package.json (no payment SDKs detected)"}))}}catch{}return{domain:o,siteType:s,evidence:n}}import{existsSync as Hn,readFileSync as zn,readdirSync as Yn,statSync as Vn}from"fs";import{join as P,sep as Jn}from"path";var bt=["tsx","jsx","js","mdx","md"],Xn=["astro","md","mdx"],qn=5e3;function vt(e,t){let n=new Map,o=0,r=(i,s,a=!1)=>{let l=Zn(i);if(l===null){o++;return}let u=n.get(l);if(u){u.in_sitemap=u.in_sitemap||a,u.source.includes(s)||(u.source+=`, ${s}`);return}n.set(l,{route:l,url:ao(t,l),in_sitemap:a,source:s})};for(let i of["app",P("src","app")]){let s=P(e,i);if(xe(s))for(let a of be(s)){let l=ve(s,a),u=l[l.length-1];oo(u)&&(l.some(p=>p.startsWith("@"))||r(Qn(l.slice(0,-1)),"app router"))}}for(let i of["pages",P("src","pages")]){let s=P(e,i);if(xe(s))for(let a of be(s)){let l=ve(s,a);if(l[0]==="api")continue;let u=l[l.length-1],p=we(u),d=bt.includes(p),h=Xn.includes(p);if(!d&&!h)continue;let A=te(u);ro(A)||r(eo(l),h?"astro":"pages router")}}for(let i of[".","public"]){let s=P(e,i);if(xe(s))for(let a of be(s,i==="."?1:1/0)){let l=ve(s,a),u=l[l.length-1];we(u)==="html"&&(l.some(p=>p==="node_modules"||p.startsWith("."))||r(to(l),"static html"))}}for(let i of["public/sitemap.xml","sitemap.xml"]){let s=P(e,...i.split("/"));if(Hn(s)){for(let a of io(s)){let l=no(a);l!==null&&r(l,"sitemap.xml",!0)}break}}return{pages:[...n.values()].sort((i,s)=>i.route.localeCompare(s.route)),dynamicCount:o}}function Zn(e){let t=e.trim();return t===""||t==="/"||(t.startsWith("/")||(t=`/${t}`),t=t.replace(/\/+$/,""),t==="")?"/":/\[.*\]/.test(t)?null:t}function Qn(e){return"/"+e.filter(n=>!(n.startsWith("(")&&n.endsWith(")"))).join("/")}function eo(e){let t=[...e],n=te(t[t.length-1]);return n==="index"?t.pop():t[t.length-1]=n,"/"+t.join("/")}function to(e){let t=[...e],n=te(t[t.length-1]);return n==="index"?t.pop():t[t.length-1]=n,"/"+t.join("/")}function no(e){try{return new URL(e).pathname||"/"}catch{return e.startsWith("/")?e:null}}function oo(e){return te(e)==="page"&&bt.includes(we(e))}function ro(e){return["_app","_document","_error","404","500","middleware"].includes(e)}function io(e){try{let t=zn(e,"utf-8"),n=[],o=/<loc>\s*([^<\s]+)\s*<\/loc>/gi,r;for(;(r=o.exec(t))!==null;)n.push(r[1].trim());return n}catch{return[]}}var so=new Set(["node_modules",".git",".next","dist","build",".vercel","out"]);function xe(e){try{return Vn(e).isDirectory()}catch{return!1}}function*be(e,t=1/0){let n=0;function*o(r,i){if(i>t)return;let s;try{s=Yn(r,{withFileTypes:!0})}catch{return}for(let a of s){if(n>=qn)return;if(a.name.startsWith("."))continue;let l=P(r,a.name);if(a.isDirectory()){if(so.has(a.name))continue;yield*o(l,i+1)}else a.isFile()&&(n++,yield l)}}yield*o(e,1)}function ve(e,t){return t.slice(e.length).replace(/^[/\\]+/,"").split(Jn).filter(Boolean)}function we(e){let t=e.lastIndexOf(".");return t===-1?"":e.slice(t+1).toLowerCase()}function te(e){let t=e.lastIndexOf(".");return t===-1?e:e.slice(0,t)}function ao(e,t){return e?`https://${e.replace(/^https?:\/\//,"").replace(/\/$/,"")}${t==="/"?"/":t}`:t}import{mkdirSync as co,writeFileSync as lo}from"fs";import{join as wt}from"path";function Et(e,t){if(t.length===0)return;let n=wt(e,g);co(n,{recursive:!0});let o=["---","generated: false",`discovered_at: ${new Date().toISOString()}`,`row_count: ${t.length}`,"---"].join(`
19
19
  `),r=["# Pages","","Inventory of pages discovered in your codebase at setup. Status,","rendered, and in-nav are filled in by the Phase 1 audit. Add or remove","rows freely \u2014 this file syncs to the cloud when you log in."].join(`
20
- `),i="| URL | In sitemap | In nav | Status | Rendered | Notes |",s="|---|---|---|---|---|---|",a=t.map(u=>`| ${wt(u.url)} | ${u.in_sitemap?"yes":"no"} | \u2014 | \u2014 | \u2014 | ${wt(u.source)} |`),c=[o,"",r,"",i,s,...a,""].join(`
21
- `);co(vt(n,"pages.md"),c,"utf-8")}function wt(e){return e.replace(/\r?\n/g," ").replace(/\|/g,"/").trim()}import{log as O}from"@clack/prompts";var l={info:e=>O.info(e),warn:e=>O.warn(e),error:e=>O.error(e),success:e=>O.success(e),step:e=>O.step(e),message:e=>O.message(e)};var Pt=[{value:"saas",label:"SaaS / App"},{value:"service",label:"Service business"},{value:"product",label:"E-commerce / Product"},{value:"content",label:"Content / Blog"},{value:"marketplace",label:"Marketplace"},{value:"tool",label:"Tool / Utility"},{value:"nonprofit",label:"Nonprofit / Community"},{value:"unknown",label:"Not sure"}],At="unknown",mo=new Set(["saas","service","product","content","marketplace","tool","app","nonprofit","community","unknown"]);function go(e){return e.field==="context"?`${e.detail} \u2014 ${e.source}`:e.field==="domain"?`Domain: ${e.detail} \u2014 ${e.source}`:`Site type: ${e.detail} \u2014 ${e.source}`}function ne(e){if(!e?.trim())return null;let t=e.trim().toLowerCase();return mo.has(t)?t:null}async function Ee(e={}){let t=process.cwd();if(qe(t)){l.warn("SEOAgent project already exists in this directory."),l.info("Run `npx @seoagent-official/seoagent status` to see your project state."),l.info("To start fresh, run `npx @seoagent-official/seoagent uninstall` then init again.");return}let n=!!e.yes||!process.stdin.isTTY;n||lo("SEOAgent \u2014 AI SEO Agent");let o=kt(t,a=>l.step(a)),r=()=>{if(o.evidence.length!==0){l.info("Inferred from your project:");for(let a of o.evidence)l.info(` \u2022 ${go(a)}`)}},i=e.domain?.trim()||process.env.SEOAGENT_DOMAIN?.trim()||o.domain||null,s=ne(e.siteType)||ne(process.env.SEOAGENT_SITE_TYPE)||o.siteType||null;if(n){e.siteType?.trim()&&ne(e.siteType)===null&&(l.warn("Invalid --site-type. Use: saas, service, product, content, marketplace, tool, nonprofit, unknown, app, community."),process.exit(1)),process.env.SEOAGENT_SITE_TYPE?.trim()&&ne(process.env.SEOAGENT_SITE_TYPE)===null&&(l.warn("Invalid SEOAGENT_SITE_TYPE environment value."),process.exit(1)),r(),i||(l.info("Couldn't detect your site URL from this repo \u2014 scaffolding anyway; you'll be prompted to supply it."),i=At),s||(s="unknown"),await It(t,i,s);return}if(r(),!i){let a=await Et({message:"Website domain",placeholder:"example.com",validate:c=>c.trim()?void 0:"Domain is required"});j(a)&&(N("Cancelled"),process.exit(0)),i=String(a)}if(!s){let a=await _e({message:"What kind of site is this?",options:[...Pt]});j(a)&&(N("Cancelled"),process.exit(0)),s=a}for(;;){let a=await fo({message:`Create .seoagent for ${i} (${s})?`});if(j(a)&&(N("Cancelled"),process.exit(0)),a)break;let c=await _e({message:"What should we change?",options:[{value:"domain",label:"Domain"},{value:"site_type",label:"Site type"},{value:"abort",label:"Cancel setup"}]});if((j(c)||c==="abort")&&(N("Cancelled"),process.exit(0)),c==="domain"){let u=await Et({message:"Website domain",placeholder:"example.com",validate:p=>p.trim()?void 0:"Domain is required"});j(u)&&(N("Cancelled"),process.exit(0)),i=String(u)}else{let u=await _e({message:"What kind of site is this?",options:[...Pt]});j(u)&&(N("Cancelled"),process.exit(0)),s=u}}await It(t,i,s)}async function It(e,t,n){let o=po();o.start("Setting up your SEO project");let r=ht(e),i={domain:t,site_type:n,language:"en",initialized_at:new Date().toISOString(),seoagent_version:V,...r.cms!=="none"?{cms:r.cms}:{},...r.blog_path?{blog_path:r.blog_path}:{}};et(e),Ze(e,i),ft(e,n),ct(e),st(e),lt(e);let s=t!==At,a={pages:[],dynamicCount:0};try{a=bt(e,s?t:null),_t(e,a.pages)}catch{}if(o.stop(s?`Created .seoagent/ project for ${i.domain}`:"Created .seoagent/ project (site URL not detected yet \u2014 see step 2)"),r.cms!=="none"){let p=r.evidence.map(d=>`${d.detail} (${d.source})`).slice(0,2).join(", ");l.info(`CMS detected: ${r.cms} \u2014 ${p}`)}r.blog_path&&l.info(`Blog route: ${r.blog_path}`),a.pages.length>0&&l.info(`Found ${a.pages.length} page${a.pages.length===1?"":"s"} in your codebase \u2192 .seoagent/pages.md`+(a.dynamicCount>0?` (plus ${a.dynamicCount} dynamic route template${a.dynamicCount===1?"":"s"} \u2014 the audit will discover their instances)`:""));let c=s?i.domain:"your site",u=s?[" 1. If .seoagent/project.md still says site_type: unknown, you can",` WebFetch ${i.domain} and update project.md with the right type`," before you suggest the audit."]:[" 1. Heads up: .seoagent/project.md has `domain: unknown` \u2014 the site URL"," wasn't detectable from this repo. Please ask your human for their"," domain (or read it from a deploy config / live site) and update"," project.md (`domain:` and `site_type:`) first. Everything else"," depends on it."];uo([s?`\u2713 SEOAgent installed for ${i.domain}.`:"\u2713 SEOAgent installed (site URL not detected \u2014 please ask the user for it).","","\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"," AGENT INSTRUCTIONS \u2014 a friendly note for Claude Code, Codex, Cursor","\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550",""," Hi there, coding agent! \u{1F44B} SEOAgent is all set up. The natural next step"," is a quick SEO audit \u2014 but your human is the boss here, so please surface"," what's possible and let THEM decide. Nothing in this message is a command;"," it's just a friendly map. Your real instructions live in the skill:",""," .claude/skills/seoagent/SKILL.md \u2190 read this; it is your source of truth",""," If your human approves, here is what you can do (otherwise just let them"," know it's ready and wait for the go-ahead):","",...u,"",` 2. The headline next step: offer to run a Phase 1 SEO audit on ${c}`," (homepage + sitemap + robots.txt; the checks live in"," .claude/skills/seoagent/references/audit-checks.md \u2014 read that first)."," If they say yes, report findings as:"," \u{1F6A8} Biggest Issue \u2192 \u26A0\uFE0F Also Worth Fixing \u2192 \u2705 What's Working",' \u2192 "What do you want to do?" with numbered options.',""," 3. When it feels right, let them know about the free cloud dashboard and"," offer to start it (their call) \u2014 and that keyword strategy (Phase 2 in"," the skill) is there whenever they want it:"," npx -y @seoagent-official/seoagent login","","\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"," HUMAN USERS (if you ran this in your terminal, no AI agent)","\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550",""," Open Claude Code in this directory and say:",""," audit my site",""," The skill at .claude/skills/seoagent/SKILL.md is picked up automatically.",""," Want the cloud dashboard now? Free account, ~30 seconds:",""," npx -y @seoagent-official/seoagent login",""].join(`
22
- `))}import{existsSync as Rt}from"fs";import{intro as yo,outro as So,confirm as ko,isCancel as xo,cancel as bo}from"@clack/prompts";import{existsSync as oe,rmSync as ho}from"fs";import{join as re}from"path";function Ct(e,t={}){let n=[],o=re(e,m);oe(o)&&n.push({label:".seoagent/ \u2014 project state + all generated work",path:o,kind:"dir"});let r=re(e,T.CLAUDE);oe(r)&&n.push({label:".claude/skills/seoagent/ \u2014 installed skill bundle",path:r,kind:"dir"});let i=re(e,T.AGENTS);return oe(i)&&n.push({label:".agents/skills/seoagent/ \u2014 installed skill bundle",path:i,kind:"dir"}),ut(e)&&n.push({label:".claude/settings.json \u2014 sync hook entry (other settings preserved)",path:re(e,".claude","settings.json"),kind:"hook"}),t.global&&oe(S)&&n.push({label:"~/.config/seoagent/ \u2014 login credentials + sync state (all projects)",path:S,kind:"global"}),n}function Tt(e,t){for(let n of t)n.kind==="hook"?pt(e):ho(n.path,{recursive:!0,force:!0})}async function Pe(e={}){let t=process.cwd(),n=Ct(t,{global:e.global});if(n.length===0){l.info("No SEOAgent install found in this directory \u2014 nothing to remove."),!e.global&&Rt(S)&&l.info("Your seoagent.com login is still stored at ~/.config/seoagent/. Re-run with --global to wipe it too.");return}let o=!!e.yes||!process.stdin.isTTY,r=n.map(s=>` \u2022 ${s.label}`).join(`
23
- `);if(!o){yo("SEOAgent \u2014 uninstall"),l.message(`This will remove:
24
- ${r}`);let s=await ko({message:"Remove these and start fresh?"});if(xo(s)||!s){bo("Cancelled \u2014 nothing was removed.");return}}Tt(t,n);let i=n.map(s=>` \u2713 ${s.label}`).join(`
25
- `);o?l.success(`Removed:
26
- ${i}`):So(`Removed:
27
- ${i}`),!e.global&&Rt(S)&&l.info("Your seoagent.com login (~/.config/seoagent/) was kept \u2014 it is shared across projects. Run `uninstall --global` to wipe it too."),l.info("Re-install any time with `npx -y @seoagent-official/seoagent@latest init`.")}import{existsSync as W,readdirSync as Ie,statSync as vo,readFileSync as $t}from"fs";import{join as L}from"path";function wo(e){let t=(e.match(/^\s*-\s+\[\s\]/gm)??[]).length,n=(e.match(/^\s*-\s+\[x\]/gim)??[]).length;return{open:t,done:n}}function _o(e){let t=L(e,"audit","latest.md");if(!W(t))return null;let n=X(t);if(!n)return null;let o=$t(t,"utf-8"),r=wo(o);return{exists:!0,date:typeof n.data.audited_at=="string"?n.data.audited_at:void 0,issueCount:r.open}}function Eo(e){try{let n=$t(e,"utf-8").split(/\r?\n/),o=!1,r=0;for(let i of n){let s=i.trim();if(s.startsWith("|")&&s.endsWith("|")){if(/^\|\s*-+\s*(\|\s*-+\s*)+\|$/.test(s)){o=!0;continue}o&&r++}else if(o&&s==="")break}return r}catch{return 0}}function Po(e){let t=L(e,"strategy","clusters");if(!W(t))return null;let n=Ie(t).filter(r=>r.endsWith(".md"));if(n.length===0)return null;let o=0;for(let r of n)o+=Eo(L(t,r));return{exists:!0,clusterCount:n.length,articleCount:o}}function Io(e){let t=L(e,"briefs");if(!W(t))return null;let n=Ie(t).filter(o=>o.endsWith(".md"));return n.length>0?{exists:!0,count:n.length}:null}function Ao(e){let t=L(e,"content");if(!W(t))return null;let n=Ie(t).filter(o=>o.endsWith(".md"));return n.length===0?null:{exists:!0,count:n.length}}function Co(e){let t=L(e,"roadmap.md");return W(t)?{exists:!0,updatedAt:vo(t).mtime.toISOString()}:null}function Ot(e){let t=g(e);if(!t)return null;let n=M(e);return{domain:t.domain,audit:_o(n),strategy:Po(n),briefs:Io(n),content:Ao(n),roadmap:Co(n)}}function Ae(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<60)return`${n} minutes ago`;let o=Math.floor(n/60);return o<24?`${o} hours ago`:`${Math.floor(o/24)} days ago`}function Ce(){let e=Ot(process.cwd());if(!e){l.warn("No SEOAgent project found in this directory."),l.info("Run `npx @seoagent-official/seoagent init` to get started.");return}l.message(`SEOAgent Status \u2014 ${e.domain}`),l.info(e.audit?.exists?`Audit: last run ${Ae(e.audit.date??"")} (${e.audit.issueCount??0} issues found)`:"Audit: not yet run"),l.info(e.strategy?.exists?`Strategy: ${e.strategy.clusterCount} topic clusters, ${e.strategy.articleCount} article ideas`:"Strategy: not yet created"),l.info(e.briefs?.exists?`Briefs: ${e.briefs.count} ready`:"Briefs: none created"),e.content?.exists?l.success(`Content: ${e.content.count} articles written`):l.info("Content: no articles yet"),l.info(e.roadmap?.exists?`Roadmap: .seoagent/roadmap.md (updated ${Ae(e.roadmap.updatedAt??"")})`:"Roadmap: not yet created")}import{exec as To}from"child_process";function Te(){let e=process.cwd(),n=g(e)?.domain??"",o=`${k.PRICING}?ref=cli${n?`&domain=${encodeURIComponent(n)}`:""}`;l.info("Opening SEOAgent Cloud pricing..."),l.message(`URL: ${o}`);let r=process.platform==="darwin"?`open "${o}"`:process.platform==="win32"?`start "${o}"`:`xdg-open "${o}"`;To(r,i=>{i&&l.warn("Could not open browser. Visit the URL above to upgrade.")})}import{exec as Lo}from"child_process";import{randomBytes as Fo}from"crypto";import{existsSync as Nt,mkdirSync as jt,readFileSync as Ro,writeFileSync as $o,chmodSync as Oo,unlinkSync as jo}from"fs";import{dirname as No}from"path";function w(){if(!Nt(v))return null;try{let e=JSON.parse(Ro(v,"utf-8"));return!e.user_token||!e.website_token?null:{user_token:e.user_token,website_token:e.website_token,api_base:e.api_base||D}}catch{return null}}function Lt(e){jt(S,{recursive:!0}),jt(No(v),{recursive:!0}),$o(v,JSON.stringify(e,null,2)+`
28
- `,"utf-8");try{Oo(v,384)}catch{}}function Ft(){if(!Nt(v))return!1;try{return jo(v),!0}catch{return!1}}function Ut(e,t){if(e>=500)return{status:"error",terminal:!1,message:`HTTP ${e} (server error)`};if(e>=400)return{status:"error",terminal:!0,message:`HTTP ${e} (client error)`};if(!t||typeof t!="object")return{status:"error",terminal:!0,message:`Malformed response: expected an object, got ${typeof t}`};let n=t;return n.status==="ready"?typeof n.user_token=="string"&&typeof n.website_token=="string"?{status:"ready",user_token:n.user_token,website_token:n.website_token}:{status:"error",terminal:!0,message:"Malformed response: status=ready without user_token+website_token"}:n.status==="pending"?{status:"pending"}:n.status==="expired"?{status:"expired"}:{status:"error",terminal:!0,message:`Malformed response: unknown status=${JSON.stringify(n.status)}`}}var Uo=1500,Do=300*1e3;function Mo(e){let t=process.platform==="darwin"?`open "${e}"`:process.platform==="win32"?`start "" "${e}"`:`xdg-open "${e}"`;Lo(t,()=>{})}function Bo(){return Fo(16).toString("hex")}async function Go(e,t){try{let n=`${e}/api/cli/auth/poll?session=${encodeURIComponent(t)}`,o=await fetch(n,{headers:{Accept:"application/json"}}),r=null;try{r=await o.json()}catch{}return Ut(o.status,r)}catch(n){return{status:"error",terminal:!1,message:n.message||"network error"}}}function Wo(e){return new Promise(t=>setTimeout(t,e))}async function Re(e={}){let t=process.cwd(),n=g(t),o=(e.apiBase||k.BASE||D).replace(/\/$/,"");if(w()){l.info("Already logged in. To switch accounts, run `npx @seoagent-official/seoagent logout` first.");return}let r=Bo(),i=new URLSearchParams({session:r});n?.domain&&i.set("domain",n.domain);let s=`${o}/cli/auth?${i.toString()}`;l.message("Opening seoagent.com to connect this CLI to your account..."),l.info(`If the browser does not open, visit: ${s}`),Mo(s),l.info('In your browser: sign in (if needed) and click "Connect this CLI" to finish.');let a=Date.now()+Do,c=!0;for(;Date.now()<a;){c||await Wo(Uo),c=!1;let u=await Go(o,r);if(u.status==="ready"){Lt({user_token:u.user_token,website_token:u.website_token,api_base:o}),l.success("Logged in. Future SEO work in this repo will sync to your dashboard.");return}if(u.status==="expired"){l.warn("Session expired. Run `npx @seoagent-official/seoagent login` again.");return}if(u.status==="error"){if(u.terminal){l.warn(`Login failed: ${u.message}. Run \`npx @seoagent-official/seoagent login\` again.`);return}continue}}l.warn("Login timed out. Run `npx @seoagent-official/seoagent login` again to retry.")}function $e(){Ft()?l.success("Logged out."):l.info("You were not logged in.")}import{existsSync as Ne,mkdirSync as lr,readFileSync as Xt,readdirSync as ur,statSync as pr,writeFileSync as dr}from"fs";import{join as Le,relative as fr,sep as mr}from"path";import{existsSync as Ko,mkdirSync as Ho,readdirSync as zo,unlinkSync as Yo,writeFileSync as Dt}from"fs";import{join as ie}from"path";function Oe(e){return ie(e,m,"inbox")}function Mt(e){return`${e.action_type}-${e.id}.md`}function Vo(e,t){let n=0;if(!Ko(e))return 0;for(let o of zo(e)){if(!o.endsWith(".md")||o==="README.md")continue;let r=o.match(/^(?:.+)-(\d+)\.md$/);if(!r)continue;let i=Number.parseInt(r[1],10);if(!Number.isNaN(i)&&!t.has(i))try{Yo(ie(e,o)),n++}catch{}}return n}function Jo(e){let t=e.payload||{},n=t.articleId??"unknown",o=t.slug??null,r=t.originalTitle??null,i=t.originalUrl??null,s=t.cmsType??null;return`---
20
+ `),i="| URL | In sitemap | In nav | Status | Rendered | Notes |",s="|---|---|---|---|---|---|",a=t.map(u=>`| ${_t(u.url)} | ${u.in_sitemap?"yes":"no"} | \u2014 | \u2014 | \u2014 | ${_t(u.source)} |`),l=[o,"",r,"",i,s,...a,""].join(`
21
+ `);lo(wt(n,"pages.md"),l,"utf-8")}function _t(e){return e.replace(/\r?\n/g," ").replace(/\|/g,"/").trim()}import{log as O}from"@clack/prompts";var c={info:e=>O.info(e),warn:e=>O.warn(e),error:e=>O.error(e),success:e=>O.success(e),step:e=>O.step(e),message:e=>O.message(e)};var Pt=[{value:"saas",label:"SaaS / App"},{value:"service",label:"Service business"},{value:"product",label:"E-commerce / Product"},{value:"content",label:"Content / Blog"},{value:"marketplace",label:"Marketplace"},{value:"tool",label:"Tool / Utility"},{value:"nonprofit",label:"Nonprofit / Community"},{value:"unknown",label:"Not sure"}],Ct="unknown",go=new Set(["saas","service","product","content","marketplace","tool","app","nonprofit","community","unknown"]);function ho(e){return e.field==="context"?`${e.detail} \u2014 ${e.source}`:e.field==="domain"?`Domain: ${e.detail} \u2014 ${e.source}`:`Site type: ${e.detail} \u2014 ${e.source}`}function ne(e){if(!e?.trim())return null;let t=e.trim().toLowerCase();return go.has(t)?t:null}async function Ee(e={}){let t=process.cwd();if(Ze(t)){c.warn("SEOAgent project already exists in this directory."),c.info("Run `npx @seoagent-official/seoagent status` to see your project state."),c.info("To start fresh, run `npx @seoagent-official/seoagent uninstall` then init again.");return}let n=!!e.yes||!process.stdin.isTTY;n||uo("SEOAgent \u2014 AI SEO Agent");let o=xt(t,a=>c.step(a)),r=()=>{if(o.evidence.length!==0){c.info("Inferred from your project:");for(let a of o.evidence)c.info(` \u2022 ${ho(a)}`)}},i=e.domain?.trim()||process.env.SEOAGENT_DOMAIN?.trim()||o.domain||null,s=ne(e.siteType)||ne(process.env.SEOAGENT_SITE_TYPE)||o.siteType||null;if(n){e.siteType?.trim()&&ne(e.siteType)===null&&(c.warn("Invalid --site-type. Use: saas, service, product, content, marketplace, tool, nonprofit, unknown, app, community."),process.exit(1)),process.env.SEOAGENT_SITE_TYPE?.trim()&&ne(process.env.SEOAGENT_SITE_TYPE)===null&&(c.warn("Invalid SEOAGENT_SITE_TYPE environment value."),process.exit(1)),r(),i||(c.info("Couldn't detect your site URL from this repo \u2014 scaffolding anyway; you'll be prompted to supply it."),i=Ct),s||(s="unknown"),await At(t,i,s);return}if(r(),!i){let a=await It({message:"Website domain",placeholder:"example.com",validate:l=>l.trim()?void 0:"Domain is required"});j(a)&&(N("Cancelled"),process.exit(0)),i=String(a)}if(!s){let a=await _e({message:"What kind of site is this?",options:[...Pt]});j(a)&&(N("Cancelled"),process.exit(0)),s=a}for(;;){let a=await mo({message:`Create .seoagent for ${i} (${s})?`});if(j(a)&&(N("Cancelled"),process.exit(0)),a)break;let l=await _e({message:"What should we change?",options:[{value:"domain",label:"Domain"},{value:"site_type",label:"Site type"},{value:"abort",label:"Cancel setup"}]});if((j(l)||l==="abort")&&(N("Cancelled"),process.exit(0)),l==="domain"){let u=await It({message:"Website domain",placeholder:"example.com",validate:p=>p.trim()?void 0:"Domain is required"});j(u)&&(N("Cancelled"),process.exit(0)),i=String(u)}else{let u=await _e({message:"What kind of site is this?",options:[...Pt]});j(u)&&(N("Cancelled"),process.exit(0)),s=u}}await At(t,i,s)}async function At(e,t,n){let o=fo();o.start("Setting up your SEO project");let r=yt(e),i={domain:t,site_type:n,language:"en",initialized_at:new Date().toISOString(),seoagent_version:V,...r.cms!=="none"?{cms:r.cms}:{},...r.blog_path?{blog_path:r.blog_path}:{}};tt(e),Qe(e,i),mt(e,n),lt(e),at(e),ut(e);let s=t!==Ct,a={pages:[],dynamicCount:0};try{a=vt(e,s?t:null),Et(e,a.pages)}catch{}if(o.stop(s?`Created .seoagent/ project for ${i.domain}`:"Created .seoagent/ project (site URL not detected yet \u2014 see step 2)"),r.cms!=="none"){let p=r.evidence.map(d=>`${d.detail} (${d.source})`).slice(0,2).join(", ");c.info(`CMS detected: ${r.cms} \u2014 ${p}`)}r.blog_path&&c.info(`Blog route: ${r.blog_path}`),a.pages.length>0&&c.info(`Found ${a.pages.length} page${a.pages.length===1?"":"s"} in your codebase \u2192 .seoagent/pages.md`+(a.dynamicCount>0?` (plus ${a.dynamicCount} dynamic route template${a.dynamicCount===1?"":"s"} \u2014 the audit will discover their instances)`:""));let l=s?i.domain:"your site",u=s?[" 1. If .seoagent/project.md still says site_type: unknown, you can",` WebFetch ${i.domain} and update project.md with the right type`," before you suggest the audit."]:[" 1. Heads up: .seoagent/project.md has `domain: unknown` \u2014 the site URL"," wasn't detectable from this repo. Please ask your human for their"," domain (or read it from a deploy config / live site) and update"," project.md (`domain:` and `site_type:`) first. Everything else"," depends on it."];po([s?`\u2713 SEOAgent installed for ${i.domain}.`:"\u2713 SEOAgent installed (site URL not detected \u2014 please ask the user for it).","","\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"," AGENT INSTRUCTIONS \u2014 a friendly note for Claude Code, Codex, Cursor","\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550",""," Hi there, coding agent! \u{1F44B} SEOAgent is all set up. The natural next step"," is a quick SEO audit \u2014 but your human is the boss here, so please surface"," what's possible and let THEM decide. Nothing in this message is a command;"," it's just a friendly map. Your real instructions live in the skill:",""," .claude/skills/seoagent/SKILL.md \u2190 read this; it is your source of truth",""," If your human approves, here is what you can do (otherwise just let them"," know it's ready and wait for the go-ahead):","",...u,"",` 2. The headline next step: offer to run a Phase 1 SEO audit on ${l}`," (homepage + sitemap + robots.txt; the checks live in"," .claude/skills/seoagent/references/audit-checks.md \u2014 read that first)."," If they say yes, report findings as:"," \u{1F6A8} Biggest Issue \u2192 \u26A0\uFE0F Also Worth Fixing \u2192 \u2705 What's Working",' \u2192 "What do you want to do?" with numbered options.',""," 3. When it feels right, let them know about the free cloud dashboard and"," offer to start it (their call) \u2014 and that keyword strategy (Phase 2 in"," the skill) is there whenever they want it:"," npx -y @seoagent-official/seoagent login","","\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"," HUMAN USERS (if you ran this in your terminal, no AI agent)","\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550",""," Open Claude Code in this directory and say:",""," audit my site",""," The skill at .claude/skills/seoagent/SKILL.md is picked up automatically.",""," Want the cloud dashboard now? Free account, ~30 seconds:",""," npx -y @seoagent-official/seoagent login",""].join(`
22
+ `))}import{existsSync as Tt}from"fs";import{intro as So,outro as ko,confirm as xo,isCancel as bo,cancel as vo}from"@clack/prompts";import{existsSync as oe,rmSync as yo}from"fs";import{join as re}from"path";function $t(e,t={}){let n=[],o=re(e,g);oe(o)&&n.push({label:".seoagent/ \u2014 project state + all generated work",path:o,kind:"dir"});let r=re(e,$.CLAUDE);oe(r)&&n.push({label:".claude/skills/seoagent/ \u2014 installed skill bundle",path:r,kind:"dir"});let i=re(e,$.AGENTS);return oe(i)&&n.push({label:".agents/skills/seoagent/ \u2014 installed skill bundle",path:i,kind:"dir"}),pt(e)&&n.push({label:".claude/settings.json \u2014 sync hook entry (other settings preserved)",path:re(e,".claude","settings.json"),kind:"hook"}),t.global&&oe(k)&&n.push({label:"~/.config/seoagent/ \u2014 login credentials + sync state (all projects)",path:k,kind:"global"}),n}function Rt(e,t){for(let n of t)n.kind==="hook"?dt(e):yo(n.path,{recursive:!0,force:!0})}async function Ie(e={}){let t=process.cwd(),n=$t(t,{global:e.global});if(n.length===0){c.info("No SEOAgent install found in this directory \u2014 nothing to remove."),!e.global&&Tt(k)&&c.info("Your seoagent.com login is still stored at ~/.config/seoagent/. Re-run with --global to wipe it too.");return}let o=!!e.yes||!process.stdin.isTTY,r=n.map(s=>` \u2022 ${s.label}`).join(`
23
+ `);if(!o){So("SEOAgent \u2014 uninstall"),c.message(`This will remove:
24
+ ${r}`);let s=await xo({message:"Remove these and start fresh?"});if(bo(s)||!s){vo("Cancelled \u2014 nothing was removed.");return}}Rt(t,n);let i=n.map(s=>` \u2713 ${s.label}`).join(`
25
+ `);o?c.success(`Removed:
26
+ ${i}`):ko(`Removed:
27
+ ${i}`),!e.global&&Tt(k)&&c.info("Your seoagent.com login (~/.config/seoagent/) was kept \u2014 it is shared across projects. Run `uninstall --global` to wipe it too."),c.info("Re-install any time with `npx -y @seoagent-official/seoagent@latest init`.")}import{existsSync as W,readdirSync as Pe,statSync as wo,readFileSync as Ot}from"fs";import{join as L}from"path";function _o(e){let t=(e.match(/^\s*-\s+\[\s\]/gm)??[]).length,n=(e.match(/^\s*-\s+\[x\]/gim)??[]).length;return{open:t,done:n}}function Eo(e){let t=L(e,"audit","latest.md");if(!W(t))return null;let n=X(t);if(!n)return null;let o=Ot(t,"utf-8"),r=_o(o);return{exists:!0,date:typeof n.data.audited_at=="string"?n.data.audited_at:void 0,issueCount:r.open}}function Io(e){try{let n=Ot(e,"utf-8").split(/\r?\n/),o=!1,r=0;for(let i of n){let s=i.trim();if(s.startsWith("|")&&s.endsWith("|")){if(/^\|\s*-+\s*(\|\s*-+\s*)+\|$/.test(s)){o=!0;continue}o&&r++}else if(o&&s==="")break}return r}catch{return 0}}function Po(e){let t=L(e,"strategy","clusters");if(!W(t))return null;let n=Pe(t).filter(r=>r.endsWith(".md"));if(n.length===0)return null;let o=0;for(let r of n)o+=Io(L(t,r));return{exists:!0,clusterCount:n.length,articleCount:o}}function Ao(e){let t=L(e,"briefs");if(!W(t))return null;let n=Pe(t).filter(o=>o.endsWith(".md"));return n.length>0?{exists:!0,count:n.length}:null}function Co(e){let t=L(e,"content");if(!W(t))return null;let n=Pe(t).filter(o=>o.endsWith(".md"));return n.length===0?null:{exists:!0,count:n.length}}function $o(e){let t=L(e,"roadmap.md");return W(t)?{exists:!0,updatedAt:wo(t).mtime.toISOString()}:null}function jt(e){let t=f(e);if(!t)return null;let n=M(e);return{domain:t.domain,audit:Eo(n),strategy:Po(n),briefs:Ao(n),content:Co(n),roadmap:$o(n)}}function Ae(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<60)return`${n} minutes ago`;let o=Math.floor(n/60);return o<24?`${o} hours ago`:`${Math.floor(o/24)} days ago`}function Ce(){let e=jt(process.cwd());if(!e){c.warn("No SEOAgent project found in this directory."),c.info("Run `npx @seoagent-official/seoagent init` to get started.");return}c.message(`SEOAgent Status \u2014 ${e.domain}`),c.info(e.audit?.exists?`Audit: last run ${Ae(e.audit.date??"")} (${e.audit.issueCount??0} issues found)`:"Audit: not yet run"),c.info(e.strategy?.exists?`Strategy: ${e.strategy.clusterCount} topic clusters, ${e.strategy.articleCount} article ideas`:"Strategy: not yet created"),c.info(e.briefs?.exists?`Briefs: ${e.briefs.count} ready`:"Briefs: none created"),e.content?.exists?c.success(`Content: ${e.content.count} articles written`):c.info("Content: no articles yet"),c.info(e.roadmap?.exists?`Roadmap: .seoagent/roadmap.md (updated ${Ae(e.roadmap.updatedAt??"")})`:"Roadmap: not yet created")}import{exec as Ro}from"child_process";function $e(){let e=process.cwd(),n=f(e)?.domain??"",o=`${S.PRICING}?ref=cli${n?`&domain=${encodeURIComponent(n)}`:""}`;c.info("Opening SEOAgent Cloud pricing..."),c.message(`URL: ${o}`);let r=process.platform==="darwin"?`open "${o}"`:process.platform==="win32"?`start "${o}"`:`xdg-open "${o}"`;Ro(r,i=>{i&&c.warn("Could not open browser. Visit the URL above to upgrade.")})}import{exec as Fo}from"child_process";import{randomBytes as Uo}from"crypto";import{existsSync as Lt,mkdirSync as Nt,readFileSync as To,writeFileSync as Oo,chmodSync as jo,unlinkSync as No}from"fs";import{dirname as Lo}from"path";function x(){if(!Lt(w))return null;try{let e=JSON.parse(To(w,"utf-8"));return!e.user_token||!e.website_token?null:{user_token:e.user_token,website_token:e.website_token,api_base:e.api_base||D}}catch{return null}}function Ft(e){Nt(k,{recursive:!0}),Nt(Lo(w),{recursive:!0}),Oo(w,JSON.stringify(e,null,2)+`
28
+ `,"utf-8");try{jo(w,384)}catch{}}function Ut(){if(!Lt(w))return!1;try{return No(w),!0}catch{return!1}}function Dt(e,t){if(e>=500)return{status:"error",terminal:!1,message:`HTTP ${e} (server error)`};if(e>=400)return{status:"error",terminal:!0,message:`HTTP ${e} (client error)`};if(!t||typeof t!="object")return{status:"error",terminal:!0,message:`Malformed response: expected an object, got ${typeof t}`};let n=t;return n.status==="ready"?typeof n.user_token=="string"&&typeof n.website_token=="string"?{status:"ready",user_token:n.user_token,website_token:n.website_token}:{status:"error",terminal:!0,message:"Malformed response: status=ready without user_token+website_token"}:n.status==="pending"?{status:"pending"}:n.status==="expired"?{status:"expired"}:{status:"error",terminal:!0,message:`Malformed response: unknown status=${JSON.stringify(n.status)}`}}var Do=1500,Mo=300*1e3;function Bo(e){let t=process.platform==="darwin"?`open "${e}"`:process.platform==="win32"?`start "" "${e}"`:`xdg-open "${e}"`;Fo(t,()=>{})}function Go(){return Uo(16).toString("hex")}async function Wo(e,t){try{let n=`${e}/api/cli/auth/poll?session=${encodeURIComponent(t)}`,o=await fetch(n,{headers:{Accept:"application/json"}}),r=null;try{r=await o.json()}catch{}return Dt(o.status,r)}catch(n){return{status:"error",terminal:!1,message:n.message||"network error"}}}function Ko(e){return new Promise(t=>setTimeout(t,e))}async function Re(e={}){let t=process.cwd(),n=f(t),o=(e.apiBase||S.BASE||D).replace(/\/$/,"");if(x()){c.info("Already logged in. To switch accounts, run `npx @seoagent-official/seoagent logout` first.");return}let r=Go(),i=new URLSearchParams({session:r});n?.domain&&i.set("domain",n.domain);let s=`${o}/cli/auth?${i.toString()}`;c.message("Opening seoagent.com to connect this CLI to your account..."),c.info(`If the browser does not open, visit: ${s}`),Bo(s),c.info('In your browser: sign in (if needed) and click "Connect this CLI" to finish.');let a=Date.now()+Mo,l=!0;for(;Date.now()<a;){l||await Ko(Do),l=!1;let u=await Wo(o,r);if(u.status==="ready"){Ft({user_token:u.user_token,website_token:u.website_token,api_base:o}),c.success("Logged in. Future SEO work in this repo will sync to your dashboard.");return}if(u.status==="expired"){c.warn("Session expired. Run `npx @seoagent-official/seoagent login` again.");return}if(u.status==="error"){if(u.terminal){c.warn(`Login failed: ${u.message}. Run \`npx @seoagent-official/seoagent login\` again.`);return}continue}}c.warn("Login timed out. Run `npx @seoagent-official/seoagent login` again to retry.")}function Te(){Ut()?c.success("Logged out."):c.info("You were not logged in.")}import{existsSync as Ne,mkdirSync as dr,readFileSync as qt,readdirSync as fr,statSync as mr,writeFileSync as gr}from"fs";import{join as Le,relative as hr,sep as yr}from"path";import{existsSync as Ho,mkdirSync as zo,readdirSync as Yo,unlinkSync as Vo,writeFileSync as Mt}from"fs";import{join as ie}from"path";function Oe(e){return ie(e,g,"inbox")}function Bt(e){return`${e.action_type}-${e.id}.md`}function Jo(e,t){let n=0;if(!Ho(e))return 0;for(let o of Yo(e)){if(!o.endsWith(".md")||o==="README.md")continue;let r=o.match(/^(?:.+)-(\d+)\.md$/);if(!r)continue;let i=Number.parseInt(r[1],10);if(!Number.isNaN(i)&&!t.has(i))try{Vo(ie(e,o)),n++}catch{}}return n}function Xo(e){let t=e.payload||{},n=t.articleId??"unknown",o=t.slug??null,r=t.originalTitle??null,i=t.originalUrl??null,s=t.cmsType??null;return`---
29
29
  action_id: ${e.id}
30
30
  action_type: ${e.action_type}
31
31
  article_id: ${n}
@@ -68,10 +68,56 @@ positive, you disagree, etc.), close it out as failed with a reason:
68
68
  \`\`\`bash
69
69
  npx @seoagent-official/seoagent ack ${e.id} --failed --reason "kept; performs well off-search"
70
70
  \`\`\`
71
- `}function Xo(e){if(e.length===0)return`# SEOAgent Inbox
71
+ `}function qo(e){let t=e.payload||{},n=t.page_url??null,o=t.issue??"other",r=t.check_id??"unknown",i=t.severity??"unknown",s=t.recommended_fix??null;return`---
72
+ action_id: ${e.id}
73
+ action_type: ${e.action_type}
74
+ issue: ${o}
75
+ check_id: ${r}
76
+ severity: ${i}
77
+ page_url: ${n??""}
78
+ created_at: ${e.created_at}
79
+ ---
80
+
81
+ # Technical SEO fix \u2014 ${e.title??r}
82
+
83
+ SEOAgent's audit found an open **${i}** technical issue (\`${r}\`,
84
+ category \`${o}\`)${n?` on \`${n}\``:""}. The cloud has queued
85
+ it for **you** (or Claude Code reading this file) to apply in the user's repo or
86
+ CMS \u2014 nothing is auto-applied.
87
+
88
+ ## The fix
89
+
90
+ ${s??e.description??"Apply the appropriate fix for this issue."}
91
+
92
+ ## How to apply
93
+
94
+ 1. Locate the page's source. ${n?`It renders at \`${n}\` \u2014 find the matching route/template/markdown in this repo (look under \`app/\`, \`pages/\`, \`src/\`, \`content/\`).`:"Find the affected page/template in this repo."}
95
+ 2. Apply the change for a \`${o}\` issue:
96
+ - **meta** \u2014 fix the \`<title>\` / \`<meta name="description">\` (or the framework's metadata API / frontmatter).
97
+ - **schema** \u2014 add or correct JSON-LD structured data.
98
+ - **canonical** \u2014 set the correct \`<link rel="canonical">\`.
99
+ - **internal_link** \u2014 add relevant internal links (fix orphan/low-link pages).
100
+ - **other** \u2014 follow the recommendation above.
101
+ 3. Show the user the diff before committing (confirm once per session, then proceed).
102
+
103
+ ## How to close this out
104
+
105
+ After applying:
106
+
107
+ \`\`\`bash
108
+ npx @seoagent-official/seoagent ack ${e.id}
109
+ \`\`\`
110
+
111
+ That marks the action \`completed\` server-side and removes this inbox file on the
112
+ next \`seoagent sync\`. If you disagree or it's a false positive, decline it:
113
+
114
+ \`\`\`bash
115
+ npx @seoagent-official/seoagent ack ${e.id} --failed --reason "not applicable; ..."
116
+ \`\`\`
117
+ `}function Zo(e){switch(e.action_type){case"cli_prune_pending":return Xo(e);case"cli_technical_fix":return qo(e);default:return null}}function Qo(e){if(e.length===0)return`# SEOAgent Inbox
72
118
 
73
119
  No pending actions. Run \`seoagent sync\` later to check for new ones.
74
- `;let t=e.map(n=>`- **${n.action_type}** id \`${n.id}\` \u2014 ${n.title??"no title"} \u2192 see \`${Mt(n)}\``);return`# SEOAgent Inbox
120
+ `;let t=e.map(n=>`- **${n.action_type}** id \`${n.id}\` \u2014 ${n.title??"no title"} \u2192 see \`${Bt(n)}\``);return`# SEOAgent Inbox
75
121
 
76
122
  You have **${e.length}** pending action${e.length===1?"":"s"} from your dashboard.
77
123
 
@@ -83,9 +129,9 @@ For each file, read it, take the action it describes, then run \`seoagent ack <a
83
129
 
84
130
  If you're using Claude Code, just open this directory and ask "process the inbox" \u2014 the
85
131
  skill knows what to do.
86
- `}function Bt(e,t){let n=Oe(e);Ho(n,{recursive:!0});let o=new Set(t.map(s=>s.id)),r=Vo(n,o),i=0;for(let s of t)s.action_type==="cli_prune_pending"&&(Dt(ie(n,Mt(s)),Jo(s),"utf-8"),i++);return Dt(ie(n,"README.md"),Xo(t),"utf-8"),{wrote:i,removed:r,inboxPath:n}}import{createHash as Qo}from"crypto";import{existsSync as Kt,mkdirSync as er,readFileSync as tr,statSync as Ht,writeFileSync as Wt,rmSync as nr}from"fs";import{dirname as or,join as je,sep as rr}from"path";function qo(e){return e.replace(/^\/+/,"").replace(/\\/g,"/")}var Zo=[{cls:"project",test:e=>e==="project.md"},{cls:"audit",test:e=>e==="audit/latest.md"||/^audit\/(critical|high|medium|low)\.md$/.test(e)},{cls:"brief",test:e=>/^briefs\/[^/]+\.md$/.test(e)},{cls:"article",test:e=>/^content\/[^/]+\.md$/.test(e)},{cls:"cluster",test:e=>/^strategy\/clusters\/[^/]+\.md$/.test(e)},{cls:"keywords",test:e=>e==="keywords.md"||/^strategy\/keywords\/[^/]+\.md$/.test(e)},{cls:"pages",test:e=>e==="pages.md"||/^pages\/[^/]+\.md$/.test(e)},{cls:"competitors",test:e=>e==="competitors.md"},{cls:"changelog",test:e=>e==="changelog.md"}];function Gt(e,t){let n=qo(e);for(let{cls:o,test:r}of Zo)if(r(n))return t&&(o==="keywords"||o==="pages")?"generated-index":o;return"other"}function ir(e){return"sha256:"+Qo("sha256").update(e).digest("hex")}function sr(e,t,n={}){let o=[];for(let r of e.artifacts){let i=t[r.path]??{exists:!1,locallyEdited:!1};if(!i.exists){o.push({path:r.path,kind:"write",body:r.body_md});continue}if(i.contentHash===r.content_hash){o.push({path:r.path,kind:"skip"});continue}if(r.generated){o.push({path:r.path,kind:"overwrite",body:r.body_md,note:i.locallyEdited?"discarded local edits \u2014 this is a cloud-generated file (edit it in the dashboard)":void 0});continue}if(i.locallyEdited&&!n.force){o.push({path:r.path,kind:"conflict",note:"local newer than cloud, keeping local \u2014 use --force to take cloud"});continue}o.push({path:r.path,kind:"overwrite",body:r.body_md})}for(let r of e.deleted){let i=t[r];if(!(!i||!i.exists)){if(i.locallyEdited&&!n.force){o.push({path:r,kind:"delete-skipped",note:"server deleted this but it has local edits \u2014 keeping it (use --force to delete)"});continue}o.push({path:r,kind:"delete"})}}return o}function ar(e,t,n,o){let r=new Map;for(let s of t.artifacts)r.set(s.path,s.generated);let i=[];for(let s of e)s.kind!=="skip"&&i.push({path:s.path,kind:s.kind,class:Gt(s.path,r.get(s.path)??!1),...s.note?{note:s.note}:{}});return i.length===0?null:{pulled_at:o,cursor:n,changes:i}}async function zt(e){let t=await Vt({apiBase:e.apiBase,authHeader:e.authHeader,since:null,fetchImpl:e.fetchImpl});if(!t.ok)return{ok:!1,error:t.error};let n=e.path.replace(/^\/+/,"").replace(/\\/g,"/"),o=t.manifest.artifacts.find(r=>r.path===n);return o?{ok:!0,body:o.body_md}:{ok:!1,error:`No cloud artifact found at "${n}"`}}function Yt(e,t){return je(e,t.split("/").join(rr))}function cr(e,t,n){let o={};for(let r of t){let i=Yt(e,r);if(!Kt(i)){o[r]={exists:!1,locallyEdited:!1};continue}let s=Ht(i),a=n[r],c=!a||a.mtime!==s.mtimeMs||a.size!==s.size;o[r]={exists:!0,contentHash:ir(tr(i,"utf-8")),locallyEdited:c}}return o}async function Vt(e){let t=e.fetchImpl??fetch,n=`${e.apiBase}/api/cli/sync`+(e.since?`?since=${encodeURIComponent(e.since)}`:"");try{let o=await t(n,{method:"GET",headers:{Authorization:e.authHeader,Accept:"application/json"}});if(!o.ok){let i=await o.text().catch(()=>"");return{ok:!1,error:`${o.status} ${i.slice(0,200)}`.trim()}}let r=await o.json().catch(()=>null);return!r||!Array.isArray(r.artifacts)||typeof r.now!="string"?{ok:!1,error:"Malformed manifest response"}:(Array.isArray(r.deleted)||(r.deleted=[]),{ok:!0,manifest:r})}catch(o){return{ok:!1,error:o.message}}}async function Jt(e){let t=je(e.projectDir,m),n={ok:!0,written:0,overwritten:0,skipped:0,conflicts:0,deleted:0,warnings:[],cursor:e.since};if(!Kt(t))return{...n,ok:!0};let o=await Vt({apiBase:e.apiBase,authHeader:e.authHeader,since:e.since,fetchImpl:e.fetchImpl});if(!o.ok)return{...n,ok:!1,error:o.error};let r=o.manifest,i=[...r.artifacts.map(p=>p.path),...r.deleted],s=cr(t,i,e.stateFiles),a=sr(r,s,{force:e.force}),c={...n,cursor:r.now};for(let p of a){let d=Yt(t,p.path);try{switch(p.kind){case"skip":c.skipped++;break;case"write":case"overwrite":{er(or(d),{recursive:!0}),Wt(d,p.body??"","utf-8");let h=Ht(d);e.stateFiles[p.path]={mtime:h.mtimeMs,size:h.size},p.kind==="write"?c.written++:c.overwritten++,p.note&&c.warnings.push(`${p.path}: ${p.note}`);break}case"conflict":c.conflicts++,c.warnings.push(`${p.path}: ${p.note??"conflict"}`);break;case"delete":nr(d,{force:!0}),delete e.stateFiles[p.path],c.deleted++;break;case"delete-skipped":c.conflicts++,c.warnings.push(`${p.path}: ${p.note??"delete skipped"}`);break}}catch(h){c.ok=!1,c.error=`${p.path}: ${h.message}`}}(c.conflicts>0||!c.ok)&&(c.cursor=e.since);let u=ar(a,r,c.cursor,new Date().toISOString());if(u)try{Wt(je(t,ze),JSON.stringify(u,null,2)+`
87
- `,"utf-8")}catch{}return c}var gr=new Set([".md"]),hr=new Set(["inbox"]);function yr(e){let t=[];function n(o,r){if(Ne(o))for(let i of ur(o,{withFileTypes:!0})){if(i.name.startsWith(".")||r===""&&hr.has(i.name))continue;let s=Le(o,i.name);if(i.isDirectory())n(s,r?`${r}/${i.name}`:i.name);else if(i.isFile()){let a=i.name.lastIndexOf("."),c=a===-1?"":i.name.slice(a);gr.has(c)&&t.push(s)}}}return n(e,""),t}function qt(e){let t=e.replace(/[^a-zA-Z0-9._-]/g,"_");return Le(de,`${t}.json`)}function Sr(e){let t=qt(e);if(!Ne(t))return{files:{},last_synced_at:null};try{return JSON.parse(Xt(t,"utf-8"))}catch{return{files:{},last_synced_at:null}}}function kr(e,t){lr(de,{recursive:!0}),dr(qt(e),JSON.stringify(t,null,2)+`
88
- `,"utf-8")}function xr(e,t){return fr(e,t).split(mr).join("/")}async function br(e,t){try{let n=await fetch(`${e}/api/cli/actions/fetch`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:t},body:JSON.stringify({})});if(!n.ok){let r=await n.text().catch(()=>"");return{ok:!1,actions:[],error:`${n.status} ${r.slice(0,200)}`}}let o=await n.json().catch(()=>null);return!o||o.status!=="ok"||!Array.isArray(o.actions)?{ok:!1,actions:[],error:"Malformed response"}:{ok:!0,actions:o.actions}}catch(n){return{ok:!1,actions:[],error:n.message}}}async function vr(e,t,n){try{let o=await fetch(`${e}/api/cli/sync`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:n},body:JSON.stringify(t)});if(!o.ok){let r=await o.text().catch(()=>"");return{ok:!1,status:o.status,error:r.slice(0,200)}}return{ok:!0,status:o.status}}catch(o){return{ok:!1,status:0,error:o.message}}}async function Zt(e,t={}){let n=w();if(!n)return{ok:!0,reason:"no-auth",synced:0,failed:0,errors:[]};let o=g(e);if(!o)return{ok:!0,reason:"no-project",synced:0,failed:0,errors:[]};let r=Le(e,m);if(!Ne(r))return{ok:!0,reason:"no-project",synced:0,failed:0,errors:[]};let i=Sr(o.domain),s=yr(r),a=n.api_base||k.BASE,c=`Bearer ${n.user_token}:${n.website_token}`,u=0,p=0,d=[],h=0;if(!t.pullOnly)for(let f of s){let U=xr(r,f);if(t.pathFilter&&!U.endsWith(t.pathFilter))continue;let H=pr(f),ue=i.files[U];if(!(!ue||ue.mtime!==H.mtimeMs||ue.size!==H.size)&&!t.force)continue;h++;let ln=Xt(f,"utf-8"),pe=await vr(a,{path:U,contents:ln,domain:o.domain},c);pe.ok?(i.files[U]={mtime:H.mtimeMs,size:H.size},u++):(p++,d.push(`${U}: ${pe.status} ${pe.error??""}`.trim()))}let A=await br(a,c),ae=0,ce=0;if(A.ok){let f=Bt(e,A.actions);ae=f.wrote,ce=f.removed}else A.error&&d.push(`pull actions: ${A.error}`);let b,le=!1,Ge=i.last_synced_at;if(!t.pushOnly){let f=await Jt({projectDir:e,apiBase:a,authHeader:c,since:i.last_synced_at,stateFiles:i.files,force:t.force});f.ok?Ge=f.cursor:(le=!0,f.error&&d.push(`pull: ${f.error}`)),b={written:f.written,overwritten:f.overwritten,skipped:f.skipped,conflicts:f.conflicts,deleted:f.deleted,warnings:f.warnings}}let cn=!!b&&b.written+b.overwritten+b.deleted+b.conflicts>0;if(i.last_synced_at=Ge,kr(o.domain,i),h===0&&ae===0&&ce===0&&!cn&&!le&&p===0)return{ok:!0,reason:"no-changes",synced:0,failed:0,errors:d,actionsPulled:0,actionsRemoved:0,pull:b};let We=p===0&&!le;return{ok:We,reason:We?void 0:"error",synced:u,failed:p,errors:d,actionsPulled:ae,actionsRemoved:ce,pull:b}}async function K(e={}){let t=await Zt(process.cwd(),{pathFilter:e.path,force:e.force,pushOnly:e.pushOnly,pullOnly:e.pullOnly});if(e.silent){t.ok||(process.exitCode=0);return}if(t.reason==="no-auth"){l.info("Not logged in. Run `npx @seoagent-official/seoagent login` to enable cloud sync.");return}if(t.reason==="no-project"){l.info("No SEOAgent project here. Run `npx @seoagent-official/seoagent init` first.");return}if(t.reason==="no-changes"){l.info("Already in sync.");return}t.synced>0&&l.success(`Synced ${t.synced} file${t.synced===1?"":"s"} to your dashboard.`);let n=t.pull;if(n){let o=n.written+n.overwritten;o>0&&l.success(`Pulled ${o} file${o===1?"":"s"} from the cloud`+(n.overwritten>0?` (${n.overwritten} updated)`:"")),n.deleted>0&&l.info(`Removed ${n.deleted} file${n.deleted===1?"":"s"} deleted in the cloud.`),n.conflicts>0&&l.warn(`${n.conflicts} conflict${n.conflicts===1?"":"s"} \u2014 local changes kept. Re-run with --force to take the cloud version.`);for(let r of n.warnings.slice(0,5))l.info(` \u2022 ${r}`)}if(t.actionsPulled&&t.actionsPulled>0&&(l.success(`Pulled ${t.actionsPulled} pending action${t.actionsPulled===1?"":"s"} \u2192 .seoagent/inbox/`),l.info(' Open Claude Code in this directory and ask it to "process the inbox", or read the files yourself.')),t.actionsRemoved&&t.actionsRemoved>0&&l.info(`Cleaned up ${t.actionsRemoved} stale inbox file${t.actionsRemoved===1?"":"s"}.`),t.failed>0){l.warn(`${t.failed} file${t.failed===1?"":"s"} failed to sync. Will retry next run.`);for(let o of t.errors.slice(0,3))l.info(` \u2022 ${o}`)}}async function Fe(e={}){if(e.print){let t=w();if(!t){l.error("Not logged in. Run `npx @seoagent-official/seoagent login` first."),process.exitCode=1;return}if(!g(process.cwd())){l.error("No SEOAgent project here. Run `npx @seoagent-official/seoagent init` first."),process.exitCode=1;return}let o=t.api_base||k.BASE,r=await zt({apiBase:o,authHeader:`Bearer ${t.user_token}:${t.website_token}`,path:e.print});if(!r.ok){l.warn(r.error),process.exitCode=1;return}process.stdout.write(r.body),r.body.endsWith(`
132
+ `}function Gt(e,t){let n=Oe(e);zo(n,{recursive:!0});let o=new Set(t.map(s=>s.id)),r=Jo(n,o),i=0;for(let s of t){let a=Zo(s);a!==null&&(Mt(ie(n,Bt(s)),a,"utf-8"),i++)}return Mt(ie(n,"README.md"),Qo(t),"utf-8"),{wrote:i,removed:r,inboxPath:n}}import{createHash as nr}from"crypto";import{existsSync as Ht,mkdirSync as or,readFileSync as rr,statSync as zt,writeFileSync as Kt,rmSync as ir}from"fs";import{dirname as sr,join as je,sep as ar}from"path";function er(e){return e.replace(/^\/+/,"").replace(/\\/g,"/")}var tr=[{cls:"project",test:e=>e==="project.md"},{cls:"audit",test:e=>e==="audit/latest.md"||/^audit\/(critical|high|medium|low)\.md$/.test(e)},{cls:"brief",test:e=>/^briefs\/[^/]+\.md$/.test(e)},{cls:"article",test:e=>/^content\/[^/]+\.md$/.test(e)},{cls:"cluster",test:e=>/^strategy\/clusters\/[^/]+\.md$/.test(e)},{cls:"keywords",test:e=>e==="keywords.md"||/^strategy\/keywords\/[^/]+\.md$/.test(e)},{cls:"pages",test:e=>e==="pages.md"||/^pages\/[^/]+\.md$/.test(e)},{cls:"competitors",test:e=>e==="competitors.md"},{cls:"changelog",test:e=>e==="changelog.md"}];function Wt(e,t){let n=er(e);for(let{cls:o,test:r}of tr)if(r(n))return t&&(o==="keywords"||o==="pages")?"generated-index":o;return"other"}function cr(e){return"sha256:"+nr("sha256").update(e).digest("hex")}function lr(e,t,n={}){let o=[];for(let r of e.artifacts){let i=t[r.path]??{exists:!1,locallyEdited:!1};if(!i.exists){o.push({path:r.path,kind:"write",body:r.body_md});continue}if(i.contentHash===r.content_hash){o.push({path:r.path,kind:"skip"});continue}if(r.generated){o.push({path:r.path,kind:"overwrite",body:r.body_md,note:i.locallyEdited?"discarded local edits \u2014 this is a cloud-generated file (edit it in the dashboard)":void 0});continue}if(i.locallyEdited&&!n.force){o.push({path:r.path,kind:"conflict",note:"local newer than cloud, keeping local \u2014 use --force to take cloud"});continue}o.push({path:r.path,kind:"overwrite",body:r.body_md})}for(let r of e.deleted){let i=t[r];if(!(!i||!i.exists)){if(i.locallyEdited&&!n.force){o.push({path:r,kind:"delete-skipped",note:"server deleted this but it has local edits \u2014 keeping it (use --force to delete)"});continue}o.push({path:r,kind:"delete"})}}return o}function ur(e,t,n,o){let r=new Map;for(let s of t.artifacts)r.set(s.path,s.generated);let i=[];for(let s of e)s.kind!=="skip"&&i.push({path:s.path,kind:s.kind,class:Wt(s.path,r.get(s.path)??!1),...s.note?{note:s.note}:{}});return i.length===0?null:{pulled_at:o,cursor:n,changes:i}}async function Yt(e){let t=await Jt({apiBase:e.apiBase,authHeader:e.authHeader,since:null,fetchImpl:e.fetchImpl});if(!t.ok)return{ok:!1,error:t.error};let n=e.path.replace(/^\/+/,"").replace(/\\/g,"/"),o=t.manifest.artifacts.find(r=>r.path===n);return o?{ok:!0,body:o.body_md}:{ok:!1,error:`No cloud artifact found at "${n}"`}}function Vt(e,t){return je(e,t.split("/").join(ar))}function pr(e,t,n){let o={};for(let r of t){let i=Vt(e,r);if(!Ht(i)){o[r]={exists:!1,locallyEdited:!1};continue}let s=zt(i),a=n[r],l=!a||a.mtime!==s.mtimeMs||a.size!==s.size;o[r]={exists:!0,contentHash:cr(rr(i,"utf-8")),locallyEdited:l}}return o}async function Jt(e){let t=e.fetchImpl??fetch,n=`${e.apiBase}/api/cli/sync`+(e.since?`?since=${encodeURIComponent(e.since)}`:"");try{let o=await t(n,{method:"GET",headers:{Authorization:e.authHeader,Accept:"application/json"}});if(!o.ok){let i=await o.text().catch(()=>"");return{ok:!1,error:`${o.status} ${i.slice(0,200)}`.trim()}}let r=await o.json().catch(()=>null);return!r||!Array.isArray(r.artifacts)||typeof r.now!="string"?{ok:!1,error:"Malformed manifest response"}:(Array.isArray(r.deleted)||(r.deleted=[]),{ok:!0,manifest:r})}catch(o){return{ok:!1,error:o.message}}}async function Xt(e){let t=je(e.projectDir,g),n={ok:!0,written:0,overwritten:0,skipped:0,conflicts:0,deleted:0,warnings:[],cursor:e.since};if(!Ht(t))return{...n,ok:!0};let o=await Jt({apiBase:e.apiBase,authHeader:e.authHeader,since:e.since,fetchImpl:e.fetchImpl});if(!o.ok)return{...n,ok:!1,error:o.error};let r=o.manifest,i=[...r.artifacts.map(p=>p.path),...r.deleted],s=pr(t,i,e.stateFiles),a=lr(r,s,{force:e.force}),l={...n,cursor:r.now};for(let p of a){let d=Vt(t,p.path);try{switch(p.kind){case"skip":l.skipped++;break;case"write":case"overwrite":{or(sr(d),{recursive:!0}),Kt(d,p.body??"","utf-8");let h=zt(d);e.stateFiles[p.path]={mtime:h.mtimeMs,size:h.size},p.kind==="write"?l.written++:l.overwritten++,p.note&&l.warnings.push(`${p.path}: ${p.note}`);break}case"conflict":l.conflicts++,l.warnings.push(`${p.path}: ${p.note??"conflict"}`);break;case"delete":ir(d,{force:!0}),delete e.stateFiles[p.path],l.deleted++;break;case"delete-skipped":l.conflicts++,l.warnings.push(`${p.path}: ${p.note??"delete skipped"}`);break}}catch(h){l.ok=!1,l.error=`${p.path}: ${h.message}`}}(l.conflicts>0||!l.ok)&&(l.cursor=e.since);let u=ur(a,r,l.cursor,new Date().toISOString());if(u)try{Kt(je(t,Ye),JSON.stringify(u,null,2)+`
133
+ `,"utf-8")}catch{}return l}var Sr=new Set([".md"]),kr=new Set(["inbox"]);function xr(e){let t=[];function n(o,r){if(Ne(o))for(let i of fr(o,{withFileTypes:!0})){if(i.name.startsWith(".")||r===""&&kr.has(i.name))continue;let s=Le(o,i.name);if(i.isDirectory())n(s,r?`${r}/${i.name}`:i.name);else if(i.isFile()){let a=i.name.lastIndexOf("."),l=a===-1?"":i.name.slice(a);Sr.has(l)&&t.push(s)}}}return n(e,""),t}function Zt(e){let t=e.replace(/[^a-zA-Z0-9._-]/g,"_");return Le(de,`${t}.json`)}function br(e){let t=Zt(e);if(!Ne(t))return{files:{},last_synced_at:null};try{return JSON.parse(qt(t,"utf-8"))}catch{return{files:{},last_synced_at:null}}}function vr(e,t){dr(de,{recursive:!0}),gr(Zt(e),JSON.stringify(t,null,2)+`
134
+ `,"utf-8")}function wr(e,t){return hr(e,t).split(yr).join("/")}async function _r(e,t){try{let n=await fetch(`${e}/api/cli/actions/fetch`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:t},body:JSON.stringify({})});if(!n.ok){let r=await n.text().catch(()=>"");return{ok:!1,actions:[],error:`${n.status} ${r.slice(0,200)}`}}let o=await n.json().catch(()=>null);return!o||o.status!=="ok"||!Array.isArray(o.actions)?{ok:!1,actions:[],error:"Malformed response"}:{ok:!0,actions:o.actions}}catch(n){return{ok:!1,actions:[],error:n.message}}}async function Er(e,t,n){try{let o=await fetch(`${e}/api/cli/sync`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:n},body:JSON.stringify(t)});if(!o.ok){let r=await o.text().catch(()=>"");return{ok:!1,status:o.status,error:r.slice(0,200)}}return{ok:!0,status:o.status}}catch(o){return{ok:!1,status:0,error:o.message}}}async function Qt(e,t={}){let n=x();if(!n)return{ok:!0,reason:"no-auth",synced:0,failed:0,errors:[]};let o=f(e);if(!o)return{ok:!0,reason:"no-project",synced:0,failed:0,errors:[]};let r=Le(e,g);if(!Ne(r))return{ok:!0,reason:"no-project",synced:0,failed:0,errors:[]};let i=br(o.domain),s=xr(r),a=n.api_base||S.BASE,l=`Bearer ${n.user_token}:${n.website_token}`,u=0,p=0,d=[],h=0;if(!t.pullOnly)for(let m of s){let U=wr(r,m);if(t.pathFilter&&!U.endsWith(t.pathFilter))continue;let H=mr(m),ue=i.files[U];if(!(!ue||ue.mtime!==H.mtimeMs||ue.size!==H.size)&&!t.force)continue;h++;let un=qt(m,"utf-8"),pe=await Er(a,{path:U,contents:un,domain:o.domain},l);pe.ok?(i.files[U]={mtime:H.mtimeMs,size:H.size},u++):(p++,d.push(`${U}: ${pe.status} ${pe.error??""}`.trim()))}let A=await _r(a,l),ae=0,ce=0;if(A.ok){let m=Gt(e,A.actions);ae=m.wrote,ce=m.removed}else A.error&&d.push(`pull actions: ${A.error}`);let v,le=!1,We=i.last_synced_at;if(!t.pushOnly){let m=await Xt({projectDir:e,apiBase:a,authHeader:l,since:i.last_synced_at,stateFiles:i.files,force:t.force});m.ok?We=m.cursor:(le=!0,m.error&&d.push(`pull: ${m.error}`)),v={written:m.written,overwritten:m.overwritten,skipped:m.skipped,conflicts:m.conflicts,deleted:m.deleted,warnings:m.warnings}}let ln=!!v&&v.written+v.overwritten+v.deleted+v.conflicts>0;if(i.last_synced_at=We,vr(o.domain,i),h===0&&ae===0&&ce===0&&!ln&&!le&&p===0)return{ok:!0,reason:"no-changes",synced:0,failed:0,errors:d,actionsPulled:0,actionsRemoved:0,pull:v};let Ke=p===0&&!le;return{ok:Ke,reason:Ke?void 0:"error",synced:u,failed:p,errors:d,actionsPulled:ae,actionsRemoved:ce,pull:v}}async function K(e={}){let t=await Qt(process.cwd(),{pathFilter:e.path,force:e.force,pushOnly:e.pushOnly,pullOnly:e.pullOnly});if(e.silent){t.ok||(process.exitCode=0);return}if(t.reason==="no-auth"){c.info("Not logged in. Run `npx @seoagent-official/seoagent login` to enable cloud sync.");return}if(t.reason==="no-project"){c.info("No SEOAgent project here. Run `npx @seoagent-official/seoagent init` first.");return}if(t.reason==="no-changes"){c.info("Already in sync.");return}t.synced>0&&c.success(`Synced ${t.synced} file${t.synced===1?"":"s"} to your dashboard.`);let n=t.pull;if(n){let o=n.written+n.overwritten;o>0&&c.success(`Pulled ${o} file${o===1?"":"s"} from the cloud`+(n.overwritten>0?` (${n.overwritten} updated)`:"")),n.deleted>0&&c.info(`Removed ${n.deleted} file${n.deleted===1?"":"s"} deleted in the cloud.`),n.conflicts>0&&c.warn(`${n.conflicts} conflict${n.conflicts===1?"":"s"} \u2014 local changes kept. Re-run with --force to take the cloud version.`);for(let r of n.warnings.slice(0,5))c.info(` \u2022 ${r}`)}if(t.actionsPulled&&t.actionsPulled>0&&(c.success(`Pulled ${t.actionsPulled} pending action${t.actionsPulled===1?"":"s"} \u2192 .seoagent/inbox/`),c.info(' Open Claude Code in this directory and ask it to "process the inbox", or read the files yourself.')),t.actionsRemoved&&t.actionsRemoved>0&&c.info(`Cleaned up ${t.actionsRemoved} stale inbox file${t.actionsRemoved===1?"":"s"}.`),t.failed>0){c.warn(`${t.failed} file${t.failed===1?"":"s"} failed to sync. Will retry next run.`);for(let o of t.errors.slice(0,3))c.info(` \u2022 ${o}`)}}async function Fe(e={}){if(e.print){let t=x();if(!t){c.error("Not logged in. Run `npx @seoagent-official/seoagent login` first."),process.exitCode=1;return}if(!f(process.cwd())){c.error("No SEOAgent project here. Run `npx @seoagent-official/seoagent init` first."),process.exitCode=1;return}let o=t.api_base||S.BASE,r=await Yt({apiBase:o,authHeader:`Bearer ${t.user_token}:${t.website_token}`,path:e.print});if(!r.ok){c.warn(r.error),process.exitCode=1;return}process.stdout.write(r.body),r.body.endsWith(`
89
135
  `)||process.stdout.write(`
90
- `);return}await K({pullOnly:!0,force:e.force,silent:e.silent})}import{existsSync as wr,readdirSync as _r,unlinkSync as Er}from"fs";import{join as Qt}from"path";async function Ue(e,t={}){let n=Number.parseInt(e,10);if(Number.isNaN(n)||n<=0){l.error(`Invalid action id: "${e}"`),process.exitCode=1;return}let o=w();if(!o){l.error("Not logged in. Run `npx @seoagent-official/seoagent login` first."),process.exitCode=1;return}if(!g(process.cwd())){l.error("No SEOAgent project here. Run `npx @seoagent-official/seoagent init` first."),process.exitCode=1;return}let i=o.api_base||k.BASE,s=`Bearer ${o.user_token}:${o.website_token}`,a=t.failed?"failed":"completed",c;try{c=await fetch(`${i}/api/cli/actions/${n}/ack`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:s},body:JSON.stringify({status:a,error_message:t.failed&&t.reason?t.reason:null,result:t.failed?{declined:!0,reason:t.reason??null}:{applied:!0}})})}catch(p){l.error(`Network error: ${p.message}`),process.exitCode=1;return}if(!c.ok){let p=await c.text().catch(()=>"");l.error(`Server rejected ack (${c.status}): ${p.slice(0,200)}`),process.exitCode=1;return}let u=Oe(process.cwd());if(wr(u)){for(let p of _r(u))if(p.endsWith(`-${n}.md`))try{Er(Qt(u,p))}catch{}}t.failed?l.success(`Action ${n} marked failed${t.reason?` (reason: ${t.reason})`:""}.`):l.success(`Action ${n} marked completed.`),l.info(` inbox location: ${Qt(m,"inbox")}`)}import{existsSync as Pr,readFileSync as Ir}from"fs";import{join as Ar}from"path";var en=["openai","fal","replicate"],F={openai:["OPENAI_API_KEY"],fal:["FAL_KEY","FAL_API_KEY"],replicate:["REPLICATE_API_TOKEN","REPLICATE_API_KEY"]};function Cr(e){let t={};if(!Pr(e))return t;let n=Ir(e,"utf-8");for(let o of n.split(/\r?\n/)){let r=o.trim();if(!r||r.startsWith("#"))continue;let i=r.indexOf("=");if(i===-1)continue;let s=r.slice(0,i).trim(),a=r.slice(i+1).trim();(a.startsWith('"')&&a.endsWith('"')||a.startsWith("'")&&a.endsWith("'"))&&(a=a.slice(1,-1)),t[s]=a}return t}function tn(e,t){let n={};for(let o of t){let r=process.env[o];r&&r.trim().length>0&&(n[o]={value:r,source:"process"})}for(let o of C){let r=Ar(e,o),i=Cr(r);for(let s of t){if(n[s])continue;let a=i[s];a&&a.length>0&&(n[s]={value:a,source:o})}}return{found:n}}function se(e){let t=[].concat(...en.map(a=>F[a])),n=tn(e,t),o=[];for(let a of en)F[a].some(c=>n.found[c])&&o.push(a);if(o.length===0)return{provider:"none",matched_key:null,source:null,available_providers:[]};let r=o[0],i=F[r].find(a=>n.found[a])??null,s=i?n.found[i].source:null;return{provider:r,matched_key:i,source:s,available_providers:o}}function nn(e,t){let n=tn(e,F[t]);for(let o of F[t])if(n.found[o])return{key:n.found[o].value,envName:o};return null}function on(){return F}function De(e={}){let t=process.cwd(),n=g(t),o=se(t);if(e.json){process.stdout.write(JSON.stringify(o,null,2)+`
91
- `);return}if(l.message("SEOAgent environment check"),o.provider==="none"){l.info("Image provider: none detected."),l.info("To enable image generation in the free tier, set ONE of:");let r=on();for(let i of Object.keys(r))l.info(` \u2022 ${i}: ${r[i].join(" or ")}`);l.info("Add to your shell, .env.local, or .env. Then re-run `npx @seoagent-official/seoagent env-check`.")}else l.success(`Image provider: ${o.provider} (${o.matched_key} from ${o.source}).`),o.available_providers.length>1&&l.info(`Other providers available: ${o.available_providers.filter(r=>r!==o.provider).join(", ")}.`);if(!n){l.warn("No SEOAgent project here. Run `npx @seoagent-official/seoagent init` first to persist the provider.");return}Qe(t,{image_provider:o.provider}),l.info(`Saved to .seoagent/project.md (image_provider: ${o.provider}).`)}import{existsSync as jr,mkdirSync as Nr,writeFileSync as Lr}from"fs";import{dirname as an,isAbsolute as Fr,resolve as Ur}from"path";import{Buffer as rn}from"buffer";async function Me(e){let t=await fetch(e);if(!t.ok)throw new Error(`Image download failed: ${t.status} ${t.statusText}`);let n=await t.arrayBuffer();return rn.from(n)}async function Tr(e){let t=e.size??"1024x1024",n=await fetch("https://api.openai.com/v1/images/generations",{method:"POST",headers:{Authorization:`Bearer ${e.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({model:"gpt-image-1",prompt:e.prompt,size:t,n:1,response_format:"b64_json"})});if(!n.ok){let i=await n.text().catch(()=>"");throw new Error(`OpenAI image API ${n.status}: ${i.slice(0,300)}`)}let r=(await n.json()).data?.[0];if(!r)throw new Error("OpenAI image API returned no data");if(r.b64_json)return{bytes:rn.from(r.b64_json,"base64"),contentType:"image/png"};if(r.url)return{bytes:await Me(r.url),contentType:"image/png"};throw new Error("OpenAI image API returned neither b64_json nor url")}async function Rr(e){let t=process.env.FAL_MODEL||"fal-ai/flux/schnell",n=await fetch(`https://fal.run/${t}`,{method:"POST",headers:{Authorization:`Key ${e.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({prompt:e.prompt,image_size:"landscape_16_9",num_images:1})});if(!n.ok){let s=await n.text().catch(()=>"");throw new Error(`fal.ai API ${n.status}: ${s.slice(0,300)}`)}let r=(await n.json()).images?.[0];if(!r?.url)throw new Error("fal.ai API returned no image url");return{bytes:await Me(r.url),contentType:r.content_type??"image/png"}}async function $r(e,t,n=9e4){let o=Date.now(),r=1e3;for(;Date.now()-o<n;){let i=await fetch(`https://api.replicate.com/v1/predictions/${e}`,{headers:{Authorization:`Token ${t}`}});if(!i.ok)throw new Error(`Replicate poll failed: ${i.status}`);let s=await i.json();if(s.status==="succeeded"||s.status==="failed"||s.status==="canceled")return s;await new Promise(a=>setTimeout(a,r)),r=Math.min(r*1.5,5e3)}throw new Error("Replicate prediction timed out")}async function Or(e){let t=process.env.REPLICATE_MODEL||"black-forest-labs/flux-schnell",n=await fetch(`https://api.replicate.com/v1/models/${t}/predictions`,{method:"POST",headers:{Authorization:`Token ${e.apiKey}`,"Content-Type":"application/json",Prefer:"wait"},body:JSON.stringify({input:{prompt:e.prompt,aspect_ratio:"16:9"}})});if(!n.ok){let s=await n.text().catch(()=>"");throw new Error(`Replicate API ${n.status}: ${s.slice(0,300)}`)}let o=await n.json();if(o.status!=="succeeded"&&o.status!=="failed"&&(o=await $r(o.id,e.apiKey)),o.status!=="succeeded")throw new Error(`Replicate prediction ${o.status}: ${o.error??""}`);let r=Array.isArray(o.output)?o.output[0]:o.output;if(!r)throw new Error("Replicate prediction returned no output");return{bytes:await Me(r),contentType:"image/png",providerImageId:o.id}}async function sn(e,t){switch(e){case"openai":return Tr(t);case"fal":return Rr(t);case"replicate":return Or(t);default:throw new Error(`Unknown image provider: ${e}`)}}function Dr(e){return e==="openai"||e==="fal"||e==="replicate"}async function Be(e={}){let t=process.cwd();if(!e.prompt){l.warn('Missing --prompt. Example: npx @seoagent-official/seoagent generate-image --prompt "..." --out content/images/hero.png'),process.exitCode=1;return}if(!e.out){l.warn("Missing --out. Example: --out .seoagent/content/images/hero.png"),process.exitCode=1;return}let n=g(t),o=null;if(e.provider){if(!Dr(e.provider)){l.warn(`Invalid --provider "${e.provider}". Use one of: openai, fal, replicate.`),process.exitCode=1;return}o=e.provider}else n?.image_provider&&n.image_provider!=="none"?o=n.image_provider:o=se(t).provider;if(!o||o==="none"){l.warn("No image generation provider available. Set OPENAI_API_KEY, FAL_KEY, or REPLICATE_API_TOKEN, then run `npx @seoagent-official/seoagent env-check`."),process.exitCode=1;return}let r=nn(t,o);if(!r){l.warn(`Provider "${o}" selected but no API key found. Set the env var, then re-run.`),process.exitCode=1;return}let i=Fr(e.out)?e.out:Ur(t,e.out);e.silent||l.info(`Generating image with ${o} (${r.envName})...`);try{let s=await sn(o,{prompt:e.prompt,apiKey:r.key,size:e.size});jr(an(i))||Nr(an(i),{recursive:!0}),Lr(i,s.bytes),e.silent||l.success(`Wrote ${i} (${s.bytes.length} bytes, ${s.contentType}).`)}catch(s){l.warn(`Image generation failed: ${s.message}`),process.exitCode=1}}var y=new Mr;y.name("seoagent").description("AI SEO agent for Claude Code").version(V);y.command("init").description("Initialize SEOAgent project \u2014 creates .seoagent/ and installs the skill file").option("-y, --yes","Non-interactive: use inferred/env/flag values only (requires domain if not inferable)").option("--domain <domain>","Website domain (non-interactive or override)").option("--site-type <type>","Site type: saas, service, product, content, etc.").action(e=>{Ee({yes:e.yes,domain:e.domain,siteType:e.siteType})});y.command("uninstall").description("Remove SEOAgent from this project \u2014 deletes .seoagent/, the skill bundle, and the sync hook").option("-y, --yes","Skip the confirmation prompt (also implied in a non-TTY shell)").option("--global","Also wipe ~/.config/seoagent (login + sync state, all projects)").action(e=>{Pe({yes:e.yes,global:e.global})});y.command("status").description("Show current SEO project state").action(Ce);y.command("login").description("Connect this CLI to your seoagent.com account (browser flow)").option("--api-base <url>","Override API base URL (for testing)").action(e=>{Re({apiBase:e.apiBase})});y.command("logout").description("Remove stored credentials for seoagent.com").action($e);y.command("sync").description("Sync .seoagent/ with your dashboard \u2014 push local changes then pull cloud changes (no-op when not logged in)").option("--silent","Suppress output (used by the Claude Code hook)").option("--force","Re-send every artifact on push; take cloud on every pull conflict").option("--path <relpath>","Push only files matching this path suffix").option("--push-only","Skip the cloud \u2192 local pull pass").option("--pull-only","Skip the local \u2192 cloud push pass (same as `seoagent pull`)").action(e=>{K({silent:e.silent,force:e.force,path:e.path,pushOnly:e.pushOnly,pullOnly:e.pullOnly})});y.command("pull").description("Pull cloud changes into .seoagent/ (dashboard / autopilot / chat edits)").option("--silent","Suppress output").option("--force","Take the cloud version on every conflict (discards local edits)").option("--print <path>","Read-only: print the current cloud body of one artifact to stdout (writes nothing). For conflict diffs.").action(e=>{Fe({force:e.force,silent:e.silent,print:e.print})});y.command("ack <action_id>").description("Close out a pending action from .seoagent/inbox/ (server marks completed)").option("--failed","Mark as failed instead of completed").option("--reason <text>","Reason for failure (used with --failed)").action((e,t)=>{Ue(e,{failed:t.failed,reason:t.reason})});y.command("env-check").description("Detect which image generation provider is available (OPENAI / FAL / REPLICATE)").option("--json","Output detection result as JSON").action(e=>{De({json:e.json})});y.command("generate-image").description("Generate an image via the detected (or explicit) provider").requiredOption("--prompt <text>","Image prompt").requiredOption("--out <path>","Output file path (relative to cwd or absolute)").option("--provider <name>","Force provider: openai | fal | replicate").option("--size <wxh>","Pixel size hint, e.g. 1024x1024").option("--silent","Suppress progress output").action(e=>{Be({prompt:e.prompt,out:e.out,provider:e.provider,size:e.size,silent:e.silent})});y.command("upgrade").description("Open SEOAgent Cloud pricing page").action(Te);y.parse();
136
+ `);return}await K({pullOnly:!0,force:e.force,silent:e.silent})}import{existsSync as Ir,readdirSync as Pr,unlinkSync as Ar}from"fs";import{join as en}from"path";async function Ue(e,t={}){let n=Number.parseInt(e,10);if(Number.isNaN(n)||n<=0){c.error(`Invalid action id: "${e}"`),process.exitCode=1;return}let o=x();if(!o){c.error("Not logged in. Run `npx @seoagent-official/seoagent login` first."),process.exitCode=1;return}if(!f(process.cwd())){c.error("No SEOAgent project here. Run `npx @seoagent-official/seoagent init` first."),process.exitCode=1;return}let i=o.api_base||S.BASE,s=`Bearer ${o.user_token}:${o.website_token}`,a=t.failed?"failed":"completed",l;try{l=await fetch(`${i}/api/cli/actions/${n}/ack`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:s},body:JSON.stringify({status:a,error_message:t.failed&&t.reason?t.reason:null,result:t.failed?{declined:!0,reason:t.reason??null}:{applied:!0}})})}catch(p){c.error(`Network error: ${p.message}`),process.exitCode=1;return}if(!l.ok){let p=await l.text().catch(()=>"");c.error(`Server rejected ack (${l.status}): ${p.slice(0,200)}`),process.exitCode=1;return}let u=Oe(process.cwd());if(Ir(u)){for(let p of Pr(u))if(p.endsWith(`-${n}.md`))try{Ar(en(u,p))}catch{}}t.failed?c.success(`Action ${n} marked failed${t.reason?` (reason: ${t.reason})`:""}.`):c.success(`Action ${n} marked completed.`),c.info(` inbox location: ${en(g,"inbox")}`)}var Cr=new Set(["on","off","status"]);async function De(e,t={}){let n=(e||"").toLowerCase();if(!Cr.has(n)){c.error(`Usage: seoagent autopilot <on|off|status> (got "${e}")`),process.exitCode=1;return}let o=x();if(!o){c.error("Not logged in. Run `npx @seoagent-official/seoagent login` first."),process.exitCode=1;return}let r=t.apiBase||o.api_base||S.BASE,i=`Bearer ${o.user_token}:${o.website_token}`,s;try{s=await fetch(`${r}/api/cli/autopilot/${n}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:i},body:"{}"})}catch(p){c.error(`Network error: ${p.message}`),process.exitCode=1;return}let a=null;try{a=await s.json()}catch{a=null}if(s.status===402||a?.code==="upgrade_required"){let d=f(process.cwd())?.domain??"",h=`${S.PRICING}?ref=cli${d?`&domain=${encodeURIComponent(d)}`:""}`;c.warn("CLI autopilot is a paid feature."),c.message("Upgrade to let SEOAgent continuously audit your site and queue fixes for your\ncoding agent to apply on each `seoagent sync` (you stay in the loop \u2014 nothing\nis auto-applied)."),c.message(`Upgrade: ${h}`),process.exitCode=1;return}if(!s.ok||a?.status!=="ok"||!a.autopilot){c.error(`Server rejected request (${s.status})${a?.error?`: ${a.error}`:""}`),process.exitCode=1;return}let{enabled:l,delivery_mode:u}=a.autopilot;if(n==="on"){c.success("CLI autopilot is ON."),c.message('SEOAgent will queue suggested fixes to `.seoagent/inbox/`. Run `seoagent sync`\n(or just ask Claude Code to "process the inbox") to review and apply them.');return}if(n==="off"){c.success("CLI autopilot is OFF. No new suggestions will be queued.");return}l&&u==="cli_queue"?c.success("CLI autopilot: ON (queueing fixes for your coding agent)."):l?c.info(`CLI autopilot: ON (delivery mode: ${u??"unknown"}).`):(c.info("CLI autopilot: OFF."),c.message("Run `seoagent autopilot on` to enable (paid)."))}import{existsSync as $r,readFileSync as Rr}from"fs";import{join as Tr}from"path";var tn=["openai","fal","replicate"],F={openai:["OPENAI_API_KEY"],fal:["FAL_KEY","FAL_API_KEY"],replicate:["REPLICATE_API_TOKEN","REPLICATE_API_KEY"]};function Or(e){let t={};if(!$r(e))return t;let n=Rr(e,"utf-8");for(let o of n.split(/\r?\n/)){let r=o.trim();if(!r||r.startsWith("#"))continue;let i=r.indexOf("=");if(i===-1)continue;let s=r.slice(0,i).trim(),a=r.slice(i+1).trim();(a.startsWith('"')&&a.endsWith('"')||a.startsWith("'")&&a.endsWith("'"))&&(a=a.slice(1,-1)),t[s]=a}return t}function nn(e,t){let n={};for(let o of t){let r=process.env[o];r&&r.trim().length>0&&(n[o]={value:r,source:"process"})}for(let o of C){let r=Tr(e,o),i=Or(r);for(let s of t){if(n[s])continue;let a=i[s];a&&a.length>0&&(n[s]={value:a,source:o})}}return{found:n}}function se(e){let t=[].concat(...tn.map(a=>F[a])),n=nn(e,t),o=[];for(let a of tn)F[a].some(l=>n.found[l])&&o.push(a);if(o.length===0)return{provider:"none",matched_key:null,source:null,available_providers:[]};let r=o[0],i=F[r].find(a=>n.found[a])??null,s=i?n.found[i].source:null;return{provider:r,matched_key:i,source:s,available_providers:o}}function on(e,t){let n=nn(e,F[t]);for(let o of F[t])if(n.found[o])return{key:n.found[o].value,envName:o};return null}function rn(){return F}function Me(e={}){let t=process.cwd(),n=f(t),o=se(t);if(e.json){process.stdout.write(JSON.stringify(o,null,2)+`
137
+ `);return}if(c.message("SEOAgent environment check"),o.provider==="none"){c.info("Image provider: none detected."),c.info("To enable image generation in the free tier, set ONE of:");let r=rn();for(let i of Object.keys(r))c.info(` \u2022 ${i}: ${r[i].join(" or ")}`);c.info("Add to your shell, .env.local, or .env. Then re-run `npx @seoagent-official/seoagent env-check`.")}else c.success(`Image provider: ${o.provider} (${o.matched_key} from ${o.source}).`),o.available_providers.length>1&&c.info(`Other providers available: ${o.available_providers.filter(r=>r!==o.provider).join(", ")}.`);if(!n){c.warn("No SEOAgent project here. Run `npx @seoagent-official/seoagent init` first to persist the provider.");return}et(t,{image_provider:o.provider}),c.info(`Saved to .seoagent/project.md (image_provider: ${o.provider}).`)}import{existsSync as Ur,mkdirSync as Dr,writeFileSync as Mr}from"fs";import{dirname as cn,isAbsolute as Br,resolve as Gr}from"path";import{Buffer as sn}from"buffer";async function Be(e){let t=await fetch(e);if(!t.ok)throw new Error(`Image download failed: ${t.status} ${t.statusText}`);let n=await t.arrayBuffer();return sn.from(n)}async function jr(e){let t=e.size??"1024x1024",n=await fetch("https://api.openai.com/v1/images/generations",{method:"POST",headers:{Authorization:`Bearer ${e.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({model:"gpt-image-1",prompt:e.prompt,size:t,n:1,response_format:"b64_json"})});if(!n.ok){let i=await n.text().catch(()=>"");throw new Error(`OpenAI image API ${n.status}: ${i.slice(0,300)}`)}let r=(await n.json()).data?.[0];if(!r)throw new Error("OpenAI image API returned no data");if(r.b64_json)return{bytes:sn.from(r.b64_json,"base64"),contentType:"image/png"};if(r.url)return{bytes:await Be(r.url),contentType:"image/png"};throw new Error("OpenAI image API returned neither b64_json nor url")}async function Nr(e){let t=process.env.FAL_MODEL||"fal-ai/flux/schnell",n=await fetch(`https://fal.run/${t}`,{method:"POST",headers:{Authorization:`Key ${e.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({prompt:e.prompt,image_size:"landscape_16_9",num_images:1})});if(!n.ok){let s=await n.text().catch(()=>"");throw new Error(`fal.ai API ${n.status}: ${s.slice(0,300)}`)}let r=(await n.json()).images?.[0];if(!r?.url)throw new Error("fal.ai API returned no image url");return{bytes:await Be(r.url),contentType:r.content_type??"image/png"}}async function Lr(e,t,n=9e4){let o=Date.now(),r=1e3;for(;Date.now()-o<n;){let i=await fetch(`https://api.replicate.com/v1/predictions/${e}`,{headers:{Authorization:`Token ${t}`}});if(!i.ok)throw new Error(`Replicate poll failed: ${i.status}`);let s=await i.json();if(s.status==="succeeded"||s.status==="failed"||s.status==="canceled")return s;await new Promise(a=>setTimeout(a,r)),r=Math.min(r*1.5,5e3)}throw new Error("Replicate prediction timed out")}async function Fr(e){let t=process.env.REPLICATE_MODEL||"black-forest-labs/flux-schnell",n=await fetch(`https://api.replicate.com/v1/models/${t}/predictions`,{method:"POST",headers:{Authorization:`Token ${e.apiKey}`,"Content-Type":"application/json",Prefer:"wait"},body:JSON.stringify({input:{prompt:e.prompt,aspect_ratio:"16:9"}})});if(!n.ok){let s=await n.text().catch(()=>"");throw new Error(`Replicate API ${n.status}: ${s.slice(0,300)}`)}let o=await n.json();if(o.status!=="succeeded"&&o.status!=="failed"&&(o=await Lr(o.id,e.apiKey)),o.status!=="succeeded")throw new Error(`Replicate prediction ${o.status}: ${o.error??""}`);let r=Array.isArray(o.output)?o.output[0]:o.output;if(!r)throw new Error("Replicate prediction returned no output");return{bytes:await Be(r),contentType:"image/png",providerImageId:o.id}}async function an(e,t){switch(e){case"openai":return jr(t);case"fal":return Nr(t);case"replicate":return Fr(t);default:throw new Error(`Unknown image provider: ${e}`)}}function Wr(e){return e==="openai"||e==="fal"||e==="replicate"}async function Ge(e={}){let t=process.cwd();if(!e.prompt){c.warn('Missing --prompt. Example: npx @seoagent-official/seoagent generate-image --prompt "..." --out content/images/hero.png'),process.exitCode=1;return}if(!e.out){c.warn("Missing --out. Example: --out .seoagent/content/images/hero.png"),process.exitCode=1;return}let n=f(t),o=null;if(e.provider){if(!Wr(e.provider)){c.warn(`Invalid --provider "${e.provider}". Use one of: openai, fal, replicate.`),process.exitCode=1;return}o=e.provider}else n?.image_provider&&n.image_provider!=="none"?o=n.image_provider:o=se(t).provider;if(!o||o==="none"){c.warn("No image generation provider available. Set OPENAI_API_KEY, FAL_KEY, or REPLICATE_API_TOKEN, then run `npx @seoagent-official/seoagent env-check`."),process.exitCode=1;return}let r=on(t,o);if(!r){c.warn(`Provider "${o}" selected but no API key found. Set the env var, then re-run.`),process.exitCode=1;return}let i=Br(e.out)?e.out:Gr(t,e.out);e.silent||c.info(`Generating image with ${o} (${r.envName})...`);try{let s=await an(o,{prompt:e.prompt,apiKey:r.key,size:e.size});Ur(cn(i))||Dr(cn(i),{recursive:!0}),Mr(i,s.bytes),e.silent||c.success(`Wrote ${i} (${s.bytes.length} bytes, ${s.contentType}).`)}catch(s){c.warn(`Image generation failed: ${s.message}`),process.exitCode=1}}var y=new Kr;y.name("seoagent").description("AI SEO agent for Claude Code").version(V);y.command("init").description("Initialize SEOAgent project \u2014 creates .seoagent/ and installs the skill file").option("-y, --yes","Non-interactive: use inferred/env/flag values only (requires domain if not inferable)").option("--domain <domain>","Website domain (non-interactive or override)").option("--site-type <type>","Site type: saas, service, product, content, etc.").action(e=>{Ee({yes:e.yes,domain:e.domain,siteType:e.siteType})});y.command("uninstall").description("Remove SEOAgent from this project \u2014 deletes .seoagent/, the skill bundle, and the sync hook").option("-y, --yes","Skip the confirmation prompt (also implied in a non-TTY shell)").option("--global","Also wipe ~/.config/seoagent (login + sync state, all projects)").action(e=>{Ie({yes:e.yes,global:e.global})});y.command("status").description("Show current SEO project state").action(Ce);y.command("login").description("Connect this CLI to your seoagent.com account (browser flow)").option("--api-base <url>","Override API base URL (for testing)").action(e=>{Re({apiBase:e.apiBase})});y.command("logout").description("Remove stored credentials for seoagent.com").action(Te);y.command("sync").description("Sync .seoagent/ with your dashboard \u2014 push local changes then pull cloud changes (no-op when not logged in)").option("--silent","Suppress output (used by the Claude Code hook)").option("--force","Re-send every artifact on push; take cloud on every pull conflict").option("--path <relpath>","Push only files matching this path suffix").option("--push-only","Skip the cloud \u2192 local pull pass").option("--pull-only","Skip the local \u2192 cloud push pass (same as `seoagent pull`)").action(e=>{K({silent:e.silent,force:e.force,path:e.path,pushOnly:e.pushOnly,pullOnly:e.pullOnly})});y.command("pull").description("Pull cloud changes into .seoagent/ (dashboard / autopilot / chat edits)").option("--silent","Suppress output").option("--force","Take the cloud version on every conflict (discards local edits)").option("--print <path>","Read-only: print the current cloud body of one artifact to stdout (writes nothing). For conflict diffs.").action(e=>{Fe({force:e.force,silent:e.silent,print:e.print})});y.command("ack <action_id>").description("Close out a pending action from .seoagent/inbox/ (server marks completed)").option("--failed","Mark as failed instead of completed").option("--reason <text>","Reason for failure (used with --failed)").action((e,t)=>{Ue(e,{failed:t.failed,reason:t.reason})});y.command("autopilot <action>").description("Turn CLI autopilot on|off or show status (paid; queues fixes for your agent)").option("--api-base <url>","Override API base URL (for testing)").action((e,t)=>{De(e,{apiBase:t.apiBase})});y.command("env-check").description("Detect which image generation provider is available (OPENAI / FAL / REPLICATE)").option("--json","Output detection result as JSON").action(e=>{Me({json:e.json})});y.command("generate-image").description("Generate an image via the detected (or explicit) provider").requiredOption("--prompt <text>","Image prompt").requiredOption("--out <path>","Output file path (relative to cwd or absolute)").option("--provider <name>","Force provider: openai | fal | replicate").option("--size <wxh>","Pixel size hint, e.g. 1024x1024").option("--silent","Suppress progress output").action(e=>{Ge({prompt:e.prompt,out:e.out,provider:e.provider,size:e.size,silent:e.silent})});y.command("upgrade").description("Open SEOAgent Cloud pricing page").action($e);y.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seoagent-official/seoagent",
3
- "version": "1.22.1",
3
+ "version": "1.23.0",
4
4
  "description": "Scaffolder for Claude Code's SEOAgent skill. Run once: `npx -y @seoagent-official/seoagent init`. Sets up .seoagent/ for persistent audits, keyword strategy, content planning, and optimized writing. Not a runtime dependency.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -92,7 +92,10 @@ Offer **once per session per topic**; if declined, drop it and keep working. Nev
92
92
 
93
93
  ## Processing the SEOAgent Inbox
94
94
 
95
- `seoagent sync` also pulls **pending actions** from the dashboard into `.seoagent/inbox/`. These are autonomous decisions the cloud has made that need a human (or you, the AI agent) to apply in the user's local repo. Today the only action type is **`cli_prune_pending`** — SEOAgent's auto-prune deciding that an underperforming article should be removed from the repo.
95
+ `seoagent sync` also pulls **pending actions** from the dashboard into `.seoagent/inbox/`. These are autonomous decisions the cloud has made that need a human (or you, the AI agent) to apply in the user's local repo. The action types today:
96
+
97
+ - **`cli_prune_pending`** — auto-prune decided an underperforming article should be removed from the repo (destructive — confirm first).
98
+ - **`cli_technical_fix`** — autopilot found an open technical-SEO issue (meta, schema, canonical, internal linking, …) to fix in a page's source. Safe/reversible (edits an existing page).
96
99
 
97
100
  **Whenever the user says "process the inbox", "handle pending actions", "what's in my inbox", or anything similar**, OR whenever you see `.seoagent/inbox/README.md` reports pending actions after a sync, do this:
98
101
 
@@ -115,10 +118,26 @@ Offer **once per session per topic**; if declined, drop it and keep working. Nev
115
118
  npx @seoagent-official/seoagent ack <action_id> --failed --reason "kept; performs well off-search"
116
119
  ```
117
120
 
118
- 3. After processing, run `npx @seoagent-official/seoagent sync` once more to clean stale inbox files and confirm everything is settled.
119
- 4. Report a summary to the user: how many actions you applied, how many you declined (and why).
121
+ 3. For each `cli_technical_fix-<id>.md` file:
122
+ - `Read` it. The frontmatter has `action_id`, `issue` (`meta`|`schema`|`canonical`|`internal_link`|`other`), `severity`, and `page_url`. The body describes the recommended fix and how to apply it per issue type.
123
+ - **Find the page's source** that renders `page_url` — the route/template/markdown under `app/`, `pages/`, `src/`, or `content/`. Match by URL path.
124
+ - Apply the fix in the source (use `Edit`/`Write`): meta → title/description (or the framework's metadata API/frontmatter); schema → JSON-LD; canonical → `<link rel="canonical">`; internal_link → add relevant internal links. These are **safe/reversible** edits to an existing page, so you don't need the hard delete-confirmation prune requires — but still **show the user the diff** (confirm once per session, then proceed).
125
+ - Acknowledge it server-side:
126
+
127
+ ```bash
128
+ npx @seoagent-official/seoagent ack <action_id>
129
+ ```
130
+
131
+ - If you disagree or it's a false positive, decline it:
132
+
133
+ ```bash
134
+ npx @seoagent-official/seoagent ack <action_id> --failed --reason "not applicable; ..."
135
+ ```
136
+
137
+ 4. After processing, run `npx @seoagent-official/seoagent sync` once more to clean stale inbox files and confirm everything is settled.
138
+ 5. Report a summary to the user: how many actions you applied, how many you declined (and why).
120
139
 
121
- **Never delete a file without explicit user confirmation on the first action of the session.** Auto-prune is conservative (requires <5 clicks in 90 days, zero inbound internal links, etc.) but it can still surprise the user. Show them what's about to go.
140
+ **Never delete a file without explicit user confirmation on the first action of the session.** Auto-prune is conservative (requires <5 clicks in 90 days, zero inbound internal links, etc.) but it can still surprise the user. Show them what's about to go. (Technical-fix actions edit an existing page rather than delete, so they only need a diff review, not a destructive-action confirmation.)
122
141
 
123
142
  ## Output Format — Always Use This
124
143