DecodeMarketing commited on
Commit
975d390
·
unverified ·
1 Parent(s): 7a5c442

[ai-standards][slice-2] structure and dependency reproducibility (#9)

Browse files

Adds dependency reproducibility artifacts and policy/runbook documentation
per the shrunken slice-2 plan (workflow hardening deferred to a later slice
on user instruction to keep deploy risk at zero for this slice).

Artifacts:
- pyproject.toml (PEP 621 metadata; no [project.dependencies] to avoid
drift; requirements.txt remains the source of truth consumed by HF Spaces)
- requirements.lock (47 packages, autogenerated by
`uv pip compile --python-version=3.12 requirements.txt`)
- .python-version (3.12; matches runtime.txt and HF Spaces)
- .env.example (comment-only; declares no local env vars; documents
HF_TOKEN as a GitHub Actions secret consumed only by main.yml)
- docs/policies/naming-conventions.md (tab<N>.py rule, helper.py role,
what we explicitly do NOT do)
- docs/policies/root-artifact-policy.md (what is tracked at root, what is
gitignored, what is tolerated locally)
- docs/runbooks/local-setup.md (Windows / macOS / Linux setup walkthrough,
troubleshooting table)
- docs/INDEX.md (link the three new docs under new ## policies and
## runbooks sections; remove their entries from the "planned" stub)

Out of scope (deferred):
- Workflow SHA pinning + permissions blocks on main.yml, gate.yml,
check-file-size.yml — deferred to a later slice because main.yml is the
HF deploy pipeline and deserves its own focused PR + verification cycle
- .gitignore additions for .ruff_cache/, .venv/, .pytest_cache/ — deferred

No changes to app code (app.py, helper.py, tab1.py-tab8.py), requirements.txt,
runtime.txt, .streamlit/, .devcontainer/, existing workflows, existing
.githooks/, existing .claude/, CLAUDE.md, or .gitignore. HF Spaces deploy
is a no-op for this slice because no runtime file is touched.

Refs decode-ai-standards@81c3f17.

.env.example ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # icat_app — environment variables
2
+ #
3
+ # Local development requires NO environment variables.
4
+ # All user input (Excel files, images, ZIPs) is uploaded via the Streamlit UI at runtime.
5
+ #
6
+ # Hugging Face Spaces deploy uses HF_TOKEN, which is stored as a GitHub Actions
7
+ # secret and consumed only by .github/workflows/main.yml. It is NOT needed for
8
+ # local development and MUST NOT be committed to the repo. See SECURITY.md for
9
+ # the secrets policy.
10
+ #
11
+ # This file is intentionally checked in as a reference. It does not need to be
12
+ # copied to a local `.env` for the app to work.
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.12
docs/INDEX.md CHANGED
@@ -19,15 +19,21 @@ This tree is for **human + AI contributors**. Operational base rules live in `/C
19
  - [`guides/protected-boundary-policy.md`](guides/protected-boundary-policy.md) — push-to-main = HF Space deploy; rules around touching the deploy boundary.
20
  - [`guides/git-and-pr-rules.md`](guides/git-and-pr-rules.md) — observed branch state, default flow, PR target.
21
 
 
 
 
 
 
 
 
 
 
22
  ## progress
23
 
24
  - [`progress/slice-integration-overview.md`](progress/slice-integration-overview.md) — tracker for the decode-ai-standards remediation slices.
25
 
26
  ## not yet present (planned)
27
 
28
- - `policies/naming-conventions.md` — slice 2.
29
- - `policies/root-artifact-policy.md` — slice 2.
30
- - `runbooks/local-setup.md` — slice 2.
31
  - `guides/ci-failure-triage.md` — slice 3.
32
  - `guides/ai-enablement-limits.md` — slice 3.
33
  - `reference/agent-guide.md` — slice 3.
 
19
  - [`guides/protected-boundary-policy.md`](guides/protected-boundary-policy.md) — push-to-main = HF Space deploy; rules around touching the deploy boundary.
20
  - [`guides/git-and-pr-rules.md`](guides/git-and-pr-rules.md) — observed branch state, default flow, PR target.
21
 
22
+ ## policies
23
+
24
+ - [`policies/naming-conventions.md`](policies/naming-conventions.md) — `tab<N>.py` rule, `helper.py` role, what we do NOT do.
25
+ - [`policies/root-artifact-policy.md`](policies/root-artifact-policy.md) — what is tracked at root, what is gitignored, what is tolerated locally.
26
+
27
+ ## runbooks
28
+
29
+ - [`runbooks/local-setup.md`](runbooks/local-setup.md) — Windows / macOS / Linux setup walkthrough, troubleshooting table.
30
+
31
  ## progress
32
 
33
  - [`progress/slice-integration-overview.md`](progress/slice-integration-overview.md) — tracker for the decode-ai-standards remediation slices.
34
 
35
  ## not yet present (planned)
36
 
 
 
 
37
  - `guides/ci-failure-triage.md` — slice 3.
38
  - `guides/ai-enablement-limits.md` — slice 3.
39
  - `reference/agent-guide.md` — slice 3.
docs/policies/naming-conventions.md ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Naming conventions
2
+
3
+ This document records the naming rules already in force in icat_app so that new
4
+ contributors (human or agent) do not invent conflicting patterns.
5
+
6
+ ## Tab files: `tab<N>.py`
7
+
8
+ - Each Streamlit tab lives in its own file at the repository root.
9
+ - The filename pattern is `tab<N>.py` where `<N>` is the positional tab index in
10
+ the UI (1-based). The order in `app.py` controls visual order.
11
+ - A new tool gets a new tab file (`tab9.py`, etc.). **Do not** inline a new tool
12
+ into `app.py` or into an existing `tab<N>.py`.
13
+ - Tabs must not import each other. Anything shared belongs in `helper.py`.
14
+
15
+ ## Shared helpers: `helper.py`
16
+
17
+ - `helper.py` is the single shared utility module for all tabs.
18
+ - Function names are `snake_case` and verb-first (`extract_images`,
19
+ `rename_assets`, `pdf_overview`, `place_on_canvas`).
20
+ - A future architectural split of `helper.py` (e.g. `helper/io.py`,
21
+ `helper/pdf.py`) is recorded as a deferred follow-up in
22
+ `docs/progress/slice-integration-overview.md`. Do not start such a split
23
+ without opening a dedicated architecture slice — the current file is imported
24
+ by all 8 tabs and the blast radius is wide.
25
+
26
+ ## Top-level files
27
+
28
+ - `app.py` — Streamlit entry point. Configures the page and wires the tabs.
29
+ - `requirements.txt` — runtime dependency source of truth (HF Spaces reads this).
30
+ - `requirements.lock` — pinned lockfile generated from `requirements.txt`.
31
+ - `runtime.txt` — HF Spaces Python version declaration (`python-3.12`).
32
+ - `.python-version` — local-development Python pin, matches `runtime.txt`.
33
+ - `pyproject.toml` — PEP 621 project metadata, does NOT redeclare deps.
34
+ - `README.md` — HF Space landing card (frontmatter required) + project overview.
35
+
36
+ ## Documentation directories
37
+
38
+ - `docs/INDEX.md` — root entry point to the doc tree.
39
+ - `docs/architecture/` — what the code is and how it deploys.
40
+ - `docs/guides/` — workflow how-to (PR rules, review workflow, deploy policy).
41
+ - `docs/policies/` — versioned project rules (this directory).
42
+ - `docs/reference/` — exhaustive lookups (commands, agents, etc.).
43
+ - `docs/runbooks/` — step-by-step setup/operational walkthroughs.
44
+ - `docs/progress/` — slice summaries and audit traceability.
45
+
46
+ ## What we explicitly do NOT do
47
+
48
+ - No `src/` layout. The app is a flat-root Streamlit app to match HF Spaces' default.
49
+ - No per-tab subdirectories. One file per tab keeps `app.py` legible.
50
+ - No AI attribution in commit messages (`Co-Authored-By` / `Generated by`
51
+ trailers). See `CLAUDE.md` DECODE base rule 5.
docs/policies/root-artifact-policy.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Root artifact policy
2
+
3
+ What may live at the repository root, and what must stay out of git.
4
+
5
+ ## Tracked at root (allowed)
6
+
7
+ - `app.py`, `helper.py`, `tab<N>.py` — application code
8
+ - `requirements.txt`, `requirements.lock`, `runtime.txt`, `pyproject.toml`,
9
+ `.python-version` — dependency + runtime declarations
10
+ - `README.md`, `AGENTS.md`, `CLAUDE.md`, `SECURITY.md` — documentation + HF
11
+ Space frontmatter
12
+ - `.env.example` — reference declaration; does NOT contain secrets
13
+ - `.gitignore`, `.gitattributes` (if added later) — git metadata
14
+
15
+ Subdirectories: `.claude/`, `.devcontainer/`, `.github/`, `.githooks/`,
16
+ `.streamlit/`, `docs/`, `scripts/`.
17
+
18
+ ## Generated artifacts — must stay out of git
19
+
20
+ These directories and files are produced at runtime or by tooling and are
21
+ ignored by `.gitignore`:
22
+
23
+ - `__pycache__/` — CPython bytecode cache
24
+ - `*.pyc`, `*.pyo`, `*.pyd` — bytecode files
25
+ - `.decode-reviewer-clean`, `.decode-reviewer-findings.md` — reviewer subagent
26
+ artifacts (session-local; see `CLAUDE.md` reviewer procedure)
27
+
28
+ ## Generated artifacts known to appear locally but NOT yet gitignored
29
+
30
+ These appear during normal local work and are tolerated, but should not be
31
+ committed. If they ever land in `git status`, do not stage them:
32
+
33
+ - `.ruff_cache/` — ruff's incremental analysis cache
34
+ - `.pytest_cache/` — pytest cache, if pytest is added in a future slice
35
+ - `.venv/`, `venv/`, `.env`, `env/` — local virtual environments
36
+ - `.coverage`, `htmlcov/` — coverage reports
37
+ - User-uploaded files processed by the Streamlit app (typically held in
38
+ Streamlit's tempdir, not the repo). If you see Excel files, ZIPs, or images
39
+ appear at the root during local testing, that is a leak — delete them and
40
+ investigate whether a tab is writing outside the tempdir.
41
+
42
+ Adding these to `.gitignore` is a future cleanup, deferred so this slice
43
+ remains zero-risk to the deploy.
44
+
45
+ ## Generated outputs produced by the app
46
+
47
+ The 8 tools generate output artifacts (ZIP exports, PDF overviews, renamed
48
+ files) that are served to the user as downloads via Streamlit. These are
49
+ emitted into Streamlit's tempdir per session and should never appear at the
50
+ repository root. If you find yourself writing output to the repo, route it
51
+ through `tempfile` or Streamlit's session state instead.
52
+
53
+ ## Why this policy exists
54
+
55
+ The repo is also the HF Spaces deploy artifact. Every tracked file is shipped
56
+ to the public Space. Keeping the root narrow keeps the deploy small, the
57
+ secret surface small, and the architecture legible.
docs/runbooks/local-setup.md ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Local setup
2
+
3
+ How to run icat_app on your machine for development.
4
+
5
+ ## Prerequisites
6
+
7
+ - **Python 3.12** (matches HF Spaces deploy; see `runtime.txt` and `.python-version`).
8
+ - **Git** with Git Bash on Windows (the repo's `.githooks/` are bash scripts).
9
+ - **gh** (GitHub CLI), optional but recommended for opening PRs.
10
+
11
+ ## One-time setup
12
+
13
+ ```bash
14
+ git clone git@github.com:implicitdiagnosticsandsolutions/icat_app.git
15
+ cd icat_app
16
+ bash scripts/setup.sh # wires .githooks/ into git via core.hooksPath
17
+ python -m venv .venv
18
+ source .venv/Scripts/activate # Windows Git Bash
19
+ # or: source .venv/bin/activate # macOS / Linux
20
+ pip install -r requirements.txt
21
+ ```
22
+
23
+ `scripts/setup.sh` is idempotent. It is also invoked automatically by the
24
+ `ensure-setup.sh` SessionStart hook the next time you open Claude Code in
25
+ this repo.
26
+
27
+ If you prefer the exact pinned versions used in the deploy build (rather than
28
+ re-resolving against the latest compatible), install from the lockfile
29
+ instead:
30
+
31
+ ```bash
32
+ pip install -r requirements.lock
33
+ ```
34
+
35
+ `requirements.lock` is generated against Python 3.12 with `uv pip compile`. Do
36
+ not regenerate it from Python 3.13+ — the resolution can differ from what HF
37
+ Spaces actually installs.
38
+
39
+ ## Running the app
40
+
41
+ ```bash
42
+ streamlit run app.py
43
+ # opens http://localhost:8501
44
+ ```
45
+
46
+ The 8 tabs map 1-to-1 to the 8 files `tab1.py` through `tab8.py`. Shared
47
+ helpers live in `helper.py`.
48
+
49
+ ## Verifying changes before commit
50
+
51
+ Run the structural validator:
52
+
53
+ ```bash
54
+ python scripts/repo_validate.py
55
+ ```
56
+
57
+ This compiles every `*.py` with `py_compile`, parses `requirements.txt`, and
58
+ sanity-checks the README HF Spaces frontmatter. The same script runs on every
59
+ PR via `.github/workflows/repo_validate.yml`.
60
+
61
+ For source-code changes, the reviewer subagent procedure in `CLAUDE.md` is
62
+ mandatory before commit. The `commit-msg` hook will block any commit that
63
+ modifies substantive files without a fresh `.decode-reviewer-clean` marker,
64
+ unless the commit message contains `[override-reviewer: <reason>]`.
65
+
66
+ ## Per-OS notes
67
+
68
+ ### Windows
69
+
70
+ - Use **Git Bash** (or WSL) for git operations. PowerShell/CMD will not invoke
71
+ the `.githooks/` bash scripts.
72
+ - If `pip install` of `opencv-python-headless` is slow, that is expected; it
73
+ ships large native wheels.
74
+ - The local Python interpreter should be 3.12. If you only have 3.13, you can
75
+ still run the app for most tabs, but the `requirements.lock` resolution will
76
+ not match HF Spaces. Install Python 3.12 via the official installer or via
77
+ `uv python install 3.12`.
78
+
79
+ ### macOS
80
+
81
+ - Standard Python 3.12 via Homebrew (`brew install python@3.12`), pyenv, or
82
+ uv works equivalently.
83
+ - No additional notes.
84
+
85
+ ### Linux
86
+
87
+ - HF Spaces itself runs on Linux, so this is the closest match to production.
88
+ - Standard `python3.12` + `python3.12-venv` from your distro is enough.
89
+
90
+ ## Troubleshooting
91
+
92
+ | Symptom | Likely cause | Fix |
93
+ |---|---|---|
94
+ | Commit blocked by `commit-msg` hook | Reviewer marker stale or missing | Run the reviewer procedure in `CLAUDE.md`, then retry |
95
+ | `Sync to Hugging Face hub` workflow fails | `HF_TOKEN` secret expired or scope wrong | Rotate the token in GitHub repo settings; see `SECURITY.md` |
96
+ | `pip install -r requirements.lock` fails on transitive | Local Python is not 3.12 | Switch to Python 3.12 (see above) |
97
+ | Streamlit complains about port 8501 | Port already in use | `streamlit run app.py --server.port 8502` |
98
+ | Hooks silently not running | `core.hooksPath` not set | Re-run `bash scripts/setup.sh` |
99
+
100
+ ## What this runbook does NOT cover
101
+
102
+ - Deploying to HF Spaces — that happens automatically on push to `main`. See
103
+ `docs/guides/protected-boundary-policy.md`.
104
+ - Editing CI workflows — see `docs/guides/git-and-pr-rules.md` and
105
+ `SECURITY.md` for the deploy-boundary rules first.
106
+ - Adding a new tool — see `docs/policies/naming-conventions.md` for the
107
+ `tab<N>.py` rule.
pyproject.toml ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Minimum-viable PEP 621 project metadata for icat_app.
2
+ #
3
+ # Runtime dependencies are declared in requirements.txt, which is the source of
4
+ # truth consumed by the Hugging Face Spaces deploy (see .github/workflows/main.yml).
5
+ # A pinned lockfile resolved against Python 3.12 lives in requirements.lock and
6
+ # is regenerated with:
7
+ #
8
+ # uv pip compile --python-version=3.12 --output-file=requirements.lock requirements.txt
9
+ #
10
+ # This file deliberately does NOT redeclare those dependencies in [project.dependencies]
11
+ # to avoid two drifting sources of truth. It exists so that tooling that expects a
12
+ # pyproject.toml (PEP 517/518/621-aware tooling, IDEs, code review bots) can discover
13
+ # the project name, Python version constraint, and license.
14
+
15
+ [project]
16
+ name = "icat-app"
17
+ version = "0.1.0"
18
+ description = "DECODE Brand Asset Management Tools — Streamlit app deployed to Hugging Face Spaces."
19
+ readme = "README.md"
20
+ requires-python = "==3.12.*"
21
+ license = { text = "MIT" }
22
+ authors = [
23
+ { name = "DECODE Marketing GmbH" },
24
+ ]
25
+ keywords = ["streamlit", "brand-assets", "decode", "huggingface-spaces"]
26
+ classifiers = [
27
+ "Development Status :: 4 - Beta",
28
+ "Framework :: Streamlit",
29
+ "License :: OSI Approved :: MIT License",
30
+ "Programming Language :: Python :: 3.12",
31
+ "Operating System :: POSIX :: Linux",
32
+ "Operating System :: Microsoft :: Windows",
33
+ ]
requirements.lock ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file was autogenerated by uv via the following command:
2
+ # uv pip compile --python-version=3.12 --output-file=requirements.lock requirements.txt
3
+ altair==5.5.0
4
+ # via streamlit
5
+ attrs==26.1.0
6
+ # via
7
+ # jsonschema
8
+ # referencing
9
+ blinker==1.9.0
10
+ # via streamlit
11
+ cachetools==5.5.2
12
+ # via streamlit
13
+ certifi==2026.5.20
14
+ # via requests
15
+ charset-normalizer==3.4.7
16
+ # via requests
17
+ click==8.4.0
18
+ # via streamlit
19
+ colorama==0.4.6
20
+ # via click
21
+ et-xmlfile==2.0.0
22
+ # via openpyxl
23
+ gitdb==4.0.12
24
+ # via gitpython
25
+ gitpython==3.1.50
26
+ # via streamlit
27
+ idna==3.15
28
+ # via requests
29
+ jinja2==3.1.6
30
+ # via
31
+ # altair
32
+ # pydeck
33
+ jsonschema==4.26.0
34
+ # via altair
35
+ jsonschema-specifications==2025.9.1
36
+ # via jsonschema
37
+ markdown-it-py==4.2.0
38
+ # via rich
39
+ markupsafe==3.0.3
40
+ # via jinja2
41
+ mdurl==0.1.2
42
+ # via markdown-it-py
43
+ narwhals==2.21.2
44
+ # via altair
45
+ numpy==1.26.4
46
+ # via
47
+ # -r requirements.txt
48
+ # opencv-python-headless
49
+ # pandas
50
+ # pydeck
51
+ # streamlit
52
+ opencv-python-headless==4.9.0.80
53
+ # via -r requirements.txt
54
+ openpyxl==3.1.5
55
+ # via -r requirements.txt
56
+ packaging==23.2
57
+ # via
58
+ # altair
59
+ # streamlit
60
+ pandas==2.3.3
61
+ # via
62
+ # -r requirements.txt
63
+ # streamlit
64
+ pillow==10.4.0
65
+ # via
66
+ # -r requirements.txt
67
+ # reportlab
68
+ # streamlit
69
+ protobuf==4.25.9
70
+ # via streamlit
71
+ pyarrow==24.0.0
72
+ # via streamlit
73
+ pydeck==0.9.2
74
+ # via streamlit
75
+ pygments==2.20.0
76
+ # via rich
77
+ python-dateutil==2.9.0.post0
78
+ # via pandas
79
+ pytz==2026.2
80
+ # via pandas
81
+ referencing==0.37.0
82
+ # via
83
+ # jsonschema
84
+ # jsonschema-specifications
85
+ reportlab==4.0.4
86
+ # via -r requirements.txt
87
+ requests==2.34.2
88
+ # via streamlit
89
+ rich==13.9.4
90
+ # via streamlit
91
+ rpds-py==0.30.0
92
+ # via
93
+ # jsonschema
94
+ # referencing
95
+ six==1.17.0
96
+ # via python-dateutil
97
+ smmap==5.0.3
98
+ # via gitdb
99
+ streamlit==1.32.2
100
+ # via -r requirements.txt
101
+ tenacity==8.5.0
102
+ # via streamlit
103
+ toml==0.10.2
104
+ # via streamlit
105
+ tornado==6.5.5
106
+ # via streamlit
107
+ typing-extensions==4.15.0
108
+ # via
109
+ # altair
110
+ # referencing
111
+ # streamlit
112
+ tzdata==2026.2
113
+ # via pandas
114
+ urllib3==2.7.0
115
+ # via requests
116
+ watchdog==6.0.0
117
+ # via streamlit
118
+ xlrd==2.0.2
119
+ # via -r requirements.txt