File size: 7,116 Bytes
46c632a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Codex kickoff prompt β€” paste this into Codex

You are working in the **StoryCode** repository (a Gradio app for the Build Small
hackathon). The architecture and all the hard, deterministic code are already
written and tested. Your job is to **deploy the model on Modal, wire it up, test
the whole app end-to-end, tune the narration, and ship it** β€” without breaking the
rules. Work through the steps in order. Do not skip ahead.

## 0. Read first (do not skip)
- `HANDOFF.md` β€” the authoritative do-this-next checklist.
- `AGENTS.md` β€” the hard rules. The most important one: **static analysis is the
  source of truth; the model only narrates it.** Never let the model invent files,
  edges, or safe-to-edit verdicts, and never override `analyzer/` output.
- `README.md` β€” what the app is and how it's meant to work.

Then confirm the baseline works with **no GPU**:
```
python -m pip install -r requirements.txt
python tests/test_analyzer.py        # must print "10/10 passed"
python app.py                        # open it, click "Try the sample project"
```
With no model endpoint set, the app uses a truthful model-free fallback story β€”
the Story/Map/Safe-to-Edit/Dependencies tabs must all render. If anything errors,
fix that before touching Modal.

## 1. Deploy MiniCPM4.1-8B on Modal (this is the "download + use the model" step)
The model is **downloaded and baked into the Modal image automatically** by
`modal_app.py` (it calls `huggingface_hub.snapshot_download("openbmb/MiniCPM4.1-8B")`
at image-build time, so there is no per-request download). You do NOT download the
model onto this machine β€” it lives on Modal's GPU.

Do this:
```
python -m pip install modal
modal token new                                   # one-time auth
modal secret create storycode-api MODAL_API_KEY=<pick-a-long-random-secret>
modal deploy modal_app.py                          # builds image (downloads weights), deploys
```
`modal deploy` prints a public URL. The OpenAI base_url is **that URL + `/v1`**.

Before deploying, open `modal_app.py` and:
- Confirm `VLLM_VERSION` matches what the **MiniCPM4.1-8B Hugging Face model card**
  lists as the supported vLLM version (the model uses custom code β†’ it serves with
  `--trust-remote-code`, already set).
- **Hybrid-reasoning caveat:** MiniCPM4.1-8B can run in a deep "thinking" mode. We
  want fast, grounded narration, NOT long chain-of-thought. Check the model card
  for how to disable thinking (often a chat-template flag or a system-prompt
  convention) and apply it. If `guided_json` is ignored, verify the installed vLLM
  supports the `xgrammar` guided-decoding backend.

Smoke-test the live endpoint (replace URL + secret):
```
curl -s -H "Authorization: Bearer <secret>" \
  <printed-url>/v1/chat/completions \
  -d '{"model":"openbmb/MiniCPM4.1-8B",
       "messages":[{"role":"user","content":"Reply with JSON only: {\"ok\": true}"}],
       "max_tokens":50}'
```
You should get a JSON chat completion back. If the container is slow to start the
first time, that is the GPU cold-start β€” retry after ~1–2 minutes.

## 2. Wire the secrets
Locally:
```
cp .env.example .env
# set MODAL_ENDPOINT_URL=<printed-url>/v1   and   MODAL_API_KEY=<secret>
```
The app reads these via `config.py` β†’ `llm.py`. (On the HF Space later, set the same
two values as Space secrets.)

## 3. Run the real (model-backed) app and verify every tab
```
python app.py
```
Click **"Try the sample project"** and confirm, with the live model:
- **πŸ“– The Story** renders, and the **Plain English** panel beside it is filled.
- Switching **Story style** (Simple Walkthrough / Kids Book / Thriller / News /
  Recipe) and **difficulty** re-narrates the Story **without re-analysing** (it
  should be fast β€” it reuses the cached per-file summaries).
- **πŸ—ΊοΈ Architecture Map** draws a Mermaid diagram (boxes grouped by job, arrows).
- **🚦 Safe to Edit** shows `config.py` and `app.py` as πŸ”΄, the rest 🟠/🟒.
- **πŸ“¦ Dependencies** explains openai / chromadb / gradio in plain English.
- Upload a `.zip` with a fake API key in it β†’ the πŸ”’ "we hid N secrets" banner shows.

If the model returns malformed or empty output, the app falls back to the
deterministic story β€” that's expected resilience, but your goal is for the live
model path to work.

## 4. Tune the narration (your main creative work β€” commit these)
Edit **only `story.py`** (the prompts). Iterate until each of the 5 styles Γ— 3
difficulty levels is **accurate AND in-voice** and never invents anything not in the
facts. Keep the grounding system message intact. After any change:
```
python tests/test_analyzer.py        # must STILL be 10/10
```
Make small, frequent, **Codex-attributed commits** with clear messages (the OpenAI
Codex prize depends on Codex-attributed commit history).

## 5. Real-user proof (required for the Backyard AI track)
Run a real, non-trivial project a non-coder built (ideally the friend's actual
Claude-generated app) through StoryCode. Capture: a short quote from them,
before/after screenshots, and the produced story. Add these to `README.md` under
"The person I built it for".

## 6. Deploy + submission assets
- Create a Gradio Space under the **`build-small-hackathon`** org, push this repo,
  and set the two Space secrets (`MODAL_ENDPOINT_URL`, `MODAL_API_KEY`). Verify the
  Space reaches Modal (check Modal logs) and **test it on a phone**.
- Record a 60–90s demo video (upload β†’ Story β†’ Map β†’ Safe-to-Edit) and link it in
  the README.
- Push to a **public GitHub repo** with the Codex-attributed commits; link it in
  the README.
- Post once on social and link it. Confirm the README frontmatter tags are present.

## Hard rules β€” do not violate (see AGENTS.md)
1. Do **not** add `torch` / `vllm` / `transformers` to `requirements.txt`. The GPU is
   on Modal; the Space is a CPU container.
2. Core model must be a **MiniCPM ≀32B** (`openbmb/MiniCPM4.1-8B`). Don't swap in a
   non-OpenBMB model.
3. Do **not** claim the Tiny Titan badge (our model is ~8B, not ≀4B).
4. Keep the custom UI (`ui/styles.css`). Don't revert to the default Gradio theme.
5. Never display or send code that hasn't passed `ingest.redact_secrets`.
6. If you change anything under `analyzer/`, update `tests/test_analyzer.py` and keep
   it green. The Architecture Map and Safe-to-Edit must stay computed from the
   ProjectModel, never from the model's text.

## When you're done, report back
List, explicitly: the live Modal endpoint URL (without the secret), the result of
the curl smoke test, whether each of the 4 tabs worked with the live model, which
prompts in `story.py` you changed and why, the Space URL, and anything you could
NOT get working. Do not claim a step passed unless you actually ran it.

## Do NOT build these yet (post-MVP queue β€” only after steps 1–6 ship)
Grounded chat Q&A β†’ "How do I change X?" β†’ error detective β†’ dependency-risk polish
β†’ save/share β†’ PDF export β†’ GitHub-URL ingestion β†’ before/after edit preview. One
feature per commit, in that order, and only once the MVP above is deployed.
```