fsbtactic-code/marketing-brain-skill / skills/marketing-brain
marketing-brain
FlaggedCreate, 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.
scripts/verify_public_install.py
View on GitHubfrom __future__ import annotations
import argparse
import hashlib
import json
import sqlite3
from collections import Counter
from pathlib import Path
from typing import Any, Sequence
from materialize_legacy_pack import BUFFER_SIZE
from mbpack_codec import decompress_json
from search_private_pack import (
connect_readonly,
read_manifest,
resolve_pack,
result_rows,
retrieve_record_context,
risk_state,
)
SKILL_ROOT = Path(__file__).resolve().parents[1]
BUILD_MANIFEST = SKILL_ROOT / "assets" / "BUILD-MANIFEST.json"
def sha256_path(path: Path) -> str:
digest = hashlib.sha256()
with path.open("rb") as handle:
for block in iter(lambda: handle.read(BUFFER_SIZE), b""):
digest.update(block)
return digest.hexdigest()
def expected_release() -> dict[str, Any]:
manifest = json.loads(BUILD_MANIFEST.read_text(encoding="utf-8"))
return {
"record_count": manifest["mbpack_record_count"],
"indexed_chunk_count": manifest["mbpack_indexed_chunk_count"],
"working_count": manifest["mbpack_working_count"],
"risk_labeled_count": manifest["mbpack_risk_labeled_count"],
"risk_counts": manifest["mbpack_risk_counts"],
"pack_sha256": manifest["files"]["legacy-library.mbpack"],
}
def actual_indexed_chunks(database: sqlite3.Connection) -> int:
row = database.execute(
"SELECT COUNT(DISTINCT c.chunk_id) FROM chunks c "
"JOIN postings p ON p.chunk_id = c.chunk_id"
).fetchone()
return int(row[0])
def risk_index_coverage(database: sqlite3.Connection) -> dict[str, int]:
risk_chunks = int(
database.execute(
"SELECT COUNT(*) FROM chunks c JOIN records r ON r.record_id = c.record_id "
"WHERE r.state = 1"
).fetchone()[0]
)
row = database.execute(
"SELECT COUNT(DISTINCT r.record_id), COUNT(DISTINCT c.chunk_id) "
"FROM records r JOIN chunks c ON c.record_id = r.record_id "
"JOIN postings p ON p.chunk_id = c.chunk_id WHERE r.state = 1"
).fetchone()
return {
"risk_records_with_postings": int(row[0]),
"risk_chunks": risk_chunks,
"risk_chunks_with_postings": int(row[1]),
}
def verify_risk_access(database: sqlite3.Connection) -> tuple[Counter[str], int, list[str]]:
states: Counter[str] = Counter()
accessible = 0
blocked: list[str] = []
rows = database.execute(
"SELECT record_id, state, provenance_blob FROM records WHERE state = 1 "
"ORDER BY record_id"
).fetchall()
for record_id, state, provenance_blob in rows:
provenance = decompress_json(provenance_blob)
states[risk_state(provenance, int(state))] += 1
candidates = retrieve_record_context(database, str(record_id), 1, 0)
if candidates and result_rows(candidates, 400):
accessible += 1
else:
blocked.append(str(record_id))
return states, accessible, blocked
def verify_install(pack: Path | None = None) -> dict[str, Any]:
path = resolve_pack(pack)
expected = expected_release()
database = connect_readonly(path)
try:
pack_manifest = read_manifest(database)
record_count = int(
database.execute("SELECT COUNT(*) FROM records").fetchone()[0]
)
working_count = int(
database.execute("SELECT COUNT(*) FROM records WHERE state = 0").fetchone()[0]
)
risk_count = int(
database.execute("SELECT COUNT(*) FROM records WHERE state = 1").fetchone()[0]
)
indexed_chunks = actual_indexed_chunks(database)
risk_index = risk_index_coverage(database)
risk_states, accessible, blocked = verify_risk_access(database)
finally:
database.close()
digest = sha256_path(path)
errors: list[str] = []
checks = {
"record_count": (record_count, expected["record_count"]),
"indexed_chunk_count": (indexed_chunks, expected["indexed_chunk_count"]),
"working_count": (working_count, expected["working_count"]),
"risk_labeled_count": (risk_count, expected["risk_labeled_count"]),
"accessible_risk_records": (accessible, risk_count),
}
for label, (actual, required) in checks.items():
if actual != required:
errors.append(f"{label}: expected {required}, got {actual}")
if digest != expected["pack_sha256"]:
errors.append("pack_sha256 does not match BUILD-MANIFEST.json")
retrieval_policy = pack_manifest.get("retrieval_policy", {})
if retrieval_policy.get("quarantine_indexed") is not True:
errors.append("retrieval_policy.quarantine_indexed is not true")
if blocked:
errors.append(f"risk records without retrievable context: {len(blocked)}")
if risk_index["risk_records_with_postings"] != risk_count:
errors.append("not every risk record has a searchable posting")
if risk_index["risk_chunks_with_postings"] != risk_index["risk_chunks"]:
errors.append("not every risk chunk has a searchable posting")
expected_risk_states = dict(expected["risk_counts"])
expected_risk_states.pop("working", None)
if dict(risk_states) != expected_risk_states:
errors.append("risk state counts do not match BUILD-MANIFEST.json")
return {
"ok": not errors,
"errors": errors,
"pack": {
"path": str(path),
"bytes": path.stat().st_size,
"sha256": digest,
},
"records": {
"total": record_count,
"working": working_count,
"risk_labeled": risk_count,
"risk_states": dict(sorted(risk_states.items())),
"accessible_risk_records": accessible,
"blocked_risk_records": len(blocked),
"blocked_record_ids": blocked,
},
"indexed_chunks": indexed_chunks,
"risk_index": risk_index,
"access_policy": {
"risk_state_filtering": "none",
"all_risk_states_searchable": (
accessible == risk_count
and risk_index["risk_records_with_postings"] == risk_count
and risk_index["risk_chunks_with_postings"] == risk_index["risk_chunks"]
),
},
}
def parse_args(argv: Sequence[str] | None = None) -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Verify a complete public Marketing Brain installation.",
)
parser.add_argument("--pack", type=Path)
parser.add_argument("--json", action="store_true", dest="as_json")
return parser.parse_args(argv)
def main(argv: Sequence[str] | None = None) -> int:
arguments = parse_args(argv)
try:
result = verify_install(arguments.pack)
except (FileNotFoundError, OSError, sqlite3.Error, ValueError) as error:
result = {"ok": False, "errors": [str(error)]}
if arguments.as_json:
print(json.dumps(result, ensure_ascii=False, indent=2, sort_keys=True))
else:
print("Marketing Brain public install: " + ("OK" if result["ok"] else "FAILED"))
for error in result.get("errors", []):
print(f"- {error}")
return 0 if result["ok"] else 2
if __name__ == "__main__":
raise SystemExit(main())
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| 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: 471k | Updated | Claude CodeCodex | Verified | Install |
| 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: 471k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |