@narumitw/pi-sync 0.61.0 → 0.62.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 +12 -0
- package/README.md +24 -17
- package/dist/chunks/{chunk-EMVZL4PH.ts → chunk-3E3TR3JE.ts} +4 -4
- package/dist/chunks/{chunk-JVFCVPPD.ts → chunk-6PFZUEUG.ts} +41 -18
- package/dist/chunks/chunk-6PFZUEUG.ts.map +7 -0
- package/dist/chunks/{chunk-ZIL6PW5L.ts → chunk-6YKOHBSC.ts} +2 -2
- package/dist/chunks/{chunk-OA4NZLSL.ts → chunk-APZVJAEW.ts} +4 -3
- package/dist/chunks/{chunk-4SR3ZYHA.ts → chunk-GELYN4UC.ts} +2 -2
- package/dist/chunks/{chunk-S7F4FOAS.ts → chunk-GSCZ4VXV.ts} +5 -5
- package/dist/chunks/{chunk-YQSFJLJ3.ts → chunk-IBXEM35O.ts} +4 -3
- package/dist/chunks/{chunk-E3YLRLJM.ts → chunk-INECVQNR.ts} +10 -10
- package/dist/chunks/{chunk-2JHAN3ZO.ts → chunk-JREGWM2B.ts} +3 -3
- package/dist/chunks/{chunk-277VHM2P.ts → chunk-MNYRU5U5.ts} +5 -2
- package/dist/chunks/{chunk-277VHM2P.ts.map → chunk-MNYRU5U5.ts.map} +2 -2
- package/dist/chunks/{chunk-2ZGV5KNC.ts → chunk-NHFGAZEC.ts} +11 -8
- package/dist/chunks/chunk-NHFGAZEC.ts.map +7 -0
- package/dist/chunks/{chunk-EMRFVLZM.ts → chunk-NXWHPVXR.ts} +2 -2
- package/dist/chunks/{chunk-SMVKMYLK.ts → chunk-P4GI7LTT.ts} +2 -2
- package/dist/chunks/{chunk-PJMM75W5.ts → chunk-PWESMTH6.ts} +6 -6
- package/dist/chunks/{chunk-ZVGRZD4C.ts → chunk-R3SAMXB6.ts} +2 -2
- package/dist/chunks/{chunk-RNIEVDTR.ts → chunk-T3LABNHF.ts} +2 -2
- package/dist/chunks/{chunk-S3R3W3KF.ts → chunk-UMPA5S7X.ts} +2 -2
- package/dist/chunks/{chunk-WP2M67XZ.ts → chunk-WBIOSK76.ts} +2 -2
- package/dist/chunks/{chunk-4KTJLJSJ.ts → chunk-ZB3GNX3P.ts} +11 -11
- package/dist/chunks/{chunk-HEB6YT64.ts → chunk-ZO52JM4H.ts} +2 -2
- package/dist/chunks/{command-handler-K4XJOGYC.ts → command-handler-6ATREPG7.ts} +16 -16
- package/dist/chunks/command-handler-6ATREPG7.ts.map +7 -0
- package/dist/chunks/{conflict-review-IGKY2TOJ.ts → conflict-review-MAOGTIAI.ts} +4 -4
- package/dist/chunks/{continuous-record-3XDXDOMV.ts → continuous-record-3SKJ6I3V.ts} +2 -2
- package/dist/chunks/{continuous-storage-HLKCHF6Z.ts → continuous-storage-3EU6I7Z3.ts} +2 -2
- package/dist/chunks/{file-selection-MGGVOKM7.ts → file-selection-QR2KZVGD.ts} +10 -10
- package/dist/chunks/manager-result-dispatcher-MC6EQOQY.ts +19 -0
- package/dist/chunks/{manager-ui-KYQ5AZJS.ts → manager-ui-AOFUNXAJ.ts} +547 -135
- package/dist/chunks/manager-ui-AOFUNXAJ.ts.map +7 -0
- package/dist/chunks/remote-selection-ui-4BTP2OJR.ts +18 -0
- package/dist/chunks/{setup-switch-D6K6PBPC.ts → setup-switch-Y6AMFFNK.ts} +7 -7
- package/dist/chunks/{setup-wizard-4DYUDHJR.ts → setup-wizard-5G426MOZ.ts} +10 -10
- package/dist/chunks/{snapshot-5HY3M2NL.ts → snapshot-ZUJJZCFW.ts} +2 -2
- package/dist/chunks/{snapshot-transaction-directory-OU2D7R7A.ts → snapshot-transaction-directory-F46JWRAU.ts} +2 -2
- package/dist/chunks/{state-directory-XXHU73Z3.ts → state-directory-CMAIF34J.ts} +2 -2
- package/dist/chunks/{sync-inspection-J3CRBORL.ts → sync-inspection-ITZ6Z4DE.ts} +5 -5
- package/dist/chunks/{sync-operations-BVWYYKH3.ts → sync-operations-NMVKF7SE.ts} +13 -9
- package/dist/chunks/sync-operations-NMVKF7SE.ts.map +7 -0
- package/dist/chunks/{sync-state-2LMIXJ2C.ts → sync-state-QIT64TKV.ts} +2 -2
- package/dist/daemon/LICENSE +21 -0
- package/dist/daemon/dist/build-version.js +8 -0
- package/dist/daemon/dist/child-sdk.mjs +17 -0
- package/dist/daemon/dist/cli.js +169 -0
- package/dist/daemon/dist/client.js +909 -0
- package/dist/daemon/dist/consent.js +265 -0
- package/dist/daemon/dist/document.js +6 -0
- package/dist/daemon/dist/endpoint.js +91 -0
- package/dist/daemon/dist/engine/backends/backend-factory.js +16 -0
- package/dist/daemon/dist/engine/backends/backend-identity.js +38 -0
- package/dist/daemon/dist/engine/backends/backend-types.js +1 -0
- package/dist/daemon/dist/engine/backends/git/git-backend.js +715 -0
- package/dist/daemon/dist/engine/backends/git/git-config.js +118 -0
- package/dist/daemon/dist/engine/backends/git/git-runner.js +232 -0
- package/dist/daemon/dist/engine/backends/git/git-storage.js +252 -0
- package/dist/daemon/dist/engine/backends/s3/s3-backend.js +444 -0
- package/dist/daemon/dist/engine/backends/s3/s3-client.js +352 -0
- package/dist/daemon/dist/engine/backends/s3/s3-conditions.js +66 -0
- package/dist/daemon/dist/engine/backends/snapshot-pointer.js +22 -0
- package/dist/daemon/dist/engine/backends/sync-backend.js +23 -0
- package/dist/daemon/dist/engine/backends/webdav/webdav-backend.js +542 -0
- package/dist/daemon/dist/engine/backends/webdav/webdav-client.js +326 -0
- package/dist/daemon/dist/engine/backends/webdav/webdav-config.js +73 -0
- package/dist/daemon/dist/engine/commands/command-types.js +1 -0
- package/dist/daemon/dist/engine/host.js +16 -0
- package/dist/daemon/dist/engine/ignore/effective-ignore-policy.js +33 -0
- package/dist/daemon/dist/engine/ignore/ignore-edit.js +102 -0
- package/dist/daemon/dist/engine/ignore/ignore-initialization.js +186 -0
- package/dist/daemon/dist/engine/ignore/ignore-migration-prompt.js +139 -0
- package/dist/daemon/dist/engine/ignore/ignore-settings.js +322 -0
- package/dist/daemon/dist/engine/ignore/ignore-source.js +250 -0
- package/dist/daemon/dist/engine/paths.js +71 -0
- package/dist/daemon/dist/engine/settings/config-errors.js +4 -0
- package/dist/daemon/dist/engine/settings/config-file.js +736 -0
- package/dist/daemon/dist/engine/settings/config.js +301 -0
- package/dist/daemon/dist/engine/settings/settings-management.js +193 -0
- package/dist/daemon/dist/engine/settings/settings-store.js +41 -0
- package/dist/daemon/dist/engine/settings/settings-types.js +1 -0
- package/dist/daemon/dist/engine/settings/settings-validation.js +384 -0
- package/dist/daemon/dist/engine/snapshot/session-paths.js +160 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-apply.js +348 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-bounds.js +20 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-case-replacement.js +82 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-codec.js +61 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-entry-projection.js +78 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-exclude-safety.js +262 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-mutation-queues.js +133 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-paths.js +11 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-payload.js +10 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-reviewed-preimages.js +60 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-root-transition.js +138 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-directory.js +16 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-images.js +387 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-plan.js +68 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-policy.js +276 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-stage.js +303 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction-verification.js +78 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-transaction.js +813 -0
- package/dist/daemon/dist/engine/snapshot/snapshot-types.js +9 -0
- package/dist/daemon/dist/engine/snapshot/snapshot.js +678 -0
- package/dist/daemon/dist/engine/state/json-file.js +49 -0
- package/dist/daemon/dist/engine/state/lock-policy.js +2 -0
- package/dist/daemon/dist/engine/state/lock.js +259 -0
- package/dist/daemon/dist/engine/state/lockfile-fs.js +13 -0
- package/dist/daemon/dist/engine/state/merge-baseline-store.js +198 -0
- package/dist/daemon/dist/engine/state/mutation-directory-sync.js +34 -0
- package/dist/daemon/dist/engine/state/operation-availability.js +40 -0
- package/dist/daemon/dist/engine/state/state-directory.js +227 -0
- package/dist/daemon/dist/engine/state/state-types.js +1 -0
- package/dist/daemon/dist/engine/state/sync-state-store.js +54 -0
- package/dist/daemon/dist/engine/sync/agent-candidate.js +207 -0
- package/dist/daemon/dist/engine/sync/agent-plan.js +84 -0
- package/dist/daemon/dist/engine/sync/agent-policy.js +10 -0
- package/dist/daemon/dist/engine/sync/agent-refusal-retry.js +39 -0
- package/dist/daemon/dist/engine/sync/agent-request.js +13 -0
- package/dist/daemon/dist/engine/sync/agent-runner.js +183 -0
- package/dist/daemon/dist/engine/sync/agent-store.js +177 -0
- package/dist/daemon/dist/engine/sync/agent-sync.js +132 -0
- package/dist/daemon/dist/engine/sync/apply-review.js +52 -0
- package/dist/daemon/dist/engine/sync/conflict-artifact-ownership.js +53 -0
- package/dist/daemon/dist/engine/sync/conflict-artifacts.js +158 -0
- package/dist/daemon/dist/engine/sync/conflict-groups.js +76 -0
- package/dist/daemon/dist/engine/sync/conflict-preview.js +53 -0
- package/dist/daemon/dist/engine/sync/conflict-resolution.js +53 -0
- package/dist/daemon/dist/engine/sync/conflict-retention.js +61 -0
- package/dist/daemon/dist/engine/sync/conflict-review.js +73 -0
- package/dist/daemon/dist/engine/sync/content-conflicts.js +70 -0
- package/dist/daemon/dist/engine/sync/continuous-errors.js +66 -0
- package/dist/daemon/dist/engine/sync/continuous-lease.js +206 -0
- package/dist/daemon/dist/engine/sync/continuous-record.js +199 -0
- package/dist/daemon/dist/engine/sync/continuous-storage.js +59 -0
- package/dist/daemon/dist/engine/sync/continuous-sync.js +521 -0
- package/dist/daemon/dist/engine/sync/continuous-watch.js +140 -0
- package/dist/daemon/dist/engine/sync/exclude-policy.js +86 -0
- package/dist/daemon/dist/engine/sync/field-migration.js +20 -0
- package/dist/daemon/dist/engine/sync/file-merge-planner.js +123 -0
- package/dist/daemon/dist/engine/sync/initialization.js +80 -0
- package/dist/daemon/dist/engine/sync/json-document.js +172 -0
- package/dist/daemon/dist/engine/sync/local-field-policy.js +26 -0
- package/dist/daemon/dist/engine/sync/local-fields.js +196 -0
- package/dist/daemon/dist/engine/sync/merge-apply.js +529 -0
- package/dist/daemon/dist/engine/sync/merge-journal.js +295 -0
- package/dist/daemon/dist/engine/sync/merge-transfer-error.js +64 -0
- package/dist/daemon/dist/engine/sync/merged-sync.js +674 -0
- package/dist/daemon/dist/engine/sync/mutation-owner.js +18 -0
- package/dist/daemon/dist/engine/sync/package-merge.js +82 -0
- package/dist/daemon/dist/engine/sync/partial-progress.js +41 -0
- package/dist/daemon/dist/engine/sync/remote-snapshot.js +104 -0
- package/dist/daemon/dist/engine/sync/resolver-stream.js +34 -0
- package/dist/daemon/dist/engine/sync/session-merge.js +178 -0
- package/dist/daemon/dist/engine/sync/session-push.js +33 -0
- package/dist/daemon/dist/engine/sync/settings-conflicts.js +56 -0
- package/dist/daemon/dist/engine/sync/settings-merge.js +93 -0
- package/dist/daemon/dist/engine/sync/signals.js +8 -0
- package/dist/daemon/dist/engine/sync/startup-timings.js +44 -0
- package/dist/daemon/dist/engine/sync/sync-decision.js +81 -0
- package/dist/daemon/dist/engine/sync/sync-error-guidance.js +55 -0
- package/dist/daemon/dist/engine/sync/sync-errors.js +18 -0
- package/dist/daemon/dist/engine/sync/sync-inspection.js +42 -0
- package/dist/daemon/dist/engine/sync/sync-loaders.js +8 -0
- package/dist/daemon/dist/engine/sync/sync-local.js +40 -0
- package/dist/daemon/dist/engine/sync/sync-mutations.js +733 -0
- package/dist/daemon/dist/engine/sync/sync-operations.js +3 -0
- package/dist/daemon/dist/engine/sync/sync-policy.js +621 -0
- package/dist/daemon/dist/engine/sync/sync-queries.js +212 -0
- package/dist/daemon/dist/engine/sync/sync-state.js +129 -0
- package/dist/daemon/dist/engine/sync/text-merge.js +124 -0
- package/dist/daemon/dist/engine/types.js +2 -0
- package/dist/daemon/dist/engine/ui/merge-review.js +7 -0
- package/dist/daemon/dist/engine/ui/merged-sync-summary.js +86 -0
- package/dist/daemon/dist/engine/ui/sync-format.js +165 -0
- package/dist/daemon/dist/engine/ui/sync-status.js +30 -0
- package/dist/daemon/dist/engine/ui/terminal-text.js +9 -0
- package/dist/daemon/dist/engine/ui/transfer-changes.js +24 -0
- package/dist/daemon/dist/engine/ui/transfer-review.js +19 -0
- package/dist/daemon/dist/engine-service.js +344 -0
- package/dist/daemon/dist/identity.js +241 -0
- package/dist/daemon/dist/idle-exit.js +77 -0
- package/dist/daemon/dist/index.js +4 -0
- package/dist/daemon/dist/lifecycle-log.js +53 -0
- package/dist/daemon/dist/lifecycle.js +21 -0
- package/dist/daemon/dist/model-signature.js +7 -0
- package/dist/daemon/dist/monitor.js +272 -0
- package/dist/daemon/dist/participant-admission.js +30 -0
- package/dist/daemon/dist/protocol.js +104 -0
- package/dist/daemon/dist/resolver-host.js +78 -0
- package/dist/daemon/dist/server.js +953 -0
- package/dist/daemon/dist/service-host.js +174 -0
- package/dist/daemon/dist/upgrade-repair.js +55 -0
- package/dist/daemon/package.json +3 -0
- package/dist/index.ts +21 -21
- package/dist/package.json +6 -0
- package/docs/daemon-migration.md +27 -16
- package/package.json +9 -3
- package/skills/configure-pi-sync/SKILL.md +38 -13
- package/skills/configure-pi-sync/references/configuration.md +2 -2
- package/src/commands/command-execution.ts +1 -1
- package/src/settings/config.ts +1 -0
- package/src/sync/sync-operations.ts +18 -10
- package/src/ui/excluded-paths-ui.ts +4 -1
- package/src/ui/ignore-file-ui.ts +271 -0
- package/src/ui/ignore-migration-prompt.ts +65 -0
- package/src/ui/manager-state.ts +27 -13
- package/src/ui/manager-ui.ts +38 -19
- package/src/ui/remote-selection-ui.ts +41 -8
- package/src/ui/settings-review.ts +26 -0
- package/src/ui/settings-ui.ts +316 -213
- package/src/ui/storage-connections-ui.ts +20 -12
- package/src/ui/sync-setups-ui.ts +45 -27
- package/dist/chunks/chunk-2ZGV5KNC.ts.map +0 -7
- package/dist/chunks/chunk-JVFCVPPD.ts.map +0 -7
- package/dist/chunks/command-handler-K4XJOGYC.ts.map +0 -7
- package/dist/chunks/manager-result-dispatcher-4VJVDEUD.ts +0 -19
- package/dist/chunks/manager-ui-KYQ5AZJS.ts.map +0 -7
- package/dist/chunks/remote-selection-ui-W3KOZM3W.ts +0 -18
- package/dist/chunks/sync-operations-BVWYYKH3.ts.map +0 -7
- /package/dist/chunks/{chunk-EMVZL4PH.ts.map → chunk-3E3TR3JE.ts.map} +0 -0
- /package/dist/chunks/{chunk-ZIL6PW5L.ts.map → chunk-6YKOHBSC.ts.map} +0 -0
- /package/dist/chunks/{chunk-OA4NZLSL.ts.map → chunk-APZVJAEW.ts.map} +0 -0
- /package/dist/chunks/{chunk-4SR3ZYHA.ts.map → chunk-GELYN4UC.ts.map} +0 -0
- /package/dist/chunks/{chunk-S7F4FOAS.ts.map → chunk-GSCZ4VXV.ts.map} +0 -0
- /package/dist/chunks/{chunk-YQSFJLJ3.ts.map → chunk-IBXEM35O.ts.map} +0 -0
- /package/dist/chunks/{chunk-E3YLRLJM.ts.map → chunk-INECVQNR.ts.map} +0 -0
- /package/dist/chunks/{chunk-2JHAN3ZO.ts.map → chunk-JREGWM2B.ts.map} +0 -0
- /package/dist/chunks/{chunk-EMRFVLZM.ts.map → chunk-NXWHPVXR.ts.map} +0 -0
- /package/dist/chunks/{chunk-SMVKMYLK.ts.map → chunk-P4GI7LTT.ts.map} +0 -0
- /package/dist/chunks/{chunk-PJMM75W5.ts.map → chunk-PWESMTH6.ts.map} +0 -0
- /package/dist/chunks/{chunk-ZVGRZD4C.ts.map → chunk-R3SAMXB6.ts.map} +0 -0
- /package/dist/chunks/{chunk-RNIEVDTR.ts.map → chunk-T3LABNHF.ts.map} +0 -0
- /package/dist/chunks/{chunk-S3R3W3KF.ts.map → chunk-UMPA5S7X.ts.map} +0 -0
- /package/dist/chunks/{chunk-WP2M67XZ.ts.map → chunk-WBIOSK76.ts.map} +0 -0
- /package/dist/chunks/{chunk-4KTJLJSJ.ts.map → chunk-ZB3GNX3P.ts.map} +0 -0
- /package/dist/chunks/{chunk-HEB6YT64.ts.map → chunk-ZO52JM4H.ts.map} +0 -0
- /package/dist/chunks/{conflict-review-IGKY2TOJ.ts.map → conflict-review-MAOGTIAI.ts.map} +0 -0
- /package/dist/chunks/{continuous-record-3XDXDOMV.ts.map → continuous-record-3SKJ6I3V.ts.map} +0 -0
- /package/dist/chunks/{continuous-storage-HLKCHF6Z.ts.map → continuous-storage-3EU6I7Z3.ts.map} +0 -0
- /package/dist/chunks/{file-selection-MGGVOKM7.ts.map → file-selection-QR2KZVGD.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-4VJVDEUD.ts.map → manager-result-dispatcher-MC6EQOQY.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-W3KOZM3W.ts.map → remote-selection-ui-4BTP2OJR.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-D6K6PBPC.ts.map → setup-switch-Y6AMFFNK.ts.map} +0 -0
- /package/dist/chunks/{setup-wizard-4DYUDHJR.ts.map → setup-wizard-5G426MOZ.ts.map} +0 -0
- /package/dist/chunks/{snapshot-5HY3M2NL.ts.map → snapshot-ZUJJZCFW.ts.map} +0 -0
- /package/dist/chunks/{snapshot-transaction-directory-OU2D7R7A.ts.map → snapshot-transaction-directory-F46JWRAU.ts.map} +0 -0
- /package/dist/chunks/{state-directory-XXHU73Z3.ts.map → state-directory-CMAIF34J.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-J3CRBORL.ts.map → sync-inspection-ITZ6Z4DE.ts.map} +0 -0
- /package/dist/chunks/{sync-state-2LMIXJ2C.ts.map → sync-state-QIT64TKV.ts.map} +0 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { constants, lstatSync } from "node:fs";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import ignore from "ignore";
|
|
6
|
+
import { isDeniedPath } from "../paths.js";
|
|
7
|
+
export const DEFAULT_IGNORE_FILENAME = ".syncignore";
|
|
8
|
+
export const DEFAULT_IGNORE_CREATION_RECORD = ".pi-sync.json.syncignore-creation";
|
|
9
|
+
export const DEFAULT_IGNORE_RULES = "/npm/\n/sessions/\n/auth.json\n/truth.json\n";
|
|
10
|
+
export const MAX_IGNORE_BYTES = 64 * 1024;
|
|
11
|
+
const MAX_MATCH_PATH_BYTES = 4_096;
|
|
12
|
+
const MATCH_CACHE_PATH_BUDGET = 2_048;
|
|
13
|
+
const RESERVED_FILENAMES = new Set([
|
|
14
|
+
"auth.json",
|
|
15
|
+
"auth.json.lock",
|
|
16
|
+
"trust.json",
|
|
17
|
+
"trust.json.lock",
|
|
18
|
+
"settings.json",
|
|
19
|
+
"settings.json.lock",
|
|
20
|
+
"models.json",
|
|
21
|
+
"models-store.json",
|
|
22
|
+
"models-store.json.lock",
|
|
23
|
+
"keybindings.json",
|
|
24
|
+
"agents.md",
|
|
25
|
+
"system.md",
|
|
26
|
+
"append_system.md",
|
|
27
|
+
"crashes.json",
|
|
28
|
+
"pi-debug.log",
|
|
29
|
+
"extensions",
|
|
30
|
+
"skills",
|
|
31
|
+
"prompts",
|
|
32
|
+
"themes",
|
|
33
|
+
"npm",
|
|
34
|
+
"sessions",
|
|
35
|
+
]);
|
|
36
|
+
export function validateIgnoreFilename(value) {
|
|
37
|
+
if (typeof value !== "string" || !/^[A-Za-z0-9._ -]{1,255}$/u.test(value) || /^[ ]|[. ]$/u.test(value)) {
|
|
38
|
+
throw new Error("Invalid sync.ignoreFile: use one safe filename in the Pi agent directory.");
|
|
39
|
+
}
|
|
40
|
+
const lower = value.toLowerCase();
|
|
41
|
+
if (/^(?:con|prn|aux|nul|com[0-9]|lpt[0-9]) *(?:\.|$)/u.test(lower) ||
|
|
42
|
+
(lower === DEFAULT_IGNORE_FILENAME && value !== DEFAULT_IGNORE_FILENAME) ||
|
|
43
|
+
RESERVED_FILENAMES.has(lower) ||
|
|
44
|
+
isDeniedPath(lower)) {
|
|
45
|
+
throw new Error(`Invalid sync.ignoreFile: "${value}" is a reserved filename.`);
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
export class IgnoreCreationPendingError extends Error {
|
|
50
|
+
constructor() {
|
|
51
|
+
super(`unfinished creation record "${DEFAULT_IGNORE_CREATION_RECORD}"; retry confirmed setup or migration to verify the starter file, or repair the incomplete creation first`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export async function readIgnoreSource(root, filename = DEFAULT_IGNORE_FILENAME, signal) {
|
|
55
|
+
signal?.throwIfAborted();
|
|
56
|
+
filename = validateIgnoreFilename(filename);
|
|
57
|
+
try {
|
|
58
|
+
const absoluteRoot = path.resolve(root);
|
|
59
|
+
const rootStat = await fs.lstat(absoluteRoot, { bigint: true });
|
|
60
|
+
if (!rootStat.isDirectory())
|
|
61
|
+
throw new Error("the Pi agent directory is not a regular directory");
|
|
62
|
+
const canonicalRoot = await fs.realpath(absoluteRoot);
|
|
63
|
+
const checkRoot = async () => {
|
|
64
|
+
const currentRealpath = await fs.realpath(absoluteRoot);
|
|
65
|
+
const current = await fs.lstat(absoluteRoot, { bigint: true });
|
|
66
|
+
if (currentRealpath !== canonicalRoot || !current.isDirectory() || !sameIdentity(rootStat, current))
|
|
67
|
+
changed();
|
|
68
|
+
signal?.throwIfAborted();
|
|
69
|
+
checkCreationRecord();
|
|
70
|
+
};
|
|
71
|
+
const target = path.join(canonicalRoot, filename);
|
|
72
|
+
const checkCreationRecord = () => {
|
|
73
|
+
if (filename === DEFAULT_IGNORE_FILENAME &&
|
|
74
|
+
lstatSync(path.join(canonicalRoot, DEFAULT_IGNORE_CREATION_RECORD), { throwIfNoEntry: false })) {
|
|
75
|
+
throw new IgnoreCreationPendingError();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
checkCreationRecord();
|
|
79
|
+
const before = await statIfPresent(target);
|
|
80
|
+
await checkRoot();
|
|
81
|
+
if (!before) {
|
|
82
|
+
if (filename !== DEFAULT_IGNORE_FILENAME)
|
|
83
|
+
throw new Error("the selected file does not exist");
|
|
84
|
+
checkCreationRecord();
|
|
85
|
+
if (lstatSync(target, { throwIfNoEntry: false }))
|
|
86
|
+
changed();
|
|
87
|
+
signal?.throwIfAborted();
|
|
88
|
+
return {
|
|
89
|
+
filename,
|
|
90
|
+
text: DEFAULT_IGNORE_RULES,
|
|
91
|
+
sourceDigest: ignoreSourceDigest(filename, false, Buffer.from(DEFAULT_IGNORE_RULES)),
|
|
92
|
+
present: false,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (!before.isFile() || before.nlink !== 1n)
|
|
96
|
+
throw new Error("use a regular file with no symlinks or hard links");
|
|
97
|
+
assertIgnoreSize(before.size);
|
|
98
|
+
if ((await fs.realpath(target)) !== target)
|
|
99
|
+
throw new Error("use the exact on-disk filename, not a path alias");
|
|
100
|
+
const bytes = await readIgnoreBytes(target, before, checkRoot, signal);
|
|
101
|
+
await checkRoot();
|
|
102
|
+
checkCreationRecord();
|
|
103
|
+
const current = lstatSync(target, { bigint: true, throwIfNoEntry: false });
|
|
104
|
+
if (!current || !sameFile(before, current))
|
|
105
|
+
changed();
|
|
106
|
+
signal?.throwIfAborted();
|
|
107
|
+
let text;
|
|
108
|
+
try {
|
|
109
|
+
text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
110
|
+
}
|
|
111
|
+
catch (cause) {
|
|
112
|
+
throw new Error("the file is not valid UTF-8", { cause });
|
|
113
|
+
}
|
|
114
|
+
if (text.includes("\0"))
|
|
115
|
+
throw new Error("the file contains NUL characters");
|
|
116
|
+
return {
|
|
117
|
+
filename,
|
|
118
|
+
text,
|
|
119
|
+
sourceDigest: ignoreSourceDigest(filename, true, bytes),
|
|
120
|
+
present: true,
|
|
121
|
+
identity: ignoreFileIdentity(before),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
catch (cause) {
|
|
125
|
+
signal?.throwIfAborted();
|
|
126
|
+
const detail = cause.code
|
|
127
|
+
? "could not verify or read the file"
|
|
128
|
+
: cause.message;
|
|
129
|
+
throw new Error(`Ignore file "${filename}": ${detail}.`, { cause });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function statIfPresent(target) {
|
|
133
|
+
try {
|
|
134
|
+
return await fs.lstat(target, { bigint: true });
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
if (error.code === "ENOENT")
|
|
138
|
+
return undefined;
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export function ignoreFileIdentity(stat) {
|
|
143
|
+
return `${stat.dev}:${stat.ino}:${stat.birthtimeNs}`;
|
|
144
|
+
}
|
|
145
|
+
export function sameIdentity(left, right) {
|
|
146
|
+
return left.dev === right.dev && left.ino === right.ino && left.birthtimeNs === right.birthtimeNs;
|
|
147
|
+
}
|
|
148
|
+
export function sameFile(left, right) {
|
|
149
|
+
return (sameIdentity(left, right) &&
|
|
150
|
+
left.mode === right.mode &&
|
|
151
|
+
left.uid === right.uid &&
|
|
152
|
+
left.gid === right.gid &&
|
|
153
|
+
left.nlink === right.nlink &&
|
|
154
|
+
left.size === right.size &&
|
|
155
|
+
left.mtimeNs === right.mtimeNs &&
|
|
156
|
+
left.ctimeNs === right.ctimeNs);
|
|
157
|
+
}
|
|
158
|
+
function changed() {
|
|
159
|
+
throw new Error("the file or Pi agent directory changed during the read; retry");
|
|
160
|
+
}
|
|
161
|
+
async function readIgnoreBytes(target, before, checkRoot, signal) {
|
|
162
|
+
signal?.throwIfAborted();
|
|
163
|
+
const flags = constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0);
|
|
164
|
+
const handle = await fs.open(target, flags);
|
|
165
|
+
try {
|
|
166
|
+
if (!sameFile(before, await handle.stat({ bigint: true })))
|
|
167
|
+
changed();
|
|
168
|
+
await checkRoot();
|
|
169
|
+
const buffer = Buffer.alloc(Number(before.size) + 1);
|
|
170
|
+
let count = 0;
|
|
171
|
+
while (count < buffer.length) {
|
|
172
|
+
signal?.throwIfAborted();
|
|
173
|
+
const { bytesRead } = await handle.read(buffer, count, buffer.length - count, count);
|
|
174
|
+
if (bytesRead === 0)
|
|
175
|
+
break;
|
|
176
|
+
count += bytesRead;
|
|
177
|
+
}
|
|
178
|
+
if (count !== Number(before.size))
|
|
179
|
+
changed();
|
|
180
|
+
if (!sameFile(before, await fs.lstat(target, { bigint: true })))
|
|
181
|
+
changed();
|
|
182
|
+
await checkRoot();
|
|
183
|
+
if (!sameFile(before, await handle.stat({ bigint: true })))
|
|
184
|
+
changed();
|
|
185
|
+
return buffer.subarray(0, count);
|
|
186
|
+
}
|
|
187
|
+
finally {
|
|
188
|
+
await handle.close();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function assertIgnoreSize(bytes) {
|
|
192
|
+
if (bytes > MAX_IGNORE_BYTES)
|
|
193
|
+
throw new Error(`rules exceed the ${MAX_IGNORE_BYTES}-byte limit`);
|
|
194
|
+
}
|
|
195
|
+
export function ignoreSourceDigest(filename, present, bytes) {
|
|
196
|
+
return createHash("sha256")
|
|
197
|
+
.update("pi-sync-ignore-source-v1\0")
|
|
198
|
+
.update(filename)
|
|
199
|
+
.update(present ? "\0present\0" : "\0absent\0")
|
|
200
|
+
.update(bytes)
|
|
201
|
+
.digest("hex");
|
|
202
|
+
}
|
|
203
|
+
export function ignorePolicyFingerprint(text, sessions) {
|
|
204
|
+
return createHash("sha256")
|
|
205
|
+
.update(JSON.stringify(["pi-sync-ignore-policy-v1", sessions, text]))
|
|
206
|
+
.digest("hex");
|
|
207
|
+
}
|
|
208
|
+
function gitByteString(value) {
|
|
209
|
+
return Buffer.from(value, "utf8").toString("latin1");
|
|
210
|
+
}
|
|
211
|
+
export function compileIgnoreRules(text) {
|
|
212
|
+
assertIgnoreSize(Buffer.byteLength(text, "utf8"));
|
|
213
|
+
if (!text.isWellFormed() || text.includes("\0"))
|
|
214
|
+
throw new Error("Ignore rules must be UTF-8 text without NULs.");
|
|
215
|
+
const rules = text.replace(/^\uFEFF/u, "");
|
|
216
|
+
for (const [index, line] of rules.split("\n").entries()) {
|
|
217
|
+
if (line.startsWith("#"))
|
|
218
|
+
continue;
|
|
219
|
+
for (let position = 0; position < line.length; position++) {
|
|
220
|
+
if (line[position] !== "\\")
|
|
221
|
+
continue;
|
|
222
|
+
if (line[++position] === "/") {
|
|
223
|
+
throw new Error(`Ignore rule on line ${index + 1} uses an unsupported escaped path separator.`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const compiled = ignore({ ignorecase: false }).add(gitByteString(rules));
|
|
228
|
+
let matcher = ignore({ ignorecase: false }).add(compiled);
|
|
229
|
+
let cachedPathUpperBound = 0;
|
|
230
|
+
return (relativePath, directory = false) => {
|
|
231
|
+
if (Buffer.byteLength(relativePath, "utf8") > MAX_MATCH_PATH_BYTES) {
|
|
232
|
+
throw new Error(`Ignore matching path exceeds the ${MAX_MATCH_PATH_BYTES}-byte limit.`);
|
|
233
|
+
}
|
|
234
|
+
const segments = relativePath.split("/");
|
|
235
|
+
if (!relativePath.isWellFormed() ||
|
|
236
|
+
relativePath.includes("\\") ||
|
|
237
|
+
relativePath.includes("\0") ||
|
|
238
|
+
/^[a-z]:/iu.test(relativePath) ||
|
|
239
|
+
segments.some((part) => !part || part === "." || part === "..")) {
|
|
240
|
+
throw new Error("Ignore matching requires a canonical relative path with / separators.");
|
|
241
|
+
}
|
|
242
|
+
if (cachedPathUpperBound + segments.length > MATCH_CACHE_PATH_BUDGET) {
|
|
243
|
+
matcher = ignore({ ignorecase: false }).add(compiled);
|
|
244
|
+
cachedPathUpperBound = 0;
|
|
245
|
+
}
|
|
246
|
+
cachedPathUpperBound += segments.length;
|
|
247
|
+
const serializedPath = gitByteString(relativePath);
|
|
248
|
+
return matcher.ignores(directory ? `${serializedPath}/` : serializedPath);
|
|
249
|
+
};
|
|
250
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
export function isDeniedPath(relativePath) {
|
|
3
|
+
const normalized = toPosix(relativePath);
|
|
4
|
+
const lower = normalized.toLowerCase();
|
|
5
|
+
const segments = lower.split("/");
|
|
6
|
+
const base = path.posix.basename(lower);
|
|
7
|
+
return (segments.includes("node_modules") ||
|
|
8
|
+
segments.includes(".git") ||
|
|
9
|
+
segments.includes(".pisync") ||
|
|
10
|
+
segments.includes("pi-sync") ||
|
|
11
|
+
segments.includes(".pi-sync-state-migration.lock") ||
|
|
12
|
+
base === ".env" ||
|
|
13
|
+
base.startsWith(".env.") ||
|
|
14
|
+
base.endsWith(".env") ||
|
|
15
|
+
base.includes("secret") ||
|
|
16
|
+
base.includes("token") ||
|
|
17
|
+
base === "pi-sync.json" ||
|
|
18
|
+
base.startsWith("pi-sync.json.") ||
|
|
19
|
+
base.startsWith(".pi-sync.json.") ||
|
|
20
|
+
base === "pi-sync.local.json" ||
|
|
21
|
+
base.startsWith("pi-sync.local.json.") ||
|
|
22
|
+
base.startsWith(".pi-sync.local.json."));
|
|
23
|
+
}
|
|
24
|
+
export function isPathInside(parent, child) {
|
|
25
|
+
const relative = path.relative(path.resolve(parent), path.resolve(child));
|
|
26
|
+
return relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
27
|
+
}
|
|
28
|
+
export function safeJoin(root, relativePath) {
|
|
29
|
+
const target = path.resolve(root, relativePath);
|
|
30
|
+
assertWithinRoot(root, target, relativePath);
|
|
31
|
+
return target;
|
|
32
|
+
}
|
|
33
|
+
export function assertWithinRoot(root, target, label = target) {
|
|
34
|
+
const resolvedRoot = path.resolve(root);
|
|
35
|
+
const resolvedTarget = path.resolve(target);
|
|
36
|
+
if (resolvedTarget !== resolvedRoot && !resolvedTarget.startsWith(`${resolvedRoot}${path.sep}`)) {
|
|
37
|
+
throw new Error(`Unsafe path in snapshot: ${label}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function encodeKey(key) {
|
|
41
|
+
// SigV4 permits only RFC 3986 unreserved characters and key separators.
|
|
42
|
+
return key
|
|
43
|
+
.split("/")
|
|
44
|
+
.map(encodeURIComponent)
|
|
45
|
+
.join("/")
|
|
46
|
+
.replace(/[!'()*]/gu, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
47
|
+
}
|
|
48
|
+
export function posixJoin(...parts) {
|
|
49
|
+
return parts
|
|
50
|
+
.map((part) => trimSlashes(part))
|
|
51
|
+
.filter(Boolean)
|
|
52
|
+
.join("/");
|
|
53
|
+
}
|
|
54
|
+
export function parentPaths(relativePath) {
|
|
55
|
+
const results = [];
|
|
56
|
+
let index = relativePath.lastIndexOf("/");
|
|
57
|
+
while (index > 0) {
|
|
58
|
+
results.push(relativePath.slice(0, index));
|
|
59
|
+
index = relativePath.lastIndexOf("/", index - 1);
|
|
60
|
+
}
|
|
61
|
+
return results;
|
|
62
|
+
}
|
|
63
|
+
export function toPosix(value) {
|
|
64
|
+
return value.split(path.sep).join("/");
|
|
65
|
+
}
|
|
66
|
+
function trimSlashes(value) {
|
|
67
|
+
return value.replace(/^\/+|\/+$/g, "");
|
|
68
|
+
}
|
|
69
|
+
export function safeName(value) {
|
|
70
|
+
return value.replace(/[^A-Za-z0-9._-]/g, "_");
|
|
71
|
+
}
|