Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
06acd51
feat(storage): add the clean-db scan and delete seam (#1184)
chappie-daemon Nov 20, 2026
374f602
feat(core): decode npub bech32 forms for the operator CLI
chappie-daemon Nov 20, 2026
2ba1206
feat(services): add the spawn seam the operator CLI drives
chappie-daemon Nov 20, 2026
2c70de7
feat(cli): add the compose, env, store and compression seams the port…
chappie-daemon Nov 20, 2026
aa0e14d
feat(cli): answer help, version and unknown words the capture's way
chappie-daemon Nov 20, 2026
4561b23
feat(cli): report, export and clean the store's events
chappie-daemon Nov 20, 2026
4b2244b
feat(cli): mint invites, seed, set up, update and clean
chappie-daemon Nov 20, 2026
b0d78aa
test(cli): drive the ported surface through the binary and the shims
chappie-daemon Nov 20, 2026
ebe04fa
test(core): allow panics in the nip19 test module, as every test targ…
chappie-daemon Nov 20, 2026
3debc93
test(cli): page an export past one page bound
chappie-daemon Nov 20, 2026
9fad10b
test(cli): expect the --file alias the port adds, not the capture's r…
chappie-daemon Nov 20, 2026
b02f9c1
test(cli): assert the settings' processor in info --json
chappie-daemon Nov 20, 2026
587ead9
fix(cli): refuse the --older-than values the capture's parser refuses
chappie-daemon Nov 20, 2026
90575a5
fix(storage): refuse an out-of-range clean-up kind and commit one bat…
chappie-daemon Nov 20, 2026
e982998
fix(cli): refuse invite values past the safe integer and envelope --j…
chappie-daemon Nov 20, 2026
641cc35
fix(cli): keep the pull's code, answer a bare --port, and page by the…
chappie-daemon Nov 20, 2026
3d23ca5
fix(cli): group the rate, end output on a closed reader, prefix the s…
chappie-daemon Nov 20, 2026
d983fb2
test(cli): assert the page, not a TUI, for a no-argument run
chappie-daemon Nov 20, 2026
b3924b7
fix(cli): answer a bare --port by hand and report a failed page write
chappie-daemon Nov 20, 2026
7fdc75d
refactor(cli): assemble the Postgres connection in one place
chappie-daemon Nov 20, 2026
3f16aa7
style(cli,storage): rustfmt the three files the rework left unformatted
chappie-daemon Nov 20, 2026
814ead8
test(cli): pin the import page's name, the failed restart's line and …
chappie-daemon Nov 20, 2026
a007a21
docs(cli): record the spawn seam, the two numeric bounds and where de…
chappie-daemon Nov 20, 2026
35d170f
docs(cli): stop describing the command set as Phase-1 stubs
chappie-daemon Nov 20, 2026
d22cfcb
docs(services): name the spawn seam's capture paths and its scope
chappie-daemon Nov 20, 2026
31fc9a1
docs(cli): cite the decision the failure shapes are recorded under
chappie-daemon Nov 20, 2026
43e712f
docs(cli): name D12 among the decisions the review round added
chappie-daemon Nov 20, 2026
b6f363f
fix(storage): report the rows a stopped criteria delete committed
chappie-daemon Nov 20, 2026
106d9a3
perf(storage): commit one clean-up batch per 10 000 rows
chappie-daemon Nov 20, 2026
83f062c
docs(cli): record the clean-up delete's batch curve and write volume
chappie-daemon Nov 20, 2026
6a6fab4
fix(cli): keep a deployment's legacy settings.json through the bootstrap
chappie-daemon Nov 20, 2026
e289245
refactor(cli): take import's Postgres from the one assembly
chappie-daemon Nov 20, 2026
afe7310
fix(cli): keep the written line on stdout when --restart fails
chappie-daemon Nov 20, 2026
bcd2dfa
fix(cli): give a broken settings file the thrown class everywhere
chappie-daemon Nov 20, 2026
8d0e685
fix(cli): envelope a --json command's settings failure
chappie-daemon Nov 20, 2026
ba3fbbe
fix(cli): make every output write fallible and keep the answer's code
chappie-daemon Nov 20, 2026
20151bd
docs(cli): correct D1's case list, D2's divergence claim and D11's ca…
chappie-daemon Nov 20, 2026
f552d49
docs(cli): correct store.rs's account of the one assembly
chappie-daemon Nov 20, 2026
ca92b83
docs(cli): record the legacy-settings guard, the migrate exception an…
chappie-daemon Nov 20, 2026
26fb14d
fix(cli): keep the written line when a restart cannot even spawn
chappie-daemon Nov 20, 2026
705a52a
fix(cli): route clean-db's production warning through the fallible wr…
chappie-daemon Nov 20, 2026
6ef44dc
test(storage): pin both untested arms of the partial-delete contract
chappie-daemon Nov 20, 2026
9ba0a7f
refactor(storage): delete the uncalled PostgresBackend::from_env
chappie-daemon Nov 20, 2026
c16054a
feat(cli): accept config set's --validate alongside --no-validate
chappie-daemon Nov 20, 2026
b3c7db8
docs(storage): stop citing the deleted from_env as a live constructor
chappie-daemon Nov 20, 2026
aeed0f1
docs(cli): name the copy's own door in the unconfigured-source test
chappie-daemon Nov 20, 2026
1d1f1a3
docs(cli): keep the --validate page to the capture's one line
chappie-daemon Nov 20, 2026
79ed337
docs(cli): say what SetRequest::validate now receives
chappie-daemon Nov 20, 2026
ee3ead0
docs(storage): name the one parse and its three doors
chappie-daemon Nov 20, 2026
5f76d8e
docs(cli): record the composed failure shape in D3
chappie-daemon Nov 20, 2026
cf5471d
docs(storage): label the one-transaction figures by the run that prod…
chappie-daemon Nov 20, 2026
48d16ae
docs(cli): tell an operator about the legacy settings.json
chappie-daemon Nov 20, 2026
fb48fce
docs(storage): point ADR 0011 at the batch delete's decision
chappie-daemon Nov 20, 2026
d997153
docs(storage): connect_lazy has no production caller
chappie-daemon Nov 21, 2026
fe62cdc
docs(cli): cite the bootstrap guard's own line
chappie-daemon Nov 21, 2026
dae8476
fix(cli): read a .env value the way node's --env-file does
chappie-daemon Nov 21, 2026
f8df3ab
fix(cli): resolve the config dir through the CLI's environment
chappie-daemon Nov 21, 2026
785053f
fix(cli): a signalled git stash is a failed update
chappie-daemon Nov 21, 2026
c168cc2
fix(cli): report a compressed export's trailer failure
chappie-daemon Nov 21, 2026
b695a25
fix(storage): count clean-db's rows where the delete writes
chappie-daemon Nov 21, 2026
c5e5891
fix(cli): strip a backtick-quoted .env value, and name the line-form …
chappie-daemon Nov 21, 2026
1dcb883
fix(cli): give the .env file its raw view beside the environment layer
chappie-daemon Nov 21, 2026
071ba29
test(cli): pin the xz trailer and the interrupted stream's archive
chappie-daemon Nov 21, 2026
c91a804
fix(storage): resolve a vanish request where the answer is cached
chappie-daemon Nov 21, 2026
d2b5f42
fix(cli): keep the raw .env view's trailing whitespace
chappie-daemon Nov 21, 2026
d55bd8a
docs(cli): correct the two statements that made migrate a .env-layer …
chappie-daemon Nov 21, 2026
873111b
docs(cli): count the parses the ADR's cost line understated
chappie-daemon Nov 21, 2026
1c4fdae
docs(cli): say what the .env split costs and which command pays it
chappie-daemon Nov 21, 2026
be57633
docs(cli): name both shapes node joins on, and the readers outside SU…
chappie-daemon Nov 21, 2026
9d71874
test(cli): pin the CRLF carriage return's removal
chappie-daemon Nov 21, 2026
323b20a
refactor(cli): hand the config env readers the context's Environment
chappie-daemon Nov 21, 2026
07bf8c9
docs(cli): split the unterminated-quote claim on the # that parts it …
chappie-daemon Nov 21, 2026
5d10e84
docs(storage): state the vanished predicates' pool rule where an impl…
chappie-daemon Nov 21, 2026
00be256
docs(cli): record the exported-but-empty variable as the third diverg…
chappie-daemon Nov 21, 2026
996aaed
docs(adr): give the .env two-view decision its own heading under D8
chappie-daemon Nov 21, 2026
f27d4e9
test(cli): make the env-readers pin discriminate env_validate
chappie-daemon Nov 21, 2026
cef2995
docs(storage): resolve the two cross-trait links and name the type th…
chappie-daemon Nov 21, 2026
7c5c53e
docs(adr): cite the set text read where grep finds it
chappie-daemon Nov 21, 2026
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
11 changes: 11 additions & 0 deletions .changeset/cli-surface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
---

feat(cli): port the `pnpm run cli` surface into `nostream-cli`

The operator line now answers the capture's page, version and unknown-command contract, and
implements the eight missing commands: `start`, `stop`, `update`, `clean`, `info`, `seed`,
`invite`, `setup`, plus `export` and `clean-db` and the `config list`/`set`/`env` family.
`nostream dev` is removed. Three dependencies are added (bech32, flate2, xz2) and four
`EventRepository` methods (`scan_live`, `count_by_criteria`, `delete_by_criteria`,
`delete_all_events`); child processes go through `nostream_services::process`.
4 changes: 3 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ jobs:
- name: Storage parity against Postgres
env:
PARITY_ADMIN_URL: postgres://postgres:postgres@localhost:5432/postgres
run: cargo test -p nostream-storage --test migrations --test parity --test migration_pg -- --ignored --test-threads=1
run: cargo test -p nostream-storage --test migrations --test parity --test migration_pg --test clean_up -- --ignored --test-threads=1
# The benchmark rig's Postgres column: the same workload and the same `--verify` the LMDB
# arm runs, against the scratch database it drops and recreates. The dev profile is
# deliberate — this proves the path and the counts, and its timings are cited nowhere.
Expand Down Expand Up @@ -313,6 +313,8 @@ jobs:
run: cargo build -p nostream-cli --no-default-features
- name: CLI refuses the migration on Windows
run: cargo test -p nostream-cli --no-default-features --test migrate_cli_unsupported
- name: CLI surface on Windows
run: cargo test -p nostream-cli --no-default-features --test cli_surface_windows

changeset-check:
name: Changeset Required
Expand Down
10 changes: 6 additions & 4 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ resolver 3:
| `nostream-relay` | connections, wire protocol, handlers, rate limiters, live dispatch, NIP-77 engine (the acceptor lives in `nostreamd`) |
| `nostream-services` | payment processors and the invoice lifecycle, operator notifications, the web-of-trust graph, Tor, the scheduler and its workers, event import, NIP-66 monitors (#865) |
| `nostream-admin` | admin API and auth |
| `nostream-cli` | operator command line (`nostream-cli config validate`, `nostream-cli import`, `nostream-cli migrate pg-to-lmdb`) |
| `nostream-cli` | operator command line: `start`, `stop`, `update`, `clean`, `info`, `seed`, `invite`, `setup`, `export`, `clean-db`, `import`, `config`, `migrate pg-to-lmdb`, `tui` (stub) |
| `nostreamd` | the daemon binary: runtime, telemetry, signals, the services composition root and the worker supervisor |

- Every crate manifest repeats `version.workspace = true`, `edition.workspace = true`,
Expand All @@ -115,9 +115,11 @@ resolver 3:
bump; do not add one.
- `nostream-services` is the only crate that opens sockets and child processes:
`reqwest` (`default-features = false` with `rustls-tls`, so no new TLS stack) behind the
`HttpClient` seam, and tokio's `process`/`fs` for the DVM worker pipes and the onion key
file. Nothing else may take those features. The branch's other third-party additions are
`aes` and `cbc`, in `nostream-core`, for the NIP-04 body NIP-47 encrypts (ADR 0010, A23).
`HttpClient` seam, and tokio's `process`/`fs` for the DVM worker pipes, the onion key file
and the operator CLI's spawn seam (ADR 0015, D11). Nothing else may take those features.
The branch's other third-party additions are `aes` and `cbc`, in `nostream-core`, for the
NIP-04 body NIP-47 encrypts (ADR 0010, A23); `bech32` in `nostream-core` for NIP-19 `npub`
decoding; and `flate2` and `xz2` in `nostream-cli` for `export`'s two codecs (ADR 0015, D6).
- Each crate's `lib.rs` doc comment names the TypeScript paths it owns at the capture
commit, and separately names what it deliberately does **not** own. Preserve both: a
reader must be able to tell an omission from a gap.
Expand Down
97 changes: 80 additions & 17 deletions CLI.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
# Nostream CLI

Nostream ships a unified command-line interface:
Nostream ships a unified command-line interface, `nostream-cli`, whose program name on every
page and message is `nostream`:

```bash
nostream --help
pnpm run cli -- --help
nostream --version
```

When run with no arguments in an interactive terminal, `nostream` launches an interactive TUI.
In non-interactive environments, it prints help and exits successfully.
With no arguments it prints the help page on stdout and exits successfully, in a terminal and
out of one alike; the page, `--help` and an unknown command are answered before the argument
parser runs.

## Exit Codes

- `0`: success
- `1`: runtime/validation error
- `2`: usage error (invalid command/options)

An unknown command prints `Unknown command: <word>` on stderr and the help page on stdout, at
exit `2`.

A failure carries the `Error: ` prefix only when the command threw it — the parser's own usage
errors and the commands' thrown validations. A message a command reports itself is printed bare,
with the code it chose:

```bash
nostream invite create --uses 0 # Error: --uses must be a positive integer, exit 2
nostream seed --count 0 # Error: --count must be a positive integer, exit 1
nostream config get payments.x # Path not found: payments.x, exit 1
```

`--json` failures are the envelope `{"error":{"message":…,"code":N}}` on stderr.

## Core Commands

```bash
Expand All @@ -28,9 +45,59 @@ nostream setup [--yes] [--start]
nostream seed [--count 100]
nostream invite create [--uses N] [--expires-in <seconds>] [--json]
nostream import [file.jsonl|file.json] [--file file.jsonl|file.json] [--batch-size 1000]
nostream export [output] [--output output] [--format jsonl|json]
nostream export [output] [--output output] [--format jsonl|json|gzip|gz|xz] [-z]
nostream clean-db [--all|--older-than=<days>|--kinds=<1,7,4>] [--dry-run] [--force]
```

`--version` and `-v` print `nostream/<version>`.

`info`, `seed`, `invite create`, `export` and `clean-db` read the store the settings name, and
take `--data-dir <DIR>` for the LMDB root: the environment lives at `<DIR>/lmdb`, the layout
`nostream-cli migrate pg-to-lmdb --target <DIR>` writes. With the lmdb backend selected and no
`--data-dir`, the command fails with `Error: the lmdb backend needs --data-dir <path>`.

`start` and `setup` create `<config>/settings.yaml` from the defaults only when the config
directory has neither `settings.yaml` nor the deprecated `settings.json`. If it holds only
`settings.json`, both leave it in place and write no `settings.yaml`, and the relay keeps reading
its values; move the overrides into YAML yourself when you want them in the new file.

## Cleaning events

`clean-db` deletes events by age, by kind, or every event. Nothing else is touched: invite
codes, invoices and users survive.

```
nostream clean-db [options]

--all Delete all events.
--older-than=<days> Delete events older than the given number of days.
--kinds=<1,7,4> Delete events for specific kinds.
--dry-run Show how many rows would be deleted without deleting them.
--force Skip interactive confirmation prompt.
--help Show this help message.
```

`--all` cannot be combined with `--older-than` or `--kinds`, and at least one of the three is
required. Without `--force` a terminal is asked to type `DELETE`; a piped stdin refuses with
`Interactive confirmation is unavailable. Re-run with --force.` and exit 1. `NODE_ENV=production`
prints a warning on stderr and changes nothing else.

What a run costs: the LMDB delete commits one batch of 10 000 rows at a time so a relay sharing
the store keeps its writer between batches. On a 160 001-row store that is 17 commits and about
1.6× the wall clock of one statement — 28 s in the shipped shape against 17.94 s for the same
store deleted in one transaction, both measured in one sweep (the first cut's own run, before
that sweep, timed the one-transaction shape at 19.46 s; ADR 0015's D13 labels every figure). It
also writes more bytes than the rows it removes, and the two measured ends of that trade bracket
the shipped shape: the 1 000-row batch shape wrote **5.31 GB** where one transaction wrote
**1.41 MB**, and it grows the store file less (**69.8 MB** against **242.9 MB**). The shipped
10 000-row shape's write volume sits between the two and was not measured; its commit count,
which is what charges it, is 17. `--dry-run` counts the same rows with one read walk (202 ms on
that store), so run it first on a big store.

A run that stops after some batches committed says so: the failure's line opens with the rows
already deleted (`4000 events were deleted before the failure: …`, exit 1). The store is then
part-deleted by design, and a re-run removes only what is left.

## NIP-43 invite codes

Join (kind 28934) is already implemented. Operators mint a claim string and share it out of band; the client then publishes a join request with a `claim` tag.
Expand Down Expand Up @@ -102,24 +169,20 @@ nostream config set limits.event.content[0].maxLength 2048
nostream config set nip05.domainWhitelist '["example.com","relay.io"]' --type json
```

## Development Commands
## Development

```bash
nostream dev db:clean [--all|--older-than=30|--kinds=1,7,4] [--dry-run] [--force]
nostream dev db:reset [--yes]
nostream dev seed:relay
nostream dev docker:clean [--yes]
nostream dev test:unit
nostream dev test:cli
nostream dev test:integration
```
The TypeScript development loop (`db:reset`, `seed:relay`, `docker:clean`, the `test:*`
wrappers) is not part of this binary: the wrapper died with the TypeScript line (#869). Its one
real operator operation, `db:clean`, is the top-level `clean-db` above. The Rust suite is the
one `cargo test --workspace --all-features` runs.

## TUI Navigation

Run:
The interactive settings editor is not ported yet: `nostream tui` is a labelled stub, and the
no-argument path prints the help page rather than launching it. What the capture's TUI offered:

```bash
nostream
nostream tui
```

Main menu includes:
Expand Down
80 changes: 80 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ aes = "0.8"
anyhow = "1"
axum = "0.8"
base64 = "0.22.1"
bech32 = "0.11"
cbc = { version = "0.1", features = ["alloc", "block-padding"] }
chacha20 = "0.10.2"
chrono = { version = "0.4", default-features = false, features = ["std", "clock", "serde"] }
clap = { version = "4", features = ["derive"] }
flate2 = "1"
futures-core = "0.3"
futures-util = "0.3"
getrandom = "0.3"
Expand Down Expand Up @@ -58,6 +60,7 @@ tracing-opentelemetry = "0.34"
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt"] }
url = "2"
uuid = { version = "1", features = ["v4"] }
xz2 = "0.1"

[workspace.lints.rust]
# `deny` rather than `forbid`: heed's LMDB `EnvOpenOptions::open` is an `unsafe fn`
Expand Down
Loading
Loading