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 };
/** `renewed` lists granted lease ids the holder already had before this claim. */
export type ClaimResult = { granted: Lease[]; conflicts: ClaimConflict[]; renewed: string[] };
/** `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;
const MAX_LEASES_PER_HOLDER = 200;
export const MAX_SUBSCRIBERS = 200;
/** One token (or user) may hold only a few of a repo's subscriber slots, so a reader cannot starve the rest (INT-A13). */
export const MAX_SUBSCRIBERS_PER_OWNER = 10;