@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 52 lines 1.85 KB
Raw
1 import * as EffectContext from "effect/Context";
2 import * as Effect from "effect/Effect";
3 import * as FileSystem from "effect/FileSystem";
4 import * as Layer from "effect/Layer";
5 import * as Option from "effect/Option";
6 import path from "pathe";
7
8 export class AlchemyContext extends EffectContext.Service<
9 AlchemyContext,
10 {
11 dotAlchemy: string;
12 dev: boolean;
13 /**
14 * Global default for the {@link import("./AdoptPolicy.ts").AdoptPolicy}
15 * service. When `true`, resources without prior state will be adopted by
16 * calling their `read` lifecycle operation; if that returns attributes
17 * (and does not fail with `OwnedBySomeoneElse`), those attributes are
18 * persisted as the resource's initial `created` state.
19 *
20 * The CLI's `--adopt` flag flows in through this field. Per-resource
21 * overrides via the `adopt(enabled)` combinator still take precedence.
22 */
23 adopt: boolean;
24 /**
25 * When `true`, an out-of-date Cloudflare state store is upgraded
26 * automatically instead of prompting for confirmation (and the upgrade
27 * proceeds even in CI). The CLI's `--yes` flag flows in through this field.
28 * @default false
29 */
30 updateStateStore?: boolean;
31 }
32 >()("alchemy/Context") {}
33
34 /** Use the configured runtime directory, with a relative fallback for standalone callers. */
35 export const dotAlchemyDirectory = Effect.serviceOption(AlchemyContext).pipe(
36 Effect.map((context) => (Option.isSome(context) ? context.value.dotAlchemy : ".alchemy")),
37 );
38
39 export const AlchemyContextLive = Layer.effect(
40 AlchemyContext,
41 Effect.gen(function* () {
42 const fs = yield* FileSystem.FileSystem;
43 const dir = path.resolve(yield* dotAlchemyDirectory);
44 yield* fs.makeDirectory(dir, { recursive: true });
45 return {
46 dotAlchemy: dir,
47 updateStateStore: false,
48 dev: false,
49 adopt: false,
50 };
51 }),
52 );