@narumitw/pi-sync 0.58.0 → 0.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +12 -6
- package/dist/chunks/{agent-candidate-U2NU3GUX.ts → agent-candidate-ZHN7FTZT.ts} +9 -8
- package/dist/chunks/{agent-plan-3YXDIJXO.ts → agent-plan-ILFEUJ2E.ts} +12 -11
- package/dist/chunks/{agent-plan-3YXDIJXO.ts.map → agent-plan-ILFEUJ2E.ts.map} +1 -1
- package/dist/chunks/{agent-refusal-retry-476YGNU5.ts → agent-refusal-retry-HRMHCX2A.ts} +9 -8
- package/dist/chunks/{agent-refusal-retry-476YGNU5.ts.map → agent-refusal-retry-HRMHCX2A.ts.map} +1 -1
- package/dist/chunks/{agent-store-7GINKTS7.ts → agent-store-CCKN4DPR.ts} +3 -3
- package/dist/chunks/{agent-sync-2R4GG2MF.ts → agent-sync-EGA2I5W7.ts} +4 -4
- package/dist/chunks/{chunk-CQD2TJHE.ts → chunk-25QCU3LY.ts} +4 -4
- package/dist/chunks/{chunk-OJARL2TG.ts → chunk-2UKUKIBI.ts} +4 -4
- package/dist/chunks/{chunk-MW6KUQYA.ts → chunk-2ZZJXITS.ts} +40 -10
- package/dist/chunks/chunk-2ZZJXITS.ts.map +7 -0
- package/dist/chunks/chunk-3JTZF7Z5.ts +77 -0
- package/dist/chunks/chunk-3JTZF7Z5.ts.map +7 -0
- package/dist/chunks/{chunk-DN4IA7MR.ts → chunk-4NVHHDN2.ts} +2 -2
- package/dist/chunks/{chunk-AKMV47YC.ts → chunk-6OFMB6KK.ts} +2 -2
- package/dist/chunks/{chunk-45COPAK7.ts → chunk-6XU5HZAN.ts} +6 -6
- package/dist/chunks/{chunk-45COPAK7.ts.map → chunk-6XU5HZAN.ts.map} +2 -2
- package/dist/chunks/{chunk-Y4UVXOLQ.ts → chunk-6YGRZSCN.ts} +15 -10
- package/dist/chunks/chunk-6YGRZSCN.ts.map +7 -0
- package/dist/chunks/{chunk-XEODG2PE.ts → chunk-76HID27T.ts} +2 -2
- package/dist/chunks/{chunk-7A35ZAVO.ts → chunk-7WYF2KUO.ts} +174 -122
- package/dist/chunks/chunk-7WYF2KUO.ts.map +7 -0
- package/dist/chunks/{chunk-MMQIEDZ6.ts → chunk-APDNHB2T.ts} +78 -35
- package/dist/chunks/chunk-APDNHB2T.ts.map +7 -0
- package/dist/chunks/{chunk-U6GXGY5G.ts → chunk-DTPELCPW.ts} +4 -4
- package/dist/chunks/{chunk-TZC7GDJE.ts → chunk-ILXMZ2HU.ts} +4 -4
- package/dist/chunks/{chunk-CBLTWXAU.ts → chunk-LA3HQMFG.ts} +2 -1
- package/dist/chunks/{chunk-CBLTWXAU.ts.map → chunk-LA3HQMFG.ts.map} +2 -2
- package/dist/chunks/{chunk-ESKOPQVB.ts → chunk-MKC3PXCN.ts} +53 -32
- package/dist/chunks/chunk-MKC3PXCN.ts.map +7 -0
- package/dist/chunks/{chunk-MG66XM5U.ts → chunk-NGW4JMBF.ts} +63 -19
- package/dist/chunks/chunk-NGW4JMBF.ts.map +7 -0
- package/dist/chunks/{chunk-TIMWN2RH.ts → chunk-OQBE2OMB.ts} +13 -14
- package/dist/chunks/chunk-OQBE2OMB.ts.map +7 -0
- package/dist/chunks/{chunk-MKSMJPVA.ts → chunk-P3YD4ONV.ts} +22 -6
- package/dist/chunks/chunk-P3YD4ONV.ts.map +7 -0
- package/dist/chunks/{chunk-JYILGR3K.ts → chunk-PQ75RPUP.ts} +3 -3
- package/dist/chunks/{chunk-FLHCOJCD.ts → chunk-QQVK2XFC.ts} +13 -6
- package/dist/chunks/chunk-QQVK2XFC.ts.map +7 -0
- package/dist/chunks/{chunk-WQMYV4DW.ts → chunk-RDOX3VH5.ts} +5 -5
- package/dist/chunks/{chunk-6O3EDBRL.ts → chunk-S7D6XWHI.ts} +2 -2
- package/dist/chunks/{chunk-7ZIYU5QS.ts → chunk-SHPNS7FM.ts} +7 -7
- package/dist/chunks/{chunk-7ZIYU5QS.ts.map → chunk-SHPNS7FM.ts.map} +2 -2
- package/dist/chunks/{chunk-GNYGNHFF.ts → chunk-T2TYBLXK.ts} +2 -2
- package/dist/chunks/{chunk-6LD5KX55.ts → chunk-UZSDS4HF.ts} +13 -6
- package/dist/chunks/chunk-UZSDS4HF.ts.map +7 -0
- package/dist/chunks/{chunk-5TSCBBPP.ts → chunk-VPODHKOX.ts} +3 -3
- package/dist/chunks/{chunk-BEST45H2.ts → chunk-WEKGW7HV.ts} +17 -8
- package/dist/chunks/chunk-WEKGW7HV.ts.map +7 -0
- package/dist/chunks/{chunk-KYTT7KV4.ts → chunk-WUHRVSWI.ts} +87 -37
- package/dist/chunks/chunk-WUHRVSWI.ts.map +7 -0
- package/dist/chunks/{chunk-OVBAW7KV.ts → chunk-XZ3ZTHKR.ts} +19 -9
- package/dist/chunks/chunk-XZ3ZTHKR.ts.map +7 -0
- package/dist/chunks/{chunk-S5OCYVPS.ts → chunk-YEULK7MK.ts} +3 -3
- package/dist/chunks/{command-handler-KCB6MCWS.ts → command-handler-SDGKIQH2.ts} +17 -14
- package/dist/chunks/command-handler-SDGKIQH2.ts.map +7 -0
- package/dist/chunks/{config-HYG7G5EM.ts → config-J5VZUY4J.ts} +4 -3
- package/dist/chunks/{conflict-artifacts-J6WSDCWP.ts → conflict-artifacts-MYSH3L2J.ts} +10 -9
- package/dist/chunks/{conflict-review-GXA6Y7KY.ts → conflict-review-J6ZSPNWL.ts} +21 -20
- package/dist/chunks/{conflict-review-GXA6Y7KY.ts.map → conflict-review-J6ZSPNWL.ts.map} +1 -1
- package/dist/chunks/{continuous-record-EPHGR2DU.ts → continuous-record-OM64J27R.ts} +4 -4
- package/dist/chunks/{continuous-sync-FAFNLEUW.ts → continuous-sync-BH5SWIRV.ts} +22 -17
- package/dist/chunks/continuous-sync-BH5SWIRV.ts.map +7 -0
- package/dist/chunks/{file-selection-IELTXSGZ.ts → file-selection-7HEVPO4T.ts} +11 -8
- package/dist/chunks/file-selection-7HEVPO4T.ts.map +7 -0
- package/dist/chunks/{git-backend-KHD36W27.ts → git-backend-6CKI6CUG.ts} +12 -15
- package/dist/chunks/{git-backend-KHD36W27.ts.map → git-backend-6CKI6CUG.ts.map} +2 -2
- package/dist/chunks/{local-fields-JEKAPZKD.ts → local-fields-SR7PH66U.ts} +6 -5
- package/dist/chunks/{manager-result-dispatcher-XCYPW7RC.ts → manager-result-dispatcher-CXUP5WDP.ts} +15 -14
- package/dist/chunks/{manager-ui-FMZXKPX2.ts → manager-ui-65ZETN6F.ts} +168 -51
- package/dist/chunks/manager-ui-65ZETN6F.ts.map +7 -0
- package/dist/chunks/{merge-baseline-store-65GKUMXI.ts → merge-baseline-store-4Y2X7P2D.ts} +4 -3
- package/dist/chunks/{remote-selection-ui-MYM2YCPF.ts → remote-selection-ui-W55BQDJQ.ts} +14 -13
- package/dist/chunks/{s3-backend-L24UZ6IK.ts → s3-backend-FDK7JSDQ.ts} +8 -7
- package/dist/chunks/{s3-backend-L24UZ6IK.ts.map → s3-backend-FDK7JSDQ.ts.map} +1 -1
- package/dist/chunks/{setup-switch-KLGESLQX.ts → setup-switch-AB27ADDI.ts} +5 -4
- package/dist/chunks/{setup-wizard-ZQAK35BP.ts → setup-wizard-5FILKFLQ.ts} +6 -5
- package/dist/chunks/{setup-wizard-ZQAK35BP.ts.map → setup-wizard-5FILKFLQ.ts.map} +1 -1
- package/dist/chunks/{snapshot-RGNDYT6A.ts → snapshot-G3W2GOGB.ts} +5 -4
- package/dist/chunks/{snapshot-transaction-26BQO36S.ts → snapshot-transaction-SGRUWT73.ts} +6 -5
- package/dist/chunks/{sync-inspection-MOMLGUTD.ts → sync-inspection-MDYHZHT7.ts} +10 -9
- package/dist/chunks/{sync-operations-45APGOL3.ts → sync-operations-ZAUP65FH.ts} +40 -29
- package/dist/chunks/sync-operations-ZAUP65FH.ts.map +7 -0
- package/dist/chunks/{sync-state-7L4NT7W2.ts → sync-state-H4TFZZ7S.ts} +7 -6
- package/dist/chunks/{webdav-backend-3ZCACILP.ts → webdav-backend-UNMIAXM5.ts} +7 -6
- package/dist/chunks/{webdav-backend-3ZCACILP.ts.map → webdav-backend-UNMIAXM5.ts.map} +1 -1
- package/dist/index.ts +26 -19
- package/dist/index.ts.map +2 -2
- package/docs/exclude-policy-audit.md +54 -0
- package/docs/exclude-review-ledger.md +36 -0
- package/docs/tui-contract.md +1 -1
- package/package.json +3 -2
- package/skills/configure-pi-sync/SKILL.md +4 -3
- package/skills/configure-pi-sync/references/configuration.md +72 -13
- package/src/backends/git/git-storage.ts +12 -11
- package/src/commands/command-execution.ts +2 -2
- package/src/commands/command-handler.ts +1 -0
- package/src/settings/config.ts +9 -3
- package/src/settings/settings-management.ts +4 -3
- package/src/settings/settings-types.ts +4 -1
- package/src/settings/settings-validation.ts +8 -4
- package/src/snapshot/session-paths.ts +1 -0
- package/src/snapshot/snapshot-apply.ts +23 -7
- package/src/snapshot/snapshot-codec.ts +12 -3
- package/src/snapshot/snapshot-exclude-safety.ts +44 -0
- package/src/snapshot/snapshot-transaction.ts +12 -0
- package/src/snapshot/snapshot-types.ts +4 -4
- package/src/snapshot/snapshot.ts +71 -30
- package/src/state/merge-baseline-store.ts +9 -1
- package/src/state/state-types.ts +1 -0
- package/src/sync/automatic-sync.ts +7 -2
- package/src/sync/continuous-watch.ts +4 -2
- package/src/sync/exclude-policy.ts +84 -0
- package/src/sync/local-fields.ts +15 -4
- package/src/sync/merge-apply.ts +6 -1
- package/src/sync/merge-journal.ts +12 -3
- package/src/sync/merged-sync.ts +17 -12
- package/src/sync/partial-progress.ts +1 -0
- package/src/sync/remote-snapshot.ts +7 -8
- package/src/sync/sync-decision.ts +11 -1
- package/src/sync/sync-inspection.ts +3 -1
- package/src/sync/sync-mutations.ts +11 -4
- package/src/sync/sync-policy.ts +101 -37
- package/src/sync/sync-queries.ts +13 -3
- package/src/sync/sync-state.ts +16 -10
- package/src/ui/excluded-paths-ui.ts +106 -0
- package/src/ui/file-selection.ts +6 -3
- package/src/ui/manager-state.ts +11 -5
- package/src/ui/remote-selection-ui.ts +73 -10
- package/src/ui/settings-ui.ts +20 -5
- package/src/ui/setup/setup-actions.ts +1 -1
- package/src/ui/setup/setup-switcher.ts +3 -2
- package/src/ui/storage-connections-ui.ts +2 -2
- package/src/ui/sync-attention.ts +46 -10
- package/src/ui/sync-format.ts +13 -1
- package/dist/chunks/chunk-6LD5KX55.ts.map +0 -7
- package/dist/chunks/chunk-7A35ZAVO.ts.map +0 -7
- package/dist/chunks/chunk-BEST45H2.ts.map +0 -7
- package/dist/chunks/chunk-ESKOPQVB.ts.map +0 -7
- package/dist/chunks/chunk-FLHCOJCD.ts.map +0 -7
- package/dist/chunks/chunk-KYTT7KV4.ts.map +0 -7
- package/dist/chunks/chunk-MG66XM5U.ts.map +0 -7
- package/dist/chunks/chunk-MKSMJPVA.ts.map +0 -7
- package/dist/chunks/chunk-MMQIEDZ6.ts.map +0 -7
- package/dist/chunks/chunk-MW6KUQYA.ts.map +0 -7
- package/dist/chunks/chunk-OVBAW7KV.ts.map +0 -7
- package/dist/chunks/chunk-TIMWN2RH.ts.map +0 -7
- package/dist/chunks/chunk-Y4UVXOLQ.ts.map +0 -7
- package/dist/chunks/command-handler-KCB6MCWS.ts.map +0 -7
- package/dist/chunks/continuous-sync-FAFNLEUW.ts.map +0 -7
- package/dist/chunks/file-selection-IELTXSGZ.ts.map +0 -7
- package/dist/chunks/manager-ui-FMZXKPX2.ts.map +0 -7
- package/dist/chunks/sync-operations-45APGOL3.ts.map +0 -7
- /package/dist/chunks/{agent-candidate-U2NU3GUX.ts.map → agent-candidate-ZHN7FTZT.ts.map} +0 -0
- /package/dist/chunks/{agent-store-7GINKTS7.ts.map → agent-store-CCKN4DPR.ts.map} +0 -0
- /package/dist/chunks/{agent-sync-2R4GG2MF.ts.map → agent-sync-EGA2I5W7.ts.map} +0 -0
- /package/dist/chunks/{chunk-CQD2TJHE.ts.map → chunk-25QCU3LY.ts.map} +0 -0
- /package/dist/chunks/{chunk-OJARL2TG.ts.map → chunk-2UKUKIBI.ts.map} +0 -0
- /package/dist/chunks/{chunk-DN4IA7MR.ts.map → chunk-4NVHHDN2.ts.map} +0 -0
- /package/dist/chunks/{chunk-AKMV47YC.ts.map → chunk-6OFMB6KK.ts.map} +0 -0
- /package/dist/chunks/{chunk-XEODG2PE.ts.map → chunk-76HID27T.ts.map} +0 -0
- /package/dist/chunks/{chunk-U6GXGY5G.ts.map → chunk-DTPELCPW.ts.map} +0 -0
- /package/dist/chunks/{chunk-TZC7GDJE.ts.map → chunk-ILXMZ2HU.ts.map} +0 -0
- /package/dist/chunks/{chunk-JYILGR3K.ts.map → chunk-PQ75RPUP.ts.map} +0 -0
- /package/dist/chunks/{chunk-WQMYV4DW.ts.map → chunk-RDOX3VH5.ts.map} +0 -0
- /package/dist/chunks/{chunk-6O3EDBRL.ts.map → chunk-S7D6XWHI.ts.map} +0 -0
- /package/dist/chunks/{chunk-GNYGNHFF.ts.map → chunk-T2TYBLXK.ts.map} +0 -0
- /package/dist/chunks/{chunk-5TSCBBPP.ts.map → chunk-VPODHKOX.ts.map} +0 -0
- /package/dist/chunks/{chunk-S5OCYVPS.ts.map → chunk-YEULK7MK.ts.map} +0 -0
- /package/dist/chunks/{config-HYG7G5EM.ts.map → config-J5VZUY4J.ts.map} +0 -0
- /package/dist/chunks/{conflict-artifacts-J6WSDCWP.ts.map → conflict-artifacts-MYSH3L2J.ts.map} +0 -0
- /package/dist/chunks/{continuous-record-EPHGR2DU.ts.map → continuous-record-OM64J27R.ts.map} +0 -0
- /package/dist/chunks/{local-fields-JEKAPZKD.ts.map → local-fields-SR7PH66U.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-XCYPW7RC.ts.map → manager-result-dispatcher-CXUP5WDP.ts.map} +0 -0
- /package/dist/chunks/{merge-baseline-store-65GKUMXI.ts.map → merge-baseline-store-4Y2X7P2D.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-MYM2YCPF.ts.map → remote-selection-ui-W55BQDJQ.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-KLGESLQX.ts.map → setup-switch-AB27ADDI.ts.map} +0 -0
- /package/dist/chunks/{snapshot-RGNDYT6A.ts.map → snapshot-G3W2GOGB.ts.map} +0 -0
- /package/dist/chunks/{snapshot-transaction-26BQO36S.ts.map → snapshot-transaction-SGRUWT73.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-MOMLGUTD.ts.map → sync-inspection-MDYHZHT7.ts.map} +0 -0
- /package/dist/chunks/{sync-state-7L4NT7W2.ts.map → sync-state-H4TFZZ7S.ts.map} +0 -0
|
@@ -3,21 +3,26 @@
|
|
|
3
3
|
import {
|
|
4
4
|
DEFAULT_SYNC_INCLUDE,
|
|
5
5
|
canonicalSnapshotPathForConfig,
|
|
6
|
+
configuredSnapshotPathMatcher,
|
|
6
7
|
customIncludePathsByLower,
|
|
7
8
|
includeFromSelectionConfig,
|
|
8
|
-
isConfiguredSnapshotPath,
|
|
9
9
|
isPreservableUnmanagedSnapshotPath,
|
|
10
10
|
normalizeExtraFiles,
|
|
11
11
|
normalizeSyncFiles,
|
|
12
|
+
sameSnapshotSelection,
|
|
12
13
|
selectionForSnapshot,
|
|
14
|
+
snapshotSelectionExclude,
|
|
13
15
|
snapshotSelectionInclude,
|
|
14
16
|
syncIncludeSelection
|
|
15
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-WUHRVSWI.ts";
|
|
16
18
|
import {
|
|
17
19
|
agentDir,
|
|
18
20
|
configuredSessionDir,
|
|
19
21
|
sessionStorageRoot
|
|
20
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-LA3HQMFG.ts";
|
|
23
|
+
import {
|
|
24
|
+
compileSyncExclude
|
|
25
|
+
} from "./chunk-3JTZF7Z5.ts";
|
|
21
26
|
import {
|
|
22
27
|
isDeniedPath,
|
|
23
28
|
posixJoin,
|
|
@@ -57,7 +62,7 @@ function isSafeSnapshotPath(relativePath) {
|
|
|
57
62
|
function snapshotsMatch(left, right) {
|
|
58
63
|
const leftHashes = new Map(left.files.map((file) => [file.path, file.sha256]));
|
|
59
64
|
const rightHashes = new Map(right.files.map((file) => [file.path, file.sha256]));
|
|
60
|
-
return left.syncSessions === right.syncSessions &&
|
|
65
|
+
return left.syncSessions === right.syncSessions && sameSnapshotSelection(left.selection, right.selection) && leftHashes.size === rightHashes.size && [...leftHashes].every(([filePath, hash]) => rightHashes.get(filePath) === hash);
|
|
61
66
|
}
|
|
62
67
|
function snapshotId() {
|
|
63
68
|
return `${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}-${randomUUID().slice(0, 8)}`;
|
|
@@ -73,19 +78,30 @@ function regenerateSnapshotIdentity(snapshot) {
|
|
|
73
78
|
async function createSnapshot(profile, options = {}) {
|
|
74
79
|
options.signal?.throwIfAborted();
|
|
75
80
|
const include = effectiveInclude(options);
|
|
76
|
-
const
|
|
77
|
-
const
|
|
81
|
+
const excluded = compileSyncExclude(options.exclude);
|
|
82
|
+
const syncSessions = include.includes("sessions") && !excluded("sessions");
|
|
83
|
+
const needsSessionConfig = syncSessions || !excluded("settings.json");
|
|
84
|
+
const sessionDir = options.sessionDir ?? (needsSessionConfig ? await configuredSessionDir() : void 0);
|
|
78
85
|
options.signal?.throwIfAborted();
|
|
79
|
-
const files = await collectFiles(
|
|
86
|
+
const files = await collectFiles(
|
|
87
|
+
agentDir(),
|
|
88
|
+
{
|
|
89
|
+
include,
|
|
90
|
+
exclude: options.exclude,
|
|
91
|
+
sessionDir,
|
|
92
|
+
signal: options.signal
|
|
93
|
+
},
|
|
94
|
+
excluded
|
|
95
|
+
);
|
|
80
96
|
options.signal?.throwIfAborted();
|
|
81
97
|
return {
|
|
82
|
-
version: VERSION,
|
|
98
|
+
version: options.exclude === void 0 ? VERSION : 4,
|
|
83
99
|
id: snapshotId(),
|
|
84
100
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
85
101
|
machine: os.hostname(),
|
|
86
102
|
profile,
|
|
87
103
|
syncSessions,
|
|
88
|
-
selection: selectionForSnapshot(include),
|
|
104
|
+
selection: selectionForSnapshot(include, options.exclude),
|
|
89
105
|
files
|
|
90
106
|
};
|
|
91
107
|
}
|
|
@@ -97,7 +113,7 @@ function effectiveInclude(options) {
|
|
|
97
113
|
...options.syncSessions ? ["sessions"] : []
|
|
98
114
|
];
|
|
99
115
|
}
|
|
100
|
-
async function collectFiles(root, options = {}) {
|
|
116
|
+
async function collectFiles(root, options = {}, excluded = compileSyncExclude(options.exclude)) {
|
|
101
117
|
const signal = options.signal;
|
|
102
118
|
signal?.throwIfAborted();
|
|
103
119
|
const results = [];
|
|
@@ -106,22 +122,23 @@ async function collectFiles(root, options = {}) {
|
|
|
106
122
|
const selection = syncIncludeSelection(effectiveInclude(options));
|
|
107
123
|
const selectedFiles = new Set(selection.builtIns);
|
|
108
124
|
for (const entry of entries) {
|
|
109
|
-
if (entry.isDirectory() && TOP_LEVEL_DIRS.has(entry.name) && selectedFiles.has(entry.name)) {
|
|
110
|
-
await collectDirectory(results, root, entry.name, { signal });
|
|
125
|
+
if (entry.isDirectory() && TOP_LEVEL_DIRS.has(entry.name) && selectedFiles.has(entry.name) && !excluded(entry.name)) {
|
|
126
|
+
await collectDirectory(results, root, entry.name, { signal, excluded });
|
|
111
127
|
}
|
|
112
128
|
}
|
|
113
129
|
for (const fileName of TOP_LEVEL_FILES) {
|
|
114
|
-
if (!selectedFiles.has(fileName)) continue;
|
|
130
|
+
if (!selectedFiles.has(fileName) || excluded(fileName)) continue;
|
|
115
131
|
const entry = selectTopLevelFileEntry(entries, fileName);
|
|
116
132
|
if (entry) await addFile(results, root, entry.name, fileName, signal);
|
|
117
133
|
}
|
|
118
134
|
for (const relativePath of selection.custom) {
|
|
119
|
-
await collectIncludedPath(results, root, relativePath, signal);
|
|
135
|
+
if (!excluded(relativePath)) await collectIncludedPath(results, root, relativePath, signal, excluded);
|
|
120
136
|
}
|
|
121
|
-
if (selection.sessions) {
|
|
137
|
+
if (selection.sessions && !excluded("sessions")) {
|
|
122
138
|
try {
|
|
123
139
|
await collectDirectory(results, sessionStorageRoot(root, options.sessionDir), "", {
|
|
124
140
|
sessionsOnly: true,
|
|
141
|
+
excluded,
|
|
125
142
|
virtualPrefix: "sessions",
|
|
126
143
|
signal
|
|
127
144
|
});
|
|
@@ -132,14 +149,14 @@ async function collectFiles(root, options = {}) {
|
|
|
132
149
|
signal?.throwIfAborted();
|
|
133
150
|
return results.sort((left, right) => left.path.localeCompare(right.path));
|
|
134
151
|
}
|
|
135
|
-
async function collectIncludedPath(results, root, relativePath, signal) {
|
|
152
|
+
async function collectIncludedPath(results, root, relativePath, signal, excluded) {
|
|
136
153
|
signal?.throwIfAborted();
|
|
137
154
|
const absolutePath = safeJoin(root, relativePath);
|
|
138
155
|
try {
|
|
139
156
|
const stat = await fs.lstat(absolutePath);
|
|
140
157
|
signal?.throwIfAborted();
|
|
141
158
|
if (stat.isFile()) await addFile(results, root, relativePath, relativePath, signal);
|
|
142
|
-
else if (stat.isDirectory()) await collectDirectory(results, root, relativePath, { signal });
|
|
159
|
+
else if (stat.isDirectory()) await collectDirectory(results, root, relativePath, { signal, excluded });
|
|
143
160
|
} catch (error) {
|
|
144
161
|
if (error.code !== "ENOENT") throw error;
|
|
145
162
|
if (!relativePath.includes("/")) {
|
|
@@ -157,7 +174,7 @@ async function collectDirectory(results, root, relativeDirectory, options = {})
|
|
|
157
174
|
options.signal?.throwIfAborted();
|
|
158
175
|
const relativePath = relativeDirectory ? posixJoin(relativeDirectory, entry.name) : entry.name;
|
|
159
176
|
const snapshotPath = options.virtualPrefix ? posixJoin(options.virtualPrefix, relativePath) : relativePath;
|
|
160
|
-
if (isDeniedPath(snapshotPath)) continue;
|
|
177
|
+
if (isDeniedPath(snapshotPath) || options.excluded?.(snapshotPath)) continue;
|
|
161
178
|
if (entry.isDirectory()) {
|
|
162
179
|
await collectDirectory(results, root, relativePath, options);
|
|
163
180
|
} else if (entry.isFile() && (!options.sessionsOnly || isSessionFilePath(snapshotPath))) {
|
|
@@ -199,15 +216,17 @@ function snapshotTarget(root, relativePath, configuredSessionDir2) {
|
|
|
199
216
|
return safeJoin(root, relativePath);
|
|
200
217
|
}
|
|
201
218
|
function snapshotIncludesSessions(snapshot) {
|
|
202
|
-
return snapshot.syncSessions === true || snapshotSelectionInclude(snapshot)?.includes("sessions") === true || snapshot.files.some((file) => isSessionPath(file.path));
|
|
219
|
+
return snapshot.syncSessions === true || snapshotSelectionInclude(snapshot)?.includes("sessions") === true && !compileSyncExclude(snapshotSelectionExclude(snapshot))("sessions") || snapshot.files.some((file) => isSessionPath(file.path));
|
|
203
220
|
}
|
|
204
221
|
function filterSnapshotForConfigPolicy(snapshot, config, options = {}) {
|
|
205
222
|
const include = includeFromSelectionConfig(config);
|
|
206
223
|
const includePaths = customIncludePathsByLower(include);
|
|
224
|
+
const exclude = config.exclude ?? (snapshot.version === 4 ? [] : void 0);
|
|
207
225
|
const filtered = {
|
|
208
226
|
...snapshot,
|
|
209
|
-
|
|
210
|
-
|
|
227
|
+
version: exclude === void 0 ? snapshot.version : 4,
|
|
228
|
+
syncSessions: include.includes("sessions") && !compileSyncExclude(exclude)("sessions") ? snapshot.syncSessions : false,
|
|
229
|
+
selection: selectionForSnapshot(include, exclude),
|
|
211
230
|
files: canonicalizeSnapshotFilesForConfig(snapshot.files, config, includePaths)
|
|
212
231
|
};
|
|
213
232
|
if (!options.regenerateId || snapshotsMatch(snapshot, filtered)) return filtered;
|
|
@@ -221,9 +240,10 @@ function filterSnapshotForConfigPolicy(snapshot, config, options = {}) {
|
|
|
221
240
|
function canonicalizeSnapshotFilesForConfig(files, config, includePaths) {
|
|
222
241
|
const configuredFiles = [];
|
|
223
242
|
const extraCandidates = /* @__PURE__ */ new Map();
|
|
243
|
+
const configured = configuredSnapshotPathMatcher(config);
|
|
224
244
|
for (const file of files) {
|
|
225
245
|
const normalized = toPosix(file.path);
|
|
226
|
-
if (!isSafeSnapshotPath(file.path) || !
|
|
246
|
+
if (!isSafeSnapshotPath(file.path) || !configured(normalized)) {
|
|
227
247
|
continue;
|
|
228
248
|
}
|
|
229
249
|
if (normalized.includes("/")) {
|
|
@@ -261,7 +281,7 @@ function snapshotWithoutSessions(snapshot) {
|
|
|
261
281
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
262
282
|
machine: os.hostname(),
|
|
263
283
|
syncSessions: false,
|
|
264
|
-
...include ? { selection: selectionForSnapshot(include) } : {},
|
|
284
|
+
...include ? { selection: selectionForSnapshot(include, snapshotSelectionExclude(snapshot)) } : {},
|
|
265
285
|
files
|
|
266
286
|
};
|
|
267
287
|
}
|
|
@@ -283,10 +303,12 @@ function scanSnapshot(snapshot) {
|
|
|
283
303
|
function mergeRemotePreservedFiles(local, remote, config) {
|
|
284
304
|
const localPathNames = new Set(local.files.map((file) => file.path.toLowerCase()));
|
|
285
305
|
const preservedPathNames = /* @__PURE__ */ new Set();
|
|
306
|
+
const configured = configuredSnapshotPathMatcher(config);
|
|
307
|
+
const excluded = compileSyncExclude(config.exclude);
|
|
286
308
|
const preserved = remote.files.filter((file) => {
|
|
287
309
|
const normalized = toPosix(file.path);
|
|
288
310
|
const lower = normalized.toLowerCase();
|
|
289
|
-
if (localPathNames.has(lower) || preservedPathNames.has(lower) || !isSafeSnapshotPath(file.path) ||
|
|
311
|
+
if (localPathNames.has(lower) || preservedPathNames.has(lower) || !isSafeSnapshotPath(file.path) || configured(normalized) || excluded(normalized) || !isPreservableUnmanagedSnapshotPath(normalized)) {
|
|
290
312
|
return false;
|
|
291
313
|
}
|
|
292
314
|
preservedPathNames.add(lower);
|
|
@@ -298,14 +320,16 @@ function mergeRemotePreservedFiles(local, remote, config) {
|
|
|
298
320
|
id: snapshotId(),
|
|
299
321
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
300
322
|
machine: os.hostname(),
|
|
301
|
-
syncSessions: snapshotIncludesSessions(local) || snapshotIncludesSessions(remote),
|
|
323
|
+
syncSessions: !excluded("sessions") && (snapshotIncludesSessions(local) || snapshotIncludesSessions(remote)),
|
|
302
324
|
files: [...local.files, ...preserved].sort((left, right) => left.path.localeCompare(right.path))
|
|
303
325
|
};
|
|
304
326
|
}
|
|
305
327
|
function mergeRemoteSessionFiles(local, remote) {
|
|
328
|
+
const excluded = compileSyncExclude(snapshotSelectionExclude(local));
|
|
329
|
+
if (excluded("sessions")) return local;
|
|
306
330
|
const remoteSessions = remote.files.filter((file) => {
|
|
307
331
|
const normalized = toPosix(file.path);
|
|
308
|
-
return isSessionFilePath(normalized) && isSafeSnapshotPath(file.path);
|
|
332
|
+
return isSessionFilePath(normalized) && isSafeSnapshotPath(file.path) && !excluded(normalized);
|
|
309
333
|
});
|
|
310
334
|
if (remoteSessions.length === 0 && !snapshotIncludesSessions(remote)) return local;
|
|
311
335
|
const localInclude = snapshotSelectionInclude(local);
|
|
@@ -317,7 +341,8 @@ function mergeRemoteSessionFiles(local, remote) {
|
|
|
317
341
|
syncSessions: true,
|
|
318
342
|
...localInclude ? {
|
|
319
343
|
selection: selectionForSnapshot(
|
|
320
|
-
localInclude.includes("sessions") ? localInclude : [...localInclude, "sessions"]
|
|
344
|
+
localInclude.includes("sessions") ? localInclude : [...localInclude, "sessions"],
|
|
345
|
+
snapshotSelectionExclude(local)
|
|
321
346
|
)
|
|
322
347
|
} : {},
|
|
323
348
|
files: [...local.files.filter((file) => !isSessionPath(file.path)), ...remoteSessions].sort(
|
|
@@ -325,10 +350,6 @@ function mergeRemoteSessionFiles(local, remote) {
|
|
|
325
350
|
)
|
|
326
351
|
};
|
|
327
352
|
}
|
|
328
|
-
function sameOptionalInclude(left, right) {
|
|
329
|
-
if (!left || !right) return left === right;
|
|
330
|
-
return left.length === right.length && left.every((item, index) => item === right[index]);
|
|
331
|
-
}
|
|
332
353
|
|
|
333
354
|
export {
|
|
334
355
|
regenerateSnapshotIdentity,
|
|
@@ -345,4 +366,4 @@ export {
|
|
|
345
366
|
mergeRemotePreservedFiles,
|
|
346
367
|
mergeRemoteSessionFiles
|
|
347
368
|
};
|
|
348
|
-
//# sourceMappingURL=chunk-
|
|
369
|
+
//# sourceMappingURL=chunk-MKC3PXCN.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/snapshot/snapshot.ts"],
|
|
4
|
+
"sourcesContent": ["import { createHash, randomUUID } from \"node:crypto\";\nimport type { Dirent } from \"node:fs\";\nimport fs from \"node:fs/promises\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { isDeniedPath, posixJoin, safeJoin, toPosix } from \"../paths.js\";\nimport { agentDir, configuredSessionDir } from \"./session-paths.js\";\nimport { sessionStorageRoot } from \"./snapshot-paths.js\";\n\nexport { isDeniedPath } from \"../paths.js\";\nexport { sessionStorageRoot } from \"./snapshot-paths.js\";\n\nimport { compileSyncExclude } from \"../sync/exclude-policy.js\";\nimport {\n canonicalSnapshotPathForConfig,\n configuredSnapshotPathMatcher,\n customIncludePathsByLower,\n DEFAULT_SYNC_INCLUDE,\n includeFromSelectionConfig,\n isPreservableUnmanagedSnapshotPath,\n normalizeExtraFiles,\n normalizeSyncFiles,\n type SyncSelectionConfig,\n sameSnapshotSelection,\n selectionForSnapshot,\n snapshotSelectionExclude,\n snapshotSelectionInclude,\n syncIncludeSelection,\n} from \"../sync/sync-policy.js\";\nimport type { Snapshot, SnapshotFile, SnapshotOptions } from \"./snapshot-types.js\";\n\nexport { canonicalSnapshotPathForConfig, isConfiguredSnapshotPath } from \"../sync/sync-policy.js\";\n\nconst VERSION = 1;\nconst TOP_LEVEL_FILES: readonly string[] = DEFAULT_SYNC_INCLUDE.filter((name) => name.includes(\".\"));\nconst TOP_LEVEL_DIRS = new Set<string>(DEFAULT_SYNC_INCLUDE.filter((name) => !name.includes(\".\")));\nconst SECRET_PATTERNS = [\n /AWS_SECRET_ACCESS_KEY\\s*[=:]\\s*['\"]?[A-Za-z0-9/+]{35,}/i,\n /(ANTHROPIC|OPENAI|GEMINI|GOOGLE|FIRECRAWL|GITHUB|CLOUDFLARE|R2|S3)_[A-Z0-9_]*(KEY|TOKEN|SECRET)\\s*[=:]\\s*['\"]?[^\\s'\"]{12,}/i,\n /sk-ant-[A-Za-z0-9_-]{20,}/,\n /sk-[A-Za-z0-9]{20,}/,\n /gh[pousr]_[A-Za-z0-9_]{20,}/,\n];\n\nfunction selectTopLevelFileEntry(entries: Dirent[], fileName: string) {\n const exact = entries.find((entry) => entry.isFile() && entry.name === fileName);\n if (exact) return exact;\n const lower = fileName.toLowerCase();\n return entries\n .filter((entry) => entry.isFile() && entry.name.toLowerCase() === lower)\n .sort((left, right) => left.name.localeCompare(right.name))[0];\n}\n\nfunction sha256(value: Buffer) {\n return createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\nfunction isSafeSnapshotPath(relativePath: string) {\n if (relativePath.includes(\"\\\\\")) return false;\n const normalized = toPosix(relativePath);\n return (\n Boolean(normalized) &&\n normalized !== \".\" &&\n normalized !== \"..\" &&\n !normalized.startsWith(\"../\") &&\n !path.posix.isAbsolute(normalized) &&\n path.posix.normalize(normalized) === normalized &&\n !isDeniedPath(normalized)\n );\n}\n\nfunction snapshotsMatch(left: Snapshot, right: Snapshot) {\n const leftHashes = new Map(left.files.map((file) => [file.path, file.sha256]));\n const rightHashes = new Map(right.files.map((file) => [file.path, file.sha256]));\n return (\n left.syncSessions === right.syncSessions &&\n sameSnapshotSelection(left.selection, right.selection) &&\n leftHashes.size === rightHashes.size &&\n [...leftHashes].every(([filePath, hash]) => rightHashes.get(filePath) === hash)\n );\n}\n\nfunction snapshotId() {\n return `${new Date().toISOString().replace(/[:.]/g, \"-\")}-${randomUUID().slice(0, 8)}`;\n}\n\nexport function regenerateSnapshotIdentity(snapshot: Snapshot): Snapshot {\n return {\n ...snapshot,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n };\n}\n\nexport async function createSnapshot(profile: string, options: SnapshotOptions = {}): Promise<Snapshot> {\n options.signal?.throwIfAborted();\n const include = effectiveInclude(options);\n const excluded = compileSyncExclude(options.exclude);\n const syncSessions = include.includes(\"sessions\") && !excluded(\"sessions\");\n const needsSessionConfig = syncSessions || !excluded(\"settings.json\");\n const sessionDir = options.sessionDir ?? (needsSessionConfig ? await configuredSessionDir() : undefined);\n options.signal?.throwIfAborted();\n const files = await collectFiles(\n agentDir(),\n {\n include,\n exclude: options.exclude,\n sessionDir,\n signal: options.signal,\n },\n excluded,\n );\n options.signal?.throwIfAborted();\n return {\n version: options.exclude === undefined ? VERSION : 4,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n profile,\n syncSessions,\n selection: selectionForSnapshot(include, options.exclude),\n files,\n };\n}\n\nfunction effectiveInclude(options: SnapshotOptions) {\n if (options.include) return options.include;\n return [\n ...normalizeSyncFiles(options.syncFiles),\n ...normalizeExtraFiles(options.extraFiles),\n ...(options.syncSessions ? [\"sessions\"] : []),\n ];\n}\n\nexport async function collectFiles(\n root: string,\n options: SnapshotOptions = {},\n excluded = compileSyncExclude(options.exclude),\n): Promise<SnapshotFile[]> {\n const signal = options.signal;\n signal?.throwIfAborted();\n const results: SnapshotFile[] = [];\n const entries = await fs.readdir(root, { withFileTypes: true });\n signal?.throwIfAborted();\n const selection = syncIncludeSelection(effectiveInclude(options));\n const selectedFiles = new Set<string>(selection.builtIns);\n for (const entry of entries) {\n if (\n entry.isDirectory() &&\n TOP_LEVEL_DIRS.has(entry.name) &&\n selectedFiles.has(entry.name) &&\n !excluded(entry.name)\n ) {\n await collectDirectory(results, root, entry.name, { signal, excluded });\n }\n }\n for (const fileName of TOP_LEVEL_FILES) {\n if (!selectedFiles.has(fileName) || excluded(fileName)) continue;\n const entry = selectTopLevelFileEntry(entries, fileName);\n if (entry) await addFile(results, root, entry.name, fileName, signal);\n }\n for (const relativePath of selection.custom) {\n if (!excluded(relativePath)) await collectIncludedPath(results, root, relativePath, signal, excluded);\n }\n if (selection.sessions && !excluded(\"sessions\")) {\n try {\n await collectDirectory(results, sessionStorageRoot(root, options.sessionDir), \"\", {\n sessionsOnly: true,\n excluded,\n virtualPrefix: \"sessions\",\n signal,\n });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n }\n }\n signal?.throwIfAborted();\n return results.sort((left, right) => left.path.localeCompare(right.path));\n}\n\nasync function collectIncludedPath(\n results: SnapshotFile[],\n root: string,\n relativePath: string,\n signal?: AbortSignal,\n excluded?: (relativePath: string) => boolean,\n) {\n signal?.throwIfAborted();\n const absolutePath = safeJoin(root, relativePath);\n try {\n const stat = await fs.lstat(absolutePath);\n signal?.throwIfAborted();\n if (stat.isFile()) await addFile(results, root, relativePath, relativePath, signal);\n else if (stat.isDirectory()) await collectDirectory(results, root, relativePath, { signal, excluded });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n if (!relativePath.includes(\"/\")) {\n const entries = await fs.readdir(root, { withFileTypes: true });\n signal?.throwIfAborted();\n const entry = selectTopLevelFileEntry(entries, relativePath);\n if (entry) await addFile(results, root, entry.name, relativePath, signal);\n }\n }\n}\n\nasync function collectDirectory(\n results: SnapshotFile[],\n root: string,\n relativeDirectory: string,\n options: {\n sessionsOnly?: boolean;\n virtualPrefix?: string;\n signal?: AbortSignal;\n excluded?: (relativePath: string) => boolean;\n } = {},\n) {\n options.signal?.throwIfAborted();\n const absoluteDirectory = path.join(root, relativeDirectory);\n for (const entry of await fs.readdir(absoluteDirectory, { withFileTypes: true })) {\n options.signal?.throwIfAborted();\n const relativePath = relativeDirectory ? posixJoin(relativeDirectory, entry.name) : entry.name;\n const snapshotPath = options.virtualPrefix ? posixJoin(options.virtualPrefix, relativePath) : relativePath;\n if (isDeniedPath(snapshotPath) || options.excluded?.(snapshotPath)) continue;\n if (entry.isDirectory()) {\n await collectDirectory(results, root, relativePath, options);\n } else if (entry.isFile() && (!options.sessionsOnly || isSessionFilePath(snapshotPath))) {\n await addFile(results, root, relativePath, snapshotPath, options.signal);\n }\n }\n}\n\nasync function addFile(\n results: SnapshotFile[],\n root: string,\n relativePath: string,\n snapshotPath = relativePath,\n signal?: AbortSignal,\n) {\n signal?.throwIfAborted();\n if (!isSafeSnapshotPath(snapshotPath)) return;\n const absolutePath = safeJoin(root, relativePath);\n const content = await fs.readFile(absolutePath, { signal });\n signal?.throwIfAborted();\n results.push({\n path: snapshotPath,\n contentBase64: content.toString(\"base64\"),\n sha256: sha256(content),\n });\n}\n\nexport function isSessionPath(relativePath: string) {\n return toPosix(relativePath).startsWith(\"sessions/\");\n}\n\nexport function isSessionFilePath(relativePath: string) {\n const normalized = toPosix(relativePath);\n return isSessionPath(normalized) && normalized.endsWith(\".jsonl\");\n}\n\nexport function sessionSnapshotPathFromAbsolute(sessionFile: string, configuredSessionDir?: string) {\n const relativePath = toPosix(path.relative(sessionStorageRoot(agentDir(), configuredSessionDir), sessionFile));\n if (!relativePath || relativePath.startsWith(\"../\") || path.posix.isAbsolute(relativePath)) {\n return undefined;\n }\n const snapshotPath = posixJoin(\"sessions\", relativePath);\n return isSessionFilePath(snapshotPath) ? snapshotPath : undefined;\n}\n\nexport function snapshotTarget(root: string, relativePath: string, configuredSessionDir?: string) {\n if (isSessionPath(relativePath)) {\n return safeJoin(sessionStorageRoot(root, configuredSessionDir), relativePath.slice(\"sessions/\".length));\n }\n return safeJoin(root, relativePath);\n}\n\nexport function snapshotIncludesSessions(snapshot: Snapshot) {\n return (\n snapshot.syncSessions === true ||\n (snapshotSelectionInclude(snapshot)?.includes(\"sessions\") === true &&\n !compileSyncExclude(snapshotSelectionExclude(snapshot))(\"sessions\")) ||\n snapshot.files.some((file) => isSessionPath(file.path))\n );\n}\n\nexport function filterSnapshotForConfigPolicy(\n snapshot: Snapshot,\n config: SyncSelectionConfig,\n options: { regenerateId?: boolean } = {},\n) {\n const include = includeFromSelectionConfig(config);\n const includePaths = customIncludePathsByLower(include);\n const exclude = config.exclude ?? (snapshot.version === 4 ? [] : undefined);\n const filtered = {\n ...snapshot,\n version: exclude === undefined ? snapshot.version : 4,\n syncSessions:\n include.includes(\"sessions\") && !compileSyncExclude(exclude)(\"sessions\") ? snapshot.syncSessions : false,\n selection: selectionForSnapshot(include, exclude),\n files: canonicalizeSnapshotFilesForConfig(snapshot.files, config, includePaths),\n };\n if (!options.regenerateId || snapshotsMatch(snapshot, filtered)) return filtered;\n return {\n ...filtered,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n };\n}\n\nfunction canonicalizeSnapshotFilesForConfig(\n files: SnapshotFile[],\n config: SyncSelectionConfig,\n includePaths: Map<string, string>,\n) {\n const configuredFiles: SnapshotFile[] = [];\n const extraCandidates = new Map<string, { exact: boolean; file: SnapshotFile; originalPath: string }>();\n const configured = configuredSnapshotPathMatcher(config);\n for (const file of files) {\n const normalized = toPosix(file.path);\n if (!isSafeSnapshotPath(file.path) || !configured(normalized)) {\n continue;\n }\n if (normalized.includes(\"/\")) {\n configuredFiles.push(normalized === file.path ? file : { ...file, path: normalized });\n continue;\n }\n const topLevelPath = canonicalSnapshotPathForConfig(normalized, includePaths);\n const candidate = {\n exact: normalized === topLevelPath,\n file: { ...file, path: topLevelPath },\n originalPath: normalized,\n };\n const current = extraCandidates.get(topLevelPath.toLowerCase());\n if (!current || isPreferredExtraCandidate(candidate, current)) {\n extraCandidates.set(topLevelPath.toLowerCase(), candidate);\n }\n }\n return [...configuredFiles, ...[...extraCandidates.values()].map((candidate) => candidate.file)].sort((left, right) =>\n left.path.localeCompare(right.path),\n );\n}\n\nfunction isPreferredExtraCandidate(\n left: { exact: boolean; originalPath: string },\n right: { exact: boolean; originalPath: string },\n) {\n if (left.exact !== right.exact) return left.exact;\n return left.originalPath.localeCompare(right.originalPath) < 0;\n}\n\nexport function snapshotWithoutSessions(snapshot: Snapshot) {\n const files = snapshot.files.filter((file) => !isSessionPath(file.path));\n const include = snapshotSelectionInclude(snapshot)?.filter((item) => item !== \"sessions\");\n if (\n files.length === snapshot.files.length &&\n snapshot.syncSessions !== true &&\n include?.length === snapshot.selection?.include.length\n ) {\n return snapshot;\n }\n return {\n ...snapshot,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n syncSessions: false,\n ...(include ? { selection: selectionForSnapshot(include, snapshotSelectionExclude(snapshot)) } : {}),\n files,\n };\n}\n\nexport function scanSnapshot(snapshot: Snapshot) {\n const findings: string[] = [];\n for (const file of snapshot.files) {\n const content = Buffer.from(file.contentBase64, \"base64\");\n if (content.includes(0)) continue;\n const text = content.toString(\"utf8\");\n for (const pattern of SECRET_PATTERNS) {\n if (pattern.test(text)) {\n findings.push(file.path);\n break;\n }\n }\n }\n return findings;\n}\n\nexport function mergeRemotePreservedFiles(local: Snapshot, remote: Snapshot, config: SyncSelectionConfig) {\n const localPathNames = new Set(local.files.map((file) => file.path.toLowerCase()));\n const preservedPathNames = new Set<string>();\n const configured = configuredSnapshotPathMatcher(config);\n const excluded = compileSyncExclude(config.exclude);\n const preserved = remote.files.filter((file) => {\n const normalized = toPosix(file.path);\n const lower = normalized.toLowerCase();\n if (\n localPathNames.has(lower) ||\n preservedPathNames.has(lower) ||\n !isSafeSnapshotPath(file.path) ||\n configured(normalized) ||\n excluded(normalized) ||\n !isPreservableUnmanagedSnapshotPath(normalized)\n ) {\n return false;\n }\n preservedPathNames.add(lower);\n return true;\n });\n if (preserved.length === 0) return local;\n return {\n ...local,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n syncSessions: !excluded(\"sessions\") && (snapshotIncludesSessions(local) || snapshotIncludesSessions(remote)),\n files: [...local.files, ...preserved].sort((left, right) => left.path.localeCompare(right.path)),\n };\n}\n\nexport function mergeRemoteSessionFiles(local: Snapshot, remote: Snapshot) {\n const excluded = compileSyncExclude(snapshotSelectionExclude(local));\n if (excluded(\"sessions\")) return local;\n const remoteSessions = remote.files.filter((file) => {\n const normalized = toPosix(file.path);\n return isSessionFilePath(normalized) && isSafeSnapshotPath(file.path) && !excluded(normalized);\n });\n if (remoteSessions.length === 0 && !snapshotIncludesSessions(remote)) return local;\n const localInclude = snapshotSelectionInclude(local);\n return {\n ...local,\n id: snapshotId(),\n createdAt: new Date().toISOString(),\n machine: os.hostname(),\n syncSessions: true,\n ...(localInclude\n ? {\n selection: selectionForSnapshot(\n localInclude.includes(\"sessions\") ? localInclude : [...localInclude, \"sessions\"],\n snapshotSelectionExclude(local),\n ),\n }\n : {}),\n files: [...local.files.filter((file) => !isSessionPath(file.path)), ...remoteSessions].sort((left, right) =>\n left.path.localeCompare(right.path),\n ),\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,kBAAkB;AAEvC,OAAO,QAAQ;AACf,OAAO,QAAQ;AACf,OAAO,UAAU;AA6BjB,IAAM,UAAU;AAChB,IAAM,kBAAqC,qBAAqB,OAAO,CAAC,SAAS,KAAK,SAAS,GAAG,CAAC;AACnG,IAAM,iBAAiB,IAAI,IAAY,qBAAqB,OAAO,CAAC,SAAS,CAAC,KAAK,SAAS,GAAG,CAAC,CAAC;AACjG,IAAM,kBAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAAS,wBAAwB,SAAmB,UAAkB;AACpE,QAAM,QAAQ,QAAQ,KAAK,CAAC,UAAU,MAAM,OAAO,KAAK,MAAM,SAAS,QAAQ;AAC/E,MAAI,MAAO,QAAO;AAClB,QAAM,QAAQ,SAAS,YAAY;AACnC,SAAO,QACJ,OAAO,CAAC,UAAU,MAAM,OAAO,KAAK,MAAM,KAAK,YAAY,MAAM,KAAK,EACtE,KAAK,CAAC,MAAM,UAAU,KAAK,KAAK,cAAc,MAAM,IAAI,CAAC,EAAE,CAAC;AACjE;AAEA,SAAS,OAAO,OAAe;AAC7B,SAAO,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AACxD;AAE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O;AAC7E,QAAM,eAAe,yBAAyB,KAAK;AACnD,SAAO;AAAA,IACL,GAAG;AAAA,IACH,IAAI,WAAW;AAAA,IACf,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,IAClC,SAAS,GAAG,SAAS;AAAA,IACrB,cAAc;AAAA,IACd,GAAI,eACA;AAAA,MACE,WAAW;AAAA,QACT,aAAa,SAAS,UAAU,IAAI,eAAe,CAAC,GAAG,cAAc,UAAU;AAAA,QAC/E,yBAAyB,KAAK;AAAA,MAChC;AAAA,IACF,IACA,CAAC;AAAA,IACL,OAAO,CAAC,GAAG,MAAM,MAAM,OAAO,CAAC,SAAS,CAAC,cAAc,KAAK,IAAI,CAAC,GAAG,GAAG,cAAc,EAAE;AAAA,MAAK,CAAC,MAAM,UACjG,KAAK,KAAK,cAAc,MAAM,IAAI;AAAA,IACpC;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["configuredSessionDir"]
|
|
7
|
+
}
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
// @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
|
|
3
3
|
import {
|
|
4
4
|
readSnapshotForHead
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-OQBE2OMB.ts";
|
|
6
6
|
import {
|
|
7
7
|
createSyncBackend
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-2UKUKIBI.ts";
|
|
9
9
|
import {
|
|
10
10
|
SyncSetupReviewChangedError,
|
|
11
11
|
updateSyncSetup
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-6XU5HZAN.ts";
|
|
13
13
|
import {
|
|
14
14
|
captureMutationOwner
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-T2TYBLXK.ts";
|
|
16
16
|
import {
|
|
17
17
|
safeTerminalText
|
|
18
18
|
} from "./chunk-AMJRUXFT.ts";
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
loadConfig,
|
|
27
27
|
syncCheckConfigFingerprint,
|
|
28
28
|
syncConfigReviewFingerprint
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-XZ3ZTHKR.ts";
|
|
30
30
|
import {
|
|
31
31
|
throwIfAborted
|
|
32
32
|
} from "./chunk-PWMWOJP4.ts";
|
|
@@ -34,7 +34,10 @@ import {
|
|
|
34
34
|
compareSyncInclude,
|
|
35
35
|
inspectRemoteSelection,
|
|
36
36
|
sameSyncInclude
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-WUHRVSWI.ts";
|
|
38
|
+
import {
|
|
39
|
+
sameSyncExclude
|
|
40
|
+
} from "./chunk-3JTZF7Z5.ts";
|
|
38
41
|
|
|
39
42
|
// src/ui/remote-selection-ui.ts
|
|
40
43
|
import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
|
|
@@ -336,6 +339,22 @@ async function showSelectionDifference(ctx, initialDecision, origin, runRoute, s
|
|
|
336
339
|
validateOwner();
|
|
337
340
|
if (!acknowledged) return void 0;
|
|
338
341
|
}
|
|
342
|
+
if (state.decision.remoteExclude !== void 0 && currentConfig.exclude === void 0) {
|
|
343
|
+
onDialog?.(true);
|
|
344
|
+
let confirmed;
|
|
345
|
+
try {
|
|
346
|
+
confirmed = await ctx.ui.confirm(
|
|
347
|
+
"Adopt excluded paths?",
|
|
348
|
+
"This upgrades settings to version 6 / snapshots to version 4. Older clients must refuse them. Both content lists are saved; no files transfer and old history is not erased.",
|
|
349
|
+
{ signal: ownedSignal }
|
|
350
|
+
);
|
|
351
|
+
} finally {
|
|
352
|
+
onDialog?.(false);
|
|
353
|
+
}
|
|
354
|
+
ownedSignal.throwIfAborted();
|
|
355
|
+
validateOwner();
|
|
356
|
+
if (!confirmed) return void 0;
|
|
357
|
+
}
|
|
339
358
|
return runWithOptionalStateAccess(options, async () => {
|
|
340
359
|
const loaded = await loadAdoptionReview(state.decision, ownedSignal, factory, validateOwner);
|
|
341
360
|
ownedSignal.throwIfAborted();
|
|
@@ -357,7 +376,8 @@ async function showSelectionDifference(ctx, initialDecision, origin, runRoute, s
|
|
|
357
376
|
options.onSelectionResolved?.();
|
|
358
377
|
continuationFingerprint = syncCheckConfigFingerprint({
|
|
359
378
|
...adoption.value.config,
|
|
360
|
-
include: [...state.decision.remoteInclude]
|
|
379
|
+
include: [...state.decision.remoteInclude],
|
|
380
|
+
exclude: adoptedExclude(state.decision)
|
|
361
381
|
});
|
|
362
382
|
flowState = { decision: state.decision, saved: true };
|
|
363
383
|
return { kind: "to", screen: "saved" };
|
|
@@ -484,8 +504,8 @@ async function loadAdoptionReview(decision, signal, factory, validateOwner) {
|
|
|
484
504
|
const snapshot = await readSnapshotForHead(backend, reviewedHead, signal);
|
|
485
505
|
throwIfAborted(signal);
|
|
486
506
|
validateOwner();
|
|
487
|
-
const state = inspectRemoteSelection(config.include, snapshot);
|
|
488
|
-
if (state.kind !== "different" || !sameSyncInclude(state.include, decision.remoteInclude)) {
|
|
507
|
+
const state = inspectRemoteSelection(config.include, snapshot, config.exclude);
|
|
508
|
+
if (state.kind !== "different" || !sameSyncInclude(state.include, decision.remoteInclude) || !sameSyncExclude(state.exclude, decision.remoteExclude)) {
|
|
489
509
|
throw new StaleRemoteSelectionReviewError("Remote synced content changed while the comparison was open.");
|
|
490
510
|
}
|
|
491
511
|
return { config, backend, reviewedHead };
|
|
@@ -500,19 +520,27 @@ async function revalidateAndAdopt(review, decision, signal, validateOwner) {
|
|
|
500
520
|
const currentSnapshot = await readSnapshotForHead(review.backend, currentHead, signal);
|
|
501
521
|
throwIfAborted(signal);
|
|
502
522
|
validateOwner();
|
|
503
|
-
const currentState = inspectRemoteSelection(review.config.include, currentSnapshot);
|
|
504
|
-
if (currentState.kind !== "different" || !sameSyncInclude(currentState.include, decision.remoteInclude)) {
|
|
523
|
+
const currentState = inspectRemoteSelection(review.config.include, currentSnapshot, review.config.exclude);
|
|
524
|
+
if (currentState.kind !== "different" || !sameSyncInclude(currentState.include, decision.remoteInclude) || !sameSyncExclude(currentState.exclude, decision.remoteExclude)) {
|
|
505
525
|
throw new StaleRemoteSelectionReviewError("Remote synced content changed while the comparison was open.");
|
|
506
526
|
}
|
|
507
527
|
await updateSyncSetup(
|
|
508
528
|
decision.setupName,
|
|
509
529
|
(setup) => {
|
|
510
530
|
validateOwner();
|
|
511
|
-
return {
|
|
531
|
+
return {
|
|
532
|
+
...setup,
|
|
533
|
+
sync: {
|
|
534
|
+
...setup.sync,
|
|
535
|
+
include: [...decision.remoteInclude],
|
|
536
|
+
...adoptedExclude(decision) === void 0 ? {} : { exclude: adoptedExclude(decision) }
|
|
537
|
+
}
|
|
538
|
+
};
|
|
512
539
|
},
|
|
513
540
|
{
|
|
514
541
|
expectedConfigFingerprint: syncCheckConfigFingerprint(review.config),
|
|
515
542
|
expectedInclude: decision.localInclude,
|
|
543
|
+
upgradeExclude: adoptedExclude(decision) !== void 0,
|
|
516
544
|
signal
|
|
517
545
|
}
|
|
518
546
|
);
|
|
@@ -535,7 +563,7 @@ async function inspectConfiguredRemoteSelection(ctx, setupName, signal, factory,
|
|
|
535
563
|
return {
|
|
536
564
|
kind: "selection",
|
|
537
565
|
config,
|
|
538
|
-
state: inspectRemoteSelection(config.include, snapshot)
|
|
566
|
+
state: inspectRemoteSelection(config.include, snapshot, config.exclude)
|
|
539
567
|
};
|
|
540
568
|
}
|
|
541
569
|
async function showLegacyDiscovery(ctx, config, discovered, signal) {
|
|
@@ -578,18 +606,22 @@ async function showLegacyDiscovery(ctx, config, discovered, signal) {
|
|
|
578
606
|
isCurrent: () => !signal?.aborted
|
|
579
607
|
});
|
|
580
608
|
}
|
|
609
|
+
function adoptedExclude(decision) {
|
|
610
|
+
return decision.remoteExclude === void 0 ? decision.localExclude === void 0 ? void 0 : [] : [...decision.remoteExclude];
|
|
611
|
+
}
|
|
581
612
|
function selectionSummaryLines(decision) {
|
|
582
613
|
const comparison = compareSyncInclude(decision.localInclude, decision.remoteInclude);
|
|
583
614
|
return [
|
|
584
615
|
`Sync setup: ${safeTerminalText(decision.setupName)}`,
|
|
585
616
|
"Nothing changed. Review both lists before choosing what happens next.",
|
|
586
|
-
...
|
|
617
|
+
...excludeReviewLines(decision),
|
|
618
|
+
...comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0 && sameSyncExclude(decision.localExclude, decision.remoteExclude) ? ["Only the ordering differs; membership is the same."] : [`Remote-only paths: ${comparison.remoteOnly.length} \xB7 Device-only paths: ${comparison.localOnly.length}`]
|
|
587
619
|
];
|
|
588
620
|
}
|
|
589
621
|
function formatSelectionDifference(decision) {
|
|
590
622
|
const comparison = compareSyncInclude(decision.localInclude, decision.remoteInclude);
|
|
591
623
|
return [
|
|
592
|
-
...comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0 ? ["Only ordering differs; both lists contain the same paths.", ""] : [],
|
|
624
|
+
...comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0 && sameSyncExclude(decision.localExclude, decision.remoteExclude) ? ["Only ordering differs; both lists contain the same paths.", ""] : [],
|
|
593
625
|
"Remote-only paths:",
|
|
594
626
|
...comparison.remoteOnly.length > 0 ? comparison.remoteOnly.map((item) => `+ ${safeTerminalText(item)}`) : ["(none)"],
|
|
595
627
|
"",
|
|
@@ -602,6 +634,7 @@ function formatSelectionDifference(decision) {
|
|
|
602
634
|
"This device's ordered list:",
|
|
603
635
|
...decision.localInclude.length > 0 ? decision.localInclude.map((item, index) => `${index + 1}. ${safeTerminalText(item)}`) : ["(none)"],
|
|
604
636
|
"",
|
|
637
|
+
...excludeReviewLines(decision),
|
|
605
638
|
"Using the remote list saves settings only and does not pull files."
|
|
606
639
|
].join("\n");
|
|
607
640
|
}
|
|
@@ -611,14 +644,23 @@ function formatRemoteSelectionSummary(decision) {
|
|
|
611
644
|
`Synced content for \u201C${safeTerminalText(decision.setupName)}\u201D differs from this device.`,
|
|
612
645
|
`Remote-only: ${safeList(comparison.remoteOnly)}`,
|
|
613
646
|
`Device-only: ${safeList(comparison.localOnly)}`,
|
|
614
|
-
...comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0 ? [
|
|
647
|
+
...comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0 && sameSyncExclude(decision.localExclude, decision.remoteExclude) ? [
|
|
615
648
|
"Only ordering differs.",
|
|
616
649
|
`Remote order: ${safeList(decision.remoteInclude)}`,
|
|
617
650
|
`Device order: ${safeList(decision.localInclude)}`
|
|
618
651
|
] : [],
|
|
652
|
+
...excludeReviewLines(decision),
|
|
619
653
|
"Run /sync in TUI to choose a content list; RPC review is read-only."
|
|
620
654
|
].join("\n");
|
|
621
655
|
}
|
|
656
|
+
function excludeReviewLines(decision) {
|
|
657
|
+
if (decision.localExclude === void 0 && decision.remoteExclude === void 0) return [];
|
|
658
|
+
return [
|
|
659
|
+
`Remote excluded paths: ${safeList(decision.remoteExclude ?? [])}`,
|
|
660
|
+
`This device excluded paths: ${safeList(decision.localExclude ?? [])}`,
|
|
661
|
+
"Removed exclusions can expose or replace content; old history is not erased."
|
|
662
|
+
];
|
|
663
|
+
}
|
|
622
664
|
function formatLegacySummary(config, discovered) {
|
|
623
665
|
return `Remote snapshot for \u201C${safeTerminalText(config.setupName)}\u201D has no portable synced-content list; ${discovered.length} safe path${discovered.length === 1 ? " was" : "s were"} discovered, but the result is partial and read-only.`;
|
|
624
666
|
}
|
|
@@ -627,11 +669,13 @@ function decisionFromState(config, state) {
|
|
|
627
669
|
setupName: config.setupName,
|
|
628
670
|
configIdentity: syncConfigReviewFingerprint(config),
|
|
629
671
|
localInclude: [...config.include],
|
|
630
|
-
remoteInclude: [...state.include]
|
|
672
|
+
remoteInclude: [...state.include],
|
|
673
|
+
...config.exclude === void 0 ? {} : { localExclude: [...config.exclude] },
|
|
674
|
+
...state.exclude === void 0 ? {} : { remoteExclude: [...state.exclude] }
|
|
631
675
|
};
|
|
632
676
|
}
|
|
633
677
|
function assertLocalSelectionCurrent(config, decision) {
|
|
634
|
-
if (syncConfigReviewFingerprint(config) === decision.configIdentity && sameSyncInclude(config.include, decision.localInclude)) {
|
|
678
|
+
if (syncConfigReviewFingerprint(config) === decision.configIdentity && sameSyncInclude(config.include, decision.localInclude) && sameSyncExclude(config.exclude, decision.localExclude)) {
|
|
635
679
|
return;
|
|
636
680
|
}
|
|
637
681
|
throw new StaleRemoteSelectionReviewError(
|
|
@@ -684,4 +728,4 @@ export {
|
|
|
684
728
|
runCancellableOperation,
|
|
685
729
|
showRemoteSelectionReview
|
|
686
730
|
};
|
|
687
|
-
//# sourceMappingURL=chunk-
|
|
731
|
+
//# sourceMappingURL=chunk-NGW4JMBF.ts.map
|