Specification, 99 acceptance tests, guardrails and prompts for an agent to build, in your own environment, the patient care system of a nutrition practice: in-person and online scheduling with confirmation and follow-up, a meal plan with versions, a diary for meals, water and weight, opt-in reminders and a Telegram team desk. The bot never prescribes. The system is not implemented yet: this repository is the plan, and you run the implementation.

There is no ready-made app here. There is the contract for what the app must do, the test suite that proves it, and the guardrails that stop the agent from cheating. The builder is Claude Code or Codex, running on your machine, on your subscription. Its sibling Atende Clínica, which this kit is based on, was built exactly this way and closed 93 of 93 tests.
Scheduling for first visits and follow-ups, in person or online (the team supplies the link), with no double booking. A meal plan entered by the nutritionist, with versions, and a bot that answers only what is in that patient's plan. Python 3 with the standard library only, plus SQLite, one practice per installation.
A 21-section specification, 99 black-box tests, 19 proposed decisions, a map to Raio-X, prompts for /goal and for the headless loop, and the guardrails that freeze the contract. An adversarial validator went over everything and fixed 10 problems, 1 of which would have blocked execution.
No-shows, follow-ups that never happen and idle slots are the leaks that scheduling attacks. The system returns atendimentos_mes, falta_pct, ocupacao_pct, clientes_novos_mes and retorno_atual_pct for the Raio-X de Margem dashboard, which is the source of the business rules.
A physical sign (chest pain, fainting, vomiting that will not stop, hypoglycemia) is answered with 192 and the emergency room. Eating disorders and self-harm (binge eating, purging, laxatives, suicidal thoughts) are answered with 188 (CVV) and the nutritionist. Both open a high-priority queue entry, even while a human chat is open. 192 and 188/CVV are Brazilian emergency numbers: in another country, the practice must swap in its local emergency contacts.
The plan, diary and weight are sensitive data: a patient can export everything, and deletion erases it (it does not merely anonymize). "PARAR" (stop) blocks everything automatic. Campaigns need specific consent. LGPD is the Brazilian data protection law: in another country, the practice must apply its local health-data law.
Raio-X researched the medical, dental and physiotherapy councils (CFM, CFO and COFFITO), not the nutritionists' council (CFN). The campaign guardrail is only the common minimum (promising results, before-and-after). The owner must confirm the CFN rules before publishing any campaign.
This is the flow of the planned system, what the agent will build. A dependency-free Python server, SQLite in a data folder and Docker for the VPS. Evolution and Telegram come in only through environment variables; without them the outbox is simulated and no network call leaves the machine.
Through the chat or WhatsApp the patient books, confirms with 1 or 2, asks for the online visit link, checks meu plano (my plan) or o que posso comer no lanche da tarde (what can I eat at the afternoon snack), logs 2 copos (2 glasses), pulei o almoço (I skipped lunch) or peso 82,5 (weight 82.5), gets FAQ answers, asks for a human and sends "PARAR" when they want no more messages. The bot's chat commands are in Portuguese.
Notices of new and cancelled bookings, and the commands /agenda, /alertas, /fila, /responder and /encerrar, also as a direct reply to the patient's message.
With a token: schedule, patients, meal plan, diary and adherence, weight series, FAQ, records, blocked time and the human queue.
Meals by time of day, with options and notes, in versions (the latest is the active one). The team reviews it and sends it to the patient. Outside the plan, "can I eat chocolate?" becomes "I don't advise outside the plan" and goes to a human. There is no nutrition calculation in v1.
Glasses of water against a goal, meals done or skipped, a meal photo (metadata only, no image is downloaded) and a weight series with the change. The reply to a weight is neutral and non-judgmental: the system never comments on progress.
The team sets up, at the visit, reminders for water and for the plan's meals, at the times the patient chose. There is a tolerance window: a late reminder does not pile up. parar lembretes (stop reminders) turns off reminders only.
To run the plan you only need Python for the tests and an agent logged in on your subscription. Docker is only needed for the final check and the deploy; Evolution and Telegram are optional and yours.
The tests use pytest (a development tool). The application itself will have no dependencies.
# check python3 --version python3 -m pip install pytest
On your subscription, no paid API. For the headless loop, clone execucao-longa into ~/projetos.
# check codex --version # or: claude --version
Docker does the final build and the VPS deploy. An Evolution instance and a Telegram bot are needed only if you want those channels; credentials live in .env.
# check docker --version
The commands below are the repository's own. The cycle: answer the decisions, freeze the contract, run the agent until 99 passed and LIMITES OK, and check with the independent verification.
There is no ./atende yet: the repository only has the plan. Check that the suite is collected without errors and that nothing passes yet (without the implementation the tests fail or error out, which is expected).
git clone https://github.com/inematds/atende-nutricao && cd atende-nutricao python3 -m pytest -q --collect-only | tail -n 1 # 99 tests collected python3 -m pytest -q | tail -n 1 # 15 failed, 84 errors (0 passed)
Read docs/DECISOES-ABERTAS.md: 19 default proposals already applied in the specification and the tests. Answering "ok em tudo" (all fine) unlocks the run. If you change anything marked ⚠ (for example the campaign guardrail, the alert words or the weight rules), edit docs/ESPECIFICACAO.md and the tests before freezing. For a real pilot, also replace exemplos/nutricao.json with your own hours, services, FAQ and sample meal plan. Also answer the CFN question, described in the notice box below. The docs are in Portuguese.
less docs/DECISOES-ABERTAS.md
With everything committed, the script records the hash of tests/, pytest.ini, the specification and the two verifiers, plus the base commit in hash-congelado.txt, and makes one commit. From then on any change to the tests is detected. If there are pending changes, the script stops and asks for a commit first.
git add -A && git commit -m "contrato v1" bash longrun/2026-10-05-nutri-v1/congelar.sh
a) Headless loop with Codex (recommended). loop.env sets 20 cycles of 30 min, 8 GB per cycle, a stop after 3 cycles with no progress, model gpt-6-astra and CODEX_ARGS="-c sandbox_workspace_write.network_access=true": without it the Codex sandbox blocks the tests' local server.
~/projetos/execucao-longa/tools/loop-longrun.sh longrun/2026-10-05-nutri-v1
b) /goal in Claude Code. Open a new Claude Code session in the project folder and follow longrun/2026-10-05-nutri-v1/prompt-goal-claude.md: paste the /goal condition (the output must show 99 passed and LIMITES OK) and, as the first message, the block from prompt-goal-codex.md starting at RESULTADO:.
claude # new session, inside atende-nutricao
c) Codex TUI. Paste the contents of longrun/2026-10-05-nutri-v1/prompt-goal-codex.md.
codex -c sandbox_workspace_write.network_access=true
In the loop, loop.log shows each cycle and progress.md has one line per checkpoint. The loop's exit code tells you what happened: 0 done (the final test passed), 1 cycle limit reached, 2 stopped after 3 cycles with no progress, 3 another loop is already running in the folder. A test that conflicts with the specification goes to failures.md: it is a human gate, and the agent must not adjust a test or the specification.
tail -f longrun/2026-10-05-nutri-v1/loop.log cat longrun/2026-10-05-nutri-v1/state.md
When the agent says "done", run the three commands. The last one is something the agent has never seen: it looks for fixture values copied into the code, brings up a practice that never appeared (20-minute step, 40-minute visit, follow-up after 15 days, no online visits, a meal plan with differently named meals, another clock) and runs docker build with a healthcheck. Then open / and /equipe in the browser.
python3 -m pytest -q tests/ # 99 passed bash longrun/2026-10-05-nutri-v1/verificar-limites.sh # LIMITES OK python3 longrun/2026-10-05-nutri-v1/verificar-independente.py # INDEPENDENTE OK
With the system implemented, copy the example, replace TROQUE-ESTE-TOKEN and start the server. The patient chat is at / and the team page at /equipe (header X-Token).
mkdir -p dados && cp exemplos/nutricao.json dados/nutricao.json ./atende serve --porta 8080 --dados dados
The deploy is yours, with your credentials. The agent itself writes the deploy README as part of the goal: bring up docker compose (port only on 127.0.0.1:8080, behind an HTTPS proxy), the Evolution webhook at /webhook/evolution/<secret> (event MESSAGES_UPSERT), the Telegram webhook with setWebhook and secret_token, and the daily backup (./atende backup in cron).
cp .env.exemplo .env && chmod 600 .env # fill in EVOLUTION_*, TELEGRAM_*, WEBHOOK_SEGREDO docker compose up -d --build
The advertising rules for nutritionists, set by the Brazilian Federal Council of Nutritionists (CFN), have not been researched in this kit yet. The campaign guardrail (section 11 of the specification) is the minimum common to the medical, dental and physiotherapy councils: it blocks promessa_resultado (guaranteed, guaranteed result, 100%) and antes_depois (before and after). No CFN article is cited, on purpose. The practice owner confirms the CFN rules (price, promotions, testimonials, before and after) before publishing any campaign; if there is an extra rule, it enters as a new code and changes the contract (decision 4 in docs/DECISOES-ABERTAS.md).
Everything the agent needs to build, and everything that stops it from pretending it built.
Black-box, over HTTP and the command line, in 11 files.
test_agenda.py 16 test_integracoes.py 15 test_conversa.py 13 test_cadastros.py 10 test_diario.py 10 test_lembretes.py 9 test_plano.py 8 test_basico.py 6 test_campanhas.py 5 test_docker.py 4 test_lgpd_raiox.py 3
docs/ESPECIFICACAO.md: execution, nutricao.json, scheduling rules, authentication, HTTP API, conversation, waitlist, confirmation and reminders, meal plan, diary and weight, campaigns, export to Raio-X, LGPD, what stays out of v1, pages, records, schedule management, database, Evolution, Telegram and Docker. Nutrition calculation, photo analysis, payments, insurance billing and multiple practices are explicitly out.
A frozen hash of tests/, pytest.ini, the specification and the two verifiers. File scope: the agent only touches the code and its own records. No external dependency, no API key, no external URL, no media download and no 0.0.0.0 in the code. verificar-limites.sh checks all of that and prints LIMITES OK.
Level 4, hidden from the agent: it looks for fixture values in the code, brings up a practice it has never seen, with every argument explicit, and runs docker build and a container healthcheck. Only that makes "99 passed" prove general logic.
Language, channels, the campaign guardrail, what the bot answers, alert signs, neutral weight replies, opt-in reminders, the meal plan, photos as metadata only, online visits, follow-ups, LGPD, Raio-X and one practice per installation. Only the items marked ⚠ change the contract.
A validator that had not seen the planning checked tests against the specification, redid the arithmetic and tried to get around the guardrails. It found and fixed 10 problems: 1 blocked execution, 6 got in the way and 3 were cosmetic. The full account is in docs/VALIDACAO.md and each fix has a line in FALHAS.md.
No-shows, follow-ups that never return and idle slots: docs/MAPA-RAIO-X.md links each leak in the clinica package to a v1 piece or to the reason it stays out. More in the Raio-X de Margem guide.
LGPD for health data (confirmation, follow-up, reminders and the plan as health care; campaigns only with consent; export and erase) and Brazil's emergency contacts: 192 and 188 (CVV). All of these are Brazilian: in another country, the practice must swap in its own emergency contacts and privacy law. The CFN rules are still to be confirmed, as in the notice box at the end of the user guide.
The plan is ready and validated. The implementation does not exist yet: it is born when you run the /goal or the loop, using the execucao-longa method. Atende Clínica followed the same path and closed 93 of 93.
99 passed and LIMITES OK, then the independent verification. Today the system is not implemented.