mirror of
https://github.com/block/buzz.git
synced 2026-12-01 13:42:45 +00:00
feat(desktop): add channel project features and project canvas
Move projects onto the channel-first stack: a channel can opt into project features and surface them as tabs alongside chat, instead of projects living as a separate top-level surface. Desktop: - Channel project features are opt-in per channel, with a feature bar, settings pane, and tabs for the canvas, resources, repos, reviews, and meetings; project home redirects to its channel - Sidebar nests project channels under a project disclosure group, adds move destinations, and keeps section storage in sync with moves - Extract the join-channel banner and the channel pane main column, and pull sidebar scroll lock and unread DM previews into their own modules to stay under the file-size ratchet - Survive unmounted editor views and listener teardown races via mountedEditorView and safeUnlisten Project Canvas: - Sandboxed local canvas packages served over a Tauri custom protocol, with manifest validation, path security, and snapshot storage that supports pending/committed widget updates and revision pruning - React canvas host and surface plus a shared protocol module - Bundle a project-canvas-template resource with demo dashboards, widgets, and styles CLI and agent surface: - Add `buzz canvas notify` to tell the local desktop that a widget's presentation or data changed; it runs locally with no relay connection - Update the ACP base prompt and nest skill docs for canvas authoring Also promotes Projects out of preview-features. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: Matt Toohey <contact@matttoohey.com>
This commit is contained in:
@@ -1580,6 +1580,9 @@ pub async fn dispatch_canvas(cmd: crate::CanvasCmd, client: &BuzzClient) -> Resu
|
||||
match cmd {
|
||||
CanvasCmd::Get { channel } => cmd_get_canvas(client, &channel).await,
|
||||
CanvasCmd::Set { channel, content } => cmd_set_canvas(client, &channel, &content).await,
|
||||
CanvasCmd::Notify { .. } => {
|
||||
unreachable!("local Canvas notifications are handled before relay setup")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ pub mod notes;
|
||||
pub mod pack;
|
||||
pub mod patches;
|
||||
pub mod pr;
|
||||
pub mod project_canvas;
|
||||
pub mod project_channel;
|
||||
pub mod projects;
|
||||
pub mod reactions;
|
||||
|
||||
338
crates/buzz-cli/src/commands/project_canvas.rs
Normal file
338
crates/buzz-cli/src/commands/project_canvas.rs
Normal file
@@ -0,0 +1,338 @@
|
||||
use std::{
|
||||
fs,
|
||||
io::{Read, Write},
|
||||
path::{Path, PathBuf},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{error::CliError, CanvasChange};
|
||||
|
||||
const INDEX_FORMAT: &str = "buzz-project-canvas-index";
|
||||
const INDEX_VERSION: u32 = 1;
|
||||
const IPC_FORMAT: &str = "buzz-project-canvas-update";
|
||||
const IPC_VERSION: u32 = 1;
|
||||
const MAX_INDEX_BYTES: u64 = 1024 * 1024;
|
||||
const MAX_INDEX_ENTRIES: usize = 4_096;
|
||||
const MAX_RESPONSE_BYTES: u64 = 16 * 1024;
|
||||
const SOCKET_FILE: &str = "agent-updates.sock";
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
struct CanvasIndex {
|
||||
format: String,
|
||||
version: u32,
|
||||
canvases: Vec<CanvasIndexEntry>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
struct CanvasIndexEntry {
|
||||
community_id: String,
|
||||
project_id: String,
|
||||
source_path: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct CanvasUpdateRequest<'a> {
|
||||
format: &'static str,
|
||||
version: u32,
|
||||
notification_id: String,
|
||||
community_id: &'a str,
|
||||
project_id: &'a str,
|
||||
widget_id: &'a str,
|
||||
change: &'a CanvasChange,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct CanvasUpdateResponse {
|
||||
accepted: bool,
|
||||
message: String,
|
||||
#[serde(flatten)]
|
||||
output: serde_json::Map<String, serde_json::Value>,
|
||||
}
|
||||
|
||||
struct ResolvedCanvas {
|
||||
canvas_root: PathBuf,
|
||||
community_id: String,
|
||||
project_id: String,
|
||||
source_path: PathBuf,
|
||||
}
|
||||
|
||||
pub fn cmd_notify(source: &Path, widget: &str, change: &CanvasChange) -> Result<(), CliError> {
|
||||
validate_widget_id(widget)?;
|
||||
let resolved = resolve_canvas(source)?;
|
||||
notify_desktop(&resolved, widget, change)
|
||||
}
|
||||
|
||||
fn validate_widget_id(widget: &str) -> Result<(), CliError> {
|
||||
if widget.is_empty()
|
||||
|| widget.len() > 128
|
||||
|| !widget
|
||||
.bytes()
|
||||
.all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_' | b'.'))
|
||||
{
|
||||
return Err(CliError::Usage(
|
||||
"--widget must be 1 to 128 ASCII letters, numbers, '.', '-', or '_'".into(),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn resolve_canvas(source: &Path) -> Result<ResolvedCanvas, CliError> {
|
||||
let source_path = source
|
||||
.canonicalize()
|
||||
.map_err(|error| CliError::Usage(format!("resolve Canvas source: {error}")))?;
|
||||
if !source_path.is_dir() {
|
||||
return Err(CliError::Usage(
|
||||
"--source must identify a Canvas package directory".into(),
|
||||
));
|
||||
}
|
||||
let canvas_root = source_path
|
||||
.ancestors()
|
||||
.find(|candidate| {
|
||||
candidate.file_name().and_then(|name| name.to_str()) == Some("CANVASES")
|
||||
&& candidate.join("index.json").is_file()
|
||||
})
|
||||
.map(Path::to_path_buf)
|
||||
.ok_or_else(|| {
|
||||
CliError::Usage(
|
||||
"--source is not listed below a Buzz CANVASES directory with index.json".into(),
|
||||
)
|
||||
})?;
|
||||
let index_path = canvas_root.join("index.json");
|
||||
let metadata = fs::metadata(&index_path)
|
||||
.map_err(|error| CliError::Usage(format!("inspect Canvas index: {error}")))?;
|
||||
if metadata.len() > MAX_INDEX_BYTES {
|
||||
return Err(CliError::Usage("Canvas index exceeds 1 MiB".into()));
|
||||
}
|
||||
let mut raw = Vec::new();
|
||||
fs::File::open(&index_path)
|
||||
.and_then(|file| {
|
||||
file.take(MAX_INDEX_BYTES + 1).read_to_end(&mut raw)?;
|
||||
Ok(())
|
||||
})
|
||||
.map_err(|error| CliError::Usage(format!("read Canvas index: {error}")))?;
|
||||
if raw.len() as u64 > MAX_INDEX_BYTES {
|
||||
return Err(CliError::Usage("Canvas index exceeds 1 MiB".into()));
|
||||
}
|
||||
let index: CanvasIndex = serde_json::from_slice(&raw)
|
||||
.map_err(|error| CliError::Usage(format!("invalid Canvas index: {error}")))?;
|
||||
if index.format != INDEX_FORMAT || index.version != INDEX_VERSION {
|
||||
return Err(CliError::Usage(
|
||||
"unsupported project Canvas index format".into(),
|
||||
));
|
||||
}
|
||||
if index.canvases.len() > MAX_INDEX_ENTRIES {
|
||||
return Err(CliError::Usage("Canvas index exceeds 4096 entries".into()));
|
||||
}
|
||||
|
||||
let mut matched = None;
|
||||
for entry in index.canvases {
|
||||
let Ok(indexed_source) = PathBuf::from(&entry.source_path).canonicalize() else {
|
||||
continue;
|
||||
};
|
||||
if indexed_source == source_path {
|
||||
if matched.is_some() {
|
||||
return Err(CliError::Usage(
|
||||
"Canvas index contains duplicate entries for --source".into(),
|
||||
));
|
||||
}
|
||||
matched = Some((entry.community_id, entry.project_id));
|
||||
}
|
||||
}
|
||||
let (community_id, project_id) = matched.ok_or_else(|| {
|
||||
CliError::NotFound("Canvas source is not present in CANVASES/index.json".into())
|
||||
})?;
|
||||
Ok(ResolvedCanvas {
|
||||
canvas_root,
|
||||
community_id,
|
||||
project_id,
|
||||
source_path,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn notify_desktop(
|
||||
resolved: &ResolvedCanvas,
|
||||
widget: &str,
|
||||
change: &CanvasChange,
|
||||
) -> Result<(), CliError> {
|
||||
use std::os::unix::net::UnixStream;
|
||||
|
||||
let socket = resolved.canvas_root.join(".runtime").join(SOCKET_FILE);
|
||||
let mut stream = UnixStream::connect(&socket).map_err(|error| {
|
||||
CliError::Other(format!(
|
||||
"connect to Buzz Desktop Canvas update socket {}: {error}; make sure Buzz Desktop is running",
|
||||
socket.display()
|
||||
))
|
||||
})?;
|
||||
let timeout = Some(Duration::from_secs(5));
|
||||
stream
|
||||
.set_read_timeout(timeout)
|
||||
.map_err(|error| CliError::Other(format!("configure Canvas update response: {error}")))?;
|
||||
stream
|
||||
.set_write_timeout(timeout)
|
||||
.map_err(|error| CliError::Other(format!("configure Canvas update request: {error}")))?;
|
||||
|
||||
let request = CanvasUpdateRequest {
|
||||
format: IPC_FORMAT,
|
||||
version: IPC_VERSION,
|
||||
notification_id: uuid::Uuid::new_v4().simple().to_string(),
|
||||
community_id: &resolved.community_id,
|
||||
project_id: &resolved.project_id,
|
||||
widget_id: widget,
|
||||
change,
|
||||
};
|
||||
serde_json::to_writer(&mut stream, &request)
|
||||
.map_err(|error| CliError::Other(format!("encode Canvas update request: {error}")))?;
|
||||
stream
|
||||
.write_all(b"\n")
|
||||
.and_then(|()| stream.flush())
|
||||
.map_err(|error| CliError::Other(format!("send Canvas update request: {error}")))?;
|
||||
|
||||
let mut raw = Vec::new();
|
||||
stream
|
||||
.take(MAX_RESPONSE_BYTES + 1)
|
||||
.read_to_end(&mut raw)
|
||||
.map_err(|error| CliError::Other(format!("read Canvas update response: {error}")))?;
|
||||
if raw.len() as u64 > MAX_RESPONSE_BYTES {
|
||||
return Err(CliError::Other(
|
||||
"Buzz Desktop Canvas update response exceeds 16 KiB".into(),
|
||||
));
|
||||
}
|
||||
let response: CanvasUpdateResponse = serde_json::from_slice(&raw)
|
||||
.map_err(|error| CliError::Other(format!("invalid Canvas update response: {error}")))?;
|
||||
if !response.accepted {
|
||||
return Err(CliError::Usage(response.message));
|
||||
}
|
||||
let mut output = response.output;
|
||||
output.insert("accepted".into(), serde_json::Value::Bool(true));
|
||||
output.insert("message".into(), response.message.into());
|
||||
output.insert(
|
||||
"sourcePath".into(),
|
||||
resolved.source_path.to_string_lossy().into_owned().into(),
|
||||
);
|
||||
println!("{}", serde_json::Value::Object(output));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
fn notify_desktop(
|
||||
_resolved: &ResolvedCanvas,
|
||||
_widget: &str,
|
||||
_change: &CanvasChange,
|
||||
) -> Result<(), CliError> {
|
||||
Err(CliError::Other(
|
||||
"sandboxed project Canvas updates are currently supported on macOS only".into(),
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
const OWNER: &str = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
|
||||
|
||||
fn indexed_canvas(temp: &tempfile::TempDir) -> PathBuf {
|
||||
let root = temp.path().join("CANVASES");
|
||||
let source = root.join("community").join(OWNER).join("project");
|
||||
fs::create_dir_all(&source).unwrap();
|
||||
fs::write(
|
||||
root.join("index.json"),
|
||||
serde_json::json!({
|
||||
"format": INDEX_FORMAT,
|
||||
"version": INDEX_VERSION,
|
||||
"canvases": [{
|
||||
"communityId": "community-id",
|
||||
"projectId": format!("30621:{OWNER}:project"),
|
||||
"sourcePath": source,
|
||||
}],
|
||||
})
|
||||
.to_string(),
|
||||
)
|
||||
.unwrap();
|
||||
source
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolves_binding_from_the_index_for_an_exact_source_path() {
|
||||
let temp = tempfile::TempDir::new().unwrap();
|
||||
let source = indexed_canvas(&temp);
|
||||
let resolved = resolve_canvas(&source).unwrap();
|
||||
assert_eq!(resolved.community_id, "community-id");
|
||||
assert_eq!(resolved.project_id, format!("30621:{OWNER}:project"));
|
||||
assert_eq!(
|
||||
resolved.canvas_root,
|
||||
temp.path().join("CANVASES").canonicalize().unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_unindexed_and_invalid_widget_inputs() {
|
||||
let temp = tempfile::TempDir::new().unwrap();
|
||||
let source = indexed_canvas(&temp);
|
||||
let other = temp.path().join("CANVASES").join("other");
|
||||
fs::create_dir(&other).unwrap();
|
||||
assert!(matches!(resolve_canvas(&other), Err(CliError::NotFound(_))));
|
||||
assert!(matches!(
|
||||
validate_widget_id("bad/widget"),
|
||||
Err(CliError::Usage(_))
|
||||
));
|
||||
assert!(resolve_canvas(&source.join("missing")).is_err());
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn sends_a_bounded_local_update_request_and_accepts_the_desktop_response() {
|
||||
use std::os::unix::net::UnixListener;
|
||||
use std::thread;
|
||||
|
||||
let temp = tempfile::Builder::new()
|
||||
.prefix("buzz-canvas")
|
||||
.tempdir_in("/tmp")
|
||||
.unwrap();
|
||||
let source = indexed_canvas(&temp);
|
||||
let runtime = temp.path().join("CANVASES").join(".runtime");
|
||||
fs::create_dir(&runtime).unwrap();
|
||||
let listener = UnixListener::bind(runtime.join(SOCKET_FILE)).unwrap();
|
||||
let server = thread::spawn(move || {
|
||||
let (mut stream, _) = listener.accept().unwrap();
|
||||
let mut raw = Vec::new();
|
||||
loop {
|
||||
let mut byte = [0_u8; 1];
|
||||
stream.read_exact(&mut byte).unwrap();
|
||||
raw.push(byte[0]);
|
||||
if byte[0] == b'\n' {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let request: serde_json::Value = serde_json::from_slice(&raw).unwrap();
|
||||
assert_eq!(request["format"], IPC_FORMAT);
|
||||
assert_eq!(request["version"], IPC_VERSION);
|
||||
assert_eq!(request["communityId"], "community-id");
|
||||
assert_eq!(request["widgetId"], "chore-board");
|
||||
assert_eq!(request["change"], "data");
|
||||
stream
|
||||
.write_all(
|
||||
serde_json::json!({
|
||||
"accepted": true,
|
||||
"change": "data",
|
||||
"message": "Canvas update delivered",
|
||||
"notificationId": request["notificationId"],
|
||||
"projectId": request["projectId"],
|
||||
"revision": "a".repeat(64),
|
||||
"widgetId": request["widgetId"],
|
||||
})
|
||||
.to_string()
|
||||
.as_bytes(),
|
||||
)
|
||||
.unwrap();
|
||||
});
|
||||
|
||||
cmd_notify(&source, "chore-board", &CanvasChange::Data).unwrap();
|
||||
server.join().unwrap();
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ Configuration (flags override env vars):
|
||||
BUZZ_PRIVATE_KEY Nostr private key (hex or nsec) [required]
|
||||
BUZZ_AUTH_TAG NIP-OA auth tag JSON [optional]
|
||||
|
||||
The 'pack' subcommand runs locally and does not require a relay connection.
|
||||
The 'pack' and 'canvas notify' subcommands run locally and do not require a relay connection.
|
||||
|
||||
Exit codes: 0=ok 1=bad input 2=relay/network error 3=auth error 4=other 5=write conflict
|
||||
Errors are JSON on stderr: {\"error\": \"<category>\", \"message\": \"<detail>\"}"
|
||||
@@ -731,6 +731,25 @@ pub enum CanvasCmd {
|
||||
#[arg(long)]
|
||||
content: String,
|
||||
},
|
||||
/// Notify the local Buzz desktop that a project widget changed
|
||||
Notify {
|
||||
/// Project Canvas source directory (use '.' from inside the package)
|
||||
#[arg(long)]
|
||||
source: std::path::PathBuf,
|
||||
/// Stable widget id from the active dashboard data
|
||||
#[arg(long)]
|
||||
widget: String,
|
||||
/// Whether presentation code or widget data changed
|
||||
#[arg(long, value_enum)]
|
||||
change: CanvasChange,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize, clap::ValueEnum)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum CanvasChange {
|
||||
Presentation,
|
||||
Data,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
@@ -2028,13 +2047,22 @@ fn normalize_auth_tag_input(input: &str) -> String {
|
||||
async fn run(cli: Cli) -> Result<(), CliError> {
|
||||
let relay_url = client::normalize_relay_url(&cli.relay);
|
||||
|
||||
// Pack commands are local-only — no relay connection needed.
|
||||
// Pack and project Canvas notification commands are local-only — no relay
|
||||
// connection or signing identity is involved.
|
||||
if let Cmd::Pack(ref sub) = cli.command {
|
||||
return match sub {
|
||||
PackCmd::Validate { path } => commands::pack::cmd_validate(path),
|
||||
PackCmd::Inspect { path } => commands::pack::cmd_inspect(path),
|
||||
};
|
||||
}
|
||||
if let Cmd::Canvas(CanvasCmd::Notify {
|
||||
ref source,
|
||||
ref widget,
|
||||
ref change,
|
||||
}) = cli.command
|
||||
{
|
||||
return commands::project_canvas::cmd_notify(source, widget, change);
|
||||
}
|
||||
|
||||
// Auth: private key is required for all relay operations.
|
||||
// The keypair IS the identity — no tokens, no other auth.
|
||||
@@ -2330,7 +2358,7 @@ mod tests {
|
||||
"update"
|
||||
]
|
||||
);
|
||||
assert_eq!(names(&cmd, "canvas"), vec!["get", "set"]);
|
||||
assert_eq!(names(&cmd, "canvas"), vec!["get", "notify", "set"]);
|
||||
assert_eq!(names(&cmd, "reactions"), vec!["add", "get", "remove"]);
|
||||
assert_eq!(
|
||||
names(&cmd, "emoji"),
|
||||
@@ -2433,7 +2461,7 @@ mod tests {
|
||||
fn subcommand_counts_are_stable() {
|
||||
let expected: Vec<(&str, usize)> = vec![
|
||||
("agents", 5),
|
||||
("canvas", 2),
|
||||
("canvas", 3),
|
||||
("channels", 16),
|
||||
("dms", 4),
|
||||
("emoji", 5),
|
||||
|
||||
Reference in New Issue
Block a user