Phase 1, part 1: fetch, write and publish posts from the web app

Brings back posting, which Phase 0 removed with the terminal interface.

- Content page: per inventory entry, fetch its X account, X hashtag
  search, YouTube channel and RSS/Atom feeds (new), then select, dismiss
  or restore the fetched items, which are kept in the database.
- Writing: one AI call returns a draft per channel (X and LinkedIn),
  prompted from the company profile, the entry's relationship, talking
  points and mention policy, and each channel's rules. Fetched text is
  quoted as untrusted. An over-long X draft gets one request to shorten.
- Drafts page: edit with a live length counter that counts like X, then
  publish each draft on its own. A draft is claimed before posting so it
  can't go out twice; failures are kept on the draft for a retry; X
  tokens are refreshed and saved.
- Migration 2 adds content_items and drafts, and turns queued posts into
  drafts for the platforms they hadn't reached.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 12:58:24 -07:00
co-authored by Claude Opus 5.5
parent abf410d097
commit 13bf18facc
29 changed files with 2484 additions and 95 deletions
+82
View File
@@ -0,0 +1,82 @@
{{define "content"}}{{with .Data}}
<nav class="tabs">
<a href="/content" aria-current="page">Sources</a>
<a href="/drafts">Drafts{{if .Drafts}} ({{.Drafts}}){{end}}</a>
</nav>
<div class="heading">
<h1>{{.Entry.Name}} <span class="badge {{.Entry.Relationship}}">{{.Entry.Relationship}}</span></h1>
<div class="buttons">
<form method="post" action="/content/{{.Entry.ID}}/fetch" data-busy="Fetching…">
<button type="submit" {{if not .Sources}}disabled{{end}}>Fetch new</button>
</form>
<a class="button secondary" href="/inventory/{{.Entry.ID}}">Edit entry</a>
</div>
</div>
<p class="lede">
{{if .Sources}}Reads {{join .Sources ", "}}.{{else}}This entry has no sources yet: add an X handle, hashtags, a YouTube channel or RSS feeds to it.{{end}}
Last fetched {{ago .LastChecked}}; the next fetch looks for posts since {{.Since.Local.Format "2 Jan 15:04"}}.
</p>
{{if .Fetched}}
<section class="card">
<p><strong>{{if .NewItems}}{{.NewItems}} new item{{if ne .NewItems 1}}s{{end}}.{{else}}Nothing new.{{end}}</strong></p>
{{if .Errors}}<p class="warn-text">Some sources failed; they'll be read from the same point next time:</p>
<ul>{{range .Errors}}<li>{{.}}</li>{{end}}</ul>{{end}}
{{if .Skipped}}<p class="muted">Skipped, for lack of credentials (<a href="/settings/credentials">add them</a>): {{join .Skipped "; "}}.</p>{{end}}
</section>
{{end}}
<nav class="tabs">
<a href="/content/{{.Entry.ID}}" {{if not .ShowDismissed}}aria-current="page"{{end}}>Items</a>
<a href="/content/{{.Entry.ID}}?dismissed=1" {{if .ShowDismissed}}aria-current="page"{{end}}>Dismissed</a>
</nav>
{{if .Items}}
<form method="post" action="/content/{{.Entry.ID}}/items" data-busy-on="write" data-busy="Writing drafts…">
{{if .ShowDismissed}}<input type="hidden" name="dismissed" value="1">{{end}}
<ul class="items">
{{range .Items}}
<li class="item{{if .Used}} used{{end}}">
<label class="check">
<input type="checkbox" name="item" value="{{.ID}}">
<span>
<span class="meta">{{.Source}} · {{if .AuthorHandle}}@{{.AuthorHandle}}{{else}}{{.Author}}{{end}} · {{.PublishedAt.Local.Format "2 Jan 15:04"}}{{if .Used}} · <em>drafted</em>{{end}}</span>
{{if .Title}}<strong>{{.Title}}</strong>{{end}}
<span class="body">{{truncate 400 .Body}}</span>
{{if .URL}}<a href="{{.URL}}" target="_blank" rel="noopener noreferrer">Open</a>{{end}}
</span>
</label>
</li>
{{end}}
</ul>
{{if .ShowDismissed}}
<div class="actions"><button type="submit" name="action" value="restore" class="secondary">Restore selected</button></div>
{{else}}
<section class="card">
<h2>Write drafts from the selected items</h2>
{{if not .ProfileSet}}<p class="warn-text">Fill in the <a href="/profile">company profile</a> first: drafts are written in its voice.</p>{{end}}
<fieldset class="choice">
<legend>Channels</legend>
{{range .Channels}}
<label class="check"><input type="checkbox" name="channel" value="{{.ID}}" {{if .Connected}}checked{{end}}> {{.Name}}{{if not .Connected}} <span class="muted">(not connected: you can draft, but not publish yet)</span>{{end}}</label>
{{end}}
</fieldset>
<fieldset class="choice">
<legend>Posts</legend>
<label class="check"><input type="radio" name="mode" value="one" checked> One post from all selected items</label>
<label class="check"><input type="radio" name="mode" value="each"> One post per item (up to 10)</label>
</fieldset>
<div class="actions">
<button type="submit" name="action" value="write" {{if not .ProfileSet}}disabled{{end}}>Write drafts</button>
<button type="submit" name="action" value="dismiss" class="secondary">Dismiss selected</button>
</div>
</section>
{{end}}
</form>
{{else}}
<section class="card empty">
<p>{{if .ShowDismissed}}Nothing dismissed.{{else}}No items yet. Fetch to see what {{.Entry.Name}} has been up to.{{end}}</p>
</section>
{{end}}
{{end}}{{end}}
+29
View File
@@ -0,0 +1,29 @@
{{define "content"}}{{with .Data}}
<nav class="tabs">
<a href="/content" aria-current="page">Sources</a>
<a href="/drafts">Drafts{{if .Drafts}} ({{.Drafts}}){{end}}</a>
</nav>
<h1>Content</h1>
<p class="lede">Pick an inventory entry to fetch its latest news, choose what to write about, and get a draft for each channel to review on the <a href="/drafts">Drafts</a> page.</p>
{{if .Rows}}
<table class="list">
<thead><tr><th>Entry</th><th>Relationship</th><th>Sources</th><th>Waiting</th><th>Last fetched</th></tr></thead>
<tbody>
{{range .Rows}}
<tr>
<td><a href="/content/{{.Entry.ID}}">{{.Entry.Name}}</a></td>
<td><span class="badge {{.Entry.Relationship}}">{{.Entry.Relationship}}</span></td>
<td>{{if .Sources}}{{join .Sources ", "}}{{else}}<span class="muted">none: <a href="/inventory/{{.Entry.ID}}">add some</a></span>{{end}}</td>
<td>{{if .Waiting}}{{.Waiting}}{{end}}</td>
<td>{{ago .LastChecked}}</td>
</tr>
{{end}}
</tbody>
</table>
{{else}}
<section class="card empty">
<p>Add the partners and competitors you post about to the <a href="/inventory">Inventory</a> first.</p>
</section>
{{end}}
{{end}}{{end}}
+2 -2
View File
@@ -23,7 +23,7 @@
<details class="card">
<summary>Imported from the old terminal app {{ago .ImportStatus.At}}</summary>
<ul>{{range .ImportStatus.Summary}}<li>{{.}}</li>{{end}}</ul>
{{if .QueuedPosts}}<p>{{.QueuedPosts}} queued posts are kept for the Content module (Phase 1).</p>{{end}}
{{if .QueuedPosts}}<p>Its queued posts are now drafts: <a href="/drafts">{{.QueuedPosts}} waiting for review</a>.</p>{{end}}
</details>
{{end}}
@@ -31,7 +31,7 @@
<div class="grid">
{{range .Modules}}
<section class="card module">
<h3>{{.Name}} <span class="badge">{{.Phase}}</span></h3>
<h3>{{if .Link}}<a href="{{.Link}}">{{.Name}}</a>{{else}}{{.Name}}{{end}} <span class="badge">{{.Phase}}</span></h3>
<p>{{.Body}}</p>
</section>
{{end}}
+63
View File
@@ -0,0 +1,63 @@
{{define "content"}}{{with .Data}}{{$conn := .Connected}}
<nav class="tabs">
<a href="/content">Sources</a>
<a href="/drafts" aria-current="page">Drafts</a>
</nav>
<h1>Drafts</h1>
<p class="lede">Each draft is for one channel, and is published on its own: if one channel fails, the other isn't posted twice. The source link is added when publishing.</p>
{{if .Batches}}
{{range .Batches}}
<section class="card batch">
<p class="meta">
{{if .InventoryName}}<strong>{{.InventoryName}}</strong> <span class="badge {{.Kind}}">{{.Kind}}</span> ·{{end}}
written {{ago .CreatedAt}}
{{if .SourceURL}} · <a href="{{.SourceURL}}" target="_blank" rel="noopener noreferrer">source</a>{{end}}
</p>
<div class="drafts">
{{range .Drafts}}
<div class="draft{{if eq .Status "failed"}} failed{{end}}">
<h3>{{.ChannelName}}</h3>
{{if .Error}}<p class="error">Last attempt failed: {{.Error}}</p>{{end}}
<form method="post" action="/drafts/{{.ID}}/save" data-busy-on="publish" data-busy="Publishing…">
<textarea name="content" rows="{{if eq .Channel "x"}}5{{else}}12{{end}}"
data-count="{{.Channel}}" data-limit="{{.Limit}}" data-reserve="{{if eq .Channel "x"}}{{xreserve .SourceURL}}{{else}}0{{end}}"
aria-describedby="count-{{.ID}}">{{.Content}}</textarea>
<p class="count{{if .TooLong}} over{{end}}" id="count-{{.ID}}">{{.Length}} / {{.Limit}}{{if and (eq .Channel "x") .SourceURL}} including the link{{end}}</p>
<div class="actions">
<button type="submit" name="action" value="publish" formaction="/drafts/{{.ID}}/publish"
{{if not (index $conn .Channel)}}disabled title="Sign in to {{.ChannelName}} under Settings → Credentials"{{end}}>Publish to {{.ChannelName}}</button>
<button type="submit" class="secondary">Save</button>
</div>
</form>
<form method="post" action="/drafts/{{.ID}}/discard" data-confirm="Discard this {{.ChannelName}} draft?">
<button type="submit" class="danger small">Discard</button>
</form>
</div>
{{end}}
</div>
</section>
{{end}}
{{else}}
<section class="card empty">
<p>No drafts waiting. Write some from the <a href="/content">Sources</a> page.</p>
</section>
{{end}}
{{if .Published}}
<h2>Recently published</h2>
<table class="list">
<thead><tr><th>When</th><th>Channel</th><th>Entry</th><th>Post</th></tr></thead>
<tbody>
{{range .Published}}
<tr>
<td>{{ago .PublishedAt}}</td>
<td>{{.ChannelName}}</td>
<td>{{.InventoryName}}</td>
<td>{{if .PostURL}}<a href="{{.PostURL}}" target="_blank" rel="noopener noreferrer">{{truncate 80 .Content}}</a>{{else}}{{truncate 80 .Content}}{{end}}</td>
</tr>
{{end}}
</tbody>
</table>
{{end}}
{{end}}{{end}}
+1
View File
@@ -15,6 +15,7 @@
<nav>
<a href="/" {{if eq .Nav "home"}}aria-current="page"{{end}}>Overview</a>
<a href="/profile" {{if eq .Nav "profile"}}aria-current="page"{{end}}>Profile</a>
<a href="/content" {{if eq .Nav "content"}}aria-current="page"{{end}}>Content</a>
<a href="/inventory" {{if eq .Nav "inventory"}}aria-current="page"{{end}}>Inventory</a>
<a href="/settings/ai" {{if eq .Nav "settings"}}aria-current="page"{{end}}>Settings</a>
<a href="/core" {{if eq .Nav "core"}}aria-current="page"{{end}}>Core &amp; Hermes</a>