# AGENTS.md — outcomefinder ## The kit wins Where this file, a personal instruction file, or a note from another bot contradicts the Build Kit (`kit/decisions.md`), **the kit is right**. Follow it, say which line differed, and fix this file in the same commit. ## What this app is **OutcomeFinder** — describe a decision in plain words, the app works out the factors that matter, you weight each one from **−10 (must never have it)** through **0 (don't care)** to **+10 (must have it)**, and it returns a ranked list of outcomes: products with real prices and links, or options in a decision. Each result carries the sentence that explains why it landed where it did. Two tabs: **Products** (price watched daily) and **Decisions**. For Addi plus a few invited friends; no public sign-up. ## What it is made of (see `MODULES.md` for the full map) | Piece | Where | What it does | |---|---|---| | Screens | `src/app.js`, `src/views.js` | One server, one port, every page and every action | | Sign-in | `src/auth.js` | scrypt password hashes, signed session cookie backed by a row, rate-limited login, invite links | | Ranking | `lib/domain/` | **The order is arithmetic, never the AI's opinion**: weights × 0–10 fulfilment, veto demotion, one sentence per result | | AI flow | `src/flows.js`, `src/ai-config.js` | The two prompts (factors + ≤4 questions; candidates rated per factor) and the strict reader of the answers | | AI connection | `lib/ai/openai.js` | One OpenAI-compatible connection set by the admin (base URL, key, model) | | Storage | `migrations/`, `src/store/`, `lib/postgres/` | Versioned SQL, every statement in one file, a zero-dependency Postgres client | | Price watching | `src/watch.js` | Once a day: read the machine-readable price off a watched page, record it, flag an absurd jump | | Status | `lib/status/`, `src/catalog.js` | The standard endpoints and the checks the monitor reads | ## Getting started (any machine, ~5 minutes) 1. `git clone` the repo (it lives on the server: `/srv/git/outcomefinder.git`). 2. Install dependencies: **none** — plain Node.js 18+, no `npm install`, no `node_modules`. 3. Environment: `APP_NAME` (required), `PORT` (default 8080), `DATABASE_URL` (required for real use; without it the app starts but stores nothing and says so), `LOGIN_EMAIL`/`LOGIN_PASSWORD`/`LOGIN_NAME` (the admin created once at first boot), `SESSION_SECRET` (optional; without it one is generated and kept in the database). 4. `node --test test/*.test.js` — the full suite; it must be green before and after any change. 5. `APP_NAME=outcomefinder node src/index.js` — status at `/status/summary`, this file at `/status/onboarding`. 6. The database suite needs a real Postgres: `bash bin/test-db.sh` (it creates and drops a scratch database on the server — see `DECISIONS.md` D016). ## Where things live - Code: `src/` (app), `lib/` (vendored and domain code), `migrations/` (schema), `test/`. - The machine-readable map: `APP-MAP.md` / `APP-MAP.json`; the hierarchy: `MODULES.md`. - Plans and history: `PLAN.md`, `progress.md`, `DECISIONS.md`, `chatlog/`. ## How to change this app safely You will not remember this app. Read it before you touch it. 1. Read `APP-MAP.md`, then `MODULES.md`, then `DECISIONS.md` (the settled questions are not reopened). 2. **Impact list first:** `node kit-map/bin/map.mjs --find `. 3. Test first, then implement; one logical change, one small commit. 4. `node bin/process.mjs verify` — the commit gate: suite, database suite, map/docs in the same commit, and the app answering its own status page green. A red step refuses the commit; never `--no-verify`. 5. `node kit-map/bin/map.mjs --write` then `--check` after any file, route or table change. 6. Regressions: revert to the last green commit. Never fix forward over a red test. 7. A new subsystem gets a check in `src/catalog.js` **with a red proof** in the same commit. ## Operations - **Deploy:** from the repo, `APP_NAME=outcomefinder DOMAIN=outcomefinder.stefanfehr.com SSH_TARGET=root@5.222.51.12 bash /opt/appkit/hosting/deploy.sh` (run on the bot's computer; it pushes/tests/migrates/restarts/polls and refuses a red build). Never pass `PORT`. - **Rollback:** `git revert` (or check out the last green commit), push, deploy again. - **Status:** `/status/summary` (the monitor reads this), `/status/modules`, `/status/onboarding`. - **The lock:** `kit.gate.json` declares the gate; `deploy.sh` proves it on loopback (6/9) and again from outside (9/9), and the app proves it about itself every minute (`public-lock` check, `src/public-lock.js`). - **Secrets:** `/etc/apps/outcomefinder.env` (0640 root:apps, read by systemd). Never in the repo, never in a log, never in a page. - **Database:** `outcomefinder`, role `app_outcomefinder`, on 127.0.0.1. Backups are the shared nightly job (`/opt/appkit/backups/restore.sh --list`). ## Who runs this - The project bot (Rakazo bot: AppBuilder) builds and operates the app. - **Addi** owns it: he decides what it does, sets the admin password, and sets up the AI connection in Settings. He is not a programmer — every report to him is in plain language, with evidence he can click.