From d039484a4a3dd6a4841c1831fa59f0083dc5b658 Mon Sep 17 00:00:00 2001 From: David Young Date: Thu, 19 Nov 2026 08:38:09 -0700 Subject: [PATCH] Phase 0: turn Supermarket into a Dockerized local web app Replace the old Go TUI with a web app (port 8470) that runs in a container as a CoreDesktop sibling: - cmd/supermarket server with htmx web UI: dashboard, company profile, inventory (partners/competitors), AI and credential settings, and a Core & Hermes page - SQLite storage and a secrets store under ~/.local/share/supermarket - AI providers (Anthropic, OpenAI-compatible) behind one interface - MCP server and a Hermes bridge to the Federated Core MCP hub - Import of the old Coremarketing TUI's state - install.sh / update.sh / lib.sh, Dockerfile, compose.yaml, the bin/supermarket launcher and hermes/setup.sh Posting is not wired back up yet; that comes in Phase 1. See PLAN.md. Co-Authored-By: Claude Opus 5.5 --- .dockerignore | 10 + .gitignore | 15 +- Dockerfile | 22 + PLAN.md | 416 +++++++++ README.md | 244 +++-- bin/supermarket | 63 ++ cmd/supermarket/main.go | 171 ++++ compose.yaml | 33 + config.example.yaml | 253 ------ examples/examples.go | 9 + examples/federated-inventory.yaml | 198 ++++ go.mod | 58 +- go.sum | 233 +++-- hermes/setup.sh | 168 ++++ install.sh | 102 ++- internal/ai/ai.go | 134 +++ internal/ai/ai_test.go | 112 +++ internal/ai/anthropic.go | 100 ++ internal/ai/openai.go | 150 +++ internal/api/claude/client.go | 112 --- internal/api/twitter/client.go | 2 +- internal/api/youtube/client.go | 2 +- internal/auth/auth.go | 334 ------- internal/bridge/bridge.go | 63 ++ internal/config/config.go | 193 ---- internal/config/config_test.go | 42 - internal/core/core.go | 111 +++ internal/core/core_test.go | 42 + internal/db/db.go | 151 +++ internal/fetcher/fetcher.go | 6 +- internal/inventory/inventory.go | 277 ++++++ internal/inventory/inventory_test.go | 82 ++ internal/legacy/legacy.go | 299 ++++++ internal/legacy/legacy_test.go | 148 +++ internal/mcpserver/mcpserver.go | 103 +++ internal/oauth/oauth.go | 190 ++++ internal/profile/draft.go | 205 +++++ internal/profile/draft_test.go | 82 ++ internal/profile/profile.go | 158 ++++ internal/secrets/secrets.go | 113 +++ internal/state/state.go | 52 -- internal/store/dismissed.go | 48 - internal/store/store.go | 94 -- internal/store/store_test.go | 39 - internal/ui/app.go | 1110 ----------------------- internal/ui/styles.go | 85 -- internal/web/inventory.go | 179 ++++ internal/web/pages.go | 314 +++++++ internal/web/profile.go | 191 ++++ internal/web/server.go | 264 ++++++ internal/web/server_test.go | 255 ++++++ internal/web/settings.go | 308 +++++++ internal/web/static/app.css | 122 +++ internal/web/static/app.js | 51 ++ internal/web/static/htmx.min.js | 1 + internal/web/templates/ai.html | 65 ++ internal/web/templates/core.html | 53 ++ internal/web/templates/credentials.html | 44 + internal/web/templates/dashboard.html | 39 + internal/web/templates/entry.html | 51 ++ internal/web/templates/import.html | 33 + internal/web/templates/inventory.html | 40 + internal/web/templates/layout.html | 30 + internal/web/templates/message.html | 4 + internal/web/templates/profile.html | 105 +++ lib.sh | 89 ++ main.go | 288 ------ update.sh | 42 + 68 files changed, 6288 insertions(+), 2914 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 PLAN.md create mode 100755 bin/supermarket create mode 100644 cmd/supermarket/main.go create mode 100644 compose.yaml delete mode 100644 config.example.yaml create mode 100644 examples/examples.go create mode 100644 examples/federated-inventory.yaml create mode 100755 hermes/setup.sh create mode 100644 internal/ai/ai.go create mode 100644 internal/ai/ai_test.go create mode 100644 internal/ai/anthropic.go create mode 100644 internal/ai/openai.go delete mode 100644 internal/api/claude/client.go delete mode 100644 internal/auth/auth.go create mode 100644 internal/bridge/bridge.go delete mode 100644 internal/config/config.go delete mode 100644 internal/config/config_test.go create mode 100644 internal/core/core.go create mode 100644 internal/core/core_test.go create mode 100644 internal/db/db.go create mode 100644 internal/inventory/inventory.go create mode 100644 internal/inventory/inventory_test.go create mode 100644 internal/legacy/legacy.go create mode 100644 internal/legacy/legacy_test.go create mode 100644 internal/mcpserver/mcpserver.go create mode 100644 internal/oauth/oauth.go create mode 100644 internal/profile/draft.go create mode 100644 internal/profile/draft_test.go create mode 100644 internal/profile/profile.go create mode 100644 internal/secrets/secrets.go delete mode 100644 internal/state/state.go delete mode 100644 internal/store/dismissed.go delete mode 100644 internal/store/store.go delete mode 100644 internal/store/store_test.go delete mode 100644 internal/ui/app.go delete mode 100644 internal/ui/styles.go create mode 100644 internal/web/inventory.go create mode 100644 internal/web/pages.go create mode 100644 internal/web/profile.go create mode 100644 internal/web/server.go create mode 100644 internal/web/server_test.go create mode 100644 internal/web/settings.go create mode 100644 internal/web/static/app.css create mode 100644 internal/web/static/app.js create mode 100644 internal/web/static/htmx.min.js create mode 100644 internal/web/templates/ai.html create mode 100644 internal/web/templates/core.html create mode 100644 internal/web/templates/credentials.html create mode 100644 internal/web/templates/dashboard.html create mode 100644 internal/web/templates/entry.html create mode 100644 internal/web/templates/import.html create mode 100644 internal/web/templates/inventory.html create mode 100644 internal/web/templates/layout.html create mode 100644 internal/web/templates/message.html create mode 100644 internal/web/templates/profile.html create mode 100644 lib.sh delete mode 100644 main.go create mode 100755 update.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e681abf --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.git +.claude +*.md +bin +hermes +install.sh +update.sh +lib.sh +compose.yaml +/supermarket diff --git a/.gitignore b/.gitignore index f61d4d6..c00e8f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,16 @@ -# Real credentials live here — copy config.example.yaml instead +# Supermarket keeps all its data outside the repository, in +# ~/.local/share/supermarket. These guard against copies landing here. config.yaml - -# Runtime data written next to the config file +secrets.json +mcp-token +compose.env +*.db +*.db-shm +*.db-wal state.json posts.json dismissed.json -coremarketing.log +*.log # Build output -/coremarketing +/supermarket diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d355a51 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +# Supermarket's web app. Built locally by install.sh / update.sh through +# compose.yaml; nothing is pulled from a registry but the base images. + +FROM golang:1.26-alpine AS build +WORKDIR /src +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +ARG VERSION=dev +RUN CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X 'main.version=${VERSION}'" \ + -o /out/supermarket ./cmd/supermarket + +FROM alpine:3.22 +# git: for the SEO and Sites modules, which work on Hugo repositories. +RUN apk add --no-cache ca-certificates tzdata git +COPY --from=build /out/supermarket /usr/local/bin/supermarket +LABEL org.opencontainers.image.title="supermarket" +ENV SUPERMARKET_DATA=/data +EXPOSE 8080 +HEALTHCHECK --interval=30s --timeout=5s --start-period=10s \ + CMD wget -q -O /dev/null http://127.0.0.1:8080/healthz || exit 1 +ENTRYPOINT ["/usr/local/bin/supermarket"] diff --git a/PLAN.md b/PLAN.md new file mode 100644 index 0000000..4e5781e --- /dev/null +++ b/PLAN.md @@ -0,0 +1,416 @@ +# 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 | The suite builds the company's **websites** from a reusable **component library** | +| 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) | +| Suite shape | One repo, one app with modules (Content, Prospects, SEO, Metrics, Sites), plus an MCP endpoint for agents | + +## 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), Brave Search API for rank tracking | +| 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. 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=" + headers: + Authorization: "Basic ${MCPHUB_AUTH}" + supermarket: + url: "http://127.0.0.1:8470/mcp" + headers: + Authorization: "Bearer ${SUPERMARKET_MCP_TOKEN}" +``` + +**`~/.hermes/.env`** (written through `hermes config set`, which routes +UPPER_SNAKE names to `.env`): + +``` +MCPHUB_AUTH=