// @generated by scripts/build-runtime.mjs; do not edit. // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader. import { fileHashMap } from "./chunk-RGJ6SOYR.ts"; import { agentDir } from "./chunk-APZVBSM6.ts"; import { inspectRemoteSelection } from "./chunk-YQ6UW7IF.ts"; // src/sync-errors.ts var SetupPullRequiresUiError = class extends Error { }; var SyncDecisionRequiredError = class extends Error { decision; constructor(decision) { super(decision.directMessage); this.name = "SyncDecisionRequiredError"; this.decision = decision; } }; function isSyncDecisionRequiredError(error) { return error instanceof SyncDecisionRequiredError; } function errorMessage(error) { const message = error instanceof Error ? error.message : String(error); return message.replace(/[\u0000-\u001f\u007f-\u009f]/gu, "?"); } // src/sync-format.ts function formatDiff(local, remote) { const localMap = fileHashMap(local); const remoteMap = fileHashMap(remote); const allPaths = [.../* @__PURE__ */ new Set([...Object.keys(localMap), ...Object.keys(remoteMap)])].sort(); const lines = [ `local: ${local.files.length} files`, `remote: ${remote.id} (${remote.files.length} files)`, "" ]; let changed = 0; for (const filePath of allPaths) { if (!localMap[filePath]) { lines.push(`Remote only: ${filePath}`); changed += 1; } else if (!remoteMap[filePath]) { lines.push(`Local only: ${filePath}`); changed += 1; } else if (localMap[filePath] !== remoteMap[filePath]) { lines.push(`Different: ${filePath}`); changed += 1; } } if (changed === 0) lines.push("No file differences."); return lines.join("\n"); } function formatSnapshotOnlyDiff(title, snapshot) { return [`${title}: ${snapshot.id}`, ...snapshot.files.map((file) => `Add: ${file.path}`)].join( "\n" ); } function formatPushSummary(config, destination, upload, head, preservedRemoteFileCount = 0, remote) { return [ `Sync setup: ${safeTerminalText(config.setupName)}`, `Storage location: ${safeTerminalText(destination)}`, `Upload ${upload.files.length} files from ${safeTerminalText(agentDir())}.`, `Sessions: ${upload.syncSessions ? "included \u2014 may contain private conversations" : "not included"}`, head ? `Remote latest: ${head.snapshotId}` : "Remote latest: empty", "Publication effect: the backend's active head will reference the new immutable snapshot.", ...remote && inspectRemoteSelection(config.include, remote).kind === "different" ? [ "Included-content policy effect: replace the differing remote selection with this setup's local selection." ] : [], formatPublicationPreview(remote, upload), preservedRemoteFileCount > 0 ? `Possible secrets in locally managed files were scanned before this prompt; ${preservedRemoteFileCount} preserved remote file(s) were not rescanned.` : "Possible secrets were scanned before this prompt." ].join("\n"); } function formatApplyPreview(local, remote) { return formatDirectionalChanges(local, remote, { add: "Add locally", update: "Update locally", remove: "Remove locally" }); } function formatPullSummary(config, destination, local, remote, protectedSessionCount) { return [ `Sync setup: ${safeTerminalText(config.setupName)}`, `Storage location: ${safeTerminalText(destination)}`, `Snapshot: ${safeTerminalText(remote.id)}`, `Sessions: ${remote.syncSessions ? "included \u2014 may contain private conversations" : "not included"}`, `Protected live sessions: ${protectedSessionCount || "none"}`, formatApplyPreview(local, remote), "A local backup is created before these writes/deletes. The remote active snapshot is unchanged." ].join("\n"); } function formatRollbackSummary(config, destination, local, remote, requestedSnapshot, protectedSessionCount) { return [ `Sync setup: ${safeTerminalText(config.setupName)}`, `Storage location: ${safeTerminalText(destination)}`, `Snapshot: ${safeTerminalText(requestedSnapshot)}`, `Sessions: ${remote.syncSessions ? "included \u2014 may contain private conversations" : "not included"}`, `Protected live sessions: ${protectedSessionCount || "none"}`, formatApplyPreview(local, remote), "A local backup is created before applying; the backend's active head will change." ].join("\n"); } function formatPublicationPreview(remote, upload) { if (!remote) { return ["Remote is empty.", ...upload.files.map((file) => `Add remotely: ${file.path}`)].join( "\n" ); } return formatDirectionalChanges(remote, upload, { add: "Add remotely", update: "Update remotely", remove: "Remove remotely" }); } function formatDirectionalChanges(before, after, labels) { const beforeMap = fileHashMap(before); const afterMap = fileHashMap(after); const paths = [.../* @__PURE__ */ new Set([...Object.keys(beforeMap), ...Object.keys(afterMap)])].sort(); const lines = []; for (const filePath of paths) { if (!beforeMap[filePath]) lines.push(`${labels.add}: ${filePath}`); else if (!afterMap[filePath]) lines.push(`${labels.remove}: ${filePath}`); else if (beforeMap[filePath] !== afterMap[filePath]) lines.push(`${labels.update}: ${filePath}`); } if (lines.length === 0) lines.push("No file changes."); return lines.join("\n"); } function countPreservedRemoteFiles(local, upload) { const localPaths = new Set(local.files.map((file) => file.path)); return upload.files.filter((file) => !localPaths.has(file.path)).length; } function publicationCapabilityDescription(capability) { switch (capability) { case "lease-protected": return "lease-protected (exact expected-ref update)"; case "atomic-conditional": return "atomic-conditional (verified atomic precondition)"; case "conditional-required": return "conditional-required (read-only until atomic preconditions are verified)"; case "read-check-write-verify": return "read-check-write-verify (visible races rejected; simultaneous unseen races remain possible)"; } } function safeTerminalText(value) { return value.replace(/[\u0000-\u001f\u007f-\u009f]/gu, "?"); } export { SetupPullRequiresUiError, SyncDecisionRequiredError, isSyncDecisionRequiredError, errorMessage, formatDiff, formatSnapshotOnlyDiff, formatPushSummary, formatPullSummary, formatRollbackSummary, countPreservedRemoteFiles, publicationCapabilityDescription, safeTerminalText }; //# sourceMappingURL=chunk-W64NEHXT.ts.map