@narumitw/pi-sync 0.67.2 → 0.68.0

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 (180) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +29 -49
  3. package/dist/chunks/{chunk-XUZV4OGI.ts → chunk-335XTMMZ.ts} +3 -2
  4. package/dist/chunks/{chunk-XUZV4OGI.ts.map → chunk-335XTMMZ.ts.map} +2 -2
  5. package/dist/chunks/{chunk-PUSMSKIM.ts → chunk-AYGMIMCV.ts} +2 -11
  6. package/dist/chunks/chunk-AYGMIMCV.ts.map +7 -0
  7. package/dist/chunks/{chunk-2MSJDLSM.ts → chunk-BCDBT4X3.ts} +7 -7
  8. package/dist/chunks/{chunk-GRXNUC6O.ts → chunk-FQKWGVMA.ts} +20 -54
  9. package/dist/chunks/chunk-FQKWGVMA.ts.map +7 -0
  10. package/dist/chunks/{chunk-DGVZYS7T.ts → chunk-FR6A7ASZ.ts} +8 -11
  11. package/dist/chunks/chunk-FR6A7ASZ.ts.map +7 -0
  12. package/dist/chunks/{chunk-3NS4PMCI.ts → chunk-J52GYZO6.ts} +2 -8
  13. package/dist/chunks/{chunk-3NS4PMCI.ts.map → chunk-J52GYZO6.ts.map} +2 -2
  14. package/dist/chunks/{chunk-2MUAR5GH.ts → chunk-KAIVTJIQ.ts} +7 -10
  15. package/dist/chunks/chunk-KAIVTJIQ.ts.map +7 -0
  16. package/dist/chunks/{chunk-WBIOSK76.ts → chunk-R7PN3KIY.ts} +1 -2
  17. package/dist/chunks/{chunk-3Q3DMMID.ts → chunk-TLYT6HVI.ts} +8 -8
  18. package/dist/chunks/{chunk-UF2HU2NM.ts → chunk-WCGLU526.ts} +39 -118
  19. package/dist/chunks/chunk-WCGLU526.ts.map +7 -0
  20. package/dist/chunks/{chunk-JREGWM2B.ts → chunk-XNUARYLR.ts} +1 -2
  21. package/dist/chunks/{chunk-C3E75DXW.ts → chunk-YV2R5SJU.ts} +73 -85
  22. package/dist/chunks/chunk-YV2R5SJU.ts.map +7 -0
  23. package/dist/chunks/{command-handler-HWRPH3K3.ts → command-handler-S6BRZMPW.ts} +117 -69
  24. package/dist/chunks/command-handler-S6BRZMPW.ts.map +7 -0
  25. package/dist/chunks/{conflict-review-OBBBSVQD.ts → conflict-review-3XMYDJIK.ts} +2 -2
  26. package/dist/chunks/{file-selection-GASCVN45.ts → file-selection-4BOQBXS7.ts} +10 -17
  27. package/dist/chunks/file-selection-4BOQBXS7.ts.map +7 -0
  28. package/dist/chunks/{manager-result-dispatcher-MJ6G2CEI.ts → manager-result-dispatcher-A4IWLS4J.ts} +7 -7
  29. package/dist/chunks/{manager-ui-Z3B5ZTA6.ts → manager-ui-KHMCSLLV.ts} +114 -581
  30. package/dist/chunks/manager-ui-KHMCSLLV.ts.map +7 -0
  31. package/dist/chunks/{chunk-ECUCXF5Y.ts → merge-review-LWMUE5IW.ts} +2 -3
  32. package/dist/chunks/{remote-selection-ui-34WC7OFE.ts → remote-selection-ui-F6NJBQ3Y.ts} +6 -6
  33. package/dist/chunks/{setup-switch-JZDFQPVW.ts → setup-switch-7LMIRMZ7.ts} +6 -6
  34. package/dist/chunks/{setup-wizard-YOXLXLBY.ts → setup-wizard-2NRPR433.ts} +11 -16
  35. package/dist/chunks/{setup-wizard-YOXLXLBY.ts.map → setup-wizard-2NRPR433.ts.map} +1 -1
  36. package/dist/chunks/{sync-inspection-NIITROKS.ts → sync-inspection-QGM54YCM.ts} +5 -5
  37. package/dist/chunks/{sync-operations-FFI4ZZQL.ts → sync-operations-DTQMKVRQ.ts} +2 -2
  38. package/dist/daemon/dist/build-id.json +1 -0
  39. package/dist/daemon/dist/build-version.js +24 -4
  40. package/dist/daemon/dist/cli.js +51 -67
  41. package/dist/daemon/dist/client-transport.js +15 -5
  42. package/dist/daemon/dist/client.js +2 -10
  43. package/dist/daemon/dist/consent.js +13 -126
  44. package/dist/daemon/dist/daemon-startup.js +135 -30
  45. package/dist/daemon/dist/daemon-status.js +56 -0
  46. package/dist/daemon/dist/engine/backends/git/git-backend.js +4 -17
  47. package/dist/daemon/dist/engine/backends/git/git-storage.js +11 -44
  48. package/dist/daemon/dist/engine/backends/s3/s3-backend.js +6 -6
  49. package/dist/daemon/dist/engine/backends/webdav/webdav-backend.js +6 -6
  50. package/dist/daemon/dist/engine/settings/config.js +16 -149
  51. package/dist/daemon/dist/engine/settings/retired-ignore-policy.js +16 -0
  52. package/dist/daemon/dist/engine/settings/retired-ignore-recovery.js +14 -0
  53. package/dist/daemon/dist/engine/settings/settings-management.js +2 -10
  54. package/dist/daemon/dist/engine/settings/settings-validation.js +8 -21
  55. package/dist/daemon/dist/engine/snapshot/session-paths.js +13 -41
  56. package/dist/daemon/dist/engine/snapshot/snapshot-apply.js +8 -24
  57. package/dist/daemon/dist/engine/snapshot/snapshot-codec.js +7 -11
  58. package/dist/daemon/dist/engine/snapshot/snapshot-exclude-safety.js +19 -76
  59. package/dist/daemon/dist/engine/snapshot/snapshot-transaction-images.js +1 -7
  60. package/dist/daemon/dist/engine/snapshot/snapshot-transaction-policy.js +8 -102
  61. package/dist/daemon/dist/engine/snapshot/snapshot-transaction.js +20 -100
  62. package/dist/daemon/dist/engine/snapshot/snapshot-types.js +1 -11
  63. package/dist/daemon/dist/engine/snapshot/snapshot.js +26 -78
  64. package/dist/daemon/dist/engine/state/sync-state-store.js +5 -1
  65. package/dist/daemon/dist/engine/sync/agent-plan.js +0 -1
  66. package/dist/daemon/dist/engine/sync/agent-policy.js +1 -1
  67. package/dist/daemon/dist/engine/sync/conflict-review.js +0 -2
  68. package/dist/daemon/dist/engine/sync/continuous-sync.js +2 -17
  69. package/dist/daemon/dist/engine/sync/continuous-watch.js +3 -7
  70. package/dist/daemon/dist/engine/sync/directional-action.js +3 -21
  71. package/dist/daemon/dist/engine/sync/initialization.js +4 -15
  72. package/dist/daemon/dist/engine/sync/local-fields.js +4 -65
  73. package/dist/daemon/dist/engine/sync/merge-apply.js +8 -31
  74. package/dist/daemon/dist/engine/sync/merge-journal.js +8 -118
  75. package/dist/daemon/dist/engine/sync/merged-sync.js +13 -70
  76. package/dist/daemon/dist/engine/sync/push-review.js +1 -16
  77. package/dist/daemon/dist/engine/sync/remote-snapshot.js +48 -65
  78. package/dist/daemon/dist/engine/sync/startup-bootstrap.js +3 -3
  79. package/dist/daemon/dist/engine/sync/sync-error-guidance.js +1 -1
  80. package/dist/daemon/dist/engine/sync/sync-inspection.js +1 -2
  81. package/dist/daemon/dist/engine/sync/sync-mutations.js +26 -118
  82. package/dist/daemon/dist/engine/sync/sync-policy.js +26 -150
  83. package/dist/daemon/dist/engine/sync/sync-queries.js +1 -8
  84. package/dist/daemon/dist/engine/sync/sync-rollback.js +12 -50
  85. package/dist/daemon/dist/engine/sync/sync-state.js +2 -15
  86. package/dist/daemon/dist/engine/sync/transfer-freshness.js +7 -17
  87. package/dist/daemon/dist/engine/sync/transfer-size-limits.js +3 -7
  88. package/dist/daemon/dist/engine-service.js +62 -205
  89. package/dist/daemon/dist/foreground-queue-outcome.js +0 -4
  90. package/dist/daemon/dist/index.js +2 -0
  91. package/dist/daemon/dist/legacy-consent-guard.js +34 -0
  92. package/dist/daemon/dist/server.js +99 -11
  93. package/dist/daemon/dist/service-host.js +3 -9
  94. package/dist/daemon/package.json +1 -1
  95. package/dist/index.ts +49 -49
  96. package/dist/index.ts.map +3 -3
  97. package/docs/agent-continuous-hardening.md +2 -0
  98. package/docs/continuous-sync-verification.md +1 -1
  99. package/docs/daemon-migration.md +17 -15
  100. package/docs/tui-contract.md +4 -6
  101. package/package.json +2 -3
  102. package/skills/configure-pi-sync/SKILL.md +23 -78
  103. package/skills/configure-pi-sync/references/configuration.md +59 -76
  104. package/src/commands/command-execution.ts +15 -38
  105. package/src/commands/command-handler.ts +0 -4
  106. package/src/commands/command.ts +2 -1
  107. package/src/daemon/daemon-status-ui.ts +64 -0
  108. package/src/daemon/directional-recovery.ts +4 -33
  109. package/src/daemon/pi-client.ts +87 -94
  110. package/src/settings/config.ts +0 -1
  111. package/src/sync/setup-switch.ts +1 -4
  112. package/src/sync-extension.ts +14 -27
  113. package/src/ui/cancellable-operation.ts +2 -13
  114. package/src/ui/excluded-paths-ui.ts +1 -4
  115. package/src/ui/file-selection.ts +0 -5
  116. package/src/ui/manager-state.ts +12 -75
  117. package/src/ui/manager-ui.ts +7 -96
  118. package/src/ui/remote-selection-ui.ts +29 -130
  119. package/src/ui/settings-ui.ts +169 -388
  120. package/src/ui/setup/setup-actions.ts +4 -16
  121. package/src/ui/setup/setup-prompts.ts +12 -49
  122. package/src/ui/setup/setup-switcher.ts +8 -14
  123. package/src/ui/storage-connections-ui.ts +21 -32
  124. package/src/ui/sync-setups-ui.ts +27 -53
  125. package/dist/chunks/chunk-2MUAR5GH.ts.map +0 -7
  126. package/dist/chunks/chunk-C3E75DXW.ts.map +0 -7
  127. package/dist/chunks/chunk-DGVZYS7T.ts.map +0 -7
  128. package/dist/chunks/chunk-EJDDRS6O.ts +0 -17
  129. package/dist/chunks/chunk-EJDDRS6O.ts.map +0 -7
  130. package/dist/chunks/chunk-GRXNUC6O.ts.map +0 -7
  131. package/dist/chunks/chunk-I72HGZJJ.ts +0 -106
  132. package/dist/chunks/chunk-I72HGZJJ.ts.map +0 -7
  133. package/dist/chunks/chunk-KNEUL4XN.ts +0 -30
  134. package/dist/chunks/chunk-KNEUL4XN.ts.map +0 -7
  135. package/dist/chunks/chunk-PUSMSKIM.ts.map +0 -7
  136. package/dist/chunks/chunk-UF2HU2NM.ts.map +0 -7
  137. package/dist/chunks/chunk-WFBHWYI6.ts +0 -18
  138. package/dist/chunks/chunk-WFBHWYI6.ts.map +0 -7
  139. package/dist/chunks/command-handler-HWRPH3K3.ts.map +0 -7
  140. package/dist/chunks/config-P54GGMXY.ts +0 -39
  141. package/dist/chunks/continuous-record-3SKJ6I3V.ts +0 -23
  142. package/dist/chunks/continuous-record-3SKJ6I3V.ts.map +0 -7
  143. package/dist/chunks/continuous-storage-3EU6I7Z3.ts +0 -27
  144. package/dist/chunks/continuous-storage-3EU6I7Z3.ts.map +0 -7
  145. package/dist/chunks/file-selection-GASCVN45.ts.map +0 -7
  146. package/dist/chunks/ignore-file-ui-5BWA6LBC.ts +0 -21
  147. package/dist/chunks/manager-ui-Z3B5ZTA6.ts.map +0 -7
  148. package/dist/chunks/merge-review-C2KETZKY.ts +0 -11
  149. package/dist/chunks/merge-review-C2KETZKY.ts.map +0 -7
  150. package/dist/chunks/remote-selection-ui-34WC7OFE.ts.map +0 -7
  151. package/dist/chunks/setup-switch-JZDFQPVW.ts.map +0 -7
  152. package/dist/daemon/dist/engine/ignore/adoption-journal.js +0 -146
  153. package/dist/daemon/dist/engine/ignore/effective-ignore-policy.js +0 -33
  154. package/dist/daemon/dist/engine/ignore/ignore-edit.js +0 -102
  155. package/dist/daemon/dist/engine/ignore/ignore-initialization.js +0 -288
  156. package/dist/daemon/dist/engine/ignore/ignore-migration-prompt.js +0 -139
  157. package/dist/daemon/dist/engine/ignore/ignore-settings.js +0 -391
  158. package/dist/daemon/dist/engine/ignore/ignore-source.js +0 -250
  159. package/dist/daemon/dist/engine/ignore/snapshot-ignore-rules.js +0 -39
  160. package/dist/daemon/dist/engine/sync/ignore-adoption-recovery.js +0 -50
  161. package/dist/daemon/dist/engine/sync/ignore-adoption.js +0 -416
  162. package/dist/daemon/dist/engine/sync/ignore-publication.js +0 -23
  163. package/dist/daemon/dist/engine/ui/ignore-rule-preview.js +0 -18
  164. package/dist/daemon/dist/monitor.js +0 -344
  165. package/src/ui/agent-mode-setting.ts +0 -99
  166. package/src/ui/ignore-file-guidance.ts +0 -7
  167. package/src/ui/ignore-file-ui.ts +0 -105
  168. package/src/ui/ignore-migration-prompt.ts +0 -65
  169. package/src/ui/settings-review.ts +0 -26
  170. /package/dist/chunks/{chunk-2MSJDLSM.ts.map → chunk-BCDBT4X3.ts.map} +0 -0
  171. /package/dist/chunks/{chunk-WBIOSK76.ts.map → chunk-R7PN3KIY.ts.map} +0 -0
  172. /package/dist/chunks/{chunk-3Q3DMMID.ts.map → chunk-TLYT6HVI.ts.map} +0 -0
  173. /package/dist/chunks/{chunk-JREGWM2B.ts.map → chunk-XNUARYLR.ts.map} +0 -0
  174. /package/dist/chunks/{conflict-review-OBBBSVQD.ts.map → conflict-review-3XMYDJIK.ts.map} +0 -0
  175. /package/dist/chunks/{config-P54GGMXY.ts.map → manager-result-dispatcher-A4IWLS4J.ts.map} +0 -0
  176. /package/dist/chunks/{chunk-ECUCXF5Y.ts.map → merge-review-LWMUE5IW.ts.map} +0 -0
  177. /package/dist/chunks/{ignore-file-ui-5BWA6LBC.ts.map → remote-selection-ui-F6NJBQ3Y.ts.map} +0 -0
  178. /package/dist/chunks/{manager-result-dispatcher-MJ6G2CEI.ts.map → setup-switch-7LMIRMZ7.ts.map} +0 -0
  179. /package/dist/chunks/{sync-inspection-NIITROKS.ts.map → sync-inspection-QGM54YCM.ts.map} +0 -0
  180. /package/dist/chunks/{sync-operations-FFI4ZZQL.ts.map → sync-operations-DTQMKVRQ.ts.map} +0 -0
@@ -12,6 +12,7 @@ import {
12
12
  DaemonConnection,
13
13
  DaemonError,
14
14
  type DaemonRecoveryTarget,
15
+ DaemonUpgradeBlockedError,
15
16
  type DocumentView,
16
17
  documentFingerprint,
17
18
  ensureDaemon,
@@ -19,6 +20,7 @@ import {
19
20
  MAX_SETTINGS_BYTES,
20
21
  modelSignature,
21
22
  OWNERSHIP_CLEANUP_REQUIRED,
23
+ requestDaemon,
22
24
  waitForDaemonExit,
23
25
  } from "@narumitw/pi-sync-daemon";
24
26
  import { appendDebugEvent, type DebugEvent } from "@narumitw/pi-sync-daemon/engine/debug-log";
@@ -42,16 +44,20 @@ import {
42
44
  import { safeTerminalText } from "../ui/terminal-text.js";
43
45
  import { PiApplyGate } from "./apply-gate.js";
44
46
  import { observeDebugJob } from "./client-debug.js";
45
- import {
46
- type DirectionalCheckpoint,
47
- isForegroundDirection,
48
- type PendingAdoptionRecovery,
49
- runDirectionalRecovery,
50
- } from "./directional-recovery.js";
47
+ import { type DirectionalCheckpoint, isForegroundDirection, runDirectionalRecovery } from "./directional-recovery.js";
51
48
  import { createQueueReleaseUI, type QueueReleaseEvent } from "./queue-release-ui.js";
52
49
  import { quarantineClient, recoverDetachedClients } from "./recovery.js";
53
50
  import { requestStartupBootstrap } from "./startup-bootstrap-client.js";
54
51
 
52
+ const PROTECTION_ONLY_GUIDANCE =
53
+ "This session is only protecting its files on an incompatible Pi Sync daemon. Stop it safely, then use /reload with the matching build.";
54
+
55
+ type DaemonAddress = Pick<Awaited<ReturnType<typeof ensureDaemon>>, "paths" | "identity" | "needsUpgrade"> & {
56
+ ignoreFilesRetired?: boolean;
57
+ autonomousSyncRetired?: boolean;
58
+ upgradeStop?: boolean;
59
+ };
60
+
55
61
  const scope = new AsyncLocalStorage<{ client: PiDaemonClient; reload?: AbortController }>();
56
62
  const clients = new WeakMap<ExtensionContext["sessionManager"], PiDaemonClient>();
57
63
  export function currentPiDaemonClient() {
@@ -238,6 +244,7 @@ function remoteErrorNamed(error: unknown, name: string) {
238
244
  export class PiDaemonClient {
239
245
  private connection?: DaemonConnection;
240
246
  private protectionOnly = false;
247
+ private blockedUpgrade?: { instance: string; reason: string; error?: unknown };
241
248
  private partialConnection?: DaemonConnection;
242
249
  private work = Promise.resolve();
243
250
  private factsQueue = Promise.resolve();
@@ -273,11 +280,6 @@ export class PiDaemonClient {
273
280
  private reloadRequest?: { received: boolean };
274
281
  private pendingReload?: AbortController;
275
282
  private directionalCheckpoint?: DirectionalCheckpoint;
276
- private adoptionRecovery?: {
277
- pending: PendingAdoptionRecovery;
278
- review: { setupName: string; fingerprint: string };
279
- assertRoot(): void;
280
- };
281
283
  private recoveringDirectionalOwner = false;
282
284
  private readonly busy = new Set<string>();
283
285
  private initialized = false;
@@ -389,6 +391,9 @@ export class PiDaemonClient {
389
391
  })();
390
392
  return this.pausing;
391
393
  }
394
+ blockedUpgradeReason(instance: string) {
395
+ return this.blockedUpgrade?.instance === instance ? this.blockedUpgrade.reason : undefined;
396
+ }
392
397
  async attachExisting({ allowUpgrade = false } = {}) {
393
398
  this.validate();
394
399
  this.assertNoDirectionalRecovery();
@@ -412,8 +417,12 @@ export class PiDaemonClient {
412
417
  return true;
413
418
  } catch (error) {
414
419
  this.validate();
415
- if (this.paused || this.recoveringDirectionalOwner) throw error;
420
+ if (this.paused || this.recoveringDirectionalOwner || this.blockedUpgrade?.error !== undefined) throw error;
416
421
  upgradeFailure = safeTerminalText(errorMessage(error));
422
+ if (address.upgradeStop) {
423
+ this.blockedUpgrade = { instance: address.identity.instance, reason: upgradeFailure, error };
424
+ throw error;
425
+ }
417
426
  }
418
427
  }
419
428
  try {
@@ -426,6 +435,7 @@ export class PiDaemonClient {
426
435
  } finally {
427
436
  if (upgradeFailure !== undefined) {
428
437
  this.validate();
438
+ this.blockedUpgrade = { instance: address.identity.instance, reason: upgradeFailure };
429
439
  this.ctx.ui.notify(`pi-sync daemon upgrade failed: ${upgradeFailure}`, "error");
430
440
  }
431
441
  }
@@ -448,22 +458,50 @@ export class PiDaemonClient {
448
458
  if (this.recoveringDirectionalOwner)
449
459
  throw new Error("Pi Sync is recovering the daemon for a transfer. Retry after recovery finishes.");
450
460
  }
451
- async connect(existing?: Awaited<ReturnType<typeof ensureDaemon>>, requestSignal?: AbortSignal) {
461
+ async connect(existing?: DaemonAddress, requestSignal?: AbortSignal) {
452
462
  this.assertNoDirectionalRecovery();
453
463
  return this.attachConnection(existing, requestSignal);
454
464
  }
455
- private async attachConnection(existing?: Awaited<ReturnType<typeof ensureDaemon>>, requestSignal?: AbortSignal) {
465
+ private async ensureWithSessionProtection(signal: AbortSignal, validate: () => void) {
466
+ try {
467
+ return await ensureDaemon(this.root, signal);
468
+ } catch (error) {
469
+ if (!(error instanceof DaemonUpgradeBlockedError)) throw error;
470
+ validate();
471
+ if (this.paused || this.recoveringDirectionalOwner) throw error;
472
+ this.blockedUpgrade = { instance: error.instance, reason: error.message, error };
473
+ try {
474
+ const address = await findDaemon(this.root, signal);
475
+ validate();
476
+ if (this.paused || this.recoveringDirectionalOwner) throw error;
477
+ if (address?.identity.instance !== error.instance || address.paths.root !== this.root || !address.needsUpgrade)
478
+ throw error;
479
+ if (!address.upgradeStop) return { ...address, replacedOwner: false };
480
+ const facts = this.facts(true);
481
+ if (facts.sessionFile) {
482
+ const result = await requestDaemon(address.paths, address.identity, "protect-session", facts, signal);
483
+ validate();
484
+ if (!result || typeof result !== "object" || !("protected" in result) || result.protected !== true)
485
+ throw new Error("Daemon did not acknowledge session-file protection.");
486
+ }
487
+ } catch (cause) {
488
+ validate();
489
+ if (cause === error) throw error;
490
+ throw new Error(`${error.message} Session-file protection could not be confirmed.`, { cause });
491
+ }
492
+ throw error;
493
+ }
494
+ }
495
+ private async attachConnection(existing?: DaemonAddress, requestSignal?: AbortSignal) {
456
496
  const startupSignal = requestSignal ? AbortSignal.any([this.signal, requestSignal]) : this.signal;
457
497
  const validateStartup = () => {
458
498
  this.validate();
459
499
  startupSignal.throwIfAborted();
460
500
  };
461
501
  validateStartup();
502
+ if (!existing && this.blockedUpgrade?.error !== undefined) throw this.blockedUpgrade.error;
462
503
  if (this.connection) {
463
- if (!existing && this.protectionOnly)
464
- throw new Error(
465
- "This session is only protecting its files on an older Pi Sync daemon. Use /reload to upgrade.",
466
- );
504
+ if (!existing && this.protectionOnly) throw new Error(PROTECTION_ONLY_GUIDANCE);
467
505
  return this.connection;
468
506
  }
469
507
  this.connecting ??= (async () => {
@@ -483,10 +521,12 @@ export class PiDaemonClient {
483
521
  let retried = false;
484
522
  for (;;) {
485
523
  validateStartup();
486
- const daemon = existing ?? (await ensureDaemon(this.root, startupSignal));
524
+ const daemon = existing
525
+ ? { ...existing, replacedOwner: false, buildVersion: undefined }
526
+ : await this.ensureWithSessionProtection(startupSignal, validateStartup);
487
527
  validateStartup();
488
528
  if (daemon.paths.root !== this.root) throw new Error("Daemon root changed before attach.");
489
- const protectionOnly = daemon.needsUpgrade === true;
529
+ const protectionOnly = daemon.needsUpgrade || !daemon.ignoreFilesRetired || !daemon.autonomousSyncRetired;
490
530
  const connection = new DaemonConnection(daemon.paths, daemon.identity, this.facts(protectionOnly), {
491
531
  callback: (callback, signal) => this.callback(connection, callback, signal, protectionOnly),
492
532
  mergeReview:
@@ -536,7 +576,7 @@ export class PiDaemonClient {
536
576
  await connection.dispose().catch(() => {});
537
577
  this.partialConnection = undefined;
538
578
  validateStartup();
539
- if (existing || retried) throw error;
579
+ if (existing || retried || this.blockedUpgrade?.error !== undefined) throw error;
540
580
  retried = true;
541
581
  await waitForDaemonExit(daemon.identity, startupSignal);
542
582
  validateStartup();
@@ -551,7 +591,17 @@ export class PiDaemonClient {
551
591
  this.validate();
552
592
  this.connection = connection;
553
593
  this.protectionOnly = protectionOnly;
594
+ if (!protectionOnly) this.blockedUpgrade = undefined;
554
595
  this.partialConnection = undefined;
596
+ if (
597
+ daemon.replacedOwner &&
598
+ daemon.buildVersion &&
599
+ this.ownsContactUI() &&
600
+ !startupSignal.aborted &&
601
+ this.ctx.hasUI &&
602
+ (this.ctx.mode === "tui" || this.ctx.mode === "rpc")
603
+ )
604
+ this.ctx.ui.notify(`Pi Sync daemon replaced. Running version ${daemon.buildVersion}.`, "info");
555
605
  return connection;
556
606
  }
557
607
  })().then(
@@ -572,8 +622,8 @@ export class PiDaemonClient {
572
622
  );
573
623
  const connection = await this.connecting;
574
624
  validateStartup();
575
- if (!existing && this.protectionOnly)
576
- throw new Error("This session is only protecting its files on an older Pi Sync daemon. Use /reload to upgrade.");
625
+ if (!existing && this.blockedUpgrade?.error !== undefined) throw this.blockedUpgrade.error;
626
+ if (!existing && this.protectionOnly) throw new Error(PROTECTION_ONLY_GUIDANCE);
577
627
  return connection;
578
628
  }
579
629
  private ownsContactUI() {
@@ -733,9 +783,11 @@ export class PiDaemonClient {
733
783
  this.clearRestoredContact();
734
784
  }
735
785
  async verifyConnection(signal?: AbortSignal) {
736
- const connection = await this.connect(undefined, signal);
737
- this.validateFactsScope(connection, signal);
786
+ this.validateFactsScope(undefined, signal);
738
787
  this.assertNoDirectionalRecovery();
788
+ const connection = this.connection;
789
+ if (!connection) return;
790
+ if (this.protectionOnly) throw new Error(PROTECTION_ONLY_GUIDANCE);
739
791
  await this.publishFacts(connection, signal);
740
792
  this.validateFactsScope(connection, signal);
741
793
  this.assertNoDirectionalRecovery();
@@ -764,20 +816,7 @@ export class PiDaemonClient {
764
816
  get ownershipCleanupRequired() {
765
817
  return this.cleanupRequired;
766
818
  }
767
- get pendingPullReview() {
768
- const recovery = this.adoptionRecovery;
769
- if (
770
- !this.cleanupRequired ||
771
- !recovery ||
772
- this.paused ||
773
- recovery.pending.owner !== this.connection ||
774
- !recovery.pending.owner.canRecoverForeground(recovery.pending.job)
775
- )
776
- return undefined;
777
- return recovery.review;
778
- }
779
819
  confirmRecoveryExit(owner: DaemonRecoveryTarget) {
780
- this.adoptionRecovery = undefined;
781
820
  this.cleanupRequired = true;
782
821
  this.recoveredOwner = owner;
783
822
  }
@@ -800,17 +839,10 @@ export class PiDaemonClient {
800
839
  ctx = this.ctx,
801
840
  onCommit?: () => void,
802
841
  reload?: AbortController,
803
- requirePendingAdoption = false,
804
842
  ) {
805
843
  const diagnostics = this.debug ? observeDebugJob(operation, (event) => this.recordDebug(event)) : undefined;
806
- const adoptionRecovery =
807
- operation === "pull.foreground" && this.pendingPullReview ? this.adoptionRecovery : undefined;
808
844
  const result = this.work
809
- .then(() => {
810
- if (requirePendingAdoption && !adoptionRecovery)
811
- throw new Error("The original Pull is no longer available for automatic recovery.");
812
- return this.runCurrent(operation, payload, signal, ctx, onCommit, reload, diagnostics, adoptionRecovery);
813
- })
845
+ .then(() => this.runCurrent(operation, payload, signal, ctx, onCommit, reload, diagnostics))
814
846
  .catch((error: unknown) => {
815
847
  diagnostics?.rejected(error, Boolean(signal?.aborted || reload?.signal.aborted));
816
848
  this.recordOwnershipFailure(error);
@@ -848,6 +880,7 @@ export class PiDaemonClient {
848
880
  assertRoot();
849
881
  const attached = await this.attachConnection(replacement, signal);
850
882
  this.validateFactsScope(attached, signal);
883
+ if (this.protectionOnly) throw new Error(PROTECTION_ONLY_GUIDANCE);
851
884
  assertRoot();
852
885
  return attached;
853
886
  } finally {
@@ -862,11 +895,8 @@ export class PiDaemonClient {
862
895
  onCommit?: () => void,
863
896
  reload?: AbortController,
864
897
  diagnostics?: ReturnType<typeof observeDebugJob>,
865
- adoptionRecovery?: PiDaemonClient["adoptionRecovery"],
866
898
  ) {
867
899
  this.validate();
868
- if (adoptionRecovery && (this.adoptionRecovery !== adoptionRecovery || !this.pendingPullReview))
869
- throw new Error("The original Pull is no longer available for automatic recovery.");
870
900
  signal?.throwIfAborted();
871
901
  reload?.signal.throwIfAborted();
872
902
  if (this.pendingReload) throw new Error("Pi resources are about to reload.");
@@ -895,39 +925,17 @@ export class PiDaemonClient {
895
925
  runSignal.addEventListener("abort", clearForeground, { once: true });
896
926
  try {
897
927
  const root = isForegroundDirection(operation) ? lstatSync(this.root) : undefined;
898
- const assertRoot =
899
- adoptionRecovery?.assertRoot ??
900
- (() => {
901
- const current = lstatSync(this.root);
902
- if (!root || !current.isDirectory() || current.dev !== root.dev || current.ino !== root.ino)
903
- throw new Error("The agent directory changed during the transfer.");
904
- });
928
+ const assertRoot = () => {
929
+ const current = lstatSync(this.root);
930
+ if (!root || !current.isDirectory() || current.dev !== root.dev || current.ino !== root.ino)
931
+ throw new Error("The agent directory changed during the transfer.");
932
+ };
905
933
  const intent = root ? structuredClone(payload) : payload;
906
- const pull = operation === "pull.foreground" ? (intent as { setup: string; fingerprint: string }) : undefined;
907
- if (
908
- adoptionRecovery &&
909
- (!pull ||
910
- pull.setup !== adoptionRecovery.review.setupName ||
911
- pull.fingerprint !== adoptionRecovery.review.fingerprint)
912
- )
913
- throw new Error("The sync setup changed before Pull recovery.");
914
- if (adoptionRecovery) {
915
- assertRoot();
916
- const { createSettingsConfigView, syncCheckConfigFingerprint } = await import("../settings/config.js");
917
- this.validateFactsScope(connection, runSignal);
918
- const document = await peekLocalConfigDocument();
919
- this.validateFactsScope(connection, runSignal);
920
- const config = document && (await createSettingsConfigView(document).observe(undefined, runSignal));
921
- this.validateFactsScope(connection, runSignal);
922
- assertRoot();
923
- if (!config || syncCheckConfigFingerprint(config) !== adoptionRecovery.review.fingerprint)
924
- throw new Error("The sync setup changed before Pull recovery.");
925
- }
926
934
  const result = root
927
935
  ? await runDirectionalRecovery(
928
936
  connection,
929
937
  runSignal,
930
- async (checkpoint, retryCheckpoint, retryAdoptionJournal) => {
938
+ async (checkpoint, retryCheckpoint) => {
931
939
  const current = checkpoint.connection;
932
940
  this.validateFactsScope(current, runSignal);
933
941
  assertRoot();
@@ -935,11 +943,7 @@ export class PiDaemonClient {
935
943
  try {
936
944
  return await current.run(
937
945
  operation,
938
- retryAdoptionJournal !== undefined
939
- ? { ...pull, retryAdoptionJournal }
940
- : retryCheckpoint === undefined
941
- ? intent
942
- : { ...(intent as object), retryCheckpoint },
946
+ retryCheckpoint === undefined ? intent : { ...(intent as object), retryCheckpoint },
943
947
  runSignal,
944
948
  onCommit,
945
949
  (id) => {
@@ -955,16 +959,6 @@ export class PiDaemonClient {
955
959
  () => {
956
960
  this.cleanupRequired = true;
957
961
  },
958
- pull && {
959
- pending: adoptionRecovery?.pending,
960
- retain: (pending) => {
961
- this.adoptionRecovery = pending && {
962
- pending,
963
- review: { setupName: pull.setup, fingerprint: pull.fingerprint },
964
- assertRoot,
965
- };
966
- },
967
- },
968
962
  )
969
963
  : await connection.run(operation, payload, runSignal, onCommit, diagnostics?.onSubmit);
970
964
  diagnostics?.returned(result, runSignal.aborted || reload?.signal.aborted);
@@ -1149,7 +1143,6 @@ export class PiDaemonClient {
1149
1143
  helpText?: string;
1150
1144
  background?: boolean;
1151
1145
  fingerprint?: string;
1152
- adoptionRecovery?: number;
1153
1146
  };
1154
1147
  if (callback.kind === "queue-release") {
1155
1148
  if (typeof payload?.reservation !== "string") throw new Error("Invalid queue release.");
@@ -1163,7 +1156,7 @@ export class PiDaemonClient {
1163
1156
  this.validateFactsScope(connection, this.runSignal);
1164
1157
  if (protectionOnly || this.directionalCheckpoint?.accept(connection, callback.job, payload?.fingerprint) !== true)
1165
1158
  return false;
1166
- return payload.adoptionRecovery === 1 ? { adoptionRecovery: 1 } : true;
1159
+ return true;
1167
1160
  }
1168
1161
  if (callback.kind === "queue-acquire") {
1169
1162
  if (this.pendingReload) throw new Error("Pi resources are about to reload.");
@@ -13,7 +13,6 @@ export {
13
13
  syncConfigReviewFingerprint,
14
14
  syncConfigReviewIdentity,
15
15
  syncSessionsWarnings,
16
- syncSettingsConfigFingerprint,
17
16
  syncSetupReviewIdentity,
18
17
  syncSetupStorageReview,
19
18
  } from "@narumitw/pi-sync-daemon/engine/settings/config";
@@ -62,9 +62,7 @@ export async function useSyncSetup(
62
62
  validate();
63
63
  const operationIdentity = syncCheckConfigFingerprint(loadedConfig);
64
64
  if (expectedOperationIdentity !== undefined && operationIdentity !== expectedOperationIdentity) {
65
- throw new Error(
66
- "Setup settings or local rule source changed while the switch preview was open; reopen it and review again.",
67
- );
65
+ throw new Error("Setup settings changed while the switch preview was open; reopen it and review again.");
68
66
  }
69
67
  const switchResult: { action: OnSwitchAction; switched: boolean } = {
70
68
  action: "ask-before-pull",
@@ -89,7 +87,6 @@ export async function useSyncSetup(
89
87
  if (expectedAction !== undefined && switchResult.action !== expectedAction) {
90
88
  throw new Error("Setup-switch behavior changed while the preview was open; reopen it and retry.");
91
89
  }
92
- if (loadedConfig.reservedIgnoreNames !== undefined) switchResult.action = "switch-only";
93
90
  if (switchResult.action === "pull-after-switch" && !ctx.hasUI) {
94
91
  throw new SetupPullRequiresUiError(
95
92
  `Automatic setup pulls require interactive confirmation; sync setup “${safeTerminalText(normalized)}” was not switched. Use TUI or RPC mode.`,
@@ -65,32 +65,25 @@ export default function sync(pi: ExtensionAPI, dependencies: Partial<SyncDepende
65
65
  }
66
66
  const commands = await loaders.commands();
67
67
  if (signal.aborted || owner !== client) return;
68
- const recoveryMenu = !command && client.pendingPullReview;
69
- if (recoveryMenu) await client.setBusy("command", true, false);
70
- try {
71
- if (signal.aborted || owner !== client) return;
72
- await commands.handleCommand(
73
- args,
74
- ctx,
75
- commandSignal,
76
- loaders,
77
- attention,
78
- undefined,
79
- needsDaemonRecovery,
80
- );
81
- } finally {
82
- if (recoveryMenu && !signal.aborted && owner === client)
83
- await client.setBusy("command", false, !needsDaemonRecovery()).catch(() => {});
84
- }
68
+ await commands.handleCommand(
69
+ args,
70
+ ctx,
71
+ commandSignal,
72
+ loaders,
73
+ attention,
74
+ undefined,
75
+ needsDaemonRecovery,
76
+ );
85
77
  return;
86
78
  }
87
- const requiresContact = !["help", "unlock", "migrate-state"].includes(command ?? "");
79
+ const daemonStatus = command === "daemon" && (!action || action === "status");
80
+ const requiresContact = !daemonStatus && !["help", "unlock", "migrate-state"].includes(command ?? "");
88
81
  let busyPublished = false;
89
82
  try {
90
83
  await client.setBusy("command", true, requiresContact);
91
84
  busyPublished = requiresContact;
92
85
  if (signal.aborted || owner !== client) return;
93
- await check.stop();
86
+ if (!daemonStatus) await check.stop();
94
87
  if (signal.aborted || owner !== client) return;
95
88
  if (
96
89
  ready === false &&
@@ -131,7 +124,7 @@ export default function sync(pi: ExtensionAPI, dependencies: Partial<SyncDepende
131
124
  } finally {
132
125
  if (!signal.aborted && owner === client) {
133
126
  // Recovery can publish busy facts after bypassing the initial contact check.
134
- const publish = busyPublished || command === "unlock" || command === "migrate-state";
127
+ const publish = busyPublished || daemonStatus || command === "unlock" || command === "migrate-state";
135
128
  // Release local busy state even if contact failed; do not mask the command result.
136
129
  await client.setBusy("command", false, publish && !needsDaemonRecovery()).catch(() => {});
137
130
  }
@@ -204,13 +197,7 @@ export default function sync(pi: ExtensionAPI, dependencies: Partial<SyncDepende
204
197
  client.disableQueueReleaseUI();
205
198
  releaseStatus();
206
199
  }
207
- if (
208
- ready &&
209
- !signal.aborted &&
210
- owner === client &&
211
- !(ready.continuous && ready.agentMode) &&
212
- (ready.automatic || startupTransferEnabled(ready))
213
- )
200
+ if (ready && !signal.aborted && owner === client && (ready.automatic || startupTransferEnabled(ready)))
214
201
  await withPiDaemonClient(ctx, async () => {
215
202
  check.start(
216
203
  ctx,
@@ -19,7 +19,6 @@ export type RunRoute = (
19
19
  onDialog?: (active: boolean) => void,
20
20
  retryRefusal?: boolean,
21
21
  directionalFingerprint?: string,
22
- requirePendingAdoption?: boolean,
23
22
  ) => Promise<RunRouteResult | undefined>;
24
23
 
25
24
  export type CancellableOperationResult = RunRouteResult | { kind: "closed" } | { kind: "cancelled" };
@@ -30,7 +29,6 @@ interface CancellableOperationOptions {
30
29
  cancelledMessage?: string | null;
31
30
  target?: string;
32
31
  directionalFingerprint?: string;
33
- requirePendingAdoption?: boolean;
34
32
  signal?: AbortSignal;
35
33
  isCurrent?: () => boolean;
36
34
  }
@@ -46,16 +44,7 @@ export async function runCancellableOperation(
46
44
  ctx,
47
45
  message,
48
46
  (signal, onCommit, onDialog) =>
49
- runRoute(
50
- route,
51
- signal,
52
- onCommit,
53
- options.target,
54
- onDialog,
55
- undefined,
56
- options.directionalFingerprint,
57
- options.requirePendingAdoption,
58
- ),
47
+ runRoute(route, signal, onCommit, options.target, onDialog, undefined, options.directionalFingerprint),
59
48
  options,
60
49
  );
61
50
  return result.kind === "completed" ? (result.value ?? { kind: "failed" }) : result;
@@ -75,7 +64,7 @@ export async function runCancellableTask<Value>(
75
64
  onCommit?: () => void,
76
65
  onDialog?: (active: boolean) => void,
77
66
  ) => Promise<Value>,
78
- options: Omit<CancellableOperationOptions, "target" | "directionalFingerprint" | "requirePendingAdoption"> = {},
67
+ options: Omit<CancellableOperationOptions, "target" | "directionalFingerprint"> = {},
79
68
  ): Promise<CancellableTaskResult<Value>> {
80
69
  const {
81
70
  commitAware = false,
@@ -100,8 +100,6 @@ export async function showExcludedPaths(ctx: ExtensionCommandContext, setupName:
100
100
  setupName,
101
101
  (setup) => {
102
102
  validate();
103
- if (setup.sync.pathPolicy === "ignore-file")
104
- throw new Error("Edit the ignore file to change this setup's policy.");
105
103
  return { ...setup, sync: { ...setup.sync, exclude } };
106
104
  },
107
105
  { expectedConfigFingerprint: syncCheckConfigFingerprint(config), upgradeExclude: true, signal },
@@ -219,8 +217,7 @@ export async function showDirectoryScope(ctx: ExtensionCommandContext, config: A
219
217
  config.setupName,
220
218
  (setup) => {
221
219
  validate();
222
- if (setup.sync.scope !== "agent-directory" || setup.sync.pathPolicy === "ignore-file")
223
- throw new Error("Sync scope changed during review.");
220
+ if (setup.sync.scope !== "agent-directory") throw new Error("Sync scope changed during review.");
224
221
  return {
225
222
  ...setup,
226
223
  sync: {
@@ -13,7 +13,6 @@ import {
13
13
  syncIncludeSelection,
14
14
  } from "../sync/sync-policy.js";
15
15
  import { showDirectoryScope } from "./excluded-paths-ui.js";
16
- import { manualIgnoreFileGuidance } from "./ignore-file-guidance.js";
17
16
 
18
17
  const BUILT_IN_PREFIX = "builtin:";
19
18
  const CUSTOM_PREFIX = "custom:";
@@ -31,10 +30,6 @@ export async function showFileSelection(ctx: ExtensionCommandContext, setupName?
31
30
  const config = await loadSettingsConfig(setupName);
32
31
  if (signal?.aborted) return;
33
32
  validate();
34
- if (config.pathPolicy === "ignore-file") {
35
- if (ctx.hasUI) ctx.ui.notify(manualIgnoreFileGuidance(config.ignoreFile ?? ".syncignore"), "info");
36
- return;
37
- }
38
33
  if (config.scope === "agent-directory") return showDirectoryScope(ctx, config, signal);
39
34
  const selection = syncIncludeSelection(config.include);
40
35
  const original: SelectionDraft = {