Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .ui-check.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"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
}
4 changes: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <owner/repo>`, `leave`, `sync`, `status`, `personal status|enable|disable`, `ssh status|enable|disable|alias <name>`, `review list|accept|undo <id>`, `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 <owner/repo>`, `leave`, `sync`, `status`, `personal status|enable|disable`, `ssh status|enable|disable|alias <name>`, `activity status|enable|disable`, `review list|accept|undo <id>`, `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 `<state>/sync.lock` (`core::lock`), so they never run at once.
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions app/src-tauri/src/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Arc<Ctx>>().paths.clone(),
));
start_watcher(app);
}

Expand Down
42 changes: 39 additions & 3 deletions app/src-tauri/src/cli.rs
Original file line number Diff line number Diff line change
@@ -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 <name>`. Handled before Tauri starts, like
//! `claude-sync personal enable|disable|status` and `claude-sync ssh enable|disable|status|alias <name>` 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;
Expand All @@ -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 <name> [--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 <name> [--json]\n claude-sync activity enable|disable|status [--json]";

#[derive(Debug, PartialEq, Eq)]
pub enum Cmd {
Expand All @@ -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)]
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -135,6 +146,26 @@ async fn execute(paths: &Paths, cmd: Cmd, json: bool) -> Result<String, String>
}
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 {
Expand Down Expand Up @@ -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());
Expand Down
26 changes: 26 additions & 0 deletions app/src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ActivityView> {
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<ActivityView> {
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<claude_sync_core::github::Coverage> {
Expand Down
2 changes: 2 additions & 0 deletions app/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions app/ui/src/activity-consent.test.mjs
Original file line number Diff line number Diff line change
@@ -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);
});
32 changes: 32 additions & 0 deletions app/ui/src/activity-consent.ts
Original file line number Diff line number Diff line change
@@ -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";
}
6 changes: 6 additions & 0 deletions app/ui/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -528,6 +532,8 @@ export const api = {
editClaudeMdLine: (source: ClashSource, line: string, text: string) => call<void>("edit_claude_md_line", { source, line, text }),
copyPreview: (from: GroupId, to: GroupId) => call<CopyPreview>("copy_preview", { from, to }),
copyToGroup: (from: GroupId, to: GroupId, request: CopyRequest) => call<Copied>("copy_to_group", { from, to, request }),
getActivity: () => call<ActivityView>("get_activity"),
setActivity: (share: boolean) => call<ActivityView>("set_activity", { share }),
getSettings: () => call<Settings>("get_settings"),
setSettings: (settings: Partial<Settings>) => call<Settings>("set_settings", { settings }),
helperStatus: () => call<HelperStatus>("helper_status"),
Expand Down
6 changes: 6 additions & 0 deletions app/ui/src/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -552,6 +553,11 @@ const handlers: Record<string, (a: Record<string, unknown>) => 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 };
Expand Down
46 changes: 46 additions & 0 deletions app/ui/src/screens/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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<Settings>, done?: string) => Promise<void>): HTMLElement {
const missing = store.info?.appClientIdMissing ?? false;
const toggle = h("input", { id: "s-ghapp", type: "checkbox", checked: s.githubApp && !missing, disabled: missing });
Expand Down Expand Up @@ -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" },
Expand Down
12 changes: 12 additions & 0 deletions app/ui/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading
Loading