The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { OrchestrationV2Subagent } from "@t3tools/contracts"; |
| 2 | import * as DateTime from "effect/DateTime"; |
| 3 | |
| 4 | const ACTIVE_SUBAGENT_STATUSES = new Set<OrchestrationV2Subagent["status"]>([ |
| 5 | "pending", |
| 6 | "running", |
| 7 | "waiting", |
| 8 | ]); |
| 9 | |
| 10 | /** Claude can reuse resumed agent ids. Active agents supersede outcomes; settled agents must start after notification. */ |
| 11 | export function subagentResumedSince( |
| 12 | agent: Pick<OrchestrationV2Subagent, "status" | "startedAt">, |
| 13 | notifiedAt: string, |
| 14 | ): boolean { |
| 15 | if (ACTIVE_SUBAGENT_STATUSES.has(agent.status)) return true; |
| 16 | if (agent.startedAt === null) return false; |
| 17 | const notifiedAtMillis = Date.parse(notifiedAt); |
| 18 | return ( |
| 19 | !Number.isNaN(notifiedAtMillis) && DateTime.toEpochMillis(agent.startedAt) > notifiedAtMillis |
| 20 | ); |
| 21 | } |