diff --git a/Cargo.lock b/Cargo.lock index 1b3e8f5f7..4d3ae0f14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13347,7 +13347,7 @@ dependencies = [ [[package]] name = "zatex" -version = "0.3.4" +version = "0.3.7" dependencies = [ "tiny-skia", "ttf-parser", @@ -13598,7 +13598,7 @@ dependencies = [ [[package]] name = "zeron" -version = "0.3.4" +version = "0.3.7" dependencies = [ "anyhow", "clap", @@ -13617,14 +13617,13 @@ dependencies = [ "zeron-mcp", "zeron-notify", "zeron-rpc", - "zeron-sync", "zeron-ui", "zeron-update", ] [[package]] name = "zeron-audio" -version = "0.3.4" +version = "0.3.7" dependencies = [ "base64 0.22.1", "cpal 0.18.2", @@ -13636,7 +13635,7 @@ dependencies = [ [[package]] name = "zeron-cli" -version = "0.3.4" +version = "0.3.7" dependencies = [ "anyhow", "clap", @@ -13652,7 +13651,7 @@ dependencies = [ [[package]] name = "zeron-client" -version = "0.3.4" +version = "0.3.7" dependencies = [ "anyhow", "async-trait", @@ -13683,7 +13682,7 @@ dependencies = [ [[package]] name = "zeron-doc" -version = "0.3.4" +version = "0.3.7" dependencies = [ "chrono", "loro", @@ -13698,7 +13697,7 @@ dependencies = [ [[package]] name = "zeron-engine" -version = "0.3.4" +version = "0.3.7" dependencies = [ "alacritty_terminal", "anyhow", @@ -13758,7 +13757,7 @@ dependencies = [ [[package]] name = "zeron-harness" -version = "0.3.4" +version = "0.3.7" dependencies = [ "anyhow", "async-trait", @@ -13792,7 +13791,7 @@ dependencies = [ [[package]] name = "zeron-launch" -version = "0.3.4" +version = "0.3.7" dependencies = [ "libc", "tempfile", @@ -13801,24 +13800,20 @@ dependencies = [ [[package]] name = "zeron-markdown" -version = "0.3.4" +version = "0.3.7" dependencies = [ "pulldown-cmark", ] [[package]] name = "zeron-mcp" -version = "0.3.4" +version = "0.3.7" dependencies = [ "anyhow", "async-trait", "base64 0.22.1", - "bytes", "chrono", "futures", - "http-body-util", - "hyper", - "hyper-util", "serde", "serde_json", "tempfile", @@ -13834,7 +13829,7 @@ dependencies = [ [[package]] name = "zeron-mobile" -version = "0.3.4" +version = "0.3.7" dependencies = [ "async-trait", "serde", @@ -13861,14 +13856,14 @@ dependencies = [ [[package]] name = "zeron-mobile-bindgen" -version = "0.3.4" +version = "0.3.7" dependencies = [ "uniffi", ] [[package]] name = "zeron-notify" -version = "0.3.4" +version = "0.3.7" dependencies = [ "objc", "sha2", @@ -13877,11 +13872,11 @@ dependencies = [ [[package]] name = "zeron-orb" -version = "0.3.4" +version = "0.3.7" [[package]] name = "zeron-plugin-guard" -version = "0.3.4" +version = "0.3.7" dependencies = [ "serde_json", "tempfile", @@ -13889,7 +13884,7 @@ dependencies = [ [[package]] name = "zeron-preview" -version = "0.3.4" +version = "0.3.7" dependencies = [ "anyhow", "async-trait", @@ -13919,11 +13914,11 @@ dependencies = [ [[package]] name = "zeron-preview-label" -version = "0.3.4" +version = "0.3.7" [[package]] name = "zeron-proto" -version = "0.3.4" +version = "0.3.7" dependencies = [ "chrono", "pulldown-cmark", @@ -13934,7 +13929,7 @@ dependencies = [ [[package]] name = "zeron-rpc" -version = "0.3.4" +version = "0.3.7" dependencies = [ "anyhow", "async-trait", @@ -13955,7 +13950,7 @@ dependencies = [ [[package]] name = "zeron-sync" -version = "0.3.4" +version = "0.3.7" dependencies = [ "base64 0.22.1", "block2 0.6.2", @@ -13981,7 +13976,7 @@ dependencies = [ [[package]] name = "zeron-syntax" -version = "0.3.4" +version = "0.3.7" dependencies = [ "thiserror 2.0.20", "tree-sitter", @@ -14016,14 +14011,14 @@ dependencies = [ [[package]] name = "zeron-term" -version = "0.3.4" +version = "0.3.7" dependencies = [ "alacritty_terminal", ] [[package]] name = "zeron-term-link" -version = "0.3.4" +version = "0.3.7" dependencies = [ "anyhow", "async-trait", @@ -14040,7 +14035,7 @@ dependencies = [ [[package]] name = "zeron-text" -version = "0.3.4" +version = "0.3.7" dependencies = [ "core-foundation 0.10.1", "core-graphics 0.24.0", @@ -14057,7 +14052,7 @@ dependencies = [ [[package]] name = "zeron-theme" -version = "0.3.4" +version = "0.3.7" dependencies = [ "anyhow", "clap", @@ -14072,7 +14067,7 @@ dependencies = [ [[package]] name = "zeron-ui" -version = "0.3.4" +version = "0.3.7" dependencies = [ "alacritty_terminal", "anyhow", @@ -14155,7 +14150,7 @@ dependencies = [ [[package]] name = "zeron-update" -version = "0.3.4" +version = "0.3.7" dependencies = [ "anyhow", "futures", @@ -14172,11 +14167,11 @@ dependencies = [ [[package]] name = "zeron-veil" -version = "0.3.4" +version = "0.3.7" [[package]] name = "zeron-visual" -version = "0.3.4" +version = "0.3.7" dependencies = [ "base64 0.22.1", "gltf", @@ -14188,7 +14183,7 @@ dependencies = [ [[package]] name = "zeron-visual-gpu" -version = "0.3.4" +version = "0.3.7" dependencies = [ "image", "pollster 0.4.0", @@ -14199,7 +14194,7 @@ dependencies = [ [[package]] name = "zeron-voice" -version = "0.3.4" +version = "0.3.7" dependencies = [ "anyhow", "cpal 0.17.3", @@ -14218,7 +14213,7 @@ dependencies = [ [[package]] name = "zeron-voice-media" -version = "0.3.4" +version = "0.3.7" dependencies = [ "async-trait", "semver", @@ -14233,7 +14228,7 @@ dependencies = [ [[package]] name = "zeron-voice-session" -version = "0.3.4" +version = "0.3.7" dependencies = [ "async-trait", "futures", diff --git a/Cargo.toml b/Cargo.toml index a39b93125..7865ac29a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ members = [ ] [workspace.package] -version = "0.3.4" +version = "0.3.7" edition = "2024" license = "MIT" publish = false diff --git a/apps/zeron/Cargo.toml b/apps/zeron/Cargo.toml index 036c03949..2fda76d93 100644 --- a/apps/zeron/Cargo.toml +++ b/apps/zeron/Cargo.toml @@ -27,7 +27,6 @@ zeron-update.workspace = true zeron-cli.workspace = true zeron-mcp.workspace = true zeron-notify.workspace = true -zeron-sync.workspace = true tokio.workspace = true clap.workspace = true anyhow.workspace = true diff --git a/apps/zeron/src/allocator.rs b/apps/zeron/src/allocator.rs index abcaad1a4..c037522f8 100644 --- a/apps/zeron/src/allocator.rs +++ b/apps/zeron/src/allocator.rs @@ -15,16 +15,6 @@ use std::sync::atomic::{AtomicBool, Ordering}; /// The VM tag mimalloc maps the heap with. pub const HEAP_VM_TAG: std::ffi::c_long = 254; -/// mimalloc v2's `mi_option_purge_delay` (`mimalloc.h`; the bindings don't -/// name it). Freed memory is handed back to the system after this many -/// milliseconds (10 by default) — but only the next time that thread -/// allocates or collects, which an engine at rest does rarely: after a burst -/// (agents streaming), what it freed stayed counted against it until some -/// later work. 0 hands it back as it's freed. Measured over five agents -/// streaming: the engine's CPU the same (1.98%), its footprint once they're -/// done 32 MB instead of 42. -const MI_OPTION_PURGE_DELAY: libmimalloc_sys::mi_option_t = 15; - static TAGGED: AtomicBool = AtomicBool::new(false); /// [`mimalloc::MiMalloc`], tagging its regions [`HEAP_VM_TAG`] from the first @@ -37,19 +27,10 @@ fn tag_heap() { // Only stores the option (no allocation); racing threads store the // same value. unsafe { libmimalloc_sys::mi_option_set(libmimalloc_sys::mi_option_os_tag, HEAP_VM_TAG) }; - unsafe { libmimalloc_sys::mi_option_set(MI_OPTION_PURGE_DELAY, 0) }; TAGGED.store(true, Ordering::Relaxed); } } -/// mimalloc's forced collect: what its threads freed (exited threads' -/// pages too) goes back to the system. The engine calls it after dropping -/// a large short-lived allocation ([`zeron_engine::heap`]). -pub fn trim() { - // SAFETY: mimalloc's collect frees nothing in use. - unsafe { libmimalloc_sys::mi_collect(true) }; -} - unsafe impl GlobalAlloc for Allocator { #[inline] unsafe fn alloc(&self, layout: Layout) -> *mut u8 { @@ -79,15 +60,6 @@ unsafe impl GlobalAlloc for Allocator { mod tests { use super::*; - /// Freed memory goes back as it's freed (`MI_OPTION_PURGE_DELAY`), from - /// the first allocation on. - #[test] - fn freed_memory_is_handed_back_at_once() { - let held = vec![0u8; 1 << 20]; - drop(held); - assert_eq!(unsafe { libmimalloc_sys::mi_option_get(MI_OPTION_PURGE_DELAY) }, 0); - } - /// `struct vm_region_extended_info` (`mach/vm_region.h`). #[repr(C)] #[derive(Default)] diff --git a/apps/zeron/src/background.rs b/apps/zeron/src/background.rs index fb4cfb71b..b5626acb9 100644 --- a/apps/zeron/src/background.rs +++ b/apps/zeron/src/background.rs @@ -55,9 +55,6 @@ fn run_engine(config: zeron_engine::EngineConfig) -> anyhow::Result<()> { /// are posted on and delivers their clicks. #[cfg(target_os = "macos")] fn run_engine(config: zeron_engine::EngineConfig) -> anyhow::Result<()> { - // Before the engine starts: its sockets then never start the polling - // wake detector (`zeron_sync::wake`). - main_loop::watch_power(); let worker = std::thread::Builder::new() .name("engine".into()) .spawn(move || { @@ -78,26 +75,9 @@ fn run_engine(config: zeron_engine::EngineConfig) -> anyhow::Result<()> { #[cfg(target_os = "macos")] mod main_loop { use std::ffi::c_void; - use std::sync::atomic::{AtomicBool, AtomicPtr, AtomicU32, Ordering}; + use std::sync::atomic::{AtomicBool, Ordering}; static DONE: AtomicBool = AtomicBool::new(false); - /// The source [`finish`] signals; null until [`run`] makes it. - static STOP: AtomicPtr = AtomicPtr::new(std::ptr::null_mut()); - - /// `CFRunLoopSourceContext`, version 0: only `perform` is used. - #[repr(C)] - struct SourceContext { - version: isize, - info: *mut c_void, - retain: *const c_void, - release: *const c_void, - copy_description: *const c_void, - equal: *const c_void, - hash: *const c_void, - schedule: *const c_void, - cancel: *const c_void, - perform: extern "C" fn(*mut c_void), - } #[link(name = "CoreFoundation", kind = "framework")] unsafe extern "C" { @@ -106,100 +86,39 @@ mod main_loop { fn CFRunLoopGetMain() -> *mut c_void; fn CFRunLoopRunInMode(mode: *const c_void, seconds: f64, return_after_source: u8) -> i32; fn CFRunLoopWakeUp(run_loop: *mut c_void); - fn CFRunLoopSourceCreate( + fn CFAbsoluteTimeGetCurrent() -> f64; + fn CFRunLoopTimerCreate( allocator: *const c_void, + fire_date: f64, + interval: f64, + flags: u64, order: isize, - context: *mut SourceContext, + callout: extern "C" fn(*mut c_void, *mut c_void), + context: *mut c_void, ) -> *mut c_void; - fn CFRunLoopAddSource(run_loop: *mut c_void, source: *mut c_void, mode: *const c_void); - fn CFRunLoopSourceSignal(source: *mut c_void); + fn CFRunLoopAddTimer(run_loop: *mut c_void, timer: *mut c_void, mode: *const c_void); } - #[link(name = "IOKit", kind = "framework")] - unsafe extern "C" { - fn IORegisterForSystemPower( - refcon: *mut c_void, - port: *mut *mut c_void, - callback: extern "C" fn(*mut c_void, u32, u32, *mut c_void), - notifier: *mut u32, - ) -> u32; - fn IONotificationPortGetRunLoopSource(port: *mut c_void) -> *mut c_void; - fn IOAllowPowerChange(kernel_port: u32, notification_id: isize) -> i32; - } + extern "C" fn tick(_timer: *mut c_void, _info: *mut c_void) {} - // IOKit's power messages (IOKit/IOMessage.h). - const CAN_SYSTEM_SLEEP: u32 = 0xe000_0270; - const SYSTEM_WILL_SLEEP: u32 = 0xe000_0280; - const SYSTEM_HAS_POWERED_ON: u32 = 0xe000_0300; - - /// The root power domain's connection, for acknowledging sleep. - static ROOT_PORT: AtomicU32 = AtomicU32::new(0); - - extern "C" fn power(_refcon: *mut c_void, _service: u32, message: u32, argument: *mut c_void) { - match message { - // Every registered client must answer these, or the Mac waits - // up to 30 s before it sleeps. - CAN_SYSTEM_SLEEP | SYSTEM_WILL_SLEEP => unsafe { - IOAllowPowerChange(ROOT_PORT.load(Ordering::Acquire), argument as isize); - }, - SYSTEM_HAS_POWERED_ON => zeron_sync::wake::notify_wake(), - _ => {} - } - } - - /// Hear the Mac's sleep and wake from IOKit on the main run loop, so the - /// engine's sockets redial on wake without a detector waking the - /// process every second to compare clocks. Falls back to that detector - /// if registering fails. - pub(super) fn watch_power() { - unsafe { - let mut port = std::ptr::null_mut(); - let mut notifier = 0u32; - let root = - IORegisterForSystemPower(std::ptr::null_mut(), &mut port, power, &mut notifier); - if root == 0 || port.is_null() { - tracing::warn!( - "couldn't register for power notifications; polling for wake instead" - ); - return; - } - ROOT_PORT.store(root, Ordering::Release); - let source = IONotificationPortGetRunLoopSource(port); - CFRunLoopAddSource(CFRunLoopGetMain(), source, kCFRunLoopCommonModes); - } - zeron_sync::wake::use_os_wake_events(); - } - - /// The stop source fired: [`run`]'s wait returns and it reads `DONE`. - extern "C" fn stop(_info: *mut c_void) {} - - /// Serve the main run loop until [`finish`]. It sleeps until something - /// arrives (a banner's click, the stop source) rather than on a timer: - /// an idle engine's main thread never wakes. The stop source both keeps - /// the loop from returning at once for want of sources and makes a - /// `finish` that comes before the wait begins end it at once (a signaled - /// source is served as soon as the loop runs). + /// Serve the main run loop until [`finish`]. A repeating timer keeps the + /// loop from returning at once for want of sources and bounds how late + /// the exit check runs. pub(super) fn run() { unsafe { let main = CFRunLoopGetMain(); - let mut context = SourceContext { - version: 0, - info: std::ptr::null_mut(), - retain: std::ptr::null(), - release: std::ptr::null(), - copy_description: std::ptr::null(), - equal: std::ptr::null(), - hash: std::ptr::null(), - schedule: std::ptr::null(), - cancel: std::ptr::null(), - perform: stop, - }; - let source = CFRunLoopSourceCreate(std::ptr::null(), 0, &mut context); - CFRunLoopAddSource(main, source, kCFRunLoopCommonModes); - STOP.store(source, Ordering::SeqCst); + let timer = CFRunLoopTimerCreate( + std::ptr::null(), + CFAbsoluteTimeGetCurrent() + 1.0, + 1.0, + 0, + 0, + tick, + std::ptr::null_mut(), + ); + CFRunLoopAddTimer(main, timer, kCFRunLoopCommonModes); while !DONE.load(Ordering::SeqCst) { - // (Returns after each source served, so `DONE` is read then.) - CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0e10, 1); + CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0, 0); } } } @@ -207,12 +126,6 @@ mod main_loop { /// End [`run`] (any thread). pub(super) fn finish() { DONE.store(true, Ordering::SeqCst); - let source = STOP.load(Ordering::SeqCst); - unsafe { - if !source.is_null() { - CFRunLoopSourceSignal(source); - } - CFRunLoopWakeUp(CFRunLoopGetMain()); - } + unsafe { CFRunLoopWakeUp(CFRunLoopGetMain()) }; } } diff --git a/apps/zeron/src/bin/zeron-engine.rs b/apps/zeron/src/bin/zeron-engine.rs index 0b6648a1d..76d9bcbc1 100644 --- a/apps/zeron/src/bin/zeron-engine.rs +++ b/apps/zeron/src/bin/zeron-engine.rs @@ -2,9 +2,8 @@ //! own ("Zeron Engine" in Activity Monitor): the app starts it and attaches; //! sessions keep running with the app closed. Without the UI linked in. //! -//! It also answers what the engine runs its own executable for: `mcp-proxy` -//! (an agent's Zeron MCP tools on stdio, served by the engine), `mcp` (the -//! standalone Zeron MCP server) and `--noop-browser` (browser +//! It also answers what the engine runs its own executable for: `mcp` (the +//! Zeron MCP server injected into agents) and `--noop-browser` (browser //! suppression for agents' sign-in flows). And it is the engine helper of an //! interface that doesn't link the engine (the zgx app): every `zeron` //! subcommand that runs the engine's code (`headless`, `login`, `status`, @@ -18,9 +17,6 @@ use zeron_cli::{Engines, Launch}; fn main() -> anyhow::Result<()> { match std::env::args().nth(1).as_deref() { Some("--noop-browser") => Ok(()), - // An agent's Zeron MCP tools on stdio, forwarded to the engine's own - // endpoint. First, before any engine setup: it must stay tiny. - Some("mcp-proxy") => zeron_mcp::proxy::run(), Some("--version" | "-V") => { println!("zeron-engine {}", zeron_update::current_version()); Ok(()) diff --git a/apps/zeron/src/lib.rs b/apps/zeron/src/lib.rs index f65d61475..265c0d7d5 100644 --- a/apps/zeron/src/lib.rs +++ b/apps/zeron/src/lib.rs @@ -12,11 +12,11 @@ pub mod engine_commands; pub mod ipc_cli; pub mod plugin_cli; -pub use engine_commands::run_engine_command; pub use zeron_cli::{ DEFAULT_EDGE_URL, DEFAULT_WORKOS_CLIENT_ID, edge_url_from_env, init_logging, long_running_setup, open_log_file, paths, workos_client_id_from_env, }; +pub use engine_commands::run_engine_command; /// mimalloc, macOS only: libmalloc never returns the streaming churn's /// high-water pages, so transient allocation became permanent RSS @@ -33,9 +33,6 @@ static ALLOC: allocator::Allocator = allocator::Allocator; /// `logout`, and `status` — one resolution so the CLI auth commands always /// operate on the exact session the daemon will load. pub fn engine_config_from_env() -> zeron_engine::EngineConfig { - // (Every way an engine starts here resolves its configuration first.) - #[cfg(target_os = "macos")] - zeron_engine::heap::set_trim(allocator::trim); // Dev-mode bearer (no WorkOS): an explicit token enables sync. let edge_token = std::env::var("ZERON_EDGE_TOKEN").ok(); zeron_engine::EngineConfig { diff --git a/apps/zeron/src/main.rs b/apps/zeron/src/main.rs index 30ca2a5f1..0a3d049b8 100644 --- a/apps/zeron/src/main.rs +++ b/apps/zeron/src/main.rs @@ -12,11 +12,6 @@ use zeron_app::{edge_url_from_env, paths, workos_client_id_from_env}; use zeron_cli::{Engines, Launch}; fn main() -> anyhow::Result<()> { - // The engine runs its own executable as an agent's stdio MCP forwarder - // (`zeron headless`'s agents): first, before any setup, to stay tiny. - if std::env::args().nth(1).as_deref() == Some("mcp-proxy") { - return zeron_mcp::proxy::run(); - } match zeron_cli::run(zeron_update::current_version(), Engines::InProcess) { Launch::Done(result) => result, Launch::Engine(command) => zeron_app::run_engine_command(command), diff --git a/apps/zgx/Cargo.lock b/apps/zgx/Cargo.lock index cc7cd5afe..d096e16e9 100644 --- a/apps/zgx/Cargo.lock +++ b/apps/zgx/Cargo.lock @@ -30,7 +30,7 @@ dependencies = [ [[package]] name = "accesskit_atspi_common" version = "0.19.1" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "accesskit", "accesskit_consumer", @@ -43,7 +43,7 @@ dependencies = [ [[package]] name = "accesskit_consumer" version = "0.38.0" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "accesskit", "hashbrown 0.16.1", @@ -66,7 +66,7 @@ dependencies = [ [[package]] name = "accesskit_macos" version = "0.26.3" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "accesskit", "accesskit_consumer", @@ -79,7 +79,7 @@ dependencies = [ [[package]] name = "accesskit_unix" version = "0.22.1" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "accesskit", "accesskit_atspi_common", @@ -96,7 +96,7 @@ dependencies = [ [[package]] name = "accesskit_windows" version = "0.34.0" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "accesskit", "accesskit_consumer", @@ -6450,7 +6450,7 @@ dependencies = [ [[package]] name = "wgpu-hal" version = "29.0.4" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "android_system_properties", "arrayvec", @@ -6888,7 +6888,7 @@ checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" [[package]] name = "winit" version = "0.30.13" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "ahash", "android-activity", @@ -7067,7 +7067,7 @@ dependencies = [ [[package]] name = "zatex" -version = "0.3.4" +version = "0.3.7" dependencies = [ "ttf-parser", ] @@ -7233,7 +7233,7 @@ checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" [[package]] name = "zeron-cli" -version = "0.3.4" +version = "0.3.7" dependencies = [ "anyhow", "clap", @@ -7248,7 +7248,7 @@ dependencies = [ [[package]] name = "zeron-launch" -version = "0.3.4" +version = "0.3.7" dependencies = [ "libc", "windows-sys 0.61.2", @@ -7256,7 +7256,7 @@ dependencies = [ [[package]] name = "zeron-notify" -version = "0.3.4" +version = "0.3.7" dependencies = [ "objc", "sha2", @@ -7265,18 +7265,18 @@ dependencies = [ [[package]] name = "zeron-plugin-guard" -version = "0.3.4" +version = "0.3.7" dependencies = [ "serde_json", ] [[package]] name = "zeron-preview-label" -version = "0.3.4" +version = "0.3.7" [[package]] name = "zeron-proto" -version = "0.3.4" +version = "0.3.7" dependencies = [ "chrono", "pulldown-cmark 0.12.2", @@ -7287,7 +7287,7 @@ dependencies = [ [[package]] name = "zeron-theme" -version = "0.3.4" +version = "0.3.7" dependencies = [ "anyhow", "clap", @@ -7301,7 +7301,7 @@ dependencies = [ [[package]] name = "zeron-update" -version = "0.3.4" +version = "0.3.7" dependencies = [ "anyhow", "futures", @@ -7318,7 +7318,7 @@ dependencies = [ [[package]] name = "zeron-visual" -version = "0.3.4" +version = "0.3.7" dependencies = [ "base64 0.22.1", "gltf", @@ -7330,7 +7330,7 @@ dependencies = [ [[package]] name = "zeron-visual-gpu" -version = "0.3.4" +version = "0.3.7" dependencies = [ "pollster", "tracing", @@ -7340,7 +7340,7 @@ dependencies = [ [[package]] name = "zeron-voice" -version = "0.3.4" +version = "0.3.7" dependencies = [ "anyhow", "cpal", @@ -7456,7 +7456,7 @@ dependencies = [ [[package]] name = "zgx" version = "0.1.10" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "fixed_decimal", "foldhash 0.2.0", @@ -7485,7 +7485,7 @@ dependencies = [ [[package]] name = "zgx-3d" version = "0.1.10" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "bytemuck", "zgx", @@ -7495,7 +7495,7 @@ dependencies = [ [[package]] name = "zgx-alacritty-terminal" version = "0.26.8" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "base64 0.22.1", "bitflags 2.13.2", @@ -7520,7 +7520,7 @@ dependencies = [ [[package]] name = "zgx-components" version = "0.1.10" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "zgx", ] @@ -7528,7 +7528,7 @@ dependencies = [ [[package]] name = "zgx-cosmic-text" version = "0.19.14" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "bitflags 2.13.2", "fontdb", @@ -7552,7 +7552,7 @@ dependencies = [ [[package]] name = "zgx-desktop" version = "0.1.10" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "accesskit", "accesskit_consumer", @@ -7603,12 +7603,12 @@ dependencies = [ [[package]] name = "zgx-ghostty-sys" version = "0.1.10" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" [[package]] name = "zgx-gpu" version = "0.1.10" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "ash", "block2 0.6.2", @@ -7648,7 +7648,7 @@ dependencies = [ [[package]] name = "zgx-harfrust" version = "0.5.4" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "bitflags 2.13.2", "bytemuck", @@ -7660,7 +7660,7 @@ dependencies = [ [[package]] name = "zgx-mlua" version = "0.12.9" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "bstr", "either", @@ -7675,7 +7675,7 @@ dependencies = [ [[package]] name = "zgx-run" version = "0.1.10" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "serde_json", "ureq 3.5.0", @@ -7687,7 +7687,7 @@ dependencies = [ [[package]] name = "zgx-script" version = "0.1.10" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "icu_locale_core", "icu_plurals", @@ -7712,7 +7712,7 @@ dependencies = [ [[package]] name = "zgx-swash" version = "0.2.11" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "skrifa", "yazi", @@ -7722,7 +7722,7 @@ dependencies = [ [[package]] name = "zgx-taffy" version = "0.9.2" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "arrayvec", "grid", @@ -7733,7 +7733,7 @@ dependencies = [ [[package]] name = "zgx-terminal" version = "0.1.10" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "base64 0.22.1", "flate2", @@ -7749,7 +7749,7 @@ dependencies = [ [[package]] name = "zgx-vte" version = "0.15.4" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "arrayvec", "bitflags 2.13.2", @@ -7761,7 +7761,7 @@ dependencies = [ [[package]] name = "zgx-zune-jpeg" version = "0.5.15" -source = "git+https://github.com/zeronsh/zgx?rev=cc3f3e2a127da70f965384ae821cdc29d4bbf0d2#cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" +source = "git+https://github.com/zeronsh/zgx?rev=d391ea7276f0de5cb3d65c191bfd66c02a4c358d#d391ea7276f0de5cb3d65c191bfd66c02a4c358d" dependencies = [ "zune-core", ] diff --git a/apps/zgx/Cargo.toml b/apps/zgx/Cargo.toml index 4008f2853..9a30cbf91 100644 --- a/apps/zgx/Cargo.toml +++ b/apps/zgx/Cargo.toml @@ -32,7 +32,7 @@ layout_probe = [] [dependencies] lz4_flex = { version = "0.11", default-features = false, features = ["safe-encode", "safe-decode"] } -zgx = { git = "https://github.com/zeronsh/zgx", rev = "cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" } +zgx = { git = "https://github.com/zeronsh/zgx", rev = "d391ea7276f0de5cb3d65c191bfd66c02a4c358d" } # `mimalloc`: the program's allocator, in place of the system's. It hands # freed memory back to the system (the system's keeps the most it ever # held), and zgx measures 1-10% less CPU for script, text and layout work. @@ -43,7 +43,7 @@ zgx = { git = "https://github.com/zeronsh/zgx", rev = "cc3f3e2a127da70f965384ae8 # none of it, and without it pages are placeholders ("Web view · "). # zgx-run turns it on by default, but this app takes zgx-run without its # defaults (below). Nothing on macOS or Windows. -zgx-desktop = { git = "https://github.com/zeronsh/zgx", rev = "cc3f3e2a127da70f965384ae821cdc29d4bbf0d2", features = ["mimalloc", "terminal", "webkitgtk"] } +zgx-desktop = { git = "https://github.com/zeronsh/zgx", rev = "d391ea7276f0de5cb3d65c191bfd66c02a4c358d", features = ["mimalloc", "terminal", "webkitgtk"] } # `inspect`: devtools for `zgx inspect` (and its MCP server), asked for # with `--inspect`. `i18n`: `ui.t`'s plurals and numbers by each locale's # own rules (ICU4X's data, about 90 KB), for ui/locales' translations. @@ -51,18 +51,18 @@ zgx-desktop = { git = "https://github.com/zeronsh/zgx", rev = "cc3f3e2a127da70f9 # wgpu this app already links), for plugins that show 3D: the CAD plugin # hands it its own triangles (`geometry = { positions, indices, … }`). It # asks no grant; a scene draws a frame only when something in it changes. -zgx-script = { git = "https://github.com/zeronsh/zgx", rev = "cc3f3e2a127da70f965384ae821cdc29d4bbf0d2", features = ["inspect", "i18n", "scene3d"] } +zgx-script = { git = "https://github.com/zeronsh/zgx", rev = "d391ea7276f0de5cb3d65c191bfd66c02a4c358d", features = ["inspect", "i18n", "scene3d"] } # A picture's pixels for the clipboard (src/images.rs): zgx's own decoder, # the formats `ui.image` shows (no features of its own: the ones zgx-desktop # turns on). -zgx-gpu = { git = "https://github.com/zeronsh/zgx", rev = "cc3f3e2a127da70f965384ae821cdc29d4bbf0d2", default-features = false } +zgx-gpu = { git = "https://github.com/zeronsh/zgx", rev = "d391ea7276f0de5cb3d65c191bfd66c02a4c358d", default-features = false } # Each plugin's own database (`zeron.db`, src/plugins/db.rs): SQLite, # built in; `limits` to keep one from attaching any other file. rusqlite = { version = "0.32", features = ["bundled", "limits", "hooks"] } # `fetch`: zgx's own transport for `ui.fetch` and remote images (HTTP and # HTTPS, rustls), given to every window (src/main.rs): the app's scripts, # and plugins granted "network". Nothing else of the runner. -zgx-run = { git = "https://github.com/zeronsh/zgx", rev = "cc3f3e2a127da70f965384ae821cdc29d4bbf0d2", default-features = false, features = ["fetch"] } +zgx-run = { git = "https://github.com/zeronsh/zgx", rev = "d391ea7276f0de5cb3d65c191bfd66c02a4c358d", default-features = false, features = ["fetch"] } # `webp`: `ui.image` decodes through this crate, by what its features # allow, so turning WebP on here is all it takes (the member cards' art). # `ico`: sites' favicons (the browser tab's: src/favicons.rs), most of @@ -162,7 +162,7 @@ foreign-types = "0.5" # elements, box drawing and Powerline glyphs to the cell; zgx's own renderer # draws them from the font at its text line height, gapped. Builds Ghostty # with Zig 0.16 (cached in ~/Library/Caches/zgx-ghostty). -zgx-desktop = { git = "https://github.com/zeronsh/zgx", rev = "cc3f3e2a127da70f965384ae821cdc29d4bbf0d2", features = ["ghostty"] } +zgx-desktop = { git = "https://github.com/zeronsh/zgx", rev = "d391ea7276f0de5cb3d65c191bfd66c02a4c358d", features = ["ghostty"] } # Windows' Transparency effects (src/transparency.rs), read and watched in # the registry, until zgx reports them (zgx-asks/windows-transparency); a @@ -172,8 +172,8 @@ zgx-desktop = { git = "https://github.com/zeronsh/zgx", rev = "cc3f3e2a127da70f9 # DirectComposition tree of the window's own. The runtime ships with Windows # 11 (and with Edge on Windows 10); without it, pages are placeholders. [target.'cfg(windows)'.dependencies] -windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_Graphics_Gdi", "Win32_Media_Audio", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_Console", "Win32_System_Registry", "Win32_System_Threading", "Win32_UI_WindowsAndMessaging"] } -zgx-desktop = { git = "https://github.com/zeronsh/zgx", rev = "cc3f3e2a127da70f965384ae821cdc29d4bbf0d2", features = ["webview2"] } +windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_Graphics_Gdi", "Win32_Media_Audio", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_Console", "Win32_System_Registry", "Win32_System_Threading", "Win32_System_Time", "Win32_UI_WindowsAndMessaging"] } +zgx-desktop = { git = "https://github.com/zeronsh/zgx", rev = "d391ea7276f0de5cb3d65c191bfd66c02a4c358d", features = ["webview2"] } # zgx's D-Bus (menus, portals) linked in rather than loaded: `zeron` is also # what a headless Linux server and every Cloud machine runs (`zeron @@ -185,13 +185,13 @@ libdbus-sys = { version = "0.2.7", features = ["vendored"] } # zgx's own patches (its root Cargo.toml): a git dependency does not bring # them, so every consumer repeats them. [patch.crates-io] -wgpu-hal = { git = "https://github.com/zeronsh/zgx", rev = "cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" } -winit = { git = "https://github.com/zeronsh/zgx", rev = "cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" } -accesskit_macos = { git = "https://github.com/zeronsh/zgx", rev = "cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" } -accesskit_consumer = { git = "https://github.com/zeronsh/zgx", rev = "cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" } -accesskit_atspi_common = { git = "https://github.com/zeronsh/zgx", rev = "cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" } -accesskit_unix = { git = "https://github.com/zeronsh/zgx", rev = "cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" } -accesskit_windows = { git = "https://github.com/zeronsh/zgx", rev = "cc3f3e2a127da70f965384ae821cdc29d4bbf0d2" } +wgpu-hal = { git = "https://github.com/zeronsh/zgx", rev = "d391ea7276f0de5cb3d65c191bfd66c02a4c358d" } +winit = { git = "https://github.com/zeronsh/zgx", rev = "d391ea7276f0de5cb3d65c191bfd66c02a4c358d" } +accesskit_macos = { git = "https://github.com/zeronsh/zgx", rev = "d391ea7276f0de5cb3d65c191bfd66c02a4c358d" } +accesskit_consumer = { git = "https://github.com/zeronsh/zgx", rev = "d391ea7276f0de5cb3d65c191bfd66c02a4c358d" } +accesskit_atspi_common = { git = "https://github.com/zeronsh/zgx", rev = "d391ea7276f0de5cb3d65c191bfd66c02a4c358d" } +accesskit_unix = { git = "https://github.com/zeronsh/zgx", rev = "d391ea7276f0de5cb3d65c191bfd66c02a4c358d" } +accesskit_windows = { git = "https://github.com/zeronsh/zgx", rev = "d391ea7276f0de5cb3d65c191bfd66c02a4c358d" } # zgx is slow unoptimized (its own setting): optimize dependencies, keep # this crate quick to build. diff --git a/apps/zgx/docs/plugins.md b/apps/zgx/docs/plugins.md index 6ad2dd6bd..5ac07018a 100644 --- a/apps/zgx/docs/plugins.md +++ b/apps/zgx/docs/plugins.md @@ -52,7 +52,8 @@ Your own plugins are signed as yours, and re-signed and reloaded each time you s | `navigate` | open chats and pages (`zeron.open`) | | `links.open` | open http(s) links (`zeron.open_url`), where you open links (Settings → Links) | | `notifications` | send you notifications (`zeron.notify`), as Zeron's own: Settings → Notifications decides whether they show, a few a minute at most | -| `compose` | put text in the message box (`zeron.compose`), or a review comment on it (`zeron.compose_comment`); you still send it | +| `compose` | put text in the message box, after what's there or in place of its words (`zeron.compose`), or a review comment on it (`zeron.compose_comment`); you still send it | +| `draft` | read the message box's draft as you type it (`zeron.draft`), or any chat's (`zeron.draft_of`), and take it whole, put it back, swap it or let it go (`zeron.take_draft`, `put_draft`, `swap_draft`, `drop_draft`). See [The composer's draft](#the-composers-draft) | | `github`, `github.write` | read (and write) GitHub through Zeron's engine (older calls; prefer `commands` with `gh`) | | `network` | the internet: `ui.fetch`, and remote images (`ui.image { src = "https://…" }`). See [Reaching the network](#reaching-the-network) | | `clipboard`, `files`, `web`, `windows` | zgx's clipboard, file dialogs, web views, windows | @@ -213,9 +214,13 @@ Zeron draws that row on your settings page: "Use as wallpaper", and while it's o | call | what | needs | |---|---|---| | `zeron.open("home" \| { session = id } \| { settings = page })` | open a page | `navigate` | -| `zeron.compose(text)` | text into the message box | `compose` | +| `zeron.compose(text, { replace?, session? })` | text into a chat's draft: after what's there (on a line of its own), or in place of its words (`replace = true`, its chips kept); the chat shown's draft, or `session`'s ([below](#the-composers-draft)) | `compose` | | `zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? }` | a review comment on a file or a diff, as a chip on a chat's draft (below) | `compose` | | `zeron.composed()` | in a build: your comments still on a draft, by `key`: `{ session, hovered }` | `compose` | +| `zeron.draft()` | in a build: the message box's draft, `{ session?, text, attachments = { { kind, name } } }` (below) | `draft` | +| `zeron.take_draft(key)`, `zeron.put_draft(key)`, `zeron.swap_draft(key)`, `zeron.drop_draft(key)` | the draft taken whole and kept by Zeron under your key; put back; traded with what the key keeps; let go (below) | `draft` | +| `zeron.drafts()` | in a build: what Zeron keeps for you, by key: `{ session?, text, attachments, at }` | `draft` | +| `zeron.draft_of(session)` | a promise of chat `session`'s draft as it is now, as `zeron.draft()` says it (`""`: a new chat's) | `draft` | | `zeron.toast(text)` | a short note at the window's foot | (always) | | `zeron.need("panel").open_tab { kind, title, icon?, data? }` | a tab of yours in the chat's panel; asked again, the one there is brought forward (found by `data.key` when you give one, else by its title) | `panel.tabs` | | `zeron.tab(kind, function(tab) return node end)` | how a kind of your tabs draws (`tab` = `{ kind, title, data }`) | `panel.tabs` | @@ -274,6 +279,48 @@ Comments on the diff (each cites the file and line it belongs to; L = line numbe Give each a `key` of your own: `zeron.composed()` lists yours still on a draft by it (taken off or sent, gone), and says which one's chip is under the pointer (`hovered`), so the lines it was left on can keep a mark and light up as its chip is pointed at. Zeron's Git plugin does all of this in its Changes (`plugins-builtin/git/changes.luau`): the diff's + (or a drag from it over lines) opens `ds/comment`'s composer under them, using `ds/git_changes`'s `on_comment`, `ranges` and `marks`. +### The composer's draft + +With `draft`, a plugin reads what you're typing and can set it aside and bring it back: a stash for a prompt written in the wrong chat, a counter of its length, a bar that says what it carries. + +- **`zeron.draft()`**, read in a build or an effect, is the draft shown as it changes: `session` (the chat it's for; nil on a new chat), `text` (the words as typed) and `attachments`, each chip's `kind` (`"file"`, `"image"`, `"chat"`, `"comment"`, …) and `name`. A file's path is never in it. +- **`zeron.take_draft(key)`** takes the draft shown whole (its words, its chips, the passages quoted in it) and clears the composer. Zeron keeps it, under your `key` (1 to 64 characters), so your plugin never holds a file's path. An empty draft isn't taken; taking under a key that's kept replaces what it kept. Up to 16 at once. +- **`zeron.put_draft(key)`** puts what `key` kept back on the draft shown, in whichever chat is open, and lets it go. Onto an empty composer it's as it was taken; onto words already there, its words follow after a blank line and its chips after theirs. +- **`zeron.swap_draft(key)`** trades the draft shown with what `key` keeps. Either may be empty, so one call sets the draft aside (nothing kept), brings it back (an empty composer), or swaps the two. +- **`zeron.drop_draft(key)`** lets what `key` kept go. +- **`zeron.drafts()`**, read in a build, is what Zeron keeps for you, by key: `{ session?, text, attachments, at }` (`at` as `os.time()`). Drafts are kept while Zeron runs, as chats' own drafts are. +- **`zeron.draft_of(session)`** reads another chat's draft once, shown or not: a promise of `{ session?, text, attachments }`, as `zeron.draft()` says it (`""` for a new chat's, with no session). + +With `compose` too, a plugin can change the words in place: **`zeron.compose(text, { replace = true })`** puts `text` in place of the draft's words, leaving its chips where they are, and `session` names another chat's draft. A rewrite or a snippet that expands is a read and a replace: + +```lua +-- ("ui.add", "draft", "compose"): /bug alone in the box becomes the template. +ui.effect(function() + local d = zeron.draft() + if d and d.text == "/bug" then + zeron.compose("## What happened\n\n## What I expected\n\n## Steps\n", { replace = true, session = d.session }) + end +end) +``` + +Nothing is sent: the person sees the new words in the composer, and sends or edits them. `zeron.compose` takes 20,000 characters at most. + +Each is done in the order you ask. A prompt stash is one shortcut and one chip: + +```lua +-- ⌘⇧S (Ctrl+Shift+S): set the draft aside, bring it back, or swap the two. +ui.command { id = "stash", title = "Stash prompt", key = "cmd+shift+s", run = function() + zeron.swap_draft("stash") +end } + +-- While one is kept, a chip over the composer: click to bring it back. +zeron.place { at = "#chat-composer", before = function(): Node + return ui.show(function(): boolean + return zeron.drafts().stash ~= nil + end, ui.button { "Stashed", on_click = function() zeron.swap_draft("stash") end }) +end } +``` + ## Programs and a database A plugin can do real work of its own: run the command-line tools you already use, and keep what it learns. diff --git a/apps/zgx/plugins-builtin/git/zeron.luau b/apps/zgx/plugins-builtin/git/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-builtin/git/zeron.luau +++ b/apps/zgx/plugins-builtin/git/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-builtin/github/zeron.luau b/apps/zgx/plugins-builtin/github/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-builtin/github/zeron.luau +++ b/apps/zgx/plugins-builtin/github/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-builtin/parallax-scenes/zeron.luau b/apps/zgx/plugins-builtin/parallax-scenes/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-builtin/parallax-scenes/zeron.luau +++ b/apps/zgx/plugins-builtin/parallax-scenes/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/account-pin/zeron.luau b/apps/zgx/plugins-dev/account-pin/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/account-pin/zeron.luau +++ b/apps/zgx/plugins-dev/account-pin/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/account-rotate/zeron.luau b/apps/zgx/plugins-dev/account-rotate/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/account-rotate/zeron.luau +++ b/apps/zgx/plugins-dev/account-rotate/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/checkout-status/zeron.luau b/apps/zgx/plugins-dev/checkout-status/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/checkout-status/zeron.luau +++ b/apps/zgx/plugins-dev/checkout-status/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/compact-sidebar/zeron.luau b/apps/zgx/plugins-dev/compact-sidebar/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/compact-sidebar/zeron.luau +++ b/apps/zgx/plugins-dev/compact-sidebar/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/composer-cat/zeron.luau b/apps/zgx/plugins-dev/composer-cat/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/composer-cat/zeron.luau +++ b/apps/zgx/plugins-dev/composer-cat/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/focus/zeron.luau b/apps/zgx/plugins-dev/focus/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/focus/zeron.luau +++ b/apps/zgx/plugins-dev/focus/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/keep-going/zeron.luau b/apps/zgx/plugins-dev/keep-going/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/keep-going/zeron.luau +++ b/apps/zgx/plugins-dev/keep-going/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/md-hello/zeron.luau b/apps/zgx/plugins-dev/md-hello/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/md-hello/zeron.luau +++ b/apps/zgx/plugins-dev/md-hello/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/notes-tool/zeron.luau b/apps/zgx/plugins-dev/notes-tool/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/notes-tool/zeron.luau +++ b/apps/zgx/plugins-dev/notes-tool/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/ping/zeron.luau b/apps/zgx/plugins-dev/ping/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/ping/zeron.luau +++ b/apps/zgx/plugins-dev/ping/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/session-status/zeron.luau b/apps/zgx/plugins-dev/session-status/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/session-status/zeron.luau +++ b/apps/zgx/plugins-dev/session-status/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/session-words/zeron.luau b/apps/zgx/plugins-dev/session-words/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/session-words/zeron.luau +++ b/apps/zgx/plugins-dev/session-words/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/settings-demo/zeron.luau b/apps/zgx/plugins-dev/settings-demo/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/settings-demo/zeron.luau +++ b/apps/zgx/plugins-dev/settings-demo/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-sdk/zeron.luau b/apps/zgx/plugins-sdk/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-sdk/zeron.luau +++ b/apps/zgx/plugins-sdk/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/src/agents.rs b/apps/zgx/src/agents.rs index af62053ae..00506865c 100644 --- a/apps/zgx/src/agents.rs +++ b/apps/zgx/src/agents.rs @@ -411,6 +411,24 @@ pub fn install(host: &ScriptHost) { a.add_key(id, provider, key, name).await } }); + // An API key for Cloud's agents (Settings → Providers with Cloud + // shown): kept by the vault, authorized for the account's Cloud device + // (`device`), the key every Cloud machine uses from its next turn. + // Rejects with the engine's words, which never hold the key. + let a = agents.clone(); + host.async_action("agents.cloud_key", move |args| { + let a = a.clone(); + let provider = args.field("provider").map(text).unwrap_or_default(); + let key = args.field("key").map(text).unwrap_or_default().trim().to_string(); + let device = args.field("device").map(text).unwrap_or_default(); + async move { + crate::plugins::preview::refuse("agents.cloud_key")?; + let params = cloud_key_params(&provider, &key, &device)?; + engine::get().call("VaultPutApiKey", params).await.map_err(|error| engine::outcome(&error).to_string())?; + a.load_accounts(true).await; + Ok(Value::Nil) + } + }); // An API key's name (no secret: on whichever device shows it), rejecting // with the engine's words. let a = agents.clone(); @@ -1948,6 +1966,20 @@ fn epoch_secs(s: &str) -> Option { mod tests { use super::*; + /// A Cloud API key goes to the vault for the account's Cloud device: + /// Anthropic's or OpenAI's only, a real key, Cloud on. + #[test] + fn a_cloud_key_is_one_cloud_runs_for_its_device() { + let ok = cloud_key_params("anthropic-key", "sk-ant-123", "cloud-acct").unwrap(); + assert_eq!(ok, json!({ "provider": "anthropic-key", "key": "sk-ant-123", "authorizedDevices": ["cloud-acct"] })); + assert!(cloud_key_params("openai-key", "sk-1", "d").is_ok()); + assert!(cloud_key_params("claude", "sk", "d").is_err(), "a login isn't a key"); + assert!(cloud_key_params("anthropic-key", "", "d").is_err()); + assert!(cloud_key_params("anthropic-key", "a\nb", "d").is_err()); + assert!(cloud_key_params("anthropic-key", &"k".repeat(5000), "d").is_err()); + assert!(cloud_key_params("anthropic-key", "sk", "").is_err(), "Cloud off"); + } + /// Pi signed in to Claude, or another login put in use: Pi's models are /// looked up again. Usage moving, or another agent's, isn't Pi's change. #[test] @@ -2228,6 +2260,22 @@ pub(crate) fn shown_target() -> Option { } /// `params` addressed to the device Providers shows. +/// `VaultPutApiKey`'s params for a Cloud API key: Anthropic's or OpenAI's +/// alone, a key that's there and no longer than any key is, for the +/// account's Cloud device. Else why not. +pub(crate) fn cloud_key_params(provider: &str, key: &str, device: &str) -> Result { + if !matches!(provider, "anthropic-key" | "openai-key") { + return Err("Cloud takes Anthropic and OpenAI keys".into()); + } + if key.is_empty() || key.len() > 4096 || key.chars().any(char::is_control) { + return Err("That isn't an API key".into()); + } + if device.is_empty() { + return Err("Turn Cloud on in Settings → Cloud first".into()); + } + Ok(json!({ "provider": provider, "key": key, "authorizedDevices": [device] })) +} + pub(crate) fn addressed_to_shown(params: Json) -> Json { addressed_to(shown_target().as_deref(), params) } diff --git a/apps/zgx/src/chat.rs b/apps/zgx/src/chat.rs index 1e6f4a6ba..b8e5734fe 100644 --- a/apps/zgx/src/chat.rs +++ b/apps/zgx/src/chat.rs @@ -149,53 +149,16 @@ struct Entry { /// by a part patch): the rest are as they were built. None: not known /// (it came whole, or grew a text). patched: Option>, - /// Its json's sum and its size as JSON, each worked out once and kept - /// until it changes (`json_mut`): a chat opened again says what it holds - /// by its sums, and one let go of is weighed (`let_go_weight`), on every - /// switch, and a long reply's json is hundreds of kilobytes. - kept_sum: std::cell::Cell>, - kept_bytes: std::cell::Cell>, } impl Entry { fn new(json: Json) -> Self { - Self { - id: json["id"].as_str().unwrap_or_default().into(), - json: Some(json), - sum: 0, - patched: None, - kept_sum: std::cell::Cell::new(None), - kept_bytes: std::cell::Cell::new(None), - } + Self { id: json["id"].as_str().unwrap_or_default().into(), json: Some(json), sum: 0, patched: None } } /// What it is now, to tell it from another copy of it. fn sum(&self) -> u64 { - let Some(json) = &self.json else { return self.sum }; - if let Some(sum) = self.kept_sum.get() { - return sum; - } - let sum = sum_of(json); - self.kept_sum.set(Some(sum)); - sum - } - - /// How many bytes its json takes as JSON (none, settled). - fn json_bytes(&self) -> usize { - let Some(json) = &self.json else { return 0 }; - if let Some(bytes) = self.kept_bytes.get() { - return bytes; - } - let bytes = serde_json::to_vec(json).map_or(0, |b| b.len()); - self.kept_bytes.set(Some(bytes)); - bytes - } - - /// Its json, to change: what was worked out from it goes. - fn json_mut(&mut self) -> Option<&mut Json> { - self.kept_sum.set(None); - self.kept_bytes.set(None); - self.json.as_mut() + self.json.as_ref().map_or(self.sum, sum_of) } } @@ -287,12 +250,7 @@ impl zgx_script::Unfold for FoldedEntry { let json = lz4_flex::block::decompress_size_prepended(&self.bytes).ok(); let entry = json.and_then(|bytes| serde_json::from_slice::(&bytes).ok()).unwrap_or(Json::Null); let RowContext { doc, device, model } = &*self.context; - // (Opened as it comes into view, after Settings' compact transcript - // may have been turned on: laid out compact as well, whichever shows.) - COMPACT_ANYWAY.set(true); - let row = built_entry(&entry, doc, device.as_deref(), model.as_deref()).unwrap_or(Value::Nil); - COMPACT_ANYWAY.set(false); - row + built_entry(&entry, doc, device.as_deref(), model.as_deref()).unwrap_or(Value::Nil) } } @@ -317,241 +275,14 @@ struct Built { subagents: Option>, /// Folded, its compressed bytes' length (what a chat kept is weighed by). folded: usize, - /// A long reply's blocks, held here rather than in its row (`set_aside`). - aside: Option>, -} - -/// A long settled reply's blocks and tools, kept out of its row. A script is -/// handed a table for every value of a row it reads, so a reply of a thousand -/// steps cost its 2,000 blocks' and 1,000 tools' tables each time its chat -/// opened (about 3 ms of a long thread's open on an M5 Max, more than all it -/// builds), though its end alone shows. Its row says its runs instead -/// (ds/transcript's windowed runs: each its first block's id, how many -/// blocks, a guess at its height, a sum of what it holds), and the -/// transcript asks for a run's blocks as it builds that run -/// (`chat.reply_run`), the end's alone as it opens. -struct Aside { - /// Each run: its key (its first block's id) and its blocks. - runs: Vec<(Rc, Rc<[Value]>)>, - blocks: Rc<[Value]>, -} - -/// More blocks than this, a settled reply's are set aside (ds/transcript's -/// LONG_REPLY, past which it windows them). -const LONG_REPLY: usize = 48; -/// ds/transcript's runs: a block whose id falls on RUN starts one, and none -/// runs past RUN_MOST. -const RUN: u64 = 32; -const RUN_MOST: usize = 64; - -thread_local! { - /// The long replies set aside, by their entry's id: the latest built of - /// each, while a view's rows (or a chat kept) hold it. - static ASIDE: RefCell, std::rc::Weak