Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(automation): 远程连接下正确显示自动化状态与下次运行 (#5479)

Dash2c406b4efb7d
diff --git a/apps/desktop/src/renderer/__tests__/automationGeneratedSessions.test.ts b/apps/desktop/src/renderer/__tests__/automationGeneratedSessions.test.ts
index 6f95053446..b631015295 100644
--- a/apps/desktop/src/renderer/__tests__/automationGeneratedSessions.test.ts
+++ b/apps/desktop/src/renderer/__tests__/automationGeneratedSessions.test.ts
@@ -411,6 +411,35 @@ describe('automation-generated sessions', () => {
expect(entries[2]).toEqual({ kind: 'session', session: sessions[3] });
});
+ it('keeps remote schedule state and the owning device on remote automation groups', () => {
+ // 侧栏把远程设备镜像的索引并入分组索引:远程组拿到暂停态 / 下次运行,
+ // 并记住所属设备,让分组操作发到那台电脑而不是本机。
+ const remoteIndex = new Map([
+ ['remote-1', makeScheduleSessionInfo({ scheduleId: 'sched-remote', scheduleName: 'Remote', scheduleStatus: 'paused', nextFireAt: 1_767_225_600_000 })],
+ ['remote-2', makeScheduleSessionInfo({ scheduleId: 'sched-remote', scheduleName: 'Remote', scheduleStatus: 'paused', nextFireAt: 1_767_225_600_000 })],
+ ]);
+ const sessions = ['remote-2', 'remote-1'].map((id) =>
+ makeSession({ id, source: 'scheduler', deviceLinkDeviceId: 'device-b' }),
+ );
+
+ const [entry] = groupAutomationSidebarEntries(sessions, {
+ notifications: new Set(),
+ scheduleSessionIndex: remoteIndex,
+ });
+
+ expect(entry).toMatchObject({
+ kind: 'automation-group',
+ group: {
+ id: 'schedule:sched-remote:device:device-b',
+ scheduleId: 'sched-remote',
+ scheduleStatus: 'paused',
+ nextFireAt: 1_767_225_600_000,
+ deviceLinkDeviceId: 'device-b',
+ title: 'Remote',
+ },
+ });
+ });
+
it('shows every recent run as its own row when expanded (primary not hidden into header)', () => {
const group = {
id: 'schedule:sched-jira',
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
index d6cb525507..aac98247f7 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
@@ -910,23 +910,41 @@ function ExpandedView({
const handleScheduleAction = useCallback(
async (group: AutomationSessionGroup, action: AutomationScheduleAction) => {
+ // 远程分组的操作发到任务所属电脑执行;本机分组仍走本机 IPC。
+ const deviceId = group.deviceLinkDeviceId;
+ const invokeSchedule = <T,>(channel: string, localCall: () => Promise<T>, id: string) =>
+ deviceId
+ ? (window.electronAPI.deviceLink.invoke(deviceId, channel, [id]) as Promise<T>)
+ : localCall();
+
if (action === 'mark-read') {
const sessionIds = group.sessions.map((session) => session.id);
- clearSessionAttentionMany(sessionIds);
- try {
- const { processed, failed } =
- await window.electronAPI.localDb.sessions.dismissPendingAlerts(sessionIds);
- clearSessionAttentionMany(processed, { intent: 'explicit' });
- if (failed.length > 0) log.warn('some pending alerts were not dismissed', failed);
- } catch (e) {
- log.warn('dismiss pending alerts failed', e);
+ // 远程分组拿不到被控端的 pending-alerts 处置通道,用户显式标已读即按 explicit
+ // 清除(对错误提醒同样生效),并经既有已读回执桥接到所属电脑。
+ clearSessionAttentionMany(sessionIds, deviceId ? { intent: 'explicit' } : undefined);
+ if (!deviceId) {
+ try {
+ const { processed, failed } =
+ await window.electronAPI.localDb.sessions.dismissPendingAlerts(sessionIds);
+ clearSessionAttentionMany(processed, { intent: 'explicit' });
+ if (failed.length > 0) log.warn('some pending alerts were not dismissed', failed);
+ } catch (e) {
+ log.warn('dismiss pending alerts failed', e);
+ }
+ void refreshPendingAlerts();
}
- void refreshPendingAlerts();
const unreadRunIds = sessionIds.flatMap(
- (sessionId) => scheduleSessionIndex.get(sessionId)?.unreadRunIds ?? [],
+ (sessionId) =>
+ (deviceId
+ ? remoteProjectsStore.getSessionScheduleInfo(sessionId)
+ : scheduleSessionIndex.get(sessionId)
+ )?.unreadRunIds ?? [],
);
if (unreadRunIds.length > 0) {
- const { processed, failed, firstError } = await markScheduleRunsReadAndSync(unreadRunIds);
+ const { processed, failed, firstError } = await markScheduleRunsReadAndSync(
+ unreadRunIds,
+ deviceId,
+ );
if (processed.length > 0) {
toast.success(t('ccAgent.layout.markedAsRead', { count: processed.length }));
}
@@ -944,12 +962,34 @@ function ExpandedView({
if (!group.scheduleId) return;
const scheduleId = group.scheduleId;
const scheduleName = group.title;
+ // 编辑页与删除确认(连同会话清理)只服务本机任务;远程分组不提供这两个入口。
+ if (deviceId && (action === 'edit' || action === 'delete')) return;
if (action === 'edit') {
navigate(`/cc-agent/scheduled?focus=${encodeURIComponent(scheduleId)}&edit=${Date.now()}`);
return;
}
+ if (action === 'run' && deviceId) {
+ // 远程运行的 fired / session-bound 来自对方电脑,不跟随跳转;新运行随侧栏刷新出现。
+ // 与本机同一个 busy guard:请求返回前重复点击不再发第二次 run-now。
+ const busyKey = `${deviceId}:${scheduleId}`;
+ if (pendingRunNowIdsRef.current.has(busyKey)) return;
+ pendingRunNowIdsRef.current.add(busyKey);
+ try {
+ await window.electronAPI.deviceLink.invoke(deviceId, 'maker:schedule:run-now', [
+ scheduleId,
+ ]);
+ } catch (e) {
+ toast.error(
+ t('scheduler.toast.runFailed', { error: e instanceof Error ? e.message : String(e) }),
+ );
+ } finally {
+ pendingRunNowIdsRef.current.delete(busyKey);
+ }
+ return;
+ }
+
if (action === 'run') {
// [必改] per-schedule busy guard:fired 事件到达前阻止同 schedule 重复调用
// runNow,避免双发 run/session,对齐 SchedulerPage 的 per-schedule busy 语义。
@@ -1020,13 +1060,19 @@ function ExpandedView({
if (action === 'toggle-pause') {
try {
if (group.scheduleStatus === 'paused') {
- await window.electronAPI.maker.schedule.resume(scheduleId);
+ await invokeSchedule(
+ 'maker:schedule:resume',
+ () => window.electronAPI.maker.schedule.resume(scheduleId),
+ scheduleId,
+ );
return;
}
if (group.scheduleStatus === 'expired') return;
- const inflight = await window.electronAPI.maker.schedule
- .getInflightCount(scheduleId)
- .catch(() => 0);
+ const inflight = await invokeSchedule(
+ 'maker:schedule:get-inflight-count',
+ () => window.electronAPI.maker.schedule.getInflightCount(scheduleId),
+ scheduleId,
+ ).catch(() => 0);
if (inflight > 0) {
const ok = await confirmDialog({
title: t('scheduler.confirm.pause.title', { name: scheduleName }),
@@ -1036,7 +1082,11 @@ function ExpandedView({
});
if (!ok) return;
}
- await window.electronAPI.maker.schedule.pause(scheduleId);
+ await invokeSchedule(
+ 'maker:schedule:pause',
+ () => window.electronAPI.maker.schedule.pause(scheduleId),
+ scheduleId,
+ );
} catch (e) {
toast.error(
t('scheduler.toast.actionFailed', {
@@ -1142,6 +1192,15 @@ function ExpandedView({
}
return next;
}, [scheduleSessionIndex, remoteScheduleIndex]);
+ // 自动化分组按任务所属电脑取索引:远程会话用该设备镜像的状态、下次运行与操作身份,
+ // 本机会话仍以本机索引为准(session id 全局唯一,两份不会互相覆盖真实条目)。
+ const automationGroupingIndex = useMemo(
+ () =>
+ remoteScheduleIndex.size === 0
+ ? scheduleSessionIndex
+ : new Map([...remoteScheduleIndex, ...scheduleSessionIndex]),
+ [scheduleSessionIndex, remoteScheduleIndex],
+ );
const sidebarNotifications = useMemo(() => {
if (unreadScheduleSessionIds.size === 0) return notifications;
return new Set([...notifications, ...unreadScheduleSessionIds]);
@@ -3741,7 +3800,7 @@ function ExpandedView({
runningSessionIds={displayRunningSessionIds}
attachedSessionIds={attachedSessionIds}
notifications={sidebarNotifications}
- scheduleSessionIndex={scheduleSessionIndex}
+ scheduleSessionIndex={automationGroupingIndex}
selectedSessionIds={selectedSessionIds}
disableSessionCollapse={false}
onToggle={collapse.toggle}
@@ -3797,7 +3856,7 @@ function ExpandedView({
runningSessionIds={displayRunningSessionIds}
attachedSessionIds={attachedSessionIds}
notifications={sidebarNotifications}
- scheduleSessionIndex={scheduleSessionIndex}
+ scheduleSessionIndex={automationGroupingIndex}
selectedSessionIds={selectedSessionIds}
onSessionClick={handleSessionClick}
onAction={handleActionClick}
@@ -3894,7 +3953,7 @@ function ExpandedView({
runningSessionIds={displayRunningSessionIds}
attachedSessionIds={attachedSessionIds}
notifications={sidebarNotifications}
- scheduleSessionIndex={scheduleSessionIndex}
+ scheduleSessionIndex={automationGroupingIndex}
selectedSessionIds={selectedSessionIds}
onSessionClick={handleSessionClick}
onAction={handleActionClick}
diff --git a/apps/desktop/src/renderer/features/cc-agent/lib/automationSidebarGrouping.ts b/apps/desktop/src/renderer/features/cc-agent/lib/automationSidebarGrouping.ts
index 1e867adfac..e6a7de2825 100644
--- a/apps/desktop/src/renderer/features/cc-agent/lib/automationSidebarGrouping.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/lib/automationSidebarGrouping.ts
@@ -58,6 +58,8 @@ export interface AutomationSessionGroup {
nextFireAt?: number;
workingDir?: string;
projectConfigId?: string;
+ /** 远程设备上的自动化分组(组键已按设备作用域隔离,组内会话同属这台设备)。 */
+ deviceLinkDeviceId?: string;
title: string;
sessions: Session[];
attentionSessionIds: string[];
@@ -164,6 +166,7 @@ export function groupAutomationSidebarEntries(
nextFireAt: groupInfo.nextFireAt,
workingDir: groupInfo.workingDir,
projectConfigId: groupInfo.projectConfigId,
+ ...(session.deviceLinkDeviceId ? { deviceLinkDeviceId: session.deviceLinkDeviceId } : {}),
title: groupInfo.title,
sessions: [session],
attentionSessionIds: options.notifications.has(session.id) ? [session.id] : [],
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/AutomationSessionGroupItem.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/AutomationSessionGroupItem.tsx
index 184fce61d4..462a0a961b 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/AutomationSessionGroupItem.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/AutomationSessionGroupItem.tsx
@@ -210,6 +210,11 @@ export const AutomationSessionGroupItem = withSidebarNavigation<AutomationSessio
}, [collapsedAttention, group.sessions, groupRemotePhases, notifications, groupAttentionKinds]);
// 与组头红/绿未读点同源:没有未读就不提供「标为已读」,避免空操作占菜单。
const canMarkRead = collapsedAttention.tone != null;
+ // 远程分组只提供在对方电脑上执行的操作(运行、暂停 / 恢复、标为已读);编辑页与删除
+ // 确认只管本机任务,查看入口也不能拿远程 id 去聚焦本机自动化页。
+ const isRemoteGroup = !!group.deviceLinkDeviceId;
+ // 远程且已结束、又没有未读时,菜单里没有可执行项,不显示「更多」。
+ const hasMoreMenuItems = !isRemoteGroup || canMarkRead || group.scheduleStatus !== 'expired';
// childView 的 24h 豁免依赖实时 now,必须每次渲染直接算,不能进 useMemo —— 否则依赖项
// 不变时时间窗口会被冻结,跨过 24h 阈值的运行不会及时移出豁免。与普通对话列表
// SessionEntryList 一致(它也是 render 内直接算 getSessionListCollapseView、不 memo);
@@ -543,7 +548,7 @@ export const AutomationSessionGroupItem = withSidebarNavigation<AutomationSessio
onClick={(event) => {
event.stopPropagation();
navigate(
- group.scheduleId
+ group.scheduleId && !isRemoteGroup
? scheduleFocusPath(group.scheduleId)
: '/cc-agent/scheduled',
);
@@ -750,78 +755,89 @@ export const AutomationSessionGroupItem = withSidebarNavigation<AutomationSessio
<Play size={14} strokeWidth={2} />
</button>
</Tip>
- <DropdownMenu open={menuOpen} onOpenChange={setMenuOpen}>
- <DropdownMenuTrigger asChild>
- <Tip text={t('ccAgent.sidebar.automationGroup.menu.more')} side="bottom">
- <button
- type="button"
- data-automation-group-inline-action="true"
- onClick={(event) => {
- event.stopPropagation();
- event.currentTarget.blur();
- }}
- onPointerDown={(event) => event.stopPropagation()}
- aria-label={t('ccAgent.sidebar.automationGroup.menu.more')}
- className={cn(
- 'flex size-5 shrink-0 items-center justify-center rounded-md',
- 'transition-colors',
- actionButtonToneClassName,
- )}
+ {hasMoreMenuItems && (
+ <DropdownMenu open={menuOpen} onOpenChange={setMenuOpen}>
+ <DropdownMenuTrigger asChild>
+ <Tip
+ text={t('ccAgent.sidebar.automationGroup.menu.more')}
+ side="bottom"
>
- <EllipsisVertical size={14} strokeWidth={2} />
- </button>
- </Tip>
- </DropdownMenuTrigger>
- <DropdownMenuContent
- align="end"
- sideOffset={2}
- onClick={(event) => event.stopPropagation()}
- className="min-w-36 overflow-hidden"
- >
- <MountedMenuContent>
- {() => (
- <>
- {canMarkRead && (
- <DropdownMenuItem
- onSelect={() => onScheduleAction(group, 'mark-read')}
- className={MENU_ITEM_CLASS}
- >
- {t('ccAgent.sidebar.automationGroup.menu.markAllAsRead')}
- </DropdownMenuItem>
- )}
- <DropdownMenuItem
- onSelect={() => onScheduleAction(group, 'edit')}
- className={MENU_ITEM_CLASS}
- >
- {t('ccAgent.sidebar.automationGroup.menu.edit')}
- </DropdownMenuItem>
- {group.scheduleStatus !== 'expired' && (
- <DropdownMenuItem
- onSelect={() => onScheduleAction(group, 'toggle-pause')}
- className={MENU_ITEM_CLASS}
- >
- {group.scheduleStatus === 'paused'
- ? t('ccAgent.sidebar.automationGroup.menu.resume')
- : t('ccAgent.sidebar.automationGroup.menu.pause')}
- </DropdownMenuItem>
+ <button
+ type="button"
+ data-automation-group-inline-action="true"
+ onClick={(event) => {
+ event.stopPropagation();
+ event.currentTarget.blur();
+ }}
+ onPointerDown={(event) => event.stopPropagation()}
+ aria-label={t('ccAgent.sidebar.automationGroup.menu.more')}
+ className={cn(
+ 'flex size-5 shrink-0 items-center justify-center rounded-md',
+ 'transition-colors',
+ actionButtonToneClassName,
)}
- <DropdownMenuSeparator />
- <DropdownMenuItem
- onSelect={() => onScheduleAction(group, 'delete')}
- disabled={
- group.scheduleSource === 'project' &&
- (!group.workingDir || !group.projectConfigId)
- }
- variant="danger"
- className={MENU_ITEM_CLASS}
- >
- {t('ccAgent.sidebar.automationGroup.menu.delete')}
- </DropdownMenuItem>
- </>
- )}
- </MountedMenuContent>
- </DropdownMenuContent>
- </DropdownMenu>
+ >
+ <EllipsisVertical size={14} strokeWidth={2} />
+ </button>
+ </Tip>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent
+ align="end"
+ sideOffset={2}
+ onClick={(event) => event.stopPropagation()}
+ className="min-w-36 overflow-hidden"
+ >
+ <MountedMenuContent>
+ {() => (
+ <>
+ {canMarkRead && (
+ <DropdownMenuItem
+ onSelect={() => onScheduleAction(group, 'mark-read')}
+ className={MENU_ITEM_CLASS}
+ >
+ {t('ccAgent.sidebar.automationGroup.menu.markAllAsRead')}
+ </DropdownMenuItem>
+ )}
+ {!isRemoteGroup && (
+ <DropdownMenuItem
+ onSelect={() => onScheduleAction(group, 'edit')}
+ className={MENU_ITEM_CLASS}
+ >
+ {t('ccAgent.sidebar.automationGroup.menu.edit')}
+ </DropdownMenuItem>
+ )}
+ {group.scheduleStatus !== 'expired' && (
+ <DropdownMenuItem
+ onSelect={() => onScheduleAction(group, 'toggle-pause')}
+ className={MENU_ITEM_CLASS}
+ >
+ {group.scheduleStatus === 'paused'
+ ? t('ccAgent.sidebar.automationGroup.menu.resume')
+ : t('ccAgent.sidebar.automationGroup.menu.pause')}
+ </DropdownMenuItem>
+ )}
+ {!isRemoteGroup && (
+ <>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem
+ onSelect={() => onScheduleAction(group, 'delete')}
+ disabled={
+ group.scheduleSource === 'project' &&
+ (!group.workingDir || !group.projectConfigId)
+ }
+ variant="danger"
+ className={MENU_ITEM_CLASS}
+ >
+ {t('ccAgent.sidebar.automationGroup.menu.delete')}
+ </DropdownMenuItem>
+ </>
+ )}
+ </>
+ )}
+ </MountedMenuContent>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )}
</div>
</>
)}
diff --git a/apps/desktop/src/renderer/features/device-link/useDeviceLinkRemoteProjects.ts b/apps/desktop/src/renderer/features/device-link/useDeviceLinkRemoteProjects.ts
index d126b92293..1a4dd98735 100644
--- a/apps/desktop/src/renderer/features/device-link/useDeviceLinkRemoteProjects.ts
+++ b/apps/desktop/src/renderer/features/device-link/useDeviceLinkRemoteProjects.ts
@@ -34,6 +34,7 @@ import { evictTaskTagCatalog } from '../task-tags/taskTagEvents';
import { useEffect, useRef } from 'react';
import { isSharedTaskPeer } from '@cindy/device-link';
+import { projectScheduleEvent } from '@cindy/maker-shared/schedule-events';
import { useAuth } from '@/contexts/AuthContext';
import { isDeviceLinkRemotePushCurrent } from '@/lib/remoteDataOwnerPushFence';
import { createLogger } from '@/lib/logger';
@@ -792,6 +793,10 @@ export function useDeviceLinkRemoteProjects(
const watching =
periodicReconcileActiveRef.current && (mainPresenceRef.current?.isActive() ?? true);
if (!watching) return;
+ // 与手机同一份事件投影:运行诊断、静默提醒这类不改索引的事件不重拉,
+ // 否则 run 进行期间高频推送会反复取消在途的列表 / 索引读取。
+ const { refresh } = projectScheduleEvent(push.payload);
+ if (!refresh.sessionIndex && !refresh.scheduleList && !refresh.unreadSummary) return;
void refreshRemoteDeviceSessions(push.deviceId, eligible.get(push.deviceId), { scope: 'schedule' }).then((result) => {
if (result === 'revoked' && !disposed) handleRevoked(push.deviceId);
});
diff --git a/apps/mobile/src/__tests__/automationGroupPreview.test.ts b/apps/mobile/src/__tests__/automationGroupPreview.test.ts
new file mode 100644
index 0000000000..a067a694c8
--- /dev/null
+++ b/apps/mobile/src/__tests__/automationGroupPreview.test.ts
@@ -0,0 +1,60 @@
+import { describe, expect, it } from 'vitest';
+import type { TFunction } from 'i18next';
+import type { RemoteSessionListItem, RemoteSessionScheduleInfo } from '@cindy/maker-shared/session-list';
+import { automationGroupPreview } from '../session/automationGroupPreview';
+
+const NOW = Date.UTC(2026, 9, 5, 9, 52);
+const t = ((key: string, options?: { count?: number }) =>
+ options?.count === undefined ? key : `${key}(${options.count})`) as unknown as TFunction;
+
+function group(info: Partial<RemoteSessionScheduleInfo> | null, pendingInteractionCount = 0): RemoteSessionListItem {
+ return {
+ pendingInteractionCount,
+ scheduleInfo: info
+ ? {
+ scheduleId: 'sched-1',
+ scheduleName: 'Daily',
+ scheduleStatus: 'active',
+ unreadRunIds: [],
+ unreadCount: 0,
+ running: false,
+ latestRunAt: NOW - 60_000,
+ ...info,
+ }
+ : undefined,
+ } as RemoteSessionListItem;
+}
+
+describe('automationGroupPreview', () => {
+ it('keeps attention, waiting and running ahead of the countdown', () => {
+ const nextFireAt = NOW + 5 * 60_000;
+ expect(automationGroupPreview(group({ unreadCount: 2, nextFireAt }, 1), 12, t, NOW))
+ .toBe('devices.list.preview.needAttention(2) · devices.list.preview.waiting(1)');
+ expect(automationGroupPreview(group({ running: true, nextFireAt }), 12, t, NOW))
+ .toBe('devices.list.preview.automationRunning');
+ });
+
+ it('shows the next run with the desktop floor rounding', () => {
+ const at = (ms: number) => automationGroupPreview(group({ nextFireAt: NOW + ms }), 12, t, NOW);
+ expect(at(5 * 60_000 + 59_000)).toBe('devices.list.preview.nextRunMinutes(5) · devices.list.preview.runCount(12)');
+ expect(at(3 * 3_600_000 + 59 * 60_000)).toBe('devices.list.preview.nextRunHours(3) · devices.list.preview.runCount(12)');
+ expect(at(3 * 86_400_000 + 1)).toBe('devices.list.preview.nextRunDays(3) · devices.list.preview.runCount(12)');
+ });
+
+ it('says the run is imminent within a minute or once the host time has passed', () => {
+ expect(automationGroupPreview(group({ nextFireAt: NOW + 30_000 }), 3, t, NOW))
+ .toBe('devices.list.preview.imminent · devices.list.preview.runCount(3)');
+ expect(automationGroupPreview(group({ nextFireAt: NOW - 30_000 }), 3, t, NOW))
+ .toBe('devices.list.preview.imminent · devices.list.preview.runCount(3)');
+ });
+
+ it('marks stopped groups with the same rule as the paused timer badge', () => {
+ expect(automationGroupPreview(group({ scheduleStatus: 'paused', allSchedulesStopped: true, nextFireAt: NOW + 60_000 }), 23, t, NOW))
+ .toBe('devices.list.preview.stopped · devices.list.preview.runCount(23)');
+ });
+
+ it('falls back to the run count for manual tasks, unknown times and older hosts', () => {
+ expect(automationGroupPreview(group({}), 3, t, NOW)).toBe('devices.list.preview.totalRuns(3)');
+ expect(automationGroupPreview(group(null), 3, t, NOW)).toBe('devices.list.preview.totalRuns(3)');
+ });
+});
diff --git a/apps/mobile/src/__tests__/homeDesktopFirst.test.ts b/apps/mobile/src/__tests__/homeDesktopFirst.test.ts
index 14f9413252..05260a63d3 100644
--- a/apps/mobile/src/__tests__/homeDesktopFirst.test.ts
+++ b/apps/mobile/src/__tests__/homeDesktopFirst.test.ts
@@ -584,7 +584,7 @@ describe('mobile home desktop-first surface', () => {
expect(sessionRowSource).toContain('buildRemoteSessionCardPreview(');
expect(sessionRowSource).toContain('useRemoteSessionMessagePreview(item.session.id)');
expect(sessionRowSource).toContain('testID={`home.sessionRowPreview.${item.session.id}`}');
- expect(sessionRowSource).toContain('const showPreviewLine = !!preview?.trim() || showSchedule || showPinned;');
+ expect(sessionRowSource).toContain('const showPreviewLine = !!group || !!preview?.trim() || showSchedule || showPinned;');
expect(sessionRowSource).toContain('!showPreviewLine && styles.sessionListRowSingleLine');
expect(sessionRowSource).toContain('!showPreviewLine && styles.sessionIconCellSingleLine');
expect(sessionRowSource).toContain('{showPreviewLine ? (');
diff --git a/apps/mobile/src/__tests__/mobileHomeSharedTasks.test.ts b/apps/mobile/src/__tests__/mobileHomeSharedTasks.test.ts
index c538be4b6c..a13d102aa0 100644
--- a/apps/mobile/src/__tests__/mobileHomeSharedTasks.test.ts
+++ b/apps/mobile/src/__tests__/mobileHomeSharedTasks.test.ts
@@ -139,7 +139,7 @@ describe('shared role row wiring', () => {
});
it('uses a fixed title-side role slot and only renders a crown for owners', () => {
- expect(source).toContain('const showPreviewLine = !!preview?.trim() || showSchedule || showPinned;');
+ expect(source).toContain('const showPreviewLine = !!group || !!preview?.trim() || showSchedule || showPinned;');
const row = source.slice(source.indexOf('function HomeSessionRowInner('), source.indexOf('function AutomationGroupChildren('));
const roleSlot = row.indexOf('testID={`home.sharedRoleSlot.owned.${item.session.id}`}');
expect(roleSlot).toBeGreaterThan(row.indexOf('<SessionStatusMark'));
diff --git a/apps/mobile/src/__tests__/remoteScheduleEvents.test.ts b/apps/mobile/src/__tests__/remoteScheduleEvents.test.ts
index c8ee80bb08..4c72f11255 100644
--- a/apps/mobile/src/__tests__/remoteScheduleEvents.test.ts
+++ b/apps/mobile/src/__tests__/remoteScheduleEvents.test.ts
@@ -54,14 +54,16 @@ describe('remote schedule event store', () => {
expect(remoteScheduleEventStore.getSnapshot('dev-1')).toMatchObject({
runsVersion: 2,
scheduleListVersion: 1,
- sessionIndexVersion: 1,
+ // changed 与 fired 都会重拉侧栏索引(fired:认领清空了下次运行时间并插入运行中)。
+ sessionIndexVersion: 2,
unreadVersion: 1,
version: 2,
});
expect(remoteScheduleEventStore.getSnapshot('dev-2')).toMatchObject({
runsVersion: 0,
scheduleListVersion: 1,
- sessionIndexVersion: 0,
+ // ready:宿主冷启 / 切账号后重标中断、重算下次运行,索引一并重拉。
+ sessionIndexVersion: 1,
unreadVersion: 0,
version: 1,
});
@@ -143,7 +145,7 @@ describe('remote schedule event store', () => {
expect(remoteScheduleEventStore.getSnapshot('dev-1')).toMatchObject({
runsVersion: 1,
scheduleListVersion: 0,
- sessionIndexVersion: 0,
+ sessionIndexVersion: 1,
unreadVersion: 0,
});
@@ -156,7 +158,7 @@ describe('remote schedule event store', () => {
expect(remoteScheduleEventStore.getSnapshot('dev-1')).toMatchObject({
runsVersion: 2,
scheduleListVersion: 0,
- sessionIndexVersion: 1,
+ sessionIndexVersion: 2,
unreadVersion: 1,
});
expect(remoteScheduleEventStore.getSnapshot('dev-1').lastProjection).toMatchObject({
@@ -172,7 +174,7 @@ describe('remote schedule event store', () => {
remoteScheduleEventStore.apply('dev-1', { type: 'all-read' });
expect(remoteScheduleEventStore.getSnapshot('dev-1')).toMatchObject({
runsVersion: 3,
- sessionIndexVersion: 2,
+ sessionIndexVersion: 3,
unreadVersion: 2,
});
expect(remoteScheduleEventStore.getSnapshot('dev-1').lastProjection?.refresh.runRefresh).toEqual({ mode: 'all' });
diff --git a/apps/mobile/src/i18n/locales/en/devices.json b/apps/mobile/src/i18n/locales/en/devices.json
index 1cb85aaac9..bd90851f26 100644
--- a/apps/mobile/src/i18n/locales/en/devices.json
+++ b/apps/mobile/src/i18n/locales/en/devices.json
@@ -427,7 +427,13 @@
"needAttention": "{{count}} need attention",
"waiting": "{{count}} waiting",
"automationRunning": "Automation running",
- "totalRuns": "{{count}} runs total"
+ "totalRuns": "{{count}} runs total",
+ "runCount": "{{count}} runs",
+ "nextRunMinutes": "Runs in {{count}}m",
+ "nextRunHours": "Runs in {{count}}h",
+ "nextRunDays": "Runs in {{count}}d",
+ "imminent": "Running soon",
+ "stopped": "Stopped"
}
},
"detail": {
diff --git a/apps/mobile/src/i18n/locales/ja/devices.json b/apps/mobile/src/i18n/locales/ja/devices.json
index 6a3644b604..4ac5e749e3 100644
--- a/apps/mobile/src/i18n/locales/ja/devices.json
+++ b/apps/mobile/src/i18n/locales/ja/devices.json
@@ -427,7 +427,13 @@
"needAttention": "要対応 {{count}} 件",
"waiting": "対応待ち {{count}} 件",
"automationRunning": "自動化を実行中",
- "totalRuns": "全 {{count}} 回の実行"
+ "totalRuns": "全 {{count}} 回の実行",
+ "runCount": "全 {{count}} 回",
+ "nextRunMinutes": "{{count}} 分後に実行",
+ "nextRunHours": "{{count}} 時間後に実行",
+ "nextRunDays": "{{count}} 日後に実行",
+ "imminent": "まもなく実行",
+ "stopped": "停止中"
}
},
"detail": {
diff --git a/apps/mobile/src/i18n/locales/ko/devices.json b/apps/mobile/src/i18n/locales/ko/devices.json
index 10e90388f7..4a8d2a8444 100644
--- a/apps/mobile/src/i18n/locales/ko/devices.json
+++ b/apps/mobile/src/i18n/locales/ko/devices.json
@@ -427,7 +427,13 @@
"needAttention": "확인 필요 {{count}}개",
"waiting": "확인 대기 {{count}}개",
"automationRunning": "자동화 실행 중",
- "totalRuns": "총 {{count}}회 실행"
+ "totalRuns": "총 {{count}}회 실행",
+ "runCount": "총 {{count}}회",
+ "nextRunMinutes": "{{count}}분 후 실행",
+ "nextRunHours": "{{count}}시간 후 실행",
+ "nextRunDays": "{{count}}일 후 실행",
+ "imminent": "곧 실행",
+ "stopped": "중지됨"
}
},
"detail": {
diff --git a/apps/mobile/src/i18n/locales/zh-CN/devices.json b/apps/mobile/src/i18n/locales/zh-CN/devices.json
index fa37078d2d..2838687bb6 100644
--- a/apps/mobile/src/i18n/locales/zh-CN/devices.json
+++ b/apps/mobile/src/i18n/locales/zh-CN/devices.json
@@ -427,7 +427,13 @@
"needAttention": "{{count}} 个需关注",
"waiting": "等待处理 {{count}} 个",
"automationRunning": "自动化运行中",
- "totalRuns": "共 {{count}} 次运行"
+ "totalRuns": "共 {{count}} 次运行",
+ "runCount": "共 {{count}} 次",
+ "nextRunMinutes": "{{count}} 分钟后运行",
+ "nextRunHours": "{{count}} 小时后运行",
+ "nextRunDays": "{{count}} 天后运行",
+ "imminent": "即将运行",
+ "stopped": "已停止"
}
},
"detail": {
diff --git a/apps/mobile/src/i18n/locales/zh-TW/devices.json b/apps/mobile/src/i18n/locales/zh-TW/devices.json
index 9122f8f040..873135b79e 100644
--- a/apps/mobile/src/i18n/locales/zh-TW/devices.json
+++ b/apps/mobile/src/i18n/locales/zh-TW/devices.json
@@ -427,7 +427,13 @@
"needAttention": "{{count}} 個需關注",
"waiting": "等待處理 {{count}} 個",
"automationRunning": "自動化執行中",
- "totalRuns": "共 {{count}} 次執行"
+ "totalRuns": "共 {{count}} 次執行",
+ "runCount": "共 {{count}} 次",
+ "nextRunMinutes": "{{count}} 分鐘後執行",
+ "nextRunHours": "{{count}} 小時後執行",
+ "nextRunDays": "{{count}} 天後執行",
+ "imminent": "即將執行",
+ "stopped": "已停止"
}
},
"detail": {
diff --git a/apps/mobile/src/session/HomeSurface.tsx b/apps/mobile/src/session/HomeSurface.tsx
index 177aa552e5..13daf90e3a 100644
--- a/apps/mobile/src/session/HomeSurface.tsx
+++ b/apps/mobile/src/session/HomeSurface.tsx
@@ -247,6 +247,7 @@ import { mapContentEqual } from '@/utils/valueEquality';
import { homeRowPropsEqual } from './homeRowPropsEqual';
import { useStableValue } from '@/utils/useStableValue';
import { useMinuteNow } from '@/utils/useMinuteNow';
+import { automationGroupPreview } from '@/session/automationGroupPreview';
import {
getScheduleIndexInvalidationVersion,
invalidateOfflineScheduleIndexFailureFor,
@@ -4232,9 +4233,10 @@ function HomeSessionRowInner({
// (收起时块底线紧贴行底,展开时组头与子行之间保持连续无线,均与项目组语义一致)。
const blockMode = asBlock && !!group;
// 预览走共享 buildRemoteSessionCardPreview(已并入 #368 的 liveActivity),运行中会显示实时活动;
- // 组行的预览位改为任务态摘要(需关注数 / 执行中 / 共 N 次运行),对齐桌面版组头 meta。
+ // 组行的预览位改为任务态摘要(需关注数 / 执行中 / 已停止 / 下次运行倒计时 / 共 N 次运行),
+ // 由 AutomationGroupPreviewText 叶子组件渲染。
const preview = group
- ? automationGroupPreview(item, group.sessionCount, t)
+ ? null
: buildRemoteSessionCardPreview(
loadedMessagePreview === undefined || loadedMessagePreview === item.messagePreview
? item
@@ -4243,7 +4245,7 @@ function HomeSessionRowInner({
);
// 零消息会话没有摘要。此时不要保留双行列表的空白第二行;定时任务与置顶
// 标记仍占用右下状态槽,因此继续使用双行布局。共享身份位于标题左侧。
- const showPreviewLine = !!preview?.trim() || showSchedule || showPinned;
+ const showPreviewLine = !!group || !!preview?.trim() || showSchedule || showPinned;
// 组行点击语义对齐桌面版侧边栏:收起且有需关注内容(未读运行 / 待处理)时,点行直接打开
// 该看的那条会话(共享层 primary:运行中 > 有未读 > 最新);想展开点行首箭头(独立热区)。
// 无需关注内容或已展开时,点行仍是展开 / 收起。
@@ -4408,14 +4410,23 @@ function HomeSessionRowInner({
</View>
{showPreviewLine ? (
<View style={styles.sessionPreviewRow}>
- <Text
- ellipsizeMode="tail"
- numberOfLines={1}
- style={styles.sessionPreview}
- testID={`home.sessionRowPreview.${item.session.id}`}
- >
- {preview}
- </Text>
+ {group ? (
+ <AutomationGroupPreviewText
+ item={item}
+ sessionCount={group.sessionCount}
+ style={styles.sessionPreview}
+ testID={`home.sessionRowPreview.${item.session.id}`}
+ />
+ ) : (
+ <Text
+ ellipsizeMode="tail"
+ numberOfLines={1}
+ style={styles.sessionPreview}
+ testID={`home.sessionRowPreview.${item.session.id}`}
+ >
+ {preview}
+ </Text>
+ )}
{showSchedule || showPinned ? (
// 组行与单次自动化会话行同款标记:Timer 放右下(时间下方的尾部图标位),
// 行首保留正常的会话状态图标(primary 运行的 vendor / 运行态)。
@@ -4583,18 +4594,24 @@ function AutomationGroupChildren({
);
}
-/** 自动化组行的预览位文案:需关注数 > 执行中 > 共 N 次运行(对齐桌面版组头 meta 的优先级)。 */
-function automationGroupPreview(item: RemoteSessionListItem, sessionCount: number, t: TFunction): string {
- const unread = item.scheduleInfo?.unreadCount ?? 0;
- const waiting = item.pendingInteractionCount;
- if (unread > 0 || waiting > 0) {
- return [
- unread > 0 ? t('devices.list.preview.needAttention', { count: unread }) : null,
- waiting > 0 ? t('devices.list.preview.waiting', { count: waiting }) : null,
- ].filter(Boolean).join(' · ');
- }
- if (item.scheduleInfo?.running) return t('devices.list.preview.automationRunning');
- return t('devices.list.preview.totalRuns', { count: sessionCount });
+/**
+ * 自动化组行预览位(文案规则见 automationGroupPreview)。与 SessionRelativeTime 同理下沉为
+ * 叶子组件订阅分钟心跳:倒计时每分钟前进,行主体不跟着重渲染。now 取渲染时刻,
+ * 心跳只负责触发,避免模块级快照在无订阅期间过期。
+ */
+function AutomationGroupPreviewText({ item, sessionCount, style, testID }: {
+ item: RemoteSessionListItem;
+ sessionCount: number;
+ style: StyleProp<TextStyle>;
+ testID: string;
+}) {
+ const { t } = useTranslation();
+ useMinuteNow();
+ return (
+ <Text ellipsizeMode="tail" numberOfLines={1} style={style} testID={testID}>
+ {automationGroupPreview(item, sessionCount, t, Date.now())}
+ </Text>
+ );
}
// 状态提醒点已移到行右侧(替代时间位,与桌面一致),行首图标只保留 vendor 标识 +
diff --git a/apps/mobile/src/session/automationGroupPreview.ts b/apps/mobile/src/session/automationGroupPreview.ts
new file mode 100644
index 0000000000..cfd6f5287e
--- /dev/null
+++ b/apps/mobile/src/session/automationGroupPreview.ts
@@ -0,0 +1,47 @@
+import type { TFunction } from 'i18next';
+import type { RemoteSessionListItem } from '@/session/sessionList';
+
+const MINUTE_MS = 60_000;
+const HOUR_MS = 60 * MINUTE_MS;
+const DAY_MS = 24 * HOUR_MS;
+
+/**
+ * 首页自动化组行第二行的任务态摘要。优先级:需关注 / 等待处理 > 执行中 > 已停止 >
+ * 下次运行倒计时 > 共 N 次运行。倒计时与桌面组头同一取整(向下取整到分 / 时 / 天),
+ * 不足一分钟或宿主已到点尚未认领时显示「即将运行」。
+ */
+export function automationGroupPreview(
+ item: RemoteSessionListItem,
+ sessionCount: number,
+ t: TFunction,
+ now: number,
+): string {
+ const info = item.scheduleInfo;
+ const unread = info?.unreadCount ?? 0;
+ const waiting = item.pendingInteractionCount;
+ if (unread > 0 || waiting > 0) {
+ return [
+ unread > 0 ? t('devices.list.preview.needAttention', { count: unread }) : null,
+ waiting > 0 ? t('devices.list.preview.waiting', { count: waiting }) : null,
+ ].filter(Boolean).join(' · ');
+ }
+ if (info?.running) return t('devices.list.preview.automationRunning');
+ const runCount = t('devices.list.preview.runCount', { count: sessionCount });
+ // 与右下 Timer 暂停角标同一判据:组内所有绑定都已暂停 / 结束才算停止。
+ if (info?.allSchedulesStopped) return `${t('devices.list.preview.stopped')} · ${runCount}`;
+ if (info?.scheduleStatus === 'active' && typeof info.nextFireAt === 'number') {
+ return `${nextRunText(info.nextFireAt - now, t)} · ${runCount}`;
+ }
+ return t('devices.list.preview.totalRuns', { count: sessionCount });
+}
+
+function nextRunText(diffMs: number, t: TFunction): string {
+ if (diffMs < MINUTE_MS) return t('devices.list.preview.imminent');
+ if (diffMs < HOUR_MS) {
+ return t('devices.list.preview.nextRunMinutes', { count: Math.floor(diffMs / MINUTE_MS) });
+ }
+ if (diffMs < DAY_MS) {
+ return t('devices.list.preview.nextRunHours', { count: Math.floor(diffMs / HOUR_MS) });
+ }
+ return t('devices.list.preview.nextRunDays', { count: Math.floor(diffMs / DAY_MS) });
+}
diff --git a/apps/mobile/src/session/scheduleIndex.ts b/apps/mobile/src/session/scheduleIndex.ts
index 379abd38fa..a3b6b0378e 100644
--- a/apps/mobile/src/session/scheduleIndex.ts
+++ b/apps/mobile/src/session/scheduleIndex.ts
@@ -354,6 +354,7 @@ function scheduleInfoEqual(a: RemoteSessionScheduleInfo, b: RemoteSessionSchedul
&& a.running === b.running
&& a.latestRunAt === b.latestRunAt
&& a.scheduleStatus === b.scheduleStatus
+ && a.nextFireAt === b.nextFireAt
&& a.allSchedulesStopped === b.allSchedulesStopped
&& stringListsEqual(a.unreadRunIds, b.unreadRunIds);
}
@@ -390,7 +391,7 @@ function buildLightweightSessionScheduleIndex(raw: LightweightScheduleSnapshot,
if (!value || typeof value !== 'object') throw new Error('Invalid schedule index row');
const row = value as Record<string, unknown>;
if (typeof row.scheduleId !== 'string' || typeof row.runId !== 'string' || typeof row.scheduleName !== 'string') throw new Error('Invalid schedule index row');
- const schedule = normalizeScheduleList([{ id: row.scheduleId, name: row.scheduleName, status: row.scheduleStatus }])[0];
+ const schedule = normalizeScheduleList([{ id: row.scheduleId, name: row.scheduleName, status: row.scheduleStatus, nextFireAt: row.nextFireAt }])[0];
// The host omits older running rows' binding to preserve latest ownership.
// Restore only that missing input; the shared builder still owns binding and recency rules.
const sessionId = row.sessionId || (row.status === 'running' ? inflightSessions.get(row.runId) : undefined);
diff --git a/packages/maker-shared/src/__tests__/scheduleEvents.test.ts b/packages/maker-shared/src/__tests__/scheduleEvents.test.ts
index 7222ed5b9b..780458a030 100644
--- a/packages/maker-shared/src/__tests__/scheduleEvents.test.ts
+++ b/packages/maker-shared/src/__tests__/scheduleEvents.test.ts
@@ -27,7 +27,7 @@ describe('shared scheduler event projection', () => {
expect(projectScheduleEvent({ type: 'ready' }).refresh).toEqual({
runRefresh: { mode: 'none' },
scheduleList: true,
- sessionIndex: false,
+ sessionIndex: true,
unreadSummary: false,
});
expect(projectScheduleEvent({ type: 'changed', scheduleId: 'sched-1' })).toMatchObject({
@@ -46,7 +46,8 @@ describe('shared scheduler event projection', () => {
refresh: {
runRefresh: { mode: 'schedule', scheduleId: 'sched-1' },
scheduleList: false,
- sessionIndex: false,
+ // 认领清空了 nextFireAt 并插入 running run,远端侧栏索引要立刻重拉。
+ sessionIndex: true,
unreadSummary: false,
},
runPatch: { scheduleId: 'sched-1', runId: 'run-1', sessionId: null, status: 'running' },
@@ -196,6 +197,20 @@ describe('shared scheduler event projection', () => {
});
});
+ it('treats silenced / notified reminder toggles as no-refresh events instead of unknown', () => {
+ for (const type of ['silenced', 'notified'] as const) {
+ const payload = { type, scheduleId: 'sched-1', runId: 'run-1', sessionId: 'chat-1' };
+ expect(normalizeSchedulerEvent(payload)).toEqual({ type, scheduleId: 'sched-1', runId: 'run-1' });
+ expect(projectScheduleEvent(payload).refresh).toEqual({
+ runRefresh: { mode: 'none' },
+ scheduleList: false,
+ sessionIndex: false,
+ unreadSummary: false,
+ });
+ expect(projectScheduleEvent(payload).unreadImpact).toBe('none');
+ }
+ });
+
it('decides whether a selected schedule should refresh its run list', () => {
expect(shouldRefreshRunsForSchedule({ mode: 'none' }, 'sched-1')).toBe(false);
expect(shouldRefreshRunsForSchedule({ mode: 'all' }, 'sched-1')).toBe(true);
diff --git a/packages/maker-shared/src/__tests__/sessionList.test.ts b/packages/maker-shared/src/__tests__/sessionList.test.ts
index f16d1ddab0..53a46bc333 100644
--- a/packages/maker-shared/src/__tests__/sessionList.test.ts
+++ b/packages/maker-shared/src/__tests__/sessionList.test.ts
@@ -446,6 +446,23 @@ describe('sessionList', () => {
});
});
+ it('carries the latest schedule next run time and omits it when the host has none', () => {
+ const nextFireAt = Date.parse('2026-01-01T00:15:00.000Z');
+ const index = buildSessionScheduleIndex([
+ schedule('sched-1', { nextFireAt }),
+ schedule('sched-2', { status: 'paused', nextFireAt: undefined }),
+ schedule('sched-3', { targetSessionId: 's3', nextFireAt: new Date(nextFireAt).toISOString() }),
+ ], new Map([
+ ['sched-1', [run('run-1', 'sched-1', { sessionId: 's1' })]],
+ ['sched-2', [run('run-2', 'sched-2', { sessionId: 's2' })]],
+ ]));
+
+ expect(index.get('s1')?.nextFireAt).toBe(nextFireAt);
+ expect(index.get('s2')).not.toHaveProperty('nextFireAt');
+ // 持久绑定会话没有 run 也要带上下次运行时间(ISO 时间戳归一为毫秒)。
+ expect(index.get('s3')?.nextFireAt).toBe(nextFireAt);
+ });
+
it('groups multiple automation-generated sessions from the same schedule', () => {
const now = new Date('2026-01-01T00:10:00.000Z').getTime();
const scheduleIndex = buildSessionScheduleIndex([
diff --git a/packages/maker-shared/src/scheduleEvents.ts b/packages/maker-shared/src/scheduleEvents.ts
index e75d8ed428..a6b092289b 100644
--- a/packages/maker-shared/src/scheduleEvents.ts
+++ b/packages/maker-shared/src/scheduleEvents.ts
@@ -14,7 +14,12 @@ export type SchedulerEvent =
* In-flight 数量或并发闸门等待队列变化的运行诊断(desktop engine 高频广播)。与 desktop
* renderer 一致,不驱动任何列表 / run / 未读刷新;投影不需要 snapshot,因此不校验也不保留。
*/
- | { type: 'runtime-state' };
+ | { type: 'runtime-state' }
+ /**
+ * 静默运行的提醒开关(silenced:本轮不提醒 / notified:agent 主动要求提醒)。只影响宿主侧
+ * 完成提醒,run 状态与未读由随后的 completed 收口;投影不驱动任何刷新。
+ */
+ | { type: 'silenced' | 'notified'; scheduleId: string; runId: string };
export type SchedulerEventType = SchedulerEvent['type'];
export type NormalizedSchedulerEvent = SchedulerEvent | { type: 'unknown'; rawType: string | null };
@@ -51,7 +56,9 @@ export function normalizeSchedulerEvent(value: unknown): NormalizedSchedulerEven
const type = readString(value.type);
switch (type) {
case 'fired':
- case 'deferred': {
+ case 'deferred':
+ case 'silenced':
+ case 'notified': {
const scheduleId = readString(value.scheduleId);
const runId = readString(value.runId);
return scheduleId && runId ? { type, scheduleId, runId } : unknownEvent(type);
@@ -101,10 +108,11 @@ export function projectScheduleEvent(value: unknown): ScheduleEventProjection {
export function projectNormalizedScheduleEvent(event: NormalizedSchedulerEvent): ScheduleEventProjection {
switch (event.type) {
case 'ready':
+ // 宿主冷启 / 切账号后会把残留 running 标成 interrupted、重算 nextFireAt,侧栏索引一并重拉。
return projection(event, {
runRefresh: { mode: 'none' },
scheduleList: true,
- sessionIndex: false,
+ sessionIndex: true,
unreadSummary: false,
}, 'none', runPatch(null, null, null, 'unknown'));
case 'changed':
@@ -115,10 +123,11 @@ export function projectNormalizedScheduleEvent(event: NormalizedSchedulerEvent):
unreadSummary: true,
}, 'none', runPatch(event.scheduleId, null, null, 'unknown'));
case 'fired':
+ // 认领时宿主清空 nextFireAt 并插入 running run:索引里的运行态与下次运行时间都变了。
return projection(event, {
runRefresh: { mode: 'schedule', scheduleId: event.scheduleId },
scheduleList: false,
- sessionIndex: false,
+ sessionIndex: true,
unreadSummary: false,
}, 'none', runPatch(event.scheduleId, event.runId, null, 'running'));
case 'deferred':
@@ -172,6 +181,8 @@ export function projectNormalizedScheduleEvent(event: NormalizedSchedulerEvent):
sessionIndex: true,
unreadSummary: true,
}, 'clear-all', runPatch(null, null, null, 'read'));
+ case 'silenced':
+ case 'notified':
case 'runtime-state':
// 纯运行诊断:不能落进 unknown 的全量刷新,否则每次 in-flight 变化都让消费方重拉
// schedule index / 列表 / runs。
diff --git a/packages/maker-shared/src/sessionList.ts b/packages/maker-shared/src/sessionList.ts
index 7276d1f7e4..596da66877 100644
--- a/packages/maker-shared/src/sessionList.ts
+++ b/packages/maker-shared/src/sessionList.ts
@@ -125,6 +125,8 @@ export interface RemoteSessionScheduleInfo {
scheduleId: string;
scheduleName: string;
scheduleStatus?: RemoteSchedule['status'];
+ /** 该 schedule 的下次自动运行时间(毫秒,宿主时钟);手动、已停止或运行中被清空时缺失。 */
+ nextFireAt?: number;
/** 同一会话的所有已知 schedule 绑定都已 paused / expired 时为 true;缺失按 false。 */
allSchedulesStopped?: boolean;
unreadRunIds: string[];
@@ -637,6 +639,7 @@ export function buildSessionScheduleIndex(
scheduleId: schedule.id,
scheduleName: schedule.name || schedule.id,
scheduleStatus: schedule.status,
+ ...nextFireAtField(schedule),
allSchedulesStopped: false,
unreadRunIds: [],
unreadCount: 0,
@@ -671,6 +674,7 @@ export function buildSessionScheduleIndex(
scheduleId: isLatest ? scheduleId : existing.scheduleId,
scheduleName: isLatest ? schedule?.name || scheduleId : existing.scheduleName,
scheduleStatus: isLatest ? schedule?.status : existing.scheduleStatus,
+ ...(isLatest ? nextFireAtField(schedule) : existing.nextFireAt !== undefined ? { nextFireAt: existing.nextFireAt } : {}),
allSchedulesStopped: false,
unreadRunIds,
unreadCount: unreadRunIds.length,
@@ -692,6 +696,11 @@ export function buildSessionScheduleIndex(
return index;
}
+function nextFireAtField(schedule: RemoteSchedule | undefined): { nextFireAt?: number } {
+ const nextFireAt = schedule ? toMillis(schedule.nextFireAt) : 0;
+ return nextFireAt > 0 ? { nextFireAt } : {};
+}
+
export function buildSessionMessagePreviewIndex(
sessionIds: readonly string[],
getMessages: (sessionId: string) => readonly RemoteMessage[],