UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

45 lines • 1.78 kB
export class MoveFencedError extends Error { constructor(moveId, record, detail) { super(`Move ${moveId} can no longer be imported here: ${detail ?? `it was already answered (${record?.state ?? "no record"})`}.`); this.code = "move_fenced"; this.name = "MoveFencedError"; this.moveId = moveId; this.record = record; } } const DECLINE_REASONS = [ "no_record", "expired", "cancelled", "chunk_without_ready", "repository", ]; const FAIL_REASONS = ["bundle_invalid", "import_failed"]; /** A receiver's answer as it arrives back at the sender; a `ready` record is not an answer. */ export function parseMoveStatus(value) { const record = parseRecord(value); return record?.state === "ready" ? undefined : record; } /** A record as it was written; `undefined` when the value is not one. */ export function parseRecord(value) { if (typeof value !== "object" || value === null) return undefined; const { state, reason } = value; if (state === "accepted" && value.revoked === true) return { state, revoked: true }; if (state === "receiving") return { state }; if (state === "accepted") return { state }; const { expiresAt } = value; if (state === "ready" && typeof expiresAt === "string" && !Number.isNaN(Date.parse(expiresAt))) return { state, expiresAt }; const decline = DECLINE_REASONS.find((known) => known === reason); if (state === "declined" && decline !== undefined) return { state, reason: decline }; const fail = FAIL_REASONS.find((known) => known === reason); if (state === "failed" && fail !== undefined) return { state, reason: fail }; return undefined; } //# sourceMappingURL=move-record.js.map