Phase 1, part 4: promote the company's own products

- Content lists the company first, at /content/own: its products from
  the profile (always there to pick from), its own feeds (a new profile
  field for the blog, news and releases), and new or updated pages from
  its websites' sitemaps, with each page's title and description.
- Drafts from it are kind "product" (utm_campaign=product), filed under
  the company's name, and prompted to promote the company's own work
  without unsupported claims; on Reddit, in the makers' voice, with a
  warning that self-promotion is often restricted.

This completes Phase 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 14:42:37 -07:00
co-authored by Claude Opus 5.5
parent 0e34f574b7
commit cd24f2a06d
20 changed files with 685 additions and 30 deletions
+16 -3
View File
@@ -101,6 +101,11 @@ func Generate(ctx context.Context, client ai.Client, req Request) ([]Draft, erro
return nil, err
}
// Drafts about the company itself are filed under its name.
name := req.Entry.Name
if IsOwn(req.Entry) {
name = req.Profile.Name
}
ids := make([]string, 0, len(req.Items))
for _, it := range req.Items {
ids = append(ids, it.ID)
@@ -117,7 +122,7 @@ func Generate(ctx context.Context, client ai.Client, req Request) ([]Draft, erro
if r := []rune(title); len(r) > RedditTitleLimit {
title = string(r[:RedditTitleLimit-1]) + "…"
}
drafts = append(drafts, Draft{InventoryName: req.Entry.Name, Kind: req.Entry.Relationship, Channel: ch,
drafts = append(drafts, Draft{InventoryName: name, Kind: req.Entry.Relationship, Channel: ch,
Title: title, Target: reddit.CleanName(req.Subreddit), Content: strings.TrimSpace(rp.Body),
SourceURL: src, ItemIDs: ids, Status: StatusDraft})
continue
@@ -136,7 +141,7 @@ func Generate(ctx context.Context, client ai.Client, req Request) ([]Draft, erro
}
}
drafts = append(drafts, Draft{
InventoryName: req.Entry.Name,
InventoryName: name,
Kind: req.Entry.Relationship,
Channel: ch,
Content: text,
@@ -227,11 +232,15 @@ func userPrompt(req Request, src string) string {
} else {
fmt.Fprintf(&b, "You may name %s.\n", e.Name)
}
case KindProduct:
fmt.Fprintf(&b, "This is about our own work at %s: a product, a release, a blog post or a page on our site. Promote it: "+
"say what's new or what it does, and the concrete benefit for the audience, with one clear next step that suits the channel "+
"(try it, read more). Make only claims that the source material or the company information supports.\n", req.Profile.Name)
default:
fmt.Fprintf(&b, "Curate this news about %s for our audience: say what happened and why it matters to them. "+
"Don't promote our products or theirs.\n", e.Name)
}
if e.Description != "" {
if e.Description != "" && !IsOwn(e) {
fmt.Fprintf(&b, "About %s: %s\n", e.Name, oneLine(e.Description))
}
if e.TalkingPoints != "" {
@@ -290,6 +299,10 @@ func redditInstructions(req Request) string {
"no calls to action. Usually 80 to 250 words, in Reddit's markdown. The title must read like a normal post title, not a headline ad. "+
"Follow the subreddit's rules below; if they forbid promotion, write a genuine discussion post that doesn't promote anything.\n",
RedditTitleLimit, sub, req.Profile.Name, req.Profile.Name)
if req.Entry.Relationship == KindProduct {
b.WriteString(" This promotes our own work: write as the people who made it, share what's genuinely useful or interesting " +
"about it, and invite questions and feedback.\n")
}
if info := req.SubredditInfo; info != nil {
b.WriteString("<subreddit>\n")
if info.Description != "" {
+2 -1
View File
@@ -117,7 +117,8 @@ func GetItems(d *db.DB, ids []string) ([]Item, error) {
// Counts is how many items an entry has waiting (not used, not dismissed).
func Counts(d *db.DB) (map[string]int, error) {
rows, err := d.Query(`SELECT c.inventory_name, count(*)` + itemFrom + `
WHERE d.item_id IS NULL AND c.used_at IS NULL GROUP BY c.inventory_name COLLATE NOCASE`)
WHERE d.item_id IS NULL AND c.used_at IS NULL AND c.source != 'Product'
GROUP BY c.inventory_name COLLATE NOCASE`)
if err != nil {
return nil, err
}
+91
View File
@@ -0,0 +1,91 @@
package content
import (
"fmt"
"strings"
"time"
"supermarket/internal/db"
"supermarket/internal/inventory"
"supermarket/internal/models"
"supermarket/internal/profile"
"supermarket/internal/utm"
)
// The company's own content (its products, feeds and site pages) is handled
// like an inventory entry that isn't stored: OwnEntry builds it from the
// profile. Its items are stored under OwnName.
const (
OwnName = "_own"
KindProduct = "product"
)
// OwnEntry is the company as a content source.
func OwnEntry(p *profile.Profile) *inventory.Entry {
e := &inventory.Entry{Name: OwnName, Relationship: KindProduct, RSS: p.Feeds,
Description: p.Description, Subreddits: p.Accounts.Subreddits}
for _, w := range p.Websites {
e.Websites = append(e.Websites, w.URL)
}
return e
}
// IsOwn reports whether e is the company itself.
func IsOwn(e *inventory.Entry) bool { return e.Name == OwnName }
// SyncProducts keeps an item for each product in the profile, so products
// can be selected and written about like fetched items. Removed products'
// items go; a product's item keeps its ID (and "drafted" mark) while its
// name stays the same.
func SyncProducts(d *db.DB, p *profile.Profile) error {
tx, err := d.Begin()
if err != nil {
return err
}
defer tx.Rollback()
keep := map[string]bool{}
for _, pr := range p.Products {
id := "product:" + utm.Slug(pr.Name)
if id == "product:" || keep[id] {
continue
}
keep[id] = true
var body strings.Builder
body.WriteString(pr.Description)
if len(pr.Benefits) > 0 {
fmt.Fprintf(&body, "\nBenefits: %s.", strings.Join(pr.Benefits, "; "))
}
if pr.Pricing != "" {
fmt.Fprintf(&body, "\nPricing: %s", pr.Pricing)
}
if _, err := tx.Exec(`INSERT INTO content_items (id, inventory_name, source, title, body, url, published_at)
VALUES (?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (id) DO UPDATE SET title = excluded.title, body = excluded.body, url = excluded.url`,
id, OwnName, string(models.SourceProduct), pr.Name, strings.TrimSpace(body.String()), pr.URL,
formatTime(time.Now())); err != nil {
return err
}
}
rows, err := tx.Query(`SELECT id FROM content_items WHERE inventory_name = ? AND source = ?`, OwnName, string(models.SourceProduct))
if err != nil {
return err
}
var stale []string
for rows.Next() {
var id string
if err := rows.Scan(&id); err != nil {
rows.Close()
return err
}
if !keep[id] {
stale = append(stale, id)
}
}
rows.Close()
for _, id := range stale {
if _, err := tx.Exec(`DELETE FROM content_items WHERE id = ?`, id); err != nil {
return err
}
}
return tx.Commit()
}
+79
View File
@@ -0,0 +1,79 @@
package content
import (
"context"
"strings"
"testing"
"supermarket/internal/models"
"supermarket/internal/profile"
)
func TestOwnContent(t *testing.T) {
d := openDB(t)
p := testProfile()
p.Products = append(p.Products, profile.Product{Name: "Acme Mail", Description: "Hosted email.", URL: "https://acme.example/mail", Pricing: "$3/user"})
p.Feeds = []string{"https://acme.example/blog/index.xml"}
p.Websites = []profile.Website{{URL: "https://acme.example"}}
if err := SyncProducts(d, p); err != nil {
t.Fatal(err)
}
items, _ := ListItems(d, OwnName, false, 10)
if len(items) != 2 {
t.Fatalf("items = %+v", items)
}
var mail Item
for _, it := range items {
if it.ID == "product:acme-mail" {
mail = it
}
}
if mail.Source != models.SourceProduct || mail.Title != "Acme Mail" || !strings.Contains(mail.Body, "Pricing: $3/user") {
t.Errorf("product item = %+v", mail)
}
if c, _ := Counts(d); c[OwnName] != 0 {
t.Errorf("products counted as waiting news: %v", c)
}
// Writing about it marks it, and a re-sync keeps the mark; a removed
// product's item goes.
e := OwnEntry(p)
if !IsOwn(e) || e.Relationship != KindProduct || len(e.RSS) != 1 || e.Websites[0] != "https://acme.example" {
t.Errorf("own entry = %+v", e)
}
f := &fakeAI{replies: []string{`{"linkedin": "Try Acme Mail."}`}}
drafts, err := Generate(context.Background(), f, Request{Profile: p, Entry: e, Items: []Item{mail}, Channels: []string{ChannelLinkedIn}})
if err != nil {
t.Fatal(err)
}
if drafts[0].InventoryName != "Acme" || drafts[0].Kind != KindProduct || drafts[0].SourceURL != "https://acme.example/mail" {
t.Errorf("draft = %+v", drafts[0])
}
if !strings.Contains(f.reqs[0].Prompt, "our own work at Acme") || strings.Contains(f.reqs[0].Prompt, "About _own") {
t.Errorf("prompt:\n%s", f.reqs[0].Prompt)
}
if _, err := CreateDrafts(d, drafts); err != nil {
t.Fatal(err)
}
p.Products = p.Products[1:]
p.Products[0].Description = "Hosted email, now with calendars."
if err := SyncProducts(d, p); err != nil {
t.Fatal(err)
}
items, _ = ListItems(d, OwnName, false, 10)
if len(items) != 1 || !items[0].Used || !strings.Contains(items[0].Body, "calendars") {
t.Errorf("after re-sync: %+v", items)
}
// On Reddit, product posts get a warning and a maker's voice.
if w := RedditWarnings(RedditCheck{Target: "selfhosted", Promo: true, Now: mail.FetchedAt}); !strings.Contains(w[0], "promotes your own work") {
t.Errorf("warnings = %q", w)
}
f = &fakeAI{replies: []string{`{"reddit": {"title": "We built a mail host", "body": "I work at Acme."}}`}}
if _, err := Generate(context.Background(), f, Request{Profile: p, Entry: e, Items: items, Channels: []string{ChannelReddit}, Subreddit: "selfhosted"}); err != nil {
t.Fatal(err)
}
if !strings.Contains(f.reqs[0].Prompt, "people who made it") {
t.Errorf("reddit product prompt:\n%s", f.reqs[0].Prompt)
}
}
+4
View File
@@ -61,6 +61,7 @@ type RedditCheck struct {
Target string
HasLink bool // the draft carries a link
OwnLink bool // to the company's own site
Promo bool // it promotes the company's own product
Info *reddit.Subreddit // nil if the rules couldn't be read
History []reddit.Submission // the account's recent posts; nil if unknown
Own func(url string) bool
@@ -72,6 +73,9 @@ type RedditCheck struct {
func RedditWarnings(c RedditCheck) []string {
var w []string
sub := "r/" + c.Target
if c.Promo {
w = append(w, "This promotes your own work. Many subreddits allow that only in designated threads, or not at all: check the rules.")
}
if c.Info == nil {
w = append(w, "Couldn't read "+sub+"'s rules: check them on Reddit before posting.")
} else {