Develop experiment front end
****************************

Note:

  This is an Agent Skill: a workflow written mainly for coding agents,
  and also useful as a checklist for people. PsyNet installs it into
  experiments at ".cursor/skills/psynet/develop-experiment-front-
  end/SKILL.md"; in Cursor, run "/develop-experiment-front-end". Edit
  it in the PsyNet repository at ".cursor/skills/experiment/develop-
  experiment-front-end/".


Read first
==========

Read these pages before acting. The "Documentation" section of the
experiment's "AGENTS.md" explains how to find and search them.

* Writing pages: pages, prompts, controls, validation, and timing
  within a page

* Control gallery: built-in controls

* Graphics: Native Graphics

* Event management: page events and the event log

* Custom front ends: custom prompts, controls, and pages, and their
  JavaScript lifecycle

* Theming: colors and layout tokens

* Testing back-end logic: how bots answer pages


Choose the lowest level that works
==================================

Work down this list and stop at the first level that can express the
design:

1. A "ModularPage" with built-in prompts and controls.

2. Native Graphics ("GraphicPrompt", "GraphicControl") for shapes,
   images, timed frame sequences, and clicks on objects.

3. A custom "Prompt" or "Control" on a "ModularPage".

4. A custom "Page" subclass with a template fragment.

For visual tasks (images, shapes, spatial clicks), record a Native
Graphics feasibility check in the plan before choosing custom
JavaScript: name the graphics objects and events you will use, or the
concrete requirement they cannot meet. Familiarity is not a reason to
write custom JavaScript.

Drive within-trial changes, such as enabling responses after a sound,
through page events rather than timers in custom code.

Find a demo to start from with "explore-psynet-repository/SKILL.md".
"demos/features/modular_page" shows custom prompts and controls, and
"demos/experiments/graphics" shows Native Graphics.


Bots on custom components
=========================

A custom "Page" or "Control" needs "get_bot_response". A plain return
value is stored as the final answer and skips "format_answer" (see
"How bots answer" in "test/backend"). Return
"BotResponse(raw_answer=...)" so bot data has the same shape as
browser data:

   from psynet.bot import BotResponse


   class ColorText(Control):
       def format_answer(self, raw_answer, **kwargs):
           return raw_answer.capitalize()

       def get_bot_response(self, experiment, bot, page, prompt):
           return BotResponse(raw_answer="hello")

Leave "session_id" at its default ("None") on repeated interactive
pages. Consecutive pages that share a "session_id" update in place and
fire "pageUpdated" instead of activating the page's JavaScript again.


Check custom components in the browser
======================================

For each custom component, build a minimal timeline and a Playwright
test ("playwright-testing/SKILL.md"). Take screenshots at key moments
and run the layout check before each one. Confirm that stimuli display
as intended, all text is visible, button layouts are intuitive, and
styling is consistent. Record video ("record-participant-
video/SKILL.md") only when screenshots cannot show the behavior,
because it is slow to review.


Rules
=====

* Use "KeyboardPushButtonControl" for keyboard responses rather than
  custom key handlers.

* Do not show non-participant-facing terms, such as calling display
  items "stimuli".

* Do not measure reaction time unless asked. When it is required,
  follow "Reaction time" in "psychophysics/SKILL.md".
