From 0dd04474529d6bfd787cb1655a2f1100a287575f Mon Sep 17 00:00:00 2001 From: Mehdi <46635765+MehdiMamas@users.noreply.github.com> Date: Thu, 5 Nov 2026 04:10:21 -0600 Subject: [PATCH 1/8] Add the activity reader, its state machine and the activity choice --- Cargo.lock | 2 + crates/core/Cargo.toml | 7 + crates/core/src/activity.rs | 288 ++++++++++++++++++++++++++++++++++++ crates/core/src/choices.rs | 56 +++++++ crates/core/src/lib.rs | 1 + 5 files changed, 354 insertions(+) create mode 100644 crates/core/src/activity.rs diff --git a/Cargo.lock b/Cargo.lock index 21bbf17..3eb75dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -735,6 +735,7 @@ dependencies = [ "async-trait", "base64 0.22.1", "chrono", + "core-foundation-sys", "ignore", "keyring", "libc", @@ -753,6 +754,7 @@ dependencies = [ "tracing", "tracing-appender", "tracing-subscriber", + "windows-sys 0.61.2", "wiremock", ] diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index f273caf..cda776b 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -43,6 +43,13 @@ secret-service = ["dep:keyring"] [target.'cfg(unix)'.dependencies] libc = "0.2" +# The idle time of the keyboard and mouse (`activity.rs`), by direct OS calls. +[target.'cfg(windows)'.dependencies] +windows-sys = { version = "0.61", features = ["Win32_UI_Input_KeyboardAndMouse", "Win32_System_SystemInformation"] } + +[target.'cfg(target_os = "macos")'.dependencies] +core-foundation-sys = "0.8" + [dev-dependencies] tempfile = "3" wiremock = "0.6" diff --git a/crates/core/src/activity.rs b/crates/core/src/activity.rs new file mode 100644 index 0000000..5a7e483 --- /dev/null +++ b/crates/core/src/activity.rs @@ -0,0 +1,288 @@ +//! Whether you are at the computer (docs/architecture.md §22). Opt-in: nothing here runs +//! unless `Choices.activity.share` is on. The idle time comes from direct OS calls, and a +//! small state machine turns it into `active`, `idle` or `unknown` and decides when to +//! write `/activity.json`. Nothing leaves this machine in this step. +use crate::state::write_json; +use crate::Paths; +use serde::{Deserialize, Serialize}; +use std::path::PathBuf; + +/// Idle at or above this many seconds counts as `idle`. +pub const IDLE_AFTER_SECS: u64 = 120; +/// The value is written again after this long with no change of state. +pub const HEARTBEAT_SECS: u64 = 300; +/// How often the loops read the idle time. +pub const READ_EVERY_SECS: u64 = 30; + +pub fn file(paths: &Paths) -> PathBuf { + paths.state_dir.join("activity.json") +} + +/// Seconds since the last keyboard or mouse input in this session. `None`: this OS (or +/// session) cannot say, shown as `unknown`, never as idle. +pub fn idle_seconds() -> Option { + os::idle_seconds() +} + +#[cfg(windows)] +mod os { + use windows_sys::Win32::System::SystemInformation::GetTickCount; + use windows_sys::Win32::UI::Input::KeyboardAndMouse::{GetLastInputInfo, LASTINPUTINFO}; + + pub fn idle_seconds() -> Option { + let mut info = LASTINPUTINFO { + cbSize: std::mem::size_of::() as u32, + dwTime: 0, + }; + // SAFETY: `info` is a valid LASTINPUTINFO with `cbSize` set. + if unsafe { GetLastInputInfo(&mut info) } == 0 { + return None; + } + // SAFETY: no arguments. Both values are 32-bit tick counts that wrap together. + let now = unsafe { GetTickCount() }; + Some(u64::from(now.wrapping_sub(info.dwTime)) / 1000) + } +} + +#[cfg(target_os = "macos")] +mod os { + use core_foundation_sys::base::{CFRelease, CFTypeRef}; + use core_foundation_sys::number::{CFNumberGetValue, CFNumberRef}; + use core_foundation_sys::string::CFStringCreateWithCString; + use std::ffi::{c_char, c_void}; + + type Port = u32; + const UTF8: u32 = 0x0800_0100; + const SINT64: isize = 4; + + #[link(name = "IOKit", kind = "framework")] + extern "C" { + fn IOServiceMatching(name: *const c_char) -> *mut c_void; + fn IOServiceGetMatchingService(main_port: Port, matching: *mut c_void) -> Port; + fn IORegistryEntryCreateCFProperty( + entry: Port, + key: *const c_void, + allocator: *const c_void, + options: u32, + ) -> CFTypeRef; + fn IOObjectRelease(object: Port) -> i32; + } + + pub fn idle_seconds() -> Option { + // SAFETY: plain IOKit/CoreFoundation calls; every object created here is released + // before returning, and `IOServiceGetMatchingService` consumes the matching dict. + unsafe { + let matching = IOServiceMatching(c"IOHIDSystem".as_ptr()); + if matching.is_null() { + return None; + } + let service = IOServiceGetMatchingService(0, matching); + if service == 0 { + return None; + } + let key = CFStringCreateWithCString(std::ptr::null(), c"HIDIdleTime".as_ptr(), UTF8); + let value = if key.is_null() { + std::ptr::null() + } else { + IORegistryEntryCreateCFProperty(service, key.cast(), std::ptr::null(), 0) + }; + let mut ns: i64 = 0; + let ok = !value.is_null() + && CFNumberGetValue(value as CFNumberRef, SINT64, (&mut ns as *mut i64).cast()) + != 0; + if !value.is_null() { + CFRelease(value); + } + if !key.is_null() { + CFRelease(key.cast()); + } + IOObjectRelease(service); + (ok && ns >= 0).then(|| ns as u64 / 1_000_000_000) + } + } +} + +#[cfg(not(any(windows, target_os = "macos")))] +mod os { + pub fn idle_seconds() -> Option { + None + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum State { + Active, + Idle, + Unknown, +} + +/// What `activity.json` holds. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Write { + pub schema: u32, + pub state: State, + pub idle_seconds: Option, + pub updated_at: u64, +} + +/// Decides, from each reading, whether to write. Pure: the clock and the reading are +/// passed in. +#[derive(Debug, Default)] +pub struct Tracker { + last: Option<(State, u64)>, +} + +impl Tracker { + /// `now` is Unix seconds. A write on a change of state, or when the last write is + /// `HEARTBEAT_SECS` old; otherwise `None`. + pub fn step(&mut self, now: u64, idle: Option) -> Option { + let state = match idle { + None => State::Unknown, + Some(s) if s >= IDLE_AFTER_SECS => State::Idle, + Some(_) => State::Active, + }; + let due = match self.last { + Some((st, at)) => st != state || now.saturating_sub(at) >= HEARTBEAT_SECS, + None => true, + }; + if !due { + return None; + } + self.last = Some((state, now)); + Some(Write { + schema: 1, + state, + idle_seconds: idle, + updated_at: now, + }) + } + + /// Forget the last write (sharing was turned off), so turning it on writes at once. + pub fn reset(&mut self) { + self.last = None; + } +} + +pub fn write(paths: &Paths, w: &Write) -> crate::Result<()> { + write_json(&file(paths), w) +} + +/// Delete the value on this machine. +pub fn remove(paths: &Paths) { + if let Err(e) = std::fs::remove_file(file(paths)) { + if e.kind() != std::io::ErrorKind::NotFound { + tracing::warn!("could not remove activity.json: {e}"); + } + } +} + +/// One pass of the 30 s loop: follows the choice. Off: the file is removed and the tracker +/// reset. On: read once and write when the tracker says so. +pub fn pass(paths: &Paths, tracker: &mut Tracker, now: u64, idle: impl FnOnce() -> Option) { + let share = crate::choices::load(paths).is_ok_and(|c| c.activity.share); + if !share { + if tracker.last.take().is_some() || file(paths).exists() { + remove(paths); + } + return; + } + if let Some(w) = tracker.step(now, idle()) { + if let Err(e) = write(paths, &w) { + tracing::warn!("could not write activity.json: {e}"); + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn paths() -> (tempfile::TempDir, Paths) { + let tmp = tempfile::tempdir().unwrap(); + let p = Paths { + claude_home: tmp.path().join(".claude"), + state_dir: tmp.path().join(".claude-sync"), + }; + (tmp, p) + } + + #[test] + fn active_below_the_threshold_idle_at_it() { + let mut t = Tracker::default(); + assert_eq!(t.step(1000, Some(119)).unwrap().state, State::Active); + assert_eq!(t.step(1030, Some(120)).unwrap().state, State::Idle); + assert_eq!(t.step(1060, Some(5)).unwrap().state, State::Active); + } + + #[test] + fn heartbeat_after_300_seconds_without_a_change() { + let mut t = Tracker::default(); + assert!(t.step(1000, Some(1)).is_some()); + assert!(t.step(1299, Some(2)).is_none()); + let w = t.step(1300, Some(3)).unwrap(); + assert_eq!( + (w.state, w.updated_at, w.idle_seconds), + (State::Active, 1300, Some(3)) + ); + assert!(t.step(1330, Some(4)).is_none()); + } + + #[test] + fn no_write_without_a_change() { + let mut t = Tracker::default(); + assert!(t.step(1000, Some(10)).is_some()); + for i in 1..10 { + assert!(t.step(1000 + i * 30, Some(10)).is_none()); + } + } + + #[test] + fn no_reading_is_unknown_never_idle() { + let mut t = Tracker::default(); + let w = t.step(1000, None).unwrap(); + assert_eq!((w.state, w.idle_seconds), (State::Unknown, None)); + assert_eq!(serde_json::to_value(&w).unwrap()["state"], "unknown"); + } + + #[test] + fn file_has_the_documented_shape_and_remove_deletes_it() { + let (_t, p) = paths(); + let mut t = Tracker::default(); + let w = t.step(42, Some(7)).unwrap(); + write(&p, &w).unwrap(); + let v: serde_json::Value = + serde_json::from_slice(&std::fs::read(file(&p)).unwrap()).unwrap(); + assert_eq!(v["schema"], 1); + assert_eq!(v["state"], "active"); + assert_eq!(v["idleSeconds"], 7); + assert_eq!(v["updatedAt"], 42); + remove(&p); + assert!(!file(&p).exists()); + remove(&p); // already gone: no error + } + + #[test] + fn pass_follows_the_choice() { + let (_t, p) = paths(); + let mut t = Tracker::default(); + pass(&p, &mut t, 100, || Some(1)); + assert!(!file(&p).exists(), "off by default: nothing written"); + crate::choices::set_activity(&p, true).unwrap(); + pass(&p, &mut t, 130, || Some(1)); + assert!(file(&p).exists()); + crate::choices::set_activity(&p, false).unwrap(); + pass(&p, &mut t, 160, || panic!("no reading while off")); + assert!(!file(&p).exists(), "turning it off removes the file"); + crate::choices::set_activity(&p, true).unwrap(); + pass(&p, &mut t, 190, || Some(1)); + assert!(file(&p).exists(), "turning it on again writes at once"); + } + + #[cfg(any(windows, target_os = "macos"))] + #[test] + fn the_os_gives_a_real_reading() { + assert!(idle_seconds().is_some()); + } +} diff --git a/crates/core/src/choices.rs b/crates/core/src/choices.rs index f9d6b5b..96e79be 100644 --- a/crates/core/src/choices.rs +++ b/crates/core/src/choices.rs @@ -9,6 +9,7 @@ //! "droppedLines": ["a line"], "member": true, "ts": 1760000000000 } }, //! "personal": { "off": true, "ts": 1760000000000 }, //! "sshPeers": { "on": true, "ts": 1760000000000 }, +//! "activity": { "share": true, "ts": 1760000000000 }, //! "order": { "list": ["owner/repo"], "ts": 1760000000000 }, //! "app": { "paused": false, "intervalSecs": 60, "startAtLogin": true, "ts": 1760000000000 } } //! ``` @@ -97,6 +98,15 @@ pub struct SshPeersChoice { pub ts: u64, } +/// Share whether you are at the computer (`activity.rs`), on every device of the account. +/// Off until you turn it on. +#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] +#[serde(default)] +pub struct ActivityChoice { + pub share: bool, + pub ts: u64, +} + #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] #[serde(default)] pub struct Choices { @@ -104,6 +114,7 @@ pub struct Choices { pub personal: PersonalChoice, #[serde(rename = "sshPeers")] pub ssh_peers: SshPeersChoice, + pub activity: ActivityChoice, pub order: Order, pub app: AppChoice, /// Keys a newer version wrote are kept. @@ -262,6 +273,17 @@ pub fn set_ssh_peers(paths: &Paths, on: bool) -> crate::Result { Ok(c) } +/// Turn sharing your activity on (or off) for every device. +pub fn set_activity(paths: &Paths, share: bool) -> crate::Result { + let mut c = load(paths)?; + c.activity = ActivityChoice { + share, + ts: stamp(c.activity.ts), + }; + write_json(&file(paths), &c)?; + Ok(c) +} + /// A group moved to a new `owner/repo`: its choices move with it. pub fn rename_group(paths: &Paths, old: &GroupId, new: &GroupId) -> crate::Result<()> { let mut c = load(paths)?; @@ -293,6 +315,9 @@ pub fn merge(local: &[u8], remote: &[u8]) -> Option> { if l.ssh_peers.ts > out.ssh_peers.ts { out.ssh_peers = l.ssh_peers; } + if l.activity.ts > out.activity.ts { + out.activity = l.activity; + } if l.order.ts > out.order.ts { out.order = l.order; } @@ -439,6 +464,37 @@ mod tests { assert!(!out.ssh_peers.on, "remote is newer"); } + #[test] + fn activity_is_off_by_default_and_keeps_unknown_keys() { + let (_t, p) = paths(); + assert!(!load(&p).unwrap().activity.share); + std::fs::create_dir_all(file(&p).parent().unwrap()).unwrap(); + std::fs::write(file(&p), br#"{"future":{"x":1}}"#).unwrap(); + let c = set_activity(&p, true).unwrap(); + assert!(c.activity.share && c.activity.ts > 0); + let back = load(&p).unwrap(); + assert!(back.activity.share); + assert_eq!(back.extra["future"]["x"], 1); + assert!(!set_activity(&p, false).unwrap().activity.share); + } + + #[test] + fn activity_merges_by_its_own_ts() { + let mk = |share: bool, ts: u64| { + let c = Choices { + activity: ActivityChoice { share, ts }, + ..Default::default() + }; + serde_json::to_vec(&c).unwrap() + }; + let out: Choices = + serde_json::from_slice(&merge(&mk(true, 5), &mk(false, 3)).unwrap()).unwrap(); + assert!(out.activity.share, "local is newer"); + let out: Choices = + serde_json::from_slice(&merge(&mk(true, 2), &mk(false, 3)).unwrap()).unwrap(); + assert!(!out.activity.share, "remote is newer"); + } + #[test] fn set_ssh_peers_saves_and_stamps() { let (_t, p) = paths(); diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index ca55153..6629fd8 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -1,6 +1,7 @@ //! claude-sync core: GitHub client, group format, sync engine, apply layer. //! Design: docs/architecture.md. Section numbers below (§N) refer to it. +pub mod activity; pub mod apply; pub mod choices; pub mod claude_cli; From 863c82526f8e9f5b3936c8a4cfee2170db6e22e6 Mon Sep 17 00:00:00 2001 From: Mehdi <46635765+MehdiMamas@users.noreply.github.com> Date: Thu, 5 Nov 2026 04:11:49 -0600 Subject: [PATCH 2/8] Add the activity command and the daemon loop to the headless CLI --- crates/cli/src/args.rs | 18 ++++++++++++++++++ crates/cli/src/cmds.rs | 25 ++++++++++++++++++++++++- crates/cli/src/daemon.rs | 11 +++++++++++ crates/cli/tests/activity.rs | 35 +++++++++++++++++++++++++++++++++++ crates/core/src/activity.rs | 27 ++++++++++++++++++++++----- 5 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 crates/cli/tests/activity.rs diff --git a/crates/cli/src/args.rs b/crates/cli/src/args.rs index e37b08d..48c2524 100644 --- a/crates/cli/src/args.rs +++ b/crates/cli/src/args.rs @@ -14,6 +14,7 @@ usage: claude-sync-cli [--json] personal status|enable|disable ssh status|enable|disable reach your own machines over SSH (ssh ) ssh alias the name your other machines use for this one + activity status|enable|disable share whether you are at the computer (off until you turn it on) review list changes waiting for you (CLAUDE.md, local edits, jobs) review accept accept one (ids come from `review list`) review undo decline or undo one @@ -37,6 +38,13 @@ pub enum Ssh { Alias(String), } +#[derive(Debug, PartialEq, Eq)] +pub enum Activity { + Status, + Enable, + Disable, +} + #[derive(Debug, PartialEq, Eq)] pub enum Review { List, @@ -62,6 +70,7 @@ pub enum Cmd { Status, Personal(Personal), Ssh(Ssh), + Activity(Activity), Review(Review), Daemon, Service(Service), @@ -107,6 +116,9 @@ pub fn parse(args: &[String]) -> Result<(Cmd, bool), String> { ["ssh", "enable"] => Cmd::Ssh(Ssh::Enable), ["ssh", "disable"] => Cmd::Ssh(Ssh::Disable), ["ssh", "alias", name] => Cmd::Ssh(Ssh::Alias((*name).into())), + ["activity", "status"] => Cmd::Activity(Activity::Status), + ["activity", "enable"] => Cmd::Activity(Activity::Enable), + ["activity", "disable"] => Cmd::Activity(Activity::Disable), ["review", "list"] => Cmd::Review(Review::List), ["review", "accept", id] => Cmd::Review(Review::Accept((*id).into())), ["review", "undo", id] => Cmd::Review(Review::Undo((*id).into())), @@ -154,6 +166,10 @@ mod tests { parse(&v(&["ssh", "alias", "tower"])), Ok((Cmd::Ssh(Ssh::Alias("tower".into())), false)) ); + assert_eq!( + parse(&v(&["activity", "enable", "--json"])), + Ok((Cmd::Activity(Activity::Enable), true)) + ); assert_eq!( parse(&v(&["review", "accept", "md:a/b:x1"])), Ok((Cmd::Review(Review::Accept("md:a/b:x1".into())), false)) @@ -196,6 +212,8 @@ mod tests { v(&["ssh"]), v(&["ssh", "alias"]), v(&["ssh", "x"]), + v(&["activity"]), + v(&["activity", "watch"]), v(&["review", "accept"]), v(&["service", "restart"]), v(&["status", "extra"]), diff --git a/crates/cli/src/cmds.rs b/crates/cli/src/cmds.rs index 7cc7173..7a57b5b 100644 --- a/crates/cli/src/cmds.rs +++ b/crates/cli/src/cmds.rs @@ -1,5 +1,5 @@ //! The commands. Each returns the text for a person and the value for `--json`. -use crate::args::{Cmd, Personal, Review, Service, Ssh}; +use crate::args::{Activity, Cmd, Personal, Review, Service, Ssh}; use crate::auth::{self, Hosts, Standing}; use crate::daemon; use crate::jobs::{Hooks, RealHooks}; @@ -61,6 +61,7 @@ pub async fn execute(paths: &Paths, cmd: Cmd) -> Result { Cmd::Status => status(paths).await, Cmd::Personal(p) => personal(paths, p).await, Cmd::Ssh(s) => ssh(paths, s), + Cmd::Activity(a) => activity(paths, a), Cmd::Review(r) => review_cmd(paths, r).await, Cmd::Service(s) => { let text = match s { @@ -314,6 +315,28 @@ fn ssh(paths: &Paths, s: Ssh) -> Result { )) } +/// Share whether you are at the computer. These set the choice; the loop does the rest. +fn activity(paths: &Paths, a: Activity) -> Result { + use claude_sync_core::choices; + let c = match a { + Activity::Enable => choices::set_activity(paths, true), + Activity::Disable => choices::set_activity(paths, false), + Activity::Status => choices::load(paths), + } + .map_err(|e| e.to_string())?; + if !c.activity.share { + claude_sync_core::activity::remove(paths); + } + let share = c.activity.share; + Ok(Out::new( + format!( + "Sharing your activity is {}.", + if share { "on" } else { "off" } + ), + json!({ "share": share }), + )) +} + async fn review_cmd(paths: &Paths, r: Review) -> Result { let (_, engine) = auth::require(paths)?; match r { diff --git a/crates/cli/src/daemon.rs b/crates/cli/src/daemon.rs index 3cf82d9..b0315bf 100644 --- a/crates/cli/src/daemon.rs +++ b/crates/cli/src/daemon.rs @@ -140,6 +140,14 @@ fn now_unix() -> u64 { .map_or(0, |d| d.as_secs()) } +struct AbortOnDrop(tokio::task::JoinHandle<()>); + +impl Drop for AbortOnDrop { + fn drop(&mut self) { + self.0.abort(); + } +} + /// Sync every poll interval until `shutdown` completes. The token file is read again at /// every pass, so `login` and `logout` take effect without a restart. pub async fn run(paths: &Paths, hooks: Arc, shutdown: impl Future) { @@ -149,6 +157,9 @@ pub async fn run(paths: &Paths, hooks: Arc, shutdown: impl Future { diff --git a/crates/cli/tests/activity.rs b/crates/cli/tests/activity.rs new file mode 100644 index 0000000..742ca4a --- /dev/null +++ b/crates/cli/tests/activity.rs @@ -0,0 +1,35 @@ +//! `claude-sync-cli activity` round trip. Only the choice is set; the state folders are +//! temporary. +use std::process::Command; + +fn run(home: &std::path::Path, args: &[&str]) -> (i32, serde_json::Value) { + let out = Command::new(env!("CARGO_BIN_EXE_claude-sync-cli")) + .args(args) + .arg("--json") + .env("CLAUDE_HOME", home.join("claude")) + .env("CLAUDE_SYNC_HOME", home.join("state")) + .output() + .unwrap(); + let v = serde_json::from_slice(&out.stdout).unwrap_or(serde_json::Value::Null); + (out.status.code().unwrap_or(-1), v) +} + +#[test] +fn enable_status_disable_round_trip() { + let t = tempfile::tempdir().unwrap(); + let (code, v) = run(t.path(), &["activity", "status"]); + assert_eq!((code, v["share"].as_bool()), (0, Some(false))); + let (code, v) = run(t.path(), &["activity", "enable"]); + assert_eq!((code, v["share"].as_bool()), (0, Some(true))); + let (code, v) = run(t.path(), &["activity", "status"]); + assert_eq!((code, v["share"].as_bool()), (0, Some(true))); + // The value on this machine goes at once when sharing is turned off. + let file = t.path().join("state").join("activity.json"); + std::fs::create_dir_all(file.parent().unwrap()).unwrap(); + std::fs::write(&file, "{}").unwrap(); + let (code, v) = run(t.path(), &["activity", "disable"]); + assert_eq!((code, v["share"].as_bool()), (0, Some(false))); + assert!(!file.exists()); + let (code, _) = run(t.path(), &["activity", "watch"]); + assert_eq!(code, 2); +} diff --git a/crates/core/src/activity.rs b/crates/core/src/activity.rs index 5a7e483..b2d7b5b 100644 --- a/crates/core/src/activity.rs +++ b/crates/core/src/activity.rs @@ -158,11 +158,6 @@ impl Tracker { updated_at: now, }) } - - /// Forget the last write (sharing was turned off), so turning it on writes at once. - pub fn reset(&mut self) { - self.last = None; - } } pub fn write(paths: &Paths, w: &Write) -> crate::Result<()> { @@ -195,6 +190,28 @@ pub fn pass(paths: &Paths, tracker: &mut Tracker, now: u64, idle: impl FnOnce() } } +/// The 30 s loop of the app and the daemon. It does nothing but read the choice while +/// sharing is off. Runs until the task is aborted. +pub async fn run_loop(paths: Paths) { + let mut tracker = Tracker::default(); + loop { + let p = paths.clone(); + match tokio::task::spawn_blocking(move || { + pass(&p, &mut tracker, crate::state::now_unix(), idle_seconds); + tracker + }) + .await + { + Ok(t) => tracker = t, + Err(e) => { + tracing::error!("activity pass failed: {e}"); + tracker = Tracker::default(); + } + } + tokio::time::sleep(std::time::Duration::from_secs(READ_EVERY_SECS)).await; + } +} + #[cfg(test)] mod tests { use super::*; From a73bd9b94937d0cfa22ad58f885540fbebe4d491 Mon Sep 17 00:00:00 2001 From: Mehdi <46635765+MehdiMamas@users.noreply.github.com> Date: Thu, 5 Nov 2026 04:13:42 -0600 Subject: [PATCH 3/8] Add the activity setting, consent dialog, app commands and docs --- AGENTS.md | 4 ++- app/src-tauri/src/background.rs | 4 +++ app/src-tauri/src/cli.rs | 42 +++++++++++++++++++++++-- app/src-tauri/src/commands.rs | 26 ++++++++++++++++ app/src-tauri/src/main.rs | 2 ++ app/ui/src/activity-consent.test.mjs | 30 ++++++++++++++++++ app/ui/src/activity-consent.ts | 32 +++++++++++++++++++ app/ui/src/api.ts | 6 ++++ app/ui/src/mock.ts | 6 ++++ app/ui/src/screens/settings.ts | 46 ++++++++++++++++++++++++++++ app/ui/src/style.css | 12 ++++++++ docs/architecture.md | 11 +++++++ 12 files changed, 217 insertions(+), 4 deletions(-) create mode 100644 app/ui/src/activity-consent.test.mjs create mode 100644 app/ui/src/activity-consent.ts diff --git a/AGENTS.md b/AGENTS.md index eb6977a..cfe0493 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -25,7 +25,7 @@ Every setting lives in exactly one scope: group, personal or project. There are ## Headless command line (`claude-sync-cli`) `crates/cli` is a separate binary with no GUI and no WebKit; it depends on core with `--no-default-features` (no Linux keyring). Build and test it alone: `cargo test -p claude-sync-core --no-default-features -p claude-sync-cli`. Exit code: 0 done, 1 failed, 2 wrong usage; `--json` for machine output. -- Commands: `login` (device flow), `logout`, `groups`, `join `, `leave`, `sync`, `status`, `personal status|enable|disable`, `ssh status|enable|disable|alias `, `review list|accept|undo `, `daemon`, `service install|remove|status`, `update [--check]`, `version`. `run-job` is hidden: the OS tasks of group jobs call it. +- Commands: `login` (device flow), `logout`, `groups`, `join `, `leave`, `sync`, `status`, `personal status|enable|disable`, `ssh status|enable|disable|alias `, `activity status|enable|disable`, `review list|accept|undo `, `daemon`, `service install|remove|status`, `update [--check]`, `version`. `run-job` is hidden: the OS tasks of group jobs call it. - The token is the file `~/.claude-sync/token` (mode 0600), not the keyring. The daemon reloads it each pass. - `service install` writes a systemd user unit when systemd runs, else an `@reboot` crontab line plus a 5-minute check. `daemon.lock` keeps one daemon alive. - Syncs from the app and the CLI share `/sync.lock` (`core::lock`), so they never run at once. @@ -39,6 +39,8 @@ The app binary is also the CLI (`app/src-tauri/src/cli.rs`, handled before Tauri - On macOS and Linux the release app links `~/.local/bin/claude-sync` to its binary at startup (only if that folder exists and the name is free). Windows has no shim: run the full path of `claude-sync.exe`. Debug builds add no link; run `target/debug/claude-sync`. - On Windows the release exe is a GUI program, so PowerShell shows none of its output when you call it directly: pipe it, e.g. `& "$env:LOCALAPPDATA\claude-sync\claude-sync.exe" status --json | Out-String` (#149). +- `claude-sync activity status|enable|disable` (also in `claude-sync-cli`): share whether you are at the computer; off by default, local only in step 1 (`crates/core/src/activity.rs`, architecture §22). + - SSH between your own machines (`crates/core/src/ssh_peers.rs`, architecture §21): the sync loops call `ssh_peers::sync_pass` after personal sync. It edits only the marked block of `~/.ssh/authorized_keys`, `~/.ssh/claude-sync.conf` and the `Include` first line of `~/.ssh/config`; tests inject `Env` and `Probe` and never touch the real `~/.ssh`. A peer's record may carry a private `lan` IPv4 address: with `nc` on PATH the conf entry falls back to it when Tailscale is down (architecture §21). ## Conventions diff --git a/app/src-tauri/src/background.rs b/app/src-tauri/src/background.rs index b853e4f..d442a89 100644 --- a/app/src-tauri/src/background.rs +++ b/app/src-tauri/src/background.rs @@ -24,6 +24,10 @@ pub fn start(app: &AppHandle) { tauri::async_runtime::spawn(async move { update_loop(a).await }); let a = app.clone(); tauri::async_runtime::spawn(async move { requests_loop(a).await }); + // Reads the idle time every 30 s, and only while sharing activity is on. + tauri::async_runtime::spawn(claude_sync_core::activity::run_loop( + app.state::>().paths.clone(), + )); start_watcher(app); } diff --git a/app/src-tauri/src/cli.rs b/app/src-tauri/src/cli.rs index eebecfc..25ed4b6 100644 --- a/app/src-tauri/src/cli.rs +++ b/app/src-tauri/src/cli.rs @@ -1,5 +1,5 @@ //! The command line (docs/architecture.md §11a): `claude-sync status` and -//! `claude-sync personal enable|disable|status` and `claude-sync ssh enable|disable|status|alias `. Handled before Tauri starts, like +//! `claude-sync personal enable|disable|status` and `claude-sync ssh enable|disable|status|alias ` and `claude-sync activity enable|disable|status`. Handled before Tauri starts, like //! `run-job`, and calling the same core functions as the Settings screen. use crate::ctx::{now_unix, Ctx}; use crate::guard; @@ -10,9 +10,9 @@ use claude_sync_core::Paths; pub const REFRESH_ARG: &str = "--refresh"; /// Subcommands this module handles. -pub const COMMANDS: [&str; 3] = ["status", "personal", "ssh"]; +pub const COMMANDS: [&str; 4] = ["status", "personal", "ssh", "activity"]; -const USAGE: &str = "usage: claude-sync status [--json]\n claude-sync personal enable|disable|status [--json]\n claude-sync ssh enable|disable|status|alias [--json]"; +const USAGE: &str = "usage: claude-sync status [--json]\n claude-sync personal enable|disable|status [--json]\n claude-sync ssh enable|disable|status|alias [--json]\n claude-sync activity enable|disable|status [--json]"; #[derive(Debug, PartialEq, Eq)] pub enum Cmd { @@ -21,6 +21,14 @@ pub enum Cmd { PersonalEnable, PersonalDisable, Ssh(Ssh), + Activity(Activity), +} + +#[derive(Debug, PartialEq, Eq)] +pub enum Activity { + Status, + Enable, + Disable, } #[derive(Debug, PartialEq, Eq)] @@ -48,6 +56,9 @@ pub fn parse(args: &[String]) -> Result<(Cmd, bool), &'static str> { ["ssh", "enable"] => Cmd::Ssh(Ssh::Enable), ["ssh", "disable"] => Cmd::Ssh(Ssh::Disable), ["ssh", "alias", name] => Cmd::Ssh(Ssh::Alias((*name).into())), + ["activity", "status"] => Cmd::Activity(Activity::Status), + ["activity", "enable"] => Cmd::Activity(Activity::Enable), + ["activity", "disable"] => Cmd::Activity(Activity::Disable), _ => return Err(USAGE), }; Ok((cmd, json)) @@ -135,6 +146,26 @@ async fn execute(paths: &Paths, cmd: Cmd, json: bool) -> Result } Ok(text) } + Cmd::Activity(a) => { + use claude_sync_core::{activity, choices}; + // The running app and the daemon read the choice every 30 seconds. + let c = match a { + Activity::Enable => choices::set_activity(paths, true), + Activity::Disable => choices::set_activity(paths, false), + Activity::Status => choices::load(paths), + } + .map_err(|e| e.to_string())?; + if !c.activity.share { + activity::remove(paths); + } + if json { + return Ok(serde_json::json!({ "share": c.activity.share }).to_string()); + } + Ok(format!( + "Sharing your activity is {}.", + if c.activity.share { "on" } else { "off" } + )) + } Cmd::PersonalStatus | Cmd::PersonalEnable | Cmd::PersonalDisable => { let engine = ctx.engine()?; let st = match cmd { @@ -286,6 +317,11 @@ mod tests { parse(&v(&["ssh", "enable"])), Ok((Cmd::Ssh(Ssh::Enable), false)) ); + assert_eq!( + parse(&v(&["activity", "enable", "--json"])), + Ok((Cmd::Activity(Activity::Enable), true)) + ); + assert!(parse(&v(&["activity"])).is_err()); assert!(parse(&v(&["ssh"])).is_err()); assert!(parse(&v(&["ssh", "alias"])).is_err()); assert!(parse(&v(&["personal"])).is_err()); diff --git a/app/src-tauri/src/commands.rs b/app/src-tauri/src/commands.rs index 6a02df5..4abf7e2 100644 --- a/app/src-tauri/src/commands.rs +++ b/app/src-tauri/src/commands.rs @@ -829,6 +829,32 @@ pub fn set_settings(app: AppHandle, ctx: CtxState, settings: SettingsPatch) -> R Ok(settings_of(&app, &ctx)) } +#[derive(Serialize)] +pub struct ActivityView { + share: bool, +} + +/// Whether sharing your activity (at the computer or not) is on. Off until you turn it on. +#[tauri::command] +pub fn get_activity(ctx: CtxState) -> Res { + let c = + claude_sync_core::choices::load(&ctx.paths).map_err(guard::logged("read the choices"))?; + Ok(ActivityView { + share: c.activity.share, + }) +} + +/// Turn sharing on or off. Off deletes the value on this machine at once. +#[tauri::command] +pub fn set_activity(ctx: CtxState, share: bool) -> Res { + claude_sync_core::choices::set_activity(&ctx.paths, share) + .map_err(guard::logged("save the activity choice"))?; + if !share { + claude_sync_core::activity::remove(&ctx.paths); + } + Ok(ActivityView { share }) +} + /// Which of this device's group repos the GitHub App can reach (issue #39). #[tauri::command] pub async fn app_coverage(app: AppHandle) -> Res { diff --git a/app/src-tauri/src/main.rs b/app/src-tauri/src/main.rs index a82e4cf..dc6ede8 100644 --- a/app/src-tauri/src/main.rs +++ b/app/src-tauri/src/main.rs @@ -181,6 +181,8 @@ fn main() { commands::copy_preview, commands::copy_to_group, commands::sync_now, + commands::get_activity, + commands::set_activity, commands::get_settings, commands::set_settings, commands::notifications, diff --git a/app/ui/src/activity-consent.test.mjs b/app/ui/src/activity-consent.test.mjs new file mode 100644 index 0000000..e588e4e --- /dev/null +++ b/app/ui/src/activity-consent.test.mjs @@ -0,0 +1,30 @@ +// `pnpm -C app/ui test`: Node runs activity-consent.ts directly (type stripping, Node 23.6+). +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { ACTIVITY_COPY, SHARE_DEFAULT, decide, statusText } from "./activity-consent.ts"; + +test("the consent copy says what is read and what is not, and where it goes", () => { + const text = ACTIVITY_COPY.paragraphs.join(" "); + assert.match(text, /seconds since the last mouse or keyboard input/); + assert.match(text, /never reads which keys you press/); + assert.match(text, /never to your groups, to other people, or to us/); + assert.match(text, /deletes the value on this machine at once/); + assert.equal(ACTIVITY_COPY.turnOn, "Turn on"); + assert.equal(ACTIVITY_COPY.notNow, "Not now"); +}); + +test("sharing is off by default", () => { + assert.equal(SHARE_DEFAULT, false); + assert.equal(statusText(SHARE_DEFAULT), "Off"); +}); + +test("it turns on only after consent", () => { + assert.equal(decide(false, "notNow"), false); + assert.equal(decide(false, "turnOn"), true); + assert.equal(statusText(decide(false, "turnOn")), "On"); +}); + +test("turning it off is one click and needs no consent", () => { + assert.equal(decide(true, "turnOff"), false); + assert.equal(decide(true, "notNow"), true); +}); diff --git a/app/ui/src/activity-consent.ts b/app/ui/src/activity-consent.ts new file mode 100644 index 0000000..d5a7ea3 --- /dev/null +++ b/app/ui/src/activity-consent.ts @@ -0,0 +1,32 @@ +// The consent for "Share activity and presence" (docs/architecture.md §22). No DOM: +// `activity-consent.test.mjs` runs it in Node. + +export const ACTIVITY_COPY = { + label: "Share activity and presence", + heading: "Share activity and presence", + paragraphs: [ + "When this is on, claude-sync reads one number from your operating system: how many seconds since the last mouse or keyboard input on this machine. It never reads which keys you press, what you click, your screen, your microphone or your camera.", + "The value stays on this machine for now. It will only ever go to your own machines (the ones signed in to your account), never to your groups, to other people, or to us.", + "Turn it off here at any time; turning it off deletes the value on this machine at once.", + ], + turnOn: "Turn on", + notNow: "Not now", + turnOff: "Turn off", +} as const; + +/** It starts off, and a machine that never answered stays off. */ +export const SHARE_DEFAULT = false; + +export type Answer = "turnOn" | "notNow" | "turnOff"; + +/** Whether sharing is on after the answer. It turns on only after "Turn on". */ +export function decide(current: boolean, answer: Answer): boolean { + if (answer === "turnOn") return true; + if (answer === "turnOff") return false; + return current; +} + +/** The row's status text. */ +export function statusText(share: boolean): string { + return share ? "On" : "Off"; +} diff --git a/app/ui/src/api.ts b/app/ui/src/api.ts index c93f312..258dcac 100644 --- a/app/ui/src/api.ts +++ b/app/ui/src/api.ts @@ -270,6 +270,10 @@ export interface Settings { /** Sign in with the GitHub App instead of the OAuth app (takes effect at next sign-in). */ githubApp: boolean; } +/** Sharing whether you are at the computer. Off until turned on. */ +export interface ActivityView { + share: boolean; +} /** Which group repos the GitHub App can reach. */ export interface Coverage { covered: GroupId[]; @@ -528,6 +532,8 @@ export const api = { editClaudeMdLine: (source: ClashSource, line: string, text: string) => call("edit_claude_md_line", { source, line, text }), copyPreview: (from: GroupId, to: GroupId) => call("copy_preview", { from, to }), copyToGroup: (from: GroupId, to: GroupId, request: CopyRequest) => call("copy_to_group", { from, to, request }), + getActivity: () => call("get_activity"), + setActivity: (share: boolean) => call("set_activity", { share }), getSettings: () => call("get_settings"), setSettings: (settings: Partial) => call("set_settings", { settings }), helperStatus: () => call("helper_status"), diff --git a/app/ui/src/mock.ts b/app/ui/src/mock.ts index d34b921..e03e91c 100644 --- a/app/ui/src/mock.ts +++ b/app/ui/src/mock.ts @@ -72,6 +72,7 @@ let notifications: Notification[] = q.has("noNotifications") let nextNotification = 7; let desktopNotifications = true; let githubApp = false; +let activityShare = false; const helperStatus = () => ({ available: q.has("helper") }); const notificationListeners: ((p: Events["notifications-changed"]) => void)[] = []; function notificationsChanged(): void { @@ -552,6 +553,11 @@ const handlers: Record) => unknown> = { open_url: (a) => { window.open(String(a.url), "_blank", "noopener"); }, + get_activity: () => ({ share: activityShare }), + set_activity: (a) => { + activityShare = Boolean(a.share); + return { share: activityShare }; + }, get_settings: () => ({ deviceName: "desktop", pollSeconds: 60, autostart: true, paused: false, desktopNotifications, githubApp }), set_settings: (a) => { const s = a.settings as { desktopNotifications?: boolean; githubApp?: boolean }; diff --git a/app/ui/src/screens/settings.ts b/app/ui/src/screens/settings.ts index fc6d600..339e80f 100644 --- a/app/ui/src/screens/settings.ts +++ b/app/ui/src/screens/settings.ts @@ -5,6 +5,7 @@ import { coverageLines } from "../copy"; import { api, errorText, type Settings } from "../api"; import { busy, errorBox, h, replace, spinner, toast } from "../dom"; import { onRefresh, store } from "../store"; +import { ACTIVITY_COPY, decide, statusText } from "../activity-consent"; import { forgetHelperState } from "./helper"; import { personalCard } from "./personal"; @@ -77,6 +78,50 @@ function helperCard(): HTMLElement { ); } +/** "Share activity and presence": off by default; the consent dialog comes before it turns on. */ +function activityCard(): HTMLElement { + const status = h("strong", { role: "status" }, statusText(false)); + const toggle = h("button", { type: "button" }, ACTIVITY_COPY.turnOn); + const dialog = h("dialog", { class: "consent", "aria-labelledby": "activity-consent-h" }); + const show = (on: boolean) => { + status.textContent = statusText(on); + toggle.textContent = on ? ACTIVITY_COPY.turnOff : ACTIVITY_COPY.turnOn; + }; + const apply = (on: boolean) => + api.setActivity(on).then( + (v) => show(v.share), + (e) => toast(errorText(e), "error"), + ); + const yes = h("button", { type: "button", class: "primary" }, ACTIVITY_COPY.turnOn); + const no = h("button", { type: "button" }, ACTIVITY_COPY.notNow); + yes.addEventListener("click", () => { + dialog.close(); + void apply(decide(false, "turnOn")); + }); + no.addEventListener("click", () => dialog.close()); + dialog.append( + h("h2", { id: "activity-consent-h" }, ACTIVITY_COPY.heading), + ...ACTIVITY_COPY.paragraphs.map((t) => h("p", null, t)), + h("div", { class: "actions" }, yes, no), + ); + toggle.addEventListener("click", () => { + if (status.textContent === "On") void apply(decide(true, "turnOff")); + else dialog.showModal(); + }); + api.getActivity().then( + (v) => show(v.share), + (e) => toast(errorText(e), "error"), + ); + return h( + "section", + { class: "card", "aria-labelledby": "activity-h" }, + h("h2", { id: "activity-h" }, ACTIVITY_COPY.label), + h("p", { class: "muted small" }, "Whether you are at this computer, from the seconds since the last mouse or keyboard input."), + h("div", { class: "actions" }, status, toggle), + dialog, + ); +} + function githubAppCard(s: Settings, save: (patch: Partial, done?: string) => Promise): HTMLElement { const missing = store.info?.appClientIdMissing ?? false; const toggle = h("input", { id: "s-ghapp", type: "checkbox", checked: s.githubApp && !missing, disabled: missing }); @@ -197,6 +242,7 @@ function form(s: Settings): HTMLElement[] { h("div", { class: "check" }, paused, h("label", { for: "s-paused" }, "Pause syncing")), ), personal.card, + activityCard(), h( "section", { class: "card", "aria-labelledby": "notify-h" }, diff --git a/app/ui/src/style.css b/app/ui/src/style.css index 237f629..20ca774 100644 --- a/app/ui/src/style.css +++ b/app/ui/src/style.css @@ -1135,3 +1135,15 @@ li.clash p { .helper-out.error { border-left-color: var(--danger, #c0392b); } + +dialog.consent { + background: var(--panel); + color: var(--text); + border: 1px solid var(--line); + border-radius: var(--radius); + padding: 1rem 1.1rem; + max-width: min(32rem, calc(100vw - 2rem)); +} +dialog.consent::backdrop { + background: rgba(0, 0, 0, 0.5); +} diff --git a/docs/architecture.md b/docs/architecture.md index 883f7b0..7585b02 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -536,3 +536,14 @@ Opt-in and personal: `sshPeers` `{on, ts}` in the choices file (§16a), merged b - **Service.** `service install` writes `~/.config/systemd/user/claude-sync.service` (`Restart=on-failure`) when systemd runs, otherwise crontab lines `@reboot` and `*/5 * * * *`. - **Adopting an existing setup.** `join` backs up `CLAUDE.md` and strips group text pasted outside the managed block before the first sync delivers it. - **Release.** `release.yml` builds `claude-sync-cli-` for Linux (x86_64, aarch64), macOS (both) and Windows, with `.sha256` files; `update` checks the relay and downloads from the public release. + +## 22. Sharing whether you are at the computer (issue #195, step 1) + +Opt-in and personal: `activity` `{share, ts}` in the choices file (§16a), off by default, merged by its own `ts`. Step 1 is local only: nothing is sent between machines (that is step 2). + +- **Reader** (`core::activity::idle_seconds`): seconds since the last keyboard or mouse input, by direct OS calls. Windows: `GetLastInputInfo` and `GetTickCount` (wrapping subtraction). macOS: IOKit `IOHIDSystem` property `HIDIdleTime` (nanoseconds). Other systems: `None`, written as `unknown`, never as idle. +- **State machine** (`activity::Tracker`, pure, clock and reading passed in): `active` below 120 s idle, `idle` from 120 s, `unknown` with no reading. It asks for a write on a change of state or after 300 s without one. +- **File** `/activity.json`: `{schema: 1, state, idleSeconds, updatedAt}`. Removed when sharing is off. +- **Loop** (`activity::run_loop`): one pass every 30 s in the app (`background::start`) and in the daemon. A pass reads the choice first; off means the file is removed and no OS call is made. Idle cost: one OS call per 30 s, 0 to 12 small local writes per hour, no network. +- **Settings:** the row "Share activity and presence" (`app/ui/src/screens/settings.ts`); the consent copy and the decision logic are in `app/ui/src/activity-consent.ts`. Commands `get_activity` and `set_activity`. +- **Command line:** `claude-sync activity status|enable|disable` (app binary) and `claude-sync-cli activity status|enable|disable`. From cbab4dc6d8860e5d73cf9d01575f5571e79eb368 Mon Sep 17 00:00:00 2001 From: Mehdi <46635765+MehdiMamas@users.noreply.github.com> Date: Thu, 5 Nov 2026 04:22:40 -0600 Subject: [PATCH 4/8] Fix the macOS idle reader: CFNumberGetValue returns a bool --- crates/core/src/activity.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/core/src/activity.rs b/crates/core/src/activity.rs index b2d7b5b..7636fde 100644 --- a/crates/core/src/activity.rs +++ b/crates/core/src/activity.rs @@ -88,8 +88,7 @@ mod os { }; let mut ns: i64 = 0; let ok = !value.is_null() - && CFNumberGetValue(value as CFNumberRef, SINT64, (&mut ns as *mut i64).cast()) - != 0; + && CFNumberGetValue(value as CFNumberRef, SINT64, (&mut ns as *mut i64).cast()); if !value.is_null() { CFRelease(value); } From 4f858f3a47a99e75a16bc3dbb6c243c394c1826f Mon Sep 17 00:00:00 2001 From: Mehdi <46635765+MehdiMamas@users.noreply.github.com> Date: Thu, 5 Nov 2026 04:28:26 -0600 Subject: [PATCH 5/8] Fix the CFNumber type in the macOS reader --- crates/core/src/activity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/activity.rs b/crates/core/src/activity.rs index 7636fde..4bc9be9 100644 --- a/crates/core/src/activity.rs +++ b/crates/core/src/activity.rs @@ -53,7 +53,7 @@ mod os { type Port = u32; const UTF8: u32 = 0x0800_0100; - const SINT64: isize = 4; + const SINT64: u32 = 4; #[link(name = "IOKit", kind = "framework")] extern "C" { From 9fddd4fad59e65d168d3fb437fc57575b2b8d957 Mon Sep 17 00:00:00 2001 From: Mehdi <46635765+MehdiMamas@users.noreply.github.com> Date: Thu, 5 Nov 2026 04:35:24 -0600 Subject: [PATCH 6/8] Satisfy clippy in the macOS reader --- crates/core/src/activity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/activity.rs b/crates/core/src/activity.rs index 4bc9be9..a3c4fff 100644 --- a/crates/core/src/activity.rs +++ b/crates/core/src/activity.rs @@ -96,7 +96,7 @@ mod os { CFRelease(key.cast()); } IOObjectRelease(service); - (ok && ns >= 0).then(|| ns as u64 / 1_000_000_000) + (ok && ns >= 0).then_some(ns as u64 / 1_000_000_000) } } } From fe213a6dd4813ff6abdbbd630e7958f3e6a3d1ce Mon Sep 17 00:00:00 2001 From: Mehdi <46635765+MehdiMamas@users.noreply.github.com> Date: Thu, 5 Nov 2026 04:42:01 -0600 Subject: [PATCH 7/8] Add the UI check config (fake backend on port 1420) Before: the UI check could not start the window. Now: it starts the Vite dev server with the fake backend and opens Settings and Groups. --- .ui-check.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .ui-check.json diff --git a/.ui-check.json b/.ui-check.json new file mode 100644 index 0000000..56cc140 --- /dev/null +++ b/.ui-check.json @@ -0,0 +1,6 @@ +{ + "start": "pnpm -C app/ui install --frozen-lockfile && pnpm -C app/ui dev", + "port": 1420, + "routes": ["/#/settings", "/#/groups"], + "startTimeoutSeconds": 180 +} From eb60b5f9a7c07f721c6f07b5fa3987de2ea3edfc Mon Sep 17 00:00:00 2001 From: Mehdi <46635765+MehdiMamas@users.noreply.github.com> Date: Thu, 5 Nov 2026 04:45:35 -0600 Subject: [PATCH 8/8] Fetch pnpm for the UI check when it is not installed Before: the UI check needed pnpm on the machine. Now: it runs pnpm 9 through npx. --- .ui-check.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ui-check.json b/.ui-check.json index 56cc140..527c574 100644 --- a/.ui-check.json +++ b/.ui-check.json @@ -1,5 +1,5 @@ { - "start": "pnpm -C app/ui install --frozen-lockfile && pnpm -C app/ui dev", + "start": "npx --yes pnpm@9 -C app/ui install --frozen-lockfile && npx --yes pnpm@9 -C app/ui dev", "port": 1420, "routes": ["/#/settings", "/#/groups"], "startTimeoutSeconds": 180