@narumitw/pi-sync 0.64.0 → 0.65.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 +10 -0
- package/README.md +76 -7
- package/dist/chunks/{chunk-CKUGCBHP.ts → chunk-AYGMIMCV.ts} +2 -2
- package/dist/chunks/chunk-AYGMIMCV.ts.map +7 -0
- package/dist/chunks/{chunk-F3VODLVQ.ts → chunk-IOM6E5FW.ts} +3 -3
- package/dist/chunks/{chunk-RW44KNFD.ts → chunk-JQ5BAWW2.ts} +182 -12
- package/dist/chunks/chunk-JQ5BAWW2.ts.map +7 -0
- package/dist/chunks/{chunk-NDEZ52SS.ts → chunk-OBVJTKVY.ts} +5 -5
- package/dist/chunks/{chunk-TJ7YNITN.ts → chunk-OWEOZZZE.ts} +2 -2
- package/dist/chunks/{chunk-VPSC7BXM.ts → chunk-SZJOUVCL.ts} +2 -2
- package/dist/chunks/{chunk-YT6PDRMM.ts → chunk-WJQ4TGN5.ts} +17 -17
- package/dist/chunks/chunk-WJQ4TGN5.ts.map +7 -0
- package/dist/chunks/{chunk-4VKWHVUO.ts → chunk-XUZV4OGI.ts} +3 -2
- package/dist/chunks/{chunk-4VKWHVUO.ts.map → chunk-XUZV4OGI.ts.map} +2 -2
- package/dist/chunks/{command-handler-N45GY7AV.ts → command-handler-YZ4DXQ7N.ts} +49 -10
- package/dist/chunks/command-handler-YZ4DXQ7N.ts.map +7 -0
- package/dist/chunks/{conflict-review-5E4M44BA.ts → conflict-review-J7L7S4AR.ts} +2 -2
- package/dist/chunks/{manager-result-dispatcher-FKW55L7I.ts → manager-result-dispatcher-XB75YLEG.ts} +4 -4
- package/dist/chunks/{manager-ui-EV23DPZQ.ts → manager-ui-RGA26Z6G.ts} +40 -38
- package/dist/chunks/manager-ui-RGA26Z6G.ts.map +7 -0
- package/dist/chunks/{merge-review-6YSLSMGS.ts → merge-review-AAC674C6.ts} +3 -3
- package/dist/chunks/{remote-selection-ui-N4NMWFT2.ts → remote-selection-ui-WVMET5RI.ts} +3 -3
- package/dist/chunks/{setup-switch-HY7K3442.ts → setup-switch-644T6KHG.ts} +3 -3
- package/dist/chunks/{setup-wizard-LEKDQ3HK.ts → setup-wizard-YP2KF2WQ.ts} +5 -5
- package/dist/chunks/{sync-inspection-OS2LVOLV.ts → sync-inspection-NBBTSMKR.ts} +2 -2
- package/dist/chunks/{sync-operations-D3MDJUQQ.ts → sync-operations-AIEM2KL2.ts} +2 -2
- package/dist/daemon/dist/client.js +125 -287
- package/dist/daemon/dist/daemon-recovery.js +85 -2
- package/dist/daemon/dist/daemon-startup.js +257 -0
- package/dist/daemon/dist/engine/backends/git/git-backend.js +10 -1
- package/dist/daemon/dist/engine/backends/s3/s3-backend.js +20 -9
- package/dist/daemon/dist/engine/backends/sync-backend.js +16 -0
- package/dist/daemon/dist/engine/backends/webdav/webdav-backend.js +19 -6
- package/dist/daemon/dist/engine/sync/directional-action.js +124 -0
- package/dist/daemon/dist/engine/sync/remote-snapshot.js +3 -1
- package/dist/daemon/dist/engine/sync/sync-errors.js +20 -0
- package/dist/daemon/dist/engine/sync/sync-local.js +56 -3
- package/dist/daemon/dist/engine/sync/sync-mutations.js +300 -334
- package/dist/daemon/dist/engine/sync/sync-queries.js +2 -1
- package/dist/daemon/dist/engine/sync/sync-rollback.js +198 -0
- package/dist/daemon/dist/engine/sync/transfer-freshness.js +11 -5
- package/dist/daemon/dist/engine-service.js +68 -0
- package/dist/daemon/dist/foreground-queue-outcome.js +9 -0
- package/dist/daemon/dist/monitor.js +1 -0
- package/dist/daemon/dist/server.js +76 -11
- package/dist/daemon/dist/service-host.js +56 -8
- package/dist/daemon/package.json +1 -1
- package/dist/index.ts +6 -6
- package/docs/daemon-migration.md +3 -6
- package/package.json +2 -2
- package/src/commands/command-execution.ts +56 -2
- package/src/commands/command-handler.ts +2 -0
- package/src/commands/command.ts +2 -1
- package/src/daemon/directional-recovery.ts +103 -0
- package/src/daemon/pi-client.ts +112 -9
- package/src/ui/cancellable-operation.ts +5 -2
- package/src/ui/manager-state.ts +2 -2
- package/src/ui/manager-ui.ts +29 -24
- package/src/ui/merge-review.ts +8 -9
- package/src/ui/sync-confirmation.ts +7 -7
- package/dist/chunks/chunk-CKUGCBHP.ts.map +0 -7
- package/dist/chunks/chunk-RW44KNFD.ts.map +0 -7
- package/dist/chunks/chunk-YT6PDRMM.ts.map +0 -7
- package/dist/chunks/command-handler-N45GY7AV.ts.map +0 -7
- package/dist/chunks/manager-ui-EV23DPZQ.ts.map +0 -7
- /package/dist/chunks/{chunk-F3VODLVQ.ts.map → chunk-IOM6E5FW.ts.map} +0 -0
- /package/dist/chunks/{chunk-NDEZ52SS.ts.map → chunk-OBVJTKVY.ts.map} +0 -0
- /package/dist/chunks/{chunk-TJ7YNITN.ts.map → chunk-OWEOZZZE.ts.map} +0 -0
- /package/dist/chunks/{chunk-VPSC7BXM.ts.map → chunk-SZJOUVCL.ts.map} +0 -0
- /package/dist/chunks/{conflict-review-5E4M44BA.ts.map → conflict-review-J7L7S4AR.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-FKW55L7I.ts.map → manager-result-dispatcher-XB75YLEG.ts.map} +0 -0
- /package/dist/chunks/{merge-review-6YSLSMGS.ts.map → merge-review-AAC674C6.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-N4NMWFT2.ts.map → remote-selection-ui-WVMET5RI.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-HY7K3442.ts.map → setup-switch-644T6KHG.ts.map} +0 -0
- /package/dist/chunks/{setup-wizard-LEKDQ3HK.ts.map → setup-wizard-YP2KF2WQ.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-OS2LVOLV.ts.map → sync-inspection-NBBTSMKR.ts.map} +0 -0
- /package/dist/chunks/{sync-operations-D3MDJUQQ.ts.map → sync-operations-AIEM2KL2.ts.map} +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { constants } from "node:fs";
|
|
1
2
|
import fs from "node:fs/promises";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { sessionDirFromContext } from "../snapshot/session-paths.js";
|
|
@@ -16,15 +17,63 @@ export function protectedSessionPaths(ctx, sessionRoot = sessionDirFromContext(c
|
|
|
16
17
|
return relative ? [relative] : [];
|
|
17
18
|
}));
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
import { captureMutationOwner } from "./mutation-owner.js";
|
|
21
|
+
export { captureMutationOwner };
|
|
22
|
+
export async function maybeReload(ctx, signal, validateMutation = captureMutationOwner(ctx, signal)) {
|
|
23
|
+
if (signal?.aborted || typeof ctx.reload !== "function")
|
|
24
|
+
return;
|
|
25
|
+
validateMutation();
|
|
26
|
+
if (ctx.hasUI &&
|
|
27
|
+
(await ctx.ui.confirm("Reload Pi resources now?", "This reloads extensions, skills, prompts, themes, and context files."))) {
|
|
28
|
+
if (signal?.aborted)
|
|
29
|
+
return;
|
|
30
|
+
validateMutation();
|
|
31
|
+
await ctx.reload();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
20
34
|
export async function backupLocal(profile, options = {}, signal) {
|
|
21
35
|
throwIfAborted(signal);
|
|
22
36
|
return backupSnapshot(await createSnapshot(profile, { ...options, signal }), signal);
|
|
23
37
|
}
|
|
24
38
|
export async function backupSnapshot(snapshot, signal) {
|
|
39
|
+
return (await writeSnapshotBackup(snapshot, signal)).backupPath;
|
|
40
|
+
}
|
|
41
|
+
export class LocalBackupVerificationError extends Error {
|
|
42
|
+
}
|
|
43
|
+
export async function backupDirectionalSnapshot(snapshot, signal) {
|
|
44
|
+
const { backupPath, encoded } = await writeSnapshotBackup(snapshot, signal, true);
|
|
45
|
+
const validate = async () => {
|
|
46
|
+
throwIfAborted(signal);
|
|
47
|
+
try {
|
|
48
|
+
if (stateDir() !== path.dirname(path.dirname(backupPath)) ||
|
|
49
|
+
!(await fs.lstat(path.dirname(backupPath))).isDirectory())
|
|
50
|
+
throw new Error("Local backup directory changed before Pull.");
|
|
51
|
+
const handle = await fs.open(backupPath, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
52
|
+
try {
|
|
53
|
+
const stat = await handle.stat();
|
|
54
|
+
if (!stat.isFile() || stat.size !== encoded.length || !(await handle.readFile()).equals(encoded))
|
|
55
|
+
throw new Error("Local backup no longer matches the exact pre-Pull bytes.");
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
await handle.close();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
throwIfAborted(signal);
|
|
63
|
+
throw new LocalBackupVerificationError(`Local backup could not be verified at ${backupPath}.`, { cause: error });
|
|
64
|
+
}
|
|
65
|
+
throwIfAborted(signal);
|
|
66
|
+
};
|
|
67
|
+
await validate();
|
|
68
|
+
return { backupPath, validate };
|
|
69
|
+
}
|
|
70
|
+
async function writeSnapshotBackup(snapshot, signal, durableParent = false) {
|
|
25
71
|
throwIfAborted(signal);
|
|
26
|
-
const
|
|
72
|
+
const root = stateDir();
|
|
73
|
+
const backupDirectory = path.join(root, "backups");
|
|
27
74
|
await fs.mkdir(backupDirectory, { recursive: true, mode: 0o700 });
|
|
75
|
+
if (durableParent && !(await fs.lstat(backupDirectory)).isDirectory())
|
|
76
|
+
throw new Error("Refusing to write to a linked local backup directory.");
|
|
28
77
|
throwIfAborted(signal);
|
|
29
78
|
const backupPath = path.join(backupDirectory, `${snapshot.id}.json.gz`);
|
|
30
79
|
const encoded = await encodeSnapshot(snapshot);
|
|
@@ -38,5 +87,9 @@ export async function backupSnapshot(snapshot, signal) {
|
|
|
38
87
|
await handle.close();
|
|
39
88
|
}
|
|
40
89
|
await syncDirectory(backupDirectory);
|
|
41
|
-
|
|
90
|
+
if (durableParent) {
|
|
91
|
+
await syncDirectory(root);
|
|
92
|
+
await syncDirectory(path.dirname(root));
|
|
93
|
+
}
|
|
94
|
+
return { backupPath, encoded };
|
|
42
95
|
}
|