// public/strata/told-or-counted/policy.mjs
//
// THE ELEVEN LIVING EXPERIMENTS, AND WHAT A GUIDE TO THEM IS ALLOWED TO SAY.
//
// Each of the eleven takes one anonymous row of bounded integers per reader through
// POST /api/collective/<arm>. Each also hides some of what it knows until the reader has
// answered, because showing it first would change the answer. A page that lists them all
// therefore has a problem no ordinary portal has: the interesting facts are exactly the
// facts it may not print.
//
// This file is the ruling, per experiment, and it is NOT an editorial judgement. Every
// entry is derived from what the experiment's OWN page already shows a reader before the
// reader acts. If a figure sits above the send control on the source page, repeating it
// here changes nothing about who contributes. If it sits behind the reveal, repeating it
// would make the portal the thing the experiment was built to exclude.
//
// So every `evidence` entry carries a `quote` that must occur VERBATIM in the named file.
// verify-told-or-counted.mjs re-reads all of them. When somebody edits one of the eleven
// pages, this file fails loudly instead of quietly going out of date, which is the only
// way a claim about somebody else's page survives being written down.
//
// TWO FIELDS DO THE WORK:
//
//   countSafe  - may the portal show this arm's live row count BEFORE the reader plays?
//                It is false where the size of the crowd is part of the stimulus.
//   priorSafe  - may the portal show this experiment's published (Arm A) result before
//                the reader plays? It is false where the source page keeps that result
//                behind its own send gate.
//
// `ask` is the third piece and the subtlest. For the unspoiled view an experiment is named
// only by the ACT it asks of you, never by its subject, because for at least one of them
// the subject is the spoiler: wason-246 asks the reader, before anything else, whether they
// have seen this task before, and any nav label saying "Wason" or "2-4-6" turns that answer
// into a report about this page.

export const OPENED = '2026-08-21';

/** @typedef {{file: string, quote: string, note: string}} Evidence */

export const EXPERIMENTS = Object.freeze([
  Object.freeze({
    arm: 'serial-position',
    slug: 'serial-position',
    title: 'Do We Lose the Middle?',
    ask: 'Remember fifteen words, then type back whatever is left.',
    minutes: 3,
    integers: 2,
    perIpDay: 3,
    countSafe: true,
    countReason:
      'The stimulus is a word list presented at 600 ms a word. How many other people have done it is not part of it.',
    priorSafe: true,
    priorReason:
      'The 1962 aggregate sits in a section of its own page that a reader can read before pressing start, and the page refuses to draw a living-versus-published curve at all.',
    evidence: Object.freeze([
      Object.freeze({
        file: 'public/strata/serial-position/index.html',
        quote: 'start one list',
        note: 'the control that begins the trial',
      }),
      Object.freeze({
        file: 'public/strata/serial-position/analysis.mjs',
        quote: 'comparisonGateOpen: false',
        note: 'the page declines to compare its living arm with Murdock 1962 at all',
      }),
    ]),
  }),

  Object.freeze({
    arm: 'change-blindness',
    slug: 'change-blindness',
    title: 'The Change You Called in Advance',
    ask: 'Say in advance whether you will spot it, then watch two pictures alternate.',
    minutes: 4,
    integers: 4,
    perIpDay: 3,
    countSafe: true,
    countReason:
      'Detection is a fact about your eyes and the 640 ms cycle. The crowd is not in the loop.',
    priorSafe: true,
    priorReason:
      'Its 1997 anchor is on the page in ordinary reading order. What must stay hidden is the paradigm itself, and this guide does not describe it.',
    evidence: Object.freeze([
      Object.freeze({
        file: 'public/strata/change-blindness/index.html',
        quote: 'seal prediction and begin',
        note: 'the prediction is sealed before any scene is shown',
      }),
      Object.freeze({
        file: 'public/strata/change-blindness/analysis.mjs',
        quote: 'export const CAP_ALTERNATIONS = 16;',
        note: 'the detection cap the sealed prediction is asked about',
      }),
    ]),
  }),

  Object.freeze({
    arm: 'wason-246',
    slug: 'wason-246',
    title: 'The Test That Tests a Set',
    ask: 'Probe a hidden rule with up to six tests, then name it once.',
    minutes: 5,
    integers: 6,
    perIpDay: 3,
    countSafe: true,
    countReason: 'Nothing in the task depends on how many others have run it.',
    priorSafe: false,
    priorReason:
      'This is the one where the NAME is the spoiler. The page asks, before anything else, whether you have met this task before, and stores the answer as a field. A guide that printed the task’s usual title would be turning that answer into a report about the guide.',
    evidence: Object.freeze([
      Object.freeze({
        file: 'public/strata/wason-246/index.html',
        quote: 'Have you seen a hidden-rule task beginning 2, 4, 6 before?',
        note: 'asked before the game starts, and stored as the exposure field',
      }),
      Object.freeze({
        file: 'public/strata/wason-246/analysis.mjs',
        quote: "export const ANNOUNCED_CLASSES = Object.freeze([",
        note: 'the six stored classes the announcement collapses into',
      }),
    ]),
  }),

  Object.freeze({
    arm: 'calibration-intervals',
    slug: 'calibration-intervals',
    title: 'How Wide Is 90%?',
    ask: 'Draw eight ranges you are ninety percent sure of.',
    minutes: 7,
    integers: 4,
    perIpDay: 2,
    countSafe: true,
    countReason: 'Your ranges are about the world, not about the other readers.',
    priorSafe: true,
    priorReason:
      'Its own hero prints the published shortfall above the instrument, deliberately. Repeating it here changes nothing that page has not already done.',
    evidence: Object.freeze([
      Object.freeze({
        file: 'public/strata/calibration-intervals/index.html',
        quote: 'Draw eight fences around what you do not know.',
        note: 'the instruction, in the page’s own words',
      }),
      Object.freeze({
        file: 'public/strata/calibration-intervals/analysis.mjs',
        quote: "export const CURRENT_ITEM_SET = 0;",
        note: 'one fixed item set, so there is exactly one version of the task',
      }),
    ]),
  }),

  Object.freeze({
    arm: 'coin-cant-fake',
    slug: 'the-coin-you-cant-fake',
    title: "The Coin You Can't Fake",
    ask: 'Type a hundred flips of a coin that only exists in your head.',
    minutes: 4,
    integers: 3,
    perIpDay: 3,
    countSafe: true,
    countReason: 'The sequence comes out of your head. Nobody else is in it.',
    priorSafe: true,
    priorReason:
      'This arm is explicitly a post-explanation crowd: its page teaches the tell before it asks for a contribution, and says so. Telling you first is the protocol, not a breach of it.',
    evidence: Object.freeze([
      Object.freeze({
        file: 'public/strata/the-coin-you-cant-fake/index.html',
        quote: 'This is explicitly a post-explanation crowd.',
        note: 'the page declares its own population',
      }),
      Object.freeze({
        file: 'public/strata/the-coin-you-cant-fake/index.html',
        quote: 'Type a hundred flips of a coin that only exists in your head',
        note: 'the instruction, verbatim',
      }),
    ]),
  }),

  Object.freeze({
    arm: 'wisdom-of-crowds',
    slug: 'wisdom-of-crowds',
    title: 'The Crowd That Watched Itself',
    ask: 'Estimate how many dots are in a field. Then, without looking back, estimate again.',
    minutes: 3,
    integers: 3,
    perIpDay: 3,
    countSafe: true,
    countReason:
      'The true count is generated for your field alone and is exact by construction. The pool does not enter your estimate.',
    priorSafe: true,
    priorReason:
      'Galton and the 2008 comparison are the essay the living arm sits at the end of. A reader meets them first on that page by design.',
    evidence: Object.freeze([
      Object.freeze({
        file: 'public/strata/wisdom-of-crowds/index.html',
        quote: 'Do not try to reconstruct the number you typed. Make a fresh estimate from the dots.',
        note: 'the inner-crowd instruction between the two estimates',
      }),
      Object.freeze({
        file: 'public/strata/wisdom-of-crowds/analysis.mjs',
        quote: 'export function buildTarget(targetId)',
        note: 'the generator that makes the answer knowable without anybody entering it',
      }),
    ]),
  }),

  Object.freeze({
    arm: 'optional-stopping-spine',
    slug: 'optional-stopping-spine',
    title: 'The Experiment You May Stop Whenever You Like',
    ask: 'Watch fair bits arrive one at a time and stop whenever you would stop.',
    minutes: 3,
    integers: 6,
    perIpDay: 4,
    countSafe: true,
    countReason:
      'All hundred bits are drawn and sealed before the first is shown, so nothing about the crowd can reach your stopping finger.',
    priorSafe: true,
    priorReason:
      'Its published figure is the headline of its own page, above the run. That is deliberate: the point of the instrument is that knowing the number does not stop you doing it.',
    evidence: Object.freeze([
      Object.freeze({
        file: 'public/strata/optional-stopping-spine/index.html',
        quote: 'One hundred fair bits. Your finger is the stopping rule.',
        note: 'the instruction',
      }),
      Object.freeze({
        file: 'public/strata/optional-stopping-spine/app.js',
        quote: 'const bits = new Uint8Array(100);',
        note: 'the whole trajectory is drawn before the first draw is revealed',
      }),
    ]),
  }),

  Object.freeze({
    arm: 'anchoring-rct',
    slug: 'anchoring-rct',
    title: 'What One Estimate Can Never Show',
    ask: 'Read one sentence, then give one whole-number estimate.',
    minutes: 2,
    integers: 4,
    perIpDay: 2,
    countSafe: true,
    countReason:
      'A row count is not a quantity on the scale this question is answered in, and this guide prints no quantity that is.',
    priorSafe: false,
    priorReason:
      'Its true target and its published medians are large numbers on the same scale as your answer, and its own page keeps them behind the reveal for that reason. Printing them upstream would be applying the mechanism the experiment measures, as the researcher.',
    evidence: Object.freeze([
      Object.freeze({
        file: 'public/strata/anchoring-rct/index.html',
        quote: 'Only the fixed target and the arm data stay behind the',
        note: 'the page states its own ordering rule',
      }),
      Object.freeze({
        file: 'public/strata/anchoring-rct/analysis.mjs',
        quote: 'export const LIVE_ANCHORS = Object.freeze({ low: 200000, high: 4000000 });',
        note: 'the randomised manipulation, which only the assigned half may ever be seen',
      }),
    ]),
  }),

  Object.freeze({
    arm: 'guess-two-thirds',
    slug: 'guess-two-thirds',
    title: 'The Number That Moves When You Look',
    ask: 'Choose any number from 0 through 100.',
    minutes: 2,
    integers: 3,
    perIpDay: 2,
    countSafe: false,
    countReason:
      'Half of the readers are randomised into an arm that must see only the rules, and the current crowd is precisely what the other arm gets to see. A count printed here would quietly move a reader from one arm to the other while the row they send still says which arm they were assigned.',
    priorSafe: false,
    priorReason:
      'The published session means run from the high thirties down to single figures over four rounds. That is a strategy hint, and the page keeps its whole history hidden until a contribution is accepted.',
    evidence: Object.freeze([
      Object.freeze({
        file: 'public/strata/guess-two-thirds/index.html',
        quote: 'Each visitor is assigned one of two views. Blind sees only these rules. Feedback also sees the current crowd before choosing.',
        note: 'the manipulation, in the page’s own words',
      }),
      Object.freeze({
        file: 'public/strata/guess-two-thirds/app.js',
        quote: "'BLIND: only the rules are visible before your choice.'",
        note: 'what the blind arm is promised',
      }),
    ]),
  }),

  Object.freeze({
    arm: 'false-consensus',
    slug: 'false-consensus',
    title: 'How Common Was the Choice You Made?',
    ask: 'Make one small choice, then guess how many other readers made the same one.',
    minutes: 2,
    integers: 4,
    perIpDay: 10,
    countSafe: false,
    countReason:
      'The question you are asked is literally about the other accepted rows for your item. The count is the denominator of the thing being measured, so printing it upstream answers part of the question for you.',
    priorSafe: true,
    priorReason:
      'The 1977 table is reproduced on the page as a check that runs before the send control unlocks, so a reader meets it before choosing either way.',
    evidence: Object.freeze([
      Object.freeze({
        file: 'public/strata/false-consensus/app.js',
        quote: "Of this page's other accepted submissions assigned this item, what percent do you think will choose",
        note: 'the forecast target is the arm itself',
      }),
      Object.freeze({
        file: 'public/strata/false-consensus/analysis.mjs',
        quote: "export const STREAM_ALPHA = 0.05 / 12;",
        note: 'twelve simultaneous streams, one alpha budget',
      }),
    ]),
  }),

  Object.freeze({
    arm: 'focal-point',
    slug: 'the-focal-point',
    title: 'The Focal Point',
    ask: 'Choose, five times, to match a reader you cannot signal.',
    minutes: 4,
    integers: 2,
    perIpDay: 8,
    countSafe: false,
    countReason:
      'You are asked to match an unknown reader. Being told in advance how many readers there are to match is a fact about the game you are playing, and with a pool of zero it is the whole of it.',
    priorSafe: false,
    priorReason:
      'Each game’s distribution is revealed only when that game’s contribution is acknowledged, and opening the archive early permanently closes the controls on that page. The page treats being told as spending the route.',
    evidence: Object.freeze([
      Object.freeze({
        file: 'public/strata/the-focal-point/index.html',
        quote: 'Reading it now permanently closes contribution controls in this page view, so its answers cannot enter your rows.',
        note: 'the page already forces this exact choice, one page at a time',
      }),
      Object.freeze({
        file: 'public/strata/the-focal-point/analysis.mjs',
        quote: 'export function pairwiseMatchFromCounts(counts)',
        note: 'the one statistic behind all three of its columns',
      }),
    ]),
  }),
]);

export const COUNT_GATED = Object.freeze(EXPERIMENTS.filter((e) => !e.countSafe).map((e) => e.arm));
export const PRIOR_GATED = Object.freeze(EXPERIMENTS.filter((e) => !e.priorSafe).map((e) => e.arm));

/**
 * The leak this page cannot close, stated as arithmetic rather than as an apology.
 *
 * While the eleven arms hold `total` rows between them, the count of any single arm is
 * pinned to the interval [0, total]. At total = 0 that interval is a point, so printing the
 * total tells a reader the exact count of the three gated arms. Above zero it is only a
 * bound, and the bound loosens as the total grows.
 *
 * This is why the page's own headline number sits behind the reader's choice, and it is
 * also why the page stops hiding it once the total is large enough for the bound to be
 * uninformative. LEAK_CLOSES_AT is that threshold, fixed here before any row existed.
 */
export const LEAK_CLOSES_AT = 20;

export function totalLeaksExactCount(total) {
  return total === 0;
}

export function leakDescription(total) {
  if (total === 0) {
    return 'exact: a total of zero fixes every arm at zero, including the three whose count is part of their stimulus';
  }
  if (total < LEAK_CLOSES_AT) {
    return `bounded: each gated arm holds somewhere from 0 to ${total} rows`;
  }
  return 'uninformative: the total no longer pins any single arm closely enough to matter';
}

// ───────────────────────────────────────────────────────────────────────────
// THE PUBLISHED COLUMN: the result each experiment is a rerun of.
//
// Shown only in the told view, and for the four gated experiments only there.
// No figure here is typed from memory or from a secondary source. Each one names
// the FILE IN THIS SITE that already carries it, and the exact substring the
// verifier re-reads. If one of the eleven ever restates its own anchor, the
// number here stops matching and the check goes red rather than this page
// quietly carrying a figure its source no longer supports.
export const PUBLISHED = Object.freeze({
  'serial-position': Object.freeze({
    figure: '103 participants, six conditions',
    gloss: 'Free recall of word lists at one or two seconds a word. This site reruns it at 600 ms with fifteen words and refuses to draw the two curves together.',
    citation: 'Murdock, B. B. Jr. (1962). The serial position effect of free recall. J. Exp. Psychol. 64(5), 482-488.',
    file: 'public/strata/serial-position/page-data.json',
    quote: '"participant_total_stated_in_text": 103',
  }),
  'change-blindness': Object.freeze({
    figure: '1.4 alternations without the blank',
    gloss: 'With no grey frame between the two views the change was caught almost at once. The blank is what makes it hard, and the page measures both on you.',
    citation: 'Rensink, R. A., O’Regan, J. K., and Clark, J. J. (1997). To See or Not to See. Psychological Science 8(5), 368-373.',
    file: 'public/strata/change-blindness/page-data.json',
    quote: '"mean_alternations": 1.4,',
  }),
  'wason-246': Object.freeze({
    figure: '6 of 29 right at the first announcement',
    gloss: 'A hidden rule, an example that fits, and as many tests as you like. Most people announced a rule that was true of every test they had bothered to run.',
    citation: 'Wason, P. C. (1960). On the failure to eliminate hypotheses in a conceptual task. Q. J. Exp. Psychol. 12(3), 129-140.',
    file: 'public/strata/wason-246/page-data.json',
    quote: '"printed_n": 29',
  }),
  'calibration-intervals': Object.freeze({
    figure: '43% coverage for ranges called 90%',
    gloss: 'Asked for intervals they were ninety percent sure of, people were right well under half the time. The page asks whether the way the endpoints are elicited changes that.',
    citation: 'Klayman, J., Soll, J. B., González-Vallejo, C., and Barlas, S. (1999). Overconfidence: It depends on how, what, and whom you ask. OBHDP 79(3), 216-247.',
    file: 'public/strata/calibration-intervals/page-data.json',
    quote: '"published_overall_coverage": 0.43',
  }),
  'coin-cant-fake': Object.freeze({
    figure: 'a median alternation rate of 0.59 against a coin’s 0.50',
    gloss: 'Across nine studies, people inventing random sequences switched sides far too often. This arm says out loud that it is a crowd that was told first.',
    citation: 'Falk, R. and Konold, C. (1997). Making sense of randomness. Psychological Review 104(2), 301-318, Table 1.',
    file: 'public/strata/the-coin-you-cant-fake/analysis.mjs',
    quote: 'median: 0.59',
  }),
  'wisdom-of-crowds': Object.freeze({
    figure: 'a crowd median of 1207 lb against an ox of 1198',
    gloss: 'Galton’s 787 legible tickets at a country fair. The living arm asks the narrower question of whether two guesses from one person beat one.',
    citation: 'Galton, F. (1907). Vox Populi. Nature 75, 7 March 1907, with the transcription corrections of Wallis (2014).',
    file: 'public/strata/wisdom-of-crowds/index.html',
    quote: 'OX_MED = 1207',
  }),
  'optional-stopping-spine': Object.freeze({
    figure: 'a 5% test that is really 14.2% after five looks',
    gloss: 'Stop a trial when the result first looks significant and the error rate is not the one printed on the test. This is the layer the other ten borrow their statistics from.',
    citation: 'Armitage, McPherson and Rowe (1969), as rendered in the 2024 Armitage Lecture; cross-checked against McPherson and Armitage (1971), Table 2.',
    file: 'public/strata/optional-stopping-spine/page-data.json',
    quote: '"0.142"',
  }),
  'anchoring-rct': Object.freeze({
    figure: 'medians of 25 and 45 from anchors of 10 and 65',
    gloss: 'A number spun on a wheel of fortune moved an estimate that had nothing to do with it. The live arm randomises which of two anchors you are shown.',
    citation: 'Tversky, A. and Kahneman, D. (1974). Judgment under Uncertainty. Science 185(4157), 1124-1131, p. 1128.',
    file: 'public/strata/anchoring-rct/page-data.json',
    quote: '"reported_median": 25',
  }),
  'guess-two-thirds': Object.freeze({
    figure: 'a first-round mean near 36.7, falling to single figures by round four',
    gloss: 'Guess two thirds of the average of everyone’s guess. The answer is not a number, it is how many steps ahead the room is thinking.',
    citation: 'Nagel, R. (1995). Unraveling in Guessing Games. American Economic Review 85(5), Table 1B, p. 1321.',
    file: 'public/strata/guess-two-thirds/page-data.json',
    quote: '"pooled_first_period_mean": "36.73"',
  }),
  'false-consensus': Object.freeze({
    figure: '65.7% against 48.5%',
    gloss: 'Whichever option you picked, you thought more other people picked it too. The two numbers are the same forecast made by the two groups.',
    citation: 'Ross, L., Greene, D., and House, P. (1977). The false consensus effect. J. Exp. Soc. Psychol. 13(3), Table 1, pp. 283-284.',
    file: 'public/strata/false-consensus/page-data.json',
    quote: '"correctTable1PrintedValues": [65.7, 48.5],',
  }),
  'focal-point': Object.freeze({
    figure: '36 of 42 chose heads',
    gloss: 'Asked to match a stranger they could not signal, people converged on the obvious. The page plays five such menus and asks whether models converge the same way.',
    citation: 'Schelling, T. C. (1960). The Strategy of Conflict, chapter 3, results footnote, p. 55.',
    file: 'public/strata/the-focal-point/analysis.mjs',
    quote: 'counts: Object.freeze([36, 6])',
  }),
});
