# Supermarket transformation plan From a single-purpose "Social Curator" TUI for Federated Computer to a general marketing suite: a local web app, run in Docker, that any company running a Federated Core can install as a CoreDesktop sibling. ## 1. Decisions so far | Topic | Decision | |-------|----------| | Name | **Supermarket** (renamed from Coremarketing on 2026-11-19; the old TUI's data path `~/.local/state/coremarketing` keeps its name) | | Distribution | A CoreDesktop sibling: `sibling add ` installs it, `update` keeps it current | | Interface | A **local web app in Docker** at `http://localhost:8470`, on this machine only | | Scope | **One company** per install. A company can have **several websites** | | Core MCP / EspoCRM | Reached through the **local Hermes agent**, which gets an `mcp_servers` entry for the Core's MCP hub | | Billing data | **Stripe** first, for CAC, CLV and NRR | | Existing content work | **Kept.** The hard-coded app list becomes the **Inventory** of partners and competitors | | Websites and components | Pages are built from **each site's own section types** (decided 2026-11-22, Phase 5); **new sites** start from Supermarket's **shared theme**, copied into each site, with federated-website's look and the site's brand (Phase 6) | | Publishing | Sites are pushed to a **Gitea repository**. The user sets up the hooks that publish it to the Hugo server | | Contact enrichment | Third-party services allowed, behind a pluggable interface (section 6) | | AI for the app | Uses Hermes' Anthropic key and model when the user agrees (2026-11-20), copied to `hermes-ai.json` by `supermarket hermes` and `update.sh`. It calls the model directly, never through Hermes: post writing reads untrusted web text, which must not reach an agent with tools and CRM access | | Suite shape | One repo, one app with modules (Content, Prospects, SEO, Metrics, Sites), plus an MCP endpoint for agents | | Backups | SQLite's own `VACUUM INTO`, on request, before every migration and daily, in `/backups`; secrets never in them (Phase 6) | | Editions | **local**, **server** (one team, one company) and **multi** (many teams at one address, each with its own domains), chosen by `SUPERMARKET_MODE` (2026-11-25; Phases 9–14) | | Database by edition | SQLite for local; **Postgres** for server and multi-tenant (2026-11-25) | | Users | Owner (with billing), admins (the whole system, users and connections), members (given modules, each view or edit) and agents (a key, given modules). Sign-in by **email and password**, with optional two-factor for everyone, or **the Core's Authelia (OIDC)** (2026-11-25) | | Posting accounts | Several social accounts per platform (the company's, users' own); admins set who may post to which; a post can go to one or several at once (2026-11-25) | | Billing | Multi-tenant only: a **Stripe subscription** per team, managed by its owner. Each team brings its own keys for AI and services (2026-11-25) | ## Where things stand (2026-11-22) **Phases 0–6 are built and merged into `main`** (3ddf716; the user pushes from their own terminal). Only Phase 1 is tagged (`v0.1.0`); whether to tag the later phases is the user's call. Every module works: Content, Prospects, SEO, Metrics and Sites, with Settings → Backups. **Next: a run through TEST.md by hand** (planned for 2026-11-23), fixing what it turns up. Make a backup first: `supermarket backup "before testing"`. **Waiting on the user, or on others:** - *The CRM bridge*: the Core's MCP hub reaches EspoCRM at a stale address; with the Core's developer. It holds up the CRM queue, the 385 customer matches waiting for Accounts, and Phase 4 part 7 (pipeline influence). - *Lead forms*: a Lead Capture in EspoCRM, the lead-forms pull request on federated-website, and a `Lead` goal in Plausible. - *The LinkedIn page*: LinkedIn approving the second app (Community Management API). - *A first new site*: an empty repository on Gitea, and its deploy hook. - *Metrics*: the start month (2025-01 suggested), the per-product margins, other spend; publishing the open metrics page is the user's choice. - *SEO*: the search-engine setup pull request on federated-website (adds a sitemap and robots.txt; Google still has an old www sitemap from 2023). - *The shopping cart*: it must save the UTM tags in Stripe Checkout's metadata for sign-ups to count per signal (and per landing-page variant). - *Reddit*: API access needs Reddit's approval; until then, posts by hand. - *Not yet tried with real money or data*: discovery (web searches), building site pages with the AI, sending outreach email through the Core's mail server. ## 2. Requirements from the notes | Note | Where it lands | |------|----------------| | Coredesktop sibling | Phase 0: `install.sh` / `update.sh` run Docker Compose and set up Hermes | | Generalize for any company | Phase 0: the company profile replaces everything Federated-specific | | Company description and targets | Company profile: products, ideal customer profile, voice, websites, accounts | | Connect to AI provider | Phase 0: Anthropic, or any OpenAI-compatible server (Ollama, LM Studio, …) | | Create and send content to X, LinkedIn, Reddit | Phase 1: Content module, built on today's pipeline, + Reddit | | Find prospects → EspoCRM via Core MCP | Phase 2: Prospects module; CRM writes go through Hermes | | SEO suggestions, change the Hugo repo | Phase 3: SEO module, with changes opened as PRs on Gitea | | SEO for Google, Brave, DuckDuckGo | Phase 3: Search Console, Bing Webmaster + IndexNow (DuckDuckGo results come mostly from Bing); rankings from Search Console (decided 2026-11-22) | | Top-of-funnel lead generation | Content + SEO + prospecting + landing-page forms that create EspoCRM Leads | | Pipeline influence, CAC, CLV, NRR | Phase 4: Metrics module (Stripe + EspoCRM via Hermes + Plausible) | | Website, components | Phase 5: Sites module and component library | | Static file hosting on Core | Phase 5: push to a Gitea repo; the user's hooks deploy it | ## 3. Architecture ### Runtime ``` Browser / GNOME app-grid launcher (CoreDesktop `webapp add`) │ http://localhost:8470 ▼ ┌──────────────── supermarket container ────────────────┐ │ Go server: web UI (HTML + htmx) · JSON API · /mcp │ │ Background jobs: fetch, generate, publish, Stripe sync, │ │ SEO crawls, scheduled posts │ │ Tools in the image: git, hugo │ └───────┬───────────────────────────────▲─────────────────┘ │ bind mount │ /mcp (bearer token) ▼ │ ~/.local/share/supermarket/ ┌──────┴─────── Hermes (sandboxed) ──┐ app.db (SQLite) · secrets │ mcp_servers: │ sites/ · logs/ │ supermarket → localhost:8470 │ ~/.config/coredesktop/core.conf │ mcphub → Core MCP hub ───────────┼──► EspoCRM (read-only: domain, email) │ cron job: run the CRM queue │ (and other └────────────────────────────────────┘ Core apps) ``` - **Go stays.** The fetchers, AI client, X/LinkedIn clients, OAuth flows, X weighted-length counting and the atomic store all carry over. The Bubble Tea UI is replaced by server-rendered pages with htmx: no Node build step, a single small image, and the existing code is reused nearly as is. - **Localhost only.** The port is published as `127.0.0.1:8470:8080`, so other machines can't reach it (it doesn't depend on ufw-docker), and the app needs no login of its own. The `/mcp` endpoint requires a bearer token. - **OAuth** for X, LinkedIn, Reddit, Google and Bing redirects back to `http://localhost:8470/auth//callback`. This replaces today's `supermarket auth` command on `localhost:8080`. Developer apps need the new redirect URI registered. - **Local AI servers.** The container reaches a server on this machine through `host.docker.internal` (`extra_hosts: host-gateway`), and LAN or tailnet servers through the host's routing. The app offers the servers that CoreDesktop's `configure ai-servers` set up. - **Secrets.** The container can't reach GNOME's keyring, so the app's own tokens live in `/data/secrets` (mode 0600, never in the repo or the image). The Core MCP hub credential is **not** held by the app; it lives in Hermes' `~/.hermes/.env`. - **No inbound webhooks.** Nothing on the internet can reach the app, so Stripe and the social platforms are polled. Stripe's Events API makes this cheap. - **Data in SQLite.** That means one file to back up (see Future enhancements: back up and restore). The existing `posts.json`, `dismissed.json` and `state.json` are imported on first start. ### The Hermes bridge (Core MCP → EspoCRM) Hermes is the only thing that talks to the Core's MCP hub. The app and Hermes meet through the app's own MCP endpoint, so Hermes is configured with **two** MCP servers. **The block `install.sh` adds to `~/.hermes/config.yaml`.** The hub URL comes from `core.conf` and the user confirms it. Each `${…}` reference is resolved from `~/.hermes/.env`, so `config.yaml` holds no secret: ```yaml mcp_servers: mcphub: url: "https://mcphub./sse?as_user=" transport: sse headers: Authorization: "Basic ${MCPHUB_AUTH}" supermarket: command: socat args: ["STDIO", "UNIX-CONNECT:/mcp.sock"] ``` **Why a socket, not `http://127.0.0.1:8470/mcp`** (found 2026-11-19). CoreDesktop runs Hermes under srt, in its own network namespace. Hermes always dials loopback directly, never through the proxy, and finds nothing there. srt's proxy, in turn, refuses any name that resolves to loopback. Unix sockets are allowed in Hermes' sandbox, so the app serves stdio-style MCP on `/data/mcp.sock`, and Hermes runs `socat` as a stdio MCP server. The socket is 0600, which is the same protection as the token file beside it. The HTTP endpoint with its bearer token stays for unsandboxed agents (Claude Code). **`~/.hermes/.env`**: ``` MCPHUB_AUTH=