- name
- reply-maker
- description
- Draft copy-paste-ready X replies - two options per reply-worthy tweet from tracked accounts, topics, or lists (default), or ready-to-post responses to engagement opps in recent logs (from-logs)
- metadata
- {"title":"Reply Maker","category":"productivity","var":"empty = auto-discover reply-worthy tweets and draft two options each; @handle / numeric X list ID / topic = scope the drafting to that; from-logs (or --from-logs [@handle|project]) = turn flagged engagement opps from recent logs into ready-to-post replies","commits":false,"tags":["social","meta"],"requires":["XAI_API_KEY?"]}
<!-- autoresearch: variation B — sharper output via specificity gates, anti-sycophancy lint, post-write self-edit, and skip-gate for low-leverage tweets -->
> **${var}** — selects the mode and scope:
> - **empty** → **Mode A (Reply Drafting):** auto-discover reply-worthy tweets across your areas of interest (from recent logs + memory) and draft two reply options for each.
> - **`@handle` / numeric X list ID / topic** → **Mode A (Reply Drafting)** scoped to that handle, list, or topic.
> - **`from-logs`** (or **`--from-logs`**, optionally followed by an `@handle` or project name to narrow the scan) → **Mode B (From-Logs Engagement):** scan recent logs for flagged engagement opportunities and turn them into copy-paste-ready responses.
> - **`revise:<instruction>`** → **Revise branch:** reload the last drafted replies and refine them per the instruction (the Telegram force-reply shape, e.g. `revise:make them shorter`).
## Preamble (both modes)
Read `memory/MEMORY.md` for context on active projects and open engagement follow-ups.
Then read `memory/logs/` — the window depends on the mode:
- **Mode A:** the last 2 days of `memory/logs/` for recent `list-digest`, `tweet-roundup`, and prior `reply-maker` outputs (used as a candidate pool and for reply de-duplication).
- **Mode B:** the last 7 days of `memory/logs/` for engagement opportunities flagged by other skills (`project-pulse`, `refresh-x`, `reply-maker`, `channel-recap`) or noted in MEMORY.md "Known Follow-ups".
**Parse `${var}` to pick the branch** (trim whitespace, compare case-insensitively):
- If `${var}` starts with `revise:` — run the **Revise branch** (below) and stop. This is the shape `scripts/telegram-route.sh` sends when the operator replies to a "refine these replies?" force-reply prompt; catch it before mode parsing.
- If `${var}` is `from-logs` or `--from-logs` — optionally followed by a whitespace-separated `@handle` or project name — run **Mode B (From-Logs Engagement)**. Treat any trailing token as an optional filter that narrows the opportunity scan to that handle/project.
- Otherwise run **Mode A (Reply Drafting)**, treating `${var}` as the scope: empty, `@handle`, numeric X list ID, or a topic string.
## Voice
If soul files exist (`soul/SOUL.md`, `soul/STYLE.md`, `soul/examples/`), read them and **mirror that voice in every reply**. Match sentence length, vocabulary choices, punctuation habits, and the kinds of things the operator would never say.
If no soul files exist (or the bodies are empty placeholders), write replies that are:
- Direct and substantive — no fluff, no sycophancy
- Under 280 characters each (X replies; DMs and GitHub comments may run longer — see Mode B)
- Opinionated but grounded in specifics
- The kind of reply that adds to the conversation, not noise
Either way, when responding to someone who cosigned/mentioned/attributed the operator (Mode B): **acknowledge without groveling** — no "thanks so much for the kind words!", just the actual response.
---
# Revise branch (`revise:…` — Telegram force-reply)
The operator tapped the "refine these replies?" prompt and sent a free-text revision instruction. Handle it before Mode A/B:
1. **Strip the prefix.** The instruction is `${var#revise:}` (keep any inner colons). Trim whitespace — e.g. `make them shorter`, `less formal`, `drop reply B on #2`.
2. **Load the last draft.** Read `memory/drafts/reply-maker-latest.md` — the stable path every normal run saves to (see the save steps in A4 / B6). If it's missing or empty, there's nothing to refine: send `./notify "Nothing to revise yet — run reply-maker first, then reply here to refine the drafts."` and **end the run**.
3. **Apply the instruction.** Read `soul/` for voice, then regenerate the saved replies applying the operator's instruction. Keep the same set of target tweets and the same **A/B two-option** structure (Mode A) or ready-to-post list (Mode B) — you're refining wording, not re-discovering candidates. Re-enforce the hard reply rules: ≤280 chars for X replies, no sycophancy (see **Banned sycophancy phrases**), specifics not gestures.
4. **Re-save** the revised drafts to `memory/drafts/reply-maker-latest.md` (overwrite), so a further `revise:` refines the newest version.
5. **Re-send** via `./notify` in the same format the originating mode uses, with a first line flagging it as a revision, e.g. `revised (${var#revise:}):`. Use `./notify -f <file>` for multi-line output.
6. **Re-offer** a further revision (the operator is actively iterating, so this is expected, not a nag — skip the daily dedup guard here):
```bash
./notify "Want another pass? Reply with a change and I'll revise again." \
--force-reply --placeholder "e.g. make them shorter" \
--context "reply-maker::revise"
```
7. **Log** under `### reply-maker` with `- **Mode:** revise` and the instruction (see **Log**), then **end the run** — do NOT run Mode A or B.
---
# Mode A — Reply Drafting
Generate **two reply options** for **5 reply-worthy tweets** from tracked X accounts, a list, or a topic.
### A1. Gather candidate tweets
Goal: assemble **10–15 candidates** posted in the **last 6 hours** (the high-leverage reply window — the algorithm rewards early replies, and the OP is still likely to engage back). **Recency fallback:** if the 6h window yields fewer than 3 candidates after the skip gate, widen to **12h** and retry before failing the run.
For every candidate, capture: `@handle`, full tweet text, tweet URL, `posted_at` (ISO), engagement counts (likes, replies, retweets if available), and a one-line **why-this-tweet** note.
**Path A — X.AI API (primary).** `XAI_API_KEY` is injected into this skill's environment (declared in `requires:`), so the direct `curl` to `https://api.x.ai/v1/responses` is the primary fetch path (full contract in **Fetching** at the bottom). Preflight the key, then call Grok's `x_search`, capturing the HTTP status so any fallback decision is fact-based. `x_search` searches X live and takes 30–120s — **set the Bash tool `timeout` to ≥180000 when you run this** (a slow curl is not a missing key).
```bash
[ -n "$XAI_API_KEY" ] && echo KEY_PRESENT || echo KEY_UNSET
TO_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
FROM_DATE=$(date -u -d "6 hours ago" +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -v-6H +%Y-%m-%dT%H:%M:%SZ)
```
If `KEY_PRESENT` (it will be), Path A is required. Build the payload **file** `/tmp/xai-rm-payload.json` per `${var}` (three shapes below — each branch writes the same fixed file), then:
```bash
HTTP=$(./secretcurl -s -o /tmp/xai-rm.json -w '%{http_code}' --max-time 150 -X POST "https://api.x.ai/v1/responses" \
-H "Content-Type: application/json" -H "Authorization: Bearer {XAI_API_KEY}" -d @/tmp/xai-rm-payload.json)
echo "xai http=$HTTP bytes=$(wc -c </tmp/xai-rm.json)"
```
On `HTTP=200` with a non-empty body, parse `/tmp/xai-rm.json` and mark `xai=ok`:
```bash
jq -r '.output[] | select(.type == "message") | .content[] | select(.type == "output_text") | .text' /tmp/xai-rm.json
```
**The payload file `/tmp/xai-rm-payload.json` depends on `${var}`.** Whichever branch matches, build it with `jq -n --arg` (never a shell-interpolated string) and write it to that one fixed path — the `./secretcurl` call above then sends it with `-d @/tmp/xai-rm-payload.json`:
**If `${var}` looks like an X list ID** (numeric):
```bash
LIST_ID="${var}"
jq -n --arg list_id "$LIST_ID" --arg from "$FROM_DATE" --arg to "$TO_DATE" '{
model: "grok-4.6",
input: [{role: "user", content: ("Look at X list https://x.com/i/lists/" + $list_id + ". Return the 12 most reply-worthy original posts (not retweets, not replies) by members of this list between " + $from + " and " + $to + ". Reply-worthy = has a take, claim, question, or framing worth engaging — NOT pure self-promo, breaking news without analysis, or threads already past 500 replies. For each: @handle, full tweet text, tweet URL, posted_at ISO timestamp, like/reply/retweet counts.")}],
tools: [{type: "x_search", from_date: $from, to_date: $to}]
}' > /tmp/xai-rm-payload.json
```
**If `${var}` looks like a `@handle`** — same query intent, scoped to that handle's recent original posts:
```bash
HANDLE="${var}"
jq -n --arg handle "$HANDLE" --arg from "$FROM_DATE" --arg to "$TO_DATE" '{
model: "grok-4.6",
input: [{role: "user", content: ("Look at recent original posts (not retweets, not replies) by " + $handle + " on X between " + $from + " and " + $to + ". Return the 12 most reply-worthy. Reply-worthy = has a take, claim, question, or framing worth engaging — NOT pure self-promo, breaking news without analysis, or threads already past 500 replies. For each: @handle, full tweet text, tweet URL, posted_at ISO timestamp, like/reply/retweet counts.")}],
tools: [{type: "x_search", from_date: $from, to_date: $to}]
}' > /tmp/xai-rm-payload.json
```
**If `${var}` is a topic** (or empty) — same query intent with `${var}` (or the top 2–3 topics from `memory/MEMORY.md` when empty) as the search query. When empty, also pull tweet candidates surfaced in the last 2 days of `tweet-roundup` and `list-digest` logs as a backup pool.
```bash
TOPIC="${var}" # when empty, substitute the top 2–3 topics from memory/MEMORY.md
jq -n --arg topic "$TOPIC" --arg from "$FROM_DATE" --arg to "$TO_DATE" '{
model: "grok-4.6",
input: [{role: "user", content: ("Search X for the 12 most reply-worthy original posts (not retweets, not replies) about " + $topic + " between " + $from + " and " + $to + ". Reply-worthy = has a take, claim, question, or framing worth engaging — NOT pure self-promo, breaking news without analysis, or threads already past 500 replies. For each: @handle, full tweet text, tweet URL, posted_at ISO timestamp, like/reply/retweet counts.")}],
tools: [{type: "x_search", from_date: $from, to_date: $to}]
}' > /tmp/xai-rm-payload.json
```
**Path B — memory logs + WebSearch (last-resort fallback only).** Reach here **only** on a real Path A failure, and record the **true reason** — `key-unset` | `http-<code>` | `empty` | `timeout` — never "XAI_API_KEY unavailable" when the key was set. Use in order until you have ≥3 candidates:
1. Recent `list-digest` + `tweet-roundup` outputs in `memory/logs/` — already have URLs and handles.
2. WebSearch for very recent posts on memory topics (filter: posted within last 6h, original post not reply). Lower quality — WebSearch favours older high-engagement tweets, so prioritise results dated within the last 6h.
### A2. Filter and select 5 tweets
Apply the **skip gate** first. **Discard** any candidate that is:
- Pure self-promo (launching a product, "buy my course", subscribe links)
- Breaking-news repost without an angle of its own
- A thread already past ~500 replies (your reply will not be seen)
- Older than 6 hours (reply window has closed; don't waste a reply slot)
- A handle/URL already replied to in the last 7 days of reply-maker logs (no duplicates)
From the survivors, **rank by leverage** = `recency × take-strength × room-to-add`:
- **Recency**: minutes-ago > hours-ago. Tweets <60min old are top priority.
- **Take-strength**: a clear claim/question/framing you can either reinforce with evidence or challenge with a flipped premise.
- **Room-to-add**: not already swarmed; thread isn't full of stronger replies; you have actual context to contribute.
- Bias toward authors whose audience overlaps your interests (from `memory/MEMORY.md`) — replies on those accounts get seen by people who care about the same things.
Pick the **top 5**. If fewer than 5 survive the gate, output what you have and add `REPLY_MAKER_DEGRADED` to the notification subject line.
### A3. Generate two replies per tweet
For each of the 5 selected tweets, draft **two reply options** with distinct angles:
**Option A — "Evidence add"**
- Builds on their point with a **specific** datum, named project, named person, concrete number, link, or counterexample they didn't include
- Tone: collaborative, substantive, calmly confident
- Must contain at least one named entity, number, or specific reference — vague "great insight, here's another angle" is banned
**Option B — "Frame challenge"**
- States the premise you're pushing back on **explicitly** (one short clause), then offers the contrarian angle, flipped framing, or sharper read
- Tone: direct, opinionated, not contrarian-for-its-own-sake
- Must contain the actual disagreement, not a hedge — vague "interesting, but have you considered..." is banned
#### Hard reply rules (apply to both A and B)
- **≤ 280 characters** including any handle prefix
- **No sycophancy** — see the `## Banned sycophancy phrases` section below. Any draft containing a banned phrase must be rewritten.
- **No hedging stacks** — "It could be argued that…", "Just my two cents but…", "Maybe I'm wrong but…" — pick a position
- **Specifics, not gestures** — names, projects, numbers, links. If you can't cite one, don't write the reply
- **Stand alone** — readers may not see the original tweet; reply must make sense on its own
- **Match soul voice** if soul files are populated
#### Self-edit pass (do this for every reply before finalizing)
For each draft reply, score 1–5 on each:
- **Specific**: cites a name/number/project/claim?
- **Standalone**: makes sense without reading the parent?
- **Non-sycophantic**: passes the banned-phrase list?
- **Voice-matched**: sounds like the soul files (or neutral-direct if no soul)?
If any score is < 4, **rewrite that reply once** before moving on. If the rewrite still scores < 4, drop that tweet from the list and pull the next-ranked candidate from step A2.
### A4. Notify
Send via `./notify` with this format (link first so the operator can open the source quickly):
```
*Reply Maker — ${today}*
*1.* https://x.com/handle/status/123 (@handle, 42m ago, 18💬)
> [first ~80 chars of tweet]…
why: [one-line reason this is reply-worthy]
A: [evidence-add reply]
B: [frame-challenge reply]
GitHubで見る