DecodeMarketing Claude Opus 4.7 (1M context) commited on
Commit
7a5c442
·
unverified ·
1 Parent(s): c7599a7

[ai-standards][slice-1] orientation and deploy boundary (#7)

Browse files

Adds docs-only governance artifacts per the shrunken slice-1 plan
(post hardening commits 1878a50..c7599a7). No changes to app code,
requirements, devcontainer, .streamlit, existing workflows, existing
.claude/.githooks, or CLAUDE.md. README.md changes are additive only.

Artifacts:
- AGENTS.md (thin entrypoint -> CLAUDE.md + docs/INDEX.md)
- SECURITY.md (HF_TOKEN handling, deploy boundary)
- docs/ (INDEX, architecture, reference, guides, progress)
- .github/pull_request_template.md (deploy-boundary checklist)
- scripts/repo_validate.py (py_compile sweep + requirements parse)
- .github/workflows/repo_validate.yml (PR-only, parallel to gate.yml)
- README.md: additive Verification + Branch & Deploy + Architecture sections

Refs decode-ai-standards@81c3f17.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

.github/pull_request_template.md ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--
2
+ This is the pull request template for icat_app.
3
+
4
+ Fill it in completely. PRs missing checklist items will be asked to revise
5
+ before review. See docs/guides/git-and-pr-rules.md for the full flow.
6
+ -->
7
+
8
+ ## What this PR does
9
+
10
+ <!-- One paragraph. What changes, why now. -->
11
+
12
+ ## Deploy-boundary impact
13
+
14
+ `main` auto-deploys to `huggingface.co/spaces/DecodeMarketing/decode_tools` on merge. Check each file this PR touches:
15
+
16
+ - [ ] Does NOT touch `app.py`
17
+ - [ ] Does NOT touch `helper.py`
18
+ - [ ] Does NOT touch any of `tab1.py` … `tab8.py`
19
+ - [ ] Does NOT touch `requirements.txt`
20
+ - [ ] Does NOT touch `runtime.txt`
21
+ - [ ] Does NOT touch `.streamlit/`
22
+ - [ ] Does NOT touch `.github/workflows/main.yml`
23
+ - [ ] Does NOT touch `README.md` frontmatter (title / sdk / sdk_version / app_file / python_version)
24
+
25
+ **If any of the above is unchecked, this PR is deploy-affecting.** Add a "Deploy continuity check" section below describing how you will verify the HF Space rebuild after merge, and tag the project owner for sign-off.
26
+
27
+ ## Deploy continuity check (only if deploy-affecting)
28
+
29
+ <!--
30
+ After merge, watch https://github.com/implicitdiagnosticsandsolutions/icat_app/actions/workflows/main.yml
31
+ and confirm the HF Space at https://huggingface.co/spaces/DecodeMarketing/decode_tools rebuilds to "Running" state.
32
+
33
+ Document here what you will click through in the app to verify the change works post-deploy.
34
+ -->
35
+
36
+ ## Pre-merge checklist
37
+
38
+ - [ ] `python scripts/repo_validate.py` exits 0 locally
39
+ - [ ] `streamlit run app.py` still launches locally (smoke check)
40
+ - [ ] `gate.yml` CI is green (ruff + override-audit)
41
+ - [ ] `repo_validate.yml` CI is green (py_compile sweep)
42
+ - [ ] `check-file-size.yml` CI is green (no file >10 MB)
43
+ - [ ] If touching shared utilities: added to `helper.py`, NOT inlined into a tab (see `docs/architecture/active-surface.md`)
44
+ - [ ] If adding a new doc: linked from `docs/INDEX.md`
45
+ - [ ] Reviewer subagent ran locally; `.decode-reviewer-clean` exists with current HEAD + diff hash
46
+ - [ ] No `[override-reviewer: ...]` lines in commits — OR — overrides present and reasons are real
47
+ - [ ] No AI attribution in commit messages (no `Co-Authored-By` naming an AI model)
48
+ - [ ] Files staged explicitly (no `git add -A` / `git add .`)
49
+
50
+ ## Related
51
+
52
+ <!-- Issues / discussions / standards refs / earlier PRs. -->
.github/workflows/repo_validate.yml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: repo_validate
2
+
3
+ # PR-only. Never fires on push to main — that path is reserved for the HF
4
+ # Spaces deploy in main.yml, which must not be perturbed.
5
+ #
6
+ # Mirrors `python scripts/repo_validate.py` locally:
7
+ # - py_compile sweep over every tracked *.py file
8
+ # - requirements.txt is parseable as PEP 508 requirements
9
+ # - README.md HF Spaces frontmatter has the expected keys
10
+ #
11
+ # Pairs with the existing gate.yml (ruff lint on changed files). gate.yml
12
+ # catches changed-file lint; this workflow catches whole-repo syntactic state.
13
+ # Together they cover the regression case where a syntax error reaches main in
14
+ # a file the PR did not touch.
15
+
16
+ on:
17
+ pull_request:
18
+ branches: [main, master]
19
+ workflow_dispatch:
20
+
21
+ permissions:
22
+ contents: read
23
+
24
+ jobs:
25
+ repo_validate:
26
+ runs-on: ubuntu-latest
27
+ timeout-minutes: 5
28
+ steps:
29
+ - name: Checkout
30
+ # Tag-pinned for slice 1. Slice 2 will SHA-pin all workflow actions.
31
+ uses: actions/checkout@v4
32
+ with:
33
+ fetch-depth: 1
34
+
35
+ - name: Set up Python
36
+ uses: actions/setup-python@v5
37
+ with:
38
+ # Match runtime.txt so the validator sees the same Python the HF
39
+ # Space uses. Keep these in sync.
40
+ python-version: "3.12"
41
+
42
+ - name: Run repo_validate.py
43
+ run: python scripts/repo_validate.py
AGENTS.md ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AGENTS.md
2
+
3
+ This file is the short, durable entrypoint for AI contributors working on `icat_app`.
4
+
5
+ `icat_app` is a Streamlit app (8 tabs, one tool per tab) that auto-deploys to a Hugging Face Space on every push to `main`. Treat any change to runtime files as deploy-affecting.
6
+
7
+ ## Read these first, in this order
8
+
9
+ 1. `CLAUDE.md` — repo-level base rules, reviewer procedure, destructive-op rules, plugin requirements, repo-specific section.
10
+ 2. `docs/INDEX.md` — map to all in-repo documentation (architecture, guides, reference, policies, progress).
11
+ 3. `docs/guides/protected-boundary-policy.md` — what auto-deploys and the rules around touching it.
12
+ 4. `docs/guides/review-workflow.md` — findings-first reviewer contract and the `.decode-reviewer-clean` marker.
13
+ 5. `docs/guides/git-and-pr-rules.md` — branch model, PR rules, observed branches.
14
+
15
+ ## Hard limits (also enforced by hooks)
16
+
17
+ - No `git add -A` / `git add .` — stage files by name.
18
+ - No destructive git ops (`push --force`, `reset --hard`, `clean -f`, `branch -D`, etc.) — blocked by `.claude/hooks/block-dangerous-git.sh`. Ask the user to run them manually.
19
+ - No writes to `.env*`, `credentials*`, `*.pem`, `*.key` — blocked by `.claude/hooks/block-env-writes.sh`.
20
+ - No AI attribution in commit messages — conventional format, human author.
21
+ - No commits touching `*.py` / `scripts/` without a fresh `.decode-reviewer-clean` marker (enforced by `.githooks/commit-msg`).
22
+ - No direct push to `main` — `main` auto-deploys to `huggingface.co/spaces/DecodeMarketing/decode_tools` via `HF_TOKEN`. PRs only.
23
+
24
+ ## Local verification
25
+
26
+ ```bash
27
+ python scripts/repo_validate.py
28
+ ```
29
+
30
+ This is the one-command structural check (py_compile sweep + `requirements.txt` parseable + README HF frontmatter sanity). It runs on every PR via `.github/workflows/repo_validate.yml`. Ruff lint over changed Python runs separately via `.github/workflows/gate.yml`.
31
+
32
+ This file is intentionally short. Do not duplicate `CLAUDE.md` content here. Update `CLAUDE.md` (with reviewer) for behavior changes; update this file only when the entrypoint changes.
README.md CHANGED
@@ -85,3 +85,33 @@ To run this application locally:
85
  pip install -r requirements.txt
86
  streamlit run app.py
87
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  pip install -r requirements.txt
86
  streamlit run app.py
87
  ```
88
+
89
+ ## Verification
90
+
91
+ Before pushing changes, run the structural validator:
92
+
93
+ ```bash
94
+ python scripts/repo_validate.py
95
+ ```
96
+
97
+ It performs a `py_compile` sweep over every tracked `*.py`, verifies `requirements.txt` is parseable, and checks the README HF Spaces frontmatter. The same script runs on every PR via `.github/workflows/repo_validate.yml`. Ruff lint over changed Python runs separately via `.github/workflows/gate.yml`.
98
+
99
+ ## Branch & Deploy
100
+
101
+ `main` is the development base AND the production deploy branch — every push to `main` triggers `.github/workflows/main.yml`, which redeploys the Hugging Face Space at `https://huggingface.co/spaces/DecodeMarketing/decode_tools`. There is no staging step.
102
+
103
+ For the full rules — what is "deploy-affecting", the post-merge continuity check, branch naming, PR template — see:
104
+
105
+ - [`docs/guides/protected-boundary-policy.md`](docs/guides/protected-boundary-policy.md) — what `main` protects and how to touch it safely
106
+ - [`docs/guides/git-and-pr-rules.md`](docs/guides/git-and-pr-rules.md) — branch model, observed branches, PR target
107
+ - [`docs/guides/review-workflow.md`](docs/guides/review-workflow.md) — reviewer subagent contract
108
+ - [`.github/pull_request_template.md`](.github/pull_request_template.md) — PR checklist
109
+
110
+ ## Architecture
111
+
112
+ `app.py` wires 8 tabs (`tab1.py`–`tab8.py`) into a single Streamlit page; all tabs share utilities from `helper.py`. For the topology map and the helper consumer table, see:
113
+
114
+ - [`docs/architecture/repository-erd.md`](docs/architecture/repository-erd.md) — runtime topology, file map, deploy pipe
115
+ - [`docs/architecture/active-surface.md`](docs/architecture/active-surface.md) — `helper.py` exports and which tab consumes what
116
+
117
+ For the full doc tree: [`docs/INDEX.md`](docs/INDEX.md). For AI-contributor context: [`AGENTS.md`](AGENTS.md) and [`CLAUDE.md`](CLAUDE.md).
SECURITY.md ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Security policy
2
+
3
+ ## Reporting
4
+
5
+ If you discover a security issue in `icat_app`, do not file a public GitHub issue. Email `matussek@decodemarketing.com` with a description and reproduction steps. Acknowledgement within 5 business days.
6
+
7
+ ## Secrets in this repo
8
+
9
+ The only secret used by `icat_app` is `HF_TOKEN`, stored as a GitHub Actions secret on `implicitdiagnosticsandsolutions/icat_app`. It is consumed by `.github/workflows/main.yml` to push the working tree to `https://huggingface.co/spaces/DecodeMarketing/decode_tools` on every push to `main`.
10
+
11
+ `HF_TOKEN` is a write token. It must:
12
+
13
+ - never be printed in workflow logs (workflow uses URL-embedded form; do not `echo` or `cat` it)
14
+ - never be committed to the repo
15
+ - never be reused as a personal access token
16
+ - be rotated if the workflow file is forked or the repo visibility changes
17
+
18
+ A second optional secret, `INCIDENT_LOG_TOKEN`, is consumed by `.github/workflows/gate.yml` to file CI-failure incidents into the `decode-claude-wiki` repo. If not set, incident filing is skipped (the gate still passes/fails on its own terms).
19
+
20
+ ## What is enforced in code
21
+
22
+ - Writes to `.env*`, `credentials*`, `*.pem`, `*.key`, and similar secret file patterns are blocked by `.claude/hooks/block-env-writes.sh` at the Claude Code tool layer.
23
+ - Destructive git operations are blocked by `.claude/hooks/block-dangerous-git.sh`.
24
+ - Commits touching source files require a fresh `.decode-reviewer-clean` marker (enforced by `.githooks/commit-msg`), or an explicit `[override-reviewer: <reason>]` in the commit message (visible forever in `git log --grep="override-reviewer"`).
25
+
26
+ ## Deploy boundary
27
+
28
+ Push to `main` = production deploy to a publicly reachable Hugging Face Space. See `docs/guides/protected-boundary-policy.md` for the full policy, including emergency-hotfix rules and the deploy-continuity check expected after merge.
29
+
30
+ ## What is NOT a secret in this repo
31
+
32
+ The Streamlit app accepts user file uploads (Excel, ZIPs, images) at runtime. Those uploads are processed in-memory or in temp directories on the HF Space and are not persisted to the repo. No environment variables are required to run the app locally (`pip install -r requirements.txt && streamlit run app.py` is sufficient). There is no `.env` file; do not introduce one without updating this document and `docs/guides/protected-boundary-policy.md`.
33
+
34
+ ## Supply chain
35
+
36
+ Dependencies are listed in `requirements.txt`. Mixed pinning today (`streamlit==1.32.2`, `reportlab==4.0.4`, `opencv-python-headless==4.9.0.80` are pinned; `Pillow`, `pandas`, `numpy`, `openpyxl`, `xlrd` are floating or lower-bounded). A lockfile is planned for slice 2 of the AI-standards remediation. Until then, treat the HF Space build as the source of truth for what is actually deployed.
docs/INDEX.md ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # docs/ index
2
+
3
+ Single entrypoint to in-repo documentation for `icat_app`.
4
+
5
+ This tree is for **human + AI contributors**. Operational base rules live in `/CLAUDE.md`; this tree is the layered detail.
6
+
7
+ ## architecture
8
+
9
+ - [`architecture/repository-erd.md`](architecture/repository-erd.md) — topology: `app.py` → `tab1..tab8.py` → `helper.py`, plus the HF Space deploy pipe.
10
+ - [`architecture/active-surface.md`](architecture/active-surface.md) — which helpers each tab consumes (helper.py is a 1293-line shared utility module).
11
+
12
+ ## reference
13
+
14
+ - [`reference/command-registry.md`](reference/command-registry.md) — every discoverable command, what it does, where it runs (local / pre-commit / CI).
15
+
16
+ ## guides
17
+
18
+ - [`guides/review-workflow.md`](guides/review-workflow.md) — findings-first reviewer contract, `.decode-reviewer-clean` marker, override semantics.
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.
34
+
35
+ When you add a new doc, link it from this index. If you remove a doc, remove the link too — broken links here are a bug.
docs/architecture/active-surface.md ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Active surface
2
+
3
+ ## What this is
4
+
5
+ `helper.py` is a single 1293-LOC module that all 8 tabs import from. This doc catalogues what is exported and which tabs consume each export. It is the closest thing to a public API contract this repo has today.
6
+
7
+ Splitting `helper.py` into focused modules is **out of scope** for the AI-standards remediation. It is flagged for a later architecture-hardening slice with explicit non-goals.
8
+
9
+ ## Top-level exports in `helper.py`
10
+
11
+ | Export | Kind | First seen at line |
12
+ |-------------------------------------------------------|----------|---------------------|
13
+ | `extract_zip_to_temp(uploaded_file)` | function | 41 |
14
+ | `extract_images_from_xlsx_zip_method(...)` | function | 48 |
15
+ | `process_files(input_folder, marken_index, output_root)` | function | 106 |
16
+ | `is_valid_file(file_path)` | function | 172 |
17
+ | `generate_excel_report(...)` | function | 179 |
18
+ | `add_brand_pages_with_png_extensions(...)` | function | 311 |
19
+ | `generate_filename_based_pdf_report_with_extensions(...)` | function | 362 |
20
+ | `extract_images_from_xlsx_by_sheet(...)` | function | 493 |
21
+ | `extract_images_from_xlsx(xlsx_file, output_dir)` | function | 608 |
22
+ | `extract_brand(file_stem)` | function | 630 |
23
+ | `erkenne_marken_aus_ordnern(input_folder)` | function | 658 |
24
+ | `get_files_by_marke(input_folder, marken)` | function | 669 |
25
+ | `get_asset_cell(file_path, filename, col_count)` | function | 689 |
26
+ | `build_marken_einzelseiten(...)` | function | 744 |
27
+ | `get_excel_worksheets_simple(excel_file_path)` | function | 807 |
28
+ | `add_brand_pages(...)` | function | 836 |
29
+ | `analyze_files_by_filename(input_folder)` | function | 874 |
30
+ | `generate_pdf_report(input_folder, erste_marke=None)` | function | 914 |
31
+ | `clean_letters_only(text)` | function | 958 |
32
+ | `get_cleaned_filename_without_brand(filename, brand)` | function | 961 |
33
+ | `generate_filename_based_pdf_report(...)` | function | 970 |
34
+ | `add_brand_pages_with_final_labels(...)` | function | 1078 |
35
+ | `generate_two_section_pdf_report(...)` | function | 1124 |
36
+ | `ALLOWED_IMAGE_EXTENSIONS` | constant | (module-level set) |
37
+ | `ALLOWED_TEXT_EXTENSIONS` | constant | (module-level set) |
38
+ | `ALLOWED_VIDEO_EXTENSIONS` | constant | (module-level set) |
39
+ | `ALLOWED_AUDIO_EXTENSIONS` | constant | (module-level set) |
40
+ | `NON_IMAGE_EXTENSIONS` | constant | (module-level set) |
41
+
42
+ ## Consumer map (which tab imports what)
43
+
44
+ | Tab | Tool | Imports from `helper` |
45
+ |----------|-----------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
46
+ | `tab1.py`| Extract Images from Excel | `get_excel_worksheets_simple`, `extract_images_from_xlsx_by_sheet` |
47
+ | `tab2.py`| Name Assets by Brand | `extract_zip_to_temp`, `ALLOWED_IMAGE_EXTENSIONS`, `ALLOWED_TEXT_EXTENSIONS`, `ALLOWED_VIDEO_EXTENSIONS`, `ALLOWED_AUDIO_EXTENSIONS`, + more |
48
+ | `tab3.py`| Canvas White to Transparent | `ALLOWED_IMAGE_EXTENSIONS` |
49
+ | `tab4.py`| Asset Overview (PDF) | `extract_zip_to_temp`, `erkenne_marken_aus_ordnern`, `generate_pdf_report`, `get_files_by_marke`, `analyze_files_by_filename`, `generate_two_section_pdf_report` |
50
+ | `tab5.py`| Name Stims by Block | `extract_zip_to_temp`, `analyze_files_by_filename`, `generate_filename_based_pdf_report_with_extensions`, `process_files`, `generate_excel_report` |
51
+ | `tab6.py`| Re-run Matrix | `ALLOWED_IMAGE_EXTENSIONS`, `ALLOWED_VIDEO_EXTENSIONS`, `ALLOWED_AUDIO_EXTENSIONS`, `ALLOWED_TEXT_EXTENSIONS`, `NON_IMAGE_EXTENSIONS`, `get_cleaned_filename_without_brand`, `extract_brand` |
52
+ | `tab7.py`| Resize | `extract_zip_to_temp`, `ALLOWED_IMAGE_EXTENSIONS` |
53
+ | `tab8.py`| Place on Canvas | `extract_zip_to_temp`, `ALLOWED_IMAGE_EXTENSIONS` |
54
+
55
+ (Counts above are derived from grepping `from helper import …` blocks at the time of writing — verify against current source before relying on them.)
56
+
57
+ ## Concern clusters within `helper.py`
58
+
59
+ If a future architecture-hardening slice splits `helper.py`, these are the natural cluster boundaries:
60
+
61
+ 1. **constants** — the five `ALLOWED_*` / `NON_IMAGE_*` extension sets.
62
+ 2. **zip + io** — `extract_zip_to_temp`, `is_valid_file`.
63
+ 3. **brand index** — `extract_brand`, `erkenne_marken_aus_ordnern`, `get_files_by_marke`, `clean_letters_only`, `get_cleaned_filename_without_brand`, `analyze_files_by_filename`, `process_files`.
64
+ 4. **Excel image extraction** — `extract_images_from_xlsx_zip_method`, `extract_images_from_xlsx_by_sheet`, `extract_images_from_xlsx`, `get_excel_worksheets_simple`.
65
+ 5. **Excel report** — `generate_excel_report`.
66
+ 6. **PDF report** — `generate_pdf_report`, `generate_filename_based_pdf_report`, `generate_filename_based_pdf_report_with_extensions`, `generate_two_section_pdf_report`, `add_brand_pages`, `add_brand_pages_with_png_extensions`, `add_brand_pages_with_final_labels`, `build_marken_einzelseiten`, `get_asset_cell`.
67
+
68
+ This is a sketch, not a commitment. The real split would need a design doc and a deprecation strategy for the existing top-level imports.
69
+
70
+ ## Rule
71
+
72
+ Until `helper.py` is split, **all changes that add a shared utility go into `helper.py`**, not into the tab files. Inlining shared logic into a tab is the cheap path that grows the next 1293-LOC module — do not do it.
docs/architecture/repository-erd.md ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Repository ERD
2
+
3
+ ## What this is
4
+
5
+ A topology map of `icat_app` — what calls what at runtime, where code lives, and how a change reaches the production Hugging Face Space.
6
+
7
+ ## Runtime topology (one Streamlit process)
8
+
9
+ ```
10
+ Hugging Face Space
11
+ DecodeMarketing/decode_tools
12
+ (Streamlit 1.32.2, Python 3.12)
13
+ ^
14
+ |
15
+ (git push, see Deploy pipe)
16
+ |
17
+ +-------------------------------+-----------------------------+
18
+ | app.py |
19
+ | Streamlit entry point. st.set_page_config, |
20
+ | st.tabs([...]) wires 8 tabs into one page. |
21
+ +--+----+----+----+----+----+----+----+-----------------------+
22
+ | | | | | | | |
23
+ v v v v v v v v
24
+ tab1 tab2 tab3 tab4 tab5 tab6 tab7 tab8
25
+ | | | | | | | |
26
+ +----+----+----+----+----+----+----+
27
+ |
28
+ v
29
+ helper.py
30
+ (1293 LOC shared utility module — see
31
+ docs/architecture/active-surface.md)
32
+ ```
33
+
34
+ ## File map
35
+
36
+ | Path | Role |
37
+ |---------------------------------------|-----------------------------------------------------------------------------------------------|
38
+ | `app.py` (55 LOC) | Streamlit entry. Imports one function per tab, wires them into `st.tabs([...])`. |
39
+ | `tab1.py` (179 LOC) | Tool: Extract Images from Excel. Exports `excel_extractor_tool`. |
40
+ | `tab2.py` (141 LOC) | Tool: Name Assets by Brand. Exports `file_renamer_tool`. |
41
+ | `tab3.py` (160 LOC) | Tool: Canvas White to Transparent. Exports `white_to_transparent_tool`. |
42
+ | `tab4.py` (152 LOC) | Tool: Asset Overview (PDF). Exports `pdf_generator_tool`. |
43
+ | `tab5.py` (302 LOC) | Tool: Name Stims by Block + create output files. Exports `brand_renamer_tool`. |
44
+ | `tab6.py` (784 LOC) | Tool: Re-run Matrix. Exports `updated_file_processor_tab`. Largest tab — owns its own logic. |
45
+ | `tab7.py` (163 LOC) | Tool: Resize (with transparent canvas). Exports `center_on_canvas_tool` (name misleading — exported function is the resize tool entry). |
46
+ | `tab8.py` (179 LOC) | Tool: Place on Canvas. Exports `resize_with_transparent_canvas_tool` (name misleading — exported function is the canvas-placement entry). |
47
+ | `helper.py` (1293 LOC) | Shared utilities. Constants (allowed extensions, brand index helpers), zip extraction, image processing, Excel image extraction, PDF generation. See `active-surface.md`. |
48
+ | `requirements.txt` | Source of truth for Python dependencies installed by HF Spaces. |
49
+ | `runtime.txt` | HF Spaces Python version pin (`python-3.12`). |
50
+ | `.streamlit/config.toml` | Streamlit server config. |
51
+ | `README.md` | HF Spaces frontmatter (title, sdk, sdk_version, app_file) + human description. |
52
+ | `CLAUDE.md` | Repo-level AI base rules and reviewer procedure. |
53
+
54
+ ## Deploy pipe (the protected boundary)
55
+
56
+ ```
57
+ developer --PR--> main --push trigger--> .github/workflows/main.yml
58
+ |
59
+ | (uses HF_TOKEN secret)
60
+ v
61
+ git push https://DecodeMarketing:$HF_TOKEN@...
62
+ |
63
+ v
64
+ Hugging Face Space rebuild & redeploy
65
+ ```
66
+
67
+ Trigger: `push` to `main` (also `workflow_dispatch` manually from the Actions tab). There is no staging / canary step. There is no pre-deploy approval. **Therefore every merge to main is a production deploy.** This is documented in `docs/guides/protected-boundary-policy.md`.
68
+
69
+ ## PR-side CI
70
+
71
+ ```
72
+ PR opened/updated against main
73
+ |
74
+ +---> .github/workflows/check-file-size.yml (ActionsDesk/lfs-warning, >10MB)
75
+ |
76
+ +---> .github/workflows/gate.yml (ruff lint on changed Python; override-audit)
77
+ |
78
+ +---> .github/workflows/repo_validate.yml (py_compile sweep + manifest sanity) <-- added in slice 1
79
+ ```
80
+
81
+ `gate.yml` also fires on push to `main`. On push-to-main failure, it auto-files a CI-failure incident issue into `decode-claude-wiki`.
82
+
83
+ ## Local gates (when `scripts/setup.sh` has wired `core.hooksPath = .githooks`)
84
+
85
+ ```
86
+ git commit
87
+ |
88
+ +---> .githooks/pre-commit --calls--> scripts/language-gate.sh (ruff lint on staged)
89
+ |
90
+ +---> .githooks/commit-msg (reviewer-marker check OR override-reviewer string)
91
+ ```
92
+
93
+ When working through Claude Code, the `.claude/hooks/` layer adds: SessionStart wires `.githooks` automatically; PreToolUse blocks dangerous git ops and writes to secret files; Stop blocks session end without a fresh reviewer marker.
94
+
95
+ ## What this ERD intentionally omits
96
+
97
+ - The internal call graph inside `helper.py`. That belongs in `active-surface.md`.
98
+ - The Streamlit widget tree per tab. Each `tab*.py` owns that locally.
99
+ - Any data persistence. There is none — all uploads are in-memory or in temp dirs on the HF Space and discarded at session end.
docs/guides/git-and-pr-rules.md ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Git and PR rules
2
+
3
+ ## Default flow
4
+
5
+ 1. Branch from `main`: `git checkout -b feature/<scope-kebab>`.
6
+ 2. Commit on the feature branch. Stage files explicitly (`git add path/to/file`, never `git add -A` / `git add .`). The pre-commit gate runs ruff on staged Python; the commit-msg gate enforces the reviewer marker. Both are bypassable only via `[override-reviewer: <reason>]` (audit-logged).
7
+ 3. Push the feature branch: `git push -u origin feature/<scope-kebab>`.
8
+ 4. Open a PR against `main`. Fill in the PR template at `.github/pull_request_template.md`.
9
+ 5. Wait for CI: `gate.yml` (ruff + override-audit), `repo_validate.yml` (py_compile sweep), `check-file-size.yml` (LFS warning).
10
+ 6. Get review: the `feature-dev:code-reviewer` subagent locally (writes `.decode-reviewer-clean`), plus at least one human approver on the PR.
11
+ 7. Merge to `main`. **Note: merging to `main` triggers an HF Space deploy.** See [`protected-boundary-policy.md`](protected-boundary-policy.md) for the deploy-continuity check expected after merge.
12
+
13
+ ## Branch naming
14
+
15
+ - `feature/<scope-kebab>` — new feature or change.
16
+ - `debug/<scope-kebab>` — short-lived branch for investigation (do not merge — close with discussion in a comment).
17
+ - `hotfix/<scope-kebab>` — emergency fix going to `main`. Requires explicit owner sign-off per the protected-boundary policy.
18
+
19
+ Anything that does not fit one of these prefixes should be discussed before pushing.
20
+
21
+ ## Commit message rules
22
+
23
+ From `CLAUDE.md` (base rules):
24
+
25
+ - **No AI attribution.** Conventional Commits format (`feat:`, `fix:`, `docs:`, `chore:`, `refactor:`, `test:`), human author.
26
+ - **No `Co-Authored-By` lines naming an AI model.**
27
+ - The override marker is the only AI-specific text permitted: `[override-reviewer: <reason>]` inline in the message.
28
+
29
+ The local agent harness applies these rules as well.
30
+
31
+ ## PR target
32
+
33
+ `main` is the PR target for all routine work. There is no `develop` / `dev` PR target in active use today (see "Observed branches" below).
34
+
35
+ ## Observed branches on origin (status: not yet defined in repo docs)
36
+
37
+ These branches exist on `origin` at the time of writing:
38
+
39
+ | Branch | Observed state | Documented role |
40
+ |---------------------------------------------------|-------------------------------------------------|-----------------|
41
+ | `main` | Default branch. Auto-deploys to HF Space. | Yes — this doc + `protected-boundary-policy.md`. |
42
+ | `dev` | Exists on origin. | **No.** Team should confirm intended role. |
43
+ | `staging` | Exists on origin. | **No.** Team should confirm intended role. |
44
+ | `hardening/decode-gates` | Source of the DECODE hardening commits merged into main 2026-05. | Historical; closed/archive candidate. |
45
+ | `sandbox` | Old, unused. | **No.** Likely archive/delete candidate. |
46
+ | `feature/refresh-codeowners-posture-2026-05-11` | Existing feature branch. | In-flight feature work (not this remediation). |
47
+
48
+ **Open team decision** — do `dev` and `staging` participate in a planned promotion model (e.g., `feature/* → dev → staging → main`)? If yes, document it here and rewire `.github/workflows/main.yml` so the HF deploy trigger fires only at the right step. If no, archive them.
49
+
50
+ This doc records what is **observed**, not what is **prescribed**. Do not invent a promotion model in the absence of team confirmation.
51
+
52
+ ## What pull request reviewers should look for
53
+
54
+ PR reviewer checklist (also in `.github/pull_request_template.md`):
55
+
56
+ 1. Does this change touch any deploy-boundary file? (See `protected-boundary-policy.md`.)
57
+ 2. Does this change add a new shared utility that should live in `helper.py`, not in a tab file? (See `docs/architecture/active-surface.md`.)
58
+ 3. Does this change add a new doc that should also be linked from `docs/INDEX.md`?
59
+ 4. Did `gate.yml`, `repo_validate.yml`, and `check-file-size.yml` all pass?
60
+ 5. Is there a `[override-reviewer: ...]` line in the commit history of this PR? If yes, is the reason real?
61
+
62
+ ## Merging strategy
63
+
64
+ Squash-merge is the recommended option for the in-repo flow. The HF deploy sees one commit per merged PR, which keeps the rebuild log clean.
65
+
66
+ ## Force push and destructive ops
67
+
68
+ Blocked by `.claude/hooks/block-dangerous-git.sh` at the Claude Code tool layer. If you genuinely need one (e.g., to clean up a feature branch before PR review), ask the user to run the command manually in their own terminal. **Never force-push `main`** under any circumstance.
docs/guides/protected-boundary-policy.md ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Protected boundary policy
2
+
3
+ ## The one rule
4
+
5
+ **Any commit that lands on `main` triggers a production deploy to a publicly reachable Hugging Face Space.** There is no staging step, no manual approval, no canary.
6
+
7
+ Trigger file: [`.github/workflows/main.yml`](../../.github/workflows/main.yml).
8
+ Trigger event: `push` to `main` or manual `workflow_dispatch`.
9
+ Destination: `https://huggingface.co/spaces/DecodeMarketing/decode_tools`.
10
+ Credential: `HF_TOKEN` GitHub Actions secret (write-scoped to the HF Space).
11
+
12
+ If you are unsure whether your change is safe to deploy, the answer is "don't merge yet". A docs-only PR is safe. A change to `app.py`, `helper.py`, `tab*.py`, `requirements.txt`, `runtime.txt`, `.streamlit/`, or any workflow file is **deploy-affecting**.
13
+
14
+ ## What is protected
15
+
16
+ Files that are part of the deploy boundary:
17
+
18
+ - `app.py`
19
+ - `helper.py`
20
+ - `tab1.py` … `tab8.py`
21
+ - `requirements.txt`
22
+ - `runtime.txt`
23
+ - `.streamlit/config.toml`
24
+ - `.github/workflows/main.yml`
25
+ - `README.md` frontmatter (HF Spaces metadata: `title`, `sdk`, `sdk_version`, `app_file`, `python_version`)
26
+
27
+ Anything else (docs, scripts, `.claude/`, `.githooks/`, `.github/pull_request_template.md`, new files outside the above paths) is **not** deploy-affecting. The HF Space will rebuild on every merge but the rebuild is a no-op.
28
+
29
+ ## Direct push to `main`
30
+
31
+ **Not permitted** for any AI contributor and not permitted for routine human contributions. Use a `feature/<scope-kebab>` branch and a PR.
32
+
33
+ The only allowed exception is a **deploy-affecting emergency hotfix** that:
34
+ - has a real outage attached (HF Space is down, or actively broken for users)
35
+ - is signed off by the project owner in the PR description (or, for an out-of-hours hotfix, in chat — record the sign-off in the commit message)
36
+ - includes a same-day follow-up PR that adds a regression check or doc update for the failure mode
37
+
38
+ ## What to do for a deploy-affecting change
39
+
40
+ 1. Branch from `main`: `git checkout -b feature/<scope-kebab>`.
41
+ 2. Make the change. Run `python scripts/repo_validate.py` locally. Run `streamlit run app.py` and click through the affected tab.
42
+ 3. Open a PR against `main`. Fill in the PR template — the deploy-boundary checklist names every file in the list above.
43
+ 4. Wait for `gate.yml` (ruff lint + override-audit) and `repo_validate.yml` to pass. `check-file-size.yml` must also pass (>10MB blocks HF sync).
44
+ 5. Get review (the reviewer subagent locally + at least one human approver on the PR).
45
+ 6. After merge, watch the `Sync to Hugging Face hub` run in the Actions tab. Confirm the HF Space rebuilds successfully (check `https://huggingface.co/spaces/DecodeMarketing/decode_tools` until the build state is "Running"). This is the **deploy-continuity check**.
46
+ 7. If the HF build fails: the `gate.yml` `ci-fail-incident` job will auto-file an incident issue into `decode-claude-wiki`. Triage immediately. If a runtime rollback is needed, open a new PR that reverts the offending change — do not force-push `main`.
47
+
48
+ ## What to do for a non-deploy-affecting change
49
+
50
+ 1. Same flow, but the HF Space rebuild after merge is a no-op. Confirm the build still goes green (a successful no-op rebuild proves nothing is silently broken in the deploy pipe).
51
+
52
+ ## Why pushing to `main` is not the deploy trigger we want, long term
53
+
54
+ Coupling "merge to dev base" and "production deploy" means:
55
+ - every merge is high-stakes
56
+ - there is no test-staging-promote cycle
57
+ - a syntax error in a tab file becomes a public-facing outage
58
+
59
+ A future remediation slice should consider:
60
+ - moving the HF push trigger from `push: branches: [main]` to `release: types: [published]` (deploy on tag), OR
61
+ - introducing a `prod` branch that `main` is fast-forwarded into on demand.
62
+
63
+ That decision belongs to the team, not the AI contributor. Until it changes, this policy is in force.
64
+
65
+ ## Origin branches observed (informational only)
66
+
67
+ The following branches exist on origin but **their role in any promotion model is not documented in this repo**:
68
+
69
+ - `dev`
70
+ - `staging`
71
+ - `hardening/decode-gates`
72
+ - `sandbox`
73
+ - `feature/refresh-codeowners-posture-2026-05-11`
74
+
75
+ See [`git-and-pr-rules.md`](git-and-pr-rules.md) for the flagged item.
76
+
77
+ ## Secrets handling
78
+
79
+ `HF_TOKEN` rules live in [`SECURITY.md`](../../SECURITY.md). Do not echo or print the token from any workflow. Do not store it outside GitHub Actions secrets.
docs/guides/review-workflow.md ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Review workflow
2
+
3
+ `icat_app` uses a findings-first reviewer contract. Reviewer behavior is enforced by hooks; this doc is the human-readable version of that contract.
4
+
5
+ ## When the reviewer runs
6
+
7
+ The reviewer must run before any commit that touches substantive files (`.py`, `.ts`, `.tsx`, `.js`, `.jsx`, `.R`, `.r`, `.java`, `.sql`, anything under `scripts/`). Pure docs / markdown changes do not require the reviewer.
8
+
9
+ In a Claude Code session, the Stop hook (`.claude/hooks/reviewer-stop.sh`) blocks session end if substantive files are modified and no fresh `.decode-reviewer-clean` marker exists. The `commit-msg` git hook (`.githooks/commit-msg`) blocks the commit itself unless a fresh marker exists.
10
+
11
+ ## What the reviewer does
12
+
13
+ The reviewer is the `feature-dev:code-reviewer` subagent (provided by the `feature-dev@claude-plugins-official` plugin). It is dispatched via the Agent tool. The contract:
14
+
15
+ - **Input**: `git diff HEAD` (current change) + repo context.
16
+ - **Latency target**: under 90 seconds.
17
+ - **Output**: blocker findings only. Confidence floor: ≥ 80.
18
+ - **Outcome (exactly one)**:
19
+ - **No blockers** → write `.decode-reviewer-clean` with one line: `<HEAD-SHA> <DIFF-HASH> <ISO-8601-UTC-timestamp>`. Compute `<HEAD-SHA>` via `git rev-parse HEAD` and `<DIFF-HASH>` via `bash scripts/reviewer-hash.sh` (covers tracked diff + untracked file contents).
20
+ - **Blockers** → write `.decode-reviewer-findings.md` with the list. **Do not** write `.decode-reviewer-clean`.
21
+
22
+ Both files are session-local artifacts. They are listed in `.gitignore` and must never be committed.
23
+
24
+ ## Why the marker binds to a diff hash
25
+
26
+ If the marker only bound to `HEAD`, an agent could pass review, then silently edit a file, then commit. By binding the marker to `bash scripts/reviewer-hash.sh` (which hashes both `git diff HEAD` AND untracked file contents), any change after review invalidates the marker. The `commit-msg` hook recomputes and compares.
27
+
28
+ ## Override
29
+
30
+ For genuinely trivial changes (typo, comment), an author may bypass with:
31
+
32
+ ```
33
+ git commit -m "... [override-reviewer: <real reason>]"
34
+ ```
35
+
36
+ The override:
37
+ - is logged forever in `git log --grep="override-reviewer"`
38
+ - is also reported in CI by the `override-audit` job in `.github/workflows/gate.yml`
39
+ - requires a real reason — `[override-reviewer: skip]` defeats the audit
40
+
41
+ Do not normalize overrides. Repeated overrides indicate the reviewer flow is broken; fix the flow.
42
+
43
+ ## What the reviewer is NOT
44
+
45
+ - Not a style police. Ruff handles lint via `.githooks/pre-commit` + `.github/workflows/gate.yml`.
46
+ - Not a structural sweep. `python scripts/repo_validate.py` handles `py_compile` + manifest sanity (locally + in `.github/workflows/repo_validate.yml`).
47
+ - Not a security scanner. See `SECURITY.md` for the secrets handling rules.
48
+
49
+ The reviewer's job is to catch **blocking semantic / design / boundary issues** that lint and `py_compile` cannot see — e.g., "this change touches `.github/workflows/main.yml` and will alter the HF deploy"; "this introduces a new `helper.py` dependency that contradicts the active-surface map".
50
+
51
+ ## Plugin requirement
52
+
53
+ The reviewer subagent ships with the `feature-dev@claude-plugins-official` plugin. Install once per machine via Claude Code:
54
+
55
+ ```
56
+ /plugin marketplace add anthropics/claude-plugins-official
57
+ /plugin install feature-dev@claude-plugins-official
58
+ ```
59
+
60
+ Without `feature-dev`, every commit touching source code will be blocked by the `commit-msg` gate. See `CLAUDE.md` for the full session-start setup.
docs/progress/slice-integration-overview.md ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Slice integration overview
2
+
3
+ _Last updated: 2026-05-20 (refresh at `c7599a7`)._
4
+
5
+ This file tracks the decode-ai-standards remediation slices for `icat_app`. It is the in-repo working copy of the plan held in the audit work folder (`C:\Users\JulianeMatussek\decode-ai-standards-work\icat_app\remediation-plan.md`).
6
+
7
+ ## Current readiness (from `audit-result.yaml` at `c7599a7`)
8
+
9
+ - readiness: `at_risk`
10
+ - `pass`: 0 / 36
11
+ - `partial`: 21 / 36
12
+ - `fail`: 15 / 36
13
+
14
+ Movement from the pre-hardening baseline at `2e95e07` (which scored 2 pass / 4 partial / 30 fail) is documented in the audit work folder's `delta-summary.md`. 14 checks moved from FAIL to PARTIAL because of the DECODE hardening commits (CLAUDE.md, .githooks, .claude/{hooks,skills,settings.json}, scripts/{setup,language-gate,reviewer-hash}.sh, gate.yml).
15
+
16
+ ## Slices
17
+
18
+ ```
19
+ [~] slice 1 orientation_and_deploy_boundary_slice (this PR)
20
+ target checks: C01 C04 C09 C11 C12 C18 C21 C23 C25 C26 C27 C29 C31 C32
21
+
22
+ [ ] slice 2 structure_and_dependency_slice
23
+ target checks: C03 C05 C06 C10 C28 C33
24
+
25
+ [ ] slice 3 agent_contract_slice (shrunk — hardening already covers enforcement)
26
+ target checks: C13 C14 C15 C16 C17 C20 C22 C24 C30 C34 C36
27
+
28
+ [ ] deferred architecture_hardening_slice (split helper.py)
29
+ [ ] deferred test_lane_slice (add pytest + integration tests)
30
+ ```
31
+
32
+ ## Slice 1 — what it adds (this PR)
33
+
34
+ - `AGENTS.md` (thin pointer to CLAUDE.md + docs/INDEX.md)
35
+ - `SECURITY.md`
36
+ - `docs/INDEX.md`
37
+ - `docs/architecture/repository-erd.md`
38
+ - `docs/architecture/active-surface.md`
39
+ - `docs/reference/command-registry.md`
40
+ - `docs/guides/review-workflow.md`
41
+ - `docs/guides/protected-boundary-policy.md`
42
+ - `docs/guides/git-and-pr-rules.md`
43
+ - `docs/progress/slice-integration-overview.md` (this file)
44
+ - `.github/pull_request_template.md`
45
+ - `scripts/repo_validate.py`
46
+ - `.github/workflows/repo_validate.yml` (PR-only — never on push to main)
47
+ - README.md additive extensions: Verification, Branch & Deploy, Architecture pointer
48
+
49
+ ## Slice 1 — what it does NOT touch
50
+
51
+ Per the hard constraints in the audit work folder:
52
+
53
+ - `app.py`, `helper.py`, `tab1.py`–`tab8.py`
54
+ - `requirements.txt`, `runtime.txt`, `.streamlit/`, `.devcontainer/`
55
+ - Existing files in `.github/workflows/`, `.githooks/`, `.claude/`
56
+ - `CLAUDE.md`, `.gitignore`
57
+
58
+ Only additions are allowed in `README.md`; no deletions/modifications of existing lines.
59
+
60
+ ## Open items (need user/team confirmation)
61
+
62
+ 1. **Branch promotion model** — `dev`, `staging`, `hardening/decode-gates`, `sandbox` exist on origin with no documented role. See `docs/guides/git-and-pr-rules.md` "Observed branches" table.
63
+ 2. **Reviewer manifest source** — `feature-dev:code-reviewer` ships from the external plugin. Should slice 3 mirror it as `.claude/agents/findings_first_reviewer.json`, or accept the external plugin as canonical?
64
+ 3. **HF Spaces SDK version pin duplication** — README frontmatter `sdk_version: 1.32.2` vs `requirements.txt` `streamlit==1.32.2`. Slice 2 picks one source of truth.
65
+ 4. **Deploy trigger semantics** — `main` is currently the dev base AND the deploy trigger. See `docs/guides/protected-boundary-policy.md` "Why pushing to `main` is not the deploy trigger we want, long term". Out of scope for slice 1.
66
+
67
+ ## Branch & PR strategy for the remediation itself
68
+
69
+ - One slice per PR. PR title prefix: `[ai-standards][slice-N]`.
70
+ - Slice 1 PR is docs-only / scripts-only / new-workflow-only — HF deploy on merge is a no-op.
71
+ - After each merge, rerun the audit against `main` and emit a refreshed `delta-summary-<slice>.md` into the audit work folder.
72
+
73
+ ## Next proof (after this PR merges)
74
+
75
+ - Rerun `audit-result.yaml` against `main`.
76
+ - Expected movement:
77
+ - C01 partial → pass (README has explicit verification + branch + architecture sections)
78
+ - C04 fail → pass (`docs/INDEX.md` + tree present)
79
+ - C09 partial → pass (`scripts/repo_validate.py` exposed)
80
+ - C11 partial → pass (`SECURITY.md` + `docs/guides/protected-boundary-policy.md`)
81
+ - C12 fail → partial (architecture docs added; helper.py split still deferred)
82
+ - C18 partial → pass (review-workflow.md exposes the contract)
83
+ - C21 partial → pass (deploy-boundary confirmation rule written)
84
+ - C23 fail → partial (git-and-pr-rules.md + PR template; promotion model still open)
85
+ - C25 partial → pass (command-registry.md)
86
+ - C26 partial → pass (repo_validate.py covers py_compile + manifest sanity)
87
+ - C27 partial → pass (PR CI is no longer file-size-only)
88
+ - C29 fail → partial (PR template added; branch protection still not configured)
89
+ - C31 fail → partial (slice tracker in-repo)
90
+ - C32 partial → pass (output contract exposed in review-workflow.md)
docs/reference/command-registry.md ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Command registry
2
+
3
+ Every discoverable command in `icat_app`, what it does, and where it runs. If a command is not on this list, it is either undocumented (open an issue) or not part of the supported surface.
4
+
5
+ ## Run the app
6
+
7
+ | Command | Purpose | Where it runs |
8
+ |------------------------------------------|-------------------------------|----------------------------------------------------------|
9
+ | `pip install -r requirements.txt` | Install dependencies | Local + HF Space build |
10
+ | `streamlit run app.py` | Start the Streamlit dev server| Local (`http://localhost:8501`) + HF Space runtime |
11
+
12
+ ## Structural verification
13
+
14
+ | Command | Purpose | Where it runs |
15
+ |------------------------------------------|------------------------------------------------------------------------------------------------------|------------------------------------------------|
16
+ | `python scripts/repo_validate.py` | Non-interactive structural check: `py_compile` over every `*.py`, `requirements.txt` parseable, README HF frontmatter sanity. Exits non-zero on first failure. | Local + `.github/workflows/repo_validate.yml` (PR only) |
17
+
18
+ This is the one-command proof. Run it before pushing.
19
+
20
+ ## Lint (via DECODE gate)
21
+
22
+ | Command | Purpose | Where it runs |
23
+ |------------------------------------------|----------------------------------------------------------|-------------------------------------------------------------------------------------|
24
+ | `bash scripts/language-gate.sh` | Ruff lint over staged or supplied files (Python). | `.githooks/pre-commit` (when `core.hooksPath = .githooks`) + `.github/workflows/gate.yml` (PR + push to main) |
25
+ | `bash scripts/setup.sh` | Wire `core.hooksPath = .githooks`. Idempotent. | Local one-time bootstrap (SessionStart hook in Claude Code does this automatically) |
26
+ | `bash scripts/reviewer-hash.sh` | Compute the diff+untracked hash that the reviewer marker binds to. | Called by `.claude/hooks/reviewer-stop.sh`, `.githooks/commit-msg`, and the reviewer subagent. |
27
+
28
+ ## Deploy
29
+
30
+ | Command | Purpose | Where it runs |
31
+ |------------------------------------------|-----------------------------------------------|-----------------------------------------------------|
32
+ | (none — automatic) | `.github/workflows/main.yml` pushes the working tree to the HF Space. Trigger: push to `main` or manual `workflow_dispatch`. | GitHub Actions on `implicitdiagnosticsandsolutions/icat_app`. Uses `HF_TOKEN`. |
33
+
34
+ There is no manual deploy script. Do not invent one. See `docs/guides/protected-boundary-policy.md`.
35
+
36
+ ## Reviewer flow (in Claude Code)
37
+
38
+ In a Claude Code session, the reviewer procedure is:
39
+
40
+ 1. `git diff HEAD` (read the change).
41
+ 2. Dispatch the `feature-dev:code-reviewer` subagent via the Agent tool.
42
+ 3. If no blocking findings, write `.decode-reviewer-clean` with one line: `<HEAD-SHA> <DIFF-HASH> <ISO-8601-UTC-timestamp>`, where `<DIFF-HASH>` comes from `bash scripts/reviewer-hash.sh`.
43
+ 4. If blocking findings, write `.decode-reviewer-findings.md` instead. The Stop hook will continue to block until the next clean review.
44
+
45
+ See `docs/guides/review-workflow.md` for the contract and override semantics.
46
+
47
+ ## Commit override (audit-logged)
48
+
49
+ | Command | Purpose |
50
+ |----------------------------------------------------------------------------------|------------------------------------------------------------------------------------|
51
+ | `git commit -m "... [override-reviewer: <reason>]"` | Bypass the reviewer-marker check in `.githooks/commit-msg`. Logged forever in git history; visible via `git log --grep="override-reviewer"`. |
52
+
53
+ Use only for genuinely trivial changes (typo, comment), and always with a real reason.
scripts/repo_validate.py ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ icat_app structural validator.
4
+
5
+ Non-interactive checks intended to run locally on Windows + Linux and in CI
6
+ via .github/workflows/repo_validate.yml. Exits non-zero on the first failure
7
+ so the diagnostic is unambiguous.
8
+
9
+ Checks performed:
10
+ 1. py_compile every tracked *.py file (catches syntax errors anywhere in the
11
+ repo, not just in changed files — ruff via gate.yml only sees changed
12
+ files).
13
+ 2. requirements.txt is parseable as PEP 508 requirement lines, with line
14
+ comments and blank lines tolerated.
15
+ 3. README.md HF Spaces frontmatter contains the expected keys with sensible
16
+ values (title, sdk, sdk_version, app_file, python_version).
17
+
18
+ Usage:
19
+ python scripts/repo_validate.py
20
+
21
+ Exit codes:
22
+ 0 all checks passed
23
+ 1 at least one check failed (details printed to stderr before exit)
24
+ """
25
+
26
+ from __future__ import annotations
27
+
28
+ import ast
29
+ import py_compile
30
+ import re
31
+ import subprocess
32
+ import sys
33
+ from pathlib import Path
34
+
35
+ REPO_ROOT = Path(__file__).resolve().parent.parent
36
+
37
+ # README HF frontmatter keys we expect. These must match the actual values that
38
+ # the HF Spaces runner cares about. Update this list (and update the doc tree)
39
+ # if HF Spaces changes its frontmatter contract.
40
+ REQUIRED_README_FRONTMATTER_KEYS = {
41
+ "title",
42
+ "sdk",
43
+ "sdk_version",
44
+ "app_file",
45
+ "python_version",
46
+ }
47
+
48
+
49
+ def _log_failure(check: str, message: str) -> None:
50
+ print(f"[repo_validate] FAIL {check}: {message}", file=sys.stderr)
51
+
52
+
53
+ def _log_pass(check: str, detail: str = "") -> None:
54
+ suffix = f" — {detail}" if detail else ""
55
+ print(f"[repo_validate] PASS {check}{suffix}")
56
+
57
+
58
+ def _tracked_python_files() -> list[Path]:
59
+ """Return every tracked *.py file. Uses git ls-files when available;
60
+ falls back to a filesystem walk otherwise."""
61
+ try:
62
+ result = subprocess.run(
63
+ ["git", "ls-files", "*.py"],
64
+ cwd=REPO_ROOT,
65
+ check=True,
66
+ capture_output=True,
67
+ text=True,
68
+ )
69
+ rel_paths = [line for line in result.stdout.splitlines() if line.strip()]
70
+ return [REPO_ROOT / p for p in rel_paths]
71
+ except (subprocess.CalledProcessError, FileNotFoundError):
72
+ # Fallback: walk the tree. Best-effort; will include ignored files,
73
+ # which is acceptable since this branch is only hit when git is not
74
+ # available (very unusual).
75
+ return [
76
+ p
77
+ for p in REPO_ROOT.rglob("*.py")
78
+ if "__pycache__" not in p.parts and ".venv" not in p.parts
79
+ ]
80
+
81
+
82
+ def check_py_compile() -> bool:
83
+ """Run py_compile on every tracked *.py. Report all failures, exit on
84
+ aggregate."""
85
+ files = _tracked_python_files()
86
+ if not files:
87
+ _log_failure("py_compile", "no Python files found — repo is empty?")
88
+ return False
89
+
90
+ failures: list[tuple[Path, str]] = []
91
+ for path in files:
92
+ try:
93
+ py_compile.compile(str(path), doraise=True)
94
+ except py_compile.PyCompileError as exc:
95
+ failures.append((path, str(exc)))
96
+ except OSError as exc:
97
+ failures.append((path, f"could not read file: {exc}"))
98
+
99
+ if failures:
100
+ for path, msg in failures:
101
+ _log_failure("py_compile", f"{path.relative_to(REPO_ROOT)}: {msg}")
102
+ return False
103
+
104
+ _log_pass("py_compile", f"{len(files)} file(s) compiled cleanly")
105
+ return True
106
+
107
+
108
+ def check_requirements_parseable() -> bool:
109
+ """Verify every non-blank, non-comment line in requirements.txt looks like
110
+ a PEP 508 requirement. We don't resolve them — that is the installer's job
111
+ — we just confirm the file is structurally sane."""
112
+ req_file = REPO_ROOT / "requirements.txt"
113
+ if not req_file.exists():
114
+ _log_failure("requirements", "requirements.txt missing")
115
+ return False
116
+
117
+ # PEP 508 is rich. We use a conservative regex that allows the common
118
+ # forms used in this repo: name, name==x, name>=x, name>=x,<y, with
119
+ # optional extras and markers.
120
+ pattern = re.compile(
121
+ r"""
122
+ ^ # start
123
+ [A-Za-z0-9][A-Za-z0-9._-]* # project name
124
+ (\[[A-Za-z0-9,_.-]+\])? # optional extras: [extra1,extra2]
125
+ \s*
126
+ ( # optional version specifier
127
+ (==|!=|<=|>=|<|>|~=)\s*[A-Za-z0-9.*+!_-]+
128
+ (\s*,\s*(==|!=|<=|>=|<|>|~=)\s*[A-Za-z0-9.*+!_-]+)*
129
+ )?
130
+ (\s*;\s*[^#]+)? # optional PEP 508 marker
131
+ \s*(\#.*)? # optional trailing comment
132
+ $
133
+ """,
134
+ re.VERBOSE,
135
+ )
136
+
137
+ lines = req_file.read_text(encoding="utf-8").splitlines()
138
+ bad: list[tuple[int, str]] = []
139
+ parsed = 0
140
+ for n, raw in enumerate(lines, 1):
141
+ line = raw.strip()
142
+ if not line or line.startswith("#"):
143
+ continue
144
+ if not pattern.match(line):
145
+ bad.append((n, raw))
146
+ continue
147
+ parsed += 1
148
+
149
+ if bad:
150
+ for n, raw in bad:
151
+ _log_failure(
152
+ "requirements",
153
+ f"requirements.txt line {n}: not a recognizable PEP 508 requirement: {raw!r}",
154
+ )
155
+ return False
156
+
157
+ _log_pass("requirements", f"{parsed} requirement line(s) parsed")
158
+ return True
159
+
160
+
161
+ def check_readme_frontmatter() -> bool:
162
+ """Verify README.md starts with an HF Spaces YAML frontmatter block and
163
+ contains the keys HF Spaces expects."""
164
+ readme = REPO_ROOT / "README.md"
165
+ if not readme.exists():
166
+ _log_failure("readme_frontmatter", "README.md missing")
167
+ return False
168
+
169
+ text = readme.read_text(encoding="utf-8")
170
+ if not text.startswith("---\n") and not text.startswith("---\r\n"):
171
+ _log_failure(
172
+ "readme_frontmatter",
173
+ "README.md does not start with an HF Spaces YAML frontmatter delimiter (---).",
174
+ )
175
+ return False
176
+
177
+ # Find the closing delimiter
178
+ body = text.split("\n", 1)[1] if text.startswith("---\n") else text.split("\r\n", 1)[1]
179
+ closing_match = re.search(r"^---\s*$", body, re.MULTILINE)
180
+ if not closing_match:
181
+ _log_failure(
182
+ "readme_frontmatter",
183
+ "README.md frontmatter has no closing --- delimiter.",
184
+ )
185
+ return False
186
+
187
+ frontmatter_text = body[: closing_match.start()]
188
+ # Minimal YAML key:value parser sufficient for HF frontmatter (flat key/value pairs).
189
+ found_keys: set[str] = set()
190
+ for line in frontmatter_text.splitlines():
191
+ stripped = line.strip()
192
+ if not stripped or stripped.startswith("#"):
193
+ continue
194
+ if ":" in stripped:
195
+ key = stripped.split(":", 1)[0].strip()
196
+ found_keys.add(key)
197
+
198
+ missing = REQUIRED_README_FRONTMATTER_KEYS - found_keys
199
+ if missing:
200
+ _log_failure(
201
+ "readme_frontmatter",
202
+ f"missing required HF Spaces frontmatter key(s): {sorted(missing)}",
203
+ )
204
+ return False
205
+
206
+ _log_pass("readme_frontmatter", f"frontmatter has {sorted(found_keys & REQUIRED_README_FRONTMATTER_KEYS)}")
207
+ return True
208
+
209
+
210
+ def main() -> int:
211
+ print(f"[repo_validate] repo root: {REPO_ROOT}")
212
+ checks = [
213
+ ("py_compile", check_py_compile),
214
+ ("requirements", check_requirements_parseable),
215
+ ("readme_frontmatter", check_readme_frontmatter),
216
+ ]
217
+ overall_ok = True
218
+ for name, fn in checks:
219
+ ok = fn()
220
+ if not ok:
221
+ overall_ok = False
222
+ # Fail fast keeps the diagnostic obvious. If you want to see all
223
+ # failures in one run, comment out the next line.
224
+ print(f"[repo_validate] stopping after first failure ({name})", file=sys.stderr)
225
+ return 1
226
+ if overall_ok:
227
+ print("[repo_validate] all checks passed")
228
+ return 0
229
+ return 1
230
+
231
+
232
+ if __name__ == "__main__":
233
+ # Sanity import-guard for older Python versions (HF Space runs 3.12, but
234
+ # the local dev machine may be 3.11 or earlier on Windows).
235
+ if sys.version_info < (3, 9):
236
+ print("[repo_validate] requires Python 3.9 or later", file=sys.stderr)
237
+ sys.exit(1)
238
+ # ast import is here only so a typo above is caught by py_compile when this
239
+ # very file is validated by the script itself.
240
+ _ = ast
241
+ sys.exit(main())