@narumitw/pi-sync 0.68.0 → 0.69.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +35 -21
- package/dist/chunks/{chunk-AYGMIMCV.ts → chunk-4KGDPLQ4.ts} +2 -2
- package/dist/chunks/chunk-4KGDPLQ4.ts.map +7 -0
- package/dist/chunks/{chunk-FR6A7ASZ.ts → chunk-EG6BUOUQ.ts} +3 -3
- package/dist/chunks/{chunk-YV2R5SJU.ts → chunk-EI2J5Z4Q.ts} +17 -8
- package/dist/chunks/chunk-EI2J5Z4Q.ts.map +7 -0
- package/dist/chunks/{chunk-BCDBT4X3.ts → chunk-GXB74FYB.ts} +4 -4
- package/dist/chunks/{chunk-J52GYZO6.ts → chunk-LNZRNXNQ.ts} +2 -4
- package/dist/chunks/{chunk-FQKWGVMA.ts → chunk-OWSKD5XG.ts} +10 -7
- package/dist/chunks/chunk-OWSKD5XG.ts.map +7 -0
- package/dist/chunks/{chunk-WCGLU526.ts → chunk-RXZVLBPU.ts} +3 -3
- package/dist/chunks/{chunk-KAIVTJIQ.ts → chunk-RZB2DPVU.ts} +2 -2
- package/dist/chunks/{chunk-335XTMMZ.ts → chunk-VQTYTUBU.ts} +24 -26
- package/dist/chunks/chunk-VQTYTUBU.ts.map +7 -0
- package/dist/chunks/{chunk-TLYT6HVI.ts → chunk-YX6DCQ7P.ts} +2 -2
- package/dist/chunks/{command-handler-S6BRZMPW.ts → command-handler-ZR26OSBX.ts} +39 -143
- package/dist/chunks/command-handler-ZR26OSBX.ts.map +7 -0
- package/dist/chunks/{conflict-review-3XMYDJIK.ts → conflict-review-W5BCZIZG.ts} +2 -2
- package/dist/chunks/{file-selection-4BOQBXS7.ts → file-selection-STCIRKF6.ts} +3 -3
- package/dist/chunks/{manager-result-dispatcher-A4IWLS4J.ts → manager-result-dispatcher-MPLPDR2P.ts} +5 -5
- package/dist/chunks/{manager-ui-KHMCSLLV.ts → manager-ui-OMZOBGYT.ts} +99 -96
- package/dist/chunks/manager-ui-OMZOBGYT.ts.map +7 -0
- package/dist/chunks/{merge-review-LWMUE5IW.ts → merge-review-KTIQBRLL.ts} +2 -2
- package/dist/chunks/{remote-selection-ui-F6NJBQ3Y.ts → remote-selection-ui-CCHMCAHQ.ts} +4 -4
- package/dist/chunks/{setup-switch-7LMIRMZ7.ts → setup-switch-J3YLBB6N.ts} +4 -4
- package/dist/chunks/{setup-wizard-2NRPR433.ts → setup-wizard-J3YOR7BR.ts} +3 -4
- package/dist/chunks/{setup-wizard-2NRPR433.ts.map → setup-wizard-J3YOR7BR.ts.map} +1 -1
- package/dist/chunks/{sync-inspection-QGM54YCM.ts → sync-inspection-7OADBR57.ts} +3 -3
- package/dist/chunks/{sync-operations-DTQMKVRQ.ts → sync-operations-3K6WLPXY.ts} +2 -10
- package/dist/chunks/{sync-operations-DTQMKVRQ.ts.map → sync-operations-3K6WLPXY.ts.map} +2 -2
- package/dist/daemon/dist/build-id.json +1 -1
- package/dist/daemon/dist/engine/backends/git/git-backend.js +1 -1
- package/dist/daemon/dist/engine/backends/s3/s3-backend.js +2 -2
- package/dist/daemon/dist/engine/backends/webdav/webdav-backend.js +67 -6
- package/dist/daemon/dist/engine/debug-check.js +59 -0
- package/dist/daemon/dist/engine/debug-log.js +100 -1
- package/dist/daemon/dist/engine/sync/directional-conflict.js +31 -0
- package/dist/daemon/dist/engine/sync/push-review.js +1 -1
- package/dist/daemon/dist/engine/sync/sync-error-guidance.js +6 -5
- package/dist/daemon/dist/engine/sync/sync-inspection.js +5 -1
- package/dist/daemon/dist/engine/sync/sync-mutations.js +40 -7
- package/dist/daemon/dist/engine/sync/sync-queries.js +179 -82
- package/dist/daemon/dist/engine/sync/sync-state.js +1 -1
- package/dist/daemon/dist/engine/ui/sync-format.js +1 -1
- package/dist/daemon/dist/engine/ui/transfer-review.js +2 -3
- package/dist/daemon/dist/engine-service.js +100 -25
- package/dist/daemon/dist/foreground-transfer.js +10 -0
- package/dist/daemon/dist/index.js +1 -0
- package/dist/daemon/dist/server.js +2 -1
- package/dist/daemon/dist/service-host.js +1 -1
- package/dist/daemon/package.json +1 -1
- package/dist/index.ts +111 -10
- package/dist/index.ts.map +3 -3
- package/docs/daemon-migration.md +2 -2
- package/docs/tui-contract.md +7 -7
- package/package.json +7 -4
- package/skills/configure-pi-sync/SKILL.md +4 -7
- package/skills/configure-pi-sync/references/configuration.md +20 -19
- package/src/commands/command-execution.ts +36 -136
- package/src/commands/command-handler.ts +3 -3
- package/src/commands/command.ts +28 -26
- package/src/daemon/directional-recovery.ts +3 -1
- package/src/daemon/pi-client.ts +14 -2
- package/src/sync/debug-tool.ts +96 -0
- package/src/sync/startup-check.ts +1 -1
- package/src/sync/sync-operations.ts +0 -6
- package/src/sync-extension.ts +13 -1
- package/src/ui/cancellable-operation.ts +11 -4
- package/src/ui/manager-state.ts +13 -12
- package/src/ui/manager-ui.ts +96 -81
- package/src/ui/operation-dialogs.ts +1 -1
- package/src/ui/settings-ui.ts +2 -3
- package/src/ui/setup/webdav-ui.ts +1 -1
- package/dist/chunks/chunk-335XTMMZ.ts.map +0 -7
- package/dist/chunks/chunk-AYGMIMCV.ts.map +0 -7
- package/dist/chunks/chunk-ECYCNZOE.ts +0 -12
- package/dist/chunks/chunk-ECYCNZOE.ts.map +0 -7
- package/dist/chunks/chunk-FQKWGVMA.ts.map +0 -7
- package/dist/chunks/chunk-YV2R5SJU.ts.map +0 -7
- package/dist/chunks/command-handler-S6BRZMPW.ts.map +0 -7
- package/dist/chunks/manager-ui-KHMCSLLV.ts.map +0 -7
- /package/dist/chunks/{chunk-FR6A7ASZ.ts.map → chunk-EG6BUOUQ.ts.map} +0 -0
- /package/dist/chunks/{chunk-BCDBT4X3.ts.map → chunk-GXB74FYB.ts.map} +0 -0
- /package/dist/chunks/{chunk-J52GYZO6.ts.map → chunk-LNZRNXNQ.ts.map} +0 -0
- /package/dist/chunks/{chunk-WCGLU526.ts.map → chunk-RXZVLBPU.ts.map} +0 -0
- /package/dist/chunks/{chunk-KAIVTJIQ.ts.map → chunk-RZB2DPVU.ts.map} +0 -0
- /package/dist/chunks/{chunk-TLYT6HVI.ts.map → chunk-YX6DCQ7P.ts.map} +0 -0
- /package/dist/chunks/{conflict-review-3XMYDJIK.ts.map → conflict-review-W5BCZIZG.ts.map} +0 -0
- /package/dist/chunks/{file-selection-4BOQBXS7.ts.map → file-selection-STCIRKF6.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-A4IWLS4J.ts.map → manager-result-dispatcher-MPLPDR2P.ts.map} +0 -0
- /package/dist/chunks/{merge-review-LWMUE5IW.ts.map → merge-review-KTIQBRLL.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-F6NJBQ3Y.ts.map → remote-selection-ui-CCHMCAHQ.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-7LMIRMZ7.ts.map → setup-switch-J3YLBB6N.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-QGM54YCM.ts.map → sync-inspection-7OADBR57.ts.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createSyncBackend } from "../backends/backend-factory.js";
|
|
2
2
|
import { HISTORY_PREVIEW_LIMIT } from "../backends/sync-backend.js";
|
|
3
|
-
import { loadConfig, syncSessionsWarnings } from "../settings/config.js";
|
|
3
|
+
import { loadConfig, loadConfigForCheck, syncCheckConfigFingerprint, syncSessionsWarnings, } from "../settings/config.js";
|
|
4
4
|
import { resolvedSnapshotOptionsForContext } from "../snapshot/session-paths.js";
|
|
5
5
|
import { createSnapshot, scanSnapshot } from "../snapshot/snapshot.js";
|
|
6
6
|
import { inspectLock, isLockGuardHeld, isStaleLock, withLock } from "../state/lock.js";
|
|
@@ -9,6 +9,7 @@ import { formatDiff, formatSnapshotOnlyDiff, publicationCapabilityDescription }
|
|
|
9
9
|
import { setSyncStatus } from "../ui/sync-status.js";
|
|
10
10
|
import { safeTerminalText } from "../ui/terminal-text.js";
|
|
11
11
|
import { portableSnapshot } from "./local-fields.js";
|
|
12
|
+
import { captureMutationOwner } from "./mutation-owner.js";
|
|
12
13
|
import { formatRemoteSelectionStatus, readRemoteSnapshot } from "./remote-snapshot.js";
|
|
13
14
|
import { throwIfAborted } from "./signals.js";
|
|
14
15
|
import { errorMessage } from "./sync-errors.js";
|
|
@@ -29,33 +30,59 @@ function contentLines(config) {
|
|
|
29
30
|
`sessions: ${syncSessionsSelected(config) ? "included" : "excluded"}`,
|
|
30
31
|
];
|
|
31
32
|
}
|
|
33
|
+
function fileCount(count) {
|
|
34
|
+
return `${count} ${count === 1 ? "file" : "files"}`;
|
|
35
|
+
}
|
|
36
|
+
function reportSection(title, lines) {
|
|
37
|
+
return lines.length > 0 ? ["", title, ...lines.map((line) => ` ${line}`)] : [];
|
|
38
|
+
}
|
|
39
|
+
function storageSection(connection, destination, details) {
|
|
40
|
+
return reportSection(`Storage · ${safeTerminalText(connection)}`, [
|
|
41
|
+
`Location: ${safeTerminalText(destination)}`,
|
|
42
|
+
...details,
|
|
43
|
+
]);
|
|
44
|
+
}
|
|
32
45
|
export async function status(ctx, options, factory = createSyncBackend) {
|
|
33
46
|
const config = await loadConfig(options.setup);
|
|
34
47
|
throwIfAborted(options.signal);
|
|
35
48
|
setSyncStatus(ctx, `checking ${config.setupName}`, { activity: "checking" });
|
|
36
|
-
const { head, selectionState, localChanged, remoteChanged, localFiles, destination, capability } = await inspectSync(config, await resolvedSnapshotOptionsForContext(ctx, config, options.signal), options.signal, factory);
|
|
49
|
+
const { head, selectionState, localChanged, remoteChanged, localFiles, firstSync, destination, capability } = await inspectSync(config, await resolvedSnapshotOptionsForContext(ctx, config, options.signal), options.signal, factory);
|
|
37
50
|
throwIfAborted(options.signal);
|
|
38
51
|
const continuous = config.continuous
|
|
39
52
|
? await (await import("./continuous-record.js")).continuousStatusLines(config)
|
|
40
53
|
: [];
|
|
41
54
|
throwIfAborted(options.signal);
|
|
42
|
-
const remoteText = head ? `remote: ${head.snapshotId} from ${head.machine} at ${head.createdAt}` : "remote: empty";
|
|
43
55
|
const warnings = syncSessionsWarnings(config);
|
|
56
|
+
const files = fileCount(localFiles);
|
|
57
|
+
const comparison = firstSync
|
|
58
|
+
? [`Local: ${files}`, `Remote: ${head ? "snapshot available" : "empty"}`]
|
|
59
|
+
: [
|
|
60
|
+
`Local: ${localChanged ? "changed" : "unchanged"} (${files})`,
|
|
61
|
+
`Remote: ${remoteChanged ? "changed" : "unchanged"}`,
|
|
62
|
+
];
|
|
44
63
|
setSyncStatus(ctx, undefined);
|
|
45
64
|
ctx.ui.notify([
|
|
46
|
-
`
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
...
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
`Remote status · ${safeTerminalText(config.setupName)}`,
|
|
66
|
+
...reportSection(firstSync ? "No previous sync recorded" : "Changes since last sync", [
|
|
67
|
+
...comparison,
|
|
68
|
+
...(head ? formatRemoteSelectionStatus(selectionState).split("\n") : []),
|
|
69
|
+
]),
|
|
70
|
+
...reportSection("Needs attention", warnings),
|
|
71
|
+
...storageSection(config.connectionName, destination, [
|
|
72
|
+
`Publication safety: ${publicationCapabilityDescription(capability)}`,
|
|
73
|
+
...(head
|
|
74
|
+
? [
|
|
75
|
+
`Latest snapshot: ${safeTerminalText(head.snapshotId)}`,
|
|
76
|
+
`Device: ${safeTerminalText(head.machine)}`,
|
|
77
|
+
`Created: ${safeTerminalText(head.createdAt)}`,
|
|
78
|
+
]
|
|
79
|
+
: firstSync
|
|
80
|
+
? []
|
|
81
|
+
: ["Latest snapshot: none"]),
|
|
82
|
+
]),
|
|
83
|
+
...reportSection("Background activity", continuous.map(safeTerminalText)),
|
|
84
|
+
...reportSection("Sync scope", contentLines(config)),
|
|
85
|
+
].join("\n"), localChanged || remoteChanged || selectionState?.kind === "different" || warnings.length > 0 ? "warning" : "info", "report");
|
|
59
86
|
}
|
|
60
87
|
export async function diff(ctx, options, factory = createSyncBackend) {
|
|
61
88
|
const config = await loadConfig(options.setup);
|
|
@@ -88,119 +115,189 @@ export async function diff(ctx, options, factory = createSyncBackend) {
|
|
|
88
115
|
ctx.ui.notify(`${header}\n\n${formatDiff(local, portableSnapshot(remote, remote.localFields))}`, level);
|
|
89
116
|
}
|
|
90
117
|
export async function doctor(ctx, options, factory = createSyncBackend) {
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
let
|
|
118
|
+
const attention = [];
|
|
119
|
+
const localChecks = [];
|
|
120
|
+
let config;
|
|
121
|
+
let snapshotOptions;
|
|
94
122
|
let backend;
|
|
95
|
-
let backendSummary = [];
|
|
96
123
|
try {
|
|
97
|
-
|
|
124
|
+
config = await loadConfig(options.setup);
|
|
125
|
+
throwIfAborted(options.signal);
|
|
126
|
+
snapshotOptions = await resolvedSnapshotOptionsForContext(ctx, config, options.signal);
|
|
98
127
|
throwIfAborted(options.signal);
|
|
99
|
-
localConfig = {
|
|
100
|
-
profile: config.snapshotIdentity,
|
|
101
|
-
snapshotOptions: await resolvedSnapshotOptionsForContext(ctx, config, options.signal),
|
|
102
|
-
};
|
|
103
128
|
backend = await factory(config);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
`publication safety: ${publicationCapabilityDescription(backend.capability)}`,
|
|
108
|
-
];
|
|
109
|
-
const warnings = syncSessionsWarnings(config);
|
|
110
|
-
if (warnings.length > 0) {
|
|
111
|
-
level = "warning";
|
|
112
|
-
messages.push(...warnings);
|
|
113
|
-
}
|
|
129
|
+
throwIfAborted(options.signal);
|
|
130
|
+
localChecks.push("Configuration: OK");
|
|
131
|
+
attention.push(...syncSessionsWarnings(config));
|
|
114
132
|
}
|
|
115
133
|
catch (error) {
|
|
116
134
|
throwIfAborted(options.signal);
|
|
117
|
-
|
|
118
|
-
messages.push(`config: ${errorMessage(error)}`);
|
|
135
|
+
attention.push(`Configuration: ${safeTerminalText(errorMessage(error))}`);
|
|
119
136
|
}
|
|
120
|
-
if (
|
|
121
|
-
const local = await createSnapshot(
|
|
137
|
+
if (config && snapshotOptions) {
|
|
138
|
+
const local = await createSnapshot(config.snapshotIdentity, snapshotOptions);
|
|
122
139
|
throwIfAborted(options.signal);
|
|
123
140
|
const secrets = scanSnapshot(local);
|
|
124
141
|
if (secrets.length > 0) {
|
|
125
|
-
|
|
126
|
-
messages.push("secret scan: possible secrets found:");
|
|
127
|
-
messages.push(...secrets.map((secret) => `- ${safeTerminalText(secret)}`));
|
|
142
|
+
attention.push("Secret scan: possible secrets found", ...secrets.map((secret) => ` - ${safeTerminalText(secret)}`));
|
|
128
143
|
}
|
|
129
144
|
else {
|
|
130
|
-
|
|
145
|
+
localChecks.push(`Secret scan: OK (${fileCount(local.files.length)} checked)`);
|
|
131
146
|
}
|
|
132
147
|
}
|
|
133
148
|
else
|
|
134
|
-
|
|
149
|
+
localChecks.push("Secret scan: skipped without a valid content policy");
|
|
135
150
|
const lock = await inspectLock();
|
|
136
151
|
throwIfAborted(options.signal);
|
|
137
152
|
if (lock.status === "valid" && isStaleLock(lock.lock)) {
|
|
138
|
-
|
|
139
|
-
messages.push(`lock: stale (pid ${lock.lock.pid}); run /sync unlock --stale after verifying no sync is running`);
|
|
153
|
+
attention.push(`Operation lock: stale (PID ${lock.lock.pid}); run /sync unlock --stale after verifying no sync is running`);
|
|
140
154
|
}
|
|
141
155
|
else if (lock.status === "valid") {
|
|
142
|
-
|
|
156
|
+
localChecks.push(`Operation lock: held by PID ${lock.lock.pid} since ${safeTerminalText(lock.lock.startedAt)}`);
|
|
143
157
|
}
|
|
144
158
|
else if (lock.status === "unreadable") {
|
|
145
|
-
|
|
146
|
-
messages.push("lock: unreadable; use /sync unlock --stale only after verifying no sync is running");
|
|
159
|
+
attention.push("Operation lock: unreadable; use /sync unlock --stale only after verifying no sync is running");
|
|
147
160
|
}
|
|
148
161
|
else if (await isLockGuardHeld()) {
|
|
149
|
-
|
|
150
|
-
level = "warning";
|
|
151
|
-
messages.push("lock: guard active while metadata is missing or still being initialized");
|
|
162
|
+
attention.push("Operation lock: guard active while metadata is missing or still being initialized");
|
|
152
163
|
}
|
|
153
164
|
else {
|
|
154
|
-
|
|
165
|
+
localChecks.push("Operation lock: free");
|
|
155
166
|
}
|
|
167
|
+
throwIfAborted(options.signal);
|
|
168
|
+
const storageChecks = [];
|
|
156
169
|
if (backend) {
|
|
157
|
-
messages.push(...backendSummary);
|
|
158
170
|
const diagnostics = await backend.diagnose(options.signal);
|
|
159
171
|
throwIfAborted(options.signal);
|
|
160
172
|
for (const diagnostic of diagnostics) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
173
|
+
if (diagnostic.key === "s3-config" && diagnostic.level === "info")
|
|
174
|
+
continue;
|
|
175
|
+
const finding = safeTerminalText(diagnostic.message.replaceAll("\n", " "));
|
|
176
|
+
(diagnostic.level === "info" ? storageChecks : attention).push(finding);
|
|
164
177
|
}
|
|
165
178
|
}
|
|
166
|
-
ctx.ui.notify(
|
|
179
|
+
ctx.ui.notify([
|
|
180
|
+
config ? `Diagnostics · ${safeTerminalText(config.setupName)}` : "Diagnostics",
|
|
181
|
+
...reportSection("Needs attention", attention),
|
|
182
|
+
...reportSection("Local checks", localChecks),
|
|
183
|
+
...(config && backend
|
|
184
|
+
? storageSection(config.connectionName, backend.destination, [
|
|
185
|
+
...storageChecks,
|
|
186
|
+
`Publication safety: ${publicationCapabilityDescription(backend.capability)}`,
|
|
187
|
+
])
|
|
188
|
+
: []),
|
|
189
|
+
...(config ? reportSection("Sync scope", contentLines(config)) : []),
|
|
190
|
+
].join("\n"), attention.length > 0 ? "warning" : "info", "report");
|
|
167
191
|
}
|
|
168
|
-
export async function history(ctx, options, factory = createSyncBackend) {
|
|
169
|
-
const
|
|
170
|
-
|
|
192
|
+
export async function history(ctx, options, factory = createSyncBackend, validateJob) {
|
|
193
|
+
const { signal } = options;
|
|
194
|
+
const validateSession = captureMutationOwner(ctx, signal);
|
|
195
|
+
const validateOwner = () => {
|
|
196
|
+
validateJob?.();
|
|
197
|
+
validateSession();
|
|
198
|
+
};
|
|
199
|
+
validateOwner();
|
|
200
|
+
const config = await loadConfig(options.setup, signal);
|
|
201
|
+
validateOwner();
|
|
171
202
|
const backend = await factory(config);
|
|
172
|
-
|
|
173
|
-
|
|
203
|
+
validateOwner();
|
|
204
|
+
const entries = await backend.listHistory(signal);
|
|
205
|
+
validateOwner();
|
|
206
|
+
const interactive = ctx.hasUI && (ctx.mode === "tui" || ctx.mode === "rpc");
|
|
207
|
+
const repair = interactive && !options.auto && config.backend.type === "webdav"
|
|
208
|
+
? backend.repairActiveHistory?.bind(backend)
|
|
209
|
+
: undefined;
|
|
210
|
+
const head = repair
|
|
211
|
+
? await backend.readHead(signal).catch(() => {
|
|
212
|
+
validateOwner();
|
|
213
|
+
ctx.ui.notify("History repair is unavailable because the active WebDAV snapshot could not be read.", "warning");
|
|
214
|
+
return undefined;
|
|
215
|
+
})
|
|
216
|
+
: undefined;
|
|
217
|
+
validateOwner();
|
|
218
|
+
const repairHead = head && !entries.some((entry) => entry.snapshotRef === head.snapshotRef) ? head : undefined;
|
|
219
|
+
const snapshots = entries.slice(-HISTORY_PREVIEW_LIMIT).reverse();
|
|
174
220
|
const lastApplied = await readStateForConfig(config)
|
|
175
221
|
.then((state) => state.lastAppliedSnapshot)
|
|
176
222
|
.catch(() => undefined);
|
|
177
|
-
|
|
223
|
+
validateOwner();
|
|
178
224
|
const appliedDetails = lastApplied
|
|
179
225
|
? `Last applied snapshot ID: ${safeTerminalText(lastApplied)}\nApplication time: unavailable. Snapshot dates are creation times.`
|
|
180
226
|
: "Last applied snapshot ID: unavailable.";
|
|
181
|
-
if (snapshots.length === 0) {
|
|
227
|
+
if (snapshots.length === 0 && !repairHead) {
|
|
182
228
|
ctx.ui.notify(`No remote pi-sync history found.\n${appliedDetails}`, "info");
|
|
183
229
|
return;
|
|
184
230
|
}
|
|
185
|
-
const
|
|
186
|
-
if (
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
231
|
+
const previewRollback = interactive && ctx.mode === "tui";
|
|
232
|
+
if (!previewRollback) {
|
|
233
|
+
ctx.ui.notify([
|
|
234
|
+
appliedDetails,
|
|
235
|
+
...snapshots.map((item) => `${safeTerminalText(item.snapshotRef)} ${safeTerminalText(item.createdAt)} ${safeTerminalText(item.machine)}`),
|
|
236
|
+
].join("\n"), "info");
|
|
237
|
+
if (!repairHead)
|
|
190
238
|
return;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
239
|
+
}
|
|
240
|
+
const currentSnapshot = repair ? head?.snapshotId : snapshots[0]?.snapshotId;
|
|
241
|
+
const labels = previewRollback
|
|
242
|
+
? snapshots.map((item, index) => `${index + 1}. ${safeTerminalText(item.createdAt)} · ${safeTerminalText(item.machine)} · ${safeTerminalText(item.snapshotId)}${item.snapshotId === currentSnapshot ? " (current)" : ""}${item.syncSessions ? " · sessions" : ""}`)
|
|
243
|
+
: [];
|
|
244
|
+
const setupName = safeTerminalText(config.setupName);
|
|
245
|
+
const repairChoice = "Repair active snapshot history";
|
|
246
|
+
const selected = await ctx.ui.select([
|
|
247
|
+
`History for sync setup “${setupName}”`,
|
|
248
|
+
appliedDetails,
|
|
249
|
+
...(labels.length > 0 ? ["Choose a snapshot to preview rollback."] : []),
|
|
250
|
+
...(repairHead ? ["The active WebDAV snapshot is missing from History."] : []),
|
|
251
|
+
].join("\n\n"), [...labels, ...(repairHead ? [repairChoice] : []), "Back"], { signal });
|
|
252
|
+
validateOwner();
|
|
253
|
+
if (!selected || selected === "Back")
|
|
254
|
+
return;
|
|
255
|
+
if (selected === repairChoice && repairHead && repair) {
|
|
256
|
+
const validateRepairOwner = () => {
|
|
257
|
+
validateOwner();
|
|
258
|
+
if (!ctx.hasUI || (ctx.mode !== "tui" && ctx.mode !== "rpc"))
|
|
259
|
+
throw new Error("History repair no longer has an observable TUI or RPC client.");
|
|
260
|
+
};
|
|
261
|
+
validateRepairOwner();
|
|
262
|
+
const fingerprint = syncCheckConfigFingerprint(config);
|
|
263
|
+
const confirmed = await ctx.ui.confirm("Repair active WebDAV snapshot history?", [
|
|
264
|
+
`Setup: ${setupName}`,
|
|
265
|
+
`Storage: ${safeTerminalText(backend.destination)}`,
|
|
266
|
+
`Active snapshot: ${safeTerminalText(repairHead.snapshotId)}`,
|
|
267
|
+
"This runs a temporary conditional write/delete probe, then adds this snapshot to remote History if it is still missing. If History is full, the oldest entry is dropped. The active snapshot and local files do not change.",
|
|
268
|
+
].join("\n"), { signal });
|
|
269
|
+
validateRepairOwner();
|
|
270
|
+
if (!confirmed)
|
|
195
271
|
return;
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
272
|
+
const validateSettings = async () => {
|
|
273
|
+
validateRepairOwner();
|
|
274
|
+
const current = await loadConfigForCheck(options.setup, signal);
|
|
275
|
+
validateRepairOwner();
|
|
276
|
+
if (syncCheckConfigFingerprint(current) !== fingerprint)
|
|
277
|
+
throw new Error("The sync setup settings changed. Reopen History before repairing it.");
|
|
278
|
+
};
|
|
279
|
+
const repaired = await withLock("history repair", async () => {
|
|
280
|
+
await validateSettings();
|
|
281
|
+
validateRepairOwner();
|
|
282
|
+
return repair(repairHead, {
|
|
283
|
+
signal,
|
|
284
|
+
validateOwner: validateRepairOwner,
|
|
285
|
+
validateSettings,
|
|
286
|
+
onCommit: options.onCommit,
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
validateRepairOwner();
|
|
290
|
+
ctx.ui.notify(repaired ? "Active WebDAV snapshot added to History." : "The active WebDAV snapshot is already in History.", "info");
|
|
200
291
|
return;
|
|
201
292
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
293
|
+
const snapshot = snapshots[labels.indexOf(selected)];
|
|
294
|
+
if (!snapshot)
|
|
295
|
+
return;
|
|
296
|
+
await withLock("rollback", () => {
|
|
297
|
+
validateOwner();
|
|
298
|
+
return rollback(ctx, { ...options, args: [snapshot.snapshotRef], yes: false }, factory, {
|
|
299
|
+
backendIdentity: backend.identity,
|
|
300
|
+
setup: config.setupName,
|
|
301
|
+
});
|
|
302
|
+
});
|
|
206
303
|
}
|
|
@@ -46,7 +46,7 @@ export function rawSnapshotHashIdentity(snapshot) {
|
|
|
46
46
|
.update(JSON.stringify(fileHashMap(snapshot)))
|
|
47
47
|
.digest("hex");
|
|
48
48
|
}
|
|
49
|
-
function stateHashMapForConfig(state, config) {
|
|
49
|
+
export function stateHashMapForConfig(state, config) {
|
|
50
50
|
const includePaths = customIncludePathsByLower(includeFromSelectionConfig(config));
|
|
51
51
|
const configured = configuredSnapshotPathMatcher(config);
|
|
52
52
|
return Object.fromEntries(Object.entries(state.lastFileHashes)
|
|
@@ -123,7 +123,7 @@ export function publicationCapabilityDescription(capability) {
|
|
|
123
123
|
case "atomic-conditional":
|
|
124
124
|
return "atomic-conditional (verified atomic precondition)";
|
|
125
125
|
case "conditional-required":
|
|
126
|
-
return "
|
|
126
|
+
return "Read-only until atomic conditional writes are verified";
|
|
127
127
|
case "read-check-write-verify":
|
|
128
128
|
return "read-check-write-verify (visible races rejected; simultaneous unseen races remain possible)";
|
|
129
129
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { confirmMergeReview } from "./merge-review.js";
|
|
2
|
-
|
|
3
|
-
export async function confirmTransferReview(ctx, title, review, signal, validate) {
|
|
2
|
+
export async function confirmTransferReview(ctx, title, review, signal, validate, reviewInRpc = false) {
|
|
4
3
|
validate();
|
|
5
4
|
const isCurrent = () => {
|
|
6
5
|
try {
|
|
@@ -11,7 +10,7 @@ export async function confirmTransferReview(ctx, title, review, signal, validate
|
|
|
11
10
|
return false;
|
|
12
11
|
}
|
|
13
12
|
};
|
|
14
|
-
const confirmed = ctx.mode === "tui" && ctx.
|
|
13
|
+
const confirmed = ctx.hasUI && (ctx.mode === "tui" || (reviewInRpc && ctx.mode === "rpc"))
|
|
15
14
|
? await confirmMergeReview(ctx, title, review.content, signal, isCurrent, "apply reviewed transfer", review.lines)
|
|
16
15
|
: await ctx.ui.confirm(title, review.content, { signal });
|
|
17
16
|
validate();
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { authorizeAfterExit, captureAutomaticAuthorization, consentFingerprint, readConsent, requireHandover, } from "./consent.js";
|
|
2
2
|
import { createDaemonDebug } from "./daemon-debug.js";
|
|
3
3
|
import { documentFingerprint } from "./document.js";
|
|
4
|
+
import { debugCheckFailure, summarizeDebugInspection } from "./engine/debug-check.js";
|
|
4
5
|
import { retiredIgnorePolicy } from "./engine/settings/retired-ignore-policy.js";
|
|
5
6
|
import { assertNoRetiredRuleJournal } from "./engine/settings/retired-ignore-recovery.js";
|
|
6
7
|
import { captureStartupReviewLock } from "./engine/state/lock.js";
|
|
8
|
+
import { isForegroundTransferIntent } from "./foreground-transfer.js";
|
|
7
9
|
import { createLegacyConsentGuard } from "./legacy-consent-guard.js";
|
|
8
10
|
import { MAX_SETTINGS_BYTES, record } from "./protocol.js";
|
|
9
11
|
import { createServiceContext, installServiceHost } from "./service-host.js";
|
|
@@ -121,23 +123,8 @@ export function createEngineService(root) {
|
|
|
121
123
|
const ctx = createServiceContext(execution);
|
|
122
124
|
if (operation === "initialize")
|
|
123
125
|
return initialize(ctx, execution);
|
|
124
|
-
if (operation === "inspect")
|
|
125
|
-
|
|
126
|
-
throw new Error("Invalid inspection request.");
|
|
127
|
-
const { withStateDirectoryAccess } = await import("./engine/state/state-directory.js");
|
|
128
|
-
const { withLock } = await import("./engine/state/lock.js");
|
|
129
|
-
return withJobTimings(ctx, execution, "daemon inspection", (timings) => withStateDirectoryAccess(() => withLock("startup-check", async () => {
|
|
130
|
-
const { loadConfigForCheck, syncCheckConfigFingerprint } = await import("./engine/settings/config.js");
|
|
131
|
-
const config = await loadConfigForCheck(payload.setup, execution.signal);
|
|
132
|
-
execution.validate();
|
|
133
|
-
if (payload.fingerprint !== syncCheckConfigFingerprint(config))
|
|
134
|
-
throw new Error("Settings changed before inspection.");
|
|
135
|
-
const { snapshotOptionsForContext } = await import("./engine/snapshot/session-paths.js");
|
|
136
|
-
const { inspectSync } = await import("./engine/sync/sync-inspection.js");
|
|
137
|
-
execution.validate();
|
|
138
|
-
return inspectSync(config, snapshotOptionsForContext(ctx, config), execution.signal, undefined, timings);
|
|
139
|
-
})));
|
|
140
|
-
}
|
|
126
|
+
if (operation === "inspect")
|
|
127
|
+
return inspectForClient(ctx, execution, payload);
|
|
141
128
|
if (operation === "push.foreground" || operation === "pull.foreground") {
|
|
142
129
|
const direction = operation === "push.foreground" ? "push" : "pull";
|
|
143
130
|
return runForegroundDirectional(host, execution, ctx, direction, payload);
|
|
@@ -269,7 +256,9 @@ export function createEngineService(root) {
|
|
|
269
256
|
}
|
|
270
257
|
if (operation === "push" || operation === "pull" || operation === "rollback")
|
|
271
258
|
return withLock(operation, () => operations[operation](ctx, options));
|
|
272
|
-
if (operation === "
|
|
259
|
+
if (operation === "history")
|
|
260
|
+
return operations.history(ctx, options, undefined, execution.validate);
|
|
261
|
+
if (operation === "status" || operation === "diff" || operation === "doctor")
|
|
273
262
|
return operations[operation](ctx, options);
|
|
274
263
|
throw new Error("Unreachable operation.");
|
|
275
264
|
});
|
|
@@ -305,7 +294,9 @@ async function runForegroundDirectional(host, execution, ctx, direction, payload
|
|
|
305
294
|
!ctx.hasUI ||
|
|
306
295
|
!["tui", "rpc"].includes(ctx.mode) ||
|
|
307
296
|
!record(payload) ||
|
|
308
|
-
Object.keys(payload).some((key) => !["setup", "fingerprint", "retryCheckpoint"].includes(key)) ||
|
|
297
|
+
Object.keys(payload).some((key) => !["setup", "fingerprint", "retryCheckpoint", "intent"].includes(key)) ||
|
|
298
|
+
(payload.intent !== undefined && !isForegroundTransferIntent(payload.intent)) ||
|
|
299
|
+
(payload.intent === "review-force" && payload.retryCheckpoint !== undefined) ||
|
|
309
300
|
typeof payload.setup !== "string" ||
|
|
310
301
|
!payload.setup ||
|
|
311
302
|
payload.setup.length > 512 ||
|
|
@@ -315,11 +306,12 @@ async function runForegroundDirectional(host, execution, ctx, direction, payload
|
|
|
315
306
|
(typeof payload.retryCheckpoint !== "string" || !fingerprintPattern.test(payload.retryCheckpoint)))) {
|
|
316
307
|
throw new Error("Invalid foreground directional request.");
|
|
317
308
|
}
|
|
318
|
-
const { setup, fingerprint, retryCheckpoint } = payload;
|
|
309
|
+
const { setup, fingerprint, retryCheckpoint, intent } = payload;
|
|
319
310
|
const { withStateDirectoryAccess } = await import("./engine/state/state-directory.js");
|
|
320
311
|
const { withLock } = await import("./engine/state/lock.js");
|
|
321
312
|
const { loadConfigForCheck, syncCheckConfigFingerprint } = await import("./engine/settings/config.js");
|
|
322
313
|
const operations = await import("./engine/sync/sync-operations.js");
|
|
314
|
+
const { DirectionalDestinationConflict, DirectionalReviewChangedError } = await import("./engine/sync/directional-conflict.js");
|
|
323
315
|
const validate = (config) => {
|
|
324
316
|
execution.validate();
|
|
325
317
|
if (config.setupName !== setup || syncCheckConfigFingerprint(config) !== fingerprint)
|
|
@@ -340,15 +332,17 @@ async function runForegroundDirectional(host, execution, ctx, direction, payload
|
|
|
340
332
|
}
|
|
341
333
|
return host.runForeground(execution, () => withLock(direction, async () => {
|
|
342
334
|
validate(await loadConfigForCheck(undefined, execution.signal));
|
|
335
|
+
const changedDuringRecovery = () => new Error("The transfer source or destination changed during recovery. The transfer was not replayed.");
|
|
343
336
|
let message;
|
|
344
|
-
const
|
|
337
|
+
const options = {
|
|
345
338
|
...optionsFrom({ setup, args: [] }, execution, false),
|
|
346
339
|
directionalAction: {
|
|
340
|
+
intent,
|
|
347
341
|
validate,
|
|
348
342
|
async checkpoint(current) {
|
|
349
343
|
execution.validate();
|
|
350
344
|
if (retryCheckpoint !== undefined && retryCheckpoint !== current)
|
|
351
|
-
throw
|
|
345
|
+
throw changedDuringRecovery();
|
|
352
346
|
const accepted = await execution.request("directional-checkpoint", { fingerprint: current });
|
|
353
347
|
if (accepted !== true)
|
|
354
348
|
throw new Error("The original transfer could not be retained for recovery. No transfer was started.");
|
|
@@ -358,11 +352,92 @@ async function runForegroundDirectional(host, execution, ctx, direction, payload
|
|
|
358
352
|
message = value;
|
|
359
353
|
},
|
|
360
354
|
},
|
|
361
|
-
}
|
|
362
|
-
|
|
355
|
+
};
|
|
356
|
+
const run = async () => {
|
|
357
|
+
try {
|
|
358
|
+
const outcome = await operations[direction](ctx, options);
|
|
359
|
+
return { outcome, ...(message === undefined ? {} : { message }) };
|
|
360
|
+
}
|
|
361
|
+
catch (error) {
|
|
362
|
+
if (intent !== "reject-conflicts" || !(error instanceof DirectionalDestinationConflict))
|
|
363
|
+
throw error;
|
|
364
|
+
execution.validate();
|
|
365
|
+
if (retryCheckpoint !== undefined)
|
|
366
|
+
throw changedDuringRecovery();
|
|
367
|
+
return { outcome: "destination-conflict" };
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
try {
|
|
371
|
+
return await run();
|
|
372
|
+
}
|
|
373
|
+
catch (error) {
|
|
374
|
+
if (intent !== "review-force" || !(error instanceof DirectionalReviewChangedError))
|
|
375
|
+
throw error;
|
|
376
|
+
validate(await loadConfigForCheck(undefined, execution.signal));
|
|
377
|
+
return run();
|
|
378
|
+
}
|
|
363
379
|
}));
|
|
364
380
|
});
|
|
365
381
|
}
|
|
382
|
+
async function inspectForClient(ctx, execution, payload) {
|
|
383
|
+
if (!record(payload) ||
|
|
384
|
+
(payload.setup !== undefined && typeof payload.setup !== "string") ||
|
|
385
|
+
(payload.origin !== undefined && payload.origin !== "recheck"))
|
|
386
|
+
throw new Error("Invalid inspection request.");
|
|
387
|
+
const origin = payload.origin === "recheck" ? "recheck" : "startup";
|
|
388
|
+
const setup = typeof payload.setup === "string" ? payload.setup : undefined;
|
|
389
|
+
if (origin === "recheck" &&
|
|
390
|
+
(!ctx.hasUI || !["tui", "rpc"].includes(ctx.mode) || !execution.facts()?.startupDebug || !setup))
|
|
391
|
+
throw new Error("Recheck requires an interactive Debug mode session.");
|
|
392
|
+
const configChanged = () => Object.assign(new Error("Settings changed during inspection."), { code: "SYNC_INSPECTION_CHANGED" });
|
|
393
|
+
let setupKey;
|
|
394
|
+
const note = (summary) => {
|
|
395
|
+
if (setupKey && !execution.signal.aborted)
|
|
396
|
+
execution.debug?.({ event: "check", origin, setupKey, summary });
|
|
397
|
+
};
|
|
398
|
+
const { withStateDirectoryAccess } = await import("./engine/state/state-directory.js");
|
|
399
|
+
const { withLock } = await import("./engine/state/lock.js");
|
|
400
|
+
try {
|
|
401
|
+
const result = await withJobTimings(ctx, execution, "daemon inspection", (timings) => withStateDirectoryAccess(() => withLock("startup-check", async () => {
|
|
402
|
+
const [{ loadConfigForCheck, syncCheckConfigFingerprint, syncConfigReviewFingerprint }, { snapshotOptionsForContext }, { inspectSync },] = await Promise.all([
|
|
403
|
+
import("./engine/settings/config.js"),
|
|
404
|
+
import("./engine/snapshot/session-paths.js"),
|
|
405
|
+
import("./engine/sync/sync-inspection.js"),
|
|
406
|
+
]);
|
|
407
|
+
const readReviewed = async () => {
|
|
408
|
+
execution.validate();
|
|
409
|
+
const config = await loadConfigForCheck(origin === "recheck" ? undefined : setup, execution.signal);
|
|
410
|
+
execution.validate();
|
|
411
|
+
if (payload.fingerprint !== syncCheckConfigFingerprint(config) ||
|
|
412
|
+
(origin === "recheck" && setup !== config.setupName))
|
|
413
|
+
throw configChanged();
|
|
414
|
+
return config;
|
|
415
|
+
};
|
|
416
|
+
const config = await readReviewed();
|
|
417
|
+
execution.validate();
|
|
418
|
+
setupKey = syncConfigReviewFingerprint(config);
|
|
419
|
+
const revalidate = origin === "recheck"
|
|
420
|
+
? async () => {
|
|
421
|
+
await readReviewed();
|
|
422
|
+
}
|
|
423
|
+
: undefined;
|
|
424
|
+
const inspected = await inspectSync(config, snapshotOptionsForContext(ctx, config), execution.signal, undefined, timings, revalidate);
|
|
425
|
+
execution.validate();
|
|
426
|
+
if (revalidate)
|
|
427
|
+
await revalidate();
|
|
428
|
+
return inspected;
|
|
429
|
+
})));
|
|
430
|
+
execution.validate();
|
|
431
|
+
const summary = summarizeDebugInspection(result);
|
|
432
|
+
if (summary)
|
|
433
|
+
note(summary);
|
|
434
|
+
return result;
|
|
435
|
+
}
|
|
436
|
+
catch (error) {
|
|
437
|
+
note(debugCheckFailure(error));
|
|
438
|
+
throw error;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
366
441
|
async function withJobTimings(ctx, execution, label, action) {
|
|
367
442
|
const { createStartupTimings } = await import("./engine/sync/startup-timings.js");
|
|
368
443
|
const timings = createStartupTimings((_ctx, report) => execution.emit("timings", { report }));
|
|
@@ -382,7 +457,7 @@ async function requireStartupRecoveryCleared(execution) {
|
|
|
382
457
|
const pending = await pendingTransactionEntries();
|
|
383
458
|
execution.validate();
|
|
384
459
|
if (pending.length)
|
|
385
|
-
throw new Error("Pi Sync startup cannot confirm recovery is clear. Preserve recovery files and
|
|
460
|
+
throw new Error("Pi Sync startup cannot confirm recovery is clear. Preserve recovery files and use /sync daemon status for recovery guidance before retrying.");
|
|
386
461
|
}
|
|
387
462
|
async function initialize(ctx, execution, diagnostics = true) {
|
|
388
463
|
const { pendingTransactionEntries } = await import("./engine/snapshot/snapshot-transaction-directory.js");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function isForegroundTransferIntent(value) {
|
|
2
|
+
return value === "reject-conflicts" || value === "review-force";
|
|
3
|
+
}
|
|
4
|
+
export function isDestinationConflict(value) {
|
|
5
|
+
return (typeof value === "object" &&
|
|
6
|
+
value !== null &&
|
|
7
|
+
"outcome" in value &&
|
|
8
|
+
value.outcome === "destination-conflict" &&
|
|
9
|
+
Object.keys(value).length === 1);
|
|
10
|
+
}
|
|
@@ -3,5 +3,6 @@ export { inspectDaemonRecovery, stopDaemonForRecovery, } from "./daemon-recovery
|
|
|
3
3
|
export { DaemonUpgradeBlockedError } from "./daemon-startup.js";
|
|
4
4
|
export { inspectDaemonStatus } from "./daemon-status.js";
|
|
5
5
|
export { documentFingerprint } from "./document.js";
|
|
6
|
+
export { isDestinationConflict } from "./foreground-transfer.js";
|
|
6
7
|
export { modelSignature } from "./model-signature.js";
|
|
7
8
|
export { MAX_SETTINGS_BYTES, OWNERSHIP_CLEANUP_REQUIRED, PROTOCOL_VERSION } from "./protocol.js";
|
|
@@ -321,7 +321,8 @@ export async function startServer(root, execute, hooks = {}) {
|
|
|
321
321
|
validate,
|
|
322
322
|
request,
|
|
323
323
|
emit: (kind, data, target = job.client) => emit(kind, data, target),
|
|
324
|
-
debug
|
|
324
|
+
debug: debug &&
|
|
325
|
+
((event, current) => debug(event.event === "check" ? { ...event, operationId: job.view.id } : event, current)),
|
|
325
326
|
noteDebugOutcome(outcome) {
|
|
326
327
|
job.debugOutcome = outcome;
|
|
327
328
|
},
|
|
@@ -228,7 +228,7 @@ export function createServiceContext(execution) {
|
|
|
228
228
|
await ask("reload", {});
|
|
229
229
|
},
|
|
230
230
|
ui: {
|
|
231
|
-
notify: (message, level = "info") => execution.emit("notify", { message, level }),
|
|
231
|
+
notify: (message, level = "info", layout) => execution.emit("notify", { message, level, ...(layout ? { layout } : {}) }),
|
|
232
232
|
setStatus: (_key, value) => execution.emit("status", { value }),
|
|
233
233
|
confirm: async (title, message, options) => (await ask("confirm", { title, message }, options?.signal)) === true,
|
|
234
234
|
select: async (title, items, options) => {
|
package/dist/daemon/package.json
CHANGED