/** * Replica presence mapper (T12721): one fleet-view location → the path-free * `ReplicaPresence` the cleo-nexus cloud accepts at * `PUT /v1/projects/:projectId/replicas/:replicaId/presence`. * * Pure: no I/O, no clock. Everything the contract marks **device-local, never * mirrored** — path, hostname, remote name and URL, upstream ref, HEAD and * upstream commit shas, probe error text — is read only to derive a boolean, * a count or an enum, and never copied. `branch` is copied only when the * caller opts in. * * @task T12721 * @epic T12496 */ import type { NexusFleetDevice, NexusFleetGitSummary, NexusFleetLocation } from '@cleocode/contracts'; import type { ReplicaPresence } from '@cleocode/contracts/cloud'; /** The `git` block of a {@link ReplicaPresence}. */ export type ReplicaPresenceGit = NonNullable; /** The remote tracking state a presence reports. */ export type ReplicaRemoteState = ReplicaPresenceGit['remote']; /** Server-side length limits of `ReplicaPresence` string fields. */ export declare const REPLICA_PRESENCE_LIMITS: { /** `git.branch` maximum length. */ readonly branchMax: 200; /** `cliVersion` maximum length. */ readonly cliVersionMax: 40; }; /** `cliVersion` sent when the device never reported its CLEO version. */ export declare const UNKNOWN_CLI_VERSION = "unknown"; /** Options for {@link toReplicaPresence}. */ export interface ToReplicaPresenceOptions { /** Include the checked-out branch (truncated to 200). Default `false`: branch names can be sensitive. */ includeBranch?: boolean; /** Presence schema version. Default {@link NEXUS_FLEET_SCHEMA_VERSION}. */ schemaVersion?: number; } /** * Remote tracking state of one probe row, as the presence enum. * * - a real probe failure (path missing or unreadable, not a repo, git error or * timeout) → `unknown`. `E_FETCH_FAILED` is NOT one: an offline `--fetch` * still recorded valid local ahead/behind as of the LAST fetch, so it maps * exactly like a probe that never fetched; * - no upstream → `no-upstream`; * - an upstream whose tracking ref is gone (`remote.headSha` null — e.g. the * branch was deleted remotely and pruned) or whose ahead/behind git did not * report → `unknown`, never a defaulted `in-sync`; * - never fetched (`fetchedAt` null) → `unknown`; * - otherwise from ahead/behind as of the last fetch: both → `diverged`, * ahead only → `ahead`, behind only → `behind`, neither → `in-sync`. * * @param git - Recorded git summary of the location. * @returns The presence remote state. * @example * ```ts * replicaRemoteState(summary); // 'behind' * ``` */ export declare function replicaRemoteState(git: NexusFleetGitSummary): ReplicaRemoteState; /** * Map one fleet-view location on one device to the cloud `ReplicaPresence`. * * - `observedAt` is the probe instant (`git.probedAt`); an unprobed location * has no `git` block and reports when it was last encountered (`lastSeen`). * - `cliVersion` is `device.cleoVersion` truncated to 40, or `unknown`. * - `git.dirty` is `(dirtyCount ?? 0) + (untrackedCount ?? 0) > 0`; * `ahead`/`behind` default to 0; `remote` is {@link replicaRemoteState}; * `lastCommitAt` is `headCommittedAt` when known; `branch` only with * `includeBranch`, truncated to 200. * * The replica id is not part of the body: it is the `:replicaId` path * segment (`location.replicaId`), and a caller must not send presence while * it is `null`. * * @param location - The location, from `nexus.projects.fleet`. * @param device - The device holding it (same `deviceId`). * @param opts - Branch opt-in and schema version. * @returns A path-free presence body. * @throws Error when `device.deviceId` differs from `location.deviceId`, or * when the observation instant (`git.probedAt`, else `lastSeen`) is not a * parseable timestamp — a raw string is never sent as `observedAt`. * @example * ```ts * const body = toReplicaPresence(loc, device, { includeBranch: false }); * ``` */ export declare function toReplicaPresence(location: NexusFleetLocation, device: NexusFleetDevice, opts?: ToReplicaPresenceOptions): ReplicaPresence; //# sourceMappingURL=presence.d.ts.map