@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
|
@@ -1,369 +0,0 @@
|
|
|
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
|
-
compileSyncExclude,
|
|
5
|
-
normalizeSyncExclude,
|
|
6
|
-
sameSyncExclude
|
|
7
|
-
} from "./chunk-3JTZF7Z5.ts";
|
|
8
|
-
import {
|
|
9
|
-
isDeniedPath,
|
|
10
|
-
toPosix
|
|
11
|
-
} from "./chunk-FHE2DCA2.ts";
|
|
12
|
-
|
|
13
|
-
// src/sync/sync-policy.ts
|
|
14
|
-
import path from "node:path";
|
|
15
|
-
var BUILT_IN_SYNC_ROOTS = [
|
|
16
|
-
"settings.json",
|
|
17
|
-
"keybindings.json",
|
|
18
|
-
"models.json",
|
|
19
|
-
"AGENTS.md",
|
|
20
|
-
"APPEND_SYSTEM.md",
|
|
21
|
-
"skills",
|
|
22
|
-
"prompts",
|
|
23
|
-
"themes",
|
|
24
|
-
"extensions"
|
|
25
|
-
];
|
|
26
|
-
var DEFAULT_SYNC_INCLUDE = [...BUILT_IN_SYNC_ROOTS];
|
|
27
|
-
var MAX_SYNC_INCLUDE_ITEMS = 1024;
|
|
28
|
-
var MAX_SYNC_INCLUDE_PATH_BYTES = 4096;
|
|
29
|
-
var MAX_SYNC_INCLUDE_TOTAL_BYTES = 256 * 1024;
|
|
30
|
-
var BUILT_IN_BY_LOWER = new Map(
|
|
31
|
-
BUILT_IN_SYNC_ROOTS.map((fileName) => [fileName.toLowerCase(), fileName])
|
|
32
|
-
);
|
|
33
|
-
var TOP_LEVEL_FILE_PATHS = new Map(
|
|
34
|
-
BUILT_IN_SYNC_ROOTS.filter((fileName) => fileName.includes(".")).map((fileName) => [
|
|
35
|
-
fileName.toLowerCase(),
|
|
36
|
-
fileName
|
|
37
|
-
])
|
|
38
|
-
);
|
|
39
|
-
var TOP_LEVEL_DIRS = new Set(BUILT_IN_SYNC_ROOTS.filter((fileName) => !fileName.includes(".")));
|
|
40
|
-
var RESERVED_TOP_LEVEL_NAMES = /* @__PURE__ */ new Set([...BUILT_IN_BY_LOWER.keys(), "sessions"]);
|
|
41
|
-
function normalizeSyncInclude(value) {
|
|
42
|
-
if (!Array.isArray(value)) {
|
|
43
|
-
throw new Error("Invalid pi-sync settings: sync.include must be an array.");
|
|
44
|
-
}
|
|
45
|
-
if (value.length > MAX_SYNC_INCLUDE_ITEMS) {
|
|
46
|
-
throw new Error(`Invalid pi-sync settings: sync.include has too many items; limit: ${MAX_SYNC_INCLUDE_ITEMS}.`);
|
|
47
|
-
}
|
|
48
|
-
const result = [];
|
|
49
|
-
const seen = /* @__PURE__ */ new Set();
|
|
50
|
-
const pathRoot = { children: /* @__PURE__ */ new Map() };
|
|
51
|
-
let totalBytes = 0;
|
|
52
|
-
for (const item of value) {
|
|
53
|
-
if (typeof item !== "string") {
|
|
54
|
-
throw new Error("Invalid pi-sync settings: sync.include items must be strings.");
|
|
55
|
-
}
|
|
56
|
-
const itemBytes = Buffer.byteLength(item, "utf8");
|
|
57
|
-
if (itemBytes > MAX_SYNC_INCLUDE_PATH_BYTES) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
`Invalid pi-sync settings: sync.include item is too long; limit: ${MAX_SYNC_INCLUDE_PATH_BYTES} bytes.`
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
totalBytes += itemBytes;
|
|
63
|
-
if (totalBytes > MAX_SYNC_INCLUDE_TOTAL_BYTES) {
|
|
64
|
-
throw new Error(
|
|
65
|
-
`Invalid pi-sync settings: sync.include is too large; limit: ${MAX_SYNC_INCLUDE_TOTAL_BYTES} bytes.`
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
const trimmed = item.trim();
|
|
69
|
-
const builtIn = BUILT_IN_BY_LOWER.get(trimmed.toLowerCase());
|
|
70
|
-
const normalized = builtIn ?? (trimmed.toLowerCase() === "sessions" ? "sessions" : trimmed);
|
|
71
|
-
if (!builtIn && normalized !== "sessions") validateAgentRelativeInclude(normalized);
|
|
72
|
-
const identity = normalized.toLowerCase();
|
|
73
|
-
if (seen.has(identity)) {
|
|
74
|
-
throw new Error(`Invalid pi-sync settings: duplicate sync.include item: ${item}`);
|
|
75
|
-
}
|
|
76
|
-
addIncludePath(pathRoot, identity, item);
|
|
77
|
-
seen.add(identity);
|
|
78
|
-
result.push(normalized);
|
|
79
|
-
}
|
|
80
|
-
return result;
|
|
81
|
-
}
|
|
82
|
-
function addIncludePath(root, identity, source) {
|
|
83
|
-
let node = root;
|
|
84
|
-
for (const segment of identity.split("/")) {
|
|
85
|
-
if (node.selected !== void 0) throwOverlappingInclude(source);
|
|
86
|
-
let child = node.children.get(segment);
|
|
87
|
-
if (!child) {
|
|
88
|
-
child = { children: /* @__PURE__ */ new Map() };
|
|
89
|
-
node.children.set(segment, child);
|
|
90
|
-
}
|
|
91
|
-
node = child;
|
|
92
|
-
}
|
|
93
|
-
if (node.children.size > 0) throwOverlappingInclude(source);
|
|
94
|
-
node.selected = identity;
|
|
95
|
-
}
|
|
96
|
-
function throwOverlappingInclude(item) {
|
|
97
|
-
throw new Error(`Invalid pi-sync settings: overlapping sync.include items are ambiguous: ${item}`);
|
|
98
|
-
}
|
|
99
|
-
function validateAgentRelativeInclude(value) {
|
|
100
|
-
const normalized = toPosix(value);
|
|
101
|
-
const topLevel = normalized.split("/")[0]?.toLowerCase();
|
|
102
|
-
if (!normalized || normalized === "." || normalized === ".." || normalized.startsWith("../") || path.posix.isAbsolute(normalized) || normalized.includes("\\") || path.posix.normalize(normalized) !== normalized || // biome-ignore lint/suspicious/noControlCharactersInRegex: Include paths cannot contain controls.
|
|
103
|
-
/[\u0000-\u001f\u007f-\u009f]/u.test(normalized)) {
|
|
104
|
-
throw new Error(`Invalid pi-sync settings: sync.include item must be a safe agent-relative path: ${value}`);
|
|
105
|
-
}
|
|
106
|
-
if (isDeniedPath(normalized)) {
|
|
107
|
-
throw new Error(`Invalid pi-sync settings: ${value} cannot be synced.`);
|
|
108
|
-
}
|
|
109
|
-
if (topLevel && RESERVED_TOP_LEVEL_NAMES.has(topLevel)) {
|
|
110
|
-
throw new Error(
|
|
111
|
-
`Invalid pi-sync settings: use the canonical ${topLevel} root instead of a nested sync.include path.`
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
function portableSnapshotSelection(value) {
|
|
116
|
-
const selection = value;
|
|
117
|
-
if (!selection || typeof selection !== "object" || Array.isArray(selection) || selection.version !== 1 && selection.version !== 2 || !Object.hasOwn(selection, "include") || selection.version === 2 && !Object.hasOwn(selection, "exclude") || Object.keys(selection).some(
|
|
118
|
-
(key) => key !== "version" && key !== "include" && !(selection.version === 2 && key === "exclude")
|
|
119
|
-
))
|
|
120
|
-
throw new Error("Invalid snapshot selection policy.");
|
|
121
|
-
const include = normalizeSyncInclude(selection.include);
|
|
122
|
-
if (selection.version === 1) return { version: 1, include };
|
|
123
|
-
if (!Array.isArray(selection.exclude)) throw new Error("Invalid snapshot exclude policy.");
|
|
124
|
-
return { version: 2, include, exclude: normalizeSyncExclude(selection.exclude) };
|
|
125
|
-
}
|
|
126
|
-
function snapshotSelectionInclude(snapshot) {
|
|
127
|
-
return snapshot.selection === void 0 ? void 0 : portableSnapshotSelection(snapshot.selection).include;
|
|
128
|
-
}
|
|
129
|
-
function snapshotSelectionExclude(snapshot) {
|
|
130
|
-
return snapshot.selection === void 0 ? void 0 : portableSnapshotSelection(snapshot.selection).exclude;
|
|
131
|
-
}
|
|
132
|
-
function selectionForSnapshot(include, exclude) {
|
|
133
|
-
const normalized = normalizeSyncInclude(include);
|
|
134
|
-
return exclude === void 0 ? { version: 1, include: normalized } : { version: 2, include: normalized, exclude: normalizeSyncExclude(exclude) };
|
|
135
|
-
}
|
|
136
|
-
function sameSnapshotSelection(left, right) {
|
|
137
|
-
return JSON.stringify(left === void 0 ? null : portableSnapshotSelection(left)) === JSON.stringify(right === void 0 ? null : portableSnapshotSelection(right));
|
|
138
|
-
}
|
|
139
|
-
function validateSnapshotSelection(snapshot) {
|
|
140
|
-
const selection = snapshot.selection === void 0 ? void 0 : portableSnapshotSelection(snapshot.selection);
|
|
141
|
-
if (snapshot.version === 4 !== (selection?.version === 2))
|
|
142
|
-
throw new Error("Exclude policy requires snapshot version 4 and selection version 2.");
|
|
143
|
-
}
|
|
144
|
-
function sameSyncInclude(left, right) {
|
|
145
|
-
const normalizedLeft = normalizeSyncInclude(left);
|
|
146
|
-
const normalizedRight = normalizeSyncInclude(right);
|
|
147
|
-
return normalizedLeft.length === normalizedRight.length && normalizedLeft.every((item, index) => item === normalizedRight[index]);
|
|
148
|
-
}
|
|
149
|
-
function compareSyncInclude(local, remote) {
|
|
150
|
-
const localInclude = normalizeSyncInclude(local);
|
|
151
|
-
const remoteInclude = normalizeSyncInclude(remote);
|
|
152
|
-
const localSet = new Set(localInclude);
|
|
153
|
-
const remoteSet = new Set(remoteInclude);
|
|
154
|
-
return {
|
|
155
|
-
same: sameSyncInclude(localInclude, remoteInclude),
|
|
156
|
-
remoteOnly: remoteInclude.filter((item) => !localSet.has(item)),
|
|
157
|
-
localOnly: localInclude.filter((item) => !remoteSet.has(item))
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
function inspectRemoteSelection(localInclude, snapshot, localExclude) {
|
|
161
|
-
const remoteInclude = snapshotSelectionInclude(snapshot);
|
|
162
|
-
if (!remoteInclude) return { kind: "legacy", discovered: discoverLegacySnapshotInclude(snapshot) };
|
|
163
|
-
const exclude = snapshotSelectionExclude(snapshot);
|
|
164
|
-
const comparison = compareSyncInclude(localInclude, remoteInclude);
|
|
165
|
-
const rules = exclude === void 0 ? {} : { exclude };
|
|
166
|
-
return comparison.same && sameSyncExclude(localExclude, exclude) ? { kind: "same", include: remoteInclude, ...rules } : {
|
|
167
|
-
kind: "different",
|
|
168
|
-
include: remoteInclude,
|
|
169
|
-
...comparison,
|
|
170
|
-
...rules,
|
|
171
|
-
...!sameSyncExclude(localExclude, exclude) ? { excludeChanged: true } : {}
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
var RemoteSelectionMismatchError = class extends Error {
|
|
175
|
-
decision;
|
|
176
|
-
setupName;
|
|
177
|
-
localInclude;
|
|
178
|
-
remoteInclude;
|
|
179
|
-
constructor(setupName, localInclude, remoteInclude, configIdentity = JSON.stringify([setupName, normalizeSyncInclude(localInclude)]), localExclude, remoteExclude) {
|
|
180
|
-
const local = normalizeSyncInclude(localInclude);
|
|
181
|
-
const remote = normalizeSyncInclude(remoteInclude);
|
|
182
|
-
super(formatRemoteSelectionMismatch(setupName, local, remote, localExclude, remoteExclude));
|
|
183
|
-
this.name = "RemoteSelectionMismatchError";
|
|
184
|
-
this.setupName = setupName;
|
|
185
|
-
this.localInclude = local;
|
|
186
|
-
this.remoteInclude = remote;
|
|
187
|
-
this.decision = {
|
|
188
|
-
setupName,
|
|
189
|
-
configIdentity,
|
|
190
|
-
localInclude: [...local],
|
|
191
|
-
remoteInclude: [...remote],
|
|
192
|
-
...localExclude === void 0 ? {} : { localExclude: normalizeSyncExclude(localExclude) },
|
|
193
|
-
...remoteExclude === void 0 ? {} : { remoteExclude: normalizeSyncExclude(remoteExclude) }
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
function remoteSelectionMismatch(config, remoteInclude, configIdentity, remoteExclude) {
|
|
198
|
-
return new RemoteSelectionMismatchError(
|
|
199
|
-
config.setupName,
|
|
200
|
-
config.include,
|
|
201
|
-
remoteInclude,
|
|
202
|
-
configIdentity,
|
|
203
|
-
config.exclude,
|
|
204
|
-
remoteExclude
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
function formatRemoteSelectionMismatch(setupName, localInclude, remoteInclude, localExclude, remoteExclude) {
|
|
208
|
-
const comparison = compareSyncInclude(localInclude, remoteInclude);
|
|
209
|
-
const lines = [
|
|
210
|
-
`Synced content differs for sync setup \u201C${stripTerminalControls(setupName)}\u201D.`,
|
|
211
|
-
`Remote-only: ${comparison.remoteOnly.join(", ") || "none"}`,
|
|
212
|
-
`This-device-only: ${comparison.localOnly.join(", ") || "none"}`
|
|
213
|
-
];
|
|
214
|
-
if (!sameSyncExclude(localExclude, remoteExclude)) {
|
|
215
|
-
lines.push(
|
|
216
|
-
`Remote excluded paths: ${normalizeSyncExclude(remoteExclude).join(", ") || "none"}`,
|
|
217
|
-
`This device excluded paths: ${normalizeSyncExclude(localExclude).join(", ") || "none"}`
|
|
218
|
-
);
|
|
219
|
-
} else if (comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0) {
|
|
220
|
-
lines.push(
|
|
221
|
-
"Only ordering differs.",
|
|
222
|
-
`Remote order: ${remoteInclude.join(", ") || "none"}`,
|
|
223
|
-
`This device order: ${localInclude.join(", ") || "none"}`
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
lines.push("Run /sync in TUI to review both content lists and choose what happens next.");
|
|
227
|
-
return lines.join("\n");
|
|
228
|
-
}
|
|
229
|
-
function stripTerminalControls(value) {
|
|
230
|
-
return value.replace(/[\u0000-\u001f\u007f-\u009f]/gu, "?");
|
|
231
|
-
}
|
|
232
|
-
function discoverLegacySnapshotInclude(snapshot) {
|
|
233
|
-
const builtIns = /* @__PURE__ */ new Set();
|
|
234
|
-
const custom = /* @__PURE__ */ new Set();
|
|
235
|
-
let sessions = false;
|
|
236
|
-
for (const file of snapshot.files) {
|
|
237
|
-
const normalized = toPosix(file.path);
|
|
238
|
-
if (!normalized || file.path.includes("\\") || normalized.length > 4096 || normalized.startsWith("../") || path.posix.isAbsolute(normalized) || path.posix.normalize(normalized) !== normalized || // biome-ignore lint/suspicious/noControlCharactersInRegex: Ignore unsafe legacy paths.
|
|
239
|
-
/[\u0000-\u001f\u007f-\u009f]/u.test(normalized) || isDeniedPath(normalized)) {
|
|
240
|
-
continue;
|
|
241
|
-
}
|
|
242
|
-
const [topLevel, ...rest] = normalized.split("/");
|
|
243
|
-
if (!topLevel) continue;
|
|
244
|
-
if (topLevel === "sessions" && rest.length > 0) {
|
|
245
|
-
sessions = true;
|
|
246
|
-
continue;
|
|
247
|
-
}
|
|
248
|
-
const builtIn = BUILT_IN_BY_LOWER.get(topLevel.toLowerCase());
|
|
249
|
-
if (builtIn && (TOP_LEVEL_DIRS.has(builtIn) && rest.length > 0 || !TOP_LEVEL_DIRS.has(builtIn) && rest.length === 0)) {
|
|
250
|
-
builtIns.add(builtIn);
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
if (isSafeCustomIncludePath(topLevel)) custom.add(topLevel);
|
|
254
|
-
}
|
|
255
|
-
return [
|
|
256
|
-
...BUILT_IN_SYNC_ROOTS.filter((item) => builtIns.has(item)),
|
|
257
|
-
...[...custom].sort((left, right) => left.localeCompare(right)),
|
|
258
|
-
...sessions ? ["sessions"] : []
|
|
259
|
-
];
|
|
260
|
-
}
|
|
261
|
-
function syncIncludeSelection(value) {
|
|
262
|
-
const include = normalizeSyncInclude(value);
|
|
263
|
-
const builtIns = include.filter((item) => BUILT_IN_BY_LOWER.has(item.toLowerCase()));
|
|
264
|
-
const custom = include.filter((item) => item !== "sessions" && !BUILT_IN_BY_LOWER.has(item.toLowerCase()));
|
|
265
|
-
return { include, builtIns, custom, sessions: include.includes("sessions") };
|
|
266
|
-
}
|
|
267
|
-
function customIncludePathsByLower(value) {
|
|
268
|
-
return new Map(syncIncludeSelection(value).custom.map((relativePath) => [relativePath.toLowerCase(), relativePath]));
|
|
269
|
-
}
|
|
270
|
-
function includeFromSelectionConfig(config) {
|
|
271
|
-
if (config.include !== void 0) return normalizeSyncInclude(config.include);
|
|
272
|
-
return [
|
|
273
|
-
...normalizeSyncFiles(config.syncFiles),
|
|
274
|
-
...normalizeExtraFiles(config.extraFiles),
|
|
275
|
-
...config.syncSessions ? ["sessions"] : []
|
|
276
|
-
];
|
|
277
|
-
}
|
|
278
|
-
function syncSessionsSelected(config) {
|
|
279
|
-
return includeFromSelectionConfig(config).includes("sessions") && !compileSyncExclude(config.exclude)("sessions");
|
|
280
|
-
}
|
|
281
|
-
function isConfiguredSnapshotPath(relativePath, config, _legacyExtraFiles) {
|
|
282
|
-
return configuredSnapshotPathMatcher(config)(relativePath);
|
|
283
|
-
}
|
|
284
|
-
function configuredSnapshotPathMatcher(config) {
|
|
285
|
-
const selection = syncIncludeSelection(includeFromSelectionConfig(config));
|
|
286
|
-
const excluded = compileSyncExclude(config.exclude);
|
|
287
|
-
return (relativePath) => {
|
|
288
|
-
const normalized = toPosix(relativePath);
|
|
289
|
-
if (excluded(normalized)) return false;
|
|
290
|
-
if (normalized.startsWith("sessions/")) return selection.sessions;
|
|
291
|
-
const lower = normalized.toLowerCase();
|
|
292
|
-
if (!normalized.includes("/")) {
|
|
293
|
-
const builtIn = BUILT_IN_BY_LOWER.get(lower);
|
|
294
|
-
if (builtIn) return selection.builtIns.includes(builtIn) && !TOP_LEVEL_DIRS.has(builtIn);
|
|
295
|
-
}
|
|
296
|
-
const topLevel = normalized.slice(0, normalized.indexOf("/"));
|
|
297
|
-
if (selection.builtIns.includes(topLevel) && TOP_LEVEL_DIRS.has(topLevel)) return true;
|
|
298
|
-
return selection.custom.some((candidate) => {
|
|
299
|
-
const key = candidate.toLowerCase();
|
|
300
|
-
return lower === key || lower.startsWith(`${key}/`);
|
|
301
|
-
});
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
function canonicalSnapshotPathForConfig(relativePath, includePaths) {
|
|
305
|
-
const normalized = toPosix(relativePath);
|
|
306
|
-
const lower = normalized.toLowerCase();
|
|
307
|
-
return TOP_LEVEL_FILE_PATHS.get(lower) ?? includePaths.get(lower) ?? normalized;
|
|
308
|
-
}
|
|
309
|
-
function isPreservableUnmanagedSnapshotPath(relativePath) {
|
|
310
|
-
const normalized = toPosix(relativePath);
|
|
311
|
-
if (!normalized || isDeniedPath(normalized)) return false;
|
|
312
|
-
if (normalized.startsWith("sessions/")) return normalized.endsWith(".jsonl");
|
|
313
|
-
if (!normalized.includes("/")) {
|
|
314
|
-
const lower = normalized.toLowerCase();
|
|
315
|
-
return TOP_LEVEL_FILE_PATHS.has(lower) || !RESERVED_TOP_LEVEL_NAMES.has(lower);
|
|
316
|
-
}
|
|
317
|
-
return true;
|
|
318
|
-
}
|
|
319
|
-
function isSafeCustomIncludePath(relativePath) {
|
|
320
|
-
try {
|
|
321
|
-
validateAgentRelativeInclude(relativePath);
|
|
322
|
-
return true;
|
|
323
|
-
} catch {
|
|
324
|
-
return false;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
function normalizeSyncFiles(value) {
|
|
328
|
-
if (value === void 0) return [...DEFAULT_SYNC_INCLUDE];
|
|
329
|
-
if (Array.isArray(value)) {
|
|
330
|
-
return normalizeSyncInclude(value).filter(
|
|
331
|
-
(item) => BUILT_IN_BY_LOWER.has(item.toLowerCase())
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
throw new Error("Invalid pi-sync settings: expected an include array.");
|
|
335
|
-
}
|
|
336
|
-
function normalizeExtraFiles(value) {
|
|
337
|
-
if (!Array.isArray(value)) return [];
|
|
338
|
-
return value.filter((item) => typeof item === "string" && isSafeCustomIncludePath(item));
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
export {
|
|
342
|
-
BUILT_IN_SYNC_ROOTS,
|
|
343
|
-
DEFAULT_SYNC_INCLUDE,
|
|
344
|
-
normalizeSyncInclude,
|
|
345
|
-
portableSnapshotSelection,
|
|
346
|
-
snapshotSelectionInclude,
|
|
347
|
-
snapshotSelectionExclude,
|
|
348
|
-
selectionForSnapshot,
|
|
349
|
-
sameSnapshotSelection,
|
|
350
|
-
validateSnapshotSelection,
|
|
351
|
-
sameSyncInclude,
|
|
352
|
-
compareSyncInclude,
|
|
353
|
-
inspectRemoteSelection,
|
|
354
|
-
RemoteSelectionMismatchError,
|
|
355
|
-
remoteSelectionMismatch,
|
|
356
|
-
formatRemoteSelectionMismatch,
|
|
357
|
-
syncIncludeSelection,
|
|
358
|
-
customIncludePathsByLower,
|
|
359
|
-
includeFromSelectionConfig,
|
|
360
|
-
syncSessionsSelected,
|
|
361
|
-
isConfiguredSnapshotPath,
|
|
362
|
-
configuredSnapshotPathMatcher,
|
|
363
|
-
canonicalSnapshotPathForConfig,
|
|
364
|
-
isPreservableUnmanagedSnapshotPath,
|
|
365
|
-
isSafeCustomIncludePath,
|
|
366
|
-
normalizeSyncFiles,
|
|
367
|
-
normalizeExtraFiles
|
|
368
|
-
};
|
|
369
|
-
//# sourceMappingURL=chunk-WUHRVSWI.ts.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/sync/sync-policy.ts"],
|
|
4
|
-
"sourcesContent": ["import path from \"node:path\";\nimport { isDeniedPath, toPosix } from \"../paths.js\";\nimport type { Snapshot, SnapshotSelection } from \"../snapshot/snapshot-types.js\";\nimport { compileSyncExclude, normalizeSyncExclude, sameSyncExclude } from \"./exclude-policy.js\";\n\nexport const BUILT_IN_SYNC_ROOTS = [\n \"settings.json\",\n \"keybindings.json\",\n \"models.json\",\n \"AGENTS.md\",\n \"APPEND_SYSTEM.md\",\n \"skills\",\n \"prompts\",\n \"themes\",\n \"extensions\",\n] as const;\n\nexport const DEFAULT_SYNC_INCLUDE = [...BUILT_IN_SYNC_ROOTS] as const;\nexport type BuiltInSyncFile = (typeof BUILT_IN_SYNC_ROOTS)[number];\nconst MAX_SYNC_INCLUDE_ITEMS = 1_024;\nconst MAX_SYNC_INCLUDE_PATH_BYTES = 4_096;\nconst MAX_SYNC_INCLUDE_TOTAL_BYTES = 256 * 1_024;\n\ninterface IncludePathNode {\n selected?: string;\n children: Map<string, IncludePathNode>;\n}\n\nconst BUILT_IN_BY_LOWER = new Map<string, BuiltInSyncFile>(\n BUILT_IN_SYNC_ROOTS.map((fileName) => [fileName.toLowerCase(), fileName]),\n);\nconst TOP_LEVEL_FILE_PATHS = new Map<string, string>(\n BUILT_IN_SYNC_ROOTS.filter((fileName) => fileName.includes(\".\")).map((fileName) => [\n fileName.toLowerCase(),\n fileName,\n ]),\n);\nconst TOP_LEVEL_DIRS = new Set<string>(BUILT_IN_SYNC_ROOTS.filter((fileName) => !fileName.includes(\".\")));\nconst RESERVED_TOP_LEVEL_NAMES = new Set<string>([...BUILT_IN_BY_LOWER.keys(), \"sessions\"]);\n\nexport function normalizeSyncInclude(value: unknown): string[] {\n if (!Array.isArray(value)) {\n throw new Error(\"Invalid pi-sync settings: sync.include must be an array.\");\n }\n if (value.length > MAX_SYNC_INCLUDE_ITEMS) {\n throw new Error(`Invalid pi-sync settings: sync.include has too many items; limit: ${MAX_SYNC_INCLUDE_ITEMS}.`);\n }\n const result: string[] = [];\n const seen = new Set<string>();\n const pathRoot: IncludePathNode = { children: new Map() };\n let totalBytes = 0;\n for (const item of value) {\n if (typeof item !== \"string\") {\n throw new Error(\"Invalid pi-sync settings: sync.include items must be strings.\");\n }\n const itemBytes = Buffer.byteLength(item, \"utf8\");\n if (itemBytes > MAX_SYNC_INCLUDE_PATH_BYTES) {\n throw new Error(\n `Invalid pi-sync settings: sync.include item is too long; limit: ${MAX_SYNC_INCLUDE_PATH_BYTES} bytes.`,\n );\n }\n totalBytes += itemBytes;\n if (totalBytes > MAX_SYNC_INCLUDE_TOTAL_BYTES) {\n throw new Error(\n `Invalid pi-sync settings: sync.include is too large; limit: ${MAX_SYNC_INCLUDE_TOTAL_BYTES} bytes.`,\n );\n }\n const trimmed = item.trim();\n const builtIn = BUILT_IN_BY_LOWER.get(trimmed.toLowerCase());\n const normalized = builtIn ?? (trimmed.toLowerCase() === \"sessions\" ? \"sessions\" : trimmed);\n if (!builtIn && normalized !== \"sessions\") validateAgentRelativeInclude(normalized);\n const identity = normalized.toLowerCase();\n if (seen.has(identity)) {\n throw new Error(`Invalid pi-sync settings: duplicate sync.include item: ${item}`);\n }\n addIncludePath(pathRoot, identity, item);\n seen.add(identity);\n result.push(normalized);\n }\n return result;\n}\n\nfunction addIncludePath(root: IncludePathNode, identity: string, source: string) {\n let node = root;\n for (const segment of identity.split(\"/\")) {\n if (node.selected !== undefined) throwOverlappingInclude(source);\n let child = node.children.get(segment);\n if (!child) {\n child = { children: new Map() };\n node.children.set(segment, child);\n }\n node = child;\n }\n if (node.children.size > 0) throwOverlappingInclude(source);\n node.selected = identity;\n}\n\nfunction throwOverlappingInclude(item: string): never {\n throw new Error(`Invalid pi-sync settings: overlapping sync.include items are ambiguous: ${item}`);\n}\n\nfunction validateAgentRelativeInclude(value: string) {\n const normalized = toPosix(value);\n const topLevel = normalized.split(\"/\")[0]?.toLowerCase();\n if (\n !normalized ||\n normalized === \".\" ||\n normalized === \"..\" ||\n normalized.startsWith(\"../\") ||\n path.posix.isAbsolute(normalized) ||\n normalized.includes(\"\\\\\") ||\n path.posix.normalize(normalized) !== normalized ||\n // biome-ignore lint/suspicious/noControlCharactersInRegex: Include paths cannot contain controls.\n /[\\u0000-\\u001f\\u007f-\\u009f]/u.test(normalized)\n ) {\n throw new Error(`Invalid pi-sync settings: sync.include item must be a safe agent-relative path: ${value}`);\n }\n if (isDeniedPath(normalized)) {\n throw new Error(`Invalid pi-sync settings: ${value} cannot be synced.`);\n }\n if (topLevel && RESERVED_TOP_LEVEL_NAMES.has(topLevel)) {\n throw new Error(\n `Invalid pi-sync settings: use the canonical ${topLevel} root instead of a nested sync.include path.`,\n );\n }\n}\n\nexport function portableSnapshotSelection(value: unknown): SnapshotSelection {\n const selection = value as Partial<SnapshotSelection> | null;\n if (\n !selection ||\n typeof selection !== \"object\" ||\n Array.isArray(selection) ||\n (selection.version !== 1 && selection.version !== 2) ||\n !Object.hasOwn(selection, \"include\") ||\n (selection.version === 2 && !Object.hasOwn(selection, \"exclude\")) ||\n Object.keys(selection).some(\n (key) => key !== \"version\" && key !== \"include\" && !(selection.version === 2 && key === \"exclude\"),\n )\n )\n throw new Error(\"Invalid snapshot selection policy.\");\n const include = normalizeSyncInclude(selection.include);\n if (selection.version === 1) return { version: 1, include };\n if (!Array.isArray(selection.exclude)) throw new Error(\"Invalid snapshot exclude policy.\");\n return { version: 2, include, exclude: normalizeSyncExclude(selection.exclude) };\n}\n\nexport function snapshotSelectionInclude(snapshot: Pick<Snapshot, \"selection\">) {\n return snapshot.selection === undefined ? undefined : portableSnapshotSelection(snapshot.selection).include;\n}\n\nexport function snapshotSelectionExclude(snapshot: Pick<Snapshot, \"selection\">) {\n return snapshot.selection === undefined ? undefined : portableSnapshotSelection(snapshot.selection).exclude;\n}\n\nexport function selectionForSnapshot(include: unknown, exclude?: unknown): SnapshotSelection {\n const normalized = normalizeSyncInclude(include);\n return exclude === undefined\n ? { version: 1, include: normalized }\n : { version: 2, include: normalized, exclude: normalizeSyncExclude(exclude) };\n}\n\n/** Metadata equality, not policy compatibility: bind the whole projection to its immutable image. */\nexport function sameSnapshotSelection(left: SnapshotSelection | undefined, right: SnapshotSelection | undefined) {\n return (\n JSON.stringify(left === undefined ? null : portableSnapshotSelection(left)) ===\n JSON.stringify(right === undefined ? null : portableSnapshotSelection(right))\n );\n}\n\nexport function validateSnapshotSelection(snapshot: Pick<Snapshot, \"version\" | \"selection\">) {\n const selection = snapshot.selection === undefined ? undefined : portableSnapshotSelection(snapshot.selection);\n if ((snapshot.version === 4) !== (selection?.version === 2))\n throw new Error(\"Exclude policy requires snapshot version 4 and selection version 2.\");\n}\n\nexport function sameSyncInclude(left: unknown, right: unknown) {\n const normalizedLeft = normalizeSyncInclude(left);\n const normalizedRight = normalizeSyncInclude(right);\n return (\n normalizedLeft.length === normalizedRight.length &&\n normalizedLeft.every((item, index) => item === normalizedRight[index])\n );\n}\n\nexport function compareSyncInclude(local: unknown, remote: unknown) {\n const localInclude = normalizeSyncInclude(local);\n const remoteInclude = normalizeSyncInclude(remote);\n const localSet = new Set(localInclude);\n const remoteSet = new Set(remoteInclude);\n return {\n same: sameSyncInclude(localInclude, remoteInclude),\n remoteOnly: remoteInclude.filter((item) => !localSet.has(item)),\n localOnly: localInclude.filter((item) => !remoteSet.has(item)),\n };\n}\n\nexport type RemoteSelectionState =\n | { kind: \"legacy\"; discovered: string[] }\n | { kind: \"same\"; include: string[]; exclude?: string[] }\n | {\n kind: \"different\";\n include: string[];\n exclude?: string[];\n remoteOnly: string[];\n localOnly: string[];\n excludeChanged?: boolean;\n };\n\nexport function inspectRemoteSelection(\n localInclude: unknown,\n snapshot: Pick<Snapshot, \"selection\" | \"files\">,\n localExclude?: unknown,\n): RemoteSelectionState {\n const remoteInclude = snapshotSelectionInclude(snapshot);\n if (!remoteInclude) return { kind: \"legacy\", discovered: discoverLegacySnapshotInclude(snapshot) };\n const exclude = snapshotSelectionExclude(snapshot);\n const comparison = compareSyncInclude(localInclude, remoteInclude);\n const rules = exclude === undefined ? {} : { exclude };\n return comparison.same && sameSyncExclude(localExclude, exclude)\n ? { kind: \"same\", include: remoteInclude, ...rules }\n : {\n kind: \"different\",\n include: remoteInclude,\n ...comparison,\n ...rules,\n ...(!sameSyncExclude(localExclude, exclude) ? { excludeChanged: true } : {}),\n };\n}\n\nexport interface RemoteSelectionDecision {\n setupName: string;\n configIdentity: string;\n localInclude: readonly string[];\n remoteInclude: readonly string[];\n localExclude?: readonly string[];\n remoteExclude?: readonly string[];\n}\n\nexport class RemoteSelectionMismatchError extends Error {\n readonly decision: RemoteSelectionDecision;\n readonly setupName: string;\n readonly localInclude: string[];\n readonly remoteInclude: string[];\n\n constructor(\n setupName: string,\n localInclude: unknown,\n remoteInclude: unknown,\n configIdentity = JSON.stringify([setupName, normalizeSyncInclude(localInclude)]),\n localExclude?: string[],\n remoteExclude?: string[],\n ) {\n const local = normalizeSyncInclude(localInclude);\n const remote = normalizeSyncInclude(remoteInclude);\n super(formatRemoteSelectionMismatch(setupName, local, remote, localExclude, remoteExclude));\n this.name = \"RemoteSelectionMismatchError\";\n this.setupName = setupName;\n this.localInclude = local;\n this.remoteInclude = remote;\n this.decision = {\n setupName,\n configIdentity,\n localInclude: [...local],\n remoteInclude: [...remote],\n ...(localExclude === undefined ? {} : { localExclude: normalizeSyncExclude(localExclude) }),\n ...(remoteExclude === undefined ? {} : { remoteExclude: normalizeSyncExclude(remoteExclude) }),\n };\n }\n}\n\nexport function remoteSelectionMismatch(\n config: { setupName: string; include: unknown; exclude?: string[] },\n remoteInclude: unknown,\n configIdentity?: string,\n remoteExclude?: string[],\n) {\n return new RemoteSelectionMismatchError(\n config.setupName,\n config.include,\n remoteInclude,\n configIdentity,\n config.exclude,\n remoteExclude,\n );\n}\n\nexport function formatRemoteSelectionMismatch(\n setupName: string,\n localInclude: readonly string[],\n remoteInclude: readonly string[],\n localExclude?: readonly string[],\n remoteExclude?: readonly string[],\n) {\n const comparison = compareSyncInclude(localInclude, remoteInclude);\n const lines = [\n `Synced content differs for sync setup \u201C${stripTerminalControls(setupName)}\u201D.`,\n `Remote-only: ${comparison.remoteOnly.join(\", \") || \"none\"}`,\n `This-device-only: ${comparison.localOnly.join(\", \") || \"none\"}`,\n ];\n if (!sameSyncExclude(localExclude, remoteExclude)) {\n lines.push(\n `Remote excluded paths: ${normalizeSyncExclude(remoteExclude).join(\", \") || \"none\"}`,\n `This device excluded paths: ${normalizeSyncExclude(localExclude).join(\", \") || \"none\"}`,\n );\n } else if (comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0) {\n lines.push(\n \"Only ordering differs.\",\n `Remote order: ${remoteInclude.join(\", \") || \"none\"}`,\n `This device order: ${localInclude.join(\", \") || \"none\"}`,\n );\n }\n lines.push(\"Run /sync in TUI to review both content lists and choose what happens next.\");\n return lines.join(\"\\n\");\n}\n\nfunction stripTerminalControls(value: string) {\n // biome-ignore lint/suspicious/noControlCharactersInRegex: Escape untrusted terminal controls.\n return value.replace(/[\\u0000-\\u001f\\u007f-\\u009f]/gu, \"?\");\n}\n\nexport function discoverLegacySnapshotInclude(snapshot: Pick<Snapshot, \"files\">) {\n const builtIns = new Set<BuiltInSyncFile>();\n const custom = new Set<string>();\n let sessions = false;\n for (const file of snapshot.files) {\n const normalized = toPosix(file.path);\n if (\n !normalized ||\n file.path.includes(\"\\\\\") ||\n normalized.length > 4096 ||\n normalized.startsWith(\"../\") ||\n path.posix.isAbsolute(normalized) ||\n path.posix.normalize(normalized) !== normalized ||\n // biome-ignore lint/suspicious/noControlCharactersInRegex: Ignore unsafe legacy paths.\n /[\\u0000-\\u001f\\u007f-\\u009f]/u.test(normalized) ||\n isDeniedPath(normalized)\n ) {\n continue;\n }\n const [topLevel, ...rest] = normalized.split(\"/\");\n if (!topLevel) continue;\n if (topLevel === \"sessions\" && rest.length > 0) {\n sessions = true;\n continue;\n }\n const builtIn = BUILT_IN_BY_LOWER.get(topLevel.toLowerCase());\n if (\n builtIn &&\n ((TOP_LEVEL_DIRS.has(builtIn) && rest.length > 0) || (!TOP_LEVEL_DIRS.has(builtIn) && rest.length === 0))\n ) {\n builtIns.add(builtIn);\n continue;\n }\n if (isSafeCustomIncludePath(topLevel)) custom.add(topLevel);\n }\n return [\n ...BUILT_IN_SYNC_ROOTS.filter((item) => builtIns.has(item)),\n ...[...custom].sort((left, right) => left.localeCompare(right)),\n ...(sessions ? [\"sessions\"] : []),\n ];\n}\n\nexport function syncIncludeSelection(value: unknown) {\n const include = normalizeSyncInclude(value);\n const builtIns = include.filter((item): item is BuiltInSyncFile => BUILT_IN_BY_LOWER.has(item.toLowerCase()));\n const custom = include.filter((item) => item !== \"sessions\" && !BUILT_IN_BY_LOWER.has(item.toLowerCase()));\n return { include, builtIns, custom, sessions: include.includes(\"sessions\") };\n}\n\nexport function customIncludePathsByLower(value: unknown) {\n return new Map(syncIncludeSelection(value).custom.map((relativePath) => [relativePath.toLowerCase(), relativePath]));\n}\n\nexport interface SyncSelectionConfig {\n include?: unknown;\n exclude?: unknown;\n syncFiles?: unknown;\n syncSessions?: boolean;\n extraFiles?: unknown;\n}\n\nexport function includeFromSelectionConfig(config: SyncSelectionConfig) {\n if (config.include !== undefined) return normalizeSyncInclude(config.include);\n return [\n ...normalizeSyncFiles(config.syncFiles),\n ...normalizeExtraFiles(config.extraFiles),\n ...(config.syncSessions ? [\"sessions\"] : []),\n ];\n}\n\nexport function syncSessionsSelected(config: SyncSelectionConfig) {\n return includeFromSelectionConfig(config).includes(\"sessions\") && !compileSyncExclude(config.exclude)(\"sessions\");\n}\n\nexport function isConfiguredSnapshotPath(\n relativePath: string,\n config: SyncSelectionConfig,\n _legacyExtraFiles?: Set<string>,\n) {\n return configuredSnapshotPathMatcher(config)(relativePath);\n}\n\nexport function configuredSnapshotPathMatcher(config: SyncSelectionConfig) {\n const selection = syncIncludeSelection(includeFromSelectionConfig(config));\n const excluded = compileSyncExclude(config.exclude);\n return (relativePath: string) => {\n const normalized = toPosix(relativePath);\n if (excluded(normalized)) return false;\n if (normalized.startsWith(\"sessions/\")) return selection.sessions;\n const lower = normalized.toLowerCase();\n if (!normalized.includes(\"/\")) {\n const builtIn = BUILT_IN_BY_LOWER.get(lower);\n if (builtIn) return selection.builtIns.includes(builtIn) && !TOP_LEVEL_DIRS.has(builtIn);\n }\n const topLevel = normalized.slice(0, normalized.indexOf(\"/\"));\n if (selection.builtIns.includes(topLevel as BuiltInSyncFile) && TOP_LEVEL_DIRS.has(topLevel)) return true;\n return selection.custom.some((candidate) => {\n const key = candidate.toLowerCase();\n return lower === key || lower.startsWith(`${key}/`);\n });\n };\n}\n\nexport function canonicalSnapshotPathForConfig(relativePath: string, includePaths: Map<string, string>) {\n const normalized = toPosix(relativePath);\n const lower = normalized.toLowerCase();\n return TOP_LEVEL_FILE_PATHS.get(lower) ?? includePaths.get(lower) ?? normalized;\n}\n\nexport function isPreservableUnmanagedSnapshotPath(relativePath: string) {\n const normalized = toPosix(relativePath);\n if (!normalized || isDeniedPath(normalized)) return false;\n if (normalized.startsWith(\"sessions/\")) return normalized.endsWith(\".jsonl\");\n if (!normalized.includes(\"/\")) {\n const lower = normalized.toLowerCase();\n return TOP_LEVEL_FILE_PATHS.has(lower) || !RESERVED_TOP_LEVEL_NAMES.has(lower);\n }\n return true;\n}\n\nexport function isSafeCustomIncludePath(relativePath: string) {\n try {\n validateAgentRelativeInclude(relativePath);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function isBuiltInTopLevelFile(fileName: string) {\n return TOP_LEVEL_FILE_PATHS.has(path.posix.basename(fileName).toLowerCase());\n}\n\n/** Compatibility projection for backend-neutral output while callers move to sync.include. */\nexport function normalizeSyncFiles(value: unknown): BuiltInSyncFile[] {\n if (value === undefined) return [...DEFAULT_SYNC_INCLUDE];\n if (Array.isArray(value)) {\n return normalizeSyncInclude(value).filter((item): item is BuiltInSyncFile =>\n BUILT_IN_BY_LOWER.has(item.toLowerCase()),\n );\n }\n throw new Error(\"Invalid pi-sync settings: expected an include array.\");\n}\n\n/** Compatibility projection for old rendering helpers; v3 persistence never writes this split field. */\nexport function normalizeExtraFiles(value: unknown) {\n if (!Array.isArray(value)) return [];\n return value.filter((item): item is string => typeof item === \"string\" && isSafeCustomIncludePath(item));\n}\n\nexport const extraFilePathsByLower = customIncludePathsByLower;\nexport const isSafeExtraFileName = isSafeCustomIncludePath;\nexport const selectedSyncFileSet = (value: unknown) => new Set(normalizeSyncFiles(value));\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;AAAA,OAAO,UAAU;AAKV,IAAM,sBAAsB;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,uBAAuB,CAAC,GAAG,mBAAmB;AAE3D,IAAM,yBAAyB;AAC/B,IAAM,8BAA8B;AACpC,IAAM,+BAA+B,MAAM;AAO3C,IAAM,oBAAoB,IAAI;AAAA,EAC5B,oBAAoB,IAAI,CAAC,aAAa,CAAC,SAAS,YAAY,GAAG,QAAQ,CAAC;AAC1E;AACA,IAAM,uBAAuB,IAAI;AAAA,EAC/B,oBAAoB,OAAO,CAAC,aAAa,SAAS,SAAS,GAAG,CAAC,EAAE,IAAI,CAAC,aAAa;AAAA,IACjF,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AO;AAAA,EACT;AACF;AAOO,SAAS,mBAAmB,OAAmC;AACpE,MAAI,UAAU,OAAW,QAAO,CAAC,GAAG,oBAAoB;AACxD,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,qBAAqB,KAAK,EAAE;AAAA,MAAO,CAAC,SACzC,kBAAkB,IAAI,KAAK,YAAY,CAAC;AAAA,IAC1C;AAAA,EACF;AACA,QAAM,IAAI,MAAM,sDAAsD;AACxE;AAGO,SAAS,oBAAoB,OAAgB;AAClD,MAAI,CAAC,MAAM,QAAQ,KAAK,EAAG,QAAO,CAAC;AACnC,SAAO,MAAM,OAAO,CAAC,SAAyB,OAAO,SAAS,YAAY,wBAAwB,IAAI,CAAC;AACzG;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
|
|
4
|
-
// src/sync/local-field-policy.ts
|
|
5
|
-
function normalizeLocalFields(value) {
|
|
6
|
-
if (value === void 0) return [];
|
|
7
|
-
if (!Array.isArray(value) || value.length > 128 || value.some(
|
|
8
|
-
(field) => typeof field !== "string" || !field || field.length > 128 || /[\p{Cc}\p{Cf}\p{Cs}]/u.test(field) || ["__proto__", "constructor", "prototype"].includes(field)
|
|
9
|
-
))
|
|
10
|
-
throw new Error("localFields must be at most 128 safe settings.json root field names.");
|
|
11
|
-
if (new Set(value).size !== value.length) throw new Error("Duplicate localFields rule.");
|
|
12
|
-
for (const [first, second] of [
|
|
13
|
-
["defaultProvider", "defaultModel"],
|
|
14
|
-
["skills", "enableSkillCommands"],
|
|
15
|
-
["queueMode", "steeringMode"],
|
|
16
|
-
["websockets", "transport"],
|
|
17
|
-
["enableAnalytics", "trackingId"]
|
|
18
|
-
]) {
|
|
19
|
-
if (value.includes(first) !== value.includes(second))
|
|
20
|
-
throw new Error("Coupled settings fields must be excluded together.");
|
|
21
|
-
}
|
|
22
|
-
return [...value].sort();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export {
|
|
26
|
-
normalizeLocalFields
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=chunk-X7R6DCVF.ts.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/sync/local-field-policy.ts"],
|
|
4
|
-
"sourcesContent": ["/** Initial rules select whole root fields of the global settings.json only. */\nexport function normalizeLocalFields(value: unknown): string[] {\n if (value === undefined) return [];\n if (\n !Array.isArray(value) ||\n value.length > 128 ||\n value.some(\n (field) =>\n typeof field !== \"string\" ||\n !field ||\n field.length > 128 ||\n /[\\p{Cc}\\p{Cf}\\p{Cs}]/u.test(field) ||\n [\"__proto__\", \"constructor\", \"prototype\"].includes(field),\n )\n )\n throw new Error(\"localFields must be at most 128 safe settings.json root field names.\");\n if (new Set(value).size !== value.length) throw new Error(\"Duplicate localFields rule.\");\n for (const [first, second] of [\n [\"defaultProvider\", \"defaultModel\"],\n [\"skills\", \"enableSkillCommands\"],\n [\"queueMode\", \"steeringMode\"],\n [\"websockets\", \"transport\"],\n [\"enableAnalytics\", \"trackingId\"],\n ]) {\n if (value.includes(first) !== value.includes(second))\n throw new Error(\"Coupled settings fields must be excluded together.\");\n }\n return [...value].sort();\n}\n"],
|
|
5
|
-
"mappings": ";;;;AACO,SAAS,qBAAqB,OAA0B;AAC7D,MAAI,UAAU,OAAW,QAAO,CAAC;AACjC,MACE,CAAC,MAAM,QAAQ,KAAK,KACpB,MAAM,SAAS,OACf,MAAM;AAAA,IACJ,CAAC,UACC,OAAO,UAAU,YACjB,CAAC,SACD,MAAM,SAAS,OACf,wBAAwB,KAAK,KAAK,KAClC,CAAC,aAAa,eAAe,WAAW,EAAE,SAAS,KAAK;AAAA,EAC5D;AAEA,UAAM,IAAI,MAAM,sEAAsE;AACxF,MAAI,IAAI,IAAI,KAAK,EAAE,SAAS,MAAM,OAAQ,OAAM,IAAI,MAAM,6BAA6B;AACvF,aAAW,CAAC,OAAO,MAAM,KAAK;AAAA,IAC5B,CAAC,mBAAmB,cAAc;AAAA,IAClC,CAAC,UAAU,qBAAqB;AAAA,IAChC,CAAC,aAAa,cAAc;AAAA,IAC5B,CAAC,cAAc,WAAW;AAAA,IAC1B,CAAC,mBAAmB,YAAY;AAAA,EAClC,GAAG;AACD,QAAI,MAAM,SAAS,KAAK,MAAM,MAAM,SAAS,MAAM;AACjD,YAAM,IAAI,MAAM,oDAAoD;AAAA,EACxE;AACA,SAAO,CAAC,GAAG,KAAK,EAAE,KAAK;AACzB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
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
|
-
isDeniedPath
|
|
5
|
-
} from "./chunk-FHE2DCA2.ts";
|
|
6
|
-
|
|
7
|
-
// src/sync/file-merge-planner.ts
|
|
8
|
-
import { createHash } from "node:crypto";
|
|
9
|
-
import path from "node:path";
|
|
10
|
-
function planFileMerge(input) {
|
|
11
|
-
if (!input.selectionCompatible) return { kind: "review", reason: "selection-changed" };
|
|
12
|
-
if (input.baseline === void 0) return { kind: "review", reason: "missing-baseline" };
|
|
13
|
-
const local = indexFiles(input.local);
|
|
14
|
-
const remote = indexFiles(input.remote);
|
|
15
|
-
const baseline = input.baseline;
|
|
16
|
-
for (const [filePath, hash] of Object.entries(baseline)) {
|
|
17
|
-
validatePath(filePath);
|
|
18
|
-
if (!/^[a-f0-9]{64}$/u.test(hash)) throw new Error("Invalid merge baseline hash.");
|
|
19
|
-
}
|
|
20
|
-
const paths = [.../* @__PURE__ */ new Set([...Object.keys(baseline), ...local.keys(), ...remote.keys()])].sort();
|
|
21
|
-
const collisions = collidingPaths(paths);
|
|
22
|
-
const protectedKeys = new Set([...input.protectedPaths ?? []].map(mergePathIdentity));
|
|
23
|
-
const decisions = paths.map((filePath) => {
|
|
24
|
-
if (collisions.has(filePath)) return { kind: "conflict", path: filePath, reason: "path-collision" };
|
|
25
|
-
const left = local.get(filePath);
|
|
26
|
-
const right = remote.get(filePath);
|
|
27
|
-
const ancestor = Object.hasOwn(baseline, filePath) ? baseline[filePath] : void 0;
|
|
28
|
-
let source;
|
|
29
|
-
let file;
|
|
30
|
-
if (left?.sha256 === right?.sha256) {
|
|
31
|
-
source = "equal";
|
|
32
|
-
file = left;
|
|
33
|
-
} else if (right?.sha256 === ancestor) {
|
|
34
|
-
source = "local";
|
|
35
|
-
file = left;
|
|
36
|
-
} else if (left?.sha256 === ancestor) {
|
|
37
|
-
source = "remote";
|
|
38
|
-
file = right;
|
|
39
|
-
} else {
|
|
40
|
-
return { kind: "conflict", path: filePath, reason: "both-changed" };
|
|
41
|
-
}
|
|
42
|
-
if (source === "remote" && protectedKeys.has(mergePathIdentity(filePath))) {
|
|
43
|
-
return { kind: "conflict", path: filePath, reason: "protected-session" };
|
|
44
|
-
}
|
|
45
|
-
return { kind: "accepted", path: filePath, source, file };
|
|
46
|
-
});
|
|
47
|
-
return {
|
|
48
|
-
kind: "planned",
|
|
49
|
-
decisions,
|
|
50
|
-
conflicts: decisions.filter((decision) => decision.kind === "conflict")
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function indexFiles(files) {
|
|
54
|
-
const result = /* @__PURE__ */ new Map();
|
|
55
|
-
for (const file of files) {
|
|
56
|
-
validatePath(file.path);
|
|
57
|
-
if (result.has(file.path)) throw new Error("Duplicate merge path.");
|
|
58
|
-
if (!/^[A-Za-z0-9+/]*={0,2}$/u.test(file.contentBase64) || file.contentBase64.length % 4 !== 0 || Buffer.from(file.contentBase64, "base64").toString("base64") !== file.contentBase64 || createHash("sha256").update(Buffer.from(file.contentBase64, "base64")).digest("hex") !== file.sha256) {
|
|
59
|
-
throw new Error("Invalid merge file content or checksum.");
|
|
60
|
-
}
|
|
61
|
-
result.set(file.path, file);
|
|
62
|
-
}
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
function validatePath(filePath) {
|
|
66
|
-
if (!filePath || filePath === "." || filePath === ".." || filePath.startsWith("../") || path.posix.isAbsolute(filePath) || filePath.includes("\\") || process.platform === "win32" && // biome-ignore lint/suspicious/noControlCharactersInRegex: Native Windows filename restrictions.
|
|
67
|
-
(/[<>:"|?*\u0001-\u001f]/u.test(filePath) || filePath.split("/").some(
|
|
68
|
-
(segment) => /[ .]$/u.test(segment) || /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/iu.test(segment)
|
|
69
|
-
)) || path.posix.normalize(filePath) !== filePath || // biome-ignore lint/suspicious/noControlCharactersInRegex: Reject unsafe snapshot paths.
|
|
70
|
-
/[\u0000\ud800-\udfff]/u.test(filePath) || isDeniedPath(filePath) || filePath.startsWith("sessions/") && !filePath.endsWith(".jsonl")) {
|
|
71
|
-
throw new Error("Unsafe merge path.");
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function mergePathIdentity(filePath) {
|
|
75
|
-
return Buffer.from(filePath, "utf8").toString("utf8").normalize("NFC").toLowerCase();
|
|
76
|
-
}
|
|
77
|
-
function collidingPaths(paths) {
|
|
78
|
-
const byLower = /* @__PURE__ */ new Map();
|
|
79
|
-
for (const filePath of paths) {
|
|
80
|
-
const lower = mergePathIdentity(filePath);
|
|
81
|
-
const variants = byLower.get(lower) ?? [];
|
|
82
|
-
variants.push(filePath);
|
|
83
|
-
byLower.set(lower, variants);
|
|
84
|
-
}
|
|
85
|
-
const result = /* @__PURE__ */ new Set();
|
|
86
|
-
for (const variants of byLower.values()) {
|
|
87
|
-
if (variants.length > 1) for (const variant of variants) result.add(variant);
|
|
88
|
-
}
|
|
89
|
-
for (const filePath of paths) {
|
|
90
|
-
const segments = mergePathIdentity(filePath).split("/");
|
|
91
|
-
for (let length = 1; length < segments.length; length += 1) {
|
|
92
|
-
const ancestors = byLower.get(segments.slice(0, length).join("/"));
|
|
93
|
-
if (ancestors) {
|
|
94
|
-
result.add(filePath);
|
|
95
|
-
for (const ancestor of ancestors) result.add(ancestor);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export {
|
|
103
|
-
planFileMerge,
|
|
104
|
-
mergePathIdentity,
|
|
105
|
-
collidingPaths
|
|
106
|
-
};
|
|
107
|
-
//# sourceMappingURL=chunk-XJHQPB3E.ts.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/sync/file-merge-planner.ts"],
|
|
4
|
-
"sourcesContent": ["import { createHash } from \"node:crypto\";\nimport path from \"node:path\";\nimport { isDeniedPath } from \"../paths.js\";\nimport type { SnapshotFile } from \"../snapshot/snapshot-types.js\";\n\n/** Absence and an empty file are different states. A missing ancestor is not absence. */\nexport type FileVersion = SnapshotFile | undefined;\nexport type FileMergeDecision =\n | { kind: \"accepted\"; path: string; source: \"equal\" | \"local\" | \"remote\" | \"merged\"; file: FileVersion }\n | { kind: \"conflict\"; path: string; reason: \"both-changed\" | \"protected-session\" | \"path-collision\" };\n\nexport type FileMergePlan =\n | { kind: \"review\"; reason: \"missing-baseline\" | \"selection-changed\" }\n | { kind: \"planned\"; decisions: FileMergeDecision[]; conflicts: Extract<FileMergeDecision, { kind: \"conflict\" }>[] };\n\nexport interface FileMergeInput {\n /** Undefined means unavailable; an empty map is an established empty baseline. */\n baseline: Readonly<Record<string, string>> | undefined;\n local: readonly SnapshotFile[];\n remote: readonly SnapshotFile[];\n selectionCompatible: boolean;\n protectedPaths?: ReadonlySet<string>;\n}\n\n/** Pure, deterministic decisions only. This does not authorize publication or mutation. */\nexport function planFileMerge(input: FileMergeInput): FileMergePlan {\n if (!input.selectionCompatible) return { kind: \"review\", reason: \"selection-changed\" };\n if (input.baseline === undefined) return { kind: \"review\", reason: \"missing-baseline\" };\n const local = indexFiles(input.local);\n const remote = indexFiles(input.remote);\n const baseline = input.baseline;\n for (const [filePath, hash] of Object.entries(baseline)) {\n validatePath(filePath);\n if (!/^[a-f0-9]{64}$/u.test(hash)) throw new Error(\"Invalid merge baseline hash.\");\n }\n const paths = [...new Set([...Object.keys(baseline), ...local.keys(), ...remote.keys()])].sort();\n const collisions = collidingPaths(paths);\n const protectedKeys = new Set([...(input.protectedPaths ?? [])].map(mergePathIdentity));\n const decisions: FileMergeDecision[] = paths.map((filePath) => {\n if (collisions.has(filePath)) return { kind: \"conflict\", path: filePath, reason: \"path-collision\" };\n const left = local.get(filePath);\n const right = remote.get(filePath);\n const ancestor = Object.hasOwn(baseline, filePath) ? baseline[filePath] : undefined;\n let source: \"equal\" | \"local\" | \"remote\";\n let file: FileVersion;\n if (left?.sha256 === right?.sha256) {\n source = \"equal\";\n file = left;\n } else if (right?.sha256 === ancestor) {\n source = \"local\";\n file = left;\n } else if (left?.sha256 === ancestor) {\n source = \"remote\";\n file = right;\n } else {\n return { kind: \"conflict\", path: filePath, reason: \"both-changed\" };\n }\n if (source === \"remote\" && protectedKeys.has(mergePathIdentity(filePath))) {\n return { kind: \"conflict\", path: filePath, reason: \"protected-session\" };\n }\n return { kind: \"accepted\", path: filePath, source, file };\n });\n return {\n kind: \"planned\",\n decisions,\n conflicts: decisions.filter((decision) => decision.kind === \"conflict\"),\n };\n}\n\nfunction indexFiles(files: readonly SnapshotFile[]) {\n const result = new Map<string, SnapshotFile>();\n for (const file of files) {\n validatePath(file.path);\n if (result.has(file.path)) throw new Error(\"Duplicate merge path.\");\n if (\n !/^[A-Za-z0-9+/]*={0,2}$/u.test(file.contentBase64) ||\n file.contentBase64.length % 4 !== 0 ||\n Buffer.from(file.contentBase64, \"base64\").toString(\"base64\") !== file.contentBase64 ||\n createHash(\"sha256\").update(Buffer.from(file.contentBase64, \"base64\")).digest(\"hex\") !== file.sha256\n ) {\n throw new Error(\"Invalid merge file content or checksum.\");\n }\n result.set(file.path, file);\n }\n return result;\n}\n\nfunction validatePath(filePath: string) {\n if (\n !filePath ||\n filePath === \".\" ||\n filePath === \"..\" ||\n filePath.startsWith(\"../\") ||\n path.posix.isAbsolute(filePath) ||\n filePath.includes(\"\\\\\") ||\n (process.platform === \"win32\" &&\n // biome-ignore lint/suspicious/noControlCharactersInRegex: Native Windows filename restrictions.\n (/[<>:\"|?*\\u0001-\\u001f]/u.test(filePath) ||\n filePath\n .split(\"/\")\n .some(\n (segment) => /[ .]$/u.test(segment) || /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\\.|$)/iu.test(segment),\n ))) ||\n path.posix.normalize(filePath) !== filePath ||\n // biome-ignore lint/suspicious/noControlCharactersInRegex: Reject unsafe snapshot paths.\n /[\\u0000\\ud800-\\udfff]/u.test(filePath) ||\n isDeniedPath(filePath) ||\n (filePath.startsWith(\"sessions/\") && !filePath.endsWith(\".jsonl\"))\n ) {\n throw new Error(\"Unsafe merge path.\");\n }\n}\n\nexport function mergePathIdentity(filePath: string) {\n // Node path strings encode invalid UTF-16 as U+FFFD; context paths can still contain it.\n return Buffer.from(filePath, \"utf8\").toString(\"utf8\").normalize(\"NFC\").toLowerCase();\n}\n\n/** Conservative dependency groups: never accept a case or file/directory transition independently. */\nexport function collidingPaths(paths: readonly string[]) {\n const byLower = new Map<string, string[]>();\n for (const filePath of paths) {\n const lower = mergePathIdentity(filePath);\n const variants = byLower.get(lower) ?? [];\n variants.push(filePath);\n byLower.set(lower, variants);\n }\n const result = new Set<string>();\n for (const variants of byLower.values()) {\n if (variants.length > 1) for (const variant of variants) result.add(variant);\n }\n for (const filePath of paths) {\n const segments = mergePathIdentity(filePath).split(\"/\");\n for (let length = 1; length < segments.length; length += 1) {\n const ancestors = byLower.get(segments.slice(0, length).join(\"/\"));\n if (ancestors) {\n result.add(filePath);\n for (const ancestor of ancestors) result.add(ancestor);\n }\n }\n }\n return result;\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