Metadata-Version: 2.5
Name: shirdal-sentinel
Version: 1.2.0
Summary: Agentic browser testing: write test cards in plain English, Claude compiles them once, pytest replays them.
Project-URL: Homepage, https://github.com/AlirezaSoltaniJazi/shirdal-sentinel
Project-URL: Repository, https://github.com/AlirezaSoltaniJazi/shirdal-sentinel
Project-URL: Changelog, https://github.com/AlirezaSoltaniJazi/shirdal-sentinel/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/AlirezaSoltaniJazi/shirdal-sentinel/issues
Author: Alireza Soltani
License-Expression: MIT
License-File: LICENSE
Keywords: accessibility,ai,browser,end-to-end,localization,playwright,pytest,testing
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Environment :: Web Environment
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.14
Requires-Dist: axe-playwright-python>=0.1.4
Requires-Dist: cryptography>=46
Requires-Dist: faker>=40.63.0
Requires-Dist: nicegui>=2.0
Requires-Dist: openpyxl>=3.1.5
Requires-Dist: playwright>=1.50
Requires-Dist: pydantic>=2.9
Requires-Dist: pytest>=9.0.3
Requires-Dist: pyyaml>=6.0
Requires-Dist: tomlkit>=0.15.2
Description-Content-Type: text/markdown

# Sentinel

Browser tests written in plain English. Claude compiles each step **once**; after
that pytest replays the card with no AI and no tokens.

```
open the record shop                      navigate        no AI
search Box                                action          Claude, once
top 5 record titles should contain box    assert          Claude, once
no serious accessibility problems         accessibility   no AI
```

## Install

Sentinel is a Python package, [`shirdal-sentinel`](https://pypi.org/project/shirdal-sentinel/)
on PyPI. It needs Python 3.14 or newer. Add it to the project that holds your
tests, or to a new folder:

```bash
uv init my-tests && cd my-tests     # skip this in a project you already have
uv add shirdal-sentinel
uv run playwright install chromium  # the browser; add firefox or webkit if you need them

uv run sentinel init                # example cards in cards/, and what git must ignore
uv run sentinel ui                  # the web app on :8080, or the next free port
```

With pip it is `pip install shirdal-sentinel`, and the commands are the same
without `uv run`.

`sentinel init` changes nothing that is already there. It adds the example
cards to `cards/` (leave them out with `--no-examples`) and makes sure
`.gitignore` names what Sentinel writes and you must not commit: `.sentinel/`
(run data and saved variables), `cards/local/` (personal cards), `.env`
(secrets) and `.nicegui/`.

Your cards, run history and secrets live in your own project. Sentinel itself
is upgraded like any other dependency: `uv lock --upgrade-package
shirdal-sentinel && uv sync`. The **System** page says when a newer release is
out.

## Quick start

To work on Sentinel itself, clone this repository instead of installing the
package:

```bash
uv sync
uv run playwright install chromium firefox webkit   # Chrome and Edge are used if installed

uv run sentinel ui          # the web app on :8080, or the next free port
```

The web app also serves a small demo site on :8765, which the example cards run
against. To run those cards without the web app, for example with `pytest`,
start the site yourself with `uv run sentinel demo`. `uv run sentinel ui
--no-demo` leaves it out.

Open the **Example: Record shop demo** card and press **Run**. It is already compiled, so
it replays in about a second without calling Claude.

To try the AI part, add a step, pick its type, write what you want, and press
**Compile & run**. That needs the `claude` command on your PATH and signed in.

The web app has a **Guide** page that explains cards, recording, data rows and
accessibility checks in plain words.

## How it works

1. **You write a card.** A card is one test case: an ordered list of steps. Each
   step has a type and one line of text.
2. **Compile.** For an action or assert step, Sentinel runs the earlier steps,
   sends Claude a compact outline of the page (not the HTML, not a screenshot),
   and gets back which element and which verb or check. The answer is verified
   against the live page before it is accepted, then saved in the card file.
3. **Replay.** pytest runs the saved instructions with Playwright. Claude is
   called again only if you edit a step, or ask it to repair one.

The step type is what keeps token use low: it selects a small prompt and answer
schema, and two of the five types need no AI at all.

| Type | Example | Uses Claude |
|---|---|---|
| Navigate | `open example.com/login` | Never |
| Action | `search Box`, `click Sign in`, `choose Title in the sort menu` | Once |
| Assert | `top 5 record titles should contain box` | Once |
| Accessibility | `page meets WCAG 2.2 AA`, `no serious accessibility problems` | Never |
| Extract | `save the code, title and price of every record to stock.csv` | Once |

One step is one instruction. "Log in as admin" is three steps: fill, fill, click.

## Card types

When you create a card you choose how to write it.

**Steps.** The card described above: you write one step per line and pick its
type. It gives the most control and uses the fewest tokens.

**Free description.** You write the test in your own words:

```yaml
name: 'Example: Record shop, free description'
kind: free
start_url: http://127.0.0.1:8765
description: |
  Search for Box. The top 5 record titles should contain "box".
  Then show only records that are in stock and check that 5 records are listed.
```

On **Compile & run**, Claude works through the description on the real page, one
instruction at a time. Each instruction is verified, executed and saved as an
ordinary compiled step, so later runs replay it with no AI. Things to know:

- It costs more to compile than a step card: one Claude call per generated
  step, each carrying the whole description. The demo card above took seven
  steps and about $0.20 once.
- A check that fails is recorded and the rest of the description still runs, so
  the saved steps cover the whole description.
- If an action fails, or Claude cannot continue, the card stays uncompiled and
  the next compile starts again from the description.
- Editing the description (or the start URL) makes the steps stale; they are
  worked out again on the next compile.
- The steps are read-only. **Convert to a step card** in the card menu hands
  them over for editing by hand.
- Be exact about values and elements. "Check the results look right" gives
  Claude nothing to assert.

## Recording a flow

Instead of writing steps you can do the flow yourself and let Sentinel write
them. On the Cards page press **Record a flow**, or from the command line:

```bash
uv run sentinel record "Order a record" --url http://127.0.0.1:8765
uv run sentinel record "Check an order" --url example.com --profile work
```

A browser window opens with Playwright's recorder switched on. Every click,
typed text, chosen option and ticked box becomes a step. The small toolbar at
the top of the page adds checks: that an element is visible, what text it
shows, or what value it has. Close the browser window and the new card opens.

- **No AI is used.** Every step carries the locator the recorder found, as
  hand-written options, so the card replays at once with **Run**.
- The browser is the one a card would run in: the browser and device from the
  settings, and the saved profile you chose, already signed in.
- Enter pressed in a field you just filled becomes part of that step
  (`submit: true`), and the click that only put the cursor in a field is dropped.
- A password typed into a field named "password" is not saved. The step gets
  `{{password}}`, and the card a secret of that name, read from a variable
  named after the card: see "Secrets and variables". Other typed text is saved
  as you typed it.
- Only the first tab is recorded. Actions in another tab or window, file
  uploads and snapshot checks are left out, and the card's description says so.
- An element found inside another one, such as "the button in the row Beta",
  keeps the selector the recorder used, written as a `css` locator with `>>`
  between its parts.

Recording uses Playwright's own recorder, started through an internal call
that Playwright's Python package does not document. If a Playwright update
changes it, `sentinel record` says so and `tests/test_record_browser.py` fails.

## Permanent and personal cards, groups and favourites

**A new card is personal.** It is saved in `cards/local/`, a folder git never
sees, so it exists on your computer only. Each person can keep their own cards
without committing them.

**A permanent card is for everyone.** Turn on **Permanent card** when you create
a card, or later in its **Card settings**. Sentinel moves the file to `cards/`,
the folder you commit. Turn the switch off and the file goes back to
`cards/local/`. The card keeps its id, so its address and run history stay the
same. The example cards that come with Sentinel are permanent.

| | Folder | Committed |
|---|---|---|
| Personal card (default) | `cards/local/` | No |
| Permanent card | `cards/` | Yes |

A permanent card is part of your next commit. Check first that it holds no
password or private data: `uv run sentinel check` warns about steps that may
type a secret. Keep passwords out of the file with the card's **Secrets**: see
"Secrets and variables".

**Groups.** Give a card a **Group** in its settings. The board then shows a tab
for that group after **All**. A tab exists as long as a card is in the group.
The group is saved in the card file, so a permanent card brings its group along.

**The three-dot menu.** Every card on the board has one. From it you can add the
card to a group, remove it from its group, add or remove tags, and delete the
card, without opening it.

**Favourites.** Click the star on a card. Your favourites get their own tab.
They are saved in `.sentinel/favorites.json`, so they are yours alone.

**Search, sort and filter.** Above the cards of a tab there is a search box, a
sort order and rows of chips. The cards can be sorted by name, date created,
latest run, result, run time or number of steps. The button next to it says
which way they run, such as "Newest first", and a click turns the order round. Chips filter by the result of the latest
run, by tag, and by what a card is: permanent or personal, a free description,
needing a compile, having data rows, or checking accessibility. Result chips
and tag chips widen the choice (failed or stopped); the other chips narrow it.
Each chip shows how many cards of the tab are behind it. Your choice is kept
in the browser. "Date created" goes by when the card file was made.

Both folders can be changed in `pyproject.toml`:

```toml
[tool.sentinel]
cards_dir = "cards"              # permanent cards
local_cards_dir = "cards/local"  # personal cards
```

`uv run pytest cards` and `uv run sentinel run` run the cards of both folders.
On CI only the permanent cards exist.

## Data rows: one card, many values

Give a card a small table and it runs once for every row. Write the column
names as `{{column}}` placeholders where the values belong, in the description
of a free card or in the steps of a step card. As soon as a card uses a
placeholder, a **Data rows** table appears on its page with one column per
placeholder. Type the rows in, or use **Import CSV**: the file needs the column
names on its first line (commas, semicolons or tabs between values), and a
column matches a placeholder when the names agree apart from case, spaces and
punctuation, so `Music Genre` fills `{{music_genre}}`. Columns the card does
not use are left out, and entirely empty rows are dropped when the card is
saved.

```yaml
description: |-
  Open https://shop.example/window
  Click "New window item", type {{code}} into the Product field,
  select the record with the same code and click Save.
  Check that the message says: Saved {{code}}
data:
- {code: R-1002}
- {code: R-1005}
```

- **Cost:** Claude compiles the card with the first row only. The row's values
  are then swapped back for the placeholders, so every other row replays
  without AI.
- **Rows are independent:** a row that fails does not stop the rows after it.
  The run page and the pytest report group the steps by row.
- **No guessing:** an element that is only identified by a row's value, such as
  the matching entry of a lookup list, is found by that value alone. If the
  value matches nothing, or several entries, the step fails instead of acting
  on another entry.
- **Limits:** values shorter than 3 characters are not swapped back, and cards
  with data rows do not propose locator repairs.

### Filling in forms from data rows

A card that fills in a form usually has one column per field, and not every
row has something for every field.

- **A blank cell leaves the field alone.** Every step that uses that column is
  left out for that row and reported as "Left out". A step can name a column
  only in its wording ("open the {{country}} row") to tie it to that cell.
- **`<empty>` clears the field.** Use it in a cell when the value should be
  removed, not skipped. It works for text fields.
- **Dropdowns** are set with one `select` step, whether the page uses a real
  select or a button that opens a list of options. The option must have
  exactly the given label; if it is not offered, the step fails.
- **Checkboxes and switches** are set with `check` and a value: `Yes` ticks,
  `No` unticks, whatever the state was before.
- **Many columns:** write a step card with one step per field. Each step is
  compiled with its own column only, so "Box" as a unit never rewrites the
  field name "Pieces per Box".

```yaml
- type: action
  text: choose {{unit}} in the Units of Measure dropdown
  options:
    verb: select
    value: '{{unit}}'
    locator: {strategy: role, value: combobox, name: Units of Measure}
- type: action
  text: set the Open for Orders switch to {{orders}}
  options:
    verb: check
    value: '{{orders}}'
    locator: {strategy: role, value: switch, name: Open for Orders}
```

Steps written with a locator like these need no AI at all.

## Secrets and variables

A password, a key or a token does not belong in a card file. A card names its
secrets and the variable each one is read from, and nothing else:

```yaml
name: Shop sign in
secrets:
  password: SHOP_PASSWORD   # {{password}} in a step, read from SHOP_PASSWORD
steps:
  - type: action
    text: type {{password}} into Password
```

In the web app this is **Card settings › Secrets**: a name, the variable, and
whether the variable is set on this computer (never its value). When the card
runs, the value is looked for in three places, and the first that has it wins:

| Where | Good for |
|---|---|
| The environment of the shell: `export SHOP_PASSWORD=...` | CI, and one run with another value |
| A `.env` file next to `pyproject.toml`: `SHOP_PASSWORD=...` | Your own computer. Git ignores the file. |
| **Test data › Variables** in the web app | Values kept per environment, secrets encrypted |

- The value is put into a step only at the moment the step is carried out. It
  is never saved in the card, and Claude is never sent it: a step is compiled
  with `{{password}}` in it, and every value is taken out of what Claude is
  asked.
- Step texts, messages, the terminal, the event file and the run history show
  `••••••` in its place.
- A card whose secret has no value does not start: the run fails at once and
  names the variable.
- `uv run sentinel check` reports a card whose data rows still hold a column of
  a secret's name, and warns about a secret no step uses.
- Screenshots and videos show what the page shows. A password field shows
  dots; a secret typed into an ordinary field can be read in them.

### Variables per environment

**Test data › Variables** keeps values in the web app, one set per
environment. Pick environments from the list or type your own:

| Suggested | Also stands for |
|---|---|
| Development, Integration, Training, Demo, Sandbox, Security | |
| QA | Regression |
| Staging | Pre-prod, Release Candidate |
| UAT | Acceptance, Validation |
| Performance | Chaos |
| Beta | Canary |
| Production | Blue / Green, Mirror / Shadow |

One environment is the default: runs read it. Another one can be named for a
run:

```bash
uv run sentinel run --env UAT            # or: uv run pytest cards/ --sentinel-env UAT
SENTINEL_ENV=UAT uv run pytest cards/
```

Each variable has a name, a value and a **Secret** switch. A secret is saved
encrypted (Fernet: AES with an HMAC), is never shown again and is hidden in
runs. A variable that is not a secret, such as an address, is shown as it is.

Everything is saved in `.sentinel/variables.json`, which git ignores, so it
stays on your computer. The key that opens the secrets is kept in
`~/.sentinel/keys/`, outside the project: a copy of the project folder does
not carry it, and without it a secret has to be saved again. `SENTINEL_KEY`
can hold the key instead of the file. In CI, set environment variables of the
same names: they win over what is saved in the web app.

## Running cards

```bash
uv run pytest cards                         # replay everything, no AI
uv run pytest cards -m "smoke and not external"   # card tags are pytest markers
uv run pytest cards --sentinel-compile      # let Claude compile new or edited steps
uv run pytest cards --sentinel-heal         # let Claude repair broken locators
uv run pytest cards --sentinel-headless     # hide the browser for every card
uv run pytest cards --sentinel-headed       # show it for every card
uv run pytest cards --sentinel-browser firefox    # another browser for this session
uv run pytest cards --sentinel-device iphone-15   # another device for this session
uv run pytest cards/prices.card.yaml --sentinel-from-row 61   # start at data row 61
uv run pytest cards/prices.card.yaml --sentinel-rows 13,130   # only these data rows
uv run pytest cards --sentinel-accessibility wcag22aa   # also scan every page
uv run sentinel run record-shop-demo        # same thing, by card id
```

A step that is new or edited fails with "needs compiling" unless
`--sentinel-compile` is given, so a CI run can never spend tokens by accident.
The terminal summary shows the tokens and cost of every session.

### Pausing and stopping a run

While a card runs in the web app, its status line has **Pause** and **Stop**.
Both take effect before the next step, so the step in progress always
finishes first.

- **Pause** holds the run with the browser open; **Continue** goes on with the
  next step.
- **Stop** ends the run. The run still gets its report, marked *Stopped*, and
  the browser closes in the normal way, so a saved profile keeps its login.
- After stopping a card with data rows, **Continue from row N** starts a new
  run at the row that was interrupted. The ⋮ menu has **Run from a chosen
  row…** for starting anywhere.
- When rows failed, **Run the N failed rows again** replays just those rows.
  The ⋮ menu has the same action, taken from the card's latest run.

What a run saves, and when:

| What | When |
|---|---|
| Files written by extract steps | at once, step by step, into `.sentinel/exports/<card-id>/` and the run folder |
| Steps Claude compiled | when the row they were compiled on is done |
| Screenshots | at once |
| The run report (Runs page) | when the run ends or is stopped |

So stopping never loses files that were already saved. Only a run that is
killed from outside (the process ends, the computer sleeps) loses its report;
its files stay.

## Locator strategies

Claude only points at an element in the outline. Sentinel then builds the
locators itself, trying strategies in this order and keeping only those the live
page confirms match exactly that element:

`role` + name → `label` → `placeholder` → `alt` → `title` → `text` → `test_id` → `css` → `xpath`

The first survivor is the primary locator; up to nine others are stored as
fallbacks, ten in all. CSS and XPath can each contribute several: an id, a
`name` attribute, an `href`, hand-written class names, the element's own text
and its position are all different handles on the same element. You can:

- change the order for the project: `locator_order` under `[tool.sentinel]`;
- pin one strategy for a step: **Details → Locator strategy** in the web app,
  or `options: {strategy: css}` in the card file;
- write the locator yourself and skip Claude entirely:

```yaml
- type: assert
  text: the logo is shown
  options:
    check: visible
    locator: {strategy: css, value: "#logo"}
```

## Assertions

`visible` `hidden` `enabled` `disabled` `checked` `unchecked` `focused` `text`
`each_text` `count` `attribute` `css` `background_image` `value` `url` `title`

Values are compared with `contains` (default), `equals`, `regex`, `starts_with`,
`ends_with`, `at_least` or `at_most`; `negate` flips any check. Every assertion
retries until it holds or the timeout passes, and a failure reports what was
expected and what was actually on the page.

### Hard and soft checks

A check (an assert or accessibility step) is **hard** by default: when it
fails, the steps after it are skipped. Marked `soft: true`, its failure is
recorded and the run goes on, so one run reports every soft check that fails
and not only the first. The card fails either way.

```yaml
- type: assert
  text: the heading says Orders
  soft: true
  options:
    check: text
    expected: Orders
    locator: {strategy: css, value: h1}
```

In the web app the switch is under the step's **Details**. Keep a check hard
when the rest depends on it (the right page opened, the sign-in worked) and
make it soft when it can be wrong on its own (a label, a heading, a price).
`soft` is not part of what Claude compiled, so changing it never recompiles a
step. Only checks can be soft, and a check that could not run at all (it was
never compiled, say) stops the run even when it is soft.

## Accessibility

Accessibility is checked with [axe-core](https://github.com/dequelabs/axe-core),
which runs inside the page and needs no AI.

### Levels

WCAG has three levels, and each includes the ones below it: **A** (the
minimum), **AA** (what most laws and contracts ask for) and **AAA** (the
strictest). It also has versions, each of which keeps the rules of the ones
before. Every combination can be chosen:

| | A | AA | AAA |
|---|---|---|---|
| WCAG 2.0 | `wcag2a` | `wcag2aa` | `wcag2aaa` |
| WCAG 2.1 | `wcag21a` | `wcag21aa` (default) | `wcag21aaa` |
| WCAG 2.2 | `wcag22a` | `wcag22aa` | `wcag22aaa` |

`best-practice` runs axe-core's advice that is not part of WCAG.

A scan finds only what a tool can find. axe-core 4.12, the version bundled
today, has about 60 rules for level A, 7 for AA and 3 for AAA, so a passed AAA
scan covers a small part of what AAA asks for. It has no rules of its own for
2.2 A, whose scan is therefore the same as 2.1 A.

### An accessibility step

An Accessibility step scans the page at that point of the card. The wording
sets the standard and the severity that fails the step (`minor`, `moderate`,
`serious`, `critical`): `page meets WCAG 2.2 AAA`, `no serious accessibility
problems`. A missing version means 2.1 and a missing level means AA. In the web
app the step's **Details** have a select for the standard and one for what
fails. Options give finer control:

```yaml
- type: accessibility
  text: the checkout form is accessible
  options:
    standard: wcag22aa
    fail_on: serious
    scope: "#checkout"
    disabled_rules: [color-contrast]
```

### Checking while the card runs

A card can also have every run scan the pages it visits, with no step for it.
Switch on **Check accessibility while the card runs** in the card's settings,
or write it in the card file:

```yaml
accessibility:
  standard: wcag21aa      # any standard from the table above
  fail_on: serious        # default: minor, so any problem fails the card
  report_only: false      # true: list the problems, never fail
  scan: pages             # pages: each new page or screen. steps: also after
                          # every step that acts, which finds dialogs and is slower
```

- A page counts as new when its address, its title or its headings changed.
  That is looked at after every step, because the next page often arrives a
  moment after the click, while a check is already waiting for it.
- A problem fails the card, but its steps still run to the end.
- Each problem (one rule broken by one element) is reported once per run, even
  when its page is opened again for every data row.
- In reports the scans appear next to the step they came after, marked with a
  plus sign, and count on the dashboard like any accessibility step.
- The scans run when steps are replayed, not while Claude works out the steps
  of a free card.

To scan with any card without changing it:

```bash
uv run sentinel run my-card --accessibility wcag22aa
uv run pytest cards --sentinel-accessibility wcag21aaa
```

Each violation is reported with its severity, the affected elements and a link
to the fix.

## Localization

A card can be run once per language, with every page checked in each one. It
works like the accessibility scans: no step for it, no AI. Switch on **Check
localization** in the card's settings, or write it in the card file:

```yaml
localization:
  languages:            # the first one is what the others are compared with
    - code: en-GB       # how browsers know the language; sets dates and numbers
      key: en           # what the app itself calls it (default: the code)
    - code: de-DE
      key: de
    - code: fr-FR
      key: fr
  switch: storage       # browser (default), storage, cookie or query
  name: i18nextLng      # the storage key, cookie or query parameter
  quoted: false         # storage only. true: the value is kept in quotes ("de")
  check: [untranslated, content, format]   # default: all three
  report_only: false    # true: list the problems, never fail
  ignore: [Acme]        # texts that need no translation
```

Each language runs in a fresh browser whose own language is the code, so
nothing of the language before is left. On top of that, `switch` says where
the app keeps its language:

- `storage`: a value in the browser's localStorage, put there before any script
  of a page runs. Some apps keep it as JSON text, in quotes (`"de_DE"`), and
  ignore a value without them: set `quoted: true` for those.
- `cookie`: a cookie for the site of every Navigate step, set before the page
  is asked for. A site that picks its language on the server, as Django does
  with `django_language`, needs it with the very first request.
- `query`: a parameter added to the address of every Navigate step.

A step can also use `{{language}}` (the code) and `{{language_key}}` (the app's
name for it), for example to choose the language in a menu.

In the web app the languages are added from a list (`sentinel/languages.py`),
or by typing any other code a browser knows. **Value format** writes the app's
value for all of them in one way (`de_DE`, `de` or `de-DE`), and a single value
can be corrected in its box. The first language in the list is the reference.

A check whose expected text is wording, such as `the page says Sign in to your
account`, is written in the first language. In the other languages a check of
an element's text, of every text in a list or of the page title only asks that
there is some text, and its result says what it read. Values, counts,
attributes, addresses, codes and texts that come from a data row are compared
as always. To compare the wording in a language too, give the step that text:

```yaml
- type: assert
  text: the page says Sign in to your account
  options:
    check: text
    expected: Sign in to your account
    expected_in:          # by language code; "de" stands for every German
      de: Melden Sie sich bei Ihrem Konto an
      es: Inicia sesión en tu cuenta
    locator: {strategy: css, value: h1}
```

Mark such wording checks `soft: true`, so that one wrong text in a language
does not skip the checks after it.

A step that finds its element by wording (a role with a name, a label, a
text) cannot find it in another language: such steps need a locator that does
not depend on the language, such as a test id.

After every step that passes, the texts on the page are read: visible text,
and the placeholders, tooltips, image descriptions and screen-reader labels
written in attributes. Three levels of problem are reported:

| Level | Rule | What it finds |
|---|---|---|
| `untranslated` | `same-as-source` | a text that reads the same as in the first language |
| | `translation-key` | a key shown instead of a text: `order.state.label`, `LOGIN_TITLE` |
| `content` | `placeholder` | a placeholder that was not filled in: `{{name}}`, `{0}`, `%s` |
| | `broken-characters` | wrong text encoding: `GrÃ¶ÃŸe`, `�` |
| | `html-as-text` | `&amp;` or `<b>` shown as text |
| | `cut-off` | a button, link, label, heading or column title that does not fit |
| | `page-language` | the page's `lang` attribute names another language |
| `format` | `date-format` | a date in figures with the wrong separator or order |
| | `time-format` | AM or PM where the 24-hour clock is used |
| | `number-format` | the wrong decimal or thousands separator |

How a language writes dates and numbers is asked from the browser (`Intl`,
which carries the Unicode CLDR data), not kept in a table here.

- Each problem is reported once per language. In reports the checks appear
  under a heading per language, next to the step they came after.
- Text inside table cells counts as data and is not compared with the first
  language. Elements marked `translate="no"` are left out altogether.
- Icons drawn by an icon font (Material Symbols, Font Awesome) are written as
  their name, such as `expand_more`: they are left out. A label kept for
  screen readers only is read, but never reported as cut off.
- A text made only of `ignore` terms, numbers, addresses or words shorter than
  three letters is never "not translated".
- A number that can be read two ways (`1.234`) and the international date form
  (`2026-03-07`) are never reported.
- The check finds missing and broken text. It cannot judge whether a
  translation is good.
- With video recording on, the video kept is the one of the last language.

`cards/localization-demo.card.yaml` runs against a demo page whose German
version has one defect of every kind.

## Extract: saving a table to a file

An extract step reads every row of a table, an ARIA grid or a list and writes
the columns you name to a file. Claude only picks the table and the columns
once; the reading itself is plain code, so replays cost nothing.

- **Rows:** rows that only appear on scrolling are read by scrolling the table,
  and a "next page" button is followed until it is disabled or adds no rows.
- **Columns:** a name matches a header that equals it, starts with it or
  contains it, so `Product ID` finds `Product ID (Product)`.
- **Format:** the file extension decides: `.txt` (comma-separated lines, the
  default), `.csv`, `.tsv`, `.json` or `.xlsx`. An Excel file gets a bold header
  row that stays in view, a filter on every column, numbers as numbers and web
  addresses as links.
- **Where:** `.sentinel/runs/<run>/<file>` (linked from the run), and the
  latest copy in `.sentinel/exports/<card>/<file>`.

```yaml
- type: extract
  text: save the stock list
  options:
    locator: {strategy: css, value: '#stock'}
    columns: [Code, Title, Price]
    file: stock.csv
```

A step fails when a named column is missing, or when the table has no rows
(set `allow_empty: true` to accept that).

An extract can also save **the fields of a form**: one line per field, with its
label and its current value ("save all fields of the record as
`{{product}}.record.json`"). It reads text boxes, dropdowns, checkboxes and
switches, and on model-driven Power Apps (Dynamics 365) forms also lookups and
read-only values. In a card file this is `what: fields`.

### Search results and other repeated blocks

Search results are usually not a table: every result is a block of its own. With
`what: records` you say which block is one record and where each column's value
sits inside it. This is written by hand; Claude is not involved.

```yaml
- type: extract
  text: save the flats
  options:
    what: records
    locator: {strategy: css, value: '#results'}   # the element around all results
    row: article.result                            # one result
    cells:
      Site: =Demo lets                 # always this text
      Title: a.title                   # text of the first match in the result
      Link: a.title@href               # an attribute; a link comes out in full
      Id: '@data-id'                   # an attribute of the result itself
      Rent: .price || .cost | number   # first place that holds something; the number only
    file: flats.xlsx
```

A list that loads more results as you scroll is scrolled to its end, and a
`next_page` button is followed like for a table. If a pop-up opens over the
results and blocks that button, Escape is pressed and the click tried once more.

A records extract takes four more options:

| Option | What it does |
|---|---|
| `key: Id` | The column that tells results apart. A result that comes up again, for example as a featured copy, is saved once. Without a key, results that read exactly the same are saved once. |
| `drop_if: {Description: 'room to rent'}` | Leaves out results whose column matches the pattern (a regular expression, whatever the case). |
| `at_most: {Rent: 1600}` | Leaves out results whose column holds a larger number. A value that is not a number passes. |
| `append: true` | Adds to the file this run already saved, for a card that searches more than once, such as once per data row. A new run starts a new file. Needs `.xlsx`, `.csv`, `.tsv` or `.json`. |

### Typing key by key

`verb: type` presses the keys of a value one by one, starting in the field you
name. Use it for a value that is split over several one-character boxes, such as
a six-digit verification code: the page moves to the next box after each key,
which a normal `fill` does not trigger.

```yaml
- type: action
  text: type the code {{code}} into the code boxes
  options:
    verb: type
    locator: {strategy: css, value: '#otp-box-0'}
    value: '{{code}}'
```

### Actions on the browser itself

Some actions are not about an element. They need no locator and no AI, and the
card editor offers them as **Ready-made action** under a step's Details:

| Options | What it does |
|---|---|
| `verb: reload` | Refreshes the page (a soft refresh, as F5 does) |
| `verb: hard_reload` | Refreshes it without the browser's cache (a hard refresh) |
| `verb: clear_cookies` | Forgets every cookie; with `value: name`, only that one |
| `verb: network`, `value: offline` | Changes the connection: `strong`, `medium`, `weak` or `offline` |
| `verb: scroll_to`, `value: bottom` | Scrolls to the `top` or `bottom` of the page; with a locator, to that element |
| `verb: wait`, `value: 5` | Waits that many seconds |

### Waiting

- **Implicit wait.** Every step waits for its element, and every check waits
  to hold, for up to the step timeout: `[tool.sentinel.browser] timeout_ms`
  (10 seconds), or a card's own `session: {wait: 30}` in seconds.
- **Explicit wait.** One step can have its own time: `timeout: 60` on the
  step, in seconds. Use it for the one step that is slow, or to make a check
  give up sooner. It does not recompile a step.
- **Wait until.** An action that waits for an element to be `visible`,
  `hidden`, `enabled` or `disabled`:

  ```yaml
  - type: action
    text: wait until the spinner is gone
    timeout: 45
    options:
      verb: wait_until
      value: hidden
      locator: {strategy: css, value: .spinner}
  ```

  To wait for a text, a number of rows or an address, use an Assert step: it
  already waits until it holds.
- **Fixed wait.** `verb: wait` pauses for a number of seconds. Prefer the
  others: a fixed wait is either too short or wastes time.

### Steps that may have nothing to do

A hand-written action can be marked `optional: true`. When its element is not on
the page after five seconds, the step is left out and the run goes on. Use it for
things that only sometimes show, such as a cookie question:

```yaml
- type: action
  text: choose Reject all if the cookie question shows
  options:
    verb: click
    locator: {strategy: css, value: '#reject-all'}
    optional: true
```

### Skipping work that is already done

A hand-written check can be marked `skip_rest: true`. It then asks whether the
work of this row is already done. When the check holds within five seconds, the
steps after it are skipped for that row and the row counts as skipped, not as
failed; the card still passes. When it does not hold, the run goes on. Use it in
cards that add data, so a second run leaves alone what the first one added:

```yaml
- type: assert
  text: skip the row when the list already has product {{product}}
  options:
    check: visible
    locator: {strategy: css, value: '[role="row"]:has-text("{{product}}")'}
    skip_rest: true
```

Make the check look for the thing itself, not for a sign that it is missing. A
page that is slow or broken then goes on to the next step and fails there,
instead of being taken for work that is done. The card page and the run page say
how many rows were skipped, and "Run the rows that failed last time" leaves
them out.

## Comparing two systems

To check that one system holds the same data as another, and to bring it in
line where it does not:

1. **Read both.** Make two free cards with the same data rows, one per system,
   that open a record and save its fields as `{{product}}.<form>.json`. A row
   whose record does not exist fails.
2. **Compare.** `uv run sentinel compare <trusted-card> <other-card>` compares
   the files of the same name and prints which fields differ and which records
   the other system lacks. It writes `differences.csv`, and under `by-field`
   one small table per field with the columns `product`, `value` (what the
   trusted system has) and `current`. `--ignore "Created On" Owner` leaves
   fields out.
3. **Apply.** For each field that should be fixed, make a card that sets it,
   with `{{product}}` and `{{value}}` in its description, and import that
   field's table as its data rows. Nothing is changed until you run such a
   card, so the differences can be reviewed first.

The comparison is plain file reading: no browser, no AI.

## Browser, window and sessions

**Browser.** Chosen on the Settings page (or `[tool.sentinel.browser] name`),
and a card can take over the choice for itself (`session: {browser: edge}`):

| Name | Browser | Comes from |
|---|---|---|
| `chrome` (default) | Google Chrome | Installed on your computer |
| `edge` | Microsoft Edge | Installed on your computer |
| `firefox` | Firefox | Playwright's own build |
| `webkit` | Safari's engine, WebKit | Playwright's own build; not the Safari app itself |
| `chromium` | Chromium | Playwright's own build |
| `chrome-beta`, `chrome-canary`, `edge-beta`, `edge-dev` | The versions that come after the stable one | Installed on your computer |

Compiled steps are not tied to a browser, so the same card runs in all of them.
`uv run playwright install webkit firefox chromium` downloads Playwright's builds.

**Browser version.** A browser's version is the one that is installed. Chrome
and Edge run as they are on the computer, and their Beta, Dev and Canary
channels are browsers of their own in the list above. Chromium, Firefox and
WebKit come with Playwright, one fixed version per Playwright release (the
System page shows which). To run any other version, point
`[tool.sentinel.browser] executable_path` at that browser's program; it must be
of the same family as `name`.

**Device (responsive mode).** `device` and `landscape`: three desktop sizes and
a custom one, 41 phones and 6 tablets, from iPhone SE to iPhone 17 Pro Max and
from Pixel 5 to Pixel 10 Pro XL and the Galaxy S, A, Z and Tab lines. Phones
and tablets take the screen size, user agent, pixel density and touch input
from Playwright's device list, like Chrome's responsive mode. Firefox applies
the size, user agent and touch but cannot switch a page to its mobile layout.
A page needs a `<meta name="viewport">` tag to lay out at phone width, as on a
real phone. A card can have a device of its own (`session: {device: iphone-16}`).

**User agent.** `user_agent` replaces what the browser tells a site it is, for
the project or for one card (`session: {user_agent: "MyBot/1.0"}`).

**Internet connection.** `network`: `strong` (not slowed down, the default),
`medium` (1.6 Mbit/s, 150 ms delay), `weak` (500 kbit/s, 400 ms delay) or
`offline`. Offline works in every browser; slowing the connection down is
something only Chrome, Edge and Chromium can be told to do, and a run in
another browser says so and does not start. A step can change the connection
in the middle of a card (see "Actions on the browser itself").

**Window.** Each card chooses **Visible window (headed)**, the default, or
**Hidden (headless)** in its card settings (`session: {headless: true}` in the
file). `--sentinel-headless` and `--sentinel-headed` override every card for
one session. On a machine with no screen, such as CI, cards always run
headless.

**Session.** A card runs in a **clean session** by default: a throwaway profile
with no cookies. To test behind a login, create a **saved profile** on the
Profiles page (or `uv run sentinel profile open work --url https://example.com/login`),
sign in by hand, close the window, and select the profile in the card settings.
A profile's **start page** is saved with it and opens every time you open the
profile's browser. The name and start page can be changed later on the Profiles
page: each profile is stored under a fixed id, so renaming keeps its logins and
the cards that use it. Logins are kept separately for each browser. Sentinel also keeps the profile's
session cookies, which a browser normally forgets when it quits, so sign-ins
that live only in those survive until the site itself ends the session.

## Evidence: screenshots and video

Set on the Settings page (or under `[tool.sentinel.capture]`):

- **Screenshots:** only when a step fails (default), or after every step.
- **Video:** record every run as `video.webm`.

A card can decide about video for itself: **Video recording** in its card
settings is **As in Settings**, **Always record** or **Never record**
(`session: {video: true}` or `false` in the file). Use it to record one card
without recording all of them, or to keep one card out of the recordings.

Both are shown on the run's page and stored under `.sentinel/runs/<run id>/`.

## Test data

The **Test data** page has two tabs. **Variables** keeps values per
environment: see "Secrets and variables". **Made-up person** makes up a person
for filling in forms: first and last
name, phone number (with and without the country's code), address, city, postal
code, region, e-mail address, date of birth, a UUID and a random number of a
length you choose, each with a Copy button. Names and addresses come from the
Faker library and look as they do in the chosen country; 35 countries are
offered, the ones Faker has addresses and phone numbers of their own for.
E-mail addresses use `example.com`, a domain kept for examples, unless you give
your own. Phone numbers follow the country's pattern but are not checked
against a real numbering plan.

## Search and filters

**Search** in the top bar looks through cards (name, group, tags, description,
step texts), the sections of the guide, the pages of the app and the saved
profiles. Enter opens the first thing found.

The Runs page filters by card, result, period, and by runs that were repaired,
used Claude, have a video or ran in several languages. The Locators page
filters by card, step, page or locator, and by status. The Dashboard can be
narrowed to a group, to tags or to cards by name. The Profiles page filters by
name, start page, and whether a card uses the profile.

## Dashboard

The Dashboard page summarises the last 7, 30 or 90 days: number of runs, pass
rate against the previous period, average run time, Claude spend, runs per day
by result, a health table per card (pass rate, Claude spend, recent results, a
*Flaky* mark when results keep flipping), the steps that stop runs most often,
and the accessibility rules broken most often.

The card table starts with the card that ran last on top. Click a column title
to sort by it, and click it again to turn the order round; the choice is
remembered.

Token use and cost are recorded for every run: on the Runs list, on the run's
page (per step that was compiled), in the card's status bar after a run, and in
pytest's terminal summary. A replay shows no cost because it calls no AI.

## Self-healing

When a primary locator stops matching, the fallbacks are tried and the step is
reported as *healed* rather than passing silently. No AI is involved: the
element is on the page, so Sentinel works out a fresh set of locators for it
and saves that as a **proposed** change. The card is not touched.

Proposed changes are listed on the **Locators** page (and by
`uv run sentinel locators`) as a diff: locators added, kept and removed, plus
what changed on the element itself, such as its text or id. **Approve** writes
the new locators into the card; **Reject** keeps the old ones and the same
change is not proposed again.

```bash
uv run sentinel locators                # what is waiting
uv run sentinel locators approve 3      # or: approve all
uv run sentinel locators reject 3
```

Every version of every element is kept in `.sentinel/locators.db`, a small
document store: the page (origin and path), the element (tag, text, id, test id,
classes and so on) and its ranked locators. The card file stays the source of
truth for replays, so CI and teammates need nothing but the cards.

If every locator is dead, the step fails; with `--sentinel-heal` Claude finds
the element again, the step is retried, and it is marked **Review** until
someone approves the new locator.

## Cost

Measured on the demo card with the Claude CLI's default model at the time
(Opus 5.5): about 2,300–3,000 input and 170–300 output tokens per compiled
step, roughly $0.015–0.02. Replays cost nothing. To spend less, set a smaller
model:

```toml
[tool.sentinel.claude]
model = "haiku"
```

## Settings

All settings live under `[tool.sentinel]` in `pyproject.toml`, so the web app,
pytest and CI share them. The Settings page edits the common ones (browser and
its program, device and window size, the implicit wait, internet connection,
user agent, screenshots, video, Claude model, effort, budget cap, outline size)
and writes them back to that file, leaving the rest of it alone. A card can
take over the browser, device, connection, wait and user agent for itself.

## Versions and releases

Sentinel has one version, written in `pyproject.toml` and read from there by
`sentinel --version`, by `sentinel.__version__` and by the **System** page.
The numbers are `MAJOR.MINOR.PATCH`: the first changes when cards written for
the version before stop working, the second when something is added, the third
when something is only fixed.

Nobody raises the version by hand. A release is made by a pull request:

1. In the pull request, write what changed under `## [Unreleased]` at the top
   of `CHANGELOG.md`.
2. Give the pull request one label: `release:patch`, `release:minor` or
   `release:major`.
3. Merge it into `main`.

The **Bump Version & Release** workflow then does the rest: it raises the
version in `pyproject.toml` and `uv.lock`, turns `[Unreleased]` into the new
version with today's date, commits that to `main`, tags the commit (`v1.2.0`)
and publishes a GitHub Release whose notes are that section of the changelog.
Then it builds the package from the tag, checks that it installs and runs in
an empty folder, publishes it to PyPI and attaches the built files to the
GitHub Release.
A pull request without a release label is merged without a release, and its
changelog lines wait under `[Unreleased]` for the next one. The workflow can
also be started by hand from the Actions tab.

| Workflow | When | What it does |
|---|---|---|
| `bump-version.yml` | A labelled pull request is merged, or by hand | Version, changelog, tag, GitHub Release, package on PyPI |
| `pr-version-check.yml` | Every pull request | Fails if the version would go backwards |
| `auto-assign-author.yml` | A pull request is opened | Assigns it to its author |
| `tests.yml` | Every pull request and push to `main` | Style, lint, security checks, the full tests, the example cards, a fresh install of the built package |

**Publishing to PyPI stores no password or token.** PyPI is told once, under
the project's *Publishing* settings, to trust this repository's
`bump-version.yml` workflow in the `pypi` environment ("trusted publishing").
The workflow then proves who it is with a short-lived identity from GitHub.
If the publish job fails, fix the cause and press **Re-run failed jobs**: the
version is not raised a second time.

The package holds the code, the guide, the demo site, the changelog and the
example cards. The example cards are named one by one in `pyproject.toml`, so
that nothing from `cards/local/` can ever be taken along; a test fails when a
new example card is not added there.

A released version can also be installed straight from its tag:

```bash
uv add "git+https://github.com/AlirezaSoltaniJazi/shirdal-sentinel@v1.1.0"
```

The System page also lists the versions of Playwright, pytest and the other
libraries, of the browsers, of Python and of the Claude command, and its
**Check for newer versions** button asks the Python package index for the
newest release of each library. Only the library's name is sent.

## Limits

- Sites with bot protection may block automated browsers. DuckDuckGo refuses
  a headless browser (error 418) but works in a visible one, so keep the
  bundled DuckDuckGo card headed. Google serves a CAPTCHA either way.
- The page outline sent to Claude grows with the page. A heavy page such as a
  search results page can reach the `snapshot_max_chars` cap (about 12,000
  input tokens per compiled step). To keep it small, wrappers that carry no
  meaning are left out and a long table shows its first 5 rows cell by cell,
  the next 40 as one line each, and the rest as a count. A step that must act
  on a row further down needs the table filtered or searched first.
- The page outline covers the main document, open shadow DOM and visible
  iframes (up to 8 frames, 3 levels deep). A locator inside a frame carries a
  `frame:` list of iframe selectors. Accessibility scans still cover the main
  document only.
- Safari is tested through WebKit, its engine. The Safari app itself, and
  Internet Explorer, cannot be driven.
- A browser's version cannot be picked from a list: see "Browser version".

## Layout

```
src/sentinel/
  models.py          card, step and compiled-instruction models
  cards.py           reading and writing *.card.yaml, permanent and personal
  accessibility.py   the WCAG versions and levels a scan can check
  testdata.py        made-up people and addresses for the Test data page
  project.py         sets up a new project: example cards, .gitignore
  secrets.py         a card's secrets: read when it runs, hidden in reports
  variables.py       variables per environment, secrets encrypted
  system_info.py     the versions of Sentinel, its libraries and the browsers
  localization.py    finds localization problems in the texts of a page
  languages.py       the languages offered for localization checks
  recording.py       turns a recorded flow into the steps of a card
  favorites.py       the cards you starred
  demo.py            serves the demo site
  engine/            driver (Playwright), locators, executor, runner, sessions
  compiler/          Claude CLI adapter, prompts, compiler
  pytest_plugin.py   collects cards as pytest tests
  check.py           static card checks for the pre-commit hook
  runs.py            run history (SQLite)
  reports.py         numbers behind the dashboard
  ui/                web app (NiceGUI)
  demo_site/         pages used by the demo cards and the tests
cards/               permanent cards, committed (the examples live here)
cards/local/         your personal cards, never committed
tests/               unit and real-browser tests
CHANGELOG.md         what changed in every release
.github/workflows/   tests, the version check and the release workflow
```

The engine talks to the browser only through the `BrowserDriver` interface in
`engine/driver.py`, so the browser layer can be replaced without touching
cards, the compiler or the web app.

## Checks before commit and push

```bash
uv run pre-commit install     # once per clone
```

| When | What runs |
|---|---|
| Every commit | Whitespace and file hygiene, YAML/TOML syntax, merge-conflict markers, large files, private keys, leftover `breakpoint()` calls; `uv.lock` in sync; autoflake, Black, pylint; Bandit (high severity); `sentinel check` on changed cards; the fast tests |
| Every push | The full test suite in a real browser; `pip-audit` for known vulnerabilities in dependencies |

`sentinel check` blocks a commit when a card file is invalid, has an empty step
or duplicate step ids, names no profile in profile mode, or contains a step that
Claude repaired and nobody has reviewed. It warns, without blocking, about
uncompiled steps, a card that does not start with a navigate step, and a typed
value that looks like a secret.

```bash
uv run sentinel check                                        # all cards
uv run pre-commit run --all-files                            # commit checks
uv run pre-commit run --all-files --hook-stage pre-push      # push checks
uv run pytest tests                                          # about 580 tests, about 7 minutes
```
