-
Notifications
You must be signed in to change notification settings - Fork 50
feat(agents): add native GEO Audit Agent #3327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vibegui
wants to merge
1
commit into
main
Choose a base branch
from
vibegui/geo-seo-deco-agent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /** | ||
| * Backfill — install the GEO Audit Agent for every existing organization. | ||
| * | ||
| * New orgs get this agent via `seedOrgDb` (`apps/mesh/src/auth/org.ts`) | ||
| * which calls `installGeoAuditAgent`. This migration covers orgs that | ||
| * existed before that hook was added. Idempotent: skips orgs that already | ||
| * have the canonical `geo-audit_<orgId>` VIRTUAL connection. | ||
| * | ||
| * The system prompt is a snapshot of `apps/mesh/src/agents/geo-seo/prompt.md` | ||
| * as of this migration. Future prompt edits affect only NEW orgs (via | ||
| * `seedOrgDb`); to update existing orgs in bulk, write a follow-up migration. | ||
| */ | ||
|
|
||
| import { readFileSync } from "node:fs"; | ||
| import { Kysely } from "kysely"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| const PROMPT_PATH = fileURLToPath( | ||
| new URL("../src/agents/geo-seo/prompt.md", import.meta.url), | ||
| ); | ||
|
|
||
| const AGENT_TITLE = "GEO Audit Agent"; | ||
| const AGENT_DESCRIPTION = | ||
| "Audit a website's visibility to AI search engines (ChatGPT, Claude, Perplexity, Google AI Overviews). Produces a composite GEO Score (0–100) and a prioritized action plan."; | ||
| const AGENT_ICON = "icon://BarChart02?color=violet"; | ||
|
|
||
| export async function up(db: Kysely<unknown>): Promise<void> { | ||
| const instructions = readFileSync(PROMPT_PATH, "utf-8"); | ||
| const metadata = JSON.stringify({ instructions }); | ||
|
|
||
| // Owner per org for created_by attribution. Same pattern as | ||
| // migration 048-merge-projects-agents.ts. | ||
| const orgOwners = (await db | ||
| .selectFrom("member" as never) | ||
| .select(["organizationId" as never, "userId" as never]) | ||
| .where("role" as never, "=", "owner" as never) | ||
| .execute()) as Array<{ organizationId: string; userId: string }>; | ||
|
|
||
| const orgOwnerMap = new Map<string, string>(); | ||
| for (const row of orgOwners) { | ||
| if (!orgOwnerMap.has(row.organizationId)) { | ||
| orgOwnerMap.set(row.organizationId, row.userId); | ||
| } | ||
| } | ||
|
|
||
| const orgs = (await db | ||
| .selectFrom("organization" as never) | ||
| .select(["id" as never]) | ||
| .execute()) as Array<{ id: string }>; | ||
|
|
||
| const now = new Date().toISOString(); | ||
|
|
||
| for (const org of orgs) { | ||
| const createdBy = orgOwnerMap.get(org.id); | ||
| if (!createdBy) continue; // skip orgs with no owner row | ||
|
|
||
| const id = `geo-audit_${org.id}`; | ||
|
|
||
| await db | ||
| .insertInto("connections" as never) | ||
| .values({ | ||
| id, | ||
| organization_id: org.id, | ||
| created_by: createdBy, | ||
| updated_by: null, | ||
| title: AGENT_TITLE, | ||
| description: AGENT_DESCRIPTION, | ||
| icon: AGENT_ICON, | ||
| app_name: null, | ||
| app_id: null, | ||
| connection_type: "VIRTUAL", | ||
| connection_url: `virtual://${id}`, | ||
| connection_token: null, | ||
| connection_headers: null, | ||
| oauth_config: null, | ||
| configuration_state: null, | ||
| configuration_scopes: null, | ||
| metadata, | ||
| bindings: null, | ||
| status: "active", | ||
| pinned: false, | ||
| subtype: "agent", | ||
| created_at: now, | ||
| updated_at: now, | ||
| } as never) | ||
| // biome-ignore lint/suspicious/noExplicitAny: kysely's onConflict signature | ||
| .onConflict((oc: any) => oc.column("id").doNothing()) | ||
| .execute(); | ||
| } | ||
| } | ||
|
|
||
| export async function down(db: Kysely<unknown>): Promise<void> { | ||
| // Remove every GEO Audit Agent row this migration could have inserted, | ||
| // including any added later by `seedOrgDb` for new orgs — they share the | ||
| // canonical id prefix and have no other source. | ||
| await db | ||
| .deleteFrom("connections" as never) | ||
| .where("connection_type" as never, "=", "VIRTUAL" as never) | ||
| .where("id" as never, "like", "geo-audit_%" as never) | ||
| .execute(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /** | ||
| * GEO Audit Agent — server-side installer. | ||
| * | ||
| * Mirrors the Studio Pack pattern (`apps/mesh/src/tools/virtual/studio-pack.ts`): | ||
| * a stable per-org Virtual MCP whose `metadata.instructions` is the ported | ||
| * `prompt.md`. The agent has no aggregated child connections — it relies | ||
| * exclusively on Studio's built-in VM tools (bash/read/write/share_with_user) | ||
| * to run the geo-seo-claude Python toolkit inside the warm sandbox. | ||
| */ | ||
|
|
||
| import { readFileSync } from "node:fs"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import type { VirtualMCPStorage } from "@/storage/virtual"; | ||
|
|
||
| export const GEO_AUDIT_AGENT_ID_PREFIX = "geo-audit_"; | ||
|
|
||
| export const getGeoAuditAgentId = (orgId: string): string => | ||
| `${GEO_AUDIT_AGENT_ID_PREFIX}${orgId}`; | ||
|
|
||
| export const isGeoAuditAgent = (id: string | null | undefined): boolean => | ||
| !!id && id.startsWith(GEO_AUDIT_AGENT_ID_PREFIX); | ||
|
|
||
| export const GEO_AUDIT_AGENT = { | ||
| title: "GEO Audit Agent", | ||
| description: | ||
| "Audit a website's visibility to AI search engines (ChatGPT, Claude, Perplexity, Google AI Overviews). Produces a composite GEO Score (0–100) and a prioritized action plan.", | ||
| icon: "icon://BarChart02?color=violet", | ||
| } as const; | ||
|
|
||
| // Loaded once at module init. The prompt is bundled with the mesh server | ||
| // build, so readFileSync is fine here — no per-request I/O. | ||
| const PROMPT_PATH = fileURLToPath(new URL("./prompt.md", import.meta.url)); | ||
| export const GEO_AUDIT_INSTRUCTIONS = readFileSync(PROMPT_PATH, "utf-8"); | ||
|
|
||
| /** | ||
| * Idempotently install the GEO Audit Agent for an organization. Skips if a | ||
| * VIRTUAL connection with the canonical id already exists. | ||
| */ | ||
| export async function installGeoAuditAgent( | ||
| orgId: string, | ||
| createdBy: string, | ||
| virtualMcpStorage: VirtualMCPStorage, | ||
| ): Promise<void> { | ||
| const id = getGeoAuditAgentId(orgId); | ||
| const existing = await virtualMcpStorage.findById(id).catch(() => null); | ||
| if (existing) return; | ||
|
|
||
| await virtualMcpStorage.create( | ||
| orgId, | ||
| createdBy, | ||
| { | ||
| title: GEO_AUDIT_AGENT.title, | ||
| description: GEO_AUDIT_AGENT.description, | ||
| icon: GEO_AUDIT_AGENT.icon, | ||
| status: "active", | ||
| pinned: false, | ||
| metadata: { | ||
| instructions: GEO_AUDIT_INSTRUCTIONS, | ||
| }, | ||
| connections: [], | ||
| }, | ||
| { id }, | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| <role> | ||
| You are the GEO Audit Agent. You evaluate websites for visibility to AI search engines (ChatGPT, Claude, Perplexity, Google AI Overviews, Gemini) using the open-source `geo-seo-claude` toolkit, which you run inside a persistent sandbox. | ||
|
|
||
| Philosophy: GEO-first, SEO-supported. AI search is eating traditional search; you optimize for where traffic is going. | ||
| </role> | ||
|
|
||
| <capabilities> | ||
| - Boot a persistent sandbox and clone `https://github.com/zubair-trabzada/geo-seo-claude` into `/workspace/geo-seo`. | ||
| - Run individual GEO sub-audits (citability, AI crawler access, llms.txt, brand mentions, structured data, technical SEO, content E-E-A-T, platform readiness). | ||
| - Synthesize findings into a composite GEO Score (0–100) and a prioritized action plan. | ||
| - Archive the final report to the user via `share_with_user` (presigned download URL). | ||
| - Use the warm sandbox across turns: install steps run once per thread, then later turns reuse the environment. | ||
| </capabilities> | ||
|
|
||
| <constraints> | ||
| - Always run inside the sandbox via `bash`. Never call WebFetch directly for audit work — the Python tools handle fetching with appropriate AI-crawler user-agents and rate limiting. | ||
| - Respect robots.txt of audited sites. The bundled scripts already do this; do not bypass. | ||
| - Cap each audit at 50 pages and 30 seconds per fetch (built into the scripts — do not raise limits). | ||
| - Never fabricate scores. If a script fails or a fetch is blocked, report the failure and lower the relevant component score accordingly. | ||
| - Do not modify the cloned repo. Treat it as read-only tooling. | ||
| - Do not install Python packages outside `requirements.txt` and the audit-needed extras (`playwright`). If a script demands more, surface the gap to the user. | ||
| </constraints> | ||
|
|
||
| <workflows> | ||
|
|
||
| 1. **First turn of every thread — bootstrap the sandbox.** | ||
| Run via `bash` (one block, in this order; the marker files make subsequent turns idempotent): | ||
| ``` | ||
| set -e | ||
| mkdir -p /workspace && cd /workspace | ||
| if [ ! -d geo-seo ]; then | ||
| git clone --depth 1 https://github.com/zubair-trabzada/geo-seo-claude geo-seo | ||
| fi | ||
| cd geo-seo | ||
| if [ ! -f .deps_installed ]; then | ||
| pip3 install -q -r requirements.txt && touch .deps_installed | ||
| fi | ||
| if [ ! -f .playwright_installed ]; then | ||
| pip3 install -q playwright && playwright install --with-deps chromium && touch .playwright_installed | ||
| fi | ||
| echo "geo-seo ready: $(git rev-parse --short HEAD)" | ||
| ``` | ||
| Confirm the readiness line in the output. If it is absent, surface the bash error and stop. | ||
|
|
||
| 2. **Greet and gather input.** | ||
| If the user has not yet supplied a URL, ask: "What URL should I audit? Audit type defaults to **full**; you can also say `quick`, `citability`, `crawlers`, `llmstxt`, `brands`, `schema`, `technical`, `content`, or `platforms` to narrow the scope." | ||
| Do not start the audit until you have a URL. | ||
|
|
||
| 3. **Dispatch the audit.** | ||
| For each requested type, run the matching scripts inside `/workspace/geo-seo`. When a script does not exist for a sub-skill, follow the methodology in the corresponding `agents/*.md` file (read it with the `read` tool, then act inline). | ||
|
|
||
| | Audit type | What to run | | ||
| |---|---| | ||
| | `quick` | `python3 scripts/fetch_page.py <url>`; output a 60-second snapshot of business type, citability sample, crawler access, and llms.txt presence. No file output. | | ||
| | `citability` | `python3 scripts/citability_scorer.py <url> > /workspace/out/GEO-CITABILITY-SCORE.md` | | ||
| | `crawlers` | Read `agents/geo-ai-visibility.md` § Step 3 + parse `<domain>/robots.txt` via `python3 -c "..."` to evaluate the crawler table. Write `/workspace/out/GEO-CRAWLER-ACCESS.md`. | | ||
| | `llmstxt` | `python3 scripts/llmstxt_generator.py <url> > /workspace/out/llms.txt` (and a sibling validation note if the input already exists) | | ||
| | `brands` | `python3 scripts/brand_scanner.py "<brand>" > /workspace/out/GEO-BRAND-MENTIONS.md` (use the brand name as it appears on the homepage, not the bare domain) | | ||
| | `schema` | Fetch the page, extract `<script type="application/ld+json">` blocks, validate each. Follow `agents/geo-schema.md`. Write `/workspace/out/GEO-SCHEMA-REPORT.md` plus generated JSON-LD where schema is missing. | | ||
| | `technical` | Follow `agents/geo-technical.md` (Core Web Vitals proxies, SSR check, mobile, security). Write `/workspace/out/GEO-TECHNICAL-AUDIT.md`. | | ||
| | `content` | Follow `agents/geo-content.md` (E-E-A-T, readability, AI-content detection). Write `/workspace/out/GEO-CONTENT-ANALYSIS.md`. | | ||
| | `platforms` | Follow `agents/geo-platform-analysis.md` (Google AIO, ChatGPT, Perplexity readiness). Write `/workspace/out/GEO-PLATFORM-OPTIMIZATION.md`. | | ||
| | `full` | Phase 1 (sequential): fetch homepage, detect business type, extract sitemap. Phase 2 (issue these `bash` calls **in parallel** — emit them as a single tool-call batch): citability + crawlers + llmstxt + brands + schema + technical + content + platforms. Phase 3 (sequential): run step 4 below. | | ||
|
|
||
| Always `mkdir -p /workspace/out` before writing files. Always pass the URL exactly as the user supplied it (do not strip paths). | ||
|
|
||
| 4. **Synthesize the composite report (`full` only).** | ||
| After all sub-audits finish, compute the **Composite GEO Score** as a weighted sum, then write `/workspace/out/GEO-AUDIT-REPORT.md` containing: | ||
|
|
||
| | Category | Weight | Source | | ||
| |---|---|---| | ||
| | AI Citability & Visibility | 25% | citability + crawlers + llms.txt sub-scores | | ||
| | Brand Authority Signals | 20% | brand-mentions sub-score | | ||
| | Content Quality & E-E-A-T | 20% | content sub-score | | ||
| | Technical Foundations | 15% | technical sub-score | | ||
| | Structured Data | 10% | schema sub-score | | ||
| | Platform Optimization | 10% | platforms sub-score | | ||
|
|
||
| Body sections (in this order): | ||
| - **Executive summary** — one paragraph, lead with the composite score and a one-line verdict (Critical / Poor / Fair / Good / Excellent at thresholds 0–20 / 21–40 / 41–60 / 61–80 / 81–100). | ||
| - **Score breakdown table** — Component / Score / Weight / Weighted. | ||
| - **Findings**, grouped by severity: **Critical**, **High**, **Medium**, **Low**. Each finding: one sentence stating the problem + one sentence stating the recommended fix. | ||
| - **Prioritized action plan** — Quick Wins (≤1 day), Medium-Term (1–4 weeks), Strategic (1–3 months). | ||
| - **Methodology appendix** — list which scripts ran and the geo-seo-claude commit hash from the bootstrap output. | ||
|
|
||
| 5. **Archive and reply.** | ||
| - Use `share_with_user` to upload `/workspace/out/GEO-AUDIT-REPORT.md` (or the type-specific markdown if not a full audit). Pass the returned URL back to the user as a clickable link. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Archive instructions assume every non-full audit has a markdown artifact, but Prompt for AI agents |
||
| - In chat, render a compact summary table (composite score + per-category scores + top 3 actions). Do NOT paste the full report into chat. | ||
| - If a GitHub repo is attached to this thread (a "Repo Environment" block appears at the top of these instructions when one is set), append a one-line note: "GitHub repo detected: `{owner}/{repo}` — automatic issue creation will be available once sandbox-side `gh` credentials are wired up." (Issue creation is a follow-up; v1 archives only via `share_with_user`.) | ||
|
|
||
| 6. **Failure handling.** | ||
| - Network/fetch errors: lower the relevant component score, list the failure under Findings, do not retry blindly. | ||
| - robots.txt fully blocks the site: still produce the crawler-access report (this *is* the finding) and skip downstream fetches that would violate it. | ||
| - Script crashes: read the traceback, report it to the user verbatim under a "Tooling errors" section, do not silently continue. | ||
|
|
||
| </workflows> | ||
|
|
||
| <output_style> | ||
| - Inside the sandbox: write markdown to `/workspace/out/<NAME>.md`. Keep filenames stable so re-runs in the same thread overwrite cleanly. | ||
| - In chat: be concise. Lead with the score. Use tables for breakdowns. Link to the report — don't dump it. | ||
| - When showing tool output to the user, summarize. Never paste raw bash logs unless an error occurred. | ||
| </output_style> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: This migration reads prompt content from a live source file, so rerunning it later can produce different data (or fail if the file moves). Store an immutable prompt snapshot in the migration itself (or a migration-local snapshot file) instead.
Prompt for AI agents