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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install -e ".[dev]"
- run: pip install -e ".[dev,portal]"
- run: ruff check .
- run: mypy src
- run: pytest -q
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# The admin portal, for a demo deploy (Fly.io, Render, or any container host).
FROM python:3.12-slim

WORKDIR /app
COPY . .
RUN pip install --no-cache-dir ".[portal]"

# The portal writes demo state (proposals, approvals, the SQLite target) under here.
ENV FIRSTSYNC_STATE_DIR=/data
ENV FIRSTSYNC_PORTAL_PORT=8000
RUN mkdir -p /data

EXPOSE 8000
CMD ["firstsync", "portal"]
72 changes: 51 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ plain language. Deterministic code decides what actually runs.
> migration engine loads approved data idempotently; and a sync engine keeps the target
> in step afterwards, adding and updating safely while reporting (never acting on) records
> that regressed or vanished. A go-live report and a `trace` view over the audit log tie
> it together. There is no tool by which the model approves, migrates, syncs, or deletes
> anything. The held-out org scored [100% with perfectly calibrated
> questions](#the-held-out-org-e). What remains is a hosted portal, not core logic. This
> is a reference implementation with no customers. See
> it together, and a [web portal](#the-portal) puts the whole flow in the browser. There
> is no tool by which the model approves, migrates, syncs, or deletes anything. The
> held-out org scored [100% with perfectly calibrated questions](#the-held-out-org-e).
> What remains is deploying the portal to a public URL, not core logic. This is a
> reference implementation with no customers. See
> [What is and is not tested](#what-is-and-is-not-tested).

```mermaid
Expand Down Expand Up @@ -159,7 +160,7 @@ Pythons refuse installs outside one.
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest -q # 214 tests, no network, no API key
pytest -q # 220 tests, no network, no API key
python scripts/run_eval.py --baseline # the evaluation, with name matching instead of a model
python -m firstsync.mcp_server # the MCP server, over stdio
```
Expand Down Expand Up @@ -406,26 +407,55 @@ All six weeks are built and merged.
| 3 | Dry-run engine, failure grouping, defect scoring | done |
| 4 | Hash-bound approval gate, idempotent migration engine | done |
| 5 | Sync engine, go-live report, audit-log trace | done |
| 6 | Held-out run on org E, observability, this README | done |
| 6 | Held-out run on org E, observability, the portal, this README | done |

The one piece still ahead is a hosted portal, covered next.
The core is complete; what is left is deploying the portal to a public URL.

## The portal

The portal is the human-facing half — where a person does the one thing the model cannot:
authorize. It walks an administrator through the lifecycle in the browser: connect and see
what the user can read, review Claude's proposed mappings (with the questions it raised),
preview the dry-run of their own data, approve, migrate, and read the go-live report.

It never calls the model. Every page reads state the engines wrote, and approve, migrate
and sync are server-side calls behind the same gates the CLI uses. So the whole portal
runs with no API key: for the demo it loads the proposals Claude produced in the
evaluation runs — real model output, pre-computed — and the review, dry-run, approve and
migrate steps downstream are genuine.

```bash
pip install -e ".[portal]"
firstsync portal # http://localhost:8000
```

Built with FastAPI and server-rendered templates — no client-side framework, so the flow
is a sequence of plain pages and the back button and refresh behave.

## Hosting

There is nothing to host yet: FirstSync runs as a CLI and an MCP server, with SQLite as
the target. The portal is the remaining piece, and the hosting choice follows from what
this project is — a portfolio demo with bursty, near-zero traffic, not a product under
steady multi-tenant load.

For the demo, the portal will run on a managed platform (Fly.io or Render) with serverless
Postgres. Scale-to-zero fits bursty traffic: it costs almost nothing between visits and
wakes on the first request, where an always-on service plus a managed database would bill
around the clock to serve no one. The production path on AWS is App Runner (or ECS
Fargate) behind the same audit and tenancy model, with Amazon RDS or Aurora Serverless for
Postgres and row-level security per tenant — the right shape once there are real tenants
and steady load, and the wrong shape, pure idle cost, for a demo. Right-sizing the host to
the traffic is the decision; the production design is written down so the step up is a
configuration change, not a rewrite.
The portal ships with a `Dockerfile` and a `fly.toml`, so a demo deploy is one command set:

```bash
fly launch --no-deploy # pick an app name and region
fly deploy
```

The hosting choice follows from what this project is — a portfolio demo with bursty,
near-zero traffic, not a product under steady multi-tenant load. The `fly.toml` scales the
machine to zero: it stops when idle and wakes on the first request, so it costs almost
nothing between visits, where an always-on service plus a managed database would bill
around the clock to serve no one. Render with a serverless Postgres add-on is the same
trade in a different wrapper. The production path on AWS is App Runner (or ECS Fargate)
behind the same audit and tenancy model, with Amazon RDS or Aurora Serverless for Postgres
and row-level security per tenant — the right shape once there are real tenants and steady
load, and the wrong shape, pure idle cost, for a demo. Right-sizing the host to the traffic
is the decision; the production design is written down so the step up is a configuration
change, not a rewrite.

Demo state (the SQLite target, proposals, approvals) is ephemeral and resettable from the
UI, so no volume is attached; point `FIRSTSYNC_STATE_DIR` at a mounted volume for durable
state.

## Licence

Expand Down
34 changes: 34 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Fly.io config for the FirstSync demo portal.
# First run: `fly launch --no-deploy` to pick an app name and region, then `fly deploy`.
# Rename the app below to whatever `fly launch` assigns (or set your own).

app = "firstsync-demo"
primary_region = "iad"

[build]
dockerfile = "Dockerfile"

[env]
FIRSTSYNC_PORTAL_PORT = "8000"
FIRSTSYNC_STATE_DIR = "/data"

[http_service]
internal_port = 8000
force_https = true
# Scale to zero: the machine stops when idle and wakes on the next request, so a
# low-traffic demo costs almost nothing between visits.
auto_stop_machines = "stop"
auto_start_machines = true
min_machines_running = 0

[[http_service.checks]]
method = "GET"
path = "/healthz"
interval = "15s"
timeout = "2s"

# Demo state is ephemeral and reset-able in the UI, so no persistent volume is attached.
# For durable demo state, attach a volume and point FIRSTSYNC_STATE_DIR at its mount.
[[vm]]
size = "shared-cpu-1x"
memory = "512mb"
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ firstsync = "firstsync.cli:main"

[project.optional-dependencies]
agent = ["claude-agent-sdk>=0.2"]
portal = [
"fastapi>=0.110",
"uvicorn[standard]>=0.29",
"jinja2>=3.1",
"python-multipart>=0.0.9",
]
dev = ["pytest>=8", "ruff>=0.6", "mypy>=1.10", "hypothesis>=6.100"]

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.package-data]
firstsync = ["target/*.sql"]
firstsync = ["target/*.sql", "portal/templates/*.html"]

[tool.pytest.ini_options]
testpaths = ["tests"]
Expand Down
20 changes: 20 additions & 0 deletions src/firstsync/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
firstsync sync ORG --db PATH bring the target in step with the source, safely
firstsync report ORG where this onboarding stands, in plain language
firstsync trace [--run ID] what the agent did, read back from the audit log
firstsync portal [--port N] run the admin portal (web UI over the engines)
firstsync audit [--last N] show the last audit-log entries

Approval and migration are deliberately CLI commands, not MCP tools: the model proposes;
Expand Down Expand Up @@ -65,6 +66,9 @@ def main(argv: list[str] | None = None) -> int:
tr.add_argument("--run", default=None, help="Show one run's full timeline.")
tr.add_argument("--connection", default=None, help="Only runs touching this connection.")

pt = sub.add_parser("portal", help="Run the admin portal (web UI).")
pt.add_argument("--port", type=int, default=None, help="Port to listen on (default 8000).")

log = sub.add_parser("audit", help="Show the last audit-log entries.")
log.add_argument("--last", type=int, default=20)

Expand Down Expand Up @@ -144,6 +148,22 @@ def main(argv: list[str] | None = None) -> int:
print(json.dumps(report, indent=2) if args.json else golive.render(report))
return 0

if args.command == "portal":
import os

if args.port:
os.environ["FIRSTSYNC_PORTAL_PORT"] = str(args.port)
try:
from firstsync.portal.app import main as serve_portal
except ModuleNotFoundError:
print(
"The portal needs the 'portal' extra: pip install -e \".[portal]\"",
file=sys.stderr,
)
return 2
serve_portal()
return 0

if args.command == "trace":
if args.run:
try:
Expand Down
1 change: 1 addition & 0 deletions src/firstsync/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Settings(BaseSettings):
run_id: str = Field(default=_PROCESS_RUN_ID, min_length=1, max_length=64)
max_tool_calls: int = Field(default=300, ge=1, le=10_000)
model: str | None = None
portal_port: int = Field(default=8000, ge=1, le=65_535)


def get_settings() -> Settings:
Expand Down
9 changes: 9 additions & 0 deletions src/firstsync/portal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""The admin portal: the human-facing surface of FirstSync.

The portal is where a person does the one thing the model cannot — authorize. It shows
Claude's proposed mappings, the dry-run preview of their own data, and the approve and
migrate controls. It never calls the model: every page reads state the engines wrote, and
every action (approve, migrate, sync) is a server-side call behind the same gate the CLI
uses. For a self-contained demo it loads the proposals Claude produced in the evaluation
runs, so the whole flow works with no API key.
"""
Loading
Loading