README.md
# Social Publisher (AgentRove native agent)
`agentrove.social-publisher` 0.1.2 · MIT · Node.js >= 20 · no npm dependencies
Published by AgentRove (provisional, configurable name). Package identifiers keep the agentrove prefix for compatibility.
Prepares social posts. **It does not post by default.** You get platform-specific drafts, a
deduplicated approval queue you keep as a JSON file, and a `publish` tool that sends one approved
item through the platform's official API with your own OAuth token, only after explicit confirmation.
There are no tools to follow, like, comment, message, scrape or create accounts, and none will be added.
## Tools
| Tool | Side effects | What it does |
| --- | --- | --- |
| `draft_posts` | none | From a `brief` (text) or a `script` (`types.json` script), builds one draft per platform: X (280, twitter-text weighting: URLs count 23, CJK and emoji count 2), LinkedIn (3000), Instagram (2200), TikTok (2200), YouTube (title 100 characters, description 5000 **bytes**, no `<`/`>`), Facebook (5000, a conservative AgentRove limit). Normalises and de-duplicates hashtags, caps them per platform, tags the link with `utm_source=<platform>`, `utm_medium=social`, `utm_campaign=...`, and, when the text is too long (usually on X), builds the draft from whole points instead: script body segments ranked by how many sources support them (from the script's claims or an "According to a and b:" prefix; the lead point's source URL is added when no link is given), or brief paragraphs in order, with announcing sentences such as "Here are 5 points." removed, so the post never promises content that was cut (`truncated: false`). Only if even one point is too long is it shortened: at the end of a complete sentence if that keeps at least half of the room, otherwise at a word boundary with an ellipsis (`truncated: true`). Instagram/TikTok captions do not get the link (it is not clickable there); it is returned separately, and a call to action that mentions a link gets a warning for those drafts. |
| `schedule_queue` | none | Turns drafts into an approval queue: content hash per account (whitespace-insensitive), de-duplication against an existing queue file, refusal of identical X posts across accounts (X automation rules; compared on the visible text, ignoring case, spacing and link metadata), explicit `publish_at` times or auto-placement into local `slots` in an IANA time zone (DST-correct), at most `max_per_account_per_day` (default 3) and `min_gap_minutes` (default 60). Every new item is `pending_approval` with `approved: false`. |
| `publish` | external_write | Publishes one item with `approved: true`, and only when the input has `"confirm": true`. Adapters: X API v2 `POST https://api.x.com/2/tweets`; LinkedIn Posts API `POST https://api.linkedin.com/rest/posts` (commentary escaped in LinkedIn's "little text" format, `#tags` become hashtag templates); Facebook Graph `POST https://graph.facebook.com/{version}/{page-id}/feed`; YouTube Data API `videos.insert` resumable upload **session** with metadata only (`private` by default). |
### Idempotency, retries and de-duplication
- `idempotency_key` = SHA-256 of platform, account and content hash (first 32 hex chars). The same
content for the same account always gets the same key. Keep a log of published keys and pass it as
`published_keys`: matching items return `already_published` without any request.
- X duplicate-content rejections (HTTP 403 "duplicate content") are reported as `already_published`.
Other HTTP 401/403 responses are `auth_error` and include the platform's own reason (for example
X's `client-not-enrolled` when your developer plan or app has no write access), never the token.
- HTTP 429 is retried at most twice, honouring `Retry-After` / `x-rate-limit-reset` up to
`max_rate_limit_wait_seconds` (default 10). HTTP 5xx, timeouts and network errors are **not**
retried, because the post may exist; the error says to check the account first.
- Items scheduled more than 5 minutes in the future are refused (`not_due`) unless `publish_now: true`.
This agent has no background scheduler: run `publish` yourself at the scheduled time.
## Usage (Node CLI)
```sh
node bin/cli.js --help
node bin/cli.js draft_posts --input brief.json # {"brief": "...", "link": "https://...", "utm": {"campaign": "launch"}, "hashtags": ["notes"]}
node bin/cli.js schedule_queue --input drafts.json # {"timezone": "Europe/London", "posts": [...], "slots": {"start_date": "2026-12-01", "times": ["09:00"]}}
# Review queue.json, set "approved": true on the items you approve, then for one item:
X_USER_ACCESS_TOKEN=... node bin/cli.js publish --input item.json # {"item": {...queue item...}, "confirm": true}
```
On Windows PowerShell, prefer `--input file.json` (or `--input -` with piped JSON) over `--json`.
### Credentials (your own accounts only)
| Platform | Environment variable | What it must be |
| --- | --- | --- |
| X | `X_USER_ACCESS_TOKEN` | OAuth 2.0 user-context access token with `tweet.write` (and `tweet.read`, `users.read`). X API write access depends on your X developer plan and may be paid. |
| LinkedIn | `LINKEDIN_ACCESS_TOKEN` | Member token with `w_member_social` (or `w_organization_social` for a page). `item.account` is the author URN. `LinkedIn-Version` defaults to `202610`; LinkedIn retires versions after about a year, so pass `linkedin_version` if you get HTTP 426. |
| Facebook | `FACEBOOK_PAGE_ACCESS_TOKEN` | Page access token with `pages_manage_posts`. `item.account` is the numeric Page id. Graph API version defaults to `v23.0` (`graph_api_version`). |
| YouTube | `YOUTUBE_ACCESS_TOKEN` | OAuth token with `https://www.googleapis.com/auth/youtube.upload`. |
This agent runs no OAuth flow and refreshes no tokens. Copy `.env.example` for the variable names.
### YouTube: metadata only
`publish` for YouTube calls `videos.insert` with `uploadType=resumable` and returns `upload_url`.
No video exists until you upload the bytes yourself, for example:
```sh
curl -X PUT --upload-file video.mp4 -H "Content-Type: video/mp4" "<upload_url>"
```
Treat `upload_url` like a password. Videos uploaded through unverified API projects (created after
28 July 2020) are restricted to private viewing until the project passes Google's audit.
`made_for_kids` is required because YouTube needs your own declaration.
## Use as an MCP server
```sh
claude mcp add social-publisher -- node /absolute/path/to/social-publisher/bin/mcp.js
```
Leave the tokens out of the MCP config unless you intend to publish. Over MCP the calling model sets
`confirm`, so keep your client's per-tool approval prompt on for `publish`. `claude-code/SKILL.md`
is a Claude Code skill that drives the CLI with the same rules.
## Testing status
Tested with Node.js (Vitest, `tests/social-publisher.test.ts`, fixtures and an injected fake `fetch`
only; no real platform was called). It has **not yet been verified inside Claude Code** or any other
MCP client by AgentRove, and the adapters have not been exercised against the live platform APIs by
AgentRove. Platform APIs, limits and versions change; check them before relying on this.
## Limitations
- X length follows the twitter-text v3 weighting rules approximately (URLs detected only with
`http(s)://`; some emoji sequences may count differently). LinkedIn, Instagram, TikTok and Facebook
lengths are counted in Unicode code points.
- Hashtag caps are conservative defaults (Instagram 5 by default, hard cap 30; YouTube hard cap 15).
Platforms change these rules.
- No Instagram or TikTok publishing adapter (they need professional accounts, hosted media and app
review); drafts and queue items for them are for posting yourself.
- No media upload except the YouTube session URL; no images, threads, polls, scheduling on the
platform side, or post deletion.
- `draft_posts` only reformats your text. It does not write new claims, check facts or check rights.
- Default API versions (`LinkedIn-Version` 202610, Graph API v23.0) are configurable and were not
checked against the live APIs by AgentRove; platforms retire versions on their own schedules.
- The returned post `url` values (x.com, linkedin.com, facebook.com) are display links only; the
agent never requests them.