Phase 0: turn Supermarket into a Dockerized local web app
Replace the old Go TUI with a web app (port 8470) that runs in a container as a CoreDesktop sibling: - cmd/supermarket server with htmx web UI: dashboard, company profile, inventory (partners/competitors), AI and credential settings, and a Core & Hermes page - SQLite storage and a secrets store under ~/.local/share/supermarket - AI providers (Anthropic, OpenAI-compatible) behind one interface - MCP server and a Hermes bridge to the Federated Core MCP hub - Import of the old Coremarketing TUI's state - install.sh / update.sh / lib.sh, Dockerfile, compose.yaml, the bin/supermarket launcher and hermes/setup.sh Posting is not wired back up yet; that comes in Phase 1. See PLAN.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
// Package profile is the company profile: what the company sells, to whom,
|
||||
// in what voice, and where it lives online. Every module reads it.
|
||||
package profile
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"supermarket/internal/db"
|
||||
)
|
||||
|
||||
const settingKey = "profile"
|
||||
|
||||
type Product struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
URL string `json:"url"`
|
||||
Pricing string `json:"pricing"`
|
||||
Benefits []string `json:"benefits"`
|
||||
}
|
||||
|
||||
// Targets is the ideal customer profile.
|
||||
type Targets struct {
|
||||
Industries []string `json:"industries"`
|
||||
CompanySizes []string `json:"company_sizes"`
|
||||
Roles []string `json:"roles"`
|
||||
Regions []string `json:"regions"`
|
||||
Problems []string `json:"problems"`
|
||||
BuyingSignals []string `json:"buying_signals"`
|
||||
Technologies []string `json:"technologies"`
|
||||
}
|
||||
|
||||
type Website struct {
|
||||
URL string `json:"url"`
|
||||
Repo string `json:"repo"` // Gitea repository of the Hugo site
|
||||
Branch string `json:"branch"` // the branch that gets published
|
||||
PlausibleSite string `json:"plausible_site"`
|
||||
SearchConsoleProperty string `json:"search_console_property"`
|
||||
BingSite string `json:"bing_site"`
|
||||
}
|
||||
|
||||
type Accounts struct {
|
||||
X string `json:"x"` // handle, without @
|
||||
LinkedIn string `json:"linkedin"` // organization page URL
|
||||
Reddit string `json:"reddit"` // user name, without u/
|
||||
Subreddits []string `json:"subreddits"`
|
||||
}
|
||||
|
||||
type Profile struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Positioning string `json:"positioning"`
|
||||
Voice string `json:"voice"`
|
||||
Avoid []string `json:"avoid"`
|
||||
Products []Product `json:"products"`
|
||||
Targets Targets `json:"targets"`
|
||||
Websites []Website `json:"websites"`
|
||||
Accounts Accounts `json:"accounts"`
|
||||
Keywords []string `json:"keywords"`
|
||||
}
|
||||
|
||||
// IsSet reports whether the profile has the minimum the other modules need.
|
||||
func (p *Profile) IsSet() bool {
|
||||
return strings.TrimSpace(p.Name) != "" && strings.TrimSpace(p.Description) != ""
|
||||
}
|
||||
|
||||
// Load returns the saved profile, or an empty one.
|
||||
func Load(d *db.DB) (*Profile, error) {
|
||||
p := &Profile{}
|
||||
if _, err := d.GetJSON(settingKey, p); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// Save stores the profile after tidying it.
|
||||
func Save(d *db.DB, p *Profile) error {
|
||||
p.Clean()
|
||||
return d.PutJSON(settingKey, p)
|
||||
}
|
||||
|
||||
// Clean trims whitespace and drops empty list entries, products and websites.
|
||||
func (p *Profile) Clean() {
|
||||
p.Name = strings.TrimSpace(p.Name)
|
||||
p.Description = strings.TrimSpace(p.Description)
|
||||
p.Positioning = strings.TrimSpace(p.Positioning)
|
||||
p.Voice = strings.TrimSpace(p.Voice)
|
||||
p.Avoid = CleanList(p.Avoid)
|
||||
p.Keywords = CleanList(p.Keywords)
|
||||
|
||||
products := p.Products[:0]
|
||||
for _, pr := range p.Products {
|
||||
pr.Name = strings.TrimSpace(pr.Name)
|
||||
pr.Description = strings.TrimSpace(pr.Description)
|
||||
pr.URL = strings.TrimSpace(pr.URL)
|
||||
pr.Pricing = strings.TrimSpace(pr.Pricing)
|
||||
pr.Benefits = CleanList(pr.Benefits)
|
||||
if pr.Name != "" {
|
||||
products = append(products, pr)
|
||||
}
|
||||
}
|
||||
p.Products = products
|
||||
|
||||
websites := p.Websites[:0]
|
||||
for _, w := range p.Websites {
|
||||
w.URL = strings.TrimRight(strings.TrimSpace(w.URL), "/")
|
||||
w.Repo = strings.TrimSpace(w.Repo)
|
||||
w.Branch = strings.TrimSpace(w.Branch)
|
||||
w.PlausibleSite = strings.TrimSpace(w.PlausibleSite)
|
||||
w.SearchConsoleProperty = strings.TrimSpace(w.SearchConsoleProperty)
|
||||
w.BingSite = strings.TrimSpace(w.BingSite)
|
||||
if w.URL != "" {
|
||||
if w.Branch == "" && w.Repo != "" {
|
||||
w.Branch = "main"
|
||||
}
|
||||
websites = append(websites, w)
|
||||
}
|
||||
}
|
||||
p.Websites = websites
|
||||
|
||||
t := &p.Targets
|
||||
t.Industries = CleanList(t.Industries)
|
||||
t.CompanySizes = CleanList(t.CompanySizes)
|
||||
t.Roles = CleanList(t.Roles)
|
||||
t.Regions = CleanList(t.Regions)
|
||||
t.Problems = CleanList(t.Problems)
|
||||
t.BuyingSignals = CleanList(t.BuyingSignals)
|
||||
t.Technologies = CleanList(t.Technologies)
|
||||
|
||||
a := &p.Accounts
|
||||
a.X = strings.TrimPrefix(strings.TrimSpace(a.X), "@")
|
||||
a.LinkedIn = strings.TrimSpace(a.LinkedIn)
|
||||
a.Reddit = strings.TrimPrefix(strings.TrimPrefix(strings.TrimSpace(a.Reddit), "/"), "u/")
|
||||
subs := CleanList(a.Subreddits)
|
||||
for i, s := range subs {
|
||||
subs[i] = strings.TrimPrefix(strings.TrimPrefix(s, "/"), "r/")
|
||||
}
|
||||
a.Subreddits = subs
|
||||
}
|
||||
|
||||
// CleanList trims entries and drops empty ones and duplicates, keeping order.
|
||||
func CleanList(in []string) []string {
|
||||
out := make([]string, 0, len(in))
|
||||
seen := map[string]bool{}
|
||||
for _, s := range in {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" || seen[strings.ToLower(s)] {
|
||||
continue
|
||||
}
|
||||
seen[strings.ToLower(s)] = true
|
||||
out = append(out, s)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Lines splits text into one entry per line, for the form's list fields.
|
||||
func Lines(text string) []string {
|
||||
return CleanList(strings.Split(strings.ReplaceAll(text, "\r\n", "\n"), "\n"))
|
||||
}
|
||||
Reference in New Issue
Block a user