# trivia-refiner

Adopt this skill: https://proskills.md/skills/other/yinon-alfred-openclaw-trivia-refiner-trivia-refiner

Page: https://proskills.md/skills/other/yinon-alfred-openclaw-trivia-refiner-trivia-refiner
This document is the public skill bundle for that page. It contains SKILL.md and every helper file the catalog carries. No login is required.

## File: trivia-refiner/SKILL.md
size: 8115
upstream: https://github.com/yinon-alfred-openclaw/trivia-refiner/blob/main/trivia-refiner/SKILL.md

````text
---
name: trivia-refiner
description: "Refine Hebrew or English trivia questions with a config-driven semi-auto workflow, guarded consensus submission, and explicit held-question review."
---

# Trivia Refiner — Semi-Auto Review Workflow

**🎯 DATABASE: Quiz Supabase (`uhfsfedwteeoxsvixvtr`)**

This skill refines Hebrew and English trivia questions with guarded automation. Yinon has approved semi-auto mode: clean high-confidence questions may be submitted automatically, while risky questions must be held for review.

Language selection is explicit and config-driven. Do not rely on session memory to choose the language:

```bash
python3 scripts/run_batch.py --lang he
python3 scripts/run_batch.py --lang en
python3 scripts/submit_changes.py changes.json --lang he
python3 scripts/submit_changes.py changes.json --lang en
```

Configs:
- `config/he.json`: `raw_questions_he` -> `questions_he`, tracking `memory/trivia-refiner-processed.json`, artifacts `memory/trivia-consensus/he`
- `config/en.json`: `questions_raw_en` -> `questions_en`, tracking `memory/trivia-refiner-en-processed.json`, artifacts `memory/trivia-consensus/en`

Compatibility:
- Hebrew cron wrapper calls `run_batch.py --lang he`
- English cron wrapper calls `run_batch.py --lang en`
- The old English skill wrapper delegates to this unified runner with `--lang en`

**Current mode:** Auto-submit only clean questions with score **7+**. Send all flagged, reconstructed, fragile, or score ≤6 questions to Yinon before any DB write for those held items.

---

## The Workflow

### Stage 1: FETCH (Automatic via cron)

```bash
0 12 * * 0-5 python3 scripts/fetch_batch.py
```

**What happens:**
- Fetches next 10 unprocessed questions from Quiz DB
- Shows raw questions
- Asks: "Ready to rephrase? Reply: REPHRASE X-Y"
- **STOPS and waits**

**What it does NOT do:**
- No processing
- No database changes
- No assumptions

---

### Stage 2: REPHRASE + SEMI-AUTO UPDATE

When you reply `REPHRASE X-Y`:

1. **I pre-fact-check every raw question before rephrasing**
   - Validate the question premise, correct answer, all options, and ambiguity/currentness risk
   - Use internal knowledge for simple stable facts; use web verification when the fact is uncertain, disputed, current/time-sensitive, superlative-based, nickname-based, percentage/date-based, or otherwise suspicious
   - Classify the fact-check as `passed`, `web_verified`, `valid_with_rewording`, `uncertain`, or `failed`
2. **I rephrase** the questions (improve Hebrew phrasing, clarity) using the verified fact-check result
3. **I review options** (replace overly specific ones with plausible alternatives, and ensure no distractor is also correct)
4. **I assign categories & difficulty** (best match from available categories)
5. **I add a self-score (1-10)** for each refined question
6. **I include the fact-check data in the shared review artifact** so Alfred/main review can audit the premise, answer, options, notes, and sources
7. **I classify each question** as AUTO-SUBMIT or HOLD FOR REVIEW
8. **I auto-submit only clean AUTO-SUBMIT questions** with the `update_question` RPC/submit script
9. **I send Yinon only the held questions** plus a daily summary of how many were updated and how many need review
10. **Held questions are updated only after explicit approval/fixes**

**Critical:** Semi-auto approval applies only to clean high-confidence questions. Anything risky is still approval-first.

### Auto-submit eligibility

Auto-submit a question only when **all** are true:
- Final score is **7+** and Alfred/main agrees with the exact proposed final version
- No 🚩 warning
- No ⚠️ low-score line
- Not reconstructed from damaged/missing source text
- Not a fragile “כל התשובות נכונות” / “אף תשובה אינה נכונה” logic question
- No factual uncertainty, ambiguity, disputed wording, or outdated-fact risk
- Fact-check is visible in the batch artifact and is `passed` or `web_verified` with clean premise, correct answer, and option validation
- Correct answer is preserved and the option set is safe
- Alfred/main is a reviewer only. Do not ask Alfred/main for rewrites, improved wording, or replacement update fields; if Alfred/main returns a rewrite anyway, treat that question as rejected/unresolved and hold it for review

Hold for review when **any** are true:
- Final score is **≤6**, including after Alfred/main review
- Any 🚩 or ⚠️ appears
- Question was reconstructed from options/damaged source
- Question has “all/none of the above” fragile logic
- Fact requires external verification or feels uncertain
- Fact-check status is `uncertain` or `failed`, or fact-check data is missing/incomplete
- Any option is ambiguous, duplicated, accidentally correct, outdated, or source-dependent
- Options are weak, ambiguous, duplicated, or may create a second correct answer
- The model is not confident enough to submit unattended
- The refiner ranks it low and Alfred/main agrees the final version remains low/risky

Always send a daily summary, even when nothing is held:
- `Hebrew trivia: updated X questions automatically, held Y for review.`
- If Y > 0, include only the held question blocks for review.

Every held question should include a safe suggested replacement when one can be made without inventing unsupported facts. The suggestion must address the exact flag/rejection reason and include source URLs when web verification was needed.

If no safe suggestion can be made, say so and explain the blocker instead of forcing a weak rewrite.

---

## Step-by-Step Detail

### Fetch Stage

**Script:** `scripts/fetch_batch.py`
- Reads the highest existing ID from `questions_he`
- Fetches the next 10 raw questions from `raw_questions_he`, starting at `max(questions_he.id) + 1`
- Prints them for user review
- Exits and waits

Example output:
```
📋 BATCH FETCHED — 10 questions (IDs 203–212)

ID 203 | Hebrew question text...
ID 204 | Hebrew question text...
...

⏸️ Ready to rephrase? Reply:
   REPHRASE 203-212
```

---

### Rephrase + Review Stage

**When you reply:** `REPHRASE 203-212`

**What I do:**

1. **Fetch questions 203-212** from Quiz DB
2. **Pre-fact-check each raw question before rephrasing**
   - Check the core premise, the stored correct answer, and every option
   - Confirm that exactly one answer is correct unless the original structure is explicitly `כל התשובות נכונות` / `אף תשובה אינה נכונה`
   - Detect outdated, source-dependent, ambiguous, disputed, exaggerated, or overly broad facts before spending effort on rewriting
   - Use web search/fetch for facts involving nicknames, superlatives, percentages, dates, “first/most/largest”, current facts, geography/history claims that feel uncertain, or anything the model cannot verify confidently from stable knowledge
   - If the fact is valid only with narrower wording, mark `valid_with_rewording` and use that safer wording in the rephrase
   - If the fact cannot be verified confidently, mark `uncertain` or `failed`, keep it out of auto-submit, and hold/skip according to severity
   - Preserve a compact fact-check block in the output/JSON for Alfred/main review; do not keep the evidence hidden inside the trivia manager
3. **Rephrase each question** in natural Hebrew
   - Keep question meaning identical
   - Improve phrasing for clarity
   - Hebrew only (no English, no translations)
   - If the source question is damaged/missing but the options and correct answer exist, flag it and try to reconstruct a sensible question from that context
   - If reconstruction is plausible, include the reconstructed question in the batch with a 🚩 warning and a low confidence score
   - If no good question can be inferred safely, skip it; do not invent a weak question just to fill the batch
   - True/false questions are valid when Option 1/2 are the only answers and Option 3/4 are null/empty; do **not** mark them damaged just because they have only two answers
4. **Review wrong options**
   - Preserve correctness over forced option changes
   - Rephrase the 
````

## File: README.md
upstream: https://github.com/yinon-alfred-openclaw/trivia-refiner/blob/main/README.md

````text
# trivia-refiner

An [OpenClaw](https://openclaw.ai) skill for refining Hebrew trivia questions from a Supabase quiz database, with user approval before any database updates.

## What it does now

The current workflow is:

1. Fetch a batch of questions from `raw_questions_he`
2. Fetch available categories from Supabase
3. Build a detailed prompt with rephrasing, option-review, categorization, and formatting rules
4. Print that prompt for Alfred to handle in the current session
5. Wait for user review and approval
6. Submit approved changes back to the database
7. Track processed question IDs locally

## Important model note

This skill does **not currently call a hardcoded model directly** from `run_batch.py`.

Instead, `run_batch.py` prints the prompt and the actual refinement work is done by **Alfred in the current OpenClaw session**.

So the effective model is simply:
- **whatever model Alfred is currently running**

## Main scripts

### `scripts/run_batch.py`
Main entrypoint.

- No args: fetch next 10 questions from `raw_questions_he`, starting after the highest ID already present in `questions_he`
- With a range like `193-202`: fetch that exact range
- Fetches categories
- Prints the full prompt for Alfred to process in-session
- Does **not** directly update the database

### `scripts/submit_changes.py`
Writes approved changes back to Supabase.

- Validates required fields
- Updates `raw_questions_he`
- Upserts into `questions_he`
- Records success/failure in tracking for audit/history

### `scripts/tracking.py`
Manages local runtime tracking. This is audit/history only; automatic batch selection uses `questions_he` as the source of truth.

Tracking file:

```bash
~/.openclaw/workspace/memory/trivia-refiner-processed.json
```

Used for:
- processed IDs
- refined/failed status
- highest processed ID for audit/history; not the next-batch source of truth
- batch count

## How to run it

### Automatic / next batch

```bash
python3 scripts/run_batch.py
```

### Specific range

```bash
python3 scripts/run_batch.py 193-202
```

### Submit approved changes

```bash
python3 scripts/submit_changes.py changes.json
```

### Dry run submission

```bash
python3 scripts/submit_changes.py changes.json --dry-run
```

## What someone should know before using it

- It is an **approval-based workflow** — database writes should only happen after explicit approval
- The refinement logic currently happens **in the Alfred session**, not inside a hardcoded Gemini/Claude pipeline
- It depends on Supabase credentials stored at:

```bash
~/.openclaw/workspace/memory/supabase-creds.json
```

Expected format:

```json
{
  "url": "https://xxxx.supabase.co",
  "key": "your-service-role-key"
}
```

- It updates two tables when submitting approved changes:
  - `raw_questions_he`
  - `questions_he`

## In one sentence

This skill is currently a **prompt-driven, human-approved trivia refinement workflow** that uses Alfred’s current session model for the actual question processing.

## License

MIT
````
