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
23 changes: 23 additions & 0 deletions apps/desktop-tauri/src-tauri/src/commands/agent_sessions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use codexbar::agent_sessions::{
AgentSession, AgentSessionDiscovery, AgentSessionDiscoveryMode, AgentSessionDiscoveryResult,
SessionFocusResult, focus_session,
};
use codexbar::settings::Settings;

#[tauri::command]
pub async fn list_agent_sessions() -> AgentSessionDiscoveryResult {
let settings = Settings::load();
let mode = if settings.agent_sessions_enabled {
AgentSessionDiscoveryMode::Enabled {
ssh_hosts: settings.agent_session_ssh_hosts,
}
} else {
AgentSessionDiscoveryMode::Disabled
};
AgentSessionDiscovery::default().scan(mode).await
}

#[tauri::command]
pub fn focus_agent_session(session: AgentSession) -> SessionFocusResult {
focus_session(&session)
}
4 changes: 4 additions & 0 deletions apps/desktop-tauri/src-tauri/src/commands/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ pub struct SettingsSnapshot {
install_updates_on_quit: bool,
global_shortcut: String,
codex_custom_sessions_dirs: Vec<String>,
agent_sessions_enabled: bool,
agent_session_ssh_hosts: Vec<String>,
ui_language: &'static str,
theme: &'static str,
window_scale_percent: u16,
Expand Down Expand Up @@ -519,6 +521,8 @@ impl From<Settings> for SettingsSnapshot {
install_updates_on_quit: settings.install_updates_on_quit,
global_shortcut: settings.global_shortcut,
codex_custom_sessions_dirs: settings.codex_custom_sessions_dirs,
agent_sessions_enabled: settings.agent_sessions_enabled,
agent_session_ssh_hosts: settings.agent_session_ssh_hosts,
ui_language: language_label(settings.ui_language),
theme: theme_label(settings.theme),
window_scale_percent: settings.window_scale_percent,
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop-tauri/src-tauri/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mod diagnostics;
mod tokens;
mod updater;

mod agent_sessions;
mod bridge;
mod browser_import;
mod credential_detection;
Expand All @@ -41,6 +42,7 @@ mod shortcuts;
mod surface;
mod system;

pub use agent_sessions::*;
pub(crate) use bridge::*;
pub use browser_import::*;
pub use credential_detection::*;
Expand Down
9 changes: 9 additions & 0 deletions apps/desktop-tauri/src-tauri/src/commands/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub struct SettingsUpdate {
pub install_updates_on_quit: Option<bool>,
pub global_shortcut: Option<String>,
pub codex_custom_sessions_dirs: Option<Vec<String>>,
pub agent_sessions_enabled: Option<bool>,
pub agent_session_ssh_hosts: Option<Vec<String>>,
pub ui_language: Option<String>,
pub theme: Option<String>,
pub window_scale_percent: Option<u16>,
Expand Down Expand Up @@ -225,6 +227,13 @@ impl SettingsUpdate {
if let Some(v) = self.codex_custom_sessions_dirs.clone() {
settings.codex_custom_sessions_dirs = normalize_custom_sessions_dirs(v);
}
if let Some(v) = self.agent_sessions_enabled {
settings.agent_sessions_enabled = v;
}
if let Some(v) = self.agent_session_ssh_hosts.clone() {
settings.agent_session_ssh_hosts =
codexbar::agent_sessions::RemoteSessionFetcher::sanitized_hosts(&v);
}
if let Some(v) = self.install_updates_on_quit {
settings.install_updates_on_quit = v;
}
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop-tauri/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ fn main() {
commands::get_bootstrap_state,
commands::get_provider_catalog,
commands::get_settings_snapshot,
commands::list_agent_sessions,
commands::focus_agent_session,
commands::update_settings,
commands::set_surface_mode,
commands::dismiss_tray_panel,
Expand Down
65 changes: 65 additions & 0 deletions apps/desktop-tauri/src/components/AgentSessions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { useCallback, useEffect, useState } from "react";
import { focusAgentSession, listAgentSessions } from "../lib/tauri";
import type {
AgentSession,
AgentSessionDiscoveryResult,
} from "../types/bridge";
import { useLocale } from "../hooks/useLocale";

export default function AgentSessions() {
const { t } = useLocale();
const [result, setResult] = useState<AgentSessionDiscoveryResult | null>(null);
const [error, setError] = useState<string | null>(null);

const refresh = useCallback(() => {
setError(null);
void listAgentSessions()
.then(setResult)
.catch((reason: unknown) =>
setError(reason instanceof Error ? reason.message : String(reason)),
);
}, []);

useEffect(refresh, [refresh]);

if (result?.status === "disabled") return null;
const hosts = result?.status === "hosts" ? result.hosts : [];
const sessions = hosts.flatMap((host) => host.sessions);
const hostErrors = hosts.flatMap((host) =>
host.error ? [`${host.host}: ${host.error}`] : [],
);

const focus = (session: AgentSession) => {
void focusAgentSession(session).then((focusResult) => {
if (focusResult.status !== "focused") setError(focusResult.message);
});
};

return (
<section className="agent-sessions" aria-label={t("AgentSessionsTitle")}>
<div className="agent-sessions__header">
<strong>{t("AgentSessionsTitle")}</strong>
<button type="button" onClick={refresh}>{t("ActionRefresh")}</button>
</div>
{!result && <p>{t("AgentSessionsLoading")}</p>}
{result && sessions.length === 0 && (
<p>{t("AgentSessionsEmpty")}</p>
)}
{sessions.map((session) => (
<button
type="button"
className="agent-sessions__row"
key={`${session.host}:${session.provider}:${session.id}`}
onClick={() => focus(session)}
>
<span>{session.provider === "codex" ? "Codex" : "Claude"}</span>
<span>{session.workspace.projectName ?? session.host}</span>
<span>{session.state}</span>
</button>
))}
{[...hostErrors, ...(error ? [error] : [])].map((message) => (
<p className="agent-sessions__error" key={message}>{message}</p>
))}
</section>
);
}
7 changes: 7 additions & 0 deletions apps/desktop-tauri/src/i18n/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ export const ALL_LOCALE_KEYS = [
"SectionLocalIntegrations",
"PowerToysPipeLabel",
"PowerToysPipeHelper",
"AgentSessionsTitle",
"AgentSessionsEnableLabel",
"AgentSessionsEnableHelper",
"AgentSessionsSshHostsLabel",
"AgentSessionsSshHostsHelper",
"AgentSessionsLoading",
"AgentSessionsEmpty",
"UpdatesTitle",
"UpdateChannelChoice",
"UpdateChannelChoiceHelper",
Expand Down
13 changes: 13 additions & 0 deletions apps/desktop-tauri/src/lib/tauri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import type {
SafeDiagnostics,
CredentialStorageStatus,
WorkAreaRect,
AgentSession,
AgentSessionDiscoveryResult,
SessionFocusResult,
} from "../types/bridge";

export function getBootstrapState(): Promise<BootstrapState> {
Expand All @@ -54,6 +57,16 @@ export function updateSettings(
return invoke<SettingsSnapshot>("update_settings", { patch });
}

export function listAgentSessions(): Promise<AgentSessionDiscoveryResult> {
return invoke<AgentSessionDiscoveryResult>("list_agent_sessions");
}

export function focusAgentSession(
session: AgentSession,
): Promise<SessionFocusResult> {
return invoke<SessionFocusResult>("focus_agent_session", { session });
}

export function setSurfaceMode<M extends VisibleSurfaceMode>(
mode: M,
target: SurfaceTargetForMode<M>,
Expand Down
29 changes: 29 additions & 0 deletions apps/desktop-tauri/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -5557,3 +5557,32 @@ html:has(.menu-surface--tray) {
padding-bottom: 3px;
}
}
.agent-sessions {
display: grid;
gap: 6px;
padding: 10px 12px;
border-bottom: 1px solid var(--panel-border);
font-size: 12px;
}

.agent-sessions__header,
.agent-sessions__row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}

.agent-sessions__row {
width: 100%;
padding: 6px 8px;
border: 0;
border-radius: 6px;
color: inherit;
background: var(--surface-elevated);
cursor: pointer;
}

.agent-sessions__error {
color: var(--provider-status-error);
}
3 changes: 3 additions & 0 deletions apps/desktop-tauri/src/surfaces/TrayPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
hydrateProviderSlots,
orderedEnabledProviderSlots,
} from "../lib/trayProviders";
import AgentSessions from "../components/AgentSessions";

/** Provider IDs that have a dashboard URL in the backend */
const HAS_DASHBOARD = new Set([
Expand Down Expand Up @@ -455,6 +456,7 @@ export default function TrayPanel({ state }: { state: BootstrapState }) {
footerRows={footerRows}
style={{ zoom: trayScale }}
>
{settings.agentSessionsEnabled && <AgentSessions />}
<MenuEmpty
isLoading={isRefreshing && !hasCachedData}
onSettings={openSettings}
Expand All @@ -477,6 +479,7 @@ export default function TrayPanel({ state }: { state: BootstrapState }) {
footerRows={footerRows}
style={{ zoom: trayScale }}
>
{settings.agentSessionsEnabled && <AgentSessions />}
<ProviderGrid
providers={expectsDenseOverview ? denseTrayProviders : sorted}
selectedProviderId={selectedProviderId}
Expand Down
45 changes: 45 additions & 0 deletions apps/desktop-tauri/src/surfaces/settings/tabs/AdvancedTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,30 @@ function parseCodexSessionsDirs(value: string): string[] {
.filter(Boolean);
}

function parseSshHosts(value: string): string[] {
return value.split(/[,\n]/).map((host) => host.trim()).filter(Boolean);
}

export default function AdvancedTab({ settings, set, saving }: TabProps) {
const { t } = useLocale();
const [shortcutError, setShortcutError] = useState<string | null>(null);
const [codexDirsDraft, setCodexDirsDraft] = useState(() =>
formatCodexSessionsDirs(settings.codexCustomSessionsDirs),
);
const [sshHostsDraft, setSshHostsDraft] = useState(() =>
(settings.agentSessionSshHosts ?? []).join(", "),
);

useEffect(() => {
if (!saving) {
setCodexDirsDraft(formatCodexSessionsDirs(settings.codexCustomSessionsDirs));
}
}, [saving, settings.codexCustomSessionsDirs]);

useEffect(() => {
if (!saving) setSshHostsDraft((settings.agentSessionSshHosts ?? []).join(", "));
}, [saving, settings.agentSessionSshHosts]);

const commitShortcut = useCallback(
async (accelerator: string) => {
setShortcutError(null);
Expand Down Expand Up @@ -114,6 +125,40 @@ export default function AdvancedTab({ settings, set, saving }: TabProps) {
</div>
</section>

{/* -- Privacy ----------------------------------------------- */}
<section className="settings-section">
<h3 className="settings-section__title">{t("AgentSessionsTitle")}</h3>
<div className="settings-section__group">
<Field
label={t("AgentSessionsEnableLabel")}
description={t("AgentSessionsEnableHelper")}
leading
>
<Toggle
checked={settings.agentSessionsEnabled ?? false}
disabled={saving}
onChange={(v) => set({ agentSessionsEnabled: v })}
/>
</Field>
<Field
label={t("AgentSessionsSshHostsLabel")}
description={t("AgentSessionsSshHostsHelper")}
>
<input
type="text"
className="text-input"
value={sshHostsDraft}
disabled={saving || !settings.agentSessionsEnabled}
onChange={(event) => setSshHostsDraft(event.target.value)}
onBlur={() => set({ agentSessionSshHosts: parseSshHosts(sshHostsDraft) })}
onKeyDown={(event) => {
if (event.key === "Enter") event.currentTarget.blur();
}}
/>
</Field>
</div>
</section>

{/* -- Privacy ----------------------------------------------- */}
<section className="settings-section">
<h3 className="settings-section__title">{t("PrivacyTitle")}</h3>
Expand Down
41 changes: 41 additions & 0 deletions apps/desktop-tauri/src/types/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,43 @@ export interface CurrentSurfaceState {
target: SurfaceTarget;
}

export interface AgentSession {
id: string;
provider: "codex" | "claude";
source: "cli" | "desktopApp" | "ide" | "unknown";
state: "active" | "idle";
pid: number | null;
transcriptPath: string | null;
host: string;
workspace: {
cwd: string | null;
projectName: string | null;
};
activity: {
startedAt: string | null;
lastActivityAt: string | null;
};
focusTarget:
| { kind: "process"; pid: number }
| { kind: "transcript"; transcriptPath: string }
| { kind: "none" };
}

export interface AgentSessionHostResult {
host: string;
sessions: AgentSession[];
error: string | null;
}

export type AgentSessionDiscoveryResult =
| { status: "disabled" }
| { status: "hosts"; hosts: AgentSessionHostResult[] };

export type SessionFocusResult =
| { status: "focused" }
| { status: "unsupported"; message: string }
| { status: "failed"; message: string };

export interface ProofRect {
x: number;
y: number;
Expand Down Expand Up @@ -195,6 +232,8 @@ export interface SettingsSnapshot {
globalShortcut: string;
/** Extra Codex home or sessions directories scanned for local cost estimates. */
codexCustomSessionsDirs: string[];
agentSessionsEnabled?: boolean;
agentSessionSshHosts?: string[];
uiLanguage: Language;
theme: ThemePreference;
/** 100..=250 — clamped server-side. */
Expand Down Expand Up @@ -252,6 +291,8 @@ export interface SettingsUpdate {
installUpdatesOnQuit?: boolean;
globalShortcut?: string;
codexCustomSessionsDirs?: string[];
agentSessionsEnabled?: boolean;
agentSessionSshHosts?: string[];
uiLanguage?: Language;
theme?: ThemePreference;
windowScalePercent?: number;
Expand Down
Loading