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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ jobs:
- uses: actions/checkout@v4
- name: Worker unit tests (node:test)
run: node --test dist/pgboxdb.com/install-worker.test.js
- name: Legacy-domain transition redirect Worker (node:test)
run: |
node --test dist/legacy-domain-redirect/redirect-worker.test.js
node --test dist/legacy-domain-redirect/install/legacy-install-worker.test.js
release-workflow:
name: release workflow and distribution names
runs-on: ubuntu-24.04
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ npx pgboxdb@latest
<!-- skills.sh badge: add [![skills.sh](https://skills.sh/b/pgrundev/pgboxdb)](https://skills.sh/pgrundev/pgboxdb) once https://skills.sh/pgrundev/pgboxdb lists the skill -->

<p align="center">
<sub>Open source · Free · v0.1.3 · For disposable databases, not production data</sub>
<sub>Open source · Free · v0.2.0 · For disposable databases, not production data</sub>
</p>

PGBoxDB is a database runtime for short-lived Postgres databases: agent
Expand Down Expand Up @@ -275,8 +275,8 @@ session end → branch dropped

## Status

PGBoxDB is at **v0.1.3**, an early release with known limitations listed in the
[release notes](https://github.com/pgrundev/pgboxdb/releases/tag/v0.1.3). It
PGBoxDB is at **v0.2.0**, an early release with known limitations listed in the
[release notes](https://github.com/pgrundev/pgboxdb/releases/tag/v0.2.0). It
already powers PGBoxDB branches in [PGRun](https://pgrun.dev), which adds the
control plane around it: safe masked copies of a source database, sealed
templates, one branch per agent, PR or CI job, routing, access and
Expand Down Expand Up @@ -384,7 +384,7 @@ activated and your permissions allow it.
| Cursor | hooks installed; `pgboxdb agent exec --` when `PGBOXDB_ISOLATION` is unset | env propagation pending live verification |
| Codex | `pgboxdb agent exec -- codex` (Codex hooks cannot set environment) | wrapper verified |

Requires PGBoxDB 0.1.2 or newer; the Skill checks the installed version before it
Requires PGBoxDB 0.2.0 or newer; the Skill checks the installed version before it
does anything. [`pgrundev/pgboxdb-plugin`](https://github.com/pgrundev/pgboxdb-plugin)
holds only the plugin (about 110 KB, generated from this repository), so
the install takes seconds; adding this repository itself as the marketplace
Expand Down
2 changes: 1 addition & 1 deletion crates/bin/pgboxdb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pgboxdb"
version = "0.1.3"
version = "0.2.0"
edition.workspace = true
publish.workspace = true
description = "PGBoxDB command-line interface: a lightweight Postgres-compatible database runtime for AI agents"
Expand Down
42 changes: 24 additions & 18 deletions crates/bin/pgboxdb/tests/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,14 @@ fn init_with_run_dir_override_accepts_long_home() {
let p = Pgboxdb::with_home(long);
let run_dir = common::scratch_root().join(format!("rd{}", p.port));
let port = p.port.to_string();
let r = common::output_locked(
p.cmd(&["init", "--port", &port])
.env("PGBOXDB_RUN_DIR", &run_dir),
)
.unwrap();
let r = common::Run::from(r);
let r = p.output_retrying_pub(
|| {
let mut c = p.cmd(&["init", "--port", &port]);
c.env("PGBOXDB_RUN_DIR", &run_dir);
c
},
"pgboxdb init",
);
assert_eq!(r.code, 0, "{}", r.all());
assert_eq!(p.config()["run_dir"], run_dir.to_string_lossy().as_ref());
let _ = std::fs::remove_dir_all(run_dir);
Expand Down Expand Up @@ -478,22 +480,26 @@ fn serve_runs_in_foreground_and_initialises() {
fn init_honors_pgboxdb_password_env() {
let p = Pgboxdb::new();
let port = p.port.to_string();
let r = common::output_locked(
p.cmd(&["init", "--port", &port])
.env("PGBOXDB_PASSWORD", "supersecret123"),
)
.unwrap();
assert_eq!(common::Run::from(r).code, 0);
let r = p.output_retrying_pub(
|| {
let mut c = p.cmd(&["init", "--port", &port]);
c.env("PGBOXDB_PASSWORD", "supersecret123");
c
},
"pgboxdb init",
);
assert_eq!(r.code, 0, "{}", r.all());
assert_eq!(p.config()["password"], "supersecret123");
// too short is rejected
let p2 = Pgboxdb::new();
let port2 = p2.port.to_string();
let r = common::Run::from(
common::output_locked(
p2.cmd(&["init", "--port", &port2])
.env("PGBOXDB_PASSWORD", "short"),
)
.unwrap(),
let r = p2.output_retrying_pub(
|| {
let mut c = p2.cmd(&["init", "--port", &port2]);
c.env("PGBOXDB_PASSWORD", "short");
c
},
"pgboxdb init",
);
assert_eq!(r.code, 2, "{}", r.all());
assert!(r.stderr.contains("too short"), "{}", r.stderr);
Expand Down
124 changes: 122 additions & 2 deletions crates/bin/pgboxdb/tests/top_tty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,22 @@ impl Tty {
self.master.flush().unwrap();
}

/// Wait until the screen output (after `from` bytes) contains `needle`.
/// Wait until `needle` appears after `from` bytes of output: either in the
/// bytes written since then, or on the reconstructed screen when it was not
/// on the screen at `from`. The second form matters because the renderer
/// sends only changed cells: a redraw of "appeared_later" over a cell that
/// already held an "r" does not resend that "r", so the byte stream alone
/// can miss text that is plainly on the screen.
fn expect(&self, needle: &str, from: usize, secs: u64) {
let deadline = Instant::now() + Duration::from_secs(secs);
let before = {
let raw = self.raw();
screen(&raw[..from.min(raw.len())]).contains(needle)
};
loop {
let raw = self.raw();
let tail = strip_ansi(&String::from_utf8_lossy(&raw[from.min(raw.len())..]));
if tail.contains(needle) {
if tail.contains(needle) || (!before && screen(&raw).contains(needle)) {
return;
}
if Instant::now() > deadline {
Expand Down Expand Up @@ -205,6 +214,117 @@ impl Drop for Tty {
}
}

/// The text of the terminal screen after `raw`, as rows joined by newlines: a
/// minimal emulator for what the TUI emits (cursor positioning, line and screen
/// erase, the alternate screen, printable characters; colours are ignored).
fn screen(raw: &[u8]) -> String {
let s = String::from_utf8_lossy(raw);
let mut grid: Vec<Vec<char>> = Vec::new();
let (mut row, mut col) = (0usize, 0usize);
let put = |grid: &mut Vec<Vec<char>>, r: usize, c: usize, ch: char| {
if grid.len() <= r {
grid.resize(r + 1, Vec::new());
}
let line = &mut grid[r];
if line.len() <= c {
line.resize(c + 1, ' ');
}
line[c] = ch;
};
let mut it = s.chars().peekable();
while let Some(ch) = it.next() {
match ch {
'\x1b' => match it.next() {
Some('[') => {
let mut params = String::new();
let mut fin = '\0';
for d in it.by_ref() {
if ('@'..='~').contains(&d) {
fin = d;
break;
}
params.push(d);
}
let private = params.starts_with('?');
let nums: Vec<usize> = params
.trim_start_matches('?')
.split(';')
.map(|n| n.parse().unwrap_or(0))
.collect();
let n = |i: usize, dflt: usize| {
nums.get(i).copied().filter(|v| *v > 0).unwrap_or(dflt)
};
match fin {
'H' | 'f' => {
row = n(0, 1) - 1;
col = n(1, 1) - 1;
}
'A' => row = row.saturating_sub(n(0, 1)),
'B' => row += n(0, 1),
'C' => col += n(0, 1),
'D' => col = col.saturating_sub(n(0, 1)),
'G' => col = n(0, 1) - 1,
'd' => row = n(0, 1) - 1,
'J' if nums.first().copied().unwrap_or(0) >= 2 => grid.clear(),
'J' => {
if let Some(line) = grid.get_mut(row) {
line.truncate(col);
}
grid.truncate(row + 1);
}
'K' => {
if let Some(line) = grid.get_mut(row) {
line.truncate(col);
}
}
'h' | 'l' if private && params.contains("1049") => grid.clear(),
_ => {}
}
}
Some(']') => {
while let Some(d) = it.next() {
if d == '\x07' || (d == '\x1b' && it.peek() == Some(&'\\')) {
if d == '\x1b' {
it.next();
}
break;
}
}
}
_ => {}
},
'\r' => col = 0,
'\n' => row += 1,
'\x08' => col = col.saturating_sub(1),
c if c.is_control() => {}
c => {
put(&mut grid, row, col, c);
col += 1;
}
}
}
grid.iter()
.map(|l| l.iter().collect::<String>())
.collect::<Vec<_>>()
.join("\n")
}

#[test]
fn screen_model_sees_text_drawn_over_unchanged_cells() {
// "appeared_later" drawn over "xxxxxrxxxxxxxx": the renderer skips the
// unchanged "r", so the byte stream holds "appea" and "ed_later" only.
let first = b"\x1b[?1049h\x1b[3;5Hxxxxxrxxxxxxxx";
let second = b"\x1b[3;5Happea\x1b[3;11Hed_later";
let mut all = first.to_vec();
all.extend_from_slice(second);
assert!(!strip_ansi(&String::from_utf8_lossy(second)).contains("appeared_later"));
assert!(screen(&all).contains("appeared_later"));
assert!(!screen(first).contains("appeared_later"));
// Erase to end of line, and a full clear.
assert!(!screen(b"\x1b[1;1Habcdef\x1b[1;3H\x1b[K").contains("cdef"));
assert!(screen(b"\x1b[1;1Habc\x1b[2Jxyz").trim() == "xyz");
}

fn strip_ansi(s: &str) -> String {
let mut out = String::with_capacity(s.len());
let mut it = s.chars().peekable();
Expand Down
2 changes: 1 addition & 1 deletion dist/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# $PGBOXDB_BIN_DIR. No root, no system PostgreSQL.
#
# curl -fsSL https://pgboxdb.com/install | sh
# PGBOXDB_VERSION=0.1.0 PGBOXDB_BIN_DIR=~/.local/bin sh install.sh
# PGBOXDB_VERSION=0.2.0 PGBOXDB_BIN_DIR=~/.local/bin sh install.sh
#
# Environment:
# PGBOXDB_VERSION version to install (default: latest release)
Expand Down
86 changes: 86 additions & 0 deletions dist/legacy-domain-redirect/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# The previous domain (pgx.dev) during and after the transition

Two Cloudflare Workers answer every request to `pgx.dev`. The domain itself
is never transferred, released or deleted.

| Worker | Route | Source |
|---|---|---|
| `pgx-dev-redirect` | `pgx.dev/*` (every path) | `redirect-worker.js`, `wrangler.toml` |
| `pgx-install` | `pgx.dev/install` | `install/` |

## Timeline

| | UTC |
|---|---|
| Transition activated (first 301) | **2026-11-19 19:58:36** |
| Authorised until (activation + 90 days) | 2027-02-17 19:58:36 |
| `REDIRECT_UNTIL`, enforced in code by both Workers | **2027-02-17 19:58:29** |

## Until `REDIRECT_UNTIL`

* `https://pgx.dev/*` and `http://pgx.dev/*` answer 301 to `https://pgboxdb.com`.
* `/`, `/index.html`, `/llms.txt` and `/robots.txt` keep their path; these
are the pages that exist on both sites. Every other path goes to the home
page. The query string is always kept.
* `Cache-Control: public, max-age=3600`, so browsers re-check hourly and do
not keep the 301 after the transition.
* `https://pgx.dev/install` serves the previous product's installer script
(tag `v0.1.3`). It is unchanged except for one line after the shebang that
defaults its version to `0.1.3`. Without that line, the script would pick
"the newest release", which from v0.2.0 on is a PGBoxDB release with other
asset names, and `curl -fsSL https://pgx.dev/install | sh` would fail. A
version the user sets still wins.
* There is no `www.pgx.dev` record, so there is nothing to redirect there.

## From `REDIRECT_UNTIL` on

Both Workers answer **`410 Gone`** (plain text, no branding) on every path,
`/install` included. They do this without any redeploy, and also if the
deadline variable is missing or invalid. The redirect Worker never forwards a
request to the origin, so the previous website can't be served again.
`curl -fsSL https://pgx.dev/install | sh` then fails (`curl -f` stops on the
410, and `sh` gets an empty script).

**Keep both Workers deployed after the deadline.** The previous site is still
deployed as the Worker `pgx`. Only the `pgx.dev/*` route keeps it unreachable,
so deleting `pgx-dev-redirect` would bring it back. To retire the old site for
good, remove the `pgx` Worker's domain or route as a separate step that needs
approval. That is not a domain transfer or deletion.

## Why the two routes can't conflict

* Cloudflare uses the most specific matching route, so `pgx.dev/install` (with
any query string) reaches `pgx-install`. Verified live: 200,
`text/x-shellscript`, `x-pgx-install-version: 0.1.3`.
* If the redirect Worker ever receives `/install` anyway, it hands the
request to `pgx-install` through the `INSTALLER` service binding, never to
the origin or to `pgboxdb.com`.
* `/install/` and every other path go to the redirect Worker: 301 until the
deadline, then 410. No path reaches the old site. Verified live: `/` answers
301, not the old page.
* Both Workers read the same `REDIRECT_UNTIL`, so they stop together.
* The tests (`redirect-worker.test.js`, `install/legacy-install-worker.test.js`,
run in CI) fail if the redirect Worker forwards to the origin, if `/install`
is redirected, or if anything other than 410 is served after the deadline.

## Deployments

| Worker | Version | Deployed (UTC) | Note |
|---|---|---|---|
| `pgx-dev-redirect` | `5c43142a-18c3-4385-942a-7b98cf8632c7` | 2026-11-19 19:58:36 | first version (activation) |
| `pgx-install` | `d1cc0c44-9283-4fd3-9fce-07c9ef118396` | 2026-11-19 20:04:41 | v0.1.3 script, version pinned |
| `pgx-install` | `f7c5157b-6261-4250-9501-a59715f43c0e` | 2026-11-19 20:23 | + 410 after the deadline |
| `pgx-dev-redirect` | `5d1fab37-4514-412c-98e7-0daa5c826709` | 2026-11-19 20:23:25 | + 410 after the deadline, `INSTALLER` binding |

Before the transition, `pgx-install` was `44d28964-e04c-4899-927a-105f9e6202ed`
(tag v0.1.0's script, unpinned).

## Change

```sh
node --test redirect-worker.test.js install/legacy-install-worker.test.js
(cd install && npx wrangler deploy) # the binding target first
npx wrangler deploy
```

Never set `REDIRECT_UNTIL` later than `2027-02-17T19:58:36Z` in either file.
Loading
Loading