Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ High-signal context for OpenCode sessions in this repo.
## Architecture

- `inlayer.py` is the pipeline library module. It exposes a frozen `Config` dataclass plus pipeline functions (`apply_euler_rotation`, `prepare_figure`, `dilate`, `build_inlay`, `wall_thickness_stats_3d`; `arrange_footprints` is the layout `build_inlay` uses). All parameters flow through `Config`.
- `app_helpers.py` holds the **Streamlit-free** helpers of the web app (`file_hash`/`bytes_hash`, `quantize_axis_value`, `resolve_selection`, `applied_figure_params`, `figure_labels`, `load_preview_mesh`, `preview_copy`, `scene_layout`, `selection_key`, plus `decimate_mesh` re-exported from `inlayer`). `app.py` imports and thinly wraps them (caching decorators, session-state lookups). Reason: `app.py` calls `st.set_page_config()` and builds the whole sidebar at import time, so it cannot be imported in tests — anything pure belongs in `app_helpers.py` so the suite tests the shipped code instead of a copy. Do not re-inline this logic into `app.py`. (`tests/test_app_render.py` does run `app.py` through Streamlit's `AppTest`, which catches render errors — but that is an integration check, not a licence to move logic back into the frontend.)
- `inlayer_project.py` owns the strict, versioned JSON recipe shared by CLI and Web (format `inlayer-project`, version 1): every `Config` field, stable figure ids, full SHA-256 source identities and individual rotations, offsets and grip positions. It imports `Config`; `inlayer.main` imports it lazily to avoid a module cycle. Recipes contain no STL bytes. Matching is by full content hash, never name or upload order; CLI-relative paths start at the recipe directory. Figure offsets are additions to the global `Config.offset_*` and `effective_offsets` combines them exactly once. Web uploads have no persisted local path. Unknown fields and unsupported versions are errors, not migration guesses.
- `app_helpers.py` holds the **Streamlit-free** helpers of the web app (`file_hash`/`bytes_hash`, `quantize_axis_value`, `resolve_selection`, `applied_figure_params`, `project_session_state`, `project_widget_value`, `figure_labels`, `load_preview_mesh`, `preview_copy`, `scene_layout`, `selection_key`, plus `decimate_mesh` re-exported from `inlayer`). `app.py` imports and thinly wraps them (caching decorators, session-state lookups). Reason: `app.py` calls `st.set_page_config()` and builds the whole sidebar at import time, so it cannot be imported in tests — anything pure belongs in `app_helpers.py` so the suite tests the shipped code instead of a copy. Do not re-inline this logic into `app.py`. (`tests/test_app_render.py` does run `app.py` through Streamlit's `AppTest`, which catches render errors — but that is an integration check, not a licence to move logic back into the frontend.)
- `app.py` is a Streamlit frontend. It builds an `inlayer.Config` from the sidebar widgets and passes it into the pipeline functions (no global mutation). Its widgets start at `Config`'s defaults (`inlayer.Config.<field>`, read the way the CLI reads them), never at literals of their own: `tests/test_app_render.py` checks that the widgets start from `Config`'s values, `tests/test_pipeline.py::TestCLIDefaults` that the parser does. The same goes for a default quoted in a help text - pass it into the translation (`default=Config.<field>`), don't type it into `i18n.py`.
- `i18n.py` holds the **bilingual UI** (English/German). `t(key, **kwargs)` looks up `TRANSLATIONS` and fills named placeholders; unknown keys return the key itself rather than raising, so a missing string can never abort a running computation. Keys are namespaced `app.*` / `cli.*` / `pipeline.*` / `config.*` / `error.*` / `check.*` (wall-check findings, shared by CLI and app through `inlayer.describe_violation`).
- **The current language is a `ContextVar`, not a module global.** Streamlit runs each session's script in its own thread; a shared global would let one session's language selection bleed into another's. Do not "simplify" this into a plain variable.
Expand All @@ -48,6 +49,8 @@ High-signal context for OpenCode sessions in this repo.
- **`app.py`'s "all figures" sentinel stays untranslated.** `ALL_FIGURES` is a stored session-state value, not display text — translating it would invalidate the saved selection on a language switch. It is rendered through `format_func` (`_fig_label`) instead. The same applies to any option value that is persisted rather than merely shown - the figure options are upload ids for the same reason.
- **Every widget in `app.py` has a fixed, language-independent `key`.** Streamlit derives an unkeyed widget's identity from its label, which is translated: a language switch created new widgets, the uploads vanished and every setting fell back to its default. `tests/test_app_render.py` fails on a widget call without `key=`.
- **Per-figure settings belong to an upload (`UploadedFile.file_id`), not to a file name.** `fig_offsets_dict` is keyed by id; entries of removed uploads are deleted (re-uploading starts from the defaults), duplicate names are shown as `model.stl (2)` (`figure_labels`). Two different `model.stl` files used to share one entry and moved together.
- **Project ids and project hashes are not cache ids.** `project_session_state` maps persistent recipe ids to transient upload ids only once per changed import; `_project_id_by_file_id` retains them for later exports and `_fallback_project_id` identifies the fallback figure. Never serialize an upload id. The existing 16-character `content_hashes` still key caches and freshness; `_project_hash_by_file_id` and `_fallback_project_hash` hold separate full SHA-256 identities for recipes. `_current_config()` is shared by run and export; `_project_config()` additionally retains hidden multi-figure choices without changing the run.
- **Imported recipes are independent of widget limits.** `_project_config_base` retains the exact validated `Config`; `_project_config_edits` retains values from deliberate control edits, including while their widgets are hidden. `fig_offsets_dict` retains raw recipe figure values, with `_project_exact_figure_fields` protecting them from routine widget quantization. Controls receive separate editable projections through `project_widget_value`; a rerun, language switch or selection change must never replace exact imported values. Resolve the effective config before preparing, dilating, previewing, caching or taking a freshness snapshot. Preserve `None` for each automatic box/cylinder dimension and `figure_gap`. Combine global and individual offsets once for application; retain their separate raw values in recipe exports. Disabling manual offsets or rotations exports their effective zero values, since the recipe has no enable flag for them. Disabled recess values can remain raw because `Config.enable_finger_recesses` carries that state.
- **Selections and sliders are reconciled with the uploads before any widget exists.** All three per-figure controls (recess position, offsets, rotation) resolve their selection through `app_helpers.resolve_selection` and reload their widgets from the stored values whenever the figure they show changes - including a removed upload, a new first figure under "all figures" and widget state dropped while hidden. Don't go back to loading in the selectbox `on_change` only: that missed every change to the file list, and the sliders then showed values the pipeline did not use.
- **`app_helpers.applied_figure_params` is the only source of per-figure values.** The run, the instant preview and the staleness snapshot all read it - never a slider, which only shows the selected figure (reading the slider made a mere selection change look like a settings change).
- **New user-facing text needs both languages.** `tests/test_i18n.py` fails on a missing translation, on placeholders that differ between languages, on positional `{}` placeholders, and on keys referenced in source but absent from the table.
Expand All @@ -61,7 +64,7 @@ High-signal context for OpenCode sessions in this repo.
- **The wall check is exact and per figure (`_wall_check`).** Each cutter is clipped to the box with manifold3d: side and floor walls come from the pocket's bounds (for the cylinder: apothem minus the farthest vertex), walls between pockets from `min_gap`, sealed voids from negative-volume shells. Findings (`side`, `floor`, `inner`, `merged`, `sealed`, `no_cavity`) carry the figure index. `passes_min_wall` means *no finding at all*; `WALL_TOLERANCE_MM` (0.05) only absorbs float32 rounding and the cylinder's chord error. `wall_thickness_stats_3d(inlay)` just reports it - there is no voxel fallback for meshes that did not come out of `build_inlay`.
- **`build_inlay` never rotates.** Rotations are applied in step 1 via `apply_euler_rotation` and are already baked into the meshes handed to `build_inlay`. It used to accept an `individual_rotations` argument that was silently ignored — that parameter is gone; don't reintroduce it.
- There are **two entry points:**
- CLI: `python inlayer.py [-i figure.stl] [-o inlay.stl] [-c 0.4] [--lang de] …` — `--lang` is parsed *before* the main parser is built, because argparse renders help strings at construction time; `INLAYER_LANG` is the fallback.
- CLI: `python inlayer.py [-i figure.stl] [-o inlay.stl] [-c 0.4] [--project project.json] [--save-project project.json] [--lang de] …` — `--lang` is parsed *before* the main parser is built, because argparse renders help strings at construction time; `INLAYER_LANG` is the fallback. With `--project`, only input/output paths, `--save-project` and language may override the invocation; configuration flags are usage errors.
The CLI is `inlayer.main(argv)` (parser in `_build_parser()`) and returns its exit code; `__main__` is only `sys.exit(main())`. Keep it that way: code under `__main__` cannot be imported, so the tests could only start it as a subprocess and never looked at the STL it wrote.
- Web UI: `streamlit run app.py`

Expand Down
13 changes: 6 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ FROM base AS test

COPY requirements-dev.txt ./
RUN pip install --no-cache-dir -r requirements-dev.txt
COPY pytest.ini inlayer.py app.py app_helpers.py i18n.py ./
COPY pytest.ini inlayer.py inlayer_project.py app.py app_helpers.py i18n.py ./
COPY tests/ ./tests/
# tests/test_streamlit_config.py reads all of these: the config whose theme and
# upload limit it pins down, the Dockerfile itself to verify the runtime
Expand All @@ -39,14 +39,13 @@ COPY Dockerfile compose.yaml ./
RUN python -m pytest -q


# --- Laufzeit ---------------------------------------------------------------
# --- Runtime ---------------------------------------------------------------
FROM base AS runtime

# Anwendungscode kopieren
COPY inlayer.py app.py app_helpers.py i18n.py ./
# Streamlit-Konfiguration: das Custom-CSS in app.py ist auf das dunkle Theme
# ausgelegt. Ohne diese Datei faellt der Container auf das helle Standard-Theme
# zurueck und Sidebar-Beschriftungen werden unlesbar.
# Copy application modules explicitly, including the shared project format.
COPY inlayer.py inlayer_project.py app.py app_helpers.py i18n.py ./
# The custom CSS in app.py expects this dark theme. Omitting the configuration
# falls back to the light theme and makes sidebar labels unreadable.
COPY .streamlit/ ./.streamlit/

# Nicht als root laufen: der Container haengt am offenen Port und verarbeitet
Expand Down
Loading
Loading