Skip to content

fsbtactic-code/marketing-brain-skill / skills/marketing-brain

marketing-brain

Flagged

Create, improve, research, or audit marketing strategy and execution using a bundled marketing library, verified live primary sources for volatile facts, and clearly labeled agent judgment. Use for full marketing systems, audits, landing pages and CRO, competitor intelligence, brand voice, audience and JTBD research, email sequences, SMM and social content systems, paid ads, headlines, copywriting, positioning, offers, launches, GTM, growth, funnels, retention, pricing, SEO, analytics, attribution, experiments, and consumer or buyer psychology. Trigger for English and Russian requests, including requests for ready-to-use assets.

FileKindSize
SKILL.mdskill md10.6 KB
agents/openai.yamlconfig325 B
assets/BUILD-MANIFEST.jsonconfig1.2 KB
assets/cards.jsonlother21.1 KB
assets/edges.jsonlother33.0 KB
assets/knowledge.sqlitebinary136.0 KB
assets/legacy-library.mbpack.parts/manifest.jsonconfig857 B
assets/legacy-library.mbpack.parts/part-0000.binbinary48.0 MB
assets/legacy-library.mbpack.parts/part-0001.binbinary48.0 MB
assets/legacy-library.mbpack.parts/part-0002.binbinary7.7 MB
assets/research-catalog.jsonlother280.4 KB
assets/source-channels.jsonlother52.1 KB
assets/sources.jsonlother10.2 KB
assets/templates/content-calendar.mdmarkdown1.3 KB
assets/templates/evidence-ledger.mdmarkdown1.3 KB
assets/templates/experiment-backlog.mdmarkdown1.2 KB
assets/templates/issue-registry.mdmarkdown1.2 KB
assets/templates/marketing-brief.mdmarkdown1.6 KB
assets/templates/marketing-system-manifest.jsonconfig1.1 KB
assets/wiki/cards/card_ad_effects_heterogeneous_by_firm.mdmarkdown1.3 KB
assets/wiki/cards/card_ad_roi_measurement_noise.mdmarkdown1.4 KB
assets/wiki/cards/card_choice_overload_context_dependent.mdmarkdown1.4 KB
assets/wiki/cards/card_cost_transparency_context.mdmarkdown1.2 KB
assets/wiki/cards/card_ftc_material_connection_disclosure.mdmarkdown1.4 KB
assets/wiki/cards/card_google_ads_experiment_hygiene.mdmarkdown1.3 KB
assets/wiki/cards/card_google_no_word_count_freshness_trick.mdmarkdown1.2 KB
assets/wiki/cards/card_google_people_first.mdmarkdown1.2 KB
assets/wiki/cards/card_google_who_how_why.mdmarkdown1.1 KB
assets/wiki/cards/card_incrementality_control_group.mdmarkdown1.2 KB
assets/wiki/cards/card_incrementality_precision_stratification.mdmarkdown1.3 KB
assets/wiki/cards/card_short_video_ad_spillover.mdmarkdown1.3 KB
assets/wiki/cards/card_telegram_ad_format.mdmarkdown1.0 KB
assets/wiki/cards/card_telegram_destination_quality.mdmarkdown1.1 KB
assets/wiki/cards/card_telegram_no_unsupported_absolutes.mdmarkdown1.0 KB
assets/wiki/cards/card_viral_content_arousal.mdmarkdown1.3 KB
assets/wiki/cards/card_youtube_audience_signals.mdmarkdown1.2 KB
assets/wiki/cards/card_youtube_publish_time.mdmarkdown1.4 KB
assets/wiki/cards/card_youtube_quality_over_frequency.mdmarkdown1.3 KB
assets/wiki/cards/card_youtube_search_ranking.mdmarkdown1.1 KB
assets/wiki/cards/card_youtube_tags_low_priority.mdmarkdown1019 B
assets/wiki/domains/consumer-behavior.mdmarkdown2.2 KB
assets/wiki/domains/content-editorial.mdmarkdown5.1 KB
assets/wiki/domains/creator-community.mdmarkdown1009 B
assets/wiki/domains/cro-funnels.mdmarkdown2.3 KB
assets/wiki/domains/law-policy-ethics.mdmarkdown2.8 KB
assets/wiki/domains/measurement-analytics.mdmarkdown4.5 KB
assets/wiki/domains/offer-messaging-copy.mdmarkdown2.7 KB
assets/wiki/domains/organic-smm.mdmarkdown4.9 KB
assets/wiki/domains/paid-acquisition.mdmarkdown6.2 KB
assets/wiki/domains/pricing-promotions.mdmarkdown850 B
assets/wiki/domains/seo-geo-ai-search.mdmarkdown2.8 KB
assets/wiki/domains/strategy-research.mdmarkdown932 B
assets/wiki/index.mdmarkdown935 B
assets/wiki/open-questions.mdmarkdown159 B
assets/wiki/pages.jsonlother18.3 KB
references/research-catalog-policy.mdmarkdown1.3 KB
references/retrieval-policy.mdmarkdown1.0 KB
references/task-playbooks.mdmarkdown5.1 KB
references/taxonomy.mdmarkdown1005 B
references/third-party-notices.mdmarkdown1.6 KB
references/workflow-audience.mdmarkdown8.4 KB
references/workflow-audit.mdmarkdown7.0 KB
references/workflow-brand-voice.mdmarkdown8.0 KB
references/workflow-competitors.mdmarkdown7.2 KB
references/workflow-email.mdmarkdown8.8 KB
references/workflow-full-system.mdmarkdown9.2 KB
references/workflow-headlines.mdmarkdown8.4 KB
references/workflow-landing-cro.mdmarkdown6.9 KB
references/workflow-paid-ads.mdmarkdown10.1 KB
references/workflow-social.mdmarkdown9.2 KB
scripts/marketing_context_output.pyscript7.3 KB
scripts/marketing_context_query.pyscript8.6 KB
scripts/materialize_legacy_pack.pyscript12.1 KB
scripts/mbpack_codec.pyscript4.1 KB
scripts/mbpack_output.pyscript5.2 KB
scripts/retrieve_marketing_context.pyscript13.1 KB
scripts/search_knowledge.pyscript7.2 KB
scripts/search_legacy_pack.pyscript131 B
scripts/search_private_pack.pyscript11.0 KB
scripts/search_research_catalog.pyscript6.2 KB
scripts/verify_public_install.pyscript7.1 KB

scripts/search_knowledge.py

View on GitHub
from __future__ import annotations

import argparse
import json
import sqlite3
import sys
from pathlib import Path
from typing import Any


SKILL_ROOT = Path(__file__).resolve().parents[1]
ASSET_ROOT = SKILL_ROOT / "assets"


def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser(description="Search verified Marketing Brain cards.")
    parser.add_argument("--query", required=True)
    parser.add_argument("--domain")
    parser.add_argument("--limit", type=int, default=5)
    parser.add_argument("--json", action="store_true", dest="as_json")
    return parser.parse_args()


def normalize_limit(value: int) -> int:
    return max(1, min(value, 20))


def fts_query(value: str) -> str:
    terms = [term.strip('"\'()[]{}:*') for term in value.split()]
    clean = [term for term in terms if term]
    return " OR ".join(f'"{term}"' for term in clean)


def decode_json(value: Any, default: Any) -> Any:
    if isinstance(value, str):
        try:
            return json.loads(value)
        except json.JSONDecodeError:
            return default
    return value if value is not None else default


def attach_sqlite_context(
    connection: sqlite3.Connection, cards: list[dict[str, Any]]
) -> list[dict[str, Any]]:
    if not cards:
        return cards
    card_ids = [card["card_id"] for card in cards]
    source_ids = sorted(
        {
            ref.get("source_id")
            for card in cards
            for ref in decode_json(card.get("source_refs_json"), [])
            if ref.get("source_id")
        }
    )
    sources: dict[str, dict[str, Any]] = {}
    if source_ids:
        placeholders = ",".join("?" for _ in source_ids)
        rows = connection.execute(
            f"SELECT * FROM sources WHERE source_id IN ({placeholders})", source_ids
        )
        sources = {row["source_id"]: dict(row) for row in rows}
    placeholders = ",".join("?" for _ in card_ids)
    edge_rows = connection.execute(
        f"SELECT * FROM edges WHERE subject_id IN ({placeholders}) "
        f"OR object_id IN ({placeholders}) ORDER BY edge_id",
        card_ids + card_ids,
    )
    edges = [dict(row) for row in edge_rows]
    for card in cards:
        refs = decode_json(card.get("source_refs_json"), [])
        card["source_refs"] = refs
        card["source_details"] = [
            sources[ref["source_id"]]
            for ref in refs
            if ref.get("source_id") in sources
        ]
        card["graph_relations"] = [
            edge
            for edge in edges
            if edge["subject_id"] == card["card_id"] or edge["object_id"] == card["card_id"]
        ]
    return cards


def search_sqlite(query: str, domain: str | None, limit: int) -> list[dict[str, Any]]:
    path = ASSET_ROOT / "knowledge.sqlite"
    if not path.exists():
        return []
    connection = sqlite3.connect(path)
    connection.row_factory = sqlite3.Row
    try:
        sql = """
            SELECT c.*, bm25(card_fts) AS rank
            FROM card_fts
            JOIN cards c ON c.rowid = card_fts.rowid
            WHERE card_fts MATCH ?
        """
        params: list[Any] = [fts_query(query)]
        if domain:
            sql += " AND c.domains_json LIKE ?"
            params.append(f'%"{domain}"%')
        sql += " ORDER BY rank LIMIT ?"
        params.append(limit)
        cards = [dict(row) for row in connection.execute(sql, params)]
        return attach_sqlite_context(connection, cards)
    except sqlite3.OperationalError:
        return []
    finally:
        connection.close()


def score_card(card: dict[str, Any], terms: set[str]) -> int:
    searchable = " ".join(
        str(card.get(field, ""))
        for field in ("claim", "application", "conditions", "limitations", "domains")
    ).casefold()
    return sum(1 for term in terms if term in searchable)


def read_jsonl(path: Path) -> list[dict[str, Any]]:
    if not path.exists():
        return []
    with path.open("r", encoding="utf-8") as handle:
        return [json.loads(line) for line in handle if line.strip()]


def attach_jsonl_context(cards: list[dict[str, Any]]) -> list[dict[str, Any]]:
    sources = {
        source["source_id"]: source for source in read_jsonl(ASSET_ROOT / "sources.jsonl")
    }
    edges = read_jsonl(ASSET_ROOT / "edges.jsonl")
    for card in cards:
        refs = card.get("source_refs", [])
        card["source_details"] = [
            sources[ref["source_id"]]
            for ref in refs
            if ref.get("source_id") in sources
        ]
        card["graph_relations"] = [
            edge
            for edge in edges
            if edge.get("subject_id") == card.get("card_id")
            or edge.get("object_id") == card.get("card_id")
        ]
    return cards


def search_jsonl(query: str, domain: str | None, limit: int) -> list[dict[str, Any]]:
    path = ASSET_ROOT / "cards.jsonl"
    terms = {term.casefold() for term in query.split() if len(term) > 1}
    matches: list[tuple[int, dict[str, Any]]] = []
    for card in read_jsonl(path):
        if domain and domain not in card.get("domains", []):
            continue
        score = score_card(card, terms)
        if score:
            matches.append((score, card))
    matches.sort(key=lambda item: (-item[0], item[1].get("card_id", "")))
    return attach_jsonl_context([card for _, card in matches[:limit]])


def render_markdown(cards: list[dict[str, Any]]) -> str:
    if not cards:
        return "No verified knowledge card matched the query."
    blocks = []
    for card in cards:
        refs = card.get("source_refs") or json.loads(card.get("source_refs_json", "[]"))
        sources = {source["source_id"]: source for source in card.get("source_details", [])}
        ref_parts = []
        for ref in refs:
            source = sources.get(ref.get("source_id"), {})
            title = source.get("title", ref.get("source_id"))
            url = source.get("canonical_url")
            label = f"[{title}]({url})" if url else str(title)
            ref_parts.append(f"{label} [{ref.get('locator')}]")
        relation_text = ", ".join(
            f"{edge['subject_id']} {edge['relation']} {edge['object_id']}"
            for edge in card.get("graph_relations", [])
            if edge.get("relation") not in {"derived_from", "classified_as"}
        )
        blocks.append(
            "\n".join(
                [
                    f"## {card.get('card_id')}",
                    str(card.get("claim", "")),
                    f"Application: {card.get('application', '')}",
                    f"Evidence: {card.get('evidence_class', '')}",
                    f"Review due: {card.get('review_due', '')}",
                    f"Sources: {', '.join(ref_parts)}",
                    f"Relations: {relation_text or 'none'}",
                ]
            )
        )
    return "\n\n".join(blocks)


def main() -> int:
    args = parse_args()
    limit = normalize_limit(args.limit)
    cards = search_sqlite(args.query, args.domain, limit)
    if not cards:
        cards = search_jsonl(args.query, args.domain, limit)
    if args.as_json:
        json.dump(cards, sys.stdout, ensure_ascii=False, indent=2)
        sys.stdout.write("\n")
    else:
        print(render_markdown(cards))
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall