@narumitw/pi-sync 0.58.1 → 0.60.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.
- package/CHANGELOG.md +21 -0
- package/README.md +28 -15
- package/dist/chunks/{chunk-AMJRUXFT.ts → chunk-2JNFEZ3V.ts} +2 -6
- package/dist/chunks/{chunk-AMJRUXFT.ts.map → chunk-2JNFEZ3V.ts.map} +1 -1
- package/dist/chunks/{chunk-MG66XM5U.ts → chunk-4RNCZZY7.ts} +86 -36
- package/dist/chunks/chunk-4RNCZZY7.ts.map +7 -0
- package/dist/chunks/{config-HYG7G5EM.ts → chunk-7AC2RX4M.ts} +6 -12
- package/dist/chunks/chunk-7AC2RX4M.ts.map +7 -0
- package/dist/chunks/{chunk-XEODG2PE.ts → chunk-BGGKHHO4.ts} +18 -14
- package/dist/chunks/{chunk-XEODG2PE.ts.map → chunk-BGGKHHO4.ts.map} +1 -1
- package/dist/chunks/chunk-BWWTOQOW.ts +737 -0
- package/dist/chunks/chunk-BWWTOQOW.ts.map +7 -0
- package/dist/chunks/chunk-CEMFCWIU.ts +20 -0
- package/dist/chunks/chunk-CEMFCWIU.ts.map +7 -0
- package/dist/chunks/chunk-CZNBKIM5.ts +20 -0
- package/dist/chunks/chunk-CZNBKIM5.ts.map +7 -0
- package/dist/chunks/{chunk-YIPK23JW.ts → chunk-ENFHHB5O.ts} +1 -16
- package/dist/chunks/{chunk-YIPK23JW.ts.map → chunk-ENFHHB5O.ts.map} +1 -1
- package/dist/chunks/{chunk-KHBPED6W.ts → chunk-GSQGBVKG.ts} +2 -2
- package/dist/chunks/chunk-HNKLBM3U.ts +18 -0
- package/dist/chunks/chunk-HNKLBM3U.ts.map +7 -0
- package/dist/chunks/{chunk-QPC5HT3A.ts → chunk-J5COV5TY.ts} +21 -2
- package/dist/chunks/chunk-J5COV5TY.ts.map +7 -0
- package/dist/chunks/chunk-JKBUYCPC.ts +52 -0
- package/dist/chunks/chunk-JKBUYCPC.ts.map +7 -0
- package/dist/chunks/chunk-JZKCOM62.ts +26 -0
- package/dist/chunks/chunk-JZKCOM62.ts.map +7 -0
- package/dist/chunks/chunk-M7RHV3H6.ts +33 -0
- package/dist/chunks/chunk-M7RHV3H6.ts.map +7 -0
- package/dist/chunks/{chunk-REMGB255.ts → chunk-MIXZVHFR.ts} +35 -10
- package/dist/chunks/chunk-MIXZVHFR.ts.map +7 -0
- package/dist/chunks/chunk-NPT2G4FU.ts +15 -0
- package/dist/chunks/chunk-NPT2G4FU.ts.map +7 -0
- package/dist/chunks/chunk-PDBTD2K6.ts +11 -0
- package/dist/chunks/chunk-PDBTD2K6.ts.map +7 -0
- package/dist/chunks/chunk-UBE6XWOM.ts +29 -0
- package/dist/chunks/chunk-UBE6XWOM.ts.map +7 -0
- package/dist/chunks/{chunk-JYILGR3K.ts → chunk-UZUUUY7C.ts} +8 -8
- package/dist/chunks/chunk-VZCWYXRS.ts +23 -0
- package/dist/chunks/chunk-VZCWYXRS.ts.map +7 -0
- package/dist/chunks/{chunk-U6GXGY5G.ts → chunk-YWEYRRQI.ts} +45 -37
- package/dist/chunks/chunk-YWEYRRQI.ts.map +7 -0
- package/dist/chunks/{chunk-ECYCNZOE.ts → chunk-ZMNVNECV.ts} +5 -1
- package/dist/chunks/chunk-ZMNVNECV.ts.map +7 -0
- package/dist/chunks/{command-handler-MRXE5AKK.ts → command-handler-3O76V7Q5.ts} +83 -87
- package/dist/chunks/command-handler-3O76V7Q5.ts.map +7 -0
- package/dist/chunks/conflict-review-XBSME2ER.ts +18 -0
- package/dist/chunks/conflict-review-XBSME2ER.ts.map +7 -0
- package/dist/chunks/{continuous-record-EPHGR2DU.ts → continuous-record-ZHUXVO4E.ts} +5 -13
- package/dist/chunks/continuous-record-ZHUXVO4E.ts.map +7 -0
- package/dist/chunks/{file-selection-IELTXSGZ.ts → file-selection-S6CNNNQI.ts} +14 -14
- package/dist/chunks/file-selection-S6CNNNQI.ts.map +7 -0
- package/dist/chunks/manager-result-dispatcher-I2AMCCE7.ts +18 -0
- package/dist/chunks/{manager-ui-AY34N4UY.ts → manager-ui-SJOBTJLY.ts} +221 -147
- package/dist/chunks/manager-ui-SJOBTJLY.ts.map +7 -0
- package/dist/chunks/merge-review-SGDLMVS4.ts +10 -0
- package/dist/chunks/remote-selection-ui-GZHPDQ4L.ts +17 -0
- package/dist/chunks/{setup-switch-KLGESLQX.ts → setup-switch-M3BAFGJM.ts} +9 -12
- package/dist/chunks/{setup-wizard-ZQAK35BP.ts → setup-wizard-NFAWP4KF.ts} +18 -20
- package/dist/chunks/{setup-wizard-ZQAK35BP.ts.map → setup-wizard-NFAWP4KF.ts.map} +1 -1
- package/dist/chunks/{snapshot-RGNDYT6A.ts → snapshot-D4SFDP5J.ts} +8 -12
- package/dist/chunks/snapshot-D4SFDP5J.ts.map +7 -0
- package/dist/chunks/snapshot-transaction-directory-TNKBQ3UQ.ts +13 -0
- package/dist/chunks/snapshot-transaction-directory-TNKBQ3UQ.ts.map +7 -0
- package/dist/chunks/state-directory-JZSZVVPX.ts +17 -0
- package/dist/chunks/sync-inspection-BJ4KPPNO.ts +23 -0
- package/dist/chunks/sync-inspection-BJ4KPPNO.ts.map +7 -0
- package/dist/chunks/sync-operations-TLWER2TT.ts +45 -0
- package/dist/chunks/sync-operations-TLWER2TT.ts.map +7 -0
- package/dist/chunks/{sync-state-7L4NT7W2.ts → sync-state-FVCJJ7MY.ts} +5 -10
- package/dist/chunks/sync-state-FVCJJ7MY.ts.map +7 -0
- package/dist/index.ts +269 -306
- package/dist/index.ts.map +4 -4
- package/docs/daemon-migration.md +93 -0
- package/docs/exclude-policy-audit.md +54 -0
- package/docs/exclude-review-ledger.md +36 -0
- package/docs/tui-contract.md +1 -1
- package/package.json +3 -5
- package/skills/configure-pi-sync/SKILL.md +5 -4
- package/skills/configure-pi-sync/references/configuration.md +91 -19
- package/src/backends/backend-factory.ts +2 -23
- package/src/backends/backend-identity.ts +5 -40
- package/src/backends/backend-types.ts +1 -81
- package/src/backends/git/git-backend.ts +6 -784
- package/src/backends/git/git-config.ts +8 -130
- package/src/backends/git/git-runner.ts +7 -255
- package/src/backends/git/git-storage.ts +14 -292
- package/src/backends/s3/s3-backend.ts +11 -523
- package/src/backends/s3/s3-client.ts +2 -399
- package/src/backends/s3/s3-conditions.ts +2 -67
- package/src/backends/snapshot-pointer.ts +2 -27
- package/src/backends/sync-backend.ts +6 -101
- package/src/backends/webdav/webdav-backend.ts +10 -622
- package/src/backends/webdav/webdav-client.ts +6 -370
- package/src/backends/webdav/webdav-config.ts +8 -82
- package/src/commands/command-execution.ts +42 -38
- package/src/commands/command.ts +23 -1
- package/src/daemon/apply-gate.ts +146 -0
- package/src/daemon/pi-client.ts +591 -0
- package/src/daemon/recovery.ts +103 -0
- package/src/paths.ts +12 -83
- package/src/settings/config-errors.ts +2 -6
- package/src/settings/config-file.ts +19 -693
- package/src/settings/config.ts +16 -257
- package/src/settings/settings-management.ts +11 -253
- package/src/settings/settings-store.ts +10 -48
- package/src/settings/settings-types.ts +1 -154
- package/src/settings/settings-validation.ts +17 -431
- package/src/snapshot/session-paths.ts +11 -110
- package/src/snapshot/snapshot-apply.ts +9 -306
- package/src/snapshot/snapshot-case-replacement.ts +6 -80
- package/src/snapshot/snapshot-codec.ts +2 -50
- package/src/snapshot/snapshot-exclude-safety.ts +2 -0
- package/src/snapshot/snapshot-mutation-queues.ts +6 -142
- package/src/snapshot/snapshot-paths.ts +2 -11
- package/src/snapshot/snapshot-root-transition.ts +6 -154
- package/src/snapshot/snapshot-transaction-directory.ts +5 -16
- package/src/snapshot/snapshot-transaction-plan.ts +2 -72
- package/src/snapshot/snapshot-transaction.ts +6 -934
- package/src/snapshot/snapshot-types.ts +1 -43
- package/src/snapshot/snapshot.ts +18 -405
- package/src/state/json-file.ts +2 -47
- package/src/state/lock-policy.ts +2 -2
- package/src/state/lock.ts +10 -292
- package/src/state/lockfile-fs.ts +2 -25
- package/src/state/merge-baseline-store.ts +8 -200
- package/src/state/mutation-directory-sync.ts +2 -34
- package/src/state/operation-availability.ts +7 -59
- package/src/state/state-directory.ts +8 -243
- package/src/state/state-types.ts +1 -24
- package/src/state/sync-state-store.ts +11 -75
- package/src/sync/agent-candidate.ts +7 -256
- package/src/sync/agent-plan.ts +2 -107
- package/src/sync/agent-policy.ts +10 -13
- package/src/sync/agent-refusal-retry.ts +2 -54
- package/src/sync/agent-request.ts +2 -19
- package/src/sync/agent-runner.ts +2 -191
- package/src/sync/agent-store.ts +7 -182
- package/src/sync/agent-sync.ts +2 -141
- package/src/sync/apply-review.ts +2 -63
- package/src/sync/automatic-sync.ts +55 -106
- package/src/sync/conflict-artifact-ownership.ts +2 -63
- package/src/sync/conflict-artifacts.ts +8 -195
- package/src/sync/conflict-groups.ts +2 -68
- package/src/sync/conflict-preview.ts +2 -56
- package/src/sync/conflict-resolution.ts +2 -93
- package/src/sync/conflict-retention.ts +2 -72
- package/src/sync/conflict-review.ts +3 -92
- package/src/sync/content-conflicts.ts +2 -73
- package/src/sync/continuous-errors.ts +7 -85
- package/src/sync/continuous-lease.ts +2 -216
- package/src/sync/continuous-record.ts +10 -261
- package/src/sync/continuous-storage.ts +12 -64
- package/src/sync/continuous-sync.ts +2 -563
- package/src/sync/continuous-watch.ts +2 -59
- package/src/sync/exclude-policy.ts +6 -0
- package/src/sync/field-migration.ts +2 -39
- package/src/sync/file-merge-planner.ts +2 -143
- package/src/sync/json-document.ts +7 -184
- package/src/sync/local-field-policy.ts +2 -29
- package/src/sync/local-fields.ts +9 -108
- package/src/sync/merge-apply.ts +2 -434
- package/src/sync/merge-journal.ts +10 -219
- package/src/sync/merge-transfer-error.ts +2 -72
- package/src/sync/merged-sync.ts +2 -914
- package/src/sync/mutation-owner.ts +2 -22
- package/src/sync/package-merge.ts +2 -87
- package/src/sync/partial-progress.ts +2 -54
- package/src/sync/remote-snapshot.ts +7 -80
- package/src/sync/session-merge.ts +2 -194
- package/src/sync/settings-conflicts.ts +2 -64
- package/src/sync/settings-merge.ts +6 -121
- package/src/sync/signals.ts +2 -8
- package/src/sync/startup-check.ts +15 -31
- package/src/sync/startup-timings.ts +2 -94
- package/src/sync/sync-decision.ts +3 -101
- package/src/sync/sync-error-guidance.ts +2 -46
- package/src/sync/sync-errors.ts +7 -23
- package/src/sync/sync-inspection.ts +10 -57
- package/src/sync/sync-local.ts +2 -44
- package/src/sync/sync-mutations.ts +10 -781
- package/src/sync/sync-operations.ts +32 -11
- package/src/sync/sync-policy.ts +34 -410
- package/src/sync/sync-queries.ts +2 -237
- package/src/sync/sync-state.ts +18 -151
- package/src/sync/text-merge.ts +10 -133
- package/src/sync-extension.ts +192 -142
- package/src/ui/excluded-paths-ui.ts +106 -0
- package/src/ui/file-selection.ts +6 -3
- package/src/ui/manager-state.ts +11 -5
- package/src/ui/remote-selection-ui.ts +73 -10
- package/src/ui/settings-ui.ts +20 -5
- package/src/ui/setup/setup-actions.ts +1 -1
- package/src/ui/setup/setup-switcher.ts +3 -2
- package/src/ui/storage-connections-ui.ts +2 -2
- package/src/ui/sync-attention.ts +17 -3
- package/src/ui/sync-format.ts +13 -1
- package/dist/chunks/agent-candidate-U2NU3GUX.ts +0 -29
- package/dist/chunks/agent-plan-3YXDIJXO.ts +0 -123
- package/dist/chunks/agent-plan-3YXDIJXO.ts.map +0 -7
- package/dist/chunks/agent-refusal-retry-476YGNU5.ts +0 -72
- package/dist/chunks/agent-refusal-retry-476YGNU5.ts.map +0 -7
- package/dist/chunks/agent-runner-FCRV2Z75.ts +0 -185
- package/dist/chunks/agent-runner-FCRV2Z75.ts.map +0 -7
- package/dist/chunks/agent-store-7GINKTS7.ts +0 -175
- package/dist/chunks/agent-store-7GINKTS7.ts.map +0 -7
- package/dist/chunks/agent-sync-2R4GG2MF.ts +0 -22
- package/dist/chunks/chunk-2JZFHNLM.ts +0 -113
- package/dist/chunks/chunk-2JZFHNLM.ts.map +0 -7
- package/dist/chunks/chunk-3ST7RSYN.ts +0 -21
- package/dist/chunks/chunk-3ST7RSYN.ts.map +0 -7
- package/dist/chunks/chunk-45COPAK7.ts +0 -205
- package/dist/chunks/chunk-45COPAK7.ts.map +0 -7
- package/dist/chunks/chunk-5SFMBY5P.ts +0 -26
- package/dist/chunks/chunk-5SFMBY5P.ts.map +0 -7
- package/dist/chunks/chunk-5TSCBBPP.ts +0 -229
- package/dist/chunks/chunk-5TSCBBPP.ts.map +0 -7
- package/dist/chunks/chunk-6LD5KX55.ts +0 -396
- package/dist/chunks/chunk-6LD5KX55.ts.map +0 -7
- package/dist/chunks/chunk-6O3EDBRL.ts +0 -258
- package/dist/chunks/chunk-6O3EDBRL.ts.map +0 -7
- package/dist/chunks/chunk-7A35ZAVO.ts +0 -1109
- package/dist/chunks/chunk-7A35ZAVO.ts.map +0 -7
- package/dist/chunks/chunk-7D5SF7P3.ts +0 -29
- package/dist/chunks/chunk-7D5SF7P3.ts.map +0 -7
- package/dist/chunks/chunk-7ZIYU5QS.ts +0 -64
- package/dist/chunks/chunk-7ZIYU5QS.ts.map +0 -7
- package/dist/chunks/chunk-AKMV47YC.ts +0 -215
- package/dist/chunks/chunk-AKMV47YC.ts.map +0 -7
- package/dist/chunks/chunk-AR2DGDUI.ts +0 -55
- package/dist/chunks/chunk-AR2DGDUI.ts.map +0 -7
- package/dist/chunks/chunk-BEST45H2.ts +0 -153
- package/dist/chunks/chunk-BEST45H2.ts.map +0 -7
- package/dist/chunks/chunk-CBLTWXAU.ts +0 -114
- package/dist/chunks/chunk-CBLTWXAU.ts.map +0 -7
- package/dist/chunks/chunk-CQD2TJHE.ts +0 -220
- package/dist/chunks/chunk-CQD2TJHE.ts.map +0 -7
- package/dist/chunks/chunk-DN4IA7MR.ts +0 -61
- package/dist/chunks/chunk-DN4IA7MR.ts.map +0 -7
- package/dist/chunks/chunk-DT7M4VQS.ts +0 -69
- package/dist/chunks/chunk-DT7M4VQS.ts.map +0 -7
- package/dist/chunks/chunk-ECYCNZOE.ts.map +0 -7
- package/dist/chunks/chunk-ESKOPQVB.ts +0 -348
- package/dist/chunks/chunk-ESKOPQVB.ts.map +0 -7
- package/dist/chunks/chunk-FHE2DCA2.ts +0 -61
- package/dist/chunks/chunk-FHE2DCA2.ts.map +0 -7
- package/dist/chunks/chunk-FLHCOJCD.ts +0 -57
- package/dist/chunks/chunk-FLHCOJCD.ts.map +0 -7
- package/dist/chunks/chunk-G4RUXRWZ.ts +0 -48
- package/dist/chunks/chunk-G4RUXRWZ.ts.map +0 -7
- package/dist/chunks/chunk-GNYGNHFF.ts +0 -27
- package/dist/chunks/chunk-GNYGNHFF.ts.map +0 -7
- package/dist/chunks/chunk-KYTT7KV4.ts +0 -319
- package/dist/chunks/chunk-KYTT7KV4.ts.map +0 -7
- package/dist/chunks/chunk-M6VQJIOU.ts +0 -54
- package/dist/chunks/chunk-M6VQJIOU.ts.map +0 -7
- package/dist/chunks/chunk-MG66XM5U.ts.map +0 -7
- package/dist/chunks/chunk-MKSMJPVA.ts +0 -107
- package/dist/chunks/chunk-MKSMJPVA.ts.map +0 -7
- package/dist/chunks/chunk-MMQIEDZ6.ts +0 -1994
- package/dist/chunks/chunk-MMQIEDZ6.ts.map +0 -7
- package/dist/chunks/chunk-OJARL2TG.ts +0 -25
- package/dist/chunks/chunk-OJARL2TG.ts.map +0 -7
- package/dist/chunks/chunk-OVBAW7KV.ts +0 -1174
- package/dist/chunks/chunk-OVBAW7KV.ts.map +0 -7
- package/dist/chunks/chunk-PRUEIIK7.ts +0 -24
- package/dist/chunks/chunk-PRUEIIK7.ts.map +0 -7
- package/dist/chunks/chunk-PWMWOJP4.ts +0 -17
- package/dist/chunks/chunk-PWMWOJP4.ts.map +0 -7
- package/dist/chunks/chunk-QPC5HT3A.ts.map +0 -7
- package/dist/chunks/chunk-REMGB255.ts.map +0 -7
- package/dist/chunks/chunk-S5OCYVPS.ts +0 -415
- package/dist/chunks/chunk-S5OCYVPS.ts.map +0 -7
- package/dist/chunks/chunk-SWRVXVFD.ts +0 -248
- package/dist/chunks/chunk-SWRVXVFD.ts.map +0 -7
- package/dist/chunks/chunk-T2SJD3N7.ts +0 -99
- package/dist/chunks/chunk-T2SJD3N7.ts.map +0 -7
- package/dist/chunks/chunk-TIMWN2RH.ts +0 -89
- package/dist/chunks/chunk-TIMWN2RH.ts.map +0 -7
- package/dist/chunks/chunk-TZC7GDJE.ts +0 -58
- package/dist/chunks/chunk-TZC7GDJE.ts.map +0 -7
- package/dist/chunks/chunk-U6GXGY5G.ts.map +0 -7
- package/dist/chunks/chunk-WQMYV4DW.ts +0 -140
- package/dist/chunks/chunk-WQMYV4DW.ts.map +0 -7
- package/dist/chunks/chunk-X7R6DCVF.ts +0 -28
- package/dist/chunks/chunk-X7R6DCVF.ts.map +0 -7
- package/dist/chunks/chunk-XJHQPB3E.ts +0 -107
- package/dist/chunks/chunk-XJHQPB3E.ts.map +0 -7
- package/dist/chunks/chunk-Y4UVXOLQ.ts +0 -123
- package/dist/chunks/chunk-Y4UVXOLQ.ts.map +0 -7
- package/dist/chunks/chunk-YDVQYUHE.ts +0 -34
- package/dist/chunks/chunk-YDVQYUHE.ts.map +0 -7
- package/dist/chunks/chunk-YHT4YTYG.ts +0 -31
- package/dist/chunks/chunk-YHT4YTYG.ts.map +0 -7
- package/dist/chunks/chunk-ZW5ZLGBI.ts +0 -154
- package/dist/chunks/chunk-ZW5ZLGBI.ts.map +0 -7
- package/dist/chunks/command-handler-MRXE5AKK.ts.map +0 -7
- package/dist/chunks/conflict-artifacts-J6WSDCWP.ts +0 -32
- package/dist/chunks/conflict-review-GXA6Y7KY.ts +0 -189
- package/dist/chunks/conflict-review-GXA6Y7KY.ts.map +0 -7
- package/dist/chunks/continuous-sync-FAFNLEUW.ts +0 -585
- package/dist/chunks/continuous-sync-FAFNLEUW.ts.map +0 -7
- package/dist/chunks/file-selection-IELTXSGZ.ts.map +0 -7
- package/dist/chunks/git-backend-KHD36W27.ts +0 -1077
- package/dist/chunks/git-backend-KHD36W27.ts.map +0 -7
- package/dist/chunks/local-fields-JEKAPZKD.ts +0 -26
- package/dist/chunks/local-fields-JEKAPZKD.ts.map +0 -7
- package/dist/chunks/manager-result-dispatcher-XCYPW7RC.ts +0 -32
- package/dist/chunks/manager-result-dispatcher-XCYPW7RC.ts.map +0 -7
- package/dist/chunks/manager-ui-AY34N4UY.ts.map +0 -7
- package/dist/chunks/merge-baseline-store-65GKUMXI.ts +0 -25
- package/dist/chunks/merge-baseline-store-65GKUMXI.ts.map +0 -7
- package/dist/chunks/remote-selection-ui-MYM2YCPF.ts +0 -31
- package/dist/chunks/remote-selection-ui-MYM2YCPF.ts.map +0 -7
- package/dist/chunks/s3-backend-L24UZ6IK.ts +0 -844
- package/dist/chunks/s3-backend-L24UZ6IK.ts.map +0 -7
- package/dist/chunks/setup-switch-KLGESLQX.ts.map +0 -7
- package/dist/chunks/snapshot-RGNDYT6A.ts.map +0 -7
- package/dist/chunks/snapshot-transaction-26BQO36S.ts +0 -24
- package/dist/chunks/snapshot-transaction-26BQO36S.ts.map +0 -7
- package/dist/chunks/sync-inspection-MOMLGUTD.ts +0 -25
- package/dist/chunks/sync-inspection-MOMLGUTD.ts.map +0 -7
- package/dist/chunks/sync-operations-45APGOL3.ts +0 -1021
- package/dist/chunks/sync-operations-45APGOL3.ts.map +0 -7
- package/dist/chunks/sync-state-7L4NT7W2.ts.map +0 -7
- package/dist/chunks/webdav-backend-3ZCACILP.ts +0 -851
- package/dist/chunks/webdav-backend-3ZCACILP.ts.map +0 -7
- /package/dist/chunks/{chunk-KHBPED6W.ts.map → chunk-GSQGBVKG.ts.map} +0 -0
- /package/dist/chunks/{chunk-JYILGR3K.ts.map → chunk-UZUUUY7C.ts.map} +0 -0
- /package/dist/chunks/{agent-candidate-U2NU3GUX.ts.map → manager-result-dispatcher-I2AMCCE7.ts.map} +0 -0
- /package/dist/chunks/{agent-sync-2R4GG2MF.ts.map → merge-review-SGDLMVS4.ts.map} +0 -0
- /package/dist/chunks/{config-HYG7G5EM.ts.map → remote-selection-ui-GZHPDQ4L.ts.map} +0 -0
- /package/dist/chunks/{conflict-artifacts-J6WSDCWP.ts.map → setup-switch-M3BAFGJM.ts.map} +0 -0
- /package/dist/chunks/{continuous-record-EPHGR2DU.ts.map → state-directory-JZSZVVPX.ts.map} +0 -0
package/dist/index.ts
CHANGED
|
@@ -1,175 +1,121 @@
|
|
|
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
3
|
import {
|
|
4
|
-
createSyncAttentionController
|
|
5
|
-
|
|
4
|
+
createSyncAttentionController,
|
|
5
|
+
readStateForConfig,
|
|
6
|
+
syncStateFingerprint
|
|
7
|
+
} from "./chunks/chunk-MIXZVHFR.ts";
|
|
8
|
+
import "./chunks/chunk-NPT2G4FU.ts";
|
|
6
9
|
import {
|
|
7
|
-
|
|
8
|
-
} from "./chunks/chunk-
|
|
10
|
+
withStateDirectoryAccess
|
|
11
|
+
} from "./chunks/chunk-CEMFCWIU.ts";
|
|
9
12
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
splitArgs
|
|
13
|
-
} from "./chunks/chunk-QPC5HT3A.ts";
|
|
13
|
+
snapshotOptionsForContext
|
|
14
|
+
} from "./chunks/chunk-CZNBKIM5.ts";
|
|
14
15
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
loadConfigForCheck,
|
|
17
|
+
syncCheckConfigFingerprint
|
|
18
|
+
} from "./chunks/chunk-7AC2RX4M.ts";
|
|
17
19
|
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
bindPiDaemonClient,
|
|
21
|
+
installPiDaemonHost,
|
|
22
|
+
piDaemonClient,
|
|
23
|
+
withPiDaemonClient
|
|
24
|
+
} from "./chunks/chunk-BWWTOQOW.ts";
|
|
20
25
|
import {
|
|
21
26
|
configureSyncStatus,
|
|
22
27
|
createSyncStatusPublisher,
|
|
23
28
|
setSyncStatus
|
|
24
|
-
} from "./chunks/chunk-
|
|
25
|
-
import {
|
|
26
|
-
errorMessage
|
|
27
|
-
} from "./chunks/chunk-7D5SF7P3.ts";
|
|
28
|
-
import {
|
|
29
|
-
consumeLocalConfigMigrationNotice,
|
|
30
|
-
loadConfig,
|
|
31
|
-
loadConfigForCheck,
|
|
32
|
-
loadPartialConfig,
|
|
33
|
-
readLocalConfigObject,
|
|
34
|
-
syncCheckConfigFingerprint
|
|
35
|
-
} from "./chunks/chunk-OVBAW7KV.ts";
|
|
36
|
-
import "./chunks/chunk-X7R6DCVF.ts";
|
|
37
|
-
import {
|
|
38
|
-
pendingTransactionEntries
|
|
39
|
-
} from "./chunks/chunk-5SFMBY5P.ts";
|
|
29
|
+
} from "./chunks/chunk-ENFHHB5O.ts";
|
|
40
30
|
import {
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
completeSyncArguments,
|
|
32
|
+
setSyncSetupCompletions,
|
|
33
|
+
splitArgs
|
|
34
|
+
} from "./chunks/chunk-J5COV5TY.ts";
|
|
43
35
|
import {
|
|
44
36
|
combineSignals,
|
|
45
37
|
throwIfAborted
|
|
46
|
-
} from "./chunks/chunk-
|
|
47
|
-
import {
|
|
48
|
-
ensureStateDir,
|
|
49
|
-
readStateForConfig,
|
|
50
|
-
syncStateFingerprint
|
|
51
|
-
} from "./chunks/chunk-DN4IA7MR.ts";
|
|
52
|
-
import "./chunks/chunk-AR2DGDUI.ts";
|
|
38
|
+
} from "./chunks/chunk-PDBTD2K6.ts";
|
|
53
39
|
import {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
} from "./chunks/chunk-SWRVXVFD.ts";
|
|
57
|
-
import "./chunks/chunk-2JZFHNLM.ts";
|
|
58
|
-
import "./chunks/chunk-T2SJD3N7.ts";
|
|
59
|
-
import "./chunks/chunk-KYTT7KV4.ts";
|
|
40
|
+
errorMessage
|
|
41
|
+
} from "./chunks/chunk-HNKLBM3U.ts";
|
|
60
42
|
import {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
43
|
+
safeTerminalText
|
|
44
|
+
} from "./chunks/chunk-2JNFEZ3V.ts";
|
|
45
|
+
import "./chunks/chunk-JKBUYCPC.ts";
|
|
46
|
+
|
|
47
|
+
// src/sync/agent-policy.ts
|
|
65
48
|
import {
|
|
49
|
+
AGENT_INPUT_BYTES,
|
|
50
|
+
AGENT_MAX_ATTEMPTS,
|
|
51
|
+
AGENT_MAX_TOKENS,
|
|
52
|
+
AGENT_MAX_UNITS,
|
|
53
|
+
AGENT_OUTPUT_BYTES,
|
|
54
|
+
AGENT_TIMEOUT_MS,
|
|
66
55
|
startupTransferEnabled
|
|
67
|
-
} from "
|
|
56
|
+
} from "@narumitw/sync-daemon/engine/sync/agent-policy";
|
|
68
57
|
|
|
69
58
|
// src/settings/config-errors.ts
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
import { isMissingConfigError } from "@narumitw/sync-daemon/engine/settings/config-errors";
|
|
60
|
+
|
|
61
|
+
// src/sync/startup-timings.ts
|
|
62
|
+
import { createStartupTimings } from "@narumitw/sync-daemon/engine/sync/startup-timings";
|
|
73
63
|
|
|
74
64
|
// src/sync/automatic-sync.ts
|
|
75
|
-
var AUTO_SYNC_OPTIONS = {
|
|
76
|
-
yes: true,
|
|
77
|
-
force: false,
|
|
78
|
-
stale: false,
|
|
79
|
-
silent: true,
|
|
80
|
-
reload: false,
|
|
81
|
-
auto: true,
|
|
82
|
-
args: []
|
|
83
|
-
};
|
|
84
65
|
async function startSession(ctx, signal, publish) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
throwIfAborted(signal);
|
|
90
|
-
const stateNotice = stateDirectoryMigrationNotice();
|
|
91
|
-
if (stateNotice && ctx.hasUI) ctx.ui.notify(stateNotice, "warning");
|
|
92
|
-
const validateMutation = captureMutationOwner(ctx, signal);
|
|
93
|
-
const currentFile = ctx.sessionManager.getSessionFile?.();
|
|
94
|
-
await timings.measure("transaction recovery", async () => {
|
|
95
|
-
const pending = await pendingTransactionEntries();
|
|
96
|
-
validateMutation();
|
|
97
|
-
if (!pending.some((entry) => entry.isDirectory())) return;
|
|
98
|
-
const { recoverSnapshotTransactionsOnStartup } = await import("./chunks/snapshot-transaction-26BQO36S.ts");
|
|
99
|
-
validateMutation();
|
|
100
|
-
await recoverSnapshotTransactionsOnStartup({
|
|
101
|
-
signal,
|
|
102
|
-
sessionDir: sessionDirFromContext(ctx),
|
|
103
|
-
protectedTargets: currentFile ? [currentFile] : [],
|
|
104
|
-
validateMutation
|
|
105
|
-
});
|
|
106
|
-
});
|
|
66
|
+
throwIfAborted(signal);
|
|
67
|
+
const client = piDaemonClient(ctx);
|
|
68
|
+
if (!ctx.hasUI || !["tui", "rpc"].includes(ctx.mode)) {
|
|
69
|
+
await client.attachExisting();
|
|
107
70
|
throwIfAborted(signal);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
throwIfAborted(signal);
|
|
126
|
-
configureSyncStatus(ctx, config.showStatus);
|
|
127
|
-
outcome = "completed";
|
|
128
|
-
return { debug, config };
|
|
129
|
-
} catch (error) {
|
|
130
|
-
throwIfAborted(signal);
|
|
131
|
-
if (!isMissingConfigError(error)) {
|
|
132
|
-
ctx.ui.notify(`pi-sync startup check skipped: ${safeTerminalText(errorMessage(error))}`, "warning");
|
|
133
|
-
}
|
|
134
|
-
}
|
|
71
|
+
return { debug: false };
|
|
72
|
+
}
|
|
73
|
+
const timings = createStartupTimings(publish);
|
|
74
|
+
const document = await timings.measure("settings read", () => client.readSettings());
|
|
75
|
+
throwIfAborted(signal);
|
|
76
|
+
configureSyncStatus(ctx, document?.parsed.showStatus ?? true);
|
|
77
|
+
const { stateDirectoryMigrationNotice } = await import("./chunks/state-directory-JZSZVVPX.ts");
|
|
78
|
+
const notice = stateDirectoryMigrationNotice();
|
|
79
|
+
const { pendingTransactionEntries } = await import("./chunks/snapshot-transaction-directory-TNKBQ3UQ.ts");
|
|
80
|
+
const recoveryNeeded = (await pendingTransactionEntries()).some((entry) => entry.isDirectory());
|
|
81
|
+
throwIfAborted(signal);
|
|
82
|
+
if (!await client.configured() && !recoveryNeeded) {
|
|
83
|
+
if (notice) ctx.ui.notify(notice, "warning");
|
|
84
|
+
setSyncSetupCompletions([]);
|
|
85
|
+
const debug = document?.parsed.debug === true;
|
|
86
|
+
await client.markReady(debug);
|
|
87
|
+
timings.publish(ctx, debug, signal, "local initialization", "completed");
|
|
135
88
|
return { debug };
|
|
136
|
-
} finally {
|
|
137
|
-
timings.publish(ctx, debug, signal, "local initialization", outcome);
|
|
138
89
|
}
|
|
90
|
+
throwIfAborted(signal);
|
|
91
|
+
const result = await client.run("initialize", {}, signal);
|
|
92
|
+
throwIfAborted(signal);
|
|
93
|
+
configureSyncStatus(ctx, result.settings?.showStatus ?? true);
|
|
94
|
+
setSyncSetupCompletions(Object.keys(result.settings?.syncSetups ?? {}).sort((a, b) => a.localeCompare(b)));
|
|
95
|
+
await client.markReady(result.debug);
|
|
96
|
+
throwIfAborted(signal);
|
|
97
|
+
if (result.handoverRequired) {
|
|
98
|
+
ctx.ui.notify(
|
|
99
|
+
"pi-sync: close or upgrade older Pi processes, then use /sync to review daemon handover. No automatic transfer is authorized yet.",
|
|
100
|
+
"warning"
|
|
101
|
+
);
|
|
102
|
+
return { debug: result.debug };
|
|
103
|
+
}
|
|
104
|
+
return { debug: result.debug, config: result.config };
|
|
139
105
|
}
|
|
140
|
-
async function autoPushSessions(ctx, signal,
|
|
106
|
+
async function autoPushSessions(ctx, signal, _loaders) {
|
|
141
107
|
try {
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
if (!partial.automatic) return;
|
|
145
|
-
if (!partial.include.includes("sessions")) return;
|
|
146
|
-
await ensureStateDir();
|
|
108
|
+
const client = piDaemonClient(ctx);
|
|
109
|
+
if (!await client.configured()) return;
|
|
147
110
|
throwIfAborted(signal);
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
loaders.snapshot(),
|
|
154
|
-
loaders.syncState()
|
|
155
|
-
]);
|
|
156
|
-
throwIfAborted(signal);
|
|
157
|
-
await withLock("auto-session-push", async () => {
|
|
158
|
-
throwIfAborted(signal);
|
|
159
|
-
const state = await readStateForConfig(config);
|
|
160
|
-
throwIfAborted(signal);
|
|
161
|
-
const local = await snapshotModule.createSnapshot(config.snapshotIdentity, {
|
|
162
|
-
...snapshotOptionsForContext(ctx, config),
|
|
163
|
-
signal
|
|
164
|
-
});
|
|
165
|
-
throwIfAborted(signal);
|
|
166
|
-
if (!syncStateModule.hasLocalChanges(local, state, config)) return;
|
|
167
|
-
await operations.push(ctx, { ...AUTO_SYNC_OPTIONS, signal }, { config, state, local });
|
|
168
|
-
});
|
|
111
|
+
await client.run(
|
|
112
|
+
"shutdown",
|
|
113
|
+
{ args: [], yes: true, force: false, stale: false, silent: true, reload: false },
|
|
114
|
+
signal
|
|
115
|
+
);
|
|
169
116
|
} catch (error) {
|
|
170
117
|
if (signal.aborted || isMissingConfigError(error)) return;
|
|
171
|
-
|
|
172
|
-
ctx.ui.notify(`pi-sync session push skipped: ${errorMessage(error)}`, "warning");
|
|
118
|
+
ctx.ui.notify(`pi-sync session push skipped: ${safeTerminalText(errorMessage(error))}`, "warning");
|
|
173
119
|
}
|
|
174
120
|
}
|
|
175
121
|
|
|
@@ -234,13 +180,7 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4, publish) {
|
|
|
234
180
|
if (syncCheckConfigFingerprint(currentConfig) !== identity) return;
|
|
235
181
|
const inspection = await timings.measure(
|
|
236
182
|
"inspection and guards",
|
|
237
|
-
() =>
|
|
238
|
-
throwIfAborted(signal);
|
|
239
|
-
return withLock("startup-check", () => {
|
|
240
|
-
throwIfAborted(signal);
|
|
241
|
-
return inspectSync(captured, snapshotOptionsForContext(ctx, captured), signal, void 0, timings);
|
|
242
|
-
});
|
|
243
|
-
})
|
|
183
|
+
() => inspectSync(captured, snapshotOptionsForContext(ctx, captured), signal, void 0, timings)
|
|
244
184
|
);
|
|
245
185
|
throwIfAborted(signal);
|
|
246
186
|
const latest = await loadConfigForCheck();
|
|
@@ -257,10 +197,7 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4, publish) {
|
|
|
257
197
|
automaticTransfer: startupTransferEnabled(captured)
|
|
258
198
|
});
|
|
259
199
|
if (startupTransferEnabled(captured) && !inspection.firstSync && inspection.head && inspection.selectionState?.kind === "same") {
|
|
260
|
-
const
|
|
261
|
-
"operations import",
|
|
262
|
-
() => Promise.all([loaders.operations(), import("./chunks/agent-sync-2R4GG2MF.ts")])
|
|
263
|
-
);
|
|
200
|
+
const operations = await timings.measure("operations import", () => loaders.operations());
|
|
264
201
|
throwIfAborted(signal);
|
|
265
202
|
if (!isCurrent()) return;
|
|
266
203
|
if (!ctx.isIdle()) {
|
|
@@ -269,24 +206,18 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4, publish) {
|
|
|
269
206
|
}
|
|
270
207
|
await timings.measure(
|
|
271
208
|
"automatic transfer",
|
|
272
|
-
() =>
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
startupTimings: timings,
|
|
285
|
-
onCommit: () => attention.clearObservation()
|
|
286
|
-
},
|
|
287
|
-
(options) => operations.syncBoth(ctx, options)
|
|
288
|
-
)
|
|
289
|
-
)
|
|
209
|
+
() => operations.syncBoth(ctx, {
|
|
210
|
+
args: [],
|
|
211
|
+
yes: true,
|
|
212
|
+
force: false,
|
|
213
|
+
stale: false,
|
|
214
|
+
silent: true,
|
|
215
|
+
reload: false,
|
|
216
|
+
auto: true,
|
|
217
|
+
signal,
|
|
218
|
+
startupTimings: timings,
|
|
219
|
+
onCommit: () => attention.clearObservation()
|
|
220
|
+
})
|
|
290
221
|
);
|
|
291
222
|
throwIfAborted(signal);
|
|
292
223
|
if (!isCurrent()) return;
|
|
@@ -358,12 +289,12 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4, publish) {
|
|
|
358
289
|
// src/sync/sync-loaders.ts
|
|
359
290
|
function createSyncLoaders(dependencies) {
|
|
360
291
|
const loaders = {
|
|
361
|
-
commands: cachedModuleLoader(dependencies.loadCommandHandler ?? (() => import("./chunks/command-handler-
|
|
362
|
-
inspection: cachedModuleLoader(dependencies.loadSyncInspection ?? (() => import("./chunks/sync-inspection-
|
|
363
|
-
setupSwitch: cachedModuleLoader(dependencies.loadSetupSwitch ?? (() => import("./chunks/setup-switch-
|
|
364
|
-
snapshot: cachedModuleLoader(dependencies.loadSnapshot ?? (() => import("./chunks/snapshot-
|
|
365
|
-
syncState: cachedModuleLoader(dependencies.loadSyncState ?? (() => import("./chunks/sync-state-
|
|
366
|
-
operations: cachedModuleLoader(dependencies.loadSyncOperations ?? (() => import("./chunks/sync-operations-
|
|
292
|
+
commands: cachedModuleLoader(dependencies.loadCommandHandler ?? (() => import("./chunks/command-handler-3O76V7Q5.ts"))),
|
|
293
|
+
inspection: cachedModuleLoader(dependencies.loadSyncInspection ?? (() => import("./chunks/sync-inspection-BJ4KPPNO.ts"))),
|
|
294
|
+
setupSwitch: cachedModuleLoader(dependencies.loadSetupSwitch ?? (() => import("./chunks/setup-switch-M3BAFGJM.ts"))),
|
|
295
|
+
snapshot: cachedModuleLoader(dependencies.loadSnapshot ?? (() => import("./chunks/snapshot-D4SFDP5J.ts"))),
|
|
296
|
+
syncState: cachedModuleLoader(dependencies.loadSyncState ?? (() => import("./chunks/sync-state-FVCJJ7MY.ts"))),
|
|
297
|
+
operations: cachedModuleLoader(dependencies.loadSyncOperations ?? (() => import("./chunks/sync-operations-TLWER2TT.ts")))
|
|
367
298
|
};
|
|
368
299
|
return loaders;
|
|
369
300
|
}
|
|
@@ -405,6 +336,7 @@ function registerStartupTimings(pi) {
|
|
|
405
336
|
|
|
406
337
|
// src/sync-extension.ts
|
|
407
338
|
function sync(pi, dependencies = {}) {
|
|
339
|
+
installPiDaemonHost();
|
|
408
340
|
const loaders = createSyncLoaders(dependencies);
|
|
409
341
|
const attention = createSyncAttentionController();
|
|
410
342
|
const status = createSyncStatusPublisher(pi.events);
|
|
@@ -413,173 +345,204 @@ function sync(pi, dependencies = {}) {
|
|
|
413
345
|
let sessionAbort = new AbortController();
|
|
414
346
|
let shutdownAbort;
|
|
415
347
|
let initialization = Promise.resolve(void 0);
|
|
416
|
-
let continuous;
|
|
417
348
|
let owner;
|
|
418
|
-
let
|
|
419
|
-
let startupDebug = false;
|
|
420
|
-
const foreground = /* @__PURE__ */ new Map();
|
|
421
|
-
async function resumeContinuous(ctx, signal, retry) {
|
|
422
|
-
const isCurrent = () => !signal.aborted && !foreground.has(ctx.sessionManager) && owner === ctx.sessionManager;
|
|
423
|
-
if (!isCurrent() || !ctx.hasUI) return;
|
|
424
|
-
try {
|
|
425
|
-
const { loadConfigForCheck: loadConfigForCheck2 } = await import("./chunks/config-HYG7G5EM.ts");
|
|
426
|
-
if (!isCurrent()) return;
|
|
427
|
-
const config = await loadConfigForCheck2();
|
|
428
|
-
if (!isCurrent()) return;
|
|
429
|
-
continuousPossible = Boolean(config.continuous && config.agentMode);
|
|
430
|
-
if (!continuousPossible) {
|
|
431
|
-
await continuous?.stop(ctx.sessionManager);
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
const { createContinuousSync } = await import("./chunks/continuous-sync-FAFNLEUW.ts");
|
|
435
|
-
if (!isCurrent()) return;
|
|
436
|
-
continuous ??= createContinuousSync(loaders, void 0, publishTimings);
|
|
437
|
-
continuous.start(
|
|
438
|
-
ctx,
|
|
439
|
-
signal,
|
|
440
|
-
Boolean(retry && (retry.setup === void 0 || retry.setup === config.setupName)),
|
|
441
|
-
startupDebug
|
|
442
|
-
);
|
|
443
|
-
} catch {
|
|
444
|
-
}
|
|
445
|
-
}
|
|
349
|
+
let ownerManager;
|
|
446
350
|
pi.registerCommand("sync", {
|
|
447
351
|
description: "Sync Pi settings through Git, WebDAV, R2, or S3-compatible storage",
|
|
448
352
|
getArgumentCompletions: completeSyncArguments,
|
|
449
353
|
handler: async (args, ctx) => {
|
|
450
|
-
if (!ctx.hasUI)
|
|
451
|
-
throw new Error("/sync requires TUI or RPC mode so results and safety prompts are observable.");
|
|
452
|
-
}
|
|
354
|
+
if (!ctx.hasUI) throw new Error("/sync requires TUI or RPC mode so results and safety prompts are observable.");
|
|
453
355
|
status.bind(ctx);
|
|
454
356
|
const signal = sessionAbort.signal;
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
357
|
+
const client = owner;
|
|
358
|
+
if (!client || ownerManager !== ctx.sessionManager) {
|
|
359
|
+
if (splitArgs(args)[0] !== "help") throw new Error("pi-sync session is not ready.");
|
|
360
|
+
const commands = await loaders.commands();
|
|
361
|
+
if (signal.aborted || owner) return;
|
|
362
|
+
ctx.isIdle();
|
|
363
|
+
await commands.handleCommand(args, ctx, signal, loaders, attention);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
await withPiDaemonClient(ctx, async (ownedContext) => {
|
|
367
|
+
ctx = ownedContext;
|
|
368
|
+
const command = splitArgs(args)[0];
|
|
461
369
|
const ready = await initialization;
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
370
|
+
if (signal.aborted || owner !== client) return;
|
|
371
|
+
await client.setBusy("command", true);
|
|
372
|
+
try {
|
|
373
|
+
await check.stop();
|
|
374
|
+
if (signal.aborted || owner !== client) return;
|
|
375
|
+
if (ready === false && command !== "help" && command !== "unlock" && command !== "migrate-state" && command !== "daemon") {
|
|
376
|
+
ctx.ui.notify(
|
|
377
|
+
"pi-sync recovery required. Repair the startup error, then /reload before syncing. Use /sync help for recovery guidance.",
|
|
378
|
+
"error"
|
|
379
|
+
);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
if (command === "unlock" || command === "migrate-state") {
|
|
383
|
+
const { stateDirectoryMigrationNotice } = await import("./chunks/state-directory-JZSZVVPX.ts");
|
|
384
|
+
if (signal.aborted || owner !== client) return;
|
|
385
|
+
stateDirectoryMigrationNotice();
|
|
386
|
+
}
|
|
387
|
+
const commands = await loaders.commands();
|
|
388
|
+
if (signal.aborted || owner !== client) return;
|
|
389
|
+
await commands.handleCommand(args, ctx, signal, loaders, attention);
|
|
390
|
+
} catch (error) {
|
|
476
391
|
if (!signal.aborted) {
|
|
477
392
|
ctx.ui.notify(`pi-sync command unavailable: ${safeTerminalText(errorMessage(error))}`, "error");
|
|
393
|
+
if (command === "unlock" || command === "migrate-state") throw error;
|
|
478
394
|
}
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
});
|
|
484
|
-
if (command === "migrate-state" || command === "help") await run();
|
|
485
|
-
else await withStateDirectoryAccess(run);
|
|
486
|
-
} finally {
|
|
487
|
-
const count = (foreground.get(manager) ?? 1) - 1;
|
|
488
|
-
if (count) foreground.set(manager, count);
|
|
489
|
-
else foreground.delete(manager);
|
|
490
|
-
if (mayResume) await resumeContinuous(ctx, signal, retry);
|
|
491
|
-
}
|
|
395
|
+
} finally {
|
|
396
|
+
if (!signal.aborted && owner === client) await client.setBusy("command", false);
|
|
397
|
+
}
|
|
398
|
+
});
|
|
492
399
|
}
|
|
493
400
|
});
|
|
494
401
|
pi.on("session_start", async (_event, ctx) => {
|
|
495
402
|
const releaseStatus = status.start(ctx);
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
403
|
+
const previousClient = owner;
|
|
404
|
+
shutdownAbort?.abort(new DOMException("Session replaced", "AbortError"));
|
|
405
|
+
shutdownAbort = void 0;
|
|
406
|
+
sessionAbort.abort(new DOMException("Session replaced", "AbortError"));
|
|
407
|
+
sessionAbort = new AbortController();
|
|
408
|
+
const signal = sessionAbort.signal;
|
|
409
|
+
const client = bindPiDaemonClient(ctx, signal, publishTimings);
|
|
410
|
+
owner = client;
|
|
411
|
+
ownerManager = ctx.sessionManager;
|
|
412
|
+
const replacementFile = ctx.sessionManager.getSessionFile?.();
|
|
413
|
+
attention.reset(ctx);
|
|
414
|
+
const previous = initialization;
|
|
415
|
+
initialization = withPiDaemonClient(ctx, async () => {
|
|
416
|
+
await previous.catch(() => {
|
|
417
|
+
});
|
|
418
|
+
if (signal.aborted || owner !== client) return false;
|
|
419
|
+
try {
|
|
512
420
|
await check.stop();
|
|
513
|
-
if (
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
ctx.ui.notify(`pi-sync recovery required: ${safeTerminalText(errorMessage(error))}`, "error");
|
|
421
|
+
if (previousClient) {
|
|
422
|
+
try {
|
|
423
|
+
await client.attachExisting();
|
|
424
|
+
} catch {
|
|
425
|
+
}
|
|
426
|
+
try {
|
|
427
|
+
await previousClient.disposeForShutdown("resume", replacementFile);
|
|
428
|
+
} catch {
|
|
522
429
|
}
|
|
523
|
-
|
|
430
|
+
await client.finishReattachment();
|
|
524
431
|
}
|
|
525
|
-
|
|
432
|
+
if (signal.aborted || owner !== client) return false;
|
|
433
|
+
return (await startSession(ctx, signal, publishTimings))?.config;
|
|
434
|
+
} catch (error) {
|
|
435
|
+
if (!signal.aborted && owner === client) {
|
|
436
|
+
try {
|
|
437
|
+
client.validate();
|
|
438
|
+
if (ctx.hasUI)
|
|
439
|
+
ctx.ui.notify(`pi-sync recovery required: ${safeTerminalText(errorMessage(error))}`, "error");
|
|
440
|
+
} catch {
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return false;
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
try {
|
|
526
447
|
const ready = await initialization;
|
|
527
448
|
if (ready === false) releaseStatus();
|
|
528
|
-
if (ready && !signal.aborted)
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
449
|
+
if (ready && !signal.aborted && owner === client && !(ready.continuous && ready.agentMode) && (ready.automatic || startupTransferEnabled(ready)))
|
|
450
|
+
await withPiDaemonClient(ctx, async () => {
|
|
451
|
+
check.start(ctx, signal, ready);
|
|
452
|
+
});
|
|
532
453
|
} catch (error) {
|
|
533
454
|
releaseStatus();
|
|
534
455
|
throw error;
|
|
535
456
|
}
|
|
536
457
|
});
|
|
537
458
|
pi.on("agent_start", async (_event, ctx) => {
|
|
538
|
-
|
|
539
|
-
|
|
459
|
+
const client = owner;
|
|
460
|
+
if (!client || ownerManager !== ctx.sessionManager || sessionAbort.signal.aborted) return;
|
|
461
|
+
if (!ctx.hasUI || !["tui", "rpc"].includes(ctx.mode)) await client.attachExisting();
|
|
462
|
+
await client.setBusy("agent", true);
|
|
463
|
+
if (owner === client && !sessionAbort.signal.aborted) await check.interrupt(ctx);
|
|
540
464
|
});
|
|
541
465
|
pi.on("agent_settled", async (_event, ctx) => {
|
|
542
|
-
const
|
|
543
|
-
if (!signal.aborted)
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
466
|
+
const client = owner;
|
|
467
|
+
if (!client || ownerManager !== ctx.sessionManager || sessionAbort.signal.aborted) return;
|
|
468
|
+
await client.setBusy("agent", false);
|
|
469
|
+
if (owner === client && !sessionAbort.signal.aborted)
|
|
470
|
+
await withPiDaemonClient(ctx, async () => {
|
|
471
|
+
check.settled(ctx);
|
|
472
|
+
});
|
|
547
473
|
});
|
|
474
|
+
pi.on("model_select", async (_event, ctx) => {
|
|
475
|
+
if (owner && ownerManager === ctx.sessionManager && !sessionAbort.signal.aborted) await owner.update();
|
|
476
|
+
});
|
|
477
|
+
const pauseForReplacement = async (_event, ctx) => {
|
|
478
|
+
const client = owner;
|
|
479
|
+
if (!client || ownerManager !== ctx.sessionManager || sessionAbort.signal.aborted) return;
|
|
480
|
+
const results = await Promise.allSettled([client.pauseForSessionChange(), check.stop()]);
|
|
481
|
+
if (results.some((result) => result.status === "rejected")) {
|
|
482
|
+
if (owner === client && !sessionAbort.signal.aborted)
|
|
483
|
+
ctx.ui.notify(
|
|
484
|
+
"pi-sync could not drain its writer. Repair or stop the existing daemon before changing sessions.",
|
|
485
|
+
"error"
|
|
486
|
+
);
|
|
487
|
+
return { cancel: true };
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
pi.on("session_before_switch", pauseForReplacement);
|
|
491
|
+
pi.on("session_before_fork", pauseForReplacement);
|
|
548
492
|
pi.on("session_shutdown", async (event, ctx) => {
|
|
549
493
|
const releaseStatus = status.cleanupFor(ctx);
|
|
494
|
+
const client = owner;
|
|
495
|
+
if (!client || ownerManager !== ctx.sessionManager) {
|
|
496
|
+
releaseStatus();
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
const controller = new AbortController();
|
|
500
|
+
shutdownAbort?.abort(new DOMException("Session shut down again", "AbortError"));
|
|
501
|
+
shutdownAbort = controller;
|
|
502
|
+
const signal = combineSignals(controller.signal, AbortSignal.timeout(3e4));
|
|
503
|
+
const reason = typeof event === "object" && event ? event.reason : void 0;
|
|
504
|
+
const target = typeof event === "object" && event ? event.targetSessionFile : void 0;
|
|
505
|
+
sessionAbort.abort(new DOMException("Session shutting down", "AbortError"));
|
|
506
|
+
let shutdownClient;
|
|
550
507
|
try {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
await withStateDirectoryAccess(async () => {
|
|
568
|
-
if (signal.aborted) return;
|
|
569
|
-
await autoPushSessions(ctx, signal, loaders);
|
|
570
|
-
});
|
|
508
|
+
await initialization.catch(() => {
|
|
509
|
+
});
|
|
510
|
+
await check.stop();
|
|
511
|
+
if (signal.aborted || owner !== client) return;
|
|
512
|
+
if (reason !== "reload") {
|
|
513
|
+
shutdownClient = bindPiDaemonClient(ctx, signal, publishTimings);
|
|
514
|
+
await shutdownClient.setBusy("shutdown", true);
|
|
515
|
+
const attached = await shutdownClient.attachExisting();
|
|
516
|
+
if (!signal.aborted && owner === client && attached)
|
|
517
|
+
await withPiDaemonClient(ctx, () => autoPushSessions(ctx, signal, loaders));
|
|
518
|
+
}
|
|
519
|
+
} catch (error) {
|
|
520
|
+
if (!signal.aborted && owner === client) {
|
|
521
|
+
try {
|
|
522
|
+
ctx.ui.notify(`pi-sync shutdown skipped: ${safeTerminalText(errorMessage(error))}`, "warning");
|
|
523
|
+
} catch {
|
|
571
524
|
}
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
|
|
525
|
+
}
|
|
526
|
+
} finally {
|
|
527
|
+
if (owner === client) {
|
|
528
|
+
owner = void 0;
|
|
529
|
+
ownerManager = void 0;
|
|
530
|
+
try {
|
|
531
|
+
attention.reset(ctx);
|
|
532
|
+
} catch {
|
|
575
533
|
}
|
|
534
|
+
}
|
|
535
|
+
try {
|
|
536
|
+
await client.disposeForShutdown(reason, target);
|
|
576
537
|
} finally {
|
|
577
|
-
|
|
538
|
+
try {
|
|
539
|
+
await shutdownClient?.disposeForShutdown(reason, target);
|
|
540
|
+
} finally {
|
|
541
|
+
controller.abort();
|
|
542
|
+
releaseStatus();
|
|
543
|
+
}
|
|
578
544
|
}
|
|
579
|
-
if (
|
|
580
|
-
setSyncStatus(ctx, void 0);
|
|
581
|
-
} finally {
|
|
582
|
-
releaseStatus();
|
|
545
|
+
if (shutdownAbort === controller) shutdownAbort = void 0;
|
|
583
546
|
}
|
|
584
547
|
});
|
|
585
548
|
}
|