Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

2.9 KB
Raw Blame
import {
  GenerationScopedRequestOwner,
  type RequestLease,
  type RequestScope
} from './generation-scoped-request-owner'

// Keep lease compile fences outside tests because mobile typechecking excludes them; unused expect-error directives fail the gate.

type FileParameters = { readonly query: string }

declare const scope: RequestScope
declare const host: object
declare const epoch: bigint
declare const label: symbol
declare const paths: GenerationScopedRequestOwner<FileParameters, string[]>
declare const counts: GenerationScopedRequestOwner<FileParameters, number>
declare const pathLease: RequestLease<string[]>
declare const countLease: RequestLease<number>

// @ts-expect-error the brand is module-private, so no caller can mint a lease
export const fenceForgedLease: RequestLease<string[]> = {}

// @ts-expect-error a lease is invariant in its value, so two owners' leases are not interchangeable
export const fenceSwappedLease: RequestLease<string[]> = countLease

export function fenceCommitTakesItsOwnLease(): void {
  // @ts-expect-error the value must be the one this owner publishes
  paths.commit(pathLease, 42)
  // @ts-expect-error a peer owner's lease is not this owner's to commit
  paths.commit(countLease, ['a'])
  counts.commit(countLease, 42)
}

export function fenceParametersAreOwnerTyped(): void {
  // @ts-expect-error the parameters are the owner's declared type, not a caller-chosen key
  paths.read(scope, 'files.list:A')
  // @ts-expect-error a missing declared parameter is not a key the owner can build
  paths.read(scope, {})
  paths.read(scope, { query: 'a' })
}

export function fenceScopeMembersAreEncodable(): void {
  // @ts-expect-error a symbol has no encoding here that is both stable and collision-free
  void paths.read([host, label], { query: 'a' })
  // @ts-expect-error a bigint is not serialisable, so it cannot identify a scope
  void paths.read([host, epoch], { query: 'a' })
  void paths.read([host, 'w1', 2], { query: 'a' })
}

export function fenceLoaderOnlyReturns(): void {
  // @ts-expect-error the loader publishes by returning the owner's value, not some other type
  void paths.load(scope, { query: 'a' }, async () => 'not-a-path-list')
  void paths.load(scope, { query: 'a' }, async () => null)
  void paths.load(scope, { query: 'a' }, async (currency) => (currency.isCurrent() ? ['a'] : null))
}

export function fenceCurrencyIsAProbeNotALease(): void {
  void paths.load(scope, { query: 'a' }, async (currency) => {
    // @ts-expect-error the probe answers currency and is not the lease, so it cannot publish
    paths.commit(currency, ['a'])
    // @ts-expect-error the probe exposes no generation at all, so there is no member to read
    void currency.generation
    return null
  })
}

// @ts-expect-error the lease carries its generation privately; a caller cannot read or compare it
export const fenceLeaseGenerationUnreadable: number = pathLease.generation