db.DB wraps database/sql for either database. The SQL stays SQLite's: on Postgres each statement's ? become $n and LIKE ignores case as SQLite's does, and the Postgres schema (postgres.sql, schema 29 as a whole) adds SQLite's instr, json_extract and two-argument max/min, and a nocase ICU collation. Needs Postgres 18. LastInsertId became db.Insert (RETURNING id), INSERT OR IGNORE became ON CONFLICT DO NOTHING, upserts qualify their columns, and three queries group by every column they use. SUPERMARKET_TEST_POSTGRES runs the test suite on Postgres, a new schema per test; all tests pass on both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2585 lines
147 KiB
Markdown
2585 lines
147 KiB
Markdown
# 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 <url>` 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 `<data>/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. **Free** (2 users, some modules, limited storage) and **Paid** ($15 per user per month, with storage limits). Each team brings its own keys for AI and services (2026-11-25) |
|
||
| Teams and domains | A person can belong to several teams; each team works on **one website domain** (with its subdomains) (2026-11-25) |
|
||
| Hosting (multi-tenant) | On a cloud, with **Garage** as the object storage we install, and the cloud's managed Postgres (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/<provider>/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.<CORE_DOMAIN>/sse?as_user=<CORE_USER>"
|
||
transport: sse
|
||
headers:
|
||
Authorization: "Basic ${MCPHUB_AUTH}"
|
||
supermarket:
|
||
command: socat
|
||
args: ["STDIO", "UNIX-CONNECT:<data folder>/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=<the user's own hub token from the Core (the part after "Basic "), from a hidden prompt>
|
||
```
|
||
|
||
How `install.sh` does it, safely and idempotently:
|
||
1. It uses `unsandboxed hermes config set mcp_servers.<name>.…`, the way
|
||
CoreDesktop's `configure hermes` calls Hermes. Hermes edits its YAML
|
||
with comment-preserving ruamel, so we never hand-edit its 2,400-line config.
|
||
If an `mcphub` entry already exists, it's left alone.
|
||
2. It asks whether Hermes may reach `mcphub.<CORE_DOMAIN>`. On yes, it adds
|
||
it to `network.allowedDomains` in
|
||
`~/.config/coredesktop/sandbox/hermes.json`. Hermes' sandbox blocks it
|
||
by default, and that file is the one no sandbox can write.
|
||
3. It stops the gateway (`hermes gateway stop`; Hermes starts it on demand) so the
|
||
servers load, then checks that Hermes lists the hub's tools.
|
||
4. The README documents the same block, with placeholders, for anyone setting
|
||
it up by hand.
|
||
|
||
How work flows through Hermes:
|
||
- **Writes (the CRM queue).** The app never calls EspoCRM itself. Approved
|
||
actions (create Lead, update Lead, add note, link Account) wait in a queue
|
||
with their exact payloads and an idempotency key. A Hermes cron job
|
||
installed by `install.sh` runs every 15 minutes. It calls
|
||
`supermarket.crm_pending_actions`, searches EspoCRM for duplicates, runs
|
||
each action through `mcphub`'s EspoCRM tools, and reports back with
|
||
`supermarket.crm_report_result(id, espo_id | error)`. You can also trigger
|
||
a run by asking Hermes, in its terminal or over Matrix.
|
||
- **Reads (for dedupe and metrics).** The same job pulls Leads, Accounts and
|
||
Opportunities changed since the last sync and hands them to
|
||
`supermarket.crm_ingest`. The app keeps a cached copy in SQLite.
|
||
- **Guardrails.** Hermes only carries out actions the app has queued; it
|
||
doesn't decide what goes into the CRM. Every result is checked against the
|
||
next read sync, and failures show in the app's CRM queue page with a retry
|
||
button.
|
||
- **Fallback.** The `crm` package has an interface. If having an LLM in the
|
||
loop proves too slow or unreliable for bulk writes, a direct MCP client in
|
||
the app can replace Hermes without changing the modules.
|
||
|
||
### Repo layout
|
||
|
||
```
|
||
cmd/supermarket/ server entry point
|
||
internal/
|
||
profile/ company, products, ICP, voice, websites
|
||
inventory/ partners & competitors (was config `applications:`)
|
||
ai/ provider interface: anthropic, openai-compatible
|
||
core/ core.conf, Core service URLs (Gitea, Plausible, MCP hub)
|
||
crm/ CRM queue + cached CRM data; executed by Hermes via mcphub
|
||
enrich/ contact-enrichment providers (Hunter, Apollo, …)
|
||
channels/ Publisher interface: x, linkedin, reddit
|
||
sources/ fetchers: x, youtube, rss/blog, reddit, (instagram)
|
||
content/ generation, drafts, approval, schedule, history ← today's pipeline
|
||
prospects/ discovery, enrichment, review, queue to CRM
|
||
seo/ crawler, checks, search-engine APIs, Hugo change sets
|
||
gitea/ clone, branch, PR, repo creation (SEO + Sites)
|
||
billing/ Stripe sync, MRR model, customer↔account matching
|
||
metrics/ pipeline influence, CAC, CLV, NRR
|
||
sites/ component library, page generation, publishing
|
||
mcp/ MCP tools over the modules (incl. the CRM bridge tools)
|
||
web/ handlers, templates, static assets
|
||
store/ SQLite + migrations
|
||
hermes/ cron job prompt + skill for the CRM bridge
|
||
Dockerfile · compose.yaml · install.sh · update.sh
|
||
```
|
||
|
||
### Sibling scripts
|
||
|
||
- `install.sh` (safe to re-run; it may prompt):
|
||
1. Checks that Docker is running and that the user is in the `docker` group.
|
||
2. Creates `~/.local/share/supermarket` and migrates
|
||
`~/.local/state/coremarketing/config.yaml` if it's there.
|
||
3. Runs `docker compose up -d --build`.
|
||
4. Adds the app-grid launcher with
|
||
`webapp add Supermarket http://localhost:8470`.
|
||
5. Sets up the Hermes bridge as described above, or explains how to run
|
||
`configure hermes` first if Hermes has no model provider yet.
|
||
6. Registers `/mcp` with Claude Code (`claude mcp add --transport http …`) so
|
||
it can drive the suite too.
|
||
- `update.sh` (doesn't prompt): runs `docker compose up -d --build`, which only
|
||
rebuilds when the source changed, and refreshes the Hermes cron job and skill
|
||
if they changed. It never touches the Hermes credentials. Schema migrations
|
||
run when the app starts.
|
||
- `restart: unless-stopped` keeps the app running across reboots, so scheduled
|
||
posts and syncs run without the browser open.
|
||
|
||
## 4. Domain model
|
||
|
||
### Company profile (one per install)
|
||
- Name, description, positioning, voice and tone, words to avoid
|
||
- **Products**: name, description, URL, pricing summary, key benefits
|
||
- **Ideal customer profile / targets**: industries, company size, roles,
|
||
regions, problems, buying signals, technologies they use
|
||
- **Websites** (many): URL, Gitea repo and branch, Plausible site, Search
|
||
Console property, Bing site
|
||
- **Accounts**: X handle, LinkedIn org/author, Reddit user, subreddits
|
||
- Keywords to rank for
|
||
|
||
The first time it runs, a wizard drafts the profile from the company's main
|
||
website with the AI, and the user edits it.
|
||
|
||
### Inventory (partners and competitors)
|
||
|
||
The current `applications:` list becomes the Inventory. Each entry has the same
|
||
fields as today (name, description, X handle, YouTube channel, Instagram,
|
||
hashtags) plus:
|
||
|
||
| Field | Purpose |
|
||
|-------|---------|
|
||
| `relationship` | `partner`, `competitor` or `watch` |
|
||
| `websites`, `linkedin`, `subreddits`, `rss` | More places to watch |
|
||
| `keywords` | Terms they own or compete on |
|
||
| `talking_points` | **Partners:** how we work together. **Competitors:** how we differ, where we win, what not to claim |
|
||
| `mention_policy` | Competitors: name them, or speak about the category without naming them |
|
||
|
||
What each relationship drives:
|
||
- **Partner**: today's behavior. Their news is fetched, and posts that
|
||
amplify it in our voice (co-promotion) are drafted for review.
|
||
- **Competitor: counter-programming.** Their launches, price changes, outages
|
||
and announcements trigger drafts that position our product, under the
|
||
entry's `mention_policy`. Also: "<competitor> alternative" landing-page
|
||
ideas, keyword-gap analysis against their sites, and prospects: companies
|
||
that use the competitor's product (technographics), and people asking for
|
||
alternatives on Reddit and X.
|
||
- **Watch**: only ecosystem news to curate, with no promotion either way.
|
||
|
||
Migration: entries from the old config are imported as `partner` (they are
|
||
the apps on a Federated Core), and the user re-labels them. The Federated list
|
||
ships as an example import file, `examples/federated-inventory.yaml`, not as a
|
||
default.
|
||
|
||
## 5. Phases
|
||
|
||
Each phase ends usable and with a release tag (`v0.x.0`).
|
||
|
||
### Phase 0: Foundation: web app, sibling, profile, Hermes bridge
|
||
|
||
**Status (2026-11-18): built on branch `phase0-foundation`.** Items 1–7 are
|
||
done, and so is the tooling for item 8. What changed from the plan:
|
||
- **No Hermes cron job yet.** Until Phase 2 there's no queued work, and every
|
||
run of the job is an LLM call. The bridge is tested by asking Hermes the
|
||
check-in question shown on the app's "Core & Hermes" page. The cron job
|
||
arrives with the CRM queue.
|
||
- **AI per task:** each task can use its own model, on the same provider.
|
||
- **The old TUI is gone.** Its post queue, dismissed items and last-checked
|
||
times are imported into SQLite, and its X/LinkedIn/YouTube clients and
|
||
fetcher are kept for Phase 1. Until Phase 1 lands, there's no way to post.
|
||
|
||
**Status (2026-11-20): Phase 0 is done, on `phase0-foundation`.** Item 8
|
||
works end to end: Hermes loads the hub's tools and checks in with the app.
|
||
|
||
What item 8 turned up:
|
||
- Sandboxed Hermes **can't** reach `127.0.0.1:8470` (see "Why a socket" in
|
||
the Hermes bridge section), so it reaches the app through `/data/mcp.sock`
|
||
with `socat`.
|
||
- `hermes config set` writes nested `mcp_servers.*` keys correctly, lists
|
||
(`args`) included.
|
||
- The hub rejected the shared admin token (401 at Traefik). The Core moved
|
||
to per-user tokens, still sent as `Authorization: "Basic <token>"`, with
|
||
`as_user=<user>` kept. The setup asks for the token, checks it with the
|
||
hub, and `supermarket hermes --reconfigure` re-enters it.
|
||
- The hub (FastMCP "mcpserver-hub" 3.2.0) speaks only SSE: a POST to `/sse`
|
||
gets 405. Hermes tries Streamable HTTP first, and that try ran out of its
|
||
60-second connect time, so setup.sh sets `transport: sse`. `tools/list`
|
||
takes about 10 seconds.
|
||
- A running Hermes gateway keeps its old servers, and `gateway stop` from
|
||
outside the sandbox didn't always stop it. setup.sh now checks the pid
|
||
file and says so when the gateway is still running.
|
||
- The hub offers 213 tools: Nextcloud 155, Listmonk 29, Superpanel 9,
|
||
Baserow 8, Plausible 6 and EspoCRM 6 (`espocrm_search_records`,
|
||
`espocrm_get_record`, `espocrm_get_related_records`,
|
||
`espocrm_create_record`, `espocrm_update_record`,
|
||
`espocrm_delete_record`). Hermes reports them with its own `mcp__mcphub__`
|
||
prefix, and the app stores the hub's names. Phase 2 builds on the generic
|
||
EspoCRM record tools.
|
||
- The per-user token also sees `nextcloud_admin_list_users` and
|
||
`nextcloud_admin_get_contacts`, both described as admin-only. To raise with
|
||
the Core's developer: it isn't known yet whether the hub blocks them for
|
||
non-admins.
|
||
|
||
Phase 1 followed (see below).
|
||
|
||
Supermarket's half can be checked before the token arrives: ask Hermes the
|
||
check-in question now. It should reach `bridge_checkin` and note that
|
||
mcphub failed.
|
||
|
||
1. Restructure into the layout above. Port config and the JSON stores to
|
||
SQLite, with import from the old files.
|
||
2. Dockerfile (multi-stage: Go build → slim runtime with git and hugo) and
|
||
`compose.yaml`.
|
||
3. `install.sh` / `update.sh` as above, following
|
||
`coredesktop/skills/sibling-project-format.md`.
|
||
4. Web shell: navigation between the modules, a settings page, a credentials
|
||
page with OAuth "Connect" buttons, and a Core status page (whether
|
||
`core.conf` was found, whether Gitea and Plausible answer, and when the
|
||
Hermes bridge last ran).
|
||
5. Company profile + the wizard that drafts it from the website.
|
||
6. AI provider layer: choose the provider and model per task, and test the
|
||
connection.
|
||
7. Inventory module: list, edit, import (from the old config and from YAML),
|
||
and relationship labels.
|
||
8. **Hermes bridge test** (do this early, since Phases 2 and 4 depend on it):
|
||
- ~~Can sandboxed Hermes reach `127.0.0.1:8470` once it's in
|
||
`hermes.json`?~~ No. Answered 2026-11-19: it uses the MCP socket instead.
|
||
- ~~Does `hermes config set` write nested `mcp_servers.*.headers` keys
|
||
correctly?~~ Yes.
|
||
- ~~What EspoCRM tools does the hub expose?~~ Six generic record tools
|
||
(above). Answered 2026-11-20.
|
||
- Can Hermes cron jobs call MCP tools? Built in Phase 2 part 1 (the
|
||
`supermarket-crm` job), not yet run live: the hub's EspoCRM connection
|
||
is stale.
|
||
- How reliable is a run of 50 queued actions? Not known until then.
|
||
|
||
### Phase 1: Content (today's pipeline, generalized) + Reddit
|
||
|
||
**Status (2026-11-20): Phase 1 is built (all 4 parts) on `phase0-foundation`.** Phase 1 is
|
||
built in four parts, each committed on its own: (1) the pipeline, items 1–2
|
||
below, for X and LinkedIn; (2) the approval inbox, schedule and UTM tags,
|
||
item 5; (3) Reddit, item 4; (4) promoting our own products, the rest of
|
||
item 3. The user chose per-channel drafts and this order on 2026-11-20.
|
||
|
||
Part 1 (commit `13bf18f`):
|
||
- One generation writes **one draft per channel** (a short X post, a longer
|
||
LinkedIn post), each edited, published and retried on its own. The old
|
||
`posts` table became the `drafts` table (migration 2), one row per
|
||
platform a queued post hadn't reached.
|
||
- Fetching reads the entry's X account, X hashtag search, YouTube and RSS
|
||
feeds (new). Items are stored in `content_items`. A fetch only moves the
|
||
entry's start time on if every source answered.
|
||
- Prompts come from the profile, the entry's relationship, talking points
|
||
and mention policy, and the channel. Fetched text is marked as untrusted
|
||
quotes. An X draft over the limit gets one request to shorten it.
|
||
- Publishing claims the draft first (`publishing`), so it can't post twice;
|
||
a draft left `publishing` by a restart is marked failed for review.
|
||
|
||
Part 2 (commit `f275f03`):
|
||
- **Inbox** (top-level menu, with a count): everything waiting for
|
||
approval, one section per module; Content's drafts for now. Phase 2's
|
||
prospects and Phase 3's SEO changes add sections.
|
||
- **Scheduling**: a draft is published now or scheduled (`scheduled`,
|
||
`publish_at`, migration 3). A scheduler in the app checks every 30
|
||
seconds. A post more than 12 hours overdue (the computer was off) goes
|
||
back to Posts rather than out stale, and so does one refused before
|
||
posting (signed out, too long). Content has Scheduled and Published tabs.
|
||
- **UTM tags** only on links to the company's websites and product URLs
|
||
(from the profile), added at publishing; drafts are stored untagged.
|
||
`utm_source` = channel, `utm_medium` = social, `utm_campaign` = kind of
|
||
post, `utm_content` = entry slug and draft ID.
|
||
- The container now runs in the computer's time zone (`SUPERMARKET_TZ` in
|
||
compose.env, from /etc/localtime), so times show and parse correctly.
|
||
|
||
Part 3, Reddit (commit `0e34f57`):
|
||
- A third channel, `reddit`: a draft has a `title` and a `target`
|
||
subreddit (migration 4), chosen when writing, with suggestions from the
|
||
entry's and the profile's subreddits. Reddit is never pre-checked.
|
||
- Sign-in through a Reddit "web app" (`duration=permanent`; scopes
|
||
identity, submit, read, history). The hour-long access token is
|
||
refreshed on a 401 and saved. Before sign-in, rules are read with an
|
||
app-only token (client credentials).
|
||
- Subreddit info (description, posting guidelines, rules, allowed post
|
||
types) is cached in `subreddits` for a day. It goes into the prompt and
|
||
is shown with the draft, with a Refresh button.
|
||
- The prompt asks for a community member's post that says where they work:
|
||
no hashtags, emoji or marketing language, following the rules.
|
||
- Publishing: a text post with "Source: <link>" at the end, or a link post
|
||
where the subreddit takes only links.
|
||
- Warnings, never blocking (`content.RedditWarnings`): promotion-related
|
||
rules, restricted subreddits, wrong post type, a post in the same
|
||
subreddit in the past 7 days, more than 1 in 10 recent posts linking to
|
||
the company's own sites (counting this one), and a new account. They use
|
||
the account's last 100 posts, cached for 10 minutes.
|
||
|
||
Part 4, promoting our own products:
|
||
- A virtual inventory entry for the company (`content.OwnEntry`, items
|
||
stored under `_own`), shown first under Content as the company's name and
|
||
served at `/content/own`. It isn't stored in `inventory`.
|
||
- Products from the profile are kept in step as items
|
||
(`product:<slug>`, source `Product`), always there to pick from; they
|
||
don't count as waiting news.
|
||
- A new profile field, **Feeds**: the company's blog, news and release
|
||
feeds, fetched like an entry's RSS.
|
||
- Site pages: new or updated pages from each website's `sitemap.xml`
|
||
(sitemap indexes one level deep), newest 15 per fetch, with each page's
|
||
title and description. This runs only for the company's own sites.
|
||
- Drafts get kind `product` (so `utm_campaign=product`) and the company's
|
||
name. The prompt asks for posts that promote the company's own work with
|
||
claims the material supports. On Reddit it asks for the makers' voice and
|
||
invites feedback, and Posts warns that self-promotion is often
|
||
restricted.
|
||
|
||
**Tried for real on 2026-11-21:** publishing to X and LinkedIn worked (LinkedIn needed the "Sign In with LinkedIn using OpenID Connect" product; X's callback must use 127.0.0.1). Reddit refuses new API apps without approval, so Reddit drafts are posted by hand. The full hand-testing checklist is now TEST.md; the steps below were the first one.
|
||
|
||
**Originally deferred on 2026-11-21 for the UI redesign below.** Parts 1–4 are covered by tests with fake AI
|
||
and channel clients, and the rebuilt app runs (schema 3). But the
|
||
installed app has no profile, AI key, inventory or social sign-ins yet, so no
|
||
real fetch, generation or post has been made. Before relying on it:
|
||
1. Fill in the Profile, add an Anthropic key, and add an inventory entry
|
||
with an RSS feed (needs no credentials).
|
||
2. Fetch, write drafts, and check Posts's prompts and lengths.
|
||
3. Connect X and LinkedIn, publish one draft now, schedule one a few
|
||
minutes ahead, and check that both go out, with UTM tags on a link to
|
||
the company's site.
|
||
4. Register a Reddit web app, connect it, write a Reddit draft for a
|
||
subreddit, and check its rules and warnings. Post to a test subreddit
|
||
you moderate first.
|
||
5. Add a product and a blog or releases feed to the profile, open
|
||
Content → (company name), fetch, and write a post from a product.
|
||
|
||
The database before migration 2 is backed up at
|
||
`~/.local/share/supermarket/app.db.pre-phase1`. Commits on
|
||
`phase0-foundation` are pushed from a host terminal (no credential helper,
|
||
so `git push` can't prompt from Claude Code). The branch stays off `main`
|
||
until the user decides to merge; posting works again now, which was the
|
||
condition for merging.
|
||
|
||
**UI redesign (2026-11-21).** The user asked for brain
|
||
(gitea.federated.computer/Federated_Computer/brain, a Next.js + Tailwind
|
||
app) to be the UI basis from now on. Supermarket stays Go templates + htmx;
|
||
it takes brain's look rather than its stack: brain's colour tokens, type,
|
||
radius and shadows (and its dark theme, following the system setting), a
|
||
left sidebar with search at the top and Settings at the bottom, a top bar
|
||
with breadcrumbs, and Settings as grouped tabs on the left. The menu:
|
||
Search, Overview (module cards and setup), Inventory, then the modules
|
||
(Content with Posts (was Inbox, renamed 2026-11-21), Sources, Scheduled and Published; the later phases
|
||
shown greyed out). Settings holds Profile, Social accounts (was
|
||
Credentials; keys and sign-in together per network), Core & Hermes, and AI
|
||
(provider, model, and the API keys, which moved there from Credentials).
|
||
Old addresses (`/profile`, `/core`, `/settings/credentials`) redirect.
|
||
Search (`/search`) matches every word across posts, fetched items, the
|
||
inventory, products and settings pages. New modules add a `modules` entry
|
||
in `internal/web/server.go` and an icon in `layout.html`. brain's fonts
|
||
(DM Sans, Plus Jakarta Sans) are named but not bundled, so the system font
|
||
is used unless they're installed.
|
||
|
||
**Done since:** Phase 1 was tried for real (posting to X and LinkedIn
|
||
worked on 2026-11-21), merged into `main` and tagged `v0.1.0` on
|
||
2026-11-21. Phase 2 followed.
|
||
|
||
The plan for Phase 1, as first written:
|
||
1. Port fetch → browse → select → generate → approve → publish into the web
|
||
UI, keeping the dismiss feature, tracking of what was posted where, partial
|
||
posting, and X length handling.
|
||
2. Generation prompts are built from the profile, the inventory entry's
|
||
relationship and talking points, and the target channel.
|
||
3. Content types: partner amplification, competitor counter-programming,
|
||
promotion of our own products (from the product list, site pages, blog RSS,
|
||
and releases).
|
||
4. Reddit: OAuth, subreddit list, each subreddit's rules shown with the draft,
|
||
approval always required, warnings about posting too often.
|
||
5. Scheduling queue, an approval inbox for drafts from all modules, and UTM
|
||
tags on every link so Metrics can attribute visits.
|
||
|
||
### Phase 2: Buying signals, prospects and the funnel
|
||
|
||
**Started 2026-11-21** on branch `phase2-prospects`, after Phase 0 and 1
|
||
were merged into `main` and tagged `v0.1.0`. **Parts 1 to 7 built, and
|
||
merged into `main` on 2026-11-22** (d23d5e2). Part 8 (Hugo pages per
|
||
signal) was built in Phase 5, part 4. Stripe and Plausible were connected
|
||
later on 2026-11-22. Not yet tried against the live services: discovery's
|
||
web search, outreach's mailbox, and the CRM bridge, which waits on the
|
||
Core's MCP hub.
|
||
|
||
**Reframed 2026-11-21 (the user's direction).** Phase 2 is built around
|
||
**buying signals**: hypotheses about why a company buys now, which are
|
||
defined, found, and then *tested* through direct action (email, LinkedIn)
|
||
and indirect action (social posts, blog posts, website and landing pages),
|
||
with results measured through the whole funnel to payment in Stripe.
|
||
Content is tested against signals and signals against content. Later, the
|
||
Hugo sites (Phase 5) create, duplicate and delete pages from this
|
||
feedback loop. origami.chat and explee.com, where signals and prospects
|
||
are already being tested, feed their results in.
|
||
|
||
**A signal** has: a name; the hypothesis ("teams complaining about the
|
||
Microsoft 365 price rise will switch within a quarter"); how to spot it
|
||
(Claude web search queries, social keywords, origami.chat / explee.com
|
||
criteria); the angle (pain and promise) for messages and content; a status
|
||
(idea, testing, proven, retired); and a slug used as `utm_campaign`.
|
||
|
||
**Everything is tagged with a signal and recorded in one funnel-event
|
||
log** (signal, channel, prospect/contact/content, stage, date, value), so
|
||
the scorecard is one query and new sources drop in without rework.
|
||
Stages, each of which counts as a success where it happens:
|
||
|
||
```
|
||
found → contacted/reached → replied → clicked the scheduling link / booked
|
||
→ visited the website or a landing page → signed up (trial, free tier) → paid
|
||
(then expanded or churned)
|
||
```
|
||
|
||
Channels: email, LinkedIn, social posts, blog posts, website pages,
|
||
origami.chat, explee.com. The **scorecard** shows, per signal and per
|
||
channel, the count at each stage and the conversion between them, revenue,
|
||
cost (AI, Hunter, origami.chat and explee.com fees) and CAC; and per piece
|
||
of content, which signal it serves and how it did. Numbers will be small:
|
||
it shows counts plainly, and a signal is "proven" only past a threshold
|
||
the user sets.
|
||
|
||
**How each stage is measured.** Supermarket runs on localhost and nothing
|
||
on the internet can reach it, so it can't use tracking pixels or its own
|
||
link redirects. Instead:
|
||
- *Replied*: IMAP on the Core's mail server reads replies to Supermarket's
|
||
emails (matched by Message-ID / thread). "STOP"-style replies go on the
|
||
suppression list.
|
||
- *Scheduling link*: the link carries UTM tags and goes through the website
|
||
or Cal.com on the Core; bookings come from Cal.com (stronger than a
|
||
click), visits from Plausible.
|
||
- *Website / landing page*: Plausible, by `utm_campaign` (the signal) and
|
||
`utm_content` (the piece of content or message). Measured per signal in
|
||
aggregate, not per person: following individuals around the website
|
||
would cut against Federated's privacy positioning.
|
||
- *Signed up / paid*: Stripe (read-only restricted key). A payment is tied
|
||
to a signal through the CRM (Stripe customer email/domain → EspoCRM
|
||
Account → prospect → signal), and, for self-serve sign-ups, through the
|
||
UTM campaign saved in Stripe metadata at sign-up. Customers buy through
|
||
Federated's shopping cart, which uses Stripe, so the cart has to pass the
|
||
visitor's UTM tags into the Stripe Checkout session's metadata.
|
||
- *origami.chat / explee.com*: their APIs.
|
||
|
||
**Sending email (the user's decision):** Supermarket sends through
|
||
mail.federated.computer on the Core (SMTP, with IMAP for replies). Every
|
||
email is drafted from the signal's angle, reviewed, and sent one by one at
|
||
a low daily limit, with a plain opt-out line; the suppression list is
|
||
checked before sending. Recommended: a dedicated mailbox, and SPF, DKIM
|
||
and DMARC checked first, so outreach can't hurt the domain's normal mail.
|
||
**LinkedIn** can't be automated (its API doesn't allow messaging, and
|
||
automation risks the account): Supermarket drafts the message and opens
|
||
the profile, the user sends it and marks it sent, as with Reddit posts.
|
||
|
||
**origami.chat and explee.com have APIs** (checked 2026-11-21, not yet
|
||
tried with a key): origami.chat has a typed API at
|
||
`https://origami.chat/api/v3` (Leads, Send, Account; long-running Jobs;
|
||
webhooks; an MCP server); explee.com has a public API at
|
||
`https://api.explee.com` (company search with natural-language queries and
|
||
`criteria` scoring; API key from Organization Settings; OpenAPI schema at
|
||
`/public/api/openapi.json`). Before building: what each returns for a
|
||
campaign's results (replies, meetings), and their terms on storing the
|
||
data. Each becomes an adapter behind a `leadsource` interface.
|
||
|
||
**Parts, in order, a commit after each:**
|
||
1. **The CRM bridge** (done, 1dc5476): the queue, the Hermes job, the read
|
||
sync, the CRM queue page. Its live test waits on the Core's MCP hub,
|
||
which connects to EspoCRM at a stale LAN address.
|
||
2. **Prospects and review** (done, 7633697): companies and contacts with
|
||
provenance, Review (accept → Account / Lead), adding by hand, CRM
|
||
duplicate warnings, the suppression list, search.
|
||
3. **Signals and the funnel**: the signal library, tagging prospects with
|
||
a signal, the funnel-event log, the scorecard (with what exists so far),
|
||
and importing origami.chat and explee.com results through their APIs,
|
||
so the scorecard starts with real data. **Built 2026-11-21**
|
||
(schema 7): `signals` (library, statuses, utm slug), `funnel_events`
|
||
(stage, channel, subject, email, campaign, source, external ID for
|
||
dedupe, count, value), `outside_campaigns` (assigned to a signal by the
|
||
user), the Signals scorecard (period and channel filters, people once
|
||
per stage, revenue, spend), the signal page (funnel by channel,
|
||
campaigns, latest steps), prospects tagged with a signal (filter, change,
|
||
"found" recorded), outcomes recorded by hand on prospects, and Settings
|
||
→ Lead sources. The explee.com import follows its typed OpenAPI schema
|
||
(campaigns, analytics, contacted leads, hot leads); the origami.chat
|
||
import reads loose JSON by the names in its docs (campaigns, stats,
|
||
enrolled people, replies) and its Test button shows the real responses,
|
||
to confirm with the user's key. Webhooks need a public address, so both
|
||
are polled every 6 hours.
|
||
4. **Discovery per signal**: saved Claude web searches belonging to a
|
||
signal, run on a schedule, each prospect with its citation; explee.com
|
||
company search as a second source. **Built 2026-11-21** (schema 8):
|
||
`internal/discovery`, `ai.Research` (the SDK's `web_search_20260209`
|
||
server tool, `pause_turn` resumed, sources gathered from search results
|
||
and citations), a company kept only when its evidence URL is among the
|
||
pages searched, exclusions (ours, inventory, prospects, CRM Accounts,
|
||
suppressed), explee.com `search/companies` with the hypothesis as a
|
||
criterion and strong matches only, `discovery_runs` with notes and
|
||
search counts, the signal page's Find companies card (polls while
|
||
running), and an every-7/14/30-days schedule. Not yet run against the
|
||
live API.
|
||
5. **Enrichment with Hunter**: the right people and verified emails at
|
||
accepted companies. **Built 2026-11-22** (schema 9):
|
||
`internal/api/hunter` (Domain Search, Email Finder, Email Verifier with
|
||
its 202 polling, Account; credits read from `X-Credits-Used`),
|
||
`internal/enrich` (find people at a company's domain by the departments,
|
||
seniority and number chosen in Settings → Lead sources; find a named
|
||
person's address; verify addresses, singly or all unchecked ones in New,
|
||
stopping when the key, credits or rate limit give out), and
|
||
`enrich_runs`, which keeps every call with its result and credits. The
|
||
buttons are on Review, for new and accepted companies alike; people
|
||
found go to New under their company. Nothing runs on a schedule, since
|
||
every call spends credits. Credits are counted but not yet turned into
|
||
spend for CAC (Hunter.io bills by plan, not per credit).
|
||
6. **Direct outreach**: email through the Core's mail server (drafted,
|
||
reviewed, sent, replies read over IMAP) and LinkedIn by hand; each
|
||
outcome recorded in the funnel. **Built 2026-11-22** (schema 10):
|
||
`internal/outreach` and the `outreach` table. Drafts come from the AI
|
||
(task "outreach") with the signal's hypothesis and angle, the person,
|
||
their company and their history. The queue sends one email at a time
|
||
(net/smtp, STARTTLS on 587 or TLS on 465) within the sending hours, the
|
||
daily limit and a gap. Before each send it checks the suppression list,
|
||
bouncing addresses, and anyone emailed in the last 14 days. Emails are
|
||
plain text with the signature, an opt-out line, `List-Unsubscribe`,
|
||
UTM-tagged links to our sites (utm_campaign = the signal) and a
|
||
Message-ID kept for matching replies; a copy goes to Sent via IMAP
|
||
APPEND. The inbox is read every 10 minutes with emersion/go-imap,
|
||
read-only (EXAMINE, BODY.PEEK), from the last UID. A reply is matched
|
||
by In-Reply-To/References, or else by sender. Out-of-office replies are
|
||
skipped. Bounces mark the address invalid. "Stop" replies go on the
|
||
suppression list. LinkedIn messages are copied and sent by hand, then
|
||
marked sent and replied. Sent counts as Contacted and a reply as Replied.
|
||
Settings → Email has the mailbox (password in `secrets.json`), the
|
||
limits, the signature, an optional scheduling link, and a check (SMTP
|
||
and IMAP sign-in, SPF, DKIM at common selectors, DMARC). Follow-up
|
||
sequences aren't automatic yet: a second draft to the same person is
|
||
written as a follow-up, and can go after 14 days.
|
||
7. **Indirect and the end of the funnel**: content drafts tagged with a
|
||
signal (UTM per signal), Plausible results per signal, Cal.com bookings,
|
||
and Stripe sign-ups and payments (pulled forward from Phase 4's Stripe
|
||
sync). **Built 2026-11-22** (schema 11):
|
||
- **Content.** Drafts can be written for a signal (`drafts.signal_id`).
|
||
The prompt gets the signal's hypothesis and angle, and the UTM
|
||
campaign becomes the signal's slug. The signal page lists its posts
|
||
and the websites tagged with its campaign.
|
||
- **Plausible.** `internal/api/plausible` (Stats API v2) and
|
||
`internal/tracking`. Once a day it reads the completed days' visitors,
|
||
filtered to the signals' campaigns, by day, source, medium and
|
||
content. These become aggregate Visited events, with the channel from
|
||
source and medium. Sites come from the profile.
|
||
- **Stripe.** `internal/api/stripe`, with a restricted key. It reads
|
||
completed Checkout Sessions and paid invoices every hour. A $0
|
||
checkout is Signed up. Paid invoices, and one-time payments without
|
||
an invoice, are Paid with their value. `stripe_customers` keeps each
|
||
customer's signal: from checkout metadata `utm_campaign` (or
|
||
`signal`), or else from the email matching a prospect person or
|
||
company domain.
|
||
- **Cal.com.** The Core's Cal.com has no API: /api/v1 and /api/v2 both
|
||
return 404 (checked 2026-11-22). The user chose to read booking
|
||
notices from the outreach mailbox instead: emails from the
|
||
configured Cal.com sender count as Booked for the first address
|
||
that isn't ours. Cancellations, reschedules, requests and reminders
|
||
are skipped.
|
||
- **Still to do.** The cart has to save the UTM tags in the Checkout
|
||
Session's metadata. Settings → Website & sales says how.
|
||
8. **Later, with Phase 5 (sites)**: Hugo pages per signal, created,
|
||
duplicated or deleted from the scorecard, through Gitea PRs. **Built in
|
||
Phase 5's part 4 (2026-11-22).**
|
||
|
||
Inbound: the lead-form component (Phase 5) queues a Lead the same way,
|
||
tagged with the signal from its UTM campaign.
|
||
|
||
### Phase 3: SEO, for all of the company's websites
|
||
|
||
**Started 2026-11-22** on branch `phase3-seo`, after Phase 2 was merged
|
||
into `main`. **All seven parts built, and merged into `main` on
|
||
2026-11-22** (2302fb0).
|
||
|
||
**Decisions (the user, 2026-11-22).**
|
||
- **chatseo.app:** borrow its ideas only, no subscription. It was reviewed
|
||
as the reminder asked. It's a paid chat-based SEO agent (from €39 a
|
||
month; MCP and API from €59) built on Search Console, DataForSEO and its
|
||
own crawler. Two ideas are worth taking: rank every issue by its Search
|
||
Console impressions and clicks, and check whether AI assistants can read
|
||
and cite the site.
|
||
- **Rankings come from Search Console only**: Google's own position per
|
||
query and page, free. There is no keyword-volume or SERP data provider.
|
||
Where the live top results matter (a brief, a keyword's competition),
|
||
they're read with Claude's web search, which costs searches, only when
|
||
the user asks.
|
||
- **The workflow follows a "full lifecycle" post** (@thwlf67, 18 Nov 2026,
|
||
saved by the user as a PDF). SEO for a small site is seven jobs that
|
||
come back every week: find what already ranks, find the next keywords,
|
||
write a brief, write the page, approve and publish, check Search Console
|
||
every morning, and write the Monday report. Supermarket does six of them;
|
||
the user keeps the approval. Its rules become the module's rules:
|
||
- Every number comes from the data, and none is invented: when a source
|
||
returns nothing, the report says "no data", not zero.
|
||
- Every recommendation carries the number that justifies it.
|
||
- Thresholds decide what's worth reporting, and "nothing real moved" is a
|
||
one-line answer.
|
||
- One job at a time, each with its own definition of done.
|
||
- Nothing changes on a site without the user's yes, given one change at a
|
||
time, never in bulk; at most 3 recommendations a week.
|
||
- Pages never claim tests or experience that didn't happen. A brief ends
|
||
with the questions only the user can answer, and the draft is written
|
||
around their answers, with what wasn't tested said plainly.
|
||
- The weekly report has a fixed format, so this Monday compares with the
|
||
last in seconds.
|
||
- Numbers are computed in code, from Search Console. The AI writes words
|
||
around them (titles, briefs, pages, the reasons in a report) and never
|
||
produces a number itself.
|
||
|
||
**Parts, in order, a commit after each:**
|
||
1. **Search Console and "what already ranks" (job 1).**
|
||
- Connect Google with OAuth (read-only `webmasters.readonly`), from
|
||
Settings. Choose the property for each website in the profile.
|
||
- Sync daily rows by page and query (and page alone, since Google hides
|
||
some queries) into SQLite. Start with 16 months of history, then the
|
||
latest final days. Search Console data is 2 to 3 days late, and the
|
||
app says so.
|
||
- An SEO page per site, showing:
|
||
- The 90-day totals and click rate.
|
||
- The best pages by clicks.
|
||
- The queries Google shows most where almost nobody clicks.
|
||
- The pages to **protect** (they carry the clicks) and to **push**
|
||
(they rank on page one and don't get clicked), each with the number
|
||
that justifies it.
|
||
- The share of clicks from queries Google doesn't name.
|
||
- **Built 2026-11-22** (schema 12):
|
||
- `oauth.GoogleStart` (PKCE, offline access) and `internal/api/gsc`
|
||
(sites and search analytics, paged at 25,000 rows).
|
||
- `internal/seo`: `Sync` reads 30-day chunks of date, date+page and
|
||
date+page+query rows. Position is stored × impressions. The last 4
|
||
days are re-read each time.
|
||
- `WhatRanks` computes job 1 over 90 days. *Protect* is the top 3
|
||
pages by clicks. *Push* is page-one pages (position ≤ 10.5) with at
|
||
least 100 impressions and under 1% click rate, each with its main
|
||
query and that query's share.
|
||
- Settings → Search engines: keys, the redirect URI, Connect, and the
|
||
property for each website, saved in the profile.
|
||
- SEO → What ranks, with a sync twice a day.
|
||
Committed as 5ea620a.
|
||
2. **Morning check and Monday report (jobs 6 and 7)**, computed in code.
|
||
- **Morning check:** the last 7 final days against the 7 before, by
|
||
page and by query. It reports only moves past the thresholds (default:
|
||
more than 5 clicks, or more than 3 positions on at least 300
|
||
impressions; both editable). Otherwise it says one line.
|
||
- Each move is explained where the data allows. The key case is "the
|
||
page didn't lose its ranking, Google showed its big query less, so
|
||
the average moved", found by splitting a page's position change by
|
||
query. A query that vanished is "no data", not a drop to zero.
|
||
- **Monday report**, on one page and the same every week:
|
||
1. Clicks, impressions and position, against the week before, with a
|
||
sentence on where the change came from: visibility, or rank and
|
||
click rate.
|
||
2. The 3 pages that moved most.
|
||
3. A list called "Waiting for your yes", with at most 3 changes.
|
||
- Kept as history, so reports can be compared. Optionally emailed to
|
||
the user through the Core's mail server.
|
||
- **Built 2026-11-22** (schema 13: `seo_reports`):
|
||
- `seo.MorningCheck` compares the last 7 final days with the 7
|
||
before, for pages and for searches. Pages that vanished show as
|
||
"no data". New ones count once they reach the impressions
|
||
threshold.
|
||
- A page's move is explained by the search whose clicks changed most,
|
||
and a like-for-like position: the searches it had both weeks,
|
||
weighted by this week's impressions. When that's under half the
|
||
move, the cause is the mix of searches. The search whose
|
||
impressions changed most is named.
|
||
- `seo.Weekly` writes the three numbers and a sentence on where the
|
||
change came from: rank and click rate, or visibility, plus "one
|
||
week is not a trend" under 200 clicks. It adds the 3 pages that
|
||
moved most, with causes. "Waiting for your yes" holds job 1's
|
||
*Push* pages until part 4 brings exact changes.
|
||
- Written on Mondays (or when the last report is over a week old),
|
||
stored, and optionally emailed through the outreach mailbox
|
||
(`outreach.SendToSelf`).
|
||
- The thresholds and the email option are under Settings → Search
|
||
engines; the pages are SEO → Morning check and Monday report.
|
||
3. **Technical audit, weighted by traffic, plus AI visibility.**
|
||
- A crawler (within the site's sitemap and links, polite, robots.txt
|
||
honoured) checks each page's:
|
||
- title and meta description (length in characters and pixels)
|
||
- H1 and heading order
|
||
- canonical, hreflang and noindex
|
||
- status, redirects and broken links
|
||
- images without alt text
|
||
- Open Graph and JSON-LD
|
||
- sitemap and robots.txt coverage
|
||
- Optionally, Core Web Vitals from the PageSpeed Insights API.
|
||
- Every issue is ranked by the page's Search Console impressions and
|
||
clicks, so a fix list starts with the pages that bring traffic.
|
||
- **AI visibility:** whether robots.txt lets AI crawlers in (GPTBot,
|
||
ClaudeBot, PerplexityBot, Google-Extended…), an `llms.txt`,
|
||
structured data, and pages readable without JavaScript.
|
||
- One more check, from job 3: a page's biggest query compared with its
|
||
title. When they don't say the same thing, that's the cheapest fix
|
||
there is.
|
||
- **Built 2026-11-22** (schema 14: `seo_audits`):
|
||
- `seo.RunAudit` reads robots.txt, llms.txt and the sitemaps. It then
|
||
reads up to 300 pages, in this order: the busiest pages from Search
|
||
Console, the sitemap's pages, then pages found through internal
|
||
links. A page robots.txt disallows is skipped.
|
||
- Redirects are counted. It checks up to 150 outside links (HEAD,
|
||
with GET as a fallback).
|
||
- Pages are parsed with `golang.org/x/net/html`.
|
||
- Issues have a severity:
|
||
- Error: 4xx/5xx, noindex on a page Google shows or the sitemap
|
||
lists, no title.
|
||
- Warning: title over about 600 px (Arial widths), no description,
|
||
no H1, a canonical pointing elsewhere, broken links, invalid
|
||
JSON-LD, and a title that covers under 3/4 of the main search's
|
||
words when that search brings 30%+ of the impressions.
|
||
- Notice: the rest.
|
||
- Issues are sorted by severity, then the page's 90-day clicks and
|
||
impressions.
|
||
- The AI checks: AI crawlers in robots.txt (GPTBot, OAI-SearchBot,
|
||
ChatGPT-User, ClaudeBot, Claude-User, Claude-SearchBot,
|
||
PerplexityBot, Google-Extended, Applebot-Extended, CCBot),
|
||
llms.txt, JSON-LD coverage, Organization or WebSite data, and text
|
||
in the HTML without JavaScript.
|
||
- Optionally, PageSpeed Insights (mobile, field data when there is
|
||
some) for the 5 busiest pages, with an optional API key.
|
||
- It runs in the background, once a week on its own or with *Audit
|
||
now*. The page is SEO → Audit.
|
||
4. **Changes, approval and pull requests (job 5), with before/after.**
|
||
- The AI proposes the exact change: a title, a meta description or an
|
||
H1. Each one comes with the number that pays for it and the title's
|
||
length in characters and pixels.
|
||
- The user says yes or no, one change at a time.
|
||
- A yes clones the site's Gitea repository into `/data/sites/` and
|
||
edits the page's front matter or content on a branch. It checks that
|
||
`hugo` still builds, shows the diff, and opens a pull request.
|
||
Nothing is pushed to the default branch, and merging is the user's
|
||
decision.
|
||
- Once merged and live, the change is checked on the site and pinged
|
||
with IndexNow. Its page's clicks, impressions and position are then
|
||
compared over the weeks before and after (PLAN item "before/after
|
||
tracking"). The morning check notices when a yes changed something.
|
||
- **Built 2026-11-22** (schema 15: `seo_changes`). Hugo 0.147 extended
|
||
is in the image.
|
||
- **Proposing.** `seo.Candidates` takes the *Push* pages first, then
|
||
the audit's title and description issues on pages with traffic,
|
||
then the rest. It skips pages with a change in the last 90 days.
|
||
`Proposer` reads the live page and its 90-day searches, and the AI
|
||
(task "seo") writes the title without the site's suffix (found
|
||
from the audit or the company name) and a description. Titles
|
||
over the pixel budget get one request to shorten. At most 3 wait.
|
||
*Propose a fix* is also on audit rows and *Push* pages.
|
||
- **Applying.** A yes runs `Applier` in the background. It gets the
|
||
repository from Gitea (push rights needed) and syncs a working copy
|
||
in `/data/sites/owner__name`; the token goes in as an HTTP header,
|
||
never into `.git/config`. It finds the content file (`index.md`,
|
||
`_index.md`, `url`, `slug`, language folders), works out the front
|
||
matter title from how the theme builds titles (`titleValue`), and
|
||
sets `title` and `description` (YAML or TOML). It builds before and
|
||
after: if the site builds, the built page's title and description
|
||
must come out as proposed. It then pushes `supermarket/seo-<id>`
|
||
and opens a pull request with the numbers.
|
||
- **Following up.** `Refresh`, every 30 minutes, notes a merge or a
|
||
close, then marks the change live once the live page shows it.
|
||
`ImpactOf` compares the page over equal windows (up to 28 days a
|
||
side, from 3 days of final data).
|
||
- The Monday report's "Waiting for your yes" lists the proposals.
|
||
- Settings → Search engines has Gitea's address (the Core's by
|
||
default), the token and a test. The repository and branch per
|
||
website stay in the profile.
|
||
- IndexNow moves to part 7.
|
||
5. **The next keywords (job 2).**
|
||
- Candidates come from four places:
|
||
- Search Console queries with impressions and no page that answers
|
||
them.
|
||
- The profile's keywords and targets.
|
||
- The signals' "How to spot it" lines.
|
||
- Content gaps against competitors' sites in the Inventory, from
|
||
their sitemaps and titles.
|
||
- Each candidate is checked against our own pages ("no page" must
|
||
really mean no page).
|
||
- On request, Claude's web search reads who holds the live top 3. A
|
||
keyword is ranked by who has to be beaten, not by volume; volume and
|
||
difficulty aren't available and say "not available".
|
||
- Pick one a month.
|
||
- **Built 2026-11-22** (schema 16: `seo_keywords`):
|
||
- `seo.FindKeywords` gathers candidates from:
|
||
- Search Console searches with 20+ impressions in 90 days at an
|
||
average position below 20;
|
||
- the profile's keywords and its customers' problems (not product
|
||
names: nobody searches a name they don't know, and "X
|
||
alternative" is what people search to leave X);
|
||
- the active signals' "How to spot it" lines;
|
||
- competitors' sitemaps, using the words of each page's address
|
||
(up to 400 pages, with junk like about, tag or dates dropped).
|
||
- Each candidate is dropped when one of our pages (from the latest
|
||
audit, or the sitemap) covers 3/4 of its words in its title or
|
||
address.
|
||
- Intent is "buyer" for price, cost, best, review, vs, alternative,
|
||
buy, hosting, provider and the like.
|
||
- `ReadTop` asks Claude with web search (at most 3 searches) for the
|
||
live top 3, each typed: big brand, marketplace, forum, social,
|
||
small site, ours, or unread. A result not among the pages the
|
||
search returned is marked unread.
|
||
- The ranking puts read keywords first, easiest first (a big brand
|
||
or marketplace counts 3, the rest 1), then buyer intent, then
|
||
impressions.
|
||
- On SEO → Next keywords you can pick, dismiss or bring back a
|
||
keyword. Picks feed part 6's briefs.
|
||
6. **Briefs and pages (jobs 3 and 4).**
|
||
- A brief starts from what the page is really shown for in Search
|
||
Console, then the live top 5 (read with web search, and "couldn't
|
||
read" said where a fetch failed).
|
||
- It gives the title, meta description, H1, the sections in order, the
|
||
questions the page must answer, and 3 internal links to existing
|
||
pages.
|
||
- It ends with questions only the user can answer.
|
||
- From the brief and the user's answers, a draft page or rewrite is
|
||
written into the Hugo site as a pull request. The draft goes through
|
||
a check that underlines every sentence claiming an experience ("we
|
||
tried", "in our test") for the user to confirm.
|
||
- Pages can be tagged with a buying signal (Phase 2's campaign tags), so
|
||
landing pages count on its scorecard.
|
||
- **Built 2026-11-22** (schema 17: `seo_briefs`):
|
||
- **The brief.** `Writer.NewBrief` handles a picked search (a new
|
||
page) or an existing page (a rewrite; the search defaults to its
|
||
biggest). It reads the page and its 90-day Search Console searches,
|
||
then makes one Claude research call (at most 5 web searches). That
|
||
call returns the finding, the top 5 (each with what it promises,
|
||
what it lacks, and whether it was read), and the plan: title,
|
||
description, H1, angle, sections, questions, internal links (kept
|
||
only when they point to our pages), needs, and "ask", the questions
|
||
only the owner can answer. A result not among the pages searched
|
||
is marked unread.
|
||
- **The page.** `WritePage` refuses until every question is answered.
|
||
It drafts Markdown from the brief and the answers (plus the
|
||
current text for a rewrite), with experience only from the
|
||
answers and "not tested" said plainly. `Claims` flags sentences
|
||
like "we tested…", "in our test" or "after two months".
|
||
- **The pull request.** `ApplyBrief` needs every flagged claim
|
||
confirmed. It writes a new content file (YAML front matter: title,
|
||
description, date), or for a rewrite replaces the body and sets
|
||
title and description. It checks with a Hugo build that the page
|
||
exists, then pushes `supermarket/page-<id>` and opens a pull
|
||
request listing the confirmed claims and what's still to add by
|
||
hand.
|
||
- **Following up.** `RefreshBriefs` follows the merge, then the live
|
||
page. Entry points: a pick on Next keywords, *Push* on What ranks,
|
||
and SEO → Briefs and pages.
|
||
- Tagging a page with a signal is left for Phase 5's pages.
|
||
7. **Bing and IndexNow:**
|
||
- Bing Webmaster's API, for Bing's queries and crawl problems.
|
||
- IndexNow on every merge.
|
||
- The Search Console sitemap status.
|
||
- **Built 2026-11-22** (no schema change):
|
||
- `internal/api/bing` reads traffic, query stats and crawl issues,
|
||
with an API key and the profile's Bing site (or the website's
|
||
address).
|
||
- `gsc.Sitemaps` lists the sitemaps Search Console has.
|
||
- **IndexNow.** A 32-hex key is kept in settings. `KeyLive` checks the
|
||
site serves `<key>.txt`. Once it does, `NewlyLive` submits the
|
||
pages that went live through Changes or Briefs in the last 14 days
|
||
and haven't been submitted, every 30 minutes, to
|
||
api.indexnow.org. The last 30 submissions are kept.
|
||
- **Site setup.** `Applier.SetupSite` opens one pull request,
|
||
`supermarket/search-engines`, that adds `static/<key>.txt`, a
|
||
`static/robots.txt` naming the sitemap (unless the site has one),
|
||
and takes `sitemap` out of a one-line `disableKinds`. A build
|
||
checks that sitemap.xml, robots.txt and the key file come out.
|
||
- `hugorepo` gained `WriteFile`, `Exists`, `ConfigFile` and
|
||
`EnableSitemap`. Files written are tracked, so commits never pick
|
||
up Hugo's generated files.
|
||
- The page is SEO → Search engines; the Bing key is under Settings →
|
||
Search engines. Submitting a sitemap to Google needs a write
|
||
scope, so the page says to do it in Search Console.
|
||
- Fixed along the way: `NewlyLive` looked things up while a query
|
||
still held the database's only connection, and would hang. It now
|
||
reads all rows first.
|
||
|
||
Before the first part: a Google Cloud project with the Search Console API
|
||
turned on and an OAuth client (redirect
|
||
`http://localhost:8470/auth/google/callback`), and a Gitea token with access
|
||
to each site's repository (needed from part 4).
|
||
|
||
### Phase 4: Metrics, with Stripe
|
||
|
||
Phase 2 (part 7) brings in the Stripe sync and ties payments to buying
|
||
signals; this phase builds the full metrics on top of it.
|
||
|
||
1. **Stripe sync**: a restricted, read-only key; customers, subscriptions,
|
||
invoices, credit notes and refunds; a full backfill, then incremental
|
||
updates through the Events API.
|
||
2. **MRR model**: MRR per customer per month, normalized from subscription items
|
||
(annual ÷ 12, with discounts, trials and pauses handled), classified as new,
|
||
expansion, contraction, churn or reactivation.
|
||
3. **Matching** Stripe customers to EspoCRM Accounts (from the cached CRM data)
|
||
by email domain or stored ID, with a screen to fix the matches it gets wrong.
|
||
4. **Spend log** for CAC: entered by hand or imported from CSV, by channel and
|
||
month (Stripe has no marketing spend). Enrichment provider costs can be
|
||
logged automatically.
|
||
|
||
| Metric | Definition | Sources |
|
||
|--------|-----------|---------|
|
||
| Pipeline influence | Value of open and won opportunities with at least one marketing touch (UTM visit, form, prospect push, engagement with a post), by channel | EspoCRM (via Hermes), Plausible, the app's own history |
|
||
| CAC | Spend ÷ new paying customers, per month and per channel | Spend log, Stripe (first paid invoice) |
|
||
| CLV | ARPA × gross margin ÷ monthly churn rate, plus actual cumulative revenue per cohort | Stripe; gross margin set in settings |
|
||
| NRR | (Starting MRR + expansion − contraction − churn) ÷ starting MRR, monthly and trailing-12-month, by cohort | Stripe MRR model |
|
||
|
||
5. A dashboard with CSV export. It can also be published as a page on one of
|
||
the company's sites.
|
||
|
||
**Started 2026-11-22** on branch `phase4-metrics`, after Phase 3 was merged
|
||
into `main`. **Parts 1 to 6 built, and merged into `main` on 2026-11-22**
|
||
(152c14b). Part 7 (pipeline influence) waits for the CRM bridge.
|
||
|
||
**Design decisions:**
|
||
- **MRR comes from invoice line items, not subscriptions.** A subscription
|
||
object only says how things stand today. An invoice line says what a
|
||
customer was billed for which period: monthly value = the line's amount,
|
||
after discounts, ÷ the months its period covers. Past months can then be
|
||
rebuilt exactly, and trials ($0), pauses (no invoice) and cancellations
|
||
(no next period) fall out naturally.
|
||
- **Every number is computed in code** from the synced data, like Phase 3.
|
||
No estimates; where data is missing, the dashboard says so.
|
||
- **One currency.** Amounts in another currency are counted apart, never
|
||
added.
|
||
- **Gross margin is per product** (the user, 2026-11-22). The default is
|
||
**60%**, and each Stripe product can have its own margin, set on
|
||
Metrics. CLV weighs each customer's revenue by the margin of what they
|
||
buy. Products come from the sync; if the key can't read Products, their
|
||
names come from the invoice lines' descriptions.
|
||
|
||
**Parts, in order, a commit after each:**
|
||
1. **The full Stripe sync.**
|
||
- Read customers, invoices (with their lines), credit notes and refunds:
|
||
a full backfill, then the Events API every hour.
|
||
- Events are kept for 30 days, so an older watermark triggers a new
|
||
backfill.
|
||
- Use the same restricted, read-only key as Phase 2. The key also needs
|
||
read access to Customers, Credit notes, Events and Charges (for
|
||
refunds).
|
||
- **Built 2026-11-22** (schema 18: `stripe_objects`,
|
||
`stripe_invoice_lines`):
|
||
- `metrics.Sync` backfills customers, invoices (drafts skipped),
|
||
credit notes and refunds (with `expand[]=data.charge` for the
|
||
customer).
|
||
- It then applies the Events API for the followed types since the
|
||
watermark. `charge.refunded` reads its refunds, and
|
||
`customer.deleted` marks the customer deleted.
|
||
- Invoice lines are re-read in full when `has_more`.
|
||
`stripe.ParseLine` reads both the older line shape and the 2025
|
||
one, and stores the amount after discounts.
|
||
- It syncs every hour, on Metrics, with *Sync now* and *Read
|
||
everything again*.
|
||
- Per-product margins came in with it (schema 19 adds the lines'
|
||
descriptions). Products are read on every sync; without Products
|
||
access, the sync says so and names come from the line
|
||
descriptions. `metrics.Products` lists each product's last 12
|
||
months billed (paid and open invoices). Margins are a default plus
|
||
per-product overrides, under Metrics → Gross margin by product.
|
||
`WeightedMargin` gives the revenue-weighted margin.
|
||
- On the live account, the first full sync read 857 customers,
|
||
2,894 invoices, 21 credit notes, 346 refunds and 63 products, all
|
||
in USD.
|
||
2. **The MRR model and NRR.**
|
||
- MRR per customer per month, from invoice lines.
|
||
- Each month's movements: new, expansion, contraction, churn,
|
||
reactivation.
|
||
- NRR monthly and over the trailing 12 months, by signup cohort.
|
||
- **Built 2026-11-22** (no schema change):
|
||
- `metrics.Build` measures each customer's MRR at each month's last
|
||
second (the current month: now). It sums the recurring lines of
|
||
paid and open invoices in the main currency whose period covers
|
||
that moment.
|
||
- A normal line is divided by its interval (a year counts as 12
|
||
months, a week as 52/12). A proration is spread over its actual
|
||
part-period, so an upgrade counts from its day. Under a cent counts
|
||
as nothing (trials).
|
||
- Moves: new, expansion, contraction, churn, reactivation. Changes
|
||
under $1 or 1% are noise from the proration arithmetic.
|
||
- NRR for a month is what last month's customers pay now ÷ what they
|
||
paid then. NRR over 12 months is what the customers of 12 months
|
||
ago pay now ÷ what they paid then.
|
||
- Cohorts are by the first paid month, with the retained share of
|
||
starting MRR for up to 12 months.
|
||
- **Start month.** When 20+ customers and most of the MRR appear as
|
||
new in one month, the app suggests counting from it. That's what
|
||
happened in January 2025 on the live account: billing came back to
|
||
Stripe after a gap through most of 2024. Customers paying in the
|
||
start month are the base, not new. You can choose "count
|
||
everything" instead.
|
||
- The pages are Metrics (MRR now, ARR, ARPA, NRR, a 24-month SVG
|
||
chart, the month-by-month table, cohorts) and Metrics → a month
|
||
(each customer's move).
|
||
- On the live data, both large swings are real: in June 2026 a
|
||
customer paying about $2,075 a month left, and in July 2026 prices
|
||
rose across the plans.
|
||
3. **Matching Stripe customers to EspoCRM Accounts** (from the cached CRM
|
||
records), by stored ID, email or email domain, with a screen to fix
|
||
wrong matches. Customers already tied to prospects (Phase 2) keep that
|
||
tie.
|
||
- **Built 2026-11-22** (schema 20: `crm_matches`, the user's choices
|
||
only):
|
||
- `metrics.Matches` matches every customer with a paid or open
|
||
invoice, in this order:
|
||
1. the user's choice;
|
||
2. an Account Hermes created from here (a done `stripe-customer:`
|
||
CRM action);
|
||
3. a stored ID: `espocrm_id`, `espo_id`, `crm_id` or
|
||
`espocrm_account_id` in the customer's metadata, or a
|
||
`cus_…` in the Account's `stripeCustomerId`, `cStripeCustomerId`
|
||
or a similar field;
|
||
4. email, on the Account or one of its Contacts (via
|
||
`accountId`);
|
||
5. the email's domain, skipping free mail.
|
||
- When several Accounts fit, the user chooses.
|
||
- The page is Metrics → Customers and the CRM, with three tabs: to
|
||
fix, paying now, all. Each customer can be matched to an Account
|
||
(by name), marked "not in the CRM", put back to automatic, or
|
||
queued as a new Account for Hermes (the website comes from the
|
||
email's domain).
|
||
- On the live account, 385 customers have billing. None can be
|
||
matched until Hermes copies the CRM's Accounts, which waits on the
|
||
Core's MCP hub.
|
||
4. **The spend log and CAC.**
|
||
- Spend by channel and month, entered by hand or imported from CSV.
|
||
- Outside tools' spend comes in automatically (origami.chat and
|
||
explee.com campaigns already report it).
|
||
- CAC = spend ÷ new paying customers, per month and per channel, with
|
||
the channel taken from the customer's first funnel touch.
|
||
- **Built 2026-11-22** (schema 21: `spend`, `spend_seen`):
|
||
- Spend is logged by month and channel: the funnel's channels plus
|
||
"general" for overheads. It comes in by hand, or from a pasted CSV
|
||
of month,channel,amount,note (all or nothing).
|
||
- `SyncOutsideSpend` runs with the hourly metrics. It adds each
|
||
origami.chat or explee.com campaign's spend since last seen to the
|
||
current month. The first time, a campaign's whole lifetime spend
|
||
goes into that month, with a note saying so. On the live account,
|
||
that was explee.com's $344.51, in November 2026.
|
||
- `BuildCAC`: each month's spend ÷ its new customers (from the MRR
|
||
model), plus a trailing three-month figure. With no spend logged,
|
||
CAC is unknown, never $0.
|
||
- By channel, over 12 months: each new customer's channel is their
|
||
first funnel event, matched by email; Stripe's own steps don't
|
||
count, and customers with none are "unknown". Phase 2's
|
||
`stripe_customers.channel` defaults to "website", so it isn't
|
||
used. General spend counts toward monthly CAC, not toward any
|
||
channel.
|
||
- The page is Metrics → Spend and CAC.
|
||
5. **CLV and cohorts.**
|
||
- CLV = ARPA × gross margin ÷ monthly churn rate, with the margin
|
||
weighted by each product's share of the revenue.
|
||
- Each signup cohort's actual cumulative revenue, net of refunds and
|
||
credit notes.
|
||
- **Built 2026-11-22** (no schema change):
|
||
- **`BuildCLV`** measures on the last complete month:
|
||
- ARPA;
|
||
- the margin, weighted by each product's 12-month billings;
|
||
- customer churn, as customers lost ÷ customers at the start,
|
||
summed over up to the last 12 complete months;
|
||
- lifetime = 1 ÷ churn;
|
||
- CLV = ARPA × margin × lifetime;
|
||
- CAC = spend ÷ new customers over its own 12-month window (churn
|
||
needs the month before, so its window starts a month later);
|
||
- CLV:CAC.
|
||
- **`RevenueByCohort`** uses money that actually came in: paid
|
||
invoices' `amount_paid` at `paid_at`, minus refunds that
|
||
succeeded, minus post-payment credit notes less any part refunded
|
||
(pre-payment notes already lowered the amount paid). It's counted
|
||
by the month it happened, cumulative per customer, for each first
|
||
paid month, with a gross profit view.
|
||
- Cells mark months not reached yet separately from the amount,
|
||
because revenue can be negative when refunds exceed payments.
|
||
- The page is Metrics → CLV and cohorts. On the live account, CLV
|
||
is about $1,161 of gross profit per customer: $94 a month, 60%
|
||
margin, 4.9% monthly churn, a 20.6-month lifetime. CAC waits for
|
||
spend to be logged.
|
||
6. **The dashboard.**
|
||
- MRR over time with its movements, NRR, CAC, CLV and CLV:CAC.
|
||
- CSV export of every table.
|
||
- Optionally published as a page on one of the sites, through a pull
|
||
request.
|
||
- **Built 2026-11-22** (no schema change):
|
||
- The MRR and NRR page has a second strip: churn, CLV, CAC and
|
||
CLV:CAC.
|
||
- `metrics.Export` writes eight tables as CSV, amounts in dollars:
|
||
MRR month by month (every month), NRR by cohort and revenue by
|
||
cohort (24 months), CAC by month and by channel, the spend log,
|
||
products and margins, and customers with their MRR and CRM match.
|
||
Each is downloaded at `/metrics/export/<name>.csv`, linked under
|
||
its table.
|
||
- **Metrics → Publish** builds an open metrics page in Markdown,
|
||
with totals only: MRR and ARR, customers and ARPA, 12-month
|
||
growth, NRR, churn, and a 12-month table, chosen part by part.
|
||
- `seo.Applier.PublishPage` opens a pull request that adds or
|
||
updates the page (`hugorepo.UpsertPage`), checked with a Hugo
|
||
build. The options and the last pull request are kept. A test
|
||
checks that no customer's name, email or ID can appear on the
|
||
page.
|
||
7. **Pipeline influence**, once the CRM bridge works: the value of open and
|
||
won EspoCRM opportunities with at least one marketing touch, by channel.
|
||
|
||
### Phase 5: Sites and components
|
||
1. **Component library**: a Hugo theme module with section partials (hero,
|
||
features, cards, steps, pricing, stats, FAQ, comparison table, testimonial,
|
||
lead form, final CTA) on the `sections:` front-matter pattern from
|
||
`webcoredesktop`, themed from the profile (colors, fonts, logo). It lives
|
||
in its own Gitea repo and is versioned, so the company's sites can pull
|
||
updates.
|
||
2. **Site builder**: create a new site from the library (which creates its
|
||
Gitea repo through the API), or add pages to an existing one (landing,
|
||
product, "<competitor> alternative" and comparison pages, blog posts) from
|
||
the profile, the Inventory and SEO findings. Changes are always PRs.
|
||
Preview runs `hugo server` inside the container.
|
||
3. **Publishing** = merging into the site repo's publish branch on Gitea. The
|
||
user's Gitea hooks deploy it to their Hugo server. The app shows the last
|
||
merge, and checks the live site afterwards to confirm it changed.
|
||
|
||
**Started 2026-11-22** on branch `phase5-sites`, after Phase 4 was merged
|
||
into `main`. **Merged into `main` on 2026-11-22** (fast-forward to
|
||
e2a72d5).
|
||
|
||
**Decisions (the user, 2026-11-22):**
|
||
- **Pages are built from each site's own sections**, not a new shared
|
||
theme. federated-website (about 20 section types) and webcoredesktop
|
||
(about 15) already use the same `sections:` front matter pattern, each
|
||
with its own layouts. Supermarket reads a site's section types (the
|
||
partials in `layouts/partials/sections/`, the README's field table, and
|
||
how existing pages use them) and composes pages from them. Nothing in
|
||
the layouts changes. A shared theme can come later.
|
||
- **Previews are built and served by the app**, under
|
||
`localhost:8470/preview/…`: Hugo builds the branch, so no second port is
|
||
needed.
|
||
|
||
**Parts, in order, a commit after each:**
|
||
1. **Reading a site.**
|
||
- Sync the website's repository (Phase 3's working copy).
|
||
- The section catalogue: each section type with its fields (from the
|
||
README's table and from the pages that use it), an example from a
|
||
real page, and how many pages use it.
|
||
- The pages, with their address, title and section types.
|
||
- The last merge on the publish branch, from Gitea.
|
||
- A Sites page per website.
|
||
2. **Preview.** Build a branch (the published one, or a pull request's)
|
||
and serve it under `/preview/<site>/<branch>/`, so a page can be seen
|
||
before it's merged.
|
||
3. **The page builder.**
|
||
- New pages of a kind: landing page, product page, "<competitor>
|
||
alternative", comparison, blog post.
|
||
- Built from the profile, the Inventory, a buying signal (its angle,
|
||
with CTAs carrying its campaign tag) or an SEO brief.
|
||
- The AI composes `sections:` using only the site's own types and
|
||
fields, and code checks every type exists.
|
||
- Opened as a pull request, checked with a build, with a preview link.
|
||
4. **Pages per signal** (Phase 2's part 8): a landing page per buying
|
||
signal, created from the scorecard, and duplicated (to test a variant)
|
||
or deleted from it, always as pull requests.
|
||
5. **Publishing status.** After a merge, check the live site: the page is
|
||
there, its title matches, and the change shows. List the recent merges.
|
||
|
||
**Part 1 built (2026-11-22; no schema change).** `internal/sites` reads a
|
||
working copy: section types are the partials in
|
||
`layouts/partials/sections/`, less the helpers other partials call (head,
|
||
ctas, wrapper…); each type gets the README's description (table rows or
|
||
list items), the fields pages use (with list items' keys), the fields its
|
||
layout reads, the pages using it, and its fullest real use as YAML in the
|
||
page's own field order. Types pages use without a layout are flagged. Pages
|
||
list their address, title and section types; TOML pages are listed but not
|
||
read. `hugorepo` gained a per-copy lock (so two jobs can't reset one copy at
|
||
once; every SEO job now takes it), `Log` and `PathOf`. Sites → Sections and
|
||
pages (`/sites`) reads the repository on request and shows the latest
|
||
commits on the published branch. Live: federated-website has 25 section
|
||
types and 59 pages (22 built from sections).
|
||
|
||
**Part 2 built (2026-11-22; no schema change).** Sites → Previews lists the
|
||
repository's branches (the published one first) and builds any of them:
|
||
a fresh read, the branch checked out, `hugo --buildDrafts --buildFuture`
|
||
for `/`, then every root-relative address in the HTML and CSS rewritten to
|
||
`/preview/<site>/<branch>/`. The copy goes back to the published branch
|
||
afterwards. A failed build keeps serving the last good preview; a preview
|
||
older than its branch says so. Previews are served with a CSP `sandbox`
|
||
(no `allow-same-origin`): the site's scripts run, but each page has an
|
||
opaque origin, so the guard refuses anything it posts to the app; it can't
|
||
connect anywhere either, so analytics don't count previews. Folders show
|
||
only through their index.html.
|
||
|
||
**The image's Hugo** was Alpine's 0.147.2, too old for federated-website
|
||
(`hugo.Data` needs 0.156+), so even the SEO build check would have failed
|
||
on it. The Dockerfile now builds Hugo v0.170.1 from source in a Go 1.27
|
||
stage (the standard edition: sites needing Sass won't build). Hugo's
|
||
errors now show the innermost cause, with paths cut to the repository's.
|
||
|
||
**Part 3 built (2026-11-22; schema 22, `site_pages`).** Sites → New pages
|
||
builds a page of a kind (landing, product, alternative, comparison, blog
|
||
post) from the profile, optionally a product, a competitor from the
|
||
Inventory, a buying signal and an SEO brief, plus the user's notes. It
|
||
reads the repository fresh, then the AI (new task "sites") gets the
|
||
company, the page's purpose, the site's pages with their section
|
||
sequences, and the section catalogue (README, fields in use, layout
|
||
fields, one real example per type; about 34,000 characters for
|
||
federated-website). It answers with the sections as a YAML string (strict
|
||
JSON schemas can't hold free-form sections). Code then checks it: every
|
||
type must exist with a layout (an error to fix otherwise); unknown fields
|
||
and links to pages the site doesn't have (in url fields and Markdown links)
|
||
are warnings; with a signal, links to the site get `utm_campaign=<signal>`
|
||
and `utm_medium=landing`; experience claims are found as for briefs. The
|
||
user edits title, description, address and the YAML, then can *Write it
|
||
again* (from their notes and edits), *Push and preview* (its own branch
|
||
`supermarket/site-page-<id>`, built, previewed, no pull request) or *Open a
|
||
pull request* (claims confirmed first; the body lists the claims, what to
|
||
add by hand and the build check). The address is fixed once the file is on
|
||
a branch. Pages show merged or closed from Gitea. Not yet tried against the
|
||
live AI or the real repository: a build is a paid AI call and pushes a
|
||
branch.
|
||
|
||
**Part 4 built (2026-11-22; schema 23, the removal pull request's
|
||
columns).** Each signal's page has a *Landing pages* section: its pages on
|
||
every site (variants after their original), their status from Gitea
|
||
(refreshed on view), the live address, and each live page's visitors over
|
||
30 days from Plausible (`event:page`, per page, never per person). A form
|
||
there builds a landing page for the signal (the page builder, with the
|
||
signal preset). Per page:
|
||
- *Duplicate as a variant*: a copy at the original's address plus `-b`,
|
||
`-c`… (variants B, C; the original becomes A), optionally rewritten from
|
||
notes on what to change. A variant's links to the site also carry
|
||
`utm_content=<its address>`, so sign-ups that keep the tags can be told
|
||
apart; the original's links stay as they are, so a live page needn't
|
||
change when a variant is added.
|
||
- *Remove from the site* (published pages): a pull request on
|
||
`supermarket/remove-site-page-<id>` deleting the file, checked with a
|
||
build; merged, the page is *removed*; closed, it's back to *merged*.
|
||
- *Close the pull request*: closes an open one (adding or removing) on
|
||
Gitea without merging.
|
||
The scorecard shows how many landing pages each signal has live. Phase 2's
|
||
part 8 is done by this.
|
||
|
||
**Part 5 built (2026-11-22; schema 24: `live_at`, `gone_at`, `checked_at`,
|
||
`live_note`).** The SEO loop (every 30 minutes) now also follows Sites
|
||
pages' pull requests and checks the live site for pages waiting on it; so
|
||
do the page, the signal's page and Sites → Publishing whenever they're
|
||
opened (at most once a minute), and *Check the live site now*. A merged
|
||
page is live when its address answers 200 with its own words (the first
|
||
heading of its sections, without Markdown) and its title; words without
|
||
the title count as live, with a note; the title without the words means
|
||
the old version is still deployed. A removed page must answer 404 or 410,
|
||
or lead elsewhere. Two hours after a merge without the page, it says to
|
||
check the deploy hook. Badges read *merged, not live yet* / *live* and
|
||
*removal merged, still on the site* / *removed*. Pages that go live or
|
||
away are sent to IndexNow with the SEO changes (`seo.NewlyLive`). Sites →
|
||
Publishing lists what's waiting for the live site, open pull requests,
|
||
and the repository's latest merged pull requests (Supermarket's or
|
||
anyone's), each linked to its page. federated-website has no merged pull
|
||
requests: its changes are pushed straight to `main`, shown as commits
|
||
under Sections and pages.
|
||
|
||
**Phase 5 is complete** (parts 1–5). Not yet tried for real: building a
|
||
page (a paid AI call) and pushing it to the real repository.
|
||
|
||
### Phase 6: Backups, lead forms, the LinkedIn page, new sites
|
||
|
||
**Started 2026-11-22** on branch `phase6`, after Phase 5 was merged into
|
||
`main`. **Merged into `main` on 2026-11-22** (fast-forward to
|
||
7da7c5f). Phases 0–5 had covered the plan; the user chose to make Phase 6
|
||
of four further pieces: the first three future enhancements below, and a
|
||
shared theme for new sites (deferred in Phase 5).
|
||
|
||
**Parts, in order, a commit after each:**
|
||
1. **Backups.** As designed under Future enhancements, item 2: SQLite's own
|
||
backup (`VACUUM INTO`), into `backups/`; made on request (Settings →
|
||
Backups, `supermarket backup [note]`), before every schema migration,
|
||
and daily; kept 7 daily and 4 weekly, the rest until deleted; listed
|
||
with size and schema, downloadable and deletable; the old
|
||
`app.db.pre-*` copies moved in.
|
||
2. **Restore.** From a backup in the list, an uploaded one, or `supermarket
|
||
restore <file>`: checked (integrity, schema not newer), the current
|
||
database backed up first, then swapped in and the app restarted.
|
||
`supermarket backup --with-secrets` for moving machines.
|
||
3. **Inbound lead forms.** The sites' `form` sections post to EspoCRM's own
|
||
lead capture (Supermarket is local-only, so it can't take the posts
|
||
itself), with the buying signal from the page's campaign tag. Supermarket
|
||
sets the capture up, puts its address in the site's settings by pull
|
||
request, and counts the leads in the funnel.
|
||
4. **The LinkedIn company page.** As designed under Future enhancements,
|
||
item 1: the second app's keys, choosing the page, and posting as the
|
||
page or the profile per draft. Built against LinkedIn's documented API;
|
||
used for real once LinkedIn approves the app.
|
||
5. **New sites from a shared theme.** Decided with the user (2026-11-22):
|
||
the theme is *copied into* each new site (`themes/supermarket/`), not a
|
||
submodule, so each site stands alone; *the user creates* the empty
|
||
Gitea repository (the `write:repository` token stays enough); the theme
|
||
has *federated-website's look*, with each site's colors, fonts and logo
|
||
as settings. In three steps, a commit after each:
|
||
1. **The theme**, embedded in Supermarket: base layouts, header and
|
||
footer, the section types both sites share (hero, text, features,
|
||
cards, steps, checklist, split, stats, table, faq, callout,
|
||
final-cta) plus federated-website's lead `form`, the stylesheet with
|
||
brand variables, and a README documenting each type and its fields
|
||
(which the catalogue reader and the page builder then use).
|
||
2. **A new site**: Sites → New site takes the empty repository, the
|
||
site's address, name and brand (colors, font, logo); the first
|
||
commit (the theme, `hugo.toml`, a starter home page) goes straight to
|
||
the empty repository's `main`, the one exception to "always a pull
|
||
request", since there's nothing published yet; then the site is added
|
||
to the profile, read, and previewed, and its first pages (home,
|
||
about, a product page, contact with a lead form) are built with the
|
||
page builder as pull requests.
|
||
3. **Theme updates**: the theme carries a version; a site whose copy is
|
||
older gets a pull request copying the new one in.
|
||
|
||
**Step 1 built (2026-11-22; no schema change).** `internal/theme` embeds
|
||
the theme (version 1): federated-website's base layout (its reveal and
|
||
sticky-header script; not its agent view or pricing script), a generic
|
||
head (title, description, canonical and Open Graph tags, favicon, the
|
||
brand font from Google Fonts, Plausible when `[params.plausible]` is
|
||
set), a header and footer driven by `hugo.toml` (logo or the site's
|
||
name, `main` menu with dropdowns, `[params.header] ctas`, footer
|
||
groups, social and legal menus, copyright), the 13 shared section types
|
||
(the hero without Federated's layer panel; the form posting through
|
||
`supermarket-leads.js`, now the theme's file and the one Part 3 uses),
|
||
pages that render sections then any Markdown body, a 404, and the
|
||
stylesheet with every brand color as a variable (the fixed violet,
|
||
lime and navy tints turned into `color-mix` of the brand variables).
|
||
`[params.brand]` sets dark, dark2, primary, accent (and hovers), font,
|
||
logo and favicon. The README documents each type's real fields; the
|
||
catalogue reader now reads `themes/*/` sections and READMEs after the
|
||
site's own (the site's win), and treats types `render-sections` picks
|
||
by name as types even before a page uses them; Lead forms knows a theme
|
||
site needs only the address. Tested with Hugo building every section.
|
||
|
||
**Step 2 built (2026-11-22; no schema change).** Sites → New site takes
|
||
the empty repository (owner/name), the site's address (https), name,
|
||
tagline, contact email, and brand (dark, primary and accent colors with
|
||
color pickers, a font from a short list of Google Fonts, an optional
|
||
logo). It checks the values (a control character, a bad color, a
|
||
non-https address are refused), checks on Gitea that the repository is
|
||
*empty* (Gitea's `empty` flag) and the token can push, builds the files
|
||
with Hugo, and only then makes the first commit (`InitPush`: git init,
|
||
commit, push to the default branch) in the site's working copy: the
|
||
theme, `hugo.toml` (brand, header button to /contact/, footer, an empty
|
||
`[params.leads] action` with the email), a starter home page (hero and
|
||
closing band), a README and a .gitignore. The site is added to the
|
||
profile and marked read. Its Sections and pages shows a *First pages*
|
||
card: Home page, About page, Contact page and a product page per
|
||
profile product, each one click to the page builder (a paid AI call;
|
||
nothing is spent until clicked). New page kinds: *home* (replaces the
|
||
site's home page, at /), *about* and *contact* (both join the top menu
|
||
through `menus: main` in their front matter; contact is built around
|
||
the form). Commits are by the Core's user "via Supermarket"
|
||
(`commitAuthor`). Deploying the new site is still the user's Gitea hook.
|
||
|
||
**Step 3 built (2026-11-22; no schema change).** The theme carries a
|
||
`MANIFEST` (each file's SHA-256) beside its `VERSION`, so a site's copy
|
||
can be checked for files changed by hand. Sites → Sections and pages
|
||
shows a *Theme* card on sites using it: their version against
|
||
Supermarket's, the files changed by hand, and *Update the theme* when
|
||
Supermarket's is newer. The update (`supermarket/theme-<n>`) writes the
|
||
new and changed files, removes the ones the theme no longer has,
|
||
rebuilds, and opens a pull request listing what changed, was added and
|
||
removed, and which hand-edited files it replaces (changes belong in the
|
||
site's own `layouts/` or `static/`, which win over the theme). To ship a
|
||
theme change: edit `internal/theme/files/`, raise `theme.Version`.
|
||
|
||
**Part 5 is complete**, and with it Phase 6's plan. Not tried for real: a
|
||
new site on the real Gitea (the user creates the empty repository).
|
||
|
||
**Part 1 built (2026-11-22; no schema change).** `internal/backup` makes
|
||
backups with `VACUUM INTO` (to a `.part` file, then renamed; mode 0600)
|
||
into `<data>/backups`, named `app-<yyyymmdd>-<hhmmss>-<kind>[-<note>].db`
|
||
(kinds: manual, migration, daily, restore, legacy). `db.BeforeMigrate`
|
||
backs up an existing database before any pending migration
|
||
(`before-schema-<n>`; a failed backup stops the migration); a new database
|
||
isn't backed up. The app makes the daily backup at start and then hourly
|
||
checks whether one is due, pruning dailies to the newest 7 plus the newest
|
||
of each of the 4 weeks before. Settings → Backups lists them (when, why,
|
||
size, schema; unreadable files are flagged), makes one with a note,
|
||
downloads and deletes; only names from the list are served. `supermarket
|
||
backup [note]` and `supermarket backups` run the binary in the container
|
||
with `docker exec`; it opens the database beside the app without
|
||
migrating it. On start, the old `app.db.pre-*` copies are moved in as
|
||
*legacy* backups dated by their file time, with any `-wal` folded in
|
||
first; one that fails the integrity check is left in place. Live: all 23
|
||
moved. Some show an older schema than the database had when they were
|
||
taken (pre-phase5-part5 is at 22, not 23): plain `cp` missed writes still
|
||
in the WAL, as feared. The live database is 60 MB (mostly Stripe objects),
|
||
so the backups folder holds about 620 MB; old legacy copies can be deleted
|
||
from the page.
|
||
|
||
**Part 2 built (2026-11-22; no schema change).** A restore is staged,
|
||
then applied on the next start, since a running app can't swap its own
|
||
database: `backup.Stage` checks the file (integrity, a Supermarket
|
||
database, schema no newer than the app's), backs up the current database
|
||
(kind *restore*), and leaves `restore-pending.db` (plus
|
||
`restore-pending.json`); `ApplyPending` runs in `main` before anything
|
||
opens the database, re-checks it, removes the old `-wal`/`-shm`, renames
|
||
it over `app.db`, and records `restore-done.json`; migrations then run as
|
||
usual. From Settings → Backups, *Restore* (asks first) stages it and
|
||
stops the app (`Server.Restart`, the signal context's cancel); Docker's
|
||
`restart: unless-stopped` starts it again within a second, and the page
|
||
reloads (a `Refresh` header). A staged restore can be cancelled until
|
||
then. *Upload* takes a `.db` file, checks it and adds it to the list as
|
||
one of the user's backups. `supermarket restore <name or file>` copies a
|
||
host file into the data folder, stages it in the container, and restarts
|
||
the app. `supermarket backup --with-secrets` writes a mode-0600
|
||
`app-<time>-with-secrets.tar.gz` (app.db, secrets.json, mcp-token) to the
|
||
backups folder, not listed on the page; restoring one replaces
|
||
secrets.json too (the old one kept in the backups folder), while this
|
||
machine's mcp-token stays. Tried live both ways (the command line and the
|
||
page) by restoring a backup taken seconds before.
|
||
|
||
**Part 3 built (2026-11-22; no schema change).** EspoCRM's Lead Capture
|
||
(docs: docs.espocrm.com/administration/web-to-lead/) takes a JSON `POST
|
||
<crm>/api/v1/LeadCapture/<api key>` without a login, allows other sites
|
||
by default (`leadCaptureAllowOrigin`, "*"), and has one fixed Campaign per
|
||
Lead Capture: a per-submission campaign can't be passed. So the signal
|
||
travels in the Lead's description, and Plausible counts it. Sites → Lead
|
||
forms:
|
||
- shows how the site's forms post now (`[params.leads] action`), which
|
||
pages have a form, and whether this site's form section can be
|
||
connected;
|
||
- gives the EspoCRM steps (a Lead Capture whose Payload Fields are First
|
||
Name, Last Name, Email, Account Name, Phone, Description);
|
||
- saves its API URL (checked: https, `/api/v1/LeadCapture/<key>`) and
|
||
tests it with a CORS preflight from the site's origin (nothing created);
|
||
- opens a pull request (`supermarket/lead-forms`): `[params.leads]
|
||
action` in `hugo.toml`, `static/js/supermarket-leads.js` defining
|
||
`window.leadPost(form, data)`, and the form partial loading it and
|
||
calling it in place of its own `fetch(form.action, …)` (patched only if
|
||
that call is there; matched on federated-website's). The script maps
|
||
name (split), email, organization/company, phone onto the Lead; the
|
||
form's name, other answers (by label), the page, the visit's UTM tags
|
||
and the referrer go in the description. Checked with a build: a page
|
||
with a form loads the script and posts to the Lead Capture.
|
||
- counts form leads: the forms already send Plausible a `Lead` event, so
|
||
the daily Plausible import also reads the `Lead` goal by the visit's
|
||
UTM tags and records them as *interested* on the signal's funnel (or
|
||
says to add the goal in Plausible).
|
||
Tested with Node running the script on a form's data. Not done for real:
|
||
creating the Lead Capture in EspoCRM, and the pull request on the real
|
||
site.
|
||
|
||
**Part 4 built (2026-11-22; schema 25: `drafts.linkedin_as`).** From
|
||
LinkedIn's docs (Microsoft Learn, community-management): posting as a page
|
||
is the same `POST /rest/posts` with `author: urn:li:organization:<id>` and
|
||
`w_organization_social`, for members with an approved ADMINISTRATOR,
|
||
CONTENT_ADMIN(ISTRATOR) or DIRECT_SPONSORED_CONTENT_POSTER role;
|
||
`GET /rest/organizationAcls?q=roleAssignee&state=APPROVED` lists the
|
||
member's roles (the docs name the field `organizationTarget` or
|
||
`organization`: both are read), and `GET
|
||
/rest/organizationsLookup?ids=List(…)` names the pages without needing
|
||
admin. The docs don't say which scope the role list needs.
|
||
- Settings → Social accounts has a **LinkedIn page** card: the second app's
|
||
client ID and secret, its own sign-in (`/auth/linkedin-page/…`, its own
|
||
redirect URL), the scopes it asks for (default `w_organization_social
|
||
r_organization_admin`, editable to match the approved app), the pages
|
||
listed after sign-in to choose from (or a page number typed in, from its
|
||
admin address, when they can't be listed), and whether new LinkedIn
|
||
drafts default to the page. The only page is chosen automatically. Its
|
||
60-day expiry is reminded like LinkedIn's.
|
||
- Each LinkedIn draft in Posts has *Post as: You / <the page>*; the
|
||
publisher posts with the page's token and URN, or the member's, and says
|
||
which sign-in is missing or expired.
|
||
Not tried for real: it waits on LinkedIn approving the page app.
|
||
|
||
### Phase 7: What to write next, from what converts
|
||
|
||
**Built 2026-11-24** on branch `phase7`, a commit per part (e987108,
|
||
77f6e1e, 855615a, 5705a9b, fdfbcd3). Notes from building it:
|
||
- Federated's Plausible has visits by entry page for about 30 days, so the
|
||
90-day figures cover what's there.
|
||
- The suggested sign-ups were the two `/signup` links people clicked
|
||
(enterprise. and cloud.federated.computer); no page reaches the flags
|
||
yet.
|
||
- The landing pages for Education, Distributed teams and SaaS costs top
|
||
the list: their signals had 134, 30 and 14 replies in 90 days.
|
||
- Replies are read without the quoted message and "Sent from…" lines (an
|
||
"Outlook" suggestion came from signatures before that).
|
||
- No section is suggested yet: the questions and comparisons people search
|
||
("what is headscale", "gitea vs github") land on the app pages, which
|
||
are Markdown, not sections.
|
||
|
||
**Planned 2026-11-24**, after comparing SEO with ChatSEO (which drafts
|
||
whole pages from Search Console alone). Supermarket already suggests
|
||
title changes (Changes), rewrites (What ranks → brief), new keywords
|
||
(Next keywords) and landing pages per signal, but each from Search
|
||
Console alone, in four places, and a page can only be retitled or
|
||
rewritten whole. Phase 7 ranks them by what turns visits into sign-ups,
|
||
adds suggestions from the funnel, puts them in one list, and adds a
|
||
section to an existing page.
|
||
|
||
**What can be measured per page today** (checked 2026-11-24 against
|
||
federated.computer's Plausible):
|
||
- *Visits by entry page*: Plausible's `visit:entry_page` (1,641 of the
|
||
last 30 days' visitors entered on `/`; then /partners/, /pricing/…).
|
||
- *Sign-up starts by entry page*: Plausible already records "Outbound Link:
|
||
Click" with the link (`event:props:url`). Clicks to
|
||
`enterprise.federated.computer/signup` (5) and
|
||
`cloud.federated.computer/signup` (2) in 30 days are sign-up starts, and
|
||
Plausible ties each to the page the visit began on.
|
||
- *Form leads by page*: the `Lead` goal, once it's added in Plausible
|
||
(Phase 6) and the forms are connected.
|
||
- *Not yet*: payments by page. Stripe knows a customer's signal only when
|
||
the shopping cart saves the UTM tags; it would need the landing page
|
||
too (`utm_content`, or a `landing_page` metadata key). Until then,
|
||
payments count per signal, not per page.
|
||
|
||
**Parts, in order, a commit after each:**
|
||
1. **Conversions by page.** Settings → Website & sales gets *What counts
|
||
as a sign-up*: link patterns for outbound clicks (default: any link
|
||
ending in `/signup`, found from the last 30 days' clicks and offered
|
||
for ticking), plus the `Lead` goal. The daily Plausible import adds,
|
||
per website and day: visitors, sign-up starts and leads by entry page
|
||
(a new `page_days` table, 16 months kept like Search Console's). The
|
||
page tables on What ranks, the audit and Sites show *Visits* and
|
||
*Sign-ups* next to clicks.
|
||
2. **Ranked by what converts.** Change candidates and *Push* pages are
|
||
ordered by expected sign-ups (impressions × the click rate a page one
|
||
result usually gets × the page's own visit-to-sign-up rate, or the
|
||
site's when the page has too few visits), not by impressions alone.
|
||
Flagged, wherever pages are listed: *traffic, no sign-ups* (at least
|
||
100 visits in 90 days and none) and *converts, hardly found* (a
|
||
sign-up rate in the site's top quarter, few impressions): the second
|
||
is the best case for a rewrite or new links to it.
|
||
3. **Suggestions from the funnel.**
|
||
- A signal with replies or interested people (origami.chat,
|
||
explee.com, email) but no landing page: *Build a landing page for
|
||
it*, with its numbers.
|
||
- An app or product named in replies: the reply texts Supermarket
|
||
already reads (email outreach), and explee.com's or origami.chat's
|
||
if their APIs give the text, are matched against the Software
|
||
Library's apps and the Inventory; one with no page of its own on the
|
||
site is suggested as a product page.
|
||
- A keyword picked but with no brief, and a brief with no page.
|
||
4. **One list: SEO → Next.** Every suggestion from parts 2 and 3, and the
|
||
existing ones (Changes' candidates, Push pages, Next keywords' picks),
|
||
in one ranked list, each with its reason in numbers and one button
|
||
that starts the existing flow (propose a title, write a brief, build a
|
||
landing page). Nothing is drafted until you press it; the brief still
|
||
asks its questions first. At most 10 shown; dismissing one hides it
|
||
for 90 days. It's a page under SEO (the module still opens on the
|
||
Morning check); the Monday report's section 3 links to it.
|
||
5. **Add a section to an existing page.** On a page (Sites → Sections and
|
||
pages), *Add a section*: choose one of the site's section types (faq,
|
||
table, features…) and where it goes; the AI drafts it from the page,
|
||
the profile and the Inventory, with the same rules as new pages (no
|
||
invented prices, customers or numbers; claims of experience to be
|
||
ticked; to-dos listed). The pull request changes only that page's
|
||
front matter, checked with a Hugo build. Suggested in the list when
|
||
the page's searches are questions (a FAQ) or name a competitor (a
|
||
comparison table).
|
||
|
||
**Decided 2026-11-24:** Supermarket suggests what counts as a sign-up
|
||
(the patterns above, from the links people really click) and the user
|
||
refines it: ticks or unticks the suggestions and adds their own patterns.
|
||
The SEO module keeps opening on the Morning check; *Next* is one more page
|
||
under SEO.
|
||
|
||
**Not in this phase:** writing drafts on its own (ChatSEO's way), images,
|
||
and competitors' live prices.
|
||
|
||
### Phase 8: Backlinks
|
||
|
||
**Planned 2026-11-24.** SEO has no view of links from other sites: who
|
||
links to the site, which links bring visitors and sign-ups, which were
|
||
lost, and where a link could be won. Google's Links report isn't in the
|
||
Search Console API, so the data comes from Plausible (links that bring
|
||
visitors), Bing Webmaster Tools (links Bing has found) and checking the
|
||
linking pages themselves. A paid index (Ahrefs, Semrush, Moz, Majestic,
|
||
DataForSEO) stays out of this phase; part 4 notes where one would help.
|
||
|
||
**What there is today** (federated.computer, last 30 days): most visits
|
||
come with no referrer ("Direct / None": 1,549 of them to the home page);
|
||
the sites that sent visitors were few (wdtprs.com 9, reddit.com 7, t.co 7,
|
||
google.com 35). No Bing key is saved yet.
|
||
|
||
**Part 1 built 2026-11-24** (392980a, on branch `phase8`). It found
|
||
that browsers send another site only the linking site, not the page
|
||
(wdtprs.com, not the post), so Plausible rarely gives a linking page to
|
||
check: part 3 will mostly check pages from Bing (part 2) and ones added
|
||
by hand. In 90 days, four sites sent visitors through a link; wdtprs.com
|
||
sent 9 and 1 sign-up. Mail filters' link rewriters (EdgePilot…) count as
|
||
email, and CRMs and chat (Salesforce, Matrix) as work apps, not links.
|
||
|
||
**Part 2 built 2026-11-24** (fc7dcf1): waits for a Bing key to show
|
||
anything. **Part 3 built 2026-11-24**: the check reads the linking page
|
||
and the page of ours it links to; an unreachable page isn't a verdict (it
|
||
keeps the last one and tries next week). Links and *What to write next*
|
||
work for websites without a Search Console property.
|
||
|
||
**Part 4 built 2026-11-24.** Asking stays by hand: an Outreach draft
|
||
needs a person to write to, and partners' and list authors' pages rarely
|
||
name one; that can come later. **Phase 8 is built** on `phase8`. It
|
||
waits on data to say much: a Bing key (parts 2 and 3), and partners and
|
||
competitors in the Inventory (part 4).
|
||
|
||
All of it lives on a new page, **SEO → Links**, with a card per part; the
|
||
items worth acting on also join *What to write next*.
|
||
|
||
**Parts, in order, a commit after each:**
|
||
1. **Links that bring visitors (Plausible).** The daily import also reads,
|
||
by day: the referring site (`visit:source`), the linking page where
|
||
Plausible has it (`visit:referrer`), and the entry page, with visitors,
|
||
sign-ups and leads as Phase 7 counts them (a new `referrer_days`
|
||
table). Search engines, social networks, email and Supermarket's own
|
||
tagged links are told apart from links on other sites, which are the
|
||
backlinks. SEO → Links lists the sites that sent visitors in 90 days,
|
||
the pages they landed on, and the sign-ups they brought, new ones this
|
||
week first. Each linking page Plausible names becomes a known backlink
|
||
(part 3 checks it).
|
||
2. **Who links to you (Bing Webmaster Tools).** With a Bing key saved and
|
||
the site verified in Bing, a weekly read of Bing's inbound links: the
|
||
count per page of the site (`GetLinkCounts`), and for the most linked
|
||
pages, the linking pages and their anchor text (`GetUrlLinks`). Stored
|
||
in a `backlinks` table (the linking page, the page of ours it links
|
||
to, the anchor, where it was found, first and last seen). SEO → Links
|
||
shows the linking sites by how many pages of ours they link to, with
|
||
the pages and anchors; a site seen for the first time this week is
|
||
marked new. Without a key, the card says how to get one.
|
||
3. **Lost links.** Each week Supermarket opens the known linking pages
|
||
(from parts 1 and 2, and any added by hand), politely and at most 100 a
|
||
day, and checks each still links to the site. A link is *kept*, *gone*
|
||
(the page no longer links), *page gone* (it answers 404 or 410, or
|
||
redirects elsewhere) or *points at a 404* (our page it links to no
|
||
longer answers; the fix is a redirect on our side, which the audit's
|
||
404 list already names). SEO → Links lists the lost ones first, with
|
||
when they were last seen; one that brought visitors or sign-ups is
|
||
flagged, and joins *What to write next* (as *Fix with a redirect*, or
|
||
*Ask for the link back*).
|
||
4. **Link opportunities.**
|
||
- *Partners:* for each Inventory partner with a website, Supermarket
|
||
looks for a page that lists providers, hosts or partners (from their
|
||
sitemap and links: "hosting", "providers", "partners", "services",
|
||
"commercial support") and checks whether it links to the site. One
|
||
that lists others but not you is an opportunity, with the page.
|
||
- *"Alternatives" lists* (costs web searches, on request): for a
|
||
competitor in the Inventory, the AI searches for lists of
|
||
alternatives to it and comparisons, and keeps the ones that name
|
||
other providers but not you, with the list's page.
|
||
- Each opportunity can be dismissed, or marked *asked* and later *won*
|
||
(when part 2 or 3 sees the link). Asking is by hand, or as a draft
|
||
in Outreach when there's a person to write to; nothing is sent
|
||
without review. The best ones join *What to write next*.
|
||
- Where a paid index would help: the sites that link to competitors but
|
||
not to you. Left for later, behind a provider setting like Hunter.io.
|
||
|
||
**Not in this phase:** buying links, automatic outreach, and authority
|
||
scores (they need a paid index).
|
||
|
||
### Editions: local, server and multi-tenant (Phases 9–14)
|
||
|
||
**Planned 2026-11-25.** Supermarket will come in three editions, chosen
|
||
when it starts by `SUPERMARKET_MODE`:
|
||
|
||
| | **local** (today) | **server** | **multi** (multi-tenant) |
|
||
|---|---|---|---|
|
||
| Who | One person, on their own computer | One team | Many teams, each signing in at one address (e.g. `app.supermarket.example`) |
|
||
| Domains | One company | One company (its websites) | One company per team, each with its own websites |
|
||
| Database | SQLite (`app.db`) | Postgres | Postgres, with every team's rows marked with its team |
|
||
| Sign-in | None: only this computer can reach it | Email and password, or the Core's sign-in (OIDC) | The same, set per team |
|
||
| Files | The data folder | The data folder (a volume) | Object storage (S3-compatible), plus scratch disk |
|
||
| Billing | None | None | Stripe subscriptions, managed by each team's owner |
|
||
| Keys for AI and services | The user's own | The team's own | Each team's own (none from the platform) |
|
||
| Agents | Agent keys | Agent keys | Agent keys, per team |
|
||
|
||
**Words used below.**
|
||
- A **team** is one company using Supermarket: its profile, websites,
|
||
connections and data. Local and server installs have exactly one; on
|
||
multi-tenant, each team sees only its own.
|
||
- A **user** is a person, or an **agent** (a program, such as an AI agent,
|
||
using a key instead of a password), who belongs to a team with a role.
|
||
- **Connections** are the services a team connects to Supermarket:
|
||
origami.chat, explee.com, Stripe, Plausible, Google Search Console, Bing,
|
||
Gitea, Listmonk, X, LinkedIn, the Core, and the AI provider. Today they
|
||
are spread over Settings (Accounts, Sources, Email, Search engines,
|
||
Tracking, AI, Core); admins set them up.
|
||
|
||
**Roles.**
|
||
- **Owner**: one per team. Everything an admin can do, plus billing (plan,
|
||
payment card, invoices), handing ownership to another admin, and
|
||
deleting the team. On local and server, the first user is the owner.
|
||
- **Admin**: the whole system: every module, Settings and Connections,
|
||
and users (invite, change access, remove), including other admins.
|
||
Admins can't change billing or remove the owner.
|
||
- **Member**: only the modules they're given (any of Content, Prospects,
|
||
SEO, Sites, Metrics), each as *view* (read-only) or *edit*
|
||
(decided 2026-11-25). Overview, the sidebar and Search show only those
|
||
modules; the Market is readable by every member, editable by admins and
|
||
by members with Content or Prospects (it feeds both).
|
||
- **Agent**: like a member, given modules, but signs in with a key and
|
||
never sees the web pages. Only an admin can create one.
|
||
|
||
**What stays the same:** the local edition. It still has no sign-in
|
||
(the port is bound to 127.0.0.1), still uses SQLite, and its data folder
|
||
keeps working without a migration step by hand. On local, everything is
|
||
done as the owner.
|
||
|
||
#### What has to change, from a look at the code (2026-11-25)
|
||
|
||
- **The database.**
|
||
- The schema is 40 tables, in 29 SQLite migrations, and about 40,000
|
||
lines of Go run SQL through `database/sql`. SQLite-only SQL found:
|
||
- `strftime` defaults (12)
|
||
- `COLLATE NOCASE` (16)
|
||
- `INSERT OR …` (4)
|
||
- two-argument `max()`/`min()` (around 50; Postgres says
|
||
`greatest`/`least`)
|
||
- `json_extract`/`json_each` (7)
|
||
- `LastInsertId` (11; Postgres needs `RETURNING id`)
|
||
- `PRAGMA` (8)
|
||
- `?` placeholders everywhere (Postgres takes `$1`)
|
||
- The settings table, with 122 reads and writes, and every table's
|
||
unique keys assume one company.
|
||
- **Secrets** are in `secrets.json` in the data folder (41 reads). In the
|
||
server and multi-tenant editions they go into the database, encrypted.
|
||
- **Files.** The data folder holds:
|
||
- the sites' git clones (`sites/`) and page previews (`previews/`)
|
||
- backups
|
||
- the CRM bridge's state, Hermes' files, the MCP socket and its token
|
||
- **The company profile** is loaded in about 44 places as *the* profile.
|
||
Background jobs (`RunSEO`, `RunTracking`, `RunOutreach`, `RunMetrics`,
|
||
`RunScheduler`, `RunImports`, `RunDiscovery`, `RunBackups`) each run
|
||
once, in-process, for the one company.
|
||
- **In-memory state** that is per company, or per process, includes:
|
||
- OAuth flows in progress
|
||
- Reddit's app token
|
||
- the one-email-at-a-time lock
|
||
|
||
On multi-tenant this has to be per team, and safe with several copies
|
||
of the app running.
|
||
- **No users.** Requests are trusted because they come from localhost
|
||
(plus a same-origin check on forms). `/mcp` takes one bearer token
|
||
(`mcp-token`) that can do everything it offers.
|
||
- **What agents can do today:** `/mcp` has 6 tools (the profile, the
|
||
Market, and the CRM bridge's queue). An agent can't yet drive the
|
||
modules.
|
||
|
||
#### Phase 9: Groundwork: editions, Postgres, secrets and files
|
||
|
||
**Part 1 built 2026-11-25** on branch `phase9`. A new `internal/config`
|
||
package reads and checks every setting, listing all the problems at once.
|
||
`supermarket config` prints the settings (never a password or the key)
|
||
and any problems; `supermarket secret-key` makes a key. Settings → About
|
||
shows the edition. Server and multi-tenant settings are checked, but
|
||
starting either one says it isn't built yet, until the parts that make
|
||
them work are done. S3 storage takes `SUPERMARKET_S3_ENDPOINT`,
|
||
`_REGION` (default `garage`), `_ACCESS_KEY` and `_SECRET_KEY`; the app's
|
||
mail takes `SUPERMARKET_MAIL_URL` (`smtp://` with STARTTLS, or
|
||
`smtps://`) and `SUPERMARKET_MAIL_FROM`.
|
||
|
||
**Part 2 built 2026-11-25** on `phase9`. It took less change to the SQL
|
||
than planned: rather than helpers in every query, the SQL stays as it is
|
||
(SQLite's, with `?`), and Postgres is made to understand it.
|
||
- `db.DB` wraps `database/sql` for either database. On Postgres, each
|
||
statement's `?`s become `$1, $2…` and `LIKE` ignores case as SQLite's
|
||
does (`x COLLATE nocase LIKE y`), skipping strings and comments. Go
|
||
booleans go in as 0 and 1, and times as SQLite's driver writes them.
|
||
- The Postgres schema (`internal/db/postgres.sql`, schema 29 as a whole,
|
||
so part of part 3 came early, to have something to test on) adds:
|
||
- SQLite's `instr`, `json_extract` and two-argument `max`/`min`, as SQL
|
||
functions
|
||
- a case-insensitive, ICU-based `nocase` collation, so `COLLATE NOCASE`
|
||
means the same in both, in columns and in queries
|
||
- 64-bit integers, identity columns for `INTEGER PRIMARY KEY`, and the
|
||
tables in an order Postgres accepts
|
||
|
||
It needs Postgres 18 or later, for `LIKE` with that collation.
|
||
- What changed in the packages:
|
||
- 11 `LastInsertId`s became `db.Insert` (`RETURNING id`)
|
||
- 4 `INSERT OR IGNORE`s became `ON CONFLICT DO NOTHING`
|
||
- 4 upserts got table-qualified columns
|
||
- 3 queries were grouped by every column they use
|
||
- 2 JSON values are cast to numbers
|
||
- 1 `strftime` moved to Go
|
||
- `SUPERMARKET_TEST_POSTGRES` runs the whole test suite on Postgres, a new
|
||
schema per test. Every test passes on both databases. The tests that
|
||
test SQLite itself (its migrations) open SQLite with `db.OpenSQLite`;
|
||
the backup page's tests skip on Postgres.
|
||
- Left for part 3: migrations after schema 29 on both databases, and what
|
||
replaces SQLite's backup before a migration.
|
||
|
||
Nothing changes for the local user; this makes the rest possible. A
|
||
commit after each part; the whole test suite runs against both SQLite and
|
||
Postgres from part 2 on.
|
||
|
||
1. **The edition and its settings.** `SUPERMARKET_MODE` (`local`, the
|
||
default; `server`; `multi`). It is read once at start, along with:
|
||
- `SUPERMARKET_DATABASE_URL`: `postgres://…`, required for server and
|
||
multi
|
||
- `SUPERMARKET_PUBLIC_URL`: already there; `https://` is required for
|
||
server and multi
|
||
- `SUPERMARKET_SECRET_KEY`: the key that encrypts secrets in the
|
||
database
|
||
- `SUPERMARKET_STORAGE`: a folder, or `s3://bucket/prefix` with its
|
||
credentials
|
||
- `SUPERMARKET_MAIL_URL`: the SMTP server for the app's own mail
|
||
(invitations, password resets), separate from each team's outreach
|
||
mail
|
||
|
||
Start refuses a combination that doesn't make sense, and says why:
|
||
server without a database URL, or multi on `http://`. Settings → About
|
||
shows the edition.
|
||
2. **One database layer, two databases.**
|
||
- `internal/db` gets a dialect (SQLite or Postgres, using the `pgx`
|
||
driver) and a small set of helpers:
|
||
- placeholders rewritten for Postgres
|
||
- `Insert…Returning` for new IDs
|
||
- `Greatest`/`Least`
|
||
- case-insensitive text (a `citext` column, or `lower()` in unique
|
||
indexes)
|
||
- JSON reads
|
||
- upserts
|
||
- The SQL in the packages is changed to use them, package by package,
|
||
with the tests run against both databases at each step.
|
||
- Timestamps stay as RFC 3339 text in both databases. Comparisons keep
|
||
working and the change stays mechanical; switching to `timestamptz`
|
||
can come later.
|
||
3. **The Postgres schema and its migrations.**
|
||
- Postgres starts from one migration that is today's schema 29 as a
|
||
whole. After it, each new migration is written once for both
|
||
databases, or as a pair when they must differ.
|
||
- `db.Version` carries on counting from 29 for both, so a backup or
|
||
export says which schema it holds.
|
||
- Before a migration, the local edition still makes its backup with
|
||
`VACUUM INTO`. On Postgres, the operator's backups (`pg_dump`, or the
|
||
host's snapshots) take that place, and the app records a migration
|
||
marker.
|
||
4. **Secrets in the database, encrypted.**
|
||
- A `secrets` table holds each secret's name and its ciphertext,
|
||
encrypted with AES-256-GCM under `SUPERMARKET_SECRET_KEY`.
|
||
`secrets.Store` keeps its interface, so the 41 callers don't change.
|
||
- The local edition keeps `secrets.json`, so its backups still leave
|
||
secrets out, unchanged.
|
||
- On server and multi, losing the key means re-entering every
|
||
connection: the operator is told so at setup, and the key never goes
|
||
in the database or its backups.
|
||
5. **Files behind one interface.** A `storage` package with two
|
||
implementations: a folder (local and server) and S3-compatible object
|
||
storage (multi). These go through it:
|
||
- backups and exports
|
||
- uploaded files
|
||
- CRM-bridge state and other small state files, which move into the
|
||
database
|
||
|
||
The sites' git clones and page previews stay on local disk as a cache:
|
||
they can be cloned and built again. They sit under a folder per team,
|
||
so a team can't reach another's clone.
|
||
6. **Background jobs that can run on several copies of the app.**
|
||
- A `jobs` table holds each job's kind, team, when it is next due and
|
||
who has it, claimed with `FOR UPDATE SKIP LOCKED` on Postgres. The
|
||
`Run…` loops become job kinds run once per team.
|
||
- With several copies running, one claims each job; on SQLite the
|
||
table works as today, in one process.
|
||
- In-memory state that has to be shared (OAuth flows in progress, the
|
||
sending lock, Reddit's token) moves into the database or becomes a
|
||
database lock.
|
||
7. **Moving a local install to a server.** `supermarket export` writes a
|
||
team's whole database plus its secrets: a mode-0600 `.tar.gz` that
|
||
warns it holds credentials, as `backup --with-secrets` does. `supermarket
|
||
import` loads it into a Postgres database, as a server's team, or as a
|
||
new team on multi-tenant (Phase 13). It is checked by moving
|
||
Federated's own install over and comparing row counts.
|
||
|
||
**Done when:** every test passes on SQLite and on Postgres, and
|
||
Federated's local install runs unchanged. The same data, exported and
|
||
imported into Postgres, shows the same pages.
|
||
|
||
#### Phase 10: Users, sign-in and roles (the server edition)
|
||
|
||
This makes the server edition usable by a team. A commit after each part.
|
||
|
||
1. **Users and sessions.**
|
||
- Tables:
|
||
- `users`: email, name, kind (person or agent), status (invited,
|
||
active or disabled), password hash (Argon2id), the profile
|
||
fields, and the time zone
|
||
- `memberships`: team, user, role, and the modules granted
|
||
- `sessions`: server-side, with only a random ID in a `Secure`,
|
||
`HttpOnly`, `SameSite=Lax` cookie
|
||
- On local, every request is the owner, as today, and nothing asks
|
||
anyone to sign in.
|
||
- Forms get a CSRF token, as well as today's same-origin check.
|
||
2. **The first owner.**
|
||
- On a new server, the start-up log prints a one-time setup link
|
||
(also `supermarket setup-link`).
|
||
- Whoever opens it creates the owner: email, name and password. Then
|
||
they fill in the company profile, as on local.
|
||
- Until that's done, every other page says the setup isn't finished.
|
||
3. **Signing in and out.**
|
||
- Email and password, with a reset link by email
|
||
(`SUPERMARKET_MAIL_URL`). The link is single-use and lasts an hour.
|
||
- Sign-in is limited per address and per IP, and an account locks
|
||
after repeated failures; the user is told, and an admin can unlock
|
||
it.
|
||
- Each user sees their active sessions and can sign out of the others
|
||
(Settings → Your account).
|
||
- Changing the password ends their other sessions.
|
||
- **Two-factor sign-in** is an option for every user, owners and admins
|
||
included (decided 2026-11-25): an authenticator app (TOTP), with
|
||
ten single-use recovery codes. Each user turns it on under Settings →
|
||
Your account. An admin can reset it for someone who lost their phone,
|
||
which is logged. Signing in with the Core (Phase 12) leaves
|
||
two-factor to Authelia.
|
||
4. **Creating users (admins).** On Settings → Users, an admin:
|
||
- enters an email and a name
|
||
- picks *Admin*, or *Member* with the modules to give, each as
|
||
*view* or *edit*
|
||
- sends the invitation
|
||
|
||
The new user gets an email with a link that lasts 7 days and can be
|
||
used once. The link leads to:
|
||
- choosing a password, or signing in with the Core (Phase 12)
|
||
- filling in their profile: name, title, time zone, photo, and which
|
||
emails they want (such as the daily SEO email, Phase 3)
|
||
|
||
Admins can resend or withdraw an invitation, change someone's role or
|
||
modules, disable or remove them, and see when each person last signed
|
||
in.
|
||
5. **Access enforced everywhere.**
|
||
- Each route belongs to a module (or to Settings or Overview). A
|
||
request outside the user's modules gets a 403 page, and htmx
|
||
fragments are checked the same way.
|
||
- Each route is also marked as reading or changing. A *view* member
|
||
sees the module's pages without the buttons and forms that change
|
||
things, and the server refuses those requests too, not just hides
|
||
them.
|
||
- The sidebar, Overview's cards, Search results and the daily emails
|
||
show only the user's modules.
|
||
- Only admins see Settings, apart from Your account.
|
||
- One table maps routes to modules, and a test fails when a new route
|
||
isn't in it.
|
||
6. **Connections, for admins.** Settings gets a **Connections** page that
|
||
lists every connected service with its state (connected, missing,
|
||
failing, last checked) and a link to set it up. The existing pages stay
|
||
where they are, behind admin access. Who connected each one, and when,
|
||
is recorded.
|
||
7. **Posting accounts, and who may post to them** (decided 2026-11-25).
|
||
- The social accounts posts go out from (X, LinkedIn profiles and the
|
||
LinkedIn page, Reddit) become **posting accounts**. There can be
|
||
several of each: the company's, and any user's own, each signed in
|
||
once by its owner or an admin.
|
||
- Settings → Posting accounts has a grid of users against accounts,
|
||
saying who may post to which. A user's own account is theirs by
|
||
default. Admins may post to every account; an admin can grant others.
|
||
- On a draft, the writer picks one account or several at once, from
|
||
those they're allowed and that are set up (signed in and working).
|
||
Each account gets its own copy, within that platform's limits, and
|
||
the draft shows where it went.
|
||
- Posting as someone else needs that permission. The post, and the
|
||
audit log, record both who wrote it and which account it went out as.
|
||
- A user who signs their own account out, or is removed, takes it out
|
||
of everyone's list; scheduled posts to it are held and their writers
|
||
told.
|
||
- Agents get the same grid: an agent posts only to the accounts it's
|
||
allowed.
|
||
8. **Who did what.** An `audit_log` records:
|
||
- sign-ins (and failed ones)
|
||
- invitations and role changes
|
||
- connection changes
|
||
- anything sent or published (posts, emails, site pushes, mailing-list
|
||
adds)
|
||
- deletions
|
||
|
||
Each entry has the user and the time. Admins see it under Settings →
|
||
Activity. Posts, drafts and emails also record who made them, shown
|
||
as *by Jane*.
|
||
9. **The server package.**
|
||
- A `compose.server.yaml` runs the app, Postgres, and Caddy for HTTPS
|
||
on the team's own domain. Supermarket is published on Caddy's port,
|
||
not on 127.0.0.1.
|
||
- Server installs face the internet by default (decided 2026-11-25),
|
||
so sign-in limits, two-factor and the audit log matter from day one.
|
||
They can also be deployed on a private network or VPN: then Caddy
|
||
uses a certificate from the team's own CA, or DNS validation, since
|
||
Let's Encrypt can't reach it; services that call in (Stripe's
|
||
webhooks) don't, and polling takes over as on local.
|
||
- An `install-server.sh` asks for the domain and the mail server, and
|
||
generates the secret key and database password.
|
||
- Postgres gets nightly `pg_dump` backups. Settings → Backups shows
|
||
them on server, with restore done by the operator.
|
||
- The OAuth redirect addresses become `https://<domain>/auth/…`, so
|
||
each service's developer app needs that address added.
|
||
- Hermes and the CRM bridge: on a server, Hermes reaches `/mcp` with an
|
||
agent key that has the CRM scope (Phase 11), instead of the socket.
|
||
|
||
**Done when:** a server install's owner can invite an admin and a member
|
||
who has only SEO. The member signs in and sees only SEO. Every other
|
||
module, Settings and their fragments answer 403. The log shows each step.
|
||
|
||
#### Phase 11: Agents
|
||
|
||
Every edition gets this, including local, where an agent key replaces the
|
||
single `mcp-token`. A commit after each part.
|
||
|
||
1. **Agent users and their keys.**
|
||
- An admin creates an agent on Settings → Users → *New agent*. It has a
|
||
name, a description, and the modules it's given, each *read* or
|
||
*read and act*.
|
||
- Supermarket shows its key once (`sm_…`). Only a hash of the key is
|
||
kept.
|
||
- Keys can have an expiry date. Each key shows when it was last used,
|
||
and from where. A key can be rotated (the old one keeps working for a
|
||
day) or revoked.
|
||
- Agents go in the audit log like people, marked as agents.
|
||
- On local, today's `mcp-token` becomes the key of a built-in *Hermes*
|
||
agent with the CRM scope. The socket stays as it is.
|
||
2. **Module tools over MCP.**
|
||
- `/mcp` checks the key, and offers only the tools for the agent's
|
||
modules. A *read* grant gets only the reading tools.
|
||
- The tools follow what the pages do, module by module:
|
||
- **Content:** list items, create and edit drafts, schedule or
|
||
publish
|
||
- **Prospects:** signals and their replies, people, outreach drafts,
|
||
mailing lists, suppression
|
||
- **SEO:** the morning check, What to write next, Links, page edits
|
||
as proposals
|
||
- **Sites:** pages, sections, previews, push to Gitea
|
||
- **Metrics:** reads only
|
||
- **The Market:** list and edit
|
||
- Each tool calls the same Go functions the web handlers use, so rules
|
||
like suppression, opt-in and posting limits hold for agents too.
|
||
3. **Approvals for what goes out.**
|
||
- Anything that leaves Supermarket is held by default for a person to
|
||
approve: a post, an email, a site push, a mailing-list add. The
|
||
agent gets back *waiting for approval*.
|
||
- An **Approvals** page (and a count in the sidebar) lists what agents
|
||
asked to do. Members with that module, and admins, approve or refuse
|
||
each item, and can edit it first.
|
||
- **Everything waits for approval at first** (decided 2026-11-25).
|
||
An agent acts on its own only once a person has marked a *class* of
|
||
action as approved for automation. The classes:
|
||
- publish a post to a given posting account
|
||
- send a first email to a prospect
|
||
- send a reply in an existing conversation
|
||
- add someone to a given mailing list
|
||
- push a page to a given site
|
||
- apply an SEO change to a page
|
||
|
||
Approving a class is done per agent, by an admin, or by a member with
|
||
*edit* on that module (for the classes in it). Each approval can carry
|
||
a cap per day, is recorded, can be withdrawn at any time, and the
|
||
agent's page lists what it may do on its own. A new agent, or one
|
||
whose key was rotated after a leak, starts with no classes approved.
|
||
- The reason: agents read untrusted web text (signals, replies,
|
||
search results), the same risk that keeps the app's AI away from
|
||
Hermes' tools today.
|
||
4. **Limits and visibility.**
|
||
- Each agent has a rate limit per minute and a cap per day on things
|
||
that go out.
|
||
- The agent's page shows its recent calls (tool, result, time) and
|
||
what it's waiting on.
|
||
- A *Pause* switch stops all of an agent's calls at once.
|
||
5. **A JSON API, for scripts that aren't MCP clients.** It uses the same
|
||
key and has the same scopes and approvals, as REST under `/api/v1`,
|
||
covering what the MCP tools do. It's documented at `/api/v1/docs`.
|
||
This part can wait until someone needs it.
|
||
|
||
**Done when:** an agent with Content (read and act) and SEO (read) can run
|
||
a day's work through MCP: read the morning check, write drafts from What
|
||
to write next, and schedule them. Each draft waits on Approvals, and the
|
||
SEO tools that change things aren't offered to it. Revoking the key stops
|
||
it at once.
|
||
|
||
#### Phase 12: Signing in with the Core (OIDC)
|
||
|
||
1. **An OIDC sign-in.**
|
||
- The Core runs **Authelia** (2026-11-25), which is an OpenID Connect
|
||
provider. Its clients are listed in Authelia's configuration, so the
|
||
Core's admin adds Supermarket there: Supermarket's Settings → Sign-in
|
||
shows the block to paste (client ID, the hashed secret, the redirect
|
||
address `https://<domain>/auth/core/callback`, scopes `openid email
|
||
profile groups`).
|
||
- On Settings → Sign-in, the issuer address is filled in as
|
||
`https://authelia.<Core domain>`; an admin enters the client ID and
|
||
the secret, and *Test* checks the provider's discovery document.
|
||
- The sign-in page then offers *Sign in with <Core>*, with the code
|
||
flow and PKCE.
|
||
2. **Who may sign in.**
|
||
- Only invited users: the Core's account is matched by email at the
|
||
first sign-in, and then remembered by its subject ID.
|
||
- Optionally, an admin turns on *anyone with an address at
|
||
<domain> joins as a member with these modules*.
|
||
3. **Password, Core, or both.** An admin can require the Core's sign-in
|
||
for everyone. If they do, passwords are turned off, except the
|
||
owner's, kept as a way in if the Core is down.
|
||
4. **Signing out**, which also ends the Authelia session where Authelia
|
||
supports it.
|
||
5. **Groups, later:** Authelia's groups could map to roles (a
|
||
`supermarket-admins` group makes admins). Until then roles are set in
|
||
Supermarket.
|
||
|
||
Authelia is always at `authelia.<Core domain>` (confirmed 2026-11-25), so
|
||
Supermarket fills in the issuer itself from the Core's domain. Still open:
|
||
whether the Core's developer adds Supermarket's client to Authelia, or the
|
||
Core's admin tooling does it.
|
||
|
||
#### Phase 13: Multi-tenant
|
||
|
||
Many teams sign in at one address, each working on its own domains. This
|
||
builds on Phases 9–12. A commit after each part.
|
||
|
||
1. **Teams everywhere.**
|
||
- Every table that holds a company's data gets `team_id`, and its
|
||
unique keys include it. The settings table's key becomes
|
||
(team, key). This is a migration for both databases; local and
|
||
server get team 1.
|
||
- Queries go through a team-scoped handle (`db.Team(id)`) that adds
|
||
the team to every query. A test walks every query in the code and
|
||
fails on one without it.
|
||
2. **A second guard in Postgres.** Every team table gets row-level
|
||
security (`team_id = current_setting('app.team')`), set for each
|
||
request's transaction. A query the handle missed returns nothing,
|
||
instead of another team's rows. Platform jobs that need to see every
|
||
team use a separate database role.
|
||
3. **Signing up and creating a team.**
|
||
- On multi, the home page offers *Sign up*: an email, password, and
|
||
the company's name and first website. That person becomes the
|
||
team's owner, and the team starts on a trial (Phase 14).
|
||
- A user can belong to several teams (decided 2026-11-25), with a
|
||
team switcher in the sidebar; the role, modules and two-factor
|
||
sign-in are per user, the role and modules per team.
|
||
- **Each team works on one website domain** (decided 2026-11-25): one
|
||
registered domain, such as `example.com`, with its subdomains
|
||
(`www.`, `cloud.`, `enterprise.`) counted as part of it. A company
|
||
with a second domain sets up a second team. The server edition
|
||
follows the same rule; the local edition keeps its list of websites.
|
||
- Invitations work as in Phase 10, within a team.
|
||
4. **Proving a domain is the team's.** Before Supermarket does anything
|
||
with a website (crawl it, read its Search Console data, publish to
|
||
it), the team proves it's theirs, in one of three ways:
|
||
- a DNS TXT record
|
||
- a file on the site
|
||
- a Google Search Console property they own
|
||
|
||
A domain can belong to one team at a time. This keeps one team from
|
||
claiming another company's site. Proving the domain covers its
|
||
subdomains.
|
||
5. **Each team's connections and jobs.**
|
||
- Connections and secrets are per team: each team brings its own AI
|
||
key and services (decided 2026-11-25).
|
||
- The OAuth redirect addresses are the platform's
|
||
(`https://app…/auth/<service>/callback`), with the team in the
|
||
state. Teams register that address in their own developer apps.
|
||
- Background jobs run per team (Phase 9, part 6), with each team's
|
||
share of the work kept fair, so one team's 10,000 pages don't hold
|
||
up another's morning check.
|
||
- Each team has limits on outgoing fetches and storage, set by plan.
|
||
6. **The Core, per team.**
|
||
- A team running a Federated Core enters its Core's domain under
|
||
Connections. That replaces the `core.conf` a local install reads.
|
||
- Hermes and the CRM bridge connect from the team's own side, using
|
||
an agent key (Phase 11). The platform never holds a Core's admin
|
||
credentials.
|
||
7. **The platform's own admin.** This is for the people running the
|
||
service, separate from teams. Super-admins sign in at a separate
|
||
`/platform` area with two-factor sign-in required, and can:
|
||
- list teams, with their plan, usage and health
|
||
- suspend a team
|
||
- see jobs failing across teams
|
||
- resend a team's invitations
|
||
|
||
They can't read a team's data by default. *View as* requires a reason,
|
||
is time-limited, and is logged in the team's own audit log.
|
||
8. **A team's data is theirs.**
|
||
- The owner can export everything (Phase 9's export, without the
|
||
secrets unless asked for).
|
||
- Deleting the team removes its rows and files after 30 days. The
|
||
deletion can be undone within that time, and every user in the team
|
||
gets an email when it's asked for.
|
||
9. **Running at scale.** Several copies of the app can sit behind one
|
||
load balancer. Everything a request needs to remember lives in the
|
||
database (sessions, OAuth flows in progress, locks), so any copy can
|
||
answer any request. Files are in object storage. Postgres runs with
|
||
connection pooling. Per-team metrics feed the platform page.
|
||
10. **Hosting and object storage** (decided 2026-11-25: a cloud, with the
|
||
object storage installed by us, not the cloud's own).
|
||
- Supermarket only speaks the S3 API, so the store can be changed
|
||
later with a configuration change and a copy of the bucket.
|
||
- What goes in it is modest: backups and exports, uploaded files and
|
||
images, crawled pages kept for SEO, and site previews. Expect
|
||
gigabytes per team, not terabytes.
|
||
- The options looked at:
|
||
- **Garage** (chosen 2026-11-25): a single small binary, built
|
||
for a few nodes across zones, with replication of 3. It's easy
|
||
to run and light on memory. AGPL, which doesn't matter for a
|
||
separate service that's only reached over its API.
|
||
- **SeaweedFS**, if storage grows large or holds many millions of
|
||
small files. Apache 2.0, with more moving parts (master, volume
|
||
and filer servers).
|
||
- **Ceph's RADOS Gateway**, only if Ceph is run anyway (for
|
||
example with Rook on Kubernetes) for block storage too. Too heavy
|
||
just for this.
|
||
- Not **MinIO**: in 2025 its community edition lost its admin
|
||
console, stopped shipping binaries and images, and went into
|
||
maintenance mode.
|
||
- With Garage:
|
||
- three nodes in different zones
|
||
- a bucket and key per environment, with Supermarket's files under
|
||
a prefix per team
|
||
- versioning or a nightly `rclone` copy to another provider or
|
||
region, so a mistake or a lost cluster isn't a lost team
|
||
- Postgres beside it: the cloud's managed Postgres (chosen 2026-11-25), the least work.
|
||
If the platform is run on Kubernetes, CloudNativePG gives
|
||
replicas, failover and backups to the same object storage.
|
||
|
||
**Done when:** two teams with their own domains are signed up. Neither
|
||
can see or change the other's data, through any page, fragment, MCP tool
|
||
or job, and a test proves it for every route and tool. Three copies of the
|
||
app share the work.
|
||
|
||
#### Phase 14: Billing (multi-tenant)
|
||
|
||
The platform bills each team through **Stripe Billing**. This uses the
|
||
platform's own Stripe account (`SUPERMARKET_STRIPE_KEY`), which is
|
||
separate from the team's own Stripe connection that the Metrics module
|
||
reads.
|
||
|
||
1. **Plans.** Plans live in a configuration file, mapped to Stripe
|
||
prices. Each plan sets:
|
||
- the modules included
|
||
- seats (people), and how many agents
|
||
- pages crawled
|
||
- fetch and storage limits
|
||
|
||
Decided 2026-11-25: a **Free** tier and a **Paid** tier at **$15 per
|
||
user per month**. The limits below were suggested and accepted the
|
||
same day:
|
||
|
||
| | **Free** | **Paid**: $15/user/month |
|
||
|---|---|---|
|
||
| People | 2 | As many as paid for |
|
||
| Agents | 1 (not counted as a user) | 5 per team (not counted as users) |
|
||
| Modules | Content, SEO and the Market | All: also Prospects, Sites and Metrics |
|
||
| Storage | 1 GB per team | 5 GB per paid user, pooled for the team; more in 25 GB blocks |
|
||
| SEO crawl | 500 pages, weekly | 10,000 pages, daily |
|
||
| Content sources | 10 | No limit beyond fair use |
|
||
|
||
Why those modules on Free:
|
||
- Content and SEO show what Supermarket does on day one, and they cost
|
||
the platform little, since each team brings its own AI key.
|
||
- **Prospects** sends email to people who didn't ask for it. Keeping it
|
||
paid keeps spammers off the platform, which protects the deliverability
|
||
of everyone's mail.
|
||
- **Sites** pushes to a team's repository and builds previews: the
|
||
heaviest on storage.
|
||
- **Metrics** is worth most to a paying business with Stripe revenue.
|
||
|
||
Also decided:
|
||
- A new team gets a 14-day trial of Paid, then drops to Free unless the
|
||
owner subscribes.
|
||
- Agents count against the team's fetch and send limits, not its
|
||
seats.
|
||
2. **The owner's Billing page.** It shows the plan, seats in use, the
|
||
trial's end, and the next invoice. *Change plan* goes to Stripe
|
||
Checkout. *Payment and invoices* goes to Stripe's Customer Portal.
|
||
Only the owner sees it; admins see the plan, not the payment details.
|
||
3. **Stripe's events.** The multi-tenant edition can be reached from the
|
||
internet, so it takes Stripe's webhooks, with their signatures checked
|
||
(local still polls). Supermarket keeps the subscription's state per
|
||
team: trialing, active, past due, canceled.
|
||
4. **What happens when it lapses.**
|
||
- Past due: a banner, and the owner gets an email.
|
||
- After 14 days: the team becomes read-only. Nothing is fetched,
|
||
sent or published, and agents get *the team's subscription has
|
||
lapsed*.
|
||
- After 60 days, the team is deleted as in Phase 13, part 8, with
|
||
emails first.
|
||
5. **Seats.** Inviting beyond the plan's seats asks the owner to add a
|
||
seat (Stripe prorates it); admins are told to ask the owner.
|
||
6. **Moving down to Free.** A team over Free's limits when Paid ends:
|
||
- People beyond the first two (the owner, and one more of the owner's
|
||
choosing) become view-only until removed or paid for.
|
||
- The paid modules keep their data, read-only.
|
||
- Storage over the limit stops new files (no new crawls kept or
|
||
previews built), and nothing is deleted.
|
||
|
||
Open questions for this phase:
|
||
- Is there an annual plan (for example two months free)?
|
||
- Tax: Stripe Tax?
|
||
|
||
#### Order
|
||
|
||
```
|
||
Phase 9 (groundwork) ──► Phase 10 (users; the server edition) ──► Phase 11 (agents)
|
||
│ │
|
||
└──► Phase 12 (Core sign-in) │
|
||
▼
|
||
Phase 13 (multi-tenant) ◄─────────── 9, 10, 11, 12
|
||
│
|
||
└──► Phase 14 (billing)
|
||
```
|
||
|
||
Phase 11's first two parts can start on local right after Phase 9, since
|
||
they replace the `mcp-token`.
|
||
|
||
#### Open questions (2026-11-25)
|
||
|
||
1. ~~Several teams~~ *Resolved 2026-11-25:* yes; each team works on one
|
||
website domain (Phase 13, part 3).
|
||
2. ~~View-only access~~ *Resolved 2026-11-25:* members get each module
|
||
as *view* or *edit* (Phase 10, part 5).
|
||
3. ~~Posting as yourself~~ *Resolved 2026-11-25:* posting accounts,
|
||
several per platform, with admins choosing who may post to which; a
|
||
post can go out as yourself, as someone else, or to several accounts
|
||
at once (Phase 10, part 7).
|
||
4. *Partly resolved 2026-11-25:* the Core runs Authelia, always at
|
||
`authelia.<Core domain>`. Who adds Supermarket's client to it is still
|
||
open (Phase 12).
|
||
5. *Partly resolved 2026-11-25:* on a cloud, with Garage as the object
|
||
storage we install, and the cloud's managed Postgres (Phase 13, part
|
||
10). Which cloud is still open.
|
||
6. ~~Agents' approvals~~ *Resolved 2026-11-25:* everything waits for
|
||
approval until a person approves a class of action for automation
|
||
(Phase 11, part 3).
|
||
7. ~~Internet or private~~ *Resolved 2026-11-25:* server installs face
|
||
the internet, and can also be deployed on a private network (Phase 10,
|
||
part 9).
|
||
8. ~~Two-factor~~ *Resolved 2026-11-25:* an option for every user,
|
||
owners and admins included (Phase 10, part 3).
|
||
9. ~~Pricing~~ *Resolved 2026-11-25:* the Free and Paid limits in Phase
|
||
14, part 1. An annual plan and Stripe Tax are still open.
|
||
|
||
### Future enhancements
|
||
|
||
Not in any phase yet; picked up when the user asks.
|
||
|
||
1. **Post to the LinkedIn company page** (deferred 2026-11-21; Phase 6,
|
||
part 4). Today posts
|
||
go to the signed-in member's profile (`w_member_social`). Posting as the
|
||
Federated Computer page needs LinkedIn's **Community Management API**,
|
||
which LinkedIn approves by hand.
|
||
- The user's side: be an admin of the company page, with its website
|
||
and domain verified; create a *second* LinkedIn app linked to the page
|
||
(Community Management can only be requested on a new app with no other
|
||
products), have a page admin verify it, and request the Development
|
||
tier (an access form describing the use). It's likely enough: 500 calls
|
||
a day, though for up to 12 months. Standard tier needs a screen
|
||
recording and a privacy policy. A rejected app can't reapply; a new app
|
||
would be needed.
|
||
- Supermarket's side, once approved: a second set of LinkedIn keys and a
|
||
Connect button for the page app; list the pages the user administers
|
||
and pick one; on each LinkedIn draft, choose the profile or the page
|
||
(author `urn:li:organization:<id>`). Check the approved app's Auth tab
|
||
for the exact scopes (expected `w_organization_social`, plus one for
|
||
listing administered pages) before building.
|
||
- Docs: learn.microsoft.com/linkedin/marketing/community-management-app-review
|
||
and .../community-management/community-management-overview.
|
||
|
||
2. **Back up the database and restore from a backup** (asked for
|
||
2026-11-21; Phase 6, parts 1 and 2). Today backups are copies made by hand before risky changes
|
||
(`app.db.pre-phase1`, `app.db.pre-dedupe`, …) in the data folder. A plain
|
||
`cp` of a running database in WAL mode can miss recent writes, so
|
||
backups must use SQLite's own backup (`VACUUM INTO` or the online backup
|
||
API). This doesn't depend on any phase.
|
||
- **Where they go:** `~/.local/share/supermarket/backups/`, named
|
||
`app-<date>-<time>[-<reason>].db`, e.g. `app-20261121-1830-before-schema-9.db`.
|
||
Each one is a single, consistent SQLite file you can open with `sqlite3`.
|
||
- **When they're made:**
|
||
- When you ask: `supermarket backup [note]` from the terminal, or
|
||
*Back up now* on Settings → Backups.
|
||
- Automatically before every schema migration, before a restore, and
|
||
before bulk changes such as merging duplicates. This replaces the
|
||
hand-made `app.db.pre-*` copies.
|
||
- Once a day while the app runs.
|
||
- **Keeping them:** the last 7 daily backups, plus 4 weekly ones. Backups
|
||
made before a migration or a restore, and the ones you make yourself,
|
||
are kept until you delete them. Settings → Backups shows each backup's
|
||
size and schema version, and lets you download or delete it.
|
||
- **Restoring:** `supermarket restore <file>`, or *Restore* on a backup in
|
||
Settings → Backups (after you confirm). The steps:
|
||
1. Check the file: `PRAGMA integrity_check`, and that its schema isn't
|
||
newer than this version of the app.
|
||
2. Back up the current database first.
|
||
3. Stop the background jobs and close the database.
|
||
4. Swap the file in, removing the old `-wal` and `-shm` files.
|
||
5. Start again. Any migrations the backup lacks run on start.
|
||
|
||
From the browser, the app exits after the swap and Docker's
|
||
`restart: unless-stopped` brings it back. You can also restore a
|
||
downloaded backup by uploading it.
|
||
- **Secrets aren't included.** Tokens and keys stay in `secrets.json`,
|
||
and a restore never touches them. Putting them in a file that gets
|
||
downloaded and copied around would spread credentials.
|
||
`supermarket backup --with-secrets` adds them for a move to a new
|
||
machine. The result is a mode-0600 `.tar.gz`, and the command warns
|
||
that the file holds credentials.
|
||
- **The `supermarket` command:** `backup`, `backups` (lists them) and
|
||
`restore` run the app's own binary inside the container
|
||
(`docker exec supermarket supermarket backup …`). That way the backup
|
||
comes from the process that holds the database, with no locking
|
||
surprises.
|
||
- **The existing `app.db.pre-*` files:** moved into `backups/` the first
|
||
time, so they show up in the list. Their `-shm` and `-wal` leftovers are
|
||
dropped after a check that each copy opens.
|
||
- **Later:** an optional copy off this machine, to Nextcloud on the Core.
|
||
A backup in the same folder as the database won't survive a lost disk.
|
||
|
||
## 6. Contact enrichment: suggested services
|
||
|
||
"Enrichment" means: given a target company (or a person's name), find the
|
||
people in the roles you sell to, their work email and LinkedIn URL, and check
|
||
that the email is deliverable. These are good candidates; check current pricing
|
||
before choosing:
|
||
|
||
| Service | What it's good for | Notes |
|
||
|---------|-------------------|-------|
|
||
| **Hunter.io** | Emails at a company's domain, email finder by name, verification | Simple API, small free tier, cheap paid plans. A good first provider |
|
||
| **Apollo.io** | Searching people by title, seniority, industry and company size; returns email and LinkedIn URL | Largest database here. API access requires a paid plan. A strong second |
|
||
| **People Data Labs** | Person and company enrichment API for developers, paid per record | Good for bulk; little UI, which suits us |
|
||
| **Snov.io / Prospeo** | Finder + verifier, lower cost | Alternatives to Hunter |
|
||
| **BuiltWith or Wappalyzer** | Technographics: which companies use a given product | Feeds competitor counter-programming |
|
||
| **ZeroBounce / NeverBounce** | Verification only | Use if the finder's own verification isn't enough |
|
||
|
||
Recommendation: build the `enrich` interface with **Hunter** first (company
|
||
domain → people → verified email). Add **Apollo** for searching people by role,
|
||
and **BuiltWith/Wappalyzer** to find companies that use a competitor. Each user
|
||
brings their own API keys, and the app logs credits used as spend for CAC.
|
||
|
||
## 7. Order and dependencies
|
||
|
||
```
|
||
Phase 0 (incl. Hermes bridge test) ──► Phase 1 (content)
|
||
│
|
||
├──► Phase 2 (signals, prospects, funnel) ── needs: Hermes bridge, mcphub EspoCRM tools,
|
||
│ mail on the Core, Plausible, Stripe key
|
||
├──► Phase 3 (SEO) ──────── needs: Google OAuth (Search Console), Gitea token
|
||
├──► Phase 4 (metrics) ──── needs: Stripe key; CRM reads for pipeline
|
||
├──► Phase 5 (sites) ────── needs: Gitea token
|
||
└──► Phase 6 (backups; lead forms ─ needs: EspoCRM lead capture;
|
||
LinkedIn page ─ needs: LinkedIn's approval; new sites)
|
||
```
|
||
|
||
Phases 1, 3, 5 and the Stripe half of 4 depend only on Phase 0.
|
||
|
||
## 8. Open questions
|
||
|
||
1. **MCP hub credentials**: the example authenticates as an admin and uses
|
||
`as_user=` to act as the user. Can the hub issue per-user credentials or
|
||
tokens instead? An admin password in each desktop's Hermes `.env` gives an
|
||
agent that reads untrusted web content admin access to the Core.
|
||
*2026-11-19:* the Core's developer confirmed it's always the admin token
|
||
today. After the admin token failed with a 401, they said the hub will
|
||
likely move to per-user tokens.
|
||
*2026-11-20:* resolved. The hub now issues per-user tokens, still sent as
|
||
`Authorization: "Basic <token>"`, with `as_user=<user>` kept in the URL.
|
||
2. **MCP hub URL**: is it always `mcphub.<CORE_DOMAIN>`, so it can be worked out
|
||
from `core.conf`?
|
||
3. **Gitea**: which Gitea do sites live on (the Core's, at
|
||
`gitea.<CORE_DOMAIN>`?), and should the app get its token from the user or
|
||
from Gitea's OAuth?
|
||
*2026-11-22:* resolved. Sites live on the Core's Gitea
|
||
(gitea.federated.computer, with Federated_Computer/federated-website for
|
||
the main site). The user gives the app an access token with the
|
||
`write:repository` scope, under Settings → Search engines.
|