# Setup

Nidhi needs no install, no account and no build step to use. There are two paths:
run it, or work on it.

## 1. Run it

### Nothing at all — the hosted app

Open <https://drsamonline.github.io/NIDHI/play/>. Served over https, so sealing
works, and nothing is installed. Your records live in that browser's storage for
that address: export a copy before you clear site data, and note that the hosted
page and a local copy are different vaults.

### Any computer, no tools

Download the repository (**Code → Download ZIP**), unpack it, and open
`index.html` — that is the landing page. **Open the vault** takes you to
`play/index.html`, which is the app itself.

That works, with one limit: browsers only expose Web Crypto in a *secure context*,
and a plain `file://` path is not one. Everything works except **Sealing**, which
will tell you so when you press it.

### Any computer, with a local server (sealing works)

```bash
cd NIDHI
python3 -m http.server 8080
```

Open <http://localhost:8080/play/>. `localhost` counts as a secure context, so
sealing works here.

### Windows

Same as above. If you do not have Python, `dist/index.html` opens by double-click
and gives you the same app without sealing.

### Android

1. Copy the folder to the phone, or host `dist/index.html` on any https address.
2. Open `play/index.html` in Chrome. From a `file://` path, sealing is unavailable;
   over https it works.
3. **Menu → Add to Home screen** installs it as an app that opens offline.

Records live in the browser's storage for that site. Clearing site data clears the
vault — export a JSON copy before you do that.

### iPhone / iPad

Open the hosted `dist/index.html` in Safari, then **Share → Add to Home Screen**.
Safari does not give a `file://` page a secure context, so host it or seal nothing.

## 2. Work on it

Requirements: Node 18 or newer, Python 3.9 or newer. Nothing else — no npm
install, no bundler.

```bash
node tests/test-nidhi.js       # the record model
./tools/run-tests.sh           # everything, and writes AUDIT_REPORT.md
python3 tools/build.py         # rebuild dist/index.html
```

`play/index.html` loads `kits/` and `src/` as separate files, which is what you want
while editing. `dist/index.html` is the same app with every script and stylesheet
inlined, for handing to someone as one file. Never edit `dist/` by hand: change the
sources and run the build.

### Integrity and snapshots

```bash
python3 tools/verify.py write  ~/my-vault          # record a manifest
python3 tools/verify.py check  ~/my-vault          # what changed since?
python3 tools/snapshot.py      ~/my-vault --keep 20
```

The manifest is written to `~/.nidhi/manifest.json` by default — outside the vault,
so it is not measuring itself. `check` exits 1 when anything differs, which is what
lets a script gate on it. It never repairs and never deletes.

### A browser check

The layout, editor, search, persistence and backlinks were checked in a headless
Chromium session during development. To repeat it you need `puppeteer-core` and a
Chromium binary:

```bash
npm i puppeteer-core
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium node tools/e2e.js
```

This is not part of `run-tests.sh`, because the test runner must stay
dependency-free.

## Two devices in one room

Optional. The app works with no host at all; this is for two devices on the same
Wi-Fi that should stay level.

```bash
node tools/sync-host.js --pin 4821
```

It prints a `localhost` address and one address per network interface. Open Nidhi
on both devices, choose **Sync**, and enter one of those addresses and the same
PIN. What arrives is merged field by field, newest wins, tags unioned, and the
view logs what came in.

Three things to know before you rely on it:

- **The PIN gates writing, not reading.** Anyone who can reach the host can read
  the room's event stream. Use it on a network you trust, or not at all.
- **It needs http, so it will not work from an https page.** A browser blocks a
  plain-http LAN host from an https origin. Open the app from `file://` or
  `http://localhost` on the devices that sync.
- **The host stores nothing.** Stop it and the room is gone; each device keeps its
  own vault. Nothing was ever sent anywhere but your own network.

## Where your records live

In the browser's own storage for the origin you opened:

- IndexedDB database `nidhi-db`, object store `records`;
- a small localStorage cache under the `nidhi:` prefix, used only to show the last
  saved copy if the database refuses to open.

Nothing leaves the device. There is no sync, no account and no network call. To
move a vault between devices today, use **Export** on one and **Import** on the
other; the import keeps both copies when a record was edited in both places.

## Troubleshooting

| What you see | Why | What to do |
|---|---|---|
| "Sealing needs a secure context" | The page is on `file://` | Serve it over `localhost` or https |
| "Could not open the local database" | Storage is blocked, or the browser is in a private window with IndexedDB disabled | Use a normal window; the app runs from the last saved copy meanwhile |
| Records vanished | Site data was cleared, or you opened a different origin (`file://` and `localhost` are different stores) | Import your last export; then always export before clearing |
| Export downloads nothing | The browser blocked the download | Allow downloads for the site, or copy the JSON from the console |
