@narumitw/pi-sync-daemon 0.6.2 → 0.8.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 +19 -0
- package/README.md +17 -3
- package/dist/consent.js +26 -1
- package/dist/engine/backends/git/git-backend.d.ts +1 -1
- package/dist/engine/backends/git/git-backend.js +17 -2
- package/dist/engine/backends/git/git-storage.d.ts +1 -1
- package/dist/engine/backends/git/git-storage.js +39 -13
- package/dist/engine/backends/s3/s3-backend.js +8 -0
- package/dist/engine/backends/sync-backend.d.ts +1 -0
- package/dist/engine/backends/webdav/webdav-backend.js +8 -0
- package/dist/engine/ignore/effective-ignore-policy.d.ts +10 -0
- package/dist/engine/ignore/effective-ignore-policy.js +33 -0
- package/dist/engine/ignore/ignore-edit.d.ts +13 -0
- package/dist/engine/ignore/ignore-edit.js +102 -0
- package/dist/engine/ignore/ignore-initialization.d.ts +6 -0
- package/dist/engine/ignore/ignore-initialization.js +186 -0
- package/dist/engine/ignore/ignore-migration-prompt.d.ts +7 -0
- package/dist/engine/ignore/ignore-migration-prompt.js +139 -0
- package/dist/engine/ignore/ignore-settings.d.ts +15 -0
- package/dist/engine/ignore/ignore-settings.js +322 -0
- package/dist/engine/ignore/ignore-source.d.ts +27 -0
- package/dist/engine/ignore/ignore-source.js +250 -0
- package/dist/engine/paths.js +1 -1
- package/dist/engine/settings/config-file.d.ts +9 -2
- package/dist/engine/settings/config-file.js +126 -28
- package/dist/engine/settings/config.d.ts +5 -4
- package/dist/engine/settings/config.js +114 -13
- package/dist/engine/settings/settings-management.js +34 -32
- package/dist/engine/settings/settings-types.d.ts +40 -5
- package/dist/engine/settings/settings-validation.js +52 -24
- package/dist/engine/snapshot/session-paths.d.ts +6 -4
- package/dist/engine/snapshot/session-paths.js +84 -15
- package/dist/engine/snapshot/snapshot-apply.d.ts +7 -8
- package/dist/engine/snapshot/snapshot-apply.js +107 -21
- package/dist/engine/snapshot/snapshot-bounds.d.ts +4 -0
- package/dist/engine/snapshot/snapshot-bounds.js +20 -0
- package/dist/engine/snapshot/snapshot-codec.d.ts +1 -1
- package/dist/engine/snapshot/snapshot-codec.js +15 -7
- package/dist/engine/snapshot/snapshot-entry-projection.d.ts +10 -0
- package/dist/engine/snapshot/snapshot-entry-projection.js +78 -0
- package/dist/engine/snapshot/snapshot-exclude-safety.d.ts +9 -2
- package/dist/engine/snapshot/snapshot-exclude-safety.js +239 -24
- package/dist/engine/snapshot/snapshot-payload.d.ts +2 -0
- package/dist/engine/snapshot/snapshot-payload.js +10 -0
- package/dist/engine/snapshot/snapshot-reviewed-preimages.d.ts +2 -0
- package/dist/engine/snapshot/snapshot-reviewed-preimages.js +60 -0
- package/dist/engine/snapshot/snapshot-root-transition.d.ts +4 -0
- package/dist/engine/snapshot/snapshot-root-transition.js +16 -0
- package/dist/engine/snapshot/snapshot-transaction-images.d.ts +39 -0
- package/dist/engine/snapshot/snapshot-transaction-images.js +387 -0
- package/dist/engine/snapshot/snapshot-transaction-policy.d.ts +73 -0
- package/dist/engine/snapshot/snapshot-transaction-policy.js +276 -0
- package/dist/engine/snapshot/snapshot-transaction-stage.d.ts +32 -0
- package/dist/engine/snapshot/snapshot-transaction-stage.js +303 -0
- package/dist/engine/snapshot/snapshot-transaction-verification.d.ts +7 -0
- package/dist/engine/snapshot/snapshot-transaction-verification.js +78 -0
- package/dist/engine/snapshot/snapshot-transaction.d.ts +1 -11
- package/dist/engine/snapshot/snapshot-transaction.js +390 -364
- package/dist/engine/snapshot/snapshot-types.d.ts +47 -2
- package/dist/engine/snapshot/snapshot-types.js +9 -1
- package/dist/engine/snapshot/snapshot.d.ts +22 -3
- package/dist/engine/snapshot/snapshot.js +357 -43
- package/dist/engine/state/merge-baseline-store.js +20 -9
- package/dist/engine/state/state-types.d.ts +3 -0
- package/dist/engine/sync/apply-review.d.ts +3 -3
- package/dist/engine/sync/apply-review.js +5 -4
- package/dist/engine/sync/continuous-sync.js +37 -12
- package/dist/engine/sync/continuous-watch.d.ts +4 -1
- package/dist/engine/sync/continuous-watch.js +90 -15
- package/dist/engine/sync/exclude-policy.d.ts +4 -0
- package/dist/engine/sync/exclude-policy.js +8 -1
- package/dist/engine/sync/initialization.js +9 -4
- package/dist/engine/sync/local-fields.d.ts +3 -1
- package/dist/engine/sync/local-fields.js +88 -8
- package/dist/engine/sync/merge-apply.js +190 -47
- package/dist/engine/sync/merge-journal.d.ts +18 -4
- package/dist/engine/sync/merge-journal.js +126 -10
- package/dist/engine/sync/merged-sync.d.ts +1 -1
- package/dist/engine/sync/merged-sync.js +124 -68
- package/dist/engine/sync/partial-progress.js +5 -3
- package/dist/engine/sync/remote-snapshot.d.ts +10 -2
- package/dist/engine/sync/remote-snapshot.js +59 -17
- package/dist/engine/sync/session-push.js +7 -6
- package/dist/engine/sync/sync-decision.d.ts +4 -0
- package/dist/engine/sync/sync-decision.js +17 -2
- package/dist/engine/sync/sync-inspection.js +8 -6
- package/dist/engine/sync/sync-mutations.d.ts +10 -2
- package/dist/engine/sync/sync-mutations.js +245 -101
- package/dist/engine/sync/sync-policy.d.ts +36 -10
- package/dist/engine/sync/sync-policy.js +285 -20
- package/dist/engine/sync/sync-queries.js +49 -32
- package/dist/engine/sync/sync-state.d.ts +11 -0
- package/dist/engine/sync/sync-state.js +42 -5
- package/dist/engine/ui/sync-format.js +22 -7
- package/dist/engine-service.js +24 -2
- package/docs/architecture.md +28 -0
- package/package.json +2 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { caseReplacementSpelling } from "./snapshot-case-replacement.js";
|
|
4
|
+
import { installedVacancyIdentityMatches, legacyImage, ownedLegacyPostTree, ownedScopedPostTree, ownedScopedSubset, recheckScopedImage, scopedIdentity, scopedTransactionImage, } from "./snapshot-transaction-images.js";
|
|
5
|
+
import { assertSafeParents, isScopedJournal, } from "./snapshot-transaction-policy.js";
|
|
6
|
+
export async function verifyTarget(directory, entry, journal, options, deletedByThisCall = false) {
|
|
7
|
+
await assertSafeParents(journal.root, journal.sessionRoot, entry.target);
|
|
8
|
+
const isScoped = isScopedJournal(journal);
|
|
9
|
+
const backup = isScoped && entry.kind !== "missing"
|
|
10
|
+
? await scopedTransactionImage(path.join(directory, "before", entry.backupName), options)
|
|
11
|
+
: undefined;
|
|
12
|
+
const before = isScoped ? (backup?.value ?? "missing") : await legacyBeforeImage(directory, entry);
|
|
13
|
+
if ((backup && backup.kind !== entry.kind) || (journal.version >= 2 && before !== entry.beforeImage))
|
|
14
|
+
throw new Error("Transaction backup changed; preserve evidence for review.");
|
|
15
|
+
const spelling = entry.afterTarget ? await caseReplacementSpelling(entry.target, entry.afterTarget) : entry.target;
|
|
16
|
+
const scoped = isScoped ? await scopedTransactionImage(entry.target, options) : undefined;
|
|
17
|
+
const value = scoped?.value ?? (await legacyImage(entry.target));
|
|
18
|
+
const result = { value, before, scoped };
|
|
19
|
+
const postFiles = entry.postFiles ?? [];
|
|
20
|
+
if (entry.vacantInstall) {
|
|
21
|
+
if (scoped?.kind === "missing" ||
|
|
22
|
+
(scoped &&
|
|
23
|
+
value === before &&
|
|
24
|
+
spelling === entry.target &&
|
|
25
|
+
(await installedVacancyMatches(entry.target, scoped, entry.vacantInstall, options))))
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
else if (value === "missing") {
|
|
29
|
+
if (value === before ||
|
|
30
|
+
deletedByThisCall ||
|
|
31
|
+
(journal.version >= 4 && entry.removalPending && !entry.replacementStarted))
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
else if (scoped && entry.scopedRemoval) {
|
|
35
|
+
const removal = entry.scopedRemoval;
|
|
36
|
+
if ((removal.image === "before"
|
|
37
|
+
? backup && ownedScopedSubset(scoped, backup)
|
|
38
|
+
: value === entry.afterImage || ownedScopedPostTree(scoped, postFiles, false)) &&
|
|
39
|
+
scoped.kind !== "missing" &&
|
|
40
|
+
scopedIdentity(scoped.stat) === removal.identity)
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
else if (value === before || (journal.version >= 2 && value === entry.afterImage)) {
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
else if (journal.version >= 2) {
|
|
47
|
+
const requireComplete = journal.version < 4 || entry.replacementStarted === true || !entry.removalPending;
|
|
48
|
+
if (scoped
|
|
49
|
+
? ownedScopedPostTree(scoped, postFiles, true)
|
|
50
|
+
: await ownedLegacyPostTree(entry.target, postFiles, requireComplete))
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
throw new Error("Transaction target has unrecognized or newer bytes; automatic rollback refused. Preserve the transaction and review its backup with Pi closed.");
|
|
54
|
+
}
|
|
55
|
+
async function installedVacancyMatches(target, image, expected, options) {
|
|
56
|
+
if (!installedVacancyIdentityMatches(image, expected) || image.kind === "missing")
|
|
57
|
+
return false;
|
|
58
|
+
if (scopedIdentity(image.stat) === expected)
|
|
59
|
+
return true;
|
|
60
|
+
const names = await fs.readdir(path.dirname(target));
|
|
61
|
+
options.validateMutation?.();
|
|
62
|
+
options.signal?.throwIfAborted();
|
|
63
|
+
if (!names.includes(path.basename(target)))
|
|
64
|
+
return false;
|
|
65
|
+
await recheckScopedImage(target, image, options);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
async function legacyBeforeImage(directory, entry) {
|
|
69
|
+
if (entry.kind === "missing")
|
|
70
|
+
return "missing";
|
|
71
|
+
const backup = path.join(directory, "before", entry.backupName);
|
|
72
|
+
if (entry.kind === "symlink")
|
|
73
|
+
return `symlink:${entry.linkTarget}`;
|
|
74
|
+
const value = await legacyImage(backup);
|
|
75
|
+
if (value === "missing")
|
|
76
|
+
throw new Error("Transaction backup is missing; preserve evidence for review.");
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
@@ -1,15 +1,5 @@
|
|
|
1
|
+
import { type TransactionOptions } from "./snapshot-transaction-policy.js";
|
|
1
2
|
import type { SnapshotApplyPlan } from "./snapshot-types.js";
|
|
2
|
-
interface TransactionOptions {
|
|
3
|
-
sessionDir?: string;
|
|
4
|
-
exclude?: readonly string[];
|
|
5
|
-
signal?: AbortSignal;
|
|
6
|
-
validateMutation?: () => void;
|
|
7
|
-
protectedTargets?: readonly string[];
|
|
8
|
-
/** Fresh apply authorization only; recovery remains bound to durable journal images. */
|
|
9
|
-
expectedPreimages?: ReadonlyMap<string, string>;
|
|
10
|
-
resolveConfiguredSessionDir?: boolean;
|
|
11
|
-
}
|
|
12
3
|
export declare function applySnapshotTransaction(plan: SnapshotApplyPlan, options?: TransactionOptions): Promise<void>;
|
|
13
4
|
export declare function recoverSnapshotTransactionsOnStartup(options?: TransactionOptions): Promise<void>;
|
|
14
5
|
export declare function recoverPendingSnapshotTransactions(options?: TransactionOptions): Promise<void>;
|
|
15
|
-
export {};
|