The internal servers have no access to outside package repositories and run Python 3.8/3.9, so the UI moves from hand-drawn curses to Textual 6.2.1 (the last release supporting 3.8.1), vendored with its pure-Python dependencies in vendor/. The launcher puts vendor/ first on sys.path, so a plain checkout runs with no pip and no network. - dsflow/: the single script split into a package (pure moves of the backend sections); action rules moved to ops.py, free of Textual - dsflow/ui/: tabs, detail pane, live sanity-run panel, log viewer, modal dialogs, filter, themes, mouse support - tests/test_ui.py: headless UI tests through Textual's pilot - tools/vendor.py (refresh vendor/), tools/screenshots.py (README images) - README, CLAUDE.md, TODO and the feature doc updated for the new layout, the Python 3.8.1 floor and the vendoring rules Verified: 11 tests green on Python 3.12 and 3.8.20; the shipped file set runs under `python -I -S` on both. Co-Authored-By: Claude Opus 5.5 <[email protected]>
194 lines
9.8 KiB
Markdown
194 lines
9.8 KiB
Markdown
# CLAUDE.md — rules for all agents working on dsflow_tui
|
||
|
||
dsflow_tui is a Textual TUI for the `dsflow` DesignSync check-in flow: it
|
||
lists a designer's changes and locks, runs sanity in a detached runner that
|
||
locks the files while it runs, and checks in or tags the result. It ships as
|
||
a self-contained checkout (dependencies vendored in `vendor/`) because the
|
||
internal servers have no access to outside package repositories. Read
|
||
`README.md` for usage and layout, and `TODO.md` for the backlog, before doing
|
||
anything. `files.zip` holds the original `dsflow` plan (bash `dsflow`,
|
||
`dsflow_ci`, `dsflow.conf`) this tool must stay compatible with.
|
||
|
||
## Hard invariants (never break these)
|
||
|
||
1. **Never leave a lock behind.** Every lock the runner takes is released
|
||
on pass, fail, cancel and runner error, and the TUI's lost-runner
|
||
cleanup (`x`) releases the rest. Locks the designer held before the run
|
||
are never released by it.
|
||
2. **Never check in untested content.** A check-in happens only after a
|
||
pass on every `SANITY_CONFIGS` entry, with the file contents unchanged
|
||
since the run started (sha1), nothing stale on Trunk, and the pass
|
||
younger than `MAX_STAMP_AGE`. When in doubt, refuse and say why.
|
||
3. **Never lose local edits.** No command the TUI issues may overwrite a
|
||
modified local copy. `ds_lock` takes the vault lock only; it never
|
||
fetches.
|
||
4. **All DesignSync access goes through the `ds_*` helpers** in
|
||
`dsflow.conf` or `BASH_DEFAULTS`. No `dssc` flags or output parsing in
|
||
Python. Site differences are fixed in the conf, not in the script.
|
||
5. **Stay compatible with bash `dsflow`.** Shared state keeps its format:
|
||
`.dsflow/new_files`, `.dsflow/sanity.stamp` (the hash must equal
|
||
`dsflow`'s `content_hash`), and the `CHECKIN_LOG` line format.
|
||
6. **The CI working tag is never moved by hand.** Only `dsflow_ci` moves
|
||
`WORKING_TAG`; the TUI filters it out of every tag list.
|
||
7. **The terminal status is written last.** Readers treat a terminal
|
||
`status` in `tui_job.json` as "locks are settled", so the runner saves it
|
||
only after lock release. History: the first version saved it before
|
||
releasing locks; the test suite caught the race (2026-09-23).
|
||
|
||
## Simplicity first
|
||
|
||
- Prefer the boring, obvious implementation. If you're building an
|
||
abstraction for a second user that doesn't exist yet, stop.
|
||
- **Nothing is installed at run time.** A plain checkout must run with no
|
||
pip, no virtualenv and no network. Runtime dependencies live only in
|
||
`vendor/`, pinned in `vendor/requirements.txt`, pure Python, licenses
|
||
kept. Adding or bumping one is a lead decision with a written reason in
|
||
the feature README; `tools/vendor.py` is the only way to change
|
||
`vendor/`. Never edit vendored code by hand.
|
||
- **Python 3.8.1 floor** (the oldest server Python). `vermin -t=3.8-` stays
|
||
clean, and the pins in `vendor/requirements.txt` must support 3.8.1:
|
||
Textual 6.2.1 is the last line that does. Only `dsflow/ui/` may import
|
||
Textual or Rich; the runner, `status` and `ops` stay standard library so
|
||
they keep working if the UI can't load.
|
||
- **Bash snippets run on bash 3.2** (macOS dev machines): no `mapfile`,
|
||
no associative arrays, no `${var,,}`.
|
||
- Small functions, descriptive names, shallow nesting. Code should be
|
||
readable top-to-bottom without jumping around.
|
||
- Match the style of the surrounding code (comment density, naming,
|
||
module layout).
|
||
|
||
## File and function size
|
||
|
||
- **Files: target 300–600 production lines.** At 800, split. A module has
|
||
to be describable in one sentence; several "and" clauses mean it wants
|
||
to be two modules.
|
||
- **Functions: 10–50 lines.** Investigate anything over 80; anything over
|
||
150 needs a reason in a comment.
|
||
- Looser for declarative tables and embedded fixtures (`FAKE_DSSC`,
|
||
`DEMO_CONF`, `styles.tcss`).
|
||
- A split is a **pure move**: behaviour and screen output identical, the
|
||
test count does not drop, all tests green.
|
||
|
||
Measured 2026-09-24 (non-blank, non-comment lines), after the move from one
|
||
file to the `dsflow/` package: `ui/app.py` 482, `ui/widgets.py` 380,
|
||
`runner.py` 317, `flow.py` 267, `demo.py` 243, `ui/dialogs.py` 189,
|
||
`ops.py` 102, `common.py` 100, `cli.py` 91. `ui/app.py` is the one to
|
||
watch: new actions go into `ops.py` (rules) and a dialog, not into the app.
|
||
Functions over 80: `Runner.execute` 99, the next pure-move candidate.
|
||
|
||
## Python standards
|
||
|
||
Before declaring any work finished:
|
||
|
||
- `python3 -m py_compile` clean on everything you touched
|
||
- `vermin --no-tips -t=3.8- --violations dsflow dsflow_tui.py tools tests`
|
||
clean (`pip install vermin` into a dev venv; never a runtime dependency)
|
||
- `tools/guard.py -- python3 -m unittest discover -s tests -v` green, on
|
||
the newest Python you have **and on a Python 3.8** (e.g.
|
||
`conda create -p <scratch>/py38 python=3.8`)
|
||
- `./dsflow_tui.py --demo --demo-reset` opened and driven by hand across
|
||
every tab you touched; for visual changes, regenerate
|
||
`docs/screenshots/` with `tools/screenshots.py` and look at them
|
||
|
||
Code rules:
|
||
|
||
- No bare `except:`. A broad `except Exception` needs a `# noqa` comment
|
||
that says why; the runner's is there so locks are always released.
|
||
- **Textual rules** (each one cost a bug on 2026-09-24):
|
||
- UI changes happen on the main thread. Workers hand results back with
|
||
`App.to_ui()`, which is a no-op once the app is shutting down.
|
||
- Don't name attributes after Textual's own: `auto_refresh`, `rows` and
|
||
`title` on the wrong class silently break the app.
|
||
- Event handlers use the widget references taken in `on_mount`, not DOM
|
||
queries; events can arrive while the app is tearing down.
|
||
- TabbedContent follows focus. Switching tabs from a dialog callback
|
||
must also move focus (`action_show_tab` does).
|
||
- Every `subprocess` that can run long gets `start_new_session=True` so
|
||
it can be killed as a process group.
|
||
- Public classes and non-obvious functions get a one-line docstring that
|
||
says what/why, not how.
|
||
|
||
## Document-based development
|
||
|
||
Every feature lives in `docs/features/<feature-name>/README.md`. That
|
||
README is the single source of truth for the feature and must contain
|
||
these sections:
|
||
|
||
```markdown
|
||
# <feature name>
|
||
## Goal — one paragraph, what and why
|
||
## Assumptions — everything you assumed that isn't enforced by code
|
||
(dssc behaviour above all: flags, output, lock rules)
|
||
## Handshakes — contracts with dsflow.conf, bash dsflow, dsflow_ci
|
||
and the job file: what you consume, what you promise
|
||
## Status / TODO — checklist; keep current as you work
|
||
## Work log — dated entries by the dev agent: what was done, key
|
||
decisions, deviations from plan
|
||
## QA log — dated entries by the QA agent: what was verified,
|
||
how, and findings
|
||
## Review — reserved for the lead; do not write here
|
||
```
|
||
|
||
Rules:
|
||
|
||
- **Dev agents**: create/update the feature README *as you work*, not at
|
||
the end. Finished TODOs get checked off in the same README. If you
|
||
change a handshake (a `ds_*` helper, the job-file schema, shared
|
||
`.dsflow/` state), say so explicitly in Handshakes and in the work log.
|
||
- **QA agents**: you verify, you don't redesign. Run the checks, try to
|
||
break the feature, record everything in the QA log. File concrete
|
||
findings (file:line, reproduction), not opinions. Small unambiguous
|
||
fixes (typos, a missing test assertion) you may fix directly and note.
|
||
- **Review section** is written only by the lead agent after examining
|
||
the work. Respond to review comments by fixing and logging in the work
|
||
log, not by editing the Review section.
|
||
|
||
## Workflow
|
||
|
||
- Do **not** run `git commit` or `git push`. The lead reviews and commits
|
||
all work.
|
||
- Do not touch files outside your feature's stated scope. If you need a
|
||
change elsewhere, write it as a request in your README's Handshakes
|
||
section and stop.
|
||
- New behavior needs tests in the same change. Anything touching the
|
||
runner, locking or check-in gets a `tests/test_runner.py` case that
|
||
proves invariants 1–3 still hold for it; a new key, dialog or tab gets a
|
||
`tests/test_ui.py` case driven through Textual's pilot.
|
||
- Update `TODO.md`: check items your feature completes (leave the item
|
||
text intact).
|
||
|
||
## Never touch a real vault; never leave processes behind
|
||
|
||
The runner starts detached processes that outlive the command that
|
||
spawned them, and every `dssc` call can change shared vault state.
|
||
|
||
- **Dev and QA work only against the demo sandbox** (`--demo`, or
|
||
`setup_demo()` in tests, in a temp or scratch directory). Running
|
||
against a real DesignSync workspace is a lead decision, made with a
|
||
designer, for the verification items in `TODO.md`.
|
||
- **Every test run and every scripted TUI drive goes through
|
||
`tools/guard.py [-t SECONDS] -- <command>`**: it kills the command's
|
||
process group after the limit (default 600 s) and exits non-zero if a
|
||
runner or `dsflow-tui` bash helper is still alive afterwards.
|
||
- A guard kill or a leak is a finding: report the command and what it
|
||
hit. Do not raise the limit or add sleeps to make it pass.
|
||
|
||
## The dev loop
|
||
|
||
Work runs **serially, one feature at a time, in one tree**:
|
||
|
||
1. **The lead plans**: writes the feature's section in `TODO.md` (each item
|
||
naming the functions or sections it touches) and a brief with the file
|
||
scope.
|
||
2. **One dev (Opus)** implements it, keeping the feature README current,
|
||
and stops when the Python standards above are met.
|
||
3. **One QA (Sonnet)** then verifies in the same tree: reruns every check,
|
||
tries to break the invariants (kill the runner mid-run, cancel during
|
||
lock, edit a file during sanity, stale a file on Trunk), and records
|
||
the QA log. Rework goes back to step 2 and to the same QA afterwards.
|
||
4. **The lead reviews**, writes the Review section, reruns the full checks
|
||
and commits.
|
||
|
||
Never two agents in the tree at once, and the next feature starts only
|
||
after the lead commits the previous one.
|