Supermarket queues CRM work in crm_actions and never writes to EspoCRM itself. A Hermes cron job (supermarket-crm, set up by `supermarket hermes`) runs every 15 minutes behind a monitor script that prints Supermarket's crm-state file, so unchanged state skips the AI run. Hermes calls the new MCP tools crm_pending_actions, crm_report_result and crm_ingest, creating each record through the Core's MCP hub unless a match exists, and copying Leads, Accounts and Contacts back every 6 hours for duplicate checks. Schema 5 adds crm_actions and crm_records. Prospects -> CRM queue shows the queue, a test Lead, sync, Retry and Cancel. When an action fails with a connection error, the page checks EspoCRM from this computer and says whether the CRM is down or the hub can't reach it, with a note to send to the Core's maintainer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
166 lines
13 KiB
Markdown
166 lines
13 KiB
Markdown
# Supermarket
|
|
|
|
A marketing suite for companies that run a [Federated Core](https://federated.computer), installed as a [CoreDesktop](https://gitea.federated.computer/Federated_Computer/coredesktop) sibling project. It runs as a web app in Docker on your computer, at <http://localhost:8470>, and only your computer can reach it.
|
|
|
|
Everything starts from your **company profile** (what you sell, to whom, in what voice) and your **inventory** of partners and competitors. On top of those, Supermarket will:
|
|
|
|
| Module | What it does | Status |
|
|
|--------|--------------|--------|
|
|
| Content | Drafts posts from partner and competitor news and your own products; you review them and publish to X, LinkedIn and Reddit | Phase 1: done |
|
|
| Prospects | Finds companies and people who fit your targets; the ones you approve go into your Core's EspoCRM through Hermes | Phase 2 |
|
|
| SEO | Audits your websites for Google, Bing/DuckDuckGo and Brave, and opens fixes as pull requests on your Hugo repositories | Phase 3 |
|
|
| Metrics | Pipeline influence, CAC, CLV and NRR, from Stripe, EspoCRM and Plausible | Phase 4 |
|
|
| Sites | Builds pages and sites from a component library and publishes them through Gitea | Phase 5 |
|
|
|
|
This version has the foundation (Phase 0): the web app, the company profile, the inventory, the AI provider, credentials, and the bridge to your Core through Hermes. It also has the Content module (Phase 1): posts about partners, competitors and your own products, a Posts page for approval, scheduled publishing to X, LinkedIn and Reddit, and UTM tags. See [PLAN.md](PLAN.md) for the whole plan.
|
|
|
|
## Install
|
|
|
|
On a CoreDesktop machine:
|
|
|
|
```
|
|
sibling add <this repository's git URL>
|
|
```
|
|
|
|
This runs [install.sh](install.sh), which:
|
|
|
|
1. builds and starts Supermarket's container (Docker and Docker Compose come with CoreDesktop),
|
|
2. adds Supermarket to GNOME's app grid with CoreDesktop's `webapp`,
|
|
3. imports the old terminal app's settings, credentials and queued posts, if it finds them in `~/.local/state/coremarketing` (copied, not moved),
|
|
4. connects Hermes to your Core's MCP hub and to Supermarket (see [Hermes](#hermes-and-your-core)), and
|
|
5. offers to let Claude Code use Supermarket's tools.
|
|
|
|
After that, CoreDesktop's `update` keeps it current: it pulls this repository and runs [update.sh](update.sh), which rebuilds the container when the code has changed.
|
|
|
|
Then open Supermarket and:
|
|
|
|
1. **Settings → AI**: Anthropic, with Hermes' key (shared by `supermarket hermes`) or your own, or an LLM server on your network, such as Ollama. Servers found by CoreDesktop's `configure ai-servers` are offered.
|
|
2. **Settings → Profile**: enter your website and press *Draft*. Correct the draft and save it.
|
|
3. **Inventory**: add your partners and competitors, or import a list. On an entry, *Fill in the empty boxes* reads their website: links, accounts and feeds come straight from the pages, and the AI drafts a description, talking points set against your profile, keywords, hashtags and subreddits. Suggested subreddits are checked with Reddit first (with the Reddit client ID and secret saved), and ones that don't exist, are private or are restricted are left out. What you typed stays; nothing is saved until you press Save.
|
|
4. **Settings → Social accounts**: connect X, LinkedIn and Reddit.
|
|
|
|
The menu on the left has a search box at the top (press `/` to jump to it), then the **Overview** with a card per module, the **Inventory**, and the modules: **Content** (Posts, Sources, Scheduled, Published), and the ones still to come. **Settings**, at the bottom, holds the Profile, Social accounts, Core & Hermes, and AI. Search finds posts, fetched items, inventory entries, your products and settings pages. The look follows brain (Federated's superbrain), including a dark theme that follows your system's setting.
|
|
|
|
## The `supermarket` command
|
|
|
|
```
|
|
supermarket open it in the browser (starting it if needed)
|
|
supermarket status running? which version?
|
|
supermarket logs follow its log
|
|
supermarket restart restart it
|
|
supermarket stop stop it, until you start it again
|
|
supermarket hermes set up Hermes' connection again (--reconfigure to change the MCP hub)
|
|
supermarket token the token agents use for its MCP endpoint
|
|
```
|
|
|
|
## Where things are
|
|
|
|
| What | Where |
|
|
|------|-------|
|
|
| Data: database, imported files | `~/.local/share/supermarket/` (`app.db`, `import/`) |
|
|
| API keys and tokens | `~/.local/share/supermarket/secrets.json`, readable only by you. Never in the repository or the image |
|
|
| MCP token | `~/.local/share/supermarket/mcp-token` |
|
|
| The Core's settings | A copy of CoreDesktop's `~/.config/coredesktop/core.conf`, refreshed by every `update` |
|
|
|
|
Back up `~/.local/share/supermarket` to keep everything.
|
|
|
|
## Hermes and your Core
|
|
|
|
Supermarket never talks to your Core's MCP hub itself. CoreDesktop's Hermes agent does: it holds your own token for the hub, and carries out the CRM work Supermarket queues. The two meet through Supermarket's own MCP server. Hermes runs in CoreDesktop's sandbox, which has its own network (`127.0.0.1:8470` there isn't your computer's), so Hermes reaches Supermarket through a Unix socket in the data folder, `~/.local/share/supermarket/mcp.sock`, using `socat`. Other agents, such as Claude Code, use `http://localhost:8470/mcp` with the bearer token from `supermarket token`.
|
|
|
|
`install.sh` (or `supermarket hermes`) adds both MCP servers to `~/.hermes/config.yaml`:
|
|
|
|
```yaml
|
|
mcp_servers:
|
|
mcphub:
|
|
url: "https://mcphub.<your Core's domain>/sse?as_user=<your user name>"
|
|
transport: sse
|
|
headers:
|
|
Authorization: "Basic ${MCPHUB_AUTH}"
|
|
supermarket:
|
|
command: socat
|
|
args: ["STDIO", "UNIX-CONNECT:/home/<you>/.local/share/supermarket/mcp.sock"]
|
|
```
|
|
|
|
Hermes fills in `${MCPHUB_AUTH}` from `~/.hermes/.env` when it connects, so `config.yaml` holds no secret:
|
|
|
|
```
|
|
MCPHUB_AUTH=<your own hub token from your Core: the part after "Basic ">
|
|
```
|
|
|
|
Hermes' sandbox can only reach the hub once it's in `network.allowedDomains` in `~/.config/coredesktop/sandbox/hermes.json`. The script asks before adding it, then restarts Hermes' gateway. To enter a different hub token: `supermarket hermes --reconfigure`.
|
|
|
|
**AI for Supermarket itself.** If Hermes uses an Anthropic key, `supermarket hermes` offers to let Supermarket use the same key and model, so AI is set up once. Only the key and model are copied, to `hermes-ai.json` in the data folder (readable only by you), and `update.sh` keeps them in step. Supermarket still calls the model directly, not through Hermes: writing posts means reading text from the web, and that text shouldn't reach an agent that has tools and your CRM. A key saved under Settings → AI takes the place of Hermes'.
|
|
|
|
To check the connection, open **Core & Hermes** in Supermarket and ask Hermes the question shown there. Hermes lists the hub's tools and reports them back to Supermarket, which shows when it last heard from Hermes.
|
|
|
|
**The CRM queue (Prospects → CRM queue).** What Supermarket wants in EspoCRM waits in a queue, with the exact fields and how to recognise a record that's already there. `supermarket hermes` adds a Hermes scheduled job, `supermarket-crm`, that runs every 15 minutes: it calls Supermarket's `crm_pending_actions` tool, creates each record through the hub's EspoCRM tools unless a matching one exists, and reports each result with `crm_report_result`. Every 6 hours (or when you press *Sync on the next run*) it also copies your Leads, Accounts and Contacts to Supermarket with `crm_ingest`, so Supermarket can spot people and companies you already have. Before each run, the job runs `~/.hermes/scripts/supermarket-crm-check.sh`, which prints `crm-state` from the data folder; while that hasn't changed, Hermes skips the run and uses no AI. The page shows the command to run the job now, and *Send a test Lead* checks the whole path. Failed actions can be retried or cancelled; nothing is written to your CRM that isn't in the queue.
|
|
|
|
## Writing and publishing posts
|
|
|
|
1. Fill in the **Profile** (posts are written in its voice) and choose an **AI provider** under Settings.
|
|
2. Add partners and competitors to the **Inventory**, with the places to watch: an X handle, hashtags, a YouTube channel, RSS feeds.
|
|
3. Under **Content**, open an entry and press **Fetch new**. Supermarket reads every source that has credentials, starting where the last fetch ended (or a week back).
|
|
4. Select items, choose the channels, and press **Write drafts**: one post from all of them, or one per item. Each channel gets its own draft.
|
|
5. Under **Posts**, edit each draft, then **Publish now** or **Schedule** it. The source link is added when publishing (on X it counts toward the 280 characters, and the counter includes it). A failed draft comes back to Posts with its error; the other channel's draft is unaffected.
|
|
6. Scheduled posts are listed under **Content → Scheduled**, and go out on time while the container runs (it starts with your computer). One more than 12 hours late, because the computer was off, goes back to Posts instead of going out stale.
|
|
|
|
Links to your own websites and product pages (from the profile) get UTM tags when published: `utm_source` is the channel, `utm_medium` is `social`, `utm_campaign` is the kind of post (partner, competitor, watch) and `utm_content` is the entry and draft. Links elsewhere are left as they are. Times are shown and read in your computer's time zone.
|
|
|
|
**Your own products.** The first row under Content is your company. It lists the products from your profile, ready to write about, and fetches your own feeds (blog, news, and releases: a GitHub or Gitea repository's `releases.atom` works) and new or updated pages from your websites' `sitemap.xml`. Add the feeds under Profile → Websites. Posts from it promote your work, under `utm_campaign=product`.
|
|
|
|
Reading X needs a bearer token from an X API plan with read access; YouTube needs a free API key; RSS needs nothing. Posting needs the sign-ins below.
|
|
|
|
### Reddit
|
|
|
|
A Reddit draft is a title and a text for one subreddit, which you choose when writing (suggestions come from the entry's and the profile's subreddits). The subreddit's rules and posting guidelines are read, given to the model, and shown with the draft in Posts. Reddit drafts are written as a community member who says where they work, without hashtags or marketing language. The source link goes at the end of the text; a subreddit that only takes links gets the title and the link.
|
|
|
|
Before you publish, Posts warns, without blocking, when:
|
|
- the subreddit has a rule about self-promotion, is restricted, or doesn't take that kind of post,
|
|
- you posted in that subreddit in the past week,
|
|
- more than 1 in 10 of your posts in the past 30 days would link to your own sites (Reddit's guideline),
|
|
- the account has no posts yet.
|
|
|
|
Reddit's Data API terms need Reddit's approval for commercial use. Supermarket is meant for a few hand-approved posts, never volume or automation: every post needs you to press Publish or Schedule.
|
|
|
|
## Signing in to X, LinkedIn and Reddit
|
|
|
|
Sign-ins come back to Supermarket at `http://localhost:8470/auth/<provider>/callback` (X: `127.0.0.1` instead of `localhost`). Register these callback URLs in your apps:
|
|
|
|
- X developer portal, your app's *User authentication settings*: `http://127.0.0.1:8470/auth/x/callback`. X refuses `localhost` in callback URLs; `127.0.0.1` is the same machine, and Supermarket sends X this address.
|
|
- LinkedIn developer portal, your app's *Auth* tab: `http://localhost:8470/auth/linkedin/callback`
|
|
- Reddit, [reddit.com/prefs/apps](https://www.reddit.com/prefs/apps): create a **web app** with the redirect URI `http://localhost:8470/auth/reddit/callback`, and put its client ID and secret under Settings → Social accounts
|
|
|
|
The old terminal app used `http://localhost:8080/callback`; you can remove that one.
|
|
|
|
## Security
|
|
|
|
- The port is published on `127.0.0.1` only, so other machines can't reach it, whatever the firewall says.
|
|
- The app has no login, so it protects itself from web pages open in the same browser: it only answers requests addressed to `localhost` (against DNS rebinding), and refuses form posts that don't come from its own pages.
|
|
- The container runs as you, with a read-only filesystem, no Linux capabilities and `no-new-privileges`. It can write only its data folder.
|
|
- `/mcp` requires the bearer token in `mcp-token`.
|
|
|
|
## Development
|
|
|
|
Requires Go (see `go.mod`).
|
|
|
|
```
|
|
go test ./...
|
|
SUPERMARKET_DATA=/tmp/cm SUPERMARKET_ADDR=127.0.0.1:8470 go run ./cmd/supermarket
|
|
```
|
|
|
|
| Path | What |
|
|
|------|------|
|
|
| `cmd/supermarket` | The server |
|
|
| `internal/web` | Pages (Go templates + [htmx](https://htmx.org), no JavaScript build) |
|
|
| `internal/profile`, `internal/inventory` | The company profile and the inventory |
|
|
| `internal/ai` | AI providers: Anthropic (official Go SDK) and OpenAI-compatible servers |
|
|
| `internal/mcpserver`, `internal/bridge` | The `/mcp` endpoint and Hermes' check-ins |
|
|
| `internal/legacy` | One-time import from the old terminal app |
|
|
| `internal/content` | The Content module: fetched items, per-channel drafts, prompts, scheduling, publishing |
|
|
| `internal/utm` | UTM tags for links to the company's own sites |
|
|
| `internal/api`, `internal/fetcher` | X, LinkedIn, Reddit, YouTube and RSS clients, and fetching for an inventory entry |
|
|
| `hermes/setup.sh` | Connects Hermes |
|
|
|
|
Database changes go in `internal/db/db.go` as a new migration; never edit one that has shipped.
|