@narumitw/pi-sync 0.67.2 → 0.68.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 +17 -0
- package/README.md +29 -49
- package/dist/chunks/{chunk-XUZV4OGI.ts → chunk-335XTMMZ.ts} +3 -2
- package/dist/chunks/{chunk-XUZV4OGI.ts.map → chunk-335XTMMZ.ts.map} +2 -2
- package/dist/chunks/{chunk-PUSMSKIM.ts → chunk-AYGMIMCV.ts} +2 -11
- package/dist/chunks/chunk-AYGMIMCV.ts.map +7 -0
- package/dist/chunks/{chunk-2MSJDLSM.ts → chunk-BCDBT4X3.ts} +7 -7
- package/dist/chunks/{chunk-GRXNUC6O.ts → chunk-FQKWGVMA.ts} +20 -54
- package/dist/chunks/chunk-FQKWGVMA.ts.map +7 -0
- package/dist/chunks/{chunk-DGVZYS7T.ts → chunk-FR6A7ASZ.ts} +8 -11
- package/dist/chunks/chunk-FR6A7ASZ.ts.map +7 -0
- package/dist/chunks/{chunk-3NS4PMCI.ts → chunk-J52GYZO6.ts} +2 -8
- package/dist/chunks/{chunk-3NS4PMCI.ts.map → chunk-J52GYZO6.ts.map} +2 -2
- package/dist/chunks/{chunk-2MUAR5GH.ts → chunk-KAIVTJIQ.ts} +7 -10
- package/dist/chunks/chunk-KAIVTJIQ.ts.map +7 -0
- package/dist/chunks/{chunk-WBIOSK76.ts → chunk-R7PN3KIY.ts} +1 -2
- package/dist/chunks/{chunk-3Q3DMMID.ts → chunk-TLYT6HVI.ts} +8 -8
- package/dist/chunks/{chunk-UF2HU2NM.ts → chunk-WCGLU526.ts} +39 -118
- package/dist/chunks/chunk-WCGLU526.ts.map +7 -0
- package/dist/chunks/{chunk-JREGWM2B.ts → chunk-XNUARYLR.ts} +1 -2
- package/dist/chunks/{chunk-C3E75DXW.ts → chunk-YV2R5SJU.ts} +73 -85
- package/dist/chunks/chunk-YV2R5SJU.ts.map +7 -0
- package/dist/chunks/{command-handler-HWRPH3K3.ts → command-handler-S6BRZMPW.ts} +117 -69
- package/dist/chunks/command-handler-S6BRZMPW.ts.map +7 -0
- package/dist/chunks/{conflict-review-OBBBSVQD.ts → conflict-review-3XMYDJIK.ts} +2 -2
- package/dist/chunks/{file-selection-GASCVN45.ts → file-selection-4BOQBXS7.ts} +10 -17
- package/dist/chunks/file-selection-4BOQBXS7.ts.map +7 -0
- package/dist/chunks/{manager-result-dispatcher-MJ6G2CEI.ts → manager-result-dispatcher-A4IWLS4J.ts} +7 -7
- package/dist/chunks/{manager-ui-Z3B5ZTA6.ts → manager-ui-KHMCSLLV.ts} +114 -581
- package/dist/chunks/manager-ui-KHMCSLLV.ts.map +7 -0
- package/dist/chunks/{chunk-ECUCXF5Y.ts → merge-review-LWMUE5IW.ts} +2 -3
- package/dist/chunks/{remote-selection-ui-34WC7OFE.ts → remote-selection-ui-F6NJBQ3Y.ts} +6 -6
- package/dist/chunks/{setup-switch-JZDFQPVW.ts → setup-switch-7LMIRMZ7.ts} +6 -6
- package/dist/chunks/{setup-wizard-YOXLXLBY.ts → setup-wizard-2NRPR433.ts} +11 -16
- package/dist/chunks/{setup-wizard-YOXLXLBY.ts.map → setup-wizard-2NRPR433.ts.map} +1 -1
- package/dist/chunks/{sync-inspection-NIITROKS.ts → sync-inspection-QGM54YCM.ts} +5 -5
- package/dist/chunks/{sync-operations-FFI4ZZQL.ts → sync-operations-DTQMKVRQ.ts} +2 -2
- package/dist/daemon/dist/build-id.json +1 -0
- package/dist/daemon/dist/build-version.js +24 -4
- package/dist/daemon/dist/cli.js +51 -67
- package/dist/daemon/dist/client-transport.js +15 -5
- package/dist/daemon/dist/client.js +2 -10
- package/dist/daemon/dist/consent.js +13 -126
- package/dist/daemon/dist/daemon-startup.js +135 -30
- package/dist/daemon/dist/daemon-status.js +56 -0
- package/dist/daemon/dist/engine/backends/git/git-backend.js +4 -17
- package/dist/daemon/dist/engine/backends/git/git-storage.js +11 -44
- package/dist/daemon/dist/engine/backends/s3/s3-backend.js +6 -6
- package/dist/daemon/dist/engine/backends/webdav/webdav-backend.js +6 -6
- package/dist/daemon/dist/engine/settings/config.js +16 -149
- package/dist/daemon/dist/engine/settings/retired-ignore-policy.js +16 -0
- package/dist/daemon/dist/engine/settings/retired-ignore-recovery.js +14 -0
- package/dist/daemon/dist/engine/settings/settings-management.js +2 -10
- package/dist/daemon/dist/engine/settings/settings-validation.js +8 -21
- package/dist/daemon/dist/engine/snapshot/session-paths.js +13 -41
- package/dist/daemon/dist/engine/snapshot/snapshot-apply.js +8 -24
- package/dist/daemon/dist/engine/snapshot/snapshot-codec.js +7 -11
- package/dist/daemon/dist/engine/snapshot/snapshot-exclude-safety.js +19 -76
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-images.js +1 -7
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-policy.js +8 -102
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction.js +20 -100
- package/dist/daemon/dist/engine/snapshot/snapshot-types.js +1 -11
- package/dist/daemon/dist/engine/snapshot/snapshot.js +26 -78
- package/dist/daemon/dist/engine/state/sync-state-store.js +5 -1
- package/dist/daemon/dist/engine/sync/agent-plan.js +0 -1
- package/dist/daemon/dist/engine/sync/agent-policy.js +1 -1
- package/dist/daemon/dist/engine/sync/conflict-review.js +0 -2
- package/dist/daemon/dist/engine/sync/continuous-sync.js +2 -17
- package/dist/daemon/dist/engine/sync/continuous-watch.js +3 -7
- package/dist/daemon/dist/engine/sync/directional-action.js +3 -21
- package/dist/daemon/dist/engine/sync/initialization.js +4 -15
- package/dist/daemon/dist/engine/sync/local-fields.js +4 -65
- package/dist/daemon/dist/engine/sync/merge-apply.js +8 -31
- package/dist/daemon/dist/engine/sync/merge-journal.js +8 -118
- package/dist/daemon/dist/engine/sync/merged-sync.js +13 -70
- package/dist/daemon/dist/engine/sync/push-review.js +1 -16
- package/dist/daemon/dist/engine/sync/remote-snapshot.js +48 -65
- package/dist/daemon/dist/engine/sync/startup-bootstrap.js +3 -3
- package/dist/daemon/dist/engine/sync/sync-error-guidance.js +1 -1
- package/dist/daemon/dist/engine/sync/sync-inspection.js +1 -2
- package/dist/daemon/dist/engine/sync/sync-mutations.js +26 -118
- package/dist/daemon/dist/engine/sync/sync-policy.js +26 -150
- package/dist/daemon/dist/engine/sync/sync-queries.js +1 -8
- package/dist/daemon/dist/engine/sync/sync-rollback.js +12 -50
- package/dist/daemon/dist/engine/sync/sync-state.js +2 -15
- package/dist/daemon/dist/engine/sync/transfer-freshness.js +7 -17
- package/dist/daemon/dist/engine/sync/transfer-size-limits.js +3 -7
- package/dist/daemon/dist/engine-service.js +62 -205
- package/dist/daemon/dist/foreground-queue-outcome.js +0 -4
- package/dist/daemon/dist/index.js +2 -0
- package/dist/daemon/dist/legacy-consent-guard.js +34 -0
- package/dist/daemon/dist/server.js +99 -11
- package/dist/daemon/dist/service-host.js +3 -9
- package/dist/daemon/package.json +1 -1
- package/dist/index.ts +49 -49
- package/dist/index.ts.map +3 -3
- package/docs/agent-continuous-hardening.md +2 -0
- package/docs/continuous-sync-verification.md +1 -1
- package/docs/daemon-migration.md +17 -15
- package/docs/tui-contract.md +4 -6
- package/package.json +2 -3
- package/skills/configure-pi-sync/SKILL.md +23 -78
- package/skills/configure-pi-sync/references/configuration.md +59 -76
- package/src/commands/command-execution.ts +15 -38
- package/src/commands/command-handler.ts +0 -4
- package/src/commands/command.ts +2 -1
- package/src/daemon/daemon-status-ui.ts +64 -0
- package/src/daemon/directional-recovery.ts +4 -33
- package/src/daemon/pi-client.ts +87 -94
- package/src/settings/config.ts +0 -1
- package/src/sync/setup-switch.ts +1 -4
- package/src/sync-extension.ts +14 -27
- package/src/ui/cancellable-operation.ts +2 -13
- package/src/ui/excluded-paths-ui.ts +1 -4
- package/src/ui/file-selection.ts +0 -5
- package/src/ui/manager-state.ts +12 -75
- package/src/ui/manager-ui.ts +7 -96
- package/src/ui/remote-selection-ui.ts +29 -130
- package/src/ui/settings-ui.ts +169 -388
- package/src/ui/setup/setup-actions.ts +4 -16
- package/src/ui/setup/setup-prompts.ts +12 -49
- package/src/ui/setup/setup-switcher.ts +8 -14
- package/src/ui/storage-connections-ui.ts +21 -32
- package/src/ui/sync-setups-ui.ts +27 -53
- package/dist/chunks/chunk-2MUAR5GH.ts.map +0 -7
- package/dist/chunks/chunk-C3E75DXW.ts.map +0 -7
- package/dist/chunks/chunk-DGVZYS7T.ts.map +0 -7
- package/dist/chunks/chunk-EJDDRS6O.ts +0 -17
- package/dist/chunks/chunk-EJDDRS6O.ts.map +0 -7
- package/dist/chunks/chunk-GRXNUC6O.ts.map +0 -7
- package/dist/chunks/chunk-I72HGZJJ.ts +0 -106
- package/dist/chunks/chunk-I72HGZJJ.ts.map +0 -7
- package/dist/chunks/chunk-KNEUL4XN.ts +0 -30
- package/dist/chunks/chunk-KNEUL4XN.ts.map +0 -7
- package/dist/chunks/chunk-PUSMSKIM.ts.map +0 -7
- package/dist/chunks/chunk-UF2HU2NM.ts.map +0 -7
- package/dist/chunks/chunk-WFBHWYI6.ts +0 -18
- package/dist/chunks/chunk-WFBHWYI6.ts.map +0 -7
- package/dist/chunks/command-handler-HWRPH3K3.ts.map +0 -7
- package/dist/chunks/config-P54GGMXY.ts +0 -39
- package/dist/chunks/continuous-record-3SKJ6I3V.ts +0 -23
- package/dist/chunks/continuous-record-3SKJ6I3V.ts.map +0 -7
- package/dist/chunks/continuous-storage-3EU6I7Z3.ts +0 -27
- package/dist/chunks/continuous-storage-3EU6I7Z3.ts.map +0 -7
- package/dist/chunks/file-selection-GASCVN45.ts.map +0 -7
- package/dist/chunks/ignore-file-ui-5BWA6LBC.ts +0 -21
- package/dist/chunks/manager-ui-Z3B5ZTA6.ts.map +0 -7
- package/dist/chunks/merge-review-C2KETZKY.ts +0 -11
- package/dist/chunks/merge-review-C2KETZKY.ts.map +0 -7
- package/dist/chunks/remote-selection-ui-34WC7OFE.ts.map +0 -7
- package/dist/chunks/setup-switch-JZDFQPVW.ts.map +0 -7
- package/dist/daemon/dist/engine/ignore/adoption-journal.js +0 -146
- package/dist/daemon/dist/engine/ignore/effective-ignore-policy.js +0 -33
- package/dist/daemon/dist/engine/ignore/ignore-edit.js +0 -102
- package/dist/daemon/dist/engine/ignore/ignore-initialization.js +0 -288
- package/dist/daemon/dist/engine/ignore/ignore-migration-prompt.js +0 -139
- package/dist/daemon/dist/engine/ignore/ignore-settings.js +0 -391
- package/dist/daemon/dist/engine/ignore/ignore-source.js +0 -250
- package/dist/daemon/dist/engine/ignore/snapshot-ignore-rules.js +0 -39
- package/dist/daemon/dist/engine/sync/ignore-adoption-recovery.js +0 -50
- package/dist/daemon/dist/engine/sync/ignore-adoption.js +0 -416
- package/dist/daemon/dist/engine/sync/ignore-publication.js +0 -23
- package/dist/daemon/dist/engine/ui/ignore-rule-preview.js +0 -18
- package/dist/daemon/dist/monitor.js +0 -344
- package/src/ui/agent-mode-setting.ts +0 -99
- package/src/ui/ignore-file-guidance.ts +0 -7
- package/src/ui/ignore-file-ui.ts +0 -105
- package/src/ui/ignore-migration-prompt.ts +0 -65
- package/src/ui/settings-review.ts +0 -26
- /package/dist/chunks/{chunk-2MSJDLSM.ts.map → chunk-BCDBT4X3.ts.map} +0 -0
- /package/dist/chunks/{chunk-WBIOSK76.ts.map → chunk-R7PN3KIY.ts.map} +0 -0
- /package/dist/chunks/{chunk-3Q3DMMID.ts.map → chunk-TLYT6HVI.ts.map} +0 -0
- /package/dist/chunks/{chunk-JREGWM2B.ts.map → chunk-XNUARYLR.ts.map} +0 -0
- /package/dist/chunks/{conflict-review-OBBBSVQD.ts.map → conflict-review-3XMYDJIK.ts.map} +0 -0
- /package/dist/chunks/{config-P54GGMXY.ts.map → manager-result-dispatcher-A4IWLS4J.ts.map} +0 -0
- /package/dist/chunks/{chunk-ECUCXF5Y.ts.map → merge-review-LWMUE5IW.ts.map} +0 -0
- /package/dist/chunks/{ignore-file-ui-5BWA6LBC.ts.map → remote-selection-ui-F6NJBQ3Y.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-MJ6G2CEI.ts.map → setup-switch-7LMIRMZ7.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-NIITROKS.ts.map → sync-inspection-QGM54YCM.ts.map} +0 -0
- /package/dist/chunks/{sync-operations-FFI4ZZQL.ts.map → sync-operations-DTQMKVRQ.ts.map} +0 -0
|
@@ -3,7 +3,7 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { isPathInside, toPosix } from "../paths.js";
|
|
5
5
|
import { mergePathIdentity } from "../sync/file-merge-planner.js";
|
|
6
|
-
import { compileSyncPolicyExclude, compileSyncPolicyTraversal, configuredSnapshotPathMatcher,
|
|
6
|
+
import { compileSyncPolicyExclude, compileSyncPolicyTraversal, configuredSnapshotPathMatcher, } from "../sync/sync-policy.js";
|
|
7
7
|
import { sessionStorageRoot } from "./snapshot-paths.js";
|
|
8
8
|
function directoryStat(absolute) {
|
|
9
9
|
try {
|
|
@@ -56,75 +56,31 @@ export function agentDirectoryAnchor(root, boundary) {
|
|
|
56
56
|
}
|
|
57
57
|
return anchor;
|
|
58
58
|
}
|
|
59
|
-
export function agentDirectorySessionRoot(root, sessionDir
|
|
59
|
+
export function agentDirectorySessionRoot(root, sessionDir) {
|
|
60
60
|
const sessionRoot = sessionStorageRoot(root, sessionDir);
|
|
61
61
|
if (physicalRelative(sessionRoot, root) !== undefined)
|
|
62
62
|
throw new Error("Pi session storage overlaps the agent directory root.");
|
|
63
63
|
const relative = physicalRelative(root, sessionRoot);
|
|
64
64
|
if (relative !== undefined) {
|
|
65
|
-
const logical = toPosix(relative);
|
|
66
65
|
const canTraverse = compileSyncPolicyTraversal({ scope: "agent-directory", include: ["sessions"] });
|
|
67
|
-
|
|
68
|
-
? new Set([
|
|
69
|
-
...(ignorePolicy ? [ignorePolicy.filename, ...ignorePolicy.reservedNames] : []),
|
|
70
|
-
...(reservedIgnoreNames ?? []),
|
|
71
|
-
].map((name) => name.toLowerCase()))
|
|
72
|
-
: undefined;
|
|
73
|
-
if (!canTraverse(logical) || (reserved && isIgnoreControlPath(logical, reserved)))
|
|
66
|
+
if (!canTraverse(toPosix(relative)))
|
|
74
67
|
throw new Error("Pi session storage overlaps protected agent files.");
|
|
75
68
|
}
|
|
76
69
|
return sessionRoot;
|
|
77
70
|
}
|
|
78
|
-
export function agentDirectoryPhysicalSessionPath(root, sessionDir
|
|
79
|
-
const sessionRoot = agentDirectorySessionRoot(root, sessionDir
|
|
71
|
+
export function agentDirectoryPhysicalSessionPath(root, sessionDir) {
|
|
72
|
+
const sessionRoot = agentDirectorySessionRoot(root, sessionDir);
|
|
80
73
|
const nested = physicalRelative(root, sessionRoot) !== undefined;
|
|
81
74
|
return (relativePath) => nested && physicalRelative(sessionRoot, path.resolve(root, relativePath)) !== undefined;
|
|
82
75
|
}
|
|
83
|
-
async function realpathWithMissingTail(target) {
|
|
84
|
-
let ancestor = path.resolve(target);
|
|
85
|
-
for (;;) {
|
|
86
|
-
try {
|
|
87
|
-
const resolved = await fs.realpath(ancestor);
|
|
88
|
-
return path.resolve(resolved, path.relative(ancestor, target));
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
const code = error.code;
|
|
92
|
-
const parent = path.dirname(ancestor);
|
|
93
|
-
if (parent === ancestor || (code !== "ENOENT" && code !== "ENOTDIR"))
|
|
94
|
-
throw error;
|
|
95
|
-
ancestor = parent;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
export function reservedIgnoreTargetGuard(root, options) {
|
|
100
|
-
if (options.reservedIgnoreNames === undefined)
|
|
101
|
-
return undefined;
|
|
102
|
-
const reserved = new Set(options.reservedIgnoreNames);
|
|
103
|
-
function check(agentRoot, target) {
|
|
104
|
-
const relative = physicalRelative(agentRoot, target);
|
|
105
|
-
if (physicalRelative(target, agentRoot) !== undefined ||
|
|
106
|
-
(relative !== undefined && isIgnoreControlPath(toPosix(relative), reserved)))
|
|
107
|
-
throw new Error("Transfer would access a protected ignore rule path or its ancestor.");
|
|
108
|
-
}
|
|
109
|
-
return async (target) => {
|
|
110
|
-
check(root, target);
|
|
111
|
-
const canonicalRoot = await realpathWithMissingTail(root);
|
|
112
|
-
const canonicalTarget = await realpathWithMissingTail(target);
|
|
113
|
-
check(canonicalRoot, canonicalTarget);
|
|
114
|
-
return canonicalTarget;
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
76
|
/** Metadata-only preflight: an ancestor replacement must not capture/remove excluded descendants. */
|
|
118
77
|
export async function assertUnexcludedTargets(root, targets, options, { recursive = true } = {}) {
|
|
119
78
|
const wholeDirectory = options.scope === "agent-directory";
|
|
120
|
-
|
|
121
|
-
if (!wholeDirectory &&
|
|
122
|
-
!guardReserved &&
|
|
123
|
-
(options.exclude === undefined || (Array.isArray(options.exclude) && !options.exclude.length)))
|
|
79
|
+
if (!wholeDirectory && (options.exclude === undefined || (Array.isArray(options.exclude) && !options.exclude.length)))
|
|
124
80
|
return;
|
|
125
81
|
const excluded = compileSyncPolicyExclude(options);
|
|
126
82
|
const sessionRoot = wholeDirectory
|
|
127
|
-
? agentDirectorySessionRoot(root, options.sessionDir
|
|
83
|
+
? agentDirectorySessionRoot(root, options.sessionDir)
|
|
128
84
|
: sessionStorageRoot(root, options.sessionDir);
|
|
129
85
|
const configured = configuredSnapshotPathMatcher(options);
|
|
130
86
|
let visited = 0;
|
|
@@ -137,16 +93,11 @@ export async function assertUnexcludedTargets(root, targets, options, { recursiv
|
|
|
137
93
|
if (++visited > 16_384)
|
|
138
94
|
throw new Error("Exclude safety preflight exceeds its path bound; review a smaller transfer.");
|
|
139
95
|
};
|
|
140
|
-
|
|
96
|
+
const refuse = () => {
|
|
141
97
|
throw new Error("Transfer would replace an excluded path or directory descendant; no replacement is authorized.");
|
|
142
|
-
}
|
|
98
|
+
};
|
|
143
99
|
async function visit(target) {
|
|
144
100
|
validate();
|
|
145
|
-
if (guardReserved) {
|
|
146
|
-
await guardReserved(target);
|
|
147
|
-
validate();
|
|
148
|
-
}
|
|
149
|
-
let logicalPath;
|
|
150
101
|
let sessionPath;
|
|
151
102
|
if (wholeDirectory) {
|
|
152
103
|
if (physicalRelative(target, sessionRoot) !== undefined)
|
|
@@ -154,16 +105,14 @@ export async function assertUnexcludedTargets(root, targets, options, { recursiv
|
|
|
154
105
|
const sessionRelative = physicalRelative(sessionRoot, target);
|
|
155
106
|
if (sessionRelative !== undefined) {
|
|
156
107
|
sessionPath = `sessions/${toPosix(sessionRelative)}`;
|
|
157
|
-
|
|
108
|
+
if (excluded(sessionPath))
|
|
109
|
+
refuse();
|
|
158
110
|
}
|
|
159
111
|
else {
|
|
160
112
|
const relative = physicalRelative(root, target);
|
|
161
|
-
if (
|
|
113
|
+
if (relative === undefined || /^sessions(?:\/|$)/iu.test(toPosix(relative)) || excluded(toPosix(relative)))
|
|
162
114
|
refuse();
|
|
163
|
-
logicalPath = toPosix(relative);
|
|
164
115
|
}
|
|
165
|
-
if (!options.ignorePolicy && excluded(logicalPath))
|
|
166
|
-
refuse();
|
|
167
116
|
}
|
|
168
117
|
else {
|
|
169
118
|
const candidates = [];
|
|
@@ -171,28 +120,22 @@ export async function assertUnexcludedTargets(root, targets, options, { recursiv
|
|
|
171
120
|
candidates.push(toPosix(path.relative(root, target)));
|
|
172
121
|
if (isPathInside(sessionRoot, target))
|
|
173
122
|
candidates.push(`sessions/${toPosix(path.relative(sessionRoot, target))}`);
|
|
174
|
-
if (candidates.some(
|
|
123
|
+
if (candidates.some(excluded))
|
|
175
124
|
refuse();
|
|
176
125
|
}
|
|
177
|
-
let
|
|
126
|
+
let stat;
|
|
178
127
|
try {
|
|
179
|
-
|
|
128
|
+
stat = await fs.lstat(target);
|
|
180
129
|
}
|
|
181
130
|
catch (error) {
|
|
131
|
+
validate();
|
|
182
132
|
const code = error.code;
|
|
183
|
-
if (code !== "ENOENT" && code !== "ENOTDIR")
|
|
184
|
-
validate();
|
|
133
|
+
if (code !== "ENOENT" && code !== "ENOTDIR")
|
|
185
134
|
throw error;
|
|
186
|
-
|
|
135
|
+
return;
|
|
187
136
|
}
|
|
188
137
|
validate();
|
|
189
|
-
if (
|
|
190
|
-
refuse();
|
|
191
|
-
if (!observed)
|
|
192
|
-
return;
|
|
193
|
-
const stat = observed;
|
|
194
|
-
if ((wholeDirectory && !stat.isDirectory() && (!stat.isFile() || stat.nlink !== 1)) ||
|
|
195
|
-
(guardReserved && stat.isFile() && stat.nlink !== 1)) {
|
|
138
|
+
if (wholeDirectory && !stat.isDirectory() && (!stat.isFile() || stat.nlink !== 1)) {
|
|
196
139
|
throw new Error("Refusing an unsafe symlink, hard link, or special file during snapshot mutation.");
|
|
197
140
|
}
|
|
198
141
|
if (sessionPath && stat.isFile() && !configured(sessionPath))
|
|
@@ -294,7 +294,7 @@ export async function recheckScopedImage(target, image, guards) {
|
|
|
294
294
|
else if (await lstat(target, guards))
|
|
295
295
|
changedImage();
|
|
296
296
|
}
|
|
297
|
-
export async function removeScopedImage(target, image, guards
|
|
297
|
+
export async function removeScopedImage(target, image, guards) {
|
|
298
298
|
if (image.kind === "missing")
|
|
299
299
|
return;
|
|
300
300
|
async function remove(target, node) {
|
|
@@ -303,18 +303,12 @@ export async function removeScopedImage(target, image, guards, validateIgnorePol
|
|
|
303
303
|
const observed = await scopedTransactionImage(target, guards);
|
|
304
304
|
if (observed.kind !== "file" || !sameObservation(node.stat, observed.stat) || observed.value !== node.value)
|
|
305
305
|
changedImage();
|
|
306
|
-
if (validateIgnorePolicy) {
|
|
307
|
-
await validateIgnorePolicy();
|
|
308
|
-
await recheck(target, node.stat, guards);
|
|
309
|
-
}
|
|
310
306
|
validate(guards);
|
|
311
307
|
await fs.unlink(target);
|
|
312
308
|
return;
|
|
313
309
|
}
|
|
314
310
|
for (const [name, child] of node.children)
|
|
315
311
|
await remove(path.join(target, name), child);
|
|
316
|
-
if (validateIgnorePolicy)
|
|
317
|
-
await validateIgnorePolicy();
|
|
318
312
|
await recheck(target, node.stat, guards, true);
|
|
319
313
|
validate(guards);
|
|
320
314
|
await fs.rmdir(target);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { DEFAULT_IGNORE_FILENAME, validateIgnoreFilename } from "../ignore/ignore-source.js";
|
|
4
3
|
import { assertWithinRoot, isDeniedPath, isPathInside } from "../paths.js";
|
|
4
|
+
import { retiredIgnorePolicy } from "../settings/retired-ignore-policy.js";
|
|
5
5
|
import { normalizeSyncExclude, sameSyncExclude } from "../sync/exclude-policy.js";
|
|
6
6
|
import { mergePathIdentity } from "../sync/file-merge-planner.js";
|
|
7
|
-
import {
|
|
7
|
+
import { portableSnapshotSelection, syncDirectoryPolicyKey } from "../sync/sync-policy.js";
|
|
8
8
|
import { agentDir } from "./session-paths.js";
|
|
9
9
|
import { isCaseReplacement } from "./snapshot-case-replacement.js";
|
|
10
10
|
import { sessionStorageRoot } from "./snapshot-paths.js";
|
|
@@ -12,22 +12,11 @@ import { validateSessionRootTransition } from "./snapshot-root-transition.js";
|
|
|
12
12
|
export const LEGACY_AGENT_DIRECTORY_JOURNAL_VERSION = 8;
|
|
13
13
|
export const FIXED_WORKSPACE_JOURNAL_VERSION = 9;
|
|
14
14
|
export const AGENT_DIRECTORY_JOURNAL_VERSION = 10;
|
|
15
|
-
export const IGNORE_POLICY_JOURNAL_VERSION = 11;
|
|
16
|
-
export const BOUND_DIRECTORY_JOURNAL_VERSION = 12;
|
|
17
|
-
export const BOUND_INCLUDED_PATHS_JOURNAL_VERSION = 13;
|
|
18
|
-
function isLocallyBoundJournal(journal) {
|
|
19
|
-
return (journal.version === BOUND_DIRECTORY_JOURNAL_VERSION || journal.version === BOUND_INCLUDED_PATHS_JOURNAL_VERSION);
|
|
20
|
-
}
|
|
21
|
-
export function recoveryPolicyKey(options) {
|
|
22
|
-
return options.setupName || options.reservedIgnoreNames !== undefined ? localIgnorePolicyKey(options) : undefined;
|
|
23
|
-
}
|
|
24
15
|
export function isScopedJournal(journal) {
|
|
25
16
|
return [
|
|
26
17
|
LEGACY_AGENT_DIRECTORY_JOURNAL_VERSION,
|
|
27
18
|
FIXED_WORKSPACE_JOURNAL_VERSION,
|
|
28
19
|
AGENT_DIRECTORY_JOURNAL_VERSION,
|
|
29
|
-
IGNORE_POLICY_JOURNAL_VERSION,
|
|
30
|
-
BOUND_DIRECTORY_JOURNAL_VERSION,
|
|
31
20
|
].includes(journal.version);
|
|
32
21
|
}
|
|
33
22
|
function usesSlottedWorkspace(journal) {
|
|
@@ -39,81 +28,11 @@ export function isRecoveryStageId(value) {
|
|
|
39
28
|
export function isScopedIdentity(value) {
|
|
40
29
|
return typeof value === "string" && /^\d{1,20}:[1-9]\d{0,19}:\d{1,20}$/u.test(value);
|
|
41
30
|
}
|
|
42
|
-
export function ignoreSourceBinding(policy) {
|
|
43
|
-
const filename = validateIgnoreFilename(policy.filename);
|
|
44
|
-
if (typeof policy.sourceDigest !== "string" ||
|
|
45
|
-
policy.sourceDigest.length !== 64 ||
|
|
46
|
-
!/^[0-9a-f]{64}$/u.test(policy.sourceDigest))
|
|
47
|
-
throw new Error("Invalid ignore policy source digest.");
|
|
48
|
-
return {
|
|
49
|
-
version: 1,
|
|
50
|
-
filename,
|
|
51
|
-
sourceDigest: policy.sourceDigest,
|
|
52
|
-
reservedNames: [
|
|
53
|
-
...new Set([DEFAULT_IGNORE_FILENAME, filename, ...policy.reservedNames].map((name) => validateIgnoreFilename(name).toLowerCase())),
|
|
54
|
-
].sort(),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function sameIgnoreSource(left, right) {
|
|
58
|
-
return (left.version === right.version &&
|
|
59
|
-
left.filename === right.filename &&
|
|
60
|
-
left.sourceDigest === right.sourceDigest &&
|
|
61
|
-
left.reservedNames.length === right.reservedNames.length &&
|
|
62
|
-
left.reservedNames.every((name, index) => name === right.reservedNames[index]));
|
|
63
|
-
}
|
|
64
|
-
export class StaleIgnorePolicyError extends Error {
|
|
65
|
-
}
|
|
66
|
-
export function ignorePolicyValidator(options) {
|
|
67
|
-
const scopedIgnore = options.ignorePolicy !== undefined || options.version === 4;
|
|
68
|
-
if (!scopedIgnore && options.reservedIgnoreNames === undefined && !options.validateIgnorePolicy)
|
|
69
|
-
return;
|
|
70
|
-
const validateIgnorePolicy = options.validateIgnorePolicy;
|
|
71
|
-
if ((scopedIgnore && (!options.ignorePolicy || options.scope !== "agent-directory")) ||
|
|
72
|
-
typeof validateIgnorePolicy !== "function")
|
|
73
|
-
throw new Error("Ignore-file mutation requires an explicit local policy and a freshness check.");
|
|
74
|
-
return async () => {
|
|
75
|
-
options.validateMutation?.();
|
|
76
|
-
options.signal?.throwIfAborted();
|
|
77
|
-
try {
|
|
78
|
-
const pending = validateIgnorePolicy();
|
|
79
|
-
if (typeof pending?.then !== "function")
|
|
80
|
-
throw new Error("The ignore policy freshness check must be async.");
|
|
81
|
-
await pending;
|
|
82
|
-
}
|
|
83
|
-
catch (cause) {
|
|
84
|
-
throw new StaleIgnorePolicyError("Pi Sync ignore policy changed or could not be verified; preserve any transaction evidence and reopen the review.", { cause });
|
|
85
|
-
}
|
|
86
|
-
options.validateMutation?.();
|
|
87
|
-
options.signal?.throwIfAborted();
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
31
|
export function validateJournalPolicy(journal) {
|
|
91
|
-
if (
|
|
92
|
-
|
|
32
|
+
if (journal && ([11, 12, 13].includes(journal.version) || Object.hasOwn(journal, "ignoreSource")))
|
|
33
|
+
throw retiredIgnorePolicy("recovery");
|
|
34
|
+
if (!journal || (![1, 2, 3, 4, 5, 6, 7].includes(journal.version) && !isScopedJournal(journal)))
|
|
93
35
|
throw new Error("Unsupported pi-sync transaction journal; preserve evidence for review.");
|
|
94
|
-
if (isLocallyBoundJournal(journal)
|
|
95
|
-
? typeof journal.localPolicyKey !== "string" || !/^[0-9a-f]{64}$/u.test(journal.localPolicyKey)
|
|
96
|
-
: journal.localPolicyKey !== undefined)
|
|
97
|
-
throw new Error("Invalid transaction local policy binding; preserve evidence for review.");
|
|
98
|
-
if (journal.version === IGNORE_POLICY_JOURNAL_VERSION ||
|
|
99
|
-
(journal.version === BOUND_DIRECTORY_JOURNAL_VERSION && journal.selection?.version === 4)) {
|
|
100
|
-
const binding = journal.ignoreSource;
|
|
101
|
-
try {
|
|
102
|
-
if (journal.exclude === undefined &&
|
|
103
|
-
portableSnapshotSelection(journal.selection).version === 4 &&
|
|
104
|
-
binding &&
|
|
105
|
-
Array.isArray(binding.reservedNames) &&
|
|
106
|
-
Object.keys(binding).length === 4 &&
|
|
107
|
-
sameIgnoreSource(binding, ignoreSourceBinding(binding)))
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
catch (cause) {
|
|
111
|
-
throw new Error("Invalid ignore-file transaction policy; preserve evidence for review.", { cause });
|
|
112
|
-
}
|
|
113
|
-
throw new Error("Invalid ignore-file transaction policy; preserve evidence for review.");
|
|
114
|
-
}
|
|
115
|
-
if (journal.ignoreSource !== undefined)
|
|
116
|
-
throw new Error("Unsupported transaction ignore source binding; preserve evidence for review.");
|
|
117
36
|
if (isScopedJournal(journal)) {
|
|
118
37
|
if (journal.exclude !== undefined || portableSnapshotSelection(journal.selection).version !== 3)
|
|
119
38
|
throw new Error("Invalid agent-directory transaction policy; preserve evidence.");
|
|
@@ -126,18 +45,6 @@ export function validateJournalPolicy(journal) {
|
|
|
126
45
|
normalizeSyncExclude(journal.exclude);
|
|
127
46
|
}
|
|
128
47
|
export function assertRecoveryPolicy(journal, options) {
|
|
129
|
-
const localKey = recoveryPolicyKey(options);
|
|
130
|
-
if (journal.localPolicyKey !== localKey)
|
|
131
|
-
throw new Error("Pending transaction has different setup or ignore policy evidence; preserve its backup for reviewed recovery.");
|
|
132
|
-
if (journal.ignoreSource || options.ignorePolicy || options.version === 4) {
|
|
133
|
-
if (journal.ignoreSource &&
|
|
134
|
-
options.scope === "agent-directory" &&
|
|
135
|
-
options.ignorePolicy &&
|
|
136
|
-
sameIgnoreSource(journal.ignoreSource, ignoreSourceBinding(options.ignorePolicy)) &&
|
|
137
|
-
sameSnapshotSelection(journal.selection, selectionForSnapshot(undefined, undefined, options)))
|
|
138
|
-
return;
|
|
139
|
-
throw new Error("Pending transaction has a different ignore-file policy; preserve its backup for reviewed recovery.");
|
|
140
|
-
}
|
|
141
48
|
const directoryKey = syncDirectoryPolicyKey(journal.selection ?? {});
|
|
142
49
|
const effectiveDirectoryKey = syncDirectoryPolicyKey(options);
|
|
143
50
|
if (directoryKey !== undefined
|
|
@@ -153,14 +60,13 @@ export function validateJournal(directory, journal, sessionDir) {
|
|
|
153
60
|
if (!Array.isArray(journal.entries) || journal.entries.length > 16_384)
|
|
154
61
|
throw new Error("Unsupported pi-sync transaction journal; preserve evidence for review.");
|
|
155
62
|
if (journal.completed !== undefined &&
|
|
156
|
-
((!wholeDirectory && ![6, 7
|
|
157
|
-
journal.completed !== true))
|
|
63
|
+
((!wholeDirectory && ![6, 7].includes(journal.version)) || journal.completed !== true))
|
|
158
64
|
throw new Error("Invalid transaction completion evidence.");
|
|
159
65
|
const root = path.resolve(agentDir());
|
|
160
66
|
if (typeof journal.root !== "string" || path.resolve(journal.root) !== root)
|
|
161
67
|
throw new Error("Transaction root no longer matches the Pi agent directory.");
|
|
162
68
|
if (journal.sessionRootTransition !== undefined) {
|
|
163
|
-
if (![7
|
|
69
|
+
if (![7].includes(journal.version) || typeof journal.sessionRoot !== "string")
|
|
164
70
|
throw new Error("Invalid session root-transition version.");
|
|
165
71
|
validateSessionRootTransition(journal.sessionRootTransition);
|
|
166
72
|
}
|
|
@@ -191,7 +97,7 @@ export function validateJournal(directory, journal, sessionDir) {
|
|
|
191
97
|
assertWithinRoot(directory, path.join(directory, "before", entry.backupName));
|
|
192
98
|
assertAllowedTarget(root, journal.sessionRoot, entry.target);
|
|
193
99
|
if (entry.afterTarget !== undefined &&
|
|
194
|
-
((!wholeDirectory && ![5, 6, 7
|
|
100
|
+
((!wholeDirectory && ![5, 6, 7].includes(journal.version)) ||
|
|
195
101
|
typeof entry.afterTarget !== "string" ||
|
|
196
102
|
!isCaseReplacement(root, entry.target, entry.afterTarget) ||
|
|
197
103
|
path.resolve(entry.afterTarget) !== entry.afterTarget ||
|