decisions 0.2.0, part 2: Gemini and Venn in three vignettes Implementation Plan
plans/2026-11-24-decisions-0.2.0-vignettes-plan.md
# decisions 0.2.0, part 2: Gemini and Venn in three vignettes Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Gemini in "Choosing a model" and "Images" (with and without references), and Venn with a calibration step in "Open models", from saved runs that a reader can make again.
**Architecture:** New cases in `data-raw/vignette_results.R` run only the new provider and merge into the saved results, so the other providers are not called again; the vignette chunks show the full code with every decider. Venn gets its own saved file, so the Laya results stay.
**Tech Stack:** R, decisions (branch with `decider_gemini()` and `decider_venn()`), yardstick, probably (mgcv), the local Venn server.
**Spec:** `replication_materials/plans/2026-11-24-decisions-0.2.0-design.md` section 3 (D313); D301, D302, D306.
Paths: `decisions/` is the package; `study/` is `fine_tuned_jev`. The map of the current pipeline is in the report of 2026-11-24 (vignette_results.R lines 26, 226-330, 332-410, 412-484, 590-604).
## Global Constraints
- Branch `vignettes-gemini-venn` of decisions, from `deciders-gemini-venn`. It merges after part 1.
- Paid calls: Gemini only, budget row of D301; every call logged in `study/replication_materials/calls/gemini-calls.csv` with `log_decide("gemini", ...)`, purpose prefix `decisions-0.2.0-`. Venn calls are local and free.
- The scripts read the keys from `study/.Renviron` and `study/.env` (the Gemini key is only in `.env`); no key is printed or written.
- "No result in a vignette that a reader cannot rerun from `data-raw/`." "No claim in a vignette that the numbers do not support."
- The `script = TRUE` chunks of a vignette show the code that a reader runs (all deciders); a `*_gemini` or `*_venn` case of the script runs the same lines for the new decider only and says so in a comment.
- Venn runs with `max_active = 1`; Laya and Venn are never up together (both use port 8000).
## Review Focus
1. A merge that drops or reorders the saved answers of the other models: each merge case checks that the old elements are byte-identical after the merge.
2. A Gemini run whose rows are not in input order, or with row errors: `report_errors()` and a check of the row count before the save.
3. Venn up on port 8000 while a Laya case waits: the Venn case waits for `reader == "ready"`; `wait_for_laya()` refuses a health answer with a `reader` field.
4. A calibration fitted and scored on the same rows: the split is fixed (seed, stratified by class) and the vignette shows the halves.
5. Prose that names "three models" or fixed numbers that change: every fixed number in the changed sections comes from the saved data in an inline chunk, or is checked with `stopifnot()`.
---
### Task 1: Gemini in "Choosing a model"
**Files:** `decisions/data-raw/vignette_results.R` (key reading at line 26; new `case_choosing_a_model_gemini()`; the case list and switch), `decisions/vignettes/choosing-a-model.Rmd`, `decisions/inst/extdata/choosing-a-model.rds`.
- [ ] **Step 1:** Read `study/.env` after `study/.Renviron` in `vignette_results.R`.
- [ ] **Step 2:** `case_choosing_a_model_gemini()`: the same injuries, question and `decide()` call as the `decide` chunk, for `decider_gemini()` only; `log_decide("gemini", out, "decisions-0.2.0-choosing-a-model", ...)`; read the saved file, check that `injuries` is identical, add `answers$gemini`, check that the old elements are identical, save.
- [ ] **Step 3:** Run it. Expected: 75 rows, no row error, about 75 calls and under USD 0.01 in the log.
- [ ] **Step 4:** Update the vignette: the list of models, the credentials table, the heading and "three", the `decide` chunk (four deciders), and the cost text; numbers from the data. The tables build themselves by model name.
- [ ] **Step 5:** Build the vignette (`devtools::build_rmd("vignettes/choosing-a-model.Rmd")`); expected: no error, a Gemini row in each table. Commit.
### Task 2: Gemini in "Images", with and without references
**Files:** `decisions/data-raw/vignette_results.R` (new `case_images_gemini()`), `decisions/vignettes/images.Rmd`, `decisions/inst/extdata/images.rds`.
- [ ] **Step 1:** `case_images_gemini()`: the same 46 inputs, question and references as the `decide` chunk, twice: `gemini` (with the 4 references) and `gemini (no references)`; log both (`decisions-0.2.0-images`); merge into `answers`, check that `inputs`, the old `answers` and `clef_answers` are identical, save.
- [ ] **Step 2:** Run it. Expected: 2 x 46 rows, no row error, about 92 calls, under USD 0.05.
- [ ] **Step 3:** Update the vignette: the list of models and the note on text-only models (Venn takes no references), the `decide` chunk, the `results` chunk (a level for the new element), and the text of the performance and cost sections; the fixed numbers at lines 271-276 come from the data.
- [ ] **Step 4:** Build the vignette; expected: Gemini rows in the performance table. Commit.
### Task 3: Venn in "Open models", with a calibration step
**Files:** `decisions/data-raw/vignette_results.R` (new `case_open_models_venn()`, `wait_for_venn()`; `wait_for_laya()` refuses a `reader` field), `decisions/vignettes/open-models.Rmd`, `decisions/inst/extdata/open-models-venn.rds` (new).
- [ ] **Step 1:** `case_open_models_venn()`: wait for Venn (`reader == "ready"`); `decide(decider_venn(), nature, text = ohio_injuries$final_narrative, max_active = 1)` on all 464 rows, with the `nature` question of "Choosing a model"; a 50/50 split stratified by class (seed in the script); a probably calibrator (`cal_estimate_multinomial(smooth = TRUE)`) fitted on one half; accuracy, ROC AUC and Brier score on the other half before and after; save the answers, the split and the metrics.
- [ ] **Step 2:** Start Venn, run the case, stop Venn. Expected: 464 rows, no row error; the metrics table has two rows.
- [ ] **Step 3:** The vignette: a section on Venn between "Time" and "Privacy" (start the server, `decider_venn()`, the data and question, the decisions, the calibration), an `eval` guard for yardstick and probably, and the Overview; the text says that Venn is a research preview, weaker on text than the hosted models (D304), and that its probabilities need a calibrator.
- [ ] **Step 4:** Build the vignette; expected: no error. Commit.
### Task 4: Words, news, check and pull request
**Files:** `decisions/inst/WORDLIST` (Gemini, Venn, and other new words), `decisions/NEWS.md`, `decisions/data-raw/record.R:157` (the filter keeps the budget rows of the package that do not say "(M3)").
- [ ] **Step 1:** `spelling::spell_check_package()`; add the new words. NEWS: one item for the three vignettes.
- [ ] **Step 2:** `devtools::check(args = "--as-cran", remote = TRUE, manual = TRUE)`; expected: 0 errors, 0 warnings, 0 notes.
- [ ] **Step 3:** Record the calls in `study/replication_materials/calls/README.md` (a section with the calls of each case), a process row, build check, record-only commit and push. Push the branch, open a pull request into `deciders-gemini-venn` (or into `main` after part 1 merges), wait for its checks.