Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

feat: add local folder and github repository workspace support for teams

Oleksandr Ivanchenkod0bc55cf348d
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index 52b0e075..98b47bc0 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -369,6 +369,8 @@ export const App: React.FC = () => {
const handleCreateTeam = async (teamData: {
name: string;
description?: string;
+ workspace_path?: string;
+ repo_url?: string;
lead_kwant_id: string;
member_kwants: string[];
icon?: string;
@@ -421,6 +423,8 @@ export const App: React.FC = () => {
data: {
name: string;
description?: string;
+ workspace_path?: string;
+ repo_url?: string;
lead_kwant_id: string;
member_kwants: string[];
}
@@ -571,6 +575,8 @@ export const App: React.FC = () => {
onCancelDiscussion={handleCancelDiscussion}
teamMembers={currentTeamMembers}
teamName={currentTeam?.name}
+ workspacePath={currentTeam?.workspace_path}
+ repoUrl={currentTeam?.repo_url}
onManageTeam={
currentTeam
? () => {
diff --git a/frontend/src/components/ChatView.tsx b/frontend/src/components/ChatView.tsx
index 05eeab55..e117d585 100644
--- a/frontend/src/components/ChatView.tsx
+++ b/frontend/src/components/ChatView.tsx
@@ -1,5 +1,5 @@
import React, { useState, useRef, useEffect } from 'react';
-import { ArrowUp, Sparkles, ChevronDown, ChevronRight, Copy, Check, Cpu, Users, Square, Settings2 } from 'lucide-react';
+import { ArrowUp, Sparkles, ChevronDown, ChevronRight, Copy, Check, Cpu, Users, Square, Settings2, Folder, GitBranch } from 'lucide-react';
import { ModernAvatar } from './ModernAvatar';
import { ModernApprovalCard, PendingApproval } from './ModernApprovalCard';
import { MentionPopover, MentionItem } from './MentionPopover';
@@ -40,6 +40,8 @@ export interface ChatViewProps {
onCancelDiscussion?: () => void;
teamMembers?: Array<{ id: string; name: string; title: string; avatar_sprite: string }>;
teamName?: string;
+ workspacePath?: string;
+ repoUrl?: string;
onManageTeam?: () => void;
}
@@ -77,6 +79,8 @@ export const ChatView: React.FC<ChatViewProps> = ({
onCancelDiscussion,
teamMembers,
teamName,
+ workspacePath,
+ repoUrl,
onManageTeam,
}) => {
const [inputVal, setInputVal] = useState('');
@@ -286,6 +290,25 @@ export const ChatView: React.FC<ChatViewProps> = ({
</div>
<div className="flex items-center gap-3">
+ {/* Active Team Workspace Badge */}
+ {(workspacePath || repoUrl) && (
+ <div
+ className="hidden sm:flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-xs font-mono text-zinc-300 bg-zinc-900 border border-zinc-700/60 max-w-[200px] truncate"
+ title={workspacePath ? `Workspace directory: ${workspacePath}` : `Git Repository: ${repoUrl}`}
+ >
+ {workspacePath ? (
+ <Folder size={12} className="text-amber-400 flex-shrink-0" />
+ ) : (
+ <GitBranch size={12} className="text-emerald-400 flex-shrink-0" />
+ )}
+ <span className="truncate">
+ {workspacePath
+ ? workspacePath.replace(/^\/Users\/[^/]+/, '~')
+ : repoUrl?.replace(/^https?:\/\/github\.com\//, '').replace(/\.git$/, '')}
+ </span>
+ </div>
+ )}
+
{teamMembers && teamMembers.length > 0 && (
<div className="flex items-center gap-2 pl-3 border-l border-zinc-800">
<div className="flex -space-x-2 overflow-hidden items-center py-0.5">
diff --git a/frontend/src/components/ManageTeamModal.tsx b/frontend/src/components/ManageTeamModal.tsx
index 621cb581..8eaa7070 100644
--- a/frontend/src/components/ManageTeamModal.tsx
+++ b/frontend/src/components/ManageTeamModal.tsx
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react';
-import { X, Users, Trash2, Check, AlertTriangle, ShieldCheck } from 'lucide-react';
+import { X, Users, Trash2, Check, AlertTriangle, ShieldCheck, Folder, GitBranch } from 'lucide-react';
import { ModernAvatar } from './ModernAvatar';
import { Team, Kwant } from './Sidebar';
import { playSfx } from '../audio/chiptune';
@@ -14,6 +14,8 @@ interface ManageTeamModalProps {
data: {
name: string;
description?: string;
+ workspace_path?: string;
+ repo_url?: string;
lead_kwant_id: string;
member_kwants: string[];
}
@@ -31,6 +33,9 @@ export const ManageTeamModal: React.FC<ManageTeamModalProps> = ({
}) => {
const [name, setName] = useState('');
const [description, setDescription] = useState('');
+ const [workspaceType, setWorkspaceType] = useState<'local' | 'repo' | 'default'>('default');
+ const [workspacePath, setWorkspacePath] = useState('');
+ const [repoUrl, setRepoUrl] = useState('');
const [leadKwantId, setLeadKwantId] = useState('');
const [memberIds, setMemberIds] = useState<string[]>([]);
const [isDeleting, setIsDeleting] = useState(false);
@@ -44,6 +49,20 @@ export const ManageTeamModal: React.FC<ManageTeamModalProps> = ({
setDescription(team.description || '');
setLeadKwantId(team.lead_kwant_id || (kwants[0]?.id ?? ''));
+ if (team.workspace_path) {
+ setWorkspaceType('local');
+ setWorkspacePath(team.workspace_path);
+ setRepoUrl('');
+ } else if (team.repo_url) {
+ setWorkspaceType('repo');
+ setWorkspacePath('');
+ setRepoUrl(team.repo_url);
+ } else {
+ setWorkspaceType('default');
+ setWorkspacePath('');
+ setRepoUrl('');
+ }
+
const parsedMembers: string[] = Array.isArray(team.member_kwants)
? team.member_kwants
: typeof team.member_kwants === 'string'
@@ -94,6 +113,8 @@ export const ManageTeamModal: React.FC<ManageTeamModalProps> = ({
await onUpdateTeam(team.id, {
name: cleanName,
description: description.trim() || undefined,
+ workspace_path: workspaceType === 'local' && workspacePath.trim() ? workspacePath.trim() : undefined,
+ repo_url: workspaceType === 'repo' && repoUrl.trim() ? repoUrl.trim() : undefined,
lead_kwant_id: leadKwantId || memberIds[0],
member_kwants: memberIds,
});
@@ -185,6 +206,95 @@ export const ManageTeamModal: React.FC<ManageTeamModalProps> = ({
/>
</div>
+ {/* Team Workspace */}
+ <div>
+ <label className="block text-xs font-medium text-zinc-400 mb-1.5">
+ Team Workspace
+ </label>
+ <div className="grid grid-cols-3 gap-1.5 p-1 bg-zinc-950 rounded-lg border border-zinc-800 text-xs mb-2">
+ <button
+ type="button"
+ onClick={() => {
+ playSfx('click');
+ setWorkspaceType('local');
+ }}
+ className={`flex items-center justify-center gap-1.5 py-1.5 rounded-md font-medium transition-all ${
+ workspaceType === 'local'
+ ? 'bg-zinc-800 text-sky-400 border border-sky-500/30 shadow-sm'
+ : 'text-zinc-400 hover:text-zinc-200 hover:bg-zinc-900'
+ }`}
+ >
+ <Folder size={13} />
+ <span>Local Folder</span>
+ </button>
+ <button
+ type="button"
+ onClick={() => {
+ playSfx('click');
+ setWorkspaceType('repo');
+ }}
+ className={`flex items-center justify-center gap-1.5 py-1.5 rounded-md font-medium transition-all ${
+ workspaceType === 'repo'
+ ? 'bg-zinc-800 text-sky-400 border border-sky-500/30 shadow-sm'
+ : 'text-zinc-400 hover:text-zinc-200 hover:bg-zinc-900'
+ }`}
+ >
+ <GitBranch size={13} />
+ <span>Git Repo</span>
+ </button>
+ <button
+ type="button"
+ onClick={() => {
+ playSfx('click');
+ setWorkspaceType('default');
+ }}
+ className={`flex items-center justify-center gap-1.5 py-1.5 rounded-md font-medium transition-all ${
+ workspaceType === 'default'
+ ? 'bg-zinc-800 text-sky-400 border border-sky-500/30 shadow-sm'
+ : 'text-zinc-400 hover:text-zinc-200 hover:bg-zinc-900'
+ }`}
+ >
+ <span>Default</span>
+ </button>
+ </div>
+
+ {workspaceType === 'local' && (
+ <div>
+ <input
+ type="text"
+ value={workspacePath}
+ onChange={(e) => setWorkspacePath(e.target.value)}
+ placeholder="e.g. ~/projects/my-app or /path/to/folder"
+ className="w-full bg-zinc-950 border border-zinc-800 rounded-lg px-3 py-2 text-xs text-zinc-100 placeholder-zinc-600 focus:border-sky-500 focus:outline-none transition-colors font-mono"
+ />
+ <p className="text-[11px] text-zinc-500 mt-1">
+ Team members will execute commands and tools directly in this directory.
+ </p>
+ </div>
+ )}
+
+ {workspaceType === 'repo' && (
+ <div>
+ <input
+ type="text"
+ value={repoUrl}
+ onChange={(e) => setRepoUrl(e.target.value)}
+ placeholder="https://github.com/owner/repository.git"
+ className="w-full bg-zinc-950 border border-zinc-800 rounded-lg px-3 py-2 text-xs text-zinc-100 placeholder-zinc-600 focus:border-sky-500 focus:outline-none transition-colors font-mono"
+ />
+ <p className="text-[11px] text-zinc-500 mt-1">
+ Repository will be cloned and managed in team workspace directory on first run.
+ </p>
+ </div>
+ )}
+
+ {workspaceType === 'default' && (
+ <p className="text-[11px] text-zinc-500">
+ Uses the default shared workspace directory.
+ </p>
+ )}
+ </div>
+
{/* Lead Kwant Selector */}
<div>
<label className="block text-xs font-medium text-zinc-400 mb-1">Team Lead</label>
diff --git a/frontend/src/components/NewTeamModal.tsx b/frontend/src/components/NewTeamModal.tsx
index 1c728f88..767e536d 100644
--- a/frontend/src/components/NewTeamModal.tsx
+++ b/frontend/src/components/NewTeamModal.tsx
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react';
-import { X, Users, AlertCircle } from 'lucide-react';
+import { X, Users, AlertCircle, Folder, GitBranch } from 'lucide-react';
import { ModernAvatar } from './ModernAvatar';
import { Kwant, Team } from './Sidebar';
import { playSfx } from '../audio/chiptune';
@@ -11,6 +11,8 @@ export interface NewTeamModalProps {
onCreateTeam?: (data: {
name: string;
description?: string;
+ workspace_path?: string;
+ repo_url?: string;
lead_kwant_id: string;
member_kwants: string[];
icon?: string;
@@ -27,6 +29,9 @@ export const NewTeamModal: React.FC<NewTeamModalProps> = ({
}) => {
const [name, setName] = useState('');
const [description, setDescription] = useState('');
+ const [workspaceType, setWorkspaceType] = useState<'local' | 'repo' | 'default'>('local');
+ const [workspacePath, setWorkspacePath] = useState('');
+ const [repoUrl, setRepoUrl] = useState('');
const [leadKwantId, setLeadKwantId] = useState('');
const [selectedMembers, setSelectedMembers] = useState<string[]>([]);
const [submitting, setSubmitting] = useState(false);
@@ -37,6 +42,9 @@ export const NewTeamModal: React.FC<NewTeamModalProps> = ({
if (isOpen) {
setName('');
setDescription('');
+ setWorkspaceType('local');
+ setWorkspacePath('');
+ setRepoUrl('');
setError(null);
if (kwants.length > 0) {
const defaultLead = kwants[0].id;
@@ -107,6 +115,8 @@ export const NewTeamModal: React.FC<NewTeamModalProps> = ({
const teamPayload = {
name: cleanSlug,
description: description.trim() || undefined,
+ workspace_path: workspaceType === 'local' && workspacePath.trim() ? workspacePath.trim() : undefined,
+ repo_url: workspaceType === 'repo' && repoUrl.trim() ? repoUrl.trim() : undefined,
lead_kwant_id: leadKwantId,
member_kwants: finalMembers,
icon: 'users',
@@ -211,6 +221,95 @@ export const NewTeamModal: React.FC<NewTeamModalProps> = ({
/>
</div>
+ {/* Team Workspace */}
+ <div>
+ <label className="block text-xs font-medium text-zinc-400 mb-1.5">
+ Team Workspace
+ </label>
+ <div className="grid grid-cols-3 gap-1.5 p-1 bg-zinc-950 rounded-lg border border-zinc-800 text-xs mb-2">
+ <button
+ type="button"
+ onClick={() => {
+ playSfx('click');
+ setWorkspaceType('local');
+ }}
+ className={`flex items-center justify-center gap-1.5 py-1.5 rounded-md font-medium transition-all ${
+ workspaceType === 'local'
+ ? 'bg-zinc-800 text-sky-400 border border-sky-500/30 shadow-sm'
+ : 'text-zinc-400 hover:text-zinc-200 hover:bg-zinc-900'
+ }`}
+ >
+ <Folder size={13} />
+ <span>Local Folder</span>
+ </button>
+ <button
+ type="button"
+ onClick={() => {
+ playSfx('click');
+ setWorkspaceType('repo');
+ }}
+ className={`flex items-center justify-center gap-1.5 py-1.5 rounded-md font-medium transition-all ${
+ workspaceType === 'repo'
+ ? 'bg-zinc-800 text-sky-400 border border-sky-500/30 shadow-sm'
+ : 'text-zinc-400 hover:text-zinc-200 hover:bg-zinc-900'
+ }`}
+ >
+ <GitBranch size={13} />
+ <span>Git Repo</span>
+ </button>
+ <button
+ type="button"
+ onClick={() => {
+ playSfx('click');
+ setWorkspaceType('default');
+ }}
+ className={`flex items-center justify-center gap-1.5 py-1.5 rounded-md font-medium transition-all ${
+ workspaceType === 'default'
+ ? 'bg-zinc-800 text-sky-400 border border-sky-500/30 shadow-sm'
+ : 'text-zinc-400 hover:text-zinc-200 hover:bg-zinc-900'
+ }`}
+ >
+ <span>Default</span>
+ </button>
+ </div>
+
+ {workspaceType === 'local' && (
+ <div>
+ <input
+ type="text"
+ value={workspacePath}
+ onChange={(e) => setWorkspacePath(e.target.value)}
+ placeholder="e.g. ~/projects/my-app or /path/to/folder"
+ className="w-full bg-zinc-950 border border-zinc-800 rounded-lg px-3 py-2 text-xs text-zinc-100 placeholder-zinc-600 focus:border-sky-500 focus:outline-none transition-colors font-mono"
+ />
+ <p className="text-[11px] text-zinc-500 mt-1">
+ Team members will execute commands and tools directly in this directory.
+ </p>
+ </div>
+ )}
+
+ {workspaceType === 'repo' && (
+ <div>
+ <input
+ type="text"
+ value={repoUrl}
+ onChange={(e) => setRepoUrl(e.target.value)}
+ placeholder="https://github.com/owner/repository.git"
+ className="w-full bg-zinc-950 border border-zinc-800 rounded-lg px-3 py-2 text-xs text-zinc-100 placeholder-zinc-600 focus:border-sky-500 focus:outline-none transition-colors font-mono"
+ />
+ <p className="text-[11px] text-zinc-500 mt-1">
+ Repository will be cloned and managed in team workspace directory on first run.
+ </p>
+ </div>
+ )}
+
+ {workspaceType === 'default' && (
+ <p className="text-[11px] text-zinc-500">
+ Uses the default shared workspace directory.
+ </p>
+ )}
+ </div>
+
{/* Lead Kwant */}
<div>
<label className="block text-xs font-medium text-zinc-400 mb-1">
diff --git a/frontend/src/components/Sidebar.tsx b/frontend/src/components/Sidebar.tsx
index 8686129a..26f993a7 100644
--- a/frontend/src/components/Sidebar.tsx
+++ b/frontend/src/components/Sidebar.tsx
@@ -26,6 +26,8 @@ export interface Team {
id: string;
name: string;
description?: string;
+ workspace_path?: string;
+ repo_url?: string;
icon: string;
lead_kwant_id: string;
member_kwants: string[];
diff --git a/src/db/mod.rs b/src/db/mod.rs
index 3824854f..52bfdf77 100644
--- a/src/db/mod.rs
+++ b/src/db/mod.rs
@@ -47,6 +47,10 @@ impl Database {
}
}
+ // Run migrations for newly added columns if existing DB
+ let _ = sqlx::query("ALTER TABLE teams ADD COLUMN workspace_path TEXT;").execute(&pool).await;
+ let _ = sqlx::query("ALTER TABLE teams ADD COLUMN repo_url TEXT;").execute(&pool).await;
+
let db = Self { pool };
db.seed_defaults().await?;
@@ -125,6 +129,8 @@ impl Database {
icon: Some("users".into()),
lead_kwant_id: lead.id.clone(),
member_kwants: member_ids,
+ workspace_path: None,
+ repo_url: None,
};
self.create_team(&default_team).await?;
}
@@ -336,8 +342,8 @@ impl Database {
sqlx::query(
r#"
- INSERT INTO teams (id, name, description, icon, lead_kwant_id, member_kwants)
- VALUES (?, ?, ?, ?, ?, ?)
+ INSERT INTO teams (id, name, description, icon, lead_kwant_id, member_kwants, workspace_path, repo_url)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
"#,
)
.bind(&id)
@@ -346,6 +352,8 @@ impl Database {
.bind(icon)
.bind(&input.lead_kwant_id)
.bind(&members_json)
+ .bind(&input.workspace_path)
+ .bind(&input.repo_url)
.execute(&self.pool)
.await?;
@@ -398,7 +406,7 @@ impl Database {
let res = sqlx::query(
r#"
UPDATE teams
- SET name = ?, description = ?, icon = ?, lead_kwant_id = ?, member_kwants = ?
+ SET name = ?, description = ?, icon = ?, lead_kwant_id = ?, member_kwants = ?, workspace_path = ?, repo_url = ?
WHERE id = ?
"#,
)
@@ -407,6 +415,8 @@ impl Database {
.bind(icon)
.bind(&input.lead_kwant_id)
.bind(&members_json)
+ .bind(&input.workspace_path)
+ .bind(&input.repo_url)
.bind(id)
.execute(&self.pool)
.await?;
diff --git a/src/db/models.rs b/src/db/models.rs
index ecf32e94..b99979ee 100644
--- a/src/db/models.rs
+++ b/src/db/models.rs
@@ -101,6 +101,8 @@ pub struct Team {
pub icon: String,
pub lead_kwant_id: String,
pub member_kwants: String, // JSON array string
+ pub workspace_path: Option<String>,
+ pub repo_url: Option<String>,
pub created_at: Option<DateTime<Utc>>,
}
@@ -111,5 +113,9 @@ pub struct NewTeam {
pub icon: Option<String>,
pub lead_kwant_id: String,
pub member_kwants: Vec<String>,
+ #[serde(default)]
+ pub workspace_path: Option<String>,
+ #[serde(default)]
+ pub repo_url: Option<String>,
}
diff --git a/src/db/schema.sql b/src/db/schema.sql
index f247b468..338560a1 100644
--- a/src/db/schema.sql
+++ b/src/db/schema.sql
@@ -59,6 +59,8 @@ CREATE TABLE IF NOT EXISTS teams (
icon TEXT NOT NULL DEFAULT 'users',
lead_kwant_id TEXT NOT NULL,
member_kwants TEXT NOT NULL,
+ workspace_path TEXT,
+ repo_url TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(lead_kwant_id) REFERENCES kwants(id)
);
diff --git a/src/drivers/cli.rs b/src/drivers/cli.rs
index 906d632d..edff5b07 100644
--- a/src/drivers/cli.rs
+++ b/src/drivers/cli.rs
@@ -100,6 +100,11 @@ impl Driver for CliDriver {
};
let mut cmd = Command::new(&bin_path);
+ if let Some(ref dir) = input.workspace_dir {
+ if dir.exists() {
+ cmd.current_dir(dir);
+ }
+ }
let mut codex_out_file: Option<String> = None;
let effort = input.effort_level.as_deref().unwrap_or("medium");
diff --git a/src/drivers/mod.rs b/src/drivers/mod.rs
index c68c1ee6..3d8fa3cc 100644
--- a/src/drivers/mod.rs
+++ b/src/drivers/mod.rs
@@ -29,6 +29,8 @@ pub struct TeamContext {
pub id: String,
pub name: String,
pub description: Option<String>,
+ pub workspace_path: Option<String>,
+ pub repo_url: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -40,6 +42,7 @@ pub struct TurnInput {
pub model_override: Option<String>,
pub effort_level: Option<String>,
pub team_context: Option<TeamContext>,
+ pub workspace_dir: Option<std::path::PathBuf>,
}
impl TurnInput {
@@ -50,9 +53,19 @@ impl TurnInput {
);
if let Some(ref team) = self.team_context {
let desc = team.description.as_deref().unwrap_or("General team objectives");
+ let mut ws_info = String::new();
+ if let Some(ref ws) = team.workspace_path {
+ ws_info.push_str(&format!("\nWorkspace: {}", ws));
+ } else if let Some(ref ws) = self.workspace_dir {
+ ws_info.push_str(&format!("\nWorkspace: {}", ws.display()));
+ }
+ if let Some(ref repo) = team.repo_url {
+ ws_info.push_str(&format!("\nGit Repo: {}", repo));
+ }
+
format!(
- "{}\n\n[Active Team Alignment: @{}]\nTeam Mission: {}\nAs a member of team @{}, align your tone, recommendations, and analysis with this team's mission and collaborate effectively with fellow team members.",
- base, team.name, desc, team.name
+ "{}\n\n[Active Team Alignment: @{}]{}\nTeam Mission: {}\nAs a member of team @{}, align your tone, recommendations, and analysis with this team's mission and collaborate effectively with fellow team members.",
+ base, team.name, ws_info, desc, team.name
)
} else {
format!("{}\n\nRespond clearly in character.", base)
diff --git a/src/router/team.rs b/src/router/team.rs
index 2b397de7..4f1dd982 100644
--- a/src/router/team.rs
+++ b/src/router/team.rs
@@ -317,6 +317,8 @@ mod tests {
id: "team-1".into(),
name: "core-engineering".into(),
description: Some("Architecture & DevOps".into()),
+ workspace_path: None,
+ repo_url: None,
icon: "users".into(),
lead_kwant_id: "kwant-1".into(),
member_kwants: "[\"kwant-1\", \"kwant-2\"]".into(),
diff --git a/src/server/routes.rs b/src/server/routes.rs
index dbf70857..c812ca31 100644
--- a/src/server/routes.rs
+++ b/src/server/routes.rs
@@ -212,6 +212,7 @@ fn execute_single_turn(
team_keys: Option<(String, String)>,
kwant_id: Option<String>,
team_context: Option<crate::drivers::TeamContext>,
+ workspace_dir: Option<std::path::PathBuf>,
) {
let event_broadcast = state.event_sender.clone();
let db = state.db.clone();
@@ -266,6 +267,7 @@ fn execute_single_turn(
model_override: Some(target_model),
effort_level: Some(effort_level),
team_context,
+ workspace_dir,
};
let (driver_tx, mut driver_rx) = mpsc::channel(32);
@@ -429,8 +431,24 @@ pub async fn send_chat(
id: t.id.clone(),
name: t.name.clone(),
description: t.description.clone(),
+ workspace_path: t.workspace_path.clone(),
+ repo_url: t.repo_url.clone(),
});
+ let workspace_dir = if let Some(ref team) = active_team {
+ Some(
+ crate::tools::resolve_or_prepare_workspace(
+ &state.config.data_dir,
+ &team.name,
+ team.workspace_path.as_deref(),
+ team.repo_url.as_deref(),
+ )
+ .await,
+ )
+ } else {
+ None
+ };
+
// Insert user message to DB
let user_msg = NewMessage {
channel_id: payload.channel_id.clone(),
@@ -505,6 +523,7 @@ pub async fn send_chat(
Some((team.id.clone(), team.name.clone())),
kwant_id_cleanup,
active_team_context,
+ workspace_dir.clone(),
);
Ok(Json(json!({
@@ -537,6 +556,7 @@ pub async fn send_chat(
let plan_clone = plan.clone();
let cancel_token_clone = cancel_token.clone();
let session_id_clone = session_id.clone();
+ let workspace_dir_clone = workspace_dir.clone();
tokio::spawn(async move {
let context_id = channel_id
@@ -622,7 +642,10 @@ pub async fn send_chat(
id: team_clone.id.clone(),
name: team_clone.name.clone(),
description: team_clone.description.clone(),
+ workspace_path: team_clone.workspace_path.clone(),
+ repo_url: team_clone.repo_url.clone(),
}),
+ workspace_dir: workspace_dir_clone.clone(),
};
let (driver_tx, mut driver_rx) = mpsc::channel(32);
@@ -743,6 +766,7 @@ pub async fn send_chat(
team_keys,
kwant_id_cleanup,
active_team_context,
+ workspace_dir,
);
Ok(Json(json!({
diff --git a/src/tools/mod.rs b/src/tools/mod.rs
index 89d848a5..2ef756b7 100644
--- a/src/tools/mod.rs
+++ b/src/tools/mod.rs
@@ -36,13 +36,61 @@ impl ToolRunner {
}
pub async fn execute(&self, tool_name: &str, args: &Value) -> Result<Value, ToolError> {
+ self.execute_in_workspace(&self.workspace_dir, tool_name, args).await
+ }
+
+ pub async fn execute_in_workspace(&self, target_dir: &std::path::Path, tool_name: &str, args: &Value) -> Result<Value, ToolError> {
match tool_name {
- "write_file" => file_ops::write_file(&self.workspace_dir, args),
- "read_file" => file_ops::read_file(&self.workspace_dir, args),
- "list_dir" => file_ops::list_dir(&self.workspace_dir, args),
- "execute_shell" => shell::execute_shell(&self.workspace_dir, args).await,
+ "write_file" => file_ops::write_file(target_dir, args),
+ "read_file" => file_ops::read_file(target_dir, args),
+ "list_dir" => file_ops::list_dir(target_dir, args),
+ "execute_shell" => shell::execute_shell(target_dir, args).await,
"web_fetch" => web::web_fetch(args).await,
other => Err(ToolError::UnknownTool(other.to_string())),
}
}
}
+
+pub async fn resolve_or_prepare_workspace(
+ base_data_dir: &std::path::Path,
+ team_name: &str,
+ workspace_path: Option<&str>,
+ repo_url: Option<&str>,
+) -> PathBuf {
+ let target_dir = if let Some(ws) = workspace_path.filter(|s| !s.trim().is_empty()) {
+ let trimmed = ws.trim();
+ if trimmed.starts_with("~/") {
+ if let Ok(home) = std::env::var("HOME") {
+ PathBuf::from(home).join(&trimmed[2..])
+ } else {
+ PathBuf::from(trimmed)
+ }
+ } else {
+ PathBuf::from(trimmed)
+ }
+ } else if repo_url.filter(|s| !s.trim().is_empty()).is_some() {
+ base_data_dir.join("workspaces").join(team_name)
+ } else {
+ base_data_dir.join("workspace")
+ };
+
+ if let Some(repo) = repo_url.filter(|s| !s.trim().is_empty()) {
+ let git_dir = target_dir.join(".git");
+ if !git_dir.exists() {
+ let _ = std::fs::create_dir_all(&target_dir);
+ let clone_res = tokio::process::Command::new("git")
+ .arg("clone")
+ .arg(repo.trim())
+ .arg(&target_dir)
+ .output()
+ .await;
+ if let Err(e) = clone_res {
+ tracing::warn!("Failed to run git clone for team {}: {}", team_name, e);
+ }
+ }
+ } else {
+ let _ = std::fs::create_dir_all(&target_dir);
+ }
+
+ target_dir
+}
diff --git a/tests/db_test.rs b/tests/db_test.rs
index 476f5449..b81bddda 100644
--- a/tests/db_test.rs
+++ b/tests/db_test.rs
@@ -90,6 +90,8 @@ async fn test_team_crud_and_seed() {
icon: Some("shield".into()),
lead_kwant_id: kwants[0].id.clone(),
member_kwants: vec![kwants[0].id.clone(), kwants[1].id.clone()],
+ workspace_path: None,
+ repo_url: None,
};
let created = db.create_team(&new_team).await.unwrap();
assert_eq!(created.name, "infra-sec");
@@ -112,3 +114,38 @@ async fn test_team_crud_and_seed() {
assert!(after_delete.is_none());
}
+#[tokio::test]
+async fn test_team_with_workspace_and_repo() {
+ let temp_dir = tempfile::tempdir().unwrap();
+ let db = Database::init(temp_dir.path()).await.unwrap();
+
+ let kwants = db.list_kwants().await.unwrap();
+ let new_team = NewTeam {
+ name: "dev-squad".into(),
+ description: Some("Frontend and backend app development".into()),
+ icon: Some("code".into()),
+ lead_kwant_id: kwants[0].id.clone(),
+ member_kwants: vec![kwants[0].id.clone()],
+ workspace_path: Some("/Users/dev/my-project".into()),
+ repo_url: Some("https://github.com/my-org/my-project.git".into()),
+ };
+ let created = db.create_team(&new_team).await.unwrap();
+ assert_eq!(created.workspace_path.as_deref(), Some("/Users/dev/my-project"));
+ assert_eq!(created.repo_url.as_deref(), Some("https://github.com/my-org/my-project.git"));
+
+ // Update team workspace and repo
+ let update_team = NewTeam {
+ name: "dev-squad".into(),
+ description: Some("Updated description".into()),
+ icon: Some("code".into()),
+ lead_kwant_id: kwants[0].id.clone(),
+ member_kwants: vec![kwants[0].id.clone()],
+ workspace_path: Some("/Users/dev/new-location".into()),
+ repo_url: None,
+ };
+ let updated = db.update_team(&created.id, &update_team).await.unwrap().unwrap();
+ assert_eq!(updated.workspace_path.as_deref(), Some("/Users/dev/new-location"));
+ assert_eq!(updated.repo_url, None);
+}
+
+
diff --git a/tests/driver_test.rs b/tests/driver_test.rs
index 3e5ff056..f2a22c31 100644
--- a/tests/driver_test.rs
+++ b/tests/driver_test.rs
@@ -84,6 +84,7 @@ async fn test_mock_driver_streaming() {
model_override: None,
effort_level: None,
team_context: None,
+ workspace_dir: None,
};
let handle = tokio::spawn(async move {
@@ -137,6 +138,7 @@ fn test_turn_input_format_system_prompt_with_and_without_team_context() {
model_override: None,
effort_level: None,
team_context: None,
+ workspace_dir: None,
};
let solo_prompt = input_solo.format_system_prompt();
@@ -156,7 +158,10 @@ fn test_turn_input_format_system_prompt_with_and_without_team_context() {
id: "team-123".into(),
name: "core-engineering".into(),
description: Some("Core architectural, engineering, and infrastructure team".into()),
+ workspace_path: None,
+ repo_url: None,
}),
+ workspace_dir: None,
};
let team_prompt = input_team.format_system_prompt();
@@ -164,5 +169,28 @@ fn test_turn_input_format_system_prompt_with_and_without_team_context() {
assert!(team_prompt.contains("[Active Team Alignment: @core-engineering]"));
assert!(team_prompt.contains("Team Mission: Core architectural, engineering, and infrastructure team"));
assert!(team_prompt.contains("align your tone, recommendations, and analysis with this team's mission"));
+
+ // 3. With team context including workspace and repo URL
+ let input_workspace = TurnInput {
+ thread_id: "thread-workspace".into(),
+ kwant: kwant.clone(),
+ prompt: "Check files".into(),
+ history: vec![],
+ model_override: None,
+ effort_level: None,
+ team_context: Some(TeamContext {
+ id: "team-456".into(),
+ name: "app-team".into(),
+ description: Some("App dev".into()),
+ workspace_path: Some("/Users/dev/app".into()),
+ repo_url: Some("https://github.com/org/app".into()),
+ }),
+ workspace_dir: Some(std::path::PathBuf::from("/Users/dev/app")),
+ };
+
+ let ws_prompt = input_workspace.format_system_prompt();
+ assert!(ws_prompt.contains("[Active Team Alignment: @app-team]"));
+ assert!(ws_prompt.contains("Workspace: /Users/dev/app"));
+ assert!(ws_prompt.contains("Git Repo: https://github.com/org/app"));
}
diff --git a/tests/router_test.rs b/tests/router_test.rs
index 09705f29..b120b8da 100644
--- a/tests/router_test.rs
+++ b/tests/router_test.rs
@@ -109,6 +109,8 @@ async fn test_team_orchestration_heuristic_fallback() {
id: "team-1".into(),
name: "core-engineering".into(),
description: Some("Architecture & DevOps".into()),
+ workspace_path: None,
+ repo_url: None,
icon: "users".into(),
lead_kwant_id: "kwant-1".into(),
member_kwants: "[\"kwant-1\", \"kwant-2\"]".into(),