Open History to see the last commit
1import {
2 ORCHESTRATION_V2_WS_METHODS,
3 type EnvironmentId,
4 type OrchestrationV2ShellSnapshot,
5 type OrchestrationV2ShellStreamItem,
6 type OrchestrationV2ThreadShell,
7 type ServerConfig,
8 type ThreadId,
9 type ThreadPullRequestLink,
10} from "@t3tools/contracts";
11import * as Cause from "effect/Cause";
12import * as Effect from "effect/Effect";
13import * as Fiber from "effect/Fiber";
14import * as Option from "effect/Option";
15import * as Queue from "effect/Queue";
16import * as Ref from "effect/Ref";
17import * as Semaphore from "effect/Semaphore";
18import * as Stream from "effect/Stream";
19import * as SubscriptionRef from "effect/SubscriptionRef";
20import { AsyncResult, Atom } from "effect/reactivity";
21
22import * as EnvironmentRegistry from "../connection/registry.ts";
23import { connectionProjectionPhase } from "../connection/model.ts";
24import * as EnvironmentSupervisor from "../connection/supervisor.ts";
25import * as ConnectionWakeups from "../connection/wakeups.ts";
26import { safeErrorLogAttributes } from "../errors/safeLog.ts";
27import * as Persistence from "../platform/persistence.ts";
28import { runCachePersistence } from "./cachePersistence.ts";
29import { subscribeDynamic } from "../rpc/client.ts";
30import type { RpcSession } from "../rpc/session.ts";
31import * as ShellSnapshotLoader from "./shellSnapshotHttp.ts";
32import type { DeferredShellSnapshot } from "./shellPullRequests.ts";
33import {
34 applyShellStreamEvent,
35 mergeShellSnapshotProjects,
36 reuseUnchangedThreadShells,
37 sameThreadPullRequests,
38} from "./shellReducer.ts";
39import { type EnvironmentCatalogState, enabledEnvironmentIds } from "./connections.ts";
40import { followStreamInEnvironment } from "./runtime.ts";
41
42export type EnvironmentShellStatus = "empty" | "cached" | "synchronizing" | "live";
43
44export interface EnvironmentShellState {
45 readonly snapshot: Option.Option<OrchestrationV2ShellSnapshot>;
46 readonly status: EnvironmentShellStatus;
47 readonly error: Option.Option<string>;
48 /**
49 * Changes with each authoritative snapshot (not enrichment refreshes); 0 until the first one.
50 * Thread families read for an older generation may miss changes from before the latest snapshot,
51 * so they are read again.
52 */
53 readonly generation: number;
54 /** Sequences of the thread removals applied since the latest authoritative snapshot. */
55 readonly removedAt: ReadonlyMap<ThreadId, number>;
56}
57
58const EMPTY_REMOVALS: ReadonlyMap<ThreadId, number> = new Map();
59// Shared by every shell state, so a rebuilt one never reuses a generation another already used.
60let lastShellGeneration = 0;
61
62export const EMPTY_SHELL_STATE: EnvironmentShellState = {
63 snapshot: Option.none(),
64 status: "empty",
65 error: Option.none(),
66 generation: 0,
67 removedAt: EMPTY_REMOVALS,
68};
69
70function shellStatusForSnapshot(
71 snapshot: Option.Option<OrchestrationV2ShellSnapshot>,
72): EnvironmentShellStatus {
73 return Option.isSome(snapshot) ? "cached" : "empty";
74}
75
76function withoutDeferredPullRequests(value: DeferredShellSnapshot): OrchestrationV2ShellSnapshot {
77 if (value.loadPullRequests === undefined) return value;
78 const { loadPullRequests: _deferred, ...snapshot } = value;
79 return snapshot;
80}
81
82const SHELL_SYNCHRONIZATION_ERROR_MESSAGE = "Could not synchronize environment data.";
83
84export const makeEnvironmentShellState = Effect.fn("EnvironmentShellState.make")(function* () {
85 const supervisor = yield* EnvironmentSupervisor.EnvironmentSupervisor;
86 const cache = yield* Persistence.EnvironmentCacheStore;
87 const snapshotLoader = yield* ShellSnapshotLoader.ShellSnapshotLoader;
88 const wakeups = yield* Effect.serviceOption(ConnectionWakeups.ConnectionWakeups);
89 const environmentId = supervisor.target.environmentId;
90 const cached = yield* cache.loadShell(environmentId).pipe(
91 Effect.catch((error) =>
92 Effect.logWarning("Could not load cached environment shell.").pipe(
93 Effect.annotateLogs({
94 environmentId,
95 ...safeErrorLogAttributes(error),
96 }),
97 Effect.as(Option.none<DeferredShellSnapshot>()),
98 ),
99 ),
100 );
101 const cachedSnapshot = Option.map(cached, withoutDeferredPullRequests);
102 const state = yield* SubscriptionRef.make<EnvironmentShellState>({
103 ...EMPTY_SHELL_STATE,
104 snapshot: cachedSnapshot,
105 status: shellStatusForSnapshot(cachedSnapshot),
106 });
107 const awaitingCompletion = yield* Ref.make(false);
108 const lastAuthoritativeSession = yield* Ref.make<RpcSession | null>(null);
109 const activeSubscriptionSession = yield* Ref.make<RpcSession | null>(null);
110 const latestLiveSnapshot = yield* Ref.make<Option.Option<OrchestrationV2ShellSnapshot>>(
111 Option.none(),
112 );
113 const persistence = yield* Queue.sliding<OrchestrationV2ShellSnapshot>(1);
114
115 const persistenceLock = yield* Semaphore.make(1);
116 let lastPersisted: OrchestrationV2ShellSnapshot | undefined;
117 // Rows still waiting for their deferred pull request links, which must not be saved:
118 // the cache would keep them without links until the next server refresh.
119 let pendingLinkRows: ReadonlySet<OrchestrationV2ThreadShell> = new Set();
120 const persistLatest = Effect.fn("EnvironmentShellState.persistLatest")(function* (
121 flush: boolean,
122 ) {
123 while (true) {
124 const latest = yield* Ref.get(latestLiveSnapshot);
125 if (Option.isNone(latest) || latest.value === lastPersisted) return;
126 if (latest.value.threads.some((thread) => pendingLinkRows.has(thread))) return;
127 const snapshot = latest.value;
128 const saved = yield* cache.saveShell(environmentId, snapshot).pipe(
129 Effect.as(true),
130 Effect.catch((error) =>
131 Effect.logWarning("Could not persist environment shell cache.").pipe(
132 Effect.annotateLogs({ environmentId, ...safeErrorLogAttributes(error) }),
133 Effect.as(false),
134 ),
135 ),
136 );
137 if (!saved) return;
138 lastPersisted = snapshot;
139 if (!flush) return;
140 }
141 }, persistenceLock.withPermit);
142 const persist = () => persistLatest(false);
143 const flushLiveShellSnapshot = persistLatest(true);
144
145 // Register before scoped worker fibers so reverse finalizer order interrupts
146 // those fibers first and this flush sees a stable latestLiveSnapshot.
147 yield* Effect.addFinalizer(() => flushLiveShellSnapshot);
148
149 yield* runCachePersistence(persistence, persist).pipe(Effect.forkScoped);
150
151 const setDisconnected = Ref.set(awaitingCompletion, false).pipe(
152 Effect.andThen(
153 SubscriptionRef.update(state, (current) => ({
154 ...current,
155 status: shellStatusForSnapshot(current.snapshot),
156 })),
157 ),
158 Effect.andThen(flushLiveShellSnapshot.pipe(Effect.forkScoped)),
159 Effect.asVoid,
160 );
161 const setSynchronizing = SubscriptionRef.update(state, (current) => ({
162 ...current,
163 status: "synchronizing" as const,
164 error: Option.none(),
165 }));
166 const setReady = SubscriptionRef.update(state, (current) =>
167 current.status === "live"
168 ? current
169 : {
170 ...current,
171 status: "synchronizing" as const,
172 error: Option.none(),
173 },
174 );
175 const setStreamError = (error: unknown) =>
176 Ref.set(awaitingCompletion, false).pipe(
177 Effect.andThen(Effect.logWarning("Could not synchronize the environment shell.")),
178 Effect.annotateLogs({
179 environmentId,
180 ...safeErrorLogAttributes(error),
181 }),
182 Effect.andThen(
183 SubscriptionRef.update(state, (current) => ({
184 ...current,
185 status: shellStatusForSnapshot(current.snapshot),
186 error: Option.some(SHELL_SYNCHRONIZATION_ERROR_MESSAGE),
187 })),
188 ),
189 );
190
191 // Server items and deferred link fills both read the snapshot and write it back; one at a
192 // time, so neither can overwrite what the other wrote in between.
193 const snapshotWriteLock = yield* Semaphore.make(1);
194
195 const applyItems = Effect.fn("EnvironmentShellState.applyItems")(function* (
196 items: ReadonlyArray<OrchestrationV2ShellStreamItem>,
197 pendingLinkIds?: ReadonlySet<ThreadId>,
198 ) {
199 const initial = yield* SubscriptionRef.get(state);
200 let waiting = yield* Ref.get(awaitingCompletion);
201 let next = initial;
202 let receivedSnapshot = false;
203 for (const item of items) {
204 if (item.kind === "synchronized") {
205 waiting = false;
206 if (Option.isSome(next.snapshot)) {
207 next = { ...next, status: "live", error: Option.none() };
208 }
209 continue;
210 }
211 const authoritative =
212 item.kind === "snapshot" && item.resolvedRepositoryIdentityRoots === undefined;
213 const nextSnapshot =
214 item.kind === "snapshot"
215 ? mergeShellSnapshotProjects(
216 Option.getOrNull(next.snapshot),
217 item.snapshot,
218 item.resolvedRepositoryIdentityRoots === undefined
219 ? undefined
220 : {
221 resolvedRepositoryIdentityRoots: item.resolvedRepositoryIdentityRoots,
222 },
223 )
224 : Option.match(next.snapshot, {
225 onNone: () => null,
226 onSome: (snapshot) =>
227 item.sequence > snapshot.snapshotSequence
228 ? applyShellStreamEvent(snapshot, item)
229 : snapshot,
230 });
231 if (nextSnapshot === null) continue;
232 receivedSnapshot ||= item.kind === "snapshot";
233 const removal =
234 item.kind === "thread.removed" &&
235 Option.exists(next.snapshot, (snapshot) => item.sequence > snapshot.snapshotSequence)
236 ? item
237 : null;
238 next = {
239 snapshot: Option.some(nextSnapshot),
240 status: waiting ? "synchronizing" : "live",
241 error: Option.none(),
242 generation: authoritative ? ++lastShellGeneration : next.generation,
243 removedAt: authoritative
244 ? EMPTY_REMOVALS
245 : removal === null
246 ? next.removedAt
247 : new Map(next.removedAt).set(removal.threadId, removal.sequence),
248 };
249 }
250 yield* Ref.set(awaitingCompletion, waiting);
251 if (next === initial) return;
252 if (pendingLinkIds !== undefined && Option.isSome(next.snapshot)) {
253 pendingLinkRows = new Set(
254 next.snapshot.value.threads.filter((thread) => pendingLinkIds.has(thread.id)),
255 );
256 }
257 if (Option.isSome(next.snapshot)) {
258 yield* Ref.set(latestLiveSnapshot, next.snapshot);
259 }
260 yield* SubscriptionRef.set(state, next);
261 if (receivedSnapshot) {
262 const session = yield* Ref.get(activeSubscriptionSession);
263 if (session !== null) {
264 yield* Ref.set(lastAuthoritativeSession, session);
265 }
266 }
267 if (next.snapshot !== initial.snapshot && Option.isSome(next.snapshot)) {
268 yield* Queue.offer(persistence, next.snapshot.value);
269 }
270 }, snapshotWriteLock.withPermit);
271
272 const stateScope = yield* Effect.scope;
273 // Each full snapshot supersedes the previous one's fill; links from an older snapshot must
274 // not land on rows a newer snapshot reused.
275
276 let activeFill: Fiber.Fiber<void> | undefined;
277 const cancelActiveFill = Effect.suspend(() => {
278 const fill = activeFill;
279 activeFill = undefined;
280 return fill === undefined ? Effect.void : Fiber.interrupt(fill);
281 });
282 const fillDeferredPullRequests = Effect.fnUntraced(function* (
283 source: DeferredShellSnapshot,
284 applied: OrchestrationV2ShellSnapshot,
285 ) {
286 yield* cancelActiveFill;
287 if (source.loadPullRequests === undefined) return;
288 const arrivedRows = new Set(applied.threads);
289 const arrivedIds = new Set(source.threads.map((thread) => thread.id));
290 pendingLinkRows = new Set(applied.threads.filter((thread) => arrivedIds.has(thread.id)));
291 activeFill = yield* source.loadPullRequests.pipe(
292 Effect.flatMap((linksByThreadId) =>
293 writeFilledLinks(linksByThreadId, arrivedRows, arrivedIds),
294 ),
295 Effect.forkIn(stateScope),
296 );
297 });
298 const writeFilledLinks = Effect.fnUntraced(
299 function* (
300 linksByThreadId: ReadonlyMap<ThreadId, ReadonlyArray<ThreadPullRequestLink>>,
301 arrivedRows: ReadonlySet<OrchestrationV2ThreadShell>,
302 arrivedIds: ReadonlySet<ThreadId>,
303 ) {
304 const filled = yield* SubscriptionRef.modify(
305 state,
306 (current): [Option.Option<OrchestrationV2ShellSnapshot>, EnvironmentShellState] => {
307 if (Option.isNone(current.snapshot)) return [Option.none(), current];
308 const snapshot = current.snapshot.value;
309 let changed = false;
310 const threads = snapshot.threads.map((thread) => {
311 if (!arrivedRows.has(thread) || !arrivedIds.has(thread.id)) return thread;
312 const links = linksByThreadId.get(thread.id);
313 if (sameThreadPullRequests(thread.pullRequests, links)) return thread;
314 changed = true;
315 if (links === undefined) {
316 const { pullRequests: _previous, ...row } = thread;
317 return row;
318 }
319 return { ...thread, pullRequests: links };
320 });
321 if (!changed) return [Option.none(), current];
322 const next = { ...snapshot, threads };
323 return [Option.some(next), { ...current, snapshot: Option.some(next) }];
324 },
325 );
326 pendingLinkRows = new Set();
327 const live = yield* Ref.get(latestLiveSnapshot);
328 if (Option.isNone(live)) return;
329 const latest = Option.isSome(filled) ? filled : live;
330 yield* Ref.set(latestLiveSnapshot, latest);
331 yield* Queue.offer(persistence, latest.value);
332 },
333 (effect) => snapshotWriteLock.withPermit(effect),
334 );
335 if (Option.isSome(cached) && Option.isSome(cachedSnapshot)) {
336 yield* fillDeferredPullRequests(cached.value, cachedSnapshot.value);
337 }
338
339 const foregroundResubscriptions = Option.match(wakeups, {
340 onNone: () => Stream.never,
341 onSome: (service) =>
342 service.changes.pipe(Stream.filter(ConnectionWakeups.shouldResubscribeAfterWakeup)),
343 });
344
345 yield* setSynchronizing;
346 yield* Effect.forkScoped(
347 subscribeDynamic(
348 ORCHESTRATION_V2_WS_METHODS.subscribeShell,
349 Effect.fn("EnvironmentShellState.makeSubscribeInput")(function* (session) {
350 yield* Ref.set(activeSubscriptionSession, session);
351 const { supportsCompletionMarker, omitIdleSubagents } = yield* session.initialConfig.pipe(
352 Effect.map((config) => ({
353 supportsCompletionMarker: config.shellResumeCompletionMarker === true,
354 omitIdleSubagents: config.shellThreadFamilies === true,
355 })),
356 Effect.orElseSucceed(() => ({
357 supportsCompletionMarker: false,
358 omitIdleSubagents: false,
359 })),
360 );
361 yield* Ref.set(awaitingCompletion, supportsCompletionMarker);
362 yield* setSynchronizing;
363
364 // Foreground resubscriptions on the same live session can resume from
365 // the in-memory cursor. A new session reloads the authoritative HTTP
366 // snapshot so a valid cursor cannot preserve incomplete cached data.
367 const hasAuthoritativeSnapshot = (yield* Ref.get(lastAuthoritativeSession)) === session;
368 let canResume = hasAuthoritativeSnapshot;
369 let current = yield* SubscriptionRef.get(state);
370 if (!hasAuthoritativeSnapshot || Option.isNone(current.snapshot)) {
371 const prepared = yield* SubscriptionRef.get(supervisor.prepared).pipe(
372 Effect.flatMap(
373 Option.match({
374 onSome: Effect.succeed,
375 onNone: () =>
376 SubscriptionRef.changes(supervisor.prepared).pipe(
377 Stream.filter(Option.isSome),
378 Stream.map((value) => value.value),
379 Stream.runHead,
380 Effect.map(Option.getOrThrow),
381 ),
382 }),
383 ),
384 );
385 // HTTP and the socket must agree, or omitted children would return through the socket.
386 const httpSnapshot = yield* snapshotLoader.load(prepared, { omitIdleSubagents });
387 if (Option.isSome(httpSnapshot)) {
388 yield* cancelActiveFill;
389 const previous = yield* SubscriptionRef.get(state);
390 const snapshot = reuseUnchangedThreadShells(
391 Option.getOrNull(previous.snapshot),
392 withoutDeferredPullRequests(httpSnapshot.value),
393 );
394 const pendingLinkIds = new Set(
395 httpSnapshot.value.loadPullRequests === undefined
396 ? []
397 : httpSnapshot.value.threads.map((thread) => thread.id),
398 );
399 yield* applyItems([{ kind: "snapshot", snapshot }], pendingLinkIds);
400 canResume = true;
401 current = yield* SubscriptionRef.get(state);
402 if (Option.isSome(current.snapshot)) {
403 yield* fillDeferredPullRequests(httpSnapshot.value, current.snapshot.value);
404 }
405 }
406 }
407
408 const omission = omitIdleSubagents ? { omitIdleSubagents: true as const } : {};
409 if (!canResume || Option.isNone(current.snapshot)) {
410 return {
411 ...omission,
412 ...(supportsCompletionMarker ? { requestCompletionMarker: true as const } : {}),
413 };
414 }
415 if (!supportsCompletionMarker) {
416 yield* SubscriptionRef.update(state, (value) => ({
417 ...value,
418 status: "live" as const,
419 error: Option.none(),
420 }));
421 }
422 return {
423 afterSequence: current.snapshot.value.snapshotSequence,
424 ...omission,
425 ...(supportsCompletionMarker ? { requestCompletionMarker: true as const } : {}),
426 };
427 }),
428 {
429 onExpectedFailure: (cause) => setStreamError(Cause.squash(cause)),
430 retryExpectedFailureAfter: "250 millis",
431 resubscribe: foregroundResubscriptions,
432 },
433 ).pipe(Stream.runForEachArray((items) => applyItems(items))),
434 );
435 yield* SubscriptionRef.changes(supervisor.state).pipe(
436 Stream.runForEach((connectionState) => {
437 switch (connectionProjectionPhase(connectionState)) {
438 case "synchronizing":
439 return setSynchronizing;
440 case "disconnected":
441 return setDisconnected;
442 case "ready":
443 return setReady;
444 }
445 }),
446 Effect.forkScoped,
447 );
448
449 return state;
450});
451
452function shellStateChanges(environmentId: EnvironmentId) {
453 return followStreamInEnvironment(
454 environmentId,
455 Stream.unwrap(makeEnvironmentShellState().pipe(Effect.map(SubscriptionRef.changes))),
456 );
457}
458
459export interface EnvironmentShellSummary {
460 readonly hasSnapshot: boolean;
461 readonly hasSynchronizingShell: boolean;
462 readonly hasCachedShell: boolean;
463 readonly hasLiveShell: boolean;
464 readonly firstError: string | null;
465}
466
467const EMPTY_ENVIRONMENT_SHELL_SUMMARY: EnvironmentShellSummary = Object.freeze({
468 hasSnapshot: false,
469 hasSynchronizingShell: false,
470 hasCachedShell: false,
471 hasLiveShell: false,
472 firstError: null,
473});
474
475const EMPTY_SERVER_CONFIGS: ReadonlyMap<EnvironmentId, ServerConfig> = new Map();
476
477function shellSummariesEqual(
478 left: EnvironmentShellSummary,
479 right: EnvironmentShellSummary,
480): boolean {
481 return (
482 left.hasSnapshot === right.hasSnapshot &&
483 left.hasSynchronizingShell === right.hasSynchronizingShell &&
484 left.hasCachedShell === right.hasCachedShell &&
485 left.hasLiveShell === right.hasLiveShell &&
486 left.firstError === right.firstError
487 );
488}
489
490function mapsEqual<K, V>(left: ReadonlyMap<K, V>, right: ReadonlyMap<K, V>): boolean {
491 if (left.size !== right.size) {
492 return false;
493 }
494 for (const [key, value] of left) {
495 if (right.get(key) !== value) {
496 return false;
497 }
498 }
499 return true;
500}
501
502export function createEnvironmentShellSummaryAtom(input: {
503 readonly catalogValueAtom: Atom.Atom<EnvironmentCatalogState>;
504 readonly shellStateValueAtom: (environmentId: EnvironmentId) => Atom.Atom<EnvironmentShellState>;
505}) {
506 let previousSummary = EMPTY_ENVIRONMENT_SHELL_SUMMARY;
507 return Atom.make((get) => {
508 let hasSnapshot = false;
509 let hasSynchronizingShell = false;
510 let hasCachedShell = false;
511 let hasLiveShell = false;
512 let firstError: string | null = null;
513
514 for (const environmentId of enabledEnvironmentIds(get(input.catalogValueAtom))) {
515 const state = get(input.shellStateValueAtom(environmentId));
516 hasSynchronizingShell ||= state.status === "synchronizing";
517 hasCachedShell ||= state.status === "cached";
518 hasLiveShell ||= state.status === "live";
519 if (firstError === null) {
520 firstError = Option.getOrNull(state.error);
521 }
522 if (Option.isNone(state.snapshot)) {
523 continue;
524 }
525 hasSnapshot = true;
526 }
527
528 const next: EnvironmentShellSummary = {
529 hasSnapshot,
530 hasSynchronizingShell,
531 hasCachedShell,
532 hasLiveShell,
533 firstError,
534 };
535 if (shellSummariesEqual(previousSummary, next)) {
536 return previousSummary;
537 }
538 previousSummary = next;
539 return previousSummary;
540 }).pipe(Atom.withLabel("environment-shell-summary"));
541}
542
543export function createEnvironmentServerConfigsAtom(input: {
544 readonly catalogValueAtom: Atom.Atom<EnvironmentCatalogState>;
545 readonly serverConfigValueAtom: (environmentId: EnvironmentId) => Atom.Atom<ServerConfig | null>;
546}) {
547 let previousServerConfigs = EMPTY_SERVER_CONFIGS;
548 return Atom.make((get) => {
549 const next = new Map<EnvironmentId, ServerConfig>();
550 for (const environmentId of enabledEnvironmentIds(get(input.catalogValueAtom))) {
551 const config = get(input.serverConfigValueAtom(environmentId));
552 if (config !== null) {
553 next.set(environmentId, config);
554 }
555 }
556 if (mapsEqual(previousServerConfigs, next)) {
557 return previousServerConfigs;
558 }
559 previousServerConfigs = next;
560 return previousServerConfigs;
561 }).pipe(Atom.withLabel("environment-server-configs"));
562}
563
564/**
565 * Every shell push replaces the state, so views that gate on load progress read these
566 * primitives instead and stay put while threads stream.
567 */
568function createEnvironmentShellProgressAtoms(
569 stateValueAtom: (environmentId: EnvironmentId) => Atom.Atom<EnvironmentShellState>,
570) {
571 return {
572 statusAtom: Atom.family((environmentId: EnvironmentId) =>
573 Atom.make((get) => get(stateValueAtom(environmentId)).status).pipe(
574 Atom.withLabel(`environment-shell-status:${environmentId}`),
575 ),
576 ),
577 hasSnapshotAtom: Atom.family((environmentId: EnvironmentId) =>
578 Atom.make((get) => Option.isSome(get(stateValueAtom(environmentId)).snapshot)).pipe(
579 Atom.withLabel(`environment-shell-has-snapshot:${environmentId}`),
580 ),
581 ),
582 };
583}
584
585export function createEnvironmentShellAtoms<R, E>(
586 runtime: Atom.AtomRuntime<
587 | EnvironmentRegistry.EnvironmentRegistry
588 | Persistence.EnvironmentCacheStore
589 | ShellSnapshotLoader.ShellSnapshotLoader
590 | R,
591 E
592 >,
593) {
594 const stateAtom = Atom.family((environmentId: EnvironmentId) =>
595 runtime.atom(shellStateChanges(environmentId), {
596 initialValue: EMPTY_SHELL_STATE,
597 }),
598 );
599
600 const stateValueAtom = Atom.family((environmentId: EnvironmentId) =>
601 Atom.make((get) =>
602 Option.getOrElse(AsyncResult.value(get(stateAtom(environmentId))), () => EMPTY_SHELL_STATE),
603 ).pipe(Atom.withLabel(`environment-shell-state-value:${environmentId}`)),
604 );
605
606 const { statusAtom, hasSnapshotAtom } = createEnvironmentShellProgressAtoms(stateValueAtom);
607
608 return {
609 stateAtom,
610 stateValueAtom,
611 statusAtom,
612 hasSnapshotAtom,
613 };
614}
615
616export * from "./models.ts";
617export * from "./shellCommands.ts";
618export * from "./shellReducer.ts";
619export * from "./shellPullRequests.ts";
620export * as ShellSnapshotLoader from "./shellSnapshotHttp.ts";
621export * from "./snapshots.ts";