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
+33
View File
@@ -0,0 +1,33 @@
package fileutil
import (
"os"
"path/filepath"
)
// WriteFileAtomic writes data to a temp file in the same directory and renames
// it over path, so a crash mid-write never leaves a truncated file behind.
func WriteFileAtomic(path string, data []byte, perm os.FileMode) error {
tmp, err := os.CreateTemp(filepath.Dir(path), "."+filepath.Base(path)+".tmp-*")
if err != nil {
return err
}
tmpName := tmp.Name()
defer os.Remove(tmpName) // no-op once the rename succeeds
if _, err := tmp.Write(data); err != nil {
tmp.Close()
return err
}
if err := tmp.Sync(); err != nil {
tmp.Close()
return err
}
if err := tmp.Close(); err != nil {
return err
}
if err := os.Chmod(tmpName, perm); err != nil {
return err
}
return os.Rename(tmpName, path)
}