docs: AGENTS.md gains verification, deploy and frontend internals

Every claim below was checked against the code, not the prose:
- the commands that exist (npm build, uv run, health endpoints) and the
  ones that do not (no test runner, no lint script, the two test_*.py
  files are manual scripts)
- the isolated-data recipe: APP_DATA_DIR + copied app.db + symlinked
  media dirs, so a verification run never writes the live dataset
- the images bake the code in, so a frontend change needs a rebuild and
  a backend rebuild kills a running job
- frontend internals: hand-written hash router, vite /api proxy,
  db.py::migrate() as the only schema mechanism, and the system-text
  clipboard being a different thing from the editor's shape clipboard
Also fixed two stale AGENTS.md section pointers (7 -> 8) in design.md and
tasks.md.
This commit is contained in:
asus committed 2026-10-29 08:30:03 +07:00
1 parent d53e800fd2
commit 6f6a7f7caf
3 files changed
+90 -4

No files matched your search

+88 -2
View File
@@ -47,8 +47,9 @@ Turn tasks into verifiable goals, and for multi-step work state a brief plan:
2. [Step] → verify: [check]
```
This repo has no automated tests, so verification means **running something**: hit the
endpoint, run the job, look at the files it produced.
This repo has **no automated test suite** — no pytest, no vitest, no lint script. Verification
means **running something**: hit the endpoint, run the job, look at the files it produced.
§11 has the exact commands.
## 5. Chain of Truth — documents first, then code
@@ -59,6 +60,8 @@ endpoint, run the job, look at the files it produced.
| `docs/requirements.md` | Numbered `REQ-xxx` requirements. Changes only with the user's approval. |
| `docs/design.md` | Data schema, API contract, disk layout. Each section names the `REQ-xxx` it serves. |
| `docs/tasks.md` | Implementation steps + verification criteria, status `[TODO]`/`[DONE]`. |
| `docs/ui-spec.md` | The UI spec — §5 is the review editor, §6 the "never simplify away" rules, the last |
| | section is an Indonesian condensed spec. Read it before touching any screen. |
The rules:
@@ -69,6 +72,10 @@ in the same commit.
- If the implementation diverges from `docs/design.md`, update the design — never let a
document lie.
- Use relative paths in markdown (`./`, `../`), not absolute ones.
- `ERD.md` at the repo root is the hand-kept schema diagram — update it when `backend/db.py`
changes. The handover-PDF compilers (`build_publication_docs.py`, `verify_publication_docs.py`)
hardcode an old absolute path (`/home/asus/feedmill/reTraining`) and are not part of the app
pipeline — leave them alone unless the PDF is the task.
## 6. Repo rules
@@ -82,6 +89,8 @@ into smaller, logical modules.
dependency, not app code — don't add scripts there or edit anything inside it. It's
installed with `uv pip install -e ./sam3`.
- **Never write into the user's video archive.** All output goes under `data/`.
- **Frontend package manager: `npm`** (`npm ci` from `frontend/package-lock.json`, the same
thing `frontend/Dockerfile` does). The SPA has no test and no lint script.
- Secrets (`HF_TOKEN`) come from `.env` only; they never belong in code or docs.
## 7. Architecture
@@ -113,6 +122,23 @@ docs/ Chain of Truth: requirements, design, tasks, UI spec
- `backend/jobs.py` — single-threaded GPU-locked job worker (extract, autolabel, merge, train, count, clock-scan, truck-scan)
- `backend/sam3_engine.py` — SAM3 vision backbone, loaded once per process
- `backend/hardware.py` — GPU VRAM detection and training batch-size defaults
- `backend/db.py::migrate()` — the **only** schema-change mechanism: idempotent
`PRAGMA table_info` + conditional `ALTER TABLE`, run once in the FastAPI lifespan. No
migration tool, no Alembic.
**Frontend internals (no framework surprises):**
- `frontend/src/App.jsx` — hand-written **hash router** (`#/batches/{id}`,
`#/projects/{id}/batches`, …). There is no router library; a new page needs a case here.
- `frontend/src/api.js` — the only fetch layer.
- `frontend/vite.config.js` — dev proxy `/api` → `process.env.API_URL || http://localhost:8000`.
Every fetch stays same-origin, exactly like nginx serves it in Docker.
- `frontend/src/clipboard.js` — the **system text** clipboard (secure-context fallback for the
YAML paste dialog, the copy-path buttons). The review editor's *shape* clipboard
(`frontend/src/hooks/useShapeClipboard.js`) is editor-local and must never touch the system
clipboard.
- `frontend/src/geometry.js` — normalized (0–1) geometry helpers shared by the canvas and the
shape clipboard.
## 8. UI/UX
@@ -155,3 +181,63 @@ Don't restructure this into set_image-per-prompt.
- **Hardware Agnosticism:** Do not hardcode hardware requirements (e.g., GPU configurations in `docker-compose.yml`) directly into base configuration files. Instead, use dynamic startup scripts (like `start.sh`) or environment overrides to detect the host's capabilities and inject the appropriate settings automatically.
- **Portability:** The app must be fully deployable and scalable on any device (from a CPU-only laptop to a massive multi-GPU rig) without requiring manual code edits to run.
- **Dynamic Configuration:** Do not hardcode absolute IP addresses, local network paths, or machine-specific environment variables in code. Rely on relative paths and configuration files to ensure maximum scalability.
## 11. Verification — the commands that actually exist
There is no test runner. These are the checks, cheapest first:
```bash
npm --prefix frontend run build # the only frontend check that exists
uv run python -c "import backend.main" # backend imports (~3 s, pulls in torch)
curl http://localhost:9010/api/health # docker backend
curl http://localhost:8000/api/health # bare-metal backend
docker compose up -d --build # full stack
```
The two `test_*.py` files are **not** a suite: `backend/test_preview.py` needs a live server,
`algoritma-batch/test_batch_logic.py` needs real videos and model weights. Do not try to
"run the tests".
**Never verify against the live dataset.** `APP_DATA_DIR` moves the whole data root
(`backend/config.py`); `VIDEO_ARCHIVE` moves the video root the same way. To exercise a
change without writing a single row into the real DB:
```bash
mkdir -p /tmp/opencode/testdata
cp data/app.db /tmp/opencode/testdata/app.db
ln -s "$PWD/data/projects" /tmp/opencode/testdata/projects
ln -s "$PWD/data/base_models" /tmp/opencode/testdata/base_models
ln -s "$PWD/data/archive" /tmp/opencode/testdata/archive
APP_DATA_DIR=/tmp/opencode/testdata uv run uvicorn backend.main:app --port 8001
```
The symlinks keep frames and weights resolvable; only the DB is a copy. (Docker mounts
`./data:/data`, so the container always sees the live DB.)
**Browser behaviour needs a real browser.** Headless Firefox + geckodriver over the W3C
WebDriver protocol, driven with stdlib `urllib` — no selenium/playwright in this repo.
`geckodriver` is at `/snap/bin/geckodriver` on this host. Point the dev server at the test
backend first:
```bash
API_URL=http://127.0.0.1:8001 npm --prefix frontend run dev -- --port 5173
```
Harness scripts live outside the repo; `docs/tasks.md` names the ones used so far (e.g.
`/tmp/opencode/topbar_check.py`, `/tmp/opencode/shape_copy_check.py`).
## 12. Deploy — the images bake the code in
Nothing is mounted into the containers, so a code change is invisible until the image is
rebuilt:
- **Frontend** — the nginx image builds the SPA from `frontend/`:
`docker compose build frontend && docker compose up -d --no-deps frontend`, then hard-refresh
the browser. `--no-deps` keeps compose from touching the backend container.
- **Backend** — `docker compose build backend && docker compose up -d backend` **replaces the
container and kills a running job** (see `docs/tasks.md`, "Known open points").
- `start.sh` deletes and regenerates `docker-compose.override.yml` (GPU passthrough) on every
run — do not hand-edit that file.
- `scripts/restart_app.sh` restarts the bare-metal stack, but it puts the frontend on **:8080**
while `start.sh` and Vite's default are **:5173**. They disagree; pick one before writing a
URL into a test.
+1 -1
View File
@@ -316,7 +316,7 @@ form defaults only (REQ-062).
## Frontend
React + Vite, no heavy UI library; plain `fetch`, job polling once a second as today.
Design system and validation checklist follow ui-ux-pro-max — see `../AGENTS.md` §7.
Design system and validation checklist follow ui-ux-pro-max — see `../AGENTS.md` §8.
Design constraints specific to this app:
+1 -1
View File
@@ -46,7 +46,7 @@ Serves REQ-001…006.
- `backend/projects.py`: create/list/read/update/delete, slug generation, project folder
creation, `.pt` upload, class list read from `YOLO(path).names`.
- `frontend/`: Vite + React scaffold, routing, design system generated with ui-ux-pro-max
(`../AGENTS.md` §7) as tokens shared by every later page, Projects page with its form.
(`../AGENTS.md` §8) as tokens shared by every later page, Projects page with its form.
**Verify:** create a `sack` project with a real `.pt`; its classes appear
automatically and are read-only. `data/projects/sack/` exists on disk. Creating a