Command line
************

Run "psynet" commands in the experiment directory, with the
experiment's virtual environment active. "psynet <command> --help"
lists every option.

+-------------------------------------+-------------------------------------------------------------------+
| Command                             | What it does                                                      |
|=====================================|===================================================================|
| "psynet setup"                      | Prepare a standalone experiment: files, "constraints.txt",        |
|                                     | packages and Git (see Set up an experiment (setup)).              |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet services check" / "ensure"  | Check, or start in Docker, the local PostgreSQL and Redis, or     |
| / "list"                            | list which local sessions use them (see Local PostgreSQL and      |
|                                     | Redis (services)).                                                |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet scripts scaffold" /         | Create, refresh or remove boilerplate files (see Manage           |
| "update" / "prune"                  | experiment boilerplate (scripts)).                                |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet generate-constraints"       | Refresh "constraints.txt" after changing "requirements.txt".      |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet check-constraints"          | Check that "constraints.txt" is up to date with                   |
|                                     | "requirements.txt"; see Managing dependencies.                    |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet debug local"                | Run the experiment on your computer; see Running and debugging    |
|                                     | locally.                                                          |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet debug ssh --app NAME"       | Run a debug deployment on a server. It uses the configured        |
|                                     | recruiter, so pilot with "recruiter = generic"; see Running a     |
|                                     | study. Without "-- app", the app is named after the experiment    |
|                                     | directory.                                                        |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet deploy ssh --app NAME"      | Deploy the experiment for data collection; see Running a study.   |
|                                     | Without "--app", the app is named after the experiment directory. |
|                                     | "-- archive" redeploys from a previous export; see Deploying from |
|                                     | archive.                                                          |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet apps ssh"                   | List the apps on a server; see Setting up a server.               |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet hibernate ssh" / "psynet    | Put a deployed app to sleep or wake it; see SSH servers.          |
| awaken ssh"                         |                                                                   |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet destroy ssh"                | Remove one or more apps from a server; see Running a study.       |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet export local" / "ssh"       | Export the data to "exports/latest/"; see Exporting data.         |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet assets cache info" / "list" | Inspect or clear the local cache of exported asset files; see     |
| / "prune"                           | Exporting data.                                                   |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet test local"                 | Run the experiment's automated tests with bots; see Testing back- |
|                                     | end logic.                                                        |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet test ssh"                   | Run bots against a debug deployment (experimental); see Testing   |
|                                     | back- end logic.                                                  |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet performance-test local" /   | Measure how the server copes with many participants; see Testing  |
| "ssh"                               | scalability.                                                      |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet audit ..."                  | Create, validate and render the experiment audit; see Audit       |
|                                     | reference.                                                        |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet translate" / "psynet        | Machine-translate the experiment's text, or list the locales      |
| locales"                            | PsyNet supports; see Internationalization.                        |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet lucid ..."                  | Manage Cint (Lucid) surveys, costs and compensation; see CINT     |
|                                     | (Lucid).                                                          |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet estimate"                   | Estimate the completion time and maximum reward (see Estimate     |
|                                     | maximum reward and completion time (estimate)).                   |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet installation update"        | Update the installed PsyNet and Dallinger packages (see Update    |
|                                     | the PsyNet/Dallinger installation (installation update)).         |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet install autocomplete"       | Install shell tab completion (see Install shell completion        |
|                                     | (install autocomplete)).                                          |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet docs show PAGE" / "path"    | Print a documentation page for the installed PsyNet version, or   |
|                                     | the folder that holds every page, for searching (for example with |
|                                     | "rg -n -i --no-ignore "<term>" "$(psynet docs path)""). Page      |
|                                     | names are the website paths without ".html", such as              |
|                                     | "code/participants/payment".                                      |
+-------------------------------------+-------------------------------------------------------------------+
| "psynet docs demos"                 | Print the folder that holds the demos' code for the installed     |
|                                     | PsyNet version (see Demos). Release installs include the demos'   |
|                                     | code and text files, but not their media.                         |
+-------------------------------------+-------------------------------------------------------------------+

Bundled demos in the PsyNet repository use the repository's
development ".venv"; "psynet debug" and "psynet test" prepare their
boilerplate automatically. Standalone experiments have their own
".venv", prepared with "psynet setup".


Estimate maximum reward and completion time ("estimate")
========================================================

"psynet estimate" examines the timeline and estimates how long a
participant takes and how much they are paid as a result. It is
experimental and can be inaccurate for some timelines, so check the
estimates by piloting.


Experiment setup and boilerplate
================================


Set up an experiment ("setup")
------------------------------

"psynet setup" is the main path for a **standalone** experiment.
Install the thin PsyNet bootstrap package first ("uv pip install
psynet"), then run setup inside the experiment's dedicated active
virtual environment. In order it:

1. Scaffolds any missing standard experiment files and pins PsyNet. An
   existing bare "psynet" line in "requirements.txt" is pinned to
   "psynet[experiment]" at the active PsyNet installation *before*
   templates are written, so a failed pin never leaves a half-written
   scaffold; a "requirements.txt" created by the scaffold is pinned
   afterwards. (The "[experiment]" extra is the full runtime; a "bare"
   requirement is just the word "psynet" with no version, URL, or
   extras.)

2. Ensures "constraints.txt" (the locked dependency list): reuses it
   when it is already up to date with "requirements.txt" or was
   written by hand, otherwise regenerates it (same freshness rule as
   "psynet check-constraints").

3. Installs from "constraints.txt" with "uv pip sync" and verifies
   with "uv pip check".

4. Ensures the experiment has a Git repository for deployment. An
   experiment that already sits inside a repository uses it as-is; one
   that is not in a repository (or that its surrounding repository
   ignores) gets a dedicated repository via "git init". If Git is not
   installed, setup continues and asks you to install Git and run "git
   init" before debugging or deploying.

5. Softly checks local PostgreSQL/Redis (and may offer to start them
   with Docker). Missing services do not fail setup; use "psynet
   services ensure" if you want a hard guarantee before debugging.

   uv pip install "psynet==14.0.0rc4"
   psynet setup

Useful flags:

* "--no-install" — skip step 3: write files, pin PsyNet, ensure
  constraints and the Git repository, but do not install packages.
  After a full "psynet setup", use "psynet debug local --docker" or a
  Docker deploy command when you want Docker.

* "--force-shared-env" — allow installing into the PsyNet repository's
  development ".venv" (rarely what you want; can remove packages other
  PsyNet work depends on).

* "--force-foreign-env" — allow installing into a virtual environment
  that is not this experiment's "./.venv" (for example another
  project's environment). Prefer creating and activating "./.venv"
  instead.

* "--yes" / "-y" — set up the folder even if it contains files that
  don't belong to a PsyNet experiment.

If PsyNet is installed editable, setup asks how to record it in
"requirements.txt": keep the editable checkout, pin a specific pushed
Git commit URL, or retain an existing explicit requirement. The same
choice can be supplied non-interactively with "--psynet-source
editable", "commit", or "existing".

If Dallinger is installed editable, setup keeps it, except with "--
psynet-source commit"; see Using a local copy of PsyNet or Dallinger.

If the folder has no "experiment.py" and contains files that don't
belong to a PsyNet experiment, setup asks before adding experiment
files there. Without a terminal to ask in, it stops unless you pass "
--yes".

If the active virtual environment is the PsyNet repository's
development ".venv", setup refuses to install packages by default.
Interactively it offers a numeric menu: create a dedicated ".venv"
here (recommended), cancel, write files only, or install into the
repository ".venv" anyway.

If the active environment is some other foreign virtualenv (not this
experiment's "./.venv"), setup still scaffolds, writes constraints and
ensures the Git repository, but refuses to "uv pip sync" into that
environment unless you confirm interactively or pass "--force-foreign-
env". If you decline, setup prints the commands that create and use a
dedicated "./.venv" instead. Without a terminal to ask, it does the
same and exits with status 1.

In a demo inside a PsyNet source checkout, "psynet setup" only adds
the boilerplate files; it never installs packages or rewrites
requirements, so "--no-install" isn't needed. It then checks the local
services but doesn't offer to start them in Docker.


Local PostgreSQL and Redis ("services")
---------------------------------------

Virtualenv "psynet debug local" expects PostgreSQL and Redis on
localhost (Dallinger defaults: ports 5432 and 6379).

   psynet services check
   psynet services ensure
   psynet services ensure --yes

"check" only verifies connectivity and exits with an error if either
service is down. "ensure" does the same check, then offers to start
Docker containers that publish those host ports ("--yes" skips the
prompt). "psynet debug", "psynet deploy", and "psynet test local" call
"ensure" automatically before launch or packaging, including SSH
deployments that still prepare the experiment against local
Postgres/Redis on this machine.

When several experiments or test runs share a machine, "psynet
services list" shows the port, database, Redis server and directory of
each of your running sessions, read from your PsyNet, Dallinger and
pytest processes and the port locks they hold, followed by every local
Redis server and database and the session that uses it. Use it to pick
free settings before starting another session.

   psynet services list

Isolated test and debug sessions drop their own databases when they
end, so a "<database>_test_<port>" database (such as
"dallinger_test_5100") with no session is left over from a killed
session. Drop it with:

   PGPASSWORD=dallinger dropdb -h localhost -U dallinger dallinger_test_5100


Manage experiment boilerplate ("scripts")
-----------------------------------------

The "psynet scripts" group is for **file-level** control of standard
boilerplate (Dockerfile, "deploy.toml", "pytest.ini", "test.py", and
related templates). Prefer "psynet setup" when you also need a
dedicated constrained environment.

   psynet scripts --help


"scaffold"
~~~~~~~~~~

Create any missing PsyNet boilerplate files. Existing authored files
are left alone. For standalone experiments, also pins a bare "psynet"
requirement and generates "constraints.txt" when needed (unless "--
skip-constraints").

   psynet scripts scaffold
   psynet scripts scaffold --skip-constraints

After "--skip-constraints", run "psynet generate-constraints" before
"psynet debug local" or "psynet test local": both stop when a
standalone experiment has no "constraints.txt".


"update"
~~~~~~~~

Overwrite scaffold-managed boilerplate with the latest templates from
the installed PsyNet version. Existing "config.txt", "README.md", and
"deploy.toml" files are preserved. PsyNet-managed Agent Skills under
".cursor/skills/psynet" are refreshed; other skill directories under
".cursor/skills/" are preserved. Recognized generated "docker/" helper
scripts ("docker/psynet", "docker/run", and related files) are
deleted; customized helpers and other files under "docker/" are kept.
This is **not** "psynet installation update".

   psynet scripts update

"psynet update-scripts" remains as a deprecated alias for this
command.


"prune"
~~~~~~~

Remove scaffold-managed boilerplate and generated leftovers (a
"static/assets" link left by older PsyNet versions, untracked
"constraints.txt"), leaving authored files such as "experiment.py" and
"requirements.txt". A real "static/assets" file or directory is kept,
but the stock ".gitignore" and "deploy.toml" exclude it, so it is not
tracked or deployed.

By default only unmodified, untracked scaffold paths are removed. Git-
tracked managed paths are kept. "--include-modified" also removes
divergent untracked scaffold paths. "--include-tracked" also removes
git-tracked managed paths. If this directory is a git work tree but
tracked files cannot be listed, the command errors unless "--include-
tracked" is passed. Recognized generated "docker/" helper scripts are
deleted even if they are git-tracked. Customized copies are preserved.

   psynet scripts prune
   psynet scripts prune --include-modified
   psynet scripts prune --include-modified --include-tracked


Generate the constraints.txt file ("generate-constraints")
----------------------------------------------------------

Standalone experiments need a "constraints.txt" lockfile so installs
and deploys are reproducible. Prefer "psynet setup" when bootstrapping
an experiment; that command creates the lockfile for you.

Use "psynet generate-constraints" when you only need to refresh an
existing lockfile after changing "requirements.txt" (for example after
bumping the PsyNet version pin):

   psynet generate-constraints

This runs Dallinger's standalone constraints script via "uv run" (the
same lock policy as "dallinger constraints generate"). An installed
Dallinger, such as an editable checkout, supplies its local script;
otherwise PsyNet runs the canonical script from Dallinger's GitHub
repository. Either way, the Dallinger version in "constraints.txt"
comes from "requirements.txt" or PsyNet's Dallinger pin, not from the
installed copy.


Install PsyNet components ("install")
=====================================

Install additional PsyNet components and utilities.


Install shell completion ("install autocomplete")
-------------------------------------------------

Shell completion lets you press Tab to complete "psynet" commands,
subcommands and options, for example "psynet debug l<TAB>" becomes
"psynet debug local". This command detects your shell (bash or zsh),
writes a completion script to "~/.local/bin/", and adds a line that
loads it to "~/.bashrc" or "~/.zshrc":

   psynet install autocomplete

In an editable PsyNet installation, running
"./psynet/resources/scripts/install-completion.sh" from the PsyNet
directory does the same. Restart the terminal, or load the script
directly:

   source ~/.local/bin/.psynet-completion.bash  # for bash
   source ~/.local/bin/.psynet-completion.zsh   # for zsh

If completion doesn't work, check that the script exists ("ls
~/.local/bin/.psynet-completion.*"), that "~/.local/bin" and "psynet"
are on your "PATH", and that your shell configuration file contains
the "source" line above.


Update the PsyNet/Dallinger installation ("installation update")
================================================================

Note:

  The following command only applies if you have installed PsyNet in a
  local environment, rather than using Docker.

This command updates the local **installations** of PsyNet and
Dallinger (the packages in your environment). It does **not** refresh
experiment boilerplate files; use "psynet scripts update" for that.

While the default is to update both packages, they can also be set to
specific versions (e.g. downgraded) using the "--psynet-version" and "
--dallinger-version" command line options.

   psynet installation update

"psynet update" remains as a deprecated alias for this command.

**Usage**

   psynet installation update [OPTIONS]

   Options:
     --dallinger-version TEXT  The git branch, commit or tag of the Dallinger
                               version to install.
     --psynet-version TEXT     The git branch, commit or tag of the psynet
                               version to install.
     --verbose                 Verbose mode
     --help                    Show this message and exit.
