- README.md: usage, keys, how a sanity run works, config, demo command - CLAUDE.md: rules for agents, ported from verilogrustformatter with a single serial dev loop (lead plans, dev, QA, lead reviews) - tests/test_runner.py: stdlib unittest suite running the runner end to end against the demo sandbox (pass, fail, cancel, stale, stamp hash) - tools/guard.py: time limit plus leaked-process check for test runs - TODO.md and docs/features/dsflow-tui/README.md: backlog and feature doc Fixes found by the tests: - the fake dssc resolved paths wrong under symlinked dirs, breaking the default --demo location on macOS (/var -> /private/var) - the runner saved its terminal status before releasing locks, so the TUI could report a run finished while locks were still held Co-Authored-By: Claude Opus 5.5 <[email protected]>
181 lines
8.7 KiB
Markdown
181 lines
8.7 KiB
Markdown
# CLAUDE.md — rules for all agents working on dsflow_tui
|
||
|
||
dsflow_tui is a single-file curses 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.
|
||
Read `README.md` for usage 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.
|
||
- **Standard library only, Python 3.6 floor.** Designers copy one file
|
||
onto locked-down EDA hosts with no pip. No third-party imports in
|
||
`dsflow_tui.py`; `vermin -t=3.6-` must stay clean. Test tooling may use
|
||
more, but the tests themselves stay on `unittest`.
|
||
- **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,
|
||
section layout).
|
||
|
||
## File and function size
|
||
|
||
The tool ships as **one file on purpose**: one file is what gets copied
|
||
onto EDA hosts. So the unit a reader navigates is the **section**, the
|
||
banner-commented block (`# ---- Flow: ...`), not the file.
|
||
|
||
- **Sections: target 300–600 production lines.** A section has to be
|
||
describable in one sentence. Several "and" clauses mean it wants to be
|
||
two sections.
|
||
- **Functions: 10–50 lines.** Investigate anything over 80; anything over
|
||
150 needs a reason in a comment.
|
||
- Looser for declarative tables and embedded fixtures (`COLOR_SPEC`,
|
||
`FAKE_DSSC`, `DEMO_CONF`).
|
||
- A split is a **pure move**: behaviour and screen output identical, the
|
||
test count does not drop, all tests green.
|
||
- If the file itself becomes the problem, splitting into a package is a
|
||
lead decision: it breaks the "copy one file" deployment and needs a
|
||
zipapp or install story first.
|
||
|
||
Measured 2026-09-23 (non-blank, non-comment lines): file 2 219. Sections:
|
||
the app (`App`) 883, demo sandbox 238, Flow 228, Runner 304, form 164,
|
||
look & feel 158, the rest under 70. **`App` is over the mark**: split it
|
||
into views (drawing) and actions (dialogs and background work) before
|
||
adding a feature to it. Functions over 80: `Runner.execute` 99 and
|
||
`App.draw_files` 90, both candidates for the next pure move.
|
||
|
||
## Python standards
|
||
|
||
Before declaring any work finished:
|
||
|
||
- `python3 -m py_compile dsflow_tui.py` clean
|
||
- `vermin --no-tips -t=3.6- --violations dsflow_tui.py` clean
|
||
(`pip install vermin` into a dev venv; never a runtime dependency)
|
||
- `tools/guard.py -- python3 -m unittest discover -s tests -v` green
|
||
- `./dsflow_tui.py --demo --demo-reset` opened and driven by hand across
|
||
every tab you touched
|
||
|
||
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.
|
||
- Curses calls happen only on the main thread. Background threads change
|
||
plain attributes, and the next frame draws them.
|
||
- 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.
|
||
- 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.
|