Stop committing credentials; fix posting length, partial posts, and data safety

- Untrack config.yaml (now gitignored) and add config.example.yaml with
  blank credentials; install.sh copies the example and sets mode 600
- Reserve room for the appended source link when asking Claude for a
  post, count length the way X does, and refuse over-length tweets
  before posting
- Return https://x.com/i/status/<id> for posted tweets
- Track which platforms each queued post reached so a partial failure
  can be retried without double-posting
- Write config, state, posts and dismissed files atomically with 0600
- Keep refreshed Twitter tokens in memory if saving them fails, and log
  the failure instead of writing to the hidden stderr
- Exit with a clear message on corrupt data files instead of panicking
- Surface save errors in the UI; show status/error messages on home
- Add tests for X length counting, the post store, and token updates

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 06:14:40 -07:00
co-authored by Claude Opus 5.5
parent c48ee22f99
commit 4d304cd65b
18 changed files with 391 additions and 96 deletions
+16 -16
View File
@@ -32,27 +32,27 @@ Your posts should:
Output ONLY the post text. No explanations, no alternatives — just the post.`
type Client struct {
client *anthropic.Client
model string
maxLength int
logFile string
client *anthropic.Client
model string
logFile string
}
func New(apiKey, model, stateDir string, maxLength int) *Client {
func New(apiKey, model, stateDir string) *Client {
c := anthropic.NewClient(option.WithAPIKey(apiKey))
return &Client{
client: c,
model: model,
maxLength: maxLength,
logFile: stateDir + "/coremarketing.log",
client: c,
model: model,
logFile: stateDir + "/coremarketing.log",
}
}
// GeneratePost creates a post in the voice of a product manager based on selected content.
func (c *Client) GeneratePost(ctx context.Context, app *models.Application, items []models.ContentItem) (string, error) {
// GeneratePost creates a post in the voice of a product manager based on
// selected content. maxLength is the space available for the post text itself,
// excluding anything appended at posting time (such as the source URL).
func (c *Client) GeneratePost(ctx context.Context, app *models.Application, items []models.ContentItem, maxLength int) (string, error) {
// Combine system instructions with the user prompt in a single user message.
// This avoids SDK version ambiguity around the System parameter content block type.
fullPrompt := systemPrompt + "\n\n---\n\n" + c.buildUserPrompt(app, items)
fullPrompt := systemPrompt + "\n\n---\n\n" + c.buildUserPrompt(app, items, maxLength)
msg, err := c.client.Messages.New(ctx, anthropic.MessageNewParams{
Model: anthropic.F(c.model),
@@ -76,11 +76,11 @@ func (c *Client) GeneratePost(ctx context.Context, app *models.Application, item
return "", fmt.Errorf("no text content in claude response (stop_reason=%s)", msg.StopReason)
}
func (c *Client) buildUserPrompt(app *models.Application, items []models.ContentItem) string {
func (c *Client) buildUserPrompt(app *models.Application, items []models.ContentItem, maxLength int) string {
var sb strings.Builder
sb.WriteString(fmt.Sprintf("Application: %s\n", app.Name))
sb.WriteString(fmt.Sprintf("Description: %s\n\n", app.Description))
sb.WriteString(fmt.Sprintf("Character limit: %d\n\n", c.maxLength))
sb.WriteString(fmt.Sprintf("Character limit: %d\n\n", maxLength))
sb.WriteString("Selected content from social media and community:\n\n")
for i, item := range items {
@@ -96,14 +96,14 @@ func (c *Client) buildUserPrompt(app *models.Application, items []models.Content
sb.WriteString(fmt.Sprintf(
"Based on this content, write ONE X.com post (max %d characters including hashtags) in the voice of a product manager helping users better use %s.",
c.maxLength, app.Name,
maxLength, app.Name,
))
return sb.String()
}
func (c *Client) log(format string, args ...any) {
f, err := os.OpenFile(c.logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
f, err := os.OpenFile(c.logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return
}