Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

threadShell.ts

587 lines23.4 KB

1import type {
2 EnvironmentId,
3 OrchestrationV2ShellSnapshot,
4 ProjectId,
5 ScopedProjectRef,
6 ScopedThreadRef,
7 ThreadId,
8} from "@t3tools/contracts";
9import { isProviderNativeSubagentThread, OrchestrationV2ThreadShell } from "@t3tools/contracts";
10import * as Schema from "effect/Schema";
11import { Atom } from "effect/reactivity";
12​
13import type { EnvironmentThreadShell, PendingSubagentRequest } from "./models.ts";
14import { presentThreadShell, threadRuntimeIsActive } from "./models.ts";
15import { type EnvironmentCatalogState, enabledEnvironmentIds } from "./connections.ts";
16import {
17 arrayElementsEqual,
18 parseProjectRefCollectionKey,
19 parseThreadKey,
20 projectRefCollectionKey,
21 threadKey,
22 threadRefsEqual,
23} from "./entities.ts";
24​
25const EMPTY_THREADS: ReadonlyArray<OrchestrationV2ThreadShell> = Object.freeze([]);
26const EMPTY_SCOPED_THREAD_REFS: ReadonlyArray<ScopedThreadRef> = Object.freeze([]);
27const EMPTY_THREAD_INDEX: ReadonlyMap<ThreadId, OrchestrationV2ThreadShell> = new Map();
28const EMPTY_SUBAGENT_REQUESTS: ReadonlyMap<ThreadId, PendingSubagentRequest> = new Map();
29const EMPTY_THREAD_REFS_BY_PROJECT: ReadonlyMap<
30 ProjectId,
31 ReadonlyArray<ScopedThreadRef>
32> = new Map();
33​
34// An async question outlives the subagent's run, but once that run ends the
35// parent is no longer waiting on the answer, so it stops counting as input.
36// The activity run stays set when a follow-up is queued behind a blocked run;
37// older servers omit it, so fall back to the latest run's status.
38const isChildRunLive = (
39 thread: Pick<OrchestrationV2ThreadShell, "activityRunStatus" | "status">,
40) =>
41 thread.activityRunStatus !== undefined
42 ? thread.activityRunStatus !== null
43 : thread.status === "preparing" ||
44 thread.status === "starting" ||
45 thread.status === "running" ||
46 thread.status === "waiting";
47​
48/**
49 * Whether a thread shows under its parent rather than in thread lists: a
50 * subagent, or a task a linked environment delegated here whose parent the
51 * client lists (`delegatedUnderParent`, by thread key). A task whose parent
52 * the client cannot list stays in the lists, so its work is never out of reach.
53 */
54export function isShownUnderParent(
55 ref: ScopedThreadRef,
56 lineage: OrchestrationV2ThreadShell["lineage"],
57 delegatedUnderParent: ReadonlySet<string>,
58): boolean {
59 return lineage.relationshipToParent === "subagent" || delegatedUnderParent.has(threadKey(ref));
61​
62/** Provider-native
63 subagents ask on their parent, so they are skipped. */
64function subagentRequest(thread: OrchestrationV2ThreadShell): PendingSubagentRequest | null {
65 const kind = thread.pendingRuntimeRequest?.kind;
66 if (
67 kind === undefined ||
68 kind === "auth_refresh" ||
69 (thread.lineage.relationshipToParent !== "subagent" && thread.delegatedFrom === undefined) ||
70 isProviderNativeSubagentThread(thread) ||
71 !isChildRunLive(thread)
72 ) {
73 return null;
74 }
75 return kind === "user_input" ? "user_input" : "approval";
77​
78/**
79 * The threads to flag for a subagent's live approval, up its
80 * subagent chain. `delegated` are tasks this environment's threads delegated
81 * to linked environments, with what each one, or its own subagents, asks.
82 */
83function pendingSubagentRequestsByThread(
84 threads: ReadonlyArray<OrchestrationV2ThreadShell>,
85 delegated: ReadonlyArray<{
86 readonly parentThreadId: ThreadId;
87 readonly request: PendingSubagentRequest;
88 }> = [],
89): ReadonlyMap<ThreadId, PendingSubagentRequest> {
90 const requests = new Map<ThreadId, PendingSubagentRequest>();
91 let byId: ReadonlyMap<ThreadId, OrchestrationV2ThreadShell> | undefined;
92 const flag = (
93 firstParentId: ThreadId | null,
94 request: PendingSubagentRequest,
95 seen: Set<ThreadId>,
96 ) => {
97 // The coordinator answers child questions; only approvals need user attention.
98 if (request === "user_input") return;
99 byId ??= new Map(threads.map((thread) => [thread.id, thread] as const));
100 let parentId = firstParentId;
101 while (parentId !== null && !seen.has(parentId)) {
102 seen.add(parentId);
103 if (requests.get(parentId) !== "approval") requests.set(parentId, request);
104 const parent = byId.get(parentId);
105 parentId =
106 parent?.lineage.relationshipToParent === "subagent" ? parent.lineage.parentThreadId : null;
107 }
108 };
109 for (const child of threads) {
110 if (child.lineage.relationshipToParent !== "subagent") continue;
111 const request = subagentRequest(child);
112 if (request !== null) flag(child.lineage.parentThreadId, request, new Set([child.id]));
113 }
114 for (const task of delegated) flag(task.parentThreadId, task.request, new Set());
115 return requests.size === 0 ? EMPTY_SUBAGENT_REQUESTS : requests;
117​
118const sameRequests = (
119 left: ReadonlyMap<ThreadId, PendingSubagentRequest>,
120 right: ReadonlyMap<ThreadId, PendingSubagentRequest>,
121) =>
122 left.size === right.size &&
123 [...right].every(([threadId, request]) => left.get(threadId) === request);
124​
125export function childThreadInputsTitle(
126 children: ReadonlyArray<Pick<EnvironmentThreadShell, "hasPendingApprovals">>,
127): string {
128 const approvals = children.filter((child) => child.hasPendingApprovals).length;
129 const need = approvals === 0 ? "input" : approvals === children.length ? "approval" : "you";
130 return children.length === 1
131 ? `Subagent needs ${need}`
132 : `${children.length} subagents need ${need}`;
134​
135const sameWireThreadShell = Schema.toEquivalence(OrchestrationV2ThreadShell);
136​
137// While a run streams, the server bumps the shell's timestamps, item counts and
138// latest message several times a second. Only the zero crossing of the counts
139// says anything (whether the thread has started). Once the run stops every
140// field counts again, so snooze wakes and failure times read the current value.
141function sameApartFromStreaming(
142 previous: EnvironmentThreadShell,
143 next: EnvironmentThreadShell,
144): boolean {
145 if (
146 previous.environmentId !== next.environmentId ||
147 previous.pendingSubagentRequest !== next.pendingSubagentRequest ||
148 !threadRuntimeIsActive(next.runtime)
149 ) {
150 return false;
151 }
152 const before = previous.source;
153 const after = next.source;
154 return (
155 before.itemCount > 0 === after.itemCount > 0 &&
156 before.visibleItemCount > 0 === after.visibleItemCount > 0 &&
157 sameWireThreadShell(
158 {
159 ...before,
160 updatedAt: after.updatedAt,
161 itemCount: after.itemCount,
162 visibleItemCount: after.visibleItemCount,
163 latestVisibleMessage: after.latestVisibleMessage,
164 },
165 after,
166 )
167 );
169​
170export function createEnvironmentThreadShellAtoms(input: {
171 readonly catalogValueAtom: Atom.Atom<EnvironmentCatalogState>;
172 readonly snapshotAtom: (
173 environmentId: EnvironmentId,
174 ) => Atom.Atom<OrchestrationV2ShellSnapshot | null>;
175}) {
176 // Point reads and aggregate lists share values without keeping an atom alive
177 // for every listed thread. Replaced source objects can be collected.
178 const scopedThreads = new WeakMap<
179 OrchestrationV2ThreadShell,
180 Map<string, EnvironmentThreadShell>
181 >();
182 const scopedThread = (
183 environmentId: EnvironmentId,
184 thread: OrchestrationV2ThreadShell,
185 subagentRequests: ReadonlyMap<ThreadId, PendingSubagentRequest>,
186 ) => {
187 let byEnvironment = scopedThreads.get(thread);
188 if (byEnvironment === undefined) {
189 byEnvironment = new Map();
190 scopedThreads.set(thread, byEnvironment);
191 }
192 const request = subagentRequests.get(thread.id) ?? null;
193 const key = request === null ? environmentId : `${environmentId}:${request}`;
194 let value = byEnvironment.get(key);
195 if (value === undefined) {
196 value = presentThreadShell(environmentId, thread, request);
197 byEnvironment.set(key, value);
198 }
199 return value;
200 };
201​
202 const environmentThreadsAtom = Atom.family((environmentId: EnvironmentId) =>
203 Atom.make(
204 (get): ReadonlyArray<OrchestrationV2ThreadShell> =>
205 get(input.snapshotAtom(environmentId))?.threads ?? EMPTY_THREADS,
206 ).pipe(Atom.withLabel(`environment-threads:${environmentId}`)),
207 );
208​
209 const environmentThreadIndexAtom = Atom.family((environmentId: EnvironmentId) =>
210 Atom.make((get): ReadonlyMap<ThreadId, OrchestrationV2ThreadShell> => {
211 const threads = get(environmentThreadsAtom(environmentId));
212 if (threads.length === 0) {
213 return EMPTY_THREAD_INDEX;
214 }
215 return new Map(threads.map((thread) => [thread.id, thread] as const));
216 }).pipe(Atom.withLabel(`environment-thread-index:${environmentId}`)),
217 );
218​
219 // What an environment's own subagents ask. Kept apart from the tasks other
220 // environments run for it, so two environments delegating to each other
221 // never read each other's totals.
222 const localSubagentRequestsAtom = Atom.family((environmentId: EnvironmentId) => {
223 let previous = EMPTY_SUBAGENT_REQUESTS;
224 return Atom.make((get) => {
225 const next = pendingSubagentRequestsByThread(get(environmentThreadsAtom(environmentId)));
226 if (sameRequests(previous, next)) return previous;
227 previous = next;
228 return next;
229 }).pipe(Atom.withLabel(`environment-local-subagent-requests:${environmentId}`));
230 });
231​
232 // Flags for environments whose threads delegated tasks, counting what each task
233 // or anything it delegated on asks. Each pass settles one more hop of a chain;
234 // flags only grow, so environments delegating to each other settle too.
235 const delegatedSubagentRequestsAtom = Atom.make((get) => {
236 const tasksByDelegator = new Map<
237 EnvironmentId,
238 Array<{
239 readonly runsIn: EnvironmentId;
240 readonly thread: OrchestrationV2ThreadShell;
241 readonly parentThreadId: ThreadId;
242 }>
243 >();
244 for (const runsIn of enabledEnvironmentIds(get(input.catalogValueAtom))) {
245 for (const thread of get(environmentThreadsAtom(runsIn))) {
246 const from = thread.delegatedFrom;
247 if (from === undefined || from.environmentId === runsIn) continue;
248 const task = { runsIn, thread, parentThreadId: from.threadId };
249 const tasks = tasksByDelegator.get(from.environmentId);
250 if (tasks === undefined) tasksByDelegator.set(from.environmentId, [task]);
251 else tasks.push(task);
252 }
253 }
254 let flags = new Map<EnvironmentId, ReadonlyMap<ThreadId, PendingSubagentRequest>>();
255 const requestsOf = (environmentId: EnvironmentId) =>
256 flags.get(environmentId) ?? get(localSubagentRequestsAtom(environmentId));
257 for (let changed = tasksByDelegator.size > 0; changed;) {
258 changed = false;
259 const next = new Map(flags);
260 for (const [environmentId, tasks] of tasksByDelegator) {
261 const delegated = tasks.flatMap(({ runsIn, thread, parentThreadId }) => {
262 const own = subagentRequest(thread);
263 const nested = requestsOf(runsIn).get(thread.id);
264 const request = own === "approval" ? own : (nested ?? own);
265 return request === null ? [] : [{ parentThreadId, request }];
266 });
267 if (delegated.length === 0) continue;
268 const requests = pendingSubagentRequestsByThread(
269 get(environmentThreadsAtom(environmentId)),
270 delegated,
271 );
272 if (sameRequests(requestsOf(environmentId), requests)) continue;
273 next.set(environmentId, requests);
274 changed = true;
275 }
276 flags = next;
277 }
278 return flags;
279 }).pipe(Atom.withLabel("environment-delegated-subagent-requests"));
280​
281 const pendingSubagentRequestsAtom = Atom.family((environmentId: EnvironmentId) => {
282 let previous = EMPTY_SUBAGENT_REQUESTS;
283 return Atom.make((get) => {
284 const next =
285 get(delegatedSubagentRequestsAtom).get(environmentId) ??
286 get(localSubagentRequestsAtom(environmentId));
287 if (sameRequests(previous, next)) return previous;
288 previous = next;
289 return next;
290 }).pipe(Atom.withLabel(`environment-pending-subagent-requests:${environmentId}`));
291 });
292​
293 const environmentThreadRefsAtom = Atom.family((environmentId: EnvironmentId) => {
294 let previous: ReadonlyArray<ScopedThreadRef> = [];
295 return Atom.make((get) => {
296 const next = get(environmentThreadsAtom(environmentId)).map((thread) => ({
297 environmentId,
298 threadId: thread.id,
299 }));
300 if (threadRefsEqual(previous, next)) {
301 return previous;
302 }
303 previous = next;
304 return next;
305 }).pipe(Atom.withLabel(`environment-thread-refs:${environmentId}`));
306 });
307​
308 const environmentThreadRefsByProjectAtom = Atom.family((environmentId: EnvironmentId) => {
309 let previous: ReadonlyMap<
310 ProjectId,
311 ReadonlyArray<ScopedThreadRef>
312 > = EMPTY_THREAD_REFS_BY_PROJECT;
313 return Atom.make((get) => {
314 const grouped = new Map<ProjectId, ScopedThreadRef[]>();
315 for (const thread of get(environmentThreadsAtom(environmentId))) {
316 const refs = grouped.get(thread.projectId);
317 const ref = { environmentId, threadId: thread.id };
318 if (refs === undefined) {
319 grouped.set(thread.projectId, [ref]);
320 } else {
321 refs.push(ref);
322 }
323 }
324 if (grouped.size === 0) {
325 previous = EMPTY_THREAD_REFS_BY_PROJECT;
326 return previous;
327 }
328 const next = new Map<ProjectId, ReadonlyArray<ScopedThreadRef>>();
329 for (const [projectId, refs] of grouped) {
330 const previousRefs = previous.get(projectId);
331 next.set(
332 projectId,
333 previousRefs !== undefined && threadRefsEqual(previousRefs, refs) ? previousRefs : refs,
334 );
335 }
336 const previousProjectIds = [...previous.keys()];
337 if (
338 next.size === previous.size &&
339 [...next].every(
340 ([projectId, refs], index) =>
341 previousProjectIds[index] === projectId && previous.get(projectId) === refs,
342 )
343 ) {
344 return previous;
345 }
346 previous = next;
347 return previous;
348 }).pipe(Atom.withLabel(`environment-thread-refs-by-project:${environmentId}`));
349 });
350​
351 const threadShellAtomFamily = Atom.family((key: string) => {
352 const ref = parseThreadKey(key);
353 return Atom.make((get) => {
354 const source = get(environmentThreadIndexAtom(ref.environmentId)).get(ref.threadId) ?? null;
355 return source === null
356 ? null
357 : scopedThread(
358 ref.environmentId,
359 source,
360 get(pendingSubagentRequestsAtom(ref.environmentId)),
361 );
362 }).pipe(Atom.withLabel(`environment-thread-shell:${key}`));
363 });
364​
365 // Keeps the previous shell while only streaming ticks changed. During a run,
366 // its timestamps, item counts and latest message are as of the last kept
367 // change; anything that needs them current reads threadShellAtom.
368 const quietThreadShellAtomFamily = Atom.family((key: string) => {
369 let previous: EnvironmentThreadShell | null = null;
370 return Atom.make((get) => {
371 const next = get(threadShellAtomFamily(key));
372 if (previous !== null && next !== null && sameApartFromStreaming(previous, next)) {
373 return previous;
374 }
375 previous = next;
376 return next;
377 }).pipe(Atom.withLabel(`environment-quiet-thread-shell:${key}`));
378 });
379​
380 // Child approvals and questions are hidden with their sidebar rows. Read their
381 // shell summaries, without subscribing to every child transcript. A task
382 // delegated to a linked environment is a child too, with its own subagents.
383 const childThreadInputsAtomFamily = Atom.family((key: string) => {
384 let previous: ReadonlyArray<EnvironmentThreadShell> = [];
385 return Atom.make((get) => {
386 const children = new Map<
387 string,
388 Array<{ environmentId: EnvironmentId; thread: OrchestrationV2ThreadShell }>
389 >();
390 const addChild = (
391 parent: ScopedThreadRef,
392 environmentId: EnvironmentId,
393 thread: OrchestrationV2ThreadShell,
394 ) => {
395 const siblings = children.get(threadKey(parent));
396 if (siblings) siblings.push({ environmentId, thread });
397 else children.set(threadKey(parent), [{ environmentId, thread }]);
398 };
399 for (const environmentId of enabledEnvironmentIds(get(input.catalogValueAtom))) {
400 for (const thread of get(environmentThreadsAtom(environmentId))) {
401 const parent = thread.lineage.parentThreadId;
402 if (parent !== null && thread.lineage.relationshipToParent === "subagent") {
403 addChild({ environmentId, threadId: parent }, environmentId, thread);
404 } else if (thread.delegatedFrom !== undefined) {
405 addChild(thread.delegatedFrom, environmentId, thread);
406 }
407 }
408 }
409 const seen = new Set<string>([key]);
410 const pending = [key];
411 const next: EnvironmentThreadShell[] = [];
412 for (const parent of pending) {
413 for (const { environmentId, thread } of children.get(parent) ?? []) {
414 const childKey = threadKey({ environmentId, threadId: thread.id });
415 if (seen.has(childKey)) continue;
416 seen.add(childKey);
417 pending.push(childKey);
418 if (subagentRequest(thread) !== null) {
419 next.push(
420 scopedThread(environmentId, thread, get(pendingSubagentRequestsAtom(environmentId))),
421 );
422 }
423 }
424 }
425 // Indicators read only ids, titles and the request kind, so other shell
426 // updates keep the old array.
427 if (
428 previous.length === next.length &&
429 previous.every(
430 (thread, index) =>
431 thread.environmentId === next[index]?.environmentId &&
432 thread.id === next[index]?.id &&
433 thread.title === next[index]?.title &&
434 thread.hasPendingApprovals === next[index]?.hasPendingApprovals,
435 )
436 ) {
437 return previous;
438 }
439 previous = next;
440 return next;
441 }).pipe(Atom.withLabel(`environment-child-thread-inputs:${key}`));
442 });
443​
444 const threadShellsForProjectRefsAtomFamily = Atom.family((key: string) => {
445 const projectRefs = parseProjectRefCollectionKey(key);
446 let previous: ReadonlyArray<EnvironmentThreadShell> = [];
447 return Atom.make((get) => {
448 const next: EnvironmentThreadShell[] = [];
449 const seen = new Set<string>();
450 for (const projectRef of projectRefs) {
451 const refs =
452 get(environmentThreadRefsByProjectAtom(projectRef.environmentId)).get(
453 projectRef.projectId,
454 ) ?? EMPTY_SCOPED_THREAD_REFS;
455 if (refs.length === 0) continue;
456 const threads = get(environmentThreadIndexAtom(projectRef.environmentId));
457 const subagentRequests = get(pendingSubagentRequestsAtom(projectRef.environmentId));
458 for (const ref of refs) {
459 const key = threadKey(ref);
460 if (seen.has(key)) {
461 continue;
462 }
463 seen.add(key);
464 const thread = threads.get(ref.threadId);
465 if (thread !== undefined) {
466 next.push(scopedThread(ref.environmentId, thread, subagentRequests));
467 }
468 }
469 }
470 if (arrayElementsEqual(previous, next)) {
471 return previous;
472 }
473 previous = next;
474 return previous;
475 }).pipe(Atom.withLabel(`environment-thread-shells-for-projects:${key}`));
476 });
477​
478 let previousThreadRefs: ReadonlyArray<ScopedThreadRef> = [];
479 const threadRefsAtom = Atom.make((get) => {
480 const refs: ScopedThreadRef[] = [];
481 for (const environmentId of enabledEnvironmentIds(get(input.catalogValueAtom))) {
482 refs.push(...get(environmentThreadRefsAtom(environmentId)));
483 }
484 if (threadRefsEqual(previousThreadRefs, refs)) {
485 return previousThreadRefs;
486 }
487 previousThreadRefs = refs;
488 return refs;
489 }).pipe(Atom.withLabel("environment-thread-refs"));
490​
491 let previousThreadShells: ReadonlyArray<EnvironmentThreadShell> = [];
492 const threadShellsAtom = Atom.make((get) => {
493 const next: EnvironmentThreadShell[] = [];
494 for (const environmentId of enabledEnvironmentIds(get(input.catalogValueAtom))) {
495 const subagentRequests = get(pendingSubagentRequestsAtom(environmentId));
496 for (const thread of get(environmentThreadsAtom(environmentId))) {
497 next.push(scopedThread(environmentId, thread, subagentRequests));
498 }
499 }
500 if (arrayElementsEqual(previousThreadShells, next)) {
501 return previousThreadShells;
502 }
503 previousThreadShells = next;
504 return previousThreadShells;
505 }).pipe(Atom.withLabel("environment-thread-shell-list"));
506​
507 // Lists that arrange threads read this, so a running thread's streaming
508 // ticks reach only what reads its live shell.
509 let previousQuietThreadShells: ReadonlyArray<EnvironmentThreadShell> = [];
510 const quietThreadShellsAtom = Atom.make((get) => {
511 const next: EnvironmentThreadShell[] = [];
512 for (const ref of get(threadRefsAtom)) {
513 const shell = get(quietThreadShellAtomFamily(threadKey(ref)));
514 if (shell !== null) next.push(shell);
515 }
516 if (arrayElementsEqual(previousQuietThreadShells, next)) return previousQuietThreadShells;
517 previousQuietThreadShells = next;
518 return next;
519 }).pipe(Atom.withLabel("environment-quiet-thread-shell-list"));
520​
521 let previousDelegatedUnderParent: ReadonlySet<string> = new Set();
522 const delegatedUnderParentAtom = Atom.make((get) => {
523 const environmentIds = new Set(enabledEnvironmentIds(get(input.catalogValueAtom)));
524 const next = new Set<string>();
525 for (const environmentId of environmentIds) {
526 for (const thread of get(environmentThreadsAtom(environmentId))) {
527 const parent = thread.delegatedFrom;
528 if (
529 parent !== undefined &&
530 environmentIds.has(parent.environmentId) &&
531 // An archived parent leaves navigation; its task there stays listed on its own.
532 get(environmentThreadIndexAtom(parent.environmentId)).get(parent.threadId)?.archivedAt ===
533 null
534 ) {
535 next.add(threadKey({ environmentId, threadId: thread.id }));
536 }
537 }
538 }
539 if (
540 next.size === previousDelegatedUnderParent.size &&
541 [...next].every((key) => previousDelegatedUnderParent.has(key))
542 ) {
543 return previousDelegatedUnderParent;
544 }
545 previousDelegatedUnderParent = next;
546 return next;
547 }).pipe(Atom.withLabel("environment-delegated-under-parent"));
548​
549 let previousNavigationShells: ReadonlyArray<EnvironmentThreadShell> = [];
550 const navigationThreadShellsAtom = Atom.make((get) => {
551 const next: EnvironmentThreadShell[] = [];
552 const underParent = get(delegatedUnderParentAtom);
553 for (const environmentId of enabledEnvironmentIds(get(input.catalogValueAtom))) {
554 const subagentRequests = get(pendingSubagentRequestsAtom(environmentId));
555 for (const thread of get(environmentThreadsAtom(environmentId))) {
556 if (
557 thread.archivedAt !== null ||
558 isShownUnderParent({ environmentId, threadId: thread.id }, thread.lineage, underParent)
559 ) {
560 continue;
561 }
562 next.push(scopedThread(environmentId, thread, subagentRequests));
563 }
564 }
565 if (arrayElementsEqual(previousNavigationShells, next)) return previousNavigationShells;
566 previousNavigationShells = next;
567 return next;
568 }).pipe(Atom.withLabel("environment-navigation-thread-shells"));
569​
570 return {
571 environmentThreadsAtom,
572 environmentThreadIndexAtom,
573 environmentThreadRefsAtom,
574 environmentThreadRefsByProjectAtom,
575 threadRefsAtom,
576 threadShellsAtom,
577 quietThreadShellsAtom,
578 navigationThreadShellsAtom,
579 delegatedUnderParentAtom,
580 pendingSubagentRequestsAtom,
581 threadShellsForProjectRefsAtom: (refs: ReadonlyArray<ScopedProjectRef>) =>
582 threadShellsForProjectRefsAtomFamily(projectRefCollectionKey(refs)),
583 threadShellAtom: (ref: ScopedThreadRef) => threadShellAtomFamily(threadKey(ref)),
584 quietThreadShellAtom: (ref: ScopedThreadRef) => quietThreadShellAtomFamily(threadKey(ref)),
585 childThreadInputsAtom: (ref: ScopedThreadRef) => childThreadInputsAtomFamily(threadKey(ref)),
586 };