Scheduled runs each get their own workspace in the sidebar (#1934)
* feat(schedules): per-run workspaces, isolation and archive controls Scheduled agents never appeared in the sidebar: each schedule reused one stamped workspace and archived the run's agent on completion. Now every run mints its own workspace — the entity the sidebar shows — with per-schedule controls for isolation (local or worktree) and whether to archive that workspace when the run finishes. The schedule form is rebuilt on a non-React form model (open/commands/close) to end the flicker, edit-into-create contamination, and multi-host hydration bugs that came from effect-choreographed shared state. That lands the reusable foundations it needed: a form kit over a single control-geometry owner, a data-access taxonomy (replica/snapshot/fetch) with real load-state semantics, and lint/boundary guardrails so new screens inherit the paved road. Also fixes desktop combobox popovers truncating options when the trigger is narrower than the content. New schedule protocol fields are optional on both create and update, so old and new clients/daemons stay compatible. * test(app): complete mock themes for control-geometry tokens switch and terminal-profile-edit-modal now style through createControlGeometry, which reads theme.borderWidth[1], theme.opacity[50], and theme.colors.borderAccent. The hand-rolled mock themes in these two suites lacked those tokens, so the eager StyleSheet.create mock threw at import (collection error), not on any assertion. Add the missing tokens. * fix(schedules): address review findings on run cleanup, edit isolation, load error, sheet dismiss, and preference hydration - Server: archive the run's workspace even when agent creation fails, so a misconfigured provider no longer orphans a sidebar workspace/worktree. - Edit form: keep a stored worktree isolation while worktree eligibility is still resolving, instead of silently downgrading a saved schedule to local. - Schedules screen: show the load error/retry UI when every host fails, rather than spinning forever behind the loading branch. - Form sheet: fire the parent onClose on native gesture/backdrop dismiss so the sheet closes instead of re-opening. - Form model: apply late-loading saved preferences to untouched create-mode fields (never to edited schedules or user-modified fields). * fix(schedules): review batch — reconnect resubscribe, worktree prune, Android dismiss, cadence and provider edit safety - Push-router: re-send terminal and checkout-diff subscriptions after a reconnect; the old per-hook effect resubscribed on isConnected and the extracted router did not, so daemon restarts silently stopped terminals_changed pushes (root cause of the terminal-activity e2e failures). - Server: pass the run's source repo root when archiving worktree runs so the worktree is unregistered (git worktree remove/prune), not just deleted; also archive the workspace when agent creation fails even with archive-off (an agentless workspace has nothing to inspect). - Sheet: RN Modal onDismiss is iOS-only — notify dismiss once-per-close on the Android native path too; replace the JSDOM component test with a real Playwright dismiss spec and inline the trivial dismiss decision. - Form model: editing an interval schedule no longer rewrites its cadence to cron unless the cadence UI is touched (90-minute intervals have no cron equivalent); switching projects clears stale provider/model state and gates submit until the new host's snapshot resolves. * chore(lint): drop custom lint wrapper and boundary script, plain oxlint The import bans stay in .oxlintrc.json (oxlint-native no-restricted-imports). The receiver-sensitive checks the custom script enforced are not worth a parallel lint pipeline; if they come back it will be as oxlint rules. * fix(schedules): crash-safe run cleanup, capability-gated run options, resilient mutations - Persist the run's workspace/agent ids on the running-run record so a daemon crash mid-run can be recovered: restart archives the interrupted run's workspace under the same policy as normal cleanup (agentless always archives, otherwise archiveOnFinish is respected). - Hide Archive on finish (and omit archiveOnFinish/isolation from payloads) on hosts without workspaceMultiplicity — an old daemon ignores the fields, so offering the switch there would lie. - Optimistic pause/resume/delete no longer throw when the schedules cache holds a still-connecting entry alongside loaded data. - Mode field is gated on provider mode options, not a selected model, so model-less providers can pick their advertised modes.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveSchedulesScreenBodyState } from "./schedules-screen-state";
|
||||
|
||||
describe("resolveSchedulesScreenBodyState", () => {
|
||||
it("routes failed loading state to the retry UI instead of the spinner", () => {
|
||||
expect(
|
||||
resolveSchedulesScreenBodyState({
|
||||
loadState: { status: "loading" },
|
||||
showLoadError: true,
|
||||
}),
|
||||
).toEqual({ kind: "load-error" });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
import type { AggregateLoadState, AggregatedSchedule } from "@/schedules/aggregated-schedules";
|
||||
|
||||
export type SchedulesScreenBodyState =
|
||||
| { kind: "loading" }
|
||||
| { kind: "load-error" }
|
||||
| { kind: "empty" }
|
||||
| { kind: "content" };
|
||||
|
||||
export function resolveSchedulesScreenBodyState(input: {
|
||||
loadState: AggregateLoadState<AggregatedSchedule>;
|
||||
showLoadError: boolean;
|
||||
}): SchedulesScreenBodyState {
|
||||
if (input.showLoadError) {
|
||||
return { kind: "load-error" };
|
||||
}
|
||||
if (input.loadState.status === "connecting" || input.loadState.status === "loading") {
|
||||
return { kind: "loading" };
|
||||
}
|
||||
if (input.loadState.data.length === 0) {
|
||||
return { kind: "empty" };
|
||||
}
|
||||
return { kind: "content" };
|
||||
}
|
||||
@@ -8,9 +8,10 @@ import {
|
||||
} from "react";
|
||||
import { ScrollView, Text, View } from "react-native";
|
||||
import { useIsFocused } from "@react-navigation/native";
|
||||
import { Plus } from "lucide-react-native";
|
||||
import { CalendarClock, Plus } from "lucide-react-native";
|
||||
import { StyleSheet } from "react-native-unistyles";
|
||||
import { MenuHeader } from "@/components/headers/menu-header";
|
||||
import { ExternalLink } from "@/components/ui/external-link";
|
||||
import { HostFilter } from "@/components/hosts/host-filter";
|
||||
import { ALL_HOSTS_OPTION_ID } from "@/components/hosts/host-picker";
|
||||
import { ScheduleFormSheet } from "@/components/schedules/schedule-form-sheet";
|
||||
@@ -22,6 +23,7 @@ import { useAggregatedAgents } from "@/hooks/use-aggregated-agents";
|
||||
import { useProjects } from "@/hooks/use-projects";
|
||||
import {
|
||||
useSchedules,
|
||||
type AggregateLoadState,
|
||||
type AggregatedSchedule,
|
||||
type ScheduleHostError,
|
||||
} from "@/hooks/use-schedules";
|
||||
@@ -31,6 +33,7 @@ import {
|
||||
type ScheduleBucket,
|
||||
type ScheduleTargetAgent,
|
||||
} from "@/schedules/schedule-derivation";
|
||||
import { resolveSchedulesScreenBodyState } from "./schedules-screen-state";
|
||||
import {
|
||||
buildProjectNameByCwd,
|
||||
buildScheduleProjectTargets,
|
||||
@@ -47,6 +50,8 @@ const STATUS_FILTER_OPTIONS: { value: ScheduleBucket; label: string; testID: str
|
||||
{ value: "ended", label: "Ended", testID: "schedules-filter-ended" },
|
||||
];
|
||||
|
||||
const EMPTY_SCHEDULES: AggregatedSchedule[] = [];
|
||||
|
||||
export function SchedulesScreen(): ReactElement {
|
||||
const isFocused = useIsFocused();
|
||||
|
||||
@@ -58,7 +63,8 @@ export function SchedulesScreen(): ReactElement {
|
||||
}
|
||||
|
||||
function SchedulesScreenContent(): ReactElement {
|
||||
const { schedules, hostErrors, isInitialLoad, isError, refetch } = useSchedules();
|
||||
const { loadState, hostErrors, isError, refetch } = useSchedules();
|
||||
const schedules = loadState.status === "loaded" ? loadState.data : EMPTY_SCHEDULES;
|
||||
const { agents } = useAggregatedAgents({ includeArchived: true });
|
||||
const { projects } = useProjects();
|
||||
const hosts = useHosts();
|
||||
@@ -154,7 +160,7 @@ function SchedulesScreenContent(): ReactElement {
|
||||
}));
|
||||
}, [resolvedRows, selectedHost, statusFilter, hosts.length]);
|
||||
|
||||
const showLoadError = isError && schedules.length === 0;
|
||||
const showLoadError = isError && loadState.status !== "loaded";
|
||||
const showHostFilter = hosts.length > 1;
|
||||
|
||||
return (
|
||||
@@ -162,9 +168,8 @@ function SchedulesScreenContent(): ReactElement {
|
||||
<MenuHeader title="Schedules" />
|
||||
<SchedulesScreenBody
|
||||
rows={visibleRows}
|
||||
loadState={loadState}
|
||||
hostErrors={hostErrors}
|
||||
hasSchedules={schedules.length > 0}
|
||||
isInitialLoad={isInitialLoad}
|
||||
showLoadError={showLoadError}
|
||||
statusFilter={statusFilter}
|
||||
onStatusFilterChange={setStatusFilter}
|
||||
@@ -189,9 +194,8 @@ function SchedulesScreenContent(): ReactElement {
|
||||
|
||||
function SchedulesScreenBody({
|
||||
rows,
|
||||
loadState,
|
||||
hostErrors,
|
||||
hasSchedules,
|
||||
isInitialLoad,
|
||||
showLoadError,
|
||||
statusFilter,
|
||||
onStatusFilterChange,
|
||||
@@ -204,9 +208,8 @@ function SchedulesScreenBody({
|
||||
onEdit,
|
||||
}: {
|
||||
rows: ScheduleRowView[];
|
||||
loadState: AggregateLoadState<AggregatedSchedule>;
|
||||
hostErrors: ScheduleHostError[];
|
||||
hasSchedules: boolean;
|
||||
isInitialLoad: boolean;
|
||||
showLoadError: boolean;
|
||||
statusFilter: ScheduleBucket;
|
||||
onStatusFilterChange: (value: ScheduleBucket) => void;
|
||||
@@ -218,7 +221,9 @@ function SchedulesScreenBody({
|
||||
onCreate: () => void;
|
||||
onEdit: (schedule: AggregatedSchedule) => void;
|
||||
}): ReactElement {
|
||||
if (isInitialLoad) {
|
||||
const bodyState = resolveSchedulesScreenBodyState({ loadState, showLoadError });
|
||||
|
||||
if (bodyState.kind === "loading") {
|
||||
return (
|
||||
<View style={styles.centered}>
|
||||
<LoadingSpinner size="large" color={styles.spinner.color} />
|
||||
@@ -226,7 +231,7 @@ function SchedulesScreenBody({
|
||||
);
|
||||
}
|
||||
|
||||
if (showLoadError) {
|
||||
if (bodyState.kind === "load-error") {
|
||||
return (
|
||||
<View style={styles.centered}>
|
||||
<Text style={styles.message}>Unable to load schedules</Text>
|
||||
@@ -237,19 +242,27 @@ function SchedulesScreenBody({
|
||||
);
|
||||
}
|
||||
|
||||
if (!hasSchedules) {
|
||||
if (bodyState.kind === "empty") {
|
||||
return (
|
||||
<View style={styles.centered} testID="schedules-empty">
|
||||
<View style={styles.centered}>
|
||||
{hostErrors.length > 0 ? <ScheduleHostErrorsBanner errors={hostErrors} /> : null}
|
||||
<Text style={styles.message}>No schedules yet</Text>
|
||||
<Button variant="ghost" leftIcon={Plus} onPress={onCreate} testID="schedules-empty-new">
|
||||
Create a schedule
|
||||
</Button>
|
||||
<SchedulesEmptyState onCreate={onCreate} testID="schedules-empty" />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const emptyFilterText = statusFilter === "ended" ? "No ended schedules" : "No active schedules";
|
||||
let schedulesContent: ReactElement;
|
||||
if (rows.length > 0) {
|
||||
schedulesContent = <SchedulesTable rows={rows} onEditSchedule={onEdit} />;
|
||||
} else if (statusFilter === "ended") {
|
||||
schedulesContent = <SchedulesEndedEmptyState />;
|
||||
} else {
|
||||
schedulesContent = (
|
||||
<View style={styles.filterEmpty}>
|
||||
<SchedulesEmptyState onCreate={onCreate} testID="schedules-empty" />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<View style={styles.body}>
|
||||
@@ -271,7 +284,13 @@ function SchedulesScreenBody({
|
||||
testID="schedules-status-filter"
|
||||
/>
|
||||
</View>
|
||||
<Button leftIcon={Plus} onPress={onCreate} size="sm" testID="schedules-new">
|
||||
<Button
|
||||
variant="outline"
|
||||
leftIcon={Plus}
|
||||
onPress={onCreate}
|
||||
size="sm"
|
||||
testID="schedules-new"
|
||||
>
|
||||
New schedule
|
||||
</Button>
|
||||
</View>
|
||||
@@ -283,18 +302,45 @@ function SchedulesScreenBody({
|
||||
testID="schedules-list"
|
||||
>
|
||||
{hostErrors.length > 0 ? <ScheduleHostErrorsBanner errors={hostErrors} /> : null}
|
||||
{rows.length > 0 ? (
|
||||
<SchedulesTable rows={rows} onEditSchedule={onEdit} />
|
||||
) : (
|
||||
<View style={styles.filterEmpty}>
|
||||
<Text style={styles.filterEmptyText}>{emptyFilterText}</Text>
|
||||
</View>
|
||||
)}
|
||||
{schedulesContent}
|
||||
</ScrollView>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function SchedulesEmptyState({
|
||||
onCreate,
|
||||
testID,
|
||||
}: {
|
||||
onCreate: () => void;
|
||||
testID?: string;
|
||||
}): ReactElement {
|
||||
return (
|
||||
<View style={styles.emptyState} testID={testID}>
|
||||
<CalendarClock size={styles.emptyIcon.width} color={styles.emptyIcon.color} />
|
||||
<View style={styles.emptyTextStack}>
|
||||
<Text style={styles.emptyTitle}>No active schedules</Text>
|
||||
<Text style={styles.emptyDescription}>Schedules run agents on a cadence.</Text>
|
||||
<ExternalLink href="https://paseo.sh/docs/schedules" label="See docs" />
|
||||
</View>
|
||||
<Button variant="outline" leftIcon={Plus} onPress={onCreate} testID="schedules-empty-new">
|
||||
New schedule
|
||||
</Button>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function SchedulesEndedEmptyState(): ReactElement {
|
||||
return (
|
||||
<View style={styles.filterEmpty}>
|
||||
<View style={styles.endedEmptyState}>
|
||||
<CalendarClock size={styles.emptyIcon.width} color={styles.emptyIcon.color} />
|
||||
<Text style={styles.emptyTitle}>No ended schedules</Text>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
function ScheduleHostErrorsBanner({ errors }: { errors: ScheduleHostError[] }): ReactElement {
|
||||
return (
|
||||
<View style={styles.errorsBannerWrap}>
|
||||
@@ -345,6 +391,7 @@ const styles = StyleSheet.create((theme) => ({
|
||||
minHeight: 0,
|
||||
},
|
||||
scrollContent: {
|
||||
flexGrow: 1,
|
||||
gap: theme.spacing[3],
|
||||
paddingTop: theme.spacing[4],
|
||||
paddingBottom: theme.spacing[6],
|
||||
@@ -364,13 +411,36 @@ const styles = StyleSheet.create((theme) => ({
|
||||
fontSize: theme.fontSize.xs,
|
||||
},
|
||||
filterEmpty: {
|
||||
flexGrow: 1,
|
||||
paddingHorizontal: { xs: theme.spacing[3], md: theme.spacing[6] },
|
||||
paddingVertical: theme.spacing[6],
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
filterEmptyText: {
|
||||
emptyState: {
|
||||
alignItems: "center",
|
||||
gap: theme.spacing[4],
|
||||
maxWidth: 420,
|
||||
width: "100%",
|
||||
},
|
||||
endedEmptyState: {
|
||||
alignItems: "center",
|
||||
gap: theme.spacing[3],
|
||||
},
|
||||
emptyTextStack: {
|
||||
alignItems: "center",
|
||||
gap: theme.spacing[2],
|
||||
},
|
||||
emptyTitle: {
|
||||
color: theme.colors.foreground,
|
||||
fontSize: theme.fontSize.base,
|
||||
fontWeight: theme.fontWeight.normal,
|
||||
textAlign: "center",
|
||||
},
|
||||
emptyDescription: {
|
||||
color: theme.colors.foregroundMuted,
|
||||
fontSize: theme.fontSize.sm,
|
||||
textAlign: "center",
|
||||
},
|
||||
message: {
|
||||
color: theme.colors.foregroundMuted,
|
||||
@@ -382,4 +452,8 @@ const styles = StyleSheet.create((theme) => ({
|
||||
spinner: {
|
||||
color: theme.colors.foregroundMuted,
|
||||
},
|
||||
emptyIcon: {
|
||||
color: theme.colors.foregroundMuted,
|
||||
width: theme.iconSize.lg,
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -6,15 +6,19 @@ import { TerminalProfileEditModal, type ProfileDraft } from "./terminal-profile-
|
||||
|
||||
const { theme } = vi.hoisted(() => ({
|
||||
theme: {
|
||||
spacing: { 2: 8, 3: 12, 4: 16 },
|
||||
spacing: { 2: 8, 3: 12, 4: 16, 6: 24 },
|
||||
fontSize: { sm: 13, base: 15, xs: 11 },
|
||||
fontWeight: { medium: 500 },
|
||||
borderRadius: { lg: 8 },
|
||||
borderRadius: { md: 6, lg: 8, xl: 12 },
|
||||
borderWidth: { 1: 1 },
|
||||
opacity: { 50: 0.5 },
|
||||
colors: {
|
||||
surface2: "#222",
|
||||
foreground: "#fff",
|
||||
foregroundMuted: "#aaa",
|
||||
border: "#555",
|
||||
accent: "#0a84ff",
|
||||
borderAccent: "#555",
|
||||
palette: { red: { 300: "#f87171" } },
|
||||
},
|
||||
},
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useTranslation } from "react-i18next";
|
||||
import { StyleSheet } from "react-native-unistyles";
|
||||
import { AdaptiveModalSheet, type SheetHeader } from "@/components/adaptive-modal-sheet";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { FormField, FormTextInput } from "@/components/ui/form-field";
|
||||
import { Field, FormTextInput } from "@/components/ui/form-field";
|
||||
|
||||
export interface ProfileDraft {
|
||||
name: string;
|
||||
@@ -139,7 +139,7 @@ export function TerminalProfileEditModal({
|
||||
desktopMaxWidth={480}
|
||||
>
|
||||
<View style={styles.body}>
|
||||
<FormField
|
||||
<Field
|
||||
label={t("settings.host.terminalProfiles.nameLabel")}
|
||||
error={nameError}
|
||||
testID="terminal-profile-name-field"
|
||||
@@ -159,9 +159,9 @@ export function TerminalProfileEditModal({
|
||||
accessibilityLabel={t("settings.host.terminalProfiles.nameLabel")}
|
||||
testID="terminal-profile-name-input"
|
||||
/>
|
||||
</FormField>
|
||||
</Field>
|
||||
|
||||
<FormField
|
||||
<Field
|
||||
label={t("settings.host.terminalProfiles.commandLabel")}
|
||||
error={commandError}
|
||||
testID="terminal-profile-command-field"
|
||||
@@ -181,9 +181,9 @@ export function TerminalProfileEditModal({
|
||||
accessibilityLabel={t("settings.host.terminalProfiles.commandLabel")}
|
||||
testID="terminal-profile-command-input"
|
||||
/>
|
||||
</FormField>
|
||||
</Field>
|
||||
|
||||
<FormField
|
||||
<Field
|
||||
label={t("settings.host.terminalProfiles.argsLabel")}
|
||||
hint={t("settings.host.terminalProfiles.argsHint")}
|
||||
testID="terminal-profile-args-field"
|
||||
@@ -203,7 +203,7 @@ export function TerminalProfileEditModal({
|
||||
accessibilityLabel={t("settings.host.terminalProfiles.argsLabel")}
|
||||
testID="terminal-profile-args-input"
|
||||
/>
|
||||
</FormField>
|
||||
</Field>
|
||||
|
||||
{submitError ? (
|
||||
<Text style={styles.submitError} testID="terminal-profile-submit-error">
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
|
||||
import type { WorkspaceDescriptor } from "@/stores/session-store";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useReplicaQuery } from "@/data/query";
|
||||
import { workspaceTerminalsPushRoute } from "@/data/push-router";
|
||||
import {
|
||||
buildTerminalsQueryKey,
|
||||
canCreateWorkspaceTerminal,
|
||||
@@ -11,7 +13,6 @@ import {
|
||||
collectStandaloneTerminalIds,
|
||||
reconcilePendingScriptTerminals,
|
||||
removeTerminalFromPayload,
|
||||
TERMINALS_QUERY_STALE_TIME,
|
||||
type ListTerminalsPayload,
|
||||
upsertCreatedTerminalPayload,
|
||||
} from "@/screens/workspace/terminals/state";
|
||||
@@ -77,19 +78,29 @@ export function useWorkspaceTerminals(input: UseWorkspaceTerminalsInput) {
|
||||
buildTerminalsQueryKey(normalizedServerId, workspaceDirectory, normalizedWorkspaceId || null),
|
||||
[normalizedServerId, normalizedWorkspaceId, workspaceDirectory],
|
||||
);
|
||||
const paneWorkspaceId = normalizedWorkspaceId || undefined;
|
||||
|
||||
const query = useQuery({
|
||||
const query = useReplicaQuery({
|
||||
queryKey,
|
||||
enabled: canCreateNow,
|
||||
pushEvent: "terminals_changed",
|
||||
meta: workspaceTerminalsPushRoute({
|
||||
enabled: canCreateNow,
|
||||
serverId: normalizedServerId,
|
||||
cwd: workspaceDirectory ?? "",
|
||||
...(paneWorkspaceId ? { workspaceId: paneWorkspaceId } : {}),
|
||||
}),
|
||||
queryFn: async () => {
|
||||
if (!client || !workspaceDirectory) {
|
||||
throw new Error(t("workspace.terminal.hostDisconnected"));
|
||||
}
|
||||
return await client.listTerminals(workspaceDirectory, undefined, {
|
||||
workspaceId: normalizedWorkspaceId || undefined,
|
||||
});
|
||||
if (paneWorkspaceId) {
|
||||
return await client.listTerminals(workspaceDirectory, undefined, {
|
||||
workspaceId: paneWorkspaceId,
|
||||
});
|
||||
}
|
||||
return await client.listTerminals(workspaceDirectory, undefined, {});
|
||||
},
|
||||
staleTime: TERMINALS_QUERY_STALE_TIME,
|
||||
});
|
||||
const terminals = useMemo(() => query.data?.terminals ?? [], [query.data]);
|
||||
const liveTerminalIds = useMemo(() => terminals.map((terminal) => terminal.id), [terminals]);
|
||||
@@ -178,54 +189,6 @@ export function useWorkspaceTerminals(input: UseWorkspaceTerminalsInput) {
|
||||
},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!isRouteFocused || !client || !isConnected || !workspaceDirectory) {
|
||||
return;
|
||||
}
|
||||
|
||||
const paneWorkspaceId = normalizedWorkspaceId || undefined;
|
||||
|
||||
const unsubscribeChanged = client.on("terminals_changed", (message) => {
|
||||
// The terminal subscription is keyed by cwd at the protocol level, so this
|
||||
// gate only routes the event to the pane watching that cwd; it is not an
|
||||
// ownership decision.
|
||||
if (message.payload.cwd !== workspaceDirectory) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Two workspaces can share a cwd, so the push can carry terminals from a
|
||||
// sibling workspace. A terminal belongs to a workspace only by its
|
||||
// workspaceId, so keep only the ones whose workspaceId matches this pane.
|
||||
const matchingTerminals = message.payload.terminals.filter(
|
||||
(terminal) => terminal.workspaceId === paneWorkspaceId,
|
||||
);
|
||||
|
||||
queryClient.setQueryData<ListTerminalsPayload>(queryKey, (current) => ({
|
||||
cwd: message.payload.cwd,
|
||||
terminals: matchingTerminals,
|
||||
requestId: current?.requestId ?? `terminals-changed-${Date.now()}`,
|
||||
}));
|
||||
});
|
||||
|
||||
client.subscribeTerminals({
|
||||
cwd: workspaceDirectory,
|
||||
workspaceId: paneWorkspaceId,
|
||||
});
|
||||
|
||||
return () => {
|
||||
unsubscribeChanged();
|
||||
client.unsubscribeTerminals({ cwd: workspaceDirectory, workspaceId: paneWorkspaceId });
|
||||
};
|
||||
}, [
|
||||
client,
|
||||
isConnected,
|
||||
isRouteFocused,
|
||||
normalizedWorkspaceId,
|
||||
queryClient,
|
||||
queryKey,
|
||||
workspaceDirectory,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!pendingCreateInput) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user