Skip to content

[Rewrite P5] Admin console parity + admin MCP server + CLI port #867

Open

Description

@chappie-daemon

Parent: #860
Milestone: Phase 5: Admin console + MCP
Host: chappie · Expected cost: $5.00

The admin surface: HTTP routes, the static console, and the new MCP server for admins driving their relay with agents.

  • HTTP admin routes (measured src/routes/admin + src/routes/callbacks + admissions/invoices routes, 244 LOC + auth provider 87 LOC): axum with the same session model (password-admin-auth-provider.ts semantics); serve the existing static console from resources/admin unchanged
  • Admin API parity: every endpoint the console's JS calls (dashboard.js, notifications.js) responds with the same shapes — the console is the oracle and must work unmodified against the Rust relay
  • MCP server for relay admins (nostream-admin crate, rmcp SDK): tools for the agent-driven admin workflow:
    • relay_status — uptime, worker health, connection count, version, NIP-11 doc
    • list_events / get_event / delete_event — audited event-store inspection with kind/pubkey filters
    • user_admin — admission, vanish, balance ops (mirrors the admin console's user actions)
    • invoices_* — list/inspect payment invoices
    • reports_* — NIP-56 report triage: list, action (hide/allow), audit trail
    • settings_get / settings_set — the typed settings surface (schema-validated, same validation the TS admin enforces)
    • maintenance_* — trigger retention/cleanup, read last-run stats
    • auth: the same admin credential model as the HTTP console; every tool call audit-logged to the delivery-log store
  • nostream-cli port (measured 3,216 LOC): the documented pnpm run cli surface as a Rust subcommand set — help text, exit codes and the --all/--force/--older-than/--kinds clean-db semantics ported exactly (measured test rows in the CLI integration suite)

Acceptance: the unmodified TS-era admin console performs every action against the Rust relay; the MCP server answers tools/list with the tool set above and each tool passes an integration test against a running Rust relay; the CLI port passes the TS CLI integration tests re-expressed.

Estimate basis (2026-10-24): $5.00 - 3,216 LOC CLI port plus console parity plus seven MCP tool families - job 008's scale ($6.91) with the CLI as one extra build pass. Model and per-unit costs: .factory/estimates.md.

Activity

  1. added
    rewrite
    rust
    mcp
    factory
    on Oct 17, 2026
  2. chappie-daemon commented on Nov 19, 2026

    @chappie-daemon
    CollaboratorAuthor

    Recon finished — job 032-admin-console-parity (recon.md, 471 lines; 129 citations machine-verified against f01cb5f3 and a 041fe34e archive).

    • There is no HTTP surface in the Rust tree at all. Relay::serve takes the listener and drops anything that is not a WebSocket upgrade; measured against the built daemon, GET /admin/, /admin/session, /healthz, / all return an empty reply. No axum/hyper server dep exists. crates/nostream-admin is a 576-line Phase-1 stub: 39 of 41 files NotImplemented, mount() unimplemented, no tests, and nostreamd does not depend on it.
    • The console is the oracle — the one at base, not the capture's. resources/admin at f01cb5f3 ships 3,346 JS lines in six files against the capture's 2,187 in two, and calls 26 endpoints across 28 of 30 registered routes; eleven of those postdate 041fe34e (all of /ops/*, /audit-log, /diagnostics/export, /moderation/*, /network-health/run|history). Since the Rust process serves the base files, parity means those 26. 041fe34e remains the semantic reference for the 18 capture-era routes.
    • The oracle command exists: a crates/nostream-admin/tests/ integration test that derives the paths from the console's own JS (a 12-line extractor caught 23 of 24; the 24th is the :pubkey/reverify template) and drives them against a live in-process server. LMDB needs no Postgres. Declared undecidable: literal headless-browser execution (no playwright/jsdom) and the /admin/metrics payload, which the capture assembles from a Prometheus endpoint Rust does not have.
    • Environment measured: cargo test --workspace --all-features → 84 targets, 1,352 passed, 0 failed, 6 ignored, 268 s cold; fmt and both clippy passes clean; warm clippy+build 87 s; disk at 84 %.

    Scope gate held: this job builds the HTTP routes + console parity only. The MCP server family (0 TS LOC, no rmcp in the lock, no counterpart to inherit) and the CLI port (3,216 LOC in 28 files, 19 TS test files, Rust nostream-cli covers 3 commands) will be filed as their own issues with these measurements. Spec stage is running now.

  3. chappie-daemon commented on Nov 19, 2026

    @chappie-daemon
    CollaboratorAuthor

    Scope split, recorded. #867 bundles three families and they do not belong in one job. Slice 1 — the HTTP admin routes plus parity with the console the binary serves — is job 032-admin-console-parity, which carries this issue. The other two are filed with recon's measurements:

    Both are on Project 4 at Todo, Phase 5. This issue keeps slice 1; when its PR merges into rewrite/main, it is closed by hand with the sha, because Closes is inert on a non-default base.

  4. chappie-daemon commented on Nov 19, 2026

    @chappie-daemon
    CollaboratorAuthor

    Spec written — job 032-admin-console-parity (spec.md, 330 lines). Slice 1 of #867 is now a buildable contract:

    • 26 API endpoints over 24 distinct paths, plus 2 page routes and 7 assets — each mapped to its TypeScript controller, its success status and every error branch, with the console's own JS as the source of the route list.
    • One listener. The daemon peeks each socket's first bytes: Upgrade: websocket goes to the relay, everything else to an axum router. A second port would change the console's URL and cookie path.
    • The console's session model, not an approximation — HMAC-SHA256 over SECRET, <expiresAt>.<hex>, bearer-then-cookie, scrypt hash with ADMIN_PASSWORD override, the capture's cookie flags and TTL fallback.
    • Thirteen decisions D1–D13 in docs/rewrite/decisions/0013-admin-http-surface.md, including the four narrowings that keep this slice honest: the NIP-66 probe is [Rewrite P2] nostream-relay: wire handlers, strategies, rate limits #865's stub (409/502 with its own messages), /moderation/stats keeps its shape with empty aggregates, /metrics streams the capture's own unavailable snapshot, and NIP-98 is not an auth path here.
    • 26 acceptance criteria — 24 runnable commands, 2 [judged] (the approver on the ADR; the operator in a browser, AC26).

    The red-team pass measured 18 fails-at-base and 8 declared guards, 0 unproven — and found 18 divergences, mostly criteria that could pass without the change (a git status check blind once committed, a grep that counts the struct line, filter-only cargo test runs that exit 0 with zero tests). Those are being folded into one correction edit; the second pass is the last.

    Cost bracket set from the measurement, not the headline: $8.50 (≈4.0k TS LOC direct / 15,977-LOC closure against a 576-line stub crate and no HTTP server in the workspace), replacing #867's provisional $5.00 — recorded with its unit basis in the job record.

  5. chappie-daemon commented on Nov 19, 2026

    @chappie-daemon
    CollaboratorAuthor

    Build READY — job 032-admin-console-parity (build.md; branch factory/032-admin-console-parity, 5 commits at 2456146).

    • The console's surface is served from the relay's one listener. An accepted socket is peeked without consuming: Upgrade: websocket goes to the relay unchanged, everything else to an axum router. The relay's wire tests and the NIP-42 challenge still pass.
    • The oracle exists and is green. cargo test -p nostream-admin --test console_parity derives the routes from the console's own JS (derived: 26 calls over 24 paths + 2 page + 7 assets, unserved: 0) and drives each against a live server; cargo test -p nostreamd --test admin_http proves the one-port claim against the real binary.
    • Gate: cargo test --workspace --all-features → 94 targets, 1,503 passed, 0 failed, 6 ignored (base 84 / 1,352 / 0 / 6); fmt, both clippy passes and the release build exit 0.
    • Static round: the guarded clippy projection ran at 2456146 — 502 artifacts, 26 build scripts, one build-finished success, 0 compiler-message records, 0 findings.
    • Two defects the round found in its own work and fixed: value: null in a settings PATCH was a 400 (needed path removal + validation against defaults), and the defaults filter dropped admin.passwordHash when the defaults omit admin.
    • Review round 1 is scoped and open: security, ux, code, architecture and performance run behind the code gate; the UI lens is stood down because the diff authors no markup, stylesheet or script (git diff f01cb5f3 -- resources/admin is empty). The operator's browser pass (AC26) remains the judged check nobody has run yet.

    Follow-ups unchanged: #1183 (MCP server), #1184 (CLI port).

  6. chappie-daemon commented on Nov 19, 2026

    @chappie-daemon
    CollaboratorAuthor

    Review round 1 — code CHANGES, two findings; the other four lenses were held back by the gate.

    The gate lens ran the full validation itself (fmt, both clippy passes, 94 targets / 1,503 passed / 0 failed, release build, both oracle targets) and then inverted three of the new branches — the peek dispatch, the WebSocket arm, and the asset traversal guard — each going red where it should.

    What it found:

    1. The oracle could not fail on a missing route. console_parity.rs:352 asserted only status < 500; deleting GET /admin/settings from routes::mount still returned unserved: 0 because the fallback answers 404. The criterion (AC6) now requires each derived path's expected status class, and a deleted registration must produce a non-empty unserved list.
    2. A null settings value answered 200, where the capture refuses it as 400 Validation failed (z.custom(v => v !== undefined)). Reachable from the console itself (dashboard.js:1126), and its test asserted only "not 400".

    Round 2 is running: both fixes, the dead admin-key escape in the defaults filter, and the inversion backlog the gate could not reach (disabled-surface gate, session and scrypt, rate limits, the 415-not-on-login clause, the metrics cadence).

  7. chappie-daemon commented on Nov 19, 2026

    @chappie-daemon
    CollaboratorAuthor

    Review round 4 — security PASS, ux PASS, code PASS, architecture CHANGES, performance CHANGES.

    Both blockers were real and neither was found by reading alone:

    • Architecture: the admin rate limiter was a third private store beside the one the tree already ports for the same capture script — it recorded refused hits (the shared sliding window's documented rule is the opposite), never evicted a key, and hard-coded the strategy away where the capture's factory selects limits.rateLimiter.strategy (EWMA by default). Fixed on the operator's ruling: the shared EwmaRateLimiter behind the Limiter trait, the private store deleted, the strategy switch live, AC12 re-derived for EWMA. Refusal advancing the rate is EWMA parity — the capture's own Lua stores before the verdict — so the fixture pins that, and the finding's refused-hit rule is recorded as the sliding window's.
    • Performance, measured: the private map grew +134 B RSS per distinct address over 25k keys; every audit append read, parsed and rewrote the whole ≤2,000-entry file — drivable by an unauthenticated POST /logout; the per-kind storage scans ran serially; scrypt blocked a runtime worker at 1,772 ms CPU per attempt. All four fixed and re-measured (audit: 34.5 s → 0.29 s over 2,000 appends; one open + one write per append).
    • Filed: admin: the audit log is created 0644, so a local user can read the relay's admin history #1187 — the audit log is created 0644, so a local user can read admin actions and login addresses.
    • Amended: AC26 now states that the three storage-backed panels are red against the daemon's unavailable::stores() until the store-wiring job lands — the ux lens measured it, and the spec's Out of scope already said it.

    Round 5 (five lenses, code gate) is confirming the fixes.

  8. chappie-daemon commented on Nov 19, 2026

    @chappie-daemon
    CollaboratorAuthor

    Stage: needs-human (approve returned ESCALATE). Branch factory/032-admin-console-parity at f20341c7, 11 commits, clean, pushed; every acceptance criterion is met under the approver's own runs (cargo fmt, both clippy passes, 95 targets / 1,509 passed / 0 failed / 6 ignored, oracle 4 passed / unserved: 0, release build, and git merge-tree against the moved rewrite/main exits 0) except two that need a person:

    • AC26 — the browser pass: the operator loads /admin/, signs in and walks the panels; its record operator-report.md does not exist yet.
    • Sign-off conditions — the branch creates the relay's admin authentication and permission surface, and adds four direct dependencies (axum, hyper, hyper-util, scrypt).

    A browser pass was driven on the operator's behalf against a release nostreamd (fixture password, one listener on :7401): login, wrong password, session landing, all six views at desktop width and five at phone width, plus the three storage-backed surfaces. The console renders; the three red surfaces are the documented unavailable::stores() ones (NIP-05 "Internal Server Error", delivery log "Unable to load delivery log", storage counts 500) and the only console entries are the Grafana widget's own connection refusals and aborted /admin/metrics reconnects on view switch. The judgement of the rendering stays with the operator.

    Review notes that came out of the last round are their own issues: #1187 (audit mode, amended: the compaction re-creates 0644), #1188 (no bounded wait on the verification pool), #1189 (the shared limiter's cap can be spent), #1190 (the limiter fails open where the capture fails closed), #1191 (compaction is one mutex, not one process).

  9. chappie-daemon commented on Nov 19, 2026

    @chappie-daemon
    CollaboratorAuthor

    Slice 1 (HTTP admin routes + static console) merged: PR #1192 → merge commit 9a7c3181.

  10. chappie-daemon commented on Nov 20, 2026

    @chappie-daemon
    CollaboratorAuthor

    The Expected cost: $5.00 at the top of this issue is superseded, and this comment is the correction rather than an edit to the line so the original figure stays visible.

    Three reasons, each measured:

    The current numbers live in the private tracker, and every departure from this issue's figure is recorded on #860, which is where the board's plan adjustments are kept. This issue stays the umbrella for the three families; its headline should not be read as a budget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    factorymcprewriterust

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions