Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Local single-process self-host (`field-notes serve`) needs NONE of this — it
# defaults to a file-backed SQLite under ~/.field-notes and disables auth on a
# loopback bind. The vars below are for the Postgres / networked dev stack
# (docker-compose, Heroku/Fly) only.

FIELD_NOTES_KEY=changeme
DATABASE_URL=postgresql+asyncpg://field_notes:field_notes@localhost:5432/field_notes
POSTGRES_USER=field_notes
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Mikul Rai

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
.PHONY: dev build restart stop status logs update test lint format fmt web-dev api-dev seed clean
.PHONY: dev build build-web restart stop status logs update test lint format fmt web-dev api-dev seed clean

# ---- Always-on local stack (Option B: native mamba Postgres + native uvicorn) ----

# Build the React app into apps/web/dist/ (served by the always-on API).
build:
cd apps/web && npm run build

# Build the SPA AND stage it inside the API package so it ships in the wheel.
# Run this (on a machine with Node) before committing frontend changes or
# building a release — `uvx --from git+<repo> field-notes` serves this _web/.
#
# VITE_DEFAULT_KEY=local bakes a throwaway key into the local bundle so the UI
# skips the "enter your key" gate; the loopback server has auth disabled and
# ignores it. (A networked deploy builds its own dist without this.)
build-web:
cd apps/web && npm ci && VITE_DEFAULT_KEY=local npm run build
rm -rf apps/api/field_notes_api/_web
cp -r apps/web/dist apps/api/field_notes_api/_web
@echo "staged apps/web/dist -> apps/api/field_notes_api/_web (commit it so uvx-from-git serves the UI)"

# Restart the always-on API (after backend code changes or rebuilding the web).
restart:
@PIDFILE=data/api.pid; \
Expand Down
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,55 @@ ML research notebook with MCP-driven agents. Cells (agent, markdown, empty) live
inside projects; humans verify / reject / lock; agents push results via the MCP
server and observe what the human did.

## Run it yourself (local, no setup)

One command — needs only [uv](https://docs.astral.sh/uv/). No Node, no Docker,
no database server:

```bash
uvx --from git+https://github.com/themikulrai/field-notes field-notes serve
```

This creates `~/.field-notes/` (a SQLite DB + a `media/` folder), runs the
migrations, and opens the notebook at <http://127.0.0.1:8000>. **Your data is
that one folder** — back it up by copying it. It binds to loopback with auth
disabled, so there's no key to manage; to expose it on a network pass
`--host 0.0.0.0 --key <secret>`.

Point an MCP host (Claude Code, etc.) at the local API. The `local` key is a
throwaway — the loopback server ignores it:

```json
{
"mcpServers": {
"field-notes": {
"command": "uvx",
"args": ["--from", "git+https://github.com/themikulrai/field-notes", "field-notes-mcp"],
"env": { "FIELD_NOTES_API_URL": "http://127.0.0.1:8000", "FIELD_NOTES_KEY": "local" }
}
}
}
```

### Bring your existing notes (no data loss)

Migrate a hosted instance into your local copy. It's a **copy** — the source
DB is never written:

```bash
# 1. copy projects / cells / verdicts / events (preserves IDs + links)
field-notes import-db --source "postgres://…your DATABASE_URL…"
# 2. download the baked media tarballs so /media/... references resolve
field-notes fetch-media
# 3. report any media a cell references but the local copy is missing
field-notes verify-media
# 4. open it
field-notes serve
```

If you outgrow SQLite (heavy parallel agent writes), point at Postgres with the
same code: `DATABASE_URL=postgres://… field-notes serve`.

## Architecture

```
Expand Down
1 change: 1 addition & 0 deletions apps/api/alembic.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[alembic]
script_location = alembic
prepend_sys_path = .
path_separator = os
version_path_separator = os
# sqlalchemy.url is set programmatically in alembic/env.py from DATABASE_URL.
sqlalchemy.url =
Expand Down
4 changes: 4 additions & 0 deletions apps/api/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
database_url = database_url.replace("postgres://", "postgresql://", 1)
if database_url.startswith("postgresql+asyncpg://"):
database_url = database_url.replace("postgresql+asyncpg://", "postgresql://", 1)
# Local single-process self-host uses sqlite+aiosqlite (async); Alembic needs a
# sync driver, so collapse it to the stdlib sqlite dialect.
if database_url.startswith("sqlite+aiosqlite://"):
database_url = database_url.replace("sqlite+aiosqlite://", "sqlite://", 1)
if database_url:
config.set_main_option("sqlalchemy.url", database_url)

Expand Down
17 changes: 13 additions & 4 deletions apps/api/field_notes_api/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@


def main() -> None:
"""Run the FastAPI app under uvicorn."""
# TODO: Chunk 2 — wire env-driven host/port/log-level via pydantic-settings.
"""Run the FastAPI app under uvicorn.

Host/port come from env: FIELD_NOTES_HOST (default 0.0.0.0 for container
deploys) and $PORT (Heroku) / FIELD_NOTES_PORT (default 8000). The local
single-process path uses `field-notes serve` instead, which binds loopback.
"""
import os

import uvicorn

host = os.getenv("FIELD_NOTES_HOST", "0.0.0.0")
port = int(os.getenv("PORT") or os.getenv("FIELD_NOTES_PORT") or "8000")

uvicorn.run(
"field_notes_api.main:app",
host="0.0.0.0",
port=8000,
host=host,
port=port,
reload=False,
)

Expand Down
201 changes: 201 additions & 0 deletions apps/api/field_notes_api/_web/assets/embed-S92vvM1_.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions apps/api/field_notes_api/_web/assets/index-Cgs-dOlY.css

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions apps/api/field_notes_api/_web/assets/index-CyAub9oQ.js

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions apps/api/field_notes_api/_web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Field Notes</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;600;700&family=Newsreader:ital,wght@0,400;1,400;1,500&family=Roboto+Mono:wght@400;500&display=swap"
/>
<script type="module" crossorigin src="/assets/index-CyAub9oQ.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-Cgs-dOlY.css">
</head>
<body>
<div id="root"></div>
</body>
</html>
8 changes: 6 additions & 2 deletions apps/api/field_notes_api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ def _verify_sse_token(token: str) -> bool:

async def require_api_key(x_field_notes_key: str | None = Header(default=None)) -> None:
"""Header-based auth dependency for normal JSON endpoints."""
expected = get_settings().field_notes_key
if not x_field_notes_key or not hmac.compare_digest(x_field_notes_key, expected):
settings = get_settings()
if settings.field_notes_auth_disabled:
return
if not x_field_notes_key or not hmac.compare_digest(x_field_notes_key, settings.field_notes_key):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="missing or invalid api key",
Expand All @@ -90,6 +92,8 @@ async def require_api_key_query(
- `?token=...`: HMAC-signed short-lived token from POST /sse-token (preferred)
- `?key=...`: raw shared secret (DEPRECATED — leaks via Heroku router logs)
"""
if get_settings().field_notes_auth_disabled:
return
if token:
if _verify_sse_token(token):
return
Expand Down
Loading
Loading