@narumitw/pi-sync 0.60.5 → 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 +25 -0
- package/README.md +32 -23
- package/dist/chunks/{chunk-F64YWRXG.ts → chunk-3E3TR3JE.ts} +4 -4
- package/dist/chunks/{chunk-YVH5VJR4.ts → chunk-6PFZUEUG.ts} +138 -61
- 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-KPWZNMKM.ts → chunk-ECYCNZOE.ts} +1 -5
- package/dist/chunks/chunk-ECYCNZOE.ts.map +7 -0
- package/dist/chunks/chunk-GELYN4UC.ts +14 -0
- package/dist/chunks/chunk-GELYN4UC.ts.map +7 -0
- package/dist/chunks/{chunk-V2QIMC3U.ts → chunk-GSCZ4VXV.ts} +13 -8
- package/dist/chunks/chunk-GSCZ4VXV.ts.map +7 -0
- package/dist/chunks/{chunk-6W2SNZ5P.ts → chunk-IBXEM35O.ts} +8 -3
- package/dist/chunks/{chunk-6W2SNZ5P.ts.map → chunk-IBXEM35O.ts.map} +3 -3
- package/dist/chunks/{chunk-6KIWZ4AY.ts → chunk-INECVQNR.ts} +13 -12
- package/dist/chunks/chunk-INECVQNR.ts.map +7 -0
- package/dist/chunks/chunk-JREGWM2B.ts +139 -0
- package/dist/chunks/chunk-JREGWM2B.ts.map +7 -0
- 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-NHFGAZEC.ts +277 -0
- 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-MCUZFUHY.ts → chunk-PWESMTH6.ts} +10 -10
- package/dist/chunks/{chunk-V4AMI3VL.ts → chunk-R3SAMXB6.ts} +10 -2
- package/dist/chunks/chunk-R3SAMXB6.ts.map +7 -0
- 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-LAXTCSX4.ts → chunk-ZB3GNX3P.ts} +124 -139
- package/dist/chunks/chunk-ZB3GNX3P.ts.map +7 -0
- package/dist/chunks/{chunk-HEB6YT64.ts → chunk-ZO52JM4H.ts} +2 -2
- package/dist/chunks/{command-handler-TNPWFIPG.ts → command-handler-6ATREPG7.ts} +44 -40
- package/dist/chunks/command-handler-6ATREPG7.ts.map +7 -0
- package/dist/chunks/{conflict-review-ETCSYJTH.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-DD6X4J2K.ts → file-selection-QR2KZVGD.ts} +28 -15
- package/dist/chunks/file-selection-QR2KZVGD.ts.map +7 -0
- package/dist/chunks/manager-result-dispatcher-MC6EQOQY.ts +19 -0
- package/dist/chunks/{manager-ui-LFONXWQN.ts → manager-ui-AOFUNXAJ.ts} +648 -305
- 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-SPZE7HIQ.ts → setup-switch-Y6AMFFNK.ts} +7 -7
- package/dist/chunks/{setup-wizard-5JYKAEIT.ts → setup-wizard-5G426MOZ.ts} +18 -16
- package/dist/chunks/setup-wizard-5G426MOZ.ts.map +7 -0
- 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-6VGR2UVZ.ts → sync-inspection-ITZ6Z4DE.ts} +7 -7
- package/dist/chunks/{sync-operations-SAKAZL6Z.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 +32 -32
- package/dist/package.json +6 -0
- package/docs/daemon-migration.md +27 -16
- package/package.json +11 -5
- package/skills/configure-pi-sync/SKILL.md +38 -13
- package/skills/configure-pi-sync/references/configuration.md +61 -34
- package/src/commands/command-execution.ts +8 -2
- package/src/daemon/pi-client.ts +1 -0
- package/src/settings/config.ts +1 -0
- package/src/sync/sync-operations.ts +18 -10
- package/src/sync/sync-policy.ts +5 -0
- package/src/ui/agent-mode-setting.ts +9 -1
- package/src/ui/excluded-paths-ui.ts +157 -2
- package/src/ui/file-selection.ts +12 -7
- package/src/ui/ignore-file-ui.ts +271 -0
- package/src/ui/ignore-migration-prompt.ts +65 -0
- package/src/ui/manager-state.ts +39 -20
- package/src/ui/manager-ui.ts +38 -19
- package/src/ui/remote-selection-ui.ts +159 -33
- package/src/ui/settings-frame.ts +2 -8
- package/src/ui/settings-review.ts +26 -0
- package/src/ui/settings-ui.ts +327 -199
- package/src/ui/setup/directory-rules.ts +81 -0
- package/src/ui/setup/git-ui.ts +14 -24
- package/src/ui/setup/s3-ui.ts +13 -26
- package/src/ui/setup/setup-actions.ts +0 -4
- package/src/ui/setup/setup-prompts.ts +99 -17
- package/src/ui/setup/setup-switcher.ts +4 -2
- package/src/ui/setup/setup-wizard.ts +5 -4
- package/src/ui/setup/webdav-ui.ts +13 -27
- package/src/ui/storage-connections-ui.ts +22 -14
- package/src/ui/sync-attention.ts +8 -3
- package/src/ui/sync-format.ts +8 -1
- package/src/ui/sync-setups-ui.ts +47 -27
- package/dist/chunks/chunk-6KIWZ4AY.ts.map +0 -7
- package/dist/chunks/chunk-KPWZNMKM.ts.map +0 -7
- package/dist/chunks/chunk-LAXTCSX4.ts.map +0 -7
- package/dist/chunks/chunk-V2QIMC3U.ts.map +0 -7
- package/dist/chunks/chunk-V4AMI3VL.ts.map +0 -7
- package/dist/chunks/chunk-YVH5VJR4.ts.map +0 -7
- package/dist/chunks/command-handler-TNPWFIPG.ts.map +0 -7
- package/dist/chunks/file-selection-DD6X4J2K.ts.map +0 -7
- package/dist/chunks/manager-result-dispatcher-2GFNWHDM.ts +0 -18
- package/dist/chunks/manager-ui-LFONXWQN.ts.map +0 -7
- package/dist/chunks/remote-selection-ui-GFR6TDTX.ts +0 -17
- package/dist/chunks/setup-wizard-5JYKAEIT.ts.map +0 -7
- package/dist/chunks/sync-operations-SAKAZL6Z.ts.map +0 -7
- /package/dist/chunks/{chunk-F64YWRXG.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-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-MCUZFUHY.ts.map → chunk-PWESMTH6.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-HEB6YT64.ts.map → chunk-ZO52JM4H.ts.map} +0 -0
- /package/dist/chunks/{conflict-review-ETCSYJTH.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/{manager-result-dispatcher-2GFNWHDM.ts.map → manager-result-dispatcher-MC6EQOQY.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-GFR6TDTX.ts.map → remote-selection-ui-4BTP2OJR.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-SPZE7HIQ.ts.map → setup-switch-Y6AMFFNK.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-6VGR2UVZ.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,165 @@
|
|
|
1
|
+
import { agentDir } from "../snapshot/session-paths.js";
|
|
2
|
+
import { inspectRemoteSelection } from "../sync/sync-policy.js";
|
|
3
|
+
import { fileHashMap } from "../sync/sync-state.js";
|
|
4
|
+
import { safeTerminalText, snapshotPathLabel } from "./terminal-text.js";
|
|
5
|
+
import { transferChanges, transferCounts } from "./transfer-changes.js";
|
|
6
|
+
export function formatDiff(local, remote) {
|
|
7
|
+
const localMap = fileHashMap(local);
|
|
8
|
+
const remoteMap = fileHashMap(remote);
|
|
9
|
+
const allPaths = [...new Set([...Object.keys(localMap), ...Object.keys(remoteMap)])].sort();
|
|
10
|
+
const lines = [
|
|
11
|
+
`local: ${local.files.length} files`,
|
|
12
|
+
`remote: ${safeTerminalText(remote.id)} (${remote.files.length} files)`,
|
|
13
|
+
"",
|
|
14
|
+
];
|
|
15
|
+
let changed = 0;
|
|
16
|
+
for (const filePath of allPaths) {
|
|
17
|
+
if (!Object.hasOwn(localMap, filePath)) {
|
|
18
|
+
lines.push(`Remote only: ${snapshotPathLabel(filePath)}`);
|
|
19
|
+
changed += 1;
|
|
20
|
+
}
|
|
21
|
+
else if (!Object.hasOwn(remoteMap, filePath)) {
|
|
22
|
+
lines.push(`Local only: ${snapshotPathLabel(filePath)}`);
|
|
23
|
+
changed += 1;
|
|
24
|
+
}
|
|
25
|
+
else if (localMap[filePath] !== remoteMap[filePath]) {
|
|
26
|
+
lines.push(`Different: ${snapshotPathLabel(filePath)}`);
|
|
27
|
+
changed += 1;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (changed === 0)
|
|
31
|
+
lines.push("No file differences.");
|
|
32
|
+
return lines.join("\n");
|
|
33
|
+
}
|
|
34
|
+
export function formatSnapshotOnlyDiff(title, snapshot) {
|
|
35
|
+
return [
|
|
36
|
+
`${safeTerminalText(title)}: ${safeTerminalText(snapshot.id)}`,
|
|
37
|
+
...snapshot.files.map((file) => `Add: ${snapshotPathLabel(file.path)}`),
|
|
38
|
+
].join("\n");
|
|
39
|
+
}
|
|
40
|
+
export function formatPushSummary(config, destination, upload, head, preservedRemoteFileCount = 0, remote) {
|
|
41
|
+
return [
|
|
42
|
+
`Sync setup: ${safeTerminalText(config.setupName)}`,
|
|
43
|
+
`Storage location: ${safeTerminalText(destination)}`,
|
|
44
|
+
`Direction: Local → Remote. Source: ${safeTerminalText(agentDir())}.`,
|
|
45
|
+
`Publish a snapshot containing ${upload.files.length} files; unchanged and preserved files are not counted as changes.`,
|
|
46
|
+
`Sessions: ${upload.syncSessions ? "included — may contain private conversations" : "not included"}`,
|
|
47
|
+
...excludedPolicyLines(config),
|
|
48
|
+
head ? `Remote latest: ${safeTerminalText(head.snapshotId)}` : "Remote latest: empty",
|
|
49
|
+
"Publication effect: the backend's active head will reference the new immutable snapshot. Removed paths leave the active snapshot; retained history is not erased.",
|
|
50
|
+
...(remote && inspectRemoteSelection(config.include, remote, config.exclude, config).kind === "different"
|
|
51
|
+
? ["Included-content policy effect: replace the differing remote selection with this setup's local selection."]
|
|
52
|
+
: []),
|
|
53
|
+
formatPublicationPreview(remote, upload),
|
|
54
|
+
config.skipSecretScan
|
|
55
|
+
? "Warning: possible-secret scanning is disabled for this push."
|
|
56
|
+
: preservedRemoteFileCount > 0
|
|
57
|
+
? `Possible secrets in locally managed files were scanned before this prompt; ${preservedRemoteFileCount} preserved remote file(s) were not rescanned.`
|
|
58
|
+
: "Possible secrets were scanned before this prompt.",
|
|
59
|
+
...(config.scope === "agent-directory"
|
|
60
|
+
? ["Warning: synced files may contain secrets or other sensitive data that the scanner cannot identify."]
|
|
61
|
+
: []),
|
|
62
|
+
].join("\n");
|
|
63
|
+
}
|
|
64
|
+
function excludedPolicyLines(config) {
|
|
65
|
+
const scoped = config.scope === "agent-directory";
|
|
66
|
+
return [
|
|
67
|
+
...(scoped
|
|
68
|
+
? [
|
|
69
|
+
"Scope: eligible files in the Pi agent directory.",
|
|
70
|
+
"Always local: Pi credentials (auth.json), project trust (trust.json), their lock files, and Pi Sync settings and service state.",
|
|
71
|
+
]
|
|
72
|
+
: []),
|
|
73
|
+
...(config.exclude === undefined && !scoped
|
|
74
|
+
? []
|
|
75
|
+
: [`Excluded paths: ${(config.exclude ?? []).map(safeTerminalText).join(", ") || "none"}`]),
|
|
76
|
+
...(scoped ? [`Re-included paths: ${(config.reinclude ?? []).map(safeTerminalText).join(", ") || "none"}`] : []),
|
|
77
|
+
...(scoped || config.exclude !== undefined
|
|
78
|
+
? [
|
|
79
|
+
"Excluded local files remain untouched; matching paths are omitted from new publications, not erased from history.",
|
|
80
|
+
]
|
|
81
|
+
: []),
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
export function formatApplyPreview(local, remote, protectedPaths = new Set(), additionalRemovals = []) {
|
|
85
|
+
return formatDirectionalChanges(local, remote, {
|
|
86
|
+
add: "Add locally",
|
|
87
|
+
update: "Update locally",
|
|
88
|
+
remove: "Remove locally",
|
|
89
|
+
}, protectedPaths, additionalRemovals);
|
|
90
|
+
}
|
|
91
|
+
export function formatPullSummary(config, destination, local, remote, protectedPaths, additionalRemovals = []) {
|
|
92
|
+
return [
|
|
93
|
+
`Sync setup: ${safeTerminalText(config.setupName)}`,
|
|
94
|
+
`Storage location: ${safeTerminalText(destination)}`,
|
|
95
|
+
"Direction: Remote → Local.",
|
|
96
|
+
`Snapshot: ${safeTerminalText(remote.id)}`,
|
|
97
|
+
...excludedPolicyLines(config),
|
|
98
|
+
`Sessions: ${remote.syncSessions ? "included — may contain private conversations" : "not included"}`,
|
|
99
|
+
`Protected live sessions: ${protectedPaths.size || "none"}`,
|
|
100
|
+
formatApplyPreview(local, remote, protectedPaths, additionalRemovals),
|
|
101
|
+
...(additionalRemovals.length
|
|
102
|
+
? ["Case-variant aliases listed above are removed before writing canonical paths."]
|
|
103
|
+
: []),
|
|
104
|
+
"A local backup is created before these writes/deletes. The remote active snapshot is unchanged.",
|
|
105
|
+
].join("\n");
|
|
106
|
+
}
|
|
107
|
+
export function formatRollbackSummary(config, destination, local, remote, requestedSnapshot, protectedPaths, additionalRemovals = []) {
|
|
108
|
+
return [
|
|
109
|
+
`Sync setup: ${safeTerminalText(config.setupName)}`,
|
|
110
|
+
`Storage location: ${safeTerminalText(destination)}`,
|
|
111
|
+
"Direction: Historical snapshot → Local and remote active head.",
|
|
112
|
+
`Snapshot: ${safeTerminalText(requestedSnapshot)}`,
|
|
113
|
+
...excludedPolicyLines(config),
|
|
114
|
+
`Sessions: ${remote.syncSessions ? "included — may contain private conversations" : "not included"}`,
|
|
115
|
+
`Protected live sessions: ${protectedPaths.size || "none"}`,
|
|
116
|
+
formatApplyPreview(local, remote, protectedPaths, additionalRemovals),
|
|
117
|
+
...(additionalRemovals.length
|
|
118
|
+
? ["Case-variant aliases listed above are removed before writing canonical paths."]
|
|
119
|
+
: []),
|
|
120
|
+
"A local backup is created before applying; the backend's active head will change.",
|
|
121
|
+
].join("\n");
|
|
122
|
+
}
|
|
123
|
+
export function formatPublicationPreview(remote, upload) {
|
|
124
|
+
return formatDirectionalChanges(remote, upload, {
|
|
125
|
+
add: "Add remotely",
|
|
126
|
+
update: "Update remotely",
|
|
127
|
+
remove: "Remove remotely",
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function formatDirectionalChanges(before, after, labels, protectedPaths = new Set(), additionalRemovals = []) {
|
|
131
|
+
const changes = transferChanges(before, after, protectedPaths);
|
|
132
|
+
const known = new Set(changes.map((change) => change.path));
|
|
133
|
+
for (const filePath of additionalRemovals) {
|
|
134
|
+
if (!known.has(filePath) && !protectedPaths.has(filePath)) {
|
|
135
|
+
changes.push({ path: filePath, action: "Delete" });
|
|
136
|
+
known.add(filePath);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const counts = transferCounts(changes);
|
|
140
|
+
const label = { Add: labels.add, Update: labels.update, Delete: labels.remove };
|
|
141
|
+
return [
|
|
142
|
+
`Changes: ${counts.add} add · ${counts.update} update · ${counts.remove} remove`,
|
|
143
|
+
...changes.map((change) => `${label[change.action]}: ${snapshotPathLabel(change.path)}`),
|
|
144
|
+
...(changes.length ? [] : ["No file changes."]),
|
|
145
|
+
].join("\n");
|
|
146
|
+
}
|
|
147
|
+
export function countPreservedRemoteFiles(local, upload) {
|
|
148
|
+
const localPaths = new Set(local.files.map((file) => file.path));
|
|
149
|
+
return upload.files.filter((file) => !localPaths.has(file.path)).length;
|
|
150
|
+
}
|
|
151
|
+
export function publicationCapabilityDescription(capability) {
|
|
152
|
+
switch (capability) {
|
|
153
|
+
case "lease-protected":
|
|
154
|
+
return "lease-protected (exact expected-ref update)";
|
|
155
|
+
case "atomic-conditional":
|
|
156
|
+
return "atomic-conditional (verified atomic precondition)";
|
|
157
|
+
case "conditional-required":
|
|
158
|
+
return "conditional-required (read-only until atomic preconditions are verified)";
|
|
159
|
+
case "read-check-write-verify":
|
|
160
|
+
return "read-check-write-verify (visible races rejected; simultaneous unseen races remain possible)";
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export function redact(value) {
|
|
164
|
+
return value.length <= 8 ? "configured" : `${value.slice(0, 4)}…${value.slice(-4)}`;
|
|
165
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { engineHost } from "../host.js";
|
|
2
|
+
const enabled = new WeakMap();
|
|
3
|
+
const reasons = {
|
|
4
|
+
transient: "temp",
|
|
5
|
+
contention: "busy",
|
|
6
|
+
stale: "stale",
|
|
7
|
+
authentication: "auth",
|
|
8
|
+
storage: "storage",
|
|
9
|
+
unsafe: "review",
|
|
10
|
+
model: "model",
|
|
11
|
+
budget: "limit",
|
|
12
|
+
unknown: "unknown",
|
|
13
|
+
};
|
|
14
|
+
export function syncStatusFailureReason(kind) {
|
|
15
|
+
return kind && Object.hasOwn(reasons, kind) ? reasons[kind] : "unknown";
|
|
16
|
+
}
|
|
17
|
+
export function configureSyncStatus(ctx, value) {
|
|
18
|
+
enabled.set(ctx.sessionManager, value);
|
|
19
|
+
if (!value)
|
|
20
|
+
setSyncStatus(ctx, undefined);
|
|
21
|
+
}
|
|
22
|
+
export function setSyncStatus(ctx, value, presentation) {
|
|
23
|
+
if (!ctx.hasUI || (value !== undefined && enabled.get(ctx.sessionManager) === false))
|
|
24
|
+
return;
|
|
25
|
+
const host = engineHost();
|
|
26
|
+
if (host.status)
|
|
27
|
+
host.status(ctx, value, presentation);
|
|
28
|
+
else
|
|
29
|
+
ctx.ui.setStatus("sync", value);
|
|
30
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: Terminal and display-direction controls.
|
|
2
|
+
const TERMINAL_CONTROLS = /[\u0000-\u001f\u007f-\u009f\u061c\u200b-\u200f\u202a-\u202e\u2060-\u2069\ufeff]/gu;
|
|
3
|
+
export function safeTerminalText(value) {
|
|
4
|
+
return value.replace(TERMINAL_CONTROLS, "?");
|
|
5
|
+
}
|
|
6
|
+
/** Escape before joining a multiline review; raw filesystem paths remain unchanged. */
|
|
7
|
+
export function snapshotPathLabel(value) {
|
|
8
|
+
return value.replace(TERMINAL_CONTROLS, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
9
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { fileHashMap } from "../sync/sync-state.js";
|
|
2
|
+
/** Compare effective before/after snapshots, not raw planner decisions. */
|
|
3
|
+
export function transferChanges(before, after, protectedPaths = new Set()) {
|
|
4
|
+
const beforeMap = before ? fileHashMap(before) : {};
|
|
5
|
+
const afterMap = fileHashMap(after);
|
|
6
|
+
return [...new Set([...Object.keys(beforeMap), ...Object.keys(afterMap)])]
|
|
7
|
+
.sort()
|
|
8
|
+
.flatMap((filePath) => {
|
|
9
|
+
if (protectedPaths.has(filePath))
|
|
10
|
+
return [];
|
|
11
|
+
if (!Object.hasOwn(beforeMap, filePath))
|
|
12
|
+
return [{ path: filePath, action: "Add" }];
|
|
13
|
+
if (!Object.hasOwn(afterMap, filePath))
|
|
14
|
+
return [{ path: filePath, action: "Delete" }];
|
|
15
|
+
return beforeMap[filePath] !== afterMap[filePath] ? [{ path: filePath, action: "Update" }] : [];
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export function transferCounts(changes) {
|
|
19
|
+
return {
|
|
20
|
+
add: changes.filter((change) => change.action === "Add").length,
|
|
21
|
+
update: changes.filter((change) => change.action === "Update").length,
|
|
22
|
+
remove: changes.filter((change) => change.action === "Delete").length,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { confirmMergeReview } from "./merge-review.js";
|
|
2
|
+
/** Presentation is supplied by the host; RPC keeps its existing directional confirmation. */
|
|
3
|
+
export async function confirmTransferReview(ctx, title, content, signal, validate) {
|
|
4
|
+
validate();
|
|
5
|
+
const isCurrent = () => {
|
|
6
|
+
try {
|
|
7
|
+
validate();
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const confirmed = ctx.mode === "tui" && ctx.hasUI
|
|
15
|
+
? await confirmMergeReview(ctx, title, content, signal, isCurrent, "apply reviewed transfer", content.split("\n"))
|
|
16
|
+
: await ctx.ui.confirm(title, content, { signal });
|
|
17
|
+
validate();
|
|
18
|
+
return confirmed;
|
|
19
|
+
}
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { authorizeAfterExit, consentFingerprint, readConsent, requireHandover } from "./consent.js";
|
|
2
|
+
import { documentFingerprint } from "./document.js";
|
|
3
|
+
import { createMonitor } from "./monitor.js";
|
|
4
|
+
import { MAX_SETTINGS_BYTES, record } from "./protocol.js";
|
|
5
|
+
import { createServiceContext, installServiceHost } from "./service-host.js";
|
|
6
|
+
function optionsFrom(value, execution) {
|
|
7
|
+
if (!record(value))
|
|
8
|
+
throw new Error("Invalid operation options.");
|
|
9
|
+
const allowed = new Set(["yes", "force", "stale", "silent", "reload", "setup", "args", "agentRetryRefusal"]);
|
|
10
|
+
if (Object.keys(value).some((key) => !allowed.has(key)) ||
|
|
11
|
+
["yes", "force", "stale", "silent", "reload", "agentRetryRefusal"].some((key) => value[key] !== undefined && typeof value[key] !== "boolean") ||
|
|
12
|
+
(value.setup !== undefined && (typeof value.setup !== "string" || value.setup.length > 512)) ||
|
|
13
|
+
!Array.isArray(value.args) ||
|
|
14
|
+
value.args.length > 16 ||
|
|
15
|
+
value.args.some((arg) => typeof arg !== "string" || arg.length > 4096))
|
|
16
|
+
throw new Error("Invalid operation options.");
|
|
17
|
+
return {
|
|
18
|
+
yes: false,
|
|
19
|
+
force: false,
|
|
20
|
+
stale: false,
|
|
21
|
+
silent: false,
|
|
22
|
+
reload: false,
|
|
23
|
+
auto: false,
|
|
24
|
+
...value,
|
|
25
|
+
args: value.args,
|
|
26
|
+
signal: execution.signal,
|
|
27
|
+
onCommit: execution.committed,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Engine dispatch is loaded only by the service, never by the public IPC client. */
|
|
31
|
+
export function createEngineService(root) {
|
|
32
|
+
const host = installServiceHost(root);
|
|
33
|
+
const monitor = createMonitor(root, host);
|
|
34
|
+
const execute = (operation, payload, execution) => host.run(execution, async () => {
|
|
35
|
+
if (operation === "ignore.capabilities") {
|
|
36
|
+
execution.validate();
|
|
37
|
+
return { available: false };
|
|
38
|
+
}
|
|
39
|
+
if (operation === "ignore.migration-offer" || operation === "ignore.migration-defer") {
|
|
40
|
+
execution.validate();
|
|
41
|
+
const { readIgnoreMigrationOffer, deferIgnoreMigrationOffer } = await import("./engine/ignore/ignore-migration-prompt.js");
|
|
42
|
+
return operation === "ignore.migration-offer"
|
|
43
|
+
? readIgnoreMigrationOffer(payload, execution)
|
|
44
|
+
: deferIgnoreMigrationOffer(payload, execution);
|
|
45
|
+
}
|
|
46
|
+
if (operation === "ignore.save") {
|
|
47
|
+
execution.validate();
|
|
48
|
+
throw new Error("Daemon ignore-file saves are unavailable. Edit the existing rule file manually.");
|
|
49
|
+
}
|
|
50
|
+
await monitor.pause();
|
|
51
|
+
execution.validate();
|
|
52
|
+
if (operation === "daemon.authorize")
|
|
53
|
+
return authorizeAfterExit(execution, payload);
|
|
54
|
+
if (operation === "daemon.handover") {
|
|
55
|
+
await requireHandover(execution);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
if (operation === "daemon.policy") {
|
|
59
|
+
const { loadConfig } = await import("./engine/settings/config.js");
|
|
60
|
+
const config = await loadConfig();
|
|
61
|
+
const fingerprint = consentFingerprint(root, config);
|
|
62
|
+
const saved = readConsent(root)?.setups[config.setupName];
|
|
63
|
+
const facts = execution.facts();
|
|
64
|
+
return {
|
|
65
|
+
setup: config.setupName,
|
|
66
|
+
fingerprint,
|
|
67
|
+
afterExit: Boolean(saved?.afterExit &&
|
|
68
|
+
saved.fingerprint === fingerprint &&
|
|
69
|
+
JSON.stringify(saved.model) === JSON.stringify(facts?.model) &&
|
|
70
|
+
saved.sessionDir === facts?.sessionDir &&
|
|
71
|
+
saved.cwd === facts?.cwd),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (operation === "monitor.pause")
|
|
75
|
+
return;
|
|
76
|
+
if (operation === "ignore.read") {
|
|
77
|
+
const { readIgnoreFileEdit } = await import("./engine/ignore/ignore-edit.js");
|
|
78
|
+
execution.validate();
|
|
79
|
+
return readIgnoreFileEdit(payload, execution);
|
|
80
|
+
}
|
|
81
|
+
if (operation === "settings.read" || operation === "settings.repair-read") {
|
|
82
|
+
const { readLocalConfigDocument } = await import("./engine/settings/settings-store.js");
|
|
83
|
+
const { readActiveLocalConfigDocumentForRepair } = await import("./engine/settings/config-file.js");
|
|
84
|
+
const document = await (operation === "settings.read" && readConsent(root)
|
|
85
|
+
? readLocalConfigDocument()
|
|
86
|
+
: readActiveLocalConfigDocumentForRepair());
|
|
87
|
+
execution.validate();
|
|
88
|
+
if (document && operation === "settings.read") {
|
|
89
|
+
const { validateSettingsDocument } = await import("./engine/settings/settings-validation.js");
|
|
90
|
+
execution.validate();
|
|
91
|
+
validateSettingsDocument(document.parsed);
|
|
92
|
+
}
|
|
93
|
+
return document ? { ...document, bytes: document.bytes.toString("base64") } : null;
|
|
94
|
+
}
|
|
95
|
+
if (operation === "settings.cas") {
|
|
96
|
+
if (!record(payload) ||
|
|
97
|
+
(payload.expected !== null &&
|
|
98
|
+
(typeof payload.expected !== "string" || !/^[a-f0-9]{64}$/u.test(payload.expected))) ||
|
|
99
|
+
!record(payload.next))
|
|
100
|
+
throw new Error("Invalid settings mutation.");
|
|
101
|
+
const { updateLocalConfigDocument, peekLocalConfigDocument } = await import("./engine/settings/config-file.js");
|
|
102
|
+
const { localConfigTemplate } = await import("./engine/settings/settings-store.js");
|
|
103
|
+
const { validateSettingsDocument } = await import("./engine/settings/settings-validation.js");
|
|
104
|
+
const next = validateSettingsDocument(payload.next);
|
|
105
|
+
if (Object.values(next.syncSetups).some((setup) => setup.sync.pathPolicy === "ignore-file")) {
|
|
106
|
+
throw new Error("Ignore-file setup activation is not available in this Daemon build.");
|
|
107
|
+
}
|
|
108
|
+
if (Buffer.byteLength(JSON.stringify(next)) > MAX_SETTINGS_BYTES)
|
|
109
|
+
throw new Error("Settings exceed the editable local API byte limit; no fields were dropped.");
|
|
110
|
+
const validateSource = (document) => {
|
|
111
|
+
execution.validate();
|
|
112
|
+
const view = document ? { bytes: document.bytes.toString("base64"), identity: document.identity } : undefined;
|
|
113
|
+
if (documentFingerprint(view) !== payload.expected)
|
|
114
|
+
throw new Error("Settings changed; reopen the review before saving.");
|
|
115
|
+
};
|
|
116
|
+
validateSource(await peekLocalConfigDocument());
|
|
117
|
+
await requireHandover(execution);
|
|
118
|
+
execution.validate();
|
|
119
|
+
return updateLocalConfigDocument(localConfigTemplate(), () => {
|
|
120
|
+
execution.validate();
|
|
121
|
+
validateSettingsDocument(next);
|
|
122
|
+
return next;
|
|
123
|
+
}, validateSettingsDocument, execution.signal, validateSource);
|
|
124
|
+
}
|
|
125
|
+
const ctx = createServiceContext(execution);
|
|
126
|
+
if (operation === "initialize")
|
|
127
|
+
return initialize(ctx, execution);
|
|
128
|
+
if (operation === "inspect") {
|
|
129
|
+
if (!record(payload) || (payload.setup !== undefined && typeof payload.setup !== "string"))
|
|
130
|
+
throw new Error("Invalid inspection request.");
|
|
131
|
+
const { withStateDirectoryAccess } = await import("./engine/state/state-directory.js");
|
|
132
|
+
const { withLock } = await import("./engine/state/lock.js");
|
|
133
|
+
return withJobTimings(ctx, execution, "daemon inspection", (timings) => withStateDirectoryAccess(() => withLock("startup-check", async () => {
|
|
134
|
+
const { loadConfig, syncCheckConfigFingerprint } = await import("./engine/settings/config.js");
|
|
135
|
+
const config = await loadConfig(payload.setup);
|
|
136
|
+
execution.validate();
|
|
137
|
+
if (payload.fingerprint !== syncCheckConfigFingerprint(config))
|
|
138
|
+
throw new Error("Settings changed before inspection.");
|
|
139
|
+
const { snapshotOptionsForContext } = await import("./engine/snapshot/session-paths.js");
|
|
140
|
+
const { inspectSync } = await import("./engine/sync/sync-inspection.js");
|
|
141
|
+
execution.validate();
|
|
142
|
+
return inspectSync(config, snapshotOptionsForContext(ctx, config), execution.signal, undefined, timings);
|
|
143
|
+
})));
|
|
144
|
+
}
|
|
145
|
+
const supported = [
|
|
146
|
+
"status",
|
|
147
|
+
"diff",
|
|
148
|
+
"doctor",
|
|
149
|
+
"history",
|
|
150
|
+
"push",
|
|
151
|
+
"pull",
|
|
152
|
+
"sync",
|
|
153
|
+
"startup-transfer",
|
|
154
|
+
"shutdown",
|
|
155
|
+
"conflicts",
|
|
156
|
+
"rollback",
|
|
157
|
+
"unlock",
|
|
158
|
+
"migrate-state",
|
|
159
|
+
];
|
|
160
|
+
if (!supported.includes(operation))
|
|
161
|
+
throw new Error("Unsupported engine operation.");
|
|
162
|
+
const options = optionsFrom(payload, execution);
|
|
163
|
+
if (!options.reload)
|
|
164
|
+
ctx.reload = undefined;
|
|
165
|
+
if (operation === "shutdown") {
|
|
166
|
+
const { loadConfigForCheck } = await import("./engine/settings/config.js");
|
|
167
|
+
const { syncSessionsSelected } = await import("./engine/sync/sync-policy.js");
|
|
168
|
+
const config = await loadConfigForCheck();
|
|
169
|
+
execution.validate();
|
|
170
|
+
if (!config.automatic || !syncSessionsSelected(config))
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (!ctx.hasUI || !["tui", "rpc"].includes(ctx.mode))
|
|
174
|
+
throw new Error("Synchronization requires an observable TUI or RPC client.");
|
|
175
|
+
const { withStateDirectoryAccess, migrateLegacyStateDirectory } = await import("./engine/state/state-directory.js");
|
|
176
|
+
if (operation === "migrate-state") {
|
|
177
|
+
if (!options.yes) {
|
|
178
|
+
const accepted = await ctx.ui.confirm("Migrate pi-sync state directory", "Confirm that every older Pi process is closed. Preserve both roots and pending journals on failure.", { signal: execution.signal });
|
|
179
|
+
execution.validate();
|
|
180
|
+
if (!accepted)
|
|
181
|
+
return { status: "cancelled", message: "pi-sync state migration cancelled." };
|
|
182
|
+
}
|
|
183
|
+
execution.validate();
|
|
184
|
+
const result = await migrateLegacyStateDirectory();
|
|
185
|
+
if (result.status === "migrated")
|
|
186
|
+
execution.committed();
|
|
187
|
+
execution.validate();
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
return withStateDirectoryAccess(async () => {
|
|
191
|
+
if (["startup-transfer", "shutdown"].includes(operation) && !readConsent(root))
|
|
192
|
+
throw new Error("Automatic work requires reviewed daemon handover first.");
|
|
193
|
+
if (["push", "pull", "sync", "startup-transfer", "shutdown", "conflicts", "rollback"].includes(operation)) {
|
|
194
|
+
await requireHandover(execution);
|
|
195
|
+
await initialize(ctx, execution, false);
|
|
196
|
+
}
|
|
197
|
+
const { withLock, unlock } = await import("./engine/state/lock.js");
|
|
198
|
+
if (operation === "unlock")
|
|
199
|
+
return unlock(ctx, options);
|
|
200
|
+
const operations = await import("./engine/sync/sync-operations.js");
|
|
201
|
+
if (operation === "conflicts") {
|
|
202
|
+
const { showConflicts } = await import("./engine/sync/conflict-review.js");
|
|
203
|
+
return withLock("sync", () => showConflicts(ctx, options));
|
|
204
|
+
}
|
|
205
|
+
if (operation === "shutdown") {
|
|
206
|
+
const { pushSessionsOnShutdown } = await import("./engine/sync/session-push.js");
|
|
207
|
+
return pushSessionsOnShutdown(ctx, options, { operations: async () => operations });
|
|
208
|
+
}
|
|
209
|
+
if (operation === "startup-transfer") {
|
|
210
|
+
const { loadConfig } = await import("./engine/settings/config.js");
|
|
211
|
+
const { startupTransferEnabled } = await import("./engine/sync/agent-policy.js");
|
|
212
|
+
if (!startupTransferEnabled(await loadConfig(options.setup)) || !ctx.isIdle())
|
|
213
|
+
throw new Error("Startup transfer is no longer authorized or idle.");
|
|
214
|
+
options.auto = true;
|
|
215
|
+
options.yes = true;
|
|
216
|
+
options.silent = true;
|
|
217
|
+
options.reload = false;
|
|
218
|
+
}
|
|
219
|
+
if (operation === "sync" || operation === "startup-transfer") {
|
|
220
|
+
const run = async () => {
|
|
221
|
+
const { prepareResolverHost } = await import("./resolver-host.js");
|
|
222
|
+
const { loadConfig } = await import("./engine/settings/config.js");
|
|
223
|
+
const config = await loadConfig(options.setup);
|
|
224
|
+
execution.validate();
|
|
225
|
+
if (operation === "sync" && !options.agentRetryRefusal)
|
|
226
|
+
monitor.explicitSync(config.setupName, execution);
|
|
227
|
+
const binding = JSON.stringify(execution.facts()?.model);
|
|
228
|
+
const resolver = await prepareResolverHost(root, config.agentMode ? execution.facts()?.model : undefined, execution.signal);
|
|
229
|
+
try {
|
|
230
|
+
ctx.modelUnavailableReason = resolver.unavailable;
|
|
231
|
+
Object.defineProperty(ctx, "model", {
|
|
232
|
+
get: () => (JSON.stringify(execution.facts()?.model) === binding ? resolver.model : undefined),
|
|
233
|
+
});
|
|
234
|
+
ctx.validateModel = async () => {
|
|
235
|
+
const fresh = await execution.request("model-binding", {});
|
|
236
|
+
execution.validate();
|
|
237
|
+
if (JSON.stringify(fresh ?? undefined) !== binding)
|
|
238
|
+
throw new Error("Selected provider/model capability changed before dispatch.");
|
|
239
|
+
};
|
|
240
|
+
ctx.modelRegistry = {
|
|
241
|
+
streamSimple: (model, context, options) => {
|
|
242
|
+
execution.validate();
|
|
243
|
+
if (JSON.stringify(execution.facts()?.model) !== binding)
|
|
244
|
+
throw new Error("Selected model changed before dispatch.");
|
|
245
|
+
if (resolver.unavailable)
|
|
246
|
+
throw new Error(resolver.unavailable);
|
|
247
|
+
return resolver.registry.streamSimple(model, context, options);
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
const { withAgentSyncLock } = await import("./engine/sync/agent-sync.js");
|
|
251
|
+
return await withAgentSyncLock(ctx, options, async (current) => {
|
|
252
|
+
if (operation === "startup-transfer") {
|
|
253
|
+
const { loadConfig } = await import("./engine/settings/config.js");
|
|
254
|
+
const { startupTransferEnabled } = await import("./engine/sync/agent-policy.js");
|
|
255
|
+
const config = await loadConfig(current.setup);
|
|
256
|
+
execution.validate();
|
|
257
|
+
const { inspectSync } = await import("./engine/sync/sync-inspection.js");
|
|
258
|
+
const { snapshotOptionsForContext } = await import("./engine/snapshot/session-paths.js");
|
|
259
|
+
const inspection = await inspectSync(config, snapshotOptionsForContext(ctx, config), current.signal);
|
|
260
|
+
execution.validate();
|
|
261
|
+
if (!startupTransferEnabled(config) ||
|
|
262
|
+
!ctx.isIdle() ||
|
|
263
|
+
execution.participants().some((peer) => peer.ready !== true) ||
|
|
264
|
+
inspection.firstSync ||
|
|
265
|
+
!inspection.head ||
|
|
266
|
+
inspection.selectionState?.kind !== "same")
|
|
267
|
+
throw new Error("Startup transfer requires a fresh initialized baseline, matching selection, and idle ready clients; use the reviewed foreground command.");
|
|
268
|
+
}
|
|
269
|
+
return operations.syncBoth(ctx, current);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
finally {
|
|
273
|
+
await resolver.settle();
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
return operation === "startup-transfer"
|
|
277
|
+
? withJobTimings(ctx, execution, "daemon transfer", (timings) => {
|
|
278
|
+
options.startupTimings = timings;
|
|
279
|
+
return run();
|
|
280
|
+
})
|
|
281
|
+
: run();
|
|
282
|
+
}
|
|
283
|
+
if (operation === "push" || operation === "pull" || operation === "rollback")
|
|
284
|
+
return withLock(operation, () => operations[operation](ctx, options));
|
|
285
|
+
if (operation === "status" || operation === "diff" || operation === "doctor" || operation === "history")
|
|
286
|
+
return operations[operation](ctx, options);
|
|
287
|
+
throw new Error("Unreachable operation.");
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
return {
|
|
291
|
+
execute,
|
|
292
|
+
bind: monitor.bind,
|
|
293
|
+
hooks: {
|
|
294
|
+
factsChanged: monitor.factsChanged,
|
|
295
|
+
idle: monitor.schedule,
|
|
296
|
+
close: monitor.close,
|
|
297
|
+
lifetime: monitor.lifetime,
|
|
298
|
+
quiesce: monitor.pause,
|
|
299
|
+
failure: monitor.blockAutomatic,
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
async function withJobTimings(ctx, execution, label, action) {
|
|
304
|
+
const { createStartupTimings } = await import("./engine/sync/startup-timings.js");
|
|
305
|
+
const timings = createStartupTimings((_ctx, report) => execution.emit("timings", { report }));
|
|
306
|
+
let completed = false;
|
|
307
|
+
try {
|
|
308
|
+
const result = await action(timings);
|
|
309
|
+
completed = true;
|
|
310
|
+
return result;
|
|
311
|
+
}
|
|
312
|
+
finally {
|
|
313
|
+
timings.publish(ctx, execution.facts()?.startupDebug ?? false, execution.signal, label, completed ? "completed" : "stopped");
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
async function initialize(ctx, execution, diagnostics = true) {
|
|
317
|
+
const { pendingTransactionEntries } = await import("./engine/snapshot/snapshot-transaction-directory.js");
|
|
318
|
+
const pending = await pendingTransactionEntries();
|
|
319
|
+
execution.validate();
|
|
320
|
+
if (pending.some((entry) => entry.isDirectory()) && !readConsent(execution.root))
|
|
321
|
+
throw new Error("Pending local recovery requires reviewed daemon handover. Close older Pi processes and use /sync daemon handover, then /reload before editing managed files.");
|
|
322
|
+
if (!readConsent(execution.root)) {
|
|
323
|
+
const { stateDirectoryMigrationNotice } = await import("./engine/state/state-directory.js");
|
|
324
|
+
const notice = await stateDirectoryMigrationNotice();
|
|
325
|
+
execution.validate();
|
|
326
|
+
if (notice)
|
|
327
|
+
throw new Error(notice);
|
|
328
|
+
// Before ownership approval, report metadata without filename migration or recovery writes.
|
|
329
|
+
const { peekLocalConfigDocument } = await import("./engine/settings/config-file.js");
|
|
330
|
+
const { validateSettingsDocument } = await import("./engine/settings/settings-validation.js");
|
|
331
|
+
const { configFromSettings } = await import("./engine/settings/config.js");
|
|
332
|
+
const document = await peekLocalConfigDocument();
|
|
333
|
+
execution.validate();
|
|
334
|
+
const settings = document ? validateSettingsDocument(document.parsed) : undefined;
|
|
335
|
+
const config = settings?.activeSyncSetup ? configFromSettings(settings) : undefined;
|
|
336
|
+
return { debug: settings?.debug ?? false, settings, config, handoverRequired: true };
|
|
337
|
+
}
|
|
338
|
+
const { initializeSync } = await import("./engine/sync/initialization.js");
|
|
339
|
+
const initialized = await initializeSync(ctx, execution.signal, (_ctx, report) => {
|
|
340
|
+
if (diagnostics)
|
|
341
|
+
execution.emit("timings", { report });
|
|
342
|
+
});
|
|
343
|
+
return { ...initialized, handoverRequired: !readConsent(execution.root) };
|
|
344
|
+
}
|