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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ __pycache__/
src-tauri/gen/
src-tauri/tauri.dev.generated.conf.json
src-tauri/binaries/
plugins/computer-use/bin/
**/.codeg-fs-*.tmp
**/*.cstemp

Expand Down
27 changes: 22 additions & 5 deletions crates/agents/src/parsers/acp_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ struct PendingTurn {
duration_ms: Option<u64>,
model: Option<String>,
agent_message_id: Option<String>,
last_text_message_id: Option<String>,
has_content: bool,
}

Expand Down Expand Up @@ -890,12 +891,20 @@ fn apply_update(
}
let p = open_turn!();
p.last_at_ms = at_ms;
let chunk_message_id = chunk
.message_id
.as_ref()
.map(|id| id.to_string())
.filter(|id| !id.trim().is_empty());
if p.agent_message_id.is_none() {
p.agent_message_id = chunk
.message_id
.as_ref()
.map(|id| id.to_string())
.filter(|id| !id.trim().is_empty());
p.agent_message_id = chunk_message_id.clone();
}
let message_id_changed = matches!(
(&p.last_text_message_id, &chunk_message_id),
(Some(prev), Some(curr)) if prev != curr
);
if chunk_message_id.is_some() {
p.last_text_message_id = chunk_message_id;
}
match &chunk.content {
agent_client_protocol::schema::v1::ContentBlock::Image(image) => {
Expand All @@ -910,6 +919,14 @@ fn apply_update(
}
other => {
let text = content_block_text(other);
if message_id_changed
&& !text.is_empty()
&& let Some(ContentBlock::Text { text: existing }) = p.blocks.last_mut()
&& !existing.is_empty()
&& !existing.ends_with('\n')
{
existing.push('\n');
}
p.push_text(&text, false);
}
}
Expand Down
44 changes: 22 additions & 22 deletions crates/application/src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ domain_commands! {
PluginActionCatalog => "plugin_action_catalog" / "plugin.read",
PluginControlCatalog => "plugin_control_catalog" / "plugin.read",
OfficialProductMcpState => "official_product_mcp_state" / "plugin.read",
CollaborationCall => "collaboration_call" / "application.call",
CollaborationCall => "collaboration_call" / "conversation.write",
PluginMcpStatus => "plugin_mcp_status" / "plugin.read",
PluginMcpEnsureRunning => "plugin_mcp_ensure_running" / "plugin.write",
PluginProductDetail => "plugin_product_detail" / "plugin.read",
Expand Down Expand Up @@ -197,9 +197,9 @@ domain_commands! {
RepoCheckoutBranch => "checkout_repo_branch" / "application.call",
RepoCreateBranch => "create_repo_branch" / "application.call",
RepoDeleteBranch => "delete_repo_branch" / "application.call",
WorkspaceList => "get_workspaces" / "application.call",
WorkspaceListByProject => "get_project_workspaces" / "application.call",
WorkspaceGet => "get_workspace" / "application.call",
WorkspaceList => "get_workspaces" / "conversation.read",
WorkspaceListByProject => "get_project_workspaces" / "conversation.read",
WorkspaceGet => "get_workspace" / "conversation.read",
WorkspaceCount => "get_workspace_count" / "application.call",
WorkspaceRepos => "get_workspace_repos" / "application.call",
WorkspaceGitStatus => "get_workspace_git_status" / "application.call",
Expand Down Expand Up @@ -243,18 +243,18 @@ domain_commands! {
ConversationEventsSince => "conversation_events_since" / "conversation.read",
ConversationEnsureSessionControls => "conversation_ensure_session_controls" / "conversation.write",
ConversationTouch => "conversation_touch" / "conversation.write",
SessionList => "get_sessions" / "application.call",
SessionSummaries => "get_session_summaries" / "application.call",
SessionGet => "get_session" / "application.call",
SessionCreate => "create_session" / "application.call",
SessionCreateProjectRoot => "create_project_root_session" / "application.call",
SessionList => "get_sessions" / "conversation.read",
SessionSummaries => "get_session_summaries" / "conversation.read",
SessionGet => "get_session" / "conversation.read",
SessionCreate => "create_session" / "conversation.write",
SessionCreateProjectRoot => "create_project_root_session" / "conversation.write",
SessionCreateProject => "create_project_session" / "application.call",
SessionEnsureWorkspace => "ensure_project_workspace" / "application.call",
SessionRename => "rename_session" / "application.call",
SessionUpdateStatus => "update_session_status" / "application.call",
SessionMarkViewed => "mark_session_viewed" / "application.call",
SessionSetPinned => "set_session_pinned" / "application.call",
SessionDelete => "delete_session" / "application.call",
SessionEnsureWorkspace => "ensure_project_workspace" / "conversation.write",
SessionRename => "rename_session" / "conversation.write",
SessionUpdateStatus => "update_session_status" / "conversation.write",
SessionMarkViewed => "mark_session_viewed" / "conversation.write",
SessionSetPinned => "set_session_pinned" / "conversation.write",
SessionDelete => "delete_session" / "conversation.write",
FileTree => "get_file_tree" / "application.call",
FileRead => "read_file_content" / "application.call",
FileSave => "save_file_content" / "application.call",
Expand All @@ -276,13 +276,13 @@ domain_commands! {
TerminalClose => "close_terminal" / "application.call",
TerminalAttach => "attach_terminal" / "application.call",
TerminalSnapshot => "terminal_snapshot" / "application.call",
AgentManagementBar => "agent_management_bar" / "application.call",
AgentManagementBar => "agent_management_bar" / "conversation.read",
AgentManagementDetail => "agent_management_detail" / "application.call",
AgentManagementSetEnabled => "agent_management_set_enabled" / "application.call",
AgentManagementRefresh => "agent_management_refresh" / "application.call",
AgentCapabilityCatalog => "agent_capability_catalog" / "application.call",
AgentSkillsList => "list_agent_skills" / "application.call",
UserSystemInfo => "get_user_system_info" / "application.call",
UserSystemInfo => "get_user_system_info" / "conversation.read",
ArtifactList => "artifact_list" / "artifact.read",
ArtifactOpenPreview => "artifact_open_preview" / "artifact.preview",
ArtifactClosePreview => "artifact_close_preview" / "artifact.preview",
Expand Down Expand Up @@ -336,7 +336,7 @@ domain_commands! {
AgentRefreshCapabilityCatalog => "agent_refresh_capability_catalog" / "application.call",
AgentCapabilityCatalogFresh => "agent_capability_catalog_fresh" / "application.call",
AgentListLiveTerminals => "agent_list_live_terminals" / "application.call",
AgentPlanUsage => "agent_plan_usage" / "application.call",
AgentPlanUsage => "agent_plan_usage" / "conversation.read",
FrontendPreferencesGet => "get_frontend_preferences" / "application.call",
FrontendPreferencesUpdate => "update_frontend_preferences" / "application.call",
ProjectWorktreeSettingsGet => "get_project_worktree_settings" / "application.call",
Expand Down Expand Up @@ -486,8 +486,8 @@ domain_commands! {
GetClaudeSettings => "get_claude_settings" / "application.call",
UpdateClaudeSettings => "update_claude_settings" / "application.call",
GetClaudeSettingsPath => "get_claude_settings_path" / "application.call",
ScanLocalSkills => "scan_local_skills" / "application.call",
ReadLocalSkill => "read_local_skill" / "application.call",
ScanLocalSkills => "scan_local_skills" / "conversation.read",
ReadLocalSkill => "read_local_skill" / "conversation.read",
SearchSkillMarket => "search_skill_market" / "application.call",
GetMarketSkillDetail => "get_market_skill_detail" / "application.call",
InstallMarketSkill => "install_market_skill" / "application.call",
Expand All @@ -496,7 +496,7 @@ domain_commands! {
ReadAgentSkill => "read_agent_skill" / "application.call",
SaveAgentSkill => "save_agent_skill" / "application.call",
DeleteAgentSkill => "delete_agent_skill" / "application.call",
McpScanLocal => "mcp_scan_local" / "application.call",
McpScanLocal => "mcp_scan_local" / "conversation.read",
McpListMarketplaces => "mcp_list_marketplaces" / "application.call",
McpSearchMarketplace => "mcp_search_marketplace" / "application.call",
McpGetMarketplaceServerDetail => "mcp_get_marketplace_server_detail" / "application.call",
Expand Down Expand Up @@ -570,7 +570,7 @@ domain_commands! {
StartWorkspaceDevServer => "start_workspace_dev_server" / "application.call",
GetFirstUserMessage => "get_first_user_message" / "application.call",
RespondToApproval => "respond_to_approval" / "application.call",
GetProjectUsageStatistics => "get_project_usage_statistics" / "application.call",
GetProjectUsageStatistics => "get_project_usage_statistics" / "conversation.read",
ClearLocalAppData => "clear_local_app_data" / "application.call",
CheckAppRelease => "check_app_release" / "application.call",
ApplyHostUpgrade => "apply_host_upgrade" / "application.call",
Expand Down
1 change: 1 addition & 0 deletions crates/remote-protocol/src/device_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ impl DevicePermissionPreset {
"conversation.question",
"conversation.cancel",
"conversation.steer",
"plugin.read",
"artifact.read",
"workflow.read",
"automation.read",
Expand Down
11 changes: 10 additions & 1 deletion crates/server/src/domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2001,7 +2001,16 @@ impl ServerApplicationDomains {
}

async fn user_system_info(&self) -> Result<Value, ApplicationError> {
crate::host::catalog::config::user_system_info(self).await
let mut value = crate::host::catalog::config::user_system_info(self).await?;
if let (Some(object), Ok(catalog)) = (
value.as_object_mut(),
self.plugin_control_catalog().await,
) {
if let Some(plugins) = catalog.get("plugins").cloned() {
object.insert("plugins".to_string(), plugins);
}
}
Ok(value)
}

async fn artifact_list(&self, args: Value) -> Result<Value, ApplicationError> {
Expand Down
30 changes: 25 additions & 5 deletions crates/server/src/host/collaboration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,11 @@ impl HostCollaborationHost {
.await
.map_err(host_error)?
{
let avatar = optional_text(input, &["avatar"]);
let avatar = input.get("avatar").and_then(|v| match v {
Value::String(s) if !s.trim().is_empty() => Some(s.trim().to_string()),
Value::Object(_) => Some(v.to_string()),
_ => None,
});
let color = optional_text(input, &["color"]);
if avatar.is_some() || color.is_some() {
sidebar::update_member_profile(
Expand Down Expand Up @@ -947,19 +951,35 @@ impl HostCollaborationHost {
)
.await
.map_err(host_error)?;
let is_supervisor = if let Some(ref mid) = identity_member_id {
collaboration::is_member_supervisor(&self.pool, mid)
let (is_supervisor, avatar, color) = if let Some(ref mid) = identity_member_id {
let sup = collaboration::is_member_supervisor(&self.pool, mid)
.await
.unwrap_or(false)
.unwrap_or(false);
let profile: Option<(Option<String>, Option<String>)> = sqlx::query_as(
"SELECT avatar, color FROM collaboration_members WHERE id = ?",
)
.bind(mid)
.fetch_optional(&self.pool)
.await
.ok()
.flatten();
let (av, col) = profile.unwrap_or((None, None));
(sup, av, col)
} else {
false
(false, None, None)
};
let mut value = serde_json::to_value(&member).map_err(|error| {
CollaborationHostError::new("conversation_control_failed", error.to_string())
})?;
if let Some(object) = value.as_object_mut() {
object.insert("identity_member_id".into(), json!(identity_member_id));
object.insert("is_supervisor".into(), json!(is_supervisor));
if let Some(av) = avatar {
object.insert("avatar".into(), json!(av));
}
if let Some(col) = color {
object.insert("color".into(), json!(col));
}
}
listed.push(value);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/server/src/host/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub const HOST_EVENT_CHANNELS: &[HostEventChannel] = &[
HostEventChannel {
prefix: "workspace-sessions-changed",
durability: EventDurability::Invalidation,
required_scope: "application.call",
required_scope: "conversation.read",
},
HostEventChannel {
prefix: "workspace-focus-conversation",
Expand Down Expand Up @@ -86,7 +86,7 @@ pub const HOST_EVENT_CHANNELS: &[HostEventChannel] = &[
HostEventChannel {
prefix: "desktop-session-attention",
durability: EventDurability::BestEffort,
required_scope: "application.call",
required_scope: "conversation.read",
},
HostEventChannel {
prefix: "file-tree-stream",
Expand Down
64 changes: 46 additions & 18 deletions crates/server/src/host/workspace_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
//! credential files. A scratch workspace's root can be the user's home directory,
//! so the policy cannot rely on the root being a clean project.

use std::collections::HashMap;
use std::path::{Component, Path, PathBuf};

use application::ApplicationError;
use db::models::workspace_repo::WorkspaceRepo;
use db::models::{project::Project, workspace_repo::WorkspaceRepo};
use deployment::Deployment;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use uuid::Uuid;
Expand Down Expand Up @@ -62,33 +64,59 @@ struct FileContent {
struct ProjectSummary {
id: Uuid,
name: String,
root_path: String,
parent_project_id: Option<Uuid>,
is_git: bool,
is_home: bool,
workspace_ids: Vec<Uuid>,
}

impl ServerApplicationDomains {
/// Projects with the workspaces they own, so a client can group conversations by project.
/// Imported projects (matching the desktop's "已导入项目" list) with their workspaces,
/// ensuring each project has a root workspace so Companion devices can start conversations in it.
pub(crate) async fn conversation_projects(&self) -> Result<Value, ApplicationError> {
let rows = sqlx::query_as::<_, (Uuid, String, Uuid)>(
r#"SELECT p.id, p.name, w.id
FROM workspaces w
JOIN projects p ON p.id = w.project_id
ORDER BY p.name COLLATE NOCASE, w.created_at"#,
let _ = self
.deployment
.project()
.migrate_multi_repo_projects(&self.pool, self.deployment.repo())
.await;
let _ = self
.deployment
.project()
.ensure_home_project(&self.pool, self.deployment.repo())
.await;
let projects = Project::find_all(&self.pool)
.await
.map_err(internal_error)?;
for project in &projects {
let _ = self.ensure_root_workspace(project.id, None).await;
}
let rows = sqlx::query_as::<_, (Uuid, Uuid)>(
r#"SELECT project_id, id
FROM workspaces
WHERE project_id IS NOT NULL
ORDER BY use_worktree ASC, created_at DESC"#,
)
.fetch_all(&self.pool)
.await
.map_err(internal_error)?;
let mut projects: Vec<ProjectSummary> = Vec::new();
for (id, name, workspace_id) in rows {
match projects.iter_mut().find(|project| project.id == id) {
Some(project) => project.workspace_ids.push(workspace_id),
None => projects.push(ProjectSummary {
id,
name,
workspace_ids: vec![workspace_id],
}),
}
let mut by_project: HashMap<Uuid, Vec<Uuid>> = HashMap::new();
for (project_id, workspace_id) in rows {
by_project.entry(project_id).or_default().push(workspace_id);
}
serialize(projects)
let summaries: Vec<ProjectSummary> = projects
.into_iter()
.map(|project| ProjectSummary {
workspace_ids: by_project.remove(&project.id).unwrap_or_default(),
id: project.id,
name: project.name,
root_path: project.root_path,
parent_project_id: project.parent_project_id,
is_git: project.is_git,
is_home: project.is_home,
})
.collect();
serialize(summaries)
}

/// The directory the Agent works in; scratch workspaces have one even without a repository.
Expand Down
2 changes: 1 addition & 1 deletion crates/server/src/host_ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ impl ServerApplicationDomains {
}
}

async fn ensure_root_workspace(
pub(crate) async fn ensure_root_workspace(
&self,
project_id: Uuid,
branch: Option<&str>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import Foundation

public enum JSONValue: Codable, Equatable {
public enum JSONValue: Codable, Equatable, Sendable {
case null
case bool(Bool)
case number(Double)
Expand Down
Loading
Loading