# AA toolkit

Tools that go with the Alternatives Analysis spec. The main one is the **Requirements Elicitation Tool** (`requirements.html`), one page with three steps:

1. **Classify.** The decision owner meets the draft requirements here first, and marks each one must-have, want, not sure or not needed. See "Requirements: Must-Haves and Wants" in the spec.
2. **Rank wants.** The owner puts the wants in order by answering "which matters more?" questions. That order sets the weights. See "Weight Elicitation" in the spec.
3. **Result.** Weights, must-haves checked option by option, and the leading option.

Until 2026-12-03 the page was called the Criteria Ranker, at `criteria-ranker.html`. That address is gone; see "Moving from the Criteria Ranker" below.

## Requirements first (the rule)

**The owner first meets the draft requirements on the Classify step, through a link. Never list requirements in the conversation for approval.** The conversation is for the interview (real moments, asking why); the page is for approval.

Before any options exist, hand the owner a link to the hosted page with `"classify": true`:

```json
{"title":"What matters for our next team offsite","key":"offsite-2027","classify":true,
 "criteria":[{"id":"COST","name":"R1 We stay inside our budget, travel included, so we need no extra sign-off","fall":"We would have to ask for more money."},
             {"id":"FOCUS","name":"R2 When we sit down to plan, nothing pulls us away, so we leave with the plan finished","fall":"We would go home with the plan half done."},
             {"id":"TRAVEL","name":"R3 Each of us can get there in under two hours, so nobody loses a day to travel","fall":"Some of us would lose a working day each way."}]}
```

Encode it as shown under "Making the link" and send `https://jonashw.dev/alternatives/toolkit/requirements.html#data=<base64url>`. Give it a `key`, and keep that key when you send the set again (reworded, or later with `alternatives` and `scores`), so the owner's choices carry over. The owner classifies, uses **Add requirement** for anything missing, and pastes the copied result back. That result is the read-back; don't ask for a second yes in the conversation.

Write each `name` as a story in the voice of whoever measures value, requirement number first, ending with its why: "R3 Each of us can get there in under two hours, so nobody loses a day to travel", not "Travel time". Give each a `fall` sentence: what falling short would cost.

**Pitfalls:**

- **A list in the conversation "just to check".** This is the mistake the rule exists for. Send the link.
- **Waiting for options.** The first link needs no `alternatives` and no `scores`.
- **Not sure rows.** The page holds Rank wants and Result while any row is not sure or still open, and offers **Back to Classify** or **Continue provisionally**. Ask one real-moment question per row in the conversation, then send a fresh link.
- **No `key`, or a new `key` each time.** The owner's earlier choices are saved under the key. Without one, or with a new one, they start from nothing.

## Moving from the Criteria Ranker

The rename of 2026-12-03 was a clean break, approved by the spec's owner (Jon): "I don't care if it breaks links." and "I don't want gates in the domain, only musts or must-haves". Any project may make these changes to its own pages, docs and prompts without asking him again.

| Was | Now |
|---|---|
| Criteria Ranker | Requirements Elicitation Tool |
| `toolkit/criteria-ranker.html` (now a 404) | `toolkit/requirements.html` |
| `toolkit/criteria.schema.json` (now a 404) | `toolkit/requirements.schema.json` |
| the **Sort** step | the **Classify** step |
| `"sort": true` | `"classify": true` (the old name is still read) |
| "gate" (in the spec, the page and the record) | "must-have" |
| `gates`, `ownGates`, `ownGateResults` (data fields) | `mustHaves`, `ownMustHaves`, `ownMustHaveResults` (the old names are still read) |
| `gates A+B of ...` (a big-tie answer in a copied record) | `mustHaves A+B of ...` (the old word is still read) |

What to do:

1. **Hosted links** (`...toolkit/criteria-ranker.html#data=...`): replace `criteria-ranker.html` with `requirements.html`. The part after `#` is unchanged, and saved answers carry over, because they are stored by key on the same site.
2. **Copies** (a page published for one decision, such as a Claude artifact): they keep working and need no change. To take the new wording, run `node toolkit/upgrade.mjs old.html > new.html` and publish at the **same address**. The upgrade keeps the copy's own `<title>`, header and `DATA`.
3. **Docs, prompts, skills and memory** that name the Criteria Ranker, the Sort step or gates: use the new names, and add the rule above ("Requirements first").
4. **Data fields:** write `mustHaves`, `ownMustHaves` and `ownMustHaveResults` in anything new. A `DATA` block or link that still says `gates`, `ownGates` or `ownGateResults` is read as before, so nothing breaks; rename the fields when you next touch it. `criteria`, `oldSortKey` and the rest are unchanged. Saved answers and old pasted records are brought to the new names by the page.
5. **AAs already written** stay as they are (an AA is a record). A new AA uses "must-have".

## Supported use (read before copying the page)

These steps avoid the mistakes that are known to break a copy or lose a record.

1. **Start from the current page.** Copy `https://jonashw.dev/alternatives/toolkit/requirements.html` (this repo's `main`), not an older copy from another project. To bring an older copy up to date, use `upgrade.mjs` (below).
2. **Publish the one file, as it is.** The page already contains the question engine, between `// BEGIN pairwise.js` and `// END pairwise.js` (and `custom.js` the same way). Don't remove those blocks, and don't replace it with a `<script src="pairwise.js">`: a page published without the engine loads but asks no questions.
3. **Change only what belongs to the decision:** the `DATA` block, the `<title>` and, if you want your own wording, the `<header>`. Everything else is shared and tested.
4. **Never edit the engine block by hand.** Change `pairwise.js`, run `node toolkit/inline.mjs`, then run the tests. The tests fail if the page's copy and `pairwise.js` differ.
5. **Keep `DATA.key` for the life of a decision.** Saved answers are stored in the viewer's browser under that key. A new decision gets a new key, so it doesn't pick up another decision's answers.
6. **Upgrade in place.** Run `node toolkit/upgrade.mjs old.html > new.html` and publish the result at the **same address** (for a Claude artifact, update the same artifact). A new address starts with empty browser storage.
7. **Don't change the copied text's format.** The lines `Set by N pairwise answers: ...` and `Checked at the end: ...` are read back when a run is pasted in to reopen or review. Treat that text, pasted verbatim, as the record.
8. **Keep the touch-screen rules:** hover only inside `@media (hover: hover)`, an `:active` style, and a blur after each click, so a tapped answer never looks chosen on the next question.
9. **Just trying it? Don't make a copy.** Hand the hosted page a criteria set by link or paste (next section). Make a copy only for a decision you want to keep at its own address.

## Try it with your own criteria (no copy needed)

The hosted page, `https://jonashw.dev/alternatives/toolkit/requirements.html`, takes a criteria set two ways:

- **A link an agent prepares.** Put the set after the `#`, as base64url of the JSON: `requirements.html#data=<base64url>`. The person taps the link and sees the page with those requirements. This is the main path for agents.
- **The paste box.** "Try it with your own criteria" on the page takes the JSON, or a whole share link. Once loaded, **Copy share link** gives the link for that set.

**Designed for privacy.** The part of a link after `#` is never sent to the server, so the criteria don't reach the site or its logs. Answers are saved only in the viewer's browser (localStorage). Nothing is uploaded. This means the server can't see the set. It does not make the set secret: anyone with the link, the browser's history and the app the link was sent through can read it.

### The format

The same shape as the page's `DATA` block, as JSON. The full rules are in [`requirements.schema.json`](requirements.schema.json) (JSON Schema 2020-12), so an agent can check its output before handing out a link. There are three shapes:

0. **Requirements, before any options:** `title`, `key`, `"classify": true` and `criteria`. See "Requirements first" above. This is the first shape an AA uses.
1. **A plain list:** `title` and `criteria` (each `id` and `name`). The person ranks the items, and the page shows no weights or winner. Optional wording: `question`, `more`, `noun`.
   ```json
   {"title":"Which chore first?","noun":"chores","question":"Which would you rather get done first?",
    "criteria":[{"id":"DISH","name":"Dishes"},{"id":"LAUN","name":"Laundry"},{"id":"YARD","name":"Yard"}]}
   ```
2. **One decision:** add `alternatives` (each starting with a short code, such as `"A City hotel"`) and give every criterion `scores`: one per alternative, in order, 0 to 5 (1 poor, 5 excellent). `draftWeights` is optional (percent by criterion id), and so is `note` on a criterion.
   ```json
   {"title":"What matters for our next team offsite",
    "alternatives":["A City hotel","B Cabin in the hills","C Our own office"],
    "criteria":[{"id":"COST","name":"R1 We stay inside our budget, travel included, so we need no extra sign-off","scores":[2,3,5]},
                {"id":"FOCUS","name":"R2 When we sit down to plan, nothing pulls us away, so we leave with the plan finished","scores":[3,5,1]},
                {"id":"TRAVEL","name":"R3 Each of us can get there in under two hours, so nobody loses a day to travel","scores":[4,2,5]}],
    "draftWeights":{"COST":40,"FOCUS":40,"TRAVEL":20}}
   ```
   Put every requirement the owner may still classify in `criteria`, with scores: the page's **Classify** step lets the owner make each one a must-have (it passes at a score of 3 or more), a want (ranked and weighed) or not needed. Use `mustHaves` only for must-haves that are already settled and checked option by option: each must-have has `id`, `name` and `pass`, one `1` (pass) or `0` (fail) per alternative, for example `"mustHaves":[{"id":"LEGAL","name":"R4 Our whole group is allowed in, so nobody is turned away at the door","pass":[1,1,0]}]`. The Classify step lists those as fixed. An alternative that fails a must-have is shown as vetoed and left out of the scoring (see the spec's "Requirements: Must-Haves and Wants").
   Optional for the Classify step: per criterion `fall` (what falling short means, in plain words), `deadline: true` (the requirement is a date; as a must-have the page warns), and `floor` (the pass score as a must-have, 1 to 5, default 3); at the top level `classify: true` (a list without alternatives opens with the Classify step, so requirements can be classified before any options exist; the older name `sort` is still read) and `questions`, other yes-or-no questions asked in their own step (`id`, `text`, `a`, `aMeans`, `b`, `bMeans`, at most 6).
   Optional per criterion: `image`, a small picture for its row (an `https://` address or a `data:image/...;base64,` URI, at most 20,000 characters), and `fromDraft`, the draft id (`NEW1`) the owner gave it with **Add requirement** (see "Classify, rank, result" below).
3. **A parent with parts:** `criteria` without scores, optional `mustHaves`, and `parts` (see "Parent and parts" below and `PARTS_EXAMPLE` in the page).

Rules: `id` is 1 to 16 letters, digits, `-` or `_`, starting with a letter or digit, used once. Write each `name` as a story in the voice of whoever measures value, requirement number first, ending with its why ("R1 When ___, I can ___, so I ___", or "The org can ___, so ___" when the owner decides for others). When two criteria are linked, open each with the situation it covers ("When saving works…", "When a site blocks saving…") so only one quality varies per question (see the spec's "Hold the situation constant"). Limits: 40 criteria, 12 alternatives, 12 parts, 300 characters per text, 40,000 characters in all. The page leaves out any other field, with a note.

### Making the link (for agents)

Base64url of the UTF-8 JSON, without `=` padding, after `#data=`:

```python
import base64, json
data = {"title": "Which chore first?", "criteria": [{"id": "DISH", "name": "Dishes"}, {"id": "LAUN", "name": "Laundry"}]}
code = base64.urlsafe_b64encode(json.dumps(data, separators=(",", ":")).encode()).decode().rstrip("=")
print("https://jonashw.dev/alternatives/toolkit/requirements.html#data=" + code)
```

```js
const code = Buffer.from(JSON.stringify(data), "utf8").toString("base64url");   // Node
console.log("https://jonashw.dev/alternatives/toolkit/requirements.html#data=" + code);
```

Without a way to run code, give the person the JSON to paste into the box instead. Don't hand-write base64. The page also reads JSON written out after `#data=` (percent-encoded), but chat apps often break such links at spaces and quotes.

When the person is done, **Copy ranking** gives the usual record, plus a last line `Criteria set: <link>`, so the run can be reopened with its criteria.

### Pitfalls (each is handled; know them anyway)

- **Query string instead of `#`.** `?data=` would send the criteria to the server and its logs. The page reads only `#data=`.
- **Long links.** Keep a link under about 2,000 characters. Some chat apps and text messages cut longer ones, and a cut link loads the example with an error. **Copy share link** warns when a link is longer than that. For a big set, send the JSON to paste.
- **Words from a stranger.** The page shows every pasted string as plain text, never as HTML, and a banner says the criteria came from a link or paste, not from this site. The words can still say anything, so treat a set from someone you don't know like any other message from them.
- **Adding to a set.** Give the set a `key` that belongs to this one decision. A keyed set saves under its key alone, so sending it again with a requirement reworded, added or split, or with options and scores, keeps the owner's choices and answers. Without a `key`, answers are saved under a hash of the ids, and any change of ids starts fresh. Never reuse a key for another decision: it would open on the first one's answers.
- **Saved answers.** A set with a `key` saves under that key; a set without one saves under a hash of its ids in order. A link without a key can never overwrite another set's answers, and no link reaches answers on a copy at another address. Rewording a name while keeping the ids keeps the answers, and the page offers **Review my answers**.
- **Copies ignore links.** Only the hosted page (whose `DATA.key` starts with `example-`) shows the box and reads `#data=`. A copy made for a real decision never swaps its criteria for a link's.
- **No reaching other answers.** Fields such as `oldKey`, which would import answers saved under another key, are left out of a pasted set.

## Files

- `requirements.html`: the decision owner classifies the requirements and sets the weights on one page. One file, nothing to install: it works as a Claude artifact, on this site, or opened from disk.
  - **Classify, rank, result:** a decision with options opens on three steps, chosen with a segmented control: **Classify**, **Rank wants** and **Result**. Classify lists every requirement with **Must-have | Want | Not sure | Not needed**; rows start still open. Each row says what falling short means (when the data gives `fall`) and which options it rules out as a must-have. A must-have row sets its pass score (1+ to 5+, default 3+) and, when the options left still differ above it, a switch weighs what lies beyond the floor as a want. A want on which every option left scores the same is pointed out. A deadline is flagged. **Really two things** marks a row to split and gives a message for Claude. Fixed must-haves from the data appear as rows to confirm (Must-have | Not needed), and other questions from the data sit in their own step at the top. Warnings say when every requirement is a must-have and when one option or none passes them all, and "Make the rest wants" classifies the rest in one go. Must-haves are pass or fail (an option passes where its score is 3 or more; a switch per option changes it). Only wants are ranked. **Continue to ranking** at the foot of Classify and **Continue to result** at the foot of Rank wants move to the next step, the same as the control at the top. Not needed rows fold into a list you can reopen. Every choice can be changed back: the same control, or **Undo** in the status line, which steps back through the choices. Changing a choice in the middle of the questions carries on with the new wants and keeps every answer. Classifying a want back in after the questions puts it back in its old place without a question; a want new to the ranking waits under the list until **Place the new wants** asks only the pairs never answered. The big-tie answer "These are must-haves" makes those must-haves, the same as the Classify step. A plain list (no options) has no Classify step unless its data says `classify: true`.
  - **Status line:** always visible at the bottom, in plain words: how many must-haves, wants, not needed and still open; how many options pass every must-have; and the most questions left to rank the wants. No bars, streaks or percents.
  - **Add requirement:** the status line's button takes one line in the owner's words and Must-have or Want. It joins the list at once as a draft (`NEW1`) and the page gives a message to paste into the thread: Claude asks follow-up questions, writes the requirement up with its number and source, adds it to the analysis (as a new AA that supersedes a decided one; see Revisiting a Decision), and republishes the ranker **at the same address** with the new criterion carrying `fromDraft: "NEW1"`. On the next load the draft's sorting and answers move to the new id. On the hosted page with a pasted set, a new criterion changes the set's ids, so its answers start fresh (see Pitfalls).
  - **Where you were:** the page saves the step you were on and the last row you classified, and an unfinished run offers **Carry on**, so a reload comes back to the same place.
  Question modes:
  - **Pairwise questions:** "Which matters more to you?", one pair at a time, sorted by binary insertion. Answers are one of the two or "About the same", which joins the whole tie group (the question names everyone in it). One fixed bar above the choices: stop, back, About the same, forward. Hotkeys on a keyboard: 1, 2, =, left arrow, right arrow or Enter, Esc. The start order is shuffled with a fixed seed.
  - **Check questions:** after the last answer, up to three neighbouring pairs near the top are asked again, never the pair the last question just asked (so two items get no check). A reversal or "about the same" turns the pair into a tie. Stop skips them.
  - **Big ties:** after the checks, any group of more than three criteria called "about the same" gets one more question that lists the whole group: "If you could only keep one of these, which?" (hotkeys 1 to 9). The one kept moves just above the rest, which stay tied. **Can't pick one** (=) keeps the tie. **These are must-haves, not trade-offs** lets the owner tick which ones become must-haves: they leave the ranking, and each option passes where its score is 3 or more, with a switch per option in the must-haves panel to change it. A segmented control on the finished screen, **Break up big ties**, sets **Until three are left** (default: asks the rest again while more than three are tied) or **Once per group**. Every big group is asked, top first; Stop skips the rest. The answers go into the copied record as `Big ties (until three are left): NOTE over MEDIA+TAP+...; mustHaves TAP+PRIV of ...; none of ...`, and a pasted record reopens or reviews them. Ties chain (A about the same as B, and B as C, puts all three in one tie), so a check answer can join groups and set aside earlier "X over Y" answers inside the new tie. When that happens, a note above the keep question names each answer set aside; the keep question then sorts them out again.
  - **Big-tie check:** when more than three criteria tie at the top, the result shows the lead of the top two with equal weights next to the lead with the owner's weights, and how much of the gap between them comes from criteria inside the tie. When it is more than half, it says the scores decide the result more than the ranking does.
  - **Back, review and saved runs:** the finished screen has a back arrow (reopens the last question) and **Review answers**, which replays the run showing each earlier answer: forward keeps it, a different pick changes it. The order, answers, ties and checks are saved together, an unfinished run offers **Carry on** after a reload, and a pasted copy of a finished run can be reopened or reviewed.
  - **Drag:** drag handles plus up and down arrows, for phones. Dragging after the questions clears the ties and the answer record.
  - Live: each criterion's weight (steep = rank-order centroid, gentle = rank-sum; tied neighbours share the mean), the winner and runner-up, a 2,000-trial ±20% weight check, a 2,000-trial check with random weights that keep the owner's order (ties stay ties), and whether the analyst's draft weights picked the same winner. One decision can carry `mustHaves` too (see the format above).
  - Returns the ranking, the winner, the pairwise answers and the check answers as text for the owner to paste back. That text is the record.
  - **Parent and parts:** one page can hold a parent decision and its parts (see "Decisions Made of Parts" in the Storytelling variant). The parent's ranking sets the weights for every part; each part uses only the criteria it has scores for, with weights renormalized over those. Shared must-haves are listed once; an option that fails one is shown as vetoed and left out of the scoring. A part may add must-haves of its own (`ownMustHaves`, `ownMustHaveResults`). A criterion marked `director: true` (for example, delight) is scored by the director with one tap on a 1 to 5 row, and those scores go into the copied record. A part marked `twoWay: true` is not scored: it shows "two-way door: prototype it". A roll-up table lists each part's winner, score, margin and status. Open the page with `?example=parts` to see an example.
  - **A list only:** leave out `alternatives` (and `parts`) to rank plain items, such as which site hurts most when it's down. The page hides the weights, the result and the scores, and the copied text is the order with its ties and answers. Optional wording: `question` (the question on each pair), `more` (as in "Last time you said: X hurts more") and `noun` (plural, for the intro). `oldKey` names the storage key of an older hand-built page that saved `{ answers }`; those answers carry over once, replayed in the DATA order. `oldSortKey` does the same for a hand-made must-or-want page that saved `{ ID: "Must" | "Want" }`: published as a ranker at the same address, its answers fill the Classify step once.
  - **To reuse:** copy the file, replace the `DATA` block and publish it. One decision: `key`, `title`, `alternatives`, `criteria` with `id`, `name`, `scores` per alternative, optional `note`, and `draftWeights`. Parent and parts: `key`, `title`, `criteria` (no scores), `draftWeights`, `mustHaves` (`id`, `name`), and `parts`, each with `id`, `name`, `alternatives`, `scores` by criterion id, and `mustHaves` by must-have id (1 pass, 0 fail). See `PARTS_EXAMPLE` in the page. Write each criterion as a short code plus one plain sentence, requirement number first, saying what good looks like (see the spec's Weight Elicitation). For example:
    ```js
    {id:"BACK", name:"R2 Results reach the right thread in the owning project, with no paste from you", scores:[5,3,1]},
    ```
    The copied record lists answers by the code (`BACK > ONCE`), so keep codes short and stable.
  - **Rewording later:** keep `DATA.key` when you reword criteria, so saved answers carry over. The page stores each criterion's wording with the answers; if any wording has changed, it lists those criteria above the questions and offers **Review my answers** (one by one, earlier answer marked, reworded criteria flagged) or **Keep my answers**. Records saved before this check have no wording on file and are not flagged.
  - **To upgrade a copy already in use:** `node toolkit/upgrade.mjs old.html > new.html`. It keeps the old page's title, header (heading and intro), `DATA` and scores note and takes everything else from the current page. Saved answers carry over in the viewer's browser because `DATA.key` stays the same. Publish the result at the same address.
- `custom.js`: reads, checks and links pasted criteria sets (`read`, `check`, `fromFragment`, `toLink`, `storageKey`, `LIMITS`, `SAMPLE`). Pure; copied into the page like `pairwise.js`. Tests: `node --test toolkit/custom.test.mjs`.
- `requirements.schema.json`: the JSON Schema for a pasted or linked criteria set.
- `pairwise.js`: the question rules on their own, for ranking anything by "which of these two?". ES module, no page, no weights. `start`, `read` (next question with its tie group, order best first, groups, ties, answers used, worst-case questions left), `answer`, `undo`, `shuffle`, `worstCase`, `checkQuestions` and `withChecks`, the big-tie helpers `groupsOf`, `tiesOf`, `keepQuestion`, `withKeeps`, `bigTies`, `keepText` and `parseKeeps`, `overridden` (the "X over Y" answers a chained tie sets aside), plus sessions for back, forward and review: `session(ids, { prior })`, `sessionAnswer`, `back`, `forward`, `earlier`, and `parseAnswers` for copied text. Answers are `{a, b, result}` with `'>'` or `'='`.
- `inline.mjs`: copies `pairwise.js` and `custom.js` into `requirements.html`. Edit either, then run `node toolkit/inline.mjs`. A test fails if the page's copy has drifted.
- `pairwise.test.mjs` and `custom.test.mjs`: `node --test toolkit/pairwise.test.mjs toolkit/custom.test.mjs`. The site deploy runs them first.

Known gap: a part cannot yet rank its own criteria on the page (the spec allows it; run a separate page for that part).
