@narumitw/pi-sync 0.57.9 → 0.57.11
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 +14 -0
- package/README.md +7 -1
- package/dist/chunks/{agent-candidate-GNEYR225.ts → agent-candidate-OCDPRI5G.ts} +12 -9
- package/dist/chunks/{agent-plan-3L7CRFDM.ts → agent-plan-P5B5RGZ7.ts} +22 -18
- package/dist/chunks/{agent-plan-3L7CRFDM.ts.map → agent-plan-P5B5RGZ7.ts.map} +1 -1
- package/dist/chunks/{agent-refusal-retry-RPTMUQXK.ts → agent-refusal-retry-476YGNU5.ts} +11 -8
- package/dist/chunks/{agent-refusal-retry-RPTMUQXK.ts.map → agent-refusal-retry-476YGNU5.ts.map} +1 -1
- package/dist/chunks/{agent-store-55CZOCPX.ts → agent-store-RJSMNOYP.ts} +12 -11
- package/dist/chunks/{agent-store-55CZOCPX.ts.map → agent-store-RJSMNOYP.ts.map} +1 -1
- package/dist/chunks/agent-sync-EUK2CPSS.ts +22 -0
- package/dist/chunks/{chunk-U3XRI2HF.ts → chunk-3IYAPMST.ts} +11 -11
- package/dist/chunks/{chunk-B4QZBDBT.ts → chunk-45COPAK7.ts} +10 -3
- package/dist/chunks/chunk-45COPAK7.ts.map +7 -0
- package/dist/chunks/chunk-5SFMBY5P.ts +26 -0
- package/dist/chunks/chunk-5SFMBY5P.ts.map +7 -0
- package/dist/chunks/{chunk-ED3TYIVW.ts → chunk-5TSCBBPP.ts} +5 -5
- package/dist/chunks/{chunk-5QAE3G3K.ts → chunk-67INJPKR.ts} +6 -6
- package/dist/chunks/{chunk-IWZH5KYS.ts → chunk-6LD5KX55.ts} +10 -10
- package/dist/chunks/{chunk-AAEEHR7H.ts → chunk-6O3EDBRL.ts} +2 -2
- package/dist/chunks/{chunk-CRKTAPSL.ts → chunk-7A35ZAVO.ts} +333 -237
- package/dist/chunks/chunk-7A35ZAVO.ts.map +7 -0
- package/dist/chunks/{chunk-6FVVRTL5.ts → chunk-7OLLPPLU.ts} +77 -63
- package/dist/chunks/chunk-7OLLPPLU.ts.map +7 -0
- package/dist/chunks/{chunk-PQW6GS4J.ts → chunk-7ZIYU5QS.ts} +12 -10
- package/dist/chunks/{chunk-PQW6GS4J.ts.map → chunk-7ZIYU5QS.ts.map} +1 -1
- package/dist/chunks/{chunk-S7QS4AWK.ts → chunk-AKMV47YC.ts} +5 -5
- package/dist/chunks/chunk-AR2DGDUI.ts +55 -0
- package/dist/chunks/chunk-AR2DGDUI.ts.map +7 -0
- package/dist/chunks/{chunk-GNH73BJ5.ts → chunk-BEST45H2.ts} +7 -7
- package/dist/chunks/chunk-CBLTWXAU.ts +114 -0
- package/dist/chunks/chunk-CBLTWXAU.ts.map +7 -0
- package/dist/chunks/{chunk-GP5DU62N.ts → chunk-CPT2BN6N.ts} +2 -2
- package/dist/chunks/{chunk-UPNVIUBN.ts → chunk-DN4IA7MR.ts} +6 -6
- package/dist/chunks/{chunk-PG7NMFP2.ts → chunk-DRTC4PKM.ts} +8 -8
- package/dist/chunks/chunk-ESKOPQVB.ts +348 -0
- package/dist/chunks/chunk-ESKOPQVB.ts.map +7 -0
- package/dist/chunks/{chunk-MKKF4IMY.ts → chunk-F7E3VFXU.ts} +5 -5
- package/dist/chunks/{chunk-HUZ5CR4W.ts → chunk-FHE2DCA2.ts} +3 -52
- package/dist/chunks/chunk-FHE2DCA2.ts.map +7 -0
- package/dist/chunks/{chunk-UBV24CG4.ts → chunk-FLHCOJCD.ts} +3 -3
- package/dist/chunks/chunk-GNYGNHFF.ts +27 -0
- package/dist/chunks/chunk-GNYGNHFF.ts.map +7 -0
- package/dist/chunks/chunk-KYTT7KV4.ts +319 -0
- package/dist/chunks/chunk-KYTT7KV4.ts.map +7 -0
- package/dist/chunks/{chunk-A6HU4ERM.ts → chunk-MKSMJPVA.ts} +6 -23
- package/dist/chunks/chunk-MKSMJPVA.ts.map +7 -0
- package/dist/chunks/{chunk-ORGBI36T.ts → chunk-OJARL2TG.ts} +4 -4
- package/dist/chunks/{chunk-JCH3VXIO.ts → chunk-OKPPZA4D.ts} +150 -91
- package/dist/chunks/chunk-OKPPZA4D.ts.map +7 -0
- package/dist/chunks/{chunk-QO333NM4.ts → chunk-OVBAW7KV.ts} +180 -133
- package/dist/chunks/chunk-OVBAW7KV.ts.map +7 -0
- package/dist/chunks/{chunk-GSNPASKB.ts → chunk-Q23JJW7E.ts} +6 -6
- package/dist/chunks/{chunk-YK52VDXG.ts → chunk-TIMWN2RH.ts} +10 -8
- package/dist/chunks/{chunk-YK52VDXG.ts.map → chunk-TIMWN2RH.ts.map} +1 -1
- package/dist/chunks/{chunk-UOHR7LRO.ts → chunk-TZC7GDJE.ts} +10 -22
- package/dist/chunks/chunk-TZC7GDJE.ts.map +7 -0
- package/dist/chunks/chunk-X7R6DCVF.ts +28 -0
- package/dist/chunks/chunk-X7R6DCVF.ts.map +7 -0
- package/dist/chunks/{chunk-76NB4R7U.ts → chunk-XJHQPB3E.ts} +2 -2
- package/dist/chunks/{chunk-BDB4IDM3.ts → chunk-Y4UVXOLQ.ts} +8 -6
- package/dist/chunks/{chunk-BDB4IDM3.ts.map → chunk-Y4UVXOLQ.ts.map} +1 -1
- package/dist/chunks/{chunk-P7DD5PWZ.ts → chunk-ZDDBZH72.ts} +3 -3
- package/dist/chunks/command-handler-F2E7A5T5.ts +548 -0
- package/dist/chunks/command-handler-F2E7A5T5.ts.map +7 -0
- package/dist/chunks/{config-KGIYTTXQ.ts → config-HYG7G5EM.ts} +7 -6
- package/dist/chunks/{conflict-artifacts-FXFIIBCB.ts → conflict-artifacts-J6WSDCWP.ts} +13 -9
- package/dist/chunks/{conflict-review-3X37QEIT.ts → conflict-review-2QMO2K6Q.ts} +31 -25
- package/dist/chunks/{conflict-review-3X37QEIT.ts.map → conflict-review-2QMO2K6Q.ts.map} +1 -1
- package/dist/chunks/{continuous-record-SQJ47CXN.ts → continuous-record-AH7JGYKM.ts} +8 -7
- package/dist/chunks/{continuous-sync-Q6QUD6TY.ts → continuous-sync-VRMXCA5X.ts} +33 -28
- package/dist/chunks/{continuous-sync-Q6QUD6TY.ts.map → continuous-sync-VRMXCA5X.ts.map} +1 -1
- package/dist/chunks/{file-selection-3JJYOVNR.ts → file-selection-IELTXSGZ.ts} +11 -10
- package/dist/chunks/{file-selection-3JJYOVNR.ts.map → file-selection-IELTXSGZ.ts.map} +1 -1
- package/dist/chunks/{git-backend-NYKSG5X6.ts → git-backend-KHD36W27.ts} +15 -12
- package/dist/chunks/{git-backend-NYKSG5X6.ts.map → git-backend-KHD36W27.ts.map} +1 -1
- package/dist/chunks/{local-fields-6DGYOOIK.ts → local-fields-JEKAPZKD.ts} +9 -5
- package/dist/chunks/manager-result-dispatcher-6W52NM7F.ts +32 -0
- package/dist/chunks/{manager-ui-ZH6DEC2G.ts → manager-ui-LM7DSJ2Y.ts} +124 -67
- package/dist/chunks/manager-ui-LM7DSJ2Y.ts.map +7 -0
- package/dist/chunks/{merge-baseline-store-RFCAH7KL.ts → merge-baseline-store-65GKUMXI.ts} +6 -5
- package/dist/chunks/remote-selection-ui-TD4C4W3J.ts +31 -0
- package/dist/chunks/{s3-backend-F7PR5FB3.ts → s3-backend-L24UZ6IK.ts} +24 -18
- package/dist/chunks/s3-backend-L24UZ6IK.ts.map +7 -0
- package/dist/chunks/{setup-switch-E7PHKI6J.ts → setup-switch-PIPXYPCW.ts} +6 -7
- package/dist/chunks/{setup-wizard-OVHZYXNW.ts → setup-wizard-RR5U3SUB.ts} +8 -9
- package/dist/chunks/{setup-wizard-OVHZYXNW.ts.map → setup-wizard-RR5U3SUB.ts.map} +1 -1
- package/dist/chunks/{snapshot-THS5EY2L.ts → snapshot-RGNDYT6A.ts} +10 -6
- package/dist/chunks/snapshot-transaction-26BQO36S.ts +24 -0
- package/dist/chunks/sync-inspection-MOMLGUTD.ts +25 -0
- package/dist/chunks/sync-inspection-MOMLGUTD.ts.map +7 -0
- package/dist/chunks/{sync-operations-Y72GNIQ2.ts → sync-operations-CV3TULLD.ts} +66 -57
- package/dist/chunks/{sync-operations-Y72GNIQ2.ts.map → sync-operations-CV3TULLD.ts.map} +1 -1
- package/dist/chunks/{sync-state-CFL4RRRB.ts → sync-state-7L4NT7W2.ts} +8 -5
- package/dist/chunks/sync-state-7L4NT7W2.ts.map +7 -0
- package/dist/chunks/{webdav-backend-TGFUH3SF.ts → webdav-backend-3ZCACILP.ts} +15 -12
- package/dist/chunks/{webdav-backend-TGFUH3SF.ts.map → webdav-backend-3ZCACILP.ts.map} +1 -1
- package/dist/index.ts +54 -537
- package/dist/index.ts.map +3 -3
- package/package.json +2 -2
- package/skills/configure-pi-sync/references/configuration.md +8 -1
- package/src/backends/s3/s3-client.ts +8 -1
- package/src/commands/command-execution.ts +8 -3
- package/src/paths.ts +6 -1
- package/src/settings/config-file.ts +205 -118
- package/src/settings/config.ts +2 -2
- package/src/settings/settings-management.ts +15 -1
- package/src/settings/settings-store.ts +0 -14
- package/src/settings/settings-validation.ts +1 -1
- package/src/snapshot/session-paths.ts +15 -2
- package/src/snapshot/snapshot-mutation-queues.ts +142 -0
- package/src/snapshot/snapshot-transaction-directory.ts +16 -0
- package/src/snapshot/snapshot-transaction.ts +123 -137
- package/src/sync/automatic-sync.ts +12 -6
- package/src/sync/local-field-policy.ts +29 -0
- package/src/sync/local-fields.ts +3 -29
- package/src/sync/merge-apply.ts +6 -0
- package/src/sync/mutation-owner.ts +22 -0
- package/src/sync/startup-check.ts +3 -2
- package/src/sync/sync-loaders.ts +4 -0
- package/src/sync/sync-local.ts +2 -19
- package/src/sync-extension.ts +7 -2
- package/src/ui/cancellable-operation.ts +36 -13
- package/src/ui/manager-state.ts +3 -1
- package/src/ui/manager-ui.ts +76 -24
- package/src/ui/remote-selection-ui.ts +131 -82
- package/src/ui/settings-ui.ts +2 -1
- package/dist/chunks/chunk-6FVVRTL5.ts.map +0 -7
- package/dist/chunks/chunk-A6HU4ERM.ts.map +0 -7
- package/dist/chunks/chunk-B4QZBDBT.ts.map +0 -7
- package/dist/chunks/chunk-CRKTAPSL.ts.map +0 -7
- package/dist/chunks/chunk-HUZ5CR4W.ts.map +0 -7
- package/dist/chunks/chunk-JCH3VXIO.ts.map +0 -7
- package/dist/chunks/chunk-QO333NM4.ts.map +0 -7
- package/dist/chunks/chunk-QOFMXPM5.ts +0 -735
- package/dist/chunks/chunk-QOFMXPM5.ts.map +0 -7
- package/dist/chunks/chunk-UOHR7LRO.ts.map +0 -7
- package/dist/chunks/manager-result-dispatcher-HOCM2GDA.ts +0 -24
- package/dist/chunks/manager-ui-ZH6DEC2G.ts.map +0 -7
- package/dist/chunks/remote-selection-ui-YFPGYGNE.ts +0 -23
- package/dist/chunks/s3-backend-F7PR5FB3.ts.map +0 -7
- package/dist/chunks/sync-inspection-J25EEKZK.ts +0 -21
- /package/dist/chunks/{agent-candidate-GNEYR225.ts.map → agent-candidate-OCDPRI5G.ts.map} +0 -0
- /package/dist/chunks/{config-KGIYTTXQ.ts.map → agent-sync-EUK2CPSS.ts.map} +0 -0
- /package/dist/chunks/{chunk-U3XRI2HF.ts.map → chunk-3IYAPMST.ts.map} +0 -0
- /package/dist/chunks/{chunk-ED3TYIVW.ts.map → chunk-5TSCBBPP.ts.map} +0 -0
- /package/dist/chunks/{chunk-5QAE3G3K.ts.map → chunk-67INJPKR.ts.map} +0 -0
- /package/dist/chunks/{chunk-IWZH5KYS.ts.map → chunk-6LD5KX55.ts.map} +0 -0
- /package/dist/chunks/{chunk-AAEEHR7H.ts.map → chunk-6O3EDBRL.ts.map} +0 -0
- /package/dist/chunks/{chunk-S7QS4AWK.ts.map → chunk-AKMV47YC.ts.map} +0 -0
- /package/dist/chunks/{chunk-GNH73BJ5.ts.map → chunk-BEST45H2.ts.map} +0 -0
- /package/dist/chunks/{chunk-GP5DU62N.ts.map → chunk-CPT2BN6N.ts.map} +0 -0
- /package/dist/chunks/{chunk-UPNVIUBN.ts.map → chunk-DN4IA7MR.ts.map} +0 -0
- /package/dist/chunks/{chunk-PG7NMFP2.ts.map → chunk-DRTC4PKM.ts.map} +0 -0
- /package/dist/chunks/{chunk-MKKF4IMY.ts.map → chunk-F7E3VFXU.ts.map} +0 -0
- /package/dist/chunks/{chunk-UBV24CG4.ts.map → chunk-FLHCOJCD.ts.map} +0 -0
- /package/dist/chunks/{chunk-ORGBI36T.ts.map → chunk-OJARL2TG.ts.map} +0 -0
- /package/dist/chunks/{chunk-GSNPASKB.ts.map → chunk-Q23JJW7E.ts.map} +0 -0
- /package/dist/chunks/{chunk-76NB4R7U.ts.map → chunk-XJHQPB3E.ts.map} +0 -0
- /package/dist/chunks/{chunk-P7DD5PWZ.ts.map → chunk-ZDDBZH72.ts.map} +0 -0
- /package/dist/chunks/{conflict-artifacts-FXFIIBCB.ts.map → config-HYG7G5EM.ts.map} +0 -0
- /package/dist/chunks/{continuous-record-SQJ47CXN.ts.map → conflict-artifacts-J6WSDCWP.ts.map} +0 -0
- /package/dist/chunks/{local-fields-6DGYOOIK.ts.map → continuous-record-AH7JGYKM.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-HOCM2GDA.ts.map → local-fields-JEKAPZKD.ts.map} +0 -0
- /package/dist/chunks/{merge-baseline-store-RFCAH7KL.ts.map → manager-result-dispatcher-6W52NM7F.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-YFPGYGNE.ts.map → merge-baseline-store-65GKUMXI.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-E7PHKI6J.ts.map → remote-selection-ui-TD4C4W3J.ts.map} +0 -0
- /package/dist/chunks/{snapshot-THS5EY2L.ts.map → setup-switch-PIPXYPCW.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-J25EEKZK.ts.map → snapshot-RGNDYT6A.ts.map} +0 -0
- /package/dist/chunks/{sync-state-CFL4RRRB.ts.map → snapshot-transaction-26BQO36S.ts.map} +0 -0
|
@@ -2,17 +2,13 @@ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
|
2
2
|
import { defineMenu, runMenu } from "@narumitw/pi-tui-kit";
|
|
3
3
|
import { createSyncBackend, type SyncBackendFactory } from "../backends/backend-factory.js";
|
|
4
4
|
import type { RemoteHead, SyncBackend } from "../backends/sync-backend.js";
|
|
5
|
-
import {
|
|
6
|
-
loadConfig,
|
|
7
|
-
loadPartialConfig,
|
|
8
|
-
type SyncSetupStorageReview,
|
|
9
|
-
syncConfigReviewFingerprint,
|
|
10
|
-
} from "../settings/config.js";
|
|
5
|
+
import { loadConfig, syncCheckConfigFingerprint, syncConfigReviewFingerprint } from "../settings/config.js";
|
|
11
6
|
import { SyncSetupReviewChangedError, updateSyncSetup } from "../settings/settings-management.js";
|
|
12
|
-
import type { AnySyncConfig
|
|
7
|
+
import type { AnySyncConfig } from "../settings/settings-types.js";
|
|
13
8
|
import { readSnapshotForHead } from "../sync/remote-snapshot.js";
|
|
14
9
|
import { throwIfAborted } from "../sync/signals.js";
|
|
15
10
|
import { errorMessage } from "../sync/sync-errors.js";
|
|
11
|
+
import { captureMutationOwner } from "../sync/sync-local.js";
|
|
16
12
|
import {
|
|
17
13
|
compareSyncInclude,
|
|
18
14
|
inspectRemoteSelection,
|
|
@@ -20,7 +16,12 @@ import {
|
|
|
20
16
|
type RemoteSelectionState,
|
|
21
17
|
sameSyncInclude,
|
|
22
18
|
} from "../sync/sync-policy.js";
|
|
23
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
type RunRoute,
|
|
21
|
+
type RunRouteResult,
|
|
22
|
+
runCancellableOperation,
|
|
23
|
+
runCancellableTask,
|
|
24
|
+
} from "./cancellable-operation.js";
|
|
24
25
|
import { setSyncStatus } from "./sync-status.js";
|
|
25
26
|
import { safeTerminalText } from "./terminal-text.js";
|
|
26
27
|
|
|
@@ -50,11 +51,23 @@ export async function showRemoteSelectionReview(
|
|
|
50
51
|
factory: SyncBackendFactory = createSyncBackend,
|
|
51
52
|
options: RemoteSelectionReviewOptions = {},
|
|
52
53
|
): Promise<RemoteSelectionReviewResult> {
|
|
54
|
+
const validateOwner = captureMutationOwner(ctx, signal);
|
|
55
|
+
const isCurrent = () => isReviewOwnerCurrent(validateOwner);
|
|
53
56
|
try {
|
|
57
|
+
validateOwner();
|
|
54
58
|
let decision = options.decision;
|
|
55
59
|
if (!decision) {
|
|
56
|
-
const
|
|
57
|
-
|
|
60
|
+
const inspection = await runCancellableTask(
|
|
61
|
+
ctx,
|
|
62
|
+
"Checking remote content list…",
|
|
63
|
+
(workSignal) => inspectConfiguredRemoteSelection(ctx, setupName, workSignal, factory, validateOwner),
|
|
64
|
+
{ signal, isCurrent, cancelledMessage: null },
|
|
65
|
+
);
|
|
66
|
+
if (!isCurrent()) return { kind: "stale" };
|
|
67
|
+
if (inspection.kind !== "completed") return { kind: inspection.kind === "cancelled" ? "back" : "closed" };
|
|
68
|
+
validateOwner();
|
|
69
|
+
const inspected = inspection.value;
|
|
70
|
+
if (!inspected) return { kind: "stale" };
|
|
58
71
|
// A successful fresh read can supersede an old explicit mismatch without
|
|
59
72
|
// changing local settings. This is not user cancellation or proof of file equality.
|
|
60
73
|
if (inspected.kind === "empty" || inspected.state.kind !== "different") {
|
|
@@ -95,12 +108,23 @@ export async function showRemoteSelectionReview(
|
|
|
95
108
|
signal,
|
|
96
109
|
factory,
|
|
97
110
|
options,
|
|
111
|
+
validateOwner,
|
|
98
112
|
);
|
|
99
113
|
if (result.kind !== "refresh") return result;
|
|
100
|
-
const
|
|
101
|
-
|
|
114
|
+
const refresh = await runCancellableTask(
|
|
115
|
+
ctx,
|
|
116
|
+
"Refreshing remote content list…",
|
|
117
|
+
(workSignal) =>
|
|
118
|
+
runWithOptionalStateAccess(options, () =>
|
|
119
|
+
inspectConfiguredRemoteSelection(ctx, currentDecision.setupName, workSignal, factory, validateOwner),
|
|
120
|
+
),
|
|
121
|
+
{ signal, isCurrent, cancelledMessage: null },
|
|
102
122
|
);
|
|
103
|
-
if (!
|
|
123
|
+
if (!isCurrent()) return { kind: "stale" };
|
|
124
|
+
if (refresh.kind !== "completed") return { kind: refresh.kind === "cancelled" ? "back" : "closed" };
|
|
125
|
+
validateOwner();
|
|
126
|
+
const refreshed = refresh.value;
|
|
127
|
+
if (!refreshed) return { kind: "stale" };
|
|
104
128
|
if (refreshed.kind === "empty") {
|
|
105
129
|
options.onSelectionResolved?.();
|
|
106
130
|
ctx.ui.notify("Remote storage no longer has a snapshot or synced-content list.", "warning");
|
|
@@ -119,11 +143,11 @@ export async function showRemoteSelectionReview(
|
|
|
119
143
|
currentDecision = decisionFromState(refreshed.config, refreshed.state);
|
|
120
144
|
}
|
|
121
145
|
} catch (error) {
|
|
122
|
-
if (
|
|
146
|
+
if (!isCurrent()) return { kind: "stale" };
|
|
123
147
|
ctx.ui.notify(`Could not review synced content: ${errorMessage(error)}`, "error");
|
|
124
148
|
return { kind: "back" };
|
|
125
149
|
} finally {
|
|
126
|
-
setSyncStatus(ctx, undefined);
|
|
150
|
+
if (isCurrent()) setSyncStatus(ctx, undefined);
|
|
127
151
|
}
|
|
128
152
|
}
|
|
129
153
|
|
|
@@ -137,6 +161,7 @@ async function showSelectionDifference(
|
|
|
137
161
|
sessionSignal: AbortSignal | undefined,
|
|
138
162
|
factory: SyncBackendFactory,
|
|
139
163
|
options: Pick<RemoteSelectionReviewOptions, "cancelLabel" | "onSelectionResolved" | "withStateAccess">,
|
|
164
|
+
validateOwner: () => void,
|
|
140
165
|
): Promise<DifferenceFlowResult> {
|
|
141
166
|
type Screen = "choice" | "review" | "saved";
|
|
142
167
|
type Action = "adopt" | "keep" | "cancel" | "continue" | "done";
|
|
@@ -144,8 +169,9 @@ async function showSelectionDifference(
|
|
|
144
169
|
decision: RemoteSelectionDecision;
|
|
145
170
|
saved: boolean;
|
|
146
171
|
}
|
|
172
|
+
const isCurrent = () => isReviewOwnerCurrent(validateOwner);
|
|
147
173
|
let flowState: FlowState = { decision: initialDecision, saved: false };
|
|
148
|
-
let
|
|
174
|
+
let continuationFingerprint: string | undefined;
|
|
149
175
|
let nextResult: RemoteSelectionReviewResult | undefined;
|
|
150
176
|
let refreshRequested = false;
|
|
151
177
|
const route = origin === "settings" ? "sync" : origin;
|
|
@@ -215,41 +241,58 @@ async function showSelectionDifference(
|
|
|
215
241
|
adopt: async ({ state, signal: actionSignal }) => {
|
|
216
242
|
const signal = combineSignals(sessionSignal, actionSignal);
|
|
217
243
|
try {
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
244
|
+
const adoption = await runCancellableTask(
|
|
245
|
+
ctx,
|
|
246
|
+
"Checking and saving remote content list…",
|
|
247
|
+
async (workSignal, _onCommit, onDialog) => {
|
|
248
|
+
const ownedSignal = workSignal ?? signal;
|
|
249
|
+
const currentConfig = await loadConfig(state.decision.setupName);
|
|
250
|
+
ownedSignal.throwIfAborted();
|
|
251
|
+
validateOwner();
|
|
252
|
+
assertLocalSelectionCurrent(currentConfig, state.decision);
|
|
253
|
+
if (!currentConfig.include.includes("sessions") && state.decision.remoteInclude.includes("sessions")) {
|
|
254
|
+
onDialog?.(true);
|
|
255
|
+
let acknowledged: boolean;
|
|
256
|
+
try {
|
|
257
|
+
acknowledged = await ctx.ui.confirm(
|
|
258
|
+
"Use a content list that includes session conversations?",
|
|
259
|
+
"Session JSONL may contain prompts, tool output, file paths, images, and secrets. This saves the list only; it does not pull files.",
|
|
260
|
+
{ signal: ownedSignal },
|
|
261
|
+
);
|
|
262
|
+
} finally {
|
|
263
|
+
onDialog?.(false);
|
|
264
|
+
}
|
|
265
|
+
ownedSignal.throwIfAborted();
|
|
266
|
+
validateOwner();
|
|
267
|
+
if (!acknowledged) return undefined;
|
|
268
|
+
}
|
|
269
|
+
return runWithOptionalStateAccess(options, async () => {
|
|
270
|
+
const loaded = await loadAdoptionReview(state.decision, ownedSignal, factory, validateOwner);
|
|
271
|
+
ownedSignal.throwIfAborted();
|
|
272
|
+
validateOwner();
|
|
273
|
+
await revalidateAndAdopt(loaded, state.decision, ownedSignal, validateOwner);
|
|
274
|
+
return loaded;
|
|
275
|
+
});
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
signal,
|
|
279
|
+
isCurrent,
|
|
280
|
+
cancelAcrossDialogs: true,
|
|
281
|
+
cancelledMessage: "Remote content-list adoption cancelled.",
|
|
282
|
+
},
|
|
283
|
+
);
|
|
284
|
+
if (signal.aborted || adoption.kind === "closed") return { kind: "close" as const };
|
|
285
|
+
if (adoption.kind === "cancelled" || !adoption.value) return { kind: "stay" as const };
|
|
286
|
+
validateOwner();
|
|
237
287
|
options.onSelectionResolved?.();
|
|
238
|
-
|
|
239
|
-
...
|
|
240
|
-
setupName: state.decision.setupName,
|
|
288
|
+
continuationFingerprint = syncCheckConfigFingerprint({
|
|
289
|
+
...adoption.value.config,
|
|
241
290
|
include: [...state.decision.remoteInclude],
|
|
242
|
-
|
|
243
|
-
automaticTransfer: review.config.automaticTransfer,
|
|
244
|
-
agentMode: review.config.agentMode,
|
|
245
|
-
continuous: review.config.continuous,
|
|
246
|
-
onSwitch: review.config.onSwitch,
|
|
247
|
-
showStatus: review.config.showStatus,
|
|
248
|
-
};
|
|
291
|
+
});
|
|
249
292
|
flowState = { decision: state.decision, saved: true };
|
|
250
293
|
return { kind: "to" as const, screen: "saved" as const };
|
|
251
294
|
} catch (error) {
|
|
252
|
-
if (signal.aborted) return { kind: "close" as const };
|
|
295
|
+
if (signal.aborted || !isCurrent()) return { kind: "close" as const };
|
|
253
296
|
if (isStaleReviewError(error)) {
|
|
254
297
|
ctx.ui.notify(`${errorMessage(error)} Refreshing the comparison.`, "warning");
|
|
255
298
|
refreshRequested = true;
|
|
@@ -268,6 +311,7 @@ async function showSelectionDifference(
|
|
|
268
311
|
try {
|
|
269
312
|
const latest = await loadConfig(state.decision.setupName);
|
|
270
313
|
if (signal.aborted) return { kind: "close" as const };
|
|
314
|
+
validateOwner();
|
|
271
315
|
assertLocalSelectionCurrent(latest, state.decision);
|
|
272
316
|
const result = await runCancellableOperation(
|
|
273
317
|
ctx,
|
|
@@ -283,7 +327,7 @@ async function showSelectionDifference(
|
|
|
283
327
|
);
|
|
284
328
|
return handleNestedRouteResult(result, "push");
|
|
285
329
|
} catch (error) {
|
|
286
|
-
if (signal.aborted) return { kind: "close" as const };
|
|
330
|
+
if (signal.aborted || !isCurrent()) return { kind: "close" as const };
|
|
287
331
|
if (isStaleReviewError(error)) {
|
|
288
332
|
ctx.ui.notify(`${errorMessage(error)} Refreshing the comparison.`, "warning");
|
|
289
333
|
refreshRequested = true;
|
|
@@ -294,12 +338,13 @@ async function showSelectionDifference(
|
|
|
294
338
|
}
|
|
295
339
|
},
|
|
296
340
|
continue: async ({ state, signal: actionSignal }) => {
|
|
297
|
-
if (!runRoute || !
|
|
341
|
+
if (!runRoute || !continuationFingerprint) return { kind: "stay" as const };
|
|
298
342
|
const signal = combineSignals(sessionSignal, actionSignal);
|
|
299
343
|
try {
|
|
300
|
-
const latest = await
|
|
344
|
+
const latest = await loadConfig(state.decision.setupName);
|
|
301
345
|
if (signal.aborted) return { kind: "close" as const };
|
|
302
|
-
|
|
346
|
+
validateOwner();
|
|
347
|
+
if (syncCheckConfigFingerprint(latest) !== continuationFingerprint) {
|
|
303
348
|
throw new StaleRemoteSelectionReviewError(
|
|
304
349
|
`Sync setup “${safeTerminalText(state.decision.setupName)}” changed after the remote content list was saved.`,
|
|
305
350
|
);
|
|
@@ -312,7 +357,7 @@ async function showSelectionDifference(
|
|
|
312
357
|
});
|
|
313
358
|
return handleNestedRouteResult(result, route);
|
|
314
359
|
} catch (error) {
|
|
315
|
-
if (signal.aborted) return { kind: "close" as const };
|
|
360
|
+
if (signal.aborted || !isCurrent()) return { kind: "close" as const };
|
|
316
361
|
ctx.ui.notify(`Could not continue: ${errorMessage(error)}`, "error");
|
|
317
362
|
return { kind: "stay" as const };
|
|
318
363
|
}
|
|
@@ -350,10 +395,10 @@ async function showSelectionDifference(
|
|
|
350
395
|
const menuResult = await runMenu(ctx, menu, {
|
|
351
396
|
getState: () => flowState,
|
|
352
397
|
signal: sessionSignal,
|
|
353
|
-
isCurrent
|
|
398
|
+
isCurrent,
|
|
354
399
|
onError: (_menuCtx, error) => ctx.ui.notify(errorMessage(error), "error"),
|
|
355
400
|
});
|
|
356
|
-
if (
|
|
401
|
+
if (!isCurrent() || menuResult.kind === "stale") return { kind: "stale" };
|
|
357
402
|
if (refreshRequested) return { kind: "refresh" };
|
|
358
403
|
if (nextResult) return nextResult;
|
|
359
404
|
if (menuResult.kind === "closed") {
|
|
@@ -364,7 +409,6 @@ async function showSelectionDifference(
|
|
|
364
409
|
|
|
365
410
|
interface AdoptionReview {
|
|
366
411
|
config: AnySyncConfig;
|
|
367
|
-
storageReview: SyncSetupStorageReview;
|
|
368
412
|
backend: SyncBackend;
|
|
369
413
|
reviewedHead: RemoteHead;
|
|
370
414
|
}
|
|
@@ -373,53 +417,58 @@ async function loadAdoptionReview(
|
|
|
373
417
|
decision: RemoteSelectionDecision,
|
|
374
418
|
signal: AbortSignal,
|
|
375
419
|
factory: SyncBackendFactory,
|
|
420
|
+
validateOwner: () => void,
|
|
376
421
|
): Promise<AdoptionReview> {
|
|
377
422
|
const config = await loadConfig(decision.setupName);
|
|
378
423
|
throwIfAborted(signal);
|
|
424
|
+
validateOwner();
|
|
379
425
|
assertLocalSelectionCurrent(config, decision);
|
|
380
|
-
const partial = await loadPartialConfig(decision.setupName);
|
|
381
|
-
throwIfAborted(signal);
|
|
382
|
-
if (!sameSyncInclude(partial.include, decision.localInclude)) {
|
|
383
|
-
throw new StaleRemoteSelectionReviewError(
|
|
384
|
-
`Sync setup “${safeTerminalText(decision.setupName)}” changed while the comparison was open.`,
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
426
|
const backend = await factory(config);
|
|
388
427
|
throwIfAborted(signal);
|
|
428
|
+
validateOwner();
|
|
389
429
|
const reviewedHead = await backend.readHead(signal);
|
|
390
430
|
throwIfAborted(signal);
|
|
431
|
+
validateOwner();
|
|
391
432
|
if (!reviewedHead) {
|
|
392
433
|
throw new StaleRemoteSelectionReviewError("Remote storage changed while the comparison was open.");
|
|
393
434
|
}
|
|
394
435
|
const snapshot = await readSnapshotForHead(backend, reviewedHead, signal);
|
|
395
436
|
throwIfAborted(signal);
|
|
437
|
+
validateOwner();
|
|
396
438
|
const state = inspectRemoteSelection(config.include, snapshot);
|
|
397
439
|
if (state.kind !== "different" || !sameSyncInclude(state.include, decision.remoteInclude)) {
|
|
398
440
|
throw new StaleRemoteSelectionReviewError("Remote synced content changed while the comparison was open.");
|
|
399
441
|
}
|
|
400
|
-
return { config,
|
|
442
|
+
return { config, backend, reviewedHead };
|
|
401
443
|
}
|
|
402
444
|
|
|
403
|
-
async function revalidateAndAdopt(
|
|
445
|
+
async function revalidateAndAdopt(
|
|
446
|
+
review: AdoptionReview,
|
|
447
|
+
decision: RemoteSelectionDecision,
|
|
448
|
+
signal: AbortSignal,
|
|
449
|
+
validateOwner: () => void,
|
|
450
|
+
) {
|
|
404
451
|
const currentHead = await review.backend.readHead(signal);
|
|
405
452
|
throwIfAborted(signal);
|
|
453
|
+
validateOwner();
|
|
406
454
|
if (!currentHead || !review.backend.sameRevision(review.reviewedHead.revision, currentHead.revision)) {
|
|
407
455
|
throw new StaleRemoteSelectionReviewError("Remote storage changed while the comparison was open.");
|
|
408
456
|
}
|
|
409
457
|
const currentSnapshot = await readSnapshotForHead(review.backend, currentHead, signal);
|
|
410
458
|
throwIfAborted(signal);
|
|
459
|
+
validateOwner();
|
|
411
460
|
const currentState = inspectRemoteSelection(review.config.include, currentSnapshot);
|
|
412
461
|
if (currentState.kind !== "different" || !sameSyncInclude(currentState.include, decision.remoteInclude)) {
|
|
413
462
|
throw new StaleRemoteSelectionReviewError("Remote synced content changed while the comparison was open.");
|
|
414
463
|
}
|
|
415
464
|
await updateSyncSetup(
|
|
416
465
|
decision.setupName,
|
|
417
|
-
(setup) =>
|
|
418
|
-
|
|
419
|
-
sync: { ...setup.sync, include: [...decision.remoteInclude] }
|
|
420
|
-
}
|
|
466
|
+
(setup) => {
|
|
467
|
+
validateOwner();
|
|
468
|
+
return { ...setup, sync: { ...setup.sync, include: [...decision.remoteInclude] } };
|
|
469
|
+
},
|
|
421
470
|
{
|
|
422
|
-
|
|
471
|
+
expectedConfigFingerprint: syncCheckConfigFingerprint(review.config),
|
|
423
472
|
expectedInclude: decision.localInclude,
|
|
424
473
|
signal,
|
|
425
474
|
},
|
|
@@ -431,6 +480,7 @@ async function inspectConfiguredRemoteSelection(
|
|
|
431
480
|
setupName: string | undefined,
|
|
432
481
|
signal: AbortSignal | undefined,
|
|
433
482
|
factory: SyncBackendFactory,
|
|
483
|
+
validateOwner: () => void,
|
|
434
484
|
): Promise<
|
|
435
485
|
| { kind: "empty"; config: AnySyncConfig }
|
|
436
486
|
| { kind: "selection"; config: AnySyncConfig; state: RemoteSelectionState }
|
|
@@ -438,14 +488,18 @@ async function inspectConfiguredRemoteSelection(
|
|
|
438
488
|
> {
|
|
439
489
|
const config = await loadConfig(setupName);
|
|
440
490
|
if (signal?.aborted) return undefined;
|
|
491
|
+
validateOwner();
|
|
441
492
|
setSyncStatus(ctx, `checking synced content for ${safeTerminalText(config.setupName)}`);
|
|
442
493
|
const backend = await factory(config);
|
|
443
494
|
if (signal?.aborted) return undefined;
|
|
495
|
+
validateOwner();
|
|
444
496
|
const head = await backend.readHead(signal);
|
|
445
497
|
if (signal?.aborted) return undefined;
|
|
498
|
+
validateOwner();
|
|
446
499
|
if (!head) return { kind: "empty", config };
|
|
447
500
|
const snapshot = await readSnapshotForHead(backend, head, signal);
|
|
448
501
|
if (signal?.aborted) return undefined;
|
|
502
|
+
validateOwner();
|
|
449
503
|
return {
|
|
450
504
|
kind: "selection",
|
|
451
505
|
config,
|
|
@@ -587,20 +641,6 @@ function assertLocalSelectionCurrent(config: AnySyncConfig, decision: RemoteSele
|
|
|
587
641
|
);
|
|
588
642
|
}
|
|
589
643
|
|
|
590
|
-
function sameContinuationReview(left: PartialConfig, right: PartialConfig) {
|
|
591
|
-
return (
|
|
592
|
-
left.setupName === right.setupName &&
|
|
593
|
-
left.connectionName === right.connectionName &&
|
|
594
|
-
left.storageKind === right.storageKind &&
|
|
595
|
-
left.storagePath === right.storagePath &&
|
|
596
|
-
left.bucket === right.bucket &&
|
|
597
|
-
left.branch === right.branch &&
|
|
598
|
-
Boolean(left.agentMode) === Boolean(right.agentMode) &&
|
|
599
|
-
Boolean(left.continuous) === Boolean(right.continuous) &&
|
|
600
|
-
sameSyncInclude(left.include, right.include)
|
|
601
|
-
);
|
|
602
|
-
}
|
|
603
|
-
|
|
604
644
|
function continueLabel(origin: RemoteSelectionOrigin) {
|
|
605
645
|
if (origin === "pull") return "Continue Pull now…";
|
|
606
646
|
if (origin === "push") return "Continue Push now…";
|
|
@@ -641,6 +681,15 @@ function runWithOptionalStateAccess<T>(
|
|
|
641
681
|
return options.withStateAccess ? options.withStateAccess(task) : task();
|
|
642
682
|
}
|
|
643
683
|
|
|
684
|
+
function isReviewOwnerCurrent(validateOwner: () => void) {
|
|
685
|
+
try {
|
|
686
|
+
validateOwner();
|
|
687
|
+
return true;
|
|
688
|
+
} catch {
|
|
689
|
+
return false;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
644
693
|
function combineSignals(sessionSignal: AbortSignal | undefined, actionSignal: AbortSignal) {
|
|
645
694
|
return sessionSignal ? AbortSignal.any([sessionSignal, actionSignal]) : actionSignal;
|
|
646
695
|
}
|
package/src/ui/settings-ui.ts
CHANGED
|
@@ -33,6 +33,7 @@ export async function showSyncSettings(
|
|
|
33
33
|
ctx: ExtensionCommandContext,
|
|
34
34
|
runRoute: SyncSettingsRoute,
|
|
35
35
|
signal?: AbortSignal,
|
|
36
|
+
reviewedSetup?: string,
|
|
36
37
|
): Promise<"back" | "exit"> {
|
|
37
38
|
let disposition: "back" | "exit" = "back";
|
|
38
39
|
const exitSettings = () => {
|
|
@@ -71,7 +72,7 @@ export async function showSyncSettings(
|
|
|
71
72
|
}
|
|
72
73
|
return disposition;
|
|
73
74
|
}
|
|
74
|
-
const initial = await loadConfig();
|
|
75
|
+
const initial = await loadConfig(reviewedSetup);
|
|
75
76
|
if (signal?.aborted) return "back";
|
|
76
77
|
const setupName = initial.setupName;
|
|
77
78
|
type Action =
|