215 lines · 7.5 KB
import { randomId } from "../crypto";

/** A claim is advisory: it never blocks git, but overlapping claims are refused unless forced. */
export type LeaseKind = "task" | "file";

export type Lease = {
  id: string;
  kind: LeaseKind;
  key: string;
  holder: string;
  agent: string;
  user: string;
  note: string | null;
  expiresAt: number;
};

export type ClaimRequest = {
  kind: LeaseKind;
  keys: string[];
  holder: string;
  agent: string;
  user: string;
  note: string | null;
  ttlMs: number;
  force: boolean;
};

export type ClaimConflict = { key: string; lease: Lease };
export type ClaimResult = { granted: Lease[]; conflicts: ClaimConflict[] };

/** `data` is JSON text so events cross Durable Object RPC without deep generic types. */
export type RepoEvent = { seq: number; type: string; at: number; data: string };

const MAX_EVENTS = 200;
const MAX_LEASES = 2000;
export const MAX_SUBSCRIBERS = 200;

type LeaseRow = {
  id: string;
  kind: LeaseKind;