Skip to content

feat: add herald post to post approved text to X verbatim - #14

Merged
abrichr merged 3 commits into
mainfrom
feat/verbatim-publish
Oct 14, 2026
Merged

abrichr merged 3 commits into
mainfrom
feat/verbatim-publish

Conversation

@abrichr

@abrichr abrichr commented Oct 10, 2026

Copy link
Copy Markdown
Member

herald post posts an approved text file to X exactly as written, with no model call. It never shortens or rewrites the text; if the text is too long, it refuses and says by how much. Each run ends in one of three results with its own exit code, so a publishing job knows whether the post exists. Existing commands are unchanged.

herald post --file approved.txt --platform x --ledger post-ledger.jsonl \
  --expect-sha256 <approved content_sha256> --precheck-timeline

What changes

Checks before anything is sent

  • --expect-sha256 ties the post to the approved text, so an edit after approval stops it. The hash covers the text without trailing newlines; --dry-run --json prints it as content_sha256.
  • The text must fit X's 280 weighted characters. A link counts as 23, and most CJK characters and emoji count as 2. A link without https:// counts as 23 or its full length, whichever is longer. Overlength text is refused, never cut.
  • An append-only JSON Lines ledger, keyed by the text's SHA-256, must not show the text as already posted.

Results and exit codes

Result Exit code Meaning
published 0 The post is on X. X returned its id, or Herald found it on the account.
not_sent 3 Herald didn't post. The request never left the machine, X refused it (4xx), the input was refused, or a check after an earlier uncertain attempt found no match.
uncertain 4 A request may have reached X (5xx, read timeout, reset connection, duplicate-content refusal, or 2xx without an id). A post may exist.

Herald also reports uncertain, without sending, when it can't read the ledger or can't open the account after an earlier uncertain attempt, because an earlier post can't be ruled out.

No blind retry

  • Herald writes an uncertain ledger record before each request, so a crash or cancelled job leaves a record the next run checks.
  • After an uncertain result, the next run reads the account's 20 most recent posts first. A match is recorded as published, and nothing is sent.
  • With no match and less than 2 minutes since the attempt, the result stays uncertain. After that, posting again requires --retry, which reads the recent posts once more and sends nothing if the read fails.

Other behavior

  • --precheck-timeline skips the post if the text is among the 20 most recent posts (covers a lost ledger).
  • --dry-run or HERALD_DRY_RUN=true runs only the local checks and never opens the X account.
  • X requests time out after 30 seconds.
  • --ledger or HERALD_POST_LEDGER (environment or .env) sets the ledger path, which a live post requires.
  • --platform linkedin exits with not_sent and asks you to paste the text yourself, because LinkedIn's API Terms of Use (section 3.1) don't allow automated posting.

Known limits

  • There's no cross-process lock, so run one herald post at a time per ledger. A GitHub Actions concurrency group is enough.
  • Emoji joined with a zero-width joiner or a skin-tone modifier count longer than X counts them, so some valid posts are refused.

How it was tested

  • pytest -q: 131 passed, including 56 in tests/test_verbatim.py, which fake the X account and make no network calls.
  • ruff check .: all checks passed.
  • uv build: the sdist and wheel build.
  • The CLI, run offline: a dry run, 281-character text, --platform linkedin, and a missing ledger each return not_sent (exit 3). A corrupt ledger returns uncertain (exit 4). HERALD_DRY_RUN=true with credentials set never opens the account.

Before merging

Merging doesn't post anything. Items 1 to 4 are needed before the first live post.

  1. Create an X developer app on a pay-per-use plan with a spending limit. Reading recent posts and creating a post are both paid calls.
  2. Set the four HERALD_TWITTER_* settings (OAuth 1.0a user tokens for the company account) where the publishing job runs.
  3. Before posting LLM-drafted text through the API, file X's request for approval of AI-generated content, as its developer guidelines require.
  4. Keep the ledger somewhere that outlasts a CI job. A GitHub-hosted runner's disk is wiped after each job.
  5. After this merges, point the internal publishing workflow's HERALD_REF at the merge commit.
  6. Not blocking: decide whether to remove or gate herald publish's LinkedIn posting (/v2/ugcPosts, which may conflict with the same terms) and its 280-character cut for X. This PR leaves both as they are.

🤖 Generated with Claude Code

abrichr and others added 3 commits October 8, 2026 23:00
Adds a publish path that posts an approved file exactly as written: no
model call, no truncation, no rewriting.

- X weighted length check (twitter-text v3 weights, every link counts 23);
  overlength text is refused, never cut.
- --expect-sha256 binds the post to the approved text hash.
- Three results with exit codes: published (0), not_sent (3), uncertain (4).
  4xx and connect failures are not_sent; 5xx, read timeouts, resets,
  duplicate-content refusals and 2xx-without-id are uncertain.
- Append-only JSON Lines ledger keyed by content hash. A write-ahead
  "uncertain" record precedes every request, so a killed job is reconciled.
- After an uncertain attempt the next run reads the account's own recent
  posts first; a match is recorded as published, an absence needs --retry.
- --precheck-timeline skips posting when the text is already on the
  timeline (covers a lost ledger).
- tweepy requests get a timeout; dry run never opens the account.
- LinkedIn stays manual copy-paste per its API terms (exit not_sent).

The existing LLM collect/compose/publish commands are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review fixes for the verbatim `herald post` path.

- Length: a bare domain (no http/https) now counts as 23 or its own
  length, whichever is longer. A long dotted word that X leaves as plain
  text used to count as 23, so the check could pass text X would refuse.
  An overlength refusal caused by such a word says to add https://.
- Dry run after an uncertain attempt now reports `uncertain` (exit 4)
  instead of `not_sent`, because an earlier request may have posted.
  A dry run after a reconciled check says a live run needs --retry.
- A --retry run reads the account's recent posts again before sending,
  so a slow earlier post that appears after the first check is not
  posted twice. If that read fails, nothing is sent.
- Reconciliation accepts any matching recent post, including one older
  than the attempt. This ends the loop where X refused duplicate text,
  the check filtered the older post out, and --retry hit the same refusal.
- Messages in uncertain states say "This run sent nothing; the earlier
  attempt may still have posted" instead of "Nothing was sent".
- Ledger write failures during a timeline check return a result instead
  of a traceback; a failed reconciliation record stays `uncertain`.
- HERALD_POST_LEDGER now works from .env (it was only read from the
  process environment), matching .env.example.
- --expect-sha256 ignores case and surrounding whitespace. The README
  and the mismatch message explain that the hash covers the text without
  trailing newlines and how to print it with --dry-run --json.
- README: result table covers found-on-account and reconciled cases,
  the 2-minute wait, the retry re-read, and ledger durability. --retry
  help no longer says the check "proved" anything.

Each fix has a regression test that fails on the previous commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review fixes for `herald post`.

- HERALD_DRY_RUN=true now keeps `herald post` preview-only, as it already
  did for `herald publish`. Before, a live post went out with the setting on.
- An unreadable ledger reports `uncertain` (exit 4), not `not_sent`. A
  full disk can cut the "published" record short right after X accepted
  the post, so a broken ledger can't rule out an earlier post.
- If the X account can't be opened (for example, missing credentials)
  after an earlier `uncertain` attempt, the result stays `uncertain`.
- The message after a successful post with a failed ledger write no
  longer promises what the next run will do; it asks for a ledger check.
- Docs no longer claim the length count is never shorter than X's: an
  explicit link always counts as 23, and if X counts more and refuses,
  the result is `not_sent`. The test for long explicit links uses a real
  TLD.
- README: one run per ledger at a time, HERALD_DRY_RUN, the extra
  `uncertain` cases, and a link to LinkedIn's API terms (section 3.1).

Each behavior fix has a regression test that fails on the previous commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@abrichr
abrichr merged commit 485b0fa into main Oct 14, 2026
3 checks passed
@abrichr
abrichr deleted the feat/verbatim-publish branch October 14, 2026 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant