flag.ts 753 B

1234567891011121314151617181920
  1. import type { WorkspaceV2 } from "@kirincode-ai/core/workspace"
  2. import { Flag } from "@kirincode-ai/core/flag/flag"
  3. import { Effect, Scope } from "effect"
  4. /**
  5. * Scoped override for `Flag.KIRINCODE_WORKSPACE_ID`. Saves the previous value
  6. * on entry and restores it via finalizer when the surrounding scope closes —
  7. * preserves the original try/finally semantics regardless of test outcome.
  8. */
  9. export function withFixedWorkspaceID(id: WorkspaceV2.ID): Effect.Effect<void, never, Scope.Scope> {
  10. return Effect.gen(function* () {
  11. const previous = Flag.KIRINCODE_WORKSPACE_ID
  12. Flag.KIRINCODE_WORKSPACE_ID = id
  13. yield* Effect.addFinalizer(() =>
  14. Effect.sync(() => {
  15. Flag.KIRINCODE_WORKSPACE_ID = previous
  16. }),
  17. )
  18. })
  19. }