The best way to control Claude Code, Codex and more from any computer or phone

main
ts 22 lines 887 Bytes
Raw
1 import * as Effect from "effect/Effect";
2 import * as References from "effect/References";
3
4 const snapshotStack = (
5 frame: References.StackFrame | undefined,
6 ): References.StackFrame | undefined => {
7 if (frame === undefined) return undefined;
8 const stack = frame.stack();
9 return { name: frame.name, stack: () => stack, parent: snapshotStack(frame.parent) };
10 };
11
12 /**
13 * Wrap a `Cache.get` so its lookup fiber inherits a materialized stack. The lazy
14 * caller frame would otherwise retain the caller's request snapshot for the TTL.
15 * Stay untraced so this helper does not introduce another lazy frame to retain.
16 */
17 export const detachStackFrame = Effect.fnUntraced(function* <A, E, R>(
18 effect: Effect.Effect<A, E, R>,
19 ) {
20 const frame = snapshotStack(yield* References.CurrentStackFrame);
21 return yield* Effect.provideService(effect, References.CurrentStackFrame, frame);
22 });