@narumitw/pi-sync 0.61.0 → 0.63.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 +25 -0
- package/README.md +46 -25
- package/dist/chunks/{chunk-277VHM2P.ts → chunk-27F5W7DX.ts} +7 -3
- package/dist/chunks/chunk-27F5W7DX.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-CKUGCBHP.ts +114 -0
- package/dist/chunks/chunk-CKUGCBHP.ts.map +7 -0
- package/dist/chunks/chunk-EJDDRS6O.ts +17 -0
- package/dist/chunks/chunk-EJDDRS6O.ts.map +7 -0
- package/dist/chunks/{chunk-JVFCVPPD.ts → chunk-EXDWEFIJ.ts} +87 -147
- package/dist/chunks/chunk-EXDWEFIJ.ts.map +7 -0
- package/dist/chunks/{chunk-4SR3ZYHA.ts → chunk-GELYN4UC.ts} +2 -2
- package/dist/chunks/{chunk-2ZGV5KNC.ts → chunk-HSCAFOT5.ts} +15 -12
- package/dist/chunks/chunk-HSCAFOT5.ts.map +7 -0
- package/dist/chunks/{chunk-YQSFJLJ3.ts → chunk-IBXEM35O.ts} +4 -3
- package/dist/chunks/{chunk-2JHAN3ZO.ts → chunk-JREGWM2B.ts} +3 -3
- package/dist/chunks/chunk-MANNB4WZ.ts +36 -0
- package/dist/chunks/chunk-MANNB4WZ.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-ZVGRZD4C.ts → chunk-R3SAMXB6.ts} +2 -2
- package/dist/chunks/{chunk-4KTJLJSJ.ts → chunk-S6FUUWV5.ts} +148 -21
- package/dist/chunks/chunk-S6FUUWV5.ts.map +7 -0
- package/dist/chunks/{chunk-PJMM75W5.ts → chunk-SXCH4Q5O.ts} +41 -23
- package/dist/chunks/chunk-SXCH4Q5O.ts.map +7 -0
- package/dist/chunks/{chunk-RNIEVDTR.ts → chunk-T3LABNHF.ts} +2 -2
- package/dist/chunks/{chunk-E3YLRLJM.ts → chunk-UGS6RYDZ.ts} +14 -12
- package/dist/chunks/chunk-UGS6RYDZ.ts.map +7 -0
- package/dist/chunks/{chunk-S3R3W3KF.ts → chunk-UMPA5S7X.ts} +2 -2
- package/dist/chunks/{chunk-EMVZL4PH.ts → chunk-V76KCWHO.ts} +7 -5
- package/dist/chunks/{chunk-EMVZL4PH.ts.map → chunk-V76KCWHO.ts.map} +1 -1
- package/dist/chunks/{chunk-S7F4FOAS.ts → chunk-VQ47JBLF.ts} +5 -5
- package/dist/chunks/{chunk-WP2M67XZ.ts → chunk-WBIOSK76.ts} +2 -2
- package/dist/chunks/chunk-WFBHWYI6.ts +18 -0
- package/dist/chunks/chunk-WFBHWYI6.ts.map +7 -0
- package/dist/chunks/{chunk-HEB6YT64.ts → chunk-ZO52JM4H.ts} +2 -2
- package/dist/chunks/{command-handler-K4XJOGYC.ts → command-handler-VINMQ7ZM.ts} +26 -43
- package/dist/chunks/command-handler-VINMQ7ZM.ts.map +7 -0
- package/dist/chunks/{conflict-review-IGKY2TOJ.ts → conflict-review-PCDFRIVB.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-KID23GAD.ts} +21 -14
- package/dist/chunks/file-selection-KID23GAD.ts.map +7 -0
- package/dist/chunks/manager-result-dispatcher-GDB74IOP.ts +20 -0
- package/dist/chunks/{manager-ui-KYQ5AZJS.ts → manager-ui-YHDECYKI.ts} +454 -167
- package/dist/chunks/manager-ui-YHDECYKI.ts.map +7 -0
- package/dist/chunks/remote-selection-ui-GPITNEBF.ts +19 -0
- package/dist/chunks/{setup-switch-D6K6PBPC.ts → setup-switch-L54X5U5I.ts} +7 -7
- package/dist/chunks/{setup-wizard-4DYUDHJR.ts → setup-wizard-YO4MCPUF.ts} +15 -11
- package/dist/chunks/{setup-wizard-4DYUDHJR.ts.map → setup-wizard-YO4MCPUF.ts.map} +1 -1
- 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-H2WX5SUT.ts} +5 -5
- package/dist/chunks/{sync-operations-BVWYYKH3.ts → sync-operations-2MZAYHL2.ts} +13 -9
- package/dist/chunks/sync-operations-2MZAYHL2.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 +383 -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 +746 -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 +252 -0
- package/dist/daemon/dist/engine/ignore/ignore-migration-prompt.js +139 -0
- package/dist/daemon/dist/engine/ignore/ignore-settings.js +393 -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 +344 -0
- package/dist/daemon/dist/engine/settings/settings-management.js +199 -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 +165 -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 +296 -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 +855 -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 +85 -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 +139 -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 +538 -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-acceptance.js +29 -0
- package/dist/daemon/dist/engine/sync/merge-apply.js +532 -0
- package/dist/daemon/dist/engine/sync/merge-journal.js +314 -0
- package/dist/daemon/dist/engine/sync/merge-transfer-error.js +64 -0
- package/dist/daemon/dist/engine/sync/merged-sync.js +666 -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 +119 -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 +47 -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 +754 -0
- package/dist/daemon/dist/engine/sync/sync-operations.js +3 -0
- package/dist/daemon/dist/engine/sync/sync-policy.js +646 -0
- package/dist/daemon/dist/engine/sync/sync-queries.js +212 -0
- package/dist/daemon/dist/engine/sync/sync-state.js +124 -0
- package/dist/daemon/dist/engine/sync/text-merge.js +124 -0
- package/dist/daemon/dist/engine/sync/transfer-freshness.js +82 -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 +441 -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 +324 -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 +994 -0
- package/dist/daemon/dist/service-host.js +175 -0
- package/dist/daemon/dist/upgrade-repair.js +55 -0
- package/dist/daemon/package.json +3 -0
- package/dist/index.ts +40 -37
- package/dist/index.ts.map +4 -4
- 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 +24 -46
- package/skills/configure-pi-sync/references/configuration.md +62 -22
- package/src/commands/command-execution.ts +13 -9
- package/src/commands/command-types.ts +1 -0
- package/src/daemon/pi-client.ts +4 -2
- package/src/settings/config.ts +2 -0
- package/src/sync/automatic-sync.ts +9 -2
- package/src/sync/setup-switch.ts +38 -15
- package/src/sync/startup-check.ts +7 -4
- package/src/sync/sync-operations.ts +18 -10
- package/src/ui/excluded-paths-ui.ts +6 -3
- package/src/ui/file-selection.ts +7 -2
- package/src/ui/ignore-file-guidance.ts +7 -0
- package/src/ui/ignore-file-ui.ts +97 -0
- package/src/ui/ignore-migration-prompt.ts +65 -0
- package/src/ui/manager-state.ts +40 -14
- package/src/ui/manager-ui.ts +41 -19
- package/src/ui/remote-selection-ui.ts +88 -28
- package/src/ui/settings-review.ts +26 -0
- package/src/ui/settings-ui.ts +378 -224
- package/src/ui/setup/setup-actions.ts +16 -4
- package/src/ui/setup/setup-prompts.ts +55 -9
- package/src/ui/setup/setup-switcher.ts +24 -11
- package/src/ui/storage-connections-ui.ts +50 -20
- package/src/ui/sync-setups-ui.ts +65 -30
- package/dist/chunks/chunk-277VHM2P.ts.map +0 -7
- package/dist/chunks/chunk-2ZGV5KNC.ts.map +0 -7
- package/dist/chunks/chunk-4KTJLJSJ.ts.map +0 -7
- package/dist/chunks/chunk-E3YLRLJM.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-JVFCVPPD.ts.map +0 -7
- package/dist/chunks/chunk-PJMM75W5.ts.map +0 -7
- package/dist/chunks/command-handler-K4XJOGYC.ts.map +0 -7
- package/dist/chunks/file-selection-MGGVOKM7.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-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-YQSFJLJ3.ts.map → chunk-IBXEM35O.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-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-S7F4FOAS.ts.map → chunk-VQ47JBLF.ts.map} +0 -0
- /package/dist/chunks/{chunk-WP2M67XZ.ts.map → chunk-WBIOSK76.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-PCDFRIVB.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/{manager-result-dispatcher-4VJVDEUD.ts.map → manager-result-dispatcher-GDB74IOP.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-W3KOZM3W.ts.map → remote-selection-ui-GPITNEBF.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-D6K6PBPC.ts.map → setup-switch-L54X5U5I.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-H2WX5SUT.ts.map} +0 -0
- /package/dist/chunks/{sync-state-2LMIXJ2C.ts.map → sync-state-QIT64TKV.ts.map} +0 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { constants, lstatSync, realpathSync, unlinkSync } from "node:fs";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { DEFAULT_IGNORE_CREATION_RECORD, DEFAULT_IGNORE_FILENAME, DEFAULT_IGNORE_RULES, ignoreFileIdentity, readIgnoreSource, sameFile, sameIdentity, } from "./ignore-source.js";
|
|
5
|
+
const starter = Buffer.from(DEFAULT_IGNORE_RULES);
|
|
6
|
+
const record = Buffer.from(`pi-sync-ignore-creation-v1\n${DEFAULT_IGNORE_RULES}`);
|
|
7
|
+
const noFollow = (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0);
|
|
8
|
+
const openRead = constants.O_RDONLY | noFollow;
|
|
9
|
+
const openExisting = process.platform === "win32" ? constants.O_RDWR | noFollow : openRead;
|
|
10
|
+
const openExclusive = constants.O_RDWR | constants.O_CREAT | constants.O_EXCL | noFollow;
|
|
11
|
+
export class AutomaticIgnoreCreationUnavailable extends Error {
|
|
12
|
+
}
|
|
13
|
+
export async function checkAutomaticIgnoreCreation(root, signal) {
|
|
14
|
+
signal.throwIfAborted();
|
|
15
|
+
root = path.resolve(root);
|
|
16
|
+
const expected = await fs.lstat(root, { bigint: true });
|
|
17
|
+
signal.throwIfAborted();
|
|
18
|
+
assertRoot(root, expected);
|
|
19
|
+
await checkCreationAccess(root);
|
|
20
|
+
const { directory } = await openCreationDirectory(root, expected);
|
|
21
|
+
try {
|
|
22
|
+
signal.throwIfAborted();
|
|
23
|
+
await syncCreationDirectory(directory);
|
|
24
|
+
assertRoot(root, expected);
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
await directory?.close();
|
|
28
|
+
signal.throwIfAborted();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export async function initializeDefaultIgnoreSource(root, signal) {
|
|
32
|
+
return (await prepareDefaultIgnoreSource(root, signal)).source;
|
|
33
|
+
}
|
|
34
|
+
export async function prepareDefaultIgnoreSource(root, signal) {
|
|
35
|
+
signal?.throwIfAborted();
|
|
36
|
+
root = path.resolve(root);
|
|
37
|
+
try {
|
|
38
|
+
const initialRoot = await fs.lstat(root, { bigint: true });
|
|
39
|
+
const verifyRoot = () => assertRoot(root, initialRoot);
|
|
40
|
+
const checkRoot = () => {
|
|
41
|
+
signal?.throwIfAborted();
|
|
42
|
+
verifyRoot();
|
|
43
|
+
};
|
|
44
|
+
checkRoot();
|
|
45
|
+
const priorRecord = statAt(path.join(root, DEFAULT_IGNORE_CREATION_RECORD));
|
|
46
|
+
if (!priorRecord) {
|
|
47
|
+
const source = await readIgnoreSource(root, DEFAULT_IGNORE_FILENAME, signal);
|
|
48
|
+
checkRoot();
|
|
49
|
+
if (source.present)
|
|
50
|
+
return { source, created: false };
|
|
51
|
+
}
|
|
52
|
+
await checkCreationAccess(root);
|
|
53
|
+
const { directory, anchor } = await openCreationDirectory(root, initialRoot);
|
|
54
|
+
try {
|
|
55
|
+
checkRoot();
|
|
56
|
+
const flushDirectory = await syncCreationDirectory(directory);
|
|
57
|
+
checkRoot();
|
|
58
|
+
const markerPath = path.join(anchor, DEFAULT_IGNORE_CREATION_RECORD);
|
|
59
|
+
const target = path.join(anchor, DEFAULT_IGNORE_FILENAME);
|
|
60
|
+
if (priorRecord)
|
|
61
|
+
assertOwned(priorRecord, DEFAULT_IGNORE_CREATION_RECORD, true);
|
|
62
|
+
else if (statAt(target))
|
|
63
|
+
changed(DEFAULT_IGNORE_FILENAME);
|
|
64
|
+
const marker = await fs.open(markerPath, priorRecord ? openExisting : openExclusive, 0o600).catch((error) => {
|
|
65
|
+
if (!priorRecord)
|
|
66
|
+
checkCreationError(error);
|
|
67
|
+
throw error;
|
|
68
|
+
});
|
|
69
|
+
try {
|
|
70
|
+
const markerStat = await flushAndVerify(marker, markerPath, path.join(root, DEFAULT_IGNORE_CREATION_RECORD), record, priorRecord ? checkRoot : verifyRoot, priorRecord, true);
|
|
71
|
+
await flushDirectory();
|
|
72
|
+
checkRoot();
|
|
73
|
+
assertCurrent(markerPath, markerStat);
|
|
74
|
+
const priorFile = priorRecord ? statAt(target) : undefined;
|
|
75
|
+
if (priorFile)
|
|
76
|
+
assertOwned(priorFile, DEFAULT_IGNORE_FILENAME, false);
|
|
77
|
+
const file = await fs.open(target, priorFile ? openExisting : openExclusive, 0o600).catch(async (cause) => {
|
|
78
|
+
if (!priorRecord && cause.code === "EEXIST") {
|
|
79
|
+
verifyRoot();
|
|
80
|
+
assertCurrent(markerPath, markerStat);
|
|
81
|
+
unlinkSync(markerPath);
|
|
82
|
+
await flushDirectory();
|
|
83
|
+
}
|
|
84
|
+
throw cause;
|
|
85
|
+
});
|
|
86
|
+
try {
|
|
87
|
+
const checkTargetRoot = priorFile ? checkRoot : verifyRoot;
|
|
88
|
+
const fileStat = await flushAndVerify(file, target, path.join(root, DEFAULT_IGNORE_FILENAME), starter, () => {
|
|
89
|
+
checkTargetRoot();
|
|
90
|
+
assertCurrent(markerPath, markerStat);
|
|
91
|
+
}, priorFile);
|
|
92
|
+
await flushDirectory();
|
|
93
|
+
checkTargetRoot();
|
|
94
|
+
assertCurrent(target, fileStat);
|
|
95
|
+
assertCurrent(markerPath, markerStat);
|
|
96
|
+
unlinkSync(markerPath);
|
|
97
|
+
await flushDirectory();
|
|
98
|
+
checkRoot();
|
|
99
|
+
const source = await readIgnoreSource(root, DEFAULT_IGNORE_FILENAME, signal);
|
|
100
|
+
checkRoot();
|
|
101
|
+
if (source.identity !== ignoreFileIdentity(fileStat) || source.text !== DEFAULT_IGNORE_RULES) {
|
|
102
|
+
changed(DEFAULT_IGNORE_FILENAME);
|
|
103
|
+
}
|
|
104
|
+
return { source, created: priorFile === undefined };
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
await file.close();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
await marker.close();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
await directory?.close();
|
|
116
|
+
signal?.throwIfAborted();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (cause) {
|
|
120
|
+
signal?.throwIfAborted();
|
|
121
|
+
if (cause instanceof AutomaticIgnoreCreationUnavailable)
|
|
122
|
+
throw cause;
|
|
123
|
+
const code = cause.code;
|
|
124
|
+
const detail = code === "EEXIST"
|
|
125
|
+
? "a file or creation record appeared concurrently; review the current files and retry"
|
|
126
|
+
: code
|
|
127
|
+
? "could not safely create or flush the file"
|
|
128
|
+
: cause.message;
|
|
129
|
+
throw new Error(`Ignore file "${DEFAULT_IGNORE_FILENAME}" initialization: ${detail}.`, { cause });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function checkCreationError(error) {
|
|
133
|
+
if (["EACCES", "EPERM", "EROFS", "ENOTSUP", "EOPNOTSUPP"].includes(error.code ?? "")) {
|
|
134
|
+
throw new AutomaticIgnoreCreationUnavailable("the filesystem does not permit automatic creation", { cause: error });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async function checkCreationAccess(root) {
|
|
138
|
+
try {
|
|
139
|
+
await fs.access(root, constants.W_OK);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
checkCreationError(error);
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function assertRoot(root, expected) {
|
|
147
|
+
const current = lstatSync(root, { bigint: true });
|
|
148
|
+
if (!current.isDirectory() || !sameIdentity(expected, current) || realpathSync(root) !== root) {
|
|
149
|
+
throw new Error("the Pi agent directory is not canonical or changed during initialization");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async function openCreationDirectory(root, expected) {
|
|
153
|
+
if (process.platform === "win32")
|
|
154
|
+
return { anchor: root };
|
|
155
|
+
const directory = await fs.open(root, openRead | (constants.O_DIRECTORY ?? 0));
|
|
156
|
+
try {
|
|
157
|
+
if (!sameIdentity(expected, await directory.stat({ bigint: true })))
|
|
158
|
+
changed("Pi agent directory");
|
|
159
|
+
return { directory, anchor: (await directoryAnchor(directory, expected)) ?? root };
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
await directory.close();
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async function syncCreationDirectory(directory) {
|
|
167
|
+
if (!directory)
|
|
168
|
+
return async () => { };
|
|
169
|
+
try {
|
|
170
|
+
await directory.sync();
|
|
171
|
+
return () => directory.sync();
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
if (["EBADF", "EINVAL", "ENOSYS", "ENOTSUP", "EOPNOTSUPP", "EPERM"].includes(error.code ?? "")) {
|
|
175
|
+
if (process.platform === "darwin")
|
|
176
|
+
return async () => { };
|
|
177
|
+
throw new AutomaticIgnoreCreationUnavailable("the filesystem does not support flushing the Pi agent directory");
|
|
178
|
+
}
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async function directoryAnchor(directory, expected) {
|
|
183
|
+
for (const base of ["/proc/self/fd", "/dev/fd"]) {
|
|
184
|
+
const candidate = `${base}/${directory.fd}`;
|
|
185
|
+
const observed = await fs.stat(`${candidate}/.`, { bigint: true }).catch((error) => {
|
|
186
|
+
if (["ENOENT", "ENOTDIR", "EACCES", "EPERM"].includes(error.code ?? ""))
|
|
187
|
+
return undefined;
|
|
188
|
+
throw error;
|
|
189
|
+
});
|
|
190
|
+
if (observed?.isDirectory() && sameIdentity(expected, observed))
|
|
191
|
+
return candidate;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function statAt(target) {
|
|
195
|
+
return lstatSync(target, { bigint: true, throwIfNoEntry: false });
|
|
196
|
+
}
|
|
197
|
+
function changed(name) {
|
|
198
|
+
throw new Error(`"${name}" changed during initialization; review the current files and retry`);
|
|
199
|
+
}
|
|
200
|
+
function assertCurrent(target, expected) {
|
|
201
|
+
const current = statAt(target);
|
|
202
|
+
if (!current || !sameFile(expected, current))
|
|
203
|
+
changed(path.basename(target));
|
|
204
|
+
}
|
|
205
|
+
function assertOwned(stat, name, privateRecord) {
|
|
206
|
+
if (!stat.isFile() ||
|
|
207
|
+
stat.nlink !== 1n ||
|
|
208
|
+
(process.getuid && stat.uid !== BigInt(process.getuid())) ||
|
|
209
|
+
(privateRecord && process.platform !== "win32" && (stat.mode & 63n) !== 0n)) {
|
|
210
|
+
throw new Error(`unsafe "${name}"; preserve it for manual recovery`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
async function flushAndVerify(handle, target, canonical, expected, checkRoot, prior, privateRecord = false) {
|
|
214
|
+
const name = path.basename(target);
|
|
215
|
+
const opened = await handle.stat({ bigint: true });
|
|
216
|
+
assertOwned(opened, name, privateRecord);
|
|
217
|
+
if (prior && !sameFile(prior, opened))
|
|
218
|
+
changed(name);
|
|
219
|
+
checkRoot();
|
|
220
|
+
if ((await fs.realpath(target)) !== canonical)
|
|
221
|
+
throw new Error(`use the exact on-disk filename "${name}"`);
|
|
222
|
+
checkRoot();
|
|
223
|
+
assertCurrent(target, opened);
|
|
224
|
+
if (!prior)
|
|
225
|
+
await handle.writeFile(expected);
|
|
226
|
+
const before = await handle.stat({ bigint: true });
|
|
227
|
+
assertOwned(before, name, privateRecord);
|
|
228
|
+
if (!(prior ? sameFile(opened, before) : sameIdentity(opened, before)))
|
|
229
|
+
changed(name);
|
|
230
|
+
checkRoot();
|
|
231
|
+
assertCurrent(target, before);
|
|
232
|
+
const observed = Buffer.alloc(expected.length + 1);
|
|
233
|
+
let count = 0;
|
|
234
|
+
while (count < observed.length) {
|
|
235
|
+
checkRoot();
|
|
236
|
+
const { bytesRead } = await handle.read(observed, count, observed.length - count, count);
|
|
237
|
+
if (bytesRead === 0)
|
|
238
|
+
break;
|
|
239
|
+
count += bytesRead;
|
|
240
|
+
}
|
|
241
|
+
if (count !== expected.length || !observed.subarray(0, count).equals(expected)) {
|
|
242
|
+
throw new Error(privateRecord
|
|
243
|
+
? `invalid creation record "${name}"; preserve it for manual recovery`
|
|
244
|
+
: `unfinished creation of "${name}"; move the incomplete file outside the Pi agent directory or restore the full starter rules, then retry confirmed setup or migration`);
|
|
245
|
+
}
|
|
246
|
+
await handle.sync();
|
|
247
|
+
if (!sameFile(before, await handle.stat({ bigint: true })))
|
|
248
|
+
changed(name);
|
|
249
|
+
checkRoot();
|
|
250
|
+
assertCurrent(target, before);
|
|
251
|
+
return before;
|
|
252
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { closeSync, constants, fstatSync, fsync, lstatSync, openSync, realpathSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { documentFingerprint } from "../../document.js";
|
|
6
|
+
import { record } from "../../protocol.js";
|
|
7
|
+
import { getEngineRoot } from "../host.js";
|
|
8
|
+
import { withLockedLocalConfigDocument } from "../settings/config-file.js";
|
|
9
|
+
import { validateConfigName, validateSettingsDocument } from "../settings/settings-validation.js";
|
|
10
|
+
import { sameFile, sameIdentity } from "./ignore-source.js";
|
|
11
|
+
const MIGRATION_VERSION = 1;
|
|
12
|
+
const flush = promisify(fsync);
|
|
13
|
+
function markerPath(root, setup) {
|
|
14
|
+
const key = createHash("sha256")
|
|
15
|
+
.update(JSON.stringify([setup, MIGRATION_VERSION]))
|
|
16
|
+
.digest("hex");
|
|
17
|
+
return path.join(root, `.pi-sync.json.ignore-migration-${key}.deferred`);
|
|
18
|
+
}
|
|
19
|
+
function markerAt(target) {
|
|
20
|
+
const marker = lstatSync(target, { bigint: true, throwIfNoEntry: false });
|
|
21
|
+
if (marker &&
|
|
22
|
+
(!marker.isFile() ||
|
|
23
|
+
marker.nlink !== 1n ||
|
|
24
|
+
marker.size !== 0n ||
|
|
25
|
+
(process.getuid && marker.uid !== BigInt(process.getuid())) ||
|
|
26
|
+
(process.platform !== "win32" && (marker.mode & 63n) !== 0n) ||
|
|
27
|
+
realpathSync(target) !== target))
|
|
28
|
+
throw new Error(`Unsafe ignore migration deferral marker at "${target}"; preserve it for inspection.`);
|
|
29
|
+
return marker;
|
|
30
|
+
}
|
|
31
|
+
function eligibleToken(document, setup) {
|
|
32
|
+
if (!document)
|
|
33
|
+
return null;
|
|
34
|
+
const settings = validateSettingsDocument(document.parsed);
|
|
35
|
+
if (settings.activeSyncSetup !== setup ||
|
|
36
|
+
!Object.hasOwn(settings.syncSetups, setup) ||
|
|
37
|
+
settings.syncSetups[setup].sync.pathPolicy === "ignore-file")
|
|
38
|
+
return null;
|
|
39
|
+
const fingerprint = documentFingerprint({ bytes: document.bytes.toString("base64"), identity: document.identity });
|
|
40
|
+
return createHash("sha256")
|
|
41
|
+
.update(JSON.stringify([MIGRATION_VERSION, document.path, fingerprint]))
|
|
42
|
+
.digest("hex");
|
|
43
|
+
}
|
|
44
|
+
function stale() {
|
|
45
|
+
throw new Error("Ignore migration offer is stale; reopen Pi Sync.");
|
|
46
|
+
}
|
|
47
|
+
export function assertCurrentIgnoreMigrationOffer(document, root, setup, token) {
|
|
48
|
+
if (eligibleToken(document, setup) !== token || markerAt(markerPath(root, setup)))
|
|
49
|
+
stale();
|
|
50
|
+
}
|
|
51
|
+
function validateClient(execution) {
|
|
52
|
+
execution.validate();
|
|
53
|
+
const facts = execution.facts();
|
|
54
|
+
if (!execution.clientId || facts?.id !== execution.clientId || facts.mode !== "tui" || !facts.hasUI)
|
|
55
|
+
throw new Error("Ignore migration offers require an attached TUI client.");
|
|
56
|
+
}
|
|
57
|
+
function readRequest(payload, execution, fields) {
|
|
58
|
+
validateClient(execution);
|
|
59
|
+
if (!record(payload) ||
|
|
60
|
+
typeof payload.setup !== "string" ||
|
|
61
|
+
Object.keys(payload).some((key) => !fields.includes(key)))
|
|
62
|
+
throw new Error("Invalid ignore migration offer request.");
|
|
63
|
+
validateConfigName(payload.setup, "sync setup");
|
|
64
|
+
return payload.setup;
|
|
65
|
+
}
|
|
66
|
+
export async function readIgnoreMigrationOffer(payload, execution) {
|
|
67
|
+
const setup = readRequest(payload, execution, ["setup"]);
|
|
68
|
+
const result = await withLockedLocalConfigDocument(async (document, recheck) => {
|
|
69
|
+
validateClient(execution);
|
|
70
|
+
const token = eligibleToken(document, setup);
|
|
71
|
+
const deferred = token && markerAt(markerPath(getEngineRoot(), setup));
|
|
72
|
+
recheck();
|
|
73
|
+
return token && !deferred ? { token } : null;
|
|
74
|
+
}, execution.signal, false, { securePermissions: false });
|
|
75
|
+
validateClient(execution);
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
export function deferIgnoreMigrationOffer(payload, execution) {
|
|
79
|
+
const setup = readRequest(payload, execution, ["setup", "token"]);
|
|
80
|
+
if (!record(payload) || typeof payload.token !== "string" || !/^[a-f0-9]{64}$/u.test(payload.token))
|
|
81
|
+
throw new Error("Invalid ignore migration offer token.");
|
|
82
|
+
const { token } = payload;
|
|
83
|
+
return withLockedLocalConfigDocument(async (document, recheck) => {
|
|
84
|
+
validateClient(execution);
|
|
85
|
+
const root = getEngineRoot();
|
|
86
|
+
const target = markerPath(root, setup);
|
|
87
|
+
assertCurrentIgnoreMigrationOffer(document, root, setup, token);
|
|
88
|
+
await createMarker(root, target, () => {
|
|
89
|
+
if (execution.liveClients().some((peer) => peer.sessionFile && path.resolve(peer.sessionFile) === target))
|
|
90
|
+
throw new Error("Cannot defer ignore migration at a protected live session path.");
|
|
91
|
+
validateClient(execution);
|
|
92
|
+
recheck();
|
|
93
|
+
});
|
|
94
|
+
return true;
|
|
95
|
+
}, execution.signal, true, { securePermissions: false });
|
|
96
|
+
}
|
|
97
|
+
async function createMarker(root, target, beforeCreate) {
|
|
98
|
+
const noFollow = constants.O_NOFOLLOW ?? 0;
|
|
99
|
+
const directory = process.platform === "win32" ? undefined : openSync(root, constants.O_RDONLY | constants.O_DIRECTORY | noFollow);
|
|
100
|
+
try {
|
|
101
|
+
beforeCreate();
|
|
102
|
+
if (directory !== undefined &&
|
|
103
|
+
!sameIdentity(lstatSync(getEngineRoot(), { bigint: true }), fstatSync(directory, { bigint: true })))
|
|
104
|
+
throw new Error("The Pi agent directory changed before recording ignore migration deferral.");
|
|
105
|
+
const marker = openMarker(target, noFollow);
|
|
106
|
+
try {
|
|
107
|
+
const installed = fstatSync(marker, { bigint: true });
|
|
108
|
+
try {
|
|
109
|
+
await flush(marker);
|
|
110
|
+
if (directory !== undefined)
|
|
111
|
+
await flush(directory);
|
|
112
|
+
}
|
|
113
|
+
catch (cause) {
|
|
114
|
+
throw new Error("Ignore migration was deferred but marker durability could not be verified.", { cause });
|
|
115
|
+
}
|
|
116
|
+
getEngineRoot();
|
|
117
|
+
const current = markerAt(target);
|
|
118
|
+
if (!current || !sameFile(installed, current))
|
|
119
|
+
throw new Error("Ignore migration deferral marker changed during publication.");
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
closeSync(marker);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
if (directory !== undefined)
|
|
127
|
+
closeSync(directory);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function openMarker(target, noFollow) {
|
|
131
|
+
try {
|
|
132
|
+
return openSync(target, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | noFollow, 0o600);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
if (error.code === "EEXIST")
|
|
136
|
+
stale();
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
}
|