@narumitw/pi-sync 0.67.0 → 0.67.2

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 (79) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/chunks/{chunk-BESRBKVO.ts → chunk-2MSJDLSM.ts} +7 -7
  4. package/dist/chunks/{chunk-BYVHABNR.ts → chunk-2MUAR5GH.ts} +2 -2
  5. package/dist/chunks/{chunk-DAZZ5BEJ.ts → chunk-3NS4PMCI.ts} +6 -2
  6. package/dist/chunks/{chunk-FI2F5JBS.ts → chunk-3Q3DMMID.ts} +8 -8
  7. package/dist/chunks/{chunk-JQ5BAWW2.ts → chunk-C3E75DXW.ts} +84 -21
  8. package/dist/chunks/chunk-C3E75DXW.ts.map +7 -0
  9. package/dist/chunks/{chunk-SZJOUVCL.ts → chunk-DGVZYS7T.ts} +5 -5
  10. package/dist/chunks/{chunk-WJQ4TGN5.ts → chunk-ECUCXF5Y.ts} +2 -2
  11. package/dist/chunks/{chunk-ASU3GZPW.ts → chunk-GRXNUC6O.ts} +6 -6
  12. package/dist/chunks/{chunk-Z5JMOXJM.ts → chunk-I72HGZJJ.ts} +5 -5
  13. package/dist/chunks/{chunk-AYGMIMCV.ts → chunk-PUSMSKIM.ts} +11 -2
  14. package/dist/chunks/chunk-PUSMSKIM.ts.map +7 -0
  15. package/dist/chunks/{chunk-5YOLQKNZ.ts → chunk-UF2HU2NM.ts} +14 -14
  16. package/dist/chunks/{command-handler-SQC2L2FJ.ts → command-handler-HWRPH3K3.ts} +40 -32
  17. package/dist/chunks/command-handler-HWRPH3K3.ts.map +7 -0
  18. package/dist/chunks/config-P54GGMXY.ts +39 -0
  19. package/dist/chunks/{conflict-review-J7L7S4AR.ts → conflict-review-OBBBSVQD.ts} +2 -2
  20. package/dist/chunks/{file-selection-XWACUTAH.ts → file-selection-GASCVN45.ts} +6 -6
  21. package/dist/chunks/{ignore-file-ui-OHFISFVC.ts → ignore-file-ui-5BWA6LBC.ts} +5 -5
  22. package/dist/chunks/{manager-result-dispatcher-WXE2BAQO.ts → manager-result-dispatcher-MJ6G2CEI.ts} +7 -7
  23. package/dist/chunks/{manager-ui-DWOMAJKE.ts → manager-ui-Z3B5ZTA6.ts} +50 -32
  24. package/dist/chunks/manager-ui-Z3B5ZTA6.ts.map +7 -0
  25. package/dist/chunks/{merge-review-AAC674C6.ts → merge-review-C2KETZKY.ts} +3 -3
  26. package/dist/chunks/{remote-selection-ui-E4XZCQ7A.ts → remote-selection-ui-34WC7OFE.ts} +6 -6
  27. package/dist/chunks/{setup-switch-644T6KHG.ts → setup-switch-JZDFQPVW.ts} +4 -4
  28. package/dist/chunks/setup-switch-JZDFQPVW.ts.map +7 -0
  29. package/dist/chunks/{setup-wizard-IEW56AZE.ts → setup-wizard-YOXLXLBY.ts} +9 -9
  30. package/dist/chunks/{sync-inspection-NBBTSMKR.ts → sync-inspection-NIITROKS.ts} +5 -5
  31. package/dist/chunks/{sync-operations-AIEM2KL2.ts → sync-operations-FFI4ZZQL.ts} +2 -2
  32. package/dist/daemon/dist/client.js +32 -18
  33. package/dist/daemon/dist/daemon-recovery.js +5 -3
  34. package/dist/daemon/dist/engine/debug-log.js +19 -0
  35. package/dist/daemon/dist/engine/ignore/adoption-journal.js +6 -3
  36. package/dist/daemon/dist/engine/sync/ignore-adoption.js +8 -2
  37. package/dist/daemon/dist/engine/sync/sync-mutations.js +4 -1
  38. package/dist/daemon/dist/engine-service.js +22 -6
  39. package/dist/daemon/dist/foreground-queue-outcome.js +4 -0
  40. package/dist/daemon/dist/server.js +4 -3
  41. package/dist/daemon/dist/service-host.js +7 -2
  42. package/dist/daemon/package.json +1 -1
  43. package/dist/index.ts +41 -32
  44. package/dist/index.ts.map +2 -2
  45. package/docs/daemon-migration.md +2 -0
  46. package/package.json +2 -2
  47. package/skills/configure-pi-sync/references/configuration.md +2 -0
  48. package/src/commands/command-execution.ts +10 -1
  49. package/src/commands/command-handler.ts +4 -0
  50. package/src/daemon/client-debug.ts +6 -3
  51. package/src/daemon/directional-recovery.ts +35 -5
  52. package/src/daemon/pi-client.ts +83 -14
  53. package/src/sync-extension.ts +17 -9
  54. package/src/ui/cancellable-operation.ts +13 -2
  55. package/src/ui/manager-state.ts +1 -0
  56. package/src/ui/manager-ui.ts +25 -4
  57. package/dist/chunks/chunk-AYGMIMCV.ts.map +0 -7
  58. package/dist/chunks/chunk-JQ5BAWW2.ts.map +0 -7
  59. package/dist/chunks/command-handler-SQC2L2FJ.ts.map +0 -7
  60. package/dist/chunks/manager-ui-DWOMAJKE.ts.map +0 -7
  61. /package/dist/chunks/{chunk-BESRBKVO.ts.map → chunk-2MSJDLSM.ts.map} +0 -0
  62. /package/dist/chunks/{chunk-BYVHABNR.ts.map → chunk-2MUAR5GH.ts.map} +0 -0
  63. /package/dist/chunks/{chunk-DAZZ5BEJ.ts.map → chunk-3NS4PMCI.ts.map} +0 -0
  64. /package/dist/chunks/{chunk-FI2F5JBS.ts.map → chunk-3Q3DMMID.ts.map} +0 -0
  65. /package/dist/chunks/{chunk-SZJOUVCL.ts.map → chunk-DGVZYS7T.ts.map} +0 -0
  66. /package/dist/chunks/{chunk-WJQ4TGN5.ts.map → chunk-ECUCXF5Y.ts.map} +0 -0
  67. /package/dist/chunks/{chunk-ASU3GZPW.ts.map → chunk-GRXNUC6O.ts.map} +0 -0
  68. /package/dist/chunks/{chunk-Z5JMOXJM.ts.map → chunk-I72HGZJJ.ts.map} +0 -0
  69. /package/dist/chunks/{chunk-5YOLQKNZ.ts.map → chunk-UF2HU2NM.ts.map} +0 -0
  70. /package/dist/chunks/{ignore-file-ui-OHFISFVC.ts.map → config-P54GGMXY.ts.map} +0 -0
  71. /package/dist/chunks/{conflict-review-J7L7S4AR.ts.map → conflict-review-OBBBSVQD.ts.map} +0 -0
  72. /package/dist/chunks/{file-selection-XWACUTAH.ts.map → file-selection-GASCVN45.ts.map} +0 -0
  73. /package/dist/chunks/{manager-result-dispatcher-WXE2BAQO.ts.map → ignore-file-ui-5BWA6LBC.ts.map} +0 -0
  74. /package/dist/chunks/{merge-review-AAC674C6.ts.map → manager-result-dispatcher-MJ6G2CEI.ts.map} +0 -0
  75. /package/dist/chunks/{remote-selection-ui-E4XZCQ7A.ts.map → merge-review-C2KETZKY.ts.map} +0 -0
  76. /package/dist/chunks/{setup-switch-644T6KHG.ts.map → remote-selection-ui-34WC7OFE.ts.map} +0 -0
  77. /package/dist/chunks/{setup-wizard-IEW56AZE.ts.map → setup-wizard-YOXLXLBY.ts.map} +0 -0
  78. /package/dist/chunks/{sync-inspection-NBBTSMKR.ts.map → sync-inspection-NIITROKS.ts.map} +0 -0
  79. /package/dist/chunks/{sync-operations-AIEM2KL2.ts.map → sync-operations-FFI4ZZQL.ts.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @narumitw/pi-sync
2
2
 
3
+ ## 0.67.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 489bc7a: Record foreground Push and Pull attempts in the private debug log, including resumed ignore-rule Pulls. Match client and daemon records by operation ID without logging raw errors or transfer data.
8
+
9
+ ## 0.67.1
10
+
11
+ ### Patch Changes
12
+
13
+ - df24888: Resume an interrupted ignore-rule adoption from Pull when the original session can verify file-queue recovery. Use the recorded snapshot and ask before continuing.
14
+
3
15
  ## 0.67.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -84,7 +84,7 @@ Remote status: Not checked
84
84
  Last applied: Never synced
85
85
  ```
86
86
 
87
- Use **Sync…** (**Sync now** in RPC) to merge both ways. **Push to remote** uses this device's version for managed files; **Pull from remote** uses the remote version. After initial daemon handover, each choice can replace or remove managed files at the destination without a second transfer confirmation. Push preserves the previous remote version in **History**; Pull creates a local backup before applying changes. History rollback still follows the current sync rules; see [Recover excluded files from History](#recover-excluded-files-from-history) for files those rules no longer select. Use **View differences** first if you want a preview. Selecting a direction does not authorize background transfers or model use. If a file-queue release cannot be confirmed, Pi Sync attempts recovery within the same action. It does not repeat a known commit or guess when the write outcome is unknown.
87
+ Use **Sync…** (**Sync now** in RPC) to merge both ways. **Push to remote** uses this device's version for managed files; **Pull from remote** uses the remote version. After initial daemon handover, each choice can replace or remove managed files at the destination without a second transfer confirmation. Push preserves the previous remote version in **History**; Pull creates a local backup before applying changes. History rollback still follows the current sync rules; see [Recover excluded files from History](#recover-excluded-files-from-history) for files those rules no longer select. Use **View differences** first if you want a preview. Selecting a direction does not authorize background transfers or model use. If a file-queue release cannot be confirmed, Pi Sync attempts recovery within the same action. It does not repeat a known commit or guess when the write outcome is unknown. Use the same **Pull from remote** action to review and continue a pending ignore-rule Pull. It uses the recorded snapshot, not the latest remote snapshot. See [daemon recovery](./docs/daemon-migration.md#recover-from-uncertain-daemon-cleanup) if it cannot recover the owner.
88
88
 
89
89
  Type to filter actions; navigation scrolls the list. **Settings**, **History**, and **Diagnostics** remain directly available. Switching appears only when multiple valid setups exist; review and access-recovery actions appear when needed.
90
90
 
@@ -2,17 +2,17 @@
2
2
  // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
3
  import {
4
4
  showRemoteSelectionReview
5
- } from "./chunk-5YOLQKNZ.ts";
5
+ } from "./chunk-UF2HU2NM.ts";
6
6
  import {
7
7
  runCancellableOperation
8
- } from "./chunk-AYGMIMCV.ts";
9
- import {
10
- loadConfig,
11
- syncConfigReviewIdentity
12
- } from "./chunk-DAZZ5BEJ.ts";
8
+ } from "./chunk-PUSMSKIM.ts";
13
9
  import {
14
10
  errorMessage
15
11
  } from "./chunk-6YKOHBSC.ts";
12
+ import {
13
+ loadConfig,
14
+ syncConfigReviewIdentity
15
+ } from "./chunk-3NS4PMCI.ts";
16
16
  import {
17
17
  safeTerminalText
18
18
  } from "./chunk-2JNFEZ3V.ts";
@@ -208,4 +208,4 @@ async function dispatchManagerResult(ctx, initialResult, origin, runRoute, signa
208
208
  export {
209
209
  dispatchManagerResult
210
210
  };
211
- //# sourceMappingURL=chunk-BESRBKVO.ts.map
211
+ //# sourceMappingURL=chunk-2MSJDLSM.ts.map
@@ -24,7 +24,7 @@ import {
24
24
  import {
25
25
  loadSettingsConfig,
26
26
  syncCheckConfigFingerprint
27
- } from "./chunk-DAZZ5BEJ.ts";
27
+ } from "./chunk-3NS4PMCI.ts";
28
28
  import {
29
29
  safeTerminalText
30
30
  } from "./chunk-2JNFEZ3V.ts";
@@ -274,4 +274,4 @@ export {
274
274
  directoryScopeSummary,
275
275
  showDirectoryScope
276
276
  };
277
- //# sourceMappingURL=chunk-BYVHABNR.ts.map
277
+ //# sourceMappingURL=chunk-2MUAR5GH.ts.map
@@ -24,6 +24,8 @@ import {
24
24
  export {
25
25
  configFromSettings,
26
26
  createSettingsConfigView,
27
+ isEnabled,
28
+ isExplicitlyEnabled,
27
29
  loadConfig,
28
30
  loadConfigForCheck,
29
31
  loadPartialConfig,
@@ -33,6 +35,8 @@ export {
33
35
  syncConfigReviewFingerprint,
34
36
  syncConfigReviewIdentity,
35
37
  syncSessionsWarnings,
36
- syncSettingsConfigFingerprint
38
+ syncSettingsConfigFingerprint,
39
+ syncSetupReviewIdentity,
40
+ syncSetupStorageReview
37
41
  };
38
- //# sourceMappingURL=chunk-DAZZ5BEJ.ts.map
42
+ //# sourceMappingURL=chunk-3NS4PMCI.ts.map
@@ -1,19 +1,19 @@
1
1
  // @generated by scripts/build-runtime.mjs; do not edit.
2
2
  // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
- import {
4
- sameSyncExclude
5
- } from "./chunk-ZO52JM4H.ts";
6
- import {
7
- syncCheckConfigFingerprint,
8
- syncConfigReviewFingerprint
9
- } from "./chunk-DAZZ5BEJ.ts";
10
3
  import {
11
4
  setSyncStatus
12
5
  } from "./chunk-H7VOTY5N.ts";
6
+ import {
7
+ sameSyncExclude
8
+ } from "./chunk-ZO52JM4H.ts";
13
9
  import {
14
10
  sameSyncInclude,
15
11
  syncDirectoryPolicyKey
16
12
  } from "./chunk-R3SAMXB6.ts";
13
+ import {
14
+ syncCheckConfigFingerprint,
15
+ syncConfigReviewFingerprint
16
+ } from "./chunk-3NS4PMCI.ts";
17
17
  import {
18
18
  safeTerminalText
19
19
  } from "./chunk-2JNFEZ3V.ts";
@@ -184,4 +184,4 @@ export {
184
184
  observationMatchesConfig,
185
185
  observationSummary
186
186
  };
187
- //# sourceMappingURL=chunk-FI2F5JBS.ts.map
187
+ //# sourceMappingURL=chunk-3Q3DMMID.ts.map
@@ -170,7 +170,7 @@ var PiApplyGate = class {
170
170
  };
171
171
 
172
172
  // src/daemon/client-debug.ts
173
- import { debugOperation } from "#pi-sync-daemon/engine/debug-log";
173
+ import { debugJobResult, debugOperation } from "#pi-sync-daemon/engine/debug-log";
174
174
  function observeDebugJob(operation, append) {
175
175
  const kind = debugOperation(operation);
176
176
  if (!kind) return void 0;
@@ -178,11 +178,14 @@ function observeDebugJob(operation, append) {
178
178
  const record = (outcome) => append({ event: "job", operation: kind, outcome, ...operationId ? { operationId } : {} });
179
179
  return {
180
180
  onSubmit(id) {
181
+ if (operationId && operationId !== id) record("blocked");
181
182
  operationId = id;
182
183
  record("started");
183
184
  },
184
- returned(result) {
185
- if (result === "cancelled") record("cancelled");
185
+ returned(result, interrupted = false) {
186
+ const outcome = debugJobResult(kind, result);
187
+ if (interrupted && outcome !== "completed") record("cancelled");
188
+ else if (outcome) record(outcome);
186
189
  else if (result === "archived" || kind === "initialize" && typeof result === "object" && result !== null && "handoverRequired" in result && result.handoverRequired === true)
187
190
  record("blocked");
188
191
  else if (kind === "migrate-state" && typeof result === "object" && result !== null && "status" in result && result.status === "cancelled")
@@ -221,6 +224,11 @@ var DirectionalCheckpoint = class {
221
224
  function recoveryOutcome(value) {
222
225
  if (!value || typeof value !== "object" || !("foregroundQueueCleanup" in value)) return;
223
226
  if (value.foregroundQueueCleanup === "before-mutation") return { phase: "unchanged" };
227
+ if (value.foregroundQueueCleanup === "resume-adoption") {
228
+ if (!("journal" in value) || typeof value.journal !== "string" || !/^[a-f0-9]{64}$/u.test(value.journal))
229
+ throw new Error("The recorded Pull could not be verified. Use /sync daemon recover.");
230
+ return { phase: "adoption", journal: value.journal };
231
+ }
224
232
  if (value.foregroundQueueCleanup === "verified-result" && "result" in value)
225
233
  return { phase: "completed", result: value.result };
226
234
  }
@@ -237,10 +245,13 @@ function cancelledAfterCompletion(result, cause) {
237
245
  error.name = "AbortError";
238
246
  return error;
239
247
  }
240
- async function runDirectionalRecovery(connection, signal, run, recover, markCleanupRequired) {
248
+ async function runDirectionalRecovery(connection, signal, run, recover, markCleanupRequired, adoption) {
241
249
  signal.throwIfAborted();
250
+ const pending = adoption?.pending;
251
+ if (pending && pending.owner !== connection) throw new Error("The daemon changed before Pull recovery.");
242
252
  const attempt2 = new DirectionalCheckpoint(connection);
243
- const result = await run(attempt2);
253
+ attempt2.job = pending?.job;
254
+ const result = pending ? { foregroundQueueCleanup: "resume-adoption", journal: pending.journal } : await run(attempt2);
244
255
  const primary = recoveryOutcome(result);
245
256
  if (!primary) return result;
246
257
  markCleanupRequired();
@@ -248,9 +259,12 @@ async function runDirectionalRecovery(connection, signal, run, recover, markClea
248
259
  const bounded = AbortSignal.any([signal, AbortSignal.timeout(45e3)]);
249
260
  try {
250
261
  bounded.throwIfAborted();
251
- if (!attempt2.job || primary.phase === "unchanged" && !attempt2.fingerprint)
262
+ if (!attempt2.job || primary.phase === "unchanged" && !attempt2.fingerprint || primary.phase === "adoption" && (!adoption || !pending && !attempt2.fingerprint))
252
263
  throw new Error("The original transfer scope could not be verified.");
264
+ if (primary.phase === "adoption")
265
+ adoption?.retain({ owner: connection, job: attempt2.job, journal: primary.journal });
253
266
  replacement = await recover(connection, attempt2.job, bounded);
267
+ if (primary.phase === "adoption") adoption?.retain(void 0);
254
268
  bounded.throwIfAborted();
255
269
  } catch (error) {
256
270
  if (signal.aborted) {
@@ -263,11 +277,14 @@ async function runDirectionalRecovery(connection, signal, run, recover, markClea
263
277
  `The transfer finished, but file-queue recovery stopped. ${detail}${restoreMessage(primary.result)}`,
264
278
  { cause: error }
265
279
  );
280
+ if (primary.phase === "adoption")
281
+ throw new Error(`Pull recovery stopped. The adoption journal was kept. ${detail}`, { cause: error });
266
282
  throw new Error(`No transfer was applied, but file-queue recovery stopped. ${detail}`, { cause: error });
267
283
  }
268
284
  if (primary.phase === "completed") return primary.result;
269
- const retry = new DirectionalCheckpoint(replacement, attempt2.fingerprint);
270
- const retried = await run(retry, attempt2.fingerprint);
285
+ const retryCheckpoint = primary.phase === "unchanged" ? attempt2.fingerprint : void 0;
286
+ const retry = new DirectionalCheckpoint(replacement, retryCheckpoint);
287
+ const retried = await run(retry, retryCheckpoint, primary.phase === "adoption" ? primary.journal : void 0);
271
288
  const remaining = recoveryOutcome(retried);
272
289
  if (!remaining) return retried;
273
290
  markCleanupRequired();
@@ -277,6 +294,11 @@ async function runDirectionalRecovery(connection, signal, run, recover, markClea
277
294
  `Transfer finished, but file-queue cleanup is still uncertain after one recovery attempt.${restoreMessage(remaining.result)}`
278
295
  );
279
296
  }
297
+ if (remaining.phase === "adoption") {
298
+ if (retry.job && retry.fingerprint)
299
+ adoption?.retain({ owner: replacement, job: retry.job, journal: remaining.journal });
300
+ throw new Error("File-queue cleanup is still uncertain after one recovery attempt. The adoption journal was kept.");
301
+ }
280
302
  throw new Error("File-queue release could not be verified after one recovery attempt. No transfer was applied.");
281
303
  }
282
304
 
@@ -672,6 +694,7 @@ var PiDaemonClient = class {
672
694
  reloadRequest;
673
695
  pendingReload;
674
696
  directionalCheckpoint;
697
+ adoptionRecovery;
675
698
  recoveringDirectionalOwner = false;
676
699
  busy = /* @__PURE__ */ new Set();
677
700
  initialized = false;
@@ -1110,7 +1133,14 @@ var PiDaemonClient = class {
1110
1133
  get ownershipCleanupRequired() {
1111
1134
  return this.cleanupRequired;
1112
1135
  }
1136
+ get pendingPullReview() {
1137
+ const recovery = this.adoptionRecovery;
1138
+ if (!this.cleanupRequired || !recovery || this.paused || recovery.pending.owner !== this.connection || !recovery.pending.owner.canRecoverForeground(recovery.pending.job))
1139
+ return void 0;
1140
+ return recovery.review;
1141
+ }
1113
1142
  confirmRecoveryExit(owner) {
1143
+ this.adoptionRecovery = void 0;
1114
1144
  this.cleanupRequired = true;
1115
1145
  this.recoveredOwner = owner;
1116
1146
  }
@@ -1118,9 +1148,14 @@ var PiDaemonClient = class {
1118
1148
  if (error instanceof DaemonError2 && error.remote.properties?.code === OWNERSHIP_CLEANUP_REQUIRED || error instanceof Error && ("code" in error && error.code === OWNERSHIP_CLEANUP_REQUIRED || error.message === "Daemon ownership cleanup is uncertain; stop and reconcile before restarting." || error.message === "Daemon ownership cleanup is uncertain; stop and reconcile before retrying." || error.message === "File-queue release is uncertain; stop the daemon and keep grants quarantined until owner exit."))
1119
1149
  this.cleanupRequired = true;
1120
1150
  }
1121
- run(operation, payload, signal, ctx = this.ctx, onCommit, reload) {
1151
+ run(operation, payload, signal, ctx = this.ctx, onCommit, reload, requirePendingAdoption = false) {
1122
1152
  const diagnostics = this.debug ? observeDebugJob(operation, (event) => this.recordDebug(event)) : void 0;
1123
- const result = this.work.then(() => this.runCurrent(operation, payload, signal, ctx, onCommit, reload, diagnostics)).catch((error) => {
1153
+ const adoptionRecovery = operation === "pull.foreground" && this.pendingPullReview ? this.adoptionRecovery : void 0;
1154
+ const result = this.work.then(() => {
1155
+ if (requirePendingAdoption && !adoptionRecovery)
1156
+ throw new Error("The original Pull is no longer available for automatic recovery.");
1157
+ return this.runCurrent(operation, payload, signal, ctx, onCommit, reload, diagnostics, adoptionRecovery);
1158
+ }).catch((error) => {
1124
1159
  diagnostics?.rejected(error, Boolean(signal?.aborted || reload?.signal.aborted));
1125
1160
  this.recordOwnershipFailure(error);
1126
1161
  throw error;
@@ -1160,8 +1195,10 @@ var PiDaemonClient = class {
1160
1195
  this.recoveringDirectionalOwner = false;
1161
1196
  }
1162
1197
  }
1163
- async runCurrent(operation, payload, signal, ctx = this.ctx, onCommit, reload, diagnostics) {
1198
+ async runCurrent(operation, payload, signal, ctx = this.ctx, onCommit, reload, diagnostics, adoptionRecovery) {
1164
1199
  this.validate();
1200
+ if (adoptionRecovery && (this.adoptionRecovery !== adoptionRecovery || !this.pendingPullReview))
1201
+ throw new Error("The original Pull is no longer available for automatic recovery.");
1165
1202
  signal?.throwIfAborted();
1166
1203
  reload?.signal.throwIfAborted();
1167
1204
  if (this.pendingReload) throw new Error("Pi resources are about to reload.");
@@ -1189,16 +1226,31 @@ var PiDaemonClient = class {
1189
1226
  runSignal.addEventListener("abort", clearForeground, { once: true });
1190
1227
  try {
1191
1228
  const root = isForegroundDirection(operation) ? lstatSync(this.root) : void 0;
1192
- const assertRoot = () => {
1229
+ const assertRoot = adoptionRecovery?.assertRoot ?? (() => {
1193
1230
  const current2 = lstatSync(this.root);
1194
1231
  if (!root || !current2.isDirectory() || current2.dev !== root.dev || current2.ino !== root.ino)
1195
1232
  throw new Error("The agent directory changed during the transfer.");
1196
- };
1233
+ });
1197
1234
  const intent = root ? structuredClone(payload) : payload;
1235
+ const pull = operation === "pull.foreground" ? intent : void 0;
1236
+ if (adoptionRecovery && (!pull || pull.setup !== adoptionRecovery.review.setupName || pull.fingerprint !== adoptionRecovery.review.fingerprint))
1237
+ throw new Error("The sync setup changed before Pull recovery.");
1238
+ if (adoptionRecovery) {
1239
+ assertRoot();
1240
+ const { createSettingsConfigView, syncCheckConfigFingerprint } = await import("./config-P54GGMXY.ts");
1241
+ this.validateFactsScope(connection, runSignal);
1242
+ const document = await peekLocalConfigDocument();
1243
+ this.validateFactsScope(connection, runSignal);
1244
+ const config = document && await createSettingsConfigView(document).observe(void 0, runSignal);
1245
+ this.validateFactsScope(connection, runSignal);
1246
+ assertRoot();
1247
+ if (!config || syncCheckConfigFingerprint(config) !== adoptionRecovery.review.fingerprint)
1248
+ throw new Error("The sync setup changed before Pull recovery.");
1249
+ }
1198
1250
  const result = root ? await runDirectionalRecovery(
1199
1251
  connection,
1200
1252
  runSignal,
1201
- async (checkpoint, retryCheckpoint) => {
1253
+ async (checkpoint, retryCheckpoint, retryAdoptionJournal) => {
1202
1254
  const current2 = checkpoint.connection;
1203
1255
  this.validateFactsScope(current2, runSignal);
1204
1256
  assertRoot();
@@ -1206,7 +1258,7 @@ var PiDaemonClient = class {
1206
1258
  try {
1207
1259
  return await current2.run(
1208
1260
  operation,
1209
- retryCheckpoint === void 0 ? intent : { ...intent, retryCheckpoint },
1261
+ retryAdoptionJournal !== void 0 ? { ...pull, retryAdoptionJournal } : retryCheckpoint === void 0 ? intent : { ...intent, retryCheckpoint },
1210
1262
  runSignal,
1211
1263
  onCommit,
1212
1264
  (id) => {
@@ -1221,10 +1273,19 @@ var PiDaemonClient = class {
1221
1273
  (owner, job, recoverySignal) => this.recoverDirectionalOwner(owner, job, recoverySignal, assertRoot),
1222
1274
  () => {
1223
1275
  this.cleanupRequired = true;
1276
+ },
1277
+ pull && {
1278
+ pending: adoptionRecovery?.pending,
1279
+ retain: (pending) => {
1280
+ this.adoptionRecovery = pending && {
1281
+ pending,
1282
+ review: { setupName: pull.setup, fingerprint: pull.fingerprint },
1283
+ assertRoot
1284
+ };
1285
+ }
1224
1286
  }
1225
1287
  ) : await connection.run(operation, payload, runSignal, onCommit, diagnostics?.onSubmit);
1226
- if (runSignal.aborted || reload?.signal.aborted) diagnostics?.rejected(void 0, true);
1227
- else diagnostics?.returned(result);
1288
+ diagnostics?.returned(result, runSignal.aborted || reload?.signal.aborted);
1228
1289
  if (request?.received && reload && !this.paused && !reload.signal.aborted && !signal?.aborted) {
1229
1290
  this.validate();
1230
1291
  this.pendingReload = reload;
@@ -1353,7 +1414,7 @@ var PiDaemonClient = class {
1353
1414
  this.validate();
1354
1415
  if (!ctx.hasUI || !["tui", "rpc"].includes(ctx.mode)) throw new Error("This client cannot present safety reviews.");
1355
1416
  const { title, confirmationLabel, summaryLines } = callback.payload;
1356
- const { confirmMergeReview } = await import("./merge-review-AAC674C6.ts");
1417
+ const { confirmMergeReview } = await import("./merge-review-C2KETZKY.ts");
1357
1418
  if (!isCurrent()) return false;
1358
1419
  this.validate();
1359
1420
  const result = await confirmMergeReview(
@@ -1381,7 +1442,9 @@ var PiDaemonClient = class {
1381
1442
  if (this.paused) throw new Error("Pi session is changing; no new work is authorized.");
1382
1443
  if (callback.kind === "directional-checkpoint") {
1383
1444
  this.validateFactsScope(connection, this.runSignal);
1384
- return !protectionOnly && this.directionalCheckpoint?.accept(connection, callback.job, payload?.fingerprint) === true;
1445
+ if (protectionOnly || this.directionalCheckpoint?.accept(connection, callback.job, payload?.fingerprint) !== true)
1446
+ return false;
1447
+ return payload.adoptionRecovery === 1 ? { adoptionRecovery: 1 } : true;
1385
1448
  }
1386
1449
  if (callback.kind === "queue-acquire") {
1387
1450
  if (this.pendingReload) throw new Error("Pi resources are about to reload.");
@@ -1413,7 +1476,7 @@ var PiDaemonClient = class {
1413
1476
  if (!ctx.hasUI || !["tui", "rpc"].includes(ctx.mode)) throw new Error("This client cannot present safety reviews.");
1414
1477
  let result;
1415
1478
  if (callback.kind === "merge-review" && typeof payload.title === "string" && typeof payload.content === "string") {
1416
- const { confirmMergeReview } = await import("./merge-review-AAC674C6.ts");
1479
+ const { confirmMergeReview } = await import("./merge-review-C2KETZKY.ts");
1417
1480
  this.validate();
1418
1481
  combined.throwIfAborted();
1419
1482
  result = await confirmMergeReview(
@@ -1488,4 +1551,4 @@ export {
1488
1551
  withPiDaemonClient,
1489
1552
  remoteOperation
1490
1553
  };
1491
- //# sourceMappingURL=chunk-JQ5BAWW2.ts.map
1554
+ //# sourceMappingURL=chunk-C3E75DXW.ts.map