@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 64 lines 2.27 KB
Raw
1 import * as Config from "effect/Config";
2 import * as Effect from "effect/Effect";
3
4 declare global {
5 /**
6 * Build-time flag marking the runtime (post-bundle) phase.
7 *
8 * The bundler folds this to `true` in every runtime artifact (see
9 * `ALCHEMY_DEFINE` in `Bundle/Bundle.ts`), so plan-only code guarded by
10 * `if (!globalThis.__ALCHEMY_RUNTIME__)` is dead-code-eliminated from deployed
11 * Workers/Lambdas/Containers.
12 *
13 * When running source directly with bun/node (no bundler) it is `undefined`
14 * (falsy), so plan-only branches run. Reading it never throws because it is a
15 * property access on `globalThis`.
16 */
17 var __ALCHEMY_RUNTIME__: boolean | undefined;
18 /**
19 * Build-time constant naming the cloud identity a bundle's host runs as,
20 * defined by the bundler of a host that has one: `"AWS.IAM.Role"` for a
21 * Lambda, ECS task or EC2 instance, `"GCP.IAM.ServiceAccount"` for Cloud Run,
22 * Cloud Functions or GKE. `undefined` everywhere else.
23 *
24 * A provider's bindings compare it against their own identity type to drop
25 * the code that host never runs (signing with a key Alchemy created).
26 */
27 var __ALCHEMY_HOST_IDENTITY__: string | undefined;
28 }
29
30 export type AlchemyPhase = "plan" | "runtime";
31
32 export const ALCHEMY_PHASE = Config.String("ALCHEMY_PHASE").pipe(
33 Config.withDefault("plan"),
34 Config.mapEffect((value) => {
35 if (value !== "plan" && value !== "runtime") {
36 return Effect.die(new Error(`Invalid ALCHEMY_PHASE: ${value}`));
37 }
38 return Effect.succeed(value as AlchemyPhase);
39 }),
40 Effect.orDie,
41 );
42
43 /**
44 * Whether the program is running under `alchemy dev` (local development with
45 * hot reload), exposed as the `ALCHEMY_DEV` environment variable / config key.
46 *
47 * The `alchemy dev` CLI command sets `ALCHEMY_DEV=true` on the spawned process;
48 * every other entrypoint (`deploy`, `plan`, deployed runtime) leaves it unset,
49 * so it defaults to `false`. Accepts the usual truthy strings (`true`, `1`,
50 * `yes`, `on`).
51 *
52 * Read it from user code to branch on dev mode:
53 *
54 * ```typescript
55 * import { ALCHEMY_DEV } from "alchemy";
56 *
57 * Effect.gen(function* () {
58 * if (yield* ALCHEMY_DEV) {
59 * // local-dev-only behavior
60 * }
61 * });
62 * ```
63 */
64 export const ALCHEMY_DEV = Config.Boolean("ALCHEMY_DEV").pipe(Config.withDefault(false));