Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
768cca2
wip: shared screen renderers for the sqb dev screen
kvlonge Nov 15, 2026
235307c
wip: dev event and control lines between sqb dev and its location child
kvlonge Nov 15, 2026
59153fd
wip: runtime sends publication step and failure events under sqb dev
kvlonge Nov 15, 2026
1a5d8ff
wip: location child forwards dev events, waits for the foreground war…
kvlonge Nov 15, 2026
4cfad9d
wip: sqb debug reads only configuration and providers, never project …
kvlonge Nov 15, 2026
93f1496
Merge remote-tracking branch 'origin/main' into feat/dev-screen
kvlonge Nov 15, 2026
aa0471e
wip: sqb dev screen state machine with transcript tests
kvlonge Nov 15, 2026
b046c6b
wip: dev screen owns its state by value, table-shaped transcript test…
kvlonge Nov 15, 2026
3b3f850
wip: dev session drives the screen from location events, foreground s…
kvlonge Nov 16, 2026
8d4b8b3
Merge remote-tracking branch 'origin/main' into feat/dev-screen
kvlonge Nov 16, 2026
569f416
wip: dev screen redirects stderr into its log, clears its rows on qui…
kvlonge Nov 16, 2026
3bf98c8
wip: dev screen passes fensu: table-shaped screen and event tests, en…
kvlonge Nov 16, 2026
64abaec
wip: dev tests wait for the plain screen lines, a terminal test prove…
kvlonge Nov 16, 2026
6d197e1
wip: repeated identical metadata read failures back off and stop, onl…
kvlonge Nov 16, 2026
d52a93a
wip: halted syncs stop paging, requests end a backoff, failed reads c…
kvlonge Nov 16, 2026
6850d3f
feat: a stopped warehouse sync retries once at each safety sync, and …
kvlonge Nov 16, 2026
7eb3434
fix: a failed statistics read always revisits catalog, so a relation …
kvlonge Nov 16, 2026
6a434f9
fix: build sqb dev on Windows: the live screen and hotkeys are Unix-o…
kvlonge Nov 16, 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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ errno = "0.3"
windows-sys = { version = "0.61", default-features = false, features = ["Win32_System_Diagnostics_Debug"] }
# Recall's local store: SQLite compiled in, so every build has the same engine version.
rusqlite = { version = "0.37", features = ["bundled", "column_decltype"] }
rustix = { version = "1.1.4", default-features = false, features = ["fs", "process", "std", "termios"] }
rustix = { version = "1.1.4", default-features = false, features = ["fs", "process", "std", "stdio", "termios"] }
saphyr-parser = "0.1"
regex = "1"
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
Expand Down
6 changes: 4 additions & 2 deletions clients/typescript/src/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,7 @@ export interface components {
name: string;
target: string;
};
/** @description Locations report bounded facts, never connection strings or user exception text. */
/** @description Locations report bounded facts, never connection strings; a failed warehouse read carries only its redacted error text. */
LocationHealth: {
/** @enum {string} */
kind: "heartbeat";
Expand All @@ -1939,6 +1939,8 @@ export interface components {
} | {
/** Format: int64 */
elapsed_millis: number;
/** @description A failed read's warehouse error, redacted and bounded; absent otherwise. */
error?: string | null;
failure?: null | components["schemas"]["WarehouseSyncFailure"];
/** Format: int64 */
generation: number;
Expand Down Expand Up @@ -3587,7 +3589,7 @@ export interface components {
session_id: string;
};
/**
* @description Closed failure stages keep warehouse errors and credentials out of health observations.
* @description The stage a warehouse sync failed at; only a failed read also reports its redacted error.
* @enum {string}
*/
WarehouseSyncFailure: "watermark" | "read" | "delivery" | "busy";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//! Apply one message to the `sqb dev` screen.

use std::time::Instant;

use sqlbuild_core::screen_text::models::PhaseState;

use crate::dev_screen::_helpers::lines::{compose, ready_lines};
use crate::dev_screen::_helpers::transitions::{
child_event, client_text, key_pressed, located, logged, run_reported, step_finished,
step_started, warehouse_settled,
};
use crate::dev_screen::models::{DevScreen, DevStep, ScreenAction, ScreenMessage, ScreenOutput};

/// `screen` changed by `message` at `now` (local wall time `clock`), and the text to write.
pub(crate) fn apply_screen_message(
screen: DevScreen,
message: ScreenMessage,
now: Instant,
clock: &str,
) -> (DevScreen, ScreenOutput) {
let mut action: ScreenAction = ScreenAction::None;
let mut raw: String = String::new();
let (mut screen, mut lines): (DevScreen, Vec<String>) = match message {
ScreenMessage::Started { step, detail } => step_started(screen, (step, detail), now),
ScreenMessage::Finished { step, detail } => {
step_finished(screen, (step, PhaseState::Ok), detail, now)
}
ScreenMessage::Child(event) => child_event(screen, event, now, clock),
ScreenMessage::Location(location) => located(screen, location),
ScreenMessage::Triggers(triggers) => (DevScreen { triggers, ..screen }, Vec::new()),
ScreenMessage::Warehouse { adapter, state } => {
let (screen, closing, lines) = warehouse_settled(screen, (adapter, state), now, clock);
raw = closing;
(screen, lines)
}
ScreenMessage::ClientOutput(text) => {
let (screen, text) = client_text(screen, &text, now);
return (screen, ScreenOutput { text, action });
}
ScreenMessage::Run {
name,
detail,
finished,
} => {
let lines: Vec<String> = run_reported(&screen, (name, detail), finished, clock);
(screen, lines)
}
ScreenMessage::Log(line) => logged(screen, line),
ScreenMessage::Key(key) => {
let (screen, shown, asked) = key_pressed(screen, key);
action = asked;
(screen, shown)
}
ScreenMessage::Tick => {
if !screen.live || screen.ready || screen.client_output || connecting(&screen) {
return (
screen,
ScreenOutput {
text: String::new(),
action,
},
);
}
let frame: usize = screen.frame + 1;
(DevScreen { frame, ..screen }, Vec::new())
}
};
if screen.event_gap && !lines.is_empty() {
screen.event_gap = false;
lines.insert(0, String::new());
}
let (screen, ready) = ready_lines(screen, now);
lines.extend(ready);
let (screen, text) = compose(screen, (&raw, &lines), now);
(screen, ScreenOutput { text, action })
}

/// The foreground connection may prompt on the terminal itself, so nothing redraws over it.
fn connecting(screen: &DevScreen) -> bool {
screen.steps.iter().any(|row| {
row.step == DevStep::Warehouse && matches!(row.state, PhaseState::Running { .. })
})
}
54 changes: 54 additions & 0 deletions crates/sqlbuild-cli/src/dev_screen/_helpers/capture.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//! Route this process's stderr into the screen's log while the screen owns the terminal.

use std::fs::File;
#[cfg(unix)]
use std::io::{BufRead, BufReader};
#[cfg(unix)]
use std::os::fd::AsFd;

use tokio::sync::mpsc::UnboundedSender;

use crate::dev_screen::models::ScreenMessage;

/// Point stderr at a pipe whose lines become log messages, and return the terminal it pointed at.
#[cfg(unix)]
pub(crate) fn capture_stderr(
messages: UnboundedSender<ScreenMessage>,
) -> std::io::Result<Option<File>> {
let terminal: File = File::from(std::io::stderr().as_fd().try_clone_to_owned()?);
let (reader, writer) = std::io::pipe()?;
rustix::stdio::dup2_stderr(&writer)?;
drop(writer);
std::thread::spawn(move || {
for line in BufReader::new(reader).split(b'\n') {
let Ok(line) = line else {
return;
};
let text: String = String::from_utf8_lossy(&line)
.trim_end_matches('\r')
.to_owned();
if messages.send(ScreenMessage::Log(text)).is_err() {
return;
}
}
});
Ok(Some(terminal))
}

/// Without file-descriptor redirection, stderr stays on the terminal.
#[cfg(not(unix))]
pub(crate) fn capture_stderr(
_messages: UnboundedSender<ScreenMessage>,
) -> std::io::Result<Option<File>> {
Ok(None)
}

/// Point stderr back at the terminal.
#[cfg(unix)]
pub(crate) fn release_stderr(terminal: &File) {
let _ = rustix::stdio::dup2_stderr(terminal);
}

/// Nothing was redirected.
#[cfg(not(unix))]
pub(crate) fn release_stderr(_terminal: &File) {}
86 changes: 86 additions & 0 deletions crates/sqlbuild-cli/src/dev_screen/_helpers/drawing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//! The screen task: apply each message, write its text, and leave the closing text behind.

use std::fs::File;
use std::io::Write;
use std::time::Instant;

use sqlbuild_core::screen_text::main::redraw_rows::redraw_rows;
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
use tokio::sync::oneshot;

use crate::dev_screen::_helpers::apply_screen_message::apply_screen_message;
use crate::dev_screen::_helpers::capture::release_stderr;
use crate::dev_screen::_helpers::keys::KeyReader;
use crate::dev_screen::constants::{FAILURE_LOG_LINES, TICK};
use crate::dev_screen::models::{DevScreen, ScreenAction, ScreenMessage};

/// Apply each message and write what it draws, until the session finishes; then leave the closing text.
pub(crate) async fn draw_screen(
mut screen: DevScreen,
(mut inbox, actions): (
UnboundedReceiver<ScreenMessage>,
UnboundedSender<ScreenAction>,
),
mut finished: oneshot::Receiver<bool>,
(keys, terminal): (Option<KeyReader>, Option<File>),
) {
let mut tick = tokio::time::interval(TICK);
tick.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
let failed: bool = loop {
let message: ScreenMessage = tokio::select! {
failed = &mut finished => break failed.unwrap_or(false),
message = inbox.recv() => match message {
Some(message) => message,
None => break false,
},
_ = tick.tick(), if screen.live => ScreenMessage::Tick,
};
let clock: String = chrono::Local::now().format("%H:%M:%S").to_string();
let output;
(screen, output) = apply_screen_message(screen, message, Instant::now(), &clock);
write_screen(terminal.as_ref(), &output.text);
if output.action != ScreenAction::None {
let _ = actions.send(output.action);
}
};
drop(keys);
if let Some(terminal) = terminal.as_ref() {
release_stderr(terminal);
}
write_screen(None, &closing_text(&screen, failed));
}

/// What stays on the terminal after the screen stops: the live rows cleared and, on failure, the newest log lines that explain it.
fn closing_text(screen: &DevScreen, failed: bool) -> String {
let mut text: String = if screen.live && screen.drawn > 0 {
redraw_rows(screen.drawn, &[])
} else {
String::new()
};
if failed && !screen.show_log {
let skip: usize = screen.log.len().saturating_sub(FAILURE_LOG_LINES);
for line in screen.log.iter().skip(skip) {
text.push_str(line);
text.push('\n');
}
}
text
}

/// Write to the terminal stderr was taken from, or to stderr when it was not redirected.
fn write_screen(terminal: Option<&File>, text: &str) {
if text.is_empty() {
return;
}
match terminal {
Some(mut terminal) => drop(terminal.write_all(text.as_bytes())),
None => {
let mut stderr = std::io::stderr().lock();
drop(
stderr
.write_all(text.as_bytes())
.and_then(|()| stderr.flush()),
);
}
}
}
100 changes: 100 additions & 0 deletions crates/sqlbuild-cli/src/dev_screen/_helpers/keys.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//! Hotkeys from the terminal: stdin in raw mode, handed back to the warehouse client while it prompts.

use std::sync::Arc;
use std::sync::atomic::Ordering;
use std::thread::JoinHandle;
#[cfg(unix)]
use std::time::Duration;

#[cfg(unix)]
use rustix::termios::{
LocalModes, OptionalActions, SpecialCodeIndex, Termios, tcgetattr, tcsetattr,
};
use tokio::sync::mpsc::UnboundedSender;

#[cfg(unix)]
use crate::dev_screen::constants::KEY_POLL;
use crate::dev_screen::models::{KeyGate, ScreenMessage};

/// The hotkey thread; dropping it restores the terminal.
pub(crate) struct KeyReader {
gate: Arc<KeyGate>,
thread: Option<JoinHandle<()>>,
}

impl KeyReader {
/// Start reading keys into `keys`, or `None` when stdin is not a terminal.
#[cfg(unix)]
pub(crate) fn start(keys: UnboundedSender<ScreenMessage>) -> Option<Self> {
let cooked: Termios = match tcgetattr(std::io::stdin()) {
Ok(cooked) => cooked,
Err(_) => return None,
};
let gate: Arc<KeyGate> = Arc::new(KeyGate::default());
let shared: Arc<KeyGate> = Arc::clone(&gate);
let thread = std::thread::spawn(move || read_keys(&shared, &cooked, &keys));
Some(Self {
gate,
thread: Some(thread),
})
}

/// Hotkeys need a Unix terminal; the screen is plain elsewhere.
#[cfg(not(unix))]
pub(crate) fn start(_keys: UnboundedSender<ScreenMessage>) -> Option<Self> {
None
}

pub(crate) fn gate(&self) -> Arc<KeyGate> {
Arc::clone(&self.gate)
}
}

impl Drop for KeyReader {
fn drop(&mut self) {
self.gate.stop.store(true, Ordering::SeqCst);
if let Some(thread) = self.thread.take() {
drop(thread.join());
}
}
}

/// Keys without echo or line buffering; Ctrl-C still interrupts, and reads give up after a tenth of a second.
#[cfg(unix)]
fn raw_mode(cooked: &Termios) -> Termios {
let mut raw: Termios = cooked.clone();
raw.local_modes -= LocalModes::ICANON | LocalModes::ECHO;
raw.special_codes[SpecialCodeIndex::VMIN] = 0;
raw.special_codes[SpecialCodeIndex::VTIME] = 1;
raw
}

#[cfg(unix)]
fn read_keys(gate: &KeyGate, cooked: &Termios, keys: &UnboundedSender<ScreenMessage>) {
let raw: Termios = raw_mode(cooked);
let mut byte: [u8; 1] = [0];
while !gate.stop.load(Ordering::SeqCst) && !keys.is_closed() {
let reading: bool = gate.reading.load(Ordering::SeqCst);
if gate.closed.load(Ordering::SeqCst) {
if reading {
let _ = tcsetattr(std::io::stdin(), OptionalActions::Now, cooked);
gate.reading.store(false, Ordering::SeqCst);
}
std::thread::sleep(KEY_POLL);
continue;
}
if !reading {
if tcsetattr(std::io::stdin(), OptionalActions::Now, &raw).is_err() {
return;
}
gate.reading.store(true, Ordering::SeqCst);
}
match rustix::io::read(std::io::stdin(), &mut byte) {
Ok(1) => drop(keys.send(ScreenMessage::Key(char::from(byte[0]).to_ascii_lowercase()))),
Ok(_) => {}
Err(_) => std::thread::sleep(Duration::from_millis(100)),
}
}
let _ = tcsetattr(std::io::stdin(), OptionalActions::Now, cooked);
gate.reading.store(false, Ordering::SeqCst);
}
Loading
Loading