Skip to content

Commit 848288b

Browse files
kalvinnchaupeonclaude
authored
feat(desktop): move to the xyz.block.buzz.desktop identifier (#1656)
Signed-off-by: Kalvin Chau <[email protected]> Co-authored-by: peon <9ac6794b000690b7e814eb1805ad32405d0bec7d52838de3a86cf967565dacc0@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 3db78b2 commit 848288b

19 files changed

Lines changed: 883 additions & 45 deletions

‎browser-host/agent-library.mjs‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { avatarSource } from "../src/shared/avatar-source.ts";
33
// input remains supported for compatibility tests/import readers; never discover
44
// Classic stores or call loaders that migrate keys or write configuration.
55
import { constants } from "node:fs";
6-
import { open } from "node:fs/promises";
6+
import { lstat, open } from "node:fs/promises";
77
import { homedir } from "node:os";
8-
import { isAbsolute, join } from "node:path";
8+
import { dirname, isAbsolute, join } from "node:path";
99

1010
const MAX_BYTES = 8 * 1024 * 1024;
1111
const MAX_ROWS = 2000;
@@ -130,19 +130,28 @@ export function installedBuzzDataDir(
130130
home = homedir(),
131131
) {
132132
if (platform === "darwin")
133-
return join(home, "Library/Application Support/dev.local.buzz.foundation");
133+
return join(home, "Library/Application Support/xyz.block.buzz.desktop");
134134
if (platform === "linux") {
135135
const xdg = env.XDG_DATA_HOME;
136136
const base = xdg && isAbsolute(xdg) ? xdg : join(home, ".local/share");
137-
return join(base, "dev.local.buzz.foundation");
137+
return join(base, "xyz.block.buzz.desktop");
138138
}
139139
return undefined;
140140
}
141+
const exists = (path) =>
142+
lstat(path).then(
143+
() => true,
144+
() => false,
145+
);
141146
export async function readAgentLibrary(path) {
142147
const current = path === undefined;
143-
path ??= (() => {
148+
path ??= await (async () => {
144149
const dir = installedBuzzDataDir();
145-
return dir ? join(dir, "agents/identities.json") : undefined;
150+
if (!dir) return undefined;
151+
// Until the updated desktop moves its pre-1.0 folder, read that one.
152+
const legacy = join(dirname(dir), "dev.local.buzz.foundation");
153+
const base = !(await exists(dir)) && (await exists(legacy)) ? legacy : dir;
154+
return join(base, "agents/identities.json");
146155
})();
147156
if (!path) throw failure();
148157
let file;

‎browser-host/agent-library.test.mjs‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ it.each(identityCases)(
3030

3131
it("locates the installed Buzz data directory per platform and refuses to guess elsewhere", () => {
3232
expect(installedBuzzDataDir("darwin", {}, "/Users/t")).toBe(
33-
"/Users/t/Library/Application Support/dev.local.buzz.foundation",
33+
"/Users/t/Library/Application Support/xyz.block.buzz.desktop",
3434
);
3535
expect(installedBuzzDataDir("linux", {}, "/home/t")).toBe(
36-
"/home/t/.local/share/dev.local.buzz.foundation",
36+
"/home/t/.local/share/xyz.block.buzz.desktop",
3737
);
3838
expect(
3939
installedBuzzDataDir("linux", { XDG_DATA_HOME: "/data" }, "/home/t"),
40-
).toBe("/data/dev.local.buzz.foundation");
40+
).toBe("/data/xyz.block.buzz.desktop");
4141
// Tauri's dirs crate ignores a relative XDG_DATA_HOME; so must this reader,
4242
// or it would look where the installed app never writes.
4343
for (const XDG_DATA_HOME of ["relative", "./data", ""])
4444
expect(
4545
installedBuzzDataDir("linux", { XDG_DATA_HOME }, "/home/t"),
4646
JSON.stringify(XDG_DATA_HOME),
47-
).toBe("/home/t/.local/share/dev.local.buzz.foundation");
47+
).toBe("/home/t/.local/share/xyz.block.buzz.desktop");
4848
expect(installedBuzzDataDir("win32", {}, "/home/t")).toBeUndefined();
4949
expect(installedBuzzDataDir("freebsd", {}, "/home/t")).toBeUndefined();
5050
});
@@ -328,14 +328,14 @@ it.skipIf(!["darwin", "linux"].includes(process.platform))(
328328
: root;
329329
const current = join(
330330
appData,
331-
"dev.local.buzz.foundation/agents/identities.json",
331+
"xyz.block.buzz.desktop/agents/identities.json",
332332
);
333333
const legacy = join(
334334
appData,
335335
"xyz.block.buzz.app/agents/managed-agents.json",
336336
);
337337
try {
338-
await mkdir(join(appData, "dev.local.buzz.foundation/agents"), {
338+
await mkdir(join(appData, "xyz.block.buzz.desktop/agents"), {
339339
recursive: true,
340340
});
341341
await mkdir(join(appData, "xyz.block.buzz.app/agents"), {
@@ -365,6 +365,19 @@ it.skipIf(!["darwin", "linux"].includes(process.platform))(
365365
identities: [],
366366
});
367367
expect(await readFile(legacy, "utf8")).toBe(JSON.stringify(rows));
368+
// Until the updated desktop moves it, the pre-1.0 folder is read.
369+
const foundation = join(appData, "dev.local.buzz.foundation/agents");
370+
await mkdir(foundation, { recursive: true });
371+
await writeFile(
372+
join(foundation, "identities.json"),
373+
JSON.stringify([{ pubkey: key, name: "Nova" }]),
374+
);
375+
expect((await readAgentLibrary()).identities).toEqual([]);
376+
await rm(join(appData, "xyz.block.buzz.desktop"), { recursive: true });
377+
expect(await readAgentLibrary()).toEqual({
378+
definitions: [],
379+
identities: [{ pubkey: key, name: "Nova" }],
380+
});
368381
} finally {
369382
vi.unstubAllEnvs();
370383
await rm(root, { recursive: true, force: true });

‎crates/plugin-manager/src/lib.rs‎

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,32 @@ pub enum InstallationResult {
597597
can_reset: bool,
598598
},
599599
}
600+
/// The desktop app data folder a CLI targets by default: a debug CLI the
601+
/// development app's, a release CLI the installed app's. Each refuses while the
602+
/// app has yet to fill that folder from the installed app's older one: creating
603+
/// it would stop the development copy, or leave both and stop the release move.
604+
fn default_home() -> Result<PathBuf> {
605+
let data =
606+
dirs::data_dir().ok_or("Cannot determine application data directory; set BUZZODZ_HOME")?;
607+
let (home, older, open): (_, &[_], _) = if cfg!(debug_assertions) {
608+
(
609+
"xyz.block.buzz.desktop.dev",
610+
&["xyz.block.buzz.desktop", "dev.local.buzz.foundation"],
611+
"Development Buzz has not copied the installed app's storage yet. Run `just desktop` once",
612+
)
613+
} else {
614+
(
615+
"xyz.block.buzz.desktop",
616+
&["dev.local.buzz.foundation"],
617+
"Buzz has not moved its storage to its 1.0 folder yet. Open Buzz once",
618+
)
619+
};
620+
let home = data.join(home);
621+
if !home.exists() && older.iter().any(|old| data.join(old).exists()) {
622+
return Err(format!("{open}, then try again, or pass --home."));
623+
}
624+
Ok(home)
625+
}
600626
#[derive(Clone)]
601627
pub struct Manager {
602628
root: PathBuf,
@@ -611,10 +637,10 @@ impl Manager {
611637

612638
pub fn open(home: Option<PathBuf>, profile: &str, safe_mode: bool) -> Result<Self> {
613639
valid_id(profile)?;
614-
let home = home
615-
.or_else(|| std::env::var_os("BUZZODZ_HOME").map(PathBuf::from))
616-
.or_else(|| dirs::data_dir().map(|p| p.join("dev.local.buzz.foundation")))
617-
.ok_or("Cannot determine application data directory; set BUZZODZ_HOME")?;
640+
let home = match home.or_else(|| std::env::var_os("BUZZODZ_HOME").map(PathBuf::from)) {
641+
Some(home) => home,
642+
None => default_home()?,
643+
};
618644
if !home.is_absolute() {
619645
return Err("Plugin home must be an absolute path".into());
620646
}
@@ -624,9 +650,10 @@ impl Manager {
624650
safe_mode,
625651
})
626652
}
627-
pub fn from_env() -> Result<Self> {
653+
/// Opens the environment's plugin home, else `home`: the desktop passes its own app data folder.
654+
pub fn from_env(home: Option<PathBuf>) -> Result<Self> {
628655
Self::open(
629-
None,
656+
std::env::var_os("BUZZODZ_HOME").map(PathBuf::from).or(home),
630657
&std::env::var("BUZZODZ_PROFILE").unwrap_or_else(|_| "default".into()),
631658
std::env::var("BUZZODZ_SAFE_MODE").as_deref() == Ok("1"),
632659
)

‎docs/identity.md‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ this app's data, local data, WebView storage, caches and plugin storage. It cann
131131
reach the clipboard, exported keys or relay data, and the dialog says so. Sign out
132132
is unavailable with the development broker (`BUZZ_DEV_VIEWER`). Development
133133
builds can sign out but not wipe: they have their own human key, but share agent
134-
keys and plugin storage with the installed app, so the native command refuses
134+
keys with the installed app, so the native command refuses
135135
wipe. The dialog asks the native side (`sign_out_wipe_refusal`) whether wipe is
136136
available and, when it isn't, disables wipe up front with the reason; this holds
137137
for any Rust debug build, including a debug bundle with a production frontend. A development-build sign-out signs out every
@@ -147,7 +147,32 @@ before it looks for a pending sign-out:
147147
by every copy using that key whatever its identifier; and
148148
- the **all-Buzz lock** (`.dev.local.buzz.foundation.instance.lock`), named for
149149
the storage all builds share (the default plugin folder and the agent key
150-
service), not for the app identifier.
150+
service), not for the app identifier. It keeps the identifier Buzz used before
151+
1.0, so those builds and later ones exclude each other.
152+
153+
Before 1.0, Buzz's identifier was `dev.local.buzz.foundation`. Before taking these
154+
locks, a launch as `xyz.block.buzz.desktop` renames what the old identifier names:
155+
app data (with plugin storage), config, local data, caches, macOS WebKit storage,
156+
their sign-out trash and a pending sign-out marker, so the update keeps
157+
everything and finishes a sign-out the old build committed. It takes the all-Buzz
158+
lock alone and waits for every agent ownership lock, so it never moves storage
159+
another copy or a stopping agent still uses. If any legacy path sits beside its
160+
new-identifier counterpart, after a rollback for instance, the launch moves
161+
nothing, finishes no pending sign-out, and exits naming every such pair; neither copy
162+
is safely the one to keep, and an erase would miss the legacy one. A failure exits
163+
with a native alert, and the next launch moves what is left. Development launches
164+
(`just desktop`, `just desktop-bundle`) use `xyz.block.buzz.desktop.dev`, so they
165+
keep their own app data and plugin storage and never take or block the installed
166+
app's. The first one copies the installed app's app data (without the release-only
167+
`archive`), config, local data and macOS WebKit storage, each from
168+
`xyz.block.buzz.desktop`, else `dev.local.buzz.foundation`, under the same locks,
169+
so the installed app must be closed once, and takes a pending development
170+
sign-out marker. It refuses while the installed app has a sign-out pending, so it
171+
never copies storage being erased. A linked folder copies what it links to; links
172+
inside are left out, so the copy shares nothing with the installed app's storage,
173+
which stays in place. Copied folders keep who else may read them, but stay
174+
writable by their owner. An interrupted copy finishes at the next launch. Credential service
175+
names don't change; on macOS, Keychain may ask once to allow the renamed app to use each saved item.
151176

152177
A sign-out needs its key lock alone, so every other copy using that key must be
153178
closed. A wipe also needs the all-Buzz lock alone, so every other Buzz must be

‎docs/plugin-architecture.md‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,18 @@ bundled defaults, preserving artifacts for reinstallation.
123123

124124
`--home ABSOLUTE_PATH` and `--profile NAME` precede `plugin`. The desktop and CLI
125125
also read `BUZZODZ_HOME` and `BUZZODZ_PROFILE` (default: `default`). Match these to
126-
target the same instance. Otherwise, profiles live under the OS application-data
127-
directory in `dev.local.buzz.foundation/profiles`.
126+
target the same instance. Otherwise, the desktop keeps profiles in its own
127+
application-data folder (`xyz.block.buzz.desktop/profiles` for the installed app,
128+
`xyz.block.buzz.desktop.dev/profiles` for development launches). A debug CLI
129+
(`just cli`, `pnpm buzzodz`) defaults to the development folder and a release CLI
130+
to the installed app's. A release CLI refuses while only the pre-1.0
131+
`dev.local.buzz.foundation` folder exists; open Buzz once to move it, or pass
132+
`--home`. A debug CLI likewise refuses before the first `just desktop` has copied
133+
the installed app's storage into the development folder.
128134

129135
```sh
130136
BUZZODZ_PROFILE=experiment just desktop
131-
buzzodz --profile experiment plugin list
137+
pnpm buzzodz --profile experiment plugin list
132138
```
133139

134140
`BUZZODZ_SAFE_MODE=1 just desktop` opens the shell without external pages.

‎docs/releases.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ WebView2 download-bootstrapper defaults (network needed if WebView2 is absent).
232232
The job silently installs into a disposable runner directory and verifies the
233233
installed app executable, without launching the app.
234234

235+
The Windows config pins `bundle.publisher` to `local`, the publisher Tauri derived
236+
from the identifier before 1.0, so an update still finds the install folder Tauri
237+
records under `Software\local\Buzz Foundation`. An update keeps existing shortcuts,
238+
so `src-tauri/installer-hooks.nsh` gives the Start menu and desktop shortcuts the
239+
current identifier as their AppUserModelID, which Windows shows notifications under.
240+
235241
Linux reuses old Buzz's Ubuntu 24.04 recipe and guarded Wayland/GStreamer AppImage
236242
repair from `block/buzz` tag `desktop-v0.5.25`. Repacking tools and the type2 runtime
237243
are checksum-pinned. The workflow verifies the app executable in the extracted deb

‎scripts/desktop-build.mjs‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@ const chose = forwarded.some(
2121
);
2222
const defaults = chose ? ["--debug"] : ["--debug", "--bundles", "app"];
2323
// Prepend, as `just desktop` does: Tauri treats everything after a bare positional
24-
// as runner arguments, and a user's own --config must merge after ours to win. With
25-
// no worktree icon there is nothing to overlay, and no --config is
26-
// passed, so the bundle is exactly what `tauri build` would produce on its own.
27-
const overlay = desktopOverlay(root);
28-
if (Object.keys(overlay).length > 0)
29-
forwarded.unshift("--config", JSON.stringify(overlay));
24+
// as runner arguments, and a user's own --config must merge after ours to win. The
25+
// overlay gives the bundle the development identifier and any worktree icon.
26+
forwarded.unshift("--config", JSON.stringify(desktopOverlay(root)));
3027
forwarded.push(...rest);
3128
const result = spawnSync(
3229
"pnpm",

‎scripts/desktop-config.mjs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ export function options(args, names) {
2424
return { values, forwarded, rest: args.slice(index) };
2525
}
2626

27+
// Development launches keep their own app storage, copied once from the
28+
// installed app's, so they never take or block it (see
29+
// `src-tauri/src/sign_out/legacy_identifier.rs`).
30+
const DEV_IDENTIFIER = "xyz.block.buzz.desktop.dev";
31+
2732
export function desktopOverlay(root) {
28-
const config = {};
33+
const config = { identifier: DEV_IDENTIFIER };
2934
const icon = worktreeIcon(root);
3035
if (icon) config.bundle = { icon: [icon] };
3136
return config;

‎src-tauri/installer-hooks.nsh‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; An update keeps existing shortcuts, and with them the AppUserModelID that
2+
; Windows shows notifications under. Give them this build's identifier, which
3+
; changed in 1.0, as a fresh install does.
4+
!macro NSIS_HOOK_POSTINSTALL
5+
${If} ${FileExists} "$SMPROGRAMS\${PRODUCTNAME}.lnk"
6+
!insertmacro SetLnkAppUserModelId "$SMPROGRAMS\${PRODUCTNAME}.lnk"
7+
${EndIf}
8+
${If} ${FileExists} "$DESKTOP\${PRODUCTNAME}.lnk"
9+
!insertmacro SetLnkAppUserModelId "$DESKTOP\${PRODUCTNAME}.lnk"
10+
${EndIf}
11+
!macroend

‎src-tauri/src/lib.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ pub fn run() {
673673
.unwrap_or_else(|message| sign_out::exit_with(&message))
674674
});
675675
let identity = IdentityHost::default();
676+
let identifier = context.config().identifier.clone();
676677
let builder = tauri::Builder::default();
677678
let builder = if !tauri::is_dev() {
678679
// Single instance comes first, as its documentation requires. Its deep-link
@@ -839,7 +840,11 @@ pub fn run() {
839840
.manage(NsecBackupHost::default())
840841
.manage(Notifications::default())
841842
.manage(DeepLinks::default())
842-
.manage(PluginManager(Manager::from_env()))
843+
// Plugin storage lives in this identifier's app data, so development
844+
// builds keep theirs apart from the installed app.
845+
.manage(PluginManager(Manager::from_env(
846+
dirs::data_dir().map(|dir| dir.join(&identifier)),
847+
)))
843848
.invoke_handler({
844849
let application_commands = commands::<tauri::Wry>();
845850
let browser_commands: fn(tauri::ipc::Invoke<tauri::Wry>) -> bool = tauri::generate_handler![

0 commit comments

Comments
 (0)