@narumitw/pi-sync 0.70.5 → 0.70.6

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 (67) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/chunks/{chunk-3XN4FR72.ts → chunk-4A34OGXY.ts} +9 -9
  3. package/dist/chunks/{chunk-7NQ7SFZK.ts → chunk-5BE6LBDC.ts} +15 -15
  4. package/dist/chunks/chunk-A43CJYG4.ts +26 -0
  5. package/dist/chunks/chunk-A43CJYG4.ts.map +7 -0
  6. package/dist/chunks/{chunk-JPTI4HFC.ts → chunk-AXN3B5KC.ts} +22 -22
  7. package/dist/chunks/{chunk-SPXEDJ2G.ts → chunk-KN4NY2VV.ts} +15 -42
  8. package/dist/chunks/chunk-KN4NY2VV.ts.map +7 -0
  9. package/dist/chunks/{chunk-N24HEZSA.ts → chunk-VERMBZGL.ts} +7 -7
  10. package/dist/chunks/{chunk-LSIUAXE4.ts → chunk-WE3KJ7JS.ts} +8 -8
  11. package/dist/chunks/{chunk-5T4ZOHYF.ts → chunk-WRS3SUNZ.ts} +4 -18
  12. package/dist/chunks/chunk-WRS3SUNZ.ts.map +7 -0
  13. package/dist/chunks/client-debug-F4WFP2YJ.ts +40 -0
  14. package/dist/chunks/client-debug-F4WFP2YJ.ts.map +7 -0
  15. package/dist/chunks/{command-handler-PT2KVTLD.ts → command-handler-GERC7LOE.ts} +34 -32
  16. package/dist/chunks/{command-handler-PT2KVTLD.ts.map → command-handler-GERC7LOE.ts.map} +1 -1
  17. package/dist/chunks/{conflict-review-QI77P7KL.ts → conflict-review-XZI7RYZX.ts} +3 -3
  18. package/dist/chunks/debug-tool-execution-7N4H6K3X.ts +67 -0
  19. package/dist/chunks/debug-tool-execution-7N4H6K3X.ts.map +7 -0
  20. package/dist/chunks/{diff-review-SOLP33TQ.ts → diff-review-FLWC5VOT.ts} +3 -3
  21. package/dist/chunks/{diff-review-ILRZDQ4S.ts → diff-review-GB4NO53B.ts} +4 -4
  22. package/dist/chunks/{file-selection-2H3J2HTX.ts → file-selection-DGC5UJVI.ts} +9 -9
  23. package/dist/chunks/{manager-result-dispatcher-75FS46JP.ts → manager-result-dispatcher-6MOJPLIS.ts} +7 -7
  24. package/dist/chunks/{manager-ui-HW3ZAEVK.ts → manager-ui-3CQU37XY.ts} +52 -50
  25. package/dist/chunks/{manager-ui-HW3ZAEVK.ts.map → manager-ui-3CQU37XY.ts.map} +1 -1
  26. package/dist/chunks/{remote-selection-ui-AE6FOEXH.ts → remote-selection-ui-2V53UBHM.ts} +6 -6
  27. package/dist/chunks/{setup-switch-LJPEZONY.ts → setup-switch-WSKVGW7L.ts} +4 -4
  28. package/dist/chunks/{setup-wizard-FBX7RTZ6.ts → setup-wizard-FRIR2EOR.ts} +9 -9
  29. package/dist/chunks/{sync-inspection-TZ4EMSBN.ts → sync-inspection-ECI4BY5N.ts} +6 -6
  30. package/dist/chunks/{sync-operations-QIQ3G66S.ts → sync-operations-KWXZZEPT.ts} +4 -4
  31. package/dist/chunks/sync-state-store-TZE7XDV5.ts +23 -0
  32. package/dist/chunks/sync-state-store-TZE7XDV5.ts.map +7 -0
  33. package/dist/daemon/dist/build-id.json +1 -1
  34. package/dist/daemon/dist/cli.js +3 -2
  35. package/dist/daemon/dist/client.js +55 -14
  36. package/dist/daemon/dist/daemon-startup.js +2 -14
  37. package/dist/daemon/dist/daemon-upgrade-error.js +14 -0
  38. package/dist/daemon/dist/index.js +20 -3
  39. package/dist/daemon/package.json +1 -1
  40. package/dist/index.ts +41 -83
  41. package/dist/index.ts.map +2 -2
  42. package/docs/daemon-migration.md +2 -0
  43. package/package.json +2 -2
  44. package/src/daemon/client-debug.ts +2 -0
  45. package/src/daemon/pi-client.ts +15 -7
  46. package/src/sync/automatic-sync.ts +3 -1
  47. package/src/sync/debug-tool-execution.ts +66 -0
  48. package/src/sync/debug-tool.ts +4 -51
  49. package/src/sync/startup-check.ts +3 -1
  50. package/src/sync-extension.ts +2 -1
  51. package/dist/chunks/chunk-5T4ZOHYF.ts.map +0 -7
  52. package/dist/chunks/chunk-SPXEDJ2G.ts.map +0 -7
  53. /package/dist/chunks/{chunk-3XN4FR72.ts.map → chunk-4A34OGXY.ts.map} +0 -0
  54. /package/dist/chunks/{chunk-7NQ7SFZK.ts.map → chunk-5BE6LBDC.ts.map} +0 -0
  55. /package/dist/chunks/{chunk-JPTI4HFC.ts.map → chunk-AXN3B5KC.ts.map} +0 -0
  56. /package/dist/chunks/{chunk-N24HEZSA.ts.map → chunk-VERMBZGL.ts.map} +0 -0
  57. /package/dist/chunks/{chunk-LSIUAXE4.ts.map → chunk-WE3KJ7JS.ts.map} +0 -0
  58. /package/dist/chunks/{conflict-review-QI77P7KL.ts.map → conflict-review-XZI7RYZX.ts.map} +0 -0
  59. /package/dist/chunks/{diff-review-SOLP33TQ.ts.map → diff-review-FLWC5VOT.ts.map} +0 -0
  60. /package/dist/chunks/{diff-review-ILRZDQ4S.ts.map → diff-review-GB4NO53B.ts.map} +0 -0
  61. /package/dist/chunks/{file-selection-2H3J2HTX.ts.map → file-selection-DGC5UJVI.ts.map} +0 -0
  62. /package/dist/chunks/{manager-result-dispatcher-75FS46JP.ts.map → manager-result-dispatcher-6MOJPLIS.ts.map} +0 -0
  63. /package/dist/chunks/{remote-selection-ui-AE6FOEXH.ts.map → remote-selection-ui-2V53UBHM.ts.map} +0 -0
  64. /package/dist/chunks/{setup-switch-LJPEZONY.ts.map → setup-switch-WSKVGW7L.ts.map} +0 -0
  65. /package/dist/chunks/{setup-wizard-FBX7RTZ6.ts.map → setup-wizard-FRIR2EOR.ts.map} +0 -0
  66. /package/dist/chunks/{sync-inspection-TZ4EMSBN.ts.map → sync-inspection-ECI4BY5N.ts.map} +0 -0
  67. /package/dist/chunks/{sync-operations-QIQ3G66S.ts.map → sync-operations-KWXZZEPT.ts.map} +0 -0
@@ -5,25 +5,25 @@ import {
5
5
  showGitSetup,
6
6
  showS3Setup,
7
7
  showWebDavSetup
8
- } from "./chunk-JPTI4HFC.ts";
8
+ } from "./chunk-AXN3B5KC.ts";
9
+ import "./chunk-HFMGK6A6.ts";
10
+ import {
11
+ localConfigPath
12
+ } from "./chunk-IBXEM35O.ts";
13
+ import "./chunk-NXWHPVXR.ts";
9
14
  import {
10
15
  validateConfigName
11
16
  } from "./chunk-APZVJAEW.ts";
12
17
  import "./chunk-R7PN3KIY.ts";
18
+ import "./chunk-GELYN4UC.ts";
13
19
  import {
14
20
  throwIfAborted
15
21
  } from "./chunk-UMPA5S7X.ts";
22
+ import "./chunk-R3SAMXB6.ts";
16
23
  import "./chunk-VQTYTUBU.ts";
17
- import "./chunk-HFMGK6A6.ts";
18
- import "./chunk-NXWHPVXR.ts";
19
- import "./chunk-GELYN4UC.ts";
20
- import {
21
- localConfigPath
22
- } from "./chunk-IBXEM35O.ts";
23
24
  import {
24
25
  errorMessage
25
26
  } from "./chunk-6YKOHBSC.ts";
26
- import "./chunk-R3SAMXB6.ts";
27
27
  import {
28
28
  safeTerminalText
29
29
  } from "./chunk-AMJRUXFT.ts";
@@ -89,4 +89,4 @@ async function showSetupWizard(ctx, signal) {
89
89
  export {
90
90
  showSetupWizard
91
91
  };
92
- //# sourceMappingURL=setup-wizard-FBX7RTZ6.ts.map
92
+ //# sourceMappingURL=setup-wizard-FRIR2EOR.ts.map
@@ -1,15 +1,15 @@
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
- syncCheckConfigFingerprint
5
- } from "./chunk-LNZRNXNQ.ts";
6
3
  import {
7
4
  currentPiDaemonClient
8
- } from "./chunk-SPXEDJ2G.ts";
5
+ } from "./chunk-KN4NY2VV.ts";
9
6
  import "./chunk-H7VOTY5N.ts";
10
- import "./chunk-6YKOHBSC.ts";
11
7
  import "./chunk-R3SAMXB6.ts";
8
+ import "./chunk-6YKOHBSC.ts";
12
9
  import "./chunk-AMJRUXFT.ts";
10
+ import {
11
+ syncCheckConfigFingerprint
12
+ } from "./chunk-LNZRNXNQ.ts";
13
13
 
14
14
  // src/sync/sync-inspection.ts
15
15
  var inspectSync = async (config, _options, signal) => await currentPiDaemonClient().run(
@@ -20,4 +20,4 @@ var inspectSync = async (config, _options, signal) => await currentPiDaemonClien
20
20
  export {
21
21
  inspectSync
22
22
  };
23
- //# sourceMappingURL=sync-inspection-TZ4EMSBN.ts.map
23
+ //# sourceMappingURL=sync-inspection-ECI4BY5N.ts.map
@@ -2,10 +2,10 @@
2
2
  // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
3
  import {
4
4
  remoteOperation
5
- } from "./chunk-SPXEDJ2G.ts";
5
+ } from "./chunk-KN4NY2VV.ts";
6
6
  import "./chunk-H7VOTY5N.ts";
7
- import "./chunk-6YKOHBSC.ts";
8
7
  import "./chunk-R3SAMXB6.ts";
8
+ import "./chunk-6YKOHBSC.ts";
9
9
  import "./chunk-AMJRUXFT.ts";
10
10
 
11
11
  // src/sync/sync-operations.ts
@@ -27,7 +27,7 @@ async function rollback(ctx, options) {
27
27
  function diff(ctx, options) {
28
28
  if (ctx.mode !== "tui" || !ctx.hasUI) return remoteOperation(ctx, "diff", options).then(() => {
29
29
  });
30
- return Promise.all([import("./diff-review-SOLP33TQ.ts"), import("./diff-review-ILRZDQ4S.ts")]).then(
30
+ return Promise.all([import("./diff-review-FLWC5VOT.ts"), import("./diff-review-GB4NO53B.ts")]).then(
31
31
  ([{ openDiffReview }, { showSyncDiffReview }]) => {
32
32
  options.signal?.throwIfAborted();
33
33
  return showSyncDiffReview(
@@ -49,4 +49,4 @@ export {
49
49
  rollback,
50
50
  syncBoth
51
51
  };
52
- //# sourceMappingURL=sync-operations-QIQ3G66S.ts.map
52
+ //# sourceMappingURL=sync-operations-KWXZZEPT.ts.map
@@ -0,0 +1,23 @@
1
+ // @generated by scripts/build-runtime.mjs; do not edit.
2
+ // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
+ import {
4
+ ensureStateDir,
5
+ lockPath,
6
+ readState,
7
+ readStateForConfig,
8
+ statePathForConfig,
9
+ syncStateFingerprint,
10
+ writeState,
11
+ writeStateForConfig
12
+ } from "./chunk-A43CJYG4.ts";
13
+ export {
14
+ ensureStateDir,
15
+ lockPath,
16
+ readState,
17
+ readStateForConfig,
18
+ statePathForConfig,
19
+ syncStateFingerprint,
20
+ writeState,
21
+ writeStateForConfig
22
+ };
23
+ //# sourceMappingURL=sync-state-store-TZE7XDV5.ts.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -1 +1 @@
1
- "83f08657a9031f4688ee5a922b53dee44e7c10809b27dfb65bf1ac91695a7315"
1
+ "00a2012761e53b860b9ac8d9ac0da8c64979559ed8e9e3ccf435913377445350"
@@ -3,8 +3,7 @@ import "./child-sdk.mjs";
3
3
  import { setTimeout as delay } from "node:timers/promises";
4
4
  import { DAEMON_BUILD_ID, DAEMON_BUILD_VERSION } from "./build-version.js";
5
5
  import { requestDaemon } from "./client-transport.js";
6
- import { DaemonUpgradeBlockedError, ensureDaemon, restartDaemon } from "./daemon-startup.js";
7
- import { inspectDaemonStatus } from "./daemon-status.js";
6
+ import { DaemonUpgradeBlockedError } from "./daemon-upgrade-error.js";
8
7
  import { privateDirectory, readIdentity, runtimePaths } from "./identity.js";
9
8
  import { openLifecycleLog } from "./lifecycle-log.js";
10
9
  async function retiredPolicyBlocker(root) {
@@ -112,11 +111,13 @@ export async function main(args) {
112
111
  return;
113
112
  }
114
113
  if (command === "start" || command === "restart") {
114
+ const { ensureDaemon, restartDaemon } = await import("./daemon-startup.js");
115
115
  const { identity } = await (command === "start" ? ensureDaemon(root) : restartDaemon(root));
116
116
  console.log(JSON.stringify({ running: true, root: identity.root, instance: identity.instance, pid: identity.pid }));
117
117
  return;
118
118
  }
119
119
  if (command === "status") {
120
+ const { inspectDaemonStatus } = await import("./daemon-status.js");
120
121
  const status = await inspectDaemonStatus(root);
121
122
  const retiredPolicy = await retiredPolicyBlocker(status.root);
122
123
  console.log(JSON.stringify({ ...status, ...(retiredPolicy ? { retiredPolicy } : {}) }));
@@ -1,13 +1,11 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
2
  import { setTimeout as delay } from "node:timers/promises";
3
3
  import { DaemonError, requestDaemon } from "./client-transport.js";
4
- import { stopDaemonAfterForegroundQueueFailure } from "./daemon-recovery.js";
5
4
  import { sameDiffReviewBinding } from "./diff-review-binding.js";
6
5
  import { DIFF_REVIEW_REQUEST_MS, isDiffReviewId, parseDiffReviewInventory, readDiffReviewPreview, } from "./diff-review-protocol.js";
7
6
  import { isForegroundDirection, isForegroundQueueOutcome } from "./foreground-queue-outcome.js";
8
7
  import { canonicalRootGuard, readProcessBirth } from "./identity.js";
9
8
  import { withCleanup } from "./lifecycle.js";
10
- import { presentPagedReview, reviewScope } from "./paged-review.js";
11
9
  import { MAX_REVIEW_BYTES, OWNERSHIP_CLEANUP_REQUIRED, operationPrefix, REVIEW_PAGE_CHARS, record, UNKNOWN_JOB_RESULT, } from "./protocol.js";
12
10
  import { STATE_WAIT_FAILURE_LIMIT, stateWaitJobs, stateWaitResult } from "./state-wait-jobs.js";
13
11
  export { DaemonError, hello, requestDaemon } from "./client-transport.js";
@@ -490,11 +488,13 @@ export class DaemonConnection {
490
488
  });
491
489
  }
492
490
  canRecoverForeground(job) {
491
+ return !this.foregroundRecovery?.attempted && this.ownsForegroundRecovery(job);
492
+ }
493
+ ownsForegroundRecovery(job) {
493
494
  const target = this.foregroundRecovery;
494
495
  return (!!target &&
495
496
  target.job === job &&
496
497
  target.generation === this.facts.generation &&
497
- !target.attempted &&
498
498
  this.attached &&
499
499
  !this.closed &&
500
500
  !this.admitting &&
@@ -511,8 +511,18 @@ export class DaemonConnection {
511
511
  throw new Error("The current Pi session could not verify a completed transfer for daemon recovery.");
512
512
  target.assertRoot();
513
513
  target.attempted = true;
514
+ const facts = { ...this.facts };
515
+ const lifecycle = this.lifecycleRevision;
514
516
  const owned = AbortSignal.any([signal, this.controller.signal, AbortSignal.timeout(FOREGROUND_RECOVERY_MS)]);
515
- await stopDaemonAfterForegroundQueueFailure(this.paths, this.identity, { ...target, client: this.facts.id }, owned);
517
+ const { stopDaemonAfterForegroundQueueFailure } = await import("./daemon-recovery.js");
518
+ owned.throwIfAborted();
519
+ if (lifecycle !== this.lifecycleRevision ||
520
+ !sameDiffReviewBinding(facts, this.facts) ||
521
+ this.foregroundRecovery !== target ||
522
+ !this.ownsForegroundRecovery(job))
523
+ throw new Error("The current Pi session could not verify a completed transfer for daemon recovery.");
524
+ target.assertRoot();
525
+ await stopDaemonAfterForegroundQueueFailure(this.paths, this.identity, { ...target, client: facts.id }, owned);
516
526
  await this.closeLocal();
517
527
  target.assertRoot();
518
528
  }
@@ -584,7 +594,9 @@ export class DaemonConnection {
584
594
  this.uncertain = true;
585
595
  const controller = new AbortController();
586
596
  const foreground = this.pendingJobs.has(callback.job);
587
- const reviewGeneration = callback.review?.offer !== undefined ? this.facts.generation : undefined;
597
+ const reviewOwner = callback.review?.offer !== undefined
598
+ ? { facts: { ...this.facts }, lifecycle: this.lifecycleRevision }
599
+ : undefined;
588
600
  this.callbacks.set(callback.id, {
589
601
  controller,
590
602
  kind: callback.kind,
@@ -597,7 +609,9 @@ export class DaemonConnection {
597
609
  try {
598
610
  if ((this.uncertain || this.resumeUncertain) && callback.kind !== "queue-release")
599
611
  throw new Error("Client is draining uncertain work.");
600
- value = await this.performCallback(callback, controller.signal);
612
+ value = await (reviewOwner
613
+ ? this.performExactReview(callback, controller.signal, reviewOwner)
614
+ : this.performCallback(callback, controller.signal));
601
615
  }
602
616
  catch {
603
617
  failed = true;
@@ -611,10 +625,10 @@ export class DaemonConnection {
611
625
  }
612
626
  try {
613
627
  await requestDaemon(this.paths, this.identity, "answer", {
614
- client: this.facts.id,
628
+ client: reviewOwner?.facts.id ?? this.facts.id,
615
629
  id: callback.id,
616
- ...(reviewGeneration !== undefined ? { generation: reviewGeneration } : {}),
617
- ...(failed || (reviewGeneration !== undefined && controller.signal.aborted)
630
+ ...(reviewOwner ? { generation: reviewOwner.facts.generation } : {}),
631
+ ...(failed || (reviewOwner && !this.ownsExactReview(callback, controller.signal, reviewOwner))
618
632
  ? { error: "Client callback cancelled or failed." }
619
633
  : { value }),
620
634
  }, this.callbackIO.signal);
@@ -702,15 +716,42 @@ export class DaemonConnection {
702
716
  this.reportRelease(callback, foreground, state);
703
717
  }
704
718
  }
719
+ ownsExactReview(callback, signal, owner) {
720
+ return (!signal.aborted &&
721
+ !this.callbackIO.signal.aborted &&
722
+ owner.lifecycle === this.lifecycleRevision &&
723
+ !this.closed &&
724
+ !this.pausing &&
725
+ !this.disposing &&
726
+ !this.uncertain &&
727
+ this.contactResumeState === "idle" &&
728
+ this.contactState !== "expired" &&
729
+ this.contactState !== "inactive" &&
730
+ this.callbacks.get(callback.id)?.controller.signal === signal &&
731
+ sameDiffReviewBinding(owner.facts, this.facts));
732
+ }
733
+ async performExactReview(callback, signal, owner) {
734
+ const present = this.options.mergeReview;
735
+ if (!present)
736
+ throw new Error("Exact review offer requires an opted-in presenter.");
737
+ const owned = AbortSignal.any([signal, this.callbackIO.signal]);
738
+ const requireCurrent = () => {
739
+ owned.throwIfAborted();
740
+ if (!this.ownsExactReview(callback, signal, owner))
741
+ throw new Error("Exact review participant changed.");
742
+ };
743
+ owned.throwIfAborted();
744
+ const { presentPagedReview, reviewScope } = await import("./paged-review.js");
745
+ requireCurrent();
746
+ return presentPagedReview(reviewScope(this.identity, owner.facts, callback), callback, owned, present, (params, pageSignal) => {
747
+ requireCurrent();
748
+ return requestDaemon(this.paths, this.identity, "review-page", params, pageSignal);
749
+ });
750
+ }
705
751
  async performCallback(callback, signal) {
706
752
  const reference = callback.review;
707
753
  if (!reference)
708
754
  return this.options.callback(callback, signal);
709
- if (reference.offer !== undefined) {
710
- if (!this.options.mergeReview)
711
- throw new Error("Exact review offer requires an opted-in presenter.");
712
- return presentPagedReview(reviewScope(this.identity, this.facts, callback), callback, AbortSignal.any([signal, this.callbackIO.signal]), this.options.mergeReview, (params, owned) => requestDaemon(this.paths, this.identity, "review-page", params, owned));
713
- }
714
755
  if (callback.kind !== "merge-review" ||
715
756
  !record(callback.payload) ||
716
757
  !Number.isSafeInteger(reference.pages) ||
@@ -6,22 +6,10 @@ import lockfile from "proper-lockfile";
6
6
  import { gt } from "semver";
7
7
  import { DAEMON_BUILD_ID, DAEMON_BUILD_VERSION, readInstalledDaemonBuild } from "./build-version.js";
8
8
  import { DaemonError, hello, requestDaemon } from "./client-transport.js";
9
+ import { DaemonUpgradeBlockedError, upgradeBlockers } from "./daemon-upgrade-error.js";
9
10
  import { canonicalRootGuard, clearUpgradeOwner, daemonPaths, privateDirectory, processExists, processExited, readIdentity, readProcessBirth, readUpgradeOwner, recordUpgradeOwner, runtimePaths, upgradeRepairStarted, } from "./identity.js";
10
11
  import { OWNERSHIP_CLEANUP_REQUIRED, record } from "./protocol.js";
11
- const upgradeBlockers = {
12
- busy: "Daemon update deferred while sync work is active. Let it finish, then use /reload or retry the daemon CLI.",
13
- repair: "Daemon update blocked by uncertain consent or queue cleanup. Follow the daemon recovery guide before retrying.",
14
- unattended: "Review or revoke unattended Pi Sync permission before stopping or replacing the daemon.",
15
- legacy: "This older daemon does not support guarded upgrades. Let sync work finish, run restart from the intended daemon CLI, then /reload.",
16
- };
17
- export class DaemonUpgradeBlockedError extends Error {
18
- instance;
19
- constructor(instance, reason) {
20
- super(upgradeBlockers[reason]);
21
- this.instance = instance;
22
- this.name = "DaemonUpgradeBlockedError";
23
- }
24
- }
12
+ export { DaemonUpgradeBlockedError } from "./daemon-upgrade-error.js";
25
13
  function matchesBuild(version, id) {
26
14
  return version === DAEMON_BUILD_VERSION && id === DAEMON_BUILD_ID;
27
15
  }
@@ -0,0 +1,14 @@
1
+ export const upgradeBlockers = {
2
+ busy: "Daemon update deferred while sync work is active. Let it finish, then use /reload or retry the daemon CLI.",
3
+ repair: "Daemon update blocked by uncertain consent or queue cleanup. Follow the daemon recovery guide before retrying.",
4
+ unattended: "Review or revoke unattended Pi Sync permission before stopping or replacing the daemon.",
5
+ legacy: "This older daemon does not support guarded upgrades. Let sync work finish, run restart from the intended daemon CLI, then /reload.",
6
+ };
7
+ export class DaemonUpgradeBlockedError extends Error {
8
+ instance;
9
+ constructor(instance, reason) {
10
+ super(upgradeBlockers[reason]);
11
+ this.instance = instance;
12
+ this.name = "DaemonUpgradeBlockedError";
13
+ }
14
+ }
@@ -1,10 +1,27 @@
1
1
  export { DaemonConnection, DaemonError, ensureDaemon, findDaemon, requestDaemon, stopDaemon, waitForDaemonExit, } from "./client.js";
2
- export { inspectDaemonRecovery, stopDaemonForRecovery, } from "./daemon-recovery.js";
3
- export { DaemonUpgradeBlockedError } from "./daemon-startup.js";
4
- export { inspectDaemonStatus } from "./daemon-status.js";
2
+ export { DaemonUpgradeBlockedError } from "./daemon-upgrade-error.js";
5
3
  export { parseDiffReviewInventory } from "./diff-review-protocol.js";
6
4
  export { documentFingerprint } from "./document.js";
7
5
  export { isDestinationConflict } from "./foreground-transfer.js";
8
6
  export { modelSignature } from "./model-signature.js";
9
7
  export { MAX_SETTINGS_BYTES, OWNERSHIP_CLEANUP_REQUIRED, PROTOCOL_VERSION } from "./protocol.js";
10
8
  export { createSessionPresence } from "./session-presence.js";
9
+ export async function inspectDaemonStatus(root, signal) {
10
+ signal?.throwIfAborted();
11
+ const { inspectDaemonStatus } = await import("./daemon-status.js");
12
+ signal?.throwIfAborted();
13
+ return inspectDaemonStatus(root, signal);
14
+ }
15
+ export async function inspectDaemonRecovery(root, signal) {
16
+ signal?.throwIfAborted();
17
+ const { inspectDaemonRecovery } = await import("./daemon-recovery.js");
18
+ signal?.throwIfAborted();
19
+ return inspectDaemonRecovery(root, signal);
20
+ }
21
+ export async function stopDaemonForRecovery(target, signal) {
22
+ signal?.throwIfAborted();
23
+ const reviewed = { ...target };
24
+ const { stopDaemonForRecovery } = await import("./daemon-recovery.js");
25
+ signal?.throwIfAborted();
26
+ return stopDaemonForRecovery(reviewed, signal);
27
+ }
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "0.16.4"
2
+ "version": "0.16.5"
3
3
  }
package/dist/index.ts CHANGED
@@ -1,53 +1,50 @@
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
- createSyncAttentionController,
5
- readStateForConfig,
6
- syncStateFingerprint
7
- } from "./chunks/chunk-5T4ZOHYF.ts";
8
- import {
9
- combineSignals,
10
- throwIfAborted
11
- } from "./chunks/chunk-UMPA5S7X.ts";
12
- import {
13
- completeSyncArguments,
14
- retiredSyncCommandGuidance,
15
- setSyncSetupCompletions,
16
- splitArgs
17
- } from "./chunks/chunk-VQTYTUBU.ts";
18
- import {
19
- withStateDirectoryAccess
20
- } from "./chunks/chunk-T3LABNHF.ts";
21
3
  import {
22
4
  snapshotOptionsForContext
23
5
  } from "./chunks/chunk-P4GI7LTT.ts";
24
- import "./chunks/chunk-ZO52JM4H.ts";
25
- import {
26
- configFromSettings,
27
- loadConfigForCheck,
28
- syncCheckConfigFingerprint,
29
- syncConfigReviewFingerprint
30
- } from "./chunks/chunk-LNZRNXNQ.ts";
31
6
  import {
32
7
  bindPiDaemonClient,
33
8
  installPiDaemonHost,
34
9
  piDaemonClient,
35
10
  withPiDaemonClient
36
- } from "./chunks/chunk-SPXEDJ2G.ts";
11
+ } from "./chunks/chunk-KN4NY2VV.ts";
12
+ import {
13
+ createSyncAttentionController
14
+ } from "./chunks/chunk-WRS3SUNZ.ts";
15
+ import "./chunks/chunk-ZO52JM4H.ts";
37
16
  import {
38
17
  configureSyncStatus,
39
18
  createSyncStatusPublisher,
40
19
  setSyncStatus
41
20
  } from "./chunks/chunk-H7VOTY5N.ts";
42
21
  import {
43
- errorMessage
44
- } from "./chunks/chunk-6YKOHBSC.ts";
22
+ combineSignals,
23
+ throwIfAborted
24
+ } from "./chunks/chunk-UMPA5S7X.ts";
45
25
  import {
46
26
  syncSessionsSelected
47
27
  } from "./chunks/chunk-R3SAMXB6.ts";
28
+ import {
29
+ completeSyncArguments,
30
+ retiredSyncCommandGuidance,
31
+ setSyncSetupCompletions,
32
+ splitArgs
33
+ } from "./chunks/chunk-VQTYTUBU.ts";
34
+ import {
35
+ errorMessage
36
+ } from "./chunks/chunk-6YKOHBSC.ts";
48
37
  import {
49
38
  safeTerminalText
50
39
  } from "./chunks/chunk-AMJRUXFT.ts";
40
+ import {
41
+ withStateDirectoryAccess
42
+ } from "./chunks/chunk-T3LABNHF.ts";
43
+ import {
44
+ configFromSettings,
45
+ loadConfigForCheck,
46
+ syncCheckConfigFingerprint
47
+ } from "./chunks/chunk-LNZRNXNQ.ts";
51
48
 
52
49
  // src/daemon/session-presence.ts
53
50
  import { createSessionPresence } from "#pi-sync-daemon";
@@ -130,7 +127,9 @@ async function startSession(ctx, signal, publish) {
130
127
  client.validate();
131
128
  throwIfAborted(signal);
132
129
  const debug = settings?.debug ?? false;
133
- client.setDebugPreference(debug);
130
+ await client.setDebugPreference(debug);
131
+ client.validate();
132
+ throwIfAborted(signal);
134
133
  configureSyncStatus(ctx, settings?.showStatus ?? true);
135
134
  const { stateDirectoryMigrationNotice } = await import("./chunks/state-directory-CMAIF34J.ts");
136
135
  client.validate();
@@ -219,14 +218,8 @@ async function autoPushSessions(ctx, signal, _loaders) {
219
218
 
220
219
  // src/sync/debug-tool.ts
221
220
  import { StringEnum } from "@earendil-works/pi-ai";
222
- import { debugCheckFailure, summarizeDebugInspection } from "#pi-sync-daemon/engine/debug-check";
223
- import { readLatestDebugCheck } from "#pi-sync-daemon/engine/debug-log";
224
221
  import { Type } from "typebox";
225
222
  var TOOL_NAME = "pi_sync_debug";
226
- var RECHECK_TIMEOUT_MS = 3e4;
227
- function toolResult(value) {
228
- return { content: [{ type: "text", text: JSON.stringify(value) }], details: {} };
229
- }
230
223
  function registerPiSyncDebug(pi, getOwner) {
231
224
  pi.registerTool({
232
225
  name: TOOL_NAME,
@@ -251,52 +244,13 @@ function registerPiSyncDebug(pi, getOwner) {
251
244
  throw new Error("The Pi Sync debug session is no longer available.");
252
245
  }
253
246
  };
254
- async function readSetup() {
255
- validate();
256
- try {
257
- const { settings } = await client.readStartupSettings(signal);
258
- validate();
259
- if (settings) return configFromSettings(settings);
260
- } catch {
261
- validate();
262
- }
263
- throw new Error("The current Pi Sync setup is not available. Review /sync \u2192 Settings.");
264
- }
265
- const setup = await readSetup();
266
247
  validate();
267
- if (action === "latest") {
268
- const last = readLatestDebugCheck(client.root, syncConfigReviewFingerprint(setup));
269
- if (last.kind === "unavailable") throw new Error("The private Pi Sync debug log is unavailable.");
270
- if (last.kind === "no-record") return toolResult({ kind: "no-record" });
271
- return toolResult({ kind: "historical", ...last.check });
272
- }
273
- if (action !== "recheck") throw new Error("Choose latest or recheck.");
274
- if (client.ownershipCleanupRequired) throw new Error("Pi Sync needs recovery. Open /sync daemon status.");
275
- const fingerprint = syncCheckConfigFingerprint(setup);
276
- const deadline = AbortSignal.timeout(RECHECK_TIMEOUT_MS);
277
- const recheckSignal = AbortSignal.any([signal, deadline]);
278
- let result;
279
- try {
280
- result = await client.run(
281
- "inspect",
282
- { setup: setup.setupName, fingerprint, origin: "recheck" },
283
- recheckSignal,
284
- ctx
285
- );
286
- } catch (error) {
248
+ const { executeDebugTool } = await import("./chunks/debug-tool-execution-7N4H6K3X.ts").catch(() => {
287
249
  validate();
288
- const { reason } = debugCheckFailure(deadline.aborted ? deadline.reason : error);
289
- throw new Error(`Pi Sync recheck failed: ${reason}.`);
290
- }
291
- validate();
292
- if (deadline.aborted) throw new Error("Pi Sync recheck failed: timeout.");
293
- const latest = await readSetup();
250
+ throw new Error("Pi Sync debug could not load.");
251
+ });
294
252
  validate();
295
- if (fingerprint !== syncCheckConfigFingerprint(latest))
296
- throw new Error("Pi Sync setup changed during recheck. Ask to recheck the new setup.");
297
- const summary = summarizeDebugInspection(result);
298
- if (!summary) throw new Error("Pi Sync did not return a valid check result.");
299
- return toolResult({ kind: "fresh", time: (/* @__PURE__ */ new Date()).toISOString(), origin: "recheck", summary });
253
+ return executeDebugTool(action, ctx, client, signal, validate);
300
254
  }
301
255
  });
302
256
  return (enabled) => {
@@ -370,6 +324,9 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4, publish) {
370
324
  () => inspectSync(captured, snapshotOptionsForContext(ctx, captured), signal, void 0, timings)
371
325
  );
372
326
  throwIfAborted(signal);
327
+ const { readStateForConfig, syncStateFingerprint } = await import("./chunks/sync-state-store-TZE7XDV5.ts");
328
+ throwIfAborted(signal);
329
+ if (!isCurrent()) return;
373
330
  const latest = await loadConfigForCheck(void 0, signal);
374
331
  throwIfAborted(signal);
375
332
  if (syncCheckConfigFingerprint(latest) !== identity) return;
@@ -480,12 +437,12 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4, publish) {
480
437
  // src/sync/sync-loaders.ts
481
438
  function createSyncLoaders(dependencies) {
482
439
  const loaders = {
483
- commands: cachedModuleLoader(dependencies.loadCommandHandler ?? (() => import("./chunks/command-handler-PT2KVTLD.ts"))),
484
- inspection: cachedModuleLoader(dependencies.loadSyncInspection ?? (() => import("./chunks/sync-inspection-TZ4EMSBN.ts"))),
485
- setupSwitch: cachedModuleLoader(dependencies.loadSetupSwitch ?? (() => import("./chunks/setup-switch-LJPEZONY.ts"))),
440
+ commands: cachedModuleLoader(dependencies.loadCommandHandler ?? (() => import("./chunks/command-handler-GERC7LOE.ts"))),
441
+ inspection: cachedModuleLoader(dependencies.loadSyncInspection ?? (() => import("./chunks/sync-inspection-ECI4BY5N.ts"))),
442
+ setupSwitch: cachedModuleLoader(dependencies.loadSetupSwitch ?? (() => import("./chunks/setup-switch-WSKVGW7L.ts"))),
486
443
  snapshot: cachedModuleLoader(dependencies.loadSnapshot ?? (() => import("./chunks/snapshot-ZUJJZCFW.ts"))),
487
444
  syncState: cachedModuleLoader(dependencies.loadSyncState ?? (() => import("./chunks/sync-state-QIT64TKV.ts"))),
488
- operations: cachedModuleLoader(dependencies.loadSyncOperations ?? (() => import("./chunks/sync-operations-QIQ3G66S.ts")))
445
+ operations: cachedModuleLoader(dependencies.loadSyncOperations ?? (() => import("./chunks/sync-operations-KWXZZEPT.ts")))
489
446
  };
490
447
  return loaders;
491
448
  }
@@ -793,7 +750,8 @@ function sync(pi, dependencies = {}) {
793
750
  if (signal.aborted || owner !== client) return;
794
751
  if (reason !== "reload") {
795
752
  shutdownClient = bindPiDaemonClient(ctx, signal, publishTimings);
796
- shutdownClient.setDebugPreference(client.debugEnabled);
753
+ await shutdownClient.setDebugPreference(client.debugEnabled);
754
+ if (signal.aborted || owner !== client) return;
797
755
  await shutdownClient.setBusy("shutdown", true);
798
756
  const attached = await shutdownClient.attachExisting();
799
757
  if (!signal.aborted && owner === client && attached)