@narumitw/pi-sync 0.57.11 → 0.57.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +27 -21
  3. package/dist/chunks/{agent-candidate-OCDPRI5G.ts → agent-candidate-U2NU3GUX.ts} +2 -2
  4. package/dist/chunks/{agent-plan-P5B5RGZ7.ts → agent-plan-3YXDIJXO.ts} +13 -10
  5. package/dist/chunks/agent-plan-3YXDIJXO.ts.map +7 -0
  6. package/dist/chunks/{agent-runner-WMSCKSCB.ts → agent-runner-FCRV2Z75.ts} +11 -10
  7. package/dist/chunks/agent-runner-FCRV2Z75.ts.map +7 -0
  8. package/dist/chunks/{agent-store-RJSMNOYP.ts → agent-store-7GINKTS7.ts} +2 -2
  9. package/dist/chunks/{agent-store-RJSMNOYP.ts.map → agent-store-7GINKTS7.ts.map} +2 -2
  10. package/dist/chunks/{agent-sync-EUK2CPSS.ts → agent-sync-P6AWQXGK.ts} +2 -2
  11. package/dist/chunks/{chunk-67INJPKR.ts → chunk-CQD2TJHE.ts} +4 -4
  12. package/dist/chunks/{chunk-67INJPKR.ts.map → chunk-CQD2TJHE.ts.map} +2 -2
  13. package/dist/chunks/{chunk-7OLLPPLU.ts → chunk-MMQIEDZ6.ts} +6 -6
  14. package/dist/chunks/{chunk-7OLLPPLU.ts.map → chunk-MMQIEDZ6.ts.map} +2 -2
  15. package/dist/chunks/{chunk-NLWS55B6.ts → chunk-QPC5HT3A.ts} +2 -2
  16. package/dist/chunks/{chunk-NLWS55B6.ts.map → chunk-QPC5HT3A.ts.map} +1 -1
  17. package/dist/chunks/{chunk-DRTC4PKM.ts → chunk-S5OCYVPS.ts} +2 -2
  18. package/dist/chunks/{chunk-DRTC4PKM.ts.map → chunk-S5OCYVPS.ts.map} +2 -2
  19. package/dist/chunks/{chunk-3IYAPMST.ts → chunk-U6GXGY5G.ts} +2 -2
  20. package/dist/chunks/{chunk-CPT2BN6N.ts → chunk-XEODG2PE.ts} +2 -2
  21. package/dist/chunks/{chunk-F7E3VFXU.ts → chunk-ZC3IHFNM.ts} +6 -6
  22. package/dist/chunks/{chunk-F7E3VFXU.ts.map → chunk-ZC3IHFNM.ts.map} +2 -2
  23. package/dist/chunks/{command-handler-F2E7A5T5.ts → command-handler-VKLZBRLO.ts} +9 -9
  24. package/dist/chunks/{command-handler-F2E7A5T5.ts.map → command-handler-VKLZBRLO.ts.map} +2 -2
  25. package/dist/chunks/{conflict-review-2QMO2K6Q.ts → conflict-review-GXA6Y7KY.ts} +2 -2
  26. package/dist/chunks/{continuous-record-AH7JGYKM.ts → continuous-record-EPHGR2DU.ts} +2 -2
  27. package/dist/chunks/{continuous-sync-VRMXCA5X.ts → continuous-sync-TTOSJCQU.ts} +3 -3
  28. package/dist/chunks/{manager-ui-LM7DSJ2Y.ts → manager-ui-INVMAFEN.ts} +146 -176
  29. package/dist/chunks/manager-ui-INVMAFEN.ts.map +7 -0
  30. package/dist/chunks/{setup-switch-PIPXYPCW.ts → setup-switch-KLGESLQX.ts} +3 -3
  31. package/dist/chunks/{setup-wizard-RR5U3SUB.ts → setup-wizard-ZQAK35BP.ts} +3 -3
  32. package/dist/chunks/{sync-operations-CV3TULLD.ts → sync-operations-TMGQHBF5.ts} +4 -4
  33. package/dist/chunks/{sync-operations-CV3TULLD.ts.map → sync-operations-TMGQHBF5.ts.map} +2 -2
  34. package/dist/index.ts +6 -6
  35. package/docs/agent-continuous-hardening.md +5 -5
  36. package/docs/agent-mode-verification.md +3 -3
  37. package/docs/agent-quality-verification.md +3 -3
  38. package/docs/continuous-sync-verification.md +2 -2
  39. package/docs/settings.md +9 -5
  40. package/docs/tui-contract.md +20 -3
  41. package/package.json +3 -3
  42. package/skills/configure-pi-sync/SKILL.md +3 -1
  43. package/skills/configure-pi-sync/references/configuration.md +48 -37
  44. package/src/commands/command-execution.ts +3 -3
  45. package/src/commands/command.ts +1 -1
  46. package/src/settings/settings-types.ts +1 -1
  47. package/src/sync/agent-candidate.ts +3 -3
  48. package/src/sync/agent-plan.ts +11 -8
  49. package/src/sync/agent-runner.ts +10 -9
  50. package/src/sync/agent-store.ts +1 -1
  51. package/src/sync/agent-sync.ts +2 -2
  52. package/src/sync/continuous-record.ts +1 -1
  53. package/src/sync/merged-sync.ts +4 -4
  54. package/src/sync/sync-mutations.ts +1 -1
  55. package/src/ui/agent-mode-setting.ts +6 -6
  56. package/src/ui/manager-state.ts +1 -1
  57. package/src/ui/settings-ui.ts +19 -55
  58. package/src/ui/setup/setup-switcher.ts +2 -2
  59. package/src/ui/sync-setups-ui.ts +2 -2
  60. package/dist/chunks/agent-plan-P5B5RGZ7.ts.map +0 -7
  61. package/dist/chunks/agent-runner-WMSCKSCB.ts.map +0 -7
  62. package/dist/chunks/manager-ui-LM7DSJ2Y.ts.map +0 -7
  63. /package/dist/chunks/{agent-candidate-OCDPRI5G.ts.map → agent-candidate-U2NU3GUX.ts.map} +0 -0
  64. /package/dist/chunks/{agent-sync-EUK2CPSS.ts.map → agent-sync-P6AWQXGK.ts.map} +0 -0
  65. /package/dist/chunks/{chunk-3IYAPMST.ts.map → chunk-U6GXGY5G.ts.map} +0 -0
  66. /package/dist/chunks/{chunk-CPT2BN6N.ts.map → chunk-XEODG2PE.ts.map} +0 -0
  67. /package/dist/chunks/{conflict-review-2QMO2K6Q.ts.map → conflict-review-GXA6Y7KY.ts.map} +0 -0
  68. /package/dist/chunks/{continuous-record-AH7JGYKM.ts.map → continuous-record-EPHGR2DU.ts.map} +0 -0
  69. /package/dist/chunks/{continuous-sync-VRMXCA5X.ts.map → continuous-sync-TTOSJCQU.ts.map} +0 -0
  70. /package/dist/chunks/{setup-switch-PIPXYPCW.ts.map → setup-switch-KLGESLQX.ts.map} +0 -0
  71. /package/dist/chunks/{setup-wizard-RR5U3SUB.ts.map → setup-wizard-ZQAK35BP.ts.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/ui/transfer-review.ts", "../../src/sync/apply-review.ts", "../../src/sync/field-migration.ts", "../../src/sync/sync-mutations.ts", "../../src/sync/sync-queries.ts"],
4
- "sourcesContent": ["import type { ExtensionCommandContext, ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { confirmMergeReview } from \"./merge-review.js\";\n\n/** Reuse the scrollable safe-default review in TUI; retain RPC's confirmation protocol. */\nexport async function confirmTransferReview(\n ctx: ExtensionCommandContext | ExtensionContext,\n title: string,\n content: string,\n signal: AbortSignal | undefined,\n validate: () => void,\n) {\n validate();\n const isCurrent = () => {\n try {\n validate();\n return true;\n } catch {\n return false;\n }\n };\n const confirmed =\n ctx.mode === \"tui\" && ctx.hasUI\n ? await confirmMergeReview(ctx, title, content, signal, isCurrent, \"apply reviewed transfer\", content.split(\"\\n\"))\n : await ctx.ui.confirm(title, content, { signal });\n validate();\n return confirmed;\n}\n", "import { createHash } from \"node:crypto\";\nimport { constants } from \"node:fs\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { agentDir } from \"../snapshot/session-paths.js\";\nimport { addTopLevelCaseVariantDeletes } from \"../snapshot/snapshot-apply.js\";\nimport type { Snapshot } from \"../snapshot/snapshot-types.js\";\nimport { throwIfAborted } from \"./signals.js\";\n\nexport interface CaseCleanupReview {\n path: string;\n fingerprint: string;\n}\n\n/** Inspect the apply engine's additional alias removals, which logical snapshots omit. */\nexport async function inspectCaseCleanup(snapshot: Snapshot, signal?: AbortSignal): Promise<CaseCleanupReview[]> {\n throwIfAborted(signal);\n const root = agentDir();\n const plan = await addTopLevelCaseVariantDeletes(root, { writes: [], deletes: [] }, snapshot);\n throwIfAborted(signal);\n const review: CaseCleanupReview[] = [];\n for (const target of plan.deletes.sort()) {\n const stat = await fs.lstat(target);\n throwIfAborted(signal);\n const hash = createHash(\"sha256\");\n if (stat.isSymbolicLink()) hash.update(await fs.readlink(target));\n else {\n if (!stat.isFile()) throw new Error(\"Case-variant path is no longer a regular file or symlink.\");\n const handle = await fs.open(\n target,\n constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0),\n );\n try {\n throwIfAborted(signal);\n const opened = await handle.stat();\n if (!opened.isFile() || opened.dev !== stat.dev || opened.ino !== stat.ino)\n throw new Error(\"Case-variant file changed while preparing review.\");\n for await (const bytes of handle.createReadStream({ autoClose: false, signal })) {\n throwIfAborted(signal);\n hash.update(bytes);\n }\n } finally {\n await handle.close();\n }\n }\n throwIfAborted(signal);\n review.push({\n path: path.basename(target),\n fingerprint: `${stat.dev}:${stat.ino}:${stat.mode}:${hash.digest(\"hex\")}`,\n });\n }\n return review;\n}\n\nexport async function revalidateCaseCleanup(\n expected: readonly CaseCleanupReview[],\n snapshot: Snapshot,\n signal?: AbortSignal,\n) {\n const current = await inspectCaseCleanup(snapshot, signal);\n if (JSON.stringify(current) !== JSON.stringify(expected))\n throw new Error(\"Case-variant paths changed during transfer review; reopen the preview.\");\n}\n", "import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport type { Snapshot } from \"../snapshot/snapshot-types.js\";\nimport type { SyncState } from \"../state/state-types.js\";\nimport { safeTerminalText } from \"../ui/terminal-text.js\";\nimport { sameLocalFields } from \"./local-fields.js\";\nimport { captureMutationOwner } from \"./sync-local.js\";\n\nexport async function confirmFieldMigration(\n ctx: ExtensionContext,\n config: AnySyncConfig,\n state: SyncState,\n remote: Snapshot | undefined,\n force: boolean,\n signal?: AbortSignal,\n) {\n if (remote?.localFields !== undefined && config.localFields === undefined)\n throw new Error(\n \"Portable snapshots require settings version 4 and explicit localFields rules on this machine; older policy must not replace local-only values.\",\n );\n const changed =\n (Boolean(state.lastAppliedSnapshot) && !sameLocalFields(state.localFields, config.localFields)) ||\n (remote !== undefined && !sameLocalFields(remote.localFields, config.localFields));\n if (!changed) return true;\n if (!force)\n throw new Error(\n \"Local-field policy changed; review an explicit push --force or pull --force migration. Old remote history is not erased.\",\n );\n const validate = captureMutationOwner(ctx, signal);\n if (!ctx.hasUI) throw new Error(\"Local-field migration requires observable TUI/RPC confirmation.\");\n validate();\n const confirmed = await ctx.ui.confirm(\n \"Migrate portable settings policy?\",\n `New machine-local fields: ${(config.localFields ?? []).map(safeTerminalText).join(\", \") || \"none\"}. Additions remove fields from future snapshots, not old history. Removals make local-only values portable again and a pull may replace them. The selected direction is authoritative; inspect /sync diff first. This confirmation is required even with --yes.`,\n { signal },\n );\n validate();\n return confirmed;\n}\n", "import type { ExtensionCommandContext, ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { createSyncBackend, type SyncBackendFactory } from \"../backends/backend-factory.js\";\nimport {\n expectedRemoteHead,\n type PublishSnapshotResult,\n type RemoteHead,\n type SyncBackend,\n} from \"../backends/sync-backend.js\";\nimport type { CommandOptions } from \"../commands/command-types.js\";\nimport { loadConfig, syncCheckConfigFingerprint } from \"../settings/config.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport { sessionDirForApply, snapshotOptionsForContext } from \"../snapshot/session-paths.js\";\nimport {\n createSnapshot,\n filterSnapshotForConfigPolicy,\n mergeRemotePreservedFiles,\n regenerateSnapshotIdentity,\n scanSnapshot,\n snapshotIncludesSessions,\n snapshotWithoutSessions,\n} from \"../snapshot/snapshot.js\";\nimport { applySnapshot } from \"../snapshot/snapshot-apply.js\";\nimport type { Snapshot } from \"../snapshot/snapshot-types.js\";\nimport { pruneMergeBaselines } from \"../state/merge-baseline-store.js\";\nimport type { SyncState } from \"../state/state-types.js\";\nimport { readStateForConfig, syncStateFingerprint, writeStateForConfig } from \"../state/sync-state-store.js\";\nimport {\n countPreservedRemoteFiles,\n formatPullSummary,\n formatPushSummary,\n formatRollbackSummary,\n} from \"../ui/sync-format.js\";\nimport { setSyncStatus } from \"../ui/sync-status.js\";\nimport { confirmTransferReview } from \"../ui/transfer-review.js\";\nimport { startupTransferEnabled } from \"./agent-policy.js\";\nimport { inspectCaseCleanup, revalidateCaseCleanup } from \"./apply-review.js\";\nimport { confirmFieldMigration } from \"./field-migration.js\";\nimport { overlayLocalFields, portableSnapshot, sameLocalFields, validatePortableSnapshot } from \"./local-fields.js\";\nimport { readMergeJournal, requireNoMergeJournal, retireMergeJournal } from \"./merge-journal.js\";\nimport { mergeSync } from \"./merged-sync.js\";\nimport { readRemoteSnapshot, readSnapshotForHead, requireCompatibleRemoteSelection } from \"./remote-snapshot.js\";\nimport { throwIfAborted } from \"./signals.js\";\nimport { createSyncDecision } from \"./sync-decision.js\";\nimport { errorMessage } from \"./sync-errors.js\";\n\nimport { backupLocal, captureMutationOwner, protectedSessionPaths } from \"./sync-local.js\";\nimport { inspectRemoteSelection } from \"./sync-policy.js\";\nimport {\n canPullRemoteSessionsOnFirstSync,\n canPullRemoteSettingsOnFirstSync,\n fileHashMap,\n hasLocalChanges,\n hasRemoteChanges,\n remoteChangedSinceState,\n sameHashes,\n shouldRefreshSyncedState,\n snapshotHashesMatchState,\n snapshotsMatch,\n syncPolicyChanged,\n} from \"./sync-state.js\";\n\nconst VERSION = 1;\nconst POST_LOCAL_COMMIT_TIMEOUT_MS = 30_000;\n\n/** Whole-direction acceptance must never forget withheld state without an explicit recovery choice. */\nfunction requireResolvedDirectionalProgress(state: SyncState, options: CommandOptions, allowForce = true) {\n if (state.unresolved?.length && (options.auto || !options.force || !allowForce))\n throw new Error(\n \"Unresolved partial conflicts remain. Review /sync conflicts or explicitly choose push --force or pull --force; automatic transfer and rollback cannot accept unresolved groups.\",\n );\n}\n\nexport class PublicationStatePersistenceError extends Error {\n readonly head: RemoteHead;\n readonly backupPath?: string;\n\n constructor(head: RemoteHead, cause: unknown, backupPath?: string) {\n super(\n `Remote publication ${head.snapshotId} is active, but local sync state could not be saved${backupPath ? `; local backup: ${backupPath}` : \"\"}: ${errorMessage(cause)}`,\n { cause },\n );\n this.name = \"PublicationStatePersistenceError\";\n this.head = head;\n this.backupPath = backupPath;\n }\n}\n\nexport class RollbackPublicationError extends Error {\n readonly backupPath: string;\n\n constructor(backupPath: string, cause: unknown) {\n super(`Rollback applied locally with backup ${backupPath}, but remote publication failed: ${errorMessage(cause)}`, {\n cause,\n });\n this.name = \"RollbackPublicationError\";\n this.backupPath = backupPath;\n }\n}\n\ninterface PushInput {\n config: AnySyncConfig;\n state: SyncState;\n local: Snapshot;\n backend?: SyncBackend;\n}\n\nexport async function push(\n ctx: ExtensionCommandContext | ExtensionContext,\n options: CommandOptions,\n input?: PushInput,\n factory: SyncBackendFactory = createSyncBackend,\n) {\n const validateMutation = captureMutationOwner(ctx, options.signal);\n const validateCommittedOwner = captureMutationOwner(ctx);\n const config = input?.config ?? (await loadConfig(options.setup));\n throwIfAborted(options.signal);\n await requireNoMergeJournal(config, options);\n const state = input?.state ?? (await readStateForConfig(config));\n validateMutation();\n requireResolvedDirectionalProgress(state, options);\n setSyncStatus(ctx, `pushing ${config.setupName}`);\n const backend = input?.backend ?? (await factory(config));\n throwIfAborted(options.signal);\n const localRaw =\n input?.local ?? (await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config)));\n const local = portableSnapshot(localRaw, config.localFields);\n throwIfAborted(options.signal);\n\n let head = await backend.readHead(options.signal);\n let remoteForUpload = await readRemoteSnapshotForUpload(backend, config, head, state, options.signal);\n if (\n !options.force &&\n !remoteForUpload &&\n head?.selection &&\n inspectRemoteSelection(config.include, { selection: head.selection, files: [] }).kind === \"different\"\n ) {\n remoteForUpload = await readSnapshotForHead(backend, head, options.signal);\n }\n if (remoteForUpload && !options.force) {\n requireCompatibleRemoteSelection(config, remoteForUpload);\n }\n if (\n remoteChangedSinceState(head, state, config, (left, right) => backend.sameRevision(left, right)) &&\n !options.force\n ) {\n const remoteForConflict = remoteForUpload ? filterSnapshotForConfigPolicy(remoteForUpload, config) : undefined;\n if (!remoteForConflict || !snapshotHashesMatchState(remoteForConflict, state, config)) {\n throw createSyncDecision({\n kind: head ? \"remote-or-policy-changed\" : \"remote-empty\",\n config,\n state,\n local,\n remote: remoteForConflict,\n localChanged: hasLocalChanges(local, state, config),\n remoteChanged: true,\n directMessage: \"Remote or sync policy changed since last sync. Run /sync pull first or /sync push --force.\",\n });\n }\n }\n\n if (!remoteForUpload && head && (config.localFields !== undefined || !options.yes))\n remoteForUpload = await readSnapshotForHead(backend, head, options.signal);\n if (!(await confirmFieldMigration(ctx, config, state, remoteForUpload, options.force, options.signal))) {\n setSyncStatus(ctx, undefined);\n return \"cancelled\" as const;\n }\n const configIdentity = syncCheckConfigFingerprint(config);\n let upload = await snapshotForUpload(backend, config, local, head, remoteForUpload, options.signal);\n if (!config.skipSecretScan) {\n const secrets = scanSnapshot(local);\n if (secrets.length > 0) {\n throw new Error(`Refusing to push possible secrets:\\n${secrets.map((s) => `- ${s}`).join(\"\\n\")}`);\n }\n }\n\n if (!(await confirmPush(ctx, options, config, backend, local, upload, head, remoteForUpload))) {\n return \"cancelled\" as const;\n }\n\n if (options.force) {\n const refreshedHead = await backend.readHead(options.signal);\n if (!sameRemoteHead(backend, head, refreshedHead)) {\n head = refreshedHead;\n remoteForUpload = head ? await readSnapshotForHead(backend, head, options.signal) : undefined;\n validateMutation();\n if (!(await confirmFieldMigration(ctx, config, state, remoteForUpload, options.force, options.signal))) {\n setSyncStatus(ctx, undefined);\n return \"cancelled\" as const;\n }\n validateMutation();\n upload = await snapshotForUpload(backend, config, local, head, remoteForUpload, options.signal);\n if (\n !(await confirmPush(\n ctx,\n options,\n config,\n backend,\n local,\n upload,\n head,\n remoteForUpload,\n \"Remote changed during review. Push the refreshed plan?\",\n ))\n ) {\n return \"cancelled\" as const;\n }\n }\n }\n\n validateMutation();\n if (configIdentity !== syncCheckConfigFingerprint(await loadConfig(options.setup)))\n throw new Error(\"Settings changed during push review.\");\n validateMutation();\n if (!options.yes || config.localFields !== undefined || (await readMergeJournal(config))) {\n const current = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));\n if (!sameHashes(fileHashMap(current), fileHashMap(localRaw)))\n throw new Error(\"Local content changed during push review; retry from current bytes.\");\n }\n const currentState = await readStateForConfig(config);\n if (!options.yes && syncStateFingerprint(currentState) !== syncStateFingerprint(state))\n throw new Error(\"Baseline changed during push review.\");\n requireResolvedDirectionalProgress(currentState, options);\n validateMutation();\n const result = await backend.publishSnapshot(upload, expectedRemoteHead(head), {\n signal: options.signal,\n onCommit: options.onCommit,\n });\n try {\n await writeStateForConfig(\n config,\n {\n version: VERSION,\n profile: config.snapshotIdentity,\n lastAppliedSnapshot: result.head.snapshotId,\n lastRemoteRevision: result.head.revision,\n lastFileHashes: fileHashMap(local),\n include: [...config.include],\n ...(config.localFields !== undefined ? { localFields: config.localFields } : {}),\n },\n local,\n validateCommittedOwner,\n );\n } catch (error) {\n throw new PublicationStatePersistenceError(result.head, error);\n }\n await retireMergeJournal(config);\n await pruneMergeBaselines(config, await readStateForConfig(config), validateCommittedOwner);\n validateCommittedOwner();\n if (options.signal?.aborted) return;\n setSyncStatus(ctx, undefined);\n if (!options.silent) {\n ctx.ui.notify(\n [\n `Pushed ${upload.files.length} files from sync setup \u201C${config.setupName}\u201D as ${result.head.snapshotId}.`,\n ...result.warnings,\n ]\n .filter(Boolean)\n .join(\"\\n\"),\n result.warnings.length > 0 ? \"warning\" : \"info\",\n );\n }\n return \"applied\" as const;\n}\n\nexport async function pull(\n ctx: ExtensionCommandContext | ExtensionContext,\n options: CommandOptions,\n factory: SyncBackendFactory = createSyncBackend,\n) {\n const validateMutation = captureMutationOwner(ctx, options.signal);\n const validateCommittedOwner = captureMutationOwner(ctx);\n const config = await loadConfig(options.setup);\n throwIfAborted(options.signal);\n await requireNoMergeJournal(config, options);\n setSyncStatus(ctx, `pulling ${config.setupName}`);\n const backend = await factory(config);\n const state = await readStateForConfig(config);\n validateMutation();\n requireResolvedDirectionalProgress(state, options);\n const local = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));\n throwIfAborted(options.signal);\n const { head, snapshot: remote } = await readRemoteSnapshot(backend, config, options.signal);\n throwIfAborted(options.signal);\n const localChanged = hasLocalChanges(local, state, config);\n if (!remote) {\n throw createSyncDecision({\n kind: \"remote-empty\",\n config,\n state,\n local,\n localChanged,\n remoteChanged: false,\n directMessage: \"Remote is empty. Run /sync push from a configured machine first.\",\n });\n }\n\n if (!sameLocalFields(config.localFields, remote.localFields)) {\n setSyncStatus(ctx, undefined);\n throw new Error(\n \"Pull requires the configured local-field policy to match the remote. To change the remote policy, review push --force from the authoritative machine first, then pull using matching rules; old history is not erased.\",\n );\n }\n if (!(await confirmFieldMigration(ctx, config, state, remote, options.force, options.signal))) {\n setSyncStatus(ctx, undefined);\n return \"cancelled\" as const;\n }\n const configIdentity = syncCheckConfigFingerprint(config);\n const logical = portableSnapshot(remote, config.localFields);\n const physical = overlayLocalFields(logical, local, config.localFields);\n const remoteChanged = hasRemoteChanges(remote, state, config, protectedSessionPaths(ctx));\n if (localChanged && remoteChanged && state.lastAppliedSnapshot && !options.force) {\n throw createSyncDecision({\n kind: \"both-changed\",\n config,\n state,\n local,\n remote,\n localChanged,\n remoteChanged,\n directMessage:\n \"Both local and remote changed since last sync. Run /sync diff, then choose /sync pull --force or /sync push --force.\",\n });\n }\n\n const caseCleanup = options.yes ? [] : await inspectCaseCleanup(physical, options.signal);\n validateMutation();\n if (\n !options.yes &&\n !(await confirmTransferReview(\n ctx,\n snapshotIncludesSessions(remote) ? \"Pull pi settings and sessions?\" : \"Pull pi settings?\",\n formatPullSummary(\n config,\n backend.destination,\n local,\n physical,\n protectedSessionPaths(ctx),\n caseCleanup.map((item) => item.path),\n ),\n options.signal,\n validateMutation,\n ))\n ) {\n setSyncStatus(ctx, undefined);\n ctx.ui.notify(\"Pull cancelled.\", \"info\");\n return \"cancelled\" as const;\n }\n\n throwIfAborted(options.signal);\n const recoveringMerge = Boolean(await readMergeJournal(config));\n const requireFreshRecovery = async () => {\n validateMutation();\n const currentHead = await backend.readHead(options.signal);\n validateMutation();\n const current = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));\n validateMutation();\n if (!sameHashes(fileHashMap(current), fileHashMap(local)) || !sameRemoteHead(backend, head, currentHead)) {\n throw new Error(\"Local or remote content changed during recovery review; retry from a fresh diff.\");\n }\n };\n if (recoveringMerge) await requireFreshRecovery();\n if (configIdentity !== syncCheckConfigFingerprint(await loadConfig(options.setup)))\n throw new Error(\"Settings changed during pull review.\");\n validateMutation();\n const refreshed = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));\n if (!sameHashes(fileHashMap(local), fileHashMap(refreshed)))\n throw new Error(\"Local bytes changed during pull review.\");\n if (!sameRemoteHead(backend, head, await backend.readHead(options.signal)))\n throw new Error(\"Remote changed during pull review.\");\n validateMutation();\n const backup = await backupLocal(config.snapshotIdentity, snapshotOptionsForContext(ctx, config), options.signal);\n const applySessionDir = await sessionDirForApply(ctx, physical);\n if (recoveringMerge) await requireFreshRecovery();\n const currentState = await readStateForConfig(config);\n if (!options.yes && syncStateFingerprint(currentState) !== syncStateFingerprint(state))\n throw new Error(\"Baseline changed during pull review.\");\n requireResolvedDirectionalProgress(currentState, options);\n if (!options.yes) await revalidateCaseCleanup(caseCleanup, physical, options.signal);\n validateMutation();\n options.onCommit?.();\n const lastFileHashes = await applySnapshot(physical, protectedSessionPaths(ctx), {\n include: config.include,\n sessionDir: applySessionDir,\n signal: options.signal,\n validateMutation,\n expectedFileHashes: config.localFields?.length\n ? { \"settings.json\": fileHashMap(local)[\"settings.json\"] ?? null }\n : undefined,\n });\n // Local installation is complete; user cancellation must not leave the baseline stale.\n validateCommittedOwner();\n await writeStateForConfig(\n config,\n {\n version: VERSION,\n profile: config.snapshotIdentity,\n lastAppliedSnapshot: remote.id,\n lastRemoteRevision: head?.revision,\n lastFileHashes: config.localFields?.length\n ? { ...lastFileHashes, \"settings.json\": fileHashMap(logical)[\"settings.json\"] }\n : lastFileHashes,\n include: [...config.include],\n ...(config.localFields !== undefined ? { localFields: config.localFields } : {}),\n },\n logical,\n validateCommittedOwner,\n );\n await retireMergeJournal(config);\n await pruneMergeBaselines(config, await readStateForConfig(config), validateCommittedOwner);\n validateCommittedOwner();\n if (options.signal?.aborted) return \"applied\" as const;\n setSyncStatus(ctx, undefined);\n if (!options.silent) {\n ctx.ui.notify(`Pulled ${remote.files.length} files from ${remote.id}. Backup: ${backup}`, \"info\");\n } else if (options.auto && config.include.includes(\"sessions\") && snapshotIncludesSessions(remote)) {\n ctx.ui.notify(\n \"Pulled Pi sessions after startup selected the current session. Restart Pi or resume a pulled session to use newly synced conversations.\",\n \"warning\",\n );\n }\n if (options.reload) await maybeReload(ctx, options.signal, validateMutation);\n return \"applied\" as const;\n}\n\nexport async function syncBoth(\n ctx: ExtensionCommandContext | ExtensionContext,\n options: CommandOptions,\n factory: SyncBackendFactory = createSyncBackend,\n) {\n const validateMutation = captureMutationOwner(ctx, options.signal);\n const config = await loadConfig(options.setup);\n throwIfAborted(options.signal);\n options.background?.validate(config);\n if (options.agentRetryRefusal) {\n if (!config.agentMode || options.auto || options.background || !ctx.hasUI)\n throw new Error(\"Enable Agent mode and use the foreground manager to retry a cached refusal.\");\n const state = await readStateForConfig(config);\n validateMutation();\n const pending = await readMergeJournal(config);\n validateMutation();\n if (!config.include.length || !state.lastAppliedSnapshot || pending)\n throw new Error(\"Retry requires an accepted baseline and no pending journal. Use Sync now or reviewed recovery.\");\n return mergeSync(ctx, options, factory);\n }\n if (config.include.length > 0 && options.auto && startupTransferEnabled(config))\n return mergeSync(ctx, options, factory);\n if (!options.auto && config.include.length > 0 && (await readMergeJournal(config)))\n return mergeSync(ctx, options, factory);\n const state = await readStateForConfig(config);\n throwIfAborted(options.signal);\n if (!options.auto && config.include.length > 0 && state.lastAppliedSnapshot) return mergeSync(ctx, options, factory);\n const backend = await factory(config);\n const local = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));\n throwIfAborted(options.signal);\n if (config.include.length === 0) {\n if (!options.silent) {\n ctx.ui.notify(\n `Sync setup \u201C${config.setupName}\u201D includes no files. Choose included content in /sync Settings before syncing.`,\n \"warning\",\n );\n }\n return;\n }\n const { head, snapshot: remote } = await readRemoteSnapshot(backend, config, options.signal);\n throwIfAborted(options.signal);\n const localChanged = hasLocalChanges(local, state, config);\n const remoteChanged = remote ? hasRemoteChanges(remote, state, config, protectedSessionPaths(ctx)) : false;\n if (options.auto) throw new Error(\"Automatic transfer is not authorized by the current settings.\");\n\n // Established baselines return through mergeSync above; only initial-source selection remains.\n const portableLocal = portableSnapshot(local, config.localFields);\n const acceptMatchingState = async (snapshot: Snapshot) => {\n requireCompatibleRemoteSelection(config, snapshot);\n const accepted = portableSnapshot(snapshot, config.localFields);\n await writeStateForConfig(\n config,\n {\n version: VERSION,\n profile: config.snapshotIdentity,\n lastAppliedSnapshot: snapshot.id,\n lastRemoteRevision: head?.revision,\n lastFileHashes: fileHashMap(accepted),\n include: [...config.include],\n ...(config.localFields !== undefined ? { localFields: config.localFields } : {}),\n },\n accepted,\n validateMutation,\n );\n await pruneMergeBaselines(config, await readStateForConfig(config), validateMutation);\n validateMutation();\n };\n if (remote && remote.files.length > 0 && local.files.length > 0) {\n requireCompatibleRemoteSelection(config, remote);\n const portableRemote = portableSnapshot(remote, config.localFields);\n if (!canPullRemoteSettingsOnFirstSync(portableLocal, portableRemote)) {\n throw createSyncDecision({\n kind: \"first-sync-settings-diverged\",\n config,\n state,\n local,\n remote,\n localChanged: true,\n remoteChanged: true,\n directMessage:\n \"Remote settings exist and this machine has different local Pi settings. Run /sync diff, then manually choose /sync pull or /sync push.\",\n });\n }\n if (!sameHashes(fileHashMap(portableLocal), fileHashMap(portableRemote))) {\n if (!canPullRemoteSessionsOnFirstSync(portableLocal, portableRemote)) {\n throw createSyncDecision({\n kind: \"first-sync-sessions-diverged\",\n config,\n state,\n local,\n remote,\n localChanged: true,\n remoteChanged: true,\n directMessage:\n \"Remote settings match, but local and remote Pi sessions differ. Run /sync diff, then manually choose /sync pull or /sync push.\",\n });\n }\n await pull(ctx, options, factory);\n return;\n }\n await acceptMatchingState(remote);\n if (!options.silent) ctx.ui.notify(\"pi-sync state initialized; local settings already match remote.\", \"info\");\n return;\n }\n if (\n localChanged &&\n remoteChanged &&\n remote &&\n snapshotsMatch(portableLocal, portableSnapshot(remote, remote.localFields))\n ) {\n requireCompatibleRemoteSelection(config, remote);\n await acceptMatchingState(remote);\n if (!options.silent) ctx.ui.notify(\"pi-sync is already up to date.\", \"info\");\n return;\n }\n if (remoteChanged) {\n await pull(ctx, options, factory);\n return;\n }\n if (localChanged || !remote) {\n await push(ctx, options, undefined, factory);\n return;\n }\n if (shouldRefreshSyncedState(remote, head, state, config, (left, right) => backend.sameRevision(left, right))) {\n await acceptMatchingState(remote);\n }\n if (!options.silent) ctx.ui.notify(\"pi-sync is already up to date.\", \"info\");\n}\n\nexport async function rollback(\n ctx: ExtensionCommandContext,\n options: CommandOptions,\n factory: SyncBackendFactory = createSyncBackend,\n expectedSelection?: { backendIdentity: string; setup?: string },\n) {\n const validateMutation = captureMutationOwner(ctx, options.signal);\n const validateCommittedOwner = captureMutationOwner(ctx);\n const target = options.args[0];\n if (!target) throw new Error(\"Usage: /sync rollback <snapshot-id> [--yes]\");\n\n const config = await loadConfig(options.setup);\n throwIfAborted(options.signal);\n const backend = await factory(config);\n if (\n expectedSelection &&\n (backend.identity !== expectedSelection.backendIdentity || config.setupName !== expectedSelection.setup)\n ) {\n throw new Error(\"Sync setup or storage location changed while history was open; reopen history and retry.\");\n }\n // --force is only a rollback compatibility flag, not a reviewed merge-recovery direction.\n await requireNoMergeJournal(config);\n const state = await readStateForConfig(config);\n validateMutation();\n requireResolvedDirectionalProgress(state, options, false);\n const decoded = await backend.readSnapshot(target, options.signal);\n validatePortableSnapshot(decoded);\n if (!sameLocalFields(decoded.localFields, config.localFields))\n throw new Error(\n \"Rollback requires the historical snapshot local-field policy to match the configured rules. Review push --force from current local bytes to migrate policy first; choose matching history afterward.\",\n );\n const selected = filterSnapshotForConfigPolicy(\n config.include.includes(\"sessions\") ? decoded : snapshotWithoutSessions(decoded),\n config,\n );\n const remote = portableSnapshot(regenerateSnapshotIdentity(selected), config.localFields);\n const local = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));\n const expectedHead = await backend.readHead(options.signal);\n const currentRemote = expectedHead ? await readSnapshotForHead(backend, expectedHead, options.signal) : undefined;\n validateMutation();\n if (!(await confirmFieldMigration(ctx, config, state, currentRemote, true, options.signal))) return;\n validateMutation();\n const physical = overlayLocalFields(remote, local, config.localFields);\n const caseCleanup = options.yes ? [] : await inspectCaseCleanup(physical, options.signal);\n validateMutation();\n\n if (!options.yes) {\n const confirmed = await ctx.ui.confirm(\n snapshotIncludesSessions(remote) ? \"Rollback pi settings and sessions?\" : \"Rollback pi settings?\",\n formatRollbackSummary(\n config,\n backend.destination,\n local,\n physical,\n target,\n protectedSessionPaths(ctx),\n caseCleanup.map((item) => item.path),\n ),\n { signal: options.signal },\n );\n validateMutation();\n if (!confirmed) {\n ctx.ui.notify(\"Rollback cancelled.\", \"info\");\n return;\n }\n }\n\n validateMutation();\n const currentLocal = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));\n if (!sameHashes(fileHashMap(currentLocal), fileHashMap(local)))\n throw new Error(\"Local bytes changed during rollback review.\");\n if (syncCheckConfigFingerprint(config) !== syncCheckConfigFingerprint(await loadConfig(options.setup)))\n throw new Error(\"Settings changed during rollback review.\");\n if (!sameRemoteHead(backend, expectedHead, await backend.readHead(options.signal)))\n throw new Error(\"Remote changed during rollback review.\");\n validateMutation();\n throwIfAborted(options.signal);\n const backup = await backupLocal(config.snapshotIdentity, snapshotOptionsForContext(ctx, config), options.signal);\n const applySessionDir = await sessionDirForApply(ctx, remote);\n const currentState = await readStateForConfig(config);\n if (!options.yes && syncStateFingerprint(currentState) !== syncStateFingerprint(state))\n throw new Error(\"Baseline changed during rollback review.\");\n requireResolvedDirectionalProgress(currentState, options, false);\n if (!options.yes) await revalidateCaseCleanup(caseCleanup, physical, options.signal);\n validateMutation();\n options.onCommit?.();\n const lastFileHashes = await applySnapshot(physical, protectedSessionPaths(ctx), {\n include: config.include,\n sessionDir: applySessionDir,\n signal: options.signal,\n validateMutation,\n expectedFileHashes: config.localFields?.length\n ? { \"settings.json\": fileHashMap(local)[\"settings.json\"] ?? null }\n : undefined,\n });\n // The local transaction is retired; finish publication despite caller cancellation.\n validateCommittedOwner();\n let result: PublishSnapshotResult;\n try {\n const completionSignal = AbortSignal.timeout(POST_LOCAL_COMMIT_TIMEOUT_MS);\n const upload = await snapshotForUpload(backend, config, remote, expectedHead, currentRemote, completionSignal);\n validateCommittedOwner();\n result = await backend.publishSnapshot(upload, expectedRemoteHead(expectedHead), {\n signal: completionSignal,\n });\n } catch (error) {\n throw new RollbackPublicationError(backup, error);\n }\n try {\n await writeStateForConfig(\n config,\n {\n version: VERSION,\n profile: config.snapshotIdentity,\n lastAppliedSnapshot: result.head.snapshotId,\n lastRemoteRevision: result.head.revision,\n lastFileHashes: config.localFields?.length\n ? { ...lastFileHashes, \"settings.json\": fileHashMap(remote)[\"settings.json\"] }\n : lastFileHashes,\n include: [...config.include],\n ...(config.localFields !== undefined ? { localFields: config.localFields } : {}),\n },\n remote,\n validateCommittedOwner,\n );\n } catch (error) {\n throw new PublicationStatePersistenceError(result.head, error, backup);\n }\n await retireMergeJournal(config);\n await pruneMergeBaselines(config, await readStateForConfig(config), validateCommittedOwner);\n validateCommittedOwner();\n if (options.signal?.aborted) return;\n ctx.ui.notify(\n [\n `Rolled back sync setup \u201C${config.setupName}\u201D to ${target}; latest: ${result.head.snapshotId}. Backup: ${backup}`,\n ...result.warnings,\n ]\n .filter(Boolean)\n .join(\"\\n\"),\n result.warnings.length > 0 ? \"warning\" : \"info\",\n );\n await maybeReload(ctx, options.signal, validateMutation);\n}\n\nasync function maybeReload(\n ctx: ExtensionCommandContext | ExtensionContext,\n signal?: AbortSignal,\n validateMutation = captureMutationOwner(ctx, signal),\n) {\n if (signal?.aborted || !(\"reload\" in ctx)) return;\n validateMutation();\n if (\n ctx.hasUI &&\n (await ctx.ui.confirm(\n \"Reload Pi resources now?\",\n \"This reloads extensions, skills, prompts, themes, and context files.\",\n ))\n ) {\n if (signal?.aborted) return;\n validateMutation();\n await ctx.reload();\n }\n}\n\nasync function readRemoteSnapshotForUpload(\n backend: SyncBackend,\n config: AnySyncConfig,\n head: RemoteHead | undefined,\n state: SyncState,\n signal?: AbortSignal,\n) {\n if (\n !head ||\n (head.snapshotId === state.lastAppliedSnapshot &&\n !syncPolicyChanged(state, config) &&\n (!state.lastRemoteRevision || backend.sameRevision(head.revision, state.lastRemoteRevision)))\n ) {\n return undefined;\n }\n return readSnapshotForHead(backend, head, signal);\n}\n\nasync function snapshotForUpload(\n backend: SyncBackend,\n config: AnySyncConfig,\n local: Snapshot,\n head: RemoteHead | undefined,\n remote?: Snapshot,\n signal?: AbortSignal,\n) {\n if (!head) return local;\n const snapshot = remote ?? (await readSnapshotForHead(backend, head, signal));\n return mergeRemotePreservedFiles(local, snapshot, config);\n}\n\nasync function confirmPush(\n ctx: ExtensionCommandContext | ExtensionContext,\n options: CommandOptions,\n config: AnySyncConfig,\n backend: SyncBackend,\n local: Snapshot,\n upload: Snapshot,\n head: RemoteHead | undefined,\n remote: Snapshot | undefined,\n title = snapshotIncludesSessions(upload) ? \"Push pi settings and sessions?\" : \"Push pi settings?\",\n) {\n throwIfAborted(options.signal);\n if (options.yes) return true;\n const confirmed = await confirmTransferReview(\n ctx,\n title,\n formatPushSummary(config, backend.destination, upload, head, countPreservedRemoteFiles(local, upload), remote),\n options.signal,\n captureMutationOwner(ctx, options.signal),\n );\n throwIfAborted(options.signal);\n if (confirmed) return true;\n setSyncStatus(ctx, undefined);\n ctx.ui.notify(\"Push cancelled.\", \"info\");\n return false;\n}\n\nfunction sameRemoteHead(backend: SyncBackend, left: RemoteHead | undefined, right: RemoteHead | undefined) {\n if (!left || !right) return left === right;\n return backend.sameRevision(left.revision, right.revision);\n}\n\nexport { backupLocal } from \"./sync-local.js\";\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { createSyncBackend, type SyncBackendFactory } from \"../backends/backend-factory.js\";\nimport type { SyncBackend } from \"../backends/sync-backend.js\";\nimport type { CommandOptions } from \"../commands/command-types.js\";\nimport { loadConfig, syncSessionsWarnings } from \"../settings/config.js\";\nimport { snapshotOptionsForContext } from \"../snapshot/session-paths.js\";\nimport { createSnapshot, scanSnapshot } from \"../snapshot/snapshot.js\";\nimport type { SnapshotOptions } from \"../snapshot/snapshot-types.js\";\nimport { inspectLock, isLockGuardHeld, isStaleLock, withLock } from \"../state/lock.js\";\nimport { readStateForConfig } from \"../state/sync-state-store.js\";\nimport { formatDiff, formatSnapshotOnlyDiff, publicationCapabilityDescription } from \"../ui/sync-format.js\";\nimport { setSyncStatus } from \"../ui/sync-status.js\";\nimport { safeTerminalText } from \"../ui/terminal-text.js\";\nimport { portableSnapshot } from \"./local-fields.js\";\nimport { formatRemoteSelectionStatus, readRemoteSnapshot } from \"./remote-snapshot.js\";\nimport { throwIfAborted } from \"./signals.js\";\nimport { errorMessage } from \"./sync-errors.js\";\nimport { inspectSync } from \"./sync-inspection.js\";\nimport { rollback } from \"./sync-mutations.js\";\n\nconst DEFAULT_PROFILE = \"default\";\n\nexport async function status(\n ctx: ExtensionCommandContext,\n options: CommandOptions,\n factory: SyncBackendFactory = createSyncBackend,\n) {\n const config = await loadConfig(options.setup);\n throwIfAborted(options.signal);\n setSyncStatus(ctx, `checking ${config.setupName}`);\n const { head, selectionState, localChanged, remoteChanged, localFiles, destination, capability } = await inspectSync(\n config,\n snapshotOptionsForContext(ctx, config),\n options.signal,\n factory,\n );\n throwIfAborted(options.signal);\n\n const continuous = config.continuous\n ? await (await import(\"./continuous-record.js\")).continuousStatusLines(config)\n : [];\n throwIfAborted(options.signal);\n const remoteText = head ? `remote: ${head.snapshotId} from ${head.machine} at ${head.createdAt}` : \"remote: empty\";\n const warnings = syncSessionsWarnings(config);\n setSyncStatus(ctx, undefined);\n ctx.ui.notify(\n [\n `sync setup: ${config.setupName}`,\n `storage connection: ${config.connectionName}`,\n `storage location: ${safeTerminalText(destination)}`,\n `publication safety: ${publicationCapabilityDescription(capability)}`,\n `included content: ${config.include.join(\", \") || \"none\"}`,\n `sessions: ${config.include.includes(\"sessions\") ? \"included\" : \"excluded\"}`,\n ...continuous,\n remoteText,\n formatRemoteSelectionStatus(selectionState),\n `local files: ${localFiles}`,\n `local changed since last sync: ${localChanged ? \"yes\" : \"no\"}`,\n `remote changed since last sync: ${remoteChanged ? \"yes\" : \"no\"}`,\n ...warnings,\n ].join(\"\\n\"),\n localChanged || remoteChanged || selectionState?.kind === \"different\" || warnings.length > 0 ? \"warning\" : \"info\",\n );\n}\n\nexport async function diff(\n ctx: ExtensionCommandContext,\n options: CommandOptions,\n factory: SyncBackendFactory = createSyncBackend,\n) {\n const config = await loadConfig(options.setup);\n throwIfAborted(options.signal);\n setSyncStatus(ctx, `checking ${config.setupName}`);\n const backend = await factory(config);\n const local = portableSnapshot(\n await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config)),\n config.localFields,\n );\n throwIfAborted(options.signal);\n const { snapshot: remote, selectionState } = await readRemoteSnapshot(backend, config, options.signal, {\n allowSelectionDifference: true,\n });\n throwIfAborted(options.signal);\n setSyncStatus(ctx, undefined);\n\n const warnings = syncSessionsWarnings(config);\n const header = [\n `sync setup: ${config.setupName}`,\n `storage connection: ${config.connectionName}`,\n `storage location: ${safeTerminalText(backend.destination)}`,\n `included content: ${config.include.join(\", \") || \"none\"}`,\n `sessions: ${config.include.includes(\"sessions\") ? \"included\" : \"excluded\"}`,\n formatRemoteSelectionStatus(selectionState),\n ...warnings,\n ].join(\"\\n\");\n const level = warnings.length > 0 || selectionState?.kind === \"different\" ? \"warning\" : \"info\";\n if (!remote) {\n ctx.ui.notify(`${header}\\n\\n${formatSnapshotOnlyDiff(\"Remote is empty. Local push would upload\", local)}`, level);\n return;\n }\n\n ctx.ui.notify(`${header}\\n\\n${formatDiff(local, portableSnapshot(remote, remote.localFields))}`, level);\n}\n\nexport async function doctor(\n ctx: ExtensionCommandContext,\n options: CommandOptions,\n factory: SyncBackendFactory = createSyncBackend,\n) {\n const messages: string[] = [];\n let level: \"info\" | \"warning\" = \"info\";\n let snapshotOptions: SnapshotOptions = {};\n let profile = DEFAULT_PROFILE;\n let backend: SyncBackend | undefined;\n let backendSummary: string[] = [];\n\n try {\n const config = await loadConfig(options.setup);\n throwIfAborted(options.signal);\n backend = await factory(config);\n profile = config.snapshotIdentity;\n snapshotOptions = snapshotOptionsForContext(ctx, config);\n messages.push(\n `config: ok (sync setup ${config.setupName})`,\n `included content: ${config.include.join(\", \") || \"none\"}`,\n `sessions: ${config.include.includes(\"sessions\") ? \"included\" : \"excluded\"}`,\n );\n backendSummary = [\n `storage location: ${safeTerminalText(backend.destination)}`,\n `publication safety: ${publicationCapabilityDescription(backend.capability)}`,\n ];\n const warnings = syncSessionsWarnings(config);\n if (warnings.length > 0) {\n level = \"warning\";\n messages.push(...warnings);\n }\n } catch (error) {\n throwIfAborted(options.signal);\n level = \"warning\";\n messages.push(`config: ${errorMessage(error)}`);\n }\n\n const local = await createSnapshot(profile, snapshotOptions);\n throwIfAborted(options.signal);\n const secrets = scanSnapshot(local);\n if (secrets.length > 0) {\n level = \"warning\";\n messages.push(\"secret scan: possible secrets found:\");\n messages.push(...secrets.map((secret) => `- ${secret}`));\n } else {\n messages.push(`secret scan: ok (${local.files.length} files checked)`);\n }\n\n const lock = await inspectLock();\n throwIfAborted(options.signal);\n if (lock.status === \"valid\" && isStaleLock(lock.lock)) {\n level = \"warning\";\n messages.push(`lock: stale (pid ${lock.lock.pid}); run /sync unlock --stale after verifying no sync is running`);\n } else if (lock.status === \"valid\") {\n messages.push(`lock: held by pid ${lock.lock.pid} since ${lock.lock.startedAt}`);\n } else if (lock.status === \"unreadable\") {\n level = \"warning\";\n messages.push(\"lock: unreadable; use /sync unlock --stale only after verifying no sync is running\");\n } else if (await isLockGuardHeld()) {\n throwIfAborted(options.signal);\n level = \"warning\";\n messages.push(\"lock: guard active while metadata is missing or still being initialized\");\n } else {\n messages.push(\"lock: free\");\n }\n\n if (backend) {\n messages.push(...backendSummary);\n const diagnostics = await backend.diagnose(options.signal);\n throwIfAborted(options.signal);\n for (const diagnostic of diagnostics) {\n messages.push(diagnostic.message);\n if (diagnostic.level !== \"info\") level = \"warning\";\n }\n }\n ctx.ui.notify(messages.join(\"\\n\"), level);\n}\n\nexport async function history(\n ctx: ExtensionCommandContext,\n options: CommandOptions,\n factory: SyncBackendFactory = createSyncBackend,\n) {\n const config = await loadConfig(options.setup);\n throwIfAborted(options.signal);\n const backend = await factory(config);\n const snapshots = (await backend.listHistory(options.signal)).slice(-20).reverse();\n throwIfAborted(options.signal);\n const lastApplied = await readStateForConfig(config)\n .then((state) => state.lastAppliedSnapshot)\n .catch(() => undefined);\n throwIfAborted(options.signal);\n const appliedDetails = lastApplied\n ? `Last applied snapshot ID: ${safeTerminalText(lastApplied)}\\nApplication time: unavailable. Snapshot dates are creation times.`\n : \"Last applied snapshot ID: unavailable.\";\n if (snapshots.length === 0) {\n ctx.ui.notify(`No remote pi-sync history found.\\n${appliedDetails}`, \"info\");\n return;\n }\n\n const currentSnapshot = snapshots[0]?.snapshotId;\n if (ctx.mode === \"tui\") {\n const labels = snapshots.map(\n (item, index) =>\n `${index + 1}. ${item.createdAt} \u00B7 ${safeTerminalText(item.machine)} \u00B7 ${item.snapshotId}${item.snapshotId === currentSnapshot ? \" (current)\" : \"\"}${item.syncSessions ? \" \u00B7 sessions\" : \"\"}`,\n );\n const selected = await ctx.ui.select(\n `History for sync setup \u201C${safeTerminalText(config.setupName)}\u201D\\n\\n${appliedDetails}\\n\\nChoose a snapshot to preview rollback.`,\n [...labels, \"Back\"],\n { signal: options.signal },\n );\n if (!selected || selected === \"Back\") return;\n throwIfAborted(options.signal);\n const index = labels.indexOf(selected);\n const snapshot = snapshots[index];\n if (!snapshot) return;\n await withLock(\"rollback\", () =>\n rollback(ctx, { ...options, args: [snapshot.snapshotRef], yes: false }, factory, {\n backendIdentity: backend.identity,\n setup: config.setupName,\n }),\n );\n return;\n }\n ctx.ui.notify(\n [\n appliedDetails,\n ...snapshots.map((item) => `${item.snapshotRef} ${item.createdAt} ${safeTerminalText(item.machine)}`),\n ].join(\"\\n\"),\n \"info\",\n );\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,eAAsB,sBACpB,KACA,OACA,SACA,QACA,UACA;AACA,WAAS;AACT,QAAM,YAAY,MAAM;AACtB,QAAI;AACF,eAAS;AACT,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACA,QAAM,YACJ,IAAI,SAAS,SAAS,IAAI,QACtB,MAAM,mBAAmB,KAAK,OAAO,SAAS,QAAQ,WAAW,2BAA2B,QAAQ,MAAM,IAAI,CAAC,IAC/G,MAAM,IAAI,GAAG,QAAQ,OAAO,SAAS,EAAE,OAAO,CAAC;AACrD,WAAS;AACT,SAAO;AACT;;;AC1BA,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAC1B,OAAO,QAAQ;AACf,OAAO,UAAU;AAYjB,eAAsB,mBAAmB,UAAoB,QAAoD;AAC/G,iBAAe,MAAM;AACrB,QAAM,OAAO,SAAS;AACtB,QAAM,OAAO,MAAM,8BAA8B,MAAM,EAAE,QAAQ,CAAC,GAAG,SAAS,CAAC,EAAE,GAAG,QAAQ;AAC5F,iBAAe,MAAM;AACrB,QAAM,SAA8B,CAAC;AACrC,aAAW,UAAU,KAAK,QAAQ,KAAK,GAAG;AACxC,UAAM,OAAO,MAAM,GAAG,MAAM,MAAM;AAClC,mBAAe,MAAM;AACrB,UAAM,OAAO,WAAW,QAAQ;AAChC,QAAI,K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AAQ,QAAQ;AACrC,UAAM,WAAW,UAAU,KAAK;AAChC,QAAI,CAAC,SAAU;AACf,UAAM;AAAA,MAAS;AAAA,MAAY,MACzB,SAAS,KAAK,EAAE,GAAG,SAAS,MAAM,CAAC,SAAS,WAAW,GAAG,KAAK,MAAM,GAAG,SAAS;AAAA,QAC/E,iBAAiB,QAAQ;AAAA,QACzB,OAAO,OAAO;AAAA,MAChB,CAAC;AAAA,IACH;AACA;AAAA,EACF;AACA,MAAI,GAAG;AAAA,IACL;AAAA,MACE;AAAA,MACA,GAAG,UAAU,IAAI,CAAC,SAAS,GAAG,KAAK,WAAW,IAAI,KAAK,SAAS,IAAI,iBAAiB,KAAK,OAAO,CAAC,EAAE;AAAA,IACtG,EAAE,KAAK,IAAI;AAAA,IACX;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import type { ExtensionCommandContext, ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { confirmMergeReview } from \"./merge-review.js\";\n\n/** Reuse the scrollable safe-default review in TUI; retain RPC's confirmation protocol. */\nexport async function confirmTransferReview(\n ctx: ExtensionCommandContext | ExtensionContext,\n title: string,\n content: string,\n signal: AbortSignal | undefined,\n validate: () => void,\n) {\n validate();\n const isCurrent = () => {\n try {\n validate();\n return true;\n } catch {\n return false;\n }\n };\n const confirmed =\n ctx.mode === \"tui\" && ctx.hasUI\n ? await confirmMergeReview(ctx, title, content, signal, isCurrent, \"apply reviewed transfer\", content.split(\"\\n\"))\n : await ctx.ui.confirm(title, content, { signal });\n validate();\n return confirmed;\n}\n", "import { createHash } from \"node:crypto\";\nimport { constants } from \"node:fs\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { agentDir } from \"../snapshot/session-paths.js\";\nimport { addTopLevelCaseVariantDeletes } from \"../snapshot/snapshot-apply.js\";\nimport type { Snapshot } from \"../snapshot/snapshot-types.js\";\nimport { throwIfAborted } from \"./signals.js\";\n\nexport interface CaseCleanupReview {\n path: string;\n fingerprint: string;\n}\n\n/** Inspect the apply engine's additional alias removals, which logical snapshots omit. */\nexport async function inspectCaseCleanup(snapshot: Snapshot, signal?: AbortSignal): Promise<CaseCleanupReview[]> {\n throwIfAborted(signal);\n const root = agentDir();\n const plan = await addTopLevelCaseVariantDeletes(root, { writes: [], deletes: [] }, snapshot);\n throwIfAborted(signal);\n const review: CaseCleanupReview[] = [];\n for (const target of plan.deletes.sort()) {\n const stat = await fs.lstat(target);\n throwIfAborted(signal);\n const hash = createHash(\"sha256\");\n if (stat.isSymbolicLink()) hash.update(await fs.readlink(target));\n else {\n if (!stat.isFile()) throw new Error(\"Case-variant path is no longer a regular file or symlink.\");\n const handle = await fs.open(\n target,\n constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0),\n );\n try {\n throwIfAborted(signal);\n const opened = await handle.stat();\n if (!opened.isFile() || opened.dev !== stat.dev || opened.ino !== stat.ino)\n throw new Error(\"Case-variant file changed while preparing review.\");\n for await (const bytes of handle.createReadStream({ autoClose: false, signal })) {\n throwIfAborted(signal);\n hash.update(bytes);\n }\n } finally {\n await handle.close();\n }\n }\n throwIfAborted(signal);\n review.push({\n path: path.basename(target),\n fingerprint: `${stat.dev}:${stat.ino}:${stat.mode}:${hash.digest(\"hex\")}`,\n });\n }\n return review;\n}\n\nexport async function revalidateCaseCleanup(\n expected: readonly CaseCleanupReview[],\n snapshot: Snapshot,\n signal?: AbortSignal,\n) {\n const current = await inspectCaseCleanup(snapshot, signal);\n if (JSON.stringify(current) !== JSON.stringify(expected))\n throw new Error(\"Case-variant paths changed during transfer review; reopen the preview.\");\n}\n", "import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport type { Snapshot } from \"../snapshot/snapshot-types.js\";\nimport type { SyncState } from \"../state/state-types.js\";\nimport { safeTerminalText } from \"../ui/terminal-text.js\";\nimport { sameLocalFields } from \"./local-fields.js\";\nimport { captureMutationOwner } from \"./sync-local.js\";\n\nexport async function confirmFieldMigration(\n ctx: ExtensionContext,\n config: AnySyncConfig,\n state: SyncState,\n remote: Snapshot | undefined,\n force: boolean,\n signal?: AbortSignal,\n) {\n if (remote?.localFields !== undefined && config.localFields === undefined)\n throw new Error(\n \"Portable snapshots require settings version 4 and explicit localFields rules on this machine; older policy must not replace local-only values.\",\n );\n const changed =\n (Boolean(state.lastAppliedSnapshot) && !sameLocalFields(state.localFields, config.localFields)) ||\n (remote !== undefined && !sameLocalFields(remote.localFields, config.localFields));\n if (!changed) return true;\n if (!force)\n throw new Error(\n \"Local-field policy changed; review an explicit push --force or pull --force migration. Old remote history is not erased.\",\n );\n const validate = captureMutationOwner(ctx, signal);\n if (!ctx.hasUI) throw new Error(\"Local-field migration requires observable TUI/RPC confirmation.\");\n validate();\n const confirmed = await ctx.ui.confirm(\n \"Migrate portable settings policy?\",\n `New machine-local fields: ${(config.localFields ?? []).map(safeTerminalText).join(\", \") || \"none\"}. Additions remove fields from future snapshots, not old history. Removals make local-only values portable again and a pull may replace them. The selected direction is authoritative; inspect /sync diff first. This confirmation is required even with --yes.`,\n { signal },\n );\n validate();\n return confirmed;\n}\n", "import type { ExtensionCommandContext, ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { createSyncBackend, type SyncBackendFactory } from \"../backends/backend-factory.js\";\nimport {\n expectedRemoteHead,\n type PublishSnapshotResult,\n type RemoteHead,\n type SyncBackend,\n} from \"../backends/sync-backend.js\";\nimport type { CommandOptions } from \"../commands/command-types.js\";\nimport { loadConfig, syncCheckConfigFingerprint } from \"../settings/config.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport { sessionDirForApply, snapshotOptionsForContext } from \"../snapshot/session-paths.js\";\nimport {\n createSnapshot,\n filterSnapshotForConfigPolicy,\n mergeRemotePreservedFiles,\n regenerateSnapshotIdentity,\n scanSnapshot,\n snapshotIncludesSessions,\n snapshotWithoutSessions,\n} from \"../snapshot/snapshot.js\";\nimport { applySnapshot } from \"../snapshot/snapshot-apply.js\";\nimport type { Snapshot } from \"../snapshot/snapshot-types.js\";\nimport { pruneMergeBaselines } from \"../state/merge-baseline-store.js\";\nimport type { SyncState } from \"../state/state-types.js\";\nimport { readStateForConfig, syncStateFingerprint, writeStateForConfig } from \"../state/sync-state-store.js\";\nimport {\n countPreservedRemoteFiles,\n formatPullSummary,\n formatPushSummary,\n formatRollbackSummary,\n} from \"../ui/sync-format.js\";\nimport { setSyncStatus } from \"../ui/sync-status.js\";\nimport { confirmTransferReview } from \"../ui/transfer-review.js\";\nimport { startupTransferEnabled } from \"./agent-policy.js\";\nimport { inspectCaseCleanup, revalidateCaseCleanup } from \"./apply-review.js\";\nimport { confirmFieldMigration } from \"./field-migration.js\";\nimport { overlayLocalFields, portableSnapshot, sameLocalFields, validatePortableSnapshot } from \"./local-fields.js\";\nimport { readMergeJournal, requireNoMergeJournal, retireMergeJournal } from \"./merge-journal.js\";\nimport { mergeSync } from \"./merged-sync.js\";\nimport { readRemoteSnapshot, readSnapshotForHead, requireCompatibleRemoteSelection } from \"./remote-snapshot.js\";\nimport { throwIfAborted } from \"./signals.js\";\nimport { createSyncDecision } from \"./sync-decision.js\";\nimport { errorMessage } from \"./sync-errors.js\";\n\nimport { backupLocal, captureMutationOwner, protectedSessionPaths } from \"./sync-local.js\";\nimport { inspectRemoteSelection } from \"./sync-policy.js\";\nimport {\n canPullRemoteSessionsOnFirstSync,\n canPullRemoteSettingsOnFirstSync,\n fileHashMap,\n hasLocalChanges,\n hasRemoteChanges,\n remoteChangedSinceState,\n sameHashes,\n shouldRefreshSyncedState,\n snapshotHashesMatchState,\n snapshotsMatch,\n syncPolicyChanged,\n} from \"./sync-state.js\";\n\nconst VERSION = 1;\nconst POST_LOCAL_COMMIT_TIMEOUT_MS = 30_000;\n\n/** Whole-direction acceptance must never forget withheld state without an explicit recovery choice. */\nfunction requireResolvedDirectionalProgress(state: SyncState, options: CommandOptions, allowForce = true) {\n if (state.unresolved?.length && (options.auto || !options.force || !allowForce))\n throw new Error(\n \"Unresolved partial conflicts remain. Review /sync conflicts or explicitly choose push --force or pull --force; automatic transfer and rollback cannot accept unresolved groups.\",\n );\n}\n\nexport class PublicationStatePersistenceError extends Error {\n readonly head: RemoteHead;\n readonly backupPath?: string;\n\n constructor(head: RemoteHead, cause: unknown, backupPath?: string) {\n super(\n `Remote publication ${head.snapshotId} is active, but local sync state could not be saved${backupPath ? `; local backup: ${backupPath}` : \"\"}: ${errorMessage(cause)}`,\n { cause },\n );\n this.name = \"PublicationStatePersistenceError\";\n this.head = head;\n this.backupPath = backupPath;\n }\n}\n\nexport class RollbackPublicationError extends Error {\n readonly backupPath: string;\n\n constructor(backupPath: string, cause: unknown) {\n super(`Rollback applied locally with backup ${backupPath}, but remote publication failed: ${errorMessage(cause)}`, {\n cause,\n });\n this.name = \"RollbackPublicationError\";\n this.backupPath = backupPath;\n }\n}\n\ninterface PushInput {\n config: AnySyncConfig;\n state: SyncState;\n local: Snapshot;\n backend?: SyncBackend;\n}\n\nexport async function push(\n ctx: ExtensionCommandContext | ExtensionContext,\n options: CommandOptions,\n input?: PushInput,\n factory: SyncBackendFactory = createSyncBackend,\n) {\n const validateMutation = captureMutationOwner(ctx, options.signal);\n const validateCommittedOwner = captureMutationOwner(ctx);\n const config = input?.config ?? (await loadConfig(options.setup));\n throwIfAborted(options.signal);\n await requireNoMergeJournal(config, options);\n const state = input?.state ?? (await readStateForConfig(config));\n validateMutation();\n requireResolvedDirectionalProgress(state, options);\n setSyncStatus(ctx, `pushing ${config.setupName}`);\n const backend = input?.backend ?? (await factory(config));\n throwIfAborted(options.signal);\n const localRaw =\n input?.local ?? (await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config)));\n const local = portableSnapshot(localRaw, config.localFields);\n throwIfAborted(options.signal);\n\n let head = await backend.readHead(options.signal);\n let remoteForUpload = await readRemoteSnapshotForUpload(backend, config, head, state, options.signal);\n if (\n !options.force &&\n !remoteForUpload &&\n head?.selection &&\n inspectRemoteSelection(config.include, { selection: head.selection, files: [] }).kind === \"different\"\n ) {\n remoteForUpload = await readSnapshotForHead(backend, head, options.signal);\n }\n if (remoteForUpload && !options.force) {\n requireCompatibleRemoteSelection(config, remoteForUpload);\n }\n if (\n remoteChangedSinceState(head, state, config, (left, right) => backend.sameRevision(left, right)) &&\n !options.force\n ) {\n const remoteForConflict = remoteForUpload ? filterSnapshotForConfigPolicy(remoteForUpload, config) : undefined;\n if (!remoteForConflict || !snapshotHashesMatchState(remoteForConflict, state, config)) {\n throw createSyncDecision({\n kind: head ? \"remote-or-policy-changed\" : \"remote-empty\",\n config,\n state,\n local,\n remote: remoteForConflict,\n localChanged: hasLocalChanges(local, state, config),\n remoteChanged: true,\n directMessage: \"Remote or sync policy changed since last sync. Run /sync pull first or /sync push --force.\",\n });\n }\n }\n\n if (!remoteForUpload && head && (config.localFields !== undefined || !options.yes))\n remoteForUpload = await readSnapshotForHead(backend, head, options.signal);\n if (!(await confirmFieldMigration(ctx, config, state, remoteForUpload, options.force, options.signal))) {\n setSyncStatus(ctx, undefined);\n return \"cancelled\" as const;\n }\n const configIdentity = syncCheckConfigFingerprint(config);\n let upload = await snapshotForUpload(backend, config, local, head, remoteForUpload, options.signal);\n if (!config.skipSecretScan) {\n const secrets = scanSnapshot(local);\n if (secrets.length > 0) {\n throw new Error(`Refusing to push possible secrets:\\n${secrets.map((s) => `- ${s}`).join(\"\\n\")}`);\n }\n }\n\n if (!(await confirmPush(ctx, options, config, backend, local, upload, head, remoteForUpload))) {\n return \"cancelled\" as const;\n }\n\n if (options.force) {\n const refreshedHead = await backend.readHead(options.signal);\n if (!sameRemoteHead(backend, head, refreshedHead)) {\n head = refreshedHead;\n remoteForUpload = head ? await readSnapshotForHead(backend, head, options.signal) : undefined;\n validateMutation();\n if (!(await confirmFieldMigration(ctx, config, state, remoteForUpload, options.force, options.signal))) {\n setSyncStatus(ctx, undefined);\n return \"cancelled\" as const;\n }\n validateMutation();\n upload = await snapshotForUpload(backend, config, local, head, remoteForUpload, options.signal);\n if (\n !(await confirmPush(\n ctx,\n options,\n config,\n backend,\n local,\n upload,\n head,\n remoteForUpload,\n \"Remote changed during review. Push the refreshed plan?\",\n ))\n ) {\n return \"cancelled\" as const;\n }\n }\n }\n\n validateMutation();\n if (configIdentity !== syncCheckConfigFingerprint(await loadConfig(options.setup)))\n throw new Error(\"Settings changed during push review.\");\n validateMutation();\n if (!options.yes || config.localFields !== undefined || (await readMergeJournal(config))) {\n const current = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));\n if (!sameHashes(fileHashMap(current), fileHashMap(localRaw)))\n throw new Error(\"Local content changed during push review; retry from current bytes.\");\n }\n const currentState = await readStateForConfig(config);\n if (!options.yes && syncStateFingerprint(currentState) !== syncStateFingerprint(state))\n throw new Error(\"Baseline changed during push review.\");\n requireResolvedDirectionalProgress(currentState, options);\n validateMutation();\n const result = await backend.publishSnapshot(upload, expectedRemoteHead(head), {\n signal: options.signal,\n onCommit: options.onCommit,\n });\n try {\n await writeStateForConfig(\n config,\n {\n version: VERSION,\n profile: config.snapshotIdentity,\n lastAppliedSnapshot: result.head.snapshotId,\n lastRemoteRevision: result.head.revision,\n lastFileHashes: fileHashMap(local),\n include: [...config.include],\n ...(config.localFields !== undefined ? { localFields: config.localFields } : {}),\n },\n local,\n validateCommittedOwner,\n );\n } catch (error) {\n throw new PublicationStatePersistenceError(result.head, error);\n }\n await retireMergeJournal(config);\n await pruneMergeBaselines(config, await readStateForConfig(config), validateCommittedOwner);\n validateCommittedOwner();\n if (options.signal?.aborted) return;\n setSyncStatus(ctx, undefined);\n if (!options.silent) {\n ctx.ui.notify(\n [\n `Pushed ${upload.files.length} files from sync setup \u201C${config.setupName}\u201D as ${result.head.snapshotId}.`,\n ...result.warnings,\n ]\n .filter(Boolean)\n .join(\"\\n\"),\n result.warnings.length > 0 ? \"warning\" : \"info\",\n );\n }\n return \"applied\" as const;\n}\n\nexport async function pull(\n ctx: ExtensionCommandContext | ExtensionContext,\n options: CommandOptions,\n factory: SyncBackendFactory = createSyncBackend,\n) {\n const validateMutation = captureMutationOwner(ctx, options.signal);\n const validateCommittedOwner = captureMutationOwner(ctx);\n const config = await loadConfig(options.setup);\n throwIfAborted(options.signal);\n await requireNoMergeJournal(config, options);\n setSyncStatus(ctx, `pulling ${config.setupName}`);\n const backend = await factory(config);\n const state = await readStateForConfig(config);\n validateMutation();\n requireResolvedDirectionalProgress(state, options);\n const local = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));\n throwIfAborted(options.signal);\n const { head, snapshot: remote } = await readRemoteSnapshot(backend, config, options.signal);\n throwIfAborted(options.signal);\n const localChanged = hasLocalChanges(local, state, config);\n if (!remote) {\n throw createSyncDecision({\n kind: \"remote-empty\",\n config,\n state,\n local,\n localChanged,\n remoteChanged: false,\n directMessage: \"Remote is empty. Run /sync push from a configured machine first.\",\n });\n }\n\n if (!sameLocalFields(config.localFields, remote.localFields)) {\n setSyncStatus(ctx, undefined);\n throw new Error(\n \"Pull requires the configured local-field policy to match the remote. To change the remote policy, review push --force from the authoritative machine first, then pull using matching rules; old history is not erased.\",\n );\n }\n if (!(await confirmFieldMigration(ctx, config, state, remote, options.force, options.signal))) {\n setSyncStatus(ctx, undefined);\n return \"cancelled\" as const;\n }\n const configIdentity = syncCheckConfigFingerprint(config);\n const logical = portableSnapshot(remote, config.localFields);\n const physical = overlayLocalFields(logical, local, config.localFields);\n const remoteChanged = hasRemoteChanges(remote, state, config, protectedSessionPaths(ctx));\n if (localChanged && remoteChanged && state.lastAppliedSnapshot && !options.force) {\n throw createSyncDecision({\n kind: \"both-changed\",\n config,\n state,\n local,\n remote,\n localChanged,\n remoteChanged,\n directMessage:\n \"Both local and remote changed since last sync. Run /sync diff, then choose /sync pull --force or /sync push --force.\",\n });\n }\n\n const caseCleanup = options.yes ? [] : await inspectCaseCleanup(physical, options.signal);\n validateMutation();\n if (\n !options.yes &&\n !(await confirmTransferReview(\n ctx,\n snapshotIncludesSessions(remote) ? \"Pull pi settings and sessions?\" : \"Pull pi settings?\",\n formatPullSummary(\n config,\n backend.destination,\n local,\n physical,\n protectedSessionPaths(ctx),\n caseCleanup.map((item) => item.path),\n ),\n options.signal,\n validateMutation,\n ))\n ) {\n setSyncStatus(ctx, undefined);\n ctx.ui.notify(\"Pull cancelled.\", \"info\");\n return \"cancelled\" as const;\n }\n\n throwIfAborted(options.signal);\n const recoveringMerge = Boolean(await readMergeJournal(config));\n const requireFreshRecovery = async () => {\n validateMutation();\n const currentHead = await backend.readHead(options.signal);\n validateMutation();\n const current = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));\n validateMutation();\n if (!sameHashes(fileHashMap(current), fileHashMap(local)) || !sameRemoteHead(backend, head, currentHead)) {\n throw new Error(\"Local or remote content changed during recovery review; retry from a fresh diff.\");\n }\n };\n if (recoveringMerge) await requireFreshRecovery();\n if (configIdentity !== syncCheckConfigFingerprint(await loadConfig(options.setup)))\n throw new Error(\"Settings changed during pull review.\");\n validateMutation();\n const refreshed = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));\n if (!sameHashes(fileHashMap(local), fileHashMap(refreshed)))\n throw new Error(\"Local bytes changed during pull review.\");\n if (!sameRemoteHead(backend, head, await backend.readHead(options.signal)))\n throw new Error(\"Remote changed during pull review.\");\n validateMutation();\n const backup = await backupLocal(config.snapshotIdentity, snapshotOptionsForContext(ctx, config), options.signal);\n const applySessionDir = await sessionDirForApply(ctx, physical);\n if (recoveringMerge) await requireFreshRecovery();\n const currentState = await readStateForConfig(config);\n if (!options.yes && syncStateFingerprint(currentState) !== syncStateFingerprint(state))\n throw new Error(\"Baseline changed during pull review.\");\n requireResolvedDirectionalProgress(currentState, options);\n if (!options.yes) await revalidateCaseCleanup(caseCleanup, physical, options.signal);\n validateMutation();\n options.onCommit?.();\n const lastFileHashes = await applySnapshot(physical, protectedSessionPaths(ctx), {\n include: config.include,\n sessionDir: applySessionDir,\n signal: options.signal,\n validateMutation,\n expectedFileHashes: config.localFields?.length\n ? { \"settings.json\": fileHashMap(local)[\"settings.json\"] ?? null }\n : undefined,\n });\n // Local installation is complete; user cancellation must not leave the baseline stale.\n validateCommittedOwner();\n await writeStateForConfig(\n config,\n {\n version: VERSION,\n profile: config.snapshotIdentity,\n lastAppliedSnapshot: remote.id,\n lastRemoteRevision: head?.revision,\n lastFileHashes: config.localFields?.length\n ? { ...lastFileHashes, \"settings.json\": fileHashMap(logical)[\"settings.json\"] }\n : lastFileHashes,\n include: [...config.include],\n ...(config.localFields !== undefined ? { localFields: config.localFields } : {}),\n },\n logical,\n validateCommittedOwner,\n );\n await retireMergeJournal(config);\n await pruneMergeBaselines(config, await readStateForConfig(config), validateCommittedOwner);\n validateCommittedOwner();\n if (options.signal?.aborted) return \"applied\" as const;\n setSyncStatus(ctx, undefined);\n if (!options.silent) {\n ctx.ui.notify(`Pulled ${remote.files.length} files from ${remote.id}. Backup: ${backup}`, \"info\");\n } else if (options.auto && config.include.includes(\"sessions\") && snapshotIncludesSessions(remote)) {\n ctx.ui.notify(\n \"Pulled Pi sessions after startup selected the current session. Restart Pi or resume a pulled session to use newly synced conversations.\",\n \"warning\",\n );\n }\n if (options.reload) await maybeReload(ctx, options.signal, validateMutation);\n return \"applied\" as const;\n}\n\nexport async function syncBoth(\n ctx: ExtensionCommandContext | ExtensionContext,\n options: CommandOptions,\n factory: SyncBackendFactory = createSyncBackend,\n) {\n const validateMutation = captureMutationOwner(ctx, options.signal);\n const config = await loadConfig(options.setup);\n throwIfAborted(options.signal);\n options.background?.validate(config);\n if (options.agentRetryRefusal) {\n if (!config.agentMode || options.auto || options.background || !ctx.hasUI)\n throw new Error(\"Enable Autonomous sync and use the foreground manager to retry a cached refusal.\");\n const state = await readStateForConfig(config);\n validateMutation();\n const pending = await readMergeJournal(config);\n validateMutation();\n if (!config.include.length || !state.lastAppliedSnapshot || pending)\n throw new Error(\"Retry requires an accepted baseline and no pending journal. Use Sync now or reviewed recovery.\");\n return mergeSync(ctx, options, factory);\n }\n if (config.include.length > 0 && options.auto && startupTransferEnabled(config))\n return mergeSync(ctx, options, factory);\n if (!options.auto && config.include.length > 0 && (await readMergeJournal(config)))\n return mergeSync(ctx, options, factory);\n const state = await readStateForConfig(config);\n throwIfAborted(options.signal);\n if (!options.auto && config.include.length > 0 && state.lastAppliedSnapshot) return mergeSync(ctx, options, factory);\n const backend = await factory(config);\n const local = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));\n throwIfAborted(options.signal);\n if (config.include.length === 0) {\n if (!options.silent) {\n ctx.ui.notify(\n `Sync setup \u201C${config.setupName}\u201D includes no files. Choose included content in /sync Settings before syncing.`,\n \"warning\",\n );\n }\n return;\n }\n const { head, snapshot: remote } = await readRemoteSnapshot(backend, config, options.signal);\n throwIfAborted(options.signal);\n const localChanged = hasLocalChanges(local, state, config);\n const remoteChanged = remote ? hasRemoteChanges(remote, state, config, protectedSessionPaths(ctx)) : false;\n if (options.auto) throw new Error(\"Automatic transfer is not authorized by the current settings.\");\n\n // Established baselines return through mergeSync above; only initial-source selection remains.\n const portableLocal = portableSnapshot(local, config.localFields);\n const acceptMatchingState = async (snapshot: Snapshot) => {\n requireCompatibleRemoteSelection(config, snapshot);\n const accepted = portableSnapshot(snapshot, config.localFields);\n await writeStateForConfig(\n config,\n {\n version: VERSION,\n profile: config.snapshotIdentity,\n lastAppliedSnapshot: snapshot.id,\n lastRemoteRevision: head?.revision,\n lastFileHashes: fileHashMap(accepted),\n include: [...config.include],\n ...(config.localFields !== undefined ? { localFields: config.localFields } : {}),\n },\n accepted,\n validateMutation,\n );\n await pruneMergeBaselines(config, await readStateForConfig(config), validateMutation);\n validateMutation();\n };\n if (remote && remote.files.length > 0 && local.files.length > 0) {\n requireCompatibleRemoteSelection(config, remote);\n const portableRemote = portableSnapshot(remote, config.localFields);\n if (!canPullRemoteSettingsOnFirstSync(portableLocal, portableRemote)) {\n throw createSyncDecision({\n kind: \"first-sync-settings-diverged\",\n config,\n state,\n local,\n remote,\n localChanged: true,\n remoteChanged: true,\n directMessage:\n \"Remote settings exist and this machine has different local Pi settings. Run /sync diff, then manually choose /sync pull or /sync push.\",\n });\n }\n if (!sameHashes(fileHashMap(portableLocal), fileHashMap(portableRemote))) {\n if (!canPullRemoteSessionsOnFirstSync(portableLocal, portableRemote)) {\n throw createSyncDecision({\n kind: \"first-sync-sessions-diverged\",\n config,\n state,\n local,\n remote,\n localChanged: true,\n remoteChanged: true,\n directMessage:\n \"Remote settings match, but local and remote Pi sessions differ. Run /sync diff, then manually choose /sync pull or /sync push.\",\n });\n }\n await pull(ctx, options, factory);\n return;\n }\n await acceptMatchingState(remote);\n if (!options.silent) ctx.ui.notify(\"pi-sync state initialized; local settings already match remote.\", \"info\");\n return;\n }\n if (\n localChanged &&\n remoteChanged &&\n remote &&\n snapshotsMatch(portableLocal, portableSnapshot(remote, remote.localFields))\n ) {\n requireCompatibleRemoteSelection(config, remote);\n await acceptMatchingState(remote);\n if (!options.silent) ctx.ui.notify(\"pi-sync is already up to date.\", \"info\");\n return;\n }\n if (remoteChanged) {\n await pull(ctx, options, factory);\n return;\n }\n if (localChanged || !remote) {\n await push(ctx, options, undefined, factory);\n return;\n }\n if (shouldRefreshSyncedState(remote, head, state, config, (left, right) => backend.sameRevision(left, right))) {\n await acceptMatchingState(remote);\n }\n if (!options.silent) ctx.ui.notify(\"pi-sync is already up to date.\", \"info\");\n}\n\nexport async function rollback(\n ctx: ExtensionCommandContext,\n options: CommandOptions,\n factory: SyncBackendFactory = createSyncBackend,\n expectedSelection?: { backendIdentity: string; setup?: string },\n) {\n const validateMutation = captureMutationOwner(ctx, options.signal);\n const validateCommittedOwner = captureMutationOwner(ctx);\n const target = options.args[0];\n if (!target) throw new Error(\"Usage: /sync rollback <snapshot-id> [--yes]\");\n\n const config = await loadConfig(options.setup);\n throwIfAborted(options.signal);\n const backend = await factory(config);\n if (\n expectedSelection &&\n (backend.identity !== expectedSelection.backendIdentity || config.setupName !== expectedSelection.setup)\n ) {\n throw new Error(\"Sync setup or storage location changed while history was open; reopen history and retry.\");\n }\n // --force is only a rollback compatibility flag, not a reviewed merge-recovery direction.\n await requireNoMergeJournal(config);\n const state = await readStateForConfig(config);\n validateMutation();\n requireResolvedDirectionalProgress(state, options, false);\n const decoded = await backend.readSnapshot(target, options.signal);\n validatePortableSnapshot(decoded);\n if (!sameLocalFields(decoded.localFields, config.localFields))\n throw new Error(\n \"Rollback requires the historical snapshot local-field policy to match the configured rules. Review push --force from current local bytes to migrate policy first; choose matching history afterward.\",\n );\n const selected = filterSnapshotForConfigPolicy(\n config.include.includes(\"sessions\") ? decoded : snapshotWithoutSessions(decoded),\n config,\n );\n const remote = portableSnapshot(regenerateSnapshotIdentity(selected), config.localFields);\n const local = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));\n const expectedHead = await backend.readHead(options.signal);\n const currentRemote = expectedHead ? await readSnapshotForHead(backend, expectedHead, options.signal) : undefined;\n validateMutation();\n if (!(await confirmFieldMigration(ctx, config, state, currentRemote, true, options.signal))) return;\n validateMutation();\n const physical = overlayLocalFields(remote, local, config.localFields);\n const caseCleanup = options.yes ? [] : await inspectCaseCleanup(physical, options.signal);\n validateMutation();\n\n if (!options.yes) {\n const confirmed = await ctx.ui.confirm(\n snapshotIncludesSessions(remote) ? \"Rollback pi settings and sessions?\" : \"Rollback pi settings?\",\n formatRollbackSummary(\n config,\n backend.destination,\n local,\n physical,\n target,\n protectedSessionPaths(ctx),\n caseCleanup.map((item) => item.path),\n ),\n { signal: options.signal },\n );\n validateMutation();\n if (!confirmed) {\n ctx.ui.notify(\"Rollback cancelled.\", \"info\");\n return;\n }\n }\n\n validateMutation();\n const currentLocal = await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config));\n if (!sameHashes(fileHashMap(currentLocal), fileHashMap(local)))\n throw new Error(\"Local bytes changed during rollback review.\");\n if (syncCheckConfigFingerprint(config) !== syncCheckConfigFingerprint(await loadConfig(options.setup)))\n throw new Error(\"Settings changed during rollback review.\");\n if (!sameRemoteHead(backend, expectedHead, await backend.readHead(options.signal)))\n throw new Error(\"Remote changed during rollback review.\");\n validateMutation();\n throwIfAborted(options.signal);\n const backup = await backupLocal(config.snapshotIdentity, snapshotOptionsForContext(ctx, config), options.signal);\n const applySessionDir = await sessionDirForApply(ctx, remote);\n const currentState = await readStateForConfig(config);\n if (!options.yes && syncStateFingerprint(currentState) !== syncStateFingerprint(state))\n throw new Error(\"Baseline changed during rollback review.\");\n requireResolvedDirectionalProgress(currentState, options, false);\n if (!options.yes) await revalidateCaseCleanup(caseCleanup, physical, options.signal);\n validateMutation();\n options.onCommit?.();\n const lastFileHashes = await applySnapshot(physical, protectedSessionPaths(ctx), {\n include: config.include,\n sessionDir: applySessionDir,\n signal: options.signal,\n validateMutation,\n expectedFileHashes: config.localFields?.length\n ? { \"settings.json\": fileHashMap(local)[\"settings.json\"] ?? null }\n : undefined,\n });\n // The local transaction is retired; finish publication despite caller cancellation.\n validateCommittedOwner();\n let result: PublishSnapshotResult;\n try {\n const completionSignal = AbortSignal.timeout(POST_LOCAL_COMMIT_TIMEOUT_MS);\n const upload = await snapshotForUpload(backend, config, remote, expectedHead, currentRemote, completionSignal);\n validateCommittedOwner();\n result = await backend.publishSnapshot(upload, expectedRemoteHead(expectedHead), {\n signal: completionSignal,\n });\n } catch (error) {\n throw new RollbackPublicationError(backup, error);\n }\n try {\n await writeStateForConfig(\n config,\n {\n version: VERSION,\n profile: config.snapshotIdentity,\n lastAppliedSnapshot: result.head.snapshotId,\n lastRemoteRevision: result.head.revision,\n lastFileHashes: config.localFields?.length\n ? { ...lastFileHashes, \"settings.json\": fileHashMap(remote)[\"settings.json\"] }\n : lastFileHashes,\n include: [...config.include],\n ...(config.localFields !== undefined ? { localFields: config.localFields } : {}),\n },\n remote,\n validateCommittedOwner,\n );\n } catch (error) {\n throw new PublicationStatePersistenceError(result.head, error, backup);\n }\n await retireMergeJournal(config);\n await pruneMergeBaselines(config, await readStateForConfig(config), validateCommittedOwner);\n validateCommittedOwner();\n if (options.signal?.aborted) return;\n ctx.ui.notify(\n [\n `Rolled back sync setup \u201C${config.setupName}\u201D to ${target}; latest: ${result.head.snapshotId}. Backup: ${backup}`,\n ...result.warnings,\n ]\n .filter(Boolean)\n .join(\"\\n\"),\n result.warnings.length > 0 ? \"warning\" : \"info\",\n );\n await maybeReload(ctx, options.signal, validateMutation);\n}\n\nasync function maybeReload(\n ctx: ExtensionCommandContext | ExtensionContext,\n signal?: AbortSignal,\n validateMutation = captureMutationOwner(ctx, signal),\n) {\n if (signal?.aborted || !(\"reload\" in ctx)) return;\n validateMutation();\n if (\n ctx.hasUI &&\n (await ctx.ui.confirm(\n \"Reload Pi resources now?\",\n \"This reloads extensions, skills, prompts, themes, and context files.\",\n ))\n ) {\n if (signal?.aborted) return;\n validateMutation();\n await ctx.reload();\n }\n}\n\nasync function readRemoteSnapshotForUpload(\n backend: SyncBackend,\n config: AnySyncConfig,\n head: RemoteHead | undefined,\n state: SyncState,\n signal?: AbortSignal,\n) {\n if (\n !head ||\n (head.snapshotId === state.lastAppliedSnapshot &&\n !syncPolicyChanged(state, config) &&\n (!state.lastRemoteRevision || backend.sameRevision(head.revision, state.lastRemoteRevision)))\n ) {\n return undefined;\n }\n return readSnapshotForHead(backend, head, signal);\n}\n\nasync function snapshotForUpload(\n backend: SyncBackend,\n config: AnySyncConfig,\n local: Snapshot,\n head: RemoteHead | undefined,\n remote?: Snapshot,\n signal?: AbortSignal,\n) {\n if (!head) return local;\n const snapshot = remote ?? (await readSnapshotForHead(backend, head, signal));\n return mergeRemotePreservedFiles(local, snapshot, config);\n}\n\nasync function confirmPush(\n ctx: ExtensionCommandContext | ExtensionContext,\n options: CommandOptions,\n config: AnySyncConfig,\n backend: SyncBackend,\n local: Snapshot,\n upload: Snapshot,\n head: RemoteHead | undefined,\n remote: Snapshot | undefined,\n title = snapshotIncludesSessions(upload) ? \"Push pi settings and sessions?\" : \"Push pi settings?\",\n) {\n throwIfAborted(options.signal);\n if (options.yes) return true;\n const confirmed = await confirmTransferReview(\n ctx,\n title,\n formatPushSummary(config, backend.destination, upload, head, countPreservedRemoteFiles(local, upload), remote),\n options.signal,\n captureMutationOwner(ctx, options.signal),\n );\n throwIfAborted(options.signal);\n if (confirmed) return true;\n setSyncStatus(ctx, undefined);\n ctx.ui.notify(\"Push cancelled.\", \"info\");\n return false;\n}\n\nfunction sameRemoteHead(backend: SyncBackend, left: RemoteHead | undefined, right: RemoteHead | undefined) {\n if (!left || !right) return left === right;\n return backend.sameRevision(left.revision, right.revision);\n}\n\nexport { backupLocal } from \"./sync-local.js\";\n", "import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport { createSyncBackend, type SyncBackendFactory } from \"../backends/backend-factory.js\";\nimport type { SyncBackend } from \"../backends/sync-backend.js\";\nimport type { CommandOptions } from \"../commands/command-types.js\";\nimport { loadConfig, syncSessionsWarnings } from \"../settings/config.js\";\nimport { snapshotOptionsForContext } from \"../snapshot/session-paths.js\";\nimport { createSnapshot, scanSnapshot } from \"../snapshot/snapshot.js\";\nimport type { SnapshotOptions } from \"../snapshot/snapshot-types.js\";\nimport { inspectLock, isLockGuardHeld, isStaleLock, withLock } from \"../state/lock.js\";\nimport { readStateForConfig } from \"../state/sync-state-store.js\";\nimport { formatDiff, formatSnapshotOnlyDiff, publicationCapabilityDescription } from \"../ui/sync-format.js\";\nimport { setSyncStatus } from \"../ui/sync-status.js\";\nimport { safeTerminalText } from \"../ui/terminal-text.js\";\nimport { portableSnapshot } from \"./local-fields.js\";\nimport { formatRemoteSelectionStatus, readRemoteSnapshot } from \"./remote-snapshot.js\";\nimport { throwIfAborted } from \"./signals.js\";\nimport { errorMessage } from \"./sync-errors.js\";\nimport { inspectSync } from \"./sync-inspection.js\";\nimport { rollback } from \"./sync-mutations.js\";\n\nconst DEFAULT_PROFILE = \"default\";\n\nexport async function status(\n ctx: ExtensionCommandContext,\n options: CommandOptions,\n factory: SyncBackendFactory = createSyncBackend,\n) {\n const config = await loadConfig(options.setup);\n throwIfAborted(options.signal);\n setSyncStatus(ctx, `checking ${config.setupName}`);\n const { head, selectionState, localChanged, remoteChanged, localFiles, destination, capability } = await inspectSync(\n config,\n snapshotOptionsForContext(ctx, config),\n options.signal,\n factory,\n );\n throwIfAborted(options.signal);\n\n const continuous = config.continuous\n ? await (await import(\"./continuous-record.js\")).continuousStatusLines(config)\n : [];\n throwIfAborted(options.signal);\n const remoteText = head ? `remote: ${head.snapshotId} from ${head.machine} at ${head.createdAt}` : \"remote: empty\";\n const warnings = syncSessionsWarnings(config);\n setSyncStatus(ctx, undefined);\n ctx.ui.notify(\n [\n `sync setup: ${config.setupName}`,\n `storage connection: ${config.connectionName}`,\n `storage location: ${safeTerminalText(destination)}`,\n `publication safety: ${publicationCapabilityDescription(capability)}`,\n `included content: ${config.include.join(\", \") || \"none\"}`,\n `sessions: ${config.include.includes(\"sessions\") ? \"included\" : \"excluded\"}`,\n ...continuous,\n remoteText,\n formatRemoteSelectionStatus(selectionState),\n `local files: ${localFiles}`,\n `local changed since last sync: ${localChanged ? \"yes\" : \"no\"}`,\n `remote changed since last sync: ${remoteChanged ? \"yes\" : \"no\"}`,\n ...warnings,\n ].join(\"\\n\"),\n localChanged || remoteChanged || selectionState?.kind === \"different\" || warnings.length > 0 ? \"warning\" : \"info\",\n );\n}\n\nexport async function diff(\n ctx: ExtensionCommandContext,\n options: CommandOptions,\n factory: SyncBackendFactory = createSyncBackend,\n) {\n const config = await loadConfig(options.setup);\n throwIfAborted(options.signal);\n setSyncStatus(ctx, `checking ${config.setupName}`);\n const backend = await factory(config);\n const local = portableSnapshot(\n await createSnapshot(config.snapshotIdentity, snapshotOptionsForContext(ctx, config)),\n config.localFields,\n );\n throwIfAborted(options.signal);\n const { snapshot: remote, selectionState } = await readRemoteSnapshot(backend, config, options.signal, {\n allowSelectionDifference: true,\n });\n throwIfAborted(options.signal);\n setSyncStatus(ctx, undefined);\n\n const warnings = syncSessionsWarnings(config);\n const header = [\n `sync setup: ${config.setupName}`,\n `storage connection: ${config.connectionName}`,\n `storage location: ${safeTerminalText(backend.destination)}`,\n `included content: ${config.include.join(\", \") || \"none\"}`,\n `sessions: ${config.include.includes(\"sessions\") ? \"included\" : \"excluded\"}`,\n formatRemoteSelectionStatus(selectionState),\n ...warnings,\n ].join(\"\\n\");\n const level = warnings.length > 0 || selectionState?.kind === \"different\" ? \"warning\" : \"info\";\n if (!remote) {\n ctx.ui.notify(`${header}\\n\\n${formatSnapshotOnlyDiff(\"Remote is empty. Local push would upload\", local)}`, level);\n return;\n }\n\n ctx.ui.notify(`${header}\\n\\n${formatDiff(local, portableSnapshot(remote, remote.localFields))}`, level);\n}\n\nexport async function doctor(\n ctx: ExtensionCommandContext,\n options: CommandOptions,\n factory: SyncBackendFactory = createSyncBackend,\n) {\n const messages: string[] = [];\n let level: \"info\" | \"warning\" = \"info\";\n let snapshotOptions: SnapshotOptions = {};\n let profile = DEFAULT_PROFILE;\n let backend: SyncBackend | undefined;\n let backendSummary: string[] = [];\n\n try {\n const config = await loadConfig(options.setup);\n throwIfAborted(options.signal);\n backend = await factory(config);\n profile = config.snapshotIdentity;\n snapshotOptions = snapshotOptionsForContext(ctx, config);\n messages.push(\n `config: ok (sync setup ${config.setupName})`,\n `included content: ${config.include.join(\", \") || \"none\"}`,\n `sessions: ${config.include.includes(\"sessions\") ? \"included\" : \"excluded\"}`,\n );\n backendSummary = [\n `storage location: ${safeTerminalText(backend.destination)}`,\n `publication safety: ${publicationCapabilityDescription(backend.capability)}`,\n ];\n const warnings = syncSessionsWarnings(config);\n if (warnings.length > 0) {\n level = \"warning\";\n messages.push(...warnings);\n }\n } catch (error) {\n throwIfAborted(options.signal);\n level = \"warning\";\n messages.push(`config: ${errorMessage(error)}`);\n }\n\n const local = await createSnapshot(profile, snapshotOptions);\n throwIfAborted(options.signal);\n const secrets = scanSnapshot(local);\n if (secrets.length > 0) {\n level = \"warning\";\n messages.push(\"secret scan: possible secrets found:\");\n messages.push(...secrets.map((secret) => `- ${secret}`));\n } else {\n messages.push(`secret scan: ok (${local.files.length} files checked)`);\n }\n\n const lock = await inspectLock();\n throwIfAborted(options.signal);\n if (lock.status === \"valid\" && isStaleLock(lock.lock)) {\n level = \"warning\";\n messages.push(`lock: stale (pid ${lock.lock.pid}); run /sync unlock --stale after verifying no sync is running`);\n } else if (lock.status === \"valid\") {\n messages.push(`lock: held by pid ${lock.lock.pid} since ${lock.lock.startedAt}`);\n } else if (lock.status === \"unreadable\") {\n level = \"warning\";\n messages.push(\"lock: unreadable; use /sync unlock --stale only after verifying no sync is running\");\n } else if (await isLockGuardHeld()) {\n throwIfAborted(options.signal);\n level = \"warning\";\n messages.push(\"lock: guard active while metadata is missing or still being initialized\");\n } else {\n messages.push(\"lock: free\");\n }\n\n if (backend) {\n messages.push(...backendSummary);\n const diagnostics = await backend.diagnose(options.signal);\n throwIfAborted(options.signal);\n for (const diagnostic of diagnostics) {\n messages.push(diagnostic.message);\n if (diagnostic.level !== \"info\") level = \"warning\";\n }\n }\n ctx.ui.notify(messages.join(\"\\n\"), level);\n}\n\nexport async function history(\n ctx: ExtensionCommandContext,\n options: CommandOptions,\n factory: SyncBackendFactory = createSyncBackend,\n) {\n const config = await loadConfig(options.setup);\n throwIfAborted(options.signal);\n const backend = await factory(config);\n const snapshots = (await backend.listHistory(options.signal)).slice(-20).reverse();\n throwIfAborted(options.signal);\n const lastApplied = await readStateForConfig(config)\n .then((state) => state.lastAppliedSnapshot)\n .catch(() => undefined);\n throwIfAborted(options.signal);\n const appliedDetails = lastApplied\n ? `Last applied snapshot ID: ${safeTerminalText(lastApplied)}\\nApplication time: unavailable. Snapshot dates are creation times.`\n : \"Last applied snapshot ID: unavailable.\";\n if (snapshots.length === 0) {\n ctx.ui.notify(`No remote pi-sync history found.\\n${appliedDetails}`, \"info\");\n return;\n }\n\n const currentSnapshot = snapshots[0]?.snapshotId;\n if (ctx.mode === \"tui\") {\n const labels = snapshots.map(\n (item, index) =>\n `${index + 1}. ${item.createdAt} \u00B7 ${safeTerminalText(item.machine)} \u00B7 ${item.snapshotId}${item.snapshotId === currentSnapshot ? \" (current)\" : \"\"}${item.syncSessions ? \" \u00B7 sessions\" : \"\"}`,\n );\n const selected = await ctx.ui.select(\n `History for sync setup \u201C${safeTerminalText(config.setupName)}\u201D\\n\\n${appliedDetails}\\n\\nChoose a snapshot to preview rollback.`,\n [...labels, \"Back\"],\n { signal: options.signal },\n );\n if (!selected || selected === \"Back\") return;\n throwIfAborted(options.signal);\n const index = labels.indexOf(selected);\n const snapshot = snapshots[index];\n if (!snapshot) return;\n await withLock(\"rollback\", () =>\n rollback(ctx, { ...options, args: [snapshot.snapshotRef], yes: false }, factory, {\n backendIdentity: backend.identity,\n setup: config.setupName,\n }),\n );\n return;\n }\n ctx.ui.notify(\n [\n appliedDetails,\n ...snapshots.map((item) => `${item.snapshotRef} ${item.createdAt} ${safeTerminalText(item.machine)}`),\n ].join(\"\\n\"),\n \"info\",\n );\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,eAAsB,sBACpB,KACA,OACA,SACA,QACA,UACA;AACA,WAAS;AACT,QAAM,YAAY,MAAM;AACtB,QAAI;AACF,eAAS;AACT,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACA,QAAM,YACJ,IAAI,SAAS,SAAS,IAAI,QACtB,MAAM,mBAAmB,KAAK,OAAO,SAAS,QAAQ,WAAW,2BAA2B,QAAQ,MAAM,IAAI,CAAC,IAC/G,MAAM,IAAI,GAAG,QAAQ,OAAO,SAAS,EAAE,OAAO,CAAC;AACrD,WAAS;AACT,SAAO;AACT;;;AC1BA,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAC1B,OAAO,Q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AK,UAAU,GAAG,KAAK,eAAe,kBAAkB,eAAe,EAAE,GAAG,KAAK,eAAe,mBAAgB,EAAE;AAAA,IAC/L;AACA,UAAM,WAAW,MAAM,IAAI,GAAG;AAAA,MAC5B,gCAA2B,iBAAiB,OAAO,SAAS,CAAC;AAAA;AAAA,EAAQ,cAAc;AAAA;AAAA;AAAA,MACnF,CAAC,GAAG,QAAQ,MAAM;AAAA,MAClB,EAAE,QAAQ,QAAQ,OAAO;AAAA,IAC3B;AACA,QAAI,CAAC,YAAY,aAAa,OAAQ;AACtC,mBAAe,QAAQ,MAAM;AAC7B,UAAM,QAAQ,OAAO,QAAQ,QAAQ;AACrC,UAAM,WAAW,UAAU,KAAK;AAChC,QAAI,CAAC,SAAU;AACf,UAAM;AAAA,MAAS;AAAA,MAAY,MACzB,SAAS,KAAK,EAAE,GAAG,SAAS,MAAM,CAAC,SAAS,WAAW,GAAG,KAAK,MAAM,GAAG,SAAS;AAAA,QAC/E,iBAAiB,QAAQ;AAAA,QACzB,OAAO,OAAO;AAAA,MAChB,CAAC;AAAA,IACH;AACA;AAAA,EACF;AACA,MAAI,GAAG;AAAA,IACL;AAAA,MACE;AAAA,MACA,GAAG,UAAU,IAAI,CAAC,SAAS,GAAG,KAAK,WAAW,IAAI,KAAK,SAAS,IAAI,iBAAiB,KAAK,OAAO,CAAC,EAAE;AAAA,IACtG,EAAE,KAAK,IAAI;AAAA,IACX;AAAA,EACF;AACF;",
6
6
  "names": ["state", "index"]
7
7
  }
package/dist/index.ts CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  completeSyncArguments,
11
11
  setSyncSetupCompletions,
12
12
  splitArgs
13
- } from "./chunks/chunk-NLWS55B6.ts";
13
+ } from "./chunks/chunk-QPC5HT3A.ts";
14
14
  import {
15
15
  captureMutationOwner
16
16
  } from "./chunks/chunk-GNYGNHFF.ts";
@@ -258,7 +258,7 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4, publish) {
258
258
  if (startupTransferEnabled(captured) && !inspection.firstSync && inspection.head && inspection.selectionState?.kind === "same") {
259
259
  const [operations, { withAgentSyncLock }] = await timings.measure(
260
260
  "operations import",
261
- () => Promise.all([loaders.operations(), import("./chunks/agent-sync-EUK2CPSS.ts")])
261
+ () => Promise.all([loaders.operations(), import("./chunks/agent-sync-P6AWQXGK.ts")])
262
262
  );
263
263
  throwIfAborted(signal);
264
264
  if (!isCurrent()) return;
@@ -357,12 +357,12 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4, publish) {
357
357
  // src/sync/sync-loaders.ts
358
358
  function createSyncLoaders(dependencies) {
359
359
  const loaders = {
360
- commands: cachedModuleLoader(dependencies.loadCommandHandler ?? (() => import("./chunks/command-handler-F2E7A5T5.ts"))),
360
+ commands: cachedModuleLoader(dependencies.loadCommandHandler ?? (() => import("./chunks/command-handler-VKLZBRLO.ts"))),
361
361
  inspection: cachedModuleLoader(dependencies.loadSyncInspection ?? (() => import("./chunks/sync-inspection-MOMLGUTD.ts"))),
362
- setupSwitch: cachedModuleLoader(dependencies.loadSetupSwitch ?? (() => import("./chunks/setup-switch-PIPXYPCW.ts"))),
362
+ setupSwitch: cachedModuleLoader(dependencies.loadSetupSwitch ?? (() => import("./chunks/setup-switch-KLGESLQX.ts"))),
363
363
  snapshot: cachedModuleLoader(dependencies.loadSnapshot ?? (() => import("./chunks/snapshot-RGNDYT6A.ts"))),
364
364
  syncState: cachedModuleLoader(dependencies.loadSyncState ?? (() => import("./chunks/sync-state-7L4NT7W2.ts"))),
365
- operations: cachedModuleLoader(dependencies.loadSyncOperations ?? (() => import("./chunks/sync-operations-CV3TULLD.ts")))
365
+ operations: cachedModuleLoader(dependencies.loadSyncOperations ?? (() => import("./chunks/sync-operations-TMGQHBF5.ts")))
366
366
  };
367
367
  return loaders;
368
368
  }
@@ -429,7 +429,7 @@ function sync(pi, dependencies = {}) {
429
429
  await continuous?.stop(ctx.sessionManager);
430
430
  return;
431
431
  }
432
- const { createContinuousSync } = await import("./chunks/continuous-sync-VRMXCA5X.ts");
432
+ const { createContinuousSync } = await import("./chunks/continuous-sync-TTOSJCQU.ts");
433
433
  if (!isCurrent()) return;
434
434
  continuous ??= createContinuousSync(loaders, void 0, publishTimings);
435
435
  continuous.start(
@@ -1,4 +1,4 @@
1
- # Agent and Continuous Sync Recovery Boundaries
1
+ # Autonomous and Continuous sync recovery boundaries
2
2
 
3
3
  Pi Sync distinguishes a rejected pre-publication observation from an uncertain publication. Only proven freshness failures retry automatically. Unknown errors do not become retryable because their text looks temporary.
4
4
 
@@ -12,8 +12,8 @@ The authoritative paths are `src/sync/merged-sync.ts`, `agent-plan.ts`, and `con
12
12
  | Local bytes, baseline fingerprint, or remote revision changes before the publication journal | `stale`; no transfer of the rejected candidate. |
13
13
  | Local bytes or baseline changes after journal creation, before any backend publication call | Clear the safely uncommitted journal first, then report `stale`; a cleanup failure retains its original classification. |
14
14
  | Backend proves a conflict happened before commit and the candidate cannot have been active | Retire the uncommitted journal and use the existing bounded merge attempts; exhausted attempts retain the typed conflict cause and classify as `stale`. |
15
- | Upload possible-secret scan; remaining unsupported or refused Agent groups | `unsafe`; retain evidence, suppress unchanged resolution, and inspect changed evidence again. |
16
- | Bounded/unsafe Agent disclosure, unsupported conflict, missing verified ancestor, or invalid candidate application | `unsafe`; no inferred ancestor or bypass of partial-sync policy. |
15
+ | Upload possible-secret scan; remaining unsupported or refused Autonomous sync groups | `unsafe`; retain evidence, suppress unchanged resolution, and inspect changed evidence again. |
16
+ | Bounded/unsafe Autonomous sync disclosure, unsupported conflict, missing verified ancestor, or invalid candidate application | `unsafe`; no inferred ancestor or bypass of partial-sync policy. |
17
17
  | Missing model or unusable/refused resolver output | `model`; unchanged evidence does not repeatedly dispatch. A valid cached refusal stays cached during ordinary Sync now. |
18
18
  | Changed local, baseline, or remote evidence during resolver validation | `stale`; discard authorization for that observation. |
19
19
  | Known HTTP/network/lock errors | Preserve the existing typed/status/code policy and bounded retry delay. |
@@ -37,7 +37,7 @@ A request reservation published before cancellation remains spent. An atomic can
37
37
 
38
38
  Ordinary Sync now retains its existing cached-result policy. The manager-only **Retry refused model result…** action uses the same `sync` operation with an internal control value, not a new public command, flag, or setting.
39
39
 
40
- The action requires Agent mode, foreground TUI/RPC, an accepted baseline, matching current evidence, a valid cached refusal, and no pending merge journal. A pending journal must be reconciled through ordinary Sync now or reviewed recovery first. A missing, accepted, corrupt, stale, or unverified cached result is not retry authorization. Opening the manager may show the action before eligibility is known; activation checks it without dispatching when those conditions are absent.
40
+ The action requires Autonomous sync, foreground TUI/RPC, an accepted baseline, matching current evidence, a valid cached refusal, and no pending merge journal. A pending journal must be reconciled through ordinary Sync now or reviewed recovery first. A missing, accepted, corrupt, stale, or unverified cached result is not retry authorization. Opening the manager may show the action before eligibility is known; activation checks it without dispatching when those conditions are absent.
41
41
 
42
42
  The flow holds the existing resolver claim while the operation lock is released for review and inference. The safe-default review names the setup, connection, exact configured storage path and bucket/branch where applicable, selected provider/model, conflict paths, disclosure, cost, and possible writes. Confirmation binds the same candidate key and cache bytes. Changed settings, model, session, evidence, or cache invalidates it. A competing participant cannot obtain another live resolver claim.
43
43
 
@@ -76,4 +76,4 @@ No live provider, production Git/S3/WebDAV, Windows, or Android verification is
76
76
 
77
77
  ## Downgrade and recovery
78
78
 
79
- Stop Continuous sync and drain all participating owners before downgrade. Disable Agent mode too if autonomous startup work must stop. Reconcile pending journals with the current runtime. Preserve backups, snapshots, accepted and refused candidates, unresolved groups, and request accounting. This change adds no settings, accounting, or candidate schema migration. Do not delete private state to regain allowance or blindly republish an uncertain transfer.
79
+ Stop Continuous sync and drain all participating owners before downgrade. Disable Autonomous sync too if autonomous startup work must stop. Reconcile pending journals with the current runtime. Preserve backups, snapshots, accepted and refused candidates, unresolved groups, and request accounting. This change adds no settings, accounting, or candidate schema migration. Do not delete private state to regain allowance or blindly republish an uncertain transfer.
@@ -1,8 +1,8 @@
1
- # Agent mode implementation verification
1
+ # Autonomous sync implementation verification
2
2
 
3
- This record describes the experimental implementation and its verification scope. The [settings reference](settings.md#experimental-agent-mode) is authoritative for user behavior, limits, privacy, and recovery.
3
+ This record describes the original implementation and its verification scope. The [settings reference](settings.md#autonomous-sync) is authoritative for current user behavior, limits, privacy, and recovery.
4
4
 
5
- Later recovery, cancellation, confirmed-refusal retry, and diagnostics changes are documented in [Agent and Continuous sync recovery boundaries](agent-continuous-hardening.md). The [synthetic quality corpus](agent-quality-verification.md) adds structural tests without claiming measured model accuracy. Historical verification below describes the original implementation.
5
+ Later recovery, cancellation, confirmed-refusal retry, and diagnostics changes are documented in [Autonomous and Continuous sync recovery boundaries](agent-continuous-hardening.md). The [synthetic quality corpus](agent-quality-verification.md) adds structural tests without claiming measured model accuracy. Historical verification below retains the former **Agent mode** name and the maturity labels used at that time; recorded results are unchanged.
6
6
 
7
7
  ## Boundaries and semantic review
8
8
 
@@ -1,6 +1,6 @@
1
- # Synthetic Agent merge-quality verification
1
+ # Synthetic Autonomous sync merge-quality verification
2
2
 
3
- The [corpus](../test/agent-quality-corpus.ts) and [tests](../test/agent-quality.test.ts) check structural merge safety with synthetic data and fixed resolver responses. They do not measure real-model semantic accuracy. Agent mode remains experimental and default-off; the [settings reference](settings.md#experimental-agent-mode) and [implementation verification](agent-mode-verification.md) retain their authority.
3
+ The [corpus](../test/agent-quality-corpus.ts) and [tests](../test/agent-quality.test.ts) check structural merge safety with synthetic data and fixed resolver responses. They do not measure real-model semantic accuracy. Autonomous sync is default-off; the [settings reference](settings.md#autonomous-sync) and [implementation verification](agent-mode-verification.md) retain their authority.
4
4
 
5
5
  ## Deterministic evidence
6
6
 
@@ -24,7 +24,7 @@ These tests prove fixture routing, contract validation and byte assembly for the
24
24
 
25
25
  No provider evaluation is authorized or executed by this work. A future evaluation must follow this protocol:
26
26
 
27
- 1. Obtain explicit approval for the provider/model, model version when available, request count, cost ceiling, repetitions, deadline and retention policy. Keep Agent and Continuous settings unchanged. Stop after one clear external-service or entitlement failure unless a retry is separately requested.
27
+ 1. Obtain explicit approval for the provider/model, model version when available, request count, cost ceiling, repetitions, deadline and retention policy. Keep Autonomous sync and Continuous sync settings unchanged. Stop after one clear external-service or entitlement failure unless a retry is separately requested.
28
28
  2. Freeze the repository revision, corpus revision, resolver contract, model settings and scoring rules before requests. Register allowed exact outputs or whole-settings source choices for each resolvable case. The deterministic fixture response is one reference, not evidence that it is the only valid semantic merge. Do not add allowed results after seeing responses; report unregistered alternatives separately for review.
29
29
  3. Use only the committed synthetic fixtures. Exclude user files, session history, credentials, real remote storage and discovered resources. Send only the current bounded unit payload and existing resolver instructions. Do not send full files, hidden policies, expected answers, scoring notes or neighboring context. Keep unsupported cases as local eligibility checks; they must not cause a provider request.
30
30
  4. Record each attempt without overwriting failures: fixture ID, approved provider/model, outcome, schema validity, refused IDs, exact accepted bytes, elapsed time and provider-reported usage. Preserve raw synthetic output for review, but exclude authentication and provider error payloads. Do not retry refusals automatically.
@@ -1,8 +1,8 @@
1
1
  # Continuous sync verification
2
2
 
3
- This record describes implementation evidence and test scope. The [settings reference](settings.md#experimental-continuous-sync) owns user-facing behavior, limits and recovery.
3
+ This record describes implementation evidence and test scope. The [settings reference](settings.md#continuous-sync) owns current user-facing behavior, limits and recovery.
4
4
 
5
- Later recovery classification, deadline propagation, confirmed-refusal retry, and read-only allowance/capacity diagnostics are documented in [Agent and Continuous sync recovery boundaries](agent-continuous-hardening.md). Historical verification below describes the original implementation.
5
+ Later recovery classification, deadline propagation, confirmed-refusal retry, and read-only allowance/capacity diagnostics are documented in [Autonomous and Continuous sync recovery boundaries](agent-continuous-hardening.md). Historical verification below retains the former **Agent mode** name for Autonomous sync and the maturity labels used at that time; recorded results are unchanged.
6
6
 
7
7
  ## Boundaries and semantic audit
8
8
 
package/docs/settings.md CHANGED
@@ -3,7 +3,7 @@
3
3
  The authoritative settings reference now ships with the [manual-only configuration skill](../skills/configure-pi-sync/SKILL.md).
4
4
  Run `/skill:configure-pi-sync` for guidance, not automatic settings edits or transfers.
5
5
  Read the [complete settings reference](../skills/configure-pi-sync/references/configuration.md) without invoking the skill.
6
- The headings below preserve existing documentation links.
6
+ The headings and invisible compatibility anchors below preserve existing documentation links.
7
7
 
8
8
  ## ⚙️ Settings
9
9
 
@@ -49,13 +49,17 @@ See [Automatic startup transfer](../skills/configure-pi-sync/references/configur
49
49
 
50
50
  See [Unchanged transfer fast path](../skills/configure-pi-sync/references/configuration.md#unchanged-transfer-fast-path).
51
51
 
52
- ### Experimental Agent mode
52
+ <a id="experimental-agent-mode"></a>
53
53
 
54
- See [Experimental Agent mode](../skills/configure-pi-sync/references/configuration.md#experimental-agent-mode).
54
+ ### Autonomous sync
55
55
 
56
- ### Experimental Continuous sync
56
+ See [Autonomous sync](../skills/configure-pi-sync/references/configuration.md#autonomous-sync).
57
57
 
58
- See [Experimental Continuous sync](../skills/configure-pi-sync/references/configuration.md#experimental-continuous-sync).
58
+ <a id="experimental-continuous-sync"></a>
59
+
60
+ ### Continuous sync
61
+
62
+ See [Continuous sync](../skills/configure-pi-sync/references/configuration.md#continuous-sync).
59
63
 
60
64
  #### Activation and ownership
61
65
 
@@ -13,11 +13,13 @@ All settings are private to this device. There are no project overrides. Default
13
13
  | Machine-local fields | `sync.localFields`, absent | Current setup | Input and compatibility review; subsequent snapshots exclude whole settings.json root fields; directional migration required |
14
14
  | Automatic sync | `sync.automatic`, explicit boolean; setup proposes Off | Current setup | Immediate save; next session start checks once; subsequent shutdown pushes all selected content only if sessions included; reload skips shutdown push |
15
15
  | Startup transfer | `sync.automaticTransfer`, false | Current setup | Immediate save; enabling schedules next session start; independent of Automatic sync |
16
+ | Autonomous sync | `sync.agentMode`, false | Current setup | Reviewed opt-in; eligible next-startup and Sync now transfers without another transfer confirmation, plus selected-model assistance for supported conflicts; no transfer from Settings or automatic reload |
17
+ | Continuous sync | `sync.continuous`, false | Current setup | Separate reviewed opt-in; requires Autonomous sync; recurring work starts at eligible startup or after the command/manager closes |
16
18
  | On setup switch | `onSwitch`, `ask-before-pull` | All setups | Immediate save; subsequent switches |
17
19
  | Storage location | `storage.bucket`, `branch`, `path` as applicable | Current setup | Reviewed save; changes future destination without moving remote history |
18
20
  | Manage sync setups | `syncSetups`, `activeSyncSetup` | This device | Existing reviewed catalog flows; replacing/removing the current setup closes its old settings owner |
19
21
  | Manage storage connections | `storageConnections` | Shared by named setups | Existing affected-setup review; changes future operations |
20
- | Merge settings fields | `sync.mergeSettings`, false | Current setup | Immediate save; experimental merge on subsequent sync with a verified ancestor |
22
+ | Merge settings fields | `sync.mergeSettings`, false | Current setup | Immediate save; opt-in merge on subsequent sync with a verified ancestor |
21
23
  | Content merge / partial progress | `sync.mergeContent`, `sync.partialSync`, false/false | Current setup | Explicit compatibility review and atomic save; Off, Merge only, Merge + partial, Partial only preserve all combinations |
22
24
  | Skip secret scan | `skipSecretScan`, false | All setups | Immediate save; subsequent manual/automatic pushes; Diagnostics still scans |
23
25
  | Show sync status | `showStatus`, true | All setups | Immediate save and immediate status visibility change; notifications/widgets remain |
@@ -29,7 +31,7 @@ Writers queue the complete read-modify-write operation, hold the cross-process l
29
31
 
30
32
  ## Presentation decisions
31
33
 
32
- Settings opens four task categories: Sync content, Sync behavior, Storage & setups, and Advanced. All settings (search) exposes the same rows for cross-category native-style typing-to-search. Each category uses the same row definitions and action handlers; navigation headings are not fake settings. Back returns one level; hard Ctrl+C closes the flow. No `/ Search` hint is added because slash is ordinary search text.
34
+ Selecting **Settings** in `/sync` opens **Pi Sync Settings** directly as one searchable flat list, with all 16 rows in their existing order and no category navigation or headings. Row values, descriptions, actions, reviews, and save behavior are unchanged. Typing searches the list. Back returns directly to the manager; hard Ctrl+C closes the flow. No `/ Search` hint is added because slash is ordinary search text.
33
35
 
34
36
  The existing public Kit settings adapter is retained rather than adding a second selector or accessing private Pi fields. Installed `SettingsList` provides `updateValue()` and `selectItem()`, but has no injected keybinding or awaited-save/rejection contract and does not expose search focus. Kit already owns ordered pending changes, rollback, retained search/selection, IME focus, bounded frames, and clipped mouse coordinates. This is an intentional existing deviation from the literal native-component convention. No new Kit API, dependency floor, or release is required. A package-owned public rendering boundary returns no lines at zero width and retains the selected row (or search when nothing matches) below five content rows; compact mouse events map back to the original rendered row. It does not access private component state or add key handlers. Search placeholder and position-footer relocation remain unsupported by that public API; the existing native-style hints and position indicator are retained rather than patched through private fields.
35
37
 
@@ -47,7 +49,7 @@ Startup transfer summaries report the preference and prerequisites, not a claim
47
49
  | Pull | Remote → local counts and paths; protected loaded session excluded; backup before apply | `sync-mutations.ts`: settings, local hashes, head and baseline rechecked before commit; `recovery-pull-freshness.test.ts`, `local-field-pull-policy.test.ts` |
48
50
  | Push | Local → remote active snapshot counts and paths; preserve eligible unmanaged content; removals do not erase retained history | `sync-mutations.ts`: fresh interactive before-image, local hashes/settings/baseline rechecked, expected-head publication; `backend-orchestration.test.ts`, `review-feedback.test.ts` |
49
51
  | Forced Pull/Push | Same directional review, not a bypass of conditional publication | Refreshed force-push plan requires new approval; migration confirmation remains mandatory even with `--yes`; `sync-state-revision.test.ts`, `local-field-migration.test.ts` |
50
- | Merge / partial progress | Effective before/after snapshots, local/remote counts, conflicts/withheld groups, backups and publication | Existing scrollable review; recheck settings, hashes, state and remote before journal/apply; `merged-sync-confirmation.test.ts`, `partial-directional-progress.test.ts`, `merged-sync-summary.test.ts` |
52
+ | Merge / partial progress | Effective before/after snapshots, local/remote counts, conflicts/withheld groups, backups and publication | Existing scrollable review unless Autonomous sync or another explicit transfer authorization applies; recheck settings, hashes, state and remote before journal/apply; `merged-sync-confirmation.test.ts`, `partial-directional-progress.test.ts`, `merged-sync-summary.test.ts` |
51
53
  | Conflicts | Review complete dependency group and separately choose authority | Artifact fingerprint, group versions, baseline, config, owner and head checks; `conflict-confirmation.test.ts`, `conflict-preview.test.ts` |
52
54
  | Case-variant cleanup | Pull/rollback include the apply engine’s additional top-level alias removals, even when canonical snapshot bytes are unchanged | `apply-review.ts` uses the authoritative apply planner, streams file hashes, records symlink identity without following its target, and rechecks the complete alias set before commit; `transfer-preview.test.ts` covers changed, added, removed, cancelled and symlink aliases plus descriptor cleanup on cancellation. Merge preflight rejects noncanonical changed targets instead of deleting aliases. |
53
55
  | History rollback | Historical snapshot → local and active remote head; backup and protected-session summary | Settings, local bytes, current head, selected backend/setup and baseline rechecked; `history-confirmation-cancellation.test.ts`, `history-cancellation.test.ts`, `rollback-field-policy.test.ts` |
@@ -59,3 +61,18 @@ TUI Pull and Push reviews reuse the existing scrollable safe-default confirmatio
59
61
  ## Review boundaries
60
62
 
61
63
  This change does not touch model prompts, tool exposure, shared-terminal handoff, settings formats, credentials, or default sync policies. Existing startup/session signals and Kit/custom-interaction disposal own new UI calls. Any awaited review is followed by owner validation, and each mutating operation revalidates its mutable inputs before its existing commit boundary. Status and differences actions use existing routes; manager opening/refresh remains observational and does not contact the remote. Diagnostics discloses its WebDAV write/repair behavior before execution.
64
+
65
+ ## Settings wording verification
66
+
67
+ The 2026-11-08 wording update uses **Autonomous sync**, removes Settings maturity markers at the user's request, and keeps `sync.agentMode`, saved consent, defaults, opt-ins, and risk warnings unchanged. A semantic diff audit checked all 16 changed runtime files against the base plus approved prose substitutions; authorization, settings storage, resolver prompts, cancellation, disposal, session replacement, and shutdown logic are unchanged. Review followed `docs/extension-conventions.md`, `docs/extension-settings.md`, and `docs/readme-conventions.md`, plus the skill editing rules. An independent complete-diff review found no issues.
68
+
69
+ Verification evidence:
70
+
71
+ - Root `npm run check` and `npm test` passed: 935 test files, 20,528 passed tests, 34 existing skips, and no unhandled errors.
72
+ - The focused Pi Sync suite passed: 185 files, 3,293 passed tests, and 19 existing skips. Cases cover all four Settings descriptions, TUI/RPC consent, cancellation, the RPC Done exit without authorization, durable saves and failure recovery, Continuous sync dependencies, non-default keys, narrow rendering, and current/legacy documentation anchors.
73
+ - A fenced-code-aware heading audit passed for all 37 package READMEs. Legacy fragment aliases remain in the README, authoritative settings reference, and compatibility index.
74
+ - `npm run package:pack -- sync` and an actual temporary tarball inspection passed: 330 entries include the runtime, source, docs, skill, license, and changelog, without tests or repository plans.
75
+
76
+ The first direct-Vitest run used a symlinked macOS temporary path and triggered existing alias-path safety checks; the successful focused run used the canonical temporary root, as the root runner does. New RPC choice assertions were corrected to include Kit's existing Done exit, and both consent flows now test that exit. No runtime safety check or acceptance criterion was relaxed. Later full-suite command-level rechecks exceeded the harness's 300-second command limit. A background full-suite recheck hit the readiness watchdog in the unchanged `test/packed-publish-native.test.ts`; that file passed separately. The final full-suite recheck uses a managed background runner without changing per-test limits. Biome reports existing schema-version and unrelated lint advisories; its gates pass without changing repository tooling.
77
+
78
+ Physical-terminal appearance, rendered Markdown fragment navigation, live model quality, production backends, Windows, and Android were not newly verified. A maintainer needs the relevant terminal/platform and a separately authorized provider/backend environment to check those paths before claiming new coverage. These are not additional gates for this wording-only change; normal CI and explicit publication approval still apply. No live-provider request, production transfer, publication, tag, or release workflow was performed.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-sync",
3
- "version": "0.57.11",
3
+ "version": "0.57.12",
4
4
  "description": "Pi extension that syncs Pi configuration through Git, WebDAV, Cloudflare R2, or S3-compatible storage.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -47,9 +47,9 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@narumitw/pi-tui-kit": "^0.69.1",
50
- "fast-xml-parser": "^5.11.2",
50
+ "fast-xml-parser": "^5.12.0",
51
51
  "proper-lockfile": "^4.1.2",
52
- "semver": "^7.8.5"
52
+ "semver": "^7.8.6"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@earendil-works/pi-coding-agent": "1.5.0",