@narumitw/pi-sync 0.59.0 → 0.60.1
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 +25 -17
- 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-NGW4JMBF.ts → chunk-4RNCZZY7.ts} +33 -27
- package/dist/chunks/{chunk-NGW4JMBF.ts.map → chunk-4RNCZZY7.ts.map} +3 -3
- package/dist/chunks/{chunk-2ZZJXITS.ts → chunk-6LHIRS5R.ts} +30 -47
- package/dist/chunks/chunk-6LHIRS5R.ts.map +7 -0
- package/dist/chunks/{config-J5VZUY4J.ts → chunk-7AC2RX4M.ts} +6 -13
- package/dist/chunks/chunk-7AC2RX4M.ts.map +7 -0
- package/dist/chunks/{chunk-76HID27T.ts → chunk-BGGKHHO4.ts} +18 -14
- package/dist/chunks/{chunk-76HID27T.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-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-PQ75RPUP.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-DTPELCPW.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-SDGKIQH2.ts → command-handler-FO4XBBHF.ts} +80 -86
- package/dist/chunks/command-handler-FO4XBBHF.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-OM64J27R.ts → continuous-record-ZHUXVO4E.ts} +5 -13
- package/dist/chunks/continuous-record-ZHUXVO4E.ts.map +7 -0
- package/dist/chunks/continuous-storage-SQBAXACF.ts +27 -0
- package/dist/chunks/continuous-storage-SQBAXACF.ts.map +7 -0
- package/dist/chunks/{file-selection-7HEVPO4T.ts → file-selection-S6CNNNQI.ts} +11 -14
- package/dist/chunks/{file-selection-7HEVPO4T.ts.map → file-selection-S6CNNNQI.ts.map} +1 -1
- package/dist/chunks/manager-result-dispatcher-I2AMCCE7.ts +18 -0
- package/dist/chunks/{manager-ui-65ZETN6F.ts → manager-ui-AY5ZU6B4.ts} +180 -164
- package/dist/chunks/manager-ui-AY5ZU6B4.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-AB27ADDI.ts → setup-switch-M3BAFGJM.ts} +9 -13
- package/dist/chunks/{setup-wizard-5FILKFLQ.ts → setup-wizard-NFAWP4KF.ts} +18 -21
- package/dist/chunks/{setup-wizard-5FILKFLQ.ts.map → setup-wizard-NFAWP4KF.ts.map} +1 -1
- package/dist/chunks/{snapshot-G3W2GOGB.ts → snapshot-D4SFDP5J.ts} +8 -13
- 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-H4TFZZ7S.ts → sync-state-FVCJJ7MY.ts} +5 -11
- package/dist/chunks/sync-state-FVCJJ7MY.ts.map +7 -0
- package/dist/index.ts +269 -313
- package/dist/index.ts.map +4 -4
- package/docs/daemon-migration.md +93 -0
- package/docs/tui-contract.md +12 -0
- package/package.json +3 -6
- package/skills/configure-pi-sync/SKILL.md +1 -1
- package/skills/configure-pi-sync/references/configuration.md +19 -6
- 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 -293
- 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 +40 -36
- 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 -263
- package/src/settings/settings-management.ts +11 -254
- package/src/settings/settings-store.ts +10 -48
- package/src/settings/settings-types.ts +1 -157
- package/src/settings/settings-validation.ts +17 -435
- package/src/snapshot/session-paths.ts +11 -111
- package/src/snapshot/snapshot-apply.ts +9 -322
- package/src/snapshot/snapshot-case-replacement.ts +6 -80
- package/src/snapshot/snapshot-codec.ts +2 -59
- package/src/snapshot/snapshot-exclude-safety.ts +2 -44
- 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 -946
- package/src/snapshot/snapshot-types.ts +1 -43
- package/src/snapshot/snapshot.ts +19 -447
- 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 -208
- 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 -25
- 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 -111
- 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 -61
- package/src/sync/exclude-policy.ts +6 -84
- 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 -119
- package/src/sync/merge-apply.ts +2 -439
- package/src/sync/merge-journal.ts +10 -228
- package/src/sync/merge-transfer-error.ts +2 -72
- package/src/sync/merged-sync.ts +2 -919
- package/src/sync/mutation-owner.ts +2 -22
- package/src/sync/package-merge.ts +2 -87
- package/src/sync/partial-progress.ts +2 -55
- package/src/sync/remote-snapshot.ts +7 -79
- 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 -111
- package/src/sync/sync-error-guidance.ts +2 -46
- package/src/sync/sync-errors.ts +7 -23
- package/src/sync/sync-inspection.ts +10 -59
- package/src/sync/sync-local.ts +2 -44
- package/src/sync/sync-mutations.ts +10 -788
- package/src/sync/sync-operations.ts +32 -11
- package/src/sync/sync-policy.ts +34 -474
- package/src/sync/sync-queries.ts +2 -247
- package/src/sync/sync-state.ts +18 -157
- package/src/sync/text-merge.ts +10 -133
- package/src/sync-extension.ts +192 -142
- package/src/ui/manager-state.ts +35 -23
- package/src/ui/manager-ui.ts +80 -36
- package/src/ui/sync-attention.ts +7 -49
- package/dist/chunks/agent-candidate-ZHN7FTZT.ts +0 -30
- package/dist/chunks/agent-plan-ILFEUJ2E.ts +0 -124
- package/dist/chunks/agent-plan-ILFEUJ2E.ts.map +0 -7
- package/dist/chunks/agent-refusal-retry-HRMHCX2A.ts +0 -73
- package/dist/chunks/agent-refusal-retry-HRMHCX2A.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-CCKN4DPR.ts +0 -175
- package/dist/chunks/agent-store-CCKN4DPR.ts.map +0 -7
- package/dist/chunks/agent-sync-EGA2I5W7.ts +0 -22
- package/dist/chunks/chunk-25QCU3LY.ts +0 -220
- package/dist/chunks/chunk-25QCU3LY.ts.map +0 -7
- package/dist/chunks/chunk-2JZFHNLM.ts +0 -113
- package/dist/chunks/chunk-2JZFHNLM.ts.map +0 -7
- package/dist/chunks/chunk-2UKUKIBI.ts +0 -25
- package/dist/chunks/chunk-2UKUKIBI.ts.map +0 -7
- package/dist/chunks/chunk-2ZZJXITS.ts.map +0 -7
- package/dist/chunks/chunk-3JTZF7Z5.ts +0 -77
- package/dist/chunks/chunk-3JTZF7Z5.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-4NVHHDN2.ts +0 -61
- package/dist/chunks/chunk-4NVHHDN2.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-6OFMB6KK.ts +0 -215
- package/dist/chunks/chunk-6OFMB6KK.ts.map +0 -7
- package/dist/chunks/chunk-6XU5HZAN.ts +0 -205
- package/dist/chunks/chunk-6XU5HZAN.ts.map +0 -7
- package/dist/chunks/chunk-6YGRZSCN.ts +0 -128
- package/dist/chunks/chunk-6YGRZSCN.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-7WYF2KUO.ts +0 -1161
- package/dist/chunks/chunk-7WYF2KUO.ts.map +0 -7
- package/dist/chunks/chunk-APDNHB2T.ts +0 -2037
- package/dist/chunks/chunk-APDNHB2T.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-DT7M4VQS.ts +0 -69
- package/dist/chunks/chunk-DT7M4VQS.ts.map +0 -7
- package/dist/chunks/chunk-DTPELCPW.ts.map +0 -7
- package/dist/chunks/chunk-ECYCNZOE.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-G4RUXRWZ.ts +0 -48
- package/dist/chunks/chunk-G4RUXRWZ.ts.map +0 -7
- package/dist/chunks/chunk-ILXMZ2HU.ts +0 -58
- package/dist/chunks/chunk-ILXMZ2HU.ts.map +0 -7
- package/dist/chunks/chunk-LA3HQMFG.ts +0 -115
- package/dist/chunks/chunk-LA3HQMFG.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-MKC3PXCN.ts +0 -369
- package/dist/chunks/chunk-MKC3PXCN.ts.map +0 -7
- package/dist/chunks/chunk-OQBE2OMB.ts +0 -88
- package/dist/chunks/chunk-OQBE2OMB.ts.map +0 -7
- package/dist/chunks/chunk-P3YD4ONV.ts +0 -123
- package/dist/chunks/chunk-P3YD4ONV.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-QQVK2XFC.ts +0 -64
- package/dist/chunks/chunk-QQVK2XFC.ts.map +0 -7
- package/dist/chunks/chunk-RDOX3VH5.ts +0 -140
- package/dist/chunks/chunk-RDOX3VH5.ts.map +0 -7
- package/dist/chunks/chunk-S7D6XWHI.ts +0 -258
- package/dist/chunks/chunk-S7D6XWHI.ts.map +0 -7
- package/dist/chunks/chunk-SHPNS7FM.ts +0 -64
- package/dist/chunks/chunk-SHPNS7FM.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-T2TYBLXK.ts +0 -27
- package/dist/chunks/chunk-T2TYBLXK.ts.map +0 -7
- package/dist/chunks/chunk-UZSDS4HF.ts +0 -403
- package/dist/chunks/chunk-UZSDS4HF.ts.map +0 -7
- package/dist/chunks/chunk-VPODHKOX.ts +0 -229
- package/dist/chunks/chunk-VPODHKOX.ts.map +0 -7
- package/dist/chunks/chunk-WEKGW7HV.ts +0 -162
- package/dist/chunks/chunk-WEKGW7HV.ts.map +0 -7
- package/dist/chunks/chunk-WUHRVSWI.ts +0 -369
- package/dist/chunks/chunk-WUHRVSWI.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-XZ3ZTHKR.ts +0 -1184
- package/dist/chunks/chunk-XZ3ZTHKR.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-YEULK7MK.ts +0 -415
- package/dist/chunks/chunk-YEULK7MK.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-SDGKIQH2.ts.map +0 -7
- package/dist/chunks/conflict-artifacts-MYSH3L2J.ts +0 -33
- package/dist/chunks/conflict-review-J6ZSPNWL.ts +0 -190
- package/dist/chunks/conflict-review-J6ZSPNWL.ts.map +0 -7
- package/dist/chunks/continuous-sync-BH5SWIRV.ts +0 -590
- package/dist/chunks/continuous-sync-BH5SWIRV.ts.map +0 -7
- package/dist/chunks/git-backend-6CKI6CUG.ts +0 -1074
- package/dist/chunks/git-backend-6CKI6CUG.ts.map +0 -7
- package/dist/chunks/local-fields-SR7PH66U.ts +0 -27
- package/dist/chunks/local-fields-SR7PH66U.ts.map +0 -7
- package/dist/chunks/manager-result-dispatcher-CXUP5WDP.ts +0 -33
- package/dist/chunks/manager-result-dispatcher-CXUP5WDP.ts.map +0 -7
- package/dist/chunks/manager-ui-65ZETN6F.ts.map +0 -7
- package/dist/chunks/merge-baseline-store-4Y2X7P2D.ts +0 -26
- package/dist/chunks/merge-baseline-store-4Y2X7P2D.ts.map +0 -7
- package/dist/chunks/remote-selection-ui-W55BQDJQ.ts +0 -32
- package/dist/chunks/remote-selection-ui-W55BQDJQ.ts.map +0 -7
- package/dist/chunks/s3-backend-FDK7JSDQ.ts +0 -845
- package/dist/chunks/s3-backend-FDK7JSDQ.ts.map +0 -7
- package/dist/chunks/setup-switch-AB27ADDI.ts.map +0 -7
- package/dist/chunks/snapshot-G3W2GOGB.ts.map +0 -7
- package/dist/chunks/snapshot-transaction-SGRUWT73.ts +0 -25
- package/dist/chunks/snapshot-transaction-SGRUWT73.ts.map +0 -7
- package/dist/chunks/sync-inspection-MDYHZHT7.ts +0 -26
- package/dist/chunks/sync-inspection-MDYHZHT7.ts.map +0 -7
- package/dist/chunks/sync-operations-ZAUP65FH.ts +0 -1032
- package/dist/chunks/sync-operations-ZAUP65FH.ts.map +0 -7
- package/dist/chunks/sync-state-H4TFZZ7S.ts.map +0 -7
- package/dist/chunks/webdav-backend-UNMIAXM5.ts +0 -852
- package/dist/chunks/webdav-backend-UNMIAXM5.ts.map +0 -7
- /package/dist/chunks/{chunk-KHBPED6W.ts.map → chunk-GSQGBVKG.ts.map} +0 -0
- /package/dist/chunks/{chunk-PQ75RPUP.ts.map → chunk-UZUUUY7C.ts.map} +0 -0
- /package/dist/chunks/{agent-candidate-ZHN7FTZT.ts.map → manager-result-dispatcher-I2AMCCE7.ts.map} +0 -0
- /package/dist/chunks/{agent-sync-EGA2I5W7.ts.map → merge-review-SGDLMVS4.ts.map} +0 -0
- /package/dist/chunks/{config-J5VZUY4J.ts.map → remote-selection-ui-GZHPDQ4L.ts.map} +0 -0
- /package/dist/chunks/{conflict-artifacts-MYSH3L2J.ts.map → setup-switch-M3BAFGJM.ts.map} +0 -0
- /package/dist/chunks/{continuous-record-OM64J27R.ts.map → state-directory-JZSZVVPX.ts.map} +0 -0
package/dist/index.ts
CHANGED
|
@@ -1,182 +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-6LHIRS5R.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-XZ3ZTHKR.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-4NVHHDN2.ts";
|
|
52
|
-
import "./chunks/chunk-AR2DGDUI.ts";
|
|
53
|
-
import {
|
|
54
|
-
stateDirectoryMigrationNotice,
|
|
55
|
-
withStateDirectoryAccess
|
|
56
|
-
} from "./chunks/chunk-SWRVXVFD.ts";
|
|
57
|
-
import "./chunks/chunk-2JZFHNLM.ts";
|
|
58
|
-
import "./chunks/chunk-T2SJD3N7.ts";
|
|
38
|
+
} from "./chunks/chunk-PDBTD2K6.ts";
|
|
59
39
|
import {
|
|
60
|
-
|
|
61
|
-
} from "./chunks/chunk-
|
|
40
|
+
errorMessage
|
|
41
|
+
} from "./chunks/chunk-HNKLBM3U.ts";
|
|
62
42
|
import {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
43
|
+
safeTerminalText
|
|
44
|
+
} from "./chunks/chunk-2JNFEZ3V.ts";
|
|
45
|
+
import "./chunks/chunk-JKBUYCPC.ts";
|
|
46
|
+
|
|
47
|
+
// src/sync/agent-policy.ts
|
|
68
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,
|
|
69
55
|
startupTransferEnabled
|
|
70
|
-
} from "
|
|
56
|
+
} from "@narumitw/sync-daemon/engine/sync/agent-policy";
|
|
71
57
|
|
|
72
58
|
// src/settings/config-errors.ts
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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";
|
|
76
63
|
|
|
77
64
|
// src/sync/automatic-sync.ts
|
|
78
|
-
var AUTO_SYNC_OPTIONS = {
|
|
79
|
-
yes: true,
|
|
80
|
-
force: false,
|
|
81
|
-
stale: false,
|
|
82
|
-
silent: true,
|
|
83
|
-
reload: false,
|
|
84
|
-
auto: true,
|
|
85
|
-
args: []
|
|
86
|
-
};
|
|
87
65
|
async function startSession(ctx, signal, publish) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
throwIfAborted(signal);
|
|
93
|
-
const stateNotice = stateDirectoryMigrationNotice();
|
|
94
|
-
if (stateNotice && ctx.hasUI) ctx.ui.notify(stateNotice, "warning");
|
|
95
|
-
const validateMutation = captureMutationOwner(ctx, signal);
|
|
96
|
-
const currentFile = ctx.sessionManager.getSessionFile?.();
|
|
97
|
-
await timings.measure("transaction recovery", async () => {
|
|
98
|
-
const pending = await pendingTransactionEntries();
|
|
99
|
-
validateMutation();
|
|
100
|
-
if (!pending.some((entry) => entry.isDirectory())) return;
|
|
101
|
-
const { recoverSnapshotTransactionsOnStartup } = await import("./chunks/snapshot-transaction-SGRUWT73.ts");
|
|
102
|
-
validateMutation();
|
|
103
|
-
const recoverySettings = await readLocalConfigObject();
|
|
104
|
-
validateMutation();
|
|
105
|
-
const recoverySetup = recoverySettings?.activeSyncSetup;
|
|
106
|
-
await recoverSnapshotTransactionsOnStartup({
|
|
107
|
-
exclude: recoverySetup ? recoverySettings.syncSetups[recoverySetup]?.sync.exclude : void 0,
|
|
108
|
-
signal,
|
|
109
|
-
sessionDir: sessionDirFromContext(ctx),
|
|
110
|
-
protectedTargets: currentFile ? [currentFile] : [],
|
|
111
|
-
validateMutation
|
|
112
|
-
});
|
|
113
|
-
});
|
|
66
|
+
throwIfAborted(signal);
|
|
67
|
+
const client = piDaemonClient(ctx);
|
|
68
|
+
if (!ctx.hasUI || !["tui", "rpc"].includes(ctx.mode)) {
|
|
69
|
+
await client.attachExisting();
|
|
114
70
|
throwIfAborted(signal);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
throwIfAborted(signal);
|
|
133
|
-
configureSyncStatus(ctx, config.showStatus);
|
|
134
|
-
outcome = "completed";
|
|
135
|
-
return { debug, config };
|
|
136
|
-
} catch (error) {
|
|
137
|
-
throwIfAborted(signal);
|
|
138
|
-
if (!isMissingConfigError(error)) {
|
|
139
|
-
ctx.ui.notify(`pi-sync startup check skipped: ${safeTerminalText(errorMessage(error))}`, "warning");
|
|
140
|
-
}
|
|
141
|
-
}
|
|
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");
|
|
142
88
|
return { debug };
|
|
143
|
-
} finally {
|
|
144
|
-
timings.publish(ctx, debug, signal, "local initialization", outcome);
|
|
145
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 };
|
|
146
105
|
}
|
|
147
|
-
async function autoPushSessions(ctx, signal,
|
|
106
|
+
async function autoPushSessions(ctx, signal, _loaders) {
|
|
148
107
|
try {
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
if (!partial.automatic) return;
|
|
152
|
-
if (!syncSessionsSelected(partial)) return;
|
|
153
|
-
await ensureStateDir();
|
|
108
|
+
const client = piDaemonClient(ctx);
|
|
109
|
+
if (!await client.configured()) return;
|
|
154
110
|
throwIfAborted(signal);
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
loaders.snapshot(),
|
|
161
|
-
loaders.syncState()
|
|
162
|
-
]);
|
|
163
|
-
throwIfAborted(signal);
|
|
164
|
-
await withLock("auto-session-push", async () => {
|
|
165
|
-
throwIfAborted(signal);
|
|
166
|
-
const state = await readStateForConfig(config);
|
|
167
|
-
throwIfAborted(signal);
|
|
168
|
-
const local = await snapshotModule.createSnapshot(config.snapshotIdentity, {
|
|
169
|
-
...snapshotOptionsForContext(ctx, config),
|
|
170
|
-
signal
|
|
171
|
-
});
|
|
172
|
-
throwIfAborted(signal);
|
|
173
|
-
if (!syncStateModule.hasLocalChanges(local, state, config)) return;
|
|
174
|
-
await operations.push(ctx, { ...AUTO_SYNC_OPTIONS, signal }, { config, state, local });
|
|
175
|
-
});
|
|
111
|
+
await client.run(
|
|
112
|
+
"shutdown",
|
|
113
|
+
{ args: [], yes: true, force: false, stale: false, silent: true, reload: false },
|
|
114
|
+
signal
|
|
115
|
+
);
|
|
176
116
|
} catch (error) {
|
|
177
117
|
if (signal.aborted || isMissingConfigError(error)) return;
|
|
178
|
-
|
|
179
|
-
ctx.ui.notify(`pi-sync session push skipped: ${errorMessage(error)}`, "warning");
|
|
118
|
+
ctx.ui.notify(`pi-sync session push skipped: ${safeTerminalText(errorMessage(error))}`, "warning");
|
|
180
119
|
}
|
|
181
120
|
}
|
|
182
121
|
|
|
@@ -241,13 +180,7 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4, publish) {
|
|
|
241
180
|
if (syncCheckConfigFingerprint(currentConfig) !== identity) return;
|
|
242
181
|
const inspection = await timings.measure(
|
|
243
182
|
"inspection and guards",
|
|
244
|
-
() =>
|
|
245
|
-
throwIfAborted(signal);
|
|
246
|
-
return withLock("startup-check", () => {
|
|
247
|
-
throwIfAborted(signal);
|
|
248
|
-
return inspectSync(captured, snapshotOptionsForContext(ctx, captured), signal, void 0, timings);
|
|
249
|
-
});
|
|
250
|
-
})
|
|
183
|
+
() => inspectSync(captured, snapshotOptionsForContext(ctx, captured), signal, void 0, timings)
|
|
251
184
|
);
|
|
252
185
|
throwIfAborted(signal);
|
|
253
186
|
const latest = await loadConfigForCheck();
|
|
@@ -264,10 +197,7 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4, publish) {
|
|
|
264
197
|
automaticTransfer: startupTransferEnabled(captured)
|
|
265
198
|
});
|
|
266
199
|
if (startupTransferEnabled(captured) && !inspection.firstSync && inspection.head && inspection.selectionState?.kind === "same") {
|
|
267
|
-
const
|
|
268
|
-
"operations import",
|
|
269
|
-
() => Promise.all([loaders.operations(), import("./chunks/agent-sync-EGA2I5W7.ts")])
|
|
270
|
-
);
|
|
200
|
+
const operations = await timings.measure("operations import", () => loaders.operations());
|
|
271
201
|
throwIfAborted(signal);
|
|
272
202
|
if (!isCurrent()) return;
|
|
273
203
|
if (!ctx.isIdle()) {
|
|
@@ -276,24 +206,18 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4, publish) {
|
|
|
276
206
|
}
|
|
277
207
|
await timings.measure(
|
|
278
208
|
"automatic transfer",
|
|
279
|
-
() =>
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
startupTimings: timings,
|
|
292
|
-
onCommit: () => attention.clearObservation()
|
|
293
|
-
},
|
|
294
|
-
(options) => operations.syncBoth(ctx, options)
|
|
295
|
-
)
|
|
296
|
-
)
|
|
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
|
+
})
|
|
297
221
|
);
|
|
298
222
|
throwIfAborted(signal);
|
|
299
223
|
if (!isCurrent()) return;
|
|
@@ -365,12 +289,12 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4, publish) {
|
|
|
365
289
|
// src/sync/sync-loaders.ts
|
|
366
290
|
function createSyncLoaders(dependencies) {
|
|
367
291
|
const loaders = {
|
|
368
|
-
commands: cachedModuleLoader(dependencies.loadCommandHandler ?? (() => import("./chunks/command-handler-
|
|
369
|
-
inspection: cachedModuleLoader(dependencies.loadSyncInspection ?? (() => import("./chunks/sync-inspection-
|
|
370
|
-
setupSwitch: cachedModuleLoader(dependencies.loadSetupSwitch ?? (() => import("./chunks/setup-switch-
|
|
371
|
-
snapshot: cachedModuleLoader(dependencies.loadSnapshot ?? (() => import("./chunks/snapshot-
|
|
372
|
-
syncState: cachedModuleLoader(dependencies.loadSyncState ?? (() => import("./chunks/sync-state-
|
|
373
|
-
operations: cachedModuleLoader(dependencies.loadSyncOperations ?? (() => import("./chunks/sync-operations-
|
|
292
|
+
commands: cachedModuleLoader(dependencies.loadCommandHandler ?? (() => import("./chunks/command-handler-FO4XBBHF.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")))
|
|
374
298
|
};
|
|
375
299
|
return loaders;
|
|
376
300
|
}
|
|
@@ -412,6 +336,7 @@ function registerStartupTimings(pi) {
|
|
|
412
336
|
|
|
413
337
|
// src/sync-extension.ts
|
|
414
338
|
function sync(pi, dependencies = {}) {
|
|
339
|
+
installPiDaemonHost();
|
|
415
340
|
const loaders = createSyncLoaders(dependencies);
|
|
416
341
|
const attention = createSyncAttentionController();
|
|
417
342
|
const status = createSyncStatusPublisher(pi.events);
|
|
@@ -420,173 +345,204 @@ function sync(pi, dependencies = {}) {
|
|
|
420
345
|
let sessionAbort = new AbortController();
|
|
421
346
|
let shutdownAbort;
|
|
422
347
|
let initialization = Promise.resolve(void 0);
|
|
423
|
-
let continuous;
|
|
424
348
|
let owner;
|
|
425
|
-
let
|
|
426
|
-
let startupDebug = false;
|
|
427
|
-
const foreground = /* @__PURE__ */ new Map();
|
|
428
|
-
async function resumeContinuous(ctx, signal, retry) {
|
|
429
|
-
const isCurrent = () => !signal.aborted && !foreground.has(ctx.sessionManager) && owner === ctx.sessionManager;
|
|
430
|
-
if (!isCurrent() || !ctx.hasUI) return;
|
|
431
|
-
try {
|
|
432
|
-
const { loadConfigForCheck: loadConfigForCheck2 } = await import("./chunks/config-J5VZUY4J.ts");
|
|
433
|
-
if (!isCurrent()) return;
|
|
434
|
-
const config = await loadConfigForCheck2();
|
|
435
|
-
if (!isCurrent()) return;
|
|
436
|
-
continuousPossible = Boolean(config.continuous && config.agentMode);
|
|
437
|
-
if (!continuousPossible) {
|
|
438
|
-
await continuous?.stop(ctx.sessionManager);
|
|
439
|
-
return;
|
|
440
|
-
}
|
|
441
|
-
const { createContinuousSync } = await import("./chunks/continuous-sync-BH5SWIRV.ts");
|
|
442
|
-
if (!isCurrent()) return;
|
|
443
|
-
continuous ??= createContinuousSync(loaders, void 0, publishTimings);
|
|
444
|
-
continuous.start(
|
|
445
|
-
ctx,
|
|
446
|
-
signal,
|
|
447
|
-
Boolean(retry && (retry.setup === void 0 || retry.setup === config.setupName)),
|
|
448
|
-
startupDebug
|
|
449
|
-
);
|
|
450
|
-
} catch {
|
|
451
|
-
}
|
|
452
|
-
}
|
|
349
|
+
let ownerManager;
|
|
453
350
|
pi.registerCommand("sync", {
|
|
454
351
|
description: "Sync Pi settings through Git, WebDAV, R2, or S3-compatible storage",
|
|
455
352
|
getArgumentCompletions: completeSyncArguments,
|
|
456
353
|
handler: async (args, ctx) => {
|
|
457
|
-
if (!ctx.hasUI)
|
|
458
|
-
throw new Error("/sync requires TUI or RPC mode so results and safety prompts are observable.");
|
|
459
|
-
}
|
|
354
|
+
if (!ctx.hasUI) throw new Error("/sync requires TUI or RPC mode so results and safety prompts are observable.");
|
|
460
355
|
status.bind(ctx);
|
|
461
356
|
const signal = sessionAbort.signal;
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
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];
|
|
468
369
|
const ready = await initialization;
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
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) {
|
|
483
391
|
if (!signal.aborted) {
|
|
484
392
|
ctx.ui.notify(`pi-sync command unavailable: ${safeTerminalText(errorMessage(error))}`, "error");
|
|
393
|
+
if (command === "unlock" || command === "migrate-state") throw error;
|
|
485
394
|
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
});
|
|
491
|
-
if (command === "migrate-state" || command === "help") await run();
|
|
492
|
-
else await withStateDirectoryAccess(run);
|
|
493
|
-
} finally {
|
|
494
|
-
const count = (foreground.get(manager) ?? 1) - 1;
|
|
495
|
-
if (count) foreground.set(manager, count);
|
|
496
|
-
else foreground.delete(manager);
|
|
497
|
-
if (mayResume) await resumeContinuous(ctx, signal, retry);
|
|
498
|
-
}
|
|
395
|
+
} finally {
|
|
396
|
+
if (!signal.aborted && owner === client) await client.setBusy("command", false);
|
|
397
|
+
}
|
|
398
|
+
});
|
|
499
399
|
}
|
|
500
400
|
});
|
|
501
401
|
pi.on("session_start", async (_event, ctx) => {
|
|
502
402
|
const releaseStatus = status.start(ctx);
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
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 {
|
|
519
420
|
await check.stop();
|
|
520
|
-
if (
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
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 {
|
|
529
429
|
}
|
|
530
|
-
|
|
430
|
+
await client.finishReattachment();
|
|
531
431
|
}
|
|
532
|
-
|
|
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 {
|
|
533
447
|
const ready = await initialization;
|
|
534
448
|
if (ready === false) releaseStatus();
|
|
535
|
-
if (ready && !signal.aborted)
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
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
|
+
});
|
|
539
453
|
} catch (error) {
|
|
540
454
|
releaseStatus();
|
|
541
455
|
throw error;
|
|
542
456
|
}
|
|
543
457
|
});
|
|
544
458
|
pi.on("agent_start", async (_event, ctx) => {
|
|
545
|
-
|
|
546
|
-
|
|
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);
|
|
547
464
|
});
|
|
548
465
|
pi.on("agent_settled", async (_event, ctx) => {
|
|
549
|
-
const
|
|
550
|
-
if (!signal.aborted)
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
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
|
+
});
|
|
554
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);
|
|
555
492
|
pi.on("session_shutdown", async (event, ctx) => {
|
|
556
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;
|
|
557
507
|
try {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
await withStateDirectoryAccess(async () => {
|
|
575
|
-
if (signal.aborted) return;
|
|
576
|
-
await autoPushSessions(ctx, signal, loaders);
|
|
577
|
-
});
|
|
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 {
|
|
578
524
|
}
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
|
|
525
|
+
}
|
|
526
|
+
} finally {
|
|
527
|
+
if (owner === client) {
|
|
528
|
+
owner = void 0;
|
|
529
|
+
ownerManager = void 0;
|
|
530
|
+
try {
|
|
531
|
+
attention.reset(ctx);
|
|
532
|
+
} catch {
|
|
582
533
|
}
|
|
534
|
+
}
|
|
535
|
+
try {
|
|
536
|
+
await client.disposeForShutdown(reason, target);
|
|
583
537
|
} finally {
|
|
584
|
-
|
|
538
|
+
try {
|
|
539
|
+
await shutdownClient?.disposeForShutdown(reason, target);
|
|
540
|
+
} finally {
|
|
541
|
+
controller.abort();
|
|
542
|
+
releaseStatus();
|
|
543
|
+
}
|
|
585
544
|
}
|
|
586
|
-
if (
|
|
587
|
-
setSyncStatus(ctx, void 0);
|
|
588
|
-
} finally {
|
|
589
|
-
releaseStatus();
|
|
545
|
+
if (shutdownAbort === controller) shutdownAbort = void 0;
|
|
590
546
|
}
|
|
591
547
|
});
|
|
592
548
|
}
|